smbios.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  4. *
  5. * Adapted from coreboot src/include/smbios.h
  6. */
  7. #ifndef _SMBIOS_H_
  8. #define _SMBIOS_H_
  9. #include <dm/ofnode.h>
  10. /* SMBIOS spec version implemented */
  11. #define SMBIOS_MAJOR_VER 3
  12. #define SMBIOS_MINOR_VER 0
  13. enum {
  14. SMBIOS_STR_MAX = 64, /* Maximum length allowed for a string */
  15. };
  16. /* SMBIOS structure types */
  17. enum {
  18. SMBIOS_BIOS_INFORMATION = 0,
  19. SMBIOS_SYSTEM_INFORMATION = 1,
  20. SMBIOS_BOARD_INFORMATION = 2,
  21. SMBIOS_SYSTEM_ENCLOSURE = 3,
  22. SMBIOS_PROCESSOR_INFORMATION = 4,
  23. SMBIOS_CACHE_INFORMATION = 7,
  24. SMBIOS_SYSTEM_SLOTS = 9,
  25. SMBIOS_PHYS_MEMORY_ARRAY = 16,
  26. SMBIOS_MEMORY_DEVICE = 17,
  27. SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS = 19,
  28. SMBIOS_SYSTEM_BOOT_INFORMATION = 32,
  29. SMBIOS_END_OF_TABLE = 127
  30. };
  31. #define SMBIOS_INTERMEDIATE_OFFSET 16
  32. #define SMBIOS_STRUCT_EOS_BYTES 2
  33. struct __packed smbios_entry {
  34. u8 anchor[4];
  35. u8 checksum;
  36. u8 length;
  37. u8 major_ver;
  38. u8 minor_ver;
  39. u16 max_struct_size;
  40. u8 entry_point_rev;
  41. u8 formatted_area[5];
  42. u8 intermediate_anchor[5];
  43. u8 intermediate_checksum;
  44. u16 struct_table_length;
  45. u32 struct_table_address;
  46. u16 struct_count;
  47. u8 bcd_rev;
  48. };
  49. /* BIOS characteristics */
  50. #define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
  51. #define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11)
  52. #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)
  53. #define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0)
  54. #define BIOS_CHARACTERISTICS_EXT1_UEFI (1 << 3)
  55. #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
  56. struct __packed smbios_type0 {
  57. u8 type;
  58. u8 length;
  59. u16 handle;
  60. u8 vendor;
  61. u8 bios_ver;
  62. u16 bios_start_segment;
  63. u8 bios_release_date;
  64. u8 bios_rom_size;
  65. u64 bios_characteristics;
  66. u8 bios_characteristics_ext1;
  67. u8 bios_characteristics_ext2;
  68. u8 bios_major_release;
  69. u8 bios_minor_release;
  70. u8 ec_major_release;
  71. u8 ec_minor_release;
  72. char eos[SMBIOS_STRUCT_EOS_BYTES];
  73. };
  74. struct __packed smbios_type1 {
  75. u8 type;
  76. u8 length;
  77. u16 handle;
  78. u8 manufacturer;
  79. u8 product_name;
  80. u8 version;
  81. u8 serial_number;
  82. u8 uuid[16];
  83. u8 wakeup_type;
  84. u8 sku_number;
  85. u8 family;
  86. char eos[SMBIOS_STRUCT_EOS_BYTES];
  87. };
  88. #define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0)
  89. #define SMBIOS_BOARD_MOTHERBOARD 10
  90. struct __packed smbios_type2 {
  91. u8 type;
  92. u8 length;
  93. u16 handle;
  94. u8 manufacturer;
  95. u8 product_name;
  96. u8 version;
  97. u8 serial_number;
  98. u8 asset_tag_number;
  99. u8 feature_flags;
  100. u8 chassis_location;
  101. u16 chassis_handle;
  102. u8 board_type;
  103. char eos[SMBIOS_STRUCT_EOS_BYTES];
  104. };
  105. #define SMBIOS_ENCLOSURE_DESKTOP 3
  106. #define SMBIOS_STATE_SAFE 3
  107. #define SMBIOS_SECURITY_NONE 3
  108. struct __packed smbios_type3 {
  109. u8 type;
  110. u8 length;
  111. u16 handle;
  112. u8 manufacturer;
  113. u8 chassis_type;
  114. u8 version;
  115. u8 serial_number;
  116. u8 asset_tag_number;
  117. u8 bootup_state;
  118. u8 power_supply_state;
  119. u8 thermal_state;
  120. u8 security_status;
  121. u32 oem_defined;
  122. u8 height;
  123. u8 number_of_power_cords;
  124. u8 element_count;
  125. u8 element_record_length;
  126. char eos[SMBIOS_STRUCT_EOS_BYTES];
  127. };
  128. #define SMBIOS_PROCESSOR_TYPE_CENTRAL 3
  129. #define SMBIOS_PROCESSOR_STATUS_ENABLED 1
  130. #define SMBIOS_PROCESSOR_UPGRADE_NONE 6
  131. #define SMBIOS_PROCESSOR_FAMILY_OTHER 1
  132. #define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2
  133. struct __packed smbios_type4 {
  134. u8 type;
  135. u8 length;
  136. u16 handle;
  137. u8 socket_designation;
  138. u8 processor_type;
  139. u8 processor_family;
  140. u8 processor_manufacturer;
  141. u32 processor_id[2];
  142. u8 processor_version;
  143. u8 voltage;
  144. u16 external_clock;
  145. u16 max_speed;
  146. u16 current_speed;
  147. u8 status;
  148. u8 processor_upgrade;
  149. u16 l1_cache_handle;
  150. u16 l2_cache_handle;
  151. u16 l3_cache_handle;
  152. u8 serial_number;
  153. u8 asset_tag;
  154. u8 part_number;
  155. u8 core_count;
  156. u8 core_enabled;
  157. u8 thread_count;
  158. u16 processor_characteristics;
  159. u16 processor_family2;
  160. u16 core_count2;
  161. u16 core_enabled2;
  162. u16 thread_count2;
  163. char eos[SMBIOS_STRUCT_EOS_BYTES];
  164. };
  165. struct __packed smbios_type32 {
  166. u8 type;
  167. u8 length;
  168. u16 handle;
  169. u8 reserved[6];
  170. u8 boot_status;
  171. char eos[SMBIOS_STRUCT_EOS_BYTES];
  172. };
  173. struct __packed smbios_type127 {
  174. u8 type;
  175. u8 length;
  176. u16 handle;
  177. char eos[SMBIOS_STRUCT_EOS_BYTES];
  178. };
  179. struct __packed smbios_header {
  180. u8 type;
  181. u8 length;
  182. u16 handle;
  183. };
  184. /**
  185. * fill_smbios_header() - Fill the header of an SMBIOS table
  186. *
  187. * This fills the header of an SMBIOS table structure.
  188. *
  189. * @table: start address of the structure
  190. * @type: the type of structure
  191. * @length: the length of the formatted area of the structure
  192. * @handle: the structure's handle, a unique 16-bit number
  193. */
  194. static inline void fill_smbios_header(void *table, int type,
  195. int length, int handle)
  196. {
  197. struct smbios_header *header = table;
  198. header->type = type;
  199. header->length = length - SMBIOS_STRUCT_EOS_BYTES;
  200. header->handle = handle;
  201. }
  202. /**
  203. * write_smbios_table() - Write SMBIOS table
  204. *
  205. * This writes SMBIOS table at a given address.
  206. *
  207. * @addr: start address to write SMBIOS table. If this is not
  208. * 16-byte-aligned then it will be aligned before the table is written
  209. * @return: end address of SMBIOS table (and start address for next entry)
  210. */
  211. ulong write_smbios_table(ulong addr);
  212. /**
  213. * smbios_entry() - Get a valid struct smbios_entry pointer
  214. *
  215. * @address: address where smbios tables is located
  216. * @size: size of smbios table
  217. * @return: NULL or a valid pointer to a struct smbios_entry
  218. */
  219. const struct smbios_entry *smbios_entry(u64 address, u32 size);
  220. /**
  221. * smbios_header() - Search for SMBIOS header type
  222. *
  223. * @entry: pointer to a struct smbios_entry
  224. * @type: SMBIOS type
  225. * @return: NULL or a valid pointer to a struct smbios_header
  226. */
  227. const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type);
  228. /**
  229. * smbios_string() - Return string from SMBIOS
  230. *
  231. * @header: pointer to struct smbios_header
  232. * @index: string index
  233. * @return: NULL or a valid const char pointer
  234. */
  235. const char *smbios_string(const struct smbios_header *header, int index);
  236. /**
  237. * smbios_update_version() - Update the version string
  238. *
  239. * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
  240. * main loop has started) to update the BIOS version string (SMBIOS table 0).
  241. *
  242. * @version: New version string to use
  243. * @return 0 if OK, -ENOENT if no version string was previously written,
  244. * -ENOSPC if the new string is too large to fit
  245. */
  246. int smbios_update_version(const char *version);
  247. /**
  248. * smbios_update_version_full() - Update the version string
  249. *
  250. * This can be called after the SMBIOS tables are written (e.g. after the U-Boot
  251. * main loop has started) to update the BIOS version string (SMBIOS table 0).
  252. * It scans for the correct place to put the version, so does not need U-Boot
  253. * to have actually written the tables itself (e.g. if a previous bootloader
  254. * did it).
  255. *
  256. * @smbios_tab: Start of SMBIOS tables
  257. * @version: New version string to use
  258. * @return 0 if OK, -ENOENT if no version string was previously written,
  259. * -ENOSPC if the new string is too large to fit
  260. */
  261. int smbios_update_version_full(void *smbios_tab, const char *version);
  262. #endif /* _SMBIOS_H_ */