diff mbox

[U-Boot,v5,1/4] dm: pci: Add an inline API to test if a device is on a PCI bus

Message ID 1441967077-20231-1-git-send-email-bmeng.cn@gmail.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Bin Meng Sept. 11, 2015, 10:24 a.m. UTC
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 <bmeng.cn@gmail.com>

---

Changes in v5:
- Move the inline API from include/pci.h to include/dm/device.h to
  resolve the cyclic dependency

Changes in v3: None
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/dm/device.h      | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

Comments

Simon Glass Sept. 15, 2015, 1:51 p.m. UTC | #1
On 11 September 2015 at 04:24, Bin Meng <bmeng.cn@gmail.com> wrote:
> 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 <bmeng.cn@gmail.com>
>
> ---
>
> Changes in v5:
> - Move the inline API from include/pci.h to include/dm/device.h to
>   resolve the cyclic dependency
>
> Changes in v3: None
> 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/dm/device.h      | 11 +++++++++++
>  2 files changed, 13 insertions(+), 2 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass Sept. 17, 2015, 6:52 p.m. UTC | #2
On 15 September 2015 at 07:51, Simon Glass <sjg@chromium.org> wrote:
> On 11 September 2015 at 04:24, Bin Meng <bmeng.cn@gmail.com> wrote:
>> 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 <bmeng.cn@gmail.com>
>>
>> ---
>>
>> Changes in v5:
>> - Move the inline API from include/pci.h to include/dm/device.h to
>>   resolve the cyclic dependency
>>
>> Changes in v3: None
>> 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/dm/device.h      | 11 +++++++++++
>>  2 files changed, 13 insertions(+), 2 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-x86, thanks!
diff mbox

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index ea70853..0756bbe 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -238,7 +238,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);
 }
@@ -303,7 +303,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/dm/device.h b/include/dm/device.h
index a239be6..8519612 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -485,6 +485,17 @@  bool device_is_last_sibling(struct udevice *dev);
  */
 int device_set_name(struct udevice *dev, const char *name);
 
+/**
+ * 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;
+}
+
 /* device resource management */
 typedef void (*dr_release_t)(struct udevice *dev, void *res);
 typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);