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