From patchwork Thu Jan 14 14:50:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 362855 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp567414jap; Thu, 14 Jan 2021 06:52:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3NAKAq+QMRbUrAU7pUK1UmIE7+dZvU0MjAeNd+VxOuh1+uMhiLVeArvtNiZgqpfkXN+5+ X-Received: by 2002:a25:4588:: with SMTP id s130mr3842061yba.281.1610635974044; Thu, 14 Jan 2021 06:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610635974; cv=none; d=google.com; s=arc-20160816; b=nLCGQFpmkTVv7cdt5NZbaJvbxPB1rhQMt/6C+cyCcok8pJ+55nv9ynV8g31qKOnUzF fvDK9MrXTm6nzePaMchwmcjFziig3dPtwsJNuZ5jrDKUrmvu9HHNQ3Nmk1q8xLj67tV4 3+9S1RJY2jEn0NnmjxbgSRd8MSvL8gJsI8/ffdR7P7DdfgyCqdO5A3PcxYuP54vNPRMZ og401qIVf5ietpFMHrb6A+l13h078feLKFch45s8YLx14nAd0NK06v1wF3dZMCcKkxUl Pk7474zH6iZrgkf54xtXA7F6/TXT5fEQapvkkIonk/RL6YftXGU+5GyRVLizZsSXAj9W 1Wnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=GLJ1M8gnJdgfUFe1l9HibzCxyIIEXe/s/L5DY+OCXTc=; b=B5ZpwcyKw+3i66CC5JmZKOdPHfvmbvR4/8zAtuIAv1R7zOi2R36TPwlbOEKrTR1vVI AzIlDqU3gqnqm9DTEpBCnPIXHpDexZaAgLzpQnNwkHJdLBba+fQMwoAd/mhbK0ocd0xU YyuJVKP9SnLh/CTu/2IT5gKOTMAadtTu/WCTZrXwqa+2HCwJNCZbC5qgb2CPsnbhnoMF xZxIP5wvM4lBoqgButKOe7NZuLyArw0EpB9aPhhIGl6XO3+72x/lDD3wzpioT/0F/wso nKDfbx03iBYeCLRC0TpMM65adPCdWpWclSKOUlHl++cqUIvieOku+F9RxZDqlEsdl6NF bGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yccVeNTk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t16si6287900ybl.135.2021.01.14.06.52.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jan 2021 06:52:54 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yccVeNTk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l03zZ-0003J2-Im for patch@linaro.org; Thu, 14 Jan 2021 09:52:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l03xT-0008HX-41 for qemu-devel@nongnu.org; Thu, 14 Jan 2021 09:50:43 -0500 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]:37119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l03xP-0003xp-Fy for qemu-devel@nongnu.org; Thu, 14 Jan 2021 09:50:42 -0500 Received: by mail-lf1-x135.google.com with SMTP id o17so8404576lfg.4 for ; Thu, 14 Jan 2021 06:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GLJ1M8gnJdgfUFe1l9HibzCxyIIEXe/s/L5DY+OCXTc=; b=yccVeNTkX7JqO7D2fwGTGVFNEGanxgpg12WMFY3+1xzD+iVzhSVASjIOQ1eAqoS0k1 WVwmrgVuQR1ZcX5BC21tfcN3Yzi2NBPqqppcvr4vURlmJh+7akNe/cCNxGHwiHIBK3bA WXS+dldLB4z+Ps63gSgR5Xpj1K+BPVG5jlrZIUuxXTxPwVnk6VutwzL0I0OxI8hzN1Yn /s8pILaPRJB+CCZVMCucfy7dKSpEYe+lo7Gi9CSj0CXnD2qPNvicC835UUJDNl4HHij+ uwVBowAiDAkIgkHu+bllk1oNr98eWJkhaNgBUAjHgoyu5VyZP33pX4hsfwmviYk0KvkN XBGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GLJ1M8gnJdgfUFe1l9HibzCxyIIEXe/s/L5DY+OCXTc=; b=FbN3Hv+c67db+g9ninXQJg3Kjg4zJhlfOw9iFYjyxrm7YxjBy//kXumL3bm31Q0soB BIcYVUnHeJBzqShosdtgmjLZieIFGy6KZxcJVG6I3FzHJ8Ro5LIOpyGxTpey5cfJA1J5 MZoVg9Snzm57sI1XAuK+Q2LbUdIVIXOcM20eLn4+figV6CWxTLTN7Cly9+u7A11CO6zo BcznQFUACsuUYLfZbWjBD0HPkSC/ti2CI47LwNuF+jNYirl+fJnXXcRc2GxYbi7sX0EP h7YjGRgMOCEsfBDjulYpJGE8QA4tswbLQoRgSb+C6ux1I84BKed7hvEyf9bF6qQ+73kX n+TA== X-Gm-Message-State: AOAM530GgJ3LtYc0TQJTGCo9Bvgxstxf2EDpMFgUIJlJdzd98v/kGpfN dlakkvZwlS9S9WMswqssKtPnEw== X-Received: by 2002:a19:6a18:: with SMTP id u24mr3514564lfu.111.1610635837959; Thu, 14 Jan 2021 06:50:37 -0800 (PST) Received: from localhost.localdomain ([2.92.195.184]) by smtp.gmail.com with ESMTPSA id p5sm567229lfj.295.2021.01.14.06.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 06:50:37 -0800 (PST) From: Maxim Uvarov To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCHv6 2/3] arm-virt: add secure pl061 for reset/power down Date: Thu, 14 Jan 2021 17:50:31 +0300 Message-Id: <20210114145032.8457-3-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210114145032.8457-1-maxim.uvarov@linaro.org> References: <20210114145032.8457-1-maxim.uvarov@linaro.org> Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=maxim.uvarov@linaro.org; helo=mail-lf1-x135.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: peter.maydell@linaro.org, drjones@redhat.com, Maxim Uvarov , Jose.Marinho@arm.com, f4bug@amsat.org, tf-a@lists.trustedfirmware.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add secure pl061 for reset/power down machine from the secure world (Arm Trusted Firmware). Connect it with gpio-pwr driver. Signed-off-by: Maxim Uvarov --- hw/arm/Kconfig | 1 + hw/arm/virt.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 37 insertions(+) -- 2.17.1 diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 0a242e4c5d..13cc42dcc8 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -17,6 +17,7 @@ config ARM_VIRT select PL011 # UART select PL031 # RTC select PL061 # GPIO + select GPIO_PWR select PLATFORM_BUS select SMBIOS select VIRTIO_MMIO diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 96985917d3..6f3ec15985 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -153,6 +153,7 @@ static const MemMapEntry base_memmap[] = { [VIRT_ACPI_GED] = { 0x09080000, ACPI_GED_EVT_SEL_LEN }, [VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN}, [VIRT_PVTIME] = { 0x090a0000, 0x00010000 }, + [VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 }, @@ -864,6 +865,32 @@ static void create_gpio(const VirtMachineState *vms) g_free(nodename); } +#define ATF_GPIO_POWEROFF 3 +#define ATF_GPIO_REBOOT 4 + +static void create_gpio_secure(const VirtMachineState *vms, MemoryRegion *mem) +{ + DeviceState *gpio_pwr_dev; + SysBusDevice *s; + hwaddr base = vms->memmap[VIRT_SECURE_GPIO].base; + DeviceState *pl061_dev; + + /* Secure pl061 */ + pl061_dev = qdev_new("pl061"); + s = SYS_BUS_DEVICE(pl061_dev); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0)); + + /* gpio-pwr */ + gpio_pwr_dev = sysbus_create_simple("gpio-pwr", -1, NULL); + + /* connect secure pl061 to gpio-pwr */ + qdev_connect_gpio_out(pl061_dev, ATF_GPIO_POWEROFF, + qdev_get_gpio_in_named(gpio_pwr_dev, "reset", 0)); + qdev_connect_gpio_out(pl061_dev, ATF_GPIO_REBOOT, + qdev_get_gpio_in_named(gpio_pwr_dev, "shutdown", 0)); +} + static void create_virtio_devices(const VirtMachineState *vms) { int i; @@ -1993,6 +2020,10 @@ static void machvirt_init(MachineState *machine) create_gpio(vms); } + if (vms->secure && !vmc->no_secure_gpio) { + create_gpio_secure(vms, secure_sysmem); + } + /* connect powerdown request */ vms->powerdown_notifier.notify = virt_powerdown_req; qemu_register_powerdown_notifier(&vms->powerdown_notifier); @@ -2608,8 +2639,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(6, 0) static void virt_machine_5_2_options(MachineClass *mc) { + VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_6_0_options(mc); compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len); + vmc->no_secure_gpio = true; } DEFINE_VIRT_MACHINE(5, 2) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index abf54fab49..6f6c85ffcf 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -81,6 +81,7 @@ enum { VIRT_GPIO, VIRT_SECURE_UART, VIRT_SECURE_MEM, + VIRT_SECURE_GPIO, VIRT_PCDIMM_ACPI, VIRT_ACPI_GED, VIRT_NVDIMM_ACPI, @@ -127,6 +128,7 @@ struct VirtMachineClass { bool kvm_no_adjvtime; bool no_kvm_steal_time; bool acpi_expose_flash; + bool no_secure_gpio; }; struct VirtMachineState {