1 /* pci_common.c: PCI controller common support.
3 * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
6 #include <linux/string.h>
7 #include <linux/slab.h>
8 #include <linux/init.h>
10 #include <linux/device.h>
13 #include <asm/of_device.h>
14 #include <asm/oplib.h>
18 void pci_get_pbm_props(struct pci_pbm_info *pbm)
20 const u32 *val = of_get_property(pbm->prom_node, "bus-range", NULL);
22 pbm->pci_first_busno = val[0];
23 pbm->pci_last_busno = val[1];
25 val = of_get_property(pbm->prom_node, "ino-bitmap", NULL);
27 pbm->ino_bitmap = (((u64)val[1] << 32UL) |
28 ((u64)val[0] << 0UL));
32 static void pci_register_legacy_regions(struct resource *io_res,
33 struct resource *mem_res)
38 p = kzalloc(sizeof(*p), GFP_KERNEL);
42 p->name = "Video RAM area";
43 p->start = mem_res->start + 0xa0000UL;
44 p->end = p->start + 0x1ffffUL;
45 p->flags = IORESOURCE_BUSY;
46 request_resource(mem_res, p);
48 p = kzalloc(sizeof(*p), GFP_KERNEL);
52 p->name = "System ROM";
53 p->start = mem_res->start + 0xf0000UL;
54 p->end = p->start + 0xffffUL;
55 p->flags = IORESOURCE_BUSY;
56 request_resource(mem_res, p);
58 p = kzalloc(sizeof(*p), GFP_KERNEL);
62 p->name = "Video ROM";
63 p->start = mem_res->start + 0xc0000UL;
64 p->end = p->start + 0x7fffUL;
65 p->flags = IORESOURCE_BUSY;
66 request_resource(mem_res, p);
69 static void pci_register_iommu_region(struct pci_pbm_info *pbm)
71 const u32 *vdma = of_get_property(pbm->prom_node, "virtual-dma", NULL);
74 struct resource *rp = kmalloc(sizeof(*rp), GFP_KERNEL);
77 prom_printf("Cannot allocate IOMMU resource.\n");
81 rp->start = pbm->mem_space.start + (unsigned long) vdma[0];
82 rp->end = rp->start + (unsigned long) vdma[1] - 1UL;
83 rp->flags = IORESOURCE_BUSY;
84 request_resource(&pbm->mem_space, rp);
88 void pci_determine_mem_io_space(struct pci_pbm_info *pbm)
90 const struct linux_prom_pci_ranges *pbm_ranges;
91 int i, saw_mem, saw_io;
95 pbm_ranges = of_get_property(pbm->prom_node, "ranges", &i);
96 num_pbm_ranges = i / sizeof(*pbm_ranges);
98 for (i = 0; i < num_pbm_ranges; i++) {
99 const struct linux_prom_pci_ranges *pr = &pbm_ranges[i];
101 u32 parent_phys_hi, parent_phys_lo;
104 parent_phys_hi = pr->parent_phys_hi;
105 parent_phys_lo = pr->parent_phys_lo;
106 if (tlb_type == hypervisor)
107 parent_phys_hi &= 0x0fffffff;
109 type = (pr->child_phys_hi >> 24) & 0x3;
110 a = (((unsigned long)parent_phys_hi << 32UL) |
111 ((unsigned long)parent_phys_lo << 0UL));
115 /* PCI config space, 16MB */
116 pbm->config_space = a;
120 /* 16-bit IO space, 16MB */
121 pbm->io_space.start = a;
122 pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
123 pbm->io_space.flags = IORESOURCE_IO;
128 /* 32-bit MEM space, 2GB */
129 pbm->mem_space.start = a;
130 pbm->mem_space.end = a + (0x80000000UL - 1UL);
131 pbm->mem_space.flags = IORESOURCE_MEM;
136 /* XXX 64-bit MEM handling XXX */
143 if (!saw_io || !saw_mem) {
144 prom_printf("%s: Fatal error, missing %s PBM range.\n",
146 (!saw_io ? "IO" : "MEM"));
150 printk("%s: PCI IO[%lx] MEM[%lx]\n",
153 pbm->mem_space.start);
155 pbm->io_space.name = pbm->mem_space.name = pbm->name;
157 request_resource(&ioport_resource, &pbm->io_space);
158 request_resource(&iomem_resource, &pbm->mem_space);
160 pci_register_legacy_regions(&pbm->io_space,
162 pci_register_iommu_region(pbm);
165 /* Generic helper routines for PCI error reporting. */
166 void pci_scan_for_target_abort(struct pci_pbm_info *pbm,
167 struct pci_bus *pbus)
169 struct pci_dev *pdev;
172 list_for_each_entry(pdev, &pbus->devices, bus_list) {
173 u16 status, error_bits;
175 pci_read_config_word(pdev, PCI_STATUS, &status);
177 (status & (PCI_STATUS_SIG_TARGET_ABORT |
178 PCI_STATUS_REC_TARGET_ABORT));
180 pci_write_config_word(pdev, PCI_STATUS, error_bits);
181 printk("%s: Device %s saw Target Abort [%016x]\n",
182 pbm->name, pci_name(pdev), status);
186 list_for_each_entry(bus, &pbus->children, node)
187 pci_scan_for_target_abort(pbm, bus);
190 void pci_scan_for_master_abort(struct pci_pbm_info *pbm,
191 struct pci_bus *pbus)
193 struct pci_dev *pdev;
196 list_for_each_entry(pdev, &pbus->devices, bus_list) {
197 u16 status, error_bits;
199 pci_read_config_word(pdev, PCI_STATUS, &status);
201 (status & (PCI_STATUS_REC_MASTER_ABORT));
203 pci_write_config_word(pdev, PCI_STATUS, error_bits);
204 printk("%s: Device %s received Master Abort [%016x]\n",
205 pbm->name, pci_name(pdev), status);
209 list_for_each_entry(bus, &pbus->children, node)
210 pci_scan_for_master_abort(pbm, bus);
213 void pci_scan_for_parity_error(struct pci_pbm_info *pbm,
214 struct pci_bus *pbus)
216 struct pci_dev *pdev;
219 list_for_each_entry(pdev, &pbus->devices, bus_list) {
220 u16 status, error_bits;
222 pci_read_config_word(pdev, PCI_STATUS, &status);
224 (status & (PCI_STATUS_PARITY |
225 PCI_STATUS_DETECTED_PARITY));
227 pci_write_config_word(pdev, PCI_STATUS, error_bits);
228 printk("%s: Device %s saw Parity Error [%016x]\n",
229 pbm->name, pci_name(pdev), status);
233 list_for_each_entry(bus, &pbus->children, node)
234 pci_scan_for_parity_error(pbm, bus);