sysinfo.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2017
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. */
  6. #ifndef __SYSINFO_H__
  7. #define __SYSINFO_H__
  8. struct udevice;
  9. /*
  10. * This uclass encapsulates hardware methods to gather information about a
  11. * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders,
  12. * read-only data in flash ICs, or similar.
  13. *
  14. * The interface offers functions to read the usual standard data types (bool,
  15. * int, string) from the device, each of which is identified by a static
  16. * numeric ID (which will usually be defined as a enum in a header file).
  17. *
  18. * If for example the sysinfo had a read-only serial number flash IC, we could
  19. * call
  20. *
  21. * ret = sysinfo_detect(dev);
  22. * if (ret) {
  23. * debug("sysinfo device not found.");
  24. * return ret;
  25. * }
  26. *
  27. * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial);
  28. * if (ret) {
  29. * debug("Error when reading serial number from device.");
  30. * return ret;
  31. * }
  32. *
  33. * to read the serial number.
  34. */
  35. /** enum sysinfo_id - Standard IDs defined by U-Boot */
  36. enum sysinfo_id {
  37. SYSINFO_ID_NONE,
  38. /* For SMBIOS tables */
  39. SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
  40. SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
  41. /* For show_board_info() */
  42. SYSINFO_ID_BOARD_MODEL,
  43. /* First value available for downstream/board used */
  44. SYSINFO_ID_USER = 0x1000,
  45. };
  46. struct sysinfo_ops {
  47. /**
  48. * detect() - Run the hardware info detection procedure for this
  49. * device.
  50. * @dev: The device containing the information
  51. *
  52. * This operation might take a long time (e.g. read from EEPROM,
  53. * check the presence of a device on a bus etc.), hence this is not
  54. * done in the probe() method, but later during operation in this
  55. * dedicated method.
  56. *
  57. * Return: 0 if OK, -ve on error.
  58. */
  59. int (*detect)(struct udevice *dev);
  60. /**
  61. * get_bool() - Read a specific bool data value that describes the
  62. * hardware setup.
  63. * @dev: The sysinfo instance to gather the data.
  64. * @id: A unique identifier for the bool value to be read.
  65. * @val: Pointer to a buffer that receives the value read.
  66. *
  67. * Return: 0 if OK, -ve on error.
  68. */
  69. int (*get_bool)(struct udevice *dev, int id, bool *val);
  70. /**
  71. * get_int() - Read a specific int data value that describes the
  72. * hardware setup.
  73. * @dev: The sysinfo instance to gather the data.
  74. * @id: A unique identifier for the int 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_int)(struct udevice *dev, int id, int *val);
  80. /**
  81. * get_str() - Read a specific string data value that describes the
  82. * hardware setup.
  83. * @dev: The sysinfo instance to gather the data.
  84. * @id: A unique identifier for the string value to be read.
  85. * @size: The size of the buffer to receive the string data.
  86. * @val: Pointer to a buffer that receives the value read.
  87. *
  88. * Return: 0 if OK, -ve on error.
  89. */
  90. int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
  91. /**
  92. * get_fit_loadable - Get the name of an image to load from FIT
  93. * This function can be used to provide the image names based on runtime
  94. * detection. A classic use-case would when DTBOs are used to describe
  95. * additionnal daughter cards.
  96. *
  97. * @dev: The sysinfo instance to gather the data.
  98. * @index: Index of the image. Starts at 0 and gets incremented
  99. * after each call to this function.
  100. * @type: The type of image. For example, "fdt" for DTBs
  101. * @strp: A pointer to string. Untouched if the function fails
  102. *
  103. * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
  104. * error.
  105. */
  106. int (*get_fit_loadable)(struct udevice *dev, int index,
  107. const char *type, const char **strp);
  108. };
  109. #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
  110. #if CONFIG_IS_ENABLED(SYSINFO)
  111. /**
  112. * sysinfo_detect() - Run the hardware info detection procedure for this device.
  113. *
  114. * @dev: The device containing the information
  115. *
  116. * Return: 0 if OK, -ve on error.
  117. */
  118. int sysinfo_detect(struct udevice *dev);
  119. /**
  120. * sysinfo_get_bool() - Read a specific bool data value that describes the
  121. * hardware setup.
  122. * @dev: The sysinfo instance to gather the data.
  123. * @id: A unique identifier for the bool value to be read.
  124. * @val: Pointer to a buffer that receives the value read.
  125. *
  126. * Return: 0 if OK, -ve on error.
  127. */
  128. int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
  129. /**
  130. * sysinfo_get_int() - Read a specific int data value that describes the
  131. * hardware setup.
  132. * @dev: The sysinfo instance to gather the data.
  133. * @id: A unique identifier for the int value to be read.
  134. * @val: Pointer to a buffer that receives the value read.
  135. *
  136. * Return: 0 if OK, -ve on error.
  137. */
  138. int sysinfo_get_int(struct udevice *dev, int id, int *val);
  139. /**
  140. * sysinfo_get_str() - Read a specific string data value that describes the
  141. * hardware setup.
  142. * @dev: The sysinfo instance to gather the data.
  143. * @id: A unique identifier for the string value to be read.
  144. * @size: The size of the buffer to receive the string data.
  145. * @val: Pointer to a buffer that receives the value read.
  146. *
  147. * Return: 0 if OK, -ve on error.
  148. */
  149. int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
  150. /**
  151. * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
  152. * @devp: Pointer to structure to receive the sysinfo device.
  153. *
  154. * Since there can only be at most one sysinfo instance, the API can supply a
  155. * function that returns the unique device. This is especially useful for use
  156. * in sysinfo files.
  157. *
  158. * Return: 0 if OK, -ve on error.
  159. */
  160. int sysinfo_get(struct udevice **devp);
  161. /**
  162. * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
  163. * This function can be used to provide the image names based on runtime
  164. * detection. A classic use-case would when DTBOs are used to describe
  165. * additionnal daughter cards.
  166. *
  167. * @dev: The sysinfo instance to gather the data.
  168. * @index: Index of the image. Starts at 0 and gets incremented
  169. * after each call to this function.
  170. * @type: The type of image. For example, "fdt" for DTBs
  171. * @strp: A pointer to string. Untouched if the function fails
  172. *
  173. *
  174. * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
  175. * error.
  176. */
  177. int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
  178. const char **strp);
  179. #else
  180. static inline int sysinfo_detect(struct udevice *dev)
  181. {
  182. return -ENOSYS;
  183. }
  184. static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
  185. {
  186. return -ENOSYS;
  187. }
  188. static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
  189. {
  190. return -ENOSYS;
  191. }
  192. static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
  193. char *val)
  194. {
  195. return -ENOSYS;
  196. }
  197. static inline int sysinfo_get(struct udevice **devp)
  198. {
  199. return -ENOSYS;
  200. }
  201. static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
  202. const char *type, const char **strp)
  203. {
  204. return -ENOSYS;
  205. }
  206. #endif
  207. #endif