]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/teg2/io.h
devarch: restrict i/o port access to 64K, disallow msr 32-bit wrap arround (thanks...
[plan9front.git] / sys / src / 9 / teg2 / io.h
1 #pragma varargck        type    "T"     int
2 #pragma varargck        type    "T"     uint
3
4 /*
5  * PCI
6  */
7
8 enum {
9         BusCBUS         = 0,            /* Corollary CBUS */
10         BusCBUSII,                      /* Corollary CBUS II */
11         BusEISA,                        /* Extended ISA */
12         BusFUTURE,                      /* IEEE Futurebus */
13         BusINTERN,                      /* Internal bus */
14         BusISA,                         /* Industry Standard Architecture */
15         BusMBI,                         /* Multibus I */
16         BusMBII,                        /* Multibus II */
17         BusMCA,                         /* Micro Channel Architecture */
18         BusMPI,                         /* MPI */
19         BusMPSA,                        /* MPSA */
20         BusNUBUS,                       /* Apple Macintosh NuBus */
21         BusPCI,                         /* Peripheral Component Interconnect */
22         BusPCMCIA,                      /* PC Memory Card International Association */
23         BusTC,                          /* DEC TurboChannel */
24         BusVL,                          /* VESA Local bus */
25         BusVME,                         /* VMEbus */
26         BusXPRESS,                      /* Express System Bus */
27 };
28
29 #define MKBUS(t,b,d,f)  (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
30 #define BUSFNO(tbdf)    (((tbdf)>>8)&0x07)
31 #define BUSDNO(tbdf)    (((tbdf)>>11)&0x1F)
32 #define BUSBNO(tbdf)    (((tbdf)>>16)&0xFF)
33 #define BUSTYPE(tbdf)   ((tbdf)>>24)
34 #define BUSBDF(tbdf)    ((tbdf)&0x00FFFF00)
35 #define BUSUNKNOWN      (-1)
36
37 enum {                                  /* type 0 & type 1 pre-defined header */
38         PciVID          = 0x00,         /* vendor ID */
39         PciDID          = 0x02,         /* device ID */
40         PciPCR          = 0x04,         /* command */
41         PciPSR          = 0x06,         /* status */
42         PciRID          = 0x08,         /* revision ID */
43         PciCCRp         = 0x09,         /* programming interface class code */
44         PciCCRu         = 0x0A,         /* sub-class code */
45         PciCCRb         = 0x0B,         /* base class code */
46         PciCLS          = 0x0C,         /* cache line size */
47         PciLTR          = 0x0D,         /* latency timer */
48         PciHDT          = 0x0E,         /* header type */
49         PciBST          = 0x0F,         /* BIST */
50
51         PciBAR0         = 0x10,         /* base address */
52         PciBAR1         = 0x14,
53
54         PciINTL         = 0x3C,         /* interrupt line */
55         PciINTP         = 0x3D,         /* interrupt pin */
56 };
57
58 /* ccrb (base class code) values; controller types */
59 enum {
60         Pcibcpci1       = 0,            /* pci 1.0; no class codes defined */
61         Pcibcstore      = 1,            /* mass storage */
62         Pcibcnet        = 2,            /* network */
63         Pcibcdisp       = 3,            /* display */
64         Pcibcmmedia     = 4,            /* multimedia */
65         Pcibcmem        = 5,            /* memory */
66         Pcibcbridge     = 6,            /* bridge */
67         Pcibccomm       = 7,            /* simple comms (e.g., serial) */
68         Pcibcbasesys    = 8,            /* base system */
69         Pcibcinput      = 9,            /* input */
70         Pcibcdock       = 0xa,          /* docking stations */
71         Pcibcproc       = 0xb,          /* processors */
72         Pcibcserial     = 0xc,          /* serial bus (e.g., USB) */
73         Pcibcwireless   = 0xd,          /* wireless */
74         Pcibcintell     = 0xe,          /* intelligent i/o */
75         Pcibcsatcom     = 0xf,          /* satellite comms */
76         Pcibccrypto     = 0x10,         /* encryption/decryption */
77         Pcibcdacq       = 0x11,         /* data acquisition & signal proc. */
78 };
79
80 /* ccru (sub-class code) values; common cases only */
81 enum {
82         /* mass storage */
83         Pciscscsi       = 0,            /* SCSI */
84         Pciscide        = 1,            /* IDE (ATA) */
85         Pciscsata       = 6,            /* SATA */
86
87         /* network */
88         Pciscether      = 0,            /* Ethernet */
89
90         /* display */
91         Pciscvga        = 0,            /* VGA */
92         Pciscxga        = 1,            /* XGA */
93         Pcisc3d         = 2,            /* 3D */
94
95         /* bridges */
96         Pcischostpci    = 0,            /* host/pci */
97         Pciscpcicpci    = 1,            /* pci/pci */
98
99         /* simple comms */
100         Pciscserial     = 0,            /* 16450, etc. */
101         Pciscmultiser   = 1,            /* multiport serial */
102
103         /* serial bus */
104         Pciscusb        = 3,            /* USB */
105 };
106
107 enum {                                  /* type 0 pre-defined header */
108         PciCIS          = 0x28,         /* cardbus CIS pointer */
109         PciSVID         = 0x2C,         /* subsystem vendor ID */
110         PciSID          = 0x2E,         /* subsystem ID */
111         PciEBAR0        = 0x30,         /* expansion ROM base address */
112         PciMGNT         = 0x3E,         /* burst period length */
113         PciMLT          = 0x3F,         /* maximum latency between bursts */
114 };
115
116 enum {                                  /* type 1 pre-defined header */
117         PciPBN          = 0x18,         /* primary bus number */
118         PciSBN          = 0x19,         /* secondary bus number */
119         PciUBN          = 0x1A,         /* subordinate bus number */
120         PciSLTR         = 0x1B,         /* secondary latency timer */
121         PciIBR          = 0x1C,         /* I/O base */
122         PciILR          = 0x1D,         /* I/O limit */
123         PciSPSR         = 0x1E,         /* secondary status */
124         PciMBR          = 0x20,         /* memory base */
125         PciMLR          = 0x22,         /* memory limit */
126         PciPMBR         = 0x24,         /* prefetchable memory base */
127         PciPMLR         = 0x26,         /* prefetchable memory limit */
128         PciPUBR         = 0x28,         /* prefetchable base upper 32 bits */
129         PciPULR         = 0x2C,         /* prefetchable limit upper 32 bits */
130         PciIUBR         = 0x30,         /* I/O base upper 16 bits */
131         PciIULR         = 0x32,         /* I/O limit upper 16 bits */
132         PciEBAR1        = 0x28,         /* expansion ROM base address */
133         PciBCR          = 0x3E,         /* bridge control register */
134 };
135
136 enum {                                  /* type 2 pre-defined header */
137         PciCBExCA       = 0x10,
138         PciCBSPSR       = 0x16,
139         PciCBPBN        = 0x18,         /* primary bus number */
140         PciCBSBN        = 0x19,         /* secondary bus number */
141         PciCBUBN        = 0x1A,         /* subordinate bus number */
142         PciCBSLTR       = 0x1B,         /* secondary latency timer */
143         PciCBMBR0       = 0x1C,
144         PciCBMLR0       = 0x20,
145         PciCBMBR1       = 0x24,
146         PciCBMLR1       = 0x28,
147         PciCBIBR0       = 0x2C,         /* I/O base */
148         PciCBILR0       = 0x30,         /* I/O limit */
149         PciCBIBR1       = 0x34,         /* I/O base */
150         PciCBILR1       = 0x38,         /* I/O limit */
151         PciCBSVID       = 0x40,         /* subsystem vendor ID */
152         PciCBSID        = 0x42,         /* subsystem ID */
153         PciCBLMBAR      = 0x44,         /* legacy mode base address */
154 };
155
156 enum {
157         /* bar bits */
158         Barioaddr       = 1<<0,         /* vs. memory addr */
159         Barwidthshift   = 1,
160         Barwidthmask    = MASK(2),
161         Barwidth32      = 0,
162         Barwidth64      = 2,
163         Barprefetch     = 1<<3,
164 };
165
166 struct Pcisiz
167 {
168         Pcidev* dev;
169         int     siz;
170         int     bar;
171 };
172
173 struct Pcidev
174 {
175         int     tbdf;                   /* type+bus+device+function */
176         ushort  vid;                    /* vendor ID */
177         ushort  did;                    /* device ID */
178
179         ushort  pcr;
180
181         uchar   rid;
182         uchar   ccrp;
183         uchar   ccru;
184         uchar   ccrb;
185         uchar   cls;
186         uchar   ltr;
187
188         struct {
189                 ulong   bar;            /* base address */
190                 int     size;
191         } mem[6];
192
193         struct {
194                 ulong   bar;    
195                 int     size;
196         } rom;
197         uchar   intl;                   /* interrupt line */
198
199         Pcidev* list;
200         Pcidev* link;                   /* next device on this bno */
201
202         Pcidev* bridge;                 /* down a bus */
203
204         int     pmrb;                   /* power management register block */
205 };
206
207 enum {
208         /* vendor ids */
209         Vatiamd = 0x1002,
210         Vintel  = 0x8086,
211         Vjmicron= 0x197b,
212         Vmarvell= 0x1b4b,
213         Vmyricom= 0x14c1,
214         Vnvidia = 0x10de,
215         Vrealtek= 0x10ec,
216 };
217
218 #define PCIWINDOW       0
219 #define PCIWADDR(va)    (PADDR(va)+PCIWINDOW)