6 #include <linux/string.h>
7 #include <linux/slab.h>
10 #include <linux/device.h>
14 #include <asm/oplib.h>
24 if (bus < pbm->pci_first_busno ||
30 static void *sun4u_config_mkaddr(
struct pci_pbm_info *pbm,
37 if (config_out_of_range(pbm, bus, devfn, reg))
40 reg = (reg & ((1 << rbits) - 1));
52 static int sun4u_read_pci_cfg_host(
struct pci_pbm_info *pbm,
53 unsigned char bus,
unsigned int devfn,
60 addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
67 unsigned long align = (
unsigned long) addr;
74 *value = tmp16 & 0xff;
89 *value |= ((
u32) tmp8) << 8;
95 sun4u_read_pci_cfg_host(pbm, bus, devfn,
100 sun4u_read_pci_cfg_host(pbm, bus, devfn,
101 where + 2, 2, &tmp32);
102 *value |= tmp32 << 16;
108 static int sun4u_read_pci_cfg(
struct pci_bus *bus_dev,
unsigned int devfn,
109 int where,
int size,
u32 *value)
112 unsigned char bus = bus_dev->
number;
130 return sun4u_read_pci_cfg_host(pbm, bus, devfn, where,
133 addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
145 printk(
"pci_read_config_word: misaligned reg [%x]\n",
150 *value = (
u32) tmp16;
155 printk(
"pci_read_config_dword: misaligned reg [%x]\n",
165 static int sun4u_write_pci_cfg_host(
struct pci_pbm_info *pbm,
166 unsigned char bus,
unsigned int devfn,
167 int where,
int size,
u32 value)
171 addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
178 unsigned long align = (
unsigned long) addr;
203 sun4u_write_pci_cfg_host(pbm, bus, devfn,
204 where, 2, value & 0xffff);
205 sun4u_write_pci_cfg_host(pbm, bus, devfn,
206 where + 2, 2, value >> 16);
212 static int sun4u_write_pci_cfg(
struct pci_bus *bus_dev,
unsigned int devfn,
213 int where,
int size,
u32 value)
216 unsigned char bus = bus_dev->
number;
220 return sun4u_write_pci_cfg_host(pbm, bus, devfn, where,
223 addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
234 printk(
"pci_write_config_word: misaligned reg [%x]\n",
243 printk(
"pci_write_config_dword: misaligned reg [%x]\n",
253 .read = sun4u_read_pci_cfg,
254 .write = sun4u_write_pci_cfg,
257 static int sun4v_read_pci_cfg(
struct pci_bus *bus_dev,
unsigned int devfn,
258 int where,
int size,
u32 *value)
262 unsigned int bus = bus_dev->
number;
267 if (config_out_of_range(pbm, bus, devfn, where)) {
279 *value = ret & 0xffff;
282 *value = ret & 0xffffffff;
290 static int sun4v_write_pci_cfg(
struct pci_bus *bus_dev,
unsigned int devfn,
291 int where,
int size,
u32 value)
295 unsigned int bus = bus_dev->
number;
296 unsigned int device =
PCI_SLOT(devfn);
297 unsigned int func =
PCI_FUNC(devfn);
299 if (config_out_of_range(pbm, bus, devfn, where)) {
314 .read = sun4v_read_pci_cfg,
315 .write = sun4v_write_pci_cfg,
328 ((
u64)val[0] << 0
UL));
332 static void pci_register_legacy_regions(
struct resource *io_res,
342 p->
name =
"Video RAM area";
352 p->
name =
"System ROM";
362 p->
name =
"Video ROM";
369 static void pci_register_iommu_region(
struct pci_pbm_info *pbm)
378 pr_info(
"%s: Cannot allocate IOMMU resource.\n",
387 pr_info(
"%s: Unable to request IOMMU resource.\n",
397 int i, saw_mem, saw_io;
400 saw_mem = saw_io = 0;
403 prom_printf(
"PCI: Fatal error, missing PBM ranges property "
409 num_pbm_ranges = i /
sizeof(*pbm_ranges);
411 for (i = 0; i < num_pbm_ranges; i++) {
413 unsigned long a,
size;
421 parent_phys_hi &= 0x0fffffff;
427 a = (((
unsigned long)parent_phys_hi << 32
UL) |
428 ((
unsigned long)parent_phys_lo << 0
UL));
429 size = (((
unsigned long)size_hi << 32
UL) |
430 ((
unsigned long)size_lo << 0
UL));
462 if (!saw_io || !saw_mem) {
463 prom_printf(
"%s: Fatal error, missing %s PBM range.\n",
465 (!saw_io ?
"IO" :
"MEM"));
469 printk(
"%s: PCI IO[%llx] MEM[%llx]\n",
479 pci_register_legacy_regions(&pbm->
io_space,
481 pci_register_iommu_region(pbm);
494 pci_read_config_word(pdev,
PCI_STATUS, &status);
499 pci_write_config_word(pdev,
PCI_STATUS, error_bits);
500 printk(
"%s: Device %s saw Target Abort [%016x]\n",
501 pbm->
name, pci_name(pdev), status);
518 pci_read_config_word(pdev,
PCI_STATUS, &status);
522 pci_write_config_word(pdev,
PCI_STATUS, error_bits);
523 printk(
"%s: Device %s received Master Abort [%016x]\n",
524 pbm->
name, pci_name(pdev), status);
541 pci_read_config_word(pdev,
PCI_STATUS, &status);
546 pci_write_config_word(pdev,
PCI_STATUS, error_bits);
547 printk(
"%s: Device %s saw Parity Error [%016x]\n",
548 pbm->
name, pci_name(pdev), status);