Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp665477imb; Fri, 1 Mar 2019 10:35:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyQ/tQVtfeiOk6DM4fLK1SNn6fhEDos2Pgm9rjNHfbDRSKAeUGkQHUnSJZpXlfdkUKwoE7i X-Received: by 2002:a17:902:3143:: with SMTP id w61mr7038468plb.253.1551465315405; Fri, 01 Mar 2019 10:35:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551465315; cv=none; d=google.com; s=arc-20160816; b=Kn3H18PrMGqVaNqodc9ZF2Lw84dnMnP+rPE0koN6MAjjGxYUlJ6J4CBTKFmmrSh/Ry ThLYDWkAh1XEcbClflTWoYPQkd742RLGm6fBuvHOMTf9kLx07TyiNYA1Ucg6IY9xQKy8 BCfnhVfMQm1OJLVrjcjsLBoKjcGC9dUT5cBxHrKvOqdjiM0pRBWfsEA69U4uaMsIHfdb TPpX2bCv+YPg4f4p5cqcVgahs4W0gCO4MaIXJbGw1NCVqLsTWpZtN2qnOZjSZ0mDar3n ZZG6IkXaHNd7xd23Hq+kaQDHpNR++EFBnXW1uOVtdollH5y7HYRDMbBdjxU+/aHr0ur2 G4Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bJiee5kQvGsLFhaXjpR1Ye+AXx87sD6dGw3O/Owvlds=; b=lP+1qHirHLy6UYSwg3Ekz7rLtkOJT3MTdAjRGM/VgI7xKVbf4jyB3wUzeV9ZrKOqic 0R/7Z+aLsbj/dUPxQRwDzBqTIf85R9aIV63lwplRYGKr1lzW/Qwk8bFh4cc4+qMwbvz0 zCd4IzzZf8+YD0K53ef9YXmdD3Wteg+Yyl91UipozLb139w6G5hxhKbJQWAUa8m5biqN HeQ+ryOQ0R0t5L0Uu+zF+a9YkNDdZARUqLW3ljccYsXkuAHUSOV+jrBgC5YnfT4hlvkK 9nL4AaLyQmMAanIhtvE7+9B+/bRcWnybv08x2w/pdVklwEePbVPY5D5tHYCaoKf2UVIK nisQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QpiR0KjX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si21512189pgm.575.2019.03.01.10.34.59; Fri, 01 Mar 2019 10:35:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QpiR0KjX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388994AbfCASbp (ORCPT + 99 others); Fri, 1 Mar 2019 13:31:45 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40266 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726835AbfCASbp (ORCPT ); Fri, 1 Mar 2019 13:31:45 -0500 Received: by mail-pg1-f193.google.com with SMTP id u9so11819791pgo.7; Fri, 01 Mar 2019 10:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=bJiee5kQvGsLFhaXjpR1Ye+AXx87sD6dGw3O/Owvlds=; b=QpiR0KjXcw7QSECxff+ZyQQuDupirTtkw9baer62Z4AKucMF7OWqNDHistCoZ2MDXm K+4QM16X9NUmnWZsl49lZrnpWSBdXRpOkBaOVWaIn5NLeT7qqx+GDDN4Iq1LVTX5Et2F 78kfGg84U+OnGcSqY8ungT0fMcfVNHf7M1AhhtYu1LoSEQKMrBCyvNTwrcMPsYgEck0b SGk05q5PgiI9uBeAdQ5dRZ1st4J7E7672RKuJJgiWb3dvuQQ/6qL/6s6FBsn8ymAXiQ/ 44vwVYY/iZ5cdN4s1qqm4SH3QBIN2SnD2meq7CqBTn+nfdyjHIPNb4pjVXTctyD8ddIc XJjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=bJiee5kQvGsLFhaXjpR1Ye+AXx87sD6dGw3O/Owvlds=; b=HD+Nvx2TK+uOF5EQ0SHmdWgvbxsDNS9l4I8Q9lZ/4jhn7ZVW54sSfERIXUc8qrwpdI /GzzfGFN6DOJ5j7aAyrtK73UNEXCE5jfNc7Eh0qnHKkf0zHpNaLvHDpcwX/Z1cX3TnMf BM/JvGJgxMxE4uABVF41k+zk82VA5Xp16glAoaiMU5EteNK3mn3SE7j8iJ5cQnQVuB95 n67m/Wrrq10nHkIps4fhcxkOSPin5OOYhOd6rugp9oMi3YlCZJRJTid5NUFnr+ysfPXw OIOFrGpXJmXRAy++d8+1WFEevASSX56V4Dg/k6ifLOcRGL0F5kCFIIqbn/mRyBOmitAF urng== X-Gm-Message-State: APjAAAVJ8moh1j7J9yB/2c3LiU28DnpQtCe6lQgN+54FGmiZSF+GxMqH SLKLAnIiPSV/2RIdUQMJ7Z0= X-Received: by 2002:a65:6241:: with SMTP id q1mr6205999pgv.340.1551465103957; Fri, 01 Mar 2019 10:31:43 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b8sm21240028pfi.129.2019.03.01.10.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 10:31:42 -0800 (PST) Date: Fri, 1 Mar 2019 10:31:41 -0800 From: Guenter Roeck To: Anson Huang Cc: "catalin.marinas@arm.com" , "will.deacon@arm.com" , "wim@linux-watchdog.org" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , Andy Gross , "heiko@sntech.de" , "horms+renesas@verge.net.au" , "arnd@arndb.de" , "olof@lixom.net" , "bjorn.andersson@linaro.org" , "jagan@amarulasolutions.com" , "enric.balletbo@collabora.com" , "marc.w.gonzalez@free.fr" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-watchdog@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH V5 1/2] watchdog: imx_sc: Add i.MX system controller watchdog support Message-ID: <20190301183141.GA26332@roeck-us.net> References: <1551421837-21230-1-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1551421837-21230-1-git-send-email-Anson.Huang@nxp.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 01, 2019 at 06:35:31AM +0000, Anson Huang wrote: > i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller > inside, the system controller is in charge of controlling power, > clock and watchdog etc.. > > This patch adds i.MX system controller watchdog driver support, > watchdog operation needs to be done in secure EL3 mode via > ARM-Trusted-Firmware, using SMC call, CPU will trap into > ARM-Trusted-Firmware and then it will request system controller > to do watchdog operation via IPC. > > Signed-off-by: Anson Huang > --- > Changes since V4: > - change the module build dependency as depends on IMX_SCU and HAVE_ARM_SMCCC, as this > driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call. > --- > drivers/watchdog/Kconfig | 14 +++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 216 insertions(+) > create mode 100644 drivers/watchdog/imx_sc_wdt.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index 65c3c42..a6bfa54 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -625,6 +625,20 @@ config IMX2_WDT > To compile this driver as a module, choose M here: the > module will be called imx2_wdt. > > +config IMX_SC_WDT > + tristate "IMX SC Watchdog" > + depends on IMX_SCU > + depends on HAVE_ARM_SMCCC > + select WATCHDOG_CORE > + help > + This is the driver for the system controller watchdog > + on the NXP i.MX SoCs with system controller inside. > + If you have one of these processors and wish to have > + watchdog support enabled, say Y, otherwise say N. > + > + To compile this driver as a module, choose M here: the > + module will be called imx_sc_wdt. > + > config UX500_WATCHDOG > tristate "ST-Ericsson Ux500 watchdog" > depends on MFD_DB8500_PRCMU > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index 4e78a8c..0c9da63 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o > obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o > obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o > obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o > +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o > obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o > obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o > obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o > diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c > new file mode 100644 > index 0000000..50b49b2 > --- /dev/null > +++ b/drivers/watchdog/imx_sc_wdt.c > @@ -0,0 +1,201 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2018-2019 NXP. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include Should no longer be needed. > +#include > +#include > +#include > + > +#define DEFAULT_TIMEOUT 60 > +/* > + * Software timer tick implemented in scfw side, support 10ms to 0xffffffff ms > + * in theory, but for normal case, 1s~128s is enough, you can change this max > + * value in case it's not enough. > + */ > +#define MAX_TIMEOUT 128 > + > +#define IMX_SIP_TIMER 0xC2000002 > +#define IMX_SIP_TIMER_START_WDOG 0x01 > +#define IMX_SIP_TIMER_STOP_WDOG 0x02 > +#define IMX_SIP_TIMER_SET_WDOG_ACT 0x03 > +#define IMX_SIP_TIMER_PING_WDOG 0x04 > +#define IMX_SIP_TIMER_SET_TIMEOUT_WDOG 0x05 > +#define IMX_SIP_TIMER_GET_WDOG_STAT 0x06 > +#define IMX_SIP_TIMER_SET_PRETIME_WDOG 0x07 > + > +#define SC_TIMER_WDOG_ACTION_PARTITION 0 > + > +static bool nowayout = WATCHDOG_NOWAYOUT; > +module_param(nowayout, bool, 0000); > +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" > + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); > + > +static unsigned int timeout = DEFAULT_TIMEOUT; > +module_param(timeout, uint, 0000); > +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" > + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); > + > +static struct platform_device *imx_sc_wdt_pdev; > + > +static int imx_sc_wdt_ping(struct watchdog_device *wdog) > +{ > + struct arm_smccc_res res; > + > + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_PING_WDOG, > + 0, 0, 0, 0, 0, 0, &res); > + > + return 0; > +} > + > +static int imx_sc_wdt_start(struct watchdog_device *wdog) > +{ > + struct arm_smccc_res res; > + > + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_START_WDOG, > + 0, 0, 0, 0, 0, 0, &res); > + if (res.a0) > + return -EACCES; > + > + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_WDOG_ACT, > + SC_TIMER_WDOG_ACTION_PARTITION, > + 0, 0, 0, 0, 0, &res); > + return res.a0 ? -EACCES : 0; > +} > + > +static int imx_sc_wdt_stop(struct watchdog_device *wdog) > +{ > + struct arm_smccc_res res; > + > + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_STOP_WDOG, > + 0, 0, 0, 0, 0, 0, &res); > + > + return res.a0 ? -EACCES : 0; > +} > + > +static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, > + unsigned int timeout) > +{ > + struct arm_smccc_res res; > + > + wdog->timeout = timeout; > + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_TIMEOUT_WDOG, > + timeout * 1000, 0, 0, 0, 0, 0, &res); > + > + return res.a0 ? -EACCES : 0; > +} > + > +static const struct watchdog_ops imx_sc_wdt_ops = { > + .owner = THIS_MODULE, > + .start = imx_sc_wdt_start, > + .stop = imx_sc_wdt_stop, > + .ping = imx_sc_wdt_ping, > + .set_timeout = imx_sc_wdt_set_timeout, > +}; > + > +static const struct watchdog_info imx_sc_wdt_info = { > + .identity = "i.MX SC watchdog timer", > + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | > + WDIOF_MAGICCLOSE | WDIOF_PRETIMEOUT, > +}; > + > +static int imx_sc_wdt_probe(struct platform_device *pdev) > +{ > + struct watchdog_device *imx_sc_wdd; > + int ret; > + > + imx_sc_wdd = devm_kzalloc(&pdev->dev, sizeof(*imx_sc_wdd), GFP_KERNEL); > + if (!imx_sc_wdd) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, imx_sc_wdd); > + > + imx_sc_wdd->info = &imx_sc_wdt_info; > + imx_sc_wdd->ops = &imx_sc_wdt_ops; > + imx_sc_wdd->min_timeout = 1; > + imx_sc_wdd->max_timeout = MAX_TIMEOUT; > + imx_sc_wdd->parent = &pdev->dev; > + imx_sc_wdd->timeout = DEFAULT_TIMEOUT; > + > + ret = watchdog_init_timeout(imx_sc_wdd, timeout, &pdev->dev); > + if (ret) > + dev_warn(&pdev->dev, "Failed to set timeout value, using default\n"); > + > + watchdog_stop_on_reboot(imx_sc_wdd); > + watchdog_stop_on_unregister(imx_sc_wdd); > + > + ret = devm_watchdog_register_device(&pdev->dev, imx_sc_wdd); > + if (ret) { > + dev_err(&pdev->dev, "Failed to register watchdog device\n"); > + return ret; > + } > + > + return 0; > +} > + > +static int __maybe_unused imx_sc_wdt_suspend(struct device *dev) > +{ > + struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); > + > + if (watchdog_active(imx_sc_wdd)) > + imx_sc_wdt_stop(imx_sc_wdd); > + > + return 0; > +} > + > +static int __maybe_unused imx_sc_wdt_resume(struct device *dev) > +{ > + struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); > + > + if (watchdog_active(imx_sc_wdd)) > + imx_sc_wdt_start(imx_sc_wdd); > + > + return 0; > +} > + > +static SIMPLE_DEV_PM_OPS(imx_sc_wdt_pm_ops, > + imx_sc_wdt_suspend, imx_sc_wdt_resume); > + > +static struct platform_driver imx_sc_wdt_driver = { > + .probe = imx_sc_wdt_probe, > + .driver = { > + .name = "imx-sc-wdt", > + .pm = &imx_sc_wdt_pm_ops, > + }, > +}; > + > +static int __init imx_sc_wdt_init(void) > +{ > + int ret; > + > + ret = platform_driver_register(&imx_sc_wdt_driver); > + if (ret) > + return ret; > + > + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -1, NULL, 0); > + if (IS_ERR(imx_sc_wdt_pdev)) { > + platform_driver_unregister(&imx_sc_wdt_driver); > + return PTR_ERR(imx_sc_wdt_pdev); > + } I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen. Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from imx_scu_probe() in drivers/firmware/imx/imx-scu.c ? Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree". If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in imx_sc_wdt_init() or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported. Guenter > + > + return 0; > +} > +module_init(imx_sc_wdt_init); > + > +static void __exit imx_sc_wdt_exit(void) > +{ > + platform_driver_unregister(&imx_sc_wdt_driver); > + platform_device_unregister(imx_sc_wdt_pdev); > +} > +module_exit(imx_sc_wdt_exit); > + > +MODULE_AUTHOR("Robin Gong "); > +MODULE_DESCRIPTION("NXP i.MX system controller watchdog driver"); > +MODULE_LICENSE("GPL v2"); > -- > 2.7.4 >