[PATCH v3 2/5] sysinfo: Add API for accessing data elements
Baocheng Su
baocheng.su at siemens.com
Mon Feb 10 14:05:41 CET 2025
This commit introduces a new API to the sysinfo module, allowing access
to data elements. This is particularly useful for handling data with
multiple instances, such as MAC addresses.
Signed-off-by: Baocheng Su <baocheng.su at siemens.com>
---
Changes in v3:
- New
drivers/sysinfo/sysinfo-uclass.c | 29 +++++++++++++++
include/sysinfo.h | 63 ++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+)
diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c
index 3c0cd51273e7..f04998ef8bb6 100644
--- a/drivers/sysinfo/sysinfo-uclass.c
+++ b/drivers/sysinfo/sysinfo-uclass.c
@@ -119,6 +119,35 @@ int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size)
return ops->get_data(dev, id, data, size);
}
+int sysinfo_get_item_count(struct udevice *dev, int id)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_item_count)
+ return -ENOSYS;
+
+ return ops->get_item_count(dev, id);
+}
+
+int sysinfo_get_data_by_index(struct udevice *dev, int id, int index,
+ void **data, size_t *size)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_data_by_index)
+ return -ENOSYS;
+
+ return ops->get_data_by_index(dev, id, index, data, size);
+}
+
UCLASS_DRIVER(sysinfo) = {
.id = UCLASS_SYSINFO,
.name = "sysinfo",
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 14e923c6589f..2866ac293cbb 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -152,6 +152,7 @@ enum sysinfo_id {
/* For show_board_info() */
SYSID_BOARD_MODEL,
SYSID_BOARD_MANUFACTURER,
+ SYSID_BOARD_MAC_ADDR,
SYSID_PRIOR_STAGE_VERSION,
SYSID_PRIOR_STAGE_DATE,
@@ -221,6 +222,30 @@ struct sysinfo_ops {
*/
int (*get_data)(struct udevice *dev, int id, void **data, size_t *size);
+ /**
+ * get_item_count() - Get the item count of the specific data area that
+ * describes the hardware setup.
+ * @dev: The sysinfo instance to gather the data.
+ * @id: A unique identifier for the data area to be get.
+ *
+ * Return: non-negative item count if OK, -ve on error.
+ */
+ int (*get_item_count)(struct udevice *dev, int id);
+
+ /**
+ * get_data_by_index() - Get a data value by index from the platform.
+ *
+ * @dev: The sysinfo instance to gather the data.
+ * @id: A unique identifier for the data area to be get.
+ * @index: The item index, starting from 0.
+ * @data: Pointer to the address of the data area.
+ * @size: Pointer to the size of the data area.
+ *
+ * Return: 0 if OK, -ve on error.
+ */
+ int (*get_data_by_index)(struct udevice *dev, int id, int index,
+ void **data, size_t *size);
+
/**
* get_fit_loadable - Get the name of an image to load from FIT
* This function can be used to provide the image names based on runtime
@@ -304,6 +329,32 @@ int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
*/
int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size);
+/**
+ * sysinfo_get_item_count() - Get the item count of the specific data area that
+ * describes the hardware setup.
+ * @dev: The sysinfo instance to gather the data.
+ * @id: A unique identifier for the data area to be get.
+ *
+ * Return: non-negative item count if OK, -EPERM if called before
+ * sysinfo_detect(), else -ve on error.
+ */
+int sysinfo_get_item_count(struct udevice *dev, int id);
+
+/**
+ * sysinfo_get_data_by_index() - Get a data value by index from the platform.
+ *
+ * @dev: The sysinfo instance to gather the data.
+ * @id: A unique identifier for the data area to be get.
+ * @index: The item index, starting from 0.
+ * @data: Pointer to the address of the data area.
+ * @size: Pointer to the size of the data area.
+ *
+ * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
+ * error.
+ */
+int sysinfo_get_data_by_index(struct udevice *dev, int id, int index,
+ void **data, size_t *size);
+
/**
* sysinfo_get() - Return the sysinfo device for the sysinfo in question.
* @devp: Pointer to structure to receive the sysinfo device.
@@ -365,6 +416,18 @@ static inline int sysinfo_get_data(struct udevice *dev, int id, void **data,
return -ENOSYS;
}
+static inline int sysinfo_get_item_count(struct udevice *dev, int id)
+{
+ return -ENOSYS;
+}
+
+static inline int sysinfo_get_data_by_index(struct udevice *dev, int id,
+ int index, void **data,
+ size_t *size)
+{
+ return -ENOSYS;
+}
+
static inline int sysinfo_get(struct udevice **devp)
{
return -ENOSYS;
--
2.39.5
More information about the U-Boot
mailing list