]>
Commit | Line | Data |
---|---|---|
5381c285 MS |
1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
2 | /* | |
3 | * (C) Copyright 2017 | |
4 | * Mario Six, Guntermann & Drunck GmbH, [email protected] | |
5 | */ | |
6 | ||
56a3433e TR |
7 | #ifndef __SYSINFO_H__ |
8 | #define __SYSINFO_H__ | |
9 | ||
401d1c4f SG |
10 | struct udevice; |
11 | ||
5381c285 MS |
12 | /* |
13 | * This uclass encapsulates hardware methods to gather information about a | |
3a8ee3df | 14 | * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders, |
5381c285 MS |
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 | * | |
3a8ee3df | 21 | * If for example the sysinfo had a read-only serial number flash IC, we could |
5381c285 MS |
22 | * call |
23 | * | |
3a8ee3df | 24 | * ret = sysinfo_detect(dev); |
5381c285 | 25 | * if (ret) { |
3a8ee3df | 26 | * debug("sysinfo device not found."); |
5381c285 MS |
27 | * return ret; |
28 | * } | |
29 | * | |
3a8ee3df | 30 | * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); |
5381c285 MS |
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 | ||
07c9e683 SG |
39 | /** enum sysinfo_id - Standard IDs defined by U-Boot */ |
40 | enum sysinfo_id { | |
41 | SYSINFO_ID_NONE, | |
42 | ||
96dedb0d | 43 | /* For SMBIOS tables */ |
07c9e683 SG |
44 | SYSINFO_ID_SMBIOS_SYSTEM_VERSION, |
45 | SYSINFO_ID_SMBIOS_BASEBOARD_VERSION, | |
46 | ||
96dedb0d SG |
47 | /* For show_board_info() */ |
48 | SYSINFO_ID_BOARD_MODEL, | |
49 | ||
07c9e683 SG |
50 | /* First value available for downstream/board used */ |
51 | SYSINFO_ID_USER = 0x1000, | |
52 | }; | |
53 | ||
3a8ee3df | 54 | struct sysinfo_ops { |
5381c285 MS |
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 | |
4d65c6bc SA |
63 | * dedicated method. This method will be called before any other |
64 | * methods. | |
5381c285 MS |
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. | |
3a8ee3df | 73 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
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. | |
3a8ee3df | 84 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
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. | |
3a8ee3df | 95 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
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); | |
d42730e8 JJH |
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 | |
4d65c6bc | 108 | * additional daughter cards. |
d42730e8 | 109 | * |
3a8ee3df | 110 | * @dev: The sysinfo instance to gather the data. |
d42730e8 JJH |
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); | |
5381c285 MS |
121 | }; |
122 | ||
3a8ee3df | 123 | #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) |
5381c285 | 124 | |
2b8e5c8d | 125 | #if CONFIG_IS_ENABLED(SYSINFO) |
5381c285 | 126 | /** |
3a8ee3df | 127 | * sysinfo_detect() - Run the hardware info detection procedure for this device. |
5381c285 MS |
128 | * |
129 | * @dev: The device containing the information | |
130 | * | |
4d65c6bc SA |
131 | * This function must be called before any other accessor function for this |
132 | * device. | |
133 | * | |
5381c285 MS |
134 | * Return: 0 if OK, -ve on error. |
135 | */ | |
3a8ee3df | 136 | int sysinfo_detect(struct udevice *dev); |
5381c285 MS |
137 | |
138 | /** | |
3a8ee3df | 139 | * sysinfo_get_bool() - Read a specific bool data value that describes the |
5381c285 | 140 | * hardware setup. |
3a8ee3df | 141 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
142 | * @id: A unique identifier for the bool value to be read. |
143 | * @val: Pointer to a buffer that receives the value read. | |
144 | * | |
4d65c6bc SA |
145 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
146 | * error. | |
5381c285 | 147 | */ |
3a8ee3df | 148 | int sysinfo_get_bool(struct udevice *dev, int id, bool *val); |
5381c285 MS |
149 | |
150 | /** | |
3a8ee3df | 151 | * sysinfo_get_int() - Read a specific int data value that describes the |
5381c285 | 152 | * hardware setup. |
3a8ee3df | 153 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
154 | * @id: A unique identifier for the int value to be read. |
155 | * @val: Pointer to a buffer that receives the value read. | |
156 | * | |
4d65c6bc SA |
157 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
158 | * error. | |
5381c285 | 159 | */ |
3a8ee3df | 160 | int sysinfo_get_int(struct udevice *dev, int id, int *val); |
5381c285 MS |
161 | |
162 | /** | |
3a8ee3df | 163 | * sysinfo_get_str() - Read a specific string data value that describes the |
5381c285 | 164 | * hardware setup. |
3a8ee3df | 165 | * @dev: The sysinfo instance to gather the data. |
5381c285 MS |
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 | * | |
4d65c6bc SA |
170 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
171 | * error. | |
5381c285 | 172 | */ |
3a8ee3df | 173 | int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); |
5381c285 MS |
174 | |
175 | /** | |
3a8ee3df SG |
176 | * sysinfo_get() - Return the sysinfo device for the sysinfo in question. |
177 | * @devp: Pointer to structure to receive the sysinfo device. | |
5381c285 | 178 | * |
3a8ee3df | 179 | * Since there can only be at most one sysinfo instance, the API can supply a |
5381c285 | 180 | * function that returns the unique device. This is especially useful for use |
3a8ee3df | 181 | * in sysinfo files. |
5381c285 | 182 | * |
4d65c6bc SA |
183 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on |
184 | * error. | |
5381c285 | 185 | */ |
3a8ee3df | 186 | int sysinfo_get(struct udevice **devp); |
d42730e8 JJH |
187 | |
188 | /** | |
3a8ee3df | 189 | * sysinfo_get_fit_loadable - Get the name of an image to load from FIT |
d42730e8 JJH |
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 | |
4d65c6bc | 192 | * additional daughter cards. |
d42730e8 | 193 | * |
3a8ee3df | 194 | * @dev: The sysinfo instance to gather the data. |
d42730e8 JJH |
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 | * | |
4d65c6bc SA |
201 | * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no |
202 | * loadable is available else -ve on error. | |
d42730e8 | 203 | */ |
3a8ee3df SG |
204 | int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, |
205 | const char **strp); | |
02806e9a JJH |
206 | |
207 | #else | |
208 | ||
3a8ee3df | 209 | static inline int sysinfo_detect(struct udevice *dev) |
02806e9a JJH |
210 | { |
211 | return -ENOSYS; | |
212 | } | |
213 | ||
3a8ee3df | 214 | static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val) |
02806e9a JJH |
215 | { |
216 | return -ENOSYS; | |
217 | } | |
218 | ||
3a8ee3df | 219 | static inline int sysinfo_get_int(struct udevice *dev, int id, int *val) |
02806e9a JJH |
220 | { |
221 | return -ENOSYS; | |
222 | } | |
223 | ||
3a8ee3df SG |
224 | static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, |
225 | char *val) | |
02806e9a JJH |
226 | { |
227 | return -ENOSYS; | |
228 | } | |
229 | ||
3a8ee3df | 230 | static inline int sysinfo_get(struct udevice **devp) |
02806e9a JJH |
231 | { |
232 | return -ENOSYS; | |
233 | } | |
234 | ||
3a8ee3df SG |
235 | static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, |
236 | const char *type, const char **strp) | |
02806e9a JJH |
237 | { |
238 | return -ENOSYS; | |
239 | } | |
240 | ||
241 | #endif | |
56a3433e | 242 | #endif |