All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: qemu-devel@nongnu.org, Ani Sinha <anisinha@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Song Gao <gaosong@loongson.cn>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Eduardo Habkost <eduardo@habkost.net>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Sergio Lopez <slp@redhat.com>
Subject: Re: [PATCH 1/3] acpi/ged: Implement S3 and S4 sleep
Date: Mon, 1 Jul 2024 16:19:39 -0400	[thread overview]
Message-ID: <20240701161751-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20240613-loongarch64-sleep-v1-1-d2ef0aaa543a@flygoat.com>

On Thu, Jun 13, 2024 at 06:30:15PM +0100, Jiaxun Yang wrote:
> Implement S3 and S4 sleep with ACPI_GED_REG_SLEEP_CTL.SLP_TYP
> writes.
> 
> Implement wakeup callback and WAK_STS register to inform guest
> about current states.
> 
> All new functions are gated by "slp-typs" property, it is defaulted
> to S5 only and machines can opt-in for S3 and S4.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>  hw/acpi/generic_event_device.c         | 70 ++++++++++++++++++++++++++++++----
>  include/hw/acpi/generic_event_device.h | 12 +++++-
>  2 files changed, 73 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index 2d6e91b124e5..f1fc99c04011 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -11,6 +11,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
> +#include "qapi/qapi-events-run-state.h"
>  #include "hw/acpi/acpi.h"
>  #include "hw/acpi/generic_event_device.h"
>  #include "hw/irq.h"
> @@ -186,24 +187,53 @@ static const MemoryRegionOps ged_evt_ops = {
>  
>  static uint64_t ged_regs_read(void *opaque, hwaddr addr, unsigned size)
>  {
> +    GEDState *ged_st = opaque;
> +
> +    switch (addr) {
> +    case ACPI_GED_REG_SLEEP_STS:
> +        return ged_st->sleep_sts;
> +    default:
> +        break;
> +    }
> +
>      return 0;
>  }
>  
>  static void ged_regs_write(void *opaque, hwaddr addr, uint64_t data,
>                             unsigned int size)
>  {
> -    bool slp_en;
> -    int slp_typ;
> +    GEDState *ged_st = opaque;
> +    AcpiGedState *s = container_of(ged_st, AcpiGedState, ged_state);
>  
>      switch (addr) {
>      case ACPI_GED_REG_SLEEP_CTL:
> -        slp_typ = (data >> 2) & 0x07;
> -        slp_en  = (data >> 5) & 0x01;
> -        if (slp_en && slp_typ == 5) {
> -            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> +        if (data & ACPI_GED_SLP_EN) {
> +            switch (extract8(data, 2, 3)) {
> +            case ACPI_GED_SLP_TYP_S3:
> +                if (s->slp_typs_bitmap & (1 << ACPI_GED_SLP_TYP_S3)) {
> +                    qemu_system_suspend_request();
> +                }
> +                break;
> +            case ACPI_GED_SLP_TYP_S4:
> +                if (s->slp_typs_bitmap & (1 << ACPI_GED_SLP_TYP_S4)) {
> +                    qapi_event_send_suspend_disk();
> +                    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> +                }
> +                break;
> +            case ACPI_GED_SLP_TYP_S5:
> +                if (s->slp_typs_bitmap & (1 << ACPI_GED_SLP_TYP_S5)) {
> +                    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> +                }
> +                break;
> +            default:
> +                break;
> +            }
>          }
>          return;
>      case ACPI_GED_REG_SLEEP_STS:
> +        if (data & ACPI_GED_WAK_STS) {
> +            ged_st->sleep_sts &= ~ACPI_GED_WAK_STS;
> +        }
>          return;
>      case ACPI_GED_REG_RESET:
>          if (data == ACPI_GED_RESET_VALUE) {
> @@ -223,6 +253,14 @@ static const MemoryRegionOps ged_regs_ops = {
>      },
>  };
>  
> +static void acpi_ged_notify_wakeup(Notifier *notifier, void *data)
> +{
> +    GEDState *ged_st = container_of(notifier, GEDState, wakeup);
> +
> +    ged_st->sleep_sts |= ACPI_GED_WAK_STS;
> +}
> +
> +
>  static void acpi_ged_device_plug_cb(HotplugHandler *hotplug_dev,
>                                      DeviceState *dev, Error **errp)
>  {
> @@ -305,6 +343,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)
>  
>  static Property acpi_ged_properties[] = {
>      DEFINE_PROP_UINT32("ged-event", AcpiGedState, ged_event_bitmap, 0),
> +    DEFINE_PROP_UINT32("slp-typs", AcpiGedState, slp_typs_bitmap,
> +                        (1 << ACPI_GED_SLP_TYP_S5)),


I don't see an immediate need for users to tweak this.
Accordingly, prefix this property with "x-" so users know that
if they do, this is unsupported.


>      DEFINE_PROP_END_OF_LIST(),
>  };
>  
> @@ -320,10 +360,11 @@ static const VMStateDescription vmstate_memhp_state = {
>  
>  static const VMStateDescription vmstate_ged_state = {
>      .name = "acpi-ged-state",
> -    .version_id = 1,
> -    .minimum_version_id = 1,
> +    .version_id = 2,
> +    .minimum_version_id = 2,
>      .fields = (const VMStateField[]) {
>          VMSTATE_UINT32(sel, GEDState),
> +        VMSTATE_UINT8(sleep_sts, GEDState),
>          VMSTATE_END_OF_LIST()
>      }
>  };


No, avoid playing with versions please.
Use a conditional section instead, so format does not change
for existing machine types.


> @@ -371,6 +412,18 @@ static const VMStateDescription vmstate_acpi_ged = {
>      }
>  };
>  
> +static void acpi_ged_realize(DeviceState *dev, Error **errp)
> +{
> +    AcpiGedState *s = ACPI_GED(dev);
> +    GEDState *ged_st = &s->ged_state;
> +
> +    if (s->slp_typs_bitmap & (1 << ACPI_GED_SLP_TYP_S3)) {
> +        ged_st->wakeup.notify = acpi_ged_notify_wakeup;
> +        qemu_register_wakeup_notifier(&ged_st->wakeup);
> +        qemu_register_wakeup_support();
> +    }
> +}
> +
>  static void acpi_ged_initfn(Object *obj)
>  {
>      DeviceState *dev = DEVICE(obj);
> @@ -409,6 +462,7 @@ static void acpi_ged_class_init(ObjectClass *class, void *data)
>      AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(class);
>  
>      dc->desc = "ACPI Generic Event Device";
> +    dc->realize = acpi_ged_realize;
>      device_class_set_props(dc, acpi_ged_properties);
>      dc->vmsd = &vmstate_acpi_ged;
>  
> diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
> index ba84ce021477..1ea3cb848679 100644
> --- a/include/hw/acpi/generic_event_device.h
> +++ b/include/hw/acpi/generic_event_device.h
> @@ -80,9 +80,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
>  /* ACPI_GED_REG_RESET value for reset*/
>  #define ACPI_GED_RESET_VALUE       0x42
>  
> -/* ACPI_GED_REG_SLEEP_CTL.SLP_TYP value for S5 (aka poweroff) */
> +/* ACPI_GED_REG_SLEEP_CTL.SLP_EN bit */
> +#define ACPI_GED_SLP_EN            (1 << 5)
> +
> +/* ACPI_GED_REG_SLEEP_CTL.SLP_TYP values */
> +#define ACPI_GED_SLP_TYP_S3        0x03
> +#define ACPI_GED_SLP_TYP_S4        0x04
>  #define ACPI_GED_SLP_TYP_S5        0x05
>  
> +#define ACPI_GED_WAK_STS           (1 << 7)
> +
>  #define GED_DEVICE      "GED"
>  #define AML_GED_EVT_REG "EREG"
>  #define AML_GED_EVT_SEL "ESEL"
> @@ -99,7 +106,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
>  typedef struct GEDState {
>      MemoryRegion evt;
>      MemoryRegion regs;
> +    Notifier     wakeup;
>      uint32_t     sel;
> +    uint8_t      sleep_sts;
>  } GEDState;
>  
>  struct AcpiGedState {
> @@ -108,6 +117,7 @@ struct AcpiGedState {
>      MemoryRegion container_memhp;
>      GEDState ged_state;
>      uint32_t ged_event_bitmap;
> +    uint32_t slp_typs_bitmap;
>      qemu_irq irq;
>      AcpiGhesState ghes_state;
>  };
> 
> -- 
> 2.43.0



  reply	other threads:[~2024-07-01 20:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 17:30 [PATCH 0/3] S3 and S4 sleep for loongarch/virt & microvm Jiaxun Yang
2024-06-13 17:30 ` [PATCH 1/3] acpi/ged: Implement S3 and S4 sleep Jiaxun Yang
2024-07-01 20:19   ` Michael S. Tsirkin [this message]
2024-07-25  8:22   ` Igor Mammedov
2024-07-25  8:30     ` Michael S. Tsirkin
2024-07-25  8:54       ` Igor Mammedov
2024-06-13 17:30 ` [PATCH 2/3] hw/loongarch/virt: Wire up " Jiaxun Yang
2024-07-25  8:26   ` Igor Mammedov
2024-06-13 17:30 ` [PATCH 3/3] hw/i386/microvm: " Jiaxun Yang
2024-06-14  3:32 ` [PATCH 0/3] S3 and S4 sleep for loongarch/virt & microvm maobibo
2024-06-14  4:27   ` Jiaxun Yang
2024-06-14  5:17     ` maobibo
2024-06-14 13:55       ` Jiaxun Yang
2024-06-14 14:03       ` Daniel P. Berrangé
2024-06-15  1:45         ` maobibo
2024-07-25  7:52           ` Igor Mammedov
2024-07-25  8:29 ` Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240701161751-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=gaosong@loongson.cn \
    --cc=imammedo@redhat.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=slp@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.