From patchwork Tue Apr 11 09:10:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 97226 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1716860qgd; Tue, 11 Apr 2017 02:11:08 -0700 (PDT) X-Received: by 10.98.212.7 with SMTP id a7mr61012120pfh.34.1491901868552; Tue, 11 Apr 2017 02:11:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c67si1708104pfl.283.2017.04.11.02.11.08; Tue, 11 Apr 2017 02:11:08 -0700 (PDT) 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=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754392AbdDKJLB (ORCPT + 23 others); Tue, 11 Apr 2017 05:11:01 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:34633 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754357AbdDKJK6 (ORCPT ); Tue, 11 Apr 2017 05:10:58 -0400 Received: by mail-pf0-f178.google.com with SMTP id c198so34878321pfc.1 for ; Tue, 11 Apr 2017 02:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FeXqW08LgJf9Qs6dc0s0lWA641oxQtsbriB5wHWToFc=; b=Sdk0Zrkgxc3fLzlMUHUTFS00vMBN2tuY3n+EKC++FSdcoUJXsoUciuqTQ/MmIByJHx to74JiY15a9JemPw8PLgU4Wzg7e9sbuNh1cPCyCVWmj5gQeMEAmgkOZvf8KM99cuDMiV xdzjfYBtxFi91ttzW6O8Aejs/7AYsz2T1dS3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FeXqW08LgJf9Qs6dc0s0lWA641oxQtsbriB5wHWToFc=; b=mi1K/9BP4Doone2O9wcmKvo8ckso+kYVP5RPR088MiT3b7mS40e2M1I+ZmvYM9Ne1C ktxS1T5SptKR/+AUfwYpsHUOv0gwhyipkRnVc5qJv8wD76B0eaUKv3lUHrqtT+M0pkCL gEuAVVM1RCaU2l2ireOHsauXrcjW8aJHpLi+unmhOCXw0EPSPewBjiY4YrgGDxr+6pXL TIX7/EcGaTINM4wxA19GZA+2PRRo0mPLtAVFCkZTY9MbDISTWk2069TuGbdJWrLChG18 TxWYr0nBug7cJ5vqM8vVGbwteTBfU+cCxCM790pSQdXmd9LfutKzTi5RMejxL+bsoD5s t9dQ== X-Gm-Message-State: AFeK/H07KAsWWJ5XKyPDLFC6Sbac+M1XKGqNw3BHNoWA4oVchFMmgP5cthLU3fMj0mkGPqe3 X-Received: by 10.99.120.206 with SMTP id t197mr60220998pgc.21.1491901857385; Tue, 11 Apr 2017 02:10:57 -0700 (PDT) Received: from localhost.localdomain (li1563-109.members.linode.com. [139.162.83.109]) by smtp.gmail.com with ESMTPSA id r77sm8196394pfe.105.2017.04.11.02.10.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 02:10:56 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan , Mike Leach , Suzuki K Poulose Subject: [PATCH RFC 4/4] coresight: tmc: dump RAM for panic Date: Tue, 11 Apr 2017 17:10:29 +0800 Message-Id: <1491901829-18477-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491901829-18477-1-git-send-email-leo.yan@linaro.org> References: <1491901829-18477-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If coresight ETB/ETF have been enabled by 'sysfs' or 'perf' modes and we can rely on panic notifier to save all ETB RAM data into memory. Relies on Kdump, finally the ETB RAM data can be extracted from kernel's vmcore, so we can analyse panic reason from dumped ETB RAM data. Cc: Mathieu Poirier Cc: Mike Leach Cc: Suzuki K Poulose Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-tmc-etf.c | 52 +++++++++++++++++++++++++ drivers/hwtracing/coresight/coresight-tmc.h | 2 + 2 files changed, 54 insertions(+) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 5e709af..bc52cad 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -102,6 +102,47 @@ static void tmc_etb_disable_hw(struct tmc_drvdata *drvdata) CS_LOCK(drvdata->base); } +static int tmc_etb_notify(struct notifier_block *nb, + unsigned long mode, void *_unused) +{ + struct tmc_drvdata *drvdata = container_of(nb, struct tmc_drvdata, + panic_nb); + unsigned long flags; + int ret = 0; + + if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETB && + drvdata->config_type != TMC_CONFIG_TYPE_ETF)) + return -EINVAL; + + spin_lock_irqsave(&drvdata->spinlock, flags); + + /* There is no point in reading a TMC in HW FIFO mode */ + mode = readl_relaxed(drvdata->base + TMC_MODE); + if (mode != TMC_MODE_CIRCULAR_BUFFER) { + ret = -EINVAL; + goto out; + } + + /* If drvdata::buf is NULL the trace data has been read already */ + if (drvdata->buf == NULL) { + ret = -EINVAL; + goto out; + } + + CS_UNLOCK(drvdata->base); + + tmc_flush_and_stop(drvdata); + tmc_etb_dump_hw(drvdata); + + dev_info(drvdata->dev, "Flush ETB buffer 0x%x@0x%p\n", + drvdata->len, drvdata->buf); + + CS_LOCK(drvdata->base); +out: + spin_unlock_irqrestore(&drvdata->spinlock, flags); + return ret; +} + static void tmc_etf_enable_hw(struct tmc_drvdata *drvdata) { CS_UNLOCK(drvdata->base); @@ -245,6 +286,12 @@ static int tmc_enable_etf_sink(struct coresight_device *csdev, u32 mode) if (ret) return ret; + drvdata->panic_nb.notifier_call = tmc_etb_notify; + ret = atomic_notifier_chain_register(&panic_notifier_list, + &drvdata->panic_nb); + if (ret) + return ret; + dev_info(drvdata->dev, "TMC-ETB/ETF enabled\n"); return 0; } @@ -262,6 +309,11 @@ static void tmc_disable_etf_sink(struct coresight_device *csdev) /* Disable the TMC only if it needs to */ if (drvdata->mode != CS_MODE_DISABLED) { + /* Unregister panic notifier */ + drvdata->panic_nb.notifier_call = NULL; + atomic_notifier_chain_unregister(&panic_notifier_list, + &drvdata->panic_nb); + tmc_etb_disable_hw(drvdata); drvdata->mode = CS_MODE_DISABLED; } diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 51c0185..bb563b8 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -93,6 +93,7 @@ enum tmc_mem_intf_width { * @base: memory mapped base address for this component. * @dev: the device entity associated to this component. * @csdev: component vitals needed by the framework. + * @panic_nb: notifier callback for panic. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. * @buf: area of memory where trace data get sent. @@ -109,6 +110,7 @@ struct tmc_drvdata { void __iomem *base; struct device *dev; struct coresight_device *csdev; + struct notifier_block panic_nb; struct miscdevice miscdev; spinlock_t spinlock; bool reading;