2 * Common pmac/prep/chrp pci routines. -- Cort
5 #include <linux/config.h>
6 #include <linux/kernel.h>
8 #include <linux/delay.h>
9 #include <linux/string.h>
10 #include <linux/init.h>
11 #include <linux/capability.h>
12 #include <linux/sched.h>
13 #include <linux/errno.h>
14 #include <linux/bootmem.h>
16 #include <asm/processor.h>
19 #include <asm/sections.h>
20 #include <asm/pci-bridge.h>
21 #include <asm/byteorder.h>
23 #include <asm/uaccess.h>
28 #define DBG(x...) printk(x)
33 unsigned long isa_io_base = 0;
34 unsigned long isa_mem_base = 0;
35 unsigned long pci_dram_offset = 0;
37 void pcibios_make_OF_bus_map(void);
39 static int pci_relocate_bridge_resource(struct pci_bus *bus, int i);
40 static int probe_resource(struct pci_bus *parent, struct resource *pr,
41 struct resource *res, struct resource **conflict);
42 static void update_bridge_base(struct pci_bus *bus, int i);
43 static void pcibios_fixup_resources(struct pci_dev* dev);
44 static void fixup_broken_pcnet32(struct pci_dev* dev);
45 static int reparent_resources(struct resource *parent, struct resource *res);
46 static void fixup_rev1_53c810(struct pci_dev* dev);
47 static void fixup_cpc710_pci64(struct pci_dev* dev);
48 #ifdef CONFIG_PPC_PMAC
49 extern void pmac_pci_fixup_cardbus(struct pci_dev* dev);
50 extern void pmac_pci_fixup_pciata(struct pci_dev* dev);
51 extern void pmac_pci_fixup_k2_sata(struct pci_dev* dev);
54 static u8* pci_to_OF_bus_map;
57 /* By default, we don't re-assign bus numbers. We do this only on
60 int pci_assign_all_busses;
62 struct pci_controller* hose_head;
63 struct pci_controller** hose_tail = &hose_head;
65 static int pci_bus_count;
67 struct pci_fixup pcibios_fixups[] = {
68 { PCI_FIXUP_HEADER, PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32 },
69 { PCI_FIXUP_HEADER, PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810 },
70 { PCI_FIXUP_HEADER, PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64},
71 { PCI_FIXUP_HEADER, PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources },
72 #ifdef CONFIG_PPC_PMAC
73 /* We should add per-machine fixup support in xxx_setup.c or xxx_pci.c */
74 { PCI_FIXUP_FINAL, PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus },
75 { PCI_FIXUP_FINAL, PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata },
76 { PCI_FIXUP_HEADER, PCI_VENDOR_ID_SERVERWORKS, 0x0240, pmac_pci_fixup_k2_sata },
77 #endif /* CONFIG_PPC_PMAC */
82 fixup_rev1_53c810(struct pci_dev* dev)
84 /* rev 1 ncr53c810 chips don't set the class at all which means
85 * they don't get their resources remapped. Fix that here.
88 if ((dev->class == PCI_CLASS_NOT_DEFINED)) {
89 printk("NCR 53c810 rev 1 detected, setting PCI class.\n");
90 dev->class = PCI_CLASS_STORAGE_SCSI;
95 fixup_broken_pcnet32(struct pci_dev* dev)
97 if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
98 dev->vendor = PCI_VENDOR_ID_AMD;
99 pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
100 pci_name_device(dev);
105 fixup_cpc710_pci64(struct pci_dev* dev)
107 /* Hide the PCI64 BARs from the kernel as their content doesn't
108 * fit well in the resource management
110 dev->resource[0].start = dev->resource[0].end = 0;
111 dev->resource[0].flags = 0;
112 dev->resource[1].start = dev->resource[1].end = 0;
113 dev->resource[1].flags = 0;
117 pcibios_fixup_resources(struct pci_dev *dev)
119 struct pci_controller* hose = (struct pci_controller *)dev->sysdata;
121 unsigned long offset;
124 printk(KERN_ERR "No hose for PCI dev %s!\n", pci_name(dev));
127 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
128 struct resource *res = dev->resource + i;
131 if (!res->start || res->end == 0xffffffff) {
132 DBG("PCI:%s Resource %d [%08lx-%08lx] is unassigned\n",
133 pci_name(dev), i, res->start, res->end);
134 res->end -= res->start;
136 res->flags |= IORESOURCE_UNSET;
140 if (res->flags & IORESOURCE_MEM) {
141 offset = hose->pci_mem_offset;
142 } else if (res->flags & IORESOURCE_IO) {
143 offset = (unsigned long) hose->io_base_virt
147 res->start += offset;
150 printk("Fixup res %d (%lx) of dev %s: %lx -> %lx\n",
151 i, res->flags, pci_name(dev),
152 res->start - offset, res->start);
157 /* Call machine specific resource fixup */
158 if (ppc_md.pcibios_fixup_resources)
159 ppc_md.pcibios_fixup_resources(dev);
163 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
164 struct resource *res)
166 unsigned long offset = 0;
167 struct pci_controller *hose = dev->sysdata;
169 if (hose && res->flags & IORESOURCE_IO)
170 offset = (unsigned long)hose->io_base_virt - isa_io_base;
171 else if (hose && res->flags & IORESOURCE_MEM)
172 offset = hose->pci_mem_offset;
173 region->start = res->start - offset;
174 region->end = res->end - offset;
178 * We need to avoid collisions with `mirrored' VGA ports
179 * and other strange ISA hardware, so we always want the
180 * addresses to be allocated in the 0x000-0x0ff region
183 * Why? Because some silly external IO cards only decode
184 * the low 10 bits of the IO address. The 0x00-0xff region
185 * is reserved for motherboard devices that decode all 16
186 * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
187 * but we want to try to avoid allocating at 0x2900-0x2bff
188 * which might have be mirrored at 0x0100-0x03ff..
191 pcibios_align_resource(void *data, struct resource *res, unsigned long size,
194 struct pci_dev *dev = data;
196 if (res->flags & IORESOURCE_IO) {
197 unsigned long start = res->start;
200 printk(KERN_ERR "PCI: I/O Region %s/%d too large"
201 " (%ld bytes)\n", pci_name(dev),
202 dev->resource - res, size);
206 start = (start + 0x3ff) & ~0x3ff;
214 * Handle resources of PCI devices. If the world were perfect, we could
215 * just allocate all the resource regions and do nothing more. It isn't.
216 * On the other hand, we cannot just re-allocate all devices, as it would
217 * require us to know lots of host bridge internals. So we attempt to
218 * keep as much of the original configuration as possible, but tweak it
219 * when it's found to be wrong.
221 * Known BIOS problems we have to work around:
222 * - I/O or memory regions not configured
223 * - regions configured, but not enabled in the command register
224 * - bogus I/O addresses above 64K used
225 * - expansion ROMs left enabled (this may sound harmless, but given
226 * the fact the PCI specs explicitly allow address decoders to be
227 * shared between expansion ROMs and other resource regions, it's
228 * at least dangerous)
231 * (1) Allocate resources for all buses behind PCI-to-PCI bridges.
232 * This gives us fixed barriers on where we can allocate.
233 * (2) Allocate resources for all enabled devices. If there is
234 * a collision, just mark the resource as unallocated. Also
235 * disable expansion ROMs during this step.
236 * (3) Try to allocate resources for disabled devices. If the
237 * resources were assigned correctly, everything goes well,
238 * if they weren't, they won't disturb allocation of other
240 * (4) Assign new addresses to resources which were either
241 * not configured at all or misconfigured. If explicitly
242 * requested by the user, configure expansion ROM address
247 pcibios_allocate_bus_resources(struct list_head *bus_list)
249 struct list_head *ln;
252 struct resource *res, *pr;
254 /* Depth-First Search on bus tree */
255 for (ln = bus_list->next; ln != bus_list; ln=ln->next) {
257 for (i = 0; i < 4; ++i) {
258 if ((res = bus->resource[i]) == NULL || !res->flags
259 || res->start > res->end)
261 if (bus->parent == NULL)
262 pr = (res->flags & IORESOURCE_IO)?
263 &ioport_resource: &iomem_resource;
265 pr = pci_find_parent_resource(bus->self, res);
267 /* this happens when the generic PCI
268 * code (wrongly) decides that this
269 * bridge is transparent -- paulus
275 DBG("PCI: bridge rsrc %lx..%lx (%lx), parent %p\n",
276 res->start, res->end, res->flags, pr);
278 if (request_resource(pr, res) == 0)
281 * Must be a conflict with an existing entry.
282 * Move that entry (or entries) under the
283 * bridge resource and try again.
285 if (reparent_resources(pr, res) == 0)
288 printk(KERN_ERR "PCI: Cannot allocate resource region "
289 "%d of PCI bridge %d\n", i, bus->number);
290 if (pci_relocate_bridge_resource(bus, i))
291 bus->resource[i] = NULL;
293 pcibios_allocate_bus_resources(&bus->children);
298 * Reparent resource children of pr that conflict with res
299 * under res, and make res replace those children.
302 reparent_resources(struct resource *parent, struct resource *res)
304 struct resource *p, **pp;
305 struct resource **firstpp = NULL;
307 for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
308 if (p->end < res->start)
310 if (res->end < p->start)
312 if (p->start < res->start || p->end > res->end)
313 return -1; /* not completely contained */
318 return -1; /* didn't find any conflicting entries? */
319 res->parent = parent;
320 res->child = *firstpp;
324 for (p = res->child; p != NULL; p = p->sibling) {
326 DBG(KERN_INFO "PCI: reparented %s [%lx..%lx] under %s\n",
327 p->name, p->start, p->end, res->name);
333 * A bridge has been allocated a range which is outside the range
334 * of its parent bridge, so it needs to be moved.
337 pci_relocate_bridge_resource(struct pci_bus *bus, int i)
339 struct resource *res, *pr, *conflict;
340 unsigned long try, size;
342 struct pci_bus *parent = bus->parent;
344 if (parent == NULL) {
345 /* shouldn't ever happen */
346 printk(KERN_ERR "PCI: can't move host bridge resource\n");
349 res = bus->resource[i];
351 for (j = 0; j < 4; j++) {
352 struct resource *r = parent->resource[j];
355 if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
357 if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) {
361 if (res->flags & IORESOURCE_PREFETCH)
366 size = res->end - res->start;
367 if (pr->start > pr->end || size > pr->end - pr->start)
371 res->start = try - size;
373 if (probe_resource(bus->parent, pr, res, &conflict) == 0)
375 if (conflict->start <= pr->start + size)
377 try = conflict->start - 1;
379 if (request_resource(pr, res)) {
380 DBG(KERN_ERR "PCI: huh? couldn't move to %lx..%lx\n",
381 res->start, res->end);
382 return -1; /* "can't happen" */
384 update_bridge_base(bus, i);
385 printk(KERN_INFO "PCI: bridge %d resource %d moved to %lx..%lx\n",
386 bus->number, i, res->start, res->end);
391 probe_resource(struct pci_bus *parent, struct resource *pr,
392 struct resource *res, struct resource **conflict)
397 struct list_head *ln;
400 for (r = pr->child; r != NULL; r = r->sibling) {
401 if (r->end >= res->start && res->end >= r->start) {
406 for (ln = parent->children.next; ln != &parent->children;
409 for (i = 0; i < 4; ++i) {
410 if ((r = bus->resource[i]) == NULL)
412 if (!r->flags || r->start > r->end || r == res)
414 if (pci_find_parent_resource(bus->self, r) != pr)
416 if (r->end >= res->start && res->end >= r->start) {
422 for (ln = parent->devices.next; ln != &parent->devices; ln=ln->next) {
424 for (i = 0; i < 6; ++i) {
425 r = &dev->resource[i];
426 if (!r->flags || (r->flags & IORESOURCE_UNSET))
428 if (pci_find_parent_resource(bus->self, r) != pr)
430 if (r->end >= res->start && res->end >= r->start) {
440 update_bridge_base(struct pci_bus *bus, int i)
442 struct resource *res = bus->resource[i];
443 u8 io_base_lo, io_limit_lo;
444 u16 mem_base, mem_limit;
446 unsigned long start, end, off;
447 struct pci_dev *dev = bus->self;
448 struct pci_controller *hose = dev->sysdata;
451 printk("update_bridge_base: no hose?\n");
454 pci_read_config_word(dev, PCI_COMMAND, &cmd);
455 pci_write_config_word(dev, PCI_COMMAND,
456 cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
457 if (res->flags & IORESOURCE_IO) {
458 off = (unsigned long) hose->io_base_virt - isa_io_base;
459 start = res->start - off;
460 end = res->end - off;
461 io_base_lo = (start >> 8) & PCI_IO_RANGE_MASK;
462 io_limit_lo = (end >> 8) & PCI_IO_RANGE_MASK;
464 pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
466 pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
468 io_base_lo |= PCI_IO_RANGE_TYPE_32;
470 io_base_lo |= PCI_IO_RANGE_TYPE_16;
471 pci_write_config_byte(dev, PCI_IO_BASE, io_base_lo);
472 pci_write_config_byte(dev, PCI_IO_LIMIT, io_limit_lo);
474 } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
476 off = hose->pci_mem_offset;
477 mem_base = ((res->start - off) >> 16) & PCI_MEMORY_RANGE_MASK;
478 mem_limit = ((res->end - off) >> 16) & PCI_MEMORY_RANGE_MASK;
479 pci_write_config_word(dev, PCI_MEMORY_BASE, mem_base);
480 pci_write_config_word(dev, PCI_MEMORY_LIMIT, mem_limit);
482 } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
483 == (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
484 off = hose->pci_mem_offset;
485 mem_base = ((res->start - off) >> 16) & PCI_PREF_RANGE_MASK;
486 mem_limit = ((res->end - off) >> 16) & PCI_PREF_RANGE_MASK;
487 pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, mem_base);
488 pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, mem_limit);
491 DBG(KERN_ERR "PCI: ugh, bridge %s res %d has flags=%lx\n",
492 pci_name(dev), i, res->flags);
494 pci_write_config_word(dev, PCI_COMMAND, cmd);
497 static inline void alloc_resource(struct pci_dev *dev, int idx)
499 struct resource *pr, *r = &dev->resource[idx];
501 DBG("PCI:%s: Resource %d: %08lx-%08lx (f=%lx)\n",
502 pci_name(dev), idx, r->start, r->end, r->flags);
503 pr = pci_find_parent_resource(dev, r);
504 if (!pr || request_resource(pr, r) < 0) {
505 printk(KERN_ERR "PCI: Cannot allocate resource region %d"
506 " of device %s\n", idx, pci_name(dev));
508 DBG("PCI: parent is %p: %08lx-%08lx (f=%lx)\n",
509 pr, pr->start, pr->end, pr->flags);
510 /* We'll assign a new address later */
511 r->flags |= IORESOURCE_UNSET;
518 pcibios_allocate_resources(int pass)
520 struct pci_dev *dev = NULL;
525 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
526 pci_read_config_word(dev, PCI_COMMAND, &command);
527 for (idx = 0; idx < 6; idx++) {
528 r = &dev->resource[idx];
529 if (r->parent) /* Already allocated */
531 if (!r->flags || (r->flags & IORESOURCE_UNSET))
532 continue; /* Not assigned at all */
533 if (r->flags & IORESOURCE_IO)
534 disabled = !(command & PCI_COMMAND_IO);
536 disabled = !(command & PCI_COMMAND_MEMORY);
537 if (pass == disabled)
538 alloc_resource(dev, idx);
542 r = &dev->resource[PCI_ROM_RESOURCE];
543 if (r->flags & PCI_ROM_ADDRESS_ENABLE) {
544 /* Turn the ROM off, leave the resource region, but keep it unregistered. */
546 DBG("PCI: Switching off ROM of %s\n", pci_name(dev));
547 r->flags &= ~PCI_ROM_ADDRESS_ENABLE;
548 pci_read_config_dword(dev, dev->rom_base_reg, ®);
549 pci_write_config_dword(dev, dev->rom_base_reg,
550 reg & ~PCI_ROM_ADDRESS_ENABLE);
556 pcibios_assign_resources(void)
558 struct pci_dev *dev = NULL;
562 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
563 int class = dev->class >> 8;
565 /* Don't touch classless devices and host bridges */
566 if (!class || class == PCI_CLASS_BRIDGE_HOST)
569 for (idx = 0; idx < 6; idx++) {
570 r = &dev->resource[idx];
573 * We shall assign a new address to this resource,
574 * either because the BIOS (sic) forgot to do so
575 * or because we have decided the old address was
576 * unusable for some reason.
578 if ((r->flags & IORESOURCE_UNSET) && r->end &&
579 (!ppc_md.pcibios_enable_device_hook ||
580 !ppc_md.pcibios_enable_device_hook(dev, 1))) {
581 r->flags &= ~IORESOURCE_UNSET;
582 pci_assign_resource(dev, idx);
586 #if 0 /* don't assign ROMs */
587 r = &dev->resource[PCI_ROM_RESOURCE];
591 pci_assign_resource(dev, PCI_ROM_RESOURCE);
598 pcibios_enable_resources(struct pci_dev *dev, int mask)
604 pci_read_config_word(dev, PCI_COMMAND, &cmd);
606 for (idx=0; idx<6; idx++) {
607 /* Only set up the requested stuff */
608 if (!(mask & (1<<idx)))
611 r = &dev->resource[idx];
612 if (r->flags & IORESOURCE_UNSET) {
613 printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
616 if (r->flags & IORESOURCE_IO)
617 cmd |= PCI_COMMAND_IO;
618 if (r->flags & IORESOURCE_MEM)
619 cmd |= PCI_COMMAND_MEMORY;
621 if (dev->resource[PCI_ROM_RESOURCE].start)
622 cmd |= PCI_COMMAND_MEMORY;
623 if (cmd != old_cmd) {
624 printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
625 pci_write_config_word(dev, PCI_COMMAND, cmd);
630 static int next_controller_index;
632 struct pci_controller * __init
633 pcibios_alloc_controller(void)
635 struct pci_controller *hose;
637 hose = (struct pci_controller *)alloc_bootmem(sizeof(*hose));
638 memset(hose, 0, sizeof(struct pci_controller));
641 hose_tail = &hose->next;
643 hose->index = next_controller_index++;
650 * Functions below are used on OpenFirmware machines.
652 static void __openfirmware
653 make_one_node_map(struct device_node* node, u8 pci_bus)
658 if (pci_bus >= pci_bus_count)
660 bus_range = (int *) get_property(node, "bus-range", &len);
661 if (bus_range == NULL || len < 2 * sizeof(int)) {
662 printk(KERN_WARNING "Can't get bus-range for %s\n",
666 pci_to_OF_bus_map[pci_bus] = bus_range[0];
668 for (node=node->child; node != 0;node = node->sibling) {
670 unsigned int *class_code, *reg;
672 class_code = (unsigned int *) get_property(node, "class-code", 0);
673 if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
674 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
676 reg = (unsigned int *)get_property(node, "reg", 0);
679 dev = pci_find_slot(pci_bus, ((reg[0] >> 8) & 0xff));
680 if (!dev || !dev->subordinate)
682 make_one_node_map(node, dev->subordinate->number);
687 pcibios_make_OF_bus_map(void)
690 struct pci_controller* hose;
693 pci_to_OF_bus_map = (u8*)kmalloc(pci_bus_count, GFP_KERNEL);
694 if (!pci_to_OF_bus_map) {
695 printk(KERN_ERR "Can't allocate OF bus map !\n");
699 /* We fill the bus map with invalid values, that helps
702 for (i=0; i<pci_bus_count; i++)
703 pci_to_OF_bus_map[i] = 0xff;
705 /* For each hose, we begin searching bridges */
706 for(hose=hose_head; hose; hose=hose->next) {
707 struct device_node* node;
708 node = (struct device_node *)hose->arch_data;
711 make_one_node_map(node, hose->first_busno);
713 of_prop_map = get_property(find_path_device("/"), "pci-OF-bus-map", 0);
715 memcpy(of_prop_map, pci_to_OF_bus_map, pci_bus_count);
717 printk("PCI->OF bus map:\n");
718 for (i=0; i<pci_bus_count; i++) {
719 if (pci_to_OF_bus_map[i] == 0xff)
721 printk("%d -> %d\n", i, pci_to_OF_bus_map[i]);
726 typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data);
728 static struct device_node* __openfirmware
729 scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void* data)
731 struct device_node* sub_node;
733 for (; node != 0;node = node->sibling) {
734 unsigned int *class_code;
736 if (filter(node, data))
739 /* For PCI<->PCI bridges or CardBus bridges, we go down
740 * Note: some OFs create a parent node "multifunc-device" as
741 * a fake root for all functions of a multi-function device,
742 * we go down them as well.
744 class_code = (unsigned int *) get_property(node, "class-code", 0);
745 if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
746 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
747 strcmp(node->name, "multifunc-device"))
749 sub_node = scan_OF_pci_childs(node->child, filter, data);
757 scan_OF_pci_childs_iterator(struct device_node* node, void* data)
760 u8* fdata = (u8*)data;
762 reg = (unsigned int *) get_property(node, "reg", 0);
763 if (reg && ((reg[0] >> 8) & 0xff) == fdata[1]
764 && ((reg[0] >> 16) & 0xff) == fdata[0])
769 static struct device_node* __openfirmware
770 scan_OF_childs_for_device(struct device_node* node, u8 bus, u8 dev_fn)
772 u8 filter_data[2] = {bus, dev_fn};
774 return scan_OF_pci_childs(node, scan_OF_pci_childs_iterator, filter_data);
778 * Scans the OF tree for a device node matching a PCI device
781 pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
783 struct pci_controller *hose;
784 struct device_node *node;
790 /* Lookup the hose */
792 hose = pci_bus_to_hose(busnr);
796 /* Check it has an OF node associated */
797 node = (struct device_node *) hose->arch_data;
801 /* Fixup bus number according to what OF think it is. */
802 #ifdef CONFIG_PPC_PMAC
803 /* The G5 need a special case here. Basically, we don't remap all
804 * busses on it so we don't create the pci-OF-map. However, we do
805 * remap the AGP bus and so have to deal with it. A future better
806 * fix has to be done by making the remapping per-host and always
807 * filling the pci_to_OF map. --BenH
809 if (_machine == _MACH_Pmac && busnr >= 0xf0)
813 if (pci_to_OF_bus_map)
814 busnr = pci_to_OF_bus_map[busnr];
818 /* Now, lookup childs of the hose */
819 return scan_OF_childs_for_device(node->child, busnr, devfn);
823 pci_device_to_OF_node(struct pci_dev *dev)
825 return pci_busdev_to_OF_node(dev->bus, dev->devfn);
828 /* This routine is meant to be used early during boot, when the
829 * PCI bus numbers have not yet been assigned, and you need to
830 * issue PCI config cycles to an OF device.
831 * It could also be used to "fix" RTAS config cycles if you want
832 * to set pci_assign_all_busses to 1 and still use RTAS for PCI
835 struct pci_controller*
836 pci_find_hose_for_OF_device(struct device_node* node)
841 struct pci_controller* hose;
842 for (hose=hose_head;hose;hose=hose->next)
843 if (hose->arch_data == node)
850 static int __openfirmware
851 find_OF_pci_device_filter(struct device_node* node, void* data)
853 return ((void *)node == data);
857 * Returns the PCI device matching a given OF node
860 pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
863 struct pci_controller* hose;
864 struct pci_dev* dev = NULL;
868 /* Make sure it's really a PCI device */
869 hose = pci_find_hose_for_OF_device(node);
870 if (!hose || !hose->arch_data)
872 if (!scan_OF_pci_childs(((struct device_node*)hose->arch_data)->child,
873 find_OF_pci_device_filter, (void *)node))
875 reg = (unsigned int *) get_property(node, "reg", 0);
878 *bus = (reg[0] >> 16) & 0xff;
879 *devfn = ((reg[0] >> 8) & 0xff);
881 /* Ok, here we need some tweak. If we have already renumbered
882 * all busses, we can't rely on the OF bus number any more.
883 * the pci_to_OF_bus_map is not enough as several PCI busses
884 * may match the same OF bus number.
886 if (!pci_to_OF_bus_map)
888 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
889 if (pci_to_OF_bus_map[dev->bus->number] != *bus)
891 if (dev->devfn != *devfn)
893 *bus = dev->bus->number;
900 pci_process_bridge_OF_ranges(struct pci_controller *hose,
901 struct device_node *dev, int primary)
903 static unsigned int static_lc_ranges[256] __initdata;
904 unsigned int *dt_ranges, *lc_ranges, *ranges, *prev;
906 int rlen = 0, orig_rlen;
908 struct resource *res;
909 int np, na = prom_n_addr_cells(dev);
912 /* First we try to merge ranges to fix a problem with some pmacs
913 * that can have more than 3 ranges, fortunately using contiguous
916 dt_ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
919 /* Sanity check, though hopefully that never happens */
920 if (rlen > sizeof(static_lc_ranges)) {
921 printk(KERN_WARNING "OF ranges property too large !\n");
922 rlen = sizeof(static_lc_ranges);
924 lc_ranges = static_lc_ranges;
925 memcpy(lc_ranges, dt_ranges, rlen);
928 /* Let's work on a copy of the "ranges" property instead of damaging
929 * the device-tree image in memory
933 while ((rlen -= np * sizeof(unsigned int)) >= 0) {
935 if (prev[0] == ranges[0] && prev[1] == ranges[1] &&
936 (prev[2] + prev[na+4]) == ranges[2] &&
937 (prev[na+2] + prev[na+4]) == ranges[na+2]) {
938 prev[na+4] += ranges[na+4];
949 * The ranges property is laid out as an array of elements,
950 * each of which comprises:
951 * cells 0 - 2: a PCI address
952 * cells 3 or 3+4: a CPU physical address
953 * (size depending on dev->n_addr_cells)
954 * cells 4+5 or 5+6: the size of the range
958 while (ranges && (rlen -= np * sizeof(unsigned int)) >= 0) {
961 switch (ranges[0] >> 24) {
962 case 1: /* I/O space */
965 hose->io_base_phys = ranges[na+2];
966 /* limit I/O space to 16MB */
967 if (size > 0x01000000)
969 hose->io_base_virt = ioremap(ranges[na+2], size);
971 isa_io_base = (unsigned long) hose->io_base_virt;
972 res = &hose->io_resource;
973 res->flags = IORESOURCE_IO;
974 res->start = ranges[2];
976 case 2: /* memory space */
978 if (ranges[1] == 0 && ranges[2] == 0
979 && ranges[na+4] <= (16 << 20)) {
980 /* 1st 16MB, i.e. ISA memory area */
982 isa_mem_base = ranges[na+2];
985 while (memno < 3 && hose->mem_resources[memno].flags)
988 hose->pci_mem_offset = ranges[na+2] - ranges[2];
990 res = &hose->mem_resources[memno];
991 res->flags = IORESOURCE_MEM;
992 res->start = ranges[na+2];
997 res->name = dev->full_name;
998 res->end = res->start + size - 1;
1000 res->sibling = NULL;
1007 /* We create the "pci-OF-bus-map" property now so it appears in the
1011 pci_create_OF_bus_map(void)
1013 struct property* of_prop;
1015 of_prop = (struct property*) alloc_bootmem(sizeof(struct property) + 256);
1016 if (of_prop && find_path_device("/")) {
1017 memset(of_prop, -1, sizeof(struct property) + 256);
1018 of_prop->name = "pci-OF-bus-map";
1019 of_prop->length = 256;
1020 of_prop->value = (unsigned char *)&of_prop[1];
1021 prom_add_property(find_path_device("/"), of_prop);
1025 static ssize_t pci_show_devspec(struct device *dev, char *buf)
1027 struct pci_dev *pdev;
1028 struct device_node *np;
1030 pdev = to_pci_dev (dev);
1031 np = pci_device_to_OF_node(pdev);
1032 if (np == NULL || np->full_name == NULL)
1034 return sprintf(buf, "%s", np->full_name);
1036 static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
1038 #endif /* CONFIG_PPC_OF */
1040 /* Add sysfs properties */
1041 void pcibios_add_platform_entries(struct pci_dev *pdev)
1043 #ifdef CONFIG_PPC_OF
1044 device_create_file(&pdev->dev, &dev_attr_devspec);
1045 #endif /* CONFIG_PPC_OF */
1049 #ifdef CONFIG_PPC_PMAC
1051 * This set of routines checks for PCI<->PCI bridges that have closed
1052 * IO resources and have child devices. It tries to re-open an IO
1055 * This is a _temporary_ fix to workaround a problem with Apple's OF
1056 * closing IO windows on P2P bridges when the OF drivers of cards
1057 * below this bridge don't claim any IO range (typically ATI or
1060 * A more complete fix would be to use drivers/pci/setup-bus.c, which
1061 * involves a working pcibios_fixup_pbus_ranges(), some more care about
1062 * ordering when creating the host bus resources, and maybe a few more
1066 /* Initialize bridges with base/limit values we have collected */
1068 do_update_p2p_io_resource(struct pci_bus *bus, int enable_vga)
1070 struct pci_dev *bridge = bus->self;
1071 struct pci_controller* hose = (struct pci_controller *)bridge->sysdata;
1074 struct resource res;
1076 res = *(bus->resource[0]);
1078 DBG("Remapping Bus %d, bridge: %s\n", bus->number, bridge->slot_name);
1079 res.start -= ((unsigned long) hose->io_base_virt - isa_io_base);
1080 res.end -= ((unsigned long) hose->io_base_virt - isa_io_base);
1081 DBG(" IO window: %08lx-%08lx\n", res.start, res.end);
1083 /* Set up the top and bottom of the PCI I/O segment for this bus. */
1084 pci_read_config_dword(bridge, PCI_IO_BASE, &l);
1086 l |= (res.start >> 8) & 0x00f0;
1087 l |= res.end & 0xf000;
1088 pci_write_config_dword(bridge, PCI_IO_BASE, l);
1090 if ((l & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) {
1091 l = (res.start >> 16) | (res.end & 0xffff0000);
1092 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, l);
1095 pci_read_config_word(bridge, PCI_COMMAND, &w);
1096 w |= PCI_COMMAND_IO;
1097 pci_write_config_word(bridge, PCI_COMMAND, w);
1099 #if 0 /* Enabling this causes XFree 4.2.0 to hang during PCI probe */
1101 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, &w);
1102 w |= PCI_BRIDGE_CTL_VGA;
1103 pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, w);
1108 /* This function is pretty basic and actually quite broken for the
1109 * general case, it's enough for us right now though. It's supposed
1110 * to tell us if we need to open an IO range at all or not and what
1114 check_for_io_childs(struct pci_bus *bus, struct resource* res, int *found_vga)
1116 struct list_head *ln;
1120 #define push_end(res, size) do { unsigned long __sz = (size) ; \
1121 res->end = ((res->end + __sz) / (__sz + 1)) * (__sz + 1) + __sz; \
1124 for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) {
1125 struct pci_dev *dev = pci_dev_b(ln);
1126 u16 class = dev->class >> 8;
1128 if (class == PCI_CLASS_DISPLAY_VGA ||
1129 class == PCI_CLASS_NOT_DEFINED_VGA)
1131 if (class >> 8 == PCI_BASE_CLASS_BRIDGE && dev->subordinate)
1132 rc |= check_for_io_childs(dev->subordinate, res, found_vga);
1133 if (class == PCI_CLASS_BRIDGE_CARDBUS)
1134 push_end(res, 0xfff);
1136 for (i=0; i<PCI_NUM_RESOURCES; i++) {
1138 unsigned long r_size;
1140 if (dev->class >> 8 == PCI_CLASS_BRIDGE_PCI
1141 && i >= PCI_BRIDGE_RESOURCES)
1143 r = &dev->resource[i];
1144 r_size = r->end - r->start;
1147 if (r->flags & IORESOURCE_IO && (r_size) != 0) {
1149 push_end(res, r_size);
1157 /* Here we scan all P2P bridges of a given level that have a closed
1158 * IO window. Note that the test for the presence of a VGA card should
1159 * be improved to take into account already configured P2P bridges,
1160 * currently, we don't see them and might end up configuring 2 bridges
1161 * with VGA pass through enabled
1164 do_fixup_p2p_level(struct pci_bus *bus)
1166 struct list_head *ln;
1170 for (parent_io=0; parent_io<4; parent_io++)
1171 if (bus->resource[parent_io]->flags & IORESOURCE_IO)
1176 for (ln=bus->children.next; ln != &bus->children; ln=ln->next) {
1177 struct pci_bus *b = pci_bus_b(ln);
1178 struct pci_dev *d = b->self;
1179 struct pci_controller* hose = (struct pci_controller *)d->sysdata;
1180 struct resource *res = b->resource[0];
1181 struct resource tmp_res;
1185 memset(&tmp_res, 0, sizeof(tmp_res));
1186 tmp_res.start = bus->resource[parent_io]->start;
1188 /* We don't let low addresses go through that closed P2P bridge, well,
1189 * that may not be necessary but I feel safer that way
1191 if (tmp_res.start == 0)
1192 tmp_res.start = 0x1000;
1194 if (!list_empty(&b->devices) && res && res->flags == 0 &&
1195 res != bus->resource[parent_io] &&
1196 (d->class >> 8) == PCI_CLASS_BRIDGE_PCI &&
1197 check_for_io_childs(b, &tmp_res, &found_vga)) {
1200 printk(KERN_INFO "Fixing up IO bus %s\n", b->name);
1204 printk(KERN_WARNING "Skipping VGA, already active"
1205 " on bus segment\n");
1210 pci_read_config_byte(d, PCI_IO_BASE, &io_base_lo);
1212 if ((io_base_lo & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32)
1213 max = ((unsigned long) hose->io_base_virt
1214 - isa_io_base) + 0xffffffff;
1216 max = ((unsigned long) hose->io_base_virt
1217 - isa_io_base) + 0xffff;
1220 res->flags = IORESOURCE_IO;
1221 res->name = b->name;
1223 /* Find a resource in the parent where we can allocate */
1224 for (i = 0 ; i < 4; i++) {
1225 struct resource *r = bus->resource[i];
1228 if ((r->flags & IORESOURCE_IO) == 0)
1230 DBG("Trying to allocate from %08lx, size %08lx from parent"
1231 " res %d: %08lx -> %08lx\n",
1232 res->start, res->end, i, r->start, r->end);
1234 if (allocate_resource(r, res, res->end + 1, res->start, max,
1235 res->end + 1, NULL, NULL) < 0) {
1239 do_update_p2p_io_resource(b, found_vga);
1243 do_fixup_p2p_level(b);
1248 pcibios_fixup_p2p_bridges(void)
1250 struct list_head *ln;
1252 for(ln=pci_root_buses.next; ln != &pci_root_buses; ln=ln->next) {
1253 struct pci_bus *b = pci_bus_b(ln);
1254 do_fixup_p2p_level(b);
1258 #endif /* CONFIG_PPC_PMAC */
1263 struct pci_controller *hose;
1264 struct pci_bus *bus;
1267 printk(KERN_INFO "PCI: Probing PCI hardware\n");
1269 /* Scan all of the recorded PCI controllers. */
1270 for (next_busno = 0, hose = hose_head; hose; hose = hose->next) {
1271 if (pci_assign_all_busses)
1272 hose->first_busno = next_busno;
1273 hose->last_busno = 0xff;
1274 bus = pci_scan_bus(hose->first_busno, hose->ops, hose);
1275 hose->last_busno = bus->subordinate;
1276 if (pci_assign_all_busses || next_busno <= hose->last_busno)
1277 next_busno = hose->last_busno+1;
1279 pci_bus_count = next_busno;
1281 /* OpenFirmware based machines need a map of OF bus
1282 * numbers vs. kernel bus numbers since we may have to
1285 if (pci_assign_all_busses && have_of)
1286 pcibios_make_OF_bus_map();
1288 /* Do machine dependent PCI interrupt routing */
1289 if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
1290 pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
1292 /* Call machine dependent fixup */
1293 if (ppc_md.pcibios_fixup)
1294 ppc_md.pcibios_fixup();
1296 /* Allocate and assign resources */
1297 pcibios_allocate_bus_resources(&pci_root_buses);
1298 pcibios_allocate_resources(0);
1299 pcibios_allocate_resources(1);
1300 #ifdef CONFIG_PPC_PMAC
1301 pcibios_fixup_p2p_bridges();
1302 #endif /* CONFIG_PPC_PMAC */
1303 pcibios_assign_resources();
1305 /* Call machine dependent post-init code */
1306 if (ppc_md.pcibios_after_init)
1307 ppc_md.pcibios_after_init();
1312 subsys_initcall(pcibios_init);
1314 unsigned char __init
1315 common_swizzle(struct pci_dev *dev, unsigned char *pinp)
1317 struct pci_controller *hose = dev->sysdata;
1319 if (dev->bus->number != hose->first_busno) {
1322 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
1323 /* Move up the chain of bridges. */
1324 dev = dev->bus->self;
1325 } while (dev->bus->self);
1328 /* The slot is the idsel of the last bridge. */
1330 return PCI_SLOT(dev->devfn);
1333 unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
1334 unsigned long start, unsigned long size)
1339 void __init pcibios_fixup_bus(struct pci_bus *bus)
1341 struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
1342 unsigned long io_offset;
1343 struct resource *res;
1346 io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
1347 if (bus->parent == NULL) {
1348 /* This is a host bridge - fill in its resources */
1351 bus->resource[0] = res = &hose->io_resource;
1354 printk(KERN_ERR "I/O resource not set for host"
1355 " bridge %d\n", hose->index);
1357 res->end = IO_SPACE_LIMIT;
1358 res->flags = IORESOURCE_IO;
1360 res->start += io_offset;
1361 res->end += io_offset;
1363 for (i = 0; i < 3; ++i) {
1364 res = &hose->mem_resources[i];
1368 printk(KERN_ERR "Memory resource not set for "
1369 "host bridge %d\n", hose->index);
1370 res->start = hose->pci_mem_offset;
1372 res->flags = IORESOURCE_MEM;
1374 bus->resource[i+1] = res;
1377 /* This is a subordinate bridge */
1378 pci_read_bridge_bases(bus);
1380 for (i = 0; i < 4; ++i) {
1381 if ((res = bus->resource[i]) == NULL)
1385 if (io_offset && (res->flags & IORESOURCE_IO)) {
1386 res->start += io_offset;
1387 res->end += io_offset;
1388 } else if (hose->pci_mem_offset
1389 && (res->flags & IORESOURCE_MEM)) {
1390 res->start += hose->pci_mem_offset;
1391 res->end += hose->pci_mem_offset;
1396 if (ppc_md.pcibios_fixup_bus)
1397 ppc_md.pcibios_fixup_bus(bus);
1400 char __init *pcibios_setup(char *str)
1405 /* the next one is stolen from the alpha port... */
1407 pcibios_update_irq(struct pci_dev *dev, int irq)
1409 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
1410 /* XXX FIXME - update OF device tree node interrupt property */
1413 int pcibios_enable_device(struct pci_dev *dev, int mask)
1419 if (ppc_md.pcibios_enable_device_hook)
1420 if (ppc_md.pcibios_enable_device_hook(dev, 0))
1423 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1425 for (idx=0; idx<6; idx++) {
1426 r = &dev->resource[idx];
1427 if (r->flags & IORESOURCE_UNSET) {
1428 printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
1431 if (r->flags & IORESOURCE_IO)
1432 cmd |= PCI_COMMAND_IO;
1433 if (r->flags & IORESOURCE_MEM)
1434 cmd |= PCI_COMMAND_MEMORY;
1436 if (cmd != old_cmd) {
1437 printk("PCI: Enabling device %s (%04x -> %04x)\n",
1438 pci_name(dev), old_cmd, cmd);
1439 pci_write_config_word(dev, PCI_COMMAND, cmd);
1444 struct pci_controller*
1445 pci_bus_to_hose(int bus)
1447 struct pci_controller* hose = hose_head;
1449 for (; hose; hose = hose->next)
1450 if (bus >= hose->first_busno && bus <= hose->last_busno)
1456 pci_bus_io_base(unsigned int bus)
1458 struct pci_controller *hose;
1460 hose = pci_bus_to_hose(bus);
1463 return hose->io_base_virt;
1467 pci_bus_io_base_phys(unsigned int bus)
1469 struct pci_controller *hose;
1471 hose = pci_bus_to_hose(bus);
1474 return hose->io_base_phys;
1478 pci_bus_mem_base_phys(unsigned int bus)
1480 struct pci_controller *hose;
1482 hose = pci_bus_to_hose(bus);
1485 return hose->pci_mem_offset;
1489 pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
1491 /* Hack alert again ! See comments in chrp_pci.c
1493 struct pci_controller* hose =
1494 (struct pci_controller *)pdev->sysdata;
1495 if (hose && res->flags & IORESOURCE_MEM)
1496 return res->start - hose->pci_mem_offset;
1497 /* We may want to do something with IOs here... */
1502 * Platform support for /proc/bus/pci/X/Y mmap()s,
1503 * modelled on the sparc64 implementation by Dave Miller.
1508 * Adjust vm_pgoff of VMA such that it is the physical page offset
1509 * corresponding to the 32-bit pci bus offset for DEV requested by the user.
1511 * Basically, the user finds the base address for his device which he wishes
1512 * to mmap. They read the 32-bit value from the config space base register,
1513 * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
1514 * offset parameter of mmap on /proc/bus/pci/XXX for that device.
1516 * Returns negative error code on failure, zero on success.
1518 static __inline__ int
1519 __pci_mmap_make_offset(struct pci_dev *dev, struct vm_area_struct *vma,
1520 enum pci_mmap_state mmap_state)
1522 struct pci_controller *hose = (struct pci_controller *) dev->sysdata;
1523 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1524 unsigned long size = vma->vm_end - vma->vm_start;
1526 struct resource *res;
1531 return -EINVAL; /* should never happen */
1532 if (offset + size <= offset)
1535 if (mmap_state == pci_mmap_mem) {
1536 /* PCI memory space */
1537 base = hose->pci_mem_offset;
1538 for (i = 0; i < 3; ++i) {
1539 res = &hose->mem_resources[i];
1540 if (res->flags == 0)
1542 if (offset >= res->start - base
1543 && offset + size - 1 <= res->end - base) {
1548 offset += hose->pci_mem_offset;
1551 base = (unsigned long)hose->io_base_virt - isa_io_base;
1552 res = &hose->io_resource;
1553 if (offset >= res->start - base
1554 && offset + size - 1 <= res->end - base)
1556 offset += hose->io_base_phys;
1559 vma->vm_pgoff = offset >> PAGE_SHIFT;
1564 * Set vm_flags of VMA, as appropriate for this architecture, for a pci device
1567 static __inline__ void
1568 __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
1569 enum pci_mmap_state mmap_state)
1571 vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
1575 * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
1578 static __inline__ void
1579 __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
1580 enum pci_mmap_state mmap_state, int write_combine)
1582 int prot = pgprot_val(vma->vm_page_prot);
1584 /* XXX would be nice to have a way to ask for write-through */
1585 prot |= _PAGE_NO_CACHE;
1587 prot |= _PAGE_GUARDED;
1588 vma->vm_page_prot = __pgprot(prot);
1592 * Perform the actual remap of the pages for a PCI device mapping, as
1593 * appropriate for this architecture. The region in the process to map
1594 * is described by vm_start and vm_end members of VMA, the base physical
1595 * address is found in vm_pgoff.
1596 * The pci device structure is provided so that architectures may make mapping
1597 * decisions on a per-device or per-bus basis.
1599 * Returns a negative error code on failure, zero on success.
1601 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1602 enum pci_mmap_state mmap_state,
1607 ret = __pci_mmap_make_offset(dev, vma, mmap_state);
1611 __pci_mmap_set_flags(dev, vma, mmap_state);
1612 __pci_mmap_set_pgprot(dev, vma, mmap_state, write_combine);
1614 ret = remap_page_range(vma, vma->vm_start, vma->vm_pgoff << PAGE_SHIFT,
1615 vma->vm_end - vma->vm_start, vma->vm_page_prot);
1620 /* Obsolete functions. Should be removed once the symbios driver
1624 phys_to_bus(unsigned long pa)
1626 struct pci_controller *hose;
1629 for (hose = hose_head; hose; hose = hose->next) {
1630 for (i = 0; i < 3; ++i) {
1631 if (pa >= hose->mem_resources[i].start
1632 && pa <= hose->mem_resources[i].end) {
1634 * XXX the hose->pci_mem_offset really
1635 * only applies to mem_resources[0].
1636 * We need a way to store an offset for
1637 * the others. -- paulus
1640 pa -= hose->pci_mem_offset;
1645 /* hmmm, didn't find it */
1650 pci_phys_to_bus(unsigned long pa, int busnr)
1652 struct pci_controller* hose = pci_bus_to_hose(busnr);
1655 return pa - hose->pci_mem_offset;
1659 pci_bus_to_phys(unsigned int ba, int busnr)
1661 struct pci_controller* hose = pci_bus_to_hose(busnr);
1664 return ba + hose->pci_mem_offset;
1667 /* Provide information on locations of various I/O regions in physical
1668 * memory. Do this on a per-card basis so that we choose the right
1670 * Note that the returned IO or memory base is a physical address
1673 long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
1675 struct pci_controller* hose;
1676 long result = -EOPNOTSUPP;
1678 /* Argh ! Please forgive me for that hack, but that's the
1679 * simplest way to get existing XFree to not lockup on some
1680 * G5 machines... So when something asks for bus 0 io base
1681 * (bus 0 is HT root), we return the AGP one instead.
1683 #ifdef CONFIG_PPC_PMAC
1684 if (_machine == _MACH_Pmac && machine_is_compatible("MacRISC4"))
1687 #endif /* CONFIG_PPC_PMAC */
1689 hose = pci_bus_to_hose(bus);
1694 case IOBASE_BRIDGE_NUMBER:
1695 return (long)hose->first_busno;
1697 return (long)hose->pci_mem_offset;
1699 return (long)hose->io_base_phys;
1701 return (long)isa_io_base;
1702 case IOBASE_ISA_MEM:
1703 return (long)isa_mem_base;
1710 pci_init_resource(struct resource *res, unsigned long start, unsigned long end,
1711 int flags, char *name)
1718 res->sibling = NULL;
1723 * Null PCI config access functions, for the case when we can't
1726 #define NULL_PCI_OP(rw, size, type) \
1728 null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
1730 return PCIBIOS_DEVICE_NOT_FOUND; \
1734 null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
1737 return PCIBIOS_DEVICE_NOT_FOUND;
1741 null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
1744 return PCIBIOS_DEVICE_NOT_FOUND;
1747 static struct pci_ops null_pci_ops =
1754 * These functions are used early on before PCI scanning is done
1755 * and all of the pci_dev and pci_bus structures have been created.
1757 static struct pci_bus *
1758 fake_pci_bus(struct pci_controller *hose, int busnr)
1760 static struct pci_bus bus;
1763 hose = pci_bus_to_hose(busnr);
1765 printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
1769 bus.ops = hose? hose->ops: &null_pci_ops;
1773 #define EARLY_PCI_OP(rw, size, type) \
1774 int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
1775 int devfn, int offset, type value) \
1777 return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
1778 devfn, offset, value); \
1781 EARLY_PCI_OP(read, byte, u8 *)
1782 EARLY_PCI_OP(read, word, u16 *)
1783 EARLY_PCI_OP(read, dword, u32 *)
1784 EARLY_PCI_OP(write, byte, u8)
1785 EARLY_PCI_OP(write, word, u16)
1786 EARLY_PCI_OP(write, dword, u32)