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