Kyösti Mälkki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/34298 )
Change subject: devicetree: Add accessors for chip_info ......................................................................
devicetree: Add accessors for chip_info
Apply uniform style of error messages for missing device nodes and chip_info.
Change-Id: I70def4599509b8193e44ea3f02c4906f865b4469 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/device/device_const.c M src/include/device/device.h 2 files changed, 31 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/98/34298/1
diff --git a/src/device/device_const.c b/src/device/device_const.c index e9cf5eb..ba12249 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -244,6 +244,33 @@ return dev_find_slot(0, devfn); }
+DEVTREE_CONST void *config_of(DEVTREE_CONST struct device *dev) +{ + if (dev && dev->chip_info) + return dev->chip_info; + + printk(BIOS_ERR, "BUG: %s has no chip_info\n", dev_path(dev)); + return NULL; +} + +DEVTREE_CONST void *config_of_path(pci_devfn_t devfn) +{ + DEVTREE_CONST struct device *dev = pcidev_path_on_root(devfn); + if (dev) + return config_of(dev); + + dev = dev_find_slot(0, devfn); + if (dev) { + printk(BIOS_ERR, "BUG: config of hidden 00:%02x.%u requested\n", + devfn >> 3, devfn & 7); + return config_of(dev); + } + + printk(BIOS_ERR, "BUG: config of missing 00:%02x.%u requested\n", + devfn >> 3, devfn & 7); + return NULL; +} + /** * Given an SMBus bus and a device number, find the device structure. * diff --git a/src/include/device/device.h b/src/include/device/device.h index 24b6421..f8485a3 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -294,6 +294,10 @@ DEVTREE_CONST struct device *dev_find_slot(unsigned int bus, unsigned int devfn); DEVTREE_CONST struct device *pcidev_path_on_root_debug(pci_devfn_t devfn, const char *func);
+/* Safely discover chip_info. */ +DEVTREE_CONST void *config_of(DEVTREE_CONST struct device *dev); +DEVTREE_CONST void *config_of_path(pci_devfn_t devfn); + void scan_smbus(struct device *bus); void scan_generic_bus(struct device *bus); void scan_static_bus(struct device *bus);