Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * (C) Copyright 2017 |
| 4 | * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
| 5 | */ |
| 6 | |
Tom Rini | 56a3433 | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 7 | #ifndef __SYSINFO_H__ |
| 8 | #define __SYSINFO_H__ |
| 9 | |
Max Krummenacher | e2e6929 | 2024-01-18 19:10:47 +0100 | [diff] [blame] | 10 | #include <linux/errno.h> |
| 11 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | struct udevice; |
| 13 | |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 14 | /* |
| 15 | * This uclass encapsulates hardware methods to gather information about a |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 16 | * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders, |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 17 | * 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 Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 23 | * If for example the sysinfo had a read-only serial number flash IC, we could |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 24 | * call |
| 25 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 26 | * ret = sysinfo_detect(dev); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 27 | * if (ret) { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 28 | * debug("sysinfo device not found."); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 29 | * return ret; |
| 30 | * } |
| 31 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 32 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 33 | * 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 Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 41 | /** enum sysinfo_id - Standard IDs defined by U-Boot */ |
| 42 | enum sysinfo_id { |
| 43 | SYSINFO_ID_NONE, |
| 44 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 45 | /* For SMBIOS tables */ |
Simon Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 46 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
| 47 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, |
| 48 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 49 | /* For show_board_info() */ |
| 50 | SYSINFO_ID_BOARD_MODEL, |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 51 | SYSINFO_ID_BOARD_MANUFACTURER, |
| 52 | SYSINFO_ID_PRIOR_STAGE_VERSION, |
| 53 | SYSINFO_ID_PRIOR_STAGE_DATE, |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 54 | |
Simon Glass | 07c9e68 | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 55 | /* First value available for downstream/board used */ |
| 56 | SYSINFO_ID_USER = 0x1000, |
| 57 | }; |
| 58 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 59 | struct sysinfo_ops { |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 60 | /** |
| 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 Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 68 | * dedicated method. This method will be called before any other |
| 69 | * methods. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 70 | * |
| 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 Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 78 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 79 | * @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 Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 89 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 90 | * @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 Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 100 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 101 | * @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 Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 108 | |
| 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 Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 113 | * additional daughter cards. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 114 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 115 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 116 | * @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 Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 128 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 129 | |
Simon Glass | 2b8e5c8 | 2021-02-04 21:17:21 -0700 | [diff] [blame] | 130 | #if CONFIG_IS_ENABLED(SYSINFO) |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 131 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 132 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 133 | * |
| 134 | * @dev: The device containing the information |
| 135 | * |
Sean Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 136 | * This function must be called before any other accessor function for this |
| 137 | * device. |
| 138 | * |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 139 | * Return: 0 if OK, -ve on error. |
| 140 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 141 | int sysinfo_detect(struct udevice *dev); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 142 | |
| 143 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 144 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 145 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 146 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 147 | * @id: A unique identifier for the bool value to be read. |
| 148 | * @val: Pointer to a buffer that receives the value read. |
| 149 | * |
Sean Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 150 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 151 | * error. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 152 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 153 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 154 | |
| 155 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 156 | * sysinfo_get_int() - Read a specific int data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 157 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 158 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 159 | * @id: A unique identifier for the int value to be read. |
| 160 | * @val: Pointer to a buffer that receives the value read. |
| 161 | * |
Sean Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 162 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 163 | * error. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 164 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 165 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 166 | |
| 167 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 168 | * sysinfo_get_str() - Read a specific string data value that describes the |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 169 | * hardware setup. |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 170 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 171 | * @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 Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 175 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 176 | * error. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 177 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 178 | int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 179 | |
| 180 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 181 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
| 182 | * @devp: Pointer to structure to receive the sysinfo device. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 183 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 184 | * Since there can only be at most one sysinfo instance, the API can supply a |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 185 | * function that returns the unique device. This is especially useful for use |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 186 | * in sysinfo files. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 187 | * |
Sean Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 188 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 189 | * error. |
Mario Six | 5381c28 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 190 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 191 | int sysinfo_get(struct udevice **devp); |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 192 | |
| 193 | /** |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 194 | * sysinfo_get_fit_loadable - Get the name of an image to load from FIT |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 195 | * 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 Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 197 | * additional daughter cards. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 198 | * |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 199 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 200 | * @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 Anderson | 4d65c6b | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 206 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no |
| 207 | * loadable is available else -ve on error. |
Jean-Jacques Hiblot | d42730e | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 208 | */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 209 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
| 210 | const char **strp); |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 211 | |
| 212 | #else |
| 213 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 214 | static inline int sysinfo_detect(struct udevice *dev) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 215 | { |
| 216 | return -ENOSYS; |
| 217 | } |
| 218 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 219 | static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 220 | { |
| 221 | return -ENOSYS; |
| 222 | } |
| 223 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 224 | static inline int sysinfo_get_int(struct udevice *dev, int id, int *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 225 | { |
| 226 | return -ENOSYS; |
| 227 | } |
| 228 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 229 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
| 230 | char *val) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 231 | { |
| 232 | return -ENOSYS; |
| 233 | } |
| 234 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 235 | static inline int sysinfo_get(struct udevice **devp) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 236 | { |
| 237 | return -ENOSYS; |
| 238 | } |
| 239 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 240 | static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, |
| 241 | const char *type, const char **strp) |
Jean-Jacques Hiblot | 02806e9 | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 242 | { |
| 243 | return -ENOSYS; |
| 244 | } |
| 245 | |
| 246 | #endif |
Tom Rini | 56a3433 | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 247 | #endif |