blob: 524c7d6b223f9eef98982e3601c59187e6548dbf [file] [log] [blame]
Mario Six5381c282018-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 Rini56a34332021-04-19 16:18:49 -04007#ifndef __SYSINFO_H__
8#define __SYSINFO_H__
9
Max Krummenachere2e69292024-01-18 19:10:47 +010010#include <linux/errno.h>
11
Simon Glass401d1c42020-10-30 21:38:53 -060012struct udevice;
13
Mario Six5381c282018-07-31 11:44:11 +020014/*
15 * This uclass encapsulates hardware methods to gather information about a
Simon Glass3a8ee3d2020-11-05 06:32:05 -070016 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six5381c282018-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 Glass3a8ee3d2020-11-05 06:32:05 -070023 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six5381c282018-07-31 11:44:11 +020024 * call
25 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070026 * ret = sysinfo_detect(dev);
Mario Six5381c282018-07-31 11:44:11 +020027 * if (ret) {
Simon Glass3a8ee3d2020-11-05 06:32:05 -070028 * debug("sysinfo device not found.");
Mario Six5381c282018-07-31 11:44:11 +020029 * return ret;
30 * }
31 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070032 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six5381c282018-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 Glass07c9e682021-02-04 21:17:23 -070041/** enum sysinfo_id - Standard IDs defined by U-Boot */
42enum sysinfo_id {
43 SYSINFO_ID_NONE,
44
Simon Glass96dedb02021-03-21 16:50:06 +130045 /* For SMBIOS tables */
Simon Glass07c9e682021-02-04 21:17:23 -070046 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
47 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
48
Simon Glass96dedb02021-03-21 16:50:06 +130049 /* For show_board_info() */
50 SYSINFO_ID_BOARD_MODEL,
Simon Glass6f646d12023-11-12 19:58:28 -070051 SYSINFO_ID_BOARD_MANUFACTURER,
52 SYSINFO_ID_PRIOR_STAGE_VERSION,
53 SYSINFO_ID_PRIOR_STAGE_DATE,
Simon Glass96dedb02021-03-21 16:50:06 +130054
Simon Glass07c9e682021-02-04 21:17:23 -070055 /* First value available for downstream/board used */
56 SYSINFO_ID_USER = 0x1000,
57};
58
Simon Glass3a8ee3d2020-11-05 06:32:05 -070059struct sysinfo_ops {
Mario Six5381c282018-07-31 11:44:11 +020060 /**
61 * detect() - Run the hardware info detection procedure for this
62 * device.
63 * @dev: The device containing the information
64 *
65 * This operation might take a long time (e.g. read from EEPROM,
66 * check the presence of a device on a bus etc.), hence this is not
67 * done in the probe() method, but later during operation in this
Sean Anderson4d65c6b2021-04-20 10:50:56 -040068 * dedicated method. This method will be called before any other
69 * methods.
Mario Six5381c282018-07-31 11:44:11 +020070 *
71 * Return: 0 if OK, -ve on error.
72 */
73 int (*detect)(struct udevice *dev);
74
75 /**
76 * get_bool() - Read a specific bool data value that describes the
77 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070078 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020079 * @id: A unique identifier for the bool value to be read.
80 * @val: Pointer to a buffer that receives the value read.
81 *
82 * Return: 0 if OK, -ve on error.
83 */
84 int (*get_bool)(struct udevice *dev, int id, bool *val);
85
86 /**
87 * get_int() - Read a specific int data value that describes the
88 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070089 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020090 * @id: A unique identifier for the int value to be read.
91 * @val: Pointer to a buffer that receives the value read.
92 *
93 * Return: 0 if OK, -ve on error.
94 */
95 int (*get_int)(struct udevice *dev, int id, int *val);
96
97 /**
98 * get_str() - Read a specific string data value that describes the
99 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700100 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200101 * @id: A unique identifier for the string value to be read.
102 * @size: The size of the buffer to receive the string data.
103 * @val: Pointer to a buffer that receives the value read.
104 *
105 * Return: 0 if OK, -ve on error.
106 */
107 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200108
109 /**
110 * get_fit_loadable - Get the name of an image to load from FIT
111 * This function can be used to provide the image names based on runtime
112 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400113 * additional daughter cards.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200114 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700115 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200116 * @index: Index of the image. Starts at 0 and gets incremented
117 * after each call to this function.
118 * @type: The type of image. For example, "fdt" for DTBs
119 * @strp: A pointer to string. Untouched if the function fails
120 *
121 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
122 * error.
123 */
124 int (*get_fit_loadable)(struct udevice *dev, int index,
125 const char *type, const char **strp);
Mario Six5381c282018-07-31 11:44:11 +0200126};
127
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700128#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six5381c282018-07-31 11:44:11 +0200129
Simon Glass2b8e5c82021-02-04 21:17:21 -0700130#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six5381c282018-07-31 11:44:11 +0200131/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700132 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six5381c282018-07-31 11:44:11 +0200133 *
134 * @dev: The device containing the information
135 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400136 * This function must be called before any other accessor function for this
137 * device.
138 *
Mario Six5381c282018-07-31 11:44:11 +0200139 * Return: 0 if OK, -ve on error.
140 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700141int sysinfo_detect(struct udevice *dev);
Mario Six5381c282018-07-31 11:44:11 +0200142
143/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700144 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200145 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700146 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200147 * @id: A unique identifier for the bool value to be read.
148 * @val: Pointer to a buffer that receives the value read.
149 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400150 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
151 * error.
Mario Six5381c282018-07-31 11:44:11 +0200152 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700153int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six5381c282018-07-31 11:44:11 +0200154
155/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700156 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200157 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700158 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200159 * @id: A unique identifier for the int value to be read.
160 * @val: Pointer to a buffer that receives the value read.
161 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400162 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
163 * error.
Mario Six5381c282018-07-31 11:44:11 +0200164 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700165int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six5381c282018-07-31 11:44:11 +0200166
167/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700168 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200169 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700170 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200171 * @id: A unique identifier for the string value to be read.
172 * @size: The size of the buffer to receive the string data.
173 * @val: Pointer to a buffer that receives the value read.
174 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400175 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
176 * error.
Mario Six5381c282018-07-31 11:44:11 +0200177 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700178int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six5381c282018-07-31 11:44:11 +0200179
180/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700181 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
182 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six5381c282018-07-31 11:44:11 +0200183 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700184 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six5381c282018-07-31 11:44:11 +0200185 * function that returns the unique device. This is especially useful for use
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700186 * in sysinfo files.
Mario Six5381c282018-07-31 11:44:11 +0200187 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400188 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
189 * error.
Mario Six5381c282018-07-31 11:44:11 +0200190 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700191int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200192
193/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700194 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200195 * This function can be used to provide the image names based on runtime
196 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400197 * additional daughter cards.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200198 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700199 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200200 * @index: Index of the image. Starts at 0 and gets incremented
201 * after each call to this function.
202 * @type: The type of image. For example, "fdt" for DTBs
203 * @strp: A pointer to string. Untouched if the function fails
204 *
205 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400206 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
207 * loadable is available else -ve on error.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200208 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700209int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
210 const char **strp);
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200211
212#else
213
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700214static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200215{
216 return -ENOSYS;
217}
218
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700219static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200220{
221 return -ENOSYS;
222}
223
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700224static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200225{
226 return -ENOSYS;
227}
228
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700229static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
230 char *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200231{
232 return -ENOSYS;
233}
234
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700235static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200236{
237 return -ENOSYS;
238}
239
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700240static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
241 const char *type, const char **strp)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200242{
243 return -ENOSYS;
244}
245
246#endif
Tom Rini56a34332021-04-19 16:18:49 -0400247#endif