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 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 12 | /* |
| 13 | * This uclass encapsulates hardware methods to gather information about a |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 14 | * 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] | 15 | * 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 Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 21 | * 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] | 22 | * call |
| 23 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 24 | * ret = sysinfo_detect(dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 25 | * if (ret) { |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 26 | * debug("sysinfo device not found."); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 27 | * return ret; |
| 28 | * } |
| 29 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 30 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 31 | * 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 Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 39 | /** enum sysinfo_id - Standard IDs defined by U-Boot */ |
| 40 | enum sysinfo_id { |
| 41 | SYSINFO_ID_NONE, |
| 42 | |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 43 | /* For SMBIOS tables */ |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 44 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
| 45 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, |
| 46 | |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 47 | /* For show_board_info() */ |
| 48 | SYSINFO_ID_BOARD_MODEL, |
Simon Glass | c2e06e9 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 49 | SYSINFO_ID_BOARD_MANUFACTURER, |
| 50 | SYSINFO_ID_PRIOR_STAGE_VERSION, |
| 51 | SYSINFO_ID_PRIOR_STAGE_DATE, |
Simon Glass | 43bc543 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 52 | |
Simon Glass | cf67d6d | 2021-02-04 21:17:23 -0700 | [diff] [blame] | 53 | /* First value available for downstream/board used */ |
| 54 | SYSINFO_ID_USER = 0x1000, |
| 55 | }; |
| 56 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 57 | struct sysinfo_ops { |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 58 | /** |
| 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 Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 66 | * dedicated method. This method will be called before any other |
| 67 | * methods. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 68 | * |
| 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 Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 76 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 77 | * @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 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 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 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 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 Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 106 | |
| 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 Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 111 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 112 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 113 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 114 | * @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 Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 126 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 127 | |
Simon Glass | 10e6f79 | 2021-02-04 21:17:21 -0700 | [diff] [blame] | 128 | #if CONFIG_IS_ENABLED(SYSINFO) |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 129 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 130 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 131 | * |
| 132 | * @dev: The device containing the information |
| 133 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 134 | * This function must be called before any other accessor function for this |
| 135 | * device. |
| 136 | * |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 137 | * Return: 0 if OK, -ve on error. |
| 138 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 139 | int sysinfo_detect(struct udevice *dev); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 140 | |
| 141 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 142 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 143 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 144 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 145 | * @id: A unique identifier for the bool value to be read. |
| 146 | * @val: Pointer to a buffer that receives the value read. |
| 147 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 148 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 149 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 150 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 151 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 152 | |
| 153 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 154 | * sysinfo_get_int() - Read a specific int data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 155 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 156 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 157 | * @id: A unique identifier for the int value to be read. |
| 158 | * @val: Pointer to a buffer that receives the value read. |
| 159 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 160 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 161 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 162 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 163 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 164 | |
| 165 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 166 | * sysinfo_get_str() - Read a specific string data value that describes the |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 167 | * hardware setup. |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 168 | * @dev: The sysinfo instance to gather the data. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 169 | * @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 Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 173 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 174 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 175 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 176 | 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] | 177 | |
| 178 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 179 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
| 180 | * @devp: Pointer to structure to receive the sysinfo device. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 181 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 182 | * 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] | 183 | * function that returns the unique device. This is especially useful for use |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 184 | * in sysinfo files. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 185 | * |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 186 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
| 187 | * error. |
Mario Six | 2161e55 | 2018-07-31 11:44:11 +0200 | [diff] [blame] | 188 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 189 | int sysinfo_get(struct udevice **devp); |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 190 | |
| 191 | /** |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 192 | * 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] | 193 | * 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 Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 195 | * additional daughter cards. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 196 | * |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 197 | * @dev: The sysinfo instance to gather the data. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 198 | * @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 Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 204 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no |
| 205 | * loadable is available else -ve on error. |
Jean-Jacques Hiblot | 7815fc1 | 2019-10-22 16:39:19 +0200 | [diff] [blame] | 206 | */ |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 207 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
| 208 | const char **strp); |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 209 | |
| 210 | #else |
| 211 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 212 | static inline int sysinfo_detect(struct udevice *dev) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 213 | { |
| 214 | return -ENOSYS; |
| 215 | } |
| 216 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 217 | 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] | 218 | { |
| 219 | return -ENOSYS; |
| 220 | } |
| 221 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 222 | 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] | 223 | { |
| 224 | return -ENOSYS; |
| 225 | } |
| 226 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 227 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
| 228 | char *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(struct udevice **devp) |
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_fit_loadable(struct udevice *dev, int index, |
| 239 | const char *type, const char **strp) |
Jean-Jacques Hiblot | 98823aa | 2019-10-22 16:39:20 +0200 | [diff] [blame] | 240 | { |
| 241 | return -ENOSYS; |
| 242 | } |
| 243 | |
| 244 | #endif |
Tom Rini | 55a297c | 2021-04-19 16:18:49 -0400 | [diff] [blame] | 245 | #endif |