diff options
| author | Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | 2011-01-23 23:28:55 -0500 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2011-02-04 13:46:50 -0500 |
| commit | 04bea68b2f0eeebb089ecc67b618795925268b4a (patch) | |
| tree | 80380294ee7e073fe312af590475dc4756826094 /drivers | |
| parent | c64eae9a73a847c1698f913c893aa4012d2a30b0 (diff) | |
of/pci: move of_irq_map_pci() into generic code
There is a tiny difference between PPC32 and PPC64. Microblaze uses the
PPC32 variant.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
[grant.likely@secretlab.ca: Added comment to #endif, moved documentation
block to function implementation, fixed for non ppc and microblaze
compiles]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/of/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/of/Makefile | 1 | ||||
| -rw-r--r-- | drivers/of/of_pci.c | 91 |
3 files changed, 98 insertions, 0 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 3c6e100a3ad0..efabbf9dd607 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
| @@ -69,4 +69,10 @@ config OF_MDIO | |||
| 69 | help | 69 | help |
| 70 | OpenFirmware MDIO bus (Ethernet PHY) accessors | 70 | OpenFirmware MDIO bus (Ethernet PHY) accessors |
| 71 | 71 | ||
| 72 | config OF_PCI | ||
| 73 | def_tristate PCI | ||
| 74 | depends on PCI && (PPC || MICROBLAZE) | ||
| 75 | help | ||
| 76 | OpenFirmware PCI bus accessors | ||
| 77 | |||
| 72 | endmenu # OF | 78 | endmenu # OF |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 3ab21a0a4907..f7861ed2f287 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
| @@ -9,3 +9,4 @@ obj-$(CONFIG_OF_I2C) += of_i2c.o | |||
| 9 | obj-$(CONFIG_OF_NET) += of_net.o | 9 | obj-$(CONFIG_OF_NET) += of_net.o |
| 10 | obj-$(CONFIG_OF_SPI) += of_spi.o | 10 | obj-$(CONFIG_OF_SPI) += of_spi.o |
| 11 | obj-$(CONFIG_OF_MDIO) += of_mdio.o | 11 | obj-$(CONFIG_OF_MDIO) += of_mdio.o |
| 12 | obj-$(CONFIG_OF_PCI) += of_pci.o | ||
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c new file mode 100644 index 000000000000..314535fa32c1 --- /dev/null +++ b/drivers/of/of_pci.c | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | #include <linux/kernel.h> | ||
| 2 | #include <linux/of_pci.h> | ||
| 3 | #include <asm/prom.h> | ||
| 4 | |||
| 5 | /** | ||
| 6 | * of_irq_map_pci - Resolve the interrupt for a PCI device | ||
| 7 | * @pdev: the device whose interrupt is to be resolved | ||
| 8 | * @out_irq: structure of_irq filled by this function | ||
| 9 | * | ||
| 10 | * This function resolves the PCI interrupt for a given PCI device. If a | ||
| 11 | * device-node exists for a given pci_dev, it will use normal OF tree | ||
| 12 | * walking. If not, it will implement standard swizzling and walk up the | ||
| 13 | * PCI tree until an device-node is found, at which point it will finish | ||
| 14 | * resolving using the OF tree walking. | ||
| 15 | */ | ||
| 16 | int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq) | ||
| 17 | { | ||
| 18 | struct device_node *dn, *ppnode; | ||
| 19 | struct pci_dev *ppdev; | ||
| 20 | u32 lspec; | ||
| 21 | __be32 lspec_be; | ||
| 22 | __be32 laddr[3]; | ||
| 23 | u8 pin; | ||
| 24 | int rc; | ||
| 25 | |||
| 26 | /* Check if we have a device node, if yes, fallback to standard | ||
| 27 | * device tree parsing | ||
| 28 | */ | ||
| 29 | dn = pci_device_to_OF_node(pdev); | ||
| 30 | if (dn) { | ||
| 31 | rc = of_irq_map_one(dn, 0, out_irq); | ||
| 32 | if (!rc) | ||
| 33 | return rc; | ||
| 34 | } | ||
| 35 | |||
| 36 | /* Ok, we don't, time to have fun. Let's start by building up an | ||
| 37 | * interrupt spec. we assume #interrupt-cells is 1, which is standard | ||
| 38 | * for PCI. If you do different, then don't use that routine. | ||
| 39 | */ | ||
| 40 | rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin); | ||
| 41 | if (rc != 0) | ||
| 42 | return rc; | ||
| 43 | /* No pin, exit */ | ||
| 44 | if (pin == 0) | ||
| 45 | return -ENODEV; | ||
| 46 | |||
| 47 | /* Now we walk up the PCI tree */ | ||
| 48 | lspec = pin; | ||
| 49 | for (;;) { | ||
| 50 | /* Get the pci_dev of our parent */ | ||
| 51 | ppdev = pdev->bus->self; | ||
| 52 | |||
| 53 | /* Ouch, it's a host bridge... */ | ||
| 54 | if (ppdev == NULL) { | ||
| 55 | ppnode = pci_bus_to_OF_node(pdev->bus); | ||
| 56 | |||
| 57 | /* No node for host bridge ? give up */ | ||
| 58 | if (ppnode == NULL) | ||
| 59 | return -EINVAL; | ||
| 60 | } else { | ||
| 61 | /* We found a P2P bridge, check if it has a node */ | ||
| 62 | ppnode = pci_device_to_OF_node(ppdev); | ||
| 63 | } | ||
| 64 | |||
| 65 | /* Ok, we have found a parent with a device-node, hand over to | ||
| 66 | * the OF parsing code. | ||
| 67 | * We build a unit address from the linux device to be used for | ||
| 68 | * resolution. Note that we use the linux bus number which may | ||
| 69 | * not match your firmware bus numbering. | ||
| 70 | * Fortunately, in most cases, interrupt-map-mask doesn't | ||
| 71 | * include the bus number as part of the matching. | ||
| 72 | * You should still be careful about that though if you intend | ||
| 73 | * to rely on this function (you ship a firmware that doesn't | ||
| 74 | * create device nodes for all PCI devices). | ||
| 75 | */ | ||
| 76 | if (ppnode) | ||
| 77 | break; | ||
| 78 | |||
| 79 | /* We can only get here if we hit a P2P bridge with no node, | ||
| 80 | * let's do standard swizzling and try again | ||
| 81 | */ | ||
| 82 | lspec = pci_swizzle_interrupt_pin(pdev, lspec); | ||
| 83 | pdev = ppdev; | ||
| 84 | } | ||
| 85 | |||
| 86 | lspec_be = cpu_to_be32(lspec); | ||
| 87 | laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); | ||
| 88 | laddr[1] = laddr[2] = cpu_to_be32(0); | ||
| 89 | return of_irq_map_raw(ppnode, &lspec_be, 1, laddr, out_irq); | ||
| 90 | } | ||
| 91 | EXPORT_SYMBOL_GPL(of_irq_map_pci); | ||
