blob: 8054d4d4a1fa70487bedd142fe1c6989d7742fdb [file] [log] [blame]
Mario Six5381c282018-07-31 11:44:11 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * (C) Copyright 2017
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Tom Rini56a34332021-04-19 16:18:49 -04007#ifndef __SYSINFO_H__
8#define __SYSINFO_H__
9
Simon Glass401d1c42020-10-30 21:38:53 -060010struct udevice;
11
Mario Six5381c282018-07-31 11:44:11 +020012/*
13 * This uclass encapsulates hardware methods to gather information about a
Simon Glass3a8ee3d2020-11-05 06:32:05 -070014 * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
Mario Six5381c282018-07-31 11:44:11 +020015 * 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 Glass3a8ee3d2020-11-05 06:32:05 -070021 * If for example the sysinfo had a read-only serial number flash IC, we could
Mario Six5381c282018-07-31 11:44:11 +020022 * call
23 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070024 * ret = sysinfo_detect(dev);
Mario Six5381c282018-07-31 11:44:11 +020025 * if (ret) {
Simon Glass3a8ee3d2020-11-05 06:32:05 -070026 * debug("sysinfo device not found.");
Mario Six5381c282018-07-31 11:44:11 +020027 * return ret;
28 * }
29 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -070030 * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
Mario Six5381c282018-07-31 11:44:11 +020031 * 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 Glass07c9e682021-02-04 21:17:23 -070039/** enum sysinfo_id - Standard IDs defined by U-Boot */
40enum sysinfo_id {
41 SYSINFO_ID_NONE,
42
Simon Glass96dedb02021-03-21 16:50:06 +130043 /* For SMBIOS tables */
Simon Glass07c9e682021-02-04 21:17:23 -070044 SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
45 SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
46
Simon Glass96dedb02021-03-21 16:50:06 +130047 /* For show_board_info() */
48 SYSINFO_ID_BOARD_MODEL,
49
Simon Glass07c9e682021-02-04 21:17:23 -070050 /* First value available for downstream/board used */
51 SYSINFO_ID_USER = 0x1000,
52};
53
Simon Glass3a8ee3d2020-11-05 06:32:05 -070054struct sysinfo_ops {
Mario Six5381c282018-07-31 11:44:11 +020055 /**
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
63 * dedicated method.
64 *
65 * Return: 0 if OK, -ve on error.
66 */
67 int (*detect)(struct udevice *dev);
68
69 /**
70 * get_bool() - Read a specific bool data value that describes the
71 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070072 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020073 * @id: A unique identifier for the bool value to be read.
74 * @val: Pointer to a buffer that receives the value read.
75 *
76 * Return: 0 if OK, -ve on error.
77 */
78 int (*get_bool)(struct udevice *dev, int id, bool *val);
79
80 /**
81 * get_int() - Read a specific int data value that describes the
82 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070083 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020084 * @id: A unique identifier for the int value to be read.
85 * @val: Pointer to a buffer that receives the value read.
86 *
87 * Return: 0 if OK, -ve on error.
88 */
89 int (*get_int)(struct udevice *dev, int id, int *val);
90
91 /**
92 * get_str() - Read a specific string data value that describes the
93 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -070094 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +020095 * @id: A unique identifier for the string value to be read.
96 * @size: The size of the buffer to receive the string data.
97 * @val: Pointer to a buffer that receives the value read.
98 *
99 * Return: 0 if OK, -ve on error.
100 */
101 int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200102
103 /**
104 * get_fit_loadable - Get the name of an image to load from FIT
105 * This function can be used to provide the image names based on runtime
106 * detection. A classic use-case would when DTBOs are used to describe
107 * additionnal daughter cards.
108 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700109 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200110 * @index: Index of the image. Starts at 0 and gets incremented
111 * after each call to this function.
112 * @type: The type of image. For example, "fdt" for DTBs
113 * @strp: A pointer to string. Untouched if the function fails
114 *
115 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
116 * error.
117 */
118 int (*get_fit_loadable)(struct udevice *dev, int index,
119 const char *type, const char **strp);
Mario Six5381c282018-07-31 11:44:11 +0200120};
121
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700122#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
Mario Six5381c282018-07-31 11:44:11 +0200123
Simon Glass2b8e5c82021-02-04 21:17:21 -0700124#if CONFIG_IS_ENABLED(SYSINFO)
Mario Six5381c282018-07-31 11:44:11 +0200125/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700126 * sysinfo_detect() - Run the hardware info detection procedure for this device.
Mario Six5381c282018-07-31 11:44:11 +0200127 *
128 * @dev: The device containing the information
129 *
130 * Return: 0 if OK, -ve on error.
131 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700132int sysinfo_detect(struct udevice *dev);
Mario Six5381c282018-07-31 11:44:11 +0200133
134/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700135 * sysinfo_get_bool() - Read a specific bool data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200136 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700137 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200138 * @id: A unique identifier for the bool value to be read.
139 * @val: Pointer to a buffer that receives the value read.
140 *
141 * Return: 0 if OK, -ve on error.
142 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700143int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
Mario Six5381c282018-07-31 11:44:11 +0200144
145/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700146 * sysinfo_get_int() - Read a specific int data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200147 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700148 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200149 * @id: A unique identifier for the int value to be read.
150 * @val: Pointer to a buffer that receives the value read.
151 *
152 * Return: 0 if OK, -ve on error.
153 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700154int sysinfo_get_int(struct udevice *dev, int id, int *val);
Mario Six5381c282018-07-31 11:44:11 +0200155
156/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700157 * sysinfo_get_str() - Read a specific string data value that describes the
Mario Six5381c282018-07-31 11:44:11 +0200158 * hardware setup.
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700159 * @dev: The sysinfo instance to gather the data.
Mario Six5381c282018-07-31 11:44:11 +0200160 * @id: A unique identifier for the string value to be read.
161 * @size: The size of the buffer to receive the string data.
162 * @val: Pointer to a buffer that receives the value read.
163 *
164 * Return: 0 if OK, -ve on error.
165 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700166int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
Mario Six5381c282018-07-31 11:44:11 +0200167
168/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700169 * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
170 * @devp: Pointer to structure to receive the sysinfo device.
Mario Six5381c282018-07-31 11:44:11 +0200171 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700172 * Since there can only be at most one sysinfo instance, the API can supply a
Mario Six5381c282018-07-31 11:44:11 +0200173 * function that returns the unique device. This is especially useful for use
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700174 * in sysinfo files.
Mario Six5381c282018-07-31 11:44:11 +0200175 *
176 * Return: 0 if OK, -ve on error.
177 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700178int sysinfo_get(struct udevice **devp);
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200179
180/**
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700181 * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200182 * This function can be used to provide the image names based on runtime
183 * detection. A classic use-case would when DTBOs are used to describe
184 * additionnal daughter cards.
185 *
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700186 * @dev: The sysinfo instance to gather the data.
Jean-Jacques Hiblotd42730e2019-10-22 16:39:19 +0200187 * @index: Index of the image. Starts at 0 and gets incremented
188 * after each call to this function.
189 * @type: The type of image. For example, "fdt" for DTBs
190 * @strp: A pointer to string. Untouched if the function fails
191 *
192 *
193 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
194 * error.
195 */
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700196int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
197 const char **strp);
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200198
199#else
200
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700201static inline int sysinfo_detect(struct udevice *dev)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200202{
203 return -ENOSYS;
204}
205
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700206static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200207{
208 return -ENOSYS;
209}
210
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700211static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200212{
213 return -ENOSYS;
214}
215
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700216static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
217 char *val)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200218{
219 return -ENOSYS;
220}
221
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700222static inline int sysinfo_get(struct udevice **devp)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200223{
224 return -ENOSYS;
225}
226
Simon Glass3a8ee3d2020-11-05 06:32:05 -0700227static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
228 const char *type, const char **strp)
Jean-Jacques Hiblot02806e92019-10-22 16:39:20 +0200229{
230 return -ENOSYS;
231}
232
233#endif
Tom Rini56a34332021-04-19 16:18:49 -0400234#endif