blob: 8a77ef448565110fe591acfb3038a9804fb56496 [file] [log] [blame]
Mario Six2161e552018-07-31 11:44:11 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * (C) Copyright 2017
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Tom Rini55a297c2021-04-19 16:18:49 -04007#ifndef __SYSINFO_H__
8#define __SYSINFO_H__
9
Max Krummenacher0e226eb2024-01-18 19:10:47 +010010#include <linux/errno.h>
11
Simon Glass3ba929a2020-10-30 21:38:53 -060012struct udevice;
13
Mario Six2161e552018-07-31 11:44:11 +020014/*
15 * This uclass encapsulates hardware methods to gather information about a
Simon Glass458b66a2020-11-05 06:32:05 -070016 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six2161e552018-07-31 11:44:11 +020017 * read-only data in flash ICs, or similar.
18 *
19 * The interface offers functions to read the usual standard data types (bool,
20 * int, string) from the device, each of which is identified by a static
21 * numeric ID (which will usually be defined as a enum in a header file).
22 *
Simon Glass458b66a2020-11-05 06:32:05 -070023 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six2161e552018-07-31 11:44:11 +020024 * call
25 *
Simon Glass458b66a2020-11-05 06:32:05 -070026 * ret = sysinfo_detect(dev);
Mario Six2161e552018-07-31 11:44:11 +020027 * if (ret) {
Simon Glass458b66a2020-11-05 06:32:05 -070028 * debug("sysinfo device not found.");
Mario Six2161e552018-07-31 11:44:11 +020029 * return ret;
30 * }
31 *
Simon Glass458b66a2020-11-05 06:32:05 -070032 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six2161e552018-07-31 11:44:11 +020033 * if (ret) {
34 * debug("Error when reading serial number from device.");
35 * return ret;
36 * }
37 *
38 * to read the serial number.
39 */
40
Simon Glasscf67d6d2021-02-04 21:17:23 -070041/** enum sysinfo_id - Standard IDs defined by U-Boot */
42enum sysinfo_id {
43 SYSINFO_ID_NONE,
44
Simon Glass43bc5432021-03-21 16:50:06 +130045 /* For SMBIOS tables */
Michal Simeka7aa3952024-04-26 15:38:13 +020046 SYSINFO_ID_SMBIOS_SYSTEM_MANUFACTURER,
47 SYSINFO_ID_SMBIOS_SYSTEM_PRODUCT,
Simon Glasscf67d6d2021-02-04 21:17:23 -070048 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
Michal Simeka7aa3952024-04-26 15:38:13 +020049 SYSINFO_ID_SMBIOS_SYSTEM_SERIAL,
50 SYSINFO_ID_SMBIOS_SYSTEM_SKU,
51 SYSINFO_ID_SMBIOS_SYSTEM_FAMILY,
52 SYSINFO_ID_SMBIOS_BASEBOARD_MANUFACTURER,
53 SYSINFO_ID_SMBIOS_BASEBOARD_PRODUCT,
Simon Glasscf67d6d2021-02-04 21:17:23 -070054 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
Michal Simeka7aa3952024-04-26 15:38:13 +020055 SYSINFO_ID_SMBIOS_BASEBOARD_SERIAL,
56 SYSINFO_ID_SMBIOS_BASEBOARD_ASSET_TAG,
Simon Glasscf67d6d2021-02-04 21:17:23 -070057
Simon Glass43bc5432021-03-21 16:50:06 +130058 /* For show_board_info() */
59 SYSINFO_ID_BOARD_MODEL,
Simon Glassc2e06e92023-11-12 19:58:28 -070060 SYSINFO_ID_BOARD_MANUFACTURER,
61 SYSINFO_ID_PRIOR_STAGE_VERSION,
62 SYSINFO_ID_PRIOR_STAGE_DATE,
Simon Glass43bc5432021-03-21 16:50:06 +130063
Simon Glasscf67d6d2021-02-04 21:17:23 -070064 /* First value available for downstream/board used */
65 SYSINFO_ID_USER = 0x1000,
66};
67
Simon Glass458b66a2020-11-05 06:32:05 -070068struct sysinfo_ops {
Mario Six2161e552018-07-31 11:44:11 +020069 /**
70 * detect() - Run the hardware info detection procedure for this
71 * device.
72 * @dev: The device containing the information
73 *
74 * This operation might take a long time (e.g. read from EEPROM,
75 * check the presence of a device on a bus etc.), hence this is not
76 * done in the probe() method, but later during operation in this
Sean Anderson6ccf10a2021-04-20 10:50:56 -040077 * dedicated method. This method will be called before any other
78 * methods.
Mario Six2161e552018-07-31 11:44:11 +020079 *
80 * Return: 0 if OK, -ve on error.
81 */
82 int (*detect)(struct udevice *dev);
83
84 /**
85 * get_bool() - Read a specific bool data value that describes the
86 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070087 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020088 * @id: A unique identifier for the bool value to be read.
89 * @val: Pointer to a buffer that receives the value read.
90 *
91 * Return: 0 if OK, -ve on error.
92 */
93 int (*get_bool)(struct udevice *dev, int id, bool *val);
94
95 /**
96 * get_int() - Read a specific int data value that describes the
97 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070098 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020099 * @id: A unique identifier for the int value to be read.
100 * @val: Pointer to a buffer that receives the value read.
101 *
102 * Return: 0 if OK, -ve on error.
103 */
104 int (*get_int)(struct udevice *dev, int id, int *val);
105
106 /**
107 * get_str() - Read a specific string data value that describes the
108 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700109 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200110 * @id: A unique identifier for the string value to be read.
111 * @size: The size of the buffer to receive the string data.
112 * @val: Pointer to a buffer that receives the value read.
113 *
114 * Return: 0 if OK, -ve on error.
115 */
116 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200117
118 /**
119 * get_fit_loadable - Get the name of an image to load from FIT
120 * This function can be used to provide the image names based on runtime
121 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400122 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200123 *
Simon Glass458b66a2020-11-05 06:32:05 -0700124 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200125 * @index: Index of the image. Starts at 0 and gets incremented
126 * after each call to this function.
127 * @type: The type of image. For example, "fdt" for DTBs
128 * @strp: A pointer to string. Untouched if the function fails
129 *
130 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
131 * error.
132 */
133 int (*get_fit_loadable)(struct udevice *dev, int index,
134 const char *type, const char **strp);
Mario Six2161e552018-07-31 11:44:11 +0200135};
136
Simon Glass458b66a2020-11-05 06:32:05 -0700137#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six2161e552018-07-31 11:44:11 +0200138
Simon Glass10e6f792021-02-04 21:17:21 -0700139#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six2161e552018-07-31 11:44:11 +0200140/**
Simon Glass458b66a2020-11-05 06:32:05 -0700141 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six2161e552018-07-31 11:44:11 +0200142 *
143 * @dev: The device containing the information
144 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400145 * This function must be called before any other accessor function for this
146 * device.
147 *
Mario Six2161e552018-07-31 11:44:11 +0200148 * Return: 0 if OK, -ve on error.
149 */
Simon Glass458b66a2020-11-05 06:32:05 -0700150int sysinfo_detect(struct udevice *dev);
Mario Six2161e552018-07-31 11:44:11 +0200151
152/**
Simon Glass458b66a2020-11-05 06:32:05 -0700153 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200154 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700155 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200156 * @id: A unique identifier for the bool value to be read.
157 * @val: Pointer to a buffer that receives the value read.
158 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400159 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
160 * error.
Mario Six2161e552018-07-31 11:44:11 +0200161 */
Simon Glass458b66a2020-11-05 06:32:05 -0700162int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six2161e552018-07-31 11:44:11 +0200163
164/**
Simon Glass458b66a2020-11-05 06:32:05 -0700165 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200166 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700167 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200168 * @id: A unique identifier for the int value to be read.
169 * @val: Pointer to a buffer that receives the value read.
170 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400171 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
172 * error.
Mario Six2161e552018-07-31 11:44:11 +0200173 */
Simon Glass458b66a2020-11-05 06:32:05 -0700174int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six2161e552018-07-31 11:44:11 +0200175
176/**
Simon Glass458b66a2020-11-05 06:32:05 -0700177 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200178 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700179 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200180 * @id: A unique identifier for the string value to be read.
181 * @size: The size of the buffer to receive the string data.
182 * @val: Pointer to a buffer that receives the value read.
183 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400184 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
185 * error.
Mario Six2161e552018-07-31 11:44:11 +0200186 */
Simon Glass458b66a2020-11-05 06:32:05 -0700187int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six2161e552018-07-31 11:44:11 +0200188
189/**
Simon Glass458b66a2020-11-05 06:32:05 -0700190 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
191 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six2161e552018-07-31 11:44:11 +0200192 *
Simon Glass458b66a2020-11-05 06:32:05 -0700193 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six2161e552018-07-31 11:44:11 +0200194 * function that returns the unique device. This is especially useful for use
Simon Glass458b66a2020-11-05 06:32:05 -0700195 * in sysinfo files.
Mario Six2161e552018-07-31 11:44:11 +0200196 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400197 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
198 * error.
Mario Six2161e552018-07-31 11:44:11 +0200199 */
Simon Glass458b66a2020-11-05 06:32:05 -0700200int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200201
202/**
Simon Glass458b66a2020-11-05 06:32:05 -0700203 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200204 * This function can be used to provide the image names based on runtime
205 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400206 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200207 *
Simon Glass458b66a2020-11-05 06:32:05 -0700208 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200209 * @index: Index of the image. Starts at 0 and gets incremented
210 * after each call to this function.
211 * @type: The type of image. For example, "fdt" for DTBs
212 * @strp: A pointer to string. Untouched if the function fails
213 *
214 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400215 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
216 * loadable is available else -ve on error.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200217 */
Simon Glass458b66a2020-11-05 06:32:05 -0700218int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
219 const char **strp);
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200220
221#else
222
Simon Glass458b66a2020-11-05 06:32:05 -0700223static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200224{
225 return -ENOSYS;
226}
227
Simon Glass458b66a2020-11-05 06:32:05 -0700228static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200229{
230 return -ENOSYS;
231}
232
Simon Glass458b66a2020-11-05 06:32:05 -0700233static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200234{
235 return -ENOSYS;
236}
237
Simon Glass458b66a2020-11-05 06:32:05 -0700238static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
239 char *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200240{
241 return -ENOSYS;
242}
243
Simon Glass458b66a2020-11-05 06:32:05 -0700244static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200245{
246 return -ENOSYS;
247}
248
Simon Glass458b66a2020-11-05 06:32:05 -0700249static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
250 const char *type, const char **strp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200251{
252 return -ENOSYS;
253}
254
255#endif
Tom Rini55a297c2021-04-19 16:18:49 -0400256#endif