From: Anton Johansson via <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PATCH 5/7] hw/loongarch: Use loongarch_palen_mask()
Date: Tue, 09 Dec 2025 14:56:06 +0100 [thread overview]
Message-ID: <20251209-phys_addr-v1-5-c387f3e72d77@rev.ng> (raw)
In-Reply-To: <20251209-phys_addr-v1-0-c387f3e72d77@rev.ng>
Replaces remaining uses of TARGET_PHYS_ADDR_SPACE_BITS with
runtime calls to loongarch_palen_mask() to fetch the physical
address mask from the cpucfg PALEN field.
Signed-off-by: Anton Johansson <anjo@rev.ng>
---
include/hw/loongarch/boot.h | 3 ++-
hw/loongarch/boot.c | 28 ++++++++++++++++------------
hw/loongarch/virt.c | 5 ++++-
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index 9819f7fbe3..4984322f75 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -113,6 +113,7 @@ struct memmap_entry {
uint32_t reserved;
};
-void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info);
+void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info,
+ uint64_t phys_addr_mask);
#endif /* HW_LOONGARCH_BOOT_H */
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 8857a04998..d18aa575ba 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -217,10 +217,12 @@ static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
{
- return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
+ uint64_t *phys_addr_mask = opaque;
+ return addr & *phys_addr_mask;
}
static int64_t load_loongarch_linux_image(const char *filename,
+ uint64_t phys_addr_mask,
uint64_t *kernel_entry,
uint64_t *kernel_low,
uint64_t *kernel_high)
@@ -251,10 +253,8 @@ static int64_t load_loongarch_linux_image(const char *filename,
}
/* Early kernel versions may have those fields in virtual address */
- *kernel_entry = extract64(le64_to_cpu(hdr->kernel_entry),
- 0, TARGET_PHYS_ADDR_SPACE_BITS);
- *kernel_low = extract64(le64_to_cpu(hdr->load_offset),
- 0, TARGET_PHYS_ADDR_SPACE_BITS);
+ *kernel_entry = le64_to_cpu(hdr->kernel_entry) & phys_addr_mask;
+ *kernel_low = le64_to_cpu(hdr->load_offset) & phys_addr_mask;
*kernel_high = *kernel_low + size;
rom_add_blob_fixed(filename, buffer, size, *kernel_low);
@@ -303,19 +303,21 @@ static ram_addr_t alloc_initrd_memory(struct loongarch_boot_info *info,
exit(1);
}
-static int64_t load_kernel_info(struct loongarch_boot_info *info)
+static int64_t load_kernel_info(struct loongarch_boot_info *info,
+ uint64_t phys_addr_mask)
{
uint64_t kernel_entry, kernel_low, kernel_high, initrd_offset = 0;
ssize_t kernel_size;
kernel_size = load_elf(info->kernel_filename, NULL,
- cpu_loongarch_virt_to_phys, NULL,
+ cpu_loongarch_virt_to_phys, &phys_addr_mask,
&kernel_entry, &kernel_low,
&kernel_high, NULL, ELFDATA2LSB,
EM_LOONGARCH, 1, 0);
- kernel_entry = cpu_loongarch_virt_to_phys(NULL, kernel_entry);
+ kernel_entry = cpu_loongarch_virt_to_phys(&phys_addr_mask, kernel_entry);
if (kernel_size < 0) {
kernel_size = load_loongarch_linux_image(info->kernel_filename,
+ phys_addr_mask,
&kernel_entry, &kernel_low,
&kernel_high);
}
@@ -395,14 +397,15 @@ static void init_boot_rom(MachineState *ms,
}
static void loongarch_direct_kernel_boot(MachineState *ms,
- struct loongarch_boot_info *info)
+ struct loongarch_boot_info *info,
+ uint64_t phys_addr_mask)
{
void *p, *bp;
int64_t kernel_addr = VIRT_FLASH0_BASE;
uint64_t *data;
if (info->kernel_filename) {
- kernel_addr = load_kernel_info(info);
+ kernel_addr = load_kernel_info(info, phys_addr_mask);
} else {
if (!qtest_enabled()) {
warn_report("No kernel provided, booting from flash drive.");
@@ -429,7 +432,8 @@ static void loongarch_direct_kernel_boot(MachineState *ms,
g_free(bp);
}
-void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
+void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info,
+ uint64_t phys_addr_mask)
{
LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(ms);
@@ -440,6 +444,6 @@ void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info)
if (lvms->bios_loaded) {
loongarch_firmware_boot(lvms, info);
} else {
- loongarch_direct_kernel_boot(ms, info);
+ loongarch_direct_kernel_boot(ms, info, phys_addr_mask);
}
}
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 49434ad182..e3e61903b0 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -33,6 +33,7 @@
#include "hw/misc/unimp.h"
#include "hw/loongarch/fw_cfg.h"
#include "target/loongarch/cpu.h"
+#include "target/loongarch/cpu-mmu.h"
#include "hw/firmware/smbios.h"
#include "qapi/qapi-visit-common.h"
#include "hw/acpi/generic_event_device.h"
@@ -785,6 +786,7 @@ static void virt_init(MachineState *machine)
hwaddr base, size, ram_size = machine->ram_size;
MachineClass *mc = MACHINE_GET_CLASS(machine);
Object *cpuobj;
+ uint64_t phys_addr_mask = 0;
if (!cpu_model) {
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
@@ -872,7 +874,8 @@ static void virt_init(MachineState *machine)
qemu_register_powerdown_notifier(&lvms->powerdown_notifier);
lvms->bootinfo.ram_size = ram_size;
- loongarch_load_kernel(machine, &lvms->bootinfo);
+ phys_addr_mask = loongarch_palen_mask(&LOONGARCH_CPU(first_cpu)->env);
+ loongarch_load_kernel(machine, &lvms->bootinfo, phys_addr_mask);
}
static void virt_get_acpi(Object *obj, Visitor *v, const char *name,
--
2.51.0
next prev parent reply other threads:[~2025-12-09 13:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 13:56 [PATCH 0/7] single-binary: Drop TARGET_PHYS_ADDR_SPACE_BITS Anton Johansson via
2025-12-09 13:56 ` [PATCH 1/7] target/alpha: Introduce alpha_phys_addr_space_bits() Anton Johansson via
2025-12-11 15:09 ` Richard Henderson
2025-12-09 13:56 ` [PATCH 2/7] target/hppa: Define PA[20|1X] physical address space size Anton Johansson via
2025-12-11 15:16 ` Richard Henderson
2025-12-09 13:56 ` [PATCH 3/7] target/i386: Drop physical address range checks Anton Johansson via
2025-12-09 13:56 ` [PATCH 4/7] target/loongarch: Introduce loongarch_palen_mask() Anton Johansson via
2025-12-09 13:56 ` Anton Johansson via [this message]
2025-12-09 13:56 ` [PATCH 6/7] hw/riscv: Fix IOMMU PAS capability to 56 bits Anton Johansson via
2025-12-09 13:56 ` [PATCH 7/7] Drop TARGET_PHYS_ADDR_SPACE_BITS Anton Johansson via
2025-12-09 16:07 ` Brian Cain
2025-12-11 15:18 ` Richard Henderson
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=20251209-phys_addr-v1-5-c387f3e72d77@rev.ng \
--to=qemu-devel@nongnu.org \
--cc=anjo@rev.ng \
--cc=philmd@linaro.org \
--cc=richard.henderson@linaro.org \
/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).