4 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
5 * Copyright (C) 2013 Red Hat, Inc.
6 * Copyright (c) 2015,2016 Corey Minyard, MontaVista Software, LLC
9 * Alex Williamson <alex.williamson@hp.com>
10 * Markus Armbruster <armbru@redhat.com>
12 * This work is licensed under the terms of the GNU GPL, version 2. See
13 * the COPYING file in the top-level directory.
15 * Contributions after 2012-01-13 are licensed under the terms of the
16 * GNU GPL, version 2 or (at your option) any later version.
19 #ifndef QEMU_SMBIOS_BUILD_H
20 #define QEMU_SMBIOS_BUILD_H
22 bool smbios_skip_table(uint8_t type
, bool required_table
);
24 extern uint8_t *smbios_tables
;
25 extern size_t smbios_tables_len
;
26 extern unsigned smbios_table_max
;
27 extern unsigned smbios_table_cnt
;
29 #define SMBIOS_BUILD_TABLE_PRE(tbl_type, tbl_handle, tbl_required) \
30 SMBIOS_BUILD_TABLE_PRE_SIZE(tbl_type, tbl_handle, tbl_required, \
31 sizeof(struct smbios_type_##tbl_type))\
33 #define SMBIOS_BUILD_TABLE_PRE_SIZE(tbl_type, tbl_handle, \
34 tbl_required, tbl_len) \
35 struct smbios_type_##tbl_type *t; \
36 size_t t_off; /* table offset into smbios_tables */ \
39 /* should we skip building this table ? */ \
40 if (smbios_skip_table(tbl_type, tbl_required)) { \
44 /* use offset of table t within smbios_tables */ \
45 /* (pointer must be updated after each realloc) */ \
46 t_off = smbios_tables_len; \
47 smbios_tables_len += tbl_len; \
48 smbios_tables = g_realloc(smbios_tables, smbios_tables_len); \
49 t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \
51 t->header.type = tbl_type; \
52 t->header.length = tbl_len; \
53 t->header.handle = cpu_to_le16(tbl_handle); \
56 #define SMBIOS_TABLE_SET_STR(tbl_type, field, value) \
58 int len = (value != NULL) ? strlen(value) + 1 : 0; \
60 smbios_tables = g_realloc(smbios_tables, \
61 smbios_tables_len + len); \
62 memcpy(smbios_tables + smbios_tables_len, value, len); \
63 smbios_tables_len += len; \
64 /* update pointer post-realloc */ \
65 t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \
66 t->field = ++str_index; \
72 #define SMBIOS_TABLE_SET_STR_LIST(tbl_type, value) \
74 int len = (value != NULL) ? strlen(value) + 1 : 0; \
76 smbios_tables = g_realloc(smbios_tables, \
77 smbios_tables_len + len); \
78 memcpy(smbios_tables + smbios_tables_len, value, len); \
79 smbios_tables_len += len; \
84 #define SMBIOS_BUILD_TABLE_POST \
86 size_t term_cnt, t_size; \
88 /* add '\0' terminator (add two if no strings defined) */ \
89 term_cnt = (str_index == 0) ? 2 : 1; \
90 smbios_tables = g_realloc(smbios_tables, \
91 smbios_tables_len + term_cnt); \
92 memset(smbios_tables + smbios_tables_len, 0, term_cnt); \
93 smbios_tables_len += term_cnt; \
95 /* update smbios max. element size */ \
96 t_size = smbios_tables_len - t_off; \
97 if (t_size > smbios_table_max) { \
98 smbios_table_max = t_size; \
101 /* update smbios element count */ \
102 smbios_table_cnt++; \
105 /* IPMI SMBIOS firmware handling */
106 void smbios_build_type_38_table(void);
108 #endif /* QEMU_SMBIOS_BUILD_H */