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