From fffc9f3b9d9de4909d35da0fb4006d5080bb8e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Wed, 3 Jul 2019 09:55:01 +0300 Subject: device/pci: Declare pci_root_bus() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is used a lot, cache the result so search of domain from devicetree is only done once. Improvement only applies when MAYBE_STATIC evaluates to static. Change-Id: If675abb632fe68acd59ba0bdfef854da3e0839a9 Signed-off-by: Kyösti Mälkki Reviewed-on: https://review.coreboot.org/c/coreboot/+/34004 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Nico Huber Reviewed-by: Angel Pons --- src/device/device_const.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/device/device_const.c') diff --git a/src/device/device_const.c b/src/device/device_const.c index 6ce1d18c93..1853b4c4d2 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -183,10 +183,24 @@ DEVTREE_CONST struct device *pcidev_path_behind( return find_dev_path(parent, &path); } -DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn) +DEVTREE_CONST struct bus *pci_root_bus(void) { DEVTREE_CONST struct device *pci_domain; + MAYBE_STATIC DEVTREE_CONST struct bus *pci_root = NULL; + + if (pci_root) + return pci_root; + + pci_domain = dev_find_path(NULL, DEVICE_PATH_DOMAIN); + if (!pci_domain) + return NULL; + + pci_root = pci_domain->link_list; + return pci_root; +} +DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn) +{ /* Work around pcidev_path_behind() below failing * due tue complicated devicetree with topology * being manipulated on-the-fly. @@ -194,11 +208,7 @@ DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn) if (CONFIG(NORTHBRIDGE_AMD_AMDFAM10)) return dev_find_slot(0, devfn); - pci_domain = dev_find_path(NULL, DEVICE_PATH_DOMAIN); - if (!pci_domain) - return NULL; - - return pcidev_path_behind(pci_domain->link_list, devfn); + return pcidev_path_behind(pci_root_bus(), devfn); } DEVTREE_CONST struct device *pcidev_on_root(uint8_t dev, uint8_t fn) -- cgit v1.2.3