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