device: Consider fw_config probing in `is_dev_enabled()`
[coreboot.git] / src / include / fw_config.h
blob7a8ad3048213424001d30dd378bfda778965cc1a
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef __FW_CONFIG__
4 #define __FW_CONFIG__
6 #include <device/device.h>
7 #include <static.h> /* Provides fw_config definitions from devicetree.cb */
8 #include <stdbool.h>
9 #include <stdint.h>
11 #define UNDEFINED_FW_CONFIG ~((uint64_t)0)
13 /**
14 * struct fw_config - Firmware configuration field and option.
15 * @field_name: Name of the field that this option belongs to.
16 * @option_name: Name of the option within this field.
17 * @mask: Bitmask of the field.
18 * @value: Value of the option within the mask.
20 struct fw_config {
21 const char *field_name;
22 const char *option_name;
23 uint64_t mask;
24 uint64_t value;
27 /* Generate a pointer to a compound literal of the fw_config structure. */
28 #define FW_CONFIG(__field, __option) (&(const struct fw_config) { \
29 .field_name = FW_CONFIG_FIELD_##__field##_NAME, \
30 .option_name = FW_CONFIG_FIELD_##__field##_OPTION_##__option##_NAME, \
31 .mask = FW_CONFIG_FIELD_##__field##_MASK, \
32 .value = FW_CONFIG_FIELD_##__field##_OPTION_##__option##_VALUE \
35 /**
36 * fw_config_get() - Provide firmware configuration value.
38 * Return 64bit firmware configuration value determined for the system.
40 uint64_t fw_config_get(void);
42 #if CONFIG(FW_CONFIG)
44 /**
45 * fw_config_probe() - Check if field and option matches.
46 * @match: Structure containing field and option to probe.
48 * Return %true if match is found, %false if match is not found.
50 bool fw_config_probe(const struct fw_config *match);
52 /**
53 * fw_config_for_each_found() - Call a callback for each fw_config field found
54 * @cb: The callback function
55 * @arg: A context argument that is passed to the callback
57 void fw_config_for_each_found(void (*cb)(const struct fw_config *config, void *arg), void *arg);
59 /**
60 * fw_config_is_provisioned() - Determine if FW_CONFIG has been provisioned.
61 * Return %true if FW_CONFIG has been provisioned, %false otherwise.
63 bool fw_config_is_provisioned(void);
65 /**
66 * fw_config_get_found() - Return a pointer to the fw_config struct for a given field.
67 * @field_mask: A field mask from static.h, e.g., FW_CONFIG_FIELD_FEATURE_MASK
69 * Return pointer to cached `struct fw_config` if successfully probed, otherwise NULL.
71 const struct fw_config *fw_config_get_found(uint64_t field_mask);
73 /**
74 * fw_config_probe_dev() - Check if any of the probe conditions are true for given device.
75 * @dev: Device for which probe conditions are checked
76 * @matching_probe: If any probe condition match, then the matching probe condition is returned
77 * to the caller.
78 * Return %true if device has no probing conditions or if a matching probe condition is
79 * encountered, %false otherwise.
81 bool fw_config_probe_dev(const struct device *dev, const struct fw_config **matching_probe);
83 #else
85 static inline bool fw_config_probe(const struct fw_config *match)
87 /* Always return true when probing with disabled fw_config. */
88 return true;
91 static inline bool fw_config_probe_dev(const struct device *dev,
92 const struct fw_config **matching_probe)
94 /* Always return true when probing with disabled fw_config. */
95 if (matching_probe)
96 *matching_probe = NULL;
97 return true;
100 #endif /* CONFIG(FW_CONFIG) */
102 #endif /* __FW_CONFIG__ */