From patchwork Thu Mar 7 03:36:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linu Cherian X-Patchwork-Id: 13585031 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 642EBC54E41 for ; Thu, 7 Mar 2024 03:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gHj4QP2G4sGbp24ND5fAMeuVZDGZEbq0rs4bG25dkew=; b=nOWMvqjwQGlOl0 6rSC9kgFUkKsXzGyaZK6m+Il8aALn44fscURz/5FAfPDWFUfDWpRti0diBPv0GNGZipStCUEY4UPz b0nNtacWBzXj65h+DqAvbL6+xmPQ5GaubnP8Unn28yPKAIpop1ycMNtmBcxiyNlNCVAPE/JKPqQ4z wqGTnhcqrZc3Q4Vz1WESPONJ2fnWRdOrkawOyHlGHCEcKKoYIaByP84Yxm5I7gUiNyxyXUEG63yOM +tlJ4jcDOJAGSiJ+IqViz1ECYwX31nQzaAhYtrOUXP4VHaKIknwq+2jIc1l2cg/KNlpB4l1TlVjSj kgW3P/VVCiOP2hwwQ2RA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ri4ZF-00000002qsk-0gsK; Thu, 07 Mar 2024 03:37:13 +0000 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ri4Z7-00000002qq5-05pm for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2024 03:37:07 +0000 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 427129k2031657; Wed, 6 Mar 2024 19:36:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= pfpt0220; bh=XGbkZPV1JVkizVUt8II3CM1DI3YOn0sCKE5pBrzqqCY=; b=jPq Oo7UsKMxU61oycoV6BlgZIs4Kw9AS/YULoZMCkxFVBQZ1BF/DQufakDp9mEycXTB Mhj0adLhANyNjsjeYKQQG9ritiG62jjOQ33htB58Lkphbi/u8xqRTnewSJcB2wHz O7eWiFKv9wwH2DlV6vcZEUcE3tVowkaB+fA/LxV9xYl9nV+qVRK8RToMP4zhnBLH YSnd2U/i/VDjTMiMg8OrZpRKQ9n8zYTQR/YPQqgAHfGBLF33KLAVQFkXploh9SSm WXjWiBNDWIzcMAUIDwl7yCboofdZZylYAyp2A5rHmhZ6YaxetU5GHoswNMFnsvWW U9B4WIbEhIa4gKbFNkw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3wq3jfrdh9-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Mar 2024 19:36:53 -0800 (PST) Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Wed, 6 Mar 2024 19:36:52 -0800 Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 6 Mar 2024 19:36:52 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Wed, 6 Mar 2024 19:36:52 -0800 Received: from virtx40.. (unknown [10.28.34.196]) by maili.marvell.com (Postfix) with ESMTP id E139F3F707F; Wed, 6 Mar 2024 19:36:47 -0800 (PST) From: Linu Cherian To: , , , CC: , , , , , , , , , Linu Cherian Subject: [PATCH v7 3/7] coresight: core: Add provision for panic callbacks Date: Thu, 7 Mar 2024 09:06:21 +0530 Message-ID: <20240307033625.325058-4-lcherian@marvell.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240307033625.325058-1-lcherian@marvell.com> References: <20240307033625.325058-1-lcherian@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 4DWl-SXKgRdEcCgCS_rc_Dh5Z5Edttth X-Proofpoint-ORIG-GUID: 4DWl-SXKgRdEcCgCS_rc_Dh5Z5Edttth X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-06_14,2024-03-06_01,2023-05-22_02 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240306_193705_222002_03EBFBA8 X-CRM114-Status: GOOD ( 17.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Panic callback handlers allows coresight device drivers to sync relevant trace data and trace metadata to reserved memory regions so that they can be retrieved later in the subsequent boot or in the crashdump kernel. Signed-off-by: Linu Cherian --- Changelog from v6: * Rebase changes w.r.t struct coresight_device drivers/hwtracing/coresight/coresight-core.c | 37 ++++++++++++++++++++ include/linux/coresight.h | 12 +++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index b83613e34289..61d75aad476b 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "coresight-etm-perf.h" #include "coresight-priv.h" @@ -1365,6 +1366,36 @@ const struct bus_type coresight_bustype = { .name = "coresight", }; +static int coresight_panic_sync(struct device *dev, void *data) +{ + int mode; + struct coresight_device *csdev; + + /* Run through panic sync handlers for all enabled devices */ + csdev = container_of(dev, struct coresight_device, dev); + mode = coresight_get_mode(csdev); + + if ((mode == CS_MODE_SYSFS) || (mode == CS_MODE_PERF)) { + if (panic_ops(csdev)) + panic_ops(csdev)->sync(csdev); + } + + return 0; +} + +static int coresight_panic_cb(struct notifier_block *self, + unsigned long v, void *p) +{ + bus_for_each_dev(&coresight_bustype, NULL, NULL, + coresight_panic_sync); + + return 0; +} + +static struct notifier_block coresight_notifier = { + .notifier_call = coresight_panic_cb, +}; + static int __init coresight_init(void) { int ret; @@ -1377,6 +1408,10 @@ static int __init coresight_init(void) if (ret) goto exit_bus_unregister; + /* Register function to be called for panic */ + ret = atomic_notifier_chain_register(&panic_notifier_list, + &coresight_notifier); + /* initialise the coresight syscfg API */ ret = cscfg_init(); if (!ret) @@ -1391,6 +1426,8 @@ static int __init coresight_init(void) static void __exit coresight_exit(void) { cscfg_exit(); + atomic_notifier_chain_unregister(&panic_notifier_list, + &coresight_notifier); etm_perf_exit(); bus_unregister(&coresight_bustype); } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 5f288d475490..b156467c9baa 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -315,6 +315,7 @@ enum cs_mode { #define link_ops(csdev) csdev->ops->link_ops #define helper_ops(csdev) csdev->ops->helper_ops #define ect_ops(csdev) csdev->ops->ect_ops +#define panic_ops(csdev) csdev->ops->panic_ops /** * struct coresight_ops_sink - basic operations for a sink @@ -384,11 +385,22 @@ struct coresight_ops_helper { int (*disable)(struct coresight_device *csdev, void *data); }; + +/** + * struct coresight_ops_panic - Generic device ops for panic handing + * + * @sync : Sync the device register state/trace data + */ +struct coresight_ops_panic { + int (*sync)(struct coresight_device *csdev); +}; + struct coresight_ops { const struct coresight_ops_sink *sink_ops; const struct coresight_ops_link *link_ops; const struct coresight_ops_source *source_ops; const struct coresight_ops_helper *helper_ops; + const struct coresight_ops_panic *panic_ops; }; static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa,