diff options
author | Felix Held <felix-coreboot@felixheld.de> | 2024-07-25 00:05:53 +0200 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2024-07-31 14:32:19 +0000 |
commit | 32c38ca221ff5956a81026fd0e5df330d569fcca (patch) | |
tree | 57a07c42f641a94c51d4f71496ca8b00ec79007d /src/device | |
parent | 2c31e86d6b7456d542ed96eeef7cc797ddd62a8b (diff) |
device: introduce and use dev_get_domain_id
To avoid having constructs like 'dev->path.domain.domain' in the SoC
code, create the 'dev_get_domain_id' helper function that returns the
domain ID of either that device if it's a domain device or the
corresponding domain device's domain ID, and use it in the code.
If this function is called with a device other than PCI or domain type,
it won't have a domain number. In order to not need to call 'die',
'dev_get_domain_id' will print an error and return 0 which is a valid
domain number. In that case, the calling code should be fixed.
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I3d79f19846cea49609f848a4c42747ac1052c288
Reviewed-on: https://review.coreboot.org/c/coreboot/+/83644
Reviewed-by: Shuo Liu <shuo.liu@intel.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/device_util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/device/device_util.c b/src/device/device_util.c index 2e97ece2a5..22dc5f7499 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include <assert.h> #include <commonlib/bsd/helpers.h> #include <console/console.h> #include <device/device.h> @@ -261,6 +262,20 @@ const struct device *dev_get_domain(const struct device *dev) return NULL; } +unsigned int dev_get_domain_id(const struct device *dev) +{ + const struct device *domain_dev = dev_get_domain(dev); + + assert(domain_dev); + + if (!domain_dev) { + printk(BIOS_ERR, "%s: doesn't have a domain device\n", dev_path(dev)); + return 0; + } + + return domain_dev->path.domain.domain; +} + bool is_domain0(const struct device *dev) { return dev && dev->path.type == DEVICE_PATH_DOMAIN && dev->path.domain.domain == 0; |