blob: ba2ac273e8e2b50aa882b239e68169811a79b29b [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
Raymond Mao8fe07312024-12-06 14:54:21 -080014#define SYSINFO_CACHE_LVL_MAX 3
15
Mario Six2161e552018-07-31 11:44:11 +020016/*
17 * This uclass encapsulates hardware methods to gather information about a
Simon Glass458b66a2020-11-05 06:32:05 -070018 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six2161e552018-07-31 11:44:11 +020019 * read-only data in flash ICs, or similar.
20 *
21 * The interface offers functions to read the usual standard data types (bool,
22 * int, string) from the device, each of which is identified by a static
23 * numeric ID (which will usually be defined as a enum in a header file).
24 *
Simon Glass458b66a2020-11-05 06:32:05 -070025 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six2161e552018-07-31 11:44:11 +020026 * call
27 *
Simon Glass458b66a2020-11-05 06:32:05 -070028 * ret = sysinfo_detect(dev);
Mario Six2161e552018-07-31 11:44:11 +020029 * if (ret) {
Simon Glass458b66a2020-11-05 06:32:05 -070030 * debug("sysinfo device not found.");
Mario Six2161e552018-07-31 11:44:11 +020031 * return ret;
32 * }
33 *
Simon Glass458b66a2020-11-05 06:32:05 -070034 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six2161e552018-07-31 11:44:11 +020035 * if (ret) {
36 * debug("Error when reading serial number from device.");
37 * return ret;
38 * }
39 *
40 * to read the serial number.
41 */
42
Simon Glasscf67d6d2021-02-04 21:17:23 -070043/** enum sysinfo_id - Standard IDs defined by U-Boot */
44enum sysinfo_id {
Simon Glassff3edc22024-10-31 18:50:23 +010045 SYSID_NONE,
Simon Glasscf67d6d2021-02-04 21:17:23 -070046
Raymond Mao8fe07312024-12-06 14:54:21 -080047 /* BIOS Information (Type 0) */
48 SYSID_SM_BIOS_VENDOR,
49 SYSID_SM_BIOS_VER,
50 SYSID_SM_BIOS_REL_DATE,
51
52 /* System Information (Type 1) */
Simon Glassff3edc22024-10-31 18:50:23 +010053 SYSID_SM_SYSTEM_MANUFACTURER,
54 SYSID_SM_SYSTEM_PRODUCT,
55 SYSID_SM_SYSTEM_VERSION,
56 SYSID_SM_SYSTEM_SERIAL,
Raymond Mao8fe07312024-12-06 14:54:21 -080057 SYSID_SM_SYSTEM_WAKEUP,
Simon Glassff3edc22024-10-31 18:50:23 +010058 SYSID_SM_SYSTEM_SKU,
59 SYSID_SM_SYSTEM_FAMILY,
Raymond Mao8fe07312024-12-06 14:54:21 -080060
61 /* Baseboard (or Module) Information (Type 2) */
Simon Glassff3edc22024-10-31 18:50:23 +010062 SYSID_SM_BASEBOARD_MANUFACTURER,
63 SYSID_SM_BASEBOARD_PRODUCT,
64 SYSID_SM_BASEBOARD_VERSION,
65 SYSID_SM_BASEBOARD_SERIAL,
66 SYSID_SM_BASEBOARD_ASSET_TAG,
Raymond Mao8fe07312024-12-06 14:54:21 -080067 SYSID_SM_BASEBOARD_FEATURE,
68 SYSID_SM_BASEBOARD_CHASSIS_LOCAT,
69 SYSID_SM_BASEBOARD_TYPE,
70 SYSID_SM_BASEBOARD_OBJS_NUM,
71 SYSID_SM_BASEBOARD_OBJS_HANDLE,
72
73 /* System Enclosure or Chassis (Type 3) */
74 SYSID_SM_ENCLOSURE_MANUFACTURER,
75 SYSID_SM_ENCLOSURE_VERSION,
76 SYSID_SM_ENCLOSURE_SERIAL,
77 SYSID_SM_ENCLOSURE_ASSET_TAG,
78 SYSID_SM_ENCLOSURE_TYPE,
79 SYSID_SM_ENCLOSURE_BOOTUP,
80 SYSID_SM_ENCLOSURE_POW,
81 SYSID_SM_ENCLOSURE_THERMAL,
82 SYSID_SM_ENCLOSURE_SECURITY,
83 SYSID_SM_ENCLOSURE_OEM,
84 SYSID_SM_ENCLOSURE_HEIGHT,
85 SYSID_SM_ENCLOSURE_POWCORE_NUM,
86 SYSID_SM_ENCLOSURE_ELEMENT_CNT,
87 SYSID_SM_ENCLOSURE_ELEMENT_LEN,
88 SYSID_SM_ENCLOSURE_ELEMENTS,
89 SYSID_SM_ENCLOSURE_SKU,
90
91 /* Processor Information (Type 4) */
92 SYSID_SM_PROCESSOR_SOCKET,
93 SYSID_SM_PROCESSOR_TYPE,
94 SYSID_SM_PROCESSOR_MANUFACT,
95 SYSID_SM_PROCESSOR_ID,
96 SYSID_SM_PROCESSOR_VERSION,
97 SYSID_SM_PROCESSOR_VOLTAGE,
98 SYSID_SM_PROCESSOR_EXT_CLOCK,
99 SYSID_SM_PROCESSOR_MAX_SPEED,
100 SYSID_SM_PROCESSOR_CUR_SPEED,
101 SYSID_SM_PROCESSOR_STATUS,
102 SYSID_SM_PROCESSOR_UPGRADE,
103 SYSID_SM_PROCESSOR_SN,
104 SYSID_SM_PROCESSOR_ASSET_TAG,
105 SYSID_SM_PROCESSOR_PN,
106 SYSID_SM_PROCESSOR_CORE_CNT,
107 SYSID_SM_PROCESSOR_CORE_EN,
108 SYSID_SM_PROCESSOR_THREAD_CNT,
109 SYSID_SM_PROCESSOR_CHARA,
110 SYSID_SM_PROCESSOR_FAMILY,
111 SYSID_SM_PROCESSOR_FAMILY2,
112 SYSID_SM_PROCESSOR_CORE_CNT2,
113 SYSID_SM_PROCESSOR_CORE_EN2,
114 SYSID_SM_PROCESSOR_THREAD_CNT2,
115 SYSID_SM_PROCESSOR_THREAD_EN,
116
117 /*
118 * Cache Information (Type 7)
119 * Each of the id should reserve space for up to
120 * SYSINFO_CACHE_LVL_MAX levels of cache
121 */
122 SYSID_SM_CACHE_LEVEL,
123 SYSID_SM_CACHE_HANDLE,
124 SYSID_SM_CACHE_INFO_START,
125 SYSID_SM_CACHE_SOCKET = SYSID_SM_CACHE_INFO_START,
126 SYSID_SM_CACHE_CONFIG =
127 SYSID_SM_CACHE_SOCKET + SYSINFO_CACHE_LVL_MAX,
128 SYSID_SM_CACHE_MAX_SIZE =
129 SYSID_SM_CACHE_CONFIG + SYSINFO_CACHE_LVL_MAX,
130 SYSID_SM_CACHE_INST_SIZE =
131 SYSID_SM_CACHE_MAX_SIZE + SYSINFO_CACHE_LVL_MAX,
132 SYSID_SM_CACHE_SUPSRAM_TYPE =
133 SYSID_SM_CACHE_INST_SIZE + SYSINFO_CACHE_LVL_MAX,
134 SYSID_SM_CACHE_CURSRAM_TYPE =
135 SYSID_SM_CACHE_SUPSRAM_TYPE + SYSINFO_CACHE_LVL_MAX,
136 SYSID_SM_CACHE_SPEED =
137 SYSID_SM_CACHE_CURSRAM_TYPE + SYSINFO_CACHE_LVL_MAX,
138 SYSID_SM_CACHE_ERRCOR_TYPE =
139 SYSID_SM_CACHE_SPEED + SYSINFO_CACHE_LVL_MAX,
140 SYSID_SM_CACHE_SCACHE_TYPE =
141 SYSID_SM_CACHE_ERRCOR_TYPE + SYSINFO_CACHE_LVL_MAX,
142 SYSID_SM_CACHE_ASSOC =
143 SYSID_SM_CACHE_SCACHE_TYPE + SYSINFO_CACHE_LVL_MAX,
144 SYSID_SM_CACHE_MAX_SIZE2 =
145 SYSID_SM_CACHE_ASSOC + SYSINFO_CACHE_LVL_MAX,
146 SYSID_SM_CACHE_INST_SIZE2 =
147 SYSID_SM_CACHE_MAX_SIZE2 + SYSINFO_CACHE_LVL_MAX,
148 SYSID_SM_CACHE_INFO_END =
149 SYSID_SM_CACHE_INST_SIZE2 + SYSINFO_CACHE_LVL_MAX - 1,
Simon Glasscf67d6d2021-02-04 21:17:23 -0700150
Simon Glass43bc5432021-03-21 16:50:06 +1300151 /* For show_board_info() */
Simon Glassff3edc22024-10-31 18:50:23 +0100152 SYSID_BOARD_MODEL,
153 SYSID_BOARD_MANUFACTURER,
154 SYSID_PRIOR_STAGE_VERSION,
155 SYSID_PRIOR_STAGE_DATE,
Simon Glass43bc5432021-03-21 16:50:06 +1300156
Simon Glasscf67d6d2021-02-04 21:17:23 -0700157 /* First value available for downstream/board used */
Simon Glassff3edc22024-10-31 18:50:23 +0100158 SYSID_USER = 0x1000,
Simon Glasscf67d6d2021-02-04 21:17:23 -0700159};
160
Simon Glass458b66a2020-11-05 06:32:05 -0700161struct sysinfo_ops {
Mario Six2161e552018-07-31 11:44:11 +0200162 /**
163 * detect() - Run the hardware info detection procedure for this
164 * device.
165 * @dev: The device containing the information
166 *
167 * This operation might take a long time (e.g. read from EEPROM,
168 * check the presence of a device on a bus etc.), hence this is not
169 * done in the probe() method, but later during operation in this
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400170 * dedicated method. This method will be called before any other
171 * methods.
Mario Six2161e552018-07-31 11:44:11 +0200172 *
173 * Return: 0 if OK, -ve on error.
174 */
175 int (*detect)(struct udevice *dev);
176
177 /**
178 * get_bool() - Read a specific bool data value that describes the
179 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700180 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200181 * @id: A unique identifier for the bool value to be read.
182 * @val: Pointer to a buffer that receives the value read.
183 *
184 * Return: 0 if OK, -ve on error.
185 */
186 int (*get_bool)(struct udevice *dev, int id, bool *val);
187
188 /**
189 * get_int() - Read a specific int data value that describes the
190 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700191 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200192 * @id: A unique identifier for the int value to be read.
193 * @val: Pointer to a buffer that receives the value read.
194 *
195 * Return: 0 if OK, -ve on error.
196 */
197 int (*get_int)(struct udevice *dev, int id, int *val);
198
199 /**
200 * get_str() - Read a specific string data value that describes the
201 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700202 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200203 * @id: A unique identifier for the string value to be read.
204 * @size: The size of the buffer to receive the string data.
205 * @val: Pointer to a buffer that receives the value read.
206 *
207 * Return: 0 if OK, -ve on error.
208 */
209 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200210
211 /**
Raymond Mao860fa8b2024-12-06 14:54:19 -0800212 * get_data() - Read a specific string data value that describes the
213 * hardware setup.
214 * @dev: The sysinfo instance to gather the data.
215 * @id: A unique identifier for the data area to be get.
216 * @data: Pointer to the address of the data area.
217 * @size: Pointer to the size of the data area.
218 *
219 * Return: 0 if OK, -ve on error.
220 */
221 int (*get_data)(struct udevice *dev, int id, void **data, size_t *size);
222
223 /**
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200224 * get_fit_loadable - Get the name of an image to load from FIT
225 * This function can be used to provide the image names based on runtime
226 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400227 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200228 *
Simon Glass458b66a2020-11-05 06:32:05 -0700229 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200230 * @index: Index of the image. Starts at 0 and gets incremented
231 * after each call to this function.
232 * @type: The type of image. For example, "fdt" for DTBs
233 * @strp: A pointer to string. Untouched if the function fails
234 *
235 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
236 * error.
237 */
238 int (*get_fit_loadable)(struct udevice *dev, int index,
239 const char *type, const char **strp);
Mario Six2161e552018-07-31 11:44:11 +0200240};
241
Simon Glass458b66a2020-11-05 06:32:05 -0700242#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six2161e552018-07-31 11:44:11 +0200243
Simon Glass10e6f792021-02-04 21:17:21 -0700244#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six2161e552018-07-31 11:44:11 +0200245/**
Simon Glass458b66a2020-11-05 06:32:05 -0700246 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six2161e552018-07-31 11:44:11 +0200247 *
248 * @dev: The device containing the information
249 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400250 * This function must be called before any other accessor function for this
251 * device.
252 *
Mario Six2161e552018-07-31 11:44:11 +0200253 * Return: 0 if OK, -ve on error.
254 */
Simon Glass458b66a2020-11-05 06:32:05 -0700255int sysinfo_detect(struct udevice *dev);
Mario Six2161e552018-07-31 11:44:11 +0200256
257/**
Simon Glass458b66a2020-11-05 06:32:05 -0700258 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200259 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700260 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200261 * @id: A unique identifier for the bool value to be read.
262 * @val: Pointer to a buffer that receives the value read.
263 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400264 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
265 * error.
Mario Six2161e552018-07-31 11:44:11 +0200266 */
Simon Glass458b66a2020-11-05 06:32:05 -0700267int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six2161e552018-07-31 11:44:11 +0200268
269/**
Simon Glass458b66a2020-11-05 06:32:05 -0700270 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200271 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700272 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200273 * @id: A unique identifier for the int value to be read.
274 * @val: Pointer to a buffer that receives the value read.
275 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400276 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
277 * error.
Mario Six2161e552018-07-31 11:44:11 +0200278 */
Simon Glass458b66a2020-11-05 06:32:05 -0700279int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six2161e552018-07-31 11:44:11 +0200280
281/**
Simon Glass458b66a2020-11-05 06:32:05 -0700282 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200283 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700284 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200285 * @id: A unique identifier for the string value to be read.
286 * @size: The size of the buffer to receive the string data.
287 * @val: Pointer to a buffer that receives the value read.
288 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400289 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
290 * error.
Mario Six2161e552018-07-31 11:44:11 +0200291 */
Simon Glass458b66a2020-11-05 06:32:05 -0700292int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six2161e552018-07-31 11:44:11 +0200293
294/**
Raymond Mao860fa8b2024-12-06 14:54:19 -0800295 * sysinfo_get_data() - Get a data area from the platform.
296 * @dev: The sysinfo instance to gather the data.
297 * @id: A unique identifier for the data area to be get.
298 * @data: Pointer to the address of the data area.
299 * @size: Pointer to the size of the data area.
300 *
301 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
302 * error.
303 */
304int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size);
305
306/**
Simon Glass458b66a2020-11-05 06:32:05 -0700307 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
308 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six2161e552018-07-31 11:44:11 +0200309 *
Simon Glass458b66a2020-11-05 06:32:05 -0700310 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six2161e552018-07-31 11:44:11 +0200311 * function that returns the unique device. This is especially useful for use
Simon Glass458b66a2020-11-05 06:32:05 -0700312 * in sysinfo files.
Mario Six2161e552018-07-31 11:44:11 +0200313 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400314 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
315 * error.
Mario Six2161e552018-07-31 11:44:11 +0200316 */
Simon Glass458b66a2020-11-05 06:32:05 -0700317int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200318
319/**
Simon Glass458b66a2020-11-05 06:32:05 -0700320 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200321 * This function can be used to provide the image names based on runtime
322 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400323 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200324 *
Simon Glass458b66a2020-11-05 06:32:05 -0700325 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200326 * @index: Index of the image. Starts at 0 and gets incremented
327 * after each call to this function.
328 * @type: The type of image. For example, "fdt" for DTBs
329 * @strp: A pointer to string. Untouched if the function fails
330 *
331 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400332 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
333 * loadable is available else -ve on error.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200334 */
Simon Glass458b66a2020-11-05 06:32:05 -0700335int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
336 const char **strp);
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200337
338#else
339
Simon Glass458b66a2020-11-05 06:32:05 -0700340static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200341{
342 return -ENOSYS;
343}
344
Simon Glass458b66a2020-11-05 06:32:05 -0700345static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200346{
347 return -ENOSYS;
348}
349
Simon Glass458b66a2020-11-05 06:32:05 -0700350static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200351{
352 return -ENOSYS;
353}
354
Simon Glass458b66a2020-11-05 06:32:05 -0700355static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
356 char *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200357{
358 return -ENOSYS;
359}
360
Raymond Mao860fa8b2024-12-06 14:54:19 -0800361static inline int sysinfo_get_data(struct udevice *dev, int id, void **data,
362 size_t *size)
363{
364 return -ENOSYS;
365}
366
Simon Glass458b66a2020-11-05 06:32:05 -0700367static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200368{
369 return -ENOSYS;
370}
371
Simon Glass458b66a2020-11-05 06:32:05 -0700372static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
373 const char *type, const char **strp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200374{
375 return -ENOSYS;
376}
377
378#endif
Tom Rini55a297c2021-04-19 16:18:49 -0400379#endif