io.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * programmable interrupt vectors (for the 8259's)
  3. */
  4. enum
  5. {
  6. Bptvec= 3, /* breakpoints */
  7. Mathemuvec= 7, /* math coprocessor emulation interrupt */
  8. Mathovervec= 9, /* math coprocessor overrun interrupt */
  9. Matherr1vec= 16, /* math coprocessor error interrupt */
  10. Faultvec= 14, /* page fault */
  11. Syscallvec= 64,
  12. VectorPIC = 24, /* external [A]PIC interrupts */
  13. VectorCLOCK = VectorPIC+0,
  14. VectorKBD = VectorPIC+1,
  15. VectorUART1 = VectorPIC+3,
  16. VectorUART0 = VectorPIC+4,
  17. VectorPCMCIA = VectorPIC+5,
  18. VectorFLOPPY = VectorPIC+6,
  19. VectorLPT = VectorPIC+7,
  20. VectorIRQ7 = VectorPIC+7,
  21. VectorAUX = VectorPIC+12, /* PS/2 port */
  22. VectorIRQ13 = VectorPIC+13, /* coprocessor on x386 */
  23. VectorATA0 = VectorPIC+14,
  24. VectorATA1 = VectorPIC+15,
  25. MaxVectorPIC = VectorPIC+15,
  26. };
  27. enum {
  28. BusCBUS = 0, /* Corollary CBUS */
  29. BusCBUSII, /* Corollary CBUS II */
  30. BusEISA, /* Extended ISA */
  31. BusFUTURE, /* IEEE Futurebus */
  32. BusINTERN, /* Internal bus */
  33. BusISA, /* Industry Standard Architecture */
  34. BusMBI, /* Multibus I */
  35. BusMBII, /* Multibus II */
  36. BusMCA, /* Micro Channel Architecture */
  37. BusMPI, /* MPI */
  38. BusMPSA, /* MPSA */
  39. BusNUBUS, /* Apple Macintosh NuBus */
  40. BusPCI, /* Peripheral Component Interconnect */
  41. BusPCMCIA, /* PC Memory Card International Association */
  42. BusTC, /* DEC TurboChannel */
  43. BusVL, /* VESA Local bus */
  44. BusVME, /* VMEbus */
  45. BusXPRESS, /* Express System Bus */
  46. };
  47. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  48. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  49. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  50. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  51. #define BUSTYPE(tbdf) ((tbdf)>>24)
  52. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  53. #define BUSUNKNOWN (-1)
  54. enum {
  55. MaxEISA = 16,
  56. CfgEISA = 0xC80,
  57. };
  58. /*
  59. * PCI support code.
  60. */
  61. enum { /* type 0 and type 1 pre-defined header */
  62. PciVID = 0x00, /* vendor ID */
  63. PciDID = 0x02, /* device ID */
  64. PciPCR = 0x04, /* command */
  65. PciPSR = 0x06, /* status */
  66. PciRID = 0x08, /* revision ID */
  67. PciCCRp = 0x09, /* programming interface class code */
  68. PciCCRu = 0x0A, /* sub-class code */
  69. PciCCRb = 0x0B, /* base class code */
  70. PciCLS = 0x0C, /* cache line size */
  71. PciLTR = 0x0D, /* latency timer */
  72. PciHDT = 0x0E, /* header type */
  73. PciBST = 0x0F, /* BIST */
  74. PciBAR0 = 0x10, /* base address */
  75. PciBAR1 = 0x14,
  76. PciINTL = 0x3C, /* interrupt line */
  77. PciINTP = 0x3D, /* interrupt pin */
  78. };
  79. /* ccrb (base class code) values; controller types */
  80. enum {
  81. Pcibcpci1 = 0, /* pci 1.0; no class codes defined */
  82. Pcibcstore = 1, /* mass storage */
  83. Pcibcnet = 2, /* network */
  84. Pcibcdisp = 3, /* display */
  85. Pcibcmmedia = 4, /* multimedia */
  86. Pcibcmem = 5, /* memory */
  87. Pcibcbridge = 6, /* bridge */
  88. Pcibccomm = 7, /* simple comms (e.g., serial) */
  89. Pcibcbasesys = 8, /* base system */
  90. Pcibcinput = 9, /* input */
  91. Pcibcdock = 0xa, /* docking stations */
  92. Pcibcproc = 0xb, /* processors */
  93. Pcibcserial = 0xc, /* serial bus (e.g., USB) */
  94. Pcibcwireless = 0xd, /* wireless */
  95. Pcibcintell = 0xe, /* intelligent i/o */
  96. Pcibcsatcom = 0xf, /* satellite comms */
  97. Pcibccrypto = 0x10, /* encryption/decryption */
  98. Pcibcdacq = 0x11, /* data acquisition & signal proc. */
  99. };
  100. /* ccru (sub-class code) values; common cases only */
  101. enum {
  102. /* mass storage */
  103. Pciscscsi = 0, /* SCSI */
  104. Pciscide = 1, /* IDE (ATA) */
  105. /* network */
  106. Pciscether = 0, /* Ethernet */
  107. /* display */
  108. Pciscvga = 0, /* VGA */
  109. Pciscxga = 1, /* XGA */
  110. Pcisc3d = 2, /* 3D */
  111. /* bridges */
  112. Pcischostpci = 0, /* host/pci */
  113. Pciscpcicpci = 1, /* pci/pci */
  114. /* simple comms */
  115. Pciscserial = 0, /* 16450, etc. */
  116. Pciscmultiser = 1, /* multiport serial */
  117. /* serial bus */
  118. Pciscusb = 3, /* USB */
  119. };
  120. enum { /* type 0 pre-defined header */
  121. PciBAR2 = 0x18,
  122. PciBAR3 = 0x1C,
  123. PciBAR4 = 0x20,
  124. PciBAR5 = 0x24,
  125. PciCIS = 0x28, /* cardbus CIS pointer */
  126. PciSVID = 0x2C, /* subsystem vendor ID */
  127. PciSID = 0x2E, /* cardbus CIS pointer */
  128. PciEBAR0 = 0x30, /* expansion ROM base address */
  129. PciMGNT = 0x3E, /* burst period length */
  130. PciMLT = 0x3F, /* maximum latency between bursts */
  131. };
  132. enum { /* type 1 pre-defined header */
  133. PciPBN = 0x18, /* primary bus number */
  134. PciSBN = 0x19, /* secondary bus number */
  135. PciUBN = 0x1A, /* subordinate bus number */
  136. PciSLTR = 0x1B, /* secondary latency timer */
  137. PciIBR = 0x1C, /* I/O base */
  138. PciILR = 0x1D, /* I/O limit */
  139. PciSPSR = 0x1E, /* secondary status */
  140. PciMBR = 0x20, /* memory base */
  141. PciMLR = 0x22, /* memory limit */
  142. PciPMBR = 0x24, /* prefetchable memory base */
  143. PciPMLR = 0x26, /* prefetchable memory limit */
  144. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  145. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  146. PciIUBR = 0x30, /* I/O base upper 16 bits */
  147. PciIULR = 0x32, /* I/O limit upper 16 bits */
  148. PciEBAR1 = 0x28, /* expansion ROM base address */
  149. PciBCR = 0x3E, /* bridge control register */
  150. };
  151. enum { /* type 2 pre-defined header */
  152. PciCBExCA = 0x10,
  153. PciCBSPSR = 0x16,
  154. PciCBPBN = 0x18, /* primary bus number */
  155. PciCBSBN = 0x19, /* secondary bus number */
  156. PciCBUBN = 0x1A, /* subordinate bus number */
  157. PciCBSLTR = 0x1B, /* secondary latency timer */
  158. PciCBMBR0 = 0x1C,
  159. PciCBMLR0 = 0x20,
  160. PciCBMBR1 = 0x24,
  161. PciCBMLR1 = 0x28,
  162. PciCBIBR0 = 0x2C, /* I/O base */
  163. PciCBILR0 = 0x30, /* I/O limit */
  164. PciCBIBR1 = 0x34, /* I/O base */
  165. PciCBILR1 = 0x38, /* I/O limit */
  166. PciCBBCTL = 0x3E, /* Bridge control */
  167. PciCBSVID = 0x40, /* subsystem vendor ID */
  168. PciCBSID = 0x42, /* subsystem ID */
  169. PciCBLMBAR = 0x44, /* legacy mode base address */
  170. };
  171. typedef struct Pcisiz Pcisiz;
  172. struct Pcisiz
  173. {
  174. Pcidev* dev;
  175. int siz;
  176. int bar;
  177. };
  178. typedef struct Pcidev Pcidev;
  179. typedef struct Pcidev {
  180. int tbdf; /* type+bus+device+function */
  181. ushort vid; /* vendor ID */
  182. ushort did; /* device ID */
  183. ushort pcr;
  184. uchar rid;
  185. uchar ccrp;
  186. uchar ccru;
  187. uchar ccrb;
  188. uchar cls;
  189. uchar ltr;
  190. struct {
  191. ulong bar; /* base address */
  192. int size;
  193. } mem[6];
  194. struct {
  195. ulong bar;
  196. int size;
  197. } rom;
  198. uchar intl; /* interrupt line */
  199. Pcidev* list;
  200. Pcidev* link; /* next device on this bno */
  201. Pcidev* bridge; /* down a bus */
  202. struct {
  203. ulong bar;
  204. int size;
  205. } ioa, mema;
  206. int pmrb; /* power management register block */
  207. };
  208. #define PCIWINDOW 0
  209. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
  210. #define ISAWINDOW 0
  211. #define ISAWADDR(va) (PADDR(va)+ISAWINDOW)
  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. int ncfg; /* number of configurations */
  270. struct {
  271. ushort cpresent; /* config registers present */
  272. ulong caddr; /* relative address of config registers */
  273. } cfg[8];
  274. int nctab; /* number of config table entries */
  275. PCMconftab ctab[8];
  276. PCMconftab *def; /* default conftab */
  277. /* memory maps */
  278. Lock mlock; /* lock down the maps */
  279. int time;
  280. PCMmap mmap[4]; /* maps, last is always for the kernel */
  281. };