io.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #define X86STEPPING(x) ((x) & 0x0F)
  2. #define X86MODEL(x) (((x)>>4) & 0x0F)
  3. #define X86FAMILY(x) (((x)>>8) & 0x0F)
  4. enum {
  5. VectorNMI = 2, /* non-maskable interrupt */
  6. VectorBPT = 3, /* breakpoint */
  7. VectorUD = 6, /* invalid opcode exception */
  8. VectorCNA = 7, /* coprocessor not available */
  9. VectorCSO = 9, /* coprocessor segment overrun */
  10. VectorPF = 14, /* page fault */
  11. VectorCERR = 16, /* coprocessor error */
  12. VectorPIC = 32, /* external i8259 interrupts */
  13. IrqCLOCK = 0,
  14. IrqKBD = 1,
  15. IrqUART1 = 3,
  16. IrqUART0 = 4,
  17. IrqPCMCIA = 5,
  18. IrqFLOPPY = 6,
  19. IrqLPT = 7,
  20. IrqIRQ7 = 7,
  21. IrqAUX = 12, /* PS/2 port */
  22. IrqIRQ13 = 13, /* coprocessor on 386 */
  23. IrqATA0 = 14,
  24. IrqATA1 = 15,
  25. MaxIrqPIC = 15,
  26. VectorLAPIC = VectorPIC+16, /* local APIC interrupts */
  27. IrqLINT0 = 16, /* LINT[01] must be offsets 0 and 1 */
  28. IrqLINT1 = 17,
  29. IrqTIMER = 18,
  30. IrqERROR = 19,
  31. IrqPCINT = 20,
  32. IrqSPURIOUS = 31, /* must have bits [3-0] == 0x0F */
  33. MaxIrqLAPIC = 31,
  34. VectorSYSCALL = 64,
  35. VectorAPIC = 65, /* external APIC interrupts */
  36. MaxVectorAPIC = 255,
  37. };
  38. typedef struct Vctl {
  39. Vctl* next; /* handlers on this vector */
  40. char name[KNAMELEN]; /* of driver */
  41. int isintr; /* interrupt or fault/trap */
  42. int irq;
  43. int tbdf;
  44. int (*isr)(int); /* get isr bit for this irq */
  45. int (*eoi)(int); /* eoi */
  46. void (*f)(Ureg*, void*); /* handler to call */
  47. void* a; /* argument to call it with */
  48. } Vctl;
  49. enum {
  50. BusCBUS = 0, /* Corollary CBUS */
  51. BusCBUSII, /* Corollary CBUS II */
  52. BusEISA, /* Extended ISA */
  53. BusFUTURE, /* IEEE Futurebus */
  54. BusINTERN, /* Internal bus */
  55. BusISA, /* Industry Standard Architecture */
  56. BusMBI, /* Multibus I */
  57. BusMBII, /* Multibus II */
  58. BusMCA, /* Micro Channel Architecture */
  59. BusMPI, /* MPI */
  60. BusMPSA, /* MPSA */
  61. BusNUBUS, /* Apple Macintosh NuBus */
  62. BusPCI, /* Peripheral Component Interconnect */
  63. BusPCMCIA, /* PC Memory Card International Association */
  64. BusTC, /* DEC TurboChannel */
  65. BusVL, /* VESA Local bus */
  66. BusVME, /* VMEbus */
  67. BusXPRESS, /* Express System Bus */
  68. };
  69. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  70. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  71. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  72. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  73. #define BUSTYPE(tbdf) ((tbdf)>>24)
  74. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  75. #define BUSUNKNOWN (-1)
  76. enum {
  77. MaxEISA = 16,
  78. CfgEISA = 0xC80,
  79. };
  80. /*
  81. * PCI support code.
  82. */
  83. enum { /* type 0 and type 1 pre-defined header */
  84. PciVID = 0x00, /* vendor ID */
  85. PciDID = 0x02, /* device ID */
  86. PciPCR = 0x04, /* command */
  87. PciPSR = 0x06, /* status */
  88. PciRID = 0x08, /* revision ID */
  89. PciCCRp = 0x09, /* programming interface class code */
  90. PciCCRu = 0x0A, /* sub-class code */
  91. PciCCRb = 0x0B, /* base class code */
  92. PciCLS = 0x0C, /* cache line size */
  93. PciLTR = 0x0D, /* latency timer */
  94. PciHDT = 0x0E, /* header type */
  95. PciBST = 0x0F, /* BIST */
  96. PciBAR0 = 0x10, /* base address */
  97. PciBAR1 = 0x14,
  98. PciINTL = 0x3C, /* interrupt line */
  99. PciINTP = 0x3D, /* interrupt pin */
  100. };
  101. enum { /* type 0 pre-defined header */
  102. PciBAR2 = 0x18,
  103. PciBAR3 = 0x1C,
  104. PciBAR4 = 0x20,
  105. PciBAR5 = 0x24,
  106. PciCIS = 0x28, /* cardbus CIS pointer */
  107. PciSVID = 0x2C, /* subsystem vendor ID */
  108. PciSID = 0x2E, /* cardbus CIS pointer */
  109. PciEBAR0 = 0x30, /* expansion ROM base address */
  110. PciMGNT = 0x3E, /* burst period length */
  111. PciMLT = 0x3F, /* maximum latency between bursts */
  112. };
  113. enum { /* type 1 pre-defined header */
  114. PciPBN = 0x18, /* primary bus number */
  115. PciSBN = 0x19, /* secondary bus number */
  116. PciUBN = 0x1A, /* subordinate bus number */
  117. PciSLTR = 0x1B, /* secondary latency timer */
  118. PciIBR = 0x1C, /* I/O base */
  119. PciILR = 0x1D, /* I/O limit */
  120. PciSPSR = 0x1E, /* secondary status */
  121. PciMBR = 0x20, /* memory base */
  122. PciMLR = 0x22, /* memory limit */
  123. PciPMBR = 0x24, /* prefetchable memory base */
  124. PciPMLR = 0x26, /* prefetchable memory limit */
  125. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  126. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  127. PciIUBR = 0x30, /* I/O base upper 16 bits */
  128. PciIULR = 0x32, /* I/O limit upper 16 bits */
  129. PciEBAR1 = 0x28, /* expansion ROM base address */
  130. PciBCR = 0x3E, /* bridge control register */
  131. };
  132. enum { /* type 2 pre-defined header */
  133. PciCBExCA = 0x10,
  134. PciCBSPSR = 0x16,
  135. PciCBPBN = 0x18, /* primary bus number */
  136. PciCBSBN = 0x19, /* secondary bus number */
  137. PciCBUBN = 0x1A, /* subordinate bus number */
  138. PciCBSLTR = 0x1B, /* secondary latency timer */
  139. PciCBMBR0 = 0x1C,
  140. PciCBMLR0 = 0x20,
  141. PciCBMBR1 = 0x24,
  142. PciCBMLR1 = 0x28,
  143. PciCBIBR0 = 0x2C, /* I/O base */
  144. PciCBILR0 = 0x30, /* I/O limit */
  145. PciCBIBR1 = 0x34, /* I/O base */
  146. PciCBILR1 = 0x38, /* I/O limit */
  147. PciCBSVID = 0x40, /* subsystem vendor ID */
  148. PciCBSID = 0x42, /* subsystem ID */
  149. PciCBLMBAR = 0x44, /* legacy mode base address */
  150. };
  151. typedef struct Pcisiz Pcisiz;
  152. struct Pcisiz
  153. {
  154. Pcidev* dev;
  155. int siz;
  156. int bar;
  157. };
  158. typedef struct Pcidev Pcidev;
  159. struct Pcidev
  160. {
  161. int tbdf; /* type+bus+device+function */
  162. ushort vid; /* vendor ID */
  163. ushort did; /* device ID */
  164. uchar rid;
  165. uchar ccrp;
  166. uchar ccru;
  167. uchar ccrb;
  168. struct {
  169. ulong bar; /* base address */
  170. int size;
  171. } mem[6];
  172. struct {
  173. ulong bar;
  174. int size;
  175. } rom;
  176. uchar intl; /* interrupt line */
  177. Pcidev* list;
  178. Pcidev* link; /* next device on this bno */
  179. Pcidev* bridge; /* down a bus */
  180. struct {
  181. ulong bar;
  182. int size;
  183. } ioa, mema;
  184. ulong pcr;
  185. };
  186. #define PCIWINDOW 0
  187. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
  188. #define ISAWINDOW 0
  189. #define ISAWADDR(va) (PADDR(va)+ISAWINDOW)
  190. /* SMBus transactions */
  191. enum
  192. {
  193. SMBquick, /* sends address only */
  194. /* write */
  195. SMBsend, /* sends address and cmd */
  196. SMBbytewrite, /* sends address and cmd and 1 byte */
  197. SMBwordwrite, /* sends address and cmd and 2 bytes */
  198. /* read */
  199. SMBrecv, /* sends address, recvs 1 byte */
  200. SMBbyteread, /* sends address and cmd, recv's byte */
  201. SMBwordread, /* sends address and cmd, recv's 2 bytes */
  202. };
  203. typedef struct SMBus SMBus;
  204. struct SMBus {
  205. QLock; /* mutex */
  206. Rendez r; /* rendezvous point for completion interrupts */
  207. void *arg; /* implementation dependent */
  208. ulong base; /* port or memory base of smbus */
  209. int busy;
  210. void (*transact)(SMBus*, int, int, int, uchar*);
  211. };
  212. /*
  213. * PCMCIA support code.
  214. */
  215. typedef struct PCMslot PCMslot;
  216. typedef struct PCMconftab PCMconftab;
  217. /*
  218. * Map between ISA memory space and PCMCIA card memory space.
  219. */
  220. struct PCMmap {
  221. ulong ca; /* card address */
  222. ulong cea; /* card end address */
  223. ulong isa; /* ISA address */
  224. int len; /* length of the ISA area */
  225. int attr; /* attribute memory */
  226. int ref;
  227. };
  228. /* configuration table entry */
  229. struct PCMconftab
  230. {
  231. int index;
  232. ushort irqs; /* legal irqs */
  233. uchar irqtype;
  234. uchar bit16; /* true for 16 bit access */
  235. struct {
  236. ulong start;
  237. ulong len;
  238. } io[16];
  239. int nio;
  240. uchar vpp1;
  241. uchar vpp2;
  242. uchar memwait;
  243. ulong maxwait;
  244. ulong readywait;
  245. ulong otherwait;
  246. };
  247. /* a card slot */
  248. struct PCMslot
  249. {
  250. Lock;
  251. int ref;
  252. void *cp; /* controller for this slot */
  253. long memlen; /* memory length */
  254. uchar base; /* index register base */
  255. uchar slotno; /* slot number */
  256. /* status */
  257. uchar special; /* in use for a special device */
  258. uchar already; /* already inited */
  259. uchar occupied;
  260. uchar battery;
  261. uchar wrprot;
  262. uchar powered;
  263. uchar configed;
  264. uchar enabled;
  265. uchar busy;
  266. /* cis info */
  267. ulong msec; /* time of last slotinfo call */
  268. char verstr[512]; /* version string */
  269. uchar cpresent; /* config registers present */
  270. ulong caddr; /* relative address of config registers */
  271. int nctab; /* number of config table entries */
  272. PCMconftab ctab[8];
  273. PCMconftab *def; /* default conftab */
  274. /* memory maps */
  275. Lock mlock; /* lock down the maps */
  276. int time;
  277. PCMmap mmap[4]; /* maps, last is always for the kernel */
  278. };