Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp575699rwl; Wed, 12 Apr 2023 00:38:06 -0700 (PDT) X-Google-Smtp-Source: AKy350bRORV8vUOV3T2wXxxIvMOow6kpoSRCHF6ENSlonPCCqTVBJUUzSe3/SHcsVO+ad0D0KBf9 X-Received: by 2002:a05:6a20:47e3:b0:eb:e2bd:33be with SMTP id ey35-20020a056a2047e300b000ebe2bd33bemr84158pzb.29.1681285086408; Wed, 12 Apr 2023 00:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681285086; cv=none; d=google.com; s=arc-20160816; b=vwanLkhhA5NNqvQuuKqe86tlkv/mmQg9Ma+sxA7DrkyqigDGQ3mQFiJF3W4Gq3rpvx kUv4n+gHy2dO5VoPXlR9S2qsdDOnnZmLciQn7PMvdI4FAJ3wBjbdmrksghCh2EcOhfYz cfVGG3t6EIU7XJ3dD68qyzP4Aao4e9P6FdSuwGbRaFtFxAiVaB77FBOKjiQXD28/nhvQ dQe5cOKUmRaCHPEFf5VNYPfeXJj8NORMwyCNmYtlx3ZIG9VBxv0OiBwd2pnjrbhw9Ge4 CK8+8GRJfA9EmCFKyodY9bGDpP3UO5w3lkealoH2QA1sKg7ek2lxLShnqrtOgsajQOev 8IFw== 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=/s0jhWff8tv25bfp2vTWmSfaSVD+vUEbw/U1s74ALyg=; b=UFoNjNZz9K7QC7M/dzUQriPKWa0VwYkTSZX/+4QETlaOmUP8bLcJ4h0VLdcOmf6fXV 3AEqJ6RviJ9Lozk47NdGQQdjd5MLg5h9Kut4svhw1p4paV5zV+kE4Kmwo3B8KMRtYEMQ nBQ4f/Y8CLJDqqOhMUG79yWduC8rg3fMoFhGP+PwnfL+Yha2bgF5xCGobujr+b95ovAL eTujpg8oADRHqG4H7c3V/yM4OPncJQuN+TnfTQvs39/upDFQArsSj8fCkYUs6nBDu9/+ AhpPpdsqJeOrPomzsJm0LpmINOftb1iO21L69cO1Lg9eap7OnU3Y0hyG3DDKZK6ICr1h 7dZQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv123-20020a632e81000000b00502d65e8491si15454212pgb.620.2023.04.12.00.37.46; Wed, 12 Apr 2023 00:38:06 -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 S229917AbjDLHTJ (ORCPT + 99 others); Wed, 12 Apr 2023 03:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjDLHTD (ORCPT ); Wed, 12 Apr 2023 03:19:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12A165B8E for ; Wed, 12 Apr 2023 00:18:38 -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 385EED75; Wed, 12 Apr 2023 00:19:22 -0700 (PDT) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 24A793F73F; Wed, 12 Apr 2023 00:18:36 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Radu Rendec , Alexandre Ghiti , Conor Dooley , Will Deacon , Pierre Gondois , Greg Kroah-Hartman , "Rafael J. Wysocki" , Sudeep Holla , Palmer Dabbelt , Gavin Shan Subject: [PATCH v2 3/3] cacheinfo: Add use_arch[|_cache]_info field/function Date: Wed, 12 Apr 2023 09:18:06 +0200 Message-Id: <20230412071809.12670-4-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230412071809.12670-1-pierre.gondois@arm.com> References: <20230412071809.12670-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The cache information can be extracted from either a Device Tree (DT), the PPTT ACPI table, or arch registers (clidr_el1 for arm64). The clidr_el1 register is used only if DT/ACPI information is not available. It does not states how caches are shared among CPUs. Add a use_arch_cache_info field/function to identify when the DT/ACPI doesn't provide cache information. Use this information to assume L1 caches are privates and L2 and higher are shared among all CPUs. Signed-off-by: Pierre Gondois --- drivers/base/cacheinfo.c | 15 +++++++++++++-- include/linux/cacheinfo.h | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 6749dc6ebf50..49dbb4357911 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -40,8 +40,9 @@ static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf, * For non DT/ACPI systems, assume unique level 1 caches, * system-wide shared caches for all other levels. */ - if (!(IS_ENABLED(CONFIG_OF) || IS_ENABLED(CONFIG_ACPI))) - return (this_leaf->level != 1) || (sib_leaf->level != 1); + if (!(IS_ENABLED(CONFIG_OF) || IS_ENABLED(CONFIG_ACPI)) || + this_leaf->use_arch_info) + return (this_leaf->level != 1) && (sib_leaf->level != 1); if ((sib_leaf->attributes & CACHE_ID) && (this_leaf->attributes & CACHE_ID)) @@ -349,6 +350,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); struct cacheinfo *this_leaf, *sib_leaf; unsigned int index, sib_index; + bool use_arch_info = false; int ret = 0; if (this_cpu_ci->cpu_map_populated) @@ -361,6 +363,12 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) */ if (!last_level_cache_is_valid(cpu)) { ret = cache_setup_properties(cpu); + if (ret && use_arch_cache_info()) { + // Possibility to rely on arch specific information. + use_arch_info = true; + ret = 0; + } + if (ret) return ret; } @@ -370,6 +378,9 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) this_leaf = per_cpu_cacheinfo_idx(cpu, index); + if (use_arch_info) + this_leaf->use_arch_info = true; + cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); for_each_online_cpu(i) { struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i); diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 908e19d17f49..853f5d97f1dc 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -66,6 +66,7 @@ struct cacheinfo { #define CACHE_ALLOCATE_POLICY_MASK \ (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE) #define CACHE_ID BIT(4) + bool use_arch_info; void *fw_token; bool disable_sysfs; void *priv; @@ -129,4 +130,14 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level) return -1; } +static inline bool +use_arch_cache_info(void) +{ +#if defined(CONFIG_ARM64) + return true; +#else + return false; +#endif +} + #endif /* _LINUX_CACHEINFO_H */ -- 2.25.1