sysinfo.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. This method will be called before any other
  56. * methods.
  57. *
  58. * Return: 0 if OK, -ve on error.
  59. */
  60. int (*detect)(struct udevice *dev);
  61. /**
  62. * get_bool() - Read a specific bool data value that describes the
  63. * hardware setup.
  64. * @dev: The sysinfo instance to gather the data.
  65. * @id: A unique identifier for the bool value to be read.
  66. * @val: Pointer to a buffer that receives the value read.
  67. *
  68. * Return: 0 if OK, -ve on error.
  69. */
  70. int (*get_bool)(struct udevice *dev, int id, bool *val);
  71. /**
  72. * get_int() - Read a specific int data value that describes the
  73. * hardware setup.
  74. * @dev: The sysinfo instance to gather the data.
  75. * @id: A unique identifier for the int value to be read.
  76. * @val: Pointer to a buffer that receives the value read.
  77. *
  78. * Return: 0 if OK, -ve on error.
  79. */
  80. int (*get_int)(struct udevice *dev, int id, int *val);
  81. /**
  82. * get_str() - Read a specific string data value that describes the
  83. * hardware setup.
  84. * @dev: The sysinfo instance to gather the data.
  85. * @id: A unique identifier for the string value to be read.
  86. * @size: The size of the buffer to receive the string data.
  87. * @val: Pointer to a buffer that receives the value read.
  88. *
  89. * Return: 0 if OK, -ve on error.
  90. */
  91. int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
  92. /**
  93. * get_fit_loadable - Get the name of an image to load from FIT
  94. * This function can be used to provide the image names based on runtime
  95. * detection. A classic use-case would when DTBOs are used to describe
  96. * additional daughter cards.
  97. *
  98. * @dev: The sysinfo instance to gather the data.
  99. * @index: Index of the image. Starts at 0 and gets incremented
  100. * after each call to this function.
  101. * @type: The type of image. For example, "fdt" for DTBs
  102. * @strp: A pointer to string. Untouched if the function fails
  103. *
  104. * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
  105. * error.
  106. */
  107. int (*get_fit_loadable)(struct udevice *dev, int index,
  108. const char *type, const char **strp);
  109. };
  110. #define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops)
  111. #if CONFIG_IS_ENABLED(SYSINFO)
  112. /**
  113. * sysinfo_detect() - Run the hardware info detection procedure for this device.
  114. *
  115. * @dev: The device containing the information
  116. *
  117. * This function must be called before any other accessor function for this
  118. * device.
  119. *
  120. * Return: 0 if OK, -ve on error.
  121. */
  122. int sysinfo_detect(struct udevice *dev);
  123. /**
  124. * sysinfo_get_bool() - Read a specific bool data value that describes the
  125. * hardware setup.
  126. * @dev: The sysinfo instance to gather the data.
  127. * @id: A unique identifier for the bool value to be read.
  128. * @val: Pointer to a buffer that receives the value read.
  129. *
  130. * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
  131. * error.
  132. */
  133. int sysinfo_get_bool(struct udevice *dev, int id, bool *val);
  134. /**
  135. * sysinfo_get_int() - Read a specific int data value that describes the
  136. * hardware setup.
  137. * @dev: The sysinfo instance to gather the data.
  138. * @id: A unique identifier for the int value to be read.
  139. * @val: Pointer to a buffer that receives the value read.
  140. *
  141. * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
  142. * error.
  143. */
  144. int sysinfo_get_int(struct udevice *dev, int id, int *val);
  145. /**
  146. * sysinfo_get_str() - Read a specific string data value that describes the
  147. * hardware setup.
  148. * @dev: The sysinfo instance to gather the data.
  149. * @id: A unique identifier for the string value to be read.
  150. * @size: The size of the buffer to receive the string data.
  151. * @val: Pointer to a buffer that receives the value read.
  152. *
  153. * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
  154. * error.
  155. */
  156. int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val);
  157. /**
  158. * sysinfo_get() - Return the sysinfo device for the sysinfo in question.
  159. * @devp: Pointer to structure to receive the sysinfo device.
  160. *
  161. * Since there can only be at most one sysinfo instance, the API can supply a
  162. * function that returns the unique device. This is especially useful for use
  163. * in sysinfo files.
  164. *
  165. * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on
  166. * error.
  167. */
  168. int sysinfo_get(struct udevice **devp);
  169. /**
  170. * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
  171. * This function can be used to provide the image names based on runtime
  172. * detection. A classic use-case would when DTBOs are used to describe
  173. * additional daughter cards.
  174. *
  175. * @dev: The sysinfo instance to gather the data.
  176. * @index: Index of the image. Starts at 0 and gets incremented
  177. * after each call to this function.
  178. * @type: The type of image. For example, "fdt" for DTBs
  179. * @strp: A pointer to string. Untouched if the function fails
  180. *
  181. *
  182. * Return: 0 if OK, -EPERM if called before sysinfo_detect(), -ENOENT if no
  183. * loadable is available else -ve on error.
  184. */
  185. int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
  186. const char **strp);
  187. #else
  188. static inline int sysinfo_detect(struct udevice *dev)
  189. {
  190. return -ENOSYS;
  191. }
  192. static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
  193. {
  194. return -ENOSYS;
  195. }
  196. static inline int sysinfo_get_int(struct udevice *dev, int id, int *val)
  197. {
  198. return -ENOSYS;
  199. }
  200. static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size,
  201. char *val)
  202. {
  203. return -ENOSYS;
  204. }
  205. static inline int sysinfo_get(struct udevice **devp)
  206. {
  207. return -ENOSYS;
  208. }
  209. static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
  210. const char *type, const char **strp)
  211. {
  212. return -ENOSYS;
  213. }
  214. #endif
  215. #endif