Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp681117pxb; Thu, 5 Nov 2020 10:06:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwvhrWWps7/lfbRS0+USB837/za6l5ABol4oCmQq1/V6HZGpCt6iwtZjtekkD2xjF/uXBKg X-Received: by 2002:a17:906:2b8b:: with SMTP id m11mr3646603ejg.457.1604599588543; Thu, 05 Nov 2020 10:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604599588; cv=none; d=google.com; s=arc-20160816; b=juIqVYqTe++6JxX9WgNfTSLxPJg3PTuFfV1B3vSCqM0CPkAPOnf78dQ87Xh5BmxkLw 7ZfxgGrsz39g6Xw+1RknwG5vpu5XO8pw7wvbE1hPS6osOjxJXXC0v0VJ7QU286tvyO+m wLjhSy4hqq9fHND4kv26qWgtIOcmtkal/r5quZUc00Eqd3qWutBK3ypX9D+tZp1ECZnf CcZowdHKOf21dF+VRJfE4b1AE90fY86kPyFmyeRxHSzwieGO+tbXIVYJXPAq8f38LXkN QpYy+CSC1k0xUBcmb/h7laeSQt8uF1Vf/PCu6J+Otd0d21uKnfp5l15PQudvr9nkagMs kwww== 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=ntWoyl/NxtYK1Y2MZnhCaUgcTJdcjkVq9YBwDHEgNLU=; b=YmDWp/cwTleo8V6i0cZZbSLvitm3QNYv0lORW07pNeqjhXgtkjvG62sXaFNV1R1CnJ 1W4cqFMvcZhLJakUYoW86QSE+y0oL2fwNmwERk/mdVenOFJe4j9XaUfjb/PHbrrFQekK I+6Yt0c3n/gDfUmYcRCl4kSTk2kOBmF8lZHstlbPfdxxij2i++NQvspLFZTZKv8SGjjb duR8B0KBzSt9mwuTkbzx+86COmotXNVjTIMGC3EzE+yTq5xjxAOTLXhCg84N0WQ4QadV 6tFzAH7ZqDTga/PIGcyAgS5XLQjr16evi77eL+3OaPvqNmaB0Cb8WEUyceQzJJioW3yv BBTQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yl23si1894899ejb.441.2020.11.05.10.06.04; Thu, 05 Nov 2020 10:06:28 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731805AbgKESBt (ORCPT + 99 others); Thu, 5 Nov 2020 13:01:49 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2060 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbgKESBt (ORCPT ); Thu, 5 Nov 2020 13:01:49 -0500 Received: from fraeml708-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4CRrSg73zhz67HHg; Fri, 6 Nov 2020 01:42:27 +0800 (CST) Received: from lhreml715-chm.china.huawei.com (10.201.108.66) by fraeml708-chm.china.huawei.com (10.206.15.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Thu, 5 Nov 2020 18:44:02 +0100 Received: from DESKTOP-6T4S3DQ.china.huawei.com (10.47.87.221) by lhreml715-chm.china.huawei.com (10.201.108.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Thu, 5 Nov 2020 17:44:01 +0000 From: Shiju Jose To: , , , , , , , , CC: , , Subject: [RFC PATCH 2/4] ACPI: PPTT: Add function acpi_find_cache_info Date: Thu, 5 Nov 2020 17:42:31 +0000 Message-ID: <20201105174233.1146-3-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20201105174233.1146-1-shiju.jose@huawei.com> References: <20201105174233.1146-1-shiju.jose@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.47.87.221] X-ClientProxiedBy: lhreml745-chm.china.huawei.com (10.201.108.195) To lhreml715-chm.china.huawei.com (10.201.108.66) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add function acpi_find_cache_info() to find the information of the caches found in a CPU hierarchy represented in the PPTT. Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- drivers/acpi/pptt.c | 62 +++++++++++++++++++++++++++++++++++++++ include/linux/cacheinfo.h | 12 ++++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index de1dd605d3ad..5f46e6257e6b 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -670,6 +670,68 @@ int acpi_find_last_cache_level(unsigned int cpu) return number_of_levels; } +/** + * acpi_find_cache_info() - Find the information of CPU caches + * represented in the PPTT. + * @cpu: Kernel logical CPU number. + * @cacheinfo: array of struct acpi_cacheinfo. + * @size: dimension of the array. + * + * Given a logical CPU number, returns the info of caches + * represented in the PPTT. + * Errors caused by lack of a PPTT table, or otherwise, return 0 + * indicating we didn't find any cache levels. + * + * Return: total number of caches found in the CPU hierarchy or error. + */ +int acpi_find_cache_info(unsigned int cpu, struct acpi_cacheinfo *cacheinfo, + size_t size) +{ + u32 acpi_cpu_id; + acpi_status status; + struct acpi_table_header *table_hdr; + struct acpi_pptt_processor *cpu_node = NULL; + struct acpi_pptt_cache *found_cache; + int i, number_of_caches = 0; + int max_level, level = 1; + enum cache_type type[] = { + CACHE_TYPE_DATA, + CACHE_TYPE_INST, + CACHE_TYPE_UNIFIED, + }; + + if (!cacheinfo || !size) + return -ENOMEM; + + status = acpi_get_table(ACPI_SIG_PPTT, 0, &table_hdr); + if (ACPI_FAILURE(status)) { + acpi_pptt_warn_missing(); + return -ENOENT; + } + + acpi_cpu_id = get_acpi_id_for_cpu(cpu); + max_level = acpi_find_cache_levels(table_hdr, acpi_cpu_id); + while (level <= max_level) { + for (i = 0; i < ARRAY_SIZE(type); i++) { + found_cache = acpi_find_cache_node(table_hdr, acpi_cpu_id, + type[i], level, &cpu_node); + if (found_cache) { + cacheinfo[number_of_caches].level = level; + cacheinfo[number_of_caches].type = acpi_cache_type(type[i]); + number_of_caches++; + if (number_of_caches >= size) { + acpi_put_table(table_hdr); + return -ENOMEM; + } + } + } + level++; + } + acpi_put_table(table_hdr); + + return number_of_caches; +} + /** * cache_setup_acpi() - Override CPU cache topology with data from the PPTT * @cpu: Kernel logical CPU number diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 4f72b47973c3..7d37945d2650 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -79,6 +79,11 @@ struct cpu_cacheinfo { bool cpu_map_populated; }; +struct acpi_cacheinfo { + u8 level; + u8 type; +}; + /* * Helpers to make sure "func" is executed on the cpu whose cache * attributes are being detected @@ -114,8 +119,15 @@ static inline int acpi_find_last_cache_level(unsigned int cpu) { return 0; } +static inline int acpi_find_cache_info(unsigned int cpu, struct acpi_cacheinfo *cacheinfo, + size_t size) +{ + return 0; +} #else int acpi_find_last_cache_level(unsigned int cpu); +int acpi_find_cache_info(unsigned int cpu, struct acpi_cacheinfo *cacheinfo, + size_t size); #endif const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf); -- 2.17.1