pci.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PCI_H
  20. #define _PCI_H
  21. #include <kernel/types.h>
  22. #include <kernel/errno.h>
  23. __uint32_t pci_read_config(__uint8_t, __uint8_t, __uint8_t, __uint8_t);
  24. __uint32_t pci_lspci(void);
  25. void pci_infodev(__uint8_t, __uint8_t, __uint8_t);
  26. struct pci_device {
  27. __uint16_t devid;
  28. __uint16_t vendor;
  29. char *devname;
  30. /* the device configure word (256 bytes) */
  31. char *config;
  32. };
  33. /* the general pci header */
  34. struct pci_header {
  35. __uint16_t vendor;
  36. __uint16_t dev;
  37. __uint16_t cmd;
  38. __uint16_t status;
  39. __uint8_t revision;
  40. __uint8_t prof_if;
  41. __uint8_t subclass;
  42. __uint8_t class_code;
  43. __uint8_t cache_size;
  44. __uint8_t latency;
  45. __uint8_t hdr_type;
  46. __uint8_t bist;
  47. } __attribute__ ((packed));
  48. /* regular device */
  49. struct pci_header0 {
  50. struct pci_header hdr;
  51. __uint32_t bar0, bar1, bar2,
  52. bar3, bar4, bar5;
  53. /* a pointer that points to the info of the card (?) */
  54. __uint32_t cardbus_cis;
  55. __uint16_t subsys_vendor;
  56. __uint16_t subsys;
  57. /* extend rom base */
  58. __uint32_t erom_base;
  59. /* ? */
  60. __uint8_t capabilities;
  61. __uint16_t rsvd0;
  62. __uint8_t rsvd1;
  63. __uint32_t rsvd2;
  64. __uint8_t irqnr;
  65. /* it looks only for apic :-( */
  66. __uint8_t intpin;
  67. /* ? */
  68. __uint8_t min_grant;
  69. __uint8_t max_latency;
  70. } __attribute__ ((packed));
  71. /* pci-pci bridge */
  72. struct pci_header1 {
  73. struct pci_header hdr;
  74. __uint32_t bar0, bar1;
  75. __uint8_t busnr_primary;
  76. __uint8_t busnr_secondary;
  77. __uint8_t busnr_sub;
  78. __uint8_t second_latency;
  79. __uint8_t io_base, io_limit;
  80. __uint16_t mem_limit;
  81. __uint16_t pre_mem_base;
  82. __uint16_t pre_mem_limit;
  83. /* for 48-bit long-mode */
  84. __uint32_t pre_base_high;
  85. __uint32_t pre_base_limit;
  86. __uint16_t io_high;
  87. __uint16_t io_limit_high;
  88. __uint8_t capabilities;
  89. __uint16_t rsvd0;
  90. __uint8_t rsvd1;
  91. __uint32_t erom_base;
  92. __uint8_t irqnr;
  93. __uint8_t intpin;
  94. __uint16_t bridge_ctl;
  95. } __attribute__ ((packed));
  96. /* pci-cardbus bridge */
  97. struct pci_header2 {
  98. struct pci_header hdr;
  99. __uint32_t cardbus_base;
  100. __uint8_t caplist_offset;
  101. __uint8_t rsvd0;
  102. __uint16_t second_status;
  103. __uint8_t pcibus_nr;
  104. __uint8_t cardbus_nr;
  105. __uint8_t sub_bus_nr;
  106. __uint8_t latency;
  107. __uint32_t mmbase_0;
  108. __uint32_t mmlimit_0;
  109. __uint32_t mmbase_1;
  110. __uint32_t mmlimit_1;
  111. __uint32_t iobase_0;
  112. __uint32_t iolimit_0;
  113. __uint32_t iobase_1;
  114. __uint32_t iolimit_1;
  115. __uint8_t irqnr;
  116. __uint8_t intpin;
  117. __uint16_t bridge_ctl;
  118. __uint16_t subsys_dev;
  119. __uint16_t subsys_vendor;
  120. __uint32_t lagency_base;
  121. } __attribute__ ((packed));
  122. #endif