blob: b140d742e93d1c4126c2e37e81ac5c47b9c07055 [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
Simon Glass3ba929a2020-10-30 21:38:53 -060010struct udevice;
11
Mario Six2161e552018-07-31 11:44:11 +020012/*
13 * This uclass encapsulates hardware methods to gather information about a
Simon Glass458b66a2020-11-05 06:32:05 -070014 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six2161e552018-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 Glass458b66a2020-11-05 06:32:05 -070021 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six2161e552018-07-31 11:44:11 +020022 * call
23 *
Simon Glass458b66a2020-11-05 06:32:05 -070024 * ret = sysinfo_detect(dev);
Mario Six2161e552018-07-31 11:44:11 +020025 * if (ret) {
Simon Glass458b66a2020-11-05 06:32:05 -070026 * debug("sysinfo device not found.");
Mario Six2161e552018-07-31 11:44:11 +020027 * return ret;
28 * }
29 *
Simon Glass458b66a2020-11-05 06:32:05 -070030 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six2161e552018-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 Glasscf67d6d2021-02-04 21:17:23 -070039/** enum sysinfo_id - Standard IDs defined by U-Boot */
40enum sysinfo_id {
41 SYSINFO_ID_NONE,
42
Simon Glass43bc5432021-03-21 16:50:06 +130043 /* For SMBIOS tables */
Simon Glasscf67d6d2021-02-04 21:17:23 -070044 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
45 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
46
Simon Glass43bc5432021-03-21 16:50:06 +130047 /* For show_board_info() */
48 SYSINFO_ID_BOARD_MODEL,
49
Simon Glasscf67d6d2021-02-04 21:17:23 -070050 /* First value available for downstream/board used */
51 SYSINFO_ID_USER = 0x1000,
52};
53
Simon Glass458b66a2020-11-05 06:32:05 -070054struct sysinfo_ops {
Mario Six2161e552018-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 Anderson6ccf10a2021-04-20 10:50:56 -040063 * dedicated method. This method will be called before any other
64 * methods.
Mario Six2161e552018-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 Glass458b66a2020-11-05 06:32:05 -070073 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Glass458b66a2020-11-05 06:32:05 -070084 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Glass458b66a2020-11-05 06:32:05 -070095 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Hiblot7815fc12019-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 Anderson6ccf10a2021-04-20 10:50:56 -0400108 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200109 *
Simon Glass458b66a2020-11-05 06:32:05 -0700110 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-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 Six2161e552018-07-31 11:44:11 +0200121};
122
Simon Glass458b66a2020-11-05 06:32:05 -0700123#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six2161e552018-07-31 11:44:11 +0200124
Simon Glass10e6f792021-02-04 21:17:21 -0700125#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six2161e552018-07-31 11:44:11 +0200126/**
Simon Glass458b66a2020-11-05 06:32:05 -0700127 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six2161e552018-07-31 11:44:11 +0200128 *
129 * @dev: The device containing the information
130 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400131 * This function must be called before any other accessor function for this
132 * device.
133 *
Mario Six2161e552018-07-31 11:44:11 +0200134 * Return: 0 if OK, -ve on error.
135 */
Simon Glass458b66a2020-11-05 06:32:05 -0700136int sysinfo_detect(struct udevice *dev);
Mario Six2161e552018-07-31 11:44:11 +0200137
138/**
Simon Glass458b66a2020-11-05 06:32:05 -0700139 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200140 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700141 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Anderson6ccf10a2021-04-20 10:50:56 -0400145 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
146 * error.
Mario Six2161e552018-07-31 11:44:11 +0200147 */
Simon Glass458b66a2020-11-05 06:32:05 -0700148int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six2161e552018-07-31 11:44:11 +0200149
150/**
Simon Glass458b66a2020-11-05 06:32:05 -0700151 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200152 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700153 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Anderson6ccf10a2021-04-20 10:50:56 -0400157 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
158 * error.
Mario Six2161e552018-07-31 11:44:11 +0200159 */
Simon Glass458b66a2020-11-05 06:32:05 -0700160int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six2161e552018-07-31 11:44:11 +0200161
162/**
Simon Glass458b66a2020-11-05 06:32:05 -0700163 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200164 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700165 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-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 Anderson6ccf10a2021-04-20 10:50:56 -0400170 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
171 * error.
Mario Six2161e552018-07-31 11:44:11 +0200172 */
Simon Glass458b66a2020-11-05 06:32:05 -0700173int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six2161e552018-07-31 11:44:11 +0200174
175/**
Simon Glass458b66a2020-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 Six2161e552018-07-31 11:44:11 +0200178 *
Simon Glass458b66a2020-11-05 06:32:05 -0700179 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six2161e552018-07-31 11:44:11 +0200180 * function that returns the unique device. This is especially useful for use
Simon Glass458b66a2020-11-05 06:32:05 -0700181 * in sysinfo files.
Mario Six2161e552018-07-31 11:44:11 +0200182 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400183 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
184 * error.
Mario Six2161e552018-07-31 11:44:11 +0200185 */
Simon Glass458b66a2020-11-05 06:32:05 -0700186int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200187
188/**
Simon Glass458b66a2020-11-05 06:32:05 -0700189 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblot7815fc12019-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 Anderson6ccf10a2021-04-20 10:50:56 -0400192 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200193 *
Simon Glass458b66a2020-11-05 06:32:05 -0700194 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-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 Anderson6ccf10a2021-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 Hiblot7815fc12019-10-22 16:39:19 +0200203 */
Simon Glass458b66a2020-11-05 06:32:05 -0700204int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
205 const char **strp);
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200206
207#else
208
Simon Glass458b66a2020-11-05 06:32:05 -0700209static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200210{
211 return -ENOSYS;
212}
213
Simon Glass458b66a2020-11-05 06:32:05 -0700214static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200215{
216 return -ENOSYS;
217}
218
Simon Glass458b66a2020-11-05 06:32:05 -0700219static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200220{
221 return -ENOSYS;
222}
223
Simon Glass458b66a2020-11-05 06:32:05 -0700224static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
225 char *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200226{
227 return -ENOSYS;
228}
229
Simon Glass458b66a2020-11-05 06:32:05 -0700230static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200231{
232 return -ENOSYS;
233}
234
Simon Glass458b66a2020-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 Hiblot98823aa2019-10-22 16:39:20 +0200237{
238 return -ENOSYS;
239}
240
241#endif
Tom Rini55a297c2021-04-19 16:18:49 -0400242#endif