9 #include <linux/types.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
21 static int postprocess_read(
u32 data,
int where,
unsigned int size)
28 ret = (data >> ((where & 3) << 3)) & 0xff;
31 ret = (data >> ((where & 3) << 3)) & 0xffff;
40 static int preprocess_write(
u32 orig_data,
u32 val,
int where,
48 ret = (orig_data & ~(0xff << ((where & 3) << 3))) |
49 (val << ((where & 3) << 3));
52 ret = (orig_data & ~(0xffff << ((where & 3) << 3))) |
53 (val << ((where & 3) << 3));
65 static int bcm63xx_setup_cfg_access(
int type,
unsigned int busn,
66 unsigned int devfn,
int where)
101 static int bcm63xx_do_cfg_read(
int type,
unsigned int busn,
102 unsigned int devfn,
int where,
int size,
110 if (bcm63xx_setup_cfg_access(type, busn, devfn, where))
117 *val = postprocess_read(data, where, size);
122 static int bcm63xx_do_cfg_write(
int type,
unsigned int busn,
123 unsigned int devfn,
int where,
int size,
131 if (bcm63xx_setup_cfg_access(type, busn, devfn, where))
136 data = preprocess_write(data, val, where, size);
148 static int bcm63xx_pci_read(
struct pci_bus *
bus,
unsigned int devfn,
149 int where,
int size,
u32 *val)
153 type = bus->
parent ? 1 : 0;
158 return bcm63xx_do_cfg_read(type, bus->
number, devfn,
162 static int bcm63xx_pci_write(
struct pci_bus *bus,
unsigned int devfn,
163 int where,
int size,
u32 val)
167 type = bus->
parent ? 1 : 0;
172 return bcm63xx_do_cfg_write(type, bus->
number, devfn,
177 .read = bcm63xx_pci_read,
178 .write = bcm63xx_pci_write
181 #ifdef CONFIG_CARDBUS
185 #define FAKE_CB_BRIDGE_SLOT 0x1e
187 static int fake_cb_bridge_bus_number = -1;
207 } fake_cb_bridge_regs;
209 static int fake_cb_bridge_read(
int where,
int size,
u32 *val)
225 data |= fake_cb_bridge_regs.pci_command;
238 data = (fake_cb_bridge_regs.bridge_control << 16);
240 data |= (0x1 << 8) | 0xff;
244 data = (fake_cb_bridge_regs.cb_latency << 24);
245 data |= (fake_cb_bridge_regs.subordinate_busn << 16);
246 data |= (fake_cb_bridge_regs.cardbus_busn << 8);
247 data |= fake_cb_bridge_regs.pci_busn;
251 data = fake_cb_bridge_regs.mem_base0;
255 data = fake_cb_bridge_regs.mem_limit0;
259 data = fake_cb_bridge_regs.mem_base1;
263 data = fake_cb_bridge_regs.mem_limit1;
268 data = fake_cb_bridge_regs.io_base0 | 0x1;
272 data = fake_cb_bridge_regs.io_limit0;
277 data = fake_cb_bridge_regs.io_base1 | 0x1;
281 data = fake_cb_bridge_regs.io_limit1;
285 *val = postprocess_read(data, where, size);
292 static int fake_cb_bridge_write(
int where,
int size,
u32 val)
298 ret = fake_cb_bridge_read((where & ~0x3), 4, &data);
302 data = preprocess_write(data, val, where, size);
307 fake_cb_bridge_regs.pci_command = (data & 0xffff);
311 fake_cb_bridge_regs.cb_latency = (data >> 24) & 0xff;
312 fake_cb_bridge_regs.subordinate_busn = (data >> 16) & 0xff;
313 fake_cb_bridge_regs.cardbus_busn = (data >> 8) & 0xff;
314 fake_cb_bridge_regs.pci_busn = data & 0xff;
315 if (fake_cb_bridge_regs.cardbus_busn)
316 fake_cb_bridge_regs.bus_assigned = 1;
320 tmp = (data >> 16) & 0xffff;
324 fake_cb_bridge_regs.bridge_control =
tmp;
328 fake_cb_bridge_regs.mem_base0 =
data;
332 fake_cb_bridge_regs.mem_limit0 =
data;
336 fake_cb_bridge_regs.mem_base1 =
data;
340 fake_cb_bridge_regs.mem_limit1 =
data;
344 fake_cb_bridge_regs.io_base0 =
data;
348 fake_cb_bridge_regs.io_limit0 =
data;
352 fake_cb_bridge_regs.io_base1 =
data;
356 fake_cb_bridge_regs.io_limit1 =
data;
363 static int bcm63xx_cb_read(
struct pci_bus *bus,
unsigned int devfn,
364 int where,
int size,
u32 *val)
369 fake_cb_bridge_bus_number = bus->
number;
370 return fake_cb_bridge_read(where, size, val);
377 if (fake_cb_bridge_regs.bus_assigned &&
378 bus->
number == fake_cb_bridge_regs.cardbus_busn &&
380 return bcm63xx_do_cfg_read(0, 0,
387 static int bcm63xx_cb_write(
struct pci_bus *bus,
unsigned int devfn,
388 int where,
int size,
u32 val)
391 fake_cb_bridge_bus_number = bus->
number;
392 return fake_cb_bridge_write(where, size, val);
395 if (fake_cb_bridge_regs.bus_assigned &&
396 bus->
number == fake_cb_bridge_regs.cardbus_busn &&
398 return bcm63xx_do_cfg_write(0, 0,
406 .read = bcm63xx_cb_read,
407 .write = bcm63xx_cb_write,
416 static int io_window = -1;
417 int i, found, new_io_window;
433 if (dev->
bus->number == fake_cb_bridge_bus_number)
437 if (fake_cb_bridge_regs.bus_assigned &&
438 dev->
bus->number == fake_cb_bridge_regs.cardbus_busn &&
444 if (new_io_window == io_window)
447 if (io_window != -1) {
449 "need IO, which hardware cannot do\n");
454 (new_io_window == 0) ?
"PCI" :
"cardbus");
463 io_window = new_io_window;
469 static int bcm63xx_pcie_can_access(
struct pci_bus *bus,
int devfn)
483 static int bcm63xx_pcie_read(
struct pci_bus *bus,
unsigned int devfn,
484 int where,
int size,
u32 *val)
487 u32 reg = where & ~3;
489 if (!bcm63xx_pcie_can_access(bus, devfn))
497 *val = postprocess_read(data, where, size);
503 static int bcm63xx_pcie_write(
struct pci_bus *bus,
unsigned int devfn,
504 int where,
int size,
u32 val)
507 u32 reg = where & ~3;
509 if (!bcm63xx_pcie_can_access(bus, devfn))
518 data = preprocess_write(data, val, where, size);
526 .read = bcm63xx_pcie_read,
527 .write = bcm63xx_pcie_write