From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10E6BC4320A for ; Tue, 10 Aug 2021 06:40:50 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2B2961051 for ; Tue, 10 Aug 2021 06:40:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F2B2961051 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 54C3682BD6; Tue, 10 Aug 2021 08:40:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.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=sifive.com header.i=@sifive.com header.b="bST/Cu8c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BC0E82BD6; Tue, 10 Aug 2021 08:40:44 +0200 (CEST) Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) (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 D223980C8A for ; Tue, 10 Aug 2021 08:40:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=zong.li@sifive.com Received: by mail-lf1-x131.google.com with SMTP id w20so12705975lfu.7 for ; Mon, 09 Aug 2021 23:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pbzYWKwlHCXFjDOvSyYWYijT7BrLM7bA/gA/VZGrI/Y=; b=bST/Cu8cw89nLOOwrQBLGG8W2bJxvDUw6fvaUsVqLl7CedA/i/1woz62IS4CPvgSTM o7PKKXGQVAvMFJtl13xUqQYrsBP2mgqYnnCrmY+Nkr8LpMNH+kvWeetMpd+6wbcf2T7v BwCIFFhqRCCT4/SNswSeN6dam2ZsK0VnVcr22lS0LEgK4wsjqQVKyKuUg70fC1hBPXYd T7efar0+bQ+7tTuBJqJ4OF+9FHARybbzOCM/Cznq/Hy++nY7fz/vUh+XiLDKTjWvMAFK WT4neYwRZol/3kzP4A993XN8M5oqQP9wHosrBVolWhHOHCNWG+0J1a64TR8fIQkHoZs/ R4XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pbzYWKwlHCXFjDOvSyYWYijT7BrLM7bA/gA/VZGrI/Y=; b=QrKpkvTLYuPAvw5/xwRZTPeee95psmMgOCPMT4sC9jGJQt0cDpWD32kz/FchkkSS7U tYgzTivXsqsiCd0JYyoY+3jXKZNT9d71UV4KWXiSAL/TFsXRi19Cnz61iMycucXceQQ/ ErtcHALT9EKJKbS+NldZ6HBCbuNJ8mu7+rZQJ7yZ2zfaJMlt7JNcN/P1bg5eo5y7RmlV AsJPfpelcZGq5459TJmGhlINWni2R+1rBehKuzwlKxQPhbhQyg39ijhyxsy4Qlj169ms /fDFNhKcXW7SyjWD/I0Yuh3Puz2sBrbOQcIz2KLAVJoX996tfitgEtMS7xiJKfXfqz+x WM+g== X-Gm-Message-State: AOAM532H7rkppBCCoSgZZ9LC732n/902eraf3nnuC+42r2aroSRppYUo O7GIOFhGMkv3rSLSKkeSQuaqbnXS3981qZKPjaKqsQ== X-Google-Smtp-Source: ABdhPJy6ZGZIZ851Y0kdw/SxleQN2iHgr9w8E9mR5puMDSeUSeySata5kMqSaQqEmHSWBEuEx1PS3hAcpVa0xeYOoB0= X-Received: by 2002:ac2:4150:: with SMTP id c16mr21129605lfi.127.1628577639023; Mon, 09 Aug 2021 23:40:39 -0700 (PDT) MIME-Version: 1.0 References: <20210803044444.14032-1-zong.li@sifive.com> <20210803044444.14032-3-zong.li@sifive.com> In-Reply-To: From: Zong Li Date: Tue, 10 Aug 2021 14:40:27 +0800 Message-ID: Subject: Re: [PATCH v2 2/6] board: sifive: use ccache driver instead of helper function To: Sean Anderson Cc: rick@andestech.com, Leo Liang , Bin Meng , Green Wan , Paul Walmsley , sjg@chromium.org, u-boot@lists.denx.de Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On Tue, Aug 10, 2021 at 12:51 PM Sean Anderson wrote: > > On 8/3/21 12:44 AM, Zong Li wrote: > > Invokes the generic cache_enable interface to execute the relative > > implementation in SiFive ccache driver. > > > > Signed-off-by: Zong Li > > --- > > arch/riscv/cpu/fu540/Kconfig | 1 + > > arch/riscv/cpu/fu540/cache.c | 54 ++++++----------------- > > arch/riscv/cpu/fu740/Kconfig | 1 + > > arch/riscv/cpu/fu740/cache.c | 52 ++++++---------------- > > arch/riscv/include/asm/arch-fu540/cache.h | 2 +- > > arch/riscv/include/asm/arch-fu740/cache.h | 2 +- > > board/sifive/unleashed/unleashed.c | 10 +---- > > board/sifive/unmatched/unmatched.c | 9 +--- > > 8 files changed, 33 insertions(+), 98 deletions(-) > > > > diff --git a/arch/riscv/cpu/fu540/Kconfig b/arch/riscv/cpu/fu540/Kconfig > > index 05463b2625..8608741779 100644 > > --- a/arch/riscv/cpu/fu540/Kconfig > > +++ b/arch/riscv/cpu/fu540/Kconfig > > @@ -19,6 +19,7 @@ config SIFIVE_FU540 > > imply SMP > > imply CLK_SIFIVE > > imply CLK_SIFIVE_PRCI > > + imply SIFIVE_CCACHE > > imply SIFIVE_SERIAL > > imply MACB > > imply MII > > diff --git a/arch/riscv/cpu/fu540/cache.c b/arch/riscv/cpu/fu540/cache.c > > index 0fc4ef6c00..bc31f664b8 100644 > > --- a/arch/riscv/cpu/fu540/cache.c > > +++ b/arch/riscv/cpu/fu540/cache.c > > @@ -1,55 +1,29 @@ > > // SPDX-License-Identifier: GPL-2.0+ > > /* > > - * Copyright (C) 2020 SiFive, Inc > > + * Copyright (C) 2020 - 2021 SiFive, Inc > > * > > * Authors: > > * Pragnesh Patel > > */ > > > > #include > > -#include > > -#include > > -#include > > +#include > > +#include > > > > -/* Register offsets */ > > -#define L2_CACHE_CONFIG 0x000 > > -#define L2_CACHE_ENABLE 0x008 > > - > > -#define MASK_NUM_WAYS GENMASK(15, 8) > > -#define NUM_WAYS_SHIFT 8 > > - > > -DECLARE_GLOBAL_DATA_PTR; > > - > > -int cache_enable_ways(void) > > +int sifive_ccache_enable_ways(void) > > { > > - const void *blob = gd->fdt_blob; > > - int node; > > - fdt_addr_t base; > > - u32 config; > > - u32 ways; > > - > > - volatile u32 *enable; > > - > > - node = fdt_node_offset_by_compatible(blob, -1, > > - "sifive,fu540-c000-ccache"); > > - > > - if (node < 0) > > - return node; > > - > > - base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0, > > - NULL, false); > > - if (base == FDT_ADDR_T_NONE) > > - return FDT_ADDR_T_NONE; > > + struct udevice *dev; > > + int ret; > > > > - config = readl((volatile u32 *)base + L2_CACHE_CONFIG); > > - ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT; > > + ret = uclass_get_device_by_driver(UCLASS_CACHE, > > + DM_DRIVER_GET(sifive_ccache), > > + &dev); > > + if (ret) > > + return log_msg_ret("Cannot enable cache ways", ret); > > > > - enable = (volatile u32 *)(base + L2_CACHE_ENABLE); > > + ret = cache_enable(dev); > > + if (ret) > > + return log_msg_ret("ccache enable failed", ret); > > > > - /* memory barrier */ > > - mb(); > > - (*enable) = ways - 1; > > - /* memory barrier */ > > - mb(); > > return 0; > > } > > diff --git a/arch/riscv/cpu/fu740/Kconfig b/arch/riscv/cpu/fu740/Kconfig > > index 408195f149..b4cada0ea9 100644 > > --- a/arch/riscv/cpu/fu740/Kconfig > > +++ b/arch/riscv/cpu/fu740/Kconfig > > @@ -19,6 +19,7 @@ config SIFIVE_FU740 > > imply SMP > > imply CLK_SIFIVE > > imply CLK_SIFIVE_PRCI > > + imply SIFIVE_CCACHE > > imply SIFIVE_SERIAL > > imply MACB > > imply MII > > diff --git a/arch/riscv/cpu/fu740/cache.c b/arch/riscv/cpu/fu740/cache.c > > index 680955c9e3..e2782d76c0 100644 > > --- a/arch/riscv/cpu/fu740/cache.c > > +++ b/arch/riscv/cpu/fu740/cache.c > > @@ -7,49 +7,23 @@ > > */ > > > > #include > > -#include > > -#include > > -#include > > +#include > > +#include > > > > -/* Register offsets */ > > -#define L2_CACHE_CONFIG 0x000 > > -#define L2_CACHE_ENABLE 0x008 > > - > > -#define MASK_NUM_WAYS GENMASK(15, 8) > > -#define NUM_WAYS_SHIFT 8 > > - > > -DECLARE_GLOBAL_DATA_PTR; > > - > > -int cache_enable_ways(void) > > +int sifive_ccache_enable_ways(void) > > { > > - const void *blob = gd->fdt_blob; > > - int node; > > - fdt_addr_t base; > > - u32 config; > > - u32 ways; > > - > > - volatile u32 *enable; > > - > > - node = fdt_node_offset_by_compatible(blob, -1, > > - "sifive,fu740-c000-ccache"); > > - > > - if (node < 0) > > - return node; > > - > > - base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0, > > - NULL, false); > > - if (base == FDT_ADDR_T_NONE) > > - return FDT_ADDR_T_NONE; > > + struct udevice *dev; > > + int ret; > > > > - config = readl((volatile u32 *)base + L2_CACHE_CONFIG); > > - ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT; > > + ret = uclass_get_device_by_driver(UCLASS_CACHE, > > + DM_DRIVER_GET(sifive_ccache), > > + &dev); > > + if (ret) > > + return log_msg_ret("Cannot enable cache ways", ret); > > > > - enable = (volatile u32 *)(base + L2_CACHE_ENABLE); > > + ret = cache_enable(dev); > > + if (ret) > > + return log_msg_ret("ccache enable failed", ret); > > > > - /* memory barrier */ > > - mb(); > > - (*enable) = ways - 1; > > - /* memory barrier */ > > - mb(); > > return 0; > > } > > diff --git a/arch/riscv/include/asm/arch-fu540/cache.h b/arch/riscv/include/asm/arch-fu540/cache.h > > index 135a17c679..c252eb64d1 100644 > > --- a/arch/riscv/include/asm/arch-fu540/cache.h > > +++ b/arch/riscv/include/asm/arch-fu540/cache.h > > @@ -9,6 +9,6 @@ > > #ifndef _CACHE_SIFIVE_H > > #define _CACHE_SIFIVE_H > > > > -int cache_enable_ways(void); > > +int sifive_ccache_enable_ways(void); > > > > #endif /* _CACHE_SIFIVE_H */ > > diff --git a/arch/riscv/include/asm/arch-fu740/cache.h b/arch/riscv/include/asm/arch-fu740/cache.h > > index 7d4fe9942b..8c456e3658 100644 > > --- a/arch/riscv/include/asm/arch-fu740/cache.h > > +++ b/arch/riscv/include/asm/arch-fu740/cache.h > > @@ -9,6 +9,6 @@ > > #ifndef _CACHE_SIFIVE_H > > #define _CACHE_SIFIVE_H > > > > -int cache_enable_ways(void); > > +int sifive_ccache_enable_ways(void); > > > > #endif /* _CACHE_SIFIVE_H */ > > diff --git a/board/sifive/unleashed/unleashed.c b/board/sifive/unleashed/unleashed.c > > index 43027f0b54..12e61ec85f 100644 > > --- a/board/sifive/unleashed/unleashed.c > > +++ b/board/sifive/unleashed/unleashed.c > > @@ -126,14 +126,6 @@ void *board_fdt_blob_setup(void) > > > > int board_init(void) > > { > > - int ret; > > - > > /* enable all cache ways */ > > - ret = cache_enable_ways(); > > - if (ret) { > > - debug("%s: could not enable cache ways\n", __func__); > > - return ret; > > - } > > - > > - return 0; > > + return sifive_ccache_enable_ways(); > > } > > diff --git a/board/sifive/unmatched/unmatched.c b/board/sifive/unmatched/unmatched.c > > index 2f5629b578..d27c4d3e88 100644 > > --- a/board/sifive/unmatched/unmatched.c > > +++ b/board/sifive/unmatched/unmatched.c > > @@ -23,13 +23,6 @@ void *board_fdt_blob_setup(void) > > > > int board_init(void) > > { > > - int ret; > > - > > /* enable all cache ways */ > > - ret = cache_enable_ways(); > > - if (ret) { > > - debug("%s: could not enable cache ways\n", __func__); > > - return ret; > > - } > > - return 0; > > + return sifive_ccache_enable_ways(); > > } > > > > Can you combine patches 2-4 in some way? It seems like you add some code only to immediately refactor it. > Okay, let me tidy up these patches. I separated them because I'd like to separate the histories of using ccache driver and using common interfaces, so people could easily know the process of evolution. But yes, I might as well re-split the patches and combine them. > --Sean