io.h 7.8 KB

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