From patchwork Fri Aug 25 10:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 716995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B89A1C71133 for ; Fri, 25 Aug 2023 10:26:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230439AbjHYK00 (ORCPT ); Fri, 25 Aug 2023 06:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244407AbjHYKZ6 (ORCPT ); Fri, 25 Aug 2023 06:25:58 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EBEA213C; Fri, 25 Aug 2023 03:25:55 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6bc57401cb9so113958a34.0; Fri, 25 Aug 2023 03:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692959154; x=1693563954; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lChd/SApErGIwbFJ4qqX7l4KF8OgUcq2GE8XgvnXy8g=; b=nKFmeiC+68/cXbnNU/dCC08Eb25EPsfmBdqzDEppzu1+dkqW9d2Pliv/PuRY5Y88Pk TOPB98C1UXa318lT3u5aLXZayyhunKfMQnq6cOdISAUX4qCuliRXw9iqOHr8ys2l9NgV Zv9iv1CdRhh9KnHD/4DHAJnB9TzTbrWuMCqDm0FnnWOLOH3eDnqyvuL8IXd5kCSIYOcl bDU/WlWGBwKA0W74bYZUnFPv/lbHnvCKRr4GHB37Fyn96XFTK3c1FeWH1NiQZoUY/yMG JZD062TPtRHz+VYwCin96SiQeqC7j9bXCto8ZRTx/UFjIzSyM1jiBby0/JcSCqgQaCCp qfug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692959154; x=1693563954; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lChd/SApErGIwbFJ4qqX7l4KF8OgUcq2GE8XgvnXy8g=; b=F2IG3rHtQKc+ZaQB8IFoiy/RsL2lIbgmHeOlYrXdq8hjoFNF5/SVYVUh5XH8dDWhb2 rvH/POS8sMp8BhnTDGszVnX1RkP4/imGSCZGcMX/JyRFR+GHhWduoIMOWafbKq+40wQy dgsbsffJ4LKzD7SPk+Jag8aOfWze8sYDqy70RmNPDBg0ea33vpc7LOqW4tjsSQmCgglW Kz56wJE7UNTF0kJTdu9DSAFn9fRkJxxAjVOE0AD6YYocA4kUd3gcFLJopoYDgyahS+a6 m8n2fwUTlKN6UsjBbnxLQmiO4RUj8Uu4fXaHeDKhAZuFpNkV9PEFy/+VQRqJPEM0H9sh CdTw== X-Gm-Message-State: AOJu0YzgjM95yQ9QNH+ipIybZnxMZyy3sXEgOxpage4Ka6WVv1YgLJWV r2CTCOPyolSWAqaE/rh4QLlij30vP1w= X-Google-Smtp-Source: AGHT+IHWPt4qLGFrEuR4p/3V/GdcPng6db4OjyXoOgFLvVBiQfoPtK+uNfbKj9toAxamYnGYlb8tXg== X-Received: by 2002:a05:6870:ecab:b0:1c8:bbd0:2fd5 with SMTP id eo43-20020a056870ecab00b001c8bbd02fd5mr22645791oab.4.1692959154289; Fri, 25 Aug 2023 03:25:54 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:3d89:37d3:ba11:1a82]) by smtp.gmail.com with ESMTPSA id eb37-20020a056870a8a500b001bf3942ea12sm835916oab.1.2023.08.25.03.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 03:25:53 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: rafael@kernel.org, amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 1/4] dt-bindings: thermal-zones: Document critical-action Date: Fri, 25 Aug 2023 07:24:50 -0300 Message-Id: <20230825102453.836627-1-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Fabio Estevam Document the critical-action property to describe the thermal action that will be taken after the critical temperature is reached. The possible values are: - 0 for shutdown - 1 for reboot. Signed-off-by: Fabio Estevam --- .../devicetree/bindings/thermal/thermal-zones.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml index 4f3acdc4dec0..782cbb4ea487 100644 --- a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml +++ b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml @@ -75,6 +75,14 @@ patternProperties: framework and assumes that the thermal sensors in this zone support interrupts. + critical-action: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The action that happens after the critical temperature is reached. + Possible values are 0 for shutdown and 1 for reboot. + + enum: [ 0, 1 ] + thermal-sensors: $ref: /schemas/types.yaml#/definitions/phandle-array maxItems: 1 From patchwork Fri Aug 25 10:24:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 716994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B6F7C7EE2C for ; Fri, 25 Aug 2023 10:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233066AbjHYK02 (ORCPT ); Fri, 25 Aug 2023 06:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244443AbjHYK0A (ORCPT ); Fri, 25 Aug 2023 06:26:00 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62CC4133; Fri, 25 Aug 2023 03:25:58 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6b9cd6876bbso206469a34.1; Fri, 25 Aug 2023 03:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692959157; x=1693563957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ntf6JA+P5dpC/3bqOCAKPhfBurn0ifYQdRA9x9uRYg0=; b=ietbD9kxagmUtMnNbFI5lWai+oO/kM6n021A+7tdwSjWIamoYORmgKO+xNYCuV6r0B hUI0GeatdKemWWhXVa9paaaHpYBpkABbKeiIdlxAob9Uc7ZXoktcyaY7g9YbCoWmfb0H ZuCAUCukKmDWt9hT0ZjJ9RUBODIXhwivIvjdlAfhfJGh4OX0hlK+RitX8797HsTgllsh 9pTVmUuTv0Uc1eH8rLs4Jc18Q/OFK9p40AAvQg/kiuCBWyVYuzZhq+xDVJ33DRrhDmTL K3ktYpqEDIeVRKUOyhVHzsaDhgKbflMuK+5F6SeVxqN7RcJh2QsZ0usjDZRQn8FyYZA+ 6rHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692959157; x=1693563957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ntf6JA+P5dpC/3bqOCAKPhfBurn0ifYQdRA9x9uRYg0=; b=cS5UKe9LsTevT14KvWHZBh8xhme+O9/gMIWpVgJeBGbwbQsHoVSXZ9RpWOT4MNGhJu axCy65IE9zIjpIfCoEJkoL0RaXbVYES11kSCFnSXB828TnUkqPwSBgrL9fUMw5JxD07n PbqaafNeNFZAerCLgwyKkHAEyaL+bKcwim3Wp3Sa3JLr9BlYkqWCL4kXFcI5VFnnQRkP VGlcfXpoU9dfI+oLlULzliTwTQQPZsYfjKslzJtEeXVG7QsYXAEsiBnb14O/QrolWO0t SXfupl9DKJ60sRb6odn5KO/Ad5Fi7B5fKKY4k973azPfd8CIXfCd5TuxMJ5XahUtGbh9 SzXQ== X-Gm-Message-State: AOJu0YxDD+OsUxQ+nDdyJYIxCmqhPSRFu6A0QfqOjaLvr0YEUGk42u4l zB3Q/H+F0ythfuBcuJkXJLY= X-Google-Smtp-Source: AGHT+IFEPFQvXpJrczk9dQqXOB4grI+8VhmvADJ0rNgOY96aEWTQCNaPJ4zglYJdJnqTH6ho0F6drQ== X-Received: by 2002:a05:6870:5688:b0:1a7:f79c:2fbc with SMTP id p8-20020a056870568800b001a7f79c2fbcmr19860993oao.0.1692959157411; Fri, 25 Aug 2023 03:25:57 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:3d89:37d3:ba11:1a82]) by smtp.gmail.com with ESMTPSA id eb37-20020a056870a8a500b001bf3942ea12sm835916oab.1.2023.08.25.03.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 03:25:57 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: rafael@kernel.org, amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 2/4] dt-bindings: thermal: Document the values for the 'critical-action' Date: Fri, 25 Aug 2023 07:24:51 -0300 Message-Id: <20230825102453.836627-2-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230825102453.836627-1-festevam@gmail.com> References: <20230825102453.836627-1-festevam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Fabio Estevam Document the possible values for the 'critical-action' property to make it more readable in the devicetree. Signed-off-by: Fabio Estevam --- include/dt-bindings/thermal/thermal.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/dt-bindings/thermal/thermal.h b/include/dt-bindings/thermal/thermal.h index bc7babb1a67c..f433b6b0ffb7 100644 --- a/include/dt-bindings/thermal/thermal.h +++ b/include/dt-bindings/thermal/thermal.h @@ -12,5 +12,9 @@ /* On cooling devices upper and lower limits */ #define THERMAL_NO_LIMIT (~0) +/* Possible values for the 'critical-action' property */ +#define THERMAL_CRITICAL_ACTION_SHUTDOWN 0 +#define THERMAL_CRITICAL_ACTION_REBOOT 1 + #endif From patchwork Fri Aug 25 10:24:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 717278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEB2AC3DA6F for ; Fri, 25 Aug 2023 10:26:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236587AbjHYK03 (ORCPT ); Fri, 25 Aug 2023 06:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244486AbjHYK0G (ORCPT ); Fri, 25 Aug 2023 06:26:06 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59A2C19A0; Fri, 25 Aug 2023 03:26:01 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6bc57401cb9so113983a34.0; Fri, 25 Aug 2023 03:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692959160; x=1693563960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iLr5gK3Lt46knsg3WNaCXteFlAoEoVQYH/7az4C+2/c=; b=qsdKwZRbm3hkdgX6kSfwJ0zI1Xc2UQOzpf5hgfvFh/OG9Z5Xv5RY27B1MUi8rDdglt C1C9bkHOR/jlPOjy1oDaiXFacGrM8StXyGTzAWZBMOeM/DKz/P+HvmiagcYtbBCcULBb Sp4zdQ/4AubMNSiFybmN9PxJk7JvGpXK3SQrs/dut6L+/zIDPGzD2WsYC3y2heswXYUG j4EgOCsrC3KxTmcUrG6qFOidPm0FZlqf/YdOZDVHdZehIr4Z7HjdImpa4B0z+fOl6fLZ ciSz2ri9HlZ4tuSGGe/EXmoexNzmrmccywrP5ynFTt3/PiXThycatpMORTnty3aQdKIp jEAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692959160; x=1693563960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iLr5gK3Lt46knsg3WNaCXteFlAoEoVQYH/7az4C+2/c=; b=LGtzZ+AK+wTiDKSmRnWizMTTnSp6H1ynouTNuKVAcwYHl+f+9YgUsekp68FmI7rG+L jklz1U1jYk3R2+RntvHWeqVuvjc4W7EgGXFzOzHY5eVsK8FKB6q8Vb++domtQ/GtfsEK //b1gEaT6QIsZe6aCFSpOuymbO1KNGU92I/wbDnCw7L42qXAznjRYvX87GlUYDsB9mOF Ohlg/mCTdl8kqOwtukAdEqGsepp0/Xiny0Xi1epMqGGvt6p9fPLPEnw7wuUCO8Fv17O/ Gtt3vcoBjYF1EotZwWFZdcW8OAxcP9Wrt3yHW0QXez/M5iXKNb+C3JGe90BfbjU0tHOg 6PbQ== X-Gm-Message-State: AOJu0YxNNGyhaxW2YrsW4VY1G0dyCewO8tRyqrovabppEpHtp5RgSBN8 kQ53RWxvEmYZ9OkByNa1mlE= X-Google-Smtp-Source: AGHT+IHW/+GUt9rsqBDwf3dvc4xtAyQgSgmNc8mOvgp5o+7JqJR+Xtyw1Y8aLU2OR796fXy4RXgDag== X-Received: by 2002:a05:6870:ecab:b0:1c8:bbd0:2fd5 with SMTP id eo43-20020a056870ecab00b001c8bbd02fd5mr22645989oab.4.1692959160592; Fri, 25 Aug 2023 03:26:00 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:3d89:37d3:ba11:1a82]) by smtp.gmail.com with ESMTPSA id eb37-20020a056870a8a500b001bf3942ea12sm835916oab.1.2023.08.25.03.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 03:26:00 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: rafael@kernel.org, amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 3/4] reboot: Introduce hw_protection_reboot() Date: Fri, 25 Aug 2023 07:24:52 -0300 Message-Id: <20230825102453.836627-3-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230825102453.836627-1-festevam@gmail.com> References: <20230825102453.836627-1-festevam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Fabio Estevam Introduce hw_protection_reboot() to trigger an emergency reboot. It is a counterpart of hw_protection_shutdown() with the difference that it will force a reboot instead of shutdown. The motivation for doing this is to allow the thermal subystem to trigger a reboot when the temperature reaches the critical temperature. Signed-off-by: Fabio Estevam --- include/linux/reboot.h | 1 + kernel/reboot.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 2b6bb593be5b..4a319bc24f6a 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -174,6 +174,7 @@ void ctrl_alt_del(void); extern void orderly_poweroff(bool force); extern void orderly_reboot(void); +void hw_protection_reboot(const char *reason, int ms_until_forced); void hw_protection_shutdown(const char *reason, int ms_until_forced); /* diff --git a/kernel/reboot.c b/kernel/reboot.c index 3bba88c7ffc6..64517d1e4c55 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -952,6 +952,40 @@ static void hw_failure_emergency_poweroff(int poweroff_delay_ms) msecs_to_jiffies(poweroff_delay_ms)); } +/** + * hw_protection_reboot - Trigger an emergency system reboot + * + * @reason: Reason of emergency reboot to be printed. + * @ms_until_forced: Time to wait for orderly reboot before tiggering a + * forced reboot. Negative value disables the forced + * reboot. + * + * Initiate an emergency system reboot in order to protect hardware from + * further damage. Usage examples include a thermal protection. + * + * NOTE: The request is ignored if protection reboot is already pending even + * if the previous request has given a large timeout for forced reboot. + * Can be called from any context. + */ +void hw_protection_reboot(const char *reason, int ms_until_forced) +{ + static atomic_t allow_proceed = ATOMIC_INIT(1); + + pr_emerg("HARDWARE PROTECTION reboot (%s)\n", reason); + + /* Reboot should be initiated only once. */ + if (!atomic_dec_and_test(&allow_proceed)) + return; + + /* + * Queue a backup emergency reboot in the event of + * orderly_reboot failure + */ + hw_failure_emergency_poweroff(ms_until_forced); + orderly_reboot(); +} +EXPORT_SYMBOL_GPL(hw_protection_reboot); + /** * hw_protection_shutdown - Trigger an emergency system poweroff * From patchwork Fri Aug 25 10:24:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 717277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E348BEE49AD for ; Fri, 25 Aug 2023 10:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238248AbjHYK0a (ORCPT ); Fri, 25 Aug 2023 06:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244533AbjHYK0S (ORCPT ); Fri, 25 Aug 2023 06:26:18 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF14910FE; Fri, 25 Aug 2023 03:26:04 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6b9da57da6bso156806a34.0; Fri, 25 Aug 2023 03:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692959164; x=1693563964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A9azgcCXgqiRFUl4vyzLhtNKVKo7gKBAaH9EMvhMpt4=; b=XRhOaQPAl+L3XziAPcFs54/7EiNlc4yq6eRhzTEilcz2Eywmj7ZgZ2GhMD17V+R5Rk kW0FRS0isgOLsl9JM5yL19/1ne2oXI3z1KgvhEpk5VDhhXk0jRYMuVocsRrFp3gpVIi9 lT3A6JLuqevJbnH628cb81WIWp+zHODcx9Fn904Qi3q8IkhDQZ2Raglp2N4lam9mcAMv cODCRr19efyW/juo/XuE+8t7ZxgMz1qM/Vyy6Xs10WpnSqIsk/uvFhstwJwtzRGA4H87 mLXZXGAZuNo034+eY2zvmD3gA4xI1dx0OdZAH6UQh8o8gpmZWshTOE+D3FEy5402UOUz bukg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692959164; x=1693563964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A9azgcCXgqiRFUl4vyzLhtNKVKo7gKBAaH9EMvhMpt4=; b=KusU9/WYDTisLHzkHNdMQU0M2zJBkVKA7eFPSzHmsIUS7h5yhl3nm8Vk2l/Pu0gGog 5nR+PJMPyNszc6VhVLvbyVxJVLRlVVZ2hNYhig+hWQ0D40EqyXhxpltOF9318Jir68GN jxa3x+DaJEYA9SuSNyWkrvXLitdKgE0QkOTyp2BazxYpmHswX+1gPtU0mbJr2/80qFRl HpOMiCAd9tP21e0etWUH+TUFQEqqmaSQoRe48D7mYLCvsnXg/HUGa5lYDHRHU1TB2q0V /Vw5iLjhqAeWEiGU0t8YT2hhxePhBcsftGw5aqIaUvvc/b+aUMlf+hj5Ry5dh/Iqrd0l Eq3g== X-Gm-Message-State: AOJu0YxBgYoxCiZUfVnLk2lmprGa5KulQDP04PtqMVA6eqvP4VMujwqb W/OutCP0n/9pypO5VFFlTdY= X-Google-Smtp-Source: AGHT+IGRE3xdG9eJUNQkncvKw8mh3uS6wgVtC/h7H4Mesn6ZdUH0yOkkT8ycHg9qcwLTE3iYRoxg/Q== X-Received: by 2002:a05:6870:6124:b0:1b7:5e47:5b75 with SMTP id s36-20020a056870612400b001b75e475b75mr19769452oae.4.1692959163924; Fri, 25 Aug 2023 03:26:03 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:3d89:37d3:ba11:1a82]) by smtp.gmail.com with ESMTPSA id eb37-20020a056870a8a500b001bf3942ea12sm835916oab.1.2023.08.25.03.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 03:26:03 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: rafael@kernel.org, amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 4/4] thermal: thermal_core: Allow rebooting after critical temp Date: Fri, 25 Aug 2023 07:24:53 -0300 Message-Id: <20230825102453.836627-4-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230825102453.836627-1-festevam@gmail.com> References: <20230825102453.836627-1-festevam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Fabio Estevam Currently, the default mechanism is to trigger a shutdown after the critical temperature is reached. In some embedded cases, such behavior does not suit well, as the board may be unattended in the field and rebooting may be a better approach. The bootloader may also check the temperature and only allow the boot to proceed when the temperature is below a certain threshold. Introduce support for allowing a reboot to be triggered after the critical temperature is reached. If the "critical-action" devicetree property is not found, fall back to the shutdown action to preserve the existing default behavior. Tested on a i.MX8MM board with the following devicetre changes: thermal-zones { cpu-thermal { critical-action = ; }; }; Signed-off-by: Fabio Estevam --- drivers/thermal/thermal_core.c | 8 +++++++- drivers/thermal/thermal_of.c | 17 ++++++++++++++--- include/linux/thermal.h | 6 ++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index cc2b5e81c620..3f4ea27560f8 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -320,11 +320,17 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) * Its a must for forced_emergency_poweroff_work to be scheduled. */ int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS; + void (*hw_protection_action)(const char *reason, int ms_until_forced); dev_emerg(&tz->device, "%s: critical temperature reached, " "shutting down\n", tz->type); - hw_protection_shutdown("Temperature too high", poweroff_delay_ms); + hw_protection_action = hw_protection_shutdown; + + if (tz->action == THERMAL_CRITICAL_ACTION_REBOOT) + hw_protection_action = hw_protection_reboot; + + hw_protection_action("Temperature too high", poweroff_delay_ms); } EXPORT_SYMBOL(thermal_zone_device_critical); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 330690a3a208..36a2c82d3405 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -218,7 +218,8 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int return tz; } -static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdelay) +static int thermal_of_monitor_init(struct device_node *np, int *delay, + int *pdelay, int *critical_action) { int ret; @@ -234,6 +235,14 @@ static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdel return ret; } + /* + * If the "critical-action" property is not found, fall back to + * the shutdown action to keep the existing behavior. + */ + ret = of_property_read_u32(np, "critical-action", critical_action); + if (ret < 0) + *critical_action = THERMAL_CRITICAL_ACTION_SHUTDOWN; + return 0; } @@ -471,7 +480,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * struct thermal_zone_params tzp = {}; struct thermal_zone_device_ops *of_ops; struct device_node *np; - int delay, pdelay; + int delay, pdelay, critical_action; int ntrips, mask; int ret; @@ -494,7 +503,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * goto out_kfree_of_ops; } - ret = thermal_of_monitor_init(np, &delay, &pdelay); + ret = thermal_of_monitor_init(np, &delay, &pdelay, &critical_action); if (ret) { pr_err("Failed to initialize monitoring delays from %pOFn\n", np); goto out_kfree_trips; @@ -516,6 +525,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * goto out_kfree_trips; } + tz->action = critical_action; + ret = thermal_zone_device_enable(tz); if (ret) { pr_err("Failed to enabled thermal zone '%s', id=%d: %d\n", diff --git a/include/linux/thermal.h b/include/linux/thermal.h index dee66ade89a0..48f29ab16218 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -34,6 +34,11 @@ struct thermal_cooling_device; struct thermal_instance; struct thermal_attr; +enum thermal_action { + THERMAL_CRITICAL_ACTION_SHUTDOWN, /* shutdown when crit temperature is reached */ + THERMAL_CRITICAL_ACTION_REBOOT, /* reboot when crit temperature is reached */ +}; + enum thermal_trend { THERMAL_TREND_STABLE, /* temperature is stable */ THERMAL_TREND_RAISING, /* temperature is raising */ @@ -185,6 +190,7 @@ struct thermal_zone_device { struct list_head node; struct delayed_work poll_queue; enum thermal_notify_event notify_event; + enum thermal_action action; }; /**