U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
To: Mayuresh Chitale <mchitale@ventanamicro.com>
Cc: "Bin Meng" <bmeng.cn@gmail.com>, "Tom Rini" <trini@konsulko.com>,
	"Łukasz Stelmach" <l.stelmach@samsung.com>,
	"Leo Yu-Chi Liang" <ycliang@andestech.com>,
	u-boot@lists.denx.de, "Rick Chen" <rick@andestech.com>
Subject: Re: [PATCH v1 3/3] board: qemu-riscv: Override enable_caches
Date: Tue, 20 Aug 2024 14:12:54 +0200	[thread overview]
Message-ID: <d7363b19-5cc6-4590-adfb-0889ea3aaf5f@canonical.com> (raw)
In-Reply-To: <20240820093800.5436-4-mchitale@ventanamicro.com>

On 20.08.24 11:37, Mayuresh Chitale wrote:
> Define enable_caches function for the qemu-riscv board which probes for
> the cbom-block-size dt property when RISCV_ISA_ZICBOM is enabled. Also
> add flush_dcache_range and invalidate_dcache_range functions which use
> the corresponding CBO ops.
> 
> Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
> ---
>   board/emulation/qemu-riscv/qemu-riscv.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
> index e5193e31e3..1795d2f831 100644
> --- a/board/emulation/qemu-riscv/qemu-riscv.c
> +++ b/board/emulation/qemu-riscv/qemu-riscv.c
> @@ -14,6 +14,7 @@
>   #include <usb.h>
>   #include <virtio_types.h>
>   #include <virtio.h>
> +#include <asm/cache.h>
>   
>   DECLARE_GLOBAL_DATA_PTR;
>   
> @@ -70,3 +71,18 @@ void *board_fdt_blob_setup(int *err)
>   	/* Stored the DTB address there during our init */
>   	return (void *)(ulong)gd->arch.firmware_fdt_addr;
>   }
> +
> +void enable_caches(void)
> +{
> +	riscv_zicbom_init();
> +}

Enable caches may be called multiple times. But riscv_zicbom_init() only 
needs to be called once.

> +
> +void flush_dcache_range(unsigned long start, unsigned long end)
> +{
> +	cbo_flush(start, end);
> +}
> +
> +void invalidate_dcache_range(unsigned long start, unsigned long end)
> +{
> +	cbo_inval(start, end);
> +}

The ZICBOM extension is not specific to a single board. We should not 
add this code to board files but into the central place for cache 
operations, i.e. arch/riscv/lib/cache.c.

E.g.

static int get_zicbom_block_size()
{
	if (!CONFIG_IS_ENABLED(RISCV_ISA_ZICBOM))
		return 0;
	if (zicbom_block_size)
		return zicbom_block_size;

	uclass_first_device(UCLASS_CPU, &dev);
	if (!dev) {
		log_err("Failed to get CPU device!\n");
		return 0;
	}

	if (dev_read_u32(dev, "riscv,cbom-block-size", &zicbom_block_size))
		return 0;
	
	return zicbom_block_size
}

__weak void invalidate_icache_range(unsigned long start, unsigned long end)
{
	if (CONFIG_IS_ENABLED(RISCV_ISA_ZICBOM) && get_zicbom_block_size())
		cbo_inval(start, end);
	else		
	        invalidate_icache_all();
}

Cc: Rick as one of the RISC-V maintainers.

Best regards

Heinrich


  reply	other threads:[~2024-08-20 12:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-20  9:37 [PATCH v1 0/3] Risc-V cache operations Mayuresh Chitale
2024-08-20  9:37 ` [PATCH v1 1/3] riscv: Add support for defining instructions Mayuresh Chitale
2024-08-20  9:37 ` [PATCH v1 2/3] riscv: cache: Add CBO instructions Mayuresh Chitale
2024-08-20 12:14   ` Heinrich Schuchardt
2024-08-21  9:11     ` Mayuresh Chitale
2024-08-21  9:57     ` Conor Dooley
2024-08-21 10:03       ` Conor.Dooley
2024-08-21 16:04         ` Mayuresh Chitale
2024-08-21 15:57       ` Mayuresh Chitale
2024-08-21 16:09         ` Conor Dooley
2024-08-20  9:37 ` [PATCH v1 3/3] board: qemu-riscv: Override enable_caches Mayuresh Chitale
2024-08-20 12:12   ` Heinrich Schuchardt [this message]
2024-08-21  9:11     ` Mayuresh Chitale
2024-08-21  9:21       ` Heinrich Schuchardt

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=d7363b19-5cc6-4590-adfb-0889ea3aaf5f@canonical.com \
    --to=heinrich.schuchardt@canonical.com \
    --cc=bmeng.cn@gmail.com \
    --cc=l.stelmach@samsung.com \
    --cc=mchitale@ventanamicro.com \
    --cc=rick@andestech.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=ycliang@andestech.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