From: Ani Sinha <anisinha@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
pbonzini@redhat.com, mst@redhat.com, gaosong@loongson.cn,
alistair.francis@wdc.com, palmer@dabbelt.com,
bin.meng@windriver.com, liwei1518@gmail.com,
dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com,
philmd@linaro.org, wangyanan55@huawei.com, eblake@redhat.com,
armbru@redhat.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org,
f.ebner@proxmox.com
Subject: Re: [PATCH v2 10/20] smbios: rename/expose structures/bitmaps used by both legacy and modern code
Date: Wed, 6 Mar 2024 12:45:13 +0530 (IST) [thread overview]
Message-ID: <b14d998d-91a1-c2b1-9d9b-5e4b41dfb045@redhat.com> (raw)
In-Reply-To: <20240305155724.2047069-11-imammedo@redhat.com>
On Tue, 5 Mar 2024, Igor Mammedov wrote:
> As a preparation to move legacy handling into a separate file,
> add prefix 'smbios_' to type0/type1/have_binfile_bitmap/have_fields_bitmap
> and expose them in smbios.h so that they can be reused in
> legacy and modern code.
>
> Doing it as a separate patch to avoid rename cluttering follow-up
> patch which will move legacy code into a separate file.
>
I checked that after application of this patch in the patcset, QEMU build
goes through fine. Therefore,
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
> ---
> include/hw/firmware/smbios.h | 16 +++++
> hw/smbios/smbios.c | 113 ++++++++++++++++-------------------
> 2 files changed, 69 insertions(+), 60 deletions(-)
>
> diff --git a/include/hw/firmware/smbios.h b/include/hw/firmware/smbios.h
> index 1fbff3c55f..bea5c3f1b1 100644
> --- a/include/hw/firmware/smbios.h
> +++ b/include/hw/firmware/smbios.h
> @@ -2,6 +2,7 @@
> #define QEMU_SMBIOS_H
>
> #include "qapi/qapi-types-machine.h"
> +#include "qemu/bitmap.h"
>
> /*
> * SMBIOS Support
> @@ -16,8 +17,23 @@
> *
> */
>
> +typedef struct {
> + const char *vendor, *version, *date;
> + bool have_major_minor, uefi;
> + uint8_t major, minor;
> +} smbios_type0_t;
> +extern smbios_type0_t smbios_type0;
> +
> +typedef struct {
> + const char *manufacturer, *product, *version, *serial, *sku, *family;
> + /* uuid is in qemu_uuid */
> +} smbios_type1_t;
> +extern smbios_type1_t smbios_type1;
>
> #define SMBIOS_MAX_TYPE 127
> +extern DECLARE_BITMAP(smbios_have_binfile_bitmap, SMBIOS_MAX_TYPE + 1);
> +extern DECLARE_BITMAP(smbios_have_fields_bitmap, SMBIOS_MAX_TYPE + 1);
> +
> #define offsetofend(TYPE, MEMBER) \
> (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
>
> diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
> index 01180bd82c..86cf66b5ce 100644
> --- a/hw/smbios/smbios.c
> +++ b/hw/smbios/smbios.c
> @@ -78,19 +78,11 @@ static int smbios_type4_count = 0;
> static bool smbios_have_defaults;
> static uint32_t smbios_cpuid_version, smbios_cpuid_features;
>
> -static DECLARE_BITMAP(have_binfile_bitmap, SMBIOS_MAX_TYPE+1);
> -static DECLARE_BITMAP(have_fields_bitmap, SMBIOS_MAX_TYPE+1);
> +DECLARE_BITMAP(smbios_have_binfile_bitmap, SMBIOS_MAX_TYPE + 1);
> +DECLARE_BITMAP(smbios_have_fields_bitmap, SMBIOS_MAX_TYPE + 1);
>
> -static struct {
> - const char *vendor, *version, *date;
> - bool have_major_minor, uefi;
> - uint8_t major, minor;
> -} type0;
> -
> -static struct {
> - const char *manufacturer, *product, *version, *serial, *sku, *family;
> - /* uuid is in qemu_uuid */
> -} type1;
> +smbios_type0_t smbios_type0;
> +smbios_type1_t smbios_type1;
>
> static struct {
> const char *manufacturer, *product, *version, *serial, *asset, *location;
> @@ -536,36 +528,36 @@ static void smbios_maybe_add_str(int type, int offset, const char *data)
> static void smbios_build_type_0_fields(void)
> {
> smbios_maybe_add_str(0, offsetof(struct smbios_type_0, vendor_str),
> - type0.vendor);
> + smbios_type0.vendor);
> smbios_maybe_add_str(0, offsetof(struct smbios_type_0, bios_version_str),
> - type0.version);
> + smbios_type0.version);
> smbios_maybe_add_str(0, offsetof(struct smbios_type_0,
> bios_release_date_str),
> - type0.date);
> - if (type0.have_major_minor) {
> + smbios_type0.date);
> + if (smbios_type0.have_major_minor) {
> smbios_add_field(0, offsetof(struct smbios_type_0,
> system_bios_major_release),
> - &type0.major, 1);
> + &smbios_type0.major, 1);
> smbios_add_field(0, offsetof(struct smbios_type_0,
> system_bios_minor_release),
> - &type0.minor, 1);
> + &smbios_type0.minor, 1);
> }
> }
>
> static void smbios_build_type_1_fields(void)
> {
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, manufacturer_str),
> - type1.manufacturer);
> + smbios_type1.manufacturer);
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, product_name_str),
> - type1.product);
> + smbios_type1.product);
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, version_str),
> - type1.version);
> + smbios_type1.version);
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, serial_number_str),
> - type1.serial);
> + smbios_type1.serial);
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, sku_number_str),
> - type1.sku);
> + smbios_type1.sku);
> smbios_maybe_add_str(1, offsetof(struct smbios_type_1, family_str),
> - type1.family);
> + smbios_type1.family);
> if (qemu_uuid_set) {
> /* We don't encode the UUID in the "wire format" here because this
> * function is for legacy mode and needs to keep the guest ABI, and
> @@ -583,14 +575,14 @@ uint8_t *smbios_get_table_legacy(size_t *length)
> size_t usr_offset;
>
> /* also complain if fields were given for types > 1 */
> - if (find_next_bit(have_fields_bitmap,
> + if (find_next_bit(smbios_have_fields_bitmap,
> SMBIOS_MAX_TYPE + 1, 2) < SMBIOS_MAX_TYPE + 1) {
> error_report("can't process fields for smbios "
> "types > 1 on machine versions < 2.1!");
> exit(1);
> }
>
> - if (test_bit(4, have_binfile_bitmap)) {
> + if (test_bit(4, smbios_have_binfile_bitmap)) {
> error_report("can't process table for smbios "
> "type 4 on machine versions < 2.1!");
> exit(1);
> @@ -631,10 +623,10 @@ uint8_t *smbios_get_table_legacy(size_t *length)
>
> bool smbios_skip_table(uint8_t type, bool required_table)
> {
> - if (test_bit(type, have_binfile_bitmap)) {
> + if (test_bit(type, smbios_have_binfile_bitmap)) {
> return true; /* user provided their own binary blob(s) */
> }
> - if (test_bit(type, have_fields_bitmap)) {
> + if (test_bit(type, smbios_have_fields_bitmap)) {
> return false; /* user provided fields via command line */
> }
> if (smbios_have_defaults && required_table) {
> @@ -661,25 +653,25 @@ static void smbios_build_type_0_table(void)
> {
> SMBIOS_BUILD_TABLE_PRE(0, T0_BASE, false); /* optional, leave up to BIOS */
>
> - SMBIOS_TABLE_SET_STR(0, vendor_str, type0.vendor);
> - SMBIOS_TABLE_SET_STR(0, bios_version_str, type0.version);
> + SMBIOS_TABLE_SET_STR(0, vendor_str, smbios_type0.vendor);
> + SMBIOS_TABLE_SET_STR(0, bios_version_str, smbios_type0.version);
>
> t->bios_starting_address_segment = cpu_to_le16(0xE800); /* from SeaBIOS */
>
> - SMBIOS_TABLE_SET_STR(0, bios_release_date_str, type0.date);
> + SMBIOS_TABLE_SET_STR(0, bios_release_date_str, smbios_type0.date);
>
> t->bios_rom_size = 0; /* hardcoded in SeaBIOS with FIXME comment */
>
> t->bios_characteristics = cpu_to_le64(0x08); /* Not supported */
> t->bios_characteristics_extension_bytes[0] = 0;
> t->bios_characteristics_extension_bytes[1] = 0x14; /* TCD/SVVP | VM */
> - if (type0.uefi) {
> + if (smbios_type0.uefi) {
> t->bios_characteristics_extension_bytes[1] |= 0x08; /* |= UEFI */
> }
>
> - if (type0.have_major_minor) {
> - t->system_bios_major_release = type0.major;
> - t->system_bios_minor_release = type0.minor;
> + if (smbios_type0.have_major_minor) {
> + t->system_bios_major_release = smbios_type0.major;
> + t->system_bios_minor_release = smbios_type0.minor;
> } else {
> t->system_bios_major_release = 0;
> t->system_bios_minor_release = 0;
> @@ -709,18 +701,18 @@ static void smbios_build_type_1_table(void)
> {
> SMBIOS_BUILD_TABLE_PRE(1, T1_BASE, true); /* required */
>
> - SMBIOS_TABLE_SET_STR(1, manufacturer_str, type1.manufacturer);
> - SMBIOS_TABLE_SET_STR(1, product_name_str, type1.product);
> - SMBIOS_TABLE_SET_STR(1, version_str, type1.version);
> - SMBIOS_TABLE_SET_STR(1, serial_number_str, type1.serial);
> + SMBIOS_TABLE_SET_STR(1, manufacturer_str, smbios_type1.manufacturer);
> + SMBIOS_TABLE_SET_STR(1, product_name_str, smbios_type1.product);
> + SMBIOS_TABLE_SET_STR(1, version_str, smbios_type1.version);
> + SMBIOS_TABLE_SET_STR(1, serial_number_str, smbios_type1.serial);
> if (qemu_uuid_set) {
> smbios_encode_uuid(&t->uuid, &qemu_uuid);
> } else {
> memset(&t->uuid, 0, 16);
> }
> t->wake_up_type = 0x06; /* power switch */
> - SMBIOS_TABLE_SET_STR(1, sku_number_str, type1.sku);
> - SMBIOS_TABLE_SET_STR(1, family_str, type1.family);
> + SMBIOS_TABLE_SET_STR(1, sku_number_str, smbios_type1.sku);
> + SMBIOS_TABLE_SET_STR(1, family_str, smbios_type1.family);
>
> SMBIOS_BUILD_TABLE_POST;
> }
> @@ -1055,9 +1047,9 @@ void smbios_set_defaults(const char *manufacturer, const char *product,
> smbios_uuid_encoded = uuid_encoded;
> smbios_ep_type = ep_type;
>
> - SMBIOS_SET_DEFAULT(type1.manufacturer, manufacturer);
> - SMBIOS_SET_DEFAULT(type1.product, product);
> - SMBIOS_SET_DEFAULT(type1.version, version);
> + SMBIOS_SET_DEFAULT(smbios_type1.manufacturer, manufacturer);
> + SMBIOS_SET_DEFAULT(smbios_type1.product, product);
> + SMBIOS_SET_DEFAULT(smbios_type1.version, version);
> SMBIOS_SET_DEFAULT(type2.manufacturer, manufacturer);
> SMBIOS_SET_DEFAULT(type2.product, product);
> SMBIOS_SET_DEFAULT(type2.version, version);
> @@ -1329,13 +1321,13 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
> }
>
> if (header->type <= SMBIOS_MAX_TYPE) {
> - if (test_bit(header->type, have_fields_bitmap)) {
> + if (test_bit(header->type, smbios_have_fields_bitmap)) {
> error_setg(errp,
> "can't load type %d struct, fields already specified!",
> header->type);
> return;
> }
> - set_bit(header->type, have_binfile_bitmap);
> + set_bit(header->type, smbios_have_binfile_bitmap);
> }
>
> if (header->type == 4) {
> @@ -1366,41 +1358,42 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
> return;
> }
>
> - if (test_bit(type, have_binfile_bitmap)) {
> + if (test_bit(type, smbios_have_binfile_bitmap)) {
> error_setg(errp, "can't add fields, binary file already loaded!");
> return;
> }
> - set_bit(type, have_fields_bitmap);
> + set_bit(type, smbios_have_fields_bitmap);
>
> switch (type) {
> case 0:
> if (!qemu_opts_validate(opts, qemu_smbios_type0_opts, errp)) {
> return;
> }
> - save_opt(&type0.vendor, opts, "vendor");
> - save_opt(&type0.version, opts, "version");
> - save_opt(&type0.date, opts, "date");
> - type0.uefi = qemu_opt_get_bool(opts, "uefi", false);
> + save_opt(&smbios_type0.vendor, opts, "vendor");
> + save_opt(&smbios_type0.version, opts, "version");
> + save_opt(&smbios_type0.date, opts, "date");
> + smbios_type0.uefi = qemu_opt_get_bool(opts, "uefi", false);
>
> val = qemu_opt_get(opts, "release");
> if (val) {
> - if (sscanf(val, "%hhu.%hhu", &type0.major, &type0.minor) != 2) {
> + if (sscanf(val, "%hhu.%hhu", &smbios_type0.major,
> + &smbios_type0.minor) != 2) {
> error_setg(errp, "Invalid release");
> return;
> }
> - type0.have_major_minor = true;
> + smbios_type0.have_major_minor = true;
> }
> return;
> case 1:
> if (!qemu_opts_validate(opts, qemu_smbios_type1_opts, errp)) {
> return;
> }
> - save_opt(&type1.manufacturer, opts, "manufacturer");
> - save_opt(&type1.product, opts, "product");
> - save_opt(&type1.version, opts, "version");
> - save_opt(&type1.serial, opts, "serial");
> - save_opt(&type1.sku, opts, "sku");
> - save_opt(&type1.family, opts, "family");
> + save_opt(&smbios_type1.manufacturer, opts, "manufacturer");
> + save_opt(&smbios_type1.product, opts, "product");
> + save_opt(&smbios_type1.version, opts, "version");
> + save_opt(&smbios_type1.serial, opts, "serial");
> + save_opt(&smbios_type1.sku, opts, "sku");
> + save_opt(&smbios_type1.family, opts, "family");
>
> val = qemu_opt_get(opts, "uuid");
> if (val) {
> --
> 2.39.3
>
>
next prev parent reply other threads:[~2024-03-06 7:16 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 15:57 [PATCH v2 00/20] Workaround Windows failing to find 64bit SMBIOS entry point with SeaBIOS Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 01/20] tests: smbios: make it possible to write SMBIOS only test Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 02/20] tests: smbios: add test for -smbios type=11 option Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 03/20] tests: smbios: add test for legacy mode CLI options Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 04/20] smbios: cleanup smbios_get_tables() from legacy handling Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 05/20] smbios: get rid of smbios_smp_sockets global Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 06/20] smbios: get rid of smbios_legacy global Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 07/20] smbios: avoid mangling user provided tables Igor Mammedov
2024-03-06 6:41 ` Ani Sinha
2024-03-07 4:03 ` Ani Sinha
2024-03-08 17:19 ` Igor Mammedov
2024-03-09 5:42 ` Ani Sinha
2024-03-05 15:57 ` [PATCH v2 08/20] smbios: don't check type4 structures in legacy mode Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 09/20] smbios: add smbios_add_usr_blob_size() helper Igor Mammedov
2024-03-06 6:48 ` Ani Sinha
2024-03-05 15:57 ` [PATCH v2 10/20] smbios: rename/expose structures/bitmaps used by both legacy and modern code Igor Mammedov
2024-03-06 7:15 ` Ani Sinha [this message]
2024-03-05 15:57 ` [PATCH v2 11/20] smbios: build legacy mode code only for 'pc' machine Igor Mammedov
2024-03-06 7:27 ` Ani Sinha
2024-03-06 10:04 ` Igor Mammedov
2024-03-06 10:03 ` [PATCH v3 " Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 12/20] smbios: handle errors consistently Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 13/20] smbios: get rid of global smbios_ep_type Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 14/20] smbios: extend smbios-entry-point-type with 'auto' value Igor Mammedov
2024-03-08 7:25 ` Markus Armbruster
2024-03-08 12:21 ` [PATCH v3 " Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 15/20] smbios: in case of entry point is 'auto' try to build v2 tables 1st Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 16/20] smbios: error out when building type 4 table is not possible Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 17/20] smbios: clear smbios_type4_count before building tables Igor Mammedov
2024-03-06 7:47 ` Ani Sinha
2024-03-06 9:58 ` Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 18/20] tests: acpi/smbios: whitelist expected blobs Igor Mammedov
2024-03-06 8:31 ` Ani Sinha
2024-03-05 15:57 ` [PATCH v2 19/20] pc/q35: set SMBIOS entry point type to 'auto' by default Igor Mammedov
2024-03-05 15:57 ` [PATCH v2 20/20] tests: acpi: update expected SSDT.dimmpxm blob Igor Mammedov
2024-03-06 9:20 ` Ani Sinha
2024-03-06 10:01 ` Igor Mammedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b14d998d-91a1-c2b1-9d9b-5e4b41dfb045@redhat.com \
--to=anisinha@redhat.com \
--cc=alistair.francis@wdc.com \
--cc=armbru@redhat.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=eblake@redhat.com \
--cc=f.ebner@proxmox.com \
--cc=gaosong@loongson.cn \
--cc=imammedo@redhat.com \
--cc=liwei1518@gmail.com \
--cc=mst@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=wangyanan55@huawei.com \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).