io.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. Vector15 = 15, /* reserved */
  13. VectorCERR = 16, /* coprocessor error */
  14. VectorPIC = 32, /* external i8259 interrupts */
  15. IrqCLOCK = 0,
  16. IrqKBD = 1,
  17. IrqUART1 = 3,
  18. IrqUART0 = 4,
  19. IrqPCMCIA = 5,
  20. IrqFLOPPY = 6,
  21. IrqLPT = 7,
  22. IrqIRQ7 = 7,
  23. IrqAUX = 12, /* PS/2 port */
  24. IrqIRQ13 = 13, /* coprocessor on 386 */
  25. IrqATA0 = 14,
  26. IrqATA1 = 15,
  27. MaxIrqPIC = 15,
  28. VectorLAPIC = VectorPIC+16, /* local APIC interrupts */
  29. IrqLINT0 = 16, /* LINT[01] must be offsets 0 and 1 */
  30. IrqLINT1 = 17,
  31. IrqTIMER = 18,
  32. IrqERROR = 19,
  33. IrqPCINT = 20,
  34. IrqSPURIOUS = 31, /* must have bits [3-0] == 0x0F */
  35. MaxIrqLAPIC = 31,
  36. VectorSYSCALL = 64,
  37. VectorAPIC = 65, /* external APIC interrupts */
  38. MaxVectorAPIC = 255,
  39. };
  40. typedef struct Vctl {
  41. Vctl* next; /* handlers on this vector */
  42. char name[KNAMELEN]; /* of driver */
  43. int isintr; /* interrupt or fault/trap */
  44. int irq;
  45. int tbdf;
  46. int (*isr)(int); /* get isr bit for this irq */
  47. int (*eoi)(int); /* eoi */
  48. void (*f)(Ureg*, void*); /* handler to call */
  49. void* a; /* argument to call it with */
  50. } Vctl;
  51. enum {
  52. BusCBUS = 0, /* Corollary CBUS */
  53. BusCBUSII, /* Corollary CBUS II */
  54. BusEISA, /* Extended ISA */
  55. BusFUTURE, /* IEEE Futurebus */
  56. BusINTERN, /* Internal bus */
  57. BusISA, /* Industry Standard Architecture */
  58. BusMBI, /* Multibus I */
  59. BusMBII, /* Multibus II */
  60. BusMCA, /* Micro Channel Architecture */
  61. BusMPI, /* MPI */
  62. BusMPSA, /* MPSA */
  63. BusNUBUS, /* Apple Macintosh NuBus */
  64. BusPCI, /* Peripheral Component Interconnect */
  65. BusPCMCIA, /* PC Memory Card International Association */
  66. BusTC, /* DEC TurboChannel */
  67. BusVL, /* VESA Local bus */
  68. BusVME, /* VMEbus */
  69. BusXPRESS, /* Express System Bus */
  70. };
  71. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  72. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  73. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  74. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  75. #define BUSTYPE(tbdf) ((tbdf)>>24)
  76. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  77. #define BUSUNKNOWN (-1)
  78. enum {
  79. MaxEISA = 16,
  80. CfgEISA = 0xC80,
  81. };
  82. /*
  83. * PCI support code.
  84. */
  85. enum { /* type 0 and type 1 pre-defined header */
  86. PciVID = 0x00, /* vendor ID */
  87. PciDID = 0x02, /* device ID */
  88. PciPCR = 0x04, /* command */
  89. PciPSR = 0x06, /* status */
  90. PciRID = 0x08, /* revision ID */
  91. PciCCRp = 0x09, /* programming interface class code */
  92. PciCCRu = 0x0A, /* sub-class code */
  93. PciCCRb = 0x0B, /* base class code */
  94. PciCLS = 0x0C, /* cache line size */
  95. PciLTR = 0x0D, /* latency timer */
  96. PciHDT = 0x0E, /* header type */
  97. PciBST = 0x0F, /* BIST */
  98. PciBAR0 = 0x10, /* base address */
  99. PciBAR1 = 0x14,
  100. PciINTL = 0x3C, /* interrupt line */
  101. PciINTP = 0x3D, /* interrupt pin */
  102. };
  103. enum { /* type 0 pre-defined header */
  104. PciCIS = 0x28, /* cardbus CIS pointer */
  105. PciSVID = 0x2C, /* subsystem vendor ID */
  106. PciSID = 0x2E, /* cardbus CIS pointer */
  107. PciEBAR0 = 0x30, /* expansion ROM base address */
  108. PciMGNT = 0x3E, /* burst period length */
  109. PciMLT = 0x3F, /* maximum latency between bursts */
  110. };
  111. enum { /* type 1 pre-defined header */
  112. PciPBN = 0x18, /* primary bus number */
  113. PciSBN = 0x19, /* secondary bus number */
  114. PciUBN = 0x1A, /* subordinate bus number */
  115. PciSLTR = 0x1B, /* secondary latency timer */
  116. PciIBR = 0x1C, /* I/O base */
  117. PciILR = 0x1D, /* I/O limit */
  118. PciSPSR = 0x1E, /* secondary status */
  119. PciMBR = 0x20, /* memory base */
  120. PciMLR = 0x22, /* memory limit */
  121. PciPMBR = 0x24, /* prefetchable memory base */
  122. PciPMLR = 0x26, /* prefetchable memory limit */
  123. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  124. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  125. PciIUBR = 0x30, /* I/O base upper 16 bits */
  126. PciIULR = 0x32, /* I/O limit upper 16 bits */
  127. PciEBAR1 = 0x28, /* expansion ROM base address */
  128. PciBCR = 0x3E, /* bridge control register */
  129. };
  130. enum { /* type 2 pre-defined header */
  131. PciCBExCA = 0x10,
  132. PciCBSPSR = 0x16,
  133. PciCBPBN = 0x18, /* primary bus number */
  134. PciCBSBN = 0x19, /* secondary bus number */
  135. PciCBUBN = 0x1A, /* subordinate bus number */
  136. PciCBSLTR = 0x1B, /* secondary latency timer */
  137. PciCBMBR0 = 0x1C,
  138. PciCBMLR0 = 0x20,
  139. PciCBMBR1 = 0x24,
  140. PciCBMLR1 = 0x28,
  141. PciCBIBR0 = 0x2C, /* I/O base */
  142. PciCBILR0 = 0x30, /* I/O limit */
  143. PciCBIBR1 = 0x34, /* I/O base */
  144. PciCBILR1 = 0x38, /* I/O limit */
  145. PciCBSVID = 0x40, /* subsystem vendor ID */
  146. PciCBSID = 0x42, /* subsystem ID */
  147. PciCBLMBAR = 0x44, /* legacy mode base address */
  148. };
  149. typedef struct Pcisiz Pcisiz;
  150. struct Pcisiz
  151. {
  152. Pcidev* dev;
  153. int siz;
  154. int bar;
  155. };
  156. typedef struct Pcidev Pcidev;
  157. struct Pcidev
  158. {
  159. int tbdf; /* type+bus+device+function */
  160. ushort vid; /* vendor ID */
  161. ushort did; /* device ID */
  162. ushort pcr;
  163. uchar rid;
  164. uchar ccrp;
  165. uchar ccru;
  166. uchar ccrb;
  167. uchar cls;
  168. uchar ltr;
  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. int pmrb; /* power management register block */
  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. int ncfg; /* number of configurations */
  271. struct {
  272. ushort cpresent; /* config registers present */
  273. ulong caddr; /* relative address of config registers */
  274. } cfg[8];
  275. int nctab; /* number of config table entries */
  276. PCMconftab ctab[8];
  277. PCMconftab *def; /* default conftab */
  278. /* memory maps */
  279. Lock mlock; /* lock down the maps */
  280. int time;
  281. PCMmap mmap[4]; /* maps, last is always for the kernel */
  282. };