From nobody Sun Apr 12 13:35:53 2026 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 579C9C4708E for ; Wed, 4 Jan 2023 01:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233962AbjADBPj (ORCPT ); Tue, 3 Jan 2023 20:15:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238350AbjADBPa (ORCPT ); Tue, 3 Jan 2023 20:15:30 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F94717066 for ; Tue, 3 Jan 2023 17:15:29 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id a1-20020a056a001d0100b0057a6f74d7bcso14870934pfx.1 for ; Tue, 03 Jan 2023 17:15:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mtD8husdIdX8frEf87nd1VCmyju2z3AAnwArL0f2tyQ=; b=Q7S++mu/KIn18rahpCG9MwKvaZ9uHew8s0cbLbJbebMmMd9u9iEwBVWMh9l5vquXUg q0ttNr9bvEJEXMhsqmtkrwa+z5iymltBuj6AK/T40tt4kZmAh3FRgcq11HtXJ1u5shN1 V1xlrJAHdDjnP303txqESGoiwuXpklvksk9UIIcM6ZRRW6sOWyAmFs2T1dhR7+Sk5YcH VzKmX36TtSXCbOnhEvbObgXsmDlpu6teqHVNTbF8tMKcoEMGx+DWuh5xvrQAvWXg0Kr/ 2OQGkDDO0nR6F2beZU32KKPuvEPaU0lpshckOUNnlOw/X1A7bUI1Sg54Xst0JGIwHumI 53xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mtD8husdIdX8frEf87nd1VCmyju2z3AAnwArL0f2tyQ=; b=JdxElg/JVzEqb9zwnOI7c7MIJKKp49/yMJnp8GFyIntEh3LR9mEE15voBSCgUi1VLm ESpjWY8FP6nFQ3t06FPYL8a2LJSEZrhHH1XCZ3e1Bq9p5LaSNjXijoytC7MvAbHpqN61 Gkka7qBoRGnPvzGByPSUV9DoYwk1PHAWcnEjExDVkyzMRoGJVcw/zSa5UpEyjqWEQtO+ /sUo1UY378srDcJhIHpg7n8V4ybRWhjxy58AhSz6BfcgghjVpufXpLiPBiurKdbdzUfw EVn8sbiCjPUzFi9AJyvXJ4NwdRhWBr43qtYAQ6kd+UF0wsYjZSPSXS8feuxsdyxl8T+l a3mg== X-Gm-Message-State: AFqh2kpx/HHJyhuIi6QpG+m1t+3IwaEgYpBPcjgrK6AVX2yLXw61cEWE kRom5gAghSRFfjtuXMzGj8Rhjg2T3kYOc+w= X-Google-Smtp-Source: AMrXdXuwLpGlApYoxwzl8NZqS+fhRZdhxTeBTrJkIe/NFknBjsLe50Lyfk6qQwpyi4OT4ignAqtCIQqdWqAZ+co= X-Received: from robbarnes3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:6451]) (user=robbarnes job=sendgmr) by 2002:a17:90a:e586:b0:221:684a:d076 with SMTP id g6-20020a17090ae58600b00221684ad076mr4131093pjz.4.1672794928809; Tue, 03 Jan 2023 17:15:28 -0800 (PST) Date: Wed, 4 Jan 2023 01:15:23 +0000 In-Reply-To: <20230104011524.369764-1-robbarnes@google.com> Mime-Version: 1.0 References: <20230104011524.369764-1-robbarnes@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230104011524.369764-2-robbarnes@google.com> Subject: [PATCH v3 1/2] platform/chrome: cros_ec: Poll EC log on EC panic From: Rob Barnes To: groeck@chromium.org, pmalani@chromium.org Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, dtor@chromium.org, Rob Barnes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add handler for CrOS EC panic events. When a panic is reported, immediately poll for EC log. This should result in the log leading to the EC panic being preserved. ACPI_NOTIFY_CROS_EC_PANIC is defined in coreboot at https://review.coreboot.org/plugins/gitiles/coreboot/+/refs/heads/master/sr= c/ec/google/chromeec/acpi/ec.asl Signed-off-by: Rob Barnes Reviewed-by: Prashant Malani --- Changelog since v1: - Split into two patches - Moved panic handle before mkbp loop - Switched to dev_emerg message drivers/platform/chrome/cros_ec_debugfs.c | 23 +++++++++++++++++++++ drivers/platform/chrome/cros_ec_lpc.c | 7 +++++++ include/linux/platform_data/cros_ec_proto.h | 9 ++++++++ 3 files changed, 39 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/c= hrome/cros_ec_debugfs.c index 21d973fc6be2..34f7b46f8761 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -49,6 +49,7 @@ struct cros_ec_debugfs { struct delayed_work log_poll_work; /* EC panicinfo */ struct debugfs_blob_wrapper panicinfo_blob; + struct notifier_block notifier_panic; }; =20 /* @@ -437,6 +438,22 @@ static int cros_ec_create_panicinfo(struct cros_ec_deb= ugfs *debug_info) return ret; } =20 +static int cros_ec_debugfs_panic_event(struct notifier_block *nb, + unsigned long queued_during_suspend, void *_notify) +{ + struct cros_ec_debugfs *debug_info =3D + container_of(nb, struct cros_ec_debugfs, notifier_panic); + + if (debug_info->log_buffer.buf) { + /* Force log poll work to run immediately */ + mod_delayed_work(debug_info->log_poll_work.wq, &debug_info->log_poll_wor= k, 0); + /* Block until log poll work finishes */ + flush_delayed_work(&debug_info->log_poll_work); + } + + return NOTIFY_DONE; +} + static int cros_ec_debugfs_probe(struct platform_device *pd) { struct cros_ec_dev *ec =3D dev_get_drvdata(pd->dev.parent); @@ -473,6 +490,12 @@ static int cros_ec_debugfs_probe(struct platform_devic= e *pd) debugfs_create_u16("suspend_timeout_ms", 0664, debug_info->dir, &ec->ec_dev->suspend_timeout_ms); =20 + debug_info->notifier_panic.notifier_call =3D cros_ec_debugfs_panic_event; + ret =3D blocking_notifier_chain_register(&ec->ec_dev->panic_notifier, + &debug_info->notifier_panic); + if (ret) + goto remove_debugfs; + ec->debug_info =3D debug_info; =20 dev_set_drvdata(&pd->dev, ec); diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrom= e/cros_ec_lpc.c index 7fc8f82280ac..5738f1d25091 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -320,6 +320,13 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device= , u32 value, void *data) =20 ec_dev->last_event_time =3D cros_ec_get_time_ns(); =20 + if (value =3D=3D ACPI_NOTIFY_CROS_EC_PANIC) { + dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!"); + blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev); + /* Do not query for other events after a panic is reported */ + return; + } + if (ec_dev->mkbp_event_supported) do { ret =3D cros_ec_get_next_event(ec_dev, NULL, diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/pl= atform_data/cros_ec_proto.h index e43107e0bee1..7fb2196f99b0 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -41,6 +41,13 @@ #define EC_MAX_REQUEST_OVERHEAD 1 #define EC_MAX_RESPONSE_OVERHEAD 32 =20 +/* + * EC panic is not covered by the standard (0-F) ACPI notify values. + * Arbitrarily choosing B0 to notify ec panic, which is in the 84-BF + * device specific ACPI notify range. + */ +#define ACPI_NOTIFY_CROS_EC_PANIC 0xB0 + /* * Command interface between EC and AP, for LPC, I2C and SPI interfaces. */ @@ -176,6 +183,8 @@ struct cros_ec_device { /* The platform devices used by the mfd driver */ struct platform_device *ec; struct platform_device *pd; + + struct blocking_notifier_head panic_notifier; }; =20 /** --=20 2.39.0.314.g84b9a713c41-goog From nobody Sun Apr 12 13:35:53 2026 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 ABEC6C3DA7D for ; Wed, 4 Jan 2023 01:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234098AbjADBPm (ORCPT ); Tue, 3 Jan 2023 20:15:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238454AbjADBPb (ORCPT ); Tue, 3 Jan 2023 20:15:31 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB0E917584 for ; Tue, 3 Jan 2023 17:15:30 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id a33-20020a630b61000000b00429d91cc649so14459158pgl.8 for ; Tue, 03 Jan 2023 17:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=f9rrPHtsDc664z8TlUhfeZ6o7/ZdnXcwK2CIJxHNuXg=; b=lRbVHoFQeHjsrzoHSmWlciMBX0cP/lBE/dgu3vX7qZ+C6TtDOl1WXGf1EO6iOIFWvG CRNkt1xKVWral6U8KW+RYgoS1G3Pv5DaUYpKG0blqxPtaaaf6nVxiZKrXcSeUx0A0abL G8+UhncS76rk/5fXhKI5d+LNkzg9eARkJ+47lSatGGZKl+rGjYETyC/EsDVxLEU7BfAL hUgEQSDc+uRXWpr3EQltY0jbZb4jgx1mJVLdmY8r8VO42Pa4eKs3RbyfWny54L9Bjjke ibqy8svP21PduGY0TidtzmTYEcsGY4bTEOfcabj8x+ZbxZvHQL7swEkRB0u4GYeRt8kp ySOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f9rrPHtsDc664z8TlUhfeZ6o7/ZdnXcwK2CIJxHNuXg=; b=Hyy6VNkUU27OGofys/hD2knThwtPzKWfb1hYptBt0ncPXHPpUbCfH5CWmmHyF7hYYm +UKd6+R+9GjsJOTyt6MEE0eN4OIYZTCwr4ccouHWAIXXypt+JwKxe/csNuOqRcY+6YBL k+X8mLKFXNwUTlkqytZerSIIIDJ672z1MAn1h0OpFzn3DdG+CKnnK2/HD/jjsHBzsFQG eRnvi3jFhDLdIhsl7x8f+9ndlU8Z5Y2xBqTEHAWpK5Fak52kmrdPaesOg4RS6NSzgQYa eMNohfvfywFw7bVGXo6mFwk0Nk5K1PY4hPCuaY1X5KNP+i+ZkAP1eSgnNDikfGAk+RV0 3TMA== X-Gm-Message-State: AFqh2kpVsQVhb9EhUlo/jeLQv43yxu/tk92vk36BBdvcMINKtdmCOHDj DBTQuE6Y8zdQ4UIRtZQ/4bpAWijgJeKmY9w= X-Google-Smtp-Source: AMrXdXtxmw9aguwDjJUz2htfsETgY4/yJbUjCtMyJXjunBRVCVyRNyKHSYsD8vefQjOZW6BtGbFgSctk+4wUdjk= X-Received: from robbarnes3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:6451]) (user=robbarnes job=sendgmr) by 2002:a62:6003:0:b0:575:e44e:3e0 with SMTP id u3-20020a626003000000b00575e44e03e0mr3301718pfb.53.1672794930240; Tue, 03 Jan 2023 17:15:30 -0800 (PST) Date: Wed, 4 Jan 2023 01:15:24 +0000 In-Reply-To: <20230104011524.369764-1-robbarnes@google.com> Mime-Version: 1.0 References: <20230104011524.369764-1-robbarnes@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230104011524.369764-3-robbarnes@google.com> Subject: [PATCH v3 2/2] platform/chrome: cros_ec: Shutdown on EC Panic From: Rob Barnes To: groeck@chromium.org, pmalani@chromium.org Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, dtor@chromium.org, Rob Barnes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When an EC panic is reported, attempt an orderly shutdown. Force a shutdown after a brief timeout if the orderly shutdown fails for any reason. Using the common hw_protection_shutdown utility function since an EC panic has the potential to cause hw damage. This is all best effort. EC should also force a hard reset after a short timeout. Signed-off-by: Rob Barnes Reviewed-by: Prashant Malani --- Changelog since v1: - Split into two patches drivers/platform/chrome/cros_ec_lpc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrom= e/cros_ec_lpc.c index 5738f1d25091..3708fa75feb1 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include =20 #include "cros_ec.h" @@ -323,6 +324,8 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device,= u32 value, void *data) if (value =3D=3D ACPI_NOTIFY_CROS_EC_PANIC) { dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!"); blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev); + /* Begin orderly shutdown. Force shutdown after 1 second. */ + hw_protection_shutdown("CrOS EC Panic", 1000); /* Do not query for other events after a panic is reported */ return; } --=20 2.39.0.314.g84b9a713c41-goog