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: Wed, 21 Aug 2024 11:21:19 +0200 [thread overview]
Message-ID: <72e591e0-ba19-4035-ac29-c628da948a74@canonical.com> (raw)
In-Reply-To: <CAN37VV4+YkL3=H+M0qahnaPA6oHzGU_pnp4-MqftUK3fty2jhg@mail.gmail.com>
On 21.08.24 11:11, Mayuresh Chitale wrote:
> Hi Heinrich,
>
> On Tue, Aug 20, 2024 at 5:43 PM Heinrich Schuchardt
> <heinrich.schuchardt@canonical.com> wrote:
>>
>> 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.
> Ok.
>>
>>> +
>>> +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.
> Most of the code is already cache.c. I didn't know if it would suffice
> for all platforms so I decided to override the weak functions like in
> ARM.
With the suggestion below boards needing a board specific solution can
still override the weak functions. But I would expect that in future new
boards converge on zicbom.
Best regards
Heinrich
>
>> 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.
> Ok.
>>
>> Best regards
>>
>> Heinrich
>>
prev parent reply other threads:[~2024-08-21 9:21 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
2024-08-21 9:11 ` Mayuresh Chitale
2024-08-21 9:21 ` Heinrich Schuchardt [this message]
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=72e591e0-ba19-4035-ac29-c628da948a74@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