Message ID | 20200319080117.7725-4-kraxel@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | microvm: add acpi support | expand |
On Thu, 19 Mar 2020 09:01:07 +0100 Gerd Hoffmann <kraxel@redhat.com> wrote: > Minimal ACPI device for PCI-less machines like microvm. it seems that x86 kernel is able to boot on hw-reduced acpi systems (but I haven't really tested any distro kernel, not sure how usable NEMU is) Maybe reusing hw/acpi/generic_event_device.c (which was borrowed for NEMU effort) would be better since guest won't have to initialize not necessary interfaces and QEMU could implement simpler hw impl compared to full ACPI with GPEs, SCIs & co. > > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> > --- > hw/acpi/isa-acpi.c | 114 ++++++++++++++++++++++++++++++++++++++++++ > hw/acpi/Makefile.objs | 1 + > 2 files changed, 115 insertions(+) > create mode 100644 hw/acpi/isa-acpi.c > > diff --git a/hw/acpi/isa-acpi.c b/hw/acpi/isa-acpi.c > new file mode 100644 > index 000000000000..5d7d770a5c0b > --- /dev/null > +++ b/hw/acpi/isa-acpi.c > @@ -0,0 +1,114 @@ > +#include "qemu/osdep.h" > +#include "hw/i386/pc.h" > +#include "hw/acpi/acpi.h" > +#include "sysemu/runstate.h" > + > +typedef struct ISAACPI { > + ISADevice base; > + > + uint32_t io_base; > + uint16_t sci_irq; > + uint32_t gpe_base; > + uint32_t gpe_len; > + > + qemu_irq irq; > + MemoryRegion io; > + ACPIREGS acpi; > + Notifier powerdown_req; > +} ISAACPI; > + > +#define TYPE_ISA_ACPI "isa-acpi" > +#define ISA_ACPI(obj) \ > + OBJECT_CHECK(ISAACPI, (obj), TYPE_ISA_ACPI) > + > +static void isa_acpi_timer(ACPIREGS *acpi) > +{ > + ISAACPI *s = container_of(acpi, ISAACPI, acpi); > + acpi_update_sci(&s->acpi, s->irq); > +} > + > +static void isa_acpi_init(Object *obj) > +{ > + ISAACPI *s = ISA_ACPI(obj); > + > + s->io_base = 0x600; > + s->sci_irq = 9; > + s->gpe_base = 0x680; > + s->gpe_len = 4; > +} > + > +static void isa_acpi_powerdown_req(Notifier *n, void *opaque) > +{ > + ISAACPI *s = container_of(n, ISAACPI, powerdown_req); > + > + acpi_pm1_evt_power_down(&s->acpi); > +} > + > +static void isa_acpi_add_propeties(ISAACPI *s) > +{ > + static const uint8_t zero; > + > + object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD, > + &zero, NULL); > + object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD, > + &zero, NULL); > + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK, > + &s->gpe_base, NULL); > + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN, > + &s->gpe_len, NULL); > + object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT, > + &s->sci_irq, NULL); > + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE, > + &s->io_base, NULL); > +} > + > +static void isa_acpi_realize(DeviceState *dev, Error **errp) > +{ > + ISADevice *isa = ISA_DEVICE(dev); > + ISAACPI *s = ISA_ACPI(dev); > + > + memory_region_init(&s->io, OBJECT(s), "isa-acpi", 64); > + memory_region_set_enabled(&s->io, true); > + isa_register_ioport(isa, &s->io, s->io_base); > + isa_init_irq(isa, &s->irq, s->sci_irq); > + > + acpi_pm_tmr_init(&s->acpi, isa_acpi_timer, &s->io); > + acpi_pm1_evt_init(&s->acpi, isa_acpi_timer, &s->io); > + acpi_pm1_cnt_init(&s->acpi, &s->io, true, true, 0); > + acpi_gpe_init(&s->acpi, 4); > + > + s->powerdown_req.notify = isa_acpi_powerdown_req; > + qemu_register_powerdown_notifier(&s->powerdown_req); > + > + isa_acpi_add_propeties(s); > +} > + > +static void isa_acpi_class_init(ObjectClass *klass, void *data) > +{ > + DeviceClass *dc = DEVICE_CLASS(klass); > + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass); > + > + dc->realize = isa_acpi_realize; > + dc->user_creatable = false; > + dc->hotpluggable = false; > + adevc->madt_cpu = pc_madt_cpu_entry; > +} > + > +static const TypeInfo isa_acpi_info = { > + .name = TYPE_ISA_ACPI, > + .parent = TYPE_ISA_DEVICE, > + .instance_size = sizeof(ISAACPI), > + .instance_init = isa_acpi_init, > + .class_init = isa_acpi_class_init, > + .interfaces = (InterfaceInfo[]) { > + { TYPE_ACPI_DEVICE_IF }, > + { } > + } > +}; > + > +static void register_types(void) > +{ > + type_register_static(&isa_acpi_info); > +} > + > +type_init(register_types) > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs > index 777da07f4d70..aae53c73ebbd 100644 > --- a/hw/acpi/Makefile.objs > +++ b/hw/acpi/Makefile.objs > @@ -14,6 +14,7 @@ common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o > common-obj-y += acpi_interface.o > common-obj-y += bios-linker-loader.o > common-obj-y += aml-build.o utils.o > +common-obj-$(CONFIG_PC) += isa-acpi.o > common-obj-$(CONFIG_ACPI_PCI) += pci.o > common-obj-$(CONFIG_TPM) += tpm.o >
On Thu, Mar 19, 2020 at 02:42:18PM +0100, Igor Mammedov wrote: > On Thu, 19 Mar 2020 09:01:07 +0100 > Gerd Hoffmann <kraxel@redhat.com> wrote: > > > Minimal ACPI device for PCI-less machines like microvm. > it seems that x86 kernel is able to boot on hw-reduced acpi systems > (but I haven't really tested any distro kernel, not sure how usable NEMU is) > > Maybe reusing hw/acpi/generic_event_device.c (which was borrowed > for NEMU effort) would be better since guest won't have to initialize > not necessary interfaces and QEMU could implement simpler hw impl > compared to full ACPI with GPEs, SCIs & co. I see the generic event device has support for powerdown request events, good. But I'm wondering how entering S5 state (aka poweroff) would work then? cheers, Gerd
On Fri, 20 Mar 2020 09:22:58 +0100 Gerd Hoffmann <kraxel@redhat.com> wrote: > On Thu, Mar 19, 2020 at 02:42:18PM +0100, Igor Mammedov wrote: > > On Thu, 19 Mar 2020 09:01:07 +0100 > > Gerd Hoffmann <kraxel@redhat.com> wrote: > > > > > Minimal ACPI device for PCI-less machines like microvm. > > it seems that x86 kernel is able to boot on hw-reduced acpi systems > > (but I haven't really tested any distro kernel, not sure how usable NEMU is) > > > > Maybe reusing hw/acpi/generic_event_device.c (which was borrowed > > for NEMU effort) would be better since guest won't have to initialize > > not necessary interfaces and QEMU could implement simpler hw impl > > compared to full ACPI with GPEs, SCIs & co. > > I see the generic event device has support for powerdown request events, > good. But I'm wondering how entering S5 state (aka poweroff) would > work then? Relevant parts from spec: ACPI6.1: 16.1.7 Transitioning from the Working to the Soft Off State ... 4. or writes the HW-reduced ACPI Sleep Type value for S5 and the SLP_EN bit to the Sleep Control Register. 4.8.3.7 Sleep Control and Status Registers in kernel handled by acpi_hw_extended_sleep() From QEMU: build_fadt_rev5() build_fadt() ... /* SLEEP_CONTROL_REG */ build_append_gas(tbl, AML_AS_SYSTEM_MEMORY, 0 , 0, 0, 0); /* SLEEP_STATUS_REG */ build_append_gas(tbl, AML_AS_SYSTEM_MEMORY, 0 , 0, 0, 0); ... this is what board should implement (we cloud add an optional MMIO register to GED to hanlde shutdown on QEMU side) (ARM doesn't use it as it's using arch specific, PSCI method to shutdown machine), I'd add relevant fields to AcpiFadtData, fill it in build_fadt_rev5() and use them in build_fadt() virt_powerdown_req() acpi_send_event(s->acpi_dev, ACPI_POWER_DOWN_STATUS) triggers in guest AML generated by: acpi_dsdt_add_power_button() build_ged_aml() ...ACPI_POWER_BUTTON_DEVICE... -> tells OSPM to do 16.1.7 using 4.8.3.7 > > cheers, > Gerd > >
diff --git a/hw/acpi/isa-acpi.c b/hw/acpi/isa-acpi.c new file mode 100644 index 000000000000..5d7d770a5c0b --- /dev/null +++ b/hw/acpi/isa-acpi.c @@ -0,0 +1,114 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +#include "hw/acpi/acpi.h" +#include "sysemu/runstate.h" + +typedef struct ISAACPI { + ISADevice base; + + uint32_t io_base; + uint16_t sci_irq; + uint32_t gpe_base; + uint32_t gpe_len; + + qemu_irq irq; + MemoryRegion io; + ACPIREGS acpi; + Notifier powerdown_req; +} ISAACPI; + +#define TYPE_ISA_ACPI "isa-acpi" +#define ISA_ACPI(obj) \ + OBJECT_CHECK(ISAACPI, (obj), TYPE_ISA_ACPI) + +static void isa_acpi_timer(ACPIREGS *acpi) +{ + ISAACPI *s = container_of(acpi, ISAACPI, acpi); + acpi_update_sci(&s->acpi, s->irq); +} + +static void isa_acpi_init(Object *obj) +{ + ISAACPI *s = ISA_ACPI(obj); + + s->io_base = 0x600; + s->sci_irq = 9; + s->gpe_base = 0x680; + s->gpe_len = 4; +} + +static void isa_acpi_powerdown_req(Notifier *n, void *opaque) +{ + ISAACPI *s = container_of(n, ISAACPI, powerdown_req); + + acpi_pm1_evt_power_down(&s->acpi); +} + +static void isa_acpi_add_propeties(ISAACPI *s) +{ + static const uint8_t zero; + + object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_ENABLE_CMD, + &zero, NULL); + object_property_add_uint8_ptr(OBJECT(s), ACPI_PM_PROP_ACPI_DISABLE_CMD, + &zero, NULL); + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK, + &s->gpe_base, NULL); + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_GPE0_BLK_LEN, + &s->gpe_len, NULL); + object_property_add_uint16_ptr(OBJECT(s), ACPI_PM_PROP_SCI_INT, + &s->sci_irq, NULL); + object_property_add_uint32_ptr(OBJECT(s), ACPI_PM_PROP_PM_IO_BASE, + &s->io_base, NULL); +} + +static void isa_acpi_realize(DeviceState *dev, Error **errp) +{ + ISADevice *isa = ISA_DEVICE(dev); + ISAACPI *s = ISA_ACPI(dev); + + memory_region_init(&s->io, OBJECT(s), "isa-acpi", 64); + memory_region_set_enabled(&s->io, true); + isa_register_ioport(isa, &s->io, s->io_base); + isa_init_irq(isa, &s->irq, s->sci_irq); + + acpi_pm_tmr_init(&s->acpi, isa_acpi_timer, &s->io); + acpi_pm1_evt_init(&s->acpi, isa_acpi_timer, &s->io); + acpi_pm1_cnt_init(&s->acpi, &s->io, true, true, 0); + acpi_gpe_init(&s->acpi, 4); + + s->powerdown_req.notify = isa_acpi_powerdown_req; + qemu_register_powerdown_notifier(&s->powerdown_req); + + isa_acpi_add_propeties(s); +} + +static void isa_acpi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass); + + dc->realize = isa_acpi_realize; + dc->user_creatable = false; + dc->hotpluggable = false; + adevc->madt_cpu = pc_madt_cpu_entry; +} + +static const TypeInfo isa_acpi_info = { + .name = TYPE_ISA_ACPI, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(ISAACPI), + .instance_init = isa_acpi_init, + .class_init = isa_acpi_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_ACPI_DEVICE_IF }, + { } + } +}; + +static void register_types(void) +{ + type_register_static(&isa_acpi_info); +} + +type_init(register_types) diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 777da07f4d70..aae53c73ebbd 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -14,6 +14,7 @@ common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o common-obj-y += acpi_interface.o common-obj-y += bios-linker-loader.o common-obj-y += aml-build.o utils.o +common-obj-$(CONFIG_PC) += isa-acpi.o common-obj-$(CONFIG_ACPI_PCI) += pci.o common-obj-$(CONFIG_TPM) += tpm.o
Minimal ACPI device for PCI-less machines like microvm. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/acpi/isa-acpi.c | 114 ++++++++++++++++++++++++++++++++++++++++++ hw/acpi/Makefile.objs | 1 + 2 files changed, 115 insertions(+) create mode 100644 hw/acpi/isa-acpi.c