Re: [PATCH v3 7/7] Update the ACPI table for the Loongarch CPU

2023-09-26 Thread lixianglai



Hi Salil Mehta:

Hi Xianglai,


From: xianglai li 
Sent: Tuesday, September 26, 2023 10:55 AM
To: qemu-devel@nongnu.org
Cc: Bernhard Beschow ; Salil Mehta
; Salil Mehta ; Xiaojuan
Yang ; Song Gao ; Michael S.
Tsirkin ; Igor Mammedov ; Ani Sinha
; Paolo Bonzini ; Richard
Henderson ; Eduardo Habkost
; Marcel Apfelbaum ;
Philippe Mathieu-Daudé ; wangyanan (Y)
; Daniel P. Berrangé ; Peter
Xu ; David Hildenbrand ; Bibo Mao

Subject: [PATCH v3 7/7] Update the ACPI table for the Loongarch CPU

Add new types of GED devices for Loongarch machines,
add CPU hot-(un)plug event response and address spaces,
and update the ACPI table.

Cc: "Bernhard Beschow" 
Cc: "Salil Mehta" 
Cc: "Salil Mehta" 
Cc: Xiaojuan Yang 
Cc: Song Gao 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: Ani Sinha 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: Marcel Apfelbaum 
Cc: "Philippe Mathieu-Daudé" 
Cc: Yanan Wang 
Cc: "Daniel P. Berrangé" 
Cc: Peter Xu 
Cc: David Hildenbrand 
Cc: Bibo Mao 
Signed-off-by: xianglai li 
---
  hw/acpi/acpi-cpu-hotplug-stub.c |  9 +
  hw/loongarch/acpi-build.c   | 34 -
  hw/loongarch/virt.c |  3 ++-
  include/hw/loongarch/virt.h |  1 +
  4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-
stub.c
index 2aec90d968..b3ac7a1e31 100644
--- a/hw/acpi/acpi-cpu-hotplug-stub.c
+++ b/hw/acpi/acpi-cpu-hotplug-stub.c
@@ -19,6 +19,15 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent,
Object *owner,
  return;
  }

+void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures
opts,
+build_madt_cpu_fn build_madt_cpu, hwaddr mmap_io_base,
+const char *res_root,
+const char *event_handler_method,
+AmlRegionSpace rs)
+{
+return;
+}
+
  void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList
***list)
  {
  return;



Ok, I'll take care of that.

Thanks,

Xianglai.



Above change is already part of the architecture agnostic patch-set.
Not required here!

Thanks
Salil.





RE: [PATCH v3 7/7] Update the ACPI table for the Loongarch CPU

2023-09-26 Thread Salil Mehta via
Hi Xianglai,

> From: xianglai li 
> Sent: Tuesday, September 26, 2023 10:55 AM
> To: qemu-devel@nongnu.org
> Cc: Bernhard Beschow ; Salil Mehta
> ; Salil Mehta ; Xiaojuan
> Yang ; Song Gao ; Michael S.
> Tsirkin ; Igor Mammedov ; Ani Sinha
> ; Paolo Bonzini ; Richard
> Henderson ; Eduardo Habkost
> ; Marcel Apfelbaum ;
> Philippe Mathieu-Daudé ; wangyanan (Y)
> ; Daniel P. Berrangé ; Peter
> Xu ; David Hildenbrand ; Bibo Mao
> 
> Subject: [PATCH v3 7/7] Update the ACPI table for the Loongarch CPU
> 
> Add new types of GED devices for Loongarch machines,
> add CPU hot-(un)plug event response and address spaces,
> and update the ACPI table.
> 
> Cc: "Bernhard Beschow" 
> Cc: "Salil Mehta" 
> Cc: "Salil Mehta" 
> Cc: Xiaojuan Yang 
> Cc: Song Gao 
> Cc: "Michael S. Tsirkin" 
> Cc: Igor Mammedov 
> Cc: Ani Sinha 
> Cc: Paolo Bonzini 
> Cc: Richard Henderson 
> Cc: Eduardo Habkost 
> Cc: Marcel Apfelbaum 
> Cc: "Philippe Mathieu-Daudé" 
> Cc: Yanan Wang 
> Cc: "Daniel P. Berrangé" 
> Cc: Peter Xu 
> Cc: David Hildenbrand 
> Cc: Bibo Mao 
> Signed-off-by: xianglai li 
> ---
>  hw/acpi/acpi-cpu-hotplug-stub.c |  9 +
>  hw/loongarch/acpi-build.c   | 34 -
>  hw/loongarch/virt.c |  3 ++-
>  include/hw/loongarch/virt.h |  1 +
>  4 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-
> stub.c
> index 2aec90d968..b3ac7a1e31 100644
> --- a/hw/acpi/acpi-cpu-hotplug-stub.c
> +++ b/hw/acpi/acpi-cpu-hotplug-stub.c
> @@ -19,6 +19,15 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent,
> Object *owner,
>  return;
>  }
> 
> +void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures
> opts,
> +build_madt_cpu_fn build_madt_cpu, hwaddr mmap_io_base,
> +const char *res_root,
> +const char *event_handler_method,
> +AmlRegionSpace rs)
> +{
> +return;
> +}
> +
>  void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList
> ***list)
>  {
>  return;


Above change is already part of the architecture agnostic patch-set.
Not required here!

Thanks
Salil.


[PATCH v3 7/7] Update the ACPI table for the Loongarch CPU

2023-09-26 Thread xianglai li
Add new types of GED devices for Loongarch machines,
add CPU hot-(un)plug event response and address spaces,
and update the ACPI table.

Cc: "Bernhard Beschow" 
Cc: "Salil Mehta" 
Cc: "Salil Mehta" 
Cc: Xiaojuan Yang 
Cc: Song Gao 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: Ani Sinha 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: Marcel Apfelbaum 
Cc: "Philippe Mathieu-Daudé" 
Cc: Yanan Wang 
Cc: "Daniel P. Berrangé" 
Cc: Peter Xu 
Cc: David Hildenbrand 
Cc: Bibo Mao 
Signed-off-by: xianglai li 
---
 hw/acpi/acpi-cpu-hotplug-stub.c |  9 +
 hw/loongarch/acpi-build.c   | 34 -
 hw/loongarch/virt.c |  3 ++-
 include/hw/loongarch/virt.h |  1 +
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-stub.c
index 2aec90d968..b3ac7a1e31 100644
--- a/hw/acpi/acpi-cpu-hotplug-stub.c
+++ b/hw/acpi/acpi-cpu-hotplug-stub.c
@@ -19,6 +19,15 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, 
Object *owner,
 return;
 }
 
+void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
+build_madt_cpu_fn build_madt_cpu, hwaddr mmap_io_base,
+const char *res_root,
+const char *event_handler_method,
+AmlRegionSpace rs)
+{
+return;
+}
+
 void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
 {
 return;
diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
index ae292fc543..cf89e5c1cb 100644
--- a/hw/loongarch/acpi-build.c
+++ b/hw/loongarch/acpi-build.c
@@ -46,6 +46,23 @@
 #define ACPI_BUILD_DPRINTF(fmt, ...)
 #endif
 
+static void virt_madt_cpu_entry(int uid,
+const CPUArchIdList *apic_ids,
+GArray *entry, bool force_enabled)
+{
+uint32_t apic_id = apic_ids->cpus[uid].arch_id;
+/* Flags – Local APIC Flags */
+uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+ 1 /* Enabled */ : 0;
+
+/* Rev 1.0b, Table 5-13 Processor Local APIC Structure */
+build_append_int_noprefix(entry, 0, 1);   /* Type */
+build_append_int_noprefix(entry, 8, 1);   /* Length */
+build_append_int_noprefix(entry, uid, 1); /* ACPI Processor ID */
+build_append_int_noprefix(entry, apic_id, 1); /* APIC ID */
+build_append_int_noprefix(entry, flags, 4); /* Flags */
+}
+
 /* build FADT */
 static void init_common_fadt_data(AcpiFadtData *data)
 {
@@ -121,15 +138,18 @@ build_madt(GArray *table_data, BIOSLinker *linker, 
LoongArchMachineState *lams)
 build_append_int_noprefix(table_data, 1 /* PCAT_COMPAT */, 4); /* Flags */
 
 for (i = 0; i < arch_ids->len; i++) {
+uint32_t flags;
+
 /* Processor Core Interrupt Controller Structure */
 arch_id = arch_ids->cpus[i].arch_id;
+flags = arch_ids->cpus[i].cpu ? 1 : 0;
 
 build_append_int_noprefix(table_data, 17, 1);/* Type */
 build_append_int_noprefix(table_data, 15, 1);/* Length */
 build_append_int_noprefix(table_data, 1, 1); /* Version */
 build_append_int_noprefix(table_data, i, 4); /* ACPI Processor ID 
*/
 build_append_int_noprefix(table_data, arch_id, 4); /* Core ID */
-build_append_int_noprefix(table_data, 1, 4); /* Flags */
+build_append_int_noprefix(table_data, flags, 4);   /* Flags */
 }
 
 /* Extend I/O Interrupt Controller Structure */
@@ -292,6 +312,18 @@ build_la_ged_aml(Aml *dsdt, MachineState *machine)
  AML_SYSTEM_MEMORY,
  VIRT_GED_MEM_ADDR);
 }
+
+if (event & ACPI_GED_CPU_HOTPLUG_EVT) {
+CPUHotplugFeatures opts = {
+.acpi_1_compatible = false,
+.has_legacy_cphp = false
+};
+
+build_cpus_aml(dsdt, machine, opts, virt_madt_cpu_entry,
+   VIRT_GED_CPUHP_ADDR, "\\_SB", "\\_GPE._E01",
+   AML_SYSTEM_MEMORY);
+
+}
 acpi_dsdt_add_power_button(dsdt);
 }
 
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index c704f3117f..22b287eb39 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -449,7 +449,7 @@ static DeviceState *create_acpi_ged(DeviceState *pch_pic, 
LoongArchMachineState
 {
 DeviceState *dev;
 MachineState *ms = MACHINE(lams);
-uint32_t event = ACPI_GED_PWR_DOWN_EVT;
+uint32_t event = ACPI_GED_PWR_DOWN_EVT | ACPI_GED_CPU_HOTPLUG_EVT;
 
 if (ms->ram_slots) {
 event |= ACPI_GED_MEM_HOTPLUG_EVT;
@@ -463,6 +463,7 @@ static DeviceState *create_acpi_ged(DeviceState *pch_pic, 
LoongArchMachineState
 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, VIRT_GED_MEM_ADDR);
 /* ged regs used for reset and power down */
 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, VIRT_GED_REG_ADDR);
+sysbus_mmio_map(SYS_BUS_DEVICE(dev), 3, VIRT_GED_CP