Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4001297 authored by Tony Truong's avatar Tony Truong
Browse files

pci/of: expand match PCI devices to OF nodes



Expand match criteria so that multiple OF nodes with
the same BDF will match with the correct PCI device.
OF node will have a compatible entry with device and
vendor ID, which will be matched to a PCI device and
vendor ID.

Change-Id: I6e654d5dbf55a05b4e1b6a60d5d87addc2cb14b9
Signed-off-by: default avatarTony Truong <truong@codeaurora.org>
parent c28328bd
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -8,6 +8,20 @@
#include <linux/of_pci.h>
#include <linux/slab.h>

static inline bool __of_pci_pci_compare_id(struct device_node *node,
					struct pci_dev *dev)
{
	char dev_id_str[10];

	scnprintf(dev_id_str, sizeof(dev_id_str), "%04x:%04x", dev->vendor,
		dev->device);

	if (of_property_match_string(node, "pci-ids", dev_id_str) < 0)
		return false;

	return true;
}

static inline int __of_pci_pci_compare(struct device_node *node,
				       unsigned int data)
{
@@ -20,14 +34,17 @@ static inline int __of_pci_pci_compare(struct device_node *node,
	return devfn == data;
}

struct device_node *of_pci_find_child_device(struct device_node *parent,
					     unsigned int devfn)
struct device_node *of_pci_find_child_device(struct pci_dev *dev)
{
	struct device_node *node, *node2;
	struct device_node *parent = dev->bus->dev.of_node;
	unsigned int devfn = dev->devfn;

	for_each_child_of_node(parent, node) {
		if (__of_pci_pci_compare(node, devfn))
			if (__of_pci_pci_compare_id(node, dev))
				return node;

		/*
		 * Some OFs create a parent node "multifunc-device" as
		 * a fake root for all functions of a multi-function
+1 −2
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@ void pci_set_of_node(struct pci_dev *dev)
{
	if (!dev->bus->dev.of_node)
		return;
	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
						    dev->devfn);
	dev->dev.of_node = of_pci_find_child_device(dev);

	if (dev->dev.of_node)
		of_reserved_mem_device_init_by_idx(&dev->dev, dev->dev.of_node,
+2 −4
Original line number Diff line number Diff line
@@ -11,8 +11,7 @@ struct device_node;

#ifdef CONFIG_OF_PCI
int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq);
struct device_node *of_pci_find_child_device(struct device_node *parent,
					     unsigned int devfn);
struct device_node *of_pci_find_child_device(struct pci_dev *dev);
int of_pci_get_devfn(struct device_node *np);
int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
@@ -28,8 +27,7 @@ static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle
	return 0;
}

static inline struct device_node *of_pci_find_child_device(struct device_node *parent,
					     unsigned int devfn)
static inline struct device_node *of_pci_find_child_device(struct pci_dev *dev)
{
	return NULL;
}