xref: /openbmc/qemu/include/hw/firmware/smbios.h (revision d638a865)
1 #ifndef QEMU_SMBIOS_H
2 #define QEMU_SMBIOS_H
3 
4 #include "qapi/qapi-types-machine.h"
5 #include "qemu/bitmap.h"
6 
7 /*
8  * SMBIOS Support
9  *
10  * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
11  *
12  * Authors:
13  *  Alex Williamson <alex.williamson@hp.com>
14  *
15  * This work is licensed under the terms of the GNU GPL, version 2.  See
16  * the COPYING file in the top-level directory.
17  *
18  */
19 
20 typedef struct {
21     const char *vendor, *version, *date;
22     bool have_major_minor, uefi;
23     uint8_t major, minor;
24 } smbios_type0_t;
25 extern smbios_type0_t smbios_type0;
26 
27 typedef struct {
28     const char *manufacturer, *product, *version, *serial, *sku, *family;
29     /* uuid is in qemu_uuid */
30 } smbios_type1_t;
31 extern smbios_type1_t smbios_type1;
32 
33 #define SMBIOS_MAX_TYPE 127
34 extern DECLARE_BITMAP(smbios_have_binfile_bitmap, SMBIOS_MAX_TYPE + 1);
35 extern DECLARE_BITMAP(smbios_have_fields_bitmap, SMBIOS_MAX_TYPE + 1);
36 
37 #define offsetofend(TYPE, MEMBER) \
38        (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
39 
40 /* memory area description, used by type 19 table */
41 struct smbios_phys_mem_area {
42     uint64_t address;
43     uint64_t length;
44 };
45 
46 /* SMBIOS Entry Point
47  * There are two types of entry points defined in the SMBIOS specification
48  * (see below). BIOS must place the entry point(s) at a 16-byte-aligned
49  * address between 0xf0000 and 0xfffff. Note that either entry point type
50  * can be used in a 64-bit target system, except that SMBIOS 2.1 entry point
51  * only allows the SMBIOS struct table to reside below 4GB address space.
52  */
53 
54 /* SMBIOS 2.1 (32-bit) Entry Point
55  *  - introduced since SMBIOS 2.1
56  *  - supports structure table below 4GB only
57  */
58 struct smbios_21_entry_point {
59     uint8_t anchor_string[4];
60     uint8_t checksum;
61     uint8_t length;
62     uint8_t smbios_major_version;
63     uint8_t smbios_minor_version;
64     uint16_t max_structure_size;
65     uint8_t entry_point_revision;
66     uint8_t formatted_area[5];
67     uint8_t intermediate_anchor_string[5];
68     uint8_t intermediate_checksum;
69     uint16_t structure_table_length;
70     uint32_t structure_table_address;
71     uint16_t number_of_structures;
72     uint8_t smbios_bcd_revision;
73 } QEMU_PACKED;
74 
75 /* SMBIOS 3.0 (64-bit) Entry Point
76  *  - introduced since SMBIOS 3.0
77  *  - supports structure table at 64-bit address space
78  */
79 struct smbios_30_entry_point {
80     uint8_t anchor_string[5];
81     uint8_t checksum;
82     uint8_t length;
83     uint8_t smbios_major_version;
84     uint8_t smbios_minor_version;
85     uint8_t smbios_doc_rev;
86     uint8_t entry_point_revision;
87     uint8_t reserved;
88     uint32_t structure_table_max_size;
89     uint64_t structure_table_address;
90 } QEMU_PACKED;
91 
92 typedef union {
93     struct smbios_21_entry_point ep21;
94     struct smbios_30_entry_point ep30;
95 } QEMU_PACKED SmbiosEntryPoint;
96 
97 /* This goes at the beginning of every SMBIOS structure. */
98 struct smbios_structure_header {
99     uint8_t type;
100     uint8_t length;
101     uint16_t handle;
102 } QEMU_PACKED;
103 
104 /* SMBIOS type 0 - BIOS Information */
105 struct smbios_type_0 {
106     struct smbios_structure_header header;
107     uint8_t vendor_str;
108     uint8_t bios_version_str;
109     uint16_t bios_starting_address_segment;
110     uint8_t bios_release_date_str;
111     uint8_t bios_rom_size;
112     uint64_t bios_characteristics;
113     uint8_t bios_characteristics_extension_bytes[2];
114     uint8_t system_bios_major_release;
115     uint8_t system_bios_minor_release;
116     uint8_t embedded_controller_major_release;
117     uint8_t embedded_controller_minor_release;
118 } QEMU_PACKED;
119 
120 /* UUID encoding. The time_* fields are little-endian, as specified by SMBIOS
121  * version 2.6.
122  */
123 struct smbios_uuid {
124     uint32_t time_low;
125     uint16_t time_mid;
126     uint16_t time_hi_and_version;
127     uint8_t clock_seq_hi_and_reserved;
128     uint8_t clock_seq_low;
129     uint8_t node[6];
130 } QEMU_PACKED;
131 
132 /* SMBIOS type 1 - System Information */
133 struct smbios_type_1 {
134     struct smbios_structure_header header;
135     uint8_t manufacturer_str;
136     uint8_t product_name_str;
137     uint8_t version_str;
138     uint8_t serial_number_str;
139     struct smbios_uuid uuid;
140     uint8_t wake_up_type;
141     uint8_t sku_number_str;
142     uint8_t family_str;
143 } QEMU_PACKED;
144 
145 /* SMBIOS type 2 - Base Board */
146 struct smbios_type_2 {
147     struct smbios_structure_header header;
148     uint8_t manufacturer_str;
149     uint8_t product_str;
150     uint8_t version_str;
151     uint8_t serial_number_str;
152     uint8_t asset_tag_number_str;
153     uint8_t feature_flags;
154     uint8_t location_str;
155     uint16_t chassis_handle;
156     uint8_t board_type;
157     uint8_t contained_element_count;
158     /* contained elements follow */
159 } QEMU_PACKED;
160 
161 /* SMBIOS type 3 - System Enclosure (v2.7) */
162 struct smbios_type_3 {
163     struct smbios_structure_header header;
164     uint8_t manufacturer_str;
165     uint8_t type;
166     uint8_t version_str;
167     uint8_t serial_number_str;
168     uint8_t asset_tag_number_str;
169     uint8_t boot_up_state;
170     uint8_t power_supply_state;
171     uint8_t thermal_state;
172     uint8_t security_status;
173     uint32_t oem_defined;
174     uint8_t height;
175     uint8_t number_of_power_cords;
176     uint8_t contained_element_count;
177     uint8_t contained_element_record_length;
178     uint8_t sku_number_str;
179     /* contained elements follow */
180 } QEMU_PACKED;
181 
182 /* SMBIOS type 4 - Processor Information (v2.6) */
183 struct smbios_type_4 {
184     struct smbios_structure_header header;
185     uint8_t socket_designation_str;
186     uint8_t processor_type;
187     uint8_t processor_family;
188     uint8_t processor_manufacturer_str;
189     uint32_t processor_id[2];
190     uint8_t processor_version_str;
191     uint8_t voltage;
192     uint16_t external_clock;
193     uint16_t max_speed;
194     uint16_t current_speed;
195     uint8_t status;
196     uint8_t processor_upgrade;
197     uint16_t l1_cache_handle;
198     uint16_t l2_cache_handle;
199     uint16_t l3_cache_handle;
200     uint8_t serial_number_str;
201     uint8_t asset_tag_number_str;
202     uint8_t part_number_str;
203     uint8_t core_count;
204     uint8_t core_enabled;
205     uint8_t thread_count;
206     uint16_t processor_characteristics;
207     uint16_t processor_family2;
208     /* SMBIOS spec 3.0.0, Table 21 */
209     uint16_t core_count2;
210     uint16_t core_enabled2;
211     uint16_t thread_count2;
212 } QEMU_PACKED;
213 
214 typedef enum smbios_type_4_len_ver {
215     SMBIOS_TYPE_4_LEN_V28 = offsetofend(struct smbios_type_4,
216                                         processor_family2),
217     SMBIOS_TYPE_4_LEN_V30 = offsetofend(struct smbios_type_4, thread_count2),
218 } smbios_type_4_len_ver;
219 
220 /* SMBIOS type 8 - Port Connector Information */
221 struct smbios_type_8 {
222     struct smbios_structure_header header;
223     uint8_t internal_reference_str;
224     uint8_t internal_connector_type;
225     uint8_t external_reference_str;
226     uint8_t external_connector_type;
227     uint8_t port_type;
228 } QEMU_PACKED;
229 
230 /* SMBIOS type 9 - System Slots (v2.1+) */
231 struct smbios_type_9 {
232     struct smbios_structure_header header;
233     uint8_t slot_designation;
234     uint8_t slot_type;
235     uint8_t slot_data_bus_width;
236     uint8_t current_usage;
237     uint8_t slot_length;
238     uint16_t slot_id;
239     uint8_t slot_characteristics1;
240     uint8_t slot_characteristics2;
241     /* SMBIOS spec v2.6+ */
242     uint16_t segment_group_number;
243     uint8_t bus_number;
244     uint8_t device_number;
245 } QEMU_PACKED;
246 
247 /* SMBIOS type 11 - OEM strings */
248 struct smbios_type_11 {
249     struct smbios_structure_header header;
250     uint8_t count;
251 } QEMU_PACKED;
252 
253 /* SMBIOS type 16 - Physical Memory Array (v2.7) */
254 struct smbios_type_16 {
255     struct smbios_structure_header header;
256     uint8_t location;
257     uint8_t use;
258     uint8_t error_correction;
259     uint32_t maximum_capacity;
260     uint16_t memory_error_information_handle;
261     uint16_t number_of_memory_devices;
262     uint64_t extended_maximum_capacity;
263 } QEMU_PACKED;
264 
265 /* SMBIOS type 17 - Memory Device (v2.8) */
266 struct smbios_type_17 {
267     struct smbios_structure_header header;
268     uint16_t physical_memory_array_handle;
269     uint16_t memory_error_information_handle;
270     uint16_t total_width;
271     uint16_t data_width;
272     uint16_t size;
273     uint8_t form_factor;
274     uint8_t device_set;
275     uint8_t device_locator_str;
276     uint8_t bank_locator_str;
277     uint8_t memory_type;
278     uint16_t type_detail;
279     uint16_t speed;
280     uint8_t manufacturer_str;
281     uint8_t serial_number_str;
282     uint8_t asset_tag_number_str;
283     uint8_t part_number_str;
284     uint8_t attributes;
285     uint32_t extended_size;
286     uint16_t configured_clock_speed;
287     uint16_t minimum_voltage;
288     uint16_t maximum_voltage;
289     uint16_t configured_voltage;
290 } QEMU_PACKED;
291 
292 /* SMBIOS type 19 - Memory Array Mapped Address (v2.7) */
293 struct smbios_type_19 {
294     struct smbios_structure_header header;
295     uint32_t starting_address;
296     uint32_t ending_address;
297     uint16_t memory_array_handle;
298     uint8_t partition_width;
299     uint64_t extended_starting_address;
300     uint64_t extended_ending_address;
301 } QEMU_PACKED;
302 
303 /* SMBIOS type 32 - System Boot Information */
304 struct smbios_type_32 {
305     struct smbios_structure_header header;
306     uint8_t reserved[6];
307     uint8_t boot_status;
308 } QEMU_PACKED;
309 
310 /* SMBIOS type 41 - Onboard Devices Extended Information */
311 struct smbios_type_41 {
312     struct smbios_structure_header header;
313     uint8_t reference_designation_str;
314     uint8_t device_type;
315     uint8_t device_type_instance;
316     uint16_t segment_group_number;
317     uint8_t bus_number;
318     uint8_t device_number;
319 } QEMU_PACKED;
320 
321 /* SMBIOS type 127 -- End-of-table */
322 struct smbios_type_127 {
323     struct smbios_structure_header header;
324 } QEMU_PACKED;
325 
326 void smbios_entry_add(QemuOpts *opts, Error **errp);
327 void smbios_set_cpuid(uint32_t version, uint32_t features);
328 void smbios_set_defaults(const char *manufacturer, const char *product,
329                          const char *version,
330                          bool uuid_encoded, SmbiosEntryPointType ep_type);
331 void smbios_set_default_processor_family(uint16_t processor_family);
332 uint8_t *smbios_get_table_legacy(size_t *length);
333 void smbios_get_tables(MachineState *ms,
334                        const struct smbios_phys_mem_area *mem_array,
335                        const unsigned int mem_array_size,
336                        uint8_t **tables, size_t *tables_len,
337                        uint8_t **anchor, size_t *anchor_len,
338                        Error **errp);
339 #endif /* QEMU_SMBIOS_H */
340