10 #include <linux/export.h>
11 #include <linux/types.h>
12 #include <linux/pci.h>
14 #include <linux/kernel.h>
22 #ifdef CONFIG_DEBUG_PCI
23 #define DBG(x...) printk(KERN_DEBUG x)
25 #define DBG(x...) do {} while (0)
28 #define PCI_ACCESS_READ 0
29 #define PCI_ACCESS_WRITE 1
55 static struct resource alchemy_pci_def_memres = {
58 .name =
"PCI memory space",
62 static struct resource alchemy_pci_def_iores = {
65 .name =
"PCI IO space",
69 static void mod_wired_entry(
int entry,
unsigned long entrylo0,
70 unsigned long entrylo1,
unsigned long entryhi,
71 unsigned long pagemask)
73 unsigned long old_pagemask;
74 unsigned long old_ctx;
96 static int config_access(
unsigned char access_type,
struct pci_bus *
bus,
97 unsigned int dev_fn,
unsigned char where,
u32 *
data)
101 unsigned int function =
PCI_FUNC(dev_fn);
127 cfg_base = (1 << device) << 11;
129 cfg_base = 0x80000000 | (bus->
number << 16) | (device << 11);
132 offset = (
function << 8) | (where & ~0x3);
142 entryLo0 = (6 << 26) | (cfg_base >> 6) | (2 << 3) | 7;
143 entryLo1 = (6 << 26) | (cfg_base >> 6) | (0x1000 >> 6) | (2 << 3) | 7;
145 mod_wired_entry(ctx->
wired_entry, entryLo0, entryLo1,
157 DBG(
"alchemy-pci: cfg access %d bus %u dev %u at %x dat %x conf %lx\n",
158 access_type, bus->
number, device, where, *data, offset);
162 if (status & (1 << 29)) {
165 DBG(
"alchemy-pci: master abort on cfg access %d bus %d dev %d",
166 access_type, bus->
number, device);
167 }
else if ((status >> 28) & 0xf) {
168 DBG(
"alchemy-pci: PCI ERR detected: dev %d, status %lx\n",
169 device, (status >> 28) & 0xf);
185 static int read_config_byte(
struct pci_bus *bus,
unsigned int devfn,
199 static int read_config_word(
struct pci_bus *bus,
unsigned int devfn,
207 *val = data & 0xffff;
211 static int read_config_dword(
struct pci_bus *bus,
unsigned int devfn,
217 static int write_config_byte(
struct pci_bus *bus,
unsigned int devfn,
225 data = (data & ~(0xff << ((where & 3) << 3))) |
226 (val << ((where & 3) << 3));
234 static int write_config_word(
struct pci_bus *bus,
unsigned int devfn,
242 data = (data & ~(0xffff << ((where & 3) << 3))) |
243 (val << ((where & 3) << 3));
251 static int write_config_dword(
struct pci_bus *bus,
unsigned int devfn,
257 static int alchemy_pci_read(
struct pci_bus *bus,
unsigned int devfn,
263 int rc = read_config_byte(bus, devfn, where, &_val);
270 int rc = read_config_word(bus, devfn, where, &_val);
276 return read_config_dword(bus, devfn, where, val);
280 static int alchemy_pci_write(
struct pci_bus *bus,
unsigned int devfn,
281 int where,
int size,
u32 val)
285 return write_config_byte(bus, devfn, where, (
u8) val);
287 return write_config_word(bus, devfn, where, (
u16) val);
289 return write_config_dword(bus, devfn, where, val);
293 static struct pci_ops alchemy_pci_ops = {
294 .read = alchemy_pci_read,
295 .write = alchemy_pci_write,
298 static int alchemy_pci_def_idsel(
unsigned int devsel,
int assert)
304 static int alchemy_pci_suspend(
void)
326 static void alchemy_pci_resume(
void)
351 alchemy_pci_wired_entry(ctx);
355 .suspend = alchemy_pci_suspend,
356 .resume = alchemy_pci_resume,
370 dev_err(&pdev->
dev,
"need platform data for PCI setup\n");
377 dev_err(&pdev->
dev,
"no memory for pcictl context\n");
384 dev_err(&pdev->
dev,
"no pcictl ctrl regs resource\n");
390 dev_err(&pdev->
dev,
"cannot claim pci regs\n");
408 dev_err(&pdev->
dev,
"cannot remap pci io space\n");
414 #ifdef CONFIG_DMA_NONCOHERENT
422 dev_info(&pdev->
dev,
"non-coherent PCI on Au1500 AA/AB/AC\n");
447 dev_err(&pdev->
dev,
"unable to get vm area\n");
452 alchemy_pci_wired_entry(ctx);
464 __alchemy_pci_ctx =
ctx;
465 platform_set_drvdata(pdev, ctx);
484 .probe = alchemy_pci_probe,
486 .name =
"alchemy-pci",
491 static int __init alchemy_pci_init(
void)
494 switch (alchemy_get_cputype()) {