io.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. PciCIS = 0x28, /* cardbus CIS pointer */
  84. PciSVID = 0x2C, /* subsystem vendor ID */
  85. PciSID = 0x2E, /* cardbus CIS pointer */
  86. PciEBAR0 = 0x30, /* expansion ROM base address */
  87. PciMGNT = 0x3E, /* burst period length */
  88. PciMLT = 0x3F, /* maximum latency between bursts */
  89. };
  90. enum { /* type 1 pre-defined header */
  91. PciPBN = 0x18, /* primary bus number */
  92. PciSBN = 0x19, /* secondary bus number */
  93. PciUBN = 0x1A, /* subordinate bus number */
  94. PciSLTR = 0x1B, /* secondary latency timer */
  95. PciIBR = 0x1C, /* I/O base */
  96. PciILR = 0x1D, /* I/O limit */
  97. PciSPSR = 0x1E, /* secondary status */
  98. PciMBR = 0x20, /* memory base */
  99. PciMLR = 0x22, /* memory limit */
  100. PciPMBR = 0x24, /* prefetchable memory base */
  101. PciPMLR = 0x26, /* prefetchable memory limit */
  102. PciPUBR = 0x28, /* prefetchable base upper 32 bits */
  103. PciPULR = 0x2C, /* prefetchable limit upper 32 bits */
  104. PciIUBR = 0x30, /* I/O base upper 16 bits */
  105. PciIULR = 0x32, /* I/O limit upper 16 bits */
  106. PciEBAR1 = 0x28, /* expansion ROM base address */
  107. PciBCR = 0x3E, /* bridge control register */
  108. };
  109. enum { /* type 2 pre-defined header */
  110. PciCBExCA = 0x10,
  111. PciCBSPSR = 0x16,
  112. PciCBPBN = 0x18, /* primary bus number */
  113. PciCBSBN = 0x19, /* secondary bus number */
  114. PciCBUBN = 0x1A, /* subordinate bus number */
  115. PciCBSLTR = 0x1B, /* secondary latency timer */
  116. PciCBMBR0 = 0x1C,
  117. PciCBMLR0 = 0x20,
  118. PciCBMBR1 = 0x24,
  119. PciCBMLR1 = 0x28,
  120. PciCBIBR0 = 0x2C, /* I/O base */
  121. PciCBILR0 = 0x30, /* I/O limit */
  122. PciCBIBR1 = 0x34, /* I/O base */
  123. PciCBILR1 = 0x38, /* I/O limit */
  124. PciCBSVID = 0x40, /* subsystem vendor ID */
  125. PciCBSID = 0x42, /* subsystem ID */
  126. PciCBLMBAR = 0x44, /* legacy mode base address */
  127. };
  128. typedef struct Pcisiz Pcisiz;
  129. struct Pcisiz
  130. {
  131. Pcidev* dev;
  132. int siz;
  133. int bar;
  134. };
  135. typedef struct Pcidev Pcidev;
  136. typedef struct Pcidev {
  137. int tbdf; /* type+bus+device+function */
  138. ushort vid; /* vendor ID */
  139. ushort did; /* device ID */
  140. uchar rid;
  141. uchar ccrp;
  142. uchar ccru;
  143. uchar ccrb;
  144. struct {
  145. ulong bar; /* base address */
  146. int size;
  147. } mem[6];
  148. uchar intl; /* interrupt line */
  149. Pcidev* list;
  150. Pcidev* link; /* next device on this bno */
  151. Pcidev* bridge; /* down a bus */
  152. struct {
  153. ulong bar;
  154. int size;
  155. } ioa, mema;
  156. ulong pcr;
  157. };
  158. #define PCIWINDOW 0x80000000
  159. #define PCIWADDR(va) (PADDR(va)+PCIWINDOW)