watchdog: Add Tegra20 watchdog driver
Subsystems (6)
v2 cover watchdog: Add Tegra20 watchdog driver
The motivation is to improve recovery from kernel hangs, which have been steadily driving me to the doorstep of a psych ward for a few months. They are rare: some happen at boot, others while using the tablet for something real, like reading PDFs, browsing the web (to the extent possible without working GPU accel), or just using it as a thin client for another device.
All my attempts to find even the slightest hint of what went wrong have come to nothing (the device just refuses to hang with UART connected), so this series is born in the hope that it will finally enable me and others to catch those bugs (using the watchdog and pstore).
Tegra20 has no dedicated watchdog block. Instead, the clock and reset controller can reset the system when timer 1's interrupt fires while the previous one is still pending. This series adds a tegra20_wdt driver for it, which takes over a watchdog left running by the bootloader.
Tegra20's boot ROM hangs after a watchdog reset if the VDE partition is off (for normal reboots, this is handled by 8f0c714ad9be). The series offers two mitigations:
- By default, tegra20_wdt stops the watchdog for good before the partition is powered off for the first time, using a new PMC power off notifier (patches 5 and 6). A watchdog started by the bootloader still covers early boot, until the PMC driver comes up. After that, opening the device, keepalives and timeout changes fail with -EBUSY. Booting with tegra20_wdt.stop_on_vde_off=0 keeps the watchdog running instead, at the risk of the system hanging instead of rebooting.
- Booting with tegra_pmc.vde_always_on=1 keeps the partition powered on, so the watchdog is fully usable, at the expense of higher power consumption.
This has been tested on ASUS TF101:
- with tegra_pmc.vde_always_on=1, the watchdog stays on. The device has been running for several hours with no issues. Suspend/resume works, and the watchdog keeps working after resume, both when only the watchdog core pings it and when user space has it open. The watchdog resets the system both when user space stops pinging it and when the kernel crashes, and U-Boot and Linux boot normally after the warm reset.
- with the default settings, the watchdog taken over from the bootloader is stopped when the PMC driver powers off the VDE partition. After that, opening the device fails with -EBUSY, and the system keeps running without resets.
Another series for fixing some other issues with warm reboots (not related to watchdog itself) will follow shortly.
Patch 5 is flagged by checkpatch (WARNING: ENOSYS means 'invalid syscall nr' and nothing else). I kept it as-is for consistency with the existing stubs. If this is not desirable, just tell me.
---
Patch 3 depends on patches 1 and 2 and must not be merged before them:
otherwise the watchdog driver conflicts with the clocksource driver over timer 1, and the clock driver helpers it uses are missing. Patch 6 depends on patch 5.
To: Daniel Lezcano <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Thierry Reding <[email protected]>
To: Jonathan Hunter <[email protected]>
To: Wim Van Sebroeck <[email protected]>
To: Guenter Roeck <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Philipp Zabel <[email protected]>
---
Changes in v2:
- Add Tegra20 support as a separate tegra20_wdt driver instead of
extending tegra_wdt, and drop the tegra_wdt match data refactor
(Guenter)
- Access RST_SOURCE through helpers exported by the clock driver
instead of mapping the clock and reset controller's registers
(Krzysztof)
- Validate the heartbeat parameter with watchdog_init_timeout()
- vde_always_on now has effect only on T20
- Leave the watchdog core's state alone in the VDE power off notifier,
which raced with the core and leaked its references (Sashiko)
- Refuse timeout changes after VDE power off before changing the
timeout (Sashiko)
- Fail pings after VDE power off, so that user space finds out
(Sashiko)
- Document that stop_on_vde_off takes precedence over nowayout
- Document the parameters of tegra20_wdt in watchdog-parameters.rst
- Link to v1: https://patch.msgid.link/[email protected]
To: Daniel Lezcano <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Thierry Reding <[email protected]>
To: Jonathan Hunter <[email protected]>
To: Prashant Gaikwad <[email protected]>
To: Stephen Boyd <[email protected]>
To: Brian Masney <[email protected]>
To: Jerome Brunet <[email protected]>
To: Wim Van Sebroeck <[email protected]>
To: Guenter Roeck <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Philipp Zabel <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Artur Kowalski (6):
clocksource/drivers/timer-tegra: Keep Tegra20's watchdog timers free
clk: tegra20: Add watchdog reset control helpers
watchdog: Add Tegra20 watchdog driver
soc/tegra: pmc: Add an option to keep the VDE partition on soc/tegra: pmc: Add a partition power off notifier
watchdog: tegra20_wdt: Stop on VDE power off
Documentation/admin-guide/kernel-parameters.txt | 12 + Documentation/watchdog/watchdog-parameters.rst | 14 + drivers/clk/tegra/clk-tegra20.c | 60 ++++ drivers/clocksource/timer-tegra.c | 40 ++- drivers/soc/tegra/pmc.c | 160 ++++++++- drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/tegra20_wdt.c | 413 ++++++++++++++++++++++++ include/linux/clk/tegra.h | 16 + include/soc/tegra/pmc.h | 19 ++ 10 files changed, 733 insertions(+), 13 deletions(-)
---
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
change-id: 20261108-t20-for-upstream-497bc765188c
Best regards,
Signature · 1 line
Artur Kowalski <[email protected]>
PATCH v2 1/6 clocksource/drivers/timer-tegra: Keep Tegra20's watchdog timers free
Tegra20 has no watchdog block. Instead, the clock and reset controller resets the system when the interrupt of TIMER1 or TIMER2 fires while the previous one is still pending. A bootloader can start this watchdog and leave it running for the kernel.
Since commit f6d50ec5f85c ("clocksource/drivers/tegra: Support per-CPU timers on all Tegra's"), the driver uses TIMER1-2 as the per-CPU clock event devices on Tegra20, where it used TIMER3 before. When CPU0's clock event device takes over TIMER1, the clock and reset controller still resets the system if a timer interrupt fires while the previous one hasn't been handled yet, which resets about half of the boots early. If the system survives that, the watchdog stays enabled but never fires, as CPU0 keeps clearing the timer's interrupts.
Use TIMER3-4 for the per-CPU clock event devices on Tegra20, leaving TIMER1-2 to the watchdog. Tegra30 needs TIMER1-4 for its four CPUs and its watchdog uses TIMER5, so keep its mapping.
A watchdog left running by the bootloader is then no longer disarmed, so it resets the system unless it is pinged. That needs the tegra20_wdt driver, added in the following patches, built in or loaded before the watchdog's timeout expires. As far as I know, the only bootloader that leaves it running is U-Boot with its new Tegra20 watchdog driver, which is queued in the U-Boot Tegra tree [1].
--- drivers/clocksource/timer-tegra.c | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
drivers/clocksource/timer-tegra.c +31 -9
@@ -208,10 +208,15 @@ static struct clocksource suspend_rtc_clocksource = { .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP, }; -static inline unsigned int tegra_base_for_cpu (int cpu,bool tegra20) +/* +* The timer used by a CPU is TIMER1-4 on Tegra20 and Tegra30, starting from +* @first, or TIMER10-13 on later SoCs. +*/ +static inline unsigned int tegra_base_for_cpu (int cpu,bool tegra20, +unsigned int first) {if (tegra20) { -switch (cpu) { +switch (cpu + first) {case 0 :return TIMER1_BASE ;case 1 :
@@ -226,10 +231,11 @@ static inline unsigned int tegra_base_for_cpu(int cpu, bool tegra20)return TIMER10_BASE + cpu *8 ; } -static inline unsigned int tegra_irq_idx_for_cpu (int cpu,bool tegra20) +static inline unsigned int tegra_irq_idx_for_cpu (int cpu,bool tegra20, +unsigned int first) {if (tegra20) -return TIMER1_IRQ_IDX + cpu; +return TIMER1_IRQ_IDX + first + cpu;return TIMER10_IRQ_IDX + cpu; }
@@ -248,7 +254,7 @@ static inline unsigned long tegra_rate_for_timer(struct timer_of *to, }static int __init tegra_init_timer (struct device_node *np,bool tegra20, -int rating) +int rating,unsigned int first) {struct timer_of *to;int cpu, ret;
@@ -297,12 +303,18 @@ static int __init tegra_init_timer(struct device_node *np, bool tegra20,writel_relaxed (usec_config, timer_reg_base +TIMERUS_USEC_CFG ); +if (tegra20 && first +num_possible_cpus () >4 ) { +pr_err ("not enough timers for %u CPUs\n" ,num_possible_cpus ()); + ret = -EINVAL ; + goto out; + } +for_each_possible_cpu (cpu) {struct timer_of *cpu_to =per_cpu_ptr (&tegra_to, cpu);unsigned long flags =IRQF_TIMER |IRQF_NOBALANCING ;unsigned long rate =tegra_rate_for_timer (to, tegra20); -unsigned int base =tegra_base_for_cpu (cpu, tegra20); -unsigned int idx =tegra_irq_idx_for_cpu (cpu, tegra20); +unsigned int base =tegra_base_for_cpu (cpu, tegra20, first); +unsigned int idx =tegra_irq_idx_for_cpu (cpu, tegra20, first);unsigned int irq =irq_of_parse_and_map (np, idx);if (!irq) {
@@ -376,12 +388,13 @@ static int __init tegra210_init_timer(struct device_node *np)* after CPUPORESET signal due to a system design shortcoming, * hence tegra-timer is more preferable on Tegra210. */ -return tegra_init_timer (np, false,460 ); +return tegra_init_timer (np, false,460 ,0 ); }TIMER_OF_DECLARE (tegra210_timer,"nvidia,tegra210-timer" , tegra210_init_timer);static int __init tegra20_init_timer (struct device_node *np) { +unsigned int first =0 ;int rating;/*
@@ -398,7 +411,16 @@ static int __init tegra20_init_timer(struct device_node *np)else rating =330 ; -return tegra_init_timer (np, true, rating); +/* +* Tegra20 has no watchdog block. Its watchdog is driven by TIMER1 or +* TIMER2, which the bootloader may leave running, so leave both to it +* and use TIMER3-4 for the two CPUs. Tegra30's watchdogs use TIMER5 +* and later, and its four CPUs need TIMER1-4. +*/ +if (of_machine_is_compatible ("nvidia,tegra20" )) + first =2 ; + +return tegra_init_timer (np, true, rating, first); }TIMER_OF_DECLARE (tegra20_timer,"nvidia,tegra20-timer" , tegra20_init_timer);
Signature · 1 line
2.56.1
PATCH v2 2/6 clk: tegra20: Add watchdog reset control helpers
In reply to Artur KowalskiTegra20 has no watchdog block. Instead, the clock and reset controller can reset the system when the interrupt of timer 1 or 2 fires while the previous one is still pending, which is enabled through its RST_SOURCE register. The clock driver doesn't use this register otherwise.
Export helpers to enable and disable this reset with timer 1, and to check whether a bootloader left it enabled, so that a watchdog driver doesn't have to map the controller's registers behind its back. The read-modify-write of RST_SOURCE is serialized by a spinlock of its own.
--- drivers/clk/tegra/clk-tegra20.c | 60 +++++++++++++++++++++++++++++++++++++++++ include/linux/clk/tegra.h | 16 +++++++++++ 2 files changed, 76 insertions(+)
drivers/clk/tegra/clk-tegra20.c +60 -0
@@ -17,6 +17,13 @@#include "clk.h" #include "clk-id.h" +#define RST_SOURCE 0x0 +#define RST_SOURCE_WDT_EN BIT(5) +#define RST_SOURCE_WDT_SEL_TMR2 BIT(4) +#define RST_SOURCE_WDT_SYS_RST_EN BIT(2) +#define RST_SOURCE_WDT_MASK (RST_SOURCE_WDT_EN | RST_SOURCE_WDT_SEL_TMR2 | \ + RST_SOURCE_WDT_SYS_RST_EN) +#define MISC_CLK_ENB 0x48#define OSC_CTRL 0x50
@@ -132,6 +139,8 @@ static struct cpu_clk_suspend_context {static void __iomem *clk_base;static void __iomem *pmc_base; +static DEFINE_SPINLOCK (rst_source_lock); +#define TEGRA_INIT_DATA_MUX (_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
@@ -1164,6 +1173,57 @@ static void __init tegra20_clock_init(struct device_node *np) }CLK_OF_DECLARE_DRIVER (tegra20,"nvidia,tegra20-car" , tegra20_clock_init); +/** +* tegra20_clk_watchdog_enable() - enable or disable the watchdog reset +* @enable: whether to enable the reset +* +* Tegra20 has no watchdog block. Instead, the clock and reset controller can +* reset the system when the interrupt of timer 1 or 2 fires while the previous +* one is still pending, which is enabled through the RST_SOURCE register. This +* enables it with timer 1. +* +* Return: 0 on success, or -ENODEV if the clock and reset controller isn't +* Tegra20's. +*/ +int tegra20_clk_watchdog_enable (bool enable) +{ +unsigned long flags; +u32 val; + +if (!clk_base) +return -ENODEV ; + +spin_lock_irqsave (&rst_source_lock, flags); + + val =readl (clk_base +RST_SOURCE ); + val &= ~RST_SOURCE_WDT_MASK ; +if (enable) + val |=RST_SOURCE_WDT_EN |RST_SOURCE_WDT_SYS_RST_EN ; +writel (val, clk_base +RST_SOURCE ); + +spin_unlock_irqrestore (&rst_source_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (tegra20_clk_watchdog_enable); + +/** +* tegra20_clk_watchdog_is_enabled() - check whether the watchdog reset is enabled +* +* A bootloader may leave the watchdog reset enabled for the kernel to take it +* over. +* +* Return: true if the watchdog reset is enabled, false otherwise. +*/ +bool tegra20_clk_watchdog_is_enabled (void ) +{ +if (!clk_base) +return false; + +return readl (clk_base +RST_SOURCE ) &RST_SOURCE_WDT_EN ; +} +EXPORT_SYMBOL_GPL (tegra20_clk_watchdog_is_enabled); +/* * Clocks that use runtime PM can't be created at the tegra20_clock_init * time because drivers' base isn't initialized yet, and thus platform
include/linux/clk/tegra.h +16 -0
@@ -6,6 +6,7 @@#ifndef __LINUX_CLK_TEGRA_H_#define __LINUX_CLK_TEGRA_H_ +#include <linux/errno.h> #include <linux/types.h> #include <linux/bug.h>
@@ -195,6 +196,21 @@ tegra20_clk_prepare_emc_mc_same_freq(struct clk *emc_clk, bool same) }#endif +#ifdef CONFIG_ARCH_TEGRA_2x_SOC +int tegra20_clk_watchdog_enable (bool enable); +bool tegra20_clk_watchdog_is_enabled (void ); +#else +static inline int tegra20_clk_watchdog_enable (bool enable) +{ +return -ENODEV ; +} + +static inline bool tegra20_clk_watchdog_is_enabled (void ) +{ +return false; +} +#endif +#ifdef CONFIG_TEGRA124_CLK_EMC void tegra124_clk_set_emc_callbacks (tegra124_emc_prepare_timing_change_cb *prep_cb,tegra124_emc_complete_timing_change_cb *complete_cb);
Signature · 1 line
2.56.1
PATCH v2 3/6 watchdog: Add Tegra20 watchdog driver
In reply to Artur KowalskiTegra20 has no watchdog block. Instead, the clock and reset controller can reset the system when the interrupt of TIMER1 or TIMER2 fires while the previous one is still pending, enabled through the WDT bits of its RST_SOURCE register. This relies on the timer driver leaving TIMER1-2 to the watchdog on Tegra20.
As this has little in common with the watchdog block of Tegra30 and later, add it as a separate driver rather than extending tegra_wdt.
Use TIMER1 for it, running periodically with half of the timeout as its period. Clearing the interrupt alone doesn't restart the period, which would leave between half and all of the timeout after a ping, so a ping also rewrites the timer setting, read back from the timer, to restart it. The timer has no readable interrupt status, so the time left can't be reported.
RST_SOURCE belongs to the clock and reset controller, so use the helpers its driver exports to enable and disable the reset, rather than mapping its registers.
A bootloader may leave the watchdog running. Take it over with the driver's timeout and let the watchdog core ping it until user space opens the device. Since it then runs without user space having started it, stop it for suspend and restart it on resume whenever it runs.
A watchdog reset leaves the PMC alone, and the boot ROM hangs if the VDE power partition is off at that point. A following patch stops the watchdog before the partition is powered off.
Tegra30 lists "nvidia,tegra20-timer" as a fallback compatible string, but is handled by tegra_wdt, so don't probe on it.
--- Documentation/watchdog/watchdog-parameters.rst | 9 + drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/tegra20_wdt.c | 267 +++++++++++++++++++++++++ 4 files changed, 288 insertions(+)
Documentation/watchdog/watchdog-parameters.rst +9 -0
@@ -603,6 +603,15 @@ tegra_wdt: ------------------------------------------------- +tegra20_wdt: + heartbeat: + Watchdog heartbeats in seconds. (default = 120) + nowayout: + Watchdog cannot be stopped once started + (default=kernel config parameter) + +------------------------------------------------- + ts72xx_wdt: timeout: Watchdog timeout in seconds. (1 <= timeout <= 8, default=8)
drivers/watchdog/Kconfig +11 -0
@@ -920,6 +920,17 @@ config TEGRA_WATCHDOG To compile this driver as a module, choose M here: the module will be called tegra_wdt. +config TEGRA20_WATCHDOG + tristate "Tegra20 watchdog" + depends on (ARCH_TEGRA_2x_SOC || COMPILE_TEST) && HAS_IOMEM && OF + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + embedded in NVIDIA Tegra20 SoCs. + + To compile this driver as a module, choose M here: the + module will be called tegra20_wdt. + config QCOM_WDT tristate "Qualcomm watchdog" depends on HAS_IOMEM
drivers/watchdog/Makefile +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_ST_LPC_WATCHDOG) += st_lpc_wdt.o obj-$(CONFIG_QCOM_WDT) += qcom-wdt.o obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o +obj-$(CONFIG_TEGRA20_WATCHDOG) += tegra20_wdt.o obj-$(CONFIG_MESON_GXBB_WATCHDOG) += meson_gxbb_wdt.o obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o
drivers/watchdog/tegra20_wdt.c new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v2 4/6 soc/tegra: pmc: Add an option to keep the VDE partition on
In reply to Artur KowalskiAfter a warm reset, which doesn't reset the PMC, Tegra20's boot ROM hangs if the VDE partition is powered off. The driver powers the partition off when it registers it, and genpd powers it off whenever the VDE is idle. The VDE driver powers it on again when the system shuts down, since commit 8f0c714ad9be ("media: staging: tegra-vde: Turn ON power domain on shutdown"), which covers regular reboots. A watchdog reset doesn't go through the shutdown, so it still hangs the system instead of rebooting it.
Add the vde_always_on module parameter, which keeps the partition powered on, at the cost of its idle power. It only applies to Tegra20, as later SoCs aren't affected. It's a parameter rather than a device tree property, as trading the idle power for working watchdog resets is a policy choice, not a description of the hardware. Instead of powering the partition off when registering it, the driver runs the power up sequence on it, which puts its clocks, resets and clamps into the same known state without cutting its power, and registers its genpd as always on. tegra_powergate_set() also doesn't power it off, which covers the legacy power gating API.
--- Documentation/admin-guide/kernel-parameters.txt | 12 ++++++ drivers/soc/tegra/pmc.c | 55 +++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -7567,6 +7567,18 @@ Kernel parameters tdfx= [HW,DRM] + tegra_pmc.vde_always_on= + [HW,ARM] Tegra20 only. Never power off the VDE power + partition. After a warm reset, which doesn't reset + the PMC, the boot ROM of Tegra20 hangs if the + partition is off. The VDE driver powers it on when + the system shuts down for a regular reboot, but a + watchdog reset doesn't go through the shutdown and + hangs. Keeping the partition on makes watchdog resets + work, at the cost of its idle power. + Format: <bool> + Default: false + test_suspend= [SUSPEND] Format: { "mem" | "standby" | "freeze" }[,N] Specify "mem" (for Suspend-to-RAM) or "standby" (for
drivers/soc/tegra/pmc.c +51 -4
95 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v2 5/6 soc/tegra: pmc: Add a partition power off notifier
In reply to Artur KowalskiAfter a watchdog reset, which doesn't reset the PMC, Tegra20's boot ROM hangs if the VDE partition is powered off. Unless booted with tegra_pmc.vde_always_on=1, the PMC driver powers the partition off when it registers it, and genpd powers it off while the VDE is idle. The Tegra20 watchdog driver will need to stop the watchdog before that happens.
genpd notifiers can't be used for this: they only reach devices attached to the domain, which the watchdog isn't, and the partitions are powered off before their genpds are registered. Add a notifier that is called before a partition is powered off, from tegra_powergate_set(), which all power off paths go through.
When a notifier is registered, it is also called for every partition that is already powered off, except one kept powered on with tegra_pmc.vde_always_on, which the PMC driver powers on when it registers it. A lock is held across both the notification and the power off, so a partition can't be powered off unnoticed while a notifier is being registered. Registration uses the early PMC, so it works before the PMC driver has probed, which is when the partitions are first powered off. The notifier, including the hook on the power off path, is therefore only built on 32-bit ARM, the only architecture with an early PMC.
--- drivers/soc/tegra/pmc.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ include/soc/tegra/pmc.h | 19 +++++++++ 2 files changed, 124 insertions(+)
drivers/soc/tegra/pmc.c +105 -0
@@ -31,6 +31,7 @@#include <linux/irq.h> #include <linux/irq_work.h> #include <linux/kernel.h> +#include <linux/notifier.h> #include <linux/of_address.h> #include <linux/of_clk.h> #include <linux/of.h>
@@ -520,6 +521,34 @@ static struct tegra_pmc *early_pmc = &(struct tegra_pmc) { .base = NULL, .suspend_mode = TEGRA_SUSPEND_NOT_READY, }; + +/* +* Notified before a partition is powered off. The lock is held across the +* notification and the power off, so that a notifier being registered either +* sees the partition still powered or is notified. +*/ +static DEFINE_MUTEX (tegra_powergate_nh_lock); +static RAW_NOTIFIER_HEAD (tegra_powergate_nh); + +static void tegra_powergate_power_off_begin (unsigned int id) +{ +mutex_lock (&tegra_powergate_nh_lock); +raw_notifier_call_chain (&tegra_powergate_nh, +TEGRA_PMC_POWERGATE_POWER_OFF , &id); +} + +static void tegra_powergate_power_off_end (void ) +{ +mutex_unlock (&tegra_powergate_nh_lock); +} +#else +static inline void tegra_powergate_power_off_begin (unsigned int id) +{ +} + +static inline void tegra_powergate_power_off_end (void ) +{ +}#endif #ifdef MODULE_PARAM_PREFIX
@@ -731,8 +760,14 @@ static int tegra_powergate_set(struct tegra_pmc *pmc, unsigned int id,return 0 ; } +if (!new_state) +tegra_powergate_power_off_begin (id); + err = pmc->soc->powergate_set (pmc, id, new_state); +if (!new_state) +tegra_powergate_power_off_end (); +mutex_unlock (&pmc->powergates_lock);return err;
@@ -5167,6 +5202,76 @@ int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)return tegra_pmc_powergate_remove_clamping (early_pmc, id); } +/** +* tegra_pmc_powergate_register_notifier() - get notified of partition power off +* @nb: notifier block +* +* The notifier is called with %TEGRA_PMC_POWERGATE_POWER_OFF and a pointer to +* the partition ID (unsigned int) as data before a partition is powered off, +* from a context that may sleep. The PMC's partition locks are held, so the +* notifier must not call back into the PMC to control partitions or register +* notifiers. Its return value is ignored. It is also called for every partition +* that is already powered off before this function returns, so a partition is +* either still powered once the function returns or the notifier has been +* called for it. A partition that is kept powered on (tegra_pmc.vde_always_on) +* is never reported, as the driver powers it on when it registers it. +* +* This works before the PMC driver has probed, as the PMC is set up early on +* 32-bit ARM, so it covers the partitions that the driver powers off when it +* registers them. +*/ +int tegra_pmc_powergate_register_notifier (struct notifier_block *nb) +{ +unsigned int id; +int err; + +mutex_lock (&tegra_powergate_nh_lock); + + err =raw_notifier_chain_register (&tegra_powergate_nh, nb); +if (err) + goto unlock; + +/* the base is switched to the driver's mapping under this lock */ +mutex_lock (&early_pmc->powergates_lock); + +if (early_pmc->base && early_pmc->soc) { +for (id =0 ; id < early_pmc->soc->num_powergates; id++) { +/* powered on when the driver registers it */ +if (tegra_powergate_is_always_on (id)) +continue ; + +if (tegra_powergate_is_powered (early_pmc, id) ==0 ) + nb->notifier_call (nb, +TEGRA_PMC_POWERGATE_POWER_OFF , + &id); + } + } + +mutex_unlock (&early_pmc->powergates_lock); + +unlock: +mutex_unlock (&tegra_powergate_nh_lock); + +return err; +} +EXPORT_SYMBOL (tegra_pmc_powergate_register_notifier); + +/** +* tegra_pmc_powergate_unregister_notifier() - unregister a power off notifier +* @nb: notifier block registered with tegra_pmc_powergate_register_notifier() +*/ +int tegra_pmc_powergate_unregister_notifier (struct notifier_block *nb) +{ +int err; + +mutex_lock (&tegra_powergate_nh_lock); + err =raw_notifier_chain_unregister (&tegra_powergate_nh, nb); +mutex_unlock (&tegra_powergate_nh_lock); + +return err; +} +EXPORT_SYMBOL (tegra_pmc_powergate_unregister_notifier); +bool tegra_pmc_core_domain_state_synced (void ) {return early_pmc->core_domain_state_synced;
include/soc/tegra/pmc.h +19 -0
@@ -231,14 +231,33 @@ static inline void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)#endif #endif +/* event of the partition power off notifier, data points to the partition ID */ +#define TEGRA_PMC_POWERGATE_POWER_OFF 0 + +struct notifier_block ; +#if defined(CONFIG_ARM ) && defined(CONFIG_SOC_TEGRA_PMC )bool tegra_pmc_core_domain_state_synced (void ); +int tegra_pmc_powergate_register_notifier (struct notifier_block *nb); +int tegra_pmc_powergate_unregister_notifier (struct notifier_block *nb);#else /* needed for COMPILE_TEST */ static inline bool tegra_pmc_core_domain_state_synced (void ) {return false; } + +static inline int +tegra_pmc_powergate_register_notifier (struct notifier_block *nb) +{ +return -ENOSYS ; +} + +static inline int +tegra_pmc_powergate_unregister_notifier (struct notifier_block *nb) +{ +return -ENOSYS ; +}#endif #endif /* __SOC_TEGRA_PMC_H__ */
Signature · 1 line
2.56.1
PATCH v2 6/6 watchdog: tegra20_wdt: Stop on VDE power off
In reply to Artur KowalskiA watchdog reset doesn't reset the PMC, and Tegra20's boot ROM hangs after it if the VDE power partition is off. Unless booted with tegra_pmc.vde_always_on=1, the PMC driver powers the partition off when it registers it, and genpd powers it off whenever the VDE is idle. A watchdog started by the bootloader can still catch hangs early during boot, before that happens.
Register a PMC partition power off notifier to stop the watchdog before the VDE partition is powered off for the first time. If the partition is already off, a watchdog left running by the bootloader is stopped instead of taken over. Afterwards the watchdog refuses to start with -EBUSY, as a reset would hang, even if the partition is powered on again. If the notifier can't be registered, the driver warns and keeps the watchdog running.
The notifier runs outside of the watchdog core's locking, so it only stops the hardware, under a mutex shared with the watchdog operations, and leaves the core's state alone. Clearing WDOG_HW_RUNNING there would race with the core, and leak the module and device references the core holds for a running watchdog. The core therefore keeps considering a watchdog stopped this way as running, which shows as follows:
- While the device is closed, the core keeps pinging, which fails without effect, and holds its references, as for any watchdog that can't be stopped. They are released when the driver is unbound.
- Opening the device fails with -EBUSY, as the core pings a watchdog it considers running instead of starting it, and starting fails as well.
- If user space has the device open, keepalives and timeout changes fail with -EBUSY, so it finds out that the watchdog is gone.
Stopping is the default. With tegra_pmc.vde_always_on=1, the partition is never powered off, so the watchdog stays usable. Booting with tegra20_wdt.stop_on_vde_off=0 also keeps it usable, but at the risk of the system hanging instead of rebooting.
The watchdog is stopped even with nowayout, as a watchdog that can't reset the system is of no use. Booting with tegra20_wdt.stop_on_vde_off=0 keeps a nowayout watchdog running after the partition is powered off.
--- Documentation/watchdog/watchdog-parameters.rst | 5 + drivers/watchdog/tegra20_wdt.c | 184 ++++++++++++++++++++++--- 2 files changed, 170 insertions(+), 19 deletions(-)
Documentation/watchdog/watchdog-parameters.rst +5 -0
@@ -609,6 +609,11 @@ tegra20_wdt: nowayout: Watchdog cannot be stopped once started (default=kernel config parameter) + stop_on_vde_off: + Stop the watchdog for good when the VDE partition is powered + off, as a reset would hang the boot ROM. This takes precedence + over nowayout. Booting with tegra_pmc.vde_always_on=1 keeps the + partition, and with it the watchdog, usable (default=1) -------------------------------------------------
drivers/watchdog/tegra20_wdt.c +165 -19
263 lines not on this page · raw message
Signature · 1 line
2.56.1