Message ID | 20190716153816.17676-9-shameerali.kolothum.thodi@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ARM virt: ACPI memory hotplug support | expand |
On Tue, 16 Jul 2019 16:38:14 +0100 Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> wrote: > This adds support to use GED for system power down event. [...] > @@ -232,6 +238,13 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) > acpi_ged_event(s, sel); > } > > +static void acpi_ged_pm_powerdown_req(Notifier *n, void *opaque) > +{ > + AcpiGedState *s = container_of(n, AcpiGedState, powerdown_notifier); > + > + acpi_ged_event(s, ACPI_GED_PWR_DOWN_EVT); > +} > + > static void acpi_ged_device_realize(DeviceState *dev, Error **errp) > { > AcpiGedState *s = ACPI_GED(dev); > @@ -243,6 +256,9 @@ static void acpi_ged_device_realize(DeviceState *dev, Error **errp) > } > > acpi_ged_init(get_system_memory(), dev, &s->ged_state); > + > + s->powerdown_notifier.notify = acpi_ged_pm_powerdown_req; one more thing: I'd reuse virt_powerdown_req() instead. pass it machine pointer and then from notifier you'd be able to get to acpi_dev > + qemu_register_powerdown_notifier(&s->powerdown_notifier); > } > > static Property acpi_ged_properties[] = { > diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h > index f69d084c89..9e63b72cb9 100644 > --- a/include/hw/acpi/generic_event_device.h > +++ b/include/hw/acpi/generic_event_device.h > @@ -61,6 +61,8 @@ > > #include "hw/acpi/memory_hotplug.h" > > +#define ACPI_POWER_BUTTON_DEVICE "PWRB" > + > #define TYPE_ACPI_GED "acpi-ged" > #define ACPI_GED(obj) \ > OBJECT_CHECK(AcpiGedState, (obj), TYPE_ACPI_GED) > @@ -79,6 +81,7 @@ > * through GED. > */ > #define ACPI_GED_MEM_HOTPLUG_EVT 0x1 > +#define ACPI_GED_PWR_DOWN_EVT 0x2 > > typedef struct GEDState { > MemoryRegion io; > @@ -88,6 +91,7 @@ typedef struct GEDState { > > typedef struct AcpiGedState { > DeviceClass parent_obj; > + Notifier powerdown_notifier; > MemHotplugState memhp_state; > hwaddr memhp_base; > hwaddr ged_base;
diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c index 2a83d68e82..2bd786b7ab 100644 --- a/hw/acpi/generic_event_device.c +++ b/hw/acpi/generic_event_device.c @@ -19,6 +19,7 @@ static const uint32_t ged_supported_events[] = { ACPI_GED_MEM_HOTPLUG_EVT, + ACPI_GED_PWR_DOWN_EVT, }; /* @@ -103,6 +104,11 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev, aml_append(if_ctx, aml_call0(MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN_METHOD)); break; + case ACPI_GED_PWR_DOWN_EVT: + aml_append(if_ctx, + aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE), + aml_int(0x80))); + break; default: /* * Please make sure all the events in ged_supported_events[] @@ -232,6 +238,13 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) acpi_ged_event(s, sel); } +static void acpi_ged_pm_powerdown_req(Notifier *n, void *opaque) +{ + AcpiGedState *s = container_of(n, AcpiGedState, powerdown_notifier); + + acpi_ged_event(s, ACPI_GED_PWR_DOWN_EVT); +} + static void acpi_ged_device_realize(DeviceState *dev, Error **errp) { AcpiGedState *s = ACPI_GED(dev); @@ -243,6 +256,9 @@ static void acpi_ged_device_realize(DeviceState *dev, Error **errp) } acpi_ged_init(get_system_memory(), dev, &s->ged_state); + + s->powerdown_notifier.notify = acpi_ged_pm_powerdown_req; + qemu_register_powerdown_notifier(&s->powerdown_notifier); } static Property acpi_ged_properties[] = { diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h index f69d084c89..9e63b72cb9 100644 --- a/include/hw/acpi/generic_event_device.h +++ b/include/hw/acpi/generic_event_device.h @@ -61,6 +61,8 @@ #include "hw/acpi/memory_hotplug.h" +#define ACPI_POWER_BUTTON_DEVICE "PWRB" + #define TYPE_ACPI_GED "acpi-ged" #define ACPI_GED(obj) \ OBJECT_CHECK(AcpiGedState, (obj), TYPE_ACPI_GED) @@ -79,6 +81,7 @@ * through GED. */ #define ACPI_GED_MEM_HOTPLUG_EVT 0x1 +#define ACPI_GED_PWR_DOWN_EVT 0x2 typedef struct GEDState { MemoryRegion io; @@ -88,6 +91,7 @@ typedef struct GEDState { typedef struct AcpiGedState { DeviceClass parent_obj; + Notifier powerdown_notifier; MemHotplugState memhp_state; hwaddr memhp_base; hwaddr ged_base;