io.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 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. BusLAPIC, /* Local APIC, fake type */
  101. BusIPI, /* IPIs, fake type like the LAPIC */
  102. };
  103. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  104. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  105. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  106. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  107. #define BUSTYPE(tbdf) ((tbdf)>>24)
  108. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  109. #define BUSUNKNOWN MKBUS(BusISA, 0xff, 0xff, 0xff)
  110. enum {
  111. MaxEISA = 16,
  112. CfgEISA = 0xC80,
  113. };
  114. /*
  115. * PCI support code.
  116. */
  117. enum { /* type 0 and type 1 pre-defined header */
  118. PciVID = 0x00, /* vendor ID */
  119. PciDID = 0x02, /* device ID */
  120. PciPCR = 0x04, /* command */
  121. PciPSR = 0x06, /* status */
  122. PciRID = 0x08, /* revision ID */
  123. PciCCRp = 0x09, /* programming interface class code */
  124. PciCCRu = 0x0A, /* sub-class code */
  125. PciCCRb = 0x0B, /* base class code */
  126. PciCLS = 0x0C, /* cache line size */
  127. PciLTR = 0x0D, /* latency timer */
  128. PciHDT = 0x0E, /* header type */
  129. PciBST = 0x0F, /* BIST */
  130. PciBAR0 = 0x10, /* base address */
  131. PciBAR1 = 0x14,
  132. PciCP = 0x34, /* capabilities pointer */
  133. PciINTL = 0x3C, /* interrupt line */
  134. PciINTP = 0x3D, /* interrupt pin */
  135. };
  136. /* ccrb (base class code) values; controller types */
  137. enum {
  138. Pcibcpci1 = 0, /* pci 1.0; no class codes defined */
  139. Pcibcstore = 1, /* mass storage */
  140. Pcibcnet = 2, /* network */
  141. Pcibcdisp = 3, /* display */
  142. Pcibcmmedia = 4, /* multimedia */
  143. Pcibcmem = 5, /* memory */
  144. Pcibcbridge = 6, /* bridge */
  145. Pcibccomm = 7, /* simple comms (e.g., serial) */
  146. Pcibcbasesys = 8, /* base system */
  147. Pcibcinput = 9, /* input */
  148. Pcibcdock = 0xa, /* docking stations */
  149. Pcibcproc = 0xb, /* processors */
  150. Pcibcserial = 0xc, /* serial bus (e.g., USB) */
  151. Pcibcwireless = 0xd, /* wireless */
  152. Pcibcintell = 0xe, /* intelligent i/o */
  153. Pcibcsatcom = 0xf, /* satellite comms */
  154. Pcibccrypto = 0x10, /* encryption/decryption */
  155. Pcibcdacq = 0x11, /* data acquisition & signal proc. */
  156. };
  157. /* ccru (sub-class code) values; common cases only */
  158. enum {
  159. /* mass storage */
  160. Pciscscsi = 0, /* SCSI */
  161. Pciscide = 1, /* IDE (ATA) */
  162. Pciscsata = 6, /* SATA */
  163. /* network */
  164. Pciscether = 0, /* Ethernet */
  165. /* display */
  166. Pciscvga = 0, /* VGA */
  167. Pciscxga = 1, /* XGA */
  168. Pcisc3d = 2, /* 3D */
  169. /* bridges */
  170. Pcischostpci = 0, /* host/pci */
  171. Pciscpcicpci = 1, /* pci/pci */
  172. /* simple comms */
  173. Pciscserial = 0, /* 16450, etc. */
  174. Pciscmultiser = 1, /* multiport serial */
  175. /* serial bus */
  176. Pciscusb = 3, /* USB */
  177. };
  178. enum { /* type 0 pre-defined header */
  179. PciCIS = 0x28, /* cardbus CIS pointer */
  180. PciSVID = 0x2C, /* subsystem vendor ID */
  181. PciSID = 0x2E, /* cardbus CIS pointer */
  182. PciEBAR0 = 0x30, /* expansion ROM base address */
  183. PciMGNT = 0x3E, /* burst period length */
  184. PciMLT = 0x3F, /* maximum latency between bursts */
  185. };
  186. enum { /* type 1 pre-defined header */
  187. PciPBN = 0x18, /* primary bus number */
  188. PciSBN = 0x19, /* secondary bus number */
  189. PciUBN = 0x1A, /* subordinate bus number */
  190. PciSLTR = 0x1B, /* secondary latency timer */
  191. PciIBR = 0x1C, /* I/O base */
  192. PciILR = 0x1D, /* I/O limit */
  193. PciSPSR = 0x1E, /* secondary status */
  194. PciMBR = 0x20, /* memory base */
  195. PciMLR = 0x22, /* memory limit */
  196. PciPMBR = 0x24, /* prefetchable memory base */
  197. PciPMLR = 0x26, /* prefetchable memory limit */
  198. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  199. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  200. PciIUBR = 0x30, /* I/O base upper 16 bits */
  201. PciIULR = 0x32, /* I/O limit upper 16 bits */
  202. PciEBAR1 = 0x28, /* expansion ROM base address */
  203. PciBCR = 0x3E, /* bridge control register */
  204. };
  205. enum { /* type 2 pre-defined header */
  206. PciCBExCA = 0x10,
  207. PciCBSPSR = 0x16,
  208. PciCBPBN = 0x18, /* primary bus number */
  209. PciCBSBN = 0x19, /* secondary bus number */
  210. PciCBUBN = 0x1A, /* subordinate bus number */
  211. PciCBSLTR = 0x1B, /* secondary latency timer */
  212. PciCBMBR0 = 0x1C,
  213. PciCBMLR0 = 0x20,
  214. PciCBMBR1 = 0x24,
  215. PciCBMLR1 = 0x28,
  216. PciCBIBR0 = 0x2C, /* I/O base */
  217. PciCBILR0 = 0x30, /* I/O limit */
  218. PciCBIBR1 = 0x34, /* I/O base */
  219. PciCBILR1 = 0x38, /* I/O limit */
  220. PciCBSVID = 0x40, /* subsystem vendor ID */
  221. PciCBSID = 0x42, /* subsystem ID */
  222. PciCBLMBAR = 0x44, /* legacy mode base address */
  223. };
  224. /* capabilities */
  225. enum {
  226. PciCapPMG = 0x01, /* power management */
  227. PciCapAGP = 0x02,
  228. PciCapVPD = 0x03, /* vital product data */
  229. PciCapSID = 0x04, /* slot id */
  230. PciCapMSI = 0x05,
  231. PciCapCHS = 0x06, /* compact pci hot swap */
  232. PciCapPCIX = 0x07,
  233. PciCapHTC = 0x08, /* hypertransport irq conf */
  234. PciCapVND = 0x09, /* vendor specific information */
  235. PciCapPCIe = 0x10,
  236. PciCapMSIX = 0x11,
  237. PciCapSATA = 0x12,
  238. PciCapHSW = 0x0c, /* hot swap */
  239. };
  240. typedef struct Pcisiz Pcisiz;
  241. struct Pcisiz
  242. {
  243. Pcidev* dev;
  244. int siz;
  245. int bar;
  246. };
  247. /* Definitions for generic PCI capability structure based on the
  248. * VIRTIO spec 1.0. Below is the layout of a capability in the PCI
  249. * device config space. The structure visible to the kernel repeats this,
  250. * but adds fields to build the linked list of capabilities per device.
  251. *
  252. * struct virtio_pci_cap {
  253. * u8 cap_vndr; // Generic PCI field: PCI_CAP_ID_VNDR
  254. * u8 cap_next; // Generic PCI field: next ptr.
  255. * u8 cap_len; // Generic PCI field: capability length
  256. * u8 cfg_type; // Identifies the structure.
  257. * u8 bar; // Where to find it.
  258. * u8 padding[3]; // Pad to full dword.
  259. * le32 offset; // Offset within bar.
  260. * le32 length; // Length of the structure, in bytes.
  261. * };
  262. */
  263. enum {
  264. PciCapVndr = 0x00,
  265. PciCapNext = 0x01,
  266. PciCapLen = 0x02,
  267. PciCapType = 0x03,
  268. PciCapBar = 0x04,
  269. PciCapOff = 0x08,
  270. PciCapLength = 0x0C
  271. };
  272. struct Pcidev;
  273. typedef struct Pcicap Pcicap;
  274. struct Pcicap {
  275. struct Pcidev *dev; /* link to the device structure */
  276. Pcicap *link; /* next capability or NULL */
  277. uint8_t vndr; /* vendor code */
  278. uint8_t caplen; /* length in the config area */
  279. uint8_t type; /* capability config type */
  280. uint8_t bar; /* BAR index in the device structure 0 - 5 */
  281. uint32_t offset; /* offset within BAR */
  282. uint32_t length; /* length in the memory or IO space */
  283. };
  284. /* Linked list of capabilities is added to the PCI device descriptor
  285. * structure. Also, an index array of pointers to the capabilities
  286. * descriptiors is added. The index will be used to simplify generation
  287. * of the capabilities directory in devpci.c.
  288. */
  289. typedef struct Pcidev Pcidev;
  290. struct Pcidev
  291. {
  292. int tbdf; /* type+bus+device+function */
  293. uint16_t vid; /* vendor ID */
  294. uint16_t did; /* device ID */
  295. uint16_t pcr;
  296. unsigned char rid;
  297. unsigned char ccrp;
  298. unsigned char ccru;
  299. unsigned char ccrb;
  300. unsigned char cls;
  301. unsigned char ltr;
  302. struct {
  303. uint32_t bar; /* base address */
  304. int size;
  305. } mem[6];
  306. struct {
  307. uint32_t bar;
  308. int size;
  309. } rom;
  310. unsigned char intl; /* interrupt line */
  311. unsigned char intp; /* interrupt pin */
  312. Pcidev* list;
  313. Pcidev* link; /* next device on this bno */
  314. Pcidev* bridge; /* down a bus */
  315. struct {
  316. uint32_t bar;
  317. int size;
  318. } ioa, mema;
  319. Pcicap *caplist;
  320. uint32_t capcnt;
  321. Pcicap **capidx;
  322. };
  323. #define PCIWINDOW 0
  324. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
  325. #define ISAWINDOW 0
  326. #define ISAWADDR(va) (PADDR(va)+ISAWINDOW)