blob: b140d742e93d1c4126c2e37e81ac5c47b9c07055 [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
Simon Glass401d1c42020-10-30 21:38:53 -060010struct udevice;
11
Mario Six5381c282018-07-31 11:44:11 +020012/*
13 * This uclass encapsulates hardware methods to gather information about a
Simon Glass3a8ee3d2020-11-05 06:32:05 -070014 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six5381c282018-07-31 11:44:11 +020015 * read-only data in flash ICs, or similar.
16 *
17 * The interface offers functions to read the usual standard data types (bool,
18 * int, string) from the device, each of which is identified by a static
19 * numeric ID (which will usually be defined as a enum in a header file).
20 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070021 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six5381c282018-07-31 11:44:11 +020022 * call
23 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070024 * ret = sysinfo_detect(dev);
Mario Six5381c282018-07-31 11:44:11 +020025 * if (ret) {
Simon Glass3a8ee3d2020-11-05 06:32:05 -070026 * debug("sysinfo device not found.");
Mario Six5381c282018-07-31 11:44:11 +020027 * return ret;
28 * }
29 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070030 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six5381c282018-07-31 11:44:11 +020031 * if (ret) {
32 * debug("Error when reading serial number from device.");
33 * return ret;
34 * }
35 *
36 * to read the serial number.
37 */
38
Simon Glass07c9e682021-02-04 21:17:23 -070039/** enum sysinfo_id - Standard IDs defined by U-Boot */
40enum sysinfo_id {
41 SYSINFO_ID_NONE,
42
Simon Glass96dedb02021-03-21 16:50:06 +130043 /* For SMBIOS tables */
Simon Glass07c9e682021-02-04 21:17:23 -070044 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
45 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
46
Simon Glass96dedb02021-03-21 16:50:06 +130047 /* For show_board_info() */
48 SYSINFO_ID_BOARD_MODEL,
49
Simon Glass07c9e682021-02-04 21:17:23 -070050 /* First value available for downstream/board used */
51 SYSINFO_ID_USER = 0x1000,
52};
53
Simon Glass3a8ee3d2020-11-05 06:32:05 -070054struct sysinfo_ops {
Mario Six5381c282018-07-31 11:44:11 +020055 /**
56 * detect() - Run the hardware info detection procedure for this
57 * device.
58 * @dev: The device containing the information
59 *
60 * This operation might take a long time (e.g. read from EEPROM,
61 * check the presence of a device on a bus etc.), hence this is not
62 * done in the probe() method, but later during operation in this
Sean Anderson4d65c6b2021-04-20 10:50:56 -040063 * dedicated method. This method will be called before any other
64 * methods.
Mario Six5381c282018-07-31 11:44:11 +020065 *
66 * Return: 0 if OK, -ve on error.
67 */
68 int (*detect)(struct udevice *dev);
69
70 /**
71 * get_bool() - Read a specific bool data value that describes the
72 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070073 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020074 * @id: A unique identifier for the bool value to be read.
75 * @val: Pointer to a buffer that receives the value read.
76 *
77 * Return: 0 if OK, -ve on error.
78 */
79 int (*get_bool)(struct udevice *dev, int id, bool *val);
80
81 /**
82 * get_int() - Read a specific int data value that describes the
83 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070084 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020085 * @id: A unique identifier for the int value to be read.
86 * @val: Pointer to a buffer that receives the value read.
87 *
88 * Return: 0 if OK, -ve on error.
89 */
90 int (*get_int)(struct udevice *dev, int id, int *val);
91
92 /**
93 * get_str() - Read a specific string data value that describes the
94 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070095 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020096 * @id: A unique identifier for the string value to be read.
97 * @size: The size of the buffer to receive the string data.
98 * @val: Pointer to a buffer that receives the value read.
99 *
100 * Return: 0 if OK, -ve on error.
101 */
102 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200103
104 /**
105 * get_fit_loadable - Get the name of an image to load from FIT
106 * This function can be used to provide the image names based on runtime
107 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400108 * additional daughter cards.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200109 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700110 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200111 * @index: Index of the image. Starts at 0 and gets incremented
112 * after each call to this function.
113 * @type: The type of image. For example, "fdt" for DTBs
114 * @strp: A pointer to string. Untouched if the function fails
115 *
116 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
117 * error.
118 */
119 int (*get_fit_loadable)(struct udevice *dev, int index,
120 const char *type, const char **strp);
Mario Six5381c282018-07-31 11:44:11 +0200121};
122
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700123#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six5381c282018-07-31 11:44:11 +0200124
Simon Glass2b8e5c82021-02-04 21:17:21 -0700125#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six5381c282018-07-31 11:44:11 +0200126/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700127 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six5381c282018-07-31 11:44:11 +0200128 *
129 * @dev: The device containing the information
130 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400131 * This function must be called before any other accessor function for this
132 * device.
133 *
Mario Six5381c282018-07-31 11:44:11 +0200134 * Return: 0 if OK, -ve on error.
135 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700136int sysinfo_detect(struct udevice *dev);
Mario Six5381c282018-07-31 11:44:11 +0200137
138/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700139 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200140 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700141 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200142 * @id: A unique identifier for the bool value to be read.
143 * @val: Pointer to a buffer that receives the value read.
144 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400145 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
146 * error.
Mario Six5381c282018-07-31 11:44:11 +0200147 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700148int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six5381c282018-07-31 11:44:11 +0200149
150/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700151 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200152 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700153 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200154 * @id: A unique identifier for the int value to be read.
155 * @val: Pointer to a buffer that receives the value read.
156 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400157 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
158 * error.
Mario Six5381c282018-07-31 11:44:11 +0200159 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700160int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six5381c282018-07-31 11:44:11 +0200161
162/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700163 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200164 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700165 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200166 * @id: A unique identifier for the string value to be read.
167 * @size: The size of the buffer to receive the string data.
168 * @val: Pointer to a buffer that receives the value read.
169 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400170 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
171 * error.
Mario Six5381c282018-07-31 11:44:11 +0200172 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700173int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six5381c282018-07-31 11:44:11 +0200174
175/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700176 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
177 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six5381c282018-07-31 11:44:11 +0200178 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700179 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six5381c282018-07-31 11:44:11 +0200180 * function that returns the unique device. This is especially useful for use
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700181 * in sysinfo files.
Mario Six5381c282018-07-31 11:44:11 +0200182 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400183 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
184 * error.
Mario Six5381c282018-07-31 11:44:11 +0200185 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700186int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200187
188/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700189 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200190 * This function can be used to provide the image names based on runtime
191 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400192 * additional daughter cards.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200193 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700194 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200195 * @index: Index of the image. Starts at 0 and gets incremented
196 * after each call to this function.
197 * @type: The type of image. For example, "fdt" for DTBs
198 * @strp: A pointer to string. Untouched if the function fails
199 *
200 *
Sean Anderson4d65c6b2021-04-20 10:50:56 -0400201 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
202 * loadable is available else -ve on error.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200203 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700204int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
205 const char **strp);
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200206
207#else
208
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700209static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200210{
211 return -ENOSYS;
212}
213
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700214static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
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_int(struct udevice *dev, int id, int *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_str(struct udevice *dev, int id, size_t size,
225 char *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200226{
227 return -ENOSYS;
228}
229
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700230static inline int sysinfo_get(struct udevice **devp)
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_fit_loadable(struct udevice *dev, int index,
236 const char *type, const char **strp)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200237{
238 return -ENOSYS;
239}
240
241#endif
Tom Rini56a34332021-04-19 16:18:49 -0400242#endif