[PATCH 1/6] of: base: Add function to check for status = "reserved"
Zev Weiss
zev at bewilderbeest.net
Wed Sep 29 21:54:03 AEST 2021
Per v0.3 of the Devicetree Specification [0]:
Indicates that the device is operational, but should not be used.
Typically this is used for devices that are controlled by another
software component, such as platform firmware.
One use-case for this is in OpenBMC, where certain devices (such as a
BIOS flash chip) may be shared by the host and the BMC, but cannot be
accessed by the BMC during its usual boot-time device probing, because
they require additional (potentially elaborate) coordination with the
host to arbitrate which processor is controlling the device.
Devices marked with this status should thus be instantiated, but not
have a driver bound to them or be otherwise touched.
[0] https://github.com/devicetree-org/devicetree-specification/releases/download/v0.3/devicetree-specification-v0.3.pdf
Signed-off-by: Zev Weiss <zev at bewilderbeest.net>
---
drivers/of/base.c | 53 +++++++++++++++++++++++++++++++++++++++-------
include/linux/of.h | 6 ++++++
2 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index f720c0d246f2..c5cc178fc6bd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -579,14 +579,18 @@ int of_machine_is_compatible(const char *compat)
EXPORT_SYMBOL(of_machine_is_compatible);
/**
- * __of_device_is_available - check if a device is available for use
+ * __of_device_check_status - check if a device's status matches a particular string
*
- * @device: Node to check for availability, with locks already held
+ * @device: Node to check status of, with locks already held
+ * @val: Status string to check for
+ * @alt: Optional alternate status string to check for (NULL to check only @val)
+ * @dflt: default to return if status property absent
*
- * Return: True if the status property is absent or set to "okay" or "ok",
- * false otherwise
+ * Return: True if status property exists and matches either @val or @alt.
+ * @dflt if status property is absent. False otherwise.
*/
-static bool __of_device_is_available(const struct device_node *device)
+static bool __of_device_check_status(const struct device_node *device, const char *val,
+ const char *alt, bool dflt)
{
const char *status;
int statlen;
@@ -595,17 +599,30 @@ static bool __of_device_is_available(const struct device_node *device)
return false;
status = __of_get_property(device, "status", &statlen);
- if (status == NULL)
- return true;
+ if (!status)
+ return dflt;
if (statlen > 0) {
- if (!strcmp(status, "okay") || !strcmp(status, "ok"))
+ if (!strcmp(status, val) || (alt && !strcmp(status, alt)))
return true;
}
return false;
}
+/**
+ * __of_device_is_available - check if a device is available for use
+ *
+ * @device: Node to check for availability, with locks already held
+ *
+ * Return: True if the status property is absent or set to "okay" or "ok",
+ * false otherwise
+ */
+static bool __of_device_is_available(const struct device_node *device)
+{
+ return __of_device_check_status(device, "okay", "ok", true);
+}
+
/**
* of_device_is_available - check if a device is available for use
*
@@ -627,6 +644,26 @@ bool of_device_is_available(const struct device_node *device)
}
EXPORT_SYMBOL(of_device_is_available);
+/**
+ * of_device_is_reserved - check if a device is marked as reserved
+ *
+ * @device: Node to check for reservation
+ *
+ * Return: True if the status property is set to "reserved", false otherwise
+ */
+bool of_device_is_reserved(const struct device_node *device)
+{
+ unsigned long flags;
+ bool res;
+
+ raw_spin_lock_irqsave(&devtree_lock, flags);
+ res = __of_device_check_status(device, "reserved", NULL, false);
+ raw_spin_unlock_irqrestore(&devtree_lock, flags);
+
+ return res;
+}
+EXPORT_SYMBOL(of_device_is_reserved);
+
/**
* of_device_is_big_endian - check if a device has BE registers
*
diff --git a/include/linux/of.h b/include/linux/of.h
index 6f1c41f109bb..aa9762da5e7c 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -345,6 +345,7 @@ extern int of_device_is_compatible(const struct device_node *device,
extern int of_device_compatible_match(struct device_node *device,
const char *const *compat);
extern bool of_device_is_available(const struct device_node *device);
+extern bool of_device_is_reserved(const struct device_node *device);
extern bool of_device_is_big_endian(const struct device_node *device);
extern const void *of_get_property(const struct device_node *node,
const char *name,
@@ -707,6 +708,11 @@ static inline bool of_device_is_available(const struct device_node *device)
return false;
}
+static inline bool of_device_is_reserved(const struct device_node *device)
+{
+ return false;
+}
+
static inline bool of_device_is_big_endian(const struct device_node *device)
{
return false;
--
2.33.0
More information about the openbmc
mailing list