device: Consider fw_config probing in `is_dev_enabled()`

With the introduction of fw_config support in coreboot, it is possible
for mainboards to control the state of a device (on/off) in ramstage
using fw_config probe conditions. However, the device tree in
immutable in all other stages and hence `is_dev_enabled()` does not
really reflect the true state as in ramstage.

This change adds a call to `fw_config_probe_dev()` in
`is_dev_enabled()` when device tree is immutable (by checking
DEVTREE_EARLY) to first check if device is disabled because of device
probe conditions. If so, then it reports device as being
disabled. Else, dev->enabled is used to report the device state.

This allows early stages (bootblock, romstage) to use
`is_dev_enabled()` to get the true state of the device by taking probe
conditions into account and eliminates the need for each caller to
perform their own separate probing.

Change-Id: Ifede6775bda245cba199d3419aebd782dc690f2c
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/54752
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Reviewed-by: EricR Lai <ericr_lai@compal.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/src/device/device_const.c b/src/device/device_const.c
index 2ce76c6..20afe7e 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -7,6 +7,7 @@
 #include <device/pci.h>
 #include <device/pci_def.h>
 #include <device/resource.h>
+#include <fw_config.h>
 
 /** Linked list of ALL devices */
 DEVTREE_CONST struct device *DEVTREE_CONST all_devices = &dev_root;
@@ -383,3 +384,16 @@
 
 	return dev;
 }
+
+bool is_dev_enabled(const struct device *dev)
+{
+	if (!dev)
+		return false;
+
+	/* For stages with immutable device tree, first check if device is disabled because of
+	   fw_config probing. In these stages, dev->enabled does not reflect the true state of a
+	   device that uses fw_config probing. */
+	if (DEVTREE_EARLY && !fw_config_probe_dev(dev, NULL))
+		return false;
+	return dev->enabled;
+}
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 88b5310..623d337 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -191,11 +191,7 @@
 void disable_children(struct bus *bus);
 bool dev_is_active_bridge(struct device *dev);
 void add_more_links(struct device *dev, unsigned int total_links);
-
-static inline bool is_dev_enabled(const struct device *const dev)
-{
-	return dev && dev->enabled;
-}
+bool is_dev_enabled(const struct device *const dev);
 
 /* Option ROM helper functions */
 void run_bios(struct device *dev, unsigned long addr);