[v2 1/1] hw/i386/acpi-build: add OSHP method support for SHPC driver load

2024-06-24 Thread Shiyuan Gao via
SHPC driver will be loaded fail in i440fx machine, the dmesg shows
that OS cannot get control of SHPC hotplug and hotplug device to
the PCI bridge will fail when we use SHPC Native type:

  [3.336059] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0.S28_)
  [3.337408] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0)
  [3.338710] shpchp :00:03.0: Cannot get control of SHPC hotplug

Add OSHP method support for transfer control to the operating system,
after this SHPC driver will be loaded success and the hotplug device to
the PCI bridge will success when we use SHPC Native type.

  [1.703975] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0.S18_)
  [1.704934] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0)
  [1.705855] shpchp :00:03.0: Gained control of SHPC hotplug (\_SB_.PCI0)
  [1.707054] shpchp :00:03.0: HPC vendor_id 1b36 device_id 1 ss_vid 0 
ss_did 0

Signed-off-by: Shiyuan Gao 
---
v1 -> v2:
* add quote PCI firmware spec 3.0
* explain why an empty method is enough
---

 hw/i386/acpi-build.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f4e366f64f..00f8abedf6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1412,6 +1412,23 @@ static void build_acpi0017(Aml *table)
 aml_append(table, scope);
 }
 
+/*
+ * PCI Firmware Specification 3.0
+ * 4.8. The OSHP Control Method
+ */
+static Aml *build_oshp_method(void)
+{
+Aml *method;
+
+/*
+ * We don't use ACPI to control the SHPC, so just return
+ * success is enough.
+ */
+method = aml_method("OSHP", 0, AML_NOTSERIALIZED);
+aml_append(method, aml_return(aml_int(0x0)));
+return method;
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -1452,6 +1469,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
 aml_append(dev, aml_name_decl("_UID", aml_int(pcmc->pci_root_uid)));
 aml_append(dev, aml_pci_edsm());
+aml_append(dev, build_oshp_method());
 aml_append(sb_scope, dev);
 aml_append(dsdt, sb_scope);
 
@@ -1586,6 +1604,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 aml_append(dev, build_q35_osc_method(true));
 } else {
 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
+aml_append(dev, build_oshp_method());
 }
 
 if (numa_node != NUMA_NODE_UNASSIGNED) {
-- 
2.36.1




[PATCH 1/1] hw/i386/acpi-build: add OSHP method support for SHPC driver load

2024-06-24 Thread Shiyuan Gao via
SHPC driver will be loaded fail in i440fx platform, the dmesg shows
that OS cannot get control of SHPC hotplug and hotplug device to
the PCI bridge will fail when we use SHPC Native type:

  [3.336059] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0.S28_)
  [3.337408] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0)
  [3.338710] shpchp :00:03.0: Cannot get control of SHPC hotplug

Add OSHP method support for SHPC driver load, the hotplug device to the PCI 
bridge will
success when we use SHPC Native type.

  [1.703975] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0.S18_)
  [1.704934] shpchp :00:03.0: Requesting control of SHPC hotplug via OSHP 
(\_SB_.PCI0)
  [1.705855] shpchp :00:03.0: Gained control of SHPC hotplug (\_SB_.PCI0)
  [1.707054] shpchp :00:03.0: HPC vendor_id 1b36 device_id 1 ss_vid 0 
ss_did 0

According to the acpi_pcihp, the OSHP method don't need parameter and return 
value now.

  shpc_probe
--> acpi_get_hp_hw_control_from_firmware
  --> acpi_run_oshp
--> status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);

Signed-off-by: Shiyuan Gao 
---
 hw/i386/acpi-build.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f4e366f64f..79622e6939 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1412,6 +1412,18 @@ static void build_acpi0017(Aml *table)
 aml_append(table, scope);
 }
 
+static Aml *build_oshp_method(void)
+{
+Aml *method;
+
+/*
+ * Request control of SHPC hotplug via OSHP method,
+ * no need parameter and return value in acpi_pcihp.
+ */
+method = aml_method("OSHP", 0, AML_NOTSERIALIZED);
+return method;
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -1452,6 +1464,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
 aml_append(dev, aml_name_decl("_UID", aml_int(pcmc->pci_root_uid)));
 aml_append(dev, aml_pci_edsm());
+aml_append(dev, build_oshp_method());
 aml_append(sb_scope, dev);
 aml_append(dsdt, sb_scope);
 
@@ -1586,6 +1599,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 aml_append(dev, build_q35_osc_method(true));
 } else {
 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
+aml_append(dev, build_oshp_method());
 }
 
 if (numa_node != NUMA_NODE_UNASSIGNED) {
-- 
2.27.0




Re: [PATCH] kvm: limit the maximum CPUID.0xA.edx[0..4] to 3

2024-01-10 Thread Shiyuan Gao via
Anyone has suggestion?

When the host kernel before this commit 2e8cd7a3b828 ("kvm: x86: limit the 
maximum number of vPMU
fixed counters to 3") on icelake microarchitecture and newer, execute cpuid in 
the Guest:

Architecture Performance Monitoring Features (0xa/edx):
number of fixed counters= 0x4 (4)

This is not inconsistent with num_architectural_pmu_fixed_counters in QEMU.



[PATCH] util/qemu-config: Remove unnecessary traversal

2023-11-13 Thread Shiyuan Gao via
From: Gao Shiyuan 

No remove QemuOptsList from *_config_groups, so no need to
traverse from the beginning every time.

No functional changes.

Signed-off-by: Gao Shiyuan 
---
 include/qemu/config-file.h |  3 +++
 util/qemu-config.c | 18 --
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h
index b82a778123..223ef7bc8f 100644
--- a/include/qemu/config-file.h
+++ b/include/qemu/config-file.h
@@ -1,6 +1,9 @@
 #ifndef QEMU_CONFIG_FILE_H
 #define QEMU_CONFIG_FILE_H
 
+#define MAX_VM_CONFIG_GROUPS48
+#define MAX_DRIVE_CONFIG_GROUPS 5
+
 typedef void QEMUConfigCB(const char *group, QDict *qdict, void *opaque, Error 
**errp);
 
 void qemu_load_module_for_opts(const char *group);
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 42076efe1e..d7bab2047f 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -9,8 +9,8 @@
 #include "qemu/config-file.h"
 #include "hw/boards.h"
 
-static QemuOptsList *vm_config_groups[48];
-static QemuOptsList *drive_config_groups[5];
+static QemuOptsList *vm_config_groups[MAX_VM_CONFIG_GROUPS];
+static QemuOptsList *drive_config_groups[MAX_DRIVE_CONFIG_GROUPS];
 
 static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
Error **errp)
@@ -260,11 +260,10 @@ QemuOptsList *qemu_find_opts_err(const char *group, Error 
**errp)
 
 void qemu_add_drive_opts(QemuOptsList *list)
 {
-int entries, i;
+static int i;
+static int entries = MAX_DRIVE_CONFIG_GROUPS - 1; /* keep list NULL 
terminated */
 
-entries = ARRAY_SIZE(drive_config_groups);
-entries--; /* keep list NULL terminated */
-for (i = 0; i < entries; i++) {
+for (; i < entries; i++) {
 if (drive_config_groups[i] == NULL) {
 drive_config_groups[i] = list;
 return;
@@ -276,11 +275,10 @@ void qemu_add_drive_opts(QemuOptsList *list)
 
 void qemu_add_opts(QemuOptsList *list)
 {
-int entries, i;
+static int i;
+static int entries = MAX_VM_CONFIG_GROUPS - 1; /* keep list NULL 
terminated */
 
-entries = ARRAY_SIZE(vm_config_groups);
-entries--; /* keep list NULL terminated */
-for (i = 0; i < entries; i++) {
+for (; i < entries; i++) {
 if (vm_config_groups[i] == NULL) {
 vm_config_groups[i] = list;
 return;
-- 
2.27.0