From 9fa4048e2deccd63d0e225152ae6a06e8c767865 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Thu, 18 Jan 2024 08:55:08 +0100 Subject: soc/intel/xeon_sp: Add helper functions Provide a helper function to locate PCI devices on a given socket by their PCI vendor and device IDs and functions to return information about the current device, like the corresponding stack and socket. In addition add functions to return "location" information, like stack and socket affiliation. This becomes handy when locating devices and generating ACPI code. Change-Id: I266360588548ba579f46b228c4d5b3ae6e39a029 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/80094 Reviewed-by: Arthur Heymans Tested-by: build bot (Jenkins) Reviewed-by: Shuo Liu Reviewed-by: Paul Menzel --- src/soc/intel/xeon_sp/chip_common.c | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/soc/intel/xeon_sp/chip_common.c') diff --git a/src/soc/intel/xeon_sp/chip_common.c b/src/soc/intel/xeon_sp/chip_common.c index 08d723bffd..0c1d52bc86 100644 --- a/src/soc/intel/xeon_sp/chip_common.c +++ b/src/soc/intel/xeon_sp/chip_common.c @@ -22,6 +22,86 @@ static const STACK_RES *domain_to_stack_res(const struct device *dev) return &hob->PlatformData.IIO_resource[dn.socket].StackRes[dn.stack]; } +/** + * Find a device of a given vendor and type for the specified socket. + * The function iterates over all PCI domains of the specified socket + * and matches the PCI vendor and device ID. + * + * @param socket The socket where to search for the device. + * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel). + * @param device A PCI device ID. + * @return Pointer to the device struct. + */ +struct device *dev_find_device_on_socket(uint8_t socket, u16 vendor, u16 device) +{ + struct device *domain, *dev = NULL; + union xeon_domain_path dn; + + while ((dev = dev_find_device(vendor, device, dev))) { + domain = dev_get_pci_domain(dev); + if (!domain) + continue; + dn.domain_path = domain->path.domain.domain; + if (dn.socket != socket) + continue; + return dev; + } + + return NULL; +} + +/** + * Returns the socket ID where the specified device is connected to. + * This is an integer in the range [0, CONFIG_MAX_SOCKET). + * + * @param dev The device to look up + * + * @return Socket ID the device is attached to, negative number on error. + */ +int iio_pci_domain_socket_from_dev(struct device *dev) +{ + struct device *domain; + union xeon_domain_path dn; + + if (dev->path.type == DEVICE_PATH_DOMAIN) + domain = dev; + else + domain = dev_get_pci_domain(dev); + + if (!domain) + return -1; + + dn.domain_path = domain->path.domain.domain; + + return dn.socket; +} + +/** + * Returns the stack ID where the specified device is connected to. + * This is an integer in the range [0, MAX_IIO_STACK). + * + * @param dev The device to look up + * + * @return Stack ID the device is attached to, negative number on error. + */ +int iio_pci_domain_stack_from_dev(struct device *dev) +{ + struct device *domain; + union xeon_domain_path dn; + + if (dev->path.type == DEVICE_PATH_DOMAIN) + domain = dev; + else + domain = dev_get_pci_domain(dev); + + if (!domain) + return -1; + + dn.domain_path = domain->path.domain.domain; + + return dn.stack; +} + void iio_pci_domain_read_resources(struct device *dev) { struct resource *res; -- cgit v1.2.3