io.h 4.8 KB

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