From patchwork Tue Nov 8 11:04:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 16985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2632949wru; Tue, 8 Nov 2022 03:07:05 -0800 (PST) X-Google-Smtp-Source: AMsMyM6BzebAbFE8yrSBLvBohPsT8nBF4U7XA6hM4ZS4jyEwfXQVXj8rZ4Qx6iOFPe5s+jfWFOWL X-Received: by 2002:a50:ce1e:0:b0:463:ce89:d0b with SMTP id y30-20020a50ce1e000000b00463ce890d0bmr37220833edi.145.1667905624685; Tue, 08 Nov 2022 03:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667905624; cv=none; d=google.com; s=arc-20160816; b=ikRZBBQxBPAQ7N5HTLdaq4MX8wF1OGPfPP3xzRnM2mq8804dDMx5tG1DyegmN/0ekG /N5hwWcoMTvWCZI3S3PqcnNNi0+W3nbncc/IEq2IRfFk6gNgghG3/KBfDui2jgHBQQZQ yBzEgJRzsa3V7gbaGV+HT99p1T5mHuwrRglb2H/PRUcPv9Q2MZXinLu3DIQ1Arfi2Irn kMkIJRMaFv9yC3VHeRTJF+MPLEIAFBAo0S+4srOTNFtKNSXI1JaAWTdca8IwLVTho6ec Njf1+mRkaFbkIolXDXlXQ22CQ8T/M7NEn/n/YevbI6zCkm2Xu4st3YQIlOIAeMGSQnlQ lULg== 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=hUiTOSZ5SjLu0FafzYmoU1PeblCxHUcqVcRI+lkR82I=; b=BnD/EyEsWbo25PJwnTUtd8WYGqJKjiktkttjilQBXAsmH1eST73r771UAe2//y1TQh e765hezCHUQoeJg01FmgD9ks5kuOusuIZLC+BRwUhVOc6ShzSj+/8fooFi0OqT0nD+Gz JlZ2ij/ptjZ1wFiIJ4LwqZAsAPgkKvCUH82MT6NdwaKJCzZMwtmdjDEIX3AO5JJ3WtqT WfErEM77Ua/q4fmWKLf1OJytpq/sdmsF5nd/pL0gHkoKEn2Tfnbfa5SxftEsGvYezbTI 2Rlh/DvNe6QCkWEqH39mPt70Mezk0UR5YxFV3IgdqHDMl31V+wxyraknikjfM/wOxMxs BCuw== 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 fj22-20020a0564022b9600b00447d6f244c6si11667423edb.248.2022.11.08.03.06.41; Tue, 08 Nov 2022 03:07:04 -0800 (PST) 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 S233935AbiKHLGK (ORCPT + 99 others); Tue, 8 Nov 2022 06:06:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233997AbiKHLGG (ORCPT ); Tue, 8 Nov 2022 06:06:06 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F11504730C; Tue, 8 Nov 2022 03:06:04 -0800 (PST) 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 DB89323A; Tue, 8 Nov 2022 03:06:10 -0800 (PST) Received: from pierre123.arm.com (unknown [10.57.5.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E1D913F534; Tue, 8 Nov 2022 03:06:01 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Len Brown , Sudeep Holla , Greg Kroah-Hartman , Gavin Shan , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Jani Nikula , Jakub Kicinski , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org Subject: [PATCH 1/5] cacheinfo: Use riscv's init_cache_level() as generic OF implem Date: Tue, 8 Nov 2022 12:04:17 +0100 Message-Id: <20221108110424.166896-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221108110424.166896-1-pierre.gondois@arm.com> References: <20221108110424.166896-1-pierre.gondois@arm.com> 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?1748925808705711311?= X-GMAIL-MSGID: =?utf-8?q?1748925808705711311?= Riscv's implementation of init_of_cache_level() is following the Devicetree Specification v0.3 regarding caches, cf.: - s3.7.3 'Internal (L1) Cache Properties' - s3.8 'Multi-level and Shared Cache Nodes' Allow reusing the implementation by moving it. Signed-off-by: Pierre Gondois Reviewed-by: Conor Dooley Reviewed-by: Sudeep Holla --- arch/riscv/kernel/cacheinfo.c | 39 +------------------------------ drivers/base/cacheinfo.c | 44 +++++++++++++++++++++++++++++++++++ include/linux/cacheinfo.h | 1 + 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/arch/riscv/kernel/cacheinfo.c b/arch/riscv/kernel/cacheinfo.c index 90deabfe63ea..440a3df5944c 100644 --- a/arch/riscv/kernel/cacheinfo.c +++ b/arch/riscv/kernel/cacheinfo.c @@ -115,44 +115,7 @@ static void fill_cacheinfo(struct cacheinfo **this_leaf, int init_cache_level(unsigned int cpu) { - struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); - struct device_node *np = of_cpu_device_node_get(cpu); - struct device_node *prev = NULL; - int levels = 0, leaves = 0, level; - - if (of_property_read_bool(np, "cache-size")) - ++leaves; - if (of_property_read_bool(np, "i-cache-size")) - ++leaves; - if (of_property_read_bool(np, "d-cache-size")) - ++leaves; - if (leaves > 0) - levels = 1; - - prev = np; - while ((np = of_find_next_cache_node(np))) { - of_node_put(prev); - prev = np; - if (!of_device_is_compatible(np, "cache")) - break; - if (of_property_read_u32(np, "cache-level", &level)) - break; - if (level <= levels) - break; - if (of_property_read_bool(np, "cache-size")) - ++leaves; - if (of_property_read_bool(np, "i-cache-size")) - ++leaves; - if (of_property_read_bool(np, "d-cache-size")) - ++leaves; - levels = level; - } - - of_node_put(np); - this_cpu_ci->num_levels = levels; - this_cpu_ci->num_leaves = leaves; - - return 0; + return init_of_cache_level(cpu); } int populate_cache_leaves(unsigned int cpu) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 4b5cd08c5a65..a4308b48dd3e 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -224,8 +224,52 @@ static int cache_setup_of_node(unsigned int cpu) return 0; } + +int init_of_cache_level(unsigned int cpu) +{ + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + struct device_node *np = of_cpu_device_node_get(cpu); + struct device_node *prev = NULL; + int levels = 0, leaves = 0, level; + + if (of_property_read_bool(np, "cache-size")) + ++leaves; + if (of_property_read_bool(np, "i-cache-size")) + ++leaves; + if (of_property_read_bool(np, "d-cache-size")) + ++leaves; + if (leaves > 0) + levels = 1; + + prev = np; + while ((np = of_find_next_cache_node(np))) { + of_node_put(prev); + prev = np; + if (!of_device_is_compatible(np, "cache")) + break; + if (of_property_read_u32(np, "cache-level", &level)) + break; + if (level <= levels) + break; + if (of_property_read_bool(np, "cache-size")) + ++leaves; + if (of_property_read_bool(np, "i-cache-size")) + ++leaves; + if (of_property_read_bool(np, "d-cache-size")) + ++leaves; + levels = level; + } + + of_node_put(np); + this_cpu_ci->num_levels = levels; + this_cpu_ci->num_leaves = leaves; + + return 0; +} + #else static inline int cache_setup_of_node(unsigned int cpu) { return 0; } +int init_of_cache_level(unsigned int cpu) { return 0; } #endif int __weak cache_setup_acpi(unsigned int cpu) diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 00b7a6ae8617..ff0328f3fbb0 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -80,6 +80,7 @@ struct cpu_cacheinfo { struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu); int init_cache_level(unsigned int cpu); +int init_of_cache_level(unsigned int cpu); int populate_cache_leaves(unsigned int cpu); int cache_setup_acpi(unsigned int cpu); bool last_level_cache_is_valid(unsigned int cpu);