]> Git Repo - linux.git/blob - arch/mips/pci/ops-bridge.c
netlink: make validation more configurable for future strictness
[linux.git] / arch / mips / pci / ops-bridge.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1999, 2000, 04, 06 Ralf Baechle ([email protected])
7  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8  */
9 #include <linux/pci.h>
10 #include <asm/paccess.h>
11 #include <asm/pci/bridge.h>
12 #include <asm/sn/arch.h>
13 #include <asm/sn/intr.h>
14 #include <asm/sn/sn0/hub.h>
15
16 /*
17  * Most of the IOC3 PCI config register aren't present
18  * we emulate what is needed for a normal PCI enumeration
19  */
20 static u32 emulate_ioc3_cfg(int where, int size)
21 {
22         if (size == 1 && where == 0x3d)
23                 return 0x01;
24         else if (size == 2 && where == 0x3c)
25                 return 0x0100;
26         else if (size == 4 && where == 0x3c)
27                 return 0x00000100;
28
29         return 0;
30 }
31
32 /*
33  * The Bridge ASIC supports both type 0 and type 1 access.  Type 1 is
34  * not really documented, so right now I can't write code which uses it.
35  * Therefore we use type 0 accesses for now even though they won't work
36  * correctly for PCI-to-PCI bridges.
37  *
38  * The function is complicated by the ultimate brokenness of the IOC3 chip
39  * which is used in SGI systems.  The IOC3 can only handle 32-bit PCI
40  * accesses and does only decode parts of it's address space.
41  */
42
43 static int pci_conf0_read_config(struct pci_bus *bus, unsigned int devfn,
44                                  int where, int size, u32 * value)
45 {
46         struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
47         struct bridge_regs *bridge = bc->base;
48         int slot = PCI_SLOT(devfn);
49         int fn = PCI_FUNC(devfn);
50         volatile void *addr;
51         u32 cf, shift, mask;
52         int res;
53
54         addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID];
55         if (get_dbe(cf, (u32 *) addr))
56                 return PCIBIOS_DEVICE_NOT_FOUND;
57
58         /*
59          * IOC3 is broken beyond belief ...  Don't even give the
60          * generic PCI code a chance to look at it for real ...
61          */
62         if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
63                 goto is_ioc3;
64
65         addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)];
66
67         if (size == 1)
68                 res = get_dbe(*value, (u8 *) addr);
69         else if (size == 2)
70                 res = get_dbe(*value, (u16 *) addr);
71         else
72                 res = get_dbe(*value, (u32 *) addr);
73
74         return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
75
76 is_ioc3:
77
78         /*
79          * IOC3 special handling
80          */
81         if ((where >= 0x14 && where < 0x40) || (where >= 0x48)) {
82                 *value = emulate_ioc3_cfg(where, size);
83                 return PCIBIOS_SUCCESSFUL;
84         }
85
86         addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
87
88         if (get_dbe(cf, (u32 *) addr))
89                 return PCIBIOS_DEVICE_NOT_FOUND;
90
91         shift = ((where & 3) << 3);
92         mask = (0xffffffffU >> ((4 - size) << 3));
93         *value = (cf >> shift) & mask;
94
95         return PCIBIOS_SUCCESSFUL;
96 }
97
98 static int pci_conf1_read_config(struct pci_bus *bus, unsigned int devfn,
99                                  int where, int size, u32 * value)
100 {
101         struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
102         struct bridge_regs *bridge = bc->base;
103         int busno = bus->number;
104         int slot = PCI_SLOT(devfn);
105         int fn = PCI_FUNC(devfn);
106         volatile void *addr;
107         u32 cf, shift, mask;
108         int res;
109
110         bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11));
111         addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID];
112         if (get_dbe(cf, (u32 *) addr))
113                 return PCIBIOS_DEVICE_NOT_FOUND;
114
115         /*
116          * IOC3 is broken beyond belief ...  Don't even give the
117          * generic PCI code a chance to look at it for real ...
118          */
119         if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
120                 goto is_ioc3;
121
122         bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11));
123         addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))];
124
125         if (size == 1)
126                 res = get_dbe(*value, (u8 *) addr);
127         else if (size == 2)
128                 res = get_dbe(*value, (u16 *) addr);
129         else
130                 res = get_dbe(*value, (u32 *) addr);
131
132         return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
133
134 is_ioc3:
135
136         /*
137          * IOC3 special handling
138          */
139         if ((where >= 0x14 && where < 0x40) || (where >= 0x48)) {
140                 *value = emulate_ioc3_cfg(where, size);
141                 return PCIBIOS_SUCCESSFUL;
142         }
143
144         bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11));
145         addr = &bridge->b_type1_cfg.c[(fn << 8) | where];
146
147         if (get_dbe(cf, (u32 *) addr))
148                 return PCIBIOS_DEVICE_NOT_FOUND;
149
150         shift = ((where & 3) << 3);
151         mask = (0xffffffffU >> ((4 - size) << 3));
152         *value = (cf >> shift) & mask;
153
154         return PCIBIOS_SUCCESSFUL;
155 }
156
157 static int pci_read_config(struct pci_bus *bus, unsigned int devfn,
158                            int where, int size, u32 * value)
159 {
160         if (!pci_is_root_bus(bus))
161                 return pci_conf1_read_config(bus, devfn, where, size, value);
162
163         return pci_conf0_read_config(bus, devfn, where, size, value);
164 }
165
166 static int pci_conf0_write_config(struct pci_bus *bus, unsigned int devfn,
167                                   int where, int size, u32 value)
168 {
169         struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
170         struct bridge_regs *bridge = bc->base;
171         int slot = PCI_SLOT(devfn);
172         int fn = PCI_FUNC(devfn);
173         volatile void *addr;
174         u32 cf, shift, mask, smask;
175         int res;
176
177         addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID];
178         if (get_dbe(cf, (u32 *) addr))
179                 return PCIBIOS_DEVICE_NOT_FOUND;
180
181         /*
182          * IOC3 is broken beyond belief ...  Don't even give the
183          * generic PCI code a chance to look at it for real ...
184          */
185         if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
186                 goto is_ioc3;
187
188         addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)];
189
190         if (size == 1) {
191                 res = put_dbe(value, (u8 *) addr);
192         } else if (size == 2) {
193                 res = put_dbe(value, (u16 *) addr);
194         } else {
195                 res = put_dbe(value, (u32 *) addr);
196         }
197
198         if (res)
199                 return PCIBIOS_DEVICE_NOT_FOUND;
200
201         return PCIBIOS_SUCCESSFUL;
202
203 is_ioc3:
204
205         /*
206          * IOC3 special handling
207          */
208         if ((where >= 0x14 && where < 0x40) || (where >= 0x48))
209                 return PCIBIOS_SUCCESSFUL;
210
211         addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
212
213         if (get_dbe(cf, (u32 *) addr))
214                 return PCIBIOS_DEVICE_NOT_FOUND;
215
216         shift = ((where & 3) << 3);
217         mask = (0xffffffffU >> ((4 - size) << 3));
218         smask = mask << shift;
219
220         cf = (cf & ~smask) | ((value & mask) << shift);
221         if (put_dbe(cf, (u32 *) addr))
222                 return PCIBIOS_DEVICE_NOT_FOUND;
223
224         return PCIBIOS_SUCCESSFUL;
225 }
226
227 static int pci_conf1_write_config(struct pci_bus *bus, unsigned int devfn,
228                                   int where, int size, u32 value)
229 {
230         struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
231         struct bridge_regs *bridge = bc->base;
232         int slot = PCI_SLOT(devfn);
233         int fn = PCI_FUNC(devfn);
234         int busno = bus->number;
235         volatile void *addr;
236         u32 cf, shift, mask, smask;
237         int res;
238
239         bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11));
240         addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID];
241         if (get_dbe(cf, (u32 *) addr))
242                 return PCIBIOS_DEVICE_NOT_FOUND;
243
244         /*
245          * IOC3 is broken beyond belief ...  Don't even give the
246          * generic PCI code a chance to look at it for real ...
247          */
248         if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
249                 goto is_ioc3;
250
251         addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))];
252
253         if (size == 1) {
254                 res = put_dbe(value, (u8 *) addr);
255         } else if (size == 2) {
256                 res = put_dbe(value, (u16 *) addr);
257         } else {
258                 res = put_dbe(value, (u32 *) addr);
259         }
260
261         if (res)
262                 return PCIBIOS_DEVICE_NOT_FOUND;
263
264         return PCIBIOS_SUCCESSFUL;
265
266 is_ioc3:
267
268         /*
269          * IOC3 special handling
270          */
271         if ((where >= 0x14 && where < 0x40) || (where >= 0x48))
272                 return PCIBIOS_SUCCESSFUL;
273
274         addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
275
276         if (get_dbe(cf, (u32 *) addr))
277                 return PCIBIOS_DEVICE_NOT_FOUND;
278
279         shift = ((where & 3) << 3);
280         mask = (0xffffffffU >> ((4 - size) << 3));
281         smask = mask << shift;
282
283         cf = (cf & ~smask) | ((value & mask) << shift);
284         if (put_dbe(cf, (u32 *) addr))
285                 return PCIBIOS_DEVICE_NOT_FOUND;
286
287         return PCIBIOS_SUCCESSFUL;
288 }
289
290 static int pci_write_config(struct pci_bus *bus, unsigned int devfn,
291         int where, int size, u32 value)
292 {
293         if (!pci_is_root_bus(bus))
294                 return pci_conf1_write_config(bus, devfn, where, size, value);
295
296         return pci_conf0_write_config(bus, devfn, where, size, value);
297 }
298
299 struct pci_ops bridge_pci_ops = {
300         .read   = pci_read_config,
301         .write  = pci_write_config,
302 };
This page took 0.047028 seconds and 4 git commands to generate.