sysinfo: Add sysinfo API for accessing data area

Add interface for sysinfo to access a data area from the platform.
This is useful to save/read a memory region of platform-specific
data.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
This commit is contained in:
Raymond Mao
2024-12-06 14:54:19 -08:00
committed by Simon Glass
parent 777ff6f0a7
commit 64803744ff
2 changed files with 50 additions and 0 deletions

View File

@@ -99,6 +99,26 @@ int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
return ops->get_str(dev, id, size, val);
}
int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size)
{
struct sysinfo_priv *priv;
struct sysinfo_ops *ops;
if (!dev)
return -ENOSYS;
priv = dev_get_uclass_priv(dev);
ops = sysinfo_get_ops(dev);
if (!priv->detected)
return -EPERM;
if (!ops->get_data)
return -ENOSYS;
return ops->get_data(dev, id, data, size);
}
UCLASS_DRIVER(sysinfo) = {
.id = UCLASS_SYSINFO,
.name = "sysinfo",

View File

@@ -115,6 +115,18 @@ struct sysinfo_ops {
*/
int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
/**
* get_data() - Read a specific string data value that describes the
* hardware setup.
* @dev: The sysinfo instance to gather the data.
* @id: A unique identifier for the data area to be get.
* @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)(struct udevice *dev, int id, 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
@@ -186,6 +198,18 @@ int sysinfo_get_int(struct udevice *dev, int id, int *val);
*/
int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
/**
* sysinfo_get_data() - Get a data area from the platform.
* @dev: The sysinfo instance to gather the data.
* @id: A unique identifier for the data area to be get.
* @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(struct udevice *dev, int id, 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.
@@ -241,6 +265,12 @@ static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
return -ENOSYS;
}
static inline int sysinfo_get_data(struct udevice *dev, int id, void **data,
size_t *size)
{
return -ENOSYS;
}
static inline int sysinfo_get(struct udevice **devp)
{
return -ENOSYS;