Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/83644?usp=email )
Change subject: device: introduce and use dev_get_domain_id ......................................................................
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 --- M src/device/device_util.c M src/include/device/device.h M src/soc/amd/common/block/data_fabric/domain.c M src/soc/amd/common/block/data_fabric/pci_segment_multi.c M src/soc/amd/common/block/data_fabric/pci_segment_single.c M src/soc/amd/common/block/root_complex/root_complex.c M src/soc/amd/genoa_poc/domain.c M src/soc/intel/xeon_sp/acpi.c M src/soc/intel/xeon_sp/chip_common.c M src/soc/intel/xeon_sp/chip_gen1.c M src/soc/intel/xeon_sp/chip_gen6.c M src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c 12 files changed, 31 insertions(+), 14 deletions(-)
Approvals: Shuo Liu: Looks good to me, approved build bot (Jenkins): Verified
diff --git a/src/device/device_util.c b/src/device/device_util.c index 2e97ece..22dc5f7 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 @@ 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; diff --git a/src/include/device/device.h b/src/include/device/device.h index ac8a117..3eee321 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -183,6 +183,7 @@ const char *dev_path(const struct device *dev); u32 dev_path_encode(const struct device *dev); const struct device *dev_get_domain(const struct device *dev); +unsigned int dev_get_domain_id(const struct device *dev); void dev_set_enabled(struct device *dev, int enable); void disable_children(struct bus *bus); bool dev_is_active_bridge(struct device *dev); diff --git a/src/soc/amd/common/block/data_fabric/domain.c b/src/soc/amd/common/block/data_fabric/domain.c index c419fe0..12a7bba 100644 --- a/src/soc/amd/common/block/data_fabric/domain.c +++ b/src/soc/amd/common/block/data_fabric/domain.c @@ -22,7 +22,7 @@
if (segment_group >= PCI_SEGMENT_GROUP_COUNT) { printk(BIOS_ERR, "Skipping domain %u due to too large segment group %u.\n", - domain->path.domain.domain, segment_group); + dev_get_domain_id(domain), segment_group); return; }
diff --git a/src/soc/amd/common/block/data_fabric/pci_segment_multi.c b/src/soc/amd/common/block/data_fabric/pci_segment_multi.c index bc680f9..433b004 100644 --- a/src/soc/amd/common/block/data_fabric/pci_segment_multi.c +++ b/src/soc/amd/common/block/data_fabric/pci_segment_multi.c @@ -29,6 +29,6 @@ }
printk(BIOS_ERR, "No valid DF PCI CFG register pair found for domain %x.\n", - domain->path.domain.domain); + dev_get_domain_id(domain)); return CB_ERR; } diff --git a/src/soc/amd/common/block/data_fabric/pci_segment_single.c b/src/soc/amd/common/block/data_fabric/pci_segment_single.c index 3e02d96..49e6b9a 100644 --- a/src/soc/amd/common/block/data_fabric/pci_segment_single.c +++ b/src/soc/amd/common/block/data_fabric/pci_segment_single.c @@ -27,6 +27,6 @@ }
printk(BIOS_ERR, "No valid DF PCI CFG register found for domain %x.\n", - domain->path.domain.domain); + dev_get_domain_id(domain)); return CB_ERR; } diff --git a/src/soc/amd/common/block/root_complex/root_complex.c b/src/soc/amd/common/block/root_complex/root_complex.c index 2bcdc1d..72eba8a 100644 --- a/src/soc/amd/common/block/root_complex/root_complex.c +++ b/src/soc/amd/common/block/root_complex/root_complex.c @@ -7,7 +7,7 @@
static const struct domain_iohc_info *get_domain_iohc_info(struct device *domain) { - const unsigned int domain_id = domain->path.domain.domain; + const unsigned int domain_id = dev_get_domain_id(domain); const struct domain_iohc_info *iohc; size_t iohc_count;
diff --git a/src/soc/amd/genoa_poc/domain.c b/src/soc/amd/genoa_poc/domain.c index 88f386c..b6369a4 100644 --- a/src/soc/amd/genoa_poc/domain.c +++ b/src/soc/amd/genoa_poc/domain.c @@ -26,7 +26,7 @@ { if (domain->downstream->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { printk(BIOS_DEBUG, "Setting VGA decoding for domain 0x%x\n", - domain->path.domain.domain); + dev_get_domain_id(domain)); const union df_vga_en vga_en = { .ve = 1, .dst_fabric_id = get_iohc_fabric_id(domain), @@ -48,6 +48,7 @@
static const char *genoa_domain_acpi_name(const struct device *domain) { + const unsigned int domain_id = dev_get_domain_id(domain); const char *domain_acpi_names[4] = { "S0B0", "S0B1", @@ -55,8 +56,8 @@ "S0B3", };
- if (domain->path.domain.domain < ARRAY_SIZE(domain_acpi_names)) - return domain_acpi_names[domain->path.domain.domain]; + if (domain_id < ARRAY_SIZE(domain_acpi_names)) + return domain_acpi_names[domain_id];
return NULL; } diff --git a/src/soc/intel/xeon_sp/acpi.c b/src/soc/intel/xeon_sp/acpi.c index f66f5e9..e5cf907 100644 --- a/src/soc/intel/xeon_sp/acpi.c +++ b/src/soc/intel/xeon_sp/acpi.c @@ -95,7 +95,7 @@ void iio_domain_set_acpi_name(struct device *dev, const char *prefix) { const union xeon_domain_path dn = { - .domain_path = dev->path.domain.domain + .domain_path = dev_get_domain_id(dev) };
assert(dn.socket < CONFIG_MAX_SOCKET); diff --git a/src/soc/intel/xeon_sp/chip_common.c b/src/soc/intel/xeon_sp/chip_common.c index d0eab02..011e1c3 100644 --- a/src/soc/intel/xeon_sp/chip_common.c +++ b/src/soc/intel/xeon_sp/chip_common.c @@ -49,7 +49,7 @@ return 0;
union xeon_domain_path dn; - dn.domain_path = domain->path.domain.domain; + dn.domain_path = dev_get_domain_id(domain);
if (socket != XEONSP_SOCKET_MAX && dn.socket != socket) return 0; @@ -140,7 +140,7 @@ if (!domain) return -1;
- dn.domain_path = domain->path.domain.domain; + dn.domain_path = dev_get_domain_id(domain);
return dn.socket; } @@ -162,7 +162,7 @@ if (!domain) return -1;
- dn.domain_path = domain->path.domain.domain; + dn.domain_path = dev_get_domain_id(domain);
return dn.stack; } diff --git a/src/soc/intel/xeon_sp/chip_gen1.c b/src/soc/intel/xeon_sp/chip_gen1.c index a68c764..ee167e2 100644 --- a/src/soc/intel/xeon_sp/chip_gen1.c +++ b/src/soc/intel/xeon_sp/chip_gen1.c @@ -17,7 +17,7 @@ { assert(dev->path.type == DEVICE_PATH_DOMAIN); const union xeon_domain_path dn = { - .domain_path = dev->path.domain.domain + .domain_path = dev_get_domain_id(dev) };
const IIO_UDS *hob = get_iio_uds(); diff --git a/src/soc/intel/xeon_sp/chip_gen6.c b/src/soc/intel/xeon_sp/chip_gen6.c index 686b3e4..d53b231 100644 --- a/src/soc/intel/xeon_sp/chip_gen6.c +++ b/src/soc/intel/xeon_sp/chip_gen6.c @@ -16,7 +16,7 @@ { assert(dev->path.type == DEVICE_PATH_DOMAIN); const union xeon_domain_path dn = { - .domain_path = dev->path.domain.domain + .domain_path = dev_get_domain_id(dev) };
const IIO_UDS *hob = get_iio_uds(); diff --git a/src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c b/src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c index 609ac55..b371034 100644 --- a/src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c +++ b/src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c @@ -128,7 +128,7 @@ static void per_device_config(MPIOCLASS_INPUT_BLK *mpio_data, struct device *dev) { static uint32_t slot_num; - const uint32_t domain = dev->upstream->dev->path.domain.domain; + const uint32_t domain = dev_get_domain_id(dev); const uint32_t devfn = dev->path.pci.devfn; const struct vendorcode_amd_opensil_chip_mpio_config *const config = dev->chip_info; printk(BIOS_DEBUG, "Setting MPIO port for domain 0x%x, PCI %d:%d\n",