From patchwork Thu Mar 19 08:01:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11446669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D65B317E6 for ; Thu, 19 Mar 2020 08:02:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB53220658 for ; Thu, 19 Mar 2020 08:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GXI6L1GR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB53220658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEq8U-000377-Mr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Mar 2020 04:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39603) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEq7Q-0001T4-1j for qemu-devel@nongnu.org; Thu, 19 Mar 2020 04:01:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEq7O-0004ix-Jg for qemu-devel@nongnu.org; Thu, 19 Mar 2020 04:01:31 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:23126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEq7O-0004gt-E2 for qemu-devel@nongnu.org; Thu, 19 Mar 2020 04:01:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584604890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTYhOkELmHFCgie3ThSBryZcp/TC9L9pIbajWLjOzNU=; b=GXI6L1GRxmBSWqJLwG6DPBY5C8xZIsm/5Ty6rmwEtyI0gGUCFSjSf/ZGOBz8KqOAXzbqMK j2MeRvsBgNWjHEC8q0oKnSqtsTJ6PQNTLiVimyWuHo0Hem0YKVVk61za8gM/6NDicJf4/R SypjSLDCy1XEieQ+BaT7dJ71zt7LJn8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-GE7tqcOTPsuVSK6D42K-yw-1; Thu, 19 Mar 2020 04:01:28 -0400 X-MC-Unique: GE7tqcOTPsuVSK6D42K-yw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AC65800D54; Thu, 19 Mar 2020 08:01:27 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 665265DA81; Thu, 19 Mar 2020 08:01:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B98C731F2D; Thu, 19 Mar 2020 09:01:17 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 03/13] microvm: add isa-acpi device Date: Thu, 19 Mar 2020 09:01:07 +0100 Message-Id: <20200319080117.7725-4-kraxel@redhat.com> In-Reply-To: <20200319080117.7725-1-kraxel@redhat.com> References: <20200319080117.7725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Sergio Lopez , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini , Igor Mammedov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Minimal ACPI device for PCI-less machines like microvm. Signed-off-by: Gerd Hoffmann --- 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