From 9ca64f73238d9f1b9f13d8e941ba42771a992afb Mon Sep 17 00:00:00 2001
From: Igor Mammedov <imammedo@redhat.com>
Date: Fri, 29 Dec 2023 14:06:05 +0100
Subject: [PATCH 20/20] pc/q35: set SMBIOS entry point type to 'auto' by
 default

RH-Author: Igor Mammedov <imammedo@redhat.com>
RH-MergeRequest: 230: Workaround Windows failing to find 64bit SMBIOS entry point with SeaBIOS
RH-Jira: RHEL-21705
RH-Acked-by: MST <mst@redhat.com>
RH-Acked-by: Ani Sinha <None>
RH-Commit: [18/18] c7fc6ac7350bca3ff99e58620710a86218385781

JIRA: https://issues.redhat.com/browse/RHEL-21705

    Use smbios-entry-point-type='auto' for newer machine types as a workaround
    for Windows not detecting SMBIOS tables. Which makes QEMU pick SMBIOS tables
    based on configuration (with 2.x preferred and fallback to 3.x if the former
    isn't compatible with configuration)

    Default compat setting of smbios-entry-point-type after series
    for pc/q35 machines:
      * 9.0-newer: 'auto'
      * 8.1-8.2: '64'
      * 8.0-older: '32'
    Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2008
    Signed-off-by: Igor Mammedov <imammedo@redhat.com>
    Reviewed-by: Ani Sinha <anisinha@redhat.com>
    Tested-by: Fiona Ebner <f.ebner@proxmox.com>

Conflicts: hw/i386/pc_piix.c hw/i386/pc_q35.c
  due to RHEL machine types

REHL only parts:
  Fix RHEL 'pc' machine types at SMBIOS 2.X
  for the latest RHEL 'q35' machine type use version autoselect
  which propagates to RHEL 9.4 q35 macine type while RHEL 9.2 q35 and older
  are kept at SMBIOS_ENTRY_POINT_TYPE_32 (see: pc_q35_machine_rhel920_options)

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/pc.c      | 2 +-
 hw/i386/pc_piix.c | 7 +++++++
 hw/i386/pc_q35.c  | 5 +++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ae6777fc1a..d6f267b220 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -2004,7 +2004,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     mc->nvdimm_supported = true;
     mc->smp_props.dies_supported = true;
     mc->default_ram_id = "pc.ram";
-    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_64;
+    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_AUTO;
 
     object_class_property_add(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
         pc_machine_get_max_ram_below_4g, pc_machine_set_max_ram_below_4g,
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 7344b35cf1..54d1c58bce 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -539,9 +539,14 @@ static void pc_i440fx_machine_options(MachineClass *m)
 
 static void pc_i440fx_8_2_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
     pc_i440fx_machine_options(m);
     m->alias = "pc";
     m->is_default = true;
+
+    /* For pc-i44fx-8.2 and 8.1, use SMBIOS 3.X by default */
+    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_64;
 }
 
 DEFINE_I440FX_MACHINE(v8_2, "pc-i440fx-8.2", NULL,
@@ -982,6 +987,8 @@ static void pc_machine_rhel7_options(MachineClass *m)
     m->alias = "pc";
     m->is_default = 1;
     m->smp_props.prefer_sockets = true;
+    /* there aren't ne PC macine types in RHEL9, keep it at SMBIOS 2.X */
+    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_32;
 }
 
 static void pc_init_rhel760(MachineState *machine)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 9a22ff5dd6..cd5fb7380e 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -377,8 +377,11 @@ static void pc_q35_machine_options(MachineClass *m)
 
 static void pc_q35_8_2_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_machine_options(m);
     m->alias = "q35";
+    /* For pc-q35-8.2 and 8.1, use SMBIOS 3.X by default */
+    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_64;
 }
 
 DEFINE_Q35_MACHINE(v8_2, "pc-q35-8.2", NULL,
@@ -712,6 +715,8 @@ static void pc_q35_machine_rhel_options(MachineClass *m)
     m->alias = "q35";
     m->max_cpus = 710;
     compat_props_add(m->compat_props, pc_rhel_compat, pc_rhel_compat_len);
+    /* use SMBIOS version autoselect by default for the latest RHEL machine */
+    pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_AUTO;
 }
 
 static void pc_q35_init_rhel940(MachineState *machine)
-- 
2.39.3