From patchwork Tue Mar 21 10:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 72806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1703874wrt; Tue, 21 Mar 2023 03:53:58 -0700 (PDT) X-Google-Smtp-Source: AK7set9NT86wjj35fi1CxmrWQy/yg6VQCrVoWLVAOLcFB2/TSuo5igFzTJQjJmoXVNuvJAiFrhOj X-Received: by 2002:a17:90a:741:b0:23c:fb54:95d5 with SMTP id s1-20020a17090a074100b0023cfb5495d5mr2009683pje.41.1679396038463; Tue, 21 Mar 2023 03:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679396038; cv=none; d=google.com; s=arc-20160816; b=Zzo5MdRQ0KDzMWmsvda/nian387lTc1zSogGwjJGkbCHPoq/1G8G1+AKdnI0y+W+og L7JhFkn11x1M/jmJlskQyl3jbRzDoRwEnuxVKq0T6slXNpEW4ra3MGEMXEyYvrF1zU+j 2oiJDhhLEVGX3y8YT+8v6mfUmdbDzIySjkaM6yV/wZJ1P8x5706t2drFQF7Xi9sG2KIF eFZPaunhqL8b7tWEdyD0+WMwTtZbqH0nYIKdnI4w+YOpSj4ELrr/bHKjtKGOVaDcFKlH rV2ScwspvdOSppeEwgWyN5NiL5YlIfc5cjSl1PW4zl9DobEX9vA6M86vpLT782Mo6ruq RKqQ== 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 :message-id:date:subject:cc:to:from; bh=MLWXeb0xOdlrwDRU8oZ4/s+s7NBZywsmE3quCP4Li4c=; b=SiNyEH4zfVnGEy6mICUXUUC0uxYMhcsNBz4snFH/6Io6+lKsxVGTRjavN7BwpiSASI FFpX/uOPrhd8XUTs8ItU0cVu6MAGS3eYoSY7lw+YfUy+SgOC9PDidLeUksgnT2WDLsxf AsX1JbAEfOwsUw0PtblI0WMKOSFcZlLW1jHi14T/FkhCOMe0LxJTECUECSmlqD2q9fu/ AkZ0S6XAzLaJvjLK1yaHvcykFT8ddD+G1yt0YQtP/RIidxdb4N0SKuiCXXnqn088j8lN cv30syAj+krFjj/L3t00XA6pJ+3/X4OGpk3IZmkargRriFucHw5FAujJD0sDBm5l9W5R VJBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902ea0300b001a1a9a1d336si13327342plg.206.2023.03.21.03.53.43; Tue, 21 Mar 2023 03:53:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229617AbjCUKrX (ORCPT + 99 others); Tue, 21 Mar 2023 06:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbjCUKrH (ORCPT ); Tue, 21 Mar 2023 06:47:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25C2E558D for ; Tue, 21 Mar 2023 03:47:06 -0700 (PDT) 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 DB99FAD7; Tue, 21 Mar 2023 03:47:49 -0700 (PDT) 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 CE0373F71E; Tue, 21 Mar 2023 03:47:04 -0700 (PDT) From: Suzuki K Poulose To: coresight@lists.linaro.org Cc: anshuman.khandual@arm.com, mike.leach@linaro.org, james.clark@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com, Steve Clevenger Subject: [PATCH v2] coresight: etm4x: Do not access TRCIDR1 for identification Date: Tue, 21 Mar 2023 10:45:30 +0000 Message-Id: <20230321104530.1547136-1-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760617946206331769?= X-GMAIL-MSGID: =?utf-8?q?1760974380624053828?= CoreSight ETM4x architecture clearly provides ways to identify a device via registers in the "Management" class, TRCDEVARCH and TRCDEVTYPE. These registers can be accessed without the Trace domain being powered on. We additionally added TRCIDR1 as fallback in order to cover for any ETMs that may not have implemented TRCDEVARCH. So far, nobody has reported hitting a WARNING we placed to catch such systems. Also, more importantly it is problematic to access TRCIDR1, which is a "Trace" register via MMIO access, without clearing the OSLK. But we cannot mess with the OSLK until we know for sure that this is an ETMv4 device. Thus, this kind of creates a chicken and egg problem unnecessarily for systems "which are compliant" to the ETMv4 architecture. Let us remove the TRCIDR1 fall back check and rely only on TRCDEVARCH. Reported-by: Steve Clevenger Link: https://lore.kernel.org/all/143540e5623d4c7393d24833f2b80600d8d745d2.1677881753.git.scclevenger@os.amperecomputing.com/ Cc: Mike Leach Cc: James Clark Fixes: 8b94db1edaee ("coresight: etm4x: Use TRCDEVARCH for component discovery") Signed-off-by: Suzuki K Poulose Reviewed-by: Mike Leach Reviewed-by: Anshuman Khandual --- Changes since v2: - Remove unused etm_tridr_to_arch() helper - Add comment to explain why TRCIDR1 cannot be used. --- .../coresight/coresight-etm4x-core.c | 22 ++++++++----------- drivers/hwtracing/coresight/coresight-etm4x.h | 20 +++++------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 104333c2c8a3..4c15fae534f3 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -1070,25 +1070,21 @@ static bool etm4_init_iomem_access(struct etmv4_drvdata *drvdata, struct csdev_access *csa) { u32 devarch = readl_relaxed(drvdata->base + TRCDEVARCH); - u32 idr1 = readl_relaxed(drvdata->base + TRCIDR1); /* * All ETMs must implement TRCDEVARCH to indicate that - * the component is an ETMv4. To support any broken - * implementations we fall back to TRCIDR1 check, which - * is not really reliable. + * the component is an ETMv4. Even though TRCIDR1 also + * contains the information, it is part of the "Trace" + * register and must be accessed with the OSLK cleared, + * with MMIO. But we cannot touch the OSLK until we are + * sure this is an ETM. So rely only on the TRCDEVARCH. */ - if ((devarch & ETM_DEVARCH_ID_MASK) == ETM_DEVARCH_ETMv4x_ARCH) { - drvdata->arch = etm_devarch_to_arch(devarch); - } else { - pr_warn("CPU%d: ETM4x incompatible TRCDEVARCH: %x, falling back to TRCIDR1\n", - smp_processor_id(), devarch); - - if (ETM_TRCIDR1_ARCH_MAJOR(idr1) != ETM_TRCIDR1_ARCH_ETMv4) - return false; - drvdata->arch = etm_trcidr_to_arch(idr1); + if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH) { + pr_warn_once("TRCDEVARCH doesn't match ETMv4 architecture\n"); + return false; } + drvdata->arch = etm_devarch_to_arch(devarch); *csa = CSDEV_ACCESS_IOMEM(drvdata->base); return true; } diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h index 434f4e95ee17..27c8a9901868 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -753,14 +753,12 @@ * TRCDEVARCH - CoreSight architected register * - Bits[15:12] - Major version * - Bits[19:16] - Minor version - * TRCIDR1 - ETM architected register - * - Bits[11:8] - Major version - * - Bits[7:4] - Minor version - * We must rely on TRCDEVARCH for the version information, - * however we don't want to break the support for potential - * old implementations which might not implement it. Thus - * we fall back to TRCIDR1 if TRCDEVARCH is not implemented - * for memory mapped components. + * + * We must rely only on TRCDEVARCH for the version information. Even though, + * TRCIDR1 also provides the architecture version, it is a "Trace" register + * and as such must be accessed only with Trace power domain ON. This may + * not be available at probe time. + * * Now to make certain decisions easier based on the version * we use an internal representation of the version in the * driver, as follows : @@ -786,12 +784,6 @@ static inline u8 etm_devarch_to_arch(u32 devarch) ETM_DEVARCH_REVISION(devarch)); } -static inline u8 etm_trcidr_to_arch(u32 trcidr1) -{ - return ETM_ARCH_VERSION(ETM_TRCIDR1_ARCH_MAJOR(trcidr1), - ETM_TRCIDR1_ARCH_MINOR(trcidr1)); -} - enum etm_impdef_type { ETM4_IMPDEF_HISI_CORE_COMMIT, ETM4_IMPDEF_FEATURE_MAX,