From patchwork Mon Apr 11 16:26:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1615847 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RT+iOe0j; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KcZ6y2zpmz9sDX for ; Tue, 12 Apr 2022 02:28:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2774383E73; Mon, 11 Apr 2022 18:27:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RT+iOe0j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A5D983E41; Mon, 11 Apr 2022 18:27:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 69B6783E45 for ; Mon, 11 Apr 2022 18:26:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ovpanait@gmail.com Received: by mail-ed1-x52d.google.com with SMTP id t25so6459005edt.9 for ; Mon, 11 Apr 2022 09:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mj9f23xQhBtpH2+ku1imdmza7nZh/nqkNIEVqfmokdA=; b=RT+iOe0j6XS/6o5vyiWQuDDkZizj8myVa4ZoYVZv7eFHOoBVgipMCib0Ip0LrqReso ze+3hZY5eHS0GQWfQdGVuHKhRfvZ89hsvDEKtWx+w6so1HszCo80Um5FQsialsHe+HF2 gHcpeqljj/cb5hN6YEcHlyICORdUdzo6otbvcApKZsYwQMNoO2SvfMVJfmD7p7zeutD6 fQHibUmIIimBRn5szeq/E19hncYC5RZxTPE3dvbvA8No1CzOndd3HuEinT0MDRjl669l L1giosYc+0FVZwkh4UgB7VtLaf25Vym9842NYhfimiDzXbZrBSrQ9e+71og0IXo0VWwH 8ZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mj9f23xQhBtpH2+ku1imdmza7nZh/nqkNIEVqfmokdA=; b=LmpFD44rZ+QUiSIDMwgDyHEJSGiD/AlzyhijbceRarmaBhxj3OhbdFMfQxAfR8lSa/ LyIcORfkRrnUQCM/o4G82D2FAE4zzUqLNdfyPW+ID7W16y2Zbx7Wj+gHal6Fluwkoi43 lcW5MvPvmROKzHYdgjLvkbn8Xy9Jjrv4QACxc/bR+YylLPop92BluB/FJUfXIWLd6Ajd hCBfaJdw7YR8pBoo2xwR9sBx6t/PxiAzcTrRRuMYMVfU0fIKZkwlNT42Fa9CxWIpF9ha WBX4ZzLElEqIJFu5loKANUwUshPWuKhSyKcoc6Q6a9Q/sbJpWW/oI9lMrAnpf3mNtHEz X5Fg== X-Gm-Message-State: AOAM531BH1gpcO9/cM0d/aiDgA49FL0ODb9ESHXR/eVS8MUwov6s+djr JXgU41+dkkkqYd44JitfFl/sZxwKsH+pAw== X-Google-Smtp-Source: ABdhPJwEseGOpvsWCtcmQKRB8XK+UnLzuKjNraq8wJVlWOld/mbn9JOOXfyTQvCze2wXRzVPmFXc7Q== X-Received: by 2002:aa7:de0e:0:b0:41d:6e55:24aa with SMTP id h14-20020aa7de0e000000b0041d6e5524aamr12270750edv.368.1649694419010; Mon, 11 Apr 2022 09:26:59 -0700 (PDT) Received: from wsdell.corp.ad.wrs.com ([2a02:2f0e:c41b:f600:4ab1:7aea:1e9:311a]) by smtp.gmail.com with ESMTPSA id y26-20020a1709063a9a00b006e0c272e263sm12111417ejd.71.2022.04.11.09.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 09:26:58 -0700 (PDT) From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Michal Simek , Michal Simek Subject: [PATCH 10/10] microblaze: cache: use fdt cache size info if available Date: Mon, 11 Apr 2022 19:26:34 +0300 Message-Id: <20220411162634.69647-10-ovpanait@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411162634.69647-1-ovpanait@gmail.com> References: <20220411162634.69647-1-ovpanait@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean If CONFIG_CPU_MICROBLAZE is enabled, the cache size and cache line size are retrieved from the fdt by the microblaze cpu driver. Adjust cache flush code to use those values if available. If a cache flush is requested very early in the boot (for example the flush_cache_all() call in start.S) or before dm is ready, the default size of CONFIG_XILINX_MICROBLAZE0_DEFAULT_CACHE_SIZE will be used instead. Signed-off-by: Ovidiu Panait --- arch/microblaze/cpu/cache.c | 45 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/arch/microblaze/cpu/cache.c b/arch/microblaze/cpu/cache.c index cce33a6eb5..8b7e212a26 100644 --- a/arch/microblaze/cpu/cache.c +++ b/arch/microblaze/cpu/cache.c @@ -9,11 +9,21 @@ #include #include #include +#include static void __invalidate_icache(ulong addr, ulong size) { if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) { - for (int i = 0; i < size; i += 4) { + int line_length = 4; + + if (CONFIG_IS_ENABLED(CPU_MICROBLAZE)) { + int size = microblaze_cpu_get_cacheline_size(ICACHE); + + if (size > 0) + line_length = size; + } + + for (int i = 0; i < size; i += line_length) { asm volatile ( "wic %0, r0;" "nop;" @@ -26,13 +36,31 @@ static void __invalidate_icache(ulong addr, ulong size) void invalidate_icache_all(void) { - __invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_DEFAULT_CACHE_SIZE); + int cache_size = CONFIG_XILINX_MICROBLAZE0_DEFAULT_CACHE_SIZE; + + if (CONFIG_IS_ENABLED(CPU_MICROBLAZE)) { + int size = microblaze_cpu_get_cache_size(ICACHE); + + if (size >= 0) + cache_size = size; + } + + __invalidate_icache(0, cache_size); } static void __flush_dcache(ulong addr, ulong size) { if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) { - for (int i = 0; i < size; i += 4) { + int line_length = 4; + + if (CONFIG_IS_ENABLED(CPU_MICROBLAZE)) { + int size = microblaze_cpu_get_cacheline_size(DCACHE); + + if (size > 0) + line_length = size; + } + + for (int i = 0; i < size; i += line_length) { asm volatile ( "wdc.flush %0, r0;" "nop;" @@ -53,7 +81,16 @@ void flush_dcache_range(unsigned long start, unsigned long end) void flush_dcache_all(void) { - __flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DEFAULT_CACHE_SIZE); + int cache_size = CONFIG_XILINX_MICROBLAZE0_DEFAULT_CACHE_SIZE; + + if (CONFIG_IS_ENABLED(CPU_MICROBLAZE)) { + int size = microblaze_cpu_get_cache_size(DCACHE); + + if (size >= 0) + cache_size = size; + } + + __flush_dcache(0, cache_size); } int dcache_status(void)