summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/device/device_const.c12
-rw-r--r--src/include/device/device.h24
2 files changed, 35 insertions, 1 deletions
diff --git a/src/device/device_const.c b/src/device/device_const.c
index f2f0177f57..c472aeaa79 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -240,12 +240,22 @@ DEVTREE_CONST struct device *pcidev_path_on_root_debug(pci_devfn_t devfn, const
if (dev)
return dev;
- printk(BIOS_ERR, "BUG: %s requests hidden 00:%02x.%u\n", func, devfn >> 3, devfn & 7);
+ devtree_bug(func, devfn);
/* FIXME: This can return wrong device. */
return dev_find_slot(0, devfn);
}
+void devtree_bug(const char *func, pci_devfn_t devfn)
+{
+ printk(BIOS_ERR, "BUG: %s requests hidden 00:%02x.%u\n", func, devfn >> 3, devfn & 7);
+}
+
+void __noreturn devtree_die(void)
+{
+ die("DEVTREE: dev or chip_info is NULL\n");
+}
+
/**
* 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 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);