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