From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-riscv@nongnu.org,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Anton Johansson" <anjo@rev.ng>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Bin Meng" <bmeng.cn@gmail.com>,
"Weiwei Li" <liwei1518@gmail.com>
Subject: Re: [PATCH] hw/riscv/spike: Replace tswap64() by ldq_endian_p()
Date: Thu, 3 Oct 2024 23:03:06 +0200 [thread overview]
Message-ID: <71f9e218-a5a7-4f24-9b8e-a8af11ad2f41@linaro.org> (raw)
In-Reply-To: <3567507b-4e1e-4924-9088-8be3b09f552f@ventanamicro.com>
On 2/10/24 17:01, Daniel Henrique Barboza wrote:
> On 10/2/24 11:44 AM, Mark Cave-Ayland wrote:
>> On 02/10/2024 15:17, Daniel Henrique Barboza wrote:
>>
>>> Phil, this patch breaks 'make check-avocado' in my env:
>>> On 9/30/24 9:48 AM, Philippe Mathieu-Daudé wrote:
>>>> Hold the target endianness in HTIFState::target_is_bigendian.
>>>> Pass the target endianness as argument to htif_mm_init().
>>>> Replace tswap64() calls by ldq_endian_p() ones.
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>> ---
>>>> Based-on: <20240930073450.33195-2-philmd@linaro.org>
>>>> "qemu/bswap: Introduce ld/st_endian_p() API"
>>>>
>>>> Note: this is a non-QOM device!
>>>> ---
>>>> include/hw/char/riscv_htif.h | 4 +++-
>>>> hw/char/riscv_htif.c | 17 +++++++++++------
>>>> hw/riscv/spike.c | 2 +-
>>>> 3 files changed, 15 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/include/hw/char/riscv_htif.h
>>>> b/include/hw/char/riscv_htif.h
>>>> index df493fdf6b..24868ddfe1 100644
>>>> --- a/include/hw/char/riscv_htif.h
>>>> +++ b/include/hw/char/riscv_htif.h
>>>> @@ -35,6 +35,7 @@ typedef struct HTIFState {
>>>> hwaddr tohost_offset;
>>>> hwaddr fromhost_offset;
>>>> MemoryRegion mmio;
>>>> + bool target_is_bigendian;
>>>> CharBackend chr;
>>>> uint64_t pending_read;
>>>> @@ -49,6 +50,7 @@ void htif_symbol_callback(const char *st_name, int
>>>> st_info, uint64_t st_value,
>>>> /* legacy pre qom */
>>>> HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr,
>>>> - uint64_t nonelf_base, bool custom_base);
>>>> + uint64_t nonelf_base, bool custom_base,
>>>> + bool target_is_bigendian);
>>>> #endif
>>>> diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
>>>> index 9bef60def1..77951f3c76 100644
>>>> --- a/hw/char/riscv_htif.c
>>>> +++ b/hw/char/riscv_htif.c
>>>> @@ -30,7 +30,6 @@
>>>> #include "qemu/timer.h"
>>>> #include "qemu/error-report.h"
>>>> #include "exec/address-spaces.h"
>>>> -#include "exec/tswap.h"
>>>> #include "sysemu/dma.h"
>>>> #include "sysemu/runstate.h"
>>>> @@ -211,13 +210,17 @@ static void htif_handle_tohost_write(HTIFState
>>>> *s, uint64_t val_written)
>>>> SHUTDOWN_CAUSE_GUEST_SHUTDOWN, exit_code);
>>>> return;
>>>> } else {
>>>> + bool be = s->target_is_bigendian;
>>>> uint64_t syscall[8];
>>>> +
>>>> cpu_physical_memory_read(payload, syscall,
>>>> sizeof(syscall));
>>>> - if (tswap64(syscall[0]) == PK_SYS_WRITE &&
>>>> - tswap64(syscall[1]) == HTIF_DEV_CONSOLE &&
>>>> - tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) {
>>>> + if (ldq_endian_p(be, &syscall[0]) == PK_SYS_WRITE &&
>>>> + ldq_endian_p(be, &syscall[1]) ==
>>>> HTIF_DEV_CONSOLE &&
>>>> + ldq_endian_p(be, &syscall[3]) ==
>>>> HTIF_CONSOLE_CMD_PUTC) {
>>>> uint8_t ch;
>>>> - cpu_physical_memory_read(tswap64(syscall[2]),
>>>> &ch, 1);
>>>> +
>>>> + cpu_physical_memory_read(ldl_endian_p(be,
>>>> &syscall[2]),
>>
>> ^^^^^^^^^^^^
>>
>> Shouldn't this be ldq_endian_p() for a 64-bit value?
Oops, thanks Mark, stupid c/p mistake.
> Bingo! This change fixes make check-avocado and the OpenSBI boot:
>
> $ git diff
> diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
> index 77951f3c76..0ed038a70c 100644
> --- a/hw/char/riscv_htif.c
> +++ b/hw/char/riscv_htif.c
> @@ -219,7 +219,7 @@ static void htif_handle_tohost_write(HTIFState *s,
> uint64_t val_written)
> ldq_endian_p(be, &syscall[3]) ==
> HTIF_CONSOLE_CMD_PUTC) {
> uint8_t ch;
>
> - cpu_physical_memory_read(ldl_endian_p(be,
> &syscall[2]),
> + cpu_physical_memory_read(ldq_endian_p(be,
> &syscall[2]),
> &ch, 1);
> qemu_chr_fe_write(&s->chr, &ch, 1);
> resp = 0x100 | (uint8_t)payload;
>
> $ ./build/qemu-system-riscv32 -M spike --nographic
>
> OpenSBI v1.5.1
> ____ _____ ____ _____
> / __ \ / ____| _ \_ _|
> | | | |_ __ ___ _ __ | (___ | |_) || |
> | | | | '_ \ / _ \ '_ \ \___ \| _ < | |
> | |__| | |_) | __/ | | |____) | |_) || |_
> \____/| .__/ \___|_| |_|_____/|____/_____|
> | |
> |_|
> (...)
I'll take that as a T-b tag :P Thanks Daniel!
prev parent reply other threads:[~2024-10-03 21:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 12:48 [PATCH] hw/riscv/spike: Replace tswap64() by ldq_endian_p() Philippe Mathieu-Daudé
2024-10-02 14:17 ` Daniel Henrique Barboza
2024-10-02 14:44 ` Mark Cave-Ayland
2024-10-02 15:01 ` Daniel Henrique Barboza
2024-10-03 21:03 ` Philippe Mathieu-Daudé [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=71f9e218-a5a7-4f24-9b8e-a8af11ad2f41@linaro.org \
--to=philmd@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=anjo@rev.ng \
--cc=bmeng.cn@gmail.com \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=thuth@redhat.com \
--cc=zhiwei_liu@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).