device/pci: Declare pci_root_bus()

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 <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34004
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Kyösti Mälkki 2019-07-03 09:55:01 +03:00
parent b72b5d9528
commit fffc9f3b9d
2 changed files with 17 additions and 6 deletions

View File

@ -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)

View File

@ -289,6 +289,7 @@ DEVTREE_CONST struct device *pcidev_path_behind(const struct bus *parent,
pci_devfn_t devfn);
DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn);
DEVTREE_CONST struct device *pcidev_on_root(uint8_t dev, uint8_t fn);
DEVTREE_CONST struct bus *pci_root_bus(void);
void scan_smbus(struct device *bus);
void scan_generic_bus(struct device *bus);