Lean Sheng Tan submitted this change.

View Change

Approvals: Nico Huber: Looks good to me, but someone else must approve build bot (Jenkins): Verified Arthur Heymans: Looks good to me, approved
device: Add inline method to identify PATH_ROOT

Add and use inline method to identify the root device.

Change-Id: I394c8668245bcfea6414b8ca5f14ef8135897e59
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/80169
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
---
M src/acpi/device.c
M src/drivers/usb/pci_xhci/pci_xhci.c
M src/include/device/device.h
3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/acpi/device.c b/src/acpi/device.c
index 92000a3..823cdbeb 100644
--- a/src/acpi/device.c
+++ b/src/acpi/device.c
@@ -87,7 +87,7 @@
pdev = pdev->bus->dev;
if (!pdev)
break;
- if (pdev->path.type == DEVICE_PATH_ROOT)
+ if (is_root_device(pdev))
break;
if (pdev->ops && pdev->ops->acpi_name)
name = pdev->ops->acpi_name(dev);
@@ -147,16 +147,15 @@
return cur;

/* Walk up the tree to the root device */
- if (dev->path.type != DEVICE_PATH_ROOT && dev->bus && dev->bus->dev)
+ if (!is_root_device(dev) && dev->bus && dev->bus->dev)
next = acpi_device_path_fill(dev->bus->dev, buf, buf_len, cur);
if (next < 0)
return next;

/* Fill in the path from the root device */
next += snprintf(buf + next, buf_len - next, "%s%s",
- (dev->path.type == DEVICE_PATH_ROOT
- || (strlen(name) == 0)) ?
- "" : ".", name);
+ (is_root_device(dev) || (strlen(name) == 0)) ?
+ "" : ".", name);

return next;
}
diff --git a/src/drivers/usb/pci_xhci/pci_xhci.c b/src/drivers/usb/pci_xhci/pci_xhci.c
index 6d022d1..398595d 100644
--- a/src/drivers/usb/pci_xhci/pci_xhci.c
+++ b/src/drivers/usb/pci_xhci/pci_xhci.c
@@ -73,7 +73,7 @@
static const struct device *get_xhci_dev(const struct device *dev)
{
while (dev && dev->ops != &xhci_pci_ops) {
- if (dev->path.type == DEVICE_PATH_ROOT)
+ if (is_root_device(dev))
return NULL;

dev = dev->bus->dev;
diff --git a/src/include/device/device.h b/src/include/device/device.h
index cd0999a..863299c 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -458,6 +458,15 @@
*/
#define config_of_soc() __pci_0_00_0_config

+static inline bool is_root_device(const struct device *dev)
+{
+ if (!dev || !dev->bus)
+ return false;
+
+ return (dev->path.type == DEVICE_PATH_ROOT) ||
+ (dev->bus->dev == dev);
+}
+
void enable_static_device(struct device *dev);
void enable_static_devices(struct device *bus);
void scan_smbus(struct device *bus);

To view, visit change 80169. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: I394c8668245bcfea6414b8ca5f14ef8135897e59
Gerrit-Change-Number: 80169
Gerrit-PatchSet: 2
Gerrit-Owner: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-Reviewer: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: Cliff Huang <cliff.huang@intel.com>
Gerrit-Reviewer: Felix Held <felix-coreboot@felixheld.de>
Gerrit-Reviewer: Lance Zhao <lance.zhao@gmail.com>
Gerrit-Reviewer: Lean Sheng Tan <sheng.tan@9elements.com>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Tim Wawrzynczak <inforichland@gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged