io.h 9.5 KB

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