Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp270333pxu; Thu, 7 Jan 2021 04:44:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxymAX1/bJO52782aDQKxM0cNxmVDEunT6OYiSFrZVkNf+jekgHBbmSgnHV8VQ2HfLiwmWa X-Received: by 2002:a17:906:924a:: with SMTP id c10mr6034745ejx.113.1610023473466; Thu, 07 Jan 2021 04:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610023473; cv=none; d=google.com; s=arc-20160816; b=t+isUdehXwdvbUbHiC2ZJCfUO/k0gg0oVy5J5tjSLKCBn4pt4ae1lbbw2pnWYmfO7m qc1eS56SQdgd1WYT71R36LB9mSYlTzs3UCpcMklTuViUjPD1wtEUqNfrtE32tvKCW2Gg cALKqCO7rdvWEKEJf7CkBgVlu/j6xDRPiYcM7DLm1WbcspJWl5/DPPDD6zL3e+/F/0Xq fRUIXBBrsQQn59vlqarIZ95+TxVyrgLGQ6MvJuEqL0bmpu8bi8Y4AmxnmGhssMwBKpKi x9KTHRegonfEAEJxUJAVv2BIwmvNdLJLiM63sePStpfLHn7Mc9pujoKEBMBfh2ryBS2S oUcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q+V91nStsrKwxM4RRYtrZbu0qNvMEiNP6FVvdoNfrNc=; b=s7qZPvLE6jB4svPYTr3Yf1EsiXAEvy9NSCqopK2/Ig1o8Hg/rLpJX3JSXqZWKQjwyQ X9/A2JA7dr3ffQKh9sHWk98LhqR8boOKY+BM6fPaY8lR7/9SOttUREu4Yb1wM5hSUrFh POFH+LDgOI2/jVfFj8NIVDp2vY79sZTCl3ST0xsxkQSHL5leZ05cQzcln8rVfwDmk/Rv pq+jQen6uxFMFdKPiyxmD2l7mu0De7LJUmWtipJB4MP4y+rQwN4/z+ptjyUXtU77MvOr zhpJe36a1Lxt71HWFwdUhyrgh7iHzqy8fKZ6XHlSFhjGHm+u0SlyNC9E5+U3ivnivTAs RBtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si2043440ejt.658.2021.01.07.04.44.09; Thu, 07 Jan 2021 04:44:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728572AbhAGMll (ORCPT + 99 others); Thu, 7 Jan 2021 07:41:41 -0500 Received: from foss.arm.com ([217.140.110.172]:59982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728516AbhAGMle (ORCPT ); Thu, 7 Jan 2021 07:41:34 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 70137150C; Thu, 7 Jan 2021 04:39:41 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 561323F719; Thu, 7 Jan 2021 04:39:40 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, coresight@lists.linaro.org, mathieu.poirier@linaro.org, leo.yan@linaro.org, mike.leach@linaro.org, anshuman.khandual@arm.com, Suzuki K Poulose Subject: [PATCH v6 20/26] coresight: etm4x: Detect system instructions support Date: Thu, 7 Jan 2021 12:38:53 +0000 Message-Id: <20210107123859.674252-21-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20210107123859.674252-1-suzuki.poulose@arm.com> References: <20210107123859.674252-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ETM v4.4 onwards adds support for system instruction access to the ETM. Detect the support on an ETM and switch to using the mode when available. Cc: Mike Leach Reviewed-by: Mathieu Poirier Signed-off-by: Suzuki K Poulose --- .../coresight/coresight-etm4x-core.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 9b00720e7a02..f5bbb6131d77 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -782,6 +782,37 @@ static const struct coresight_ops etm4_cs_ops = { .source_ops = &etm4_source_ops, }; +static inline bool cpu_supports_sysreg_trace(void) +{ + u64 dfr0 = read_sysreg_s(SYS_ID_AA64DFR0_EL1); + + return ((dfr0 >> ID_AA64DFR0_TRACEVER_SHIFT) & 0xfUL) > 0; +} + +static bool etm4_init_sysreg_access(struct etmv4_drvdata *drvdata, + struct csdev_access *csa) +{ + u32 devarch; + + if (!cpu_supports_sysreg_trace()) + return false; + + /* + * ETMs implementing sysreg access must implement TRCDEVARCH. + */ + devarch = read_etm4x_sysreg_const_offset(TRCDEVARCH); + if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH) + return false; + *csa = (struct csdev_access) { + .io_mem = false, + .read = etm4x_sysreg_read, + .write = etm4x_sysreg_write, + }; + + drvdata->arch = etm_devarch_to_arch(devarch); + return true; +} + static bool etm4_init_iomem_access(struct etmv4_drvdata *drvdata, struct csdev_access *csa) { @@ -812,9 +843,17 @@ static bool etm4_init_iomem_access(struct etmv4_drvdata *drvdata, static bool etm4_init_csdev_access(struct etmv4_drvdata *drvdata, struct csdev_access *csa) { + /* + * Always choose the memory mapped io, if there is + * a memory map to prevent sysreg access on broken + * systems. + */ if (drvdata->base) return etm4_init_iomem_access(drvdata, csa); + if (etm4_init_sysreg_access(drvdata, csa)) + return true; + return false; } -- 2.24.1