From: Bin Meng Date: Wed, 2 Sep 2015 02:17:36 -0700 Subject: [U-Boot] [PATCH v2 08/11] dm: pci: Add an inline API to test if a device is on a PCI bus In-Reply-To: <1441185460-31362-1-git-send-email-bmeng.cn@gmail.com> References: <1441185460-31362-1-git-send-email-bmeng.cn@gmail.com> Message-ID: <1441185460-31362-9-git-send-email-bmeng.cn@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Introduce device_is_on_pci_bus() which can be utilized by driver to test if a device is on a PCI bus. Signed-off-by: Bin Meng --- Changes in v2: - New patch to add an inline API to test if a device is on a PCI bus drivers/pci/pci-uclass.c | 4 ++-- include/pci.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index b25298f..79a05cb 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -218,7 +218,7 @@ int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value, { struct udevice *bus; - for (bus = dev; device_get_uclass_id(bus->parent) == UCLASS_PCI;) + for (bus = dev; device_is_on_pci_bus(bus);) bus = bus->parent; return pci_bus_write_config(bus, pci_get_bdf(dev), offset, value, size); } @@ -283,7 +283,7 @@ int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep, { struct udevice *bus; - for (bus = dev; device_get_uclass_id(bus->parent) == UCLASS_PCI;) + for (bus = dev; device_is_on_pci_bus(bus);) bus = bus->parent; return pci_bus_read_config(bus, pci_get_bdf(dev), offset, valuep, size); diff --git a/include/pci.h b/include/pci.h index e24c970..293a021 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1273,5 +1273,20 @@ struct pci_driver_entry { .match = __match, \ } +#ifdef CONFIG_DM +#include + +/** + * device_is_on_pci_bus - Test if a device is on a PCI bus + * + * @dev: device to test + * @return: true if it is on a PCI bus, false otherwise + */ +static inline bool device_is_on_pci_bus(struct udevice *dev) +{ + return device_get_uclass_id(dev->parent) == UCLASS_PCI; +} +#endif + #endif /* __ASSEMBLY__ */ #endif /* _PCI_H */ -- 1.8.2.1