sysinfo.h 6.7 KB

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