From patchwork Wed Jun 3 22:31:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11586323 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 BFCC01391 for ; Wed, 3 Jun 2020 22:32:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 955912067B for ; Wed, 3 Jun 2020 22:32:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Twr04paC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 955912067B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jgbvU-0006hC-9z; Wed, 03 Jun 2020 22:32:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jgbvT-0006h7-1j for xen-devel@lists.xenproject.org; Wed, 03 Jun 2020 22:31:59 +0000 X-Inumbo-ID: 092b3416-a5ea-11ea-81bc-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 092b3416-a5ea-11ea-81bc-bc764e2007e4; Wed, 03 Jun 2020 22:31:58 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B954F2067B; Wed, 3 Jun 2020 22:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591223518; bh=y0pwcX6CXfJoRYSOzlsliNS8HcDu032oeBcqYJ8YDtg=; h=From:To:Cc:Subject:Date:From; b=Twr04paC3T7wh/8UQkngPzj2fBcGsMrA0yjHW6GpY1X0O340Ms5VtN0WgInBTuZtw X4FOAYf/+EyibX0EXZsJ4qKvGzC9ACNfyp/mgXoo5k9AT18Ed0iBLn5ojOdXCyn+ez 3zLEBDh7vgrLLVPd1tUJdcY86TBV6aFrDrYsFBlQ= From: Stefano Stabellini To: julien@xen.org Subject: [PATCH] xen/rpi4: implement watchdog-based reset Date: Wed, 3 Jun 2020 15:31:56 -0700 Message-Id: <20200603223156.12767-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: cminyard@mvista.com, tamas@tklengyel.com, roman@zededa.com, Stefano Stabellini , xen-devel@lists.xenproject.org, Stefano Stabellini Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Touching the watchdog is required to be able to reboot the board. The implementation is based on drivers/watchdog/bcm2835_wdt.c:__bcm2835_restart in Linux. Signed-off-by: Stefano Stabellini Tested-by: Roman Shaposhnik Tested-by: Corey Minyard --- xen/arch/arm/platforms/brcm-raspberry-pi.c | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/xen/arch/arm/platforms/brcm-raspberry-pi.c b/xen/arch/arm/platforms/brcm-raspberry-pi.c index f5ae58a7d5..0214ae2b3c 100644 --- a/xen/arch/arm/platforms/brcm-raspberry-pi.c +++ b/xen/arch/arm/platforms/brcm-raspberry-pi.c @@ -18,6 +18,10 @@ */ #include +#include +#include +#include +#include static const char *const rpi4_dt_compat[] __initconst = { @@ -37,12 +41,68 @@ static const struct dt_device_match rpi4_blacklist_dev[] __initconst = * The aux peripheral also shares a page with the aux UART. */ DT_MATCH_COMPATIBLE("brcm,bcm2835-aux"), + /* Special device used for rebooting */ + DT_MATCH_COMPATIBLE("brcm,bcm2835-pm"), { /* sentinel */ }, }; + +#define PM_PASSWORD 0x5a000000 +#define PM_RSTC 0x1c +#define PM_WDOG 0x24 +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020 +#define PM_RSTC_WRCFG_CLR 0xffffffcf + +static void __iomem *rpi4_map_watchdog(void) +{ + void __iomem *base; + struct dt_device_node *node; + paddr_t start, len; + int ret; + + node = dt_find_compatible_node(NULL, NULL, "brcm,bcm2835-pm"); + if ( !node ) + return NULL; + + ret = dt_device_get_address(node, 0, &start, &len); + if ( ret ) + { + dprintk(XENLOG_ERR, "Cannot read watchdog register address\n"); + return NULL; + } + + base = ioremap_nocache(start & PAGE_MASK, PAGE_SIZE); + if ( !base ) + { + dprintk(XENLOG_ERR, "Unable to map watchdog register!\n"); + return NULL; + } + + return base; +} + +static void rpi4_reset(void) +{ + u32 val; + void __iomem *base = rpi4_map_watchdog(); + if ( !base ) + return; + + /* use a timeout of 10 ticks (~150us) */ + writel(10 | PM_PASSWORD, base + PM_WDOG); + val = readl(base + PM_RSTC); + val &= PM_RSTC_WRCFG_CLR; + val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET; + writel(val, base + PM_RSTC); + + /* No sleeping, possibly atomic. */ + mdelay(1); +} + PLATFORM_START(rpi4, "Raspberry Pi 4") .compatible = rpi4_dt_compat, .blacklist_dev = rpi4_blacklist_dev, + .reset = rpi4_reset, .dma_bitsize = 30, PLATFORM_END