Skip to content

Commit

Permalink
of/irq: Create of_irq_parse_and_map_pci() to consolidate arch code.
Browse files Browse the repository at this point in the history
Several architectures open code effectively the same code block for
finding and mapping PCI irqs. This patch consolidates it down to a
single function.

Signed-off-by: Grant Likely <[email protected]>
Acked-by: Michal Simek <[email protected]>
Cc: Russell King <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
  • Loading branch information
glikely committed Oct 24, 2013
1 parent f757849 commit 16b84e5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 67 deletions.
17 changes: 1 addition & 16 deletions arch/arm/mach-integrator/pci_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,21 +835,6 @@ static struct hw_pci pci_v3 __initdata = {

#ifdef CONFIG_OF

static int __init pci_v3_map_irq_dt(const struct pci_dev *dev, u8 slot, u8 pin)
{
struct of_phandle_args oirq;
int ret;

ret = of_irq_parse_pci(dev, &oirq);
if (ret) {
dev_err(&dev->dev, "of_irq_parse_pci() %d\n", ret);
/* Proper return code 0 == NO_IRQ */
return 0;
}

return irq_create_of_mapping(&oirq);
}

static int __init pci_v3_dtprobe(struct platform_device *pdev,
struct device_node *np)
{
Expand Down Expand Up @@ -918,7 +903,7 @@ static int __init pci_v3_dtprobe(struct platform_device *pdev,
return -EINVAL;
}

pci_v3.map_irq = pci_v3_map_irq_dt;
pci_v3.map_irq = of_irq_parse_and_map_pci;
pci_common_init_dev(&pdev->dev, &pci_v3);

return 0;
Expand Down
12 changes: 1 addition & 11 deletions arch/mips/pci/fixup-lantiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,5 @@ int pcibios_plat_dev_init(struct pci_dev *dev)

int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
struct of_phandle_args dev_irq;
int irq;

if (of_irq_parse_pci(dev, &dev_irq)) {
dev_err(&dev->dev, "trying to map irq for unknown slot:%d pin:%d\n",
slot, pin);
return 0;
}
irq = irq_create_of_mapping(&dev_irq);
dev_info(&dev->dev, "SLOT:%d PIN:%d IRQ:%d\n", slot, pin, irq);
return irq;
return of_irq_parse_and_map_pci(dev, slot, pin);
}
22 changes: 1 addition & 21 deletions arch/mips/pci/pci-rt3883.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,27 +583,7 @@ static int rt3883_pci_probe(struct platform_device *pdev)

int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
struct of_phandle_args dev_irq;
int err;
int irq;

err = of_irq_parse_pci(dev, &dev_irq);
if (err) {
pr_err("pci %s: unable to get irq map, err=%d\n",
pci_name((struct pci_dev *) dev), err);
return 0;
}

irq = irq_create_of_mapping(&dev_irq);

if (irq == 0)
pr_crit("pci %s: no irq found for pin %u\n",
pci_name((struct pci_dev *) dev), pin);
else
pr_info("pci %s: using irq %d for pin %u\n",
pci_name((struct pci_dev *) dev), irq, pin);

return irq;
return of_irq_parse_and_map_pci(dev, slot, pin);
}

int pcibios_plat_dev_init(struct pci_dev *dev)
Expand Down
7 changes: 1 addition & 6 deletions arch/x86/kernel/devicetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)

static int x86_of_pci_irq_enable(struct pci_dev *dev)
{
struct of_phandle_args oirq;
u32 virq;
int ret;
u8 pin;
Expand All @@ -116,11 +115,7 @@ static int x86_of_pci_irq_enable(struct pci_dev *dev)
if (!pin)
return 0;

ret = of_irq_parse_pci(dev, &oirq);
if (ret)
return ret;

virq = irq_create_of_mapping(&oirq);
virq = of_irq_parse_and_map_pci(dev, 0, 0);
if (virq == 0)
return -EINVAL;
dev->irq = virq;
Expand Down
25 changes: 25 additions & 0 deletions drivers/of/of_pci_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,28 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq
return of_irq_parse_raw(laddr, out_irq);
}
EXPORT_SYMBOL_GPL(of_irq_parse_pci);

/**
* of_irq_parse_and_map_pci() - Decode a PCI irq from the device tree and map to a virq
* @dev: The pci device needing an irq
* @slot: PCI slot number; passed when used as map_irq callback. Unused
* @pin: PCI irq pin number; passed when used as map_irq callback. Unused
*
* @slot and @pin are unused, but included in the function so that this
* function can be used directly as the map_irq callback to pci_fixup_irqs().
*/
int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
{
struct of_phandle_args oirq;
int ret;

ret = of_irq_parse_pci(dev, &oirq);
if (ret) {
dev_err(&dev->dev, "of_irq_parse_pci() failed with rc=%d\n", ret);
return 0; /* Proper return code 0 == NO_IRQ */
}

return irq_create_of_mapping(&oirq);
}
EXPORT_SYMBOL_GPL(of_irq_parse_and_map_pci);

14 changes: 1 addition & 13 deletions drivers/pci/host/pci-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,18 +645,6 @@ static int __init mvebu_pcie_setup(int nr, struct pci_sys_data *sys)
return 1;
}

static int __init mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
struct of_phandle_args oirq;
int ret;

ret = of_irq_parse_pci(dev, &oirq);
if (ret)
return ret;

return irq_create_of_mapping(&oirq);
}

static struct pci_bus *mvebu_pcie_scan_bus(int nr, struct pci_sys_data *sys)
{
struct mvebu_pcie *pcie = sys_to_pcie(sys);
Expand Down Expand Up @@ -705,7 +693,7 @@ static void __init mvebu_pcie_enable(struct mvebu_pcie *pcie)
hw.private_data = (void **)&pcie;
hw.setup = mvebu_pcie_setup;
hw.scan = mvebu_pcie_scan_bus;
hw.map_irq = mvebu_pcie_map_irq;
hw.map_irq = of_irq_parse_and_map_pci;
hw.ops = &mvebu_pcie_ops;
hw.align_resource = mvebu_pcie_align_resource;

Expand Down
1 change: 1 addition & 0 deletions include/linux/of_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
struct pci_dev;
struct of_phandle_args;
int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq);
int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);

struct device_node;
struct device_node *of_pci_find_child_device(struct device_node *parent,
Expand Down

0 comments on commit 16b84e5

Please sign in to comment.