From patchwork Tue May 9 02:49:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 98860 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1616679qge; Mon, 8 May 2017 19:50:56 -0700 (PDT) X-Received: by 10.99.95.79 with SMTP id t76mr21730466pgb.82.1494298256464; Mon, 08 May 2017 19:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494298256; cv=none; d=google.com; s=arc-20160816; b=Fj2IdSprapszPxwRsN5QFhwSmK+HfnsFTLt1WJYV5G9XwqHr6+MlscbEvN+OnC5AOG tygBPm0EPm93qm4ju7v3/Y0soiBaVO5poANfOnR1kSTX//aEA0gNzh42NCcJFSjPAOIo M5/kmC89rC1IhwnheTC1xS4OwUnxK5PRsgWWwq7vhXyREgOaCMG3JaNdhTMYD0oD2nUc VbnhuXvDnpbggzZp/oVw56G96bYmDaHB9jcwM1XswSFm8YGRUlbQCMzuTrHMKoxrCimp d9obntMyWdPPml1XdvWFudXx58FdNba7vVFuP5p/UzSNsrzCC8504i7TvMbgUyjRxKVn yQyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=RznkZ7Ydm11LKpoLEKyL3gnbYSNvWEVqr08vOdNy028=; b=oxVJuUMIBJ8E5JhAkBKgQUFar3HQWdnlHaR9VZcVhYZxPRGy3++Q76oMB16BS5G7IZ KCiQQrET+sV1h4Xs1v2zRk8onWQCld6j3SfZOhG7gdItCvIetRk23t3do+AC+RPFKzqi cLKL0S0avQr3+D/rB+AyQuxPmluI62AFRpeKNeY+RYcqO+lPDRI9uSwukc9CGfzO1xcL LkYupOAw/gHuTefoeryMNuyV1xpdQG/NigejT7md6ewBLFQPkXeJRZ8JzfVQBLpzuoCj aoBqKjkjW6Ef//zVQEa3xYAT/bzV0pFi4wdv06SZgfYaOFdRgOWVuAx4eXGQXehGOAXY lP2g== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si14649235plx.323.2017.05.08.19.50.56; Mon, 08 May 2017 19:50:56 -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 S1754819AbdEICuq (ORCPT + 25 others); Mon, 8 May 2017 22:50:46 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:36788 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754660AbdEICum (ORCPT ); Mon, 8 May 2017 22:50:42 -0400 Received: by mail-pg0-f41.google.com with SMTP id 64so20672894pgb.3 for ; Mon, 08 May 2017 19:50:42 -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=RznkZ7Ydm11LKpoLEKyL3gnbYSNvWEVqr08vOdNy028=; b=dbQWmXD2RnEkIlBxPSylSSZvAayQNht7pcEiI4UFK6SgXBLqvZ+Krp1i+OppvPHx9s 9RAOvTs/derzum0m4O5TFZbk28sPoo1qcVijQmCG8tUXpAsMYFWSG1Hgul6KtdeX1TAx Wm39di/sNdLW32AfgjDJW41ErkGhyT8YeZHyA= 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=RznkZ7Ydm11LKpoLEKyL3gnbYSNvWEVqr08vOdNy028=; b=hMIXFbCDKaJH4IhPO6l8WV7kPCfbEn979MxnRYbBfy9H2FbBrCS/1ZLhO8vZPZLRm6 gUUx+fVRbs/0l1u7tnILLfaeaGds3tiLphFGphuvFIa09miq/E95jF4CSSmhMQADLDzG 25j91ja09drkJRUhoF34xOZy9tty2C6+eALemkA9ELucaaS7pGf9vNHAXnwCG+o5hLx5 TEDDVVm0bsYB1zaNRw9dSitMDM/J/mSp56u47Ke79RdMTnhF2j6YTfEVBGmMKsIqLMAr dS4jGwkonwSrUqvPCI3DxagNKgbo690Ztc4qofaMlor++6YzR8/ZCw5PC9Ycx6RZ6zT2 yx+Q== X-Gm-Message-State: AODbwcBnGt9EmyxPWCwFwOsMrrgTAueQH78nWIS06i/CBOeWepoWdBNf vF2C8O/8hdeU6skB X-Received: by 10.98.23.74 with SMTP id 71mr14043761pfx.30.1494298241330; Mon, 08 May 2017 19:50:41 -0700 (PDT) Received: from localhost.localdomain (li1627-128.members.linode.com. [172.104.47.128]) by smtp.gmail.com with ESMTPSA id 20sm35326370pfq.42.2017.05.08.19.50.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 19:50:40 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Wei Xu , Catalin Marinas , Will Deacon , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , Stephen Boyd , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mike Leach , Sudeep Holla Cc: Leo Yan Subject: [PATCH v9 2/9] doc: Add documentation for Coresight CPU debug Date: Tue, 9 May 2017 10:49:55 +0800 Message-Id: <1494298202-6739-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494298202-6739-1-git-send-email-leo.yan@linaro.org> References: <1494298202-6739-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 Add detailed documentation for Coresight CPU debug driver, which contains the info for driver implementation, Mike Leach excellent summary for "clock and power domain". At the end some examples on how to enable the debugging functionality are provided. Suggested-by: Mike Leach Signed-off-by: Leo Yan --- Documentation/trace/coresight-cpu-debug.txt | 174 ++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Documentation/trace/coresight-cpu-debug.txt -- 2.7.4 diff --git a/Documentation/trace/coresight-cpu-debug.txt b/Documentation/trace/coresight-cpu-debug.txt new file mode 100644 index 0000000..0426d50 --- /dev/null +++ b/Documentation/trace/coresight-cpu-debug.txt @@ -0,0 +1,174 @@ + Coresight CPU Debug Module + ========================== + + Author: Leo Yan + Date: April 5th, 2017 + +Introduction +------------ + +Coresight CPU debug module is defined in ARMv8-a architecture reference manual +(ARM DDI 0487A.k) Chapter 'Part H: External debug', the CPU can integrate +debug module and it is mainly used for two modes: self-hosted debug and +external debug. Usually the external debug mode is well known as the external +debugger connects with SoC from JTAG port; on the other hand the program can +explore debugging method which rely on self-hosted debug mode, this document +is to focus on this part. + +The debug module provides sample-based profiling extension, which can be used +to sample CPU program counter, secure state and exception level, etc; usually +every CPU has one dedicated debug module to be connected. Based on self-hosted +debug mechanism, Linux kernel can access these related registers from mmio +region when the kernel panic happens. The callback notifier for kernel panic +will dump related registers for every CPU; finally this is good for assistant +analysis for panic. + + +Implementation +-------------- + +- During driver registration, use EDDEVID and EDDEVID1 two device ID + registers to decide if sample-based profiling is implemented or not. On some + platforms this hardware feature is fully or partialy implemented; and if + this feature is not supported then registration will fail. + +- When write this doc, the debug driver mainly relies on three sampling + registers. The kernel panic callback notifier gathers info from EDPCSR + EDVIDSR and EDCIDSR; from EDPCSR we can get program counter, EDVIDSR has + information for secure state, exception level, bit width, etc; EDCIDSR is + context ID value which contains the sampled value of CONTEXTIDR_EL1. + +- The driver supports CPU running mode with either AArch64 or AArch32. The + registers naming convention is a bit different between them, AArch64 uses + 'ED' for register prefix (ARM DDI 0487A.k, chapter H9.1) and AArch32 uses + 'DBG' as prefix (ARM DDI 0487A.k, chapter G5.1). The driver is unified to + use AArch64 naming convention. + +- ARMv8-a (ARM DDI 0487A.k) and ARMv7-a (ARM DDI 0406C.b) have different + register bits definition. So the driver consolidates two difference: + + If PCSROffset=0b0000, on ARMv8-a the feature of EDPCSR is not implemented; + but ARMv7-a defines "PCSR samples are offset by a value that depends on the + instruction set state". For ARMv7-a, the driver checks furthermore if CPU + runs with ARM or thumb instruction set and calibrate PCSR value, the + detailed description for offset is in ARMv7-a ARM (ARM DDI 0406C.b) chapter + C11.11.34 "DBGPCSR, Program Counter Sampling Register". + + If PCSROffset=0b0010, ARMv8-a defines "EDPCSR implemented, and samples have + no offset applied and do not sample the instruction set state in AArch32 + state". So on ARMv8 if EDDEVID1.PCSROffset is 0b0010 and the CPU operates + in AArch32 state, EDPCSR is not sampled; when the CPU operates in AArch64 + state EDPCSR is sampled and no offset are applied. + + +Clock and power domain +---------------------- + +Before accessing debug registers, we should ensure the clock and power domain +have been enabled properly. In ARMv8-a ARM (ARM DDI 0487A.k) chapter 'H9.1 +Debug registers', the debug registers are spread into two domains: the debug +domain and the CPU domain. + + +---------------+ + | | + | | + +----------+--+ | + dbg_clk -->| |**| |<-- cpu_clk + | Debug |**| CPU | + dbg_pd -->| |**| |<-- cpu_pd + +----------+--+ | + | | + | | + +---------------+ + +For debug domain, the user uses DT binding "clocks" and "power-domains" to +specify the corresponding clock source and power supply for the debug logic. +The driver calls the pm_runtime_{put|get} operations as needed to handle the +debug power domain. + +For CPU domain, the different SoC designs have different power management +schemes and finally this heavily impacts external debug module. So we can +divide into below cases: + +- On systems with a sane power controller which can behave correctly with + respect to CPU power domain, the CPU power domain can be controlled by + register EDPRCR in driver. The driver firstly writes bit EDPRCR.COREPURQ + to power up the CPU, and then writes bit EDPRCR.CORENPDRQ for emulation + of CPU power down. As result, this can ensure the CPU power domain is + powered on properly during the period when access debug related registers; + +- Some designs will power down an entire cluster if all CPUs on the cluster + are powered down - including the parts of the debug registers that should + remain powered in the debug power domain. The bits in EDPRCR are not + respected in these cases, so these designs do not support debug over + power down in the way that the CoreSight / Debug designers anticipated. + This means that even checking EDPRSR has the potential to cause a bus hang + if the target register is unpowered. + + In this case, accessing to the debug registers while they are not powered + is a recipe for disaster; so we need preventing CPU low power states at boot + time or when user enable module at the run time. Please see chapter + "How to use the module" for detailed usage info for this. + + +Device Tree Bindings +-------------------- + +See Documentation/devicetree/bindings/arm/coresight-cpu-debug.txt for details. + + +How to use the module +--------------------- + +If you want to enable debugging functionality at boot time, you can add +"coresight_cpu_debug.enable=1" to the kernel command line parameter. + +The driver also can work as module, so can enable the debugging when insmod +module: +# insmod coresight_cpu_debug.ko debug=1 + +When boot time or insmod module you have not enabled the debugging, the driver +uses the debugfs file system to provide a knob to dynamically enable or disable +debugging: + +To enable it, write a '1' into /sys/kernel/debug/coresight_cpu_debug/enable: +# echo 1 > /sys/kernel/debug/coresight_cpu_debug/enable + +To disable it, write a '0' into /sys/kernel/debug/coresight_cpu_debug/enable: +# echo 0 > /sys/kernel/debug/coresight_cpu_debug/enable + +As explained in chapter "Clock and power domain", if you are working on one +platform which has idle states to power off debug logic and the power +controller cannot work well for the request from EDPRCR, then you should +firstly constraint CPU idle states before enable CPU debugging feature; so can +ensure the accessing to debug logic. + +If you want to limit idle states at boot time, you can use "nohlt" or +"cpuidle.off=1" in the kernel command line. + +At the runtime you can disable idle states with below methods: + +Set latency request to /dev/cpu_dma_latency to disable all CPUs specific idle +states (if latency = 0uS then disable all idle states): +# echo "what_ever_latency_you_need_in_uS" > /dev/cpu_dma_latency + +Disable specific CPU's specific idle state: +# echo 1 > /sys/devices/system/cpu/cpu$cpu/cpuidle/state$state/disable + + +Output format +------------- + +Here is an example of the debugging output format: + +ARM external debug module: +CPU[0]: + EDPRSR: 0000000b (Power:On DLK:Unlock) + EDPCSR: [] handle_IPI+0xe4/0x150 + EDCIDSR: 00000000 + EDVIDSR: 90000000 (State:Non-secure Mode:EL1/0 Width:64bits VMID:0) +CPU[1]: + EDPRSR: 0000000b (Power:On DLK:Unlock) + EDPCSR: [] debug_notifier_call+0x108/0x288 + EDCIDSR: 00000000 + EDVIDSR: 90000000 (State:Non-secure Mode:EL1/0 Width:64bits VMID:0) From patchwork Tue May 9 02:49:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 98862 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1616740qge; Mon, 8 May 2017 19:51:08 -0700 (PDT) X-Received: by 10.98.215.19 with SMTP id b19mr206316pfh.34.1494298268275; Mon, 08 May 2017 19:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494298268; cv=none; d=google.com; s=arc-20160816; b=pDhlEwMpHRNdLYHzQbqNB4aSHMJw+sI3p5EzU3STH7RwwmkG49e0MChyRoXvb3Jial snWaoQlutHIIKJfYiagDzFAH/R8fL5JkPTFZ22vtGwcUi9vk+ggGLdS+Jpkj9jPhLVtV RDsxMeLt9JSBuRKrxtgHlZ8NCn/noNzwPet6b172dFwu7j8efsCPQevIKgXV0HTZhJ0X KEav/496bQReeZtagt1i1vWXeIMQBfWttcLCDUismV8gHqy3fmqFQas2tQLZNHFxX4SD cLGK1qdlucXCkOoN2B8WYpduVbQhTh+vAmv3Daoi1XMhJ0qlPLdE9VmNRjqJ8bdhCNVV v9HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ZyItBD41w6mrhto/IO6yYL5EB6/oUgigViEY8vNoIH4=; b=gKEJhgECkekvY/N0EtRYIt7dJBUl3JBbmgsxaDtB7GJjfmgB4T3uYGutbqj8AJ8sc9 bDvDAHYF0Q/PhpNolYOTCbfHCdQbw1AGtFXpZvX6MmVY1nY1uH2yQ5hCGDoBs2B6yqm9 X2DV3LPmEPGBBtPv3b9jZ5aRWFeMyADwF48AGnKofY8K0xR2nKKnLrivTVMSy5wlA37h Z+YApnd9jGsrtvSj+JK3q5xFbaQqvyVICxtTQGF3Tm/JWP/Z4Dt+RpC02/M7E0pPTg2Y lJnkjKa/tSwB1mBsHNwiODp8KN33trusdAfr4VWRDLQNs3G34euk1wdIfrP5YRpJa5oU JBsw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z61si14717924plb.68.2017.05.08.19.51.08; Mon, 08 May 2017 19:51: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 S1754992AbdEICvD (ORCPT + 25 others); Mon, 8 May 2017 22:51:03 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35006 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754140AbdEICvA (ORCPT ); Mon, 8 May 2017 22:51:00 -0400 Received: by mail-pf0-f177.google.com with SMTP id v14so42036828pfd.2 for ; Mon, 08 May 2017 19:50:59 -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=ZyItBD41w6mrhto/IO6yYL5EB6/oUgigViEY8vNoIH4=; b=a0K5QbAh/HzDbA7n2zJcejTjqHBGb2Fi50F5qtzPbPAColitnZiO+NaYezlylvvBPs m6vpHsyUNwfzBYsN7504qCtQKCaMyHZ6swn9uiZbM0jUb6yLZMZjB6ezUsfeqlsGiH2u Pp4mumjtQtHKXNm4qbLNvm3wzJvAf0t9rqskw= 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=ZyItBD41w6mrhto/IO6yYL5EB6/oUgigViEY8vNoIH4=; b=axoibbMQRSAUyYs+e9nq/XnNq09HwzoCYNrkGz5MIq65xz53O32zgMZiBpaaKOsMKY /bZ1JOFCFHwNgHYi6mCT1dWogWKoCHRKCu1pLLYpV/lnymCvWuNPJitxx1mXednld7qD 6EKtomo9D3zumk6PKC4hDpT92stktkUh7bB/FcFwL07k7FrROvPJeKjwN6YS4hBSHtbl 1FOU+Js2EvT22H5SWKNFaFUJiNSk3Rbh17HmP7iytCj4/tiHMG41xtueGekO/MuBF/Aw 9L+etPg3BBRVFYVeYy/bYZ3nr5wprEnIu/g8oiZA/58ZvWHOXaUHvVSnuUrSES8QwZxe 3BVQ== X-Gm-Message-State: AN3rC/67vcgN5bkrtgdszgT/Wm36Btua+7kMbmzMdHJGGlQvin2S+FLC IvDLcgKp+AQfpRRL X-Received: by 10.98.144.21 with SMTP id a21mr25283662pfe.181.1494298259328; Mon, 08 May 2017 19:50:59 -0700 (PDT) Received: from localhost.localdomain (li1627-128.members.linode.com. [172.104.47.128]) by smtp.gmail.com with ESMTPSA id 20sm35326370pfq.42.2017.05.08.19.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 19:50:58 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Wei Xu , Catalin Marinas , Will Deacon , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , Stephen Boyd , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mike Leach , Sudeep Holla Cc: Leo Yan Subject: [PATCH v9 4/9] MAINTAINERS: update file entries for Coresight subsystem Date: Tue, 9 May 2017 10:49:57 +0800 Message-Id: <1494298202-6739-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494298202-6739-1-git-send-email-leo.yan@linaro.org> References: <1494298202-6739-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 Update document file entries for Coresight debug module. Signed-off-by: Leo Yan --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) -- 2.7.4 Reviewed-by: Mathieu Poirier diff --git a/MAINTAINERS b/MAINTAINERS index b948dfa..a4b1f60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1191,7 +1191,9 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/hwtracing/coresight/* F: Documentation/trace/coresight.txt +F: Documentation/trace/coresight-cpu-debug.txt F: Documentation/devicetree/bindings/arm/coresight.txt +F: Documentation/devicetree/bindings/arm/coresight-cpu-debug.txt F: Documentation/ABI/testing/sysfs-bus-coresight-devices-* F: tools/perf/arch/arm/util/pmu.c F: tools/perf/arch/arm/util/auxtrace.c From patchwork Tue May 9 02:50:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 98865 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1616856qge; Mon, 8 May 2017 19:51:35 -0700 (PDT) X-Received: by 10.84.168.4 with SMTP id e4mr88275297plb.138.1494298295053; Mon, 08 May 2017 19:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494298295; cv=none; d=google.com; s=arc-20160816; b=X7LPLzaydbWOJ4QYDg1Ewr6B060WlOVoXmQOMt8ngbJat5qu2B3j4okOr1L12iNWIm 2DD5g2ubzR8z2MwiZmBAtY6KknLlMmYYUrPuJrOMyM7fkcaB4NigZBp0bjXlakANpx1F 8C0HO86PhBEYoz7v6bkBdY7IYpBv1vDhqTNoBCiyE3uF/reWoUTPkMRs/swlsaKxoiul XNaS6a+qKl3+mJplnI9caxBksxjvB5K9YBdCKxrWawnwy4IAjQxuKuMkG7MpmRMq42Jj yDHrpmcedP9KRKO0O/inHWdr8eLODkkrk4m5XwIzO+JooFBKAuscyG/ZwRCc2EXiot97 7NHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1JLSobRb6BXNdY7LZ5ShOs/oVjN947mlRBwagJpeyd8=; b=JXFAV6733+GEdAJcokeUXuQxm61xylxFsH7lpxWckUzGTwb310rnbOAzlMlsyECi6x oga2r0D6HXch/e9LAoIzPYqtbSQJa0nemXPLoik35y+FNTiXtVolSrPHs3OWd/f1QxvG hPzYhSFOsAzZUO21gu6VQZCZGDwxaD604geKKhXUPoP+1pFAwjhz4GYCGZEtSTdVCU+d rA5hZdVzoqb9blc619CCkiwXXtOmQ196r5oHItMKdWFodQcUkW//1J1gbQ4Do0laHhny E3IrJ6b2V3eMM7RBJlS5PA82si/LRWHF25A69lV+a6lcSXFzuepXT2+8KrdyNbWS96ty /8yg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e10si12071877pgn.333.2017.05.08.19.51.34; Mon, 08 May 2017 19:51:35 -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 S1755343AbdEICvc (ORCPT + 25 others); Mon, 8 May 2017 22:51:32 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:35241 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753396AbdEICv1 (ORCPT ); Mon, 8 May 2017 22:51:27 -0400 Received: by mail-pg0-f54.google.com with SMTP id o3so45069977pgn.2 for ; Mon, 08 May 2017 19:51:27 -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=1JLSobRb6BXNdY7LZ5ShOs/oVjN947mlRBwagJpeyd8=; b=WrShkiFmAfK2+8jWwSjtEy9X4m+wd/iyfediyB282rc6ils1y6MamfKy4zdlrHvEQO cWpucRbHAMWrWW4ukTsKpneqJvULp1LMZA6ipjiOOMzeIl7Y0aCdMP9QnJ7wqK64uAK6 atSBXdGxb+arsMtuviG1Augk7R7Ht/WwjNKtM= 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=1JLSobRb6BXNdY7LZ5ShOs/oVjN947mlRBwagJpeyd8=; b=ptUxOxKbO+1qhMy22s0gz95ICrVB+op6PjoWH8PZUl1YaHPsEQa6DAqW7ACortZ2Ai 54pSMikMfHJYjM5VNwWwrWNx4hfI0daR24tLmwL6rm9yEnKqwJR2gj6BCb6aFjaudYeq diWvf26Ui2kjjWrqm4+9cvJZHwvuHaoCgJdK+WeICmyjZ8CEzJVnsSfAalB08+lrb+d0 0mNeslqbpm+7XzgWmpiGrS0EJZaCW3vO9/oPMJOOQ8iWLLpDI5sfe/uusvEdcjBfqncr 0qy/rPNJOx9cy3oaUkedl8GFYdPeiamJIho2F410zANOxG44NUy4VGrwedxL9QDbrtZA 7+fg== X-Gm-Message-State: AN3rC/6Vl3fJs/6xxzU4Z6SrywzKsNKCYJOlGKEY6Jqaueg1HeMhXeL3 qkj8VSJAPddBjDop X-Received: by 10.99.147.5 with SMTP id b5mr21749187pge.218.1494298286794; Mon, 08 May 2017 19:51:26 -0700 (PDT) Received: from localhost.localdomain (li1627-128.members.linode.com. [172.104.47.128]) by smtp.gmail.com with ESMTPSA id 20sm35326370pfq.42.2017.05.08.19.51.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 19:51:25 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Wei Xu , Catalin Marinas , Will Deacon , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , Stephen Boyd , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mike Leach , Sudeep Holla Cc: Leo Yan Subject: [PATCH v9 7/9] coresight: add support for CPU debug module Date: Tue, 9 May 2017 10:50:00 +0800 Message-Id: <1494298202-6739-8-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494298202-6739-1-git-send-email-leo.yan@linaro.org> References: <1494298202-6739-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 Coresight includes debug module and usually the module connects with CPU debug logic. ARMv8 architecture reference manual (ARM DDI 0487A.k) has description for related info in "Part H: External Debug". Chapter H7 "The Sample-based Profiling Extension" introduces several sampling registers, e.g. we can check program counter value with combined CPU exception level, secure state, etc. So this is helpful for analysis CPU lockup scenarios, e.g. if one CPU has run into infinite loop with IRQ disabled. In this case the CPU cannot switch context and handle any interrupt (including IPIs), as the result it cannot handle SMP call for stack dump. This patch is to enable coresight debug module, so firstly this driver is to bind apb clock for debug module and this is to ensure the debug module can be accessed from program or external debugger. And the driver uses sample-based registers for debug purpose, e.g. when system triggers panic, the driver will dump program counter and combined context registers (EDCIDSR, EDVIDSR); by parsing context registers so can quickly get to know CPU secure state, exception level, etc. Some of the debug module registers are located in CPU power domain, so this requires the CPU power domain stays on when access related debug registers, but the power management for CPU power domain is quite dependent on SoC integration for power management. For the platforms which with sane power controller implementations, this driver follows the method to set EDPRCR to try to pull the CPU out of low power state and then set 'no power down request' bit so the CPU has no chance to lose power. If the SoC has not followed up this design well for power management controller, the user should use the command line parameter or sysfs to constrain all or partial idle states to ensure the CPU power domain is enabled and access coresight CPU debug component safely. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/Kconfig | 14 + drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/coresight-cpu-debug.c | 693 ++++++++++++++++++++++ 3 files changed, 708 insertions(+) create mode 100644 drivers/hwtracing/coresight/coresight-cpu-debug.c -- 2.7.4 diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 130cb21..8d55d6d 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -89,4 +89,18 @@ config CORESIGHT_STM logging useful software events or data coming from various entities in the system, possibly running different OSs +config CORESIGHT_CPU_DEBUG + tristate "CoreSight CPU Debug driver" + depends on ARM || ARM64 + depends on DEBUG_FS + help + This driver provides support for coresight debugging module. This + is primarily used to dump sample-based profiling registers when + system triggers panic, the driver will parse context registers so + can quickly get to know program counter (PC), secure state, + exception level, etc. Before use debugging functionality, platform + needs to ensure the clock domain and power domain are enabled + properly, please refer Documentation/trace/coresight-cpu-debug.txt + for detailed description and the example for usage. + endif diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index af480d9..433d590 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -16,3 +16,4 @@ obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \ coresight-etm4x-sysfs.o obj-$(CONFIG_CORESIGHT_QCOM_REPLICATOR) += coresight-replicator-qcom.o obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o +obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c new file mode 100644 index 0000000..ab12ec1 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c @@ -0,0 +1,693 @@ +/* + * Copyright (c) 2017 Linaro Limited. All rights reserved. + * + * Author: Leo Yan + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coresight-priv.h" + +#define EDPCSR 0x0A0 +#define EDCIDSR 0x0A4 +#define EDVIDSR 0x0A8 +#define EDPCSR_HI 0x0AC +#define EDOSLAR 0x300 +#define EDPRCR 0x310 +#define EDPRSR 0x314 +#define EDDEVID1 0xFC4 +#define EDDEVID 0xFC8 + +#define EDPCSR_PROHIBITED 0xFFFFFFFF + +/* bits definition for EDPCSR */ +#define EDPCSR_THUMB BIT(0) +#define EDPCSR_ARM_INST_MASK GENMASK(31, 2) +#define EDPCSR_THUMB_INST_MASK GENMASK(31, 1) + +/* bits definition for EDPRCR */ +#define EDPRCR_COREPURQ BIT(3) +#define EDPRCR_CORENPDRQ BIT(0) + +/* bits definition for EDPRSR */ +#define EDPRSR_DLK BIT(6) +#define EDPRSR_PU BIT(0) + +/* bits definition for EDVIDSR */ +#define EDVIDSR_NS BIT(31) +#define EDVIDSR_E2 BIT(30) +#define EDVIDSR_E3 BIT(29) +#define EDVIDSR_HV BIT(28) +#define EDVIDSR_VMID GENMASK(7, 0) + +/* + * bits definition for EDDEVID1:PSCROffset + * + * NOTE: armv8 and armv7 have different definition for the register, + * so consolidate the bits definition as below: + * + * 0b0000 - Sample offset applies based on the instruction state, we + * rely on EDDEVID to check if EDPCSR is implemented or not + * 0b0001 - No offset applies. + * 0b0010 - No offset applies, but do not use in AArch32 mode + * + */ +#define EDDEVID1_PCSR_OFFSET_MASK GENMASK(3, 0) +#define EDDEVID1_PCSR_OFFSET_INS_SET (0x0) +#define EDDEVID1_PCSR_NO_OFFSET_DIS_AARCH32 (0x2) + +/* bits definition for EDDEVID */ +#define EDDEVID_PCSAMPLE_MODE GENMASK(3, 0) +#define EDDEVID_IMPL_EDPCSR (0x1) +#define EDDEVID_IMPL_EDPCSR_EDCIDSR (0x2) +#define EDDEVID_IMPL_FULL (0x3) + +#define DEBUG_WAIT_SLEEP 1000 +#define DEBUG_WAIT_TIMEOUT 32000 + +struct debug_drvdata { + void __iomem *base; + struct device *dev; + int cpu; + + bool edpcsr_present; + bool edcidsr_present; + bool edvidsr_present; + bool pc_has_offset; + + u32 edpcsr; + u32 edpcsr_hi; + u32 edprsr; + u32 edvidsr; + u32 edcidsr; +}; + +static DEFINE_MUTEX(debug_lock); +static DEFINE_PER_CPU(struct debug_drvdata *, debug_drvdata); +static int debug_count; +static struct dentry *debug_debugfs_dir; + +static bool debug_enable; +module_param_named(enable, debug_enable, bool, 0600); +MODULE_PARM_DESC(enable, "Knob to enable debug functionality " + "(default is 0, which means is disabled by default)"); + +static void debug_os_unlock(struct debug_drvdata *drvdata) +{ + /* Unlocks the debug registers */ + writel_relaxed(0x0, drvdata->base + EDOSLAR); + + /* Make sure the registers are unlocked before accessing */ + wmb(); +} + +/* + * According to ARM DDI 0487A.k, before access external debug + * registers should firstly check the access permission; if any + * below condition has been met then cannot access debug + * registers to avoid lockup issue: + * + * - CPU power domain is powered off; + * - The OS Double Lock is locked; + * + * By checking EDPRSR can get to know if meet these conditions. + */ +static bool debug_access_permitted(struct debug_drvdata *drvdata) +{ + /* CPU is powered off */ + if (!(drvdata->edprsr & EDPRSR_PU)) + return false; + + /* The OS Double Lock is locked */ + if (drvdata->edprsr & EDPRSR_DLK) + return false; + + return true; +} + +static void debug_force_cpu_powered_up(struct debug_drvdata *drvdata) +{ + u32 edprcr; + +try_again: + + /* + * Send request to power management controller and assert + * DBGPWRUPREQ signal; if power management controller has + * sane implementation, it should enable CPU power domain + * in case CPU is in low power state. + */ + edprcr = readl_relaxed(drvdata->base + EDPRCR); + edprcr |= EDPRCR_COREPURQ; + writel_relaxed(edprcr, drvdata->base + EDPRCR); + + /* Wait for CPU to be powered up (timeout~=32ms) */ + if (readx_poll_timeout_atomic(readl_relaxed, drvdata->base + EDPRSR, + drvdata->edprsr, (drvdata->edprsr & EDPRSR_PU), + DEBUG_WAIT_SLEEP, DEBUG_WAIT_TIMEOUT)) { + /* + * Unfortunately the CPU cannot be powered up, so return + * back and later has no permission to access other + * registers. For this case, should disable CPU low power + * states to ensure CPU power domain is enabled! + */ + pr_err("%s: power up request for CPU%d failed\n", + __func__, drvdata->cpu); + return; + } + + /* + * At this point the CPU is powered up, so set the no powerdown + * request bit so we don't lose power and emulate power down. + */ + edprcr = readl_relaxed(drvdata->base + EDPRCR); + edprcr |= EDPRCR_COREPURQ | EDPRCR_CORENPDRQ; + writel_relaxed(edprcr, drvdata->base + EDPRCR); + + drvdata->edprsr = readl_relaxed(drvdata->base + EDPRSR); + + /* The core power domain got switched off on use, try again */ + if (unlikely(!(drvdata->edprsr & EDPRSR_PU))) + goto try_again; +} + +static void debug_read_regs(struct debug_drvdata *drvdata) +{ + u32 save_edprcr; + + CS_UNLOCK(drvdata->base); + + /* Unlock os lock */ + debug_os_unlock(drvdata); + + /* Save EDPRCR register */ + save_edprcr = readl_relaxed(drvdata->base + EDPRCR); + + /* + * Ensure CPU power domain is enabled to let registers + * are accessiable. + */ + debug_force_cpu_powered_up(drvdata); + + if (!debug_access_permitted(drvdata)) + goto out; + + drvdata->edpcsr = readl_relaxed(drvdata->base + EDPCSR); + + /* + * As described in ARM DDI 0487A.k, if the processing + * element (PE) is in debug state, or sample-based + * profiling is prohibited, EDPCSR reads as 0xFFFFFFFF; + * EDCIDSR, EDVIDSR and EDPCSR_HI registers also become + * UNKNOWN state. So directly bail out for this case. + */ + if (drvdata->edpcsr == EDPCSR_PROHIBITED) + goto out; + + /* + * A read of the EDPCSR normally has the side-effect of + * indirectly writing to EDCIDSR, EDVIDSR and EDPCSR_HI; + * at this point it's safe to read value from them. + */ + if (IS_ENABLED(CONFIG_64BIT)) + drvdata->edpcsr_hi = readl_relaxed(drvdata->base + EDPCSR_HI); + + if (drvdata->edcidsr_present) + drvdata->edcidsr = readl_relaxed(drvdata->base + EDCIDSR); + + if (drvdata->edvidsr_present) + drvdata->edvidsr = readl_relaxed(drvdata->base + EDVIDSR); + +out: + /* Restore EDPRCR register */ + writel_relaxed(save_edprcr, drvdata->base + EDPRCR); + + CS_LOCK(drvdata->base); +} + +static unsigned long debug_adjust_pc(struct debug_drvdata *drvdata) +{ + unsigned long arm_inst_offset = 0, thumb_inst_offset = 0; + unsigned long pc; + + if (IS_ENABLED(CONFIG_64BIT)) + return (unsigned long)drvdata->edpcsr_hi << 32 | + (unsigned long)drvdata->edpcsr; + + pc = (unsigned long)drvdata->edpcsr; + + if (drvdata->pc_has_offset) { + arm_inst_offset = 8; + thumb_inst_offset = 4; + } + + /* Handle thumb instruction */ + if (pc & EDPCSR_THUMB) { + pc = (pc & EDPCSR_THUMB_INST_MASK) - thumb_inst_offset; + return pc; + } + + /* + * Handle arm instruction offset, if the arm instruction + * is not 4 byte alignment then it's possible the case + * for implementation defined; keep original value for this + * case and print info for notice. + */ + if (pc & BIT(1)) + pr_emerg("Instruction offset is implementation defined\n"); + else + pc = (pc & EDPCSR_ARM_INST_MASK) - arm_inst_offset; + + return pc; +} + +static void debug_dump_regs(struct debug_drvdata *drvdata) +{ + unsigned long pc; + + pr_emerg("\tEDPRSR: %08x (Power:%s DLK:%s)\n", drvdata->edprsr, + drvdata->edprsr & EDPRSR_PU ? "On" : "Off", + drvdata->edprsr & EDPRSR_DLK ? "Lock" : "Unlock"); + + if (!debug_access_permitted(drvdata)) { + pr_emerg("No permission to access debug registers!\n"); + return; + } + + if (drvdata->edpcsr == EDPCSR_PROHIBITED) { + pr_emerg("CPU is in Debug state or profiling is prohibited!\n"); + return; + } + + pc = debug_adjust_pc(drvdata); + pr_emerg("\tEDPCSR: [<%p>] %pS\n", (void *)pc, (void *)pc); + + if (drvdata->edcidsr_present) + pr_emerg("\tEDCIDSR: %08x\n", drvdata->edcidsr); + + if (drvdata->edvidsr_present) + pr_emerg("\tEDVIDSR: %08x (State:%s Mode:%s Width:%dbits VMID:%x)\n", + drvdata->edvidsr, + drvdata->edvidsr & EDVIDSR_NS ? "Non-secure" : "Secure", + drvdata->edvidsr & EDVIDSR_E3 ? "EL3" : + (drvdata->edvidsr & EDVIDSR_E2 ? "EL2" : "EL1/0"), + drvdata->edvidsr & EDVIDSR_HV ? 64 : 32, + drvdata->edvidsr & (u32)EDVIDSR_VMID); +} + +static void debug_init_arch_data(void *info) +{ + struct debug_drvdata *drvdata = info; + u32 mode, pcsr_offset; + u32 eddevid, eddevid1; + + CS_UNLOCK(drvdata->base); + + /* Read device info */ + eddevid = readl_relaxed(drvdata->base + EDDEVID); + eddevid1 = readl_relaxed(drvdata->base + EDDEVID1); + + CS_LOCK(drvdata->base); + + /* Parse implementation feature */ + mode = eddevid & EDDEVID_PCSAMPLE_MODE; + pcsr_offset = eddevid1 & EDDEVID1_PCSR_OFFSET_MASK; + + drvdata->edpcsr_present = false; + drvdata->edcidsr_present = false; + drvdata->edvidsr_present = false; + drvdata->pc_has_offset = false; + + switch (mode) { + case EDDEVID_IMPL_FULL: + drvdata->edvidsr_present = true; + /* Fall through */ + case EDDEVID_IMPL_EDPCSR_EDCIDSR: + drvdata->edcidsr_present = true; + /* Fall through */ + case EDDEVID_IMPL_EDPCSR: + /* + * In ARM DDI 0487A.k, the EDDEVID1.PCSROffset is used to + * define if has the offset for PC sampling value; if read + * back EDDEVID1.PCSROffset == 0x2, then this means the debug + * module does not sample the instruction set state when + * armv8 CPU in AArch32 state. + */ + drvdata->edpcsr_present = + ((IS_ENABLED(CONFIG_64BIT) && pcsr_offset != 0) || + (pcsr_offset != EDDEVID1_PCSR_NO_OFFSET_DIS_AARCH32)); + + drvdata->pc_has_offset = + (pcsr_offset == EDDEVID1_PCSR_OFFSET_INS_SET); + break; + default: + break; + } +} + +/* + * Dump out information on panic. + */ +static int debug_notifier_call(struct notifier_block *self, + unsigned long v, void *p) +{ + int cpu; + struct debug_drvdata *drvdata; + + mutex_lock(&debug_lock); + + /* Bail out if the functionality is disabled */ + if (!debug_enable) + goto skip_dump; + + pr_emerg("ARM external debug module:\n"); + + for_each_possible_cpu(cpu) { + drvdata = per_cpu(debug_drvdata, cpu); + if (!drvdata) + continue; + + pr_emerg("CPU[%d]:\n", drvdata->cpu); + + debug_read_regs(drvdata); + debug_dump_regs(drvdata); + } + +skip_dump: + mutex_unlock(&debug_lock); + return 0; +} + +static struct notifier_block debug_notifier = { + .notifier_call = debug_notifier_call, +}; + +static int debug_enable_func(void) +{ + struct debug_drvdata *drvdata; + int cpu, ret = 0; + cpumask_t mask; + + /* + * Use cpumask to track which debug power domains have + * been powered on and use it to handle failure case. + */ + cpumask_clear(&mask); + + for_each_possible_cpu(cpu) { + drvdata = per_cpu(debug_drvdata, cpu); + if (!drvdata) + continue; + + ret = pm_runtime_get_sync(drvdata->dev); + if (ret < 0) + goto err; + else + cpumask_set_cpu(cpu, &mask); + } + + return 0; + +err: + /* + * If pm_runtime_get_sync() has failed, need rollback on + * all the other CPUs that have been enabled before that. + */ + for_each_cpu(cpu, &mask) { + drvdata = per_cpu(debug_drvdata, cpu); + pm_runtime_put_noidle(drvdata->dev); + } + + return ret; +} + +static int debug_disable_func(void) +{ + struct debug_drvdata *drvdata; + int cpu, ret, err = 0; + + /* + * Disable debug power domains, records the error and keep + * circling through all other CPUs when an error has been + * encountered. + */ + for_each_possible_cpu(cpu) { + drvdata = per_cpu(debug_drvdata, cpu); + if (!drvdata) + continue; + + ret = pm_runtime_put(drvdata->dev); + if (ret < 0) + err = ret; + } + + return err; +} + +static ssize_t debug_func_knob_write(struct file *f, + const char __user *buf, size_t count, loff_t *ppos) +{ + u8 val; + int ret; + + ret = kstrtou8_from_user(buf, count, 2, &val); + if (ret) + return ret; + + mutex_lock(&debug_lock); + + if (val == debug_enable) + goto out; + + if (val) + ret = debug_enable_func(); + else + ret = debug_disable_func(); + + if (ret) { + pr_err("%s: unable to %s debug function: %d\n", + __func__, val ? "enable" : "disable", ret); + goto err; + } + + debug_enable = val; +out: + ret = count; +err: + mutex_unlock(&debug_lock); + return ret; +} + +static ssize_t debug_func_knob_read(struct file *f, + char __user *ubuf, size_t count, loff_t *ppos) +{ + ssize_t ret; + char buf[3]; + + mutex_lock(&debug_lock); + snprintf(buf, sizeof(buf), "%d\n", debug_enable); + mutex_unlock(&debug_lock); + + ret = simple_read_from_buffer(ubuf, count, ppos, buf, sizeof(buf)); + return ret; +} + +static const struct file_operations debug_func_knob_fops = { + .open = simple_open, + .read = debug_func_knob_read, + .write = debug_func_knob_write, +}; + +static int debug_func_init(void) +{ + struct dentry *file; + int ret; + + /* Create debugfs node */ + debug_debugfs_dir = debugfs_create_dir("coresight_cpu_debug", NULL); + if (!debug_debugfs_dir) { + pr_err("%s: unable to create debugfs directory\n", __func__); + return -ENOMEM; + } + + file = debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL, + &debug_func_knob_fops); + if (!file) { + pr_err("%s: unable to create enable knob file\n", __func__); + ret = -ENOMEM; + goto err; + } + + /* Register function to be called for panic */ + ret = atomic_notifier_chain_register(&panic_notifier_list, + &debug_notifier); + if (ret) { + pr_err("%s: unable to register notifier: %d\n", + __func__, ret); + goto err; + } + + return 0; + +err: + debugfs_remove_recursive(debug_debugfs_dir); + return ret; +} + +static void debug_func_exit(void) +{ + atomic_notifier_chain_unregister(&panic_notifier_list, + &debug_notifier); + debugfs_remove_recursive(debug_debugfs_dir); +} + +static int debug_probe(struct amba_device *adev, const struct amba_id *id) +{ + void __iomem *base; + struct device *dev = &adev->dev; + struct debug_drvdata *drvdata; + struct resource *res = &adev->res; + struct device_node *np = adev->dev.of_node; + int ret; + + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + drvdata->cpu = np ? of_coresight_get_cpu(np) : 0; + if (per_cpu(debug_drvdata, drvdata->cpu)) { + dev_err(dev, "CPU%d drvdata has been initialized, " + "may be caused by binding wrong CPU node in the DT\n", + drvdata->cpu); + return -EBUSY; + } + + drvdata->dev = &adev->dev; + amba_set_drvdata(adev, drvdata); + + /* Validity for the resource is already checked by the AMBA core */ + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + drvdata->base = base; + + get_online_cpus(); + per_cpu(debug_drvdata, drvdata->cpu) = drvdata; + ret = smp_call_function_single(drvdata->cpu, debug_init_arch_data, + drvdata, 1); + put_online_cpus(); + + if (ret) { + dev_err(dev, "CPU%d debug arch init failed\n", drvdata->cpu); + goto err; + } + + if (!drvdata->edpcsr_present) { + dev_err(dev, "CPU%d sample-based profiling isn't implemented\n", + drvdata->cpu); + ret = -ENXIO; + goto err; + } + + if (!debug_count++) { + ret = debug_func_init(); + if (ret) + goto err_func_init; + } + + mutex_lock(&debug_lock); + /* Turn off debug power domain if debugging is disabled */ + if (!debug_enable) + pm_runtime_put(dev); + mutex_unlock(&debug_lock); + + dev_info(dev, "Coresight debug-CPU%d initialized\n", drvdata->cpu); + return 0; + +err_func_init: + debug_count--; +err: + per_cpu(debug_drvdata, drvdata->cpu) = NULL; + return ret; +} + +static int debug_remove(struct amba_device *adev) +{ + struct device *dev = &adev->dev; + struct debug_drvdata *drvdata = amba_get_drvdata(adev); + + per_cpu(debug_drvdata, drvdata->cpu) = NULL; + + mutex_lock(&debug_lock); + /* Turn off debug power domain before rmmod the module */ + if (debug_enable) + pm_runtime_put(dev); + mutex_unlock(&debug_lock); + + if (!--debug_count) + debug_func_exit(); + + return 0; +} + +static struct amba_id debug_ids[] = { + { /* Debug for Cortex-A53 */ + .id = 0x000bbd03, + .mask = 0x000fffff, + }, + { /* Debug for Cortex-A57 */ + .id = 0x000bbd07, + .mask = 0x000fffff, + }, + { /* Debug for Cortex-A72 */ + .id = 0x000bbd08, + .mask = 0x000fffff, + }, + { 0, 0 }, +}; + +static struct amba_driver debug_driver = { + .drv = { + .name = "coresight-cpu-debug", + .suppress_bind_attrs = true, + }, + .probe = debug_probe, + .remove = debug_remove, + .id_table = debug_ids, +}; + +module_amba_driver(debug_driver); + +MODULE_AUTHOR("Leo Yan "); +MODULE_DESCRIPTION("ARM Coresight CPU Debug Driver"); +MODULE_LICENSE("GPL"); From patchwork Tue May 9 02:50:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 98866 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1616907qge; Mon, 8 May 2017 19:51:49 -0700 (PDT) X-Received: by 10.98.15.23 with SMTP id x23mr13857769pfi.86.1494298309868; Mon, 08 May 2017 19:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494298309; cv=none; d=google.com; s=arc-20160816; b=Yt0Br7HPT1TFyR/WerbZg8n87JuB42+Uto437jHicGJQ69JyvKVkXmozChOUTsCbwO 1rpIwFAAvW98A8tb1CDiX51PHTuKhU26byZ93SXShPfXRl87SRYw4mb3hKUqW6KbAD1e xp/akSSYNzragY/Al+qAxCglX1R9PXqdMYfv880DaQqCGTgsF5BN9SK1KOgPu5RIQ6cW WFwcwvJlvIUtrKr2WJntFAtQJEWg7L42gnIl/itZhHjjzTAmsc+AelTErmjQbBv3PX6o k+r/fvetgjWIYv/YBwj5cLs3fWpCtJyxILCV/GrwVSMhhdO8H4GgeEB57FwrBne4RgAE u2ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Tbswh5cFBfrAzQTlCt870+M3haV74uJPnmvSQMqsJQI=; b=f0X98aGUAVonKUq823gu1r2u6Y+WnNeY1UUgeA9Ui9k5z2eqKm367me7JpBybChrx6 KVDNXJiCqRENi3/7TEKBQwWb2rcTRaD4hCh7lecCdcVaoJJJjpptpbAMeO4k5AUyv5SJ Hy1YX/juolHzntOFtl/LQkg3PT2XK0cqUhqJ6U9DUJH/a9rWNUdVhY0S8LFZdRzPy019 JhXKr/d4uxBpHNLDOLYjbtAaT0PjS89Ga4OREQJXs2nmz+ojlolfrNM0QYTayhX8/FKH w4SCtmLfX1rZY7EYzD1bnab3gkwmOtjT6VnsZilIKT91rgVtZjHJN4pgwub7YKHXrDul jUCQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si15215445pls.286.2017.05.08.19.51.49; Mon, 08 May 2017 19:51:49 -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 S1755619AbdEICvl (ORCPT + 25 others); Mon, 8 May 2017 22:51:41 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:32855 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753396AbdEICvg (ORCPT ); Mon, 8 May 2017 22:51:36 -0400 Received: by mail-pg0-f53.google.com with SMTP id u187so36526411pgb.0 for ; Mon, 08 May 2017 19:51:35 -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=Tbswh5cFBfrAzQTlCt870+M3haV74uJPnmvSQMqsJQI=; b=c9zyqffb0Tn9d3W4UBzwuVWOBHpQpAjDti4vuvSW6i9Ml1zbT4WBhBXk+zaWWYYFl5 pdBt/prV5FFJbpnX+0tN47LWRAdxMLPkfk1XzxNvUYigCUgAbduU2T2LPHSysJr0Ll7K ZpHKz5OY4onY1l51ox2203Pvthip591EADS3w= 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=Tbswh5cFBfrAzQTlCt870+M3haV74uJPnmvSQMqsJQI=; b=oAtxl7oNphR7EnBKMBMCVgmpVJSEKevPSjFHuhzvVeXKgAj6DGLf9OnpQ/S0HarwZ3 aZx7ggl4RTfAeb9yimHkCqiWZE2mLD98VeYaRtbrVWfkueMevu/NoGWp+uBviVNJ3XHJ ExmoI/RvZVR/EkrvR+JAsOeQr0a0w07KZV9Tbn2Avz1fVTWwbB+lfEBCVbcmf1WBIa3w d+9Pb4pTp0RhNJCyCYg6xhKCkLL2OXSbg3t2JbvkmLW5+2cwTiPjPPkNey89S+JV2TEy zsjE5xLAqWA5MuNCttmvXP9uzNDMaUO6dmGWSgNnDF4OW9qSBuAkiwDDsa+OxcD0yF0Q MQhw== X-Gm-Message-State: AN3rC/4xJecHySNj2ObWZKIftCUaIyc2mhstFILlnIa24R5ns/t3jUzQ 6xy/SBhok5V/lDfx X-Received: by 10.99.112.66 with SMTP id a2mr21746559pgn.7.1494298295444; Mon, 08 May 2017 19:51:35 -0700 (PDT) Received: from localhost.localdomain (li1627-128.members.linode.com. [172.104.47.128]) by smtp.gmail.com with ESMTPSA id 20sm35326370pfq.42.2017.05.08.19.51.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 19:51:34 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Wei Xu , Catalin Marinas , Will Deacon , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , Stephen Boyd , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mike Leach , Sudeep Holla Cc: Leo Yan Subject: [PATCH v9 8/9] arm64: dts: hi6220: register debug module Date: Tue, 9 May 2017 10:50:01 +0800 Message-Id: <1494298202-6739-9-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494298202-6739-1-git-send-email-leo.yan@linaro.org> References: <1494298202-6739-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 Bind debug module driver for Hi6220. Signed-off-by: Leo Yan --- arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) -- 2.7.4 diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi index 470461d..467aa15 100644 --- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi +++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi @@ -913,5 +913,69 @@ }; }; }; + + debug@f6590000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf6590000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu0>; + }; + + debug@f6592000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf6592000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu1>; + }; + + debug@f6594000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf6594000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu2>; + }; + + debug@f6596000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf6596000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu3>; + }; + + debug@f65d0000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf65d0000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu4>; + }; + + debug@f65d2000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf65d2000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu5>; + }; + + debug@f65d4000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf65d4000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu6>; + }; + + debug@f65d6000 { + compatible = "arm,coresight-cpu-debug","arm,primecell"; + reg = <0 0xf65d6000 0 0x1000>; + clocks = <&sys_ctrl HI6220_DAPB_CLK>; + clock-names = "apb_pclk"; + cpu = <&cpu7>; + }; }; };