Create a new GED device type for Loongarch, mount cpu_madt function to update the ACPI table.
Cc: "Salil Mehta" <salil.me...@opnsrc.net> Cc: Xiaojuan Yang <yangxiaoj...@loongson.cn> Cc: Song Gao <gaos...@loongson.cn> Cc: "Michael S. Tsirkin" <m...@redhat.com> Cc: Igor Mammedov <imamm...@redhat.com> Cc: Ani Sinha <anisi...@redhat.com> Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: Richard Henderson <richard.hender...@linaro.org> Cc: Eduardo Habkost <edua...@habkost.net> Cc: Marcel Apfelbaum <marcel.apfelb...@gmail.com> Cc: "Philippe Mathieu-Daudé" <phi...@linaro.org> Cc: Yanan Wang <wangyana...@huawei.com> Cc: "Daniel P. Berrangé" <berra...@redhat.com> Cc: Peter Xu <pet...@redhat.com> Cc: David Hildenbrand <da...@redhat.com> Cc: Bibo Mao <maob...@loongson.cn> Signed-off-by: xianglai li <lixiang...@loongson.cn> --- hw/loongarch/acpi-build.c | 17 +++++++++ hw/loongarch/generic_event_device_loongarch.c | 36 +++++++++++++++++++ hw/loongarch/meson.build | 2 +- include/hw/acpi/generic_event_device.h | 1 + include/hw/loongarch/virt.h | 4 +++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 hw/loongarch/generic_event_device_loongarch.c diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c index ae292fc543..66fad295cc 100644 --- a/hw/loongarch/acpi-build.c +++ b/hw/loongarch/acpi-build.c @@ -46,6 +46,23 @@ #define ACPI_BUILD_DPRINTF(fmt, ...) #endif +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) { diff --git a/hw/loongarch/generic_event_device_loongarch.c b/hw/loongarch/generic_event_device_loongarch.c new file mode 100644 index 0000000000..1fe550239b --- /dev/null +++ b/hw/loongarch/generic_event_device_loongarch.c @@ -0,0 +1,36 @@ +/* + * loongarch variant of the generic event device for hw reduced acpi + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + */ + +#include "qemu/osdep.h" +#include "hw/acpi/generic_event_device.h" +#include "hw/loongarch/virt.h" + +static void acpi_ged_loongarch_class_init(ObjectClass *class, void *data) +{ + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(class); + + adevc->madt_cpu = virt_madt_cpu_entry; +} + +static const TypeInfo acpi_ged_loongarch_info = { + .name = TYPE_ACPI_GED_LOONGARCH, + .parent = TYPE_ACPI_GED, + .class_init = acpi_ged_loongarch_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { TYPE_ACPI_DEVICE_IF }, + { } + } +}; + +static void acpi_ged_loongarch_register_types(void) +{ + type_register_static(&acpi_ged_loongarch_info); +} + +type_init(acpi_ged_loongarch_register_types) diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build index c0421502ab..8d21addee3 100644 --- a/hw/loongarch/meson.build +++ b/hw/loongarch/meson.build @@ -3,6 +3,6 @@ loongarch_ss.add(files( 'fw_cfg.c', )) loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: [files('virt.c'), fdt]) -loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c')) +loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c', 'generic_event_device_loongarch.c')) hw_arch += {'loongarch': loongarch_ss} diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h index d0a5a43abf..2923bd9d82 100644 --- a/include/hw/acpi/generic_event_device.h +++ b/include/hw/acpi/generic_event_device.h @@ -71,6 +71,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED) #define TYPE_ACPI_GED_X86 "acpi-ged-x86" +#define TYPE_ACPI_GED_LOONGARCH "acpi-ged-loongarch" #define ACPI_GED_EVT_SEL_OFFSET 0x0 #define ACPI_GED_EVT_SEL_LEN 0x4 diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h index 176dc43a93..f6c9495af2 100644 --- a/include/hw/loongarch/virt.h +++ b/include/hw/loongarch/virt.h @@ -60,4 +60,8 @@ struct LoongArchMachineState { OBJECT_DECLARE_SIMPLE_TYPE(LoongArchMachineState, LOONGARCH_MACHINE) bool loongarch_is_acpi_enabled(LoongArchMachineState *lams); void loongarch_acpi_setup(LoongArchMachineState *lams); +void virt_madt_cpu_entry(int uid, + const CPUArchIdList *apic_ids, GArray *entry, + bool force_enabled); + #endif -- 2.39.1