sysinfo: Add API for accessing data elements

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@siemens.com>
This commit is contained in:
Baocheng Su 2025-02-18 10:36:11 +08:00 committed by Tom Rini
parent 6b654ac5a6
commit 920629c594
2 changed files with 92 additions and 0 deletions

View file

@ -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",

View file

@ -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;