From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
Sergio Lopez <slp@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: [PATCH v2 08/13] acpi: generic event device for x86
Date: Tue, 5 May 2020 15:43:00 +0200 [thread overview]
Message-ID: <20200505134305.22666-9-kraxel@redhat.com> (raw)
In-Reply-To: <20200505134305.22666-1-kraxel@redhat.com>
Uses TYPE_ACPI_GED as QOM parent for code reuse.
Add registers for sleep states and reset.
Add powerdown notifier for power button events.
Set AcpiDeviceIfClass->madt_cpu.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
include/hw/acpi/generic_event_device.h | 10 +++
hw/i386/generic_event_device_x86.c | 114 +++++++++++++++++++++++++
hw/i386/Makefile.objs | 1 +
3 files changed, 125 insertions(+)
create mode 100644 hw/i386/generic_event_device_x86.c
diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
index 9eb86ca4fd94..16d1f2b3cd30 100644
--- a/include/hw/acpi/generic_event_device.h
+++ b/include/hw/acpi/generic_event_device.h
@@ -68,9 +68,19 @@
#define ACPI_GED(obj) \
OBJECT_CHECK(AcpiGedState, (obj), TYPE_ACPI_GED)
+#define TYPE_ACPI_GED_X86 "acpi-ged-x86"
+#define ACPI_GED_X86(obj) \
+ OBJECT_CHECK(AcpiGedX86State, (obj), TYPE_ACPI_GED_X86)
+
#define ACPI_GED_EVT_SEL_OFFSET 0x0
#define ACPI_GED_EVT_SEL_LEN 0x4
+#define ACPI_GED_X86_REG_SLEEP_CTL 0x00
+#define ACPI_GED_X86_REG_SLEEP_STS 0x01
+#define ACPI_GED_X86_REG_RESET 0x02
+#define ACPI_GED_X86_RESET_VALUE 0x42
+#define ACPI_GED_X86_REG_COUNT 0x03
+
#define GED_DEVICE "GED"
#define AML_GED_EVT_REG "EREG"
#define AML_GED_EVT_SEL "ESEL"
diff --git a/hw/i386/generic_event_device_x86.c b/hw/i386/generic_event_device_x86.c
new file mode 100644
index 000000000000..8ae4a63084f3
--- /dev/null
+++ b/hw/i386/generic_event_device_x86.c
@@ -0,0 +1,114 @@
+/*
+ * x86 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 "qapi/error.h"
+#include "exec/address-spaces.h"
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/generic_event_device.h"
+#include "hw/i386/pc.h"
+#include "hw/irq.h"
+#include "hw/mem/pc-dimm.h"
+#include "hw/qdev-properties.h"
+#include "migration/vmstate.h"
+#include "qemu/error-report.h"
+#include "sysemu/runstate.h"
+
+typedef struct AcpiGedX86State {
+ struct AcpiGedState parent_obj;
+ MemoryRegion regs;
+ Notifier powerdown_req;
+} AcpiGedX86State;
+
+static uint64_t acpi_ged_x86_regs_read(void *opaque, hwaddr addr, unsigned size)
+{
+ return 0;
+}
+
+static void acpi_ged_x86_regs_write(void *opaque, hwaddr addr, uint64_t data,
+ unsigned int size)
+{
+ bool slp_en;
+ int slp_typ;
+
+ switch (addr) {
+ case ACPI_GED_X86_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);
+ }
+ return;
+ case ACPI_GED_X86_REG_SLEEP_STS:
+ return;
+ case ACPI_GED_X86_REG_RESET:
+ if (data == ACPI_GED_X86_RESET_VALUE) {
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+ }
+ return;
+ }
+}
+
+static const MemoryRegionOps acpi_ged_x86_regs_ops = {
+ .read = acpi_ged_x86_regs_read,
+ .write = acpi_ged_x86_regs_write,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 1,
+ },
+};
+
+static void acpi_ged_x86_powerdown_req(Notifier *n, void *opaque)
+{
+ AcpiGedX86State *s = container_of(n, AcpiGedX86State, powerdown_req);
+ AcpiDeviceIf *adev = ACPI_DEVICE_IF(s);
+ AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(OBJECT(s));
+
+ adevc->send_event(adev, ACPI_POWER_DOWN_STATUS);
+}
+
+static void acpi_ged_x86_initfn(Object *obj)
+{
+ AcpiGedX86State *s = ACPI_GED_X86(obj);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+
+ memory_region_init_io(&s->regs, obj, &acpi_ged_x86_regs_ops,
+ obj, "acpi-regs", ACPI_GED_X86_REG_COUNT);
+ sysbus_init_mmio(sbd, &s->regs);
+
+ s->powerdown_req.notify = acpi_ged_x86_powerdown_req;
+ qemu_register_powerdown_notifier(&s->powerdown_req);
+}
+
+static void acpi_ged_x86_class_init(ObjectClass *class, void *data)
+{
+ AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(class);
+
+ adevc->madt_cpu = pc_madt_cpu_entry;
+}
+
+static const TypeInfo acpi_ged_x86_info = {
+ .name = TYPE_ACPI_GED_X86,
+ .parent = TYPE_ACPI_GED,
+ .instance_size = sizeof(AcpiGedX86State),
+ .instance_init = acpi_ged_x86_initfn,
+ .class_init = acpi_ged_x86_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { TYPE_ACPI_DEVICE_IF },
+ { }
+ }
+};
+
+static void acpi_ged_x86_register_types(void)
+{
+ type_register_static(&acpi_ged_x86_info);
+}
+
+type_init(acpi_ged_x86_register_types)
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 6abc74551a72..622739305882 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -17,4 +17,5 @@ obj-$(CONFIG_PC) += port92.o
obj-y += kvmvapic.o
obj-$(CONFIG_ACPI) += acpi-common.o
+obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device_x86.o
obj-$(CONFIG_PC) += acpi-build.o
--
2.18.4
next prev parent reply other threads:[~2020-05-05 13:50 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 13:42 [PATCH v2 00/13] microvm: add acpi support Gerd Hoffmann
2020-05-05 13:42 ` [PATCH v2 01/13] acpi: make build_madt() more generic Gerd Hoffmann
2020-05-05 13:54 ` Igor Mammedov
2020-05-05 13:42 ` [PATCH v2 02/13] acpi: create acpi-common.c and move madt code Gerd Hoffmann
2020-05-05 14:00 ` Igor Mammedov
2020-05-05 13:42 ` [PATCH v2 03/13] acpi: madt: skip pci override on pci-less systems (microvm) Gerd Hoffmann
2020-05-05 14:10 ` Igor Mammedov
2020-05-05 14:17 ` Philippe Mathieu-Daudé
2020-05-05 13:42 ` [PATCH v2 04/13] acpi: move acpi_build_facs to acpi-common.c Gerd Hoffmann
2020-05-05 13:49 ` Philippe Mathieu-Daudé
2020-05-05 14:16 ` Igor Mammedov
2020-05-05 13:42 ` [PATCH v2 05/13] acpi: move acpi_init_common_fadt_data " Gerd Hoffmann
2020-05-05 14:25 ` Igor Mammedov
2020-05-06 10:03 ` Gerd Hoffmann
2020-05-05 13:42 ` [PATCH v2 06/13] acpi: move acpi_align_size to acpi-common.h Gerd Hoffmann
2020-05-05 13:53 ` Philippe Mathieu-Daudé
2020-05-05 14:30 ` Igor Mammedov
2020-05-05 13:42 ` [PATCH v2 07/13] acpi: fadt: add hw-reduced sleep register support Gerd Hoffmann
2020-05-05 14:35 ` Igor Mammedov
2020-05-05 13:43 ` Gerd Hoffmann [this message]
2020-05-05 15:03 ` [PATCH v2 08/13] acpi: generic event device for x86 Igor Mammedov
2020-05-06 10:31 ` Gerd Hoffmann
2020-05-06 12:41 ` Igor Mammedov
2020-05-07 14:03 ` Gerd Hoffmann
2020-05-05 13:43 ` [PATCH v2 09/13] microvm: add minimal acpi support Gerd Hoffmann
2020-05-05 15:20 ` Igor Mammedov
2020-05-06 10:35 ` Gerd Hoffmann
2020-05-06 14:14 ` Igor Mammedov
2020-05-07 13:39 ` Gerd Hoffmann
2020-05-05 13:43 ` [PATCH v2 10/13] microvm: disable virtio-mmio cmdline hack Gerd Hoffmann
2020-05-05 15:22 ` Igor Mammedov
2020-05-05 13:43 ` [PATCH v2 11/13] microvm: add acpi_dsdt_add_virtio() for x86 Gerd Hoffmann
2020-05-06 7:27 ` Sergio Lopez
2020-05-05 13:43 ` [PATCH v2 12/13] microvm: make virtio irq base runtime configurable Gerd Hoffmann
2020-05-06 7:28 ` Sergio Lopez
2020-05-05 13:43 ` [PATCH v2 13/13] microvm/acpi: use GSI 16-23 for virtio Gerd Hoffmann
2020-05-06 7:28 ` Sergio Lopez
2020-05-05 14:04 ` [PATCH v2 00/13] microvm: add acpi support Michael S. Tsirkin
2020-05-05 14:16 ` Philippe Mathieu-Daudé
2020-05-06 7:25 ` Sergio Lopez
2020-05-06 11:46 ` Gerd Hoffmann
2020-05-06 11:50 ` Michael S. Tsirkin
2020-05-07 13:57 ` Gerd Hoffmann
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=20200505134305.22666-9-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).