blob: f2c1aa29d18ed3bdb82cf117da4d6b372eeaae3b [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,
Simon Glassc2e06e92023-11-12 19:58:28 -070049 SYSINFO_ID_BOARD_MANUFACTURER,
50 SYSINFO_ID_PRIOR_STAGE_VERSION,
51 SYSINFO_ID_PRIOR_STAGE_DATE,
Simon Glass43bc5432021-03-21 16:50:06 +130052
Simon Glasscf67d6d2021-02-04 21:17:23 -070053 /* First value available for downstream/board used */
54 SYSINFO_ID_USER = 0x1000,
55};
56
Simon Glass458b66a2020-11-05 06:32:05 -070057struct sysinfo_ops {
Mario Six2161e552018-07-31 11:44:11 +020058 /**
59 * detect() - Run the hardware info detection procedure for this
60 * device.
61 * @dev: The device containing the information
62 *
63 * This operation might take a long time (e.g. read from EEPROM,
64 * check the presence of a device on a bus etc.), hence this is not
65 * done in the probe() method, but later during operation in this
Sean Anderson6ccf10a2021-04-20 10:50:56 -040066 * dedicated method. This method will be called before any other
67 * methods.
Mario Six2161e552018-07-31 11:44:11 +020068 *
69 * Return: 0 if OK, -ve on error.
70 */
71 int (*detect)(struct udevice *dev);
72
73 /**
74 * get_bool() - Read a specific bool data value that describes the
75 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -070076 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +020077 * @id: A unique identifier for the bool value to be read.
78 * @val: Pointer to a buffer that receives the value read.
79 *
80 * Return: 0 if OK, -ve on error.
81 */
82 int (*get_bool)(struct udevice *dev, int id, bool *val);
83
84 /**
85 * get_int() - Read a specific int 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 int 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_int)(struct udevice *dev, int id, int *val);
94
95 /**
96 * get_str() - Read a specific string 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 string value to be read.
100 * @size: The size of the buffer to receive the string data.
101 * @val: Pointer to a buffer that receives the value read.
102 *
103 * Return: 0 if OK, -ve on error.
104 */
105 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200106
107 /**
108 * get_fit_loadable - Get the name of an image to load from FIT
109 * This function can be used to provide the image names based on runtime
110 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400111 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200112 *
Simon Glass458b66a2020-11-05 06:32:05 -0700113 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200114 * @index: Index of the image. Starts at 0 and gets incremented
115 * after each call to this function.
116 * @type: The type of image. For example, "fdt" for DTBs
117 * @strp: A pointer to string. Untouched if the function fails
118 *
119 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
120 * error.
121 */
122 int (*get_fit_loadable)(struct udevice *dev, int index,
123 const char *type, const char **strp);
Mario Six2161e552018-07-31 11:44:11 +0200124};
125
Simon Glass458b66a2020-11-05 06:32:05 -0700126#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six2161e552018-07-31 11:44:11 +0200127
Simon Glass10e6f792021-02-04 21:17:21 -0700128#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six2161e552018-07-31 11:44:11 +0200129/**
Simon Glass458b66a2020-11-05 06:32:05 -0700130 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six2161e552018-07-31 11:44:11 +0200131 *
132 * @dev: The device containing the information
133 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400134 * This function must be called before any other accessor function for this
135 * device.
136 *
Mario Six2161e552018-07-31 11:44:11 +0200137 * Return: 0 if OK, -ve on error.
138 */
Simon Glass458b66a2020-11-05 06:32:05 -0700139int sysinfo_detect(struct udevice *dev);
Mario Six2161e552018-07-31 11:44:11 +0200140
141/**
Simon Glass458b66a2020-11-05 06:32:05 -0700142 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200143 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700144 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200145 * @id: A unique identifier for the bool value to be read.
146 * @val: Pointer to a buffer that receives the value read.
147 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400148 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
149 * error.
Mario Six2161e552018-07-31 11:44:11 +0200150 */
Simon Glass458b66a2020-11-05 06:32:05 -0700151int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six2161e552018-07-31 11:44:11 +0200152
153/**
Simon Glass458b66a2020-11-05 06:32:05 -0700154 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200155 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700156 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200157 * @id: A unique identifier for the int value to be read.
158 * @val: Pointer to a buffer that receives the value read.
159 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400160 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
161 * error.
Mario Six2161e552018-07-31 11:44:11 +0200162 */
Simon Glass458b66a2020-11-05 06:32:05 -0700163int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six2161e552018-07-31 11:44:11 +0200164
165/**
Simon Glass458b66a2020-11-05 06:32:05 -0700166 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six2161e552018-07-31 11:44:11 +0200167 * hardware setup.
Simon Glass458b66a2020-11-05 06:32:05 -0700168 * @dev: The sysinfo instance to gather the data.
Mario Six2161e552018-07-31 11:44:11 +0200169 * @id: A unique identifier for the string value to be read.
170 * @size: The size of the buffer to receive the string data.
171 * @val: Pointer to a buffer that receives the value read.
172 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400173 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
174 * error.
Mario Six2161e552018-07-31 11:44:11 +0200175 */
Simon Glass458b66a2020-11-05 06:32:05 -0700176int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six2161e552018-07-31 11:44:11 +0200177
178/**
Simon Glass458b66a2020-11-05 06:32:05 -0700179 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
180 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six2161e552018-07-31 11:44:11 +0200181 *
Simon Glass458b66a2020-11-05 06:32:05 -0700182 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six2161e552018-07-31 11:44:11 +0200183 * function that returns the unique device. This is especially useful for use
Simon Glass458b66a2020-11-05 06:32:05 -0700184 * in sysinfo files.
Mario Six2161e552018-07-31 11:44:11 +0200185 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400186 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
187 * error.
Mario Six2161e552018-07-31 11:44:11 +0200188 */
Simon Glass458b66a2020-11-05 06:32:05 -0700189int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200190
191/**
Simon Glass458b66a2020-11-05 06:32:05 -0700192 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200193 * This function can be used to provide the image names based on runtime
194 * detection. A classic use-case would when DTBOs are used to describe
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400195 * additional daughter cards.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200196 *
Simon Glass458b66a2020-11-05 06:32:05 -0700197 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200198 * @index: Index of the image. Starts at 0 and gets incremented
199 * after each call to this function.
200 * @type: The type of image. For example, "fdt" for DTBs
201 * @strp: A pointer to string. Untouched if the function fails
202 *
203 *
Sean Anderson6ccf10a2021-04-20 10:50:56 -0400204 * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
205 * loadable is available else -ve on error.
Jean-Jacques Hiblot7815fc12019-10-22 16:39:19 +0200206 */
Simon Glass458b66a2020-11-05 06:32:05 -0700207int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
208 const char **strp);
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200209
210#else
211
Simon Glass458b66a2020-11-05 06:32:05 -0700212static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200213{
214 return -ENOSYS;
215}
216
Simon Glass458b66a2020-11-05 06:32:05 -0700217static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200218{
219 return -ENOSYS;
220}
221
Simon Glass458b66a2020-11-05 06:32:05 -0700222static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200223{
224 return -ENOSYS;
225}
226
Simon Glass458b66a2020-11-05 06:32:05 -0700227static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
228 char *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(struct udevice **devp)
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_fit_loadable(struct udevice *dev, int index,
239 const char *type, const char **strp)
Jean-Jacques Hiblot98823aa2019-10-22 16:39:20 +0200240{
241 return -ENOSYS;
242}
243
244#endif
Tom Rini55a297c2021-04-19 16:18:49 -0400245#endif