public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: Zong Li <zong.li@sifive.com>,
	rick@andestech.com, ycliang@andestech.com, bmeng.cn@gmail.com,
	green.wan@sifive.com, paul.walmsley@sifive.com, sjg@chromium.org,
	u-boot@lists.denx.de
Subject: Re: [PATCH v2 2/6] board: sifive: use ccache driver instead of helper function
Date: Tue, 10 Aug 2021 00:51:08 -0400	[thread overview]
Message-ID: <d69b5fc4-ec85-a682-a38d-1ffc2620ca82@gmail.com> (raw)
In-Reply-To: <20210803044444.14032-3-zong.li@sifive.com>

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 <zong.li@sifive.com>
> ---
>   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 <pragnesh.patel@sifive.com>
>    */
>   
>   #include <common.h>
> -#include <asm/global_data.h>
> -#include <asm/io.h>
> -#include <linux/bitops.h>
> +#include <cache.h>
> +#include <dm.h>
>   
> -/* 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 <common.h>
> -#include <asm/io.h>
> -#include <linux/bitops.h>
> -#include <asm/global_data.h>
> +#include <cache.h>
> +#include <dm.h>
>   
> -/* 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.

--Sean

  reply	other threads:[~2021-08-10  4:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03  4:44 [PATCH v2 0/6] Support SiFive Composable cache driver Zong Li
2021-08-03  4:44 ` [PATCH v2 1/6] cache: add sifive composable " Zong Li
2021-08-10  4:39   ` Sean Anderson
2021-08-03  4:44 ` [PATCH v2 2/6] board: sifive: use ccache driver instead of helper function Zong Li
2021-08-10  4:51   ` Sean Anderson [this message]
2021-08-10  6:40     ` Zong Li
2021-08-03  4:44 ` [PATCH v2 3/6] riscv: lib: introduce cache_init interface Zong Li
2021-08-10  4:47   ` Sean Anderson
2021-08-10  6:57     ` Zong Li
2021-08-12 20:20       ` Sean Anderson
2021-08-13  4:00         ` Zong Li
2021-08-03  4:44 ` [PATCH v2 4/6] riscv: sifive: use common cache_init instead of duplicated implementation Zong Li
2021-08-03  4:44 ` [PATCH v2 5/6] riscv: lib: move platform-related libraries to sperate folder Zong Li
2021-08-10  4:55   ` Sean Anderson
2021-08-10  7:04     ` Zong Li
2021-08-12 20:22       ` Sean Anderson
2021-08-13  3:49         ` Zong Li
2021-08-03  4:44 ` [PATCH v2 6/6] riscv: lib: modify the indent Zong Li
2021-08-10  4:55   ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d69b5fc4-ec85-a682-a38d-1ffc2620ca82@gmail.com \
    --to=seanga2@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=green.wan@sifive.com \
    --cc=paul.walmsley@sifive.com \
    --cc=rick@andestech.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=ycliang@andestech.com \
    --cc=zong.li@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox