io.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. /*
  10. * programmable interrupt vectors (for the 8259's)
  11. */
  12. enum
  13. {
  14. Bptvec= 3, /* breakpoints */
  15. Mathemuvec= 7, /* math coprocessor emulation interrupt */
  16. Mathovervec= 9, /* math coprocessor overrun interrupt */
  17. Matherr1vec= 16, /* math coprocessor error interrupt */
  18. Faultvec= 14, /* page fault */
  19. Syscallvec= 64,
  20. VectorPIC = 24, /* external [A]PIC interrupts */
  21. VectorCLOCK = VectorPIC+0,
  22. VectorKBD = VectorPIC+1,
  23. VectorUART1 = VectorPIC+3,
  24. VectorUART0 = VectorPIC+4,
  25. VectorPCMCIA = VectorPIC+5,
  26. VectorFLOPPY = VectorPIC+6,
  27. VectorLPT = VectorPIC+7,
  28. VectorIRQ7 = VectorPIC+7,
  29. VectorAUX = VectorPIC+12, /* PS/2 port */
  30. VectorIRQ13 = VectorPIC+13, /* coprocessor on x386 */
  31. VectorATA0 = VectorPIC+14,
  32. VectorATA1 = VectorPIC+15,
  33. MaxVectorPIC = VectorPIC+15,
  34. };
  35. enum {
  36. BusCBUS = 0, /* Corollary CBUS */
  37. BusCBUSII, /* Corollary CBUS II */
  38. BusEISA, /* Extended ISA */
  39. BusFUTURE, /* IEEE Futurebus */
  40. BusINTERN, /* Internal bus */
  41. BusISA, /* Industry Standard Architecture */
  42. BusMBI, /* Multibus I */
  43. BusMBII, /* Multibus II */
  44. BusMCA, /* Micro Channel Architecture */
  45. BusMPI, /* MPI */
  46. BusMPSA, /* MPSA */
  47. BusNUBUS, /* Apple Macintosh NuBus */
  48. BusPCI, /* Peripheral Component Interconnect */
  49. BusPCMCIA, /* PC Memory Card International Association */
  50. BusTC, /* DEC TurboChannel */
  51. BusVL, /* VESA Local bus */
  52. BusVME, /* VMEbus */
  53. BusXPRESS, /* Express System Bus */
  54. };
  55. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  56. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  57. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  58. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  59. #define BUSTYPE(tbdf) ((tbdf)>>24)
  60. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  61. #define BUSUNKNOWN (-1)
  62. enum {
  63. MaxEISA = 16,
  64. CfgEISA = 0xC80,
  65. };
  66. /*
  67. * PCI support code.
  68. */
  69. enum { /* type 0 and type 1 pre-defined header */
  70. PciVID = 0x00, /* vendor ID */
  71. PciDID = 0x02, /* device ID */
  72. PciPCR = 0x04, /* command */
  73. PciPSR = 0x06, /* status */
  74. PciRID = 0x08, /* revision ID */
  75. PciCCRp = 0x09, /* programming interface class code */
  76. PciCCRu = 0x0A, /* sub-class code */
  77. PciCCRb = 0x0B, /* base class code */
  78. PciCLS = 0x0C, /* cache line size */
  79. PciLTR = 0x0D, /* latency timer */
  80. PciHDT = 0x0E, /* header type */
  81. PciBST = 0x0F, /* BIST */
  82. PciBAR0 = 0x10, /* base address */
  83. PciBAR1 = 0x14,
  84. PciINTL = 0x3C, /* interrupt line */
  85. PciINTP = 0x3D, /* interrupt pin */
  86. };
  87. enum { /* type 0 pre-defined header */
  88. PciBAR2 = 0x18,
  89. PciBAR3 = 0x1C,
  90. PciBAR4 = 0x20,
  91. PciBAR5 = 0x24,
  92. PciCIS = 0x28, /* cardbus CIS pointer */
  93. PciSVID = 0x2C, /* subsystem vendor ID */
  94. PciSID = 0x2E, /* cardbus CIS pointer */
  95. PciEBAR0 = 0x30, /* expansion ROM base address */
  96. PciMGNT = 0x3E, /* burst period length */
  97. PciMLT = 0x3F, /* maximum latency between bursts */
  98. };
  99. enum { /* type 1 pre-defined header */
  100. PciPBN = 0x18, /* primary bus number */
  101. PciSBN = 0x19, /* secondary bus number */
  102. PciUBN = 0x1A, /* subordinate bus number */
  103. PciSLTR = 0x1B, /* secondary latency timer */
  104. PciIBR = 0x1C, /* I/O base */
  105. PciILR = 0x1D, /* I/O limit */
  106. PciSPSR = 0x1E, /* secondary status */
  107. PciMBR = 0x20, /* memory base */
  108. PciMLR = 0x22, /* memory limit */
  109. PciPMBR = 0x24, /* prefetchable memory base */
  110. PciPMLR = 0x26, /* prefetchable memory limit */
  111. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  112. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  113. PciIUBR = 0x30, /* I/O base upper 16 bits */
  114. PciIULR = 0x32, /* I/O limit upper 16 bits */
  115. PciEBAR1 = 0x28, /* expansion ROM base address */
  116. PciBCR = 0x3E, /* bridge control register */
  117. };
  118. enum { /* type 2 pre-defined header */
  119. PciCBExCA = 0x10,
  120. PciCBSPSR = 0x16,
  121. PciCBPBN = 0x18, /* primary bus number */
  122. PciCBSBN = 0x19, /* secondary bus number */
  123. PciCBUBN = 0x1A, /* subordinate bus number */
  124. PciCBSLTR = 0x1B, /* secondary latency timer */
  125. PciCBMBR0 = 0x1C,
  126. PciCBMLR0 = 0x20,
  127. PciCBMBR1 = 0x24,
  128. PciCBMLR1 = 0x28,
  129. PciCBIBR0 = 0x2C, /* I/O base */
  130. PciCBILR0 = 0x30, /* I/O limit */
  131. PciCBIBR1 = 0x34, /* I/O base */
  132. PciCBILR1 = 0x38, /* I/O limit */
  133. PciCBBCTL = 0x3E, /* Bridge control */
  134. PciCBSVID = 0x40, /* subsystem vendor ID */
  135. PciCBSID = 0x42, /* subsystem ID */
  136. PciCBLMBAR = 0x44, /* legacy mode base address */
  137. };
  138. typedef struct Pcisiz Pcisiz;
  139. struct Pcisiz
  140. {
  141. Pcidev* dev;
  142. int siz;
  143. int bar;
  144. };
  145. typedef struct Pcidev Pcidev;
  146. typedef struct Pcidev {
  147. int tbdf; /* type+bus+device+function */
  148. ushort vid; /* vendor ID */
  149. ushort did; /* device ID */
  150. ushort pcr;
  151. uchar rid;
  152. uchar ccrp;
  153. uchar ccru;
  154. uchar ccrb;
  155. uchar cls;
  156. uchar ltr;
  157. struct {
  158. uint32_t bar; /* base address */
  159. int size;
  160. } mem[6];
  161. struct {
  162. uint32_t bar;
  163. int size;
  164. } rom;
  165. uchar intl; /* interrupt line */
  166. uchar intp; /* interrupt pin */
  167. Pcidev* list;
  168. Pcidev* link; /* next device on this bno */
  169. Pcidev* bridge; /* down a bus */
  170. struct {
  171. uint32_t bar;
  172. int size;
  173. } ioa, mema;
  174. int pmrb; /* power management register block */
  175. };
  176. #define PCIWINDOW 0
  177. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
  178. #define ISAWINDOW 0
  179. #define ISAWADDR(va) (PADDR(va)+ISAWINDOW)
  180. /*
  181. * PCMCIA support code.
  182. */
  183. typedef struct PCMslot PCMslot;
  184. typedef struct PCMconftab PCMconftab;
  185. /*
  186. * Map between ISA memory space and PCMCIA card memory space.
  187. */
  188. struct PCMmap {
  189. uint32_t ca; /* card address */
  190. uint32_t cea; /* card end address */
  191. uint32_t isa; /* ISA address */
  192. int len; /* length of the ISA area */
  193. int attr; /* attribute memory */
  194. int ref;
  195. };
  196. /* configuration table entry */
  197. struct PCMconftab
  198. {
  199. int index;
  200. ushort irqs; /* legal irqs */
  201. uchar irqtype;
  202. uchar bit16; /* true for 16 bit access */
  203. struct {
  204. uint32_t start;
  205. uint32_t len;
  206. } io[16];
  207. int nio;
  208. uchar vpp1;
  209. uchar vpp2;
  210. uchar memwait;
  211. uint32_t maxwait;
  212. uint32_t readywait;
  213. uint32_t otherwait;
  214. };
  215. /* a card slot */
  216. struct PCMslot
  217. {
  218. Lock;
  219. int ref;
  220. void *cp; /* controller for this slot */
  221. long memlen; /* memory length */
  222. uchar base; /* index register base */
  223. uchar slotno; /* slot number */
  224. /* status */
  225. uchar special; /* in use for a special device */
  226. uchar already; /* already inited */
  227. uchar occupied;
  228. uchar battery;
  229. uchar wrprot;
  230. uchar powered;
  231. uchar configed;
  232. uchar enabled;
  233. uchar busy;
  234. /* cis info */
  235. ulong msec; /* time of last slotinfo call */
  236. char verstr[512]; /* version string */
  237. int ncfg; /* number of configurations */
  238. struct {
  239. ushort cpresent; /* config registers present */
  240. ulong caddr; /* relative address of config registers */
  241. } cfg[8];
  242. int nctab; /* number of config table entries */
  243. PCMconftab ctab[8];
  244. PCMconftab *def; /* default conftab */
  245. /* memory maps */
  246. Lock mlock; /* lock down the maps */
  247. int time;
  248. PCMmap mmap[4]; /* maps, last is always for the kernel */
  249. };