[PATCH 05/13] acpi: Send the GPE event of sleep for x86

Annie Li posted 13 patches 5 months, 3 weeks ago
Maintainers: "Dr. David Alan Gilbert" <dave@treblig.org>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Sergio Lopez <slp@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH 05/13] acpi: Send the GPE event of sleep for x86
Posted by Annie Li 5 months, 3 weeks ago
The GPE event is triggered to notify x86 guest to sleep
itself. The function acpi_send_sleep_event will also
trigger GED events on HW-reduced systems where ACPI GED
sleep event is supported.

Signed-off-by: Annie Li <annie.li@oracle.com>
---
 hw/acpi/core.c                       | 12 ++++++++++++
 include/hw/acpi/acpi.h               |  1 +
 include/hw/acpi/acpi_dev_interface.h |  1 +
 3 files changed, 14 insertions(+)

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 58f8964e13..dcabe881bf 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -359,6 +359,18 @@ int acpi_get_slic_oem(AcpiSlicOem *oem)
     return -1;
 }
 
+void acpi_send_sleep_event(void)
+{
+    bool ambiguous;
+    Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambiguous);
+
+    assert(!ambiguous);
+    if (obj) {
+        /* Send sleep event */
+        acpi_send_event(DEVICE(obj), ACPI_SLEEP_STATUS);
+    }
+}
+
 static void acpi_notify_wakeup(Notifier *notifier, void *data)
 {
     ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
index d1a4fa2af8..64d3ff78ed 100644
--- a/include/hw/acpi/acpi.h
+++ b/include/hw/acpi/acpi.h
@@ -184,6 +184,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
 
 void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
                          AcpiEventStatusBits status);
+void acpi_send_sleep_event(void);
 
 void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
 
diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
index 68d9d15f50..1cb050cd3a 100644
--- a/include/hw/acpi/acpi_dev_interface.h
+++ b/include/hw/acpi/acpi_dev_interface.h
@@ -13,6 +13,7 @@ typedef enum {
     ACPI_NVDIMM_HOTPLUG_STATUS = 16,
     ACPI_VMGENID_CHANGE_STATUS = 32,
     ACPI_POWER_DOWN_STATUS = 64,
+    ACPI_SLEEP_STATUS = 128,
 } AcpiEventStatusBits;
 
 #define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
-- 
2.43.5
Re: [PATCH 05/13] acpi: Send the GPE event of sleep for x86
Posted by Igor Mammedov 5 months, 2 weeks ago
On Wed, 28 May 2025 12:39:52 -0400
Annie Li <annie.li@oracle.com> wrote:

> The GPE event is triggered to notify x86 guest to sleep
> itself. The function acpi_send_sleep_event will also
> trigger GED events on HW-reduced systems where ACPI GED
> sleep event is supported.
> 
> Signed-off-by: Annie Li <annie.li@oracle.com>
> ---
>  hw/acpi/core.c                       | 12 ++++++++++++
>  include/hw/acpi/acpi.h               |  1 +
>  include/hw/acpi/acpi_dev_interface.h |  1 +
>  3 files changed, 14 insertions(+)
> 
> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> index 58f8964e13..dcabe881bf 100644
> --- a/hw/acpi/core.c
> +++ b/hw/acpi/core.c
> @@ -359,6 +359,18 @@ int acpi_get_slic_oem(AcpiSlicOem *oem)
>      return -1;
>  }
>  
> +void acpi_send_sleep_event(void)
> +{
> +    bool ambiguous;
> +    Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambiguous);
> +
> +    assert(!ambiguous);
> +    if (obj) {

Can it ever be NULL?
If not drop condition.

> +        /* Send sleep event */
> +        acpi_send_event(DEVICE(obj), ACPI_SLEEP_STATUS);
> +    }
> +}
> +
>  static void acpi_notify_wakeup(Notifier *notifier, void *data)
>  {
>      ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> index d1a4fa2af8..64d3ff78ed 100644
> --- a/include/hw/acpi/acpi.h
> +++ b/include/hw/acpi/acpi.h
> @@ -184,6 +184,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
>  
>  void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
>                           AcpiEventStatusBits status);
> +void acpi_send_sleep_event(void);
>  
>  void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
>  
> diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
> index 68d9d15f50..1cb050cd3a 100644
> --- a/include/hw/acpi/acpi_dev_interface.h
> +++ b/include/hw/acpi/acpi_dev_interface.h
> @@ -13,6 +13,7 @@ typedef enum {
>      ACPI_NVDIMM_HOTPLUG_STATUS = 16,
>      ACPI_VMGENID_CHANGE_STATUS = 32,
>      ACPI_POWER_DOWN_STATUS = 64,
> +    ACPI_SLEEP_STATUS = 128,
>  } AcpiEventStatusBits;
>  
>  #define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
Re: [PATCH 05/13] acpi: Send the GPE event of sleep for x86
Posted by Annie Li 5 months, 2 weeks ago
Hi Igor,

On 6/3/2025 8:34 AM, Igor Mammedov wrote:
> On Wed, 28 May 2025 12:39:52 -0400
> Annie Li <annie.li@oracle.com> wrote:
>
>> The GPE event is triggered to notify x86 guest to sleep
>> itself. The function acpi_send_sleep_event will also
>> trigger GED events on HW-reduced systems where ACPI GED
>> sleep event is supported.
>>
>> Signed-off-by: Annie Li <annie.li@oracle.com>
>> ---
>>   hw/acpi/core.c                       | 12 ++++++++++++
>>   include/hw/acpi/acpi.h               |  1 +
>>   include/hw/acpi/acpi_dev_interface.h |  1 +
>>   3 files changed, 14 insertions(+)
>>
>> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
>> index 58f8964e13..dcabe881bf 100644
>> --- a/hw/acpi/core.c
>> +++ b/hw/acpi/core.c
>> @@ -359,6 +359,18 @@ int acpi_get_slic_oem(AcpiSlicOem *oem)
>>       return -1;
>>   }
>>   
>> +void acpi_send_sleep_event(void)
>> +{
>> +    bool ambiguous;
>> +    Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambiguous);
>> +
>> +    assert(!ambiguous);
>> +    if (obj) {
> Can it ever be NULL?
> If not drop condition.

assert happens earlier if it is NULL.

will drop it.

Thanks

Annie

>
>> +        /* Send sleep event */
>> +        acpi_send_event(DEVICE(obj), ACPI_SLEEP_STATUS);
>> +    }
>> +}
>> +
>>   static void acpi_notify_wakeup(Notifier *notifier, void *data)
>>   {
>>       ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
>> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
>> index d1a4fa2af8..64d3ff78ed 100644
>> --- a/include/hw/acpi/acpi.h
>> +++ b/include/hw/acpi/acpi.h
>> @@ -184,6 +184,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
>>   
>>   void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
>>                            AcpiEventStatusBits status);
>> +void acpi_send_sleep_event(void);
>>   
>>   void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
>>   
>> diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
>> index 68d9d15f50..1cb050cd3a 100644
>> --- a/include/hw/acpi/acpi_dev_interface.h
>> +++ b/include/hw/acpi/acpi_dev_interface.h
>> @@ -13,6 +13,7 @@ typedef enum {
>>       ACPI_NVDIMM_HOTPLUG_STATUS = 16,
>>       ACPI_VMGENID_CHANGE_STATUS = 32,
>>       ACPI_POWER_DOWN_STATUS = 64,
>> +    ACPI_SLEEP_STATUS = 128,
>>   } AcpiEventStatusBits;
>>   
>>   #define TYPE_ACPI_DEVICE_IF "acpi-device-interface"