[PATCH] hw/riscv: Treat kernel_start_addr as vaddr

Anton Johansson via posted 1 patch 4 days, 3 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251209123135.22534-1-anjo@rev.ng
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
There is a newer version of this series
include/hw/riscv/boot.h | 2 +-
hw/riscv/boot.c         | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[PATCH] hw/riscv: Treat kernel_start_addr as vaddr
Posted by Anton Johansson via 4 days, 3 hours ago
Changes kernel_start_addr from target_ulong to vaddr. Logically, the
argument represents the virtual address at which to load the kernel image,
which as a fallback gets treated as a hwaddr if elf/uimage loading fails.

(Note: callers of riscv_load_kernel() currently pass in a hwaddr as
kernel_start_addr, so I'm not 100% if hwaddr or vaddr is right here.
Please correct me if I'm wrong.)

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 include/hw/riscv/boot.h | 2 +-
 hw/riscv/boot.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h
index 51b0e13bd3..d872fe5e98 100644
--- a/include/hw/riscv/boot.h
+++ b/include/hw/riscv/boot.h
@@ -57,7 +57,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename,
                            symbol_fn_t sym_cb);
 void riscv_load_kernel(MachineState *machine,
                        RISCVBootInfo *info,
-                       target_ulong kernel_start_addr,
+                       vaddr kernel_start_addr,
                        bool load_initrd,
                        symbol_fn_t sym_cb);
 uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size,
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 75f34287ff..02a2bb2f87 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -228,7 +228,7 @@ static void riscv_load_initrd(MachineState *machine, RISCVBootInfo *info)
 
 void riscv_load_kernel(MachineState *machine,
                        RISCVBootInfo *info,
-                       target_ulong kernel_start_addr,
+                       vaddr kernel_start_addr,
                        bool load_initrd,
                        symbol_fn_t sym_cb)
 {
-- 
2.51.0


Re: [PATCH] hw/riscv: Treat kernel_start_addr as vaddr
Posted by Philippe Mathieu-Daudé 4 days, 2 hours ago
On 9/12/25 13:31, Anton Johansson wrote:
> Changes kernel_start_addr from target_ulong to vaddr. Logically, the
> argument represents the virtual address at which to load the kernel image,
> which as a fallback gets treated as a hwaddr if elf/uimage loading fails.
> 
> (Note: callers of riscv_load_kernel() currently pass in a hwaddr as
> kernel_start_addr, so I'm not 100% if hwaddr or vaddr is right here.
> Please correct me if I'm wrong.)

IMHO they need to be updated, i.e.:

-- >8 --
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
index a17f62cd082..bc4f409c19c 100644
--- a/hw/riscv/microchip_pfsoc.c
+++ b/hw/riscv/microchip_pfsoc.c
@@ -521,7 +521,8 @@ static void 
microchip_icicle_kit_machine_init(MachineState *machine)
      uint64_t mem_low_size, mem_high_size;
      hwaddr firmware_load_addr;
      const char *firmware_name;
-    hwaddr firmware_end_addr, kernel_start_addr;
+    hwaddr firmware_end_addr;
+    vaddr kernel_start_addr;
      uint64_t kernel_entry;
      uint64_t fdt_load_addr;
      DriveInfo *dinfo = drive_get(IF_SD, 0, 0);
---

> 
> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
>   include/hw/riscv/boot.h | 2 +-
>   hw/riscv/boot.c         | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>