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 | |
Raymond Mao | 8fe0731 | 2024-12-06 14:54:21 -0800 | [diff] [blame] | 14 | #define SYSINFO_CACHE_LVL_MAX 3 |
| 15 | |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 16 | /* |
| 17 | * This uclass encapsulates hardware methods to gather information about a |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 18 | * 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] | 19 | * read-only data in flash ICs, or similar. |
| 20 | * |
| 21 | * The interface offers functions to read the usual standard data types (bool, |
| 22 | * int, string) from the device, each of which is identified by a static |
| 23 | * numeric ID (which will usually be defined as a enum in a header file). |
| 24 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 25 | * 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] | 26 | * call |
| 27 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 28 | * ret = sysinfo_detect(dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 29 | * if (ret) { |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 30 | * debug("sysinfo device not found."); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 31 | * return ret; |
| 32 | * } |
| 33 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 34 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 35 | * if (ret) { |
| 36 | * debug("Error when reading serial number from device."); |
| 37 | * return ret; |
| 38 | * } |
| 39 | * |
| 40 | * to read the serial number. |
| 41 | */ |
| 42 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 43 | /** enum sysinfo_id - Standard IDs defined by U-Boot */ |
| 44 | enum sysinfo_id { |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 45 | SYSID_NONE, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 46 | |
Raymond Mao | 8fe0731 | 2024-12-06 14:54:21 -0800 | [diff] [blame] | 47 | /* BIOS Information (Type 0) */ |
| 48 | SYSID_SM_BIOS_VENDOR, |
| 49 | SYSID_SM_BIOS_VER, |
| 50 | SYSID_SM_BIOS_REL_DATE, |
| 51 | |
| 52 | /* System Information (Type 1) */ |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 53 | SYSID_SM_SYSTEM_MANUFACTURER, |
| 54 | SYSID_SM_SYSTEM_PRODUCT, |
| 55 | SYSID_SM_SYSTEM_VERSION, |
| 56 | SYSID_SM_SYSTEM_SERIAL, |
Raymond Mao | 8fe0731 | 2024-12-06 14:54:21 -0800 | [diff] [blame] | 57 | SYSID_SM_SYSTEM_WAKEUP, |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 58 | SYSID_SM_SYSTEM_SKU, |
| 59 | SYSID_SM_SYSTEM_FAMILY, |
Baocheng Su | 5cb083e | 2025-02-18 10:36:10 +0800 | [diff] [blame] | 60 | SYSID_SM_SYSTEM_UUID, |
Raymond Mao | 8fe0731 | 2024-12-06 14:54:21 -0800 | [diff] [blame] | 61 | |
| 62 | /* Baseboard (or Module) Information (Type 2) */ |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 63 | SYSID_SM_BASEBOARD_MANUFACTURER, |
| 64 | SYSID_SM_BASEBOARD_PRODUCT, |
| 65 | SYSID_SM_BASEBOARD_VERSION, |
| 66 | SYSID_SM_BASEBOARD_SERIAL, |
| 67 | SYSID_SM_BASEBOARD_ASSET_TAG, |
Raymond Mao | 8fe0731 | 2024-12-06 14:54:21 -0800 | [diff] [blame] | 68 | SYSID_SM_BASEBOARD_FEATURE, |
| 69 | SYSID_SM_BASEBOARD_CHASSIS_LOCAT, |
| 70 | SYSID_SM_BASEBOARD_TYPE, |
| 71 | SYSID_SM_BASEBOARD_OBJS_NUM, |
| 72 | SYSID_SM_BASEBOARD_OBJS_HANDLE, |
| 73 | |
| 74 | /* System Enclosure or Chassis (Type 3) */ |
| 75 | SYSID_SM_ENCLOSURE_MANUFACTURER, |
| 76 | SYSID_SM_ENCLOSURE_VERSION, |
| 77 | SYSID_SM_ENCLOSURE_SERIAL, |
| 78 | SYSID_SM_ENCLOSURE_ASSET_TAG, |
| 79 | SYSID_SM_ENCLOSURE_TYPE, |
| 80 | SYSID_SM_ENCLOSURE_BOOTUP, |
| 81 | SYSID_SM_ENCLOSURE_POW, |
| 82 | SYSID_SM_ENCLOSURE_THERMAL, |
| 83 | SYSID_SM_ENCLOSURE_SECURITY, |
| 84 | SYSID_SM_ENCLOSURE_OEM, |
| 85 | SYSID_SM_ENCLOSURE_HEIGHT, |
| 86 | SYSID_SM_ENCLOSURE_POWCORE_NUM, |
| 87 | SYSID_SM_ENCLOSURE_ELEMENT_CNT, |
| 88 | SYSID_SM_ENCLOSURE_ELEMENT_LEN, |
| 89 | SYSID_SM_ENCLOSURE_ELEMENTS, |
| 90 | SYSID_SM_ENCLOSURE_SKU, |
| 91 | |
| 92 | /* Processor Information (Type 4) */ |
| 93 | SYSID_SM_PROCESSOR_SOCKET, |
| 94 | SYSID_SM_PROCESSOR_TYPE, |
| 95 | SYSID_SM_PROCESSOR_MANUFACT, |
| 96 | SYSID_SM_PROCESSOR_ID, |
| 97 | SYSID_SM_PROCESSOR_VERSION, |
| 98 | SYSID_SM_PROCESSOR_VOLTAGE, |
| 99 | SYSID_SM_PROCESSOR_EXT_CLOCK, |
| 100 | SYSID_SM_PROCESSOR_MAX_SPEED, |
| 101 | SYSID_SM_PROCESSOR_CUR_SPEED, |
| 102 | SYSID_SM_PROCESSOR_STATUS, |
| 103 | SYSID_SM_PROCESSOR_UPGRADE, |
| 104 | SYSID_SM_PROCESSOR_SN, |
| 105 | SYSID_SM_PROCESSOR_ASSET_TAG, |
| 106 | SYSID_SM_PROCESSOR_PN, |
| 107 | SYSID_SM_PROCESSOR_CORE_CNT, |
| 108 | SYSID_SM_PROCESSOR_CORE_EN, |
| 109 | SYSID_SM_PROCESSOR_THREAD_CNT, |
| 110 | SYSID_SM_PROCESSOR_CHARA, |
| 111 | SYSID_SM_PROCESSOR_FAMILY, |
| 112 | SYSID_SM_PROCESSOR_FAMILY2, |
| 113 | SYSID_SM_PROCESSOR_CORE_CNT2, |
| 114 | SYSID_SM_PROCESSOR_CORE_EN2, |
| 115 | SYSID_SM_PROCESSOR_THREAD_CNT2, |
| 116 | SYSID_SM_PROCESSOR_THREAD_EN, |
| 117 | |
| 118 | /* |
| 119 | * Cache Information (Type 7) |
| 120 | * Each of the id should reserve space for up to |
| 121 | * SYSINFO_CACHE_LVL_MAX levels of cache |
| 122 | */ |
| 123 | SYSID_SM_CACHE_LEVEL, |
| 124 | SYSID_SM_CACHE_HANDLE, |
| 125 | SYSID_SM_CACHE_INFO_START, |
| 126 | SYSID_SM_CACHE_SOCKET = SYSID_SM_CACHE_INFO_START, |
| 127 | SYSID_SM_CACHE_CONFIG = |
| 128 | SYSID_SM_CACHE_SOCKET + SYSINFO_CACHE_LVL_MAX, |
| 129 | SYSID_SM_CACHE_MAX_SIZE = |
| 130 | SYSID_SM_CACHE_CONFIG + SYSINFO_CACHE_LVL_MAX, |
| 131 | SYSID_SM_CACHE_INST_SIZE = |
| 132 | SYSID_SM_CACHE_MAX_SIZE + SYSINFO_CACHE_LVL_MAX, |
| 133 | SYSID_SM_CACHE_SUPSRAM_TYPE = |
| 134 | SYSID_SM_CACHE_INST_SIZE + SYSINFO_CACHE_LVL_MAX, |
| 135 | SYSID_SM_CACHE_CURSRAM_TYPE = |
| 136 | SYSID_SM_CACHE_SUPSRAM_TYPE + SYSINFO_CACHE_LVL_MAX, |
| 137 | SYSID_SM_CACHE_SPEED = |
| 138 | SYSID_SM_CACHE_CURSRAM_TYPE + SYSINFO_CACHE_LVL_MAX, |
| 139 | SYSID_SM_CACHE_ERRCOR_TYPE = |
| 140 | SYSID_SM_CACHE_SPEED + SYSINFO_CACHE_LVL_MAX, |
| 141 | SYSID_SM_CACHE_SCACHE_TYPE = |
| 142 | SYSID_SM_CACHE_ERRCOR_TYPE + SYSINFO_CACHE_LVL_MAX, |
| 143 | SYSID_SM_CACHE_ASSOC = |
| 144 | SYSID_SM_CACHE_SCACHE_TYPE + SYSINFO_CACHE_LVL_MAX, |
| 145 | SYSID_SM_CACHE_MAX_SIZE2 = |
| 146 | SYSID_SM_CACHE_ASSOC + SYSINFO_CACHE_LVL_MAX, |
| 147 | SYSID_SM_CACHE_INST_SIZE2 = |
| 148 | SYSID_SM_CACHE_MAX_SIZE2 + SYSINFO_CACHE_LVL_MAX, |
| 149 | SYSID_SM_CACHE_INFO_END = |
| 150 | SYSID_SM_CACHE_INST_SIZE2 + SYSINFO_CACHE_LVL_MAX - 1, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 151 | |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 152 | /* For show_board_info() */ |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 153 | SYSID_BOARD_MODEL, |
| 154 | SYSID_BOARD_MANUFACTURER, |
Baocheng Su | 94d59e3 | 2025-02-18 10:36:11 +0800 | [diff] [blame^] | 155 | SYSID_BOARD_MAC_ADDR, |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 156 | SYSID_PRIOR_STAGE_VERSION, |
| 157 | SYSID_PRIOR_STAGE_DATE, |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 158 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 159 | /* First value available for downstream/board used */ |
Simon Glass | ff3edc2 | 2024-10-31 18:50:23 +0100 | [diff] [blame] | 160 | SYSID_USER = 0x1000, |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 163 | struct sysinfo_ops { |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 164 | /** |
| 165 | * detect() - Run the hardware info detection procedure for this |
| 166 | * device. |
| 167 | * @dev: The device containing the information |
| 168 | * |
| 169 | * This operation might take a long time (e.g. read from EEPROM, |
| 170 | * check the presence of a device on a bus etc.), hence this is not |
| 171 | * done in the probe() method, but later during operation in this |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 172 | * dedicated method. This method will be called before any other |
| 173 | * methods. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 174 | * |
| 175 | * Return: 0 if OK, -ve on error. |
| 176 | */ |
| 177 | int (*detect)(struct udevice *dev); |
| 178 | |
| 179 | /** |
| 180 | * get_bool() - Read a specific bool data value that describes the |
| 181 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 182 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 183 | * @id: A unique identifier for the bool value to be read. |
| 184 | * @val: Pointer to a buffer that receives the value read. |
| 185 | * |
| 186 | * Return: 0 if OK, -ve on error. |
| 187 | */ |
| 188 | int (*get_bool)(struct udevice *dev, int id, bool *val); |
| 189 | |
| 190 | /** |
| 191 | * get_int() - Read a specific int data value that describes the |
| 192 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 193 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 194 | * @id: A unique identifier for the int value to be read. |
| 195 | * @val: Pointer to a buffer that receives the value read. |
| 196 | * |
| 197 | * Return: 0 if OK, -ve on error. |
| 198 | */ |
| 199 | int (*get_int)(struct udevice *dev, int id, int *val); |
| 200 | |
| 201 | /** |
| 202 | * get_str() - Read a specific string data value that describes the |
| 203 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 204 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 205 | * @id: A unique identifier for the string value to be read. |
| 206 | * @size: The size of the buffer to receive the string data. |
| 207 | * @val: Pointer to a buffer that receives the value read. |
| 208 | * |
| 209 | * Return: 0 if OK, -ve on error. |
| 210 | */ |
| 211 | 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] | 212 | |
| 213 | /** |
Raymond Mao | 860fa8b | 2024-12-06 14:54:19 -0800 | [diff] [blame] | 214 | * get_data() - Read a specific string data value that describes the |
| 215 | * hardware setup. |
| 216 | * @dev: The sysinfo instance to gather the data. |
| 217 | * @id: A unique identifier for the data area to be get. |
| 218 | * @data: Pointer to the address of the data area. |
| 219 | * @size: Pointer to the size of the data area. |
| 220 | * |
| 221 | * Return: 0 if OK, -ve on error. |
| 222 | */ |
| 223 | int (*get_data)(struct udevice *dev, int id, void **data, size_t *size); |
| 224 | |
| 225 | /** |
Baocheng Su | 94d59e3 | 2025-02-18 10:36:11 +0800 | [diff] [blame^] | 226 | * get_item_count() - Get the item count of the specific data area that |
| 227 | * describes the hardware setup. |
| 228 | * @dev: The sysinfo instance to gather the data. |
| 229 | * @id: A unique identifier for the data area to be get. |
| 230 | * |
| 231 | * Return: non-negative item count if OK, -ve on error. |
| 232 | */ |
| 233 | int (*get_item_count)(struct udevice *dev, int id); |
| 234 | |
| 235 | /** |
| 236 | * get_data_by_index() - Get a data value by index from the platform. |
| 237 | * |
| 238 | * @dev: The sysinfo instance to gather the data. |
| 239 | * @id: A unique identifier for the data area to be get. |
| 240 | * @index: The item index, starting from 0. |
| 241 | * @data: Pointer to the address of the data area. |
| 242 | * @size: Pointer to the size of the data area. |
| 243 | * |
| 244 | * Return: 0 if OK, -ve on error. |
| 245 | */ |
| 246 | int (*get_data_by_index)(struct udevice *dev, int id, int index, |
| 247 | void **data, size_t *size); |
| 248 | |
| 249 | /** |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 250 | * get_fit_loadable - Get the name of an image to load from FIT |
| 251 | * This function can be used to provide the image names based on runtime |
| 252 | * detection. A classic use-case would when DTBOs are used to describe |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 253 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 254 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 255 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 256 | * @index: Index of the image. Starts at 0 and gets incremented |
| 257 | * after each call to this function. |
| 258 | * @type: The type of image. For example, "fdt" for DTBs |
| 259 | * @strp: A pointer to string. Untouched if the function fails |
| 260 | * |
| 261 | * Return: 0 if OK, -ENOENT if no loadable is available else -ve on |
| 262 | * error. |
| 263 | */ |
| 264 | int (*get_fit_loadable)(struct udevice *dev, int index, |
| 265 | const char *type, const char **strp); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 266 | }; |
| 267 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 268 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 269 | |
Simon Glass | 10e6f79 | 2021-02-04 21:17:21 -0700 | [diff] [blame] | 270 | #if CONFIG_IS_ENABLED(SYSINFO) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 271 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 272 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 273 | * |
| 274 | * @dev: The device containing the information |
| 275 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 276 | * This function must be called before any other accessor function for this |
| 277 | * device. |
| 278 | * |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 279 | * Return: 0 if OK, -ve on error. |
| 280 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 281 | int sysinfo_detect(struct udevice *dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 282 | |
| 283 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 284 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 285 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 286 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 287 | * @id: A unique identifier for the bool value to be read. |
| 288 | * @val: Pointer to a buffer that receives the value read. |
| 289 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 290 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 291 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 292 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 293 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 294 | |
| 295 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 296 | * sysinfo_get_int() - Read a specific int data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 297 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 298 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 299 | * @id: A unique identifier for the int value to be read. |
| 300 | * @val: Pointer to a buffer that receives the value read. |
| 301 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 302 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 303 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 304 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 305 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 306 | |
| 307 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 308 | * sysinfo_get_str() - Read a specific string data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 309 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 310 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 311 | * @id: A unique identifier for the string value to be read. |
| 312 | * @size: The size of the buffer to receive the string data. |
| 313 | * @val: Pointer to a buffer that receives the value read. |
| 314 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 315 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 316 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 317 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 318 | 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] | 319 | |
| 320 | /** |
Raymond Mao | 860fa8b | 2024-12-06 14:54:19 -0800 | [diff] [blame] | 321 | * sysinfo_get_data() - Get a data area from the platform. |
| 322 | * @dev: The sysinfo instance to gather the data. |
| 323 | * @id: A unique identifier for the data area to be get. |
| 324 | * @data: Pointer to the address of the data area. |
| 325 | * @size: Pointer to the size of the data area. |
| 326 | * |
| 327 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 328 | * error. |
| 329 | */ |
| 330 | int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size); |
| 331 | |
| 332 | /** |
Baocheng Su | 94d59e3 | 2025-02-18 10:36:11 +0800 | [diff] [blame^] | 333 | * sysinfo_get_item_count() - Get the item count of the specific data area that |
| 334 | * describes the hardware setup. |
| 335 | * @dev: The sysinfo instance to gather the data. |
| 336 | * @id: A unique identifier for the data area to be get. |
| 337 | * |
| 338 | * Return: non-negative item count if OK, -EPERM if called before |
| 339 | * sysinfo_detect(), else -ve on error. |
| 340 | */ |
| 341 | int sysinfo_get_item_count(struct udevice *dev, int id); |
| 342 | |
| 343 | /** |
| 344 | * sysinfo_get_data_by_index() - Get a data value by index from the platform. |
| 345 | * |
| 346 | * @dev: The sysinfo instance to gather the data. |
| 347 | * @id: A unique identifier for the data area to be get. |
| 348 | * @index: The item index, starting from 0. |
| 349 | * @data: Pointer to the address of the data area. |
| 350 | * @size: Pointer to the size of the data area. |
| 351 | * |
| 352 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 353 | * error. |
| 354 | */ |
| 355 | int sysinfo_get_data_by_index(struct udevice *dev, int id, int index, |
| 356 | void **data, size_t *size); |
| 357 | |
| 358 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 359 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
| 360 | * @devp: Pointer to structure to receive the sysinfo device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 361 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 362 | * 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] | 363 | * function that returns the unique device. This is especially useful for use |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 364 | * in sysinfo files. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 365 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 366 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 367 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 368 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 369 | int sysinfo_get(struct udevice **devp); |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 370 | |
| 371 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 372 | * 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] | 373 | * This function can be used to provide the image names based on runtime |
| 374 | * detection. A classic use-case would when DTBOs are used to describe |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 375 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 376 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 377 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 378 | * @index: Index of the image. Starts at 0 and gets incremented |
| 379 | * after each call to this function. |
| 380 | * @type: The type of image. For example, "fdt" for DTBs |
| 381 | * @strp: A pointer to string. Untouched if the function fails |
| 382 | * |
| 383 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 384 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no |
| 385 | * loadable is available else -ve on error. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 386 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 387 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
| 388 | const char **strp); |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 389 | |
| 390 | #else |
| 391 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 392 | static inline int sysinfo_detect(struct udevice *dev) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 393 | { |
| 394 | return -ENOSYS; |
| 395 | } |
| 396 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 397 | 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] | 398 | { |
| 399 | return -ENOSYS; |
| 400 | } |
| 401 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 402 | 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] | 403 | { |
| 404 | return -ENOSYS; |
| 405 | } |
| 406 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 407 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
| 408 | char *val) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 409 | { |
| 410 | return -ENOSYS; |
| 411 | } |
| 412 | |
Raymond Mao | 860fa8b | 2024-12-06 14:54:19 -0800 | [diff] [blame] | 413 | static inline int sysinfo_get_data(struct udevice *dev, int id, void **data, |
| 414 | size_t *size) |
| 415 | { |
| 416 | return -ENOSYS; |
| 417 | } |
| 418 | |
Baocheng Su | 94d59e3 | 2025-02-18 10:36:11 +0800 | [diff] [blame^] | 419 | static inline int sysinfo_get_item_count(struct udevice *dev, int id) |
| 420 | { |
| 421 | return -ENOSYS; |
| 422 | } |
| 423 | |
| 424 | static inline int sysinfo_get_data_by_index(struct udevice *dev, int id, |
| 425 | int index, void **data, |
| 426 | size_t *size) |
| 427 | { |
| 428 | return -ENOSYS; |
| 429 | } |
| 430 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 431 | static inline int sysinfo_get(struct udevice **devp) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 432 | { |
| 433 | return -ENOSYS; |
| 434 | } |
| 435 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 436 | static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, |
| 437 | const char *type, const char **strp) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 438 | { |
| 439 | return -ENOSYS; |
| 440 | } |
| 441 | |
| 442 | #endif |
Tom Rini | 55a297c | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 443 | #endif |