pci.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. /* the general pci header */
  27. struct pci_header {
  28. __uint16_t vendor;
  29. __uint16_t dev;
  30. __uint16_t cmd;
  31. __uint16_t status;
  32. __uint8_t revision;
  33. __uint8_t prog_if;
  34. __uint8_t subclass;
  35. __uint8_t class_code;
  36. __uint8_t cache_size;
  37. __uint8_t latency;
  38. __uint8_t hdr_type;
  39. __uint8_t bist;
  40. } __attribute__ ((packed));
  41. /* regular device */
  42. struct pci_header0 {
  43. struct pci_header hdr;
  44. __uint32_t bar0, bar1, bar2,
  45. bar3, bar4, bar5;
  46. /* a pointer that points to the info of the card (?) */
  47. __uint32_t cardbus_cis;
  48. __uint16_t subsys_vendor;
  49. __uint16_t subsys;
  50. /* extend rom base */
  51. __uint32_t erom_base;
  52. /* ? */
  53. __uint8_t capabilities;
  54. __uint16_t rsvd0;
  55. __uint8_t rsvd1;
  56. __uint32_t rsvd2;
  57. __uint8_t irqnr;
  58. /* it looks only for apic :-( */
  59. __uint8_t intpin;
  60. /* ? */
  61. __uint8_t min_grant;
  62. __uint8_t max_latency;
  63. } __attribute__ ((packed));
  64. /* pci-pci bridge */
  65. struct pci_header1 {
  66. struct pci_header hdr;
  67. __uint32_t bar0, bar1;
  68. __uint8_t busnr_primary;
  69. __uint8_t busnr_secondary;
  70. __uint8_t busnr_sub;
  71. __uint8_t second_latency;
  72. __uint8_t io_base, io_limit;
  73. __uint16_t mem_limit;
  74. __uint16_t pre_mem_base;
  75. __uint16_t pre_mem_limit;
  76. /* for 48-bit long-mode */
  77. __uint32_t pre_base_high;
  78. __uint32_t pre_base_limit;
  79. __uint16_t io_high;
  80. __uint16_t io_limit_high;
  81. __uint8_t capabilities;
  82. __uint16_t rsvd0;
  83. __uint8_t rsvd1;
  84. __uint32_t erom_base;
  85. __uint8_t irqnr;
  86. __uint8_t intpin;
  87. __uint16_t bridge_ctl;
  88. } __attribute__ ((packed));
  89. /* pci-cardbus bridge */
  90. struct pci_header2 {
  91. struct pci_header hdr;
  92. __uint32_t cardbus_base;
  93. __uint8_t caplist_offset;
  94. __uint8_t rsvd0;
  95. __uint16_t second_status;
  96. __uint8_t pcibus_nr;
  97. __uint8_t cardbus_nr;
  98. __uint8_t sub_bus_nr;
  99. __uint8_t latency;
  100. __uint32_t mmbase_0;
  101. __uint32_t mmlimit_0;
  102. __uint32_t mmbase_1;
  103. __uint32_t mmlimit_1;
  104. __uint32_t iobase_0;
  105. __uint32_t iolimit_0;
  106. __uint32_t iobase_1;
  107. __uint32_t iolimit_1;
  108. __uint8_t irqnr;
  109. __uint8_t intpin;
  110. __uint16_t bridge_ctl;
  111. __uint16_t subsys_dev;
  112. __uint16_t subsys_vendor;
  113. __uint32_t lagency_base;
  114. } __attribute__ ((packed));
  115. struct pci_device {
  116. __uint16_t devid;
  117. __uint16_t vendor;
  118. char *devname;
  119. /* the device configure word (256 bytes) */
  120. char *config;
  121. errno_t (* dev_init) (struct pci_header0 *);
  122. };
  123. struct pci_vendor_table {
  124. __uint8_t class;
  125. __uint8_t subclass;
  126. errno_t (* dev_init) (struct pci_header0 *);
  127. };
  128. /* pci_header.class-codes */
  129. #define CLASS_UNK 0x00
  130. #define CLASS_DISK 0x01
  131. #define CLASS_NETCTL 0x02
  132. #define CLASS_DISPLAY 0x03
  133. #define CLASS_MEDIACTL 0x04
  134. #define CLASS_MMCTL 0x05
  135. #define CLASS_BRIDGE 0x06
  136. #define CLASS_CMMCTL 0x07
  137. #define CLASS_SYSDEV 0x08
  138. #define CLASS_INPUTDEV 0x09
  139. #define CLASS_DOCK 0x0a
  140. #define CLASS_CPU 0x0b
  141. #define CLASS_SBUS_CTL 0x0c
  142. #define CLASS_WIRELESS 0x0d
  143. #define CLASS_INTCTL 0x0e
  144. #define CLASS_SCMCTL 0x0f
  145. #define CLASS_ENCRY 0x10
  146. #define CLASS_SIGPROC 0x11
  147. #define CLASS_PROCSPD 0x12
  148. #define CLASS_NEACC 0x13
  149. #define CLASS_FPU 0x40
  150. #define CLASS_NOCLASS 0xff
  151. #endif