summaryrefslogtreecommitdiff
path: root/src/include/device
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2019-07-12 16:20:14 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2019-07-18 15:22:09 +0000
commit4323d262473a1ea09eb3f843c4e856eb5851146f (patch)
tree46bf2e95fdddc2d1e8cae5227fd4063f66855b9d /src/include/device
parent73d560a71ae55d39a1ca189cb02663454835b03c (diff)
downloadcoreboot-4323d262473a1ea09eb3f843c4e856eb5851146f.tar.xz
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> Reviewed-on: https://review.coreboot.org/c/coreboot/+/34298 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/include/device')
-rw-r--r--src/include/device/device.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 4ffbff4ac9..8e1e62aa7c 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -294,6 +294,30 @@ DEVTREE_CONST struct bus *pci_root_bus(void);
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);
+/* Robust discovery of chip_info. */
+void devtree_bug(const char *func, pci_devfn_t devfn);
+void __noreturn devtree_die(void);
+
+static inline DEVTREE_CONST void *config_of(const struct device *dev)
+{
+ if (dev && dev->chip_info)
+ return dev->chip_info;
+
+ devtree_die();
+}
+
+static inline DEVTREE_CONST void *config_of_path(pci_devfn_t devfn)
+{
+ const struct device *dev = pcidev_path_on_root(devfn);
+ if (dev)
+ return config_of(dev);
+
+ devtree_bug(__func__, devfn);
+
+ dev = dev_find_slot(0, devfn);
+ return config_of(dev);
+}
+
void scan_smbus(struct device *bus);
void scan_generic_bus(struct device *bus);
void scan_static_bus(struct device *bus);