Mario Six | 2161e55 | 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 | 55a297c | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 7 | #ifndef __SYSINFO_H__ |
| 8 | #define __SYSINFO_H__ |
| 9 | |
Max Krummenacher | 0e226eb | 2024-01-18 19:10:47 +0100 | [diff] [blame] | 10 | #include <linux/errno.h> |
| 11 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | struct udevice; |
| 13 | |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 14 | /* |
| 15 | * This uclass encapsulates hardware methods to gather information about a |
Simon Glass | 458b66a | 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 | 2161e55 | 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 | 458b66a | 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 | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 24 | * call |
| 25 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 26 | * ret = sysinfo_detect(dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 27 | * if (ret) { |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 28 | * debug("sysinfo device not found."); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 29 | * return ret; |
| 30 | * } |
| 31 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 32 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
Mario Six | 2161e55 | 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 | cf67d6d | 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 | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 45 | /* For SMBIOS tables */ |
Michal Simek | a7aa395 | 2024-04-26 15:38:13 +0200 | [diff] [blame] | 46 | SYSINFO_ID_SMBIOS_SYSTEM_MANUFACTURER, |
| 47 | SYSINFO_ID_SMBIOS_SYSTEM_PRODUCT, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 48 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
Michal Simek | a7aa395 | 2024-04-26 15:38:13 +0200 | [diff] [blame] | 49 | SYSINFO_ID_SMBIOS_SYSTEM_SERIAL, |
| 50 | SYSINFO_ID_SMBIOS_SYSTEM_SKU, |
| 51 | SYSINFO_ID_SMBIOS_SYSTEM_FAMILY, |
| 52 | SYSINFO_ID_SMBIOS_BASEBOARD_MANUFACTURER, |
| 53 | SYSINFO_ID_SMBIOS_BASEBOARD_PRODUCT, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 54 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, |
Michal Simek | a7aa395 | 2024-04-26 15:38:13 +0200 | [diff] [blame] | 55 | SYSINFO_ID_SMBIOS_BASEBOARD_SERIAL, |
| 56 | SYSINFO_ID_SMBIOS_BASEBOARD_ASSET_TAG, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 57 | |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 58 | /* For show_board_info() */ |
| 59 | SYSINFO_ID_BOARD_MODEL, |
Simon Glass | c2e06e9 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 60 | SYSINFO_ID_BOARD_MANUFACTURER, |
| 61 | SYSINFO_ID_PRIOR_STAGE_VERSION, |
| 62 | SYSINFO_ID_PRIOR_STAGE_DATE, |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 63 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 64 | /* First value available for downstream/board used */ |
| 65 | SYSINFO_ID_USER = 0x1000, |
| 66 | }; |
| 67 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 68 | struct sysinfo_ops { |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 69 | /** |
| 70 | * detect() - Run the hardware info detection procedure for this |
| 71 | * device. |
| 72 | * @dev: The device containing the information |
| 73 | * |
| 74 | * This operation might take a long time (e.g. read from EEPROM, |
| 75 | * check the presence of a device on a bus etc.), hence this is not |
| 76 | * done in the probe() method, but later during operation in this |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 77 | * dedicated method. This method will be called before any other |
| 78 | * methods. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 79 | * |
| 80 | * Return: 0 if OK, -ve on error. |
| 81 | */ |
| 82 | int (*detect)(struct udevice *dev); |
| 83 | |
| 84 | /** |
| 85 | * get_bool() - Read a specific bool data value that describes the |
| 86 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 87 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 88 | * @id: A unique identifier for the bool 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_bool)(struct udevice *dev, int id, bool *val); |
| 94 | |
| 95 | /** |
| 96 | * get_int() - Read a specific int data value that describes the |
| 97 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 98 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 99 | * @id: A unique identifier for the int value to be read. |
| 100 | * @val: Pointer to a buffer that receives the value read. |
| 101 | * |
| 102 | * Return: 0 if OK, -ve on error. |
| 103 | */ |
| 104 | int (*get_int)(struct udevice *dev, int id, int *val); |
| 105 | |
| 106 | /** |
| 107 | * get_str() - Read a specific string data value that describes the |
| 108 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 109 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 110 | * @id: A unique identifier for the string value to be read. |
| 111 | * @size: The size of the buffer to receive the string data. |
| 112 | * @val: Pointer to a buffer that receives the value read. |
| 113 | * |
| 114 | * Return: 0 if OK, -ve on error. |
| 115 | */ |
| 116 | int (*get_str)(struct udevice *dev, int id, size_t size, char *val); |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * get_fit_loadable - Get the name of an image to load from FIT |
| 120 | * This function can be used to provide the image names based on runtime |
| 121 | * detection. A classic use-case would when DTBOs are used to describe |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 122 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 123 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 124 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 125 | * @index: Index of the image. Starts at 0 and gets incremented |
| 126 | * after each call to this function. |
| 127 | * @type: The type of image. For example, "fdt" for DTBs |
| 128 | * @strp: A pointer to string. Untouched if the function fails |
| 129 | * |
| 130 | * Return: 0 if OK, -ENOENT if no loadable is available else -ve on |
| 131 | * error. |
| 132 | */ |
| 133 | int (*get_fit_loadable)(struct udevice *dev, int index, |
| 134 | const char *type, const char **strp); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 137 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 138 | |
Simon Glass | 10e6f79 | 2021-02-04 21:17:21 -0700 | [diff] [blame] | 139 | #if CONFIG_IS_ENABLED(SYSINFO) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 140 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 141 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 142 | * |
| 143 | * @dev: The device containing the information |
| 144 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 145 | * This function must be called before any other accessor function for this |
| 146 | * device. |
| 147 | * |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 148 | * Return: 0 if OK, -ve on error. |
| 149 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 150 | int sysinfo_detect(struct udevice *dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 151 | |
| 152 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 153 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 154 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 155 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 156 | * @id: A unique identifier for the bool value to be read. |
| 157 | * @val: Pointer to a buffer that receives the value read. |
| 158 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 159 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 160 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 161 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 162 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 163 | |
| 164 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 165 | * sysinfo_get_int() - Read a specific int data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 166 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 167 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 168 | * @id: A unique identifier for the int value to be read. |
| 169 | * @val: Pointer to a buffer that receives the value read. |
| 170 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 171 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 172 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 173 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 174 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 175 | |
| 176 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 177 | * sysinfo_get_str() - Read a specific string data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 178 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 179 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 180 | * @id: A unique identifier for the string value to be read. |
| 181 | * @size: The size of the buffer to receive the string data. |
| 182 | * @val: Pointer to a buffer that receives the value read. |
| 183 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 184 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 185 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 186 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 187 | int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 188 | |
| 189 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 190 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
| 191 | * @devp: Pointer to structure to receive the sysinfo device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 192 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 193 | * Since there can only be at most one sysinfo instance, the API can supply a |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 194 | * function that returns the unique device. This is especially useful for use |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 195 | * in sysinfo files. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 196 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 197 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 198 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 199 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 200 | int sysinfo_get(struct udevice **devp); |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 201 | |
| 202 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 203 | * sysinfo_get_fit_loadable - Get the name of an image to load from FIT |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 204 | * This function can be used to provide the image names based on runtime |
| 205 | * detection. A classic use-case would when DTBOs are used to describe |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 206 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 207 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 208 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 209 | * @index: Index of the image. Starts at 0 and gets incremented |
| 210 | * after each call to this function. |
| 211 | * @type: The type of image. For example, "fdt" for DTBs |
| 212 | * @strp: A pointer to string. Untouched if the function fails |
| 213 | * |
| 214 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 215 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no |
| 216 | * loadable is available else -ve on error. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 217 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 218 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
| 219 | const char **strp); |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 220 | |
| 221 | #else |
| 222 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 223 | static inline int sysinfo_detect(struct udevice *dev) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 224 | { |
| 225 | return -ENOSYS; |
| 226 | } |
| 227 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 228 | static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 229 | { |
| 230 | return -ENOSYS; |
| 231 | } |
| 232 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 233 | static inline int sysinfo_get_int(struct udevice *dev, int id, int *val) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 234 | { |
| 235 | return -ENOSYS; |
| 236 | } |
| 237 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 238 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
| 239 | char *val) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 240 | { |
| 241 | return -ENOSYS; |
| 242 | } |
| 243 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 244 | static inline int sysinfo_get(struct udevice **devp) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 245 | { |
| 246 | return -ENOSYS; |
| 247 | } |
| 248 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 249 | static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, |
| 250 | const char *type, const char **strp) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 251 | { |
| 252 | return -ENOSYS; |
| 253 | } |
| 254 | |
| 255 | #endif |
Tom Rini | 55a297c | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 256 | #endif |