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