smbios.h 6.1 KB

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