From patchwork Mon Sep 8 11:38:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 36968 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5029520491 for ; Mon, 8 Sep 2014 11:38:45 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf75553573obc.4 for ; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=fJKXmTovftvp2xYpniragL2EAzc/rN/Wl1C+U9daU0o=; b=eNYfBV+A+xce2dH2NoC5JLT703Xt7Mp+jwokdMkzCKCV554ud8vBlzxIB7801p2RZb 8TD187+TIwf6OW9+cO6DwJ/fZBMqM0wQ4Wk2b3t/ayRBBSTtyGPQ5dJB3oVUaFITPX8b g4ehqMaeWZNPSsYa5Xror/lM3u/1zvuyKVHvhRxq+nSNqIyDSkIemHFWhBQ69GKgisQ1 pC8khMLw/qdAaArN+jqIQaU5oRmSpI7GVJ7gOp1Rehh1uiiRn/1R+xKJJVJCpZbK4NXF LF+KjXPBKgcZtJLdcm3fhB29O0zY1jEMZrOYtQSfkXPACbB9ANT5SECzRHpCMQbXst26 i6hA== X-Gm-Message-State: ALoCoQlwLGRevV/XkdNQiuQGUQxyBMgB7oddCugfKEB0ZQa2x4T3CzcG2L8935PKV5LpXN9s6IWs X-Received: by 10.182.236.136 with SMTP id uu8mr714113obc.46.1410176324913; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.148 with SMTP id 20ls1637317qgt.86.gmail; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) X-Received: by 10.220.79.68 with SMTP id o4mr2499326vck.38.1410176324832; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id fg6si4410098vdc.31.2014.09.08.04.38.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Sep 2014 04:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lf12so15158131vcb.34 for ; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) X-Received: by 10.220.44.80 with SMTP id z16mr25062576vce.7.1410176324743; Mon, 08 Sep 2014 04:38:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp119398vcb; Mon, 8 Sep 2014 04:38:44 -0700 (PDT) X-Received: by 10.70.38.239 with SMTP id j15mr46268329pdk.109.1410176323710; Mon, 08 Sep 2014 04:38:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7si17209054pdl.188.2014.09.08.04.38.43 for ; Mon, 08 Sep 2014 04:38:43 -0700 (PDT) Received-SPF: none (google.com: linux-leds-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753808AbaIHLif (ORCPT ); Mon, 8 Sep 2014 07:38:35 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:43388 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753256AbaIHLie (ORCPT ); Mon, 8 Sep 2014 07:38:34 -0400 Received: by mail-wg0-f41.google.com with SMTP id k14so558262wgh.0 for ; Mon, 08 Sep 2014 04:38:32 -0700 (PDT) X-Received: by 10.194.200.137 with SMTP id js9mr33758003wjc.90.1410176312397; Mon, 08 Sep 2014 04:38:32 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id iy10sm11565938wic.8.2014.09.08.04.38.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Sep 2014 04:38:31 -0700 (PDT) From: Linus Walleij To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org Cc: Arnd Bergmann , Pawel Moll , Mark Rutland , Marc Zyngier , Will Deacon , Rob Herring , Linus Walleij Subject: [PATCH 6/7 v6] ARM: l2x0: calculate associativity from ePAPR cache props Date: Mon, 8 Sep 2014 13:38:05 +0200 Message-Id: <1410176286-32533-7-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1410176286-32533-1-git-send-email-linus.walleij@linaro.org> References: <1410176286-32533-1-git-send-email-linus.walleij@linaro.org> Sender: linux-leds-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-leds@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Using the cache size, number of sets and cache line size we can calculate desired associativity of the L2 cache. This is done by the calculation: associativity = (cache size / cache sets) / cache line size For most normal cache sizes this will quickly roof out to the maximum associativity of 8 (L2x0 variants) or 16 (PL3x0 variants). While all variants have a hard-coded line size of 32 bytes we also support reading the "cache-line-size" ePAPR binding and complain if it does not match the hardware. Signed-off-by: Linus Walleij --- arch/arm/mm/cache-l2x0.c | 62 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c index 61a684c743c6..f275cd4e5151 100644 --- a/arch/arm/mm/cache-l2x0.c +++ b/arch/arm/mm/cache-l2x0.c @@ -947,14 +947,18 @@ static u32 cache_id_part_number_from_dt; static void __init l2x0_cache_size_of_parse(const struct device_node *np, u32 *aux_val, u32 *aux_mask, - u32 max_way_size) + u32 max_way_size, + u32 max_associativity) { u32 mask = 0, val = 0; u32 size = 0, sets = 0; u32 way_size = 0, way_size_bits = 1; + u32 linesize = 0; + u32 assoc = 0; of_property_read_u32(np, "cache-size", &size); of_property_read_u32(np, "cache-sets", &sets); + of_property_read_u32(np, "cache-line-size", &linesize); if (!size || !sets) return; @@ -962,10 +966,56 @@ static void __init l2x0_cache_size_of_parse(const struct device_node *np, way_size = size / sets; if (way_size > max_way_size) { - pr_warn("L2C: way size %dKB is too large\n", way_size >> 10); + pr_warn("L2C OF: way size %dKB is too large\n", way_size >> 10); return; } + /* All these l2 caches have the same line size actually */ + if (!linesize) + linesize = CACHE_LINE_SIZE; + if (linesize != CACHE_LINE_SIZE) + pr_warn("L2C OF: DT supplied line size %d bytes does " + "not match hardware line size of %d bytes\n", + linesize, + CACHE_LINE_SIZE); + + /* + * This cache is set associative. By increasing associativity + * we increase the number of blocks per set. Usually this + * quickly hits the roof at 8 or 16 ways of associativity. + */ + assoc = way_size / linesize; + if (assoc > max_associativity) + assoc = max_associativity; + + mask |= L2X0_AUX_CTRL_ASSOC_MASK; + + /* + * Special checks for the PL310 that only has two settings and + * cannot be set to fully associative. + */ + if (max_associativity == 16) { + if (assoc <= 8) { + assoc = 8; + /* Leave bit 16 in associativity set to 0 */ + } + if (assoc > 8 && assoc <= 16) { + assoc = 16; + val |= L310_AUX_CTRL_ASSOCIATIVITY_16; + } + } else { + if (sets == 1) + /* Direct-mapped cache */ + assoc = 1; + val |= (assoc << L2X0_AUX_CTRL_ASSOC_SHIFT); + } + + pr_info("L2C OF: size: %d bytes (%dKB)\n", size, size >> 10); + pr_info("L2C OF: way_size: %d bytes (%d KB)\n", + way_size, way_size >> 10); + pr_info("L2C OF: associativity: %d ways\n", assoc); + + /* Convert to KB */ way_size >>= 10; switch (way_size) { case 512: @@ -987,7 +1037,7 @@ static void __init l2x0_cache_size_of_parse(const struct device_node *np, way_size_bits = 1; break; default: - pr_err("cache way size: %d KB is not mapped\n", + pr_err("L2C OF: cache way size: %d KB is not mapped\n", way_size); break; } @@ -1029,7 +1079,7 @@ static void __init l2x0_of_parse(const struct device_node *np, val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT; } - l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_256K); + l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_256K, 8); *aux_val &= ~mask; *aux_val |= val; @@ -1105,7 +1155,7 @@ static void __init l2c310_of_parse(const struct device_node *np, l2x0_base + L310_ADDR_FILTER_START); } - l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_512K); + l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_512K, 16); } static const struct l2c_init_data of_l2c310_data __initconst = { @@ -1313,7 +1363,7 @@ static void __init aurora_of_parse(const struct device_node *np, *aux_val |= val; *aux_mask &= ~mask; - l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_256K); + l2x0_cache_size_of_parse(np, aux_val, aux_mask, SZ_256K, 8); } static const struct l2c_init_data of_aurora_with_outer_data __initconst = {