io.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. enum {
  10. VectorNMI = 2, /* non-maskable interrupt */
  11. VectorBPT = 3, /* breakpoint */
  12. VectorUD = 6, /* invalid opcode exception */
  13. VectorCNA = 7, /* coprocessor not available */
  14. Vector2F = 8, /* double fault */
  15. VectorCSO = 9, /* coprocessor segment overrun */
  16. VectorPF = 14, /* page fault */
  17. Vector15 = 15, /* reserved */
  18. VectorCERR = 16, /* coprocessor error */
  19. VectorPIC = 32, /* external i8259 interrupts */
  20. IrqCLOCK = 0,
  21. IrqKBD = 1,
  22. IrqUART1 = 3,
  23. IrqUART0 = 4,
  24. IrqPCMCIA = 5,
  25. IrqFLOPPY = 6,
  26. IrqLPT = 7,
  27. IrqIRQ7 = 7,
  28. IrqAUX = 12, /* PS/2 port */
  29. IrqIRQ13 = 13, /* coprocessor on 386 */
  30. IrqATA0 = 14,
  31. IrqATA1 = 15,
  32. MaxIrqPIC = 15,
  33. VectorLAPIC = VectorPIC+16, /* local APIC interrupts */
  34. IrqLINT0 = VectorLAPIC+0,
  35. IrqLINT1 = VectorLAPIC+1,
  36. IrqTIMER = VectorLAPIC+2,
  37. IrqERROR = VectorLAPIC+3,
  38. IrqPCINT = VectorLAPIC+4,
  39. IrqSPURIOUS = VectorLAPIC+15,
  40. MaxIrqLAPIC = VectorLAPIC+15,
  41. VectorSYSCALL = 64,
  42. VectorAPIC = 65, /* external APIC interrupts */
  43. MaxVectorAPIC = 255,
  44. };
  45. enum {
  46. IdtPIC = 32, /* external i8259 interrupts */
  47. IdtLINT0 = 48, /* local APIC interrupts */
  48. IdtLINT1 = 49,
  49. IdtTIMER = 50,
  50. IdtERROR = 51,
  51. IdtPCINT = 52,
  52. IdtIPI = 62,
  53. IdtSPURIOUS = 63,
  54. IdtSYSCALL = 64,
  55. IdtIOAPIC = 65, /* external APIC interrupts */
  56. IdtMAX = 255,
  57. };
  58. typedef struct Vkey {
  59. int tbdf; /* pci: ioapic or msi sources */
  60. int irq; /* 8259-emulating sources */
  61. } Vkey;
  62. typedef struct Vctl {
  63. Vctl* next; /* handlers on this vector */
  64. int isintr; /* interrupt or fault/trap */
  65. Vkey; /* source-specific key; tbdf for pci */
  66. void (*f)(Ureg*, void*); /* handler to call */
  67. void* a; /* argument to call it with */
  68. char name[KNAMELEN]; /* of driver */
  69. char *type;
  70. int (*isr)(int); /* get isr bit for this irq */
  71. int (*eoi)(int); /* eoi */
  72. int (*mask)(Vkey*, int); /* interrupt enable returns masked vector */
  73. int vno;
  74. } Vctl;
  75. typedef struct ACVctl {
  76. char* (*f)(Ureg*,void*);
  77. void* a;
  78. int vno;
  79. char name[KNAMELEN]; /* of driver */
  80. } ACVctl;
  81. enum {
  82. BusCBUS = 0, /* Corollary CBUS */
  83. BusCBUSII, /* Corollary CBUS II */
  84. BusEISA, /* Extended ISA */
  85. BusFUTURE, /* IEEE Futurebus */
  86. BusINTERN, /* Internal bus */
  87. BusISA, /* Industry Standard Architecture */
  88. BusMBI, /* Multibus I */
  89. BusMBII, /* Multibus II */
  90. BusMCA, /* Micro Channel Architecture */
  91. BusMPI, /* MPI */
  92. BusMPSA, /* MPSA */
  93. BusNUBUS, /* Apple Macintosh NuBus */
  94. BusPCI, /* Peripheral Component Interconnect */
  95. BusPCMCIA, /* PC Memory Card International Association */
  96. BusTC, /* DEC TurboChannel */
  97. BusVL, /* VESA Local bus */
  98. BusVME, /* VMEbus */
  99. BusXPRESS, /* Express System Bus */
  100. };
  101. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  102. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  103. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  104. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  105. #define BUSTYPE(tbdf) ((tbdf)>>24)
  106. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  107. #define BUSUNKNOWN (-1)
  108. enum {
  109. MaxEISA = 16,
  110. CfgEISA = 0xC80,
  111. };
  112. /*
  113. * PCI support code.
  114. */
  115. enum { /* type 0 and type 1 pre-defined header */
  116. PciVID = 0x00, /* vendor ID */
  117. PciDID = 0x02, /* device ID */
  118. PciPCR = 0x04, /* command */
  119. PciPSR = 0x06, /* status */
  120. PciRID = 0x08, /* revision ID */
  121. PciCCRp = 0x09, /* programming interface class code */
  122. PciCCRu = 0x0A, /* sub-class code */
  123. PciCCRb = 0x0B, /* base class code */
  124. PciCLS = 0x0C, /* cache line size */
  125. PciLTR = 0x0D, /* latency timer */
  126. PciHDT = 0x0E, /* header type */
  127. PciBST = 0x0F, /* BIST */
  128. PciBAR0 = 0x10, /* base address */
  129. PciBAR1 = 0x14,
  130. PciCP = 0x34, /* capabilities pointer */
  131. PciINTL = 0x3C, /* interrupt line */
  132. PciINTP = 0x3D, /* interrupt pin */
  133. };
  134. /* ccrb (base class code) values; controller types */
  135. enum {
  136. Pcibcpci1 = 0, /* pci 1.0; no class codes defined */
  137. Pcibcstore = 1, /* mass storage */
  138. Pcibcnet = 2, /* network */
  139. Pcibcdisp = 3, /* display */
  140. Pcibcmmedia = 4, /* multimedia */
  141. Pcibcmem = 5, /* memory */
  142. Pcibcbridge = 6, /* bridge */
  143. Pcibccomm = 7, /* simple comms (e.g., serial) */
  144. Pcibcbasesys = 8, /* base system */
  145. Pcibcinput = 9, /* input */
  146. Pcibcdock = 0xa, /* docking stations */
  147. Pcibcproc = 0xb, /* processors */
  148. Pcibcserial = 0xc, /* serial bus (e.g., USB) */
  149. Pcibcwireless = 0xd, /* wireless */
  150. Pcibcintell = 0xe, /* intelligent i/o */
  151. Pcibcsatcom = 0xf, /* satellite comms */
  152. Pcibccrypto = 0x10, /* encryption/decryption */
  153. Pcibcdacq = 0x11, /* data acquisition & signal proc. */
  154. };
  155. /* ccru (sub-class code) values; common cases only */
  156. enum {
  157. /* mass storage */
  158. Pciscscsi = 0, /* SCSI */
  159. Pciscide = 1, /* IDE (ATA) */
  160. Pciscsata = 6, /* SATA */
  161. /* network */
  162. Pciscether = 0, /* Ethernet */
  163. /* display */
  164. Pciscvga = 0, /* VGA */
  165. Pciscxga = 1, /* XGA */
  166. Pcisc3d = 2, /* 3D */
  167. /* bridges */
  168. Pcischostpci = 0, /* host/pci */
  169. Pciscpcicpci = 1, /* pci/pci */
  170. /* simple comms */
  171. Pciscserial = 0, /* 16450, etc. */
  172. Pciscmultiser = 1, /* multiport serial */
  173. /* serial bus */
  174. Pciscusb = 3, /* USB */
  175. };
  176. enum { /* type 0 pre-defined header */
  177. PciCIS = 0x28, /* cardbus CIS pointer */
  178. PciSVID = 0x2C, /* subsystem vendor ID */
  179. PciSID = 0x2E, /* cardbus CIS pointer */
  180. PciEBAR0 = 0x30, /* expansion ROM base address */
  181. PciMGNT = 0x3E, /* burst period length */
  182. PciMLT = 0x3F, /* maximum latency between bursts */
  183. };
  184. enum { /* type 1 pre-defined header */
  185. PciPBN = 0x18, /* primary bus number */
  186. PciSBN = 0x19, /* secondary bus number */
  187. PciUBN = 0x1A, /* subordinate bus number */
  188. PciSLTR = 0x1B, /* secondary latency timer */
  189. PciIBR = 0x1C, /* I/O base */
  190. PciILR = 0x1D, /* I/O limit */
  191. PciSPSR = 0x1E, /* secondary status */
  192. PciMBR = 0x20, /* memory base */
  193. PciMLR = 0x22, /* memory limit */
  194. PciPMBR = 0x24, /* prefetchable memory base */
  195. PciPMLR = 0x26, /* prefetchable memory limit */
  196. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  197. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  198. PciIUBR = 0x30, /* I/O base upper 16 bits */
  199. PciIULR = 0x32, /* I/O limit upper 16 bits */
  200. PciEBAR1 = 0x28, /* expansion ROM base address */
  201. PciBCR = 0x3E, /* bridge control register */
  202. };
  203. enum { /* type 2 pre-defined header */
  204. PciCBExCA = 0x10,
  205. PciCBSPSR = 0x16,
  206. PciCBPBN = 0x18, /* primary bus number */
  207. PciCBSBN = 0x19, /* secondary bus number */
  208. PciCBUBN = 0x1A, /* subordinate bus number */
  209. PciCBSLTR = 0x1B, /* secondary latency timer */
  210. PciCBMBR0 = 0x1C,
  211. PciCBMLR0 = 0x20,
  212. PciCBMBR1 = 0x24,
  213. PciCBMLR1 = 0x28,
  214. PciCBIBR0 = 0x2C, /* I/O base */
  215. PciCBILR0 = 0x30, /* I/O limit */
  216. PciCBIBR1 = 0x34, /* I/O base */
  217. PciCBILR1 = 0x38, /* I/O limit */
  218. PciCBSVID = 0x40, /* subsystem vendor ID */
  219. PciCBSID = 0x42, /* subsystem ID */
  220. PciCBLMBAR = 0x44, /* legacy mode base address */
  221. };
  222. /* capabilities */
  223. enum {
  224. PciCapPMG = 0x01, /* power management */
  225. PciCapAGP = 0x02,
  226. PciCapVPD = 0x03, /* vital product data */
  227. PciCapSID = 0x04, /* slot id */
  228. PciCapMSI = 0x05,
  229. PciCapCHS = 0x06, /* compact pci hot swap */
  230. PciCapPCIX = 0x07,
  231. PciCapHTC = 0x08, /* hypertransport irq conf */
  232. PciCapVND = 0x09, /* vendor specific information */
  233. PciCapPCIe = 0x10,
  234. PciCapMSIX = 0x11,
  235. PciCapSATA = 0x12,
  236. PciCapHSW = 0x0c, /* hot swap */
  237. };
  238. typedef struct Pcisiz Pcisiz;
  239. struct Pcisiz
  240. {
  241. Pcidev* dev;
  242. int siz;
  243. int bar;
  244. };
  245. typedef struct Pcidev Pcidev;
  246. struct Pcidev
  247. {
  248. int tbdf; /* type+bus+device+function */
  249. uint16_t vid; /* vendor ID */
  250. uint16_t did; /* device ID */
  251. uint16_t pcr;
  252. unsigned char rid;
  253. unsigned char ccrp;
  254. unsigned char ccru;
  255. unsigned char ccrb;
  256. unsigned char cls;
  257. unsigned char ltr;
  258. struct {
  259. uint32_t bar; /* base address */
  260. int size;
  261. } mem[6];
  262. struct {
  263. uint32_t bar;
  264. int size;
  265. } rom;
  266. unsigned char intl; /* interrupt line */
  267. Pcidev* list;
  268. Pcidev* link; /* next device on this bno */
  269. Pcidev* bridge; /* down a bus */
  270. struct {
  271. uint32_t bar;
  272. int size;
  273. } ioa, mema;
  274. };
  275. #define PCIWINDOW 0
  276. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
  277. #define ISAWINDOW 0
  278. #define ISAWADDR(va) (PADDR(va)+ISAWINDOW)
  279. #pragma varargck type "T" int