From patchwork Thu Apr 6 23:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Rendec X-Patchwork-Id: 13204336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE2F5C76196 for ; Thu, 6 Apr 2023 23:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3FS/9+J22RrAZM5wfQ+ilSaWiH0gk5hIGTBJ1fEX194=; b=FSVnYH5QcYJYwe VTgYVlZotYHJuY11T3T3+HtFwJ8NbgQPQU2dnBVBjeAgdWAmPByfm8dkCc73QBo4YQuPydjbQ0ShF 8qtDOol3XXbm7JDh/XySkpZjDJK5IrAmOud3cutvxguxPTlfiJfnD+fwVx3USE095/Sfi3JQ6TivM 9odp1JzHwag+c/NI+dnIRttzlDriZ2ZFmjRmN2QB3YLL3tAZ9zjwbLvUrxNqK7Ww2/DOFz7qJp+ng 2IBU9zK1xPgk4qFNhlRUfB4f8mBYsMdppYPxxmjeKEhLfCSLdSHWgw6gcXklCkSBSyzIJEulTTCkK mHrOV4zpD409On8bI3UA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkZD8-008pER-2G; Thu, 06 Apr 2023 23:40:10 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkZD4-008pDE-2j for linux-arm-kernel@lists.infradead.org; Thu, 06 Apr 2023 23:40:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680824406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cc6KVLkxiFkbIiP9zsTzJIOe0YheAFkwqXrNmWhCyPk=; b=alrD9g2ydfBuIvLuUeCpT6e+AHy/Bo9bdl+rKFWD1IxIoQVi9hQcge+Dh41NJZ9BX7aEge w+kW8LuI8cdmszyZ8mUJjJ4bInPaoi+7Q5TBkpPlRbO71IX7MX7pvJVF0779RV9b9uiJQx mg6x5XOy1M7AUJH2ODivvtWfxTkvxCM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-AoMX1gScNEe-CbMidFbO9w-1; Thu, 06 Apr 2023 19:40:04 -0400 X-MC-Unique: AoMX1gScNEe-CbMidFbO9w-1 Received: by mail-qv1-f71.google.com with SMTP id pe26-20020a056214495a00b005df3eac4c0bso15546889qvb.1 for ; Thu, 06 Apr 2023 16:40:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680824404; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cc6KVLkxiFkbIiP9zsTzJIOe0YheAFkwqXrNmWhCyPk=; b=BPOMHdbiuiNOTkAOB5AdXN0ALQKbpGqT+vZLi8faoCZn35qME1lyJF2zEGbt+jXwgQ 08pfj0xv8QR3D8b3ohfp7jFU0WLhVcwkiU1ul4rA/r22P+9z68+/lbnbTmJT8Em+ubx1 0skZS5Q0K9x6hId1X+wlJ9jnc555HkF1RjkkYkQQKyyxoqBDKR3nqP8uSP8EHscgIWZ1 yobuhot0CiLqzeoELURJlbQbrd9M/R9qp8kq7pow/F3hT+O4y9URlVoeiyJu6yTNkBQL Ph73L57W+n7wsnJpXP84wktUKKs9WWGFV7bBXg9YBvIJBaAGNRa86abC6sNtUCUfF4Vo DHCQ== X-Gm-Message-State: AAQBX9eQ3Ttvrth2Z5+gbX8WyIt0I1dQnsPPGzlTDNesYv7OXHcKrVhb ZX83T4BUnqOzMg2MhiR0r1rdh14VOK5/OicLcTsI2cLr8vLQHNijyPjy3D2v3n8ZGxowQp7ZCx8 6C7TyvBVcjFjHofi8ayMiSmfib1jBKCIdeps= X-Received: by 2002:a05:6214:258a:b0:5aa:6130:7c63 with SMTP id fq10-20020a056214258a00b005aa61307c63mr1917413qvb.46.1680824404346; Thu, 06 Apr 2023 16:40:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9Dgcc6gLQTk8bLQ4IVUqeocwCx5vwYcTw5awKGExfowZ81MT28oLHi+tu3tjZv2Xx4Eyl7w== X-Received: by 2002:a05:6214:258a:b0:5aa:6130:7c63 with SMTP id fq10-20020a056214258a00b005aa61307c63mr1917395qvb.46.1680824404082; Thu, 06 Apr 2023 16:40:04 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id mk21-20020a056214581500b005dd8b9345f0sm865599qvb.136.2023.04.06.16.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 16:40:03 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Pierre Gondois , Sudeep Holla , linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/2] cacheinfo: Add arch specific early level initializer Date: Thu, 6 Apr 2023 19:39:25 -0400 Message-Id: <20230406233926.1670094-2-rrendec@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406233926.1670094-1-rrendec@redhat.com> References: <20230406233926.1670094-1-rrendec@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230406_164006_957374_86A2E1D0 X-CRM114-Status: GOOD ( 28.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch gives of architecture specific code the ability to initialize the cache level and allocate cacheinfo memory early, when cache level initialization runs on the primary CPU for all possible CPUs. This is part of a patch series that attempts to further the work in commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU"). Previously, in the absence of any DT/ACPI cache info, architecture specific cache detection and info allocation for secondary CPUs would happen in non-preemptible context during early CPU initialization and trigger a "BUG: sleeping function called from invalid context" splat on an RT kernel. More specifically, this patch adds the early_cache_level() function, which is called by fetch_cache_info() as a fallback when the number of cache leaves cannot be extracted from DT/ACPI. In the default generic (weak) implementation, this new function returns -ENOENT, which preserves the original behavior for architectures that do not implement the function. Since early detection can get the number of cache leaves wrong in some cases*, additional logic is added to still call init_cache_level() later on the secondary CPU, therefore giving the architecture specific code an opportunity to go back and fix the initial guess. Again, the original behavior is preserved for architectures that do not implement the new function. * For example, on arm64, CLIDR_EL1 detection works only when it runs on the current CPU. In other words, a CPU cannot detect the cache depth for any other CPU than itself. Signed-off-by: Radu Rendec --- drivers/base/cacheinfo.c | 75 +++++++++++++++++++++++++++------------ include/linux/cacheinfo.h | 2 ++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index f6573c335f4c..30f5553d3ebb 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -398,6 +398,11 @@ static void free_cache_attributes(unsigned int cpu) cache_shared_cpu_map_remove(cpu); } +int __weak early_cache_level(unsigned int cpu) +{ + return -ENOENT; +} + int __weak init_cache_level(unsigned int cpu) { return -ENOENT; @@ -423,56 +428,82 @@ int allocate_cache_info(int cpu) int fetch_cache_info(unsigned int cpu) { - struct cpu_cacheinfo *this_cpu_ci; + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); unsigned int levels = 0, split_levels = 0; int ret; if (acpi_disabled) { ret = init_of_cache_level(cpu); - if (ret < 0) - return ret; } else { ret = acpi_get_cache_info(cpu, &levels, &split_levels); - if (ret < 0) + if (!ret) { + this_cpu_ci->num_levels = levels; + /* + * This assumes that: + * - there cannot be any split caches (data/instruction) + * above a unified cache + * - data/instruction caches come by pair + */ + this_cpu_ci->num_leaves = levels + split_levels; + } + } + + if (ret || !cache_leaves(cpu)) { + ret = early_cache_level(cpu); + if (ret) return ret; - this_cpu_ci = get_cpu_cacheinfo(cpu); - this_cpu_ci->num_levels = levels; - /* - * This assumes that: - * - there cannot be any split caches (data/instruction) - * above a unified cache - * - data/instruction caches come by pair - */ - this_cpu_ci->num_leaves = levels + split_levels; + if (!cache_leaves(cpu)) + return -ENOENT; + + this_cpu_ci->early_arch_info = true; } - if (!cache_leaves(cpu)) - return -ENOENT; return allocate_cache_info(cpu); } -int detect_cache_attributes(unsigned int cpu) +static inline int init_level_allocate_ci(unsigned int cpu) { - int ret; + unsigned int early_leaves = cache_leaves(cpu); /* Since early initialization/allocation of the cacheinfo is allowed * via fetch_cache_info() and this also gets called as CPU hotplug * callbacks via cacheinfo_cpu_online, the init/alloc can be skipped * as it will happen only once (the cacheinfo memory is never freed). - * Just populate the cacheinfo. + * Just populate the cacheinfo. However, if the cacheinfo has been + * allocated early through the arch-specific early_cache_level() call, + * there is a chance the info is wrong (this can happen on arm64). In + * that case, call init_cache_level() anyway to give the arch-specific + * code a chance to make things right. */ - if (per_cpu_cacheinfo(cpu)) - goto populate_leaves; + if (per_cpu_cacheinfo(cpu) && !ci_cacheinfo(cpu)->early_arch_info) + return 0; if (init_cache_level(cpu) || !cache_leaves(cpu)) return -ENOENT; - ret = allocate_cache_info(cpu); + /* + * Now that we have properly initialized the cache level info, make + * sure we don't try to do that again the next time we are called + * (e.g. as CPU hotplug callbacks). + */ + ci_cacheinfo(cpu)->early_arch_info = false; + + if (cache_leaves(cpu) <= early_leaves) + return 0; + + kfree(per_cpu_cacheinfo(cpu)); + return allocate_cache_info(cpu); +} + +int detect_cache_attributes(unsigned int cpu) +{ + int ret; + + ret = init_level_allocate_ci(cpu); if (ret) return ret; -populate_leaves: /* * populate_cache_leaves() may completely setup the cache leaves and * shared_cpu_map or it may leave it partially setup. diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 908e19d17f49..c9d44308fc42 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -76,9 +76,11 @@ struct cpu_cacheinfo { unsigned int num_levels; unsigned int num_leaves; bool cpu_map_populated; + bool early_arch_info; }; struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu); +int early_cache_level(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); From patchwork Thu Apr 6 23:39:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Rendec X-Patchwork-Id: 13204337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06991C77B6C for ; Thu, 6 Apr 2023 23:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UkSm+VFJiXbcjfrbKTTqi9Bt5oHIRTnKfS+lUIIY7t8=; b=hRVng1iXJft6T9 7JoestTsHBMFL0yZI/gJGqgQxT8aiLcsj+hzhJVAyFeRFV6AnV5pqArbQeBduadbQoZUfP+i8F+SO v7rtH0wdx6Nf4gdUPvhTsx7dX4dvxM8GQXmko3+/z49qSfJ6dEpPi/xnxlkz3fAOUBZBM1LwEQrOv 0upugnvCHRFTOoaDJX4MQ8d2rMMT3/TkhH/vqs/dVcaps5Z43v3ynyLSnFxfXw5YlhRCmTxQG3ty1 gS3698p6mX9xydMqE76TW8uJntwNVFJAKWx59woC49C1DNT7SpSsNwCUBSqkX7NH+bqVfE/116nHh heqTY10bncgbkfIbb2Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkZDC-008pF2-2X; Thu, 06 Apr 2023 23:40:14 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkZDA-008pEX-0E for linux-arm-kernel@lists.infradead.org; Thu, 06 Apr 2023 23:40:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680824411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BFLHr8TD8RfqA6eplD+afVyXuh6c0xOW13sUk0OaDso=; b=YErFHKXDzrmR7XuGzsGtTZlGbsoGXgxjqUadGDVjAP5AIXJ4VRBtYFOLId0iUW76X+qNxt eYy6+/TSdDIzrYZWboEwd6pcbuqoM+yK1OfDf5F/liW5fCMqCG9/ejhW2n7d8nEO4DyBD7 xSnyELBIa0bi5winVq7WXfws+581QXM= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-_uuCus8vN_atmnBQs_mRhA-1; Thu, 06 Apr 2023 19:40:10 -0400 X-MC-Unique: _uuCus8vN_atmnBQs_mRhA-1 Received: by mail-qt1-f199.google.com with SMTP id u1-20020a05622a198100b003e12a0467easo27670807qtc.11 for ; Thu, 06 Apr 2023 16:40:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680824409; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BFLHr8TD8RfqA6eplD+afVyXuh6c0xOW13sUk0OaDso=; b=zOIV4aIB3SRXXkEeC/7qg6vJJQNU9XxWvsAg2yY4r/EvZYxoVqGyDGLzRl8/Yca7dy USCnbgh37leFJiVfWd0d4vPz6NEhwpYUVCzFlZIt3LsjBVyhazjf8AVg1MxkjlT/O8rU WlPaMyUYhEZ584l7XwlR5g/9/MBYQpHcsAgee+FHZYwSSmtvy8qcQZgFBbeUduvsgtCR xsI1YXyzXslr38V/WeIK6RTTG0pwxNr9hiO97mi4umDU/Bpp3cVZciMA1UD06XqLBvxN EIdtU8VixEyeq8rzeMjIoBk0uWoLXErTese4/YQVtxDo1XjNezC/sHrBll7459A0eGxe vaLw== X-Gm-Message-State: AAQBX9d3QK+YeaTk3iTnwB2MUMTsHwMmgrSdZxkvXFen1vYNLb4Ad5Ch ZLQjbFXnG7Wt9ssOunA+yQCwAlb0nV8hKsW+iTqW163n8M+lqGHbo13oLk5rzM1a/Xpt5QFDaK9 GhJavl/Ua2kpS62bjG0oPuJ52H4urX+io0Ec= X-Received: by 2002:a05:6214:2a87:b0:537:6416:fc2b with SMTP id jr7-20020a0562142a8700b005376416fc2bmr758095qvb.52.1680824409683; Thu, 06 Apr 2023 16:40:09 -0700 (PDT) X-Google-Smtp-Source: AKy350aTZWTs4QSNMHkYA2K7OeW1qBjRzYrUyinDc/jKPjqpu8gsXnfpGGgDYWwYR/lquRY5QeMyYA== X-Received: by 2002:a05:6214:2a87:b0:537:6416:fc2b with SMTP id jr7-20020a0562142a8700b005376416fc2bmr758083qvb.52.1680824409459; Thu, 06 Apr 2023 16:40:09 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id mk21-20020a056214581500b005dd8b9345f0sm865599qvb.136.2023.04.06.16.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 16:40:09 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Pierre Gondois , Sudeep Holla , linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/2] cacheinfo: Add arm64 early level initializer implementation Date: Thu, 6 Apr 2023 19:39:26 -0400 Message-Id: <20230406233926.1670094-3-rrendec@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406233926.1670094-1-rrendec@redhat.com> References: <20230406233926.1670094-1-rrendec@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230406_164012_188732_5FD1214A X-CRM114-Status: GOOD ( 20.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch adds an architecture specific early cache level detection handler for arm64. This is basically the CLIDR_EL1 based detection that was previously done (only) in init_cache_level(). This is part of a patch series that attempts to further the work in commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU"). Previously, in the absence of any DT/ACPI cache info, architecture specific cache detection and info allocation for secondary CPUs would happen in non-preemptible context during early CPU initialization and trigger a "BUG: sleeping function called from invalid context" splat on an RT kernel. This patch does not solve the problem completely for RT kernels. It relies on the assumption that on most systems, the CPUs are symmetrical and therefore have the same number of cache leaves. The cacheinfo memory is allocated early (on the primary CPU), relying on the new handler. If later (when CLIDR_EL1 based detection runs again on the secondary CPU) the initial assumption proves to be wrong and the CPU has in fact more leaves, the cacheinfo memory is reallocated, and that still triggers a splat on an RT kernel. In other words, asymmetrical CPU systems *must* still provide cacheinfo data in DT/ACPI to avoid the splat on RT kernels (unless secondary CPUs happen to have less leaves than the primary CPU). But symmetrical CPU systems (the majority) can now get away without the additional DT/ACPI data and rely on CLIDR_EL1 based detection. Signed-off-by: Radu Rendec --- arch/arm64/kernel/cacheinfo.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c index c307f69e9b55..520d17e4ebe9 100644 --- a/arch/arm64/kernel/cacheinfo.c +++ b/arch/arm64/kernel/cacheinfo.c @@ -38,21 +38,37 @@ static void ci_leaf_init(struct cacheinfo *this_leaf, this_leaf->type = type; } -int init_cache_level(unsigned int cpu) +static void detect_cache_level(unsigned int *level, unsigned int *leaves) { - unsigned int ctype, level, leaves; - int fw_level, ret; - struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + unsigned int ctype; - for (level = 1, leaves = 0; level <= MAX_CACHE_LEVEL; level++) { - ctype = get_cache_type(level); + for (*level = 1, *leaves = 0; *level <= MAX_CACHE_LEVEL; (*level)++) { + ctype = get_cache_type(*level); if (ctype == CACHE_TYPE_NOCACHE) { - level--; + (*level)--; break; } /* Separate instruction and data caches */ - leaves += (ctype == CACHE_TYPE_SEPARATE) ? 2 : 1; + *leaves += (ctype == CACHE_TYPE_SEPARATE) ? 2 : 1; } +} + +int early_cache_level(unsigned int cpu) +{ + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + + detect_cache_level(&this_cpu_ci->num_levels, &this_cpu_ci->num_leaves); + + return 0; +} + +int init_cache_level(unsigned int cpu) +{ + unsigned int level, leaves; + int fw_level, ret; + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + + detect_cache_level(&level, &leaves); if (acpi_disabled) { fw_level = of_find_last_cache_level(cpu);