> On 19 Mar 2026, at 8:36 AM, liu.xuemei1@zte.com.cn wrote:
>
> From: Xuemei Liu <liu.xuemei1@zte.com.cn>
>
> For riscv virt machine, add powerdown notification callback
> and send ACPI_POWER_DOWN_STATUS event by acpi ged. Also add
> acpi dsdt table for ACPI_POWER_BUTTON_DEVICE device in this
> patch.
>
> Signed-off-by: Xuemei Liu <liu.xuemei1@zte.com.cn>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
> ---
> hw/riscv/virt-acpi-build.c | 2 ++
> hw/riscv/virt.c | 14 ++++++++++++++
> include/hw/riscv/virt.h | 1 +
> 3 files changed, 17 insertions(+)
>
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index 1717b1c24f..77aea55ece 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -504,6 +504,8 @@ static void build_dsdt(GArray *table_data,
> ACPI_GED_IRQ, AML_SYSTEM_MEMORY,
> s->memmap[VIRT_ACPI_GED].base);
>
> + acpi_dsdt_add_power_button(scope);
> +
> aml_append(dsdt, scope);
>
> /* copy AML table into ACPI tables blob and patch header there */
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 4f1654d5ec..20002c6e43 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -51,6 +51,7 @@
> #include "system/kvm.h"
> #include "system/tpm.h"
> #include "system/qtest.h"
> +#include "system/runstate.h"
> #include "hw/pci/pci.h"
> #include "hw/pci-host/gpex.h"
> #include "hw/display/ramfb.h"
> @@ -1446,6 +1447,16 @@ static void virt_build_smbios(RISCVVirtState *s)
> }
> }
>
> +static void virt_powerdown_req(Notifier *notifier, void *opaque)
> +{
> + RISCVVirtState *s;
> +
> + s = container_of(notifier, RISCVVirtState, powerdown_notifier);
> + if (s->acpi_ged) {
> + acpi_send_event(s->acpi_ged, ACPI_POWER_DOWN_STATUS);
> + }
> +}
> +
> static void virt_machine_done(Notifier *notifier, void *data)
> {
> RISCVVirtState *s = container_of(notifier, RISCVVirtState,
> @@ -1773,6 +1784,9 @@ static void virt_machine_init(MachineState *machine)
> sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
> }
>
> + s->powerdown_notifier.notify = virt_powerdown_req;
> + qemu_register_powerdown_notifier(&s->powerdown_notifier);
> +
> s->machine_done.notify = virt_machine_done;
> qemu_add_machine_init_done_notifier(&s->machine_done);
> }
> diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
> index 9ea0b3b7b6..e631d57268 100644
> --- a/include/hw/riscv/virt.h
> +++ b/include/hw/riscv/virt.h
> @@ -47,6 +47,7 @@ struct RISCVVirtState {
>
> /*< public >*/
> Notifier machine_done;
> + Notifier powerdown_notifier;
> DeviceState *acpi_ged;
> DeviceState *platform_bus_dev;
> RISCVHartArrayState soc[VIRT_SOCKETS_MAX];
> --
> 2.27.0
>