From patchwork Thu Nov 7 21:24:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11233787 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 46A9E1599 for ; Thu, 7 Nov 2019 21:24:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 248AF222C5 for ; Thu, 7 Nov 2019 21:24:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LULKUd20" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 248AF222C5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rb3GQa2Qnirp3ZjIeHvp11mqi6QICqyG+tq0qQhRzNo=; b=LULKUd20r1NN39 sZ52d6U30yHIUxTkvsgGkJQqXdxdtHPl9SiiiW29to9oRf1blFINk63Rg7wmo5bM4n+XesLd71A1w PYJoeKYZCLYZk9YS2CttwYaCbA1GXwsNMtqgtOZL8ww7axTaiMsFb1PQlbCleCr7mR1u9awa9hg2P wsAHNFmieMYPVTwmX8YYk7hVg98VOK/sLiOxiUvT3GYFNOZx3bD5V2/LdHsNph9IxFixJaln+wkyk FZdtiTeOl1DdwLC46rIB/gG7lV4ayHYJTAYTcSBzPkCwINqNPEw9g3AJr6d6+wyrRDtMKTrRMwVkO S8h8Iquf/9S1vbzK4mAw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSpGL-0007IL-Px; Thu, 07 Nov 2019 21:24:17 +0000 Received: from [2001:4bb8:184:e48:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSpGJ-0007Fe-VH; Thu, 07 Nov 2019 21:24:16 +0000 From: Christoph Hellwig To: Sebastian Reichel , Rob Herring , Mark Rutland , Paul Walmsley , Palmer Dabbelt Subject: [PATCH 1/2] dt-bindings: power: reset: document the QEMU RISC-V virt machine poweroff device Date: Thu, 7 Nov 2019 22:24:07 +0100 Message-Id: <20191107212408.11857-2-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191107212408.11857-1-hch@lst.de> References: <20191107212408.11857-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add the binding for the trivial Qemu RISC-V poweroff mechanism, which is just a single MMIO register exposed through the DT. Signed-off-by: Christoph Hellwig Reviewed-by: Palmer Dabbelt --- .../power/reset/qemu-riscv-virt-poweroff.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/qemu-riscv-virt-poweroff.txt diff --git a/Documentation/devicetree/bindings/power/reset/qemu-riscv-virt-poweroff.txt b/Documentation/devicetree/bindings/power/reset/qemu-riscv-virt-poweroff.txt new file mode 100644 index 000000000000..80ff6fd4e3b7 --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/qemu-riscv-virt-poweroff.txt @@ -0,0 +1,16 @@ +QEMU RISC-V virt machine poweroff device + +This is a device in Qemu that can signal successful or error exit +by writing two magic numbers to a trivial mmio register. +A Linux poweroff is implemented as successful exit. + +Required Properties: +-compatible: "sifive,test0" +-reg: Specifies the physical address of the register + +Example: + + test@100000 { + compatible = "sifive,test0"; + reg = <0x100000 0x1000>; + }; From patchwork Thu Nov 7 21:24:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11233791 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 507C01599 for ; Thu, 7 Nov 2019 21:24:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 22F8E21D82 for ; Thu, 7 Nov 2019 21:24:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QWgPFLDt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22F8E21D82 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2GygaaIeQUYh5Mcea6Uhly/8hzFV1PPHYl4PRfCye2Q=; b=QWgPFLDtbZWxdc eVn/k6b6fmrPvIN3gDsQ3V/gm5eeZihuhgKw3lwwAbsfVw8n+HFgnrY2wYcrkq1+GGtEJwyqsXlMs A9J7aH4RzvXibyIwiIj4Thwtjxah2paalKBotCdbx6vlE04CGka7eZFEGYxXdlABg0iRS+t5Go0Em bCw5FjZOL6HdgV+FeXPUzieqHQ7CiQqU/hcN0+JjKnyQLjauQUzxyUuaZhIihvY7pKxb/JwIxjWL4 SGgCMIYrk8WtzFDxja1kNJuCcssnAr/1Bz24UWuNTktwUAPmK+6G7gYbPkJSI7rIhr1R3KEI0J0Bx P2w6ANS2HymXHFUo/pbg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSpGO-0007MA-P8; Thu, 07 Nov 2019 21:24:20 +0000 Received: from [2001:4bb8:184:e48:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSpGM-0007Hi-Dr; Thu, 07 Nov 2019 21:24:18 +0000 From: Christoph Hellwig To: Sebastian Reichel , Rob Herring , Mark Rutland , Paul Walmsley , Palmer Dabbelt Subject: [PATCH 2/2] power: reset: add a QEMU RISC-V virt machine poweroff driver Date: Thu, 7 Nov 2019 22:24:08 +0100 Message-Id: <20191107212408.11857-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191107212408.11857-1-hch@lst.de> References: <20191107212408.11857-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add a trivial poweroff driver for the qemu-virt test device that allows an oderly shutdown of the VM. Signed-off-by: Christoph Hellwig Reviewed-by: Palmer Dabbelt --- arch/riscv/configs/defconfig | 2 + drivers/power/reset/Kconfig | 8 ++++ drivers/power/reset/Makefile | 1 + .../power/reset/qemu-riscv-virt-poweroff.c | 47 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 drivers/power/reset/qemu-riscv-virt-poweroff.c diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index 420a0dbef386..47da87725b5e 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -63,6 +63,8 @@ CONFIG_HW_RANDOM_VIRTIO=y CONFIG_SPI=y CONFIG_SPI_SIFIVE=y # CONFIG_PTP_1588_CLOCK is not set +CONFIG_POWER_RESET=y +CONFIG_QEMU_RISCV_VIRT_POWEROFF=y CONFIG_DRM=y CONFIG_DRM_RADEON=y CONFIG_DRM_VIRTIO_GPU=y diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a564237278ff..56cb18520850 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -256,5 +256,13 @@ config NVMEM_REBOOT_MODE then the bootloader can read it and take different action according to the mode. +config QEMU_RISCV_VIRT_POWEROFF + tristate "QEMU RISC-V virt machine poweroff driver" + depends on OF + depends on RISCV || COMPILE_TEST + help + Say y here to allow RISC-V Qemu VMs to be shut down by + the kernel. + endif diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 85da3198e4e0..b3094016b634 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o +obj-$(CONFIG_QEMU_RISCV_VIRT_POWEROFF) += qemu-riscv-virt-poweroff.o diff --git a/drivers/power/reset/qemu-riscv-virt-poweroff.c b/drivers/power/reset/qemu-riscv-virt-poweroff.c new file mode 100644 index 000000000000..5b9a12dd853b --- /dev/null +++ b/drivers/power/reset/qemu-riscv-virt-poweroff.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Christoph Hellwig. + */ + +#include +#include +#include +#include +#include +#include + +#define VIRT_TEST_FINISHER_PASS 0x5555 + +static u16 __iomem *test_addr; + +static void qemu_virt_power_off(void) +{ + writew(VIRT_TEST_FINISHER_PASS, test_addr); +} + +static int sifive_test_probe(struct platform_device *pdev) +{ + /* there can only be a single instance */ + if (WARN_ON_ONCE(test_addr)) + return -EINVAL; + + test_addr = of_iomap(pdev->dev.of_node, 0); + if (!test_addr) + return -EINVAL; + pm_power_off = qemu_virt_power_off; + return 0; +} + +static const struct of_device_id sifive_test_of_match[] = { + { .compatible = "sifive,test0", }, + {}, +}; + +static struct platform_driver sifive_test_driver = { + .probe = sifive_test_probe, + .driver = { + .name = "sifive_test", + .of_match_table = sifive_test_of_match, + }, +}; +module_platform_driver(sifive_test_driver);