@samitouri / QOSamiQemu / commits / 1a80a03a40

hppa: Get physical address space bits from HPPACPUDef

Signed-off-by: Anton Johansson <anjo@rev.ng> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260305-hppa-c3600-v6-2-d51526e5269c@rev.ng> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Anton Johansson committed Mar 5, 2026 at 23:54 UTC 1a80a03a40d106ea37f5ba3a4bb4916d1ae88128
6 files changed +43 -37
hw/hppa/machine.c
+10 -5
@@ -179,19 +179,21 @@ static uint64_t linux_kernel_virt_to_phys(void *opaque, uint64_t addr)
179 return addr;
180 }
181
182 +static HPPACPU *cpu[HPPA_MAX_CPUS];
183 +static uint64_t firmware_entry;
184 +
185 static uint64_t translate_pa10(void *dummy, uint64_t addr)
186 {
184 - return hppa_abs_to_phys_pa1x(addr);
187 + const uint8_t pa_bits = hppa_phys_addr_bits(&cpu[0]->env);
188 + return hppa_abs_to_phys_pa1x(pa_bits, addr);
189 }
190
191 static uint64_t translate_pa20(void *dummy, uint64_t addr)
192 {
189 - return hppa_abs_to_phys_pa2_w0(addr);
193 + const uint8_t pa_bits = hppa_phys_addr_bits(&cpu[0]->env);
194 + return hppa_abs_to_phys_pa2_w0(pa_bits, addr);
195 }
196
192 -static HPPACPU *cpu[HPPA_MAX_CPUS];
193 -static uint64_t firmware_entry;
194 -
197 static void fw_cfg_boot_set(void *opaque, const char *boot_device,
198 Error **errp)
199 {
@@ -685,6 +687,9 @@ static AstroState *astro_init(void)
687 DeviceState *dev;
688
689 dev = qdev_new(TYPE_ASTRO_CHIP);
690 + object_property_set_int(OBJECT(dev), "phys-addr-bits",
691 + hppa_phys_addr_bits(&cpu[0]->env),
692 + &error_abort);
693 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
694
695 return ASTRO_CHIP(dev);
hw/pci-host/astro.c
+7 -1
@@ -303,7 +303,7 @@ static IOMMUTLBEntry astro_translate_iommu(IOMMUMemoryRegion *iommu,
303 * language which not-coincidentally matches the PSW.W=0 mapping.
304 */
305 if (addr <= UINT32_MAX) {
306 - entry = hppa_abs_to_phys_pa2_w0(addr);
306 + entry = hppa_abs_to_phys_pa2_w0(s->phys_addr_bits, addr);
307 } else {
308 entry = addr;
309 }
@@ -910,6 +910,10 @@ static void astro_realize(DeviceState *obj, Error **errp)
910 }
911 }
912
913 +static const Property astro_props[] = {
914 + DEFINE_PROP_UINT8("phys-addr-bits", AstroState, phys_addr_bits, 32),
915 +};
916 +
917 static void astro_class_init(ObjectClass *klass, const void *data)
918 {
919 DeviceClass *dc = DEVICE_CLASS(klass);
@@ -922,6 +926,8 @@ static void astro_class_init(ObjectClass *klass, const void *data)
926 * be created without that hardware
927 */
928 dc->user_creatable = false;
929 +
930 + device_class_set_props(dc, astro_props);
931 }
932
933 static const TypeInfo astro_chip_info = {
include/hw/pci-host/astro.h
+2
@@ -82,6 +82,8 @@ struct AstroState {
82 uint64_t tlb_tcnfg;
83 uint64_t tlb_pdir_base;
84
85 + uint8_t phys_addr_bits;
86 +
87 struct ElroyState *elroy[ELROY_NUM];
88
89 MemoryRegion this_mem;
target/hppa/cpu.c
+5
@@ -283,6 +283,11 @@ static void hppa_cpu_class_base_init(ObjectClass *oc, const void *data)
283 /* Make sure all CPU models define a HPPACPUDef */
284 g_assert(!object_class_is_abstract(oc) && data != NULL);
285 acc->def = data;
286 + /*
287 + * Verify assumptions made in hppa_abs_to_phys_pa2_w1() on the size
288 + * of the physical address space.
289 + */
290 + g_assert(acc->def->phys_addr_bits <= 54);
291 }
292
293 static void hppa_cpu_class_init(ObjectClass *oc, const void *data)
target/hppa/cpu.h
+8 -3
@@ -320,6 +320,11 @@ static inline const HPPACPUDef *hppa_def(CPUHPPAState *env)
320 return HPPA_CPU_GET_CLASS(env_cpu(env))->def;
321 }
322
323 +static inline uint8_t hppa_phys_addr_bits(CPUHPPAState *env)
324 +{
325 + return hppa_def(env)->phys_addr_bits;
326 +}
327 +
328 static inline bool hppa_is_pa20(CPUHPPAState *env)
329 {
330 return hppa_def(env)->is_pa20;
@@ -352,9 +357,9 @@ static inline vaddr hppa_form_gva(CPUHPPAState *env, uint64_t spc,
357 return hppa_form_gva_mask(env->gva_offset_mask, spc, off);
358 }
359
355 -hwaddr hppa_abs_to_phys_pa1x(vaddr addr);
356 -hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr);
357 -hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr);
360 +hwaddr hppa_abs_to_phys_pa1x(uint8_t phys_addr_bits, vaddr addr);
361 +hwaddr hppa_abs_to_phys_pa2_w0(uint8_t phys_addr_bits, vaddr addr);
362 +hwaddr hppa_abs_to_phys_pa2_w1(uint8_t phys_addr_bits, vaddr addr);
363
364 /*
365 * Since PSW_{I,CB} will never need to be in tb->flags, reuse them.
target/hppa/mem_helper.c
+11 -28
@@ -29,29 +29,12 @@
29 #include "hw/core/cpu.h"
30 #include "trace.h"
31
32 -/*
33 - * 64-bit (PA-RISC 2.0) machines are assumed to run PA-8700, and 32-bit
34 - * machines 7300LC. This should give 44 and 32 bits of physical address
35 - * space respectively.
36 - *
37 - * CPU model Physical address space bits
38 - * PA-7000--7300LC 32
39 - * PA-8000--8600 40
40 - * PA-8700--8900 44
41 - *
42 - * FIXME: However, the SeaBIOS firmware that is that tested against
43 - * uses 40-bit physical addresses, despite supposedly running a C3700
44 - * with a PA-8700 cpu, so use 40-bits for 64-bit.
45 - */
46 -#define HPPA_PHYS_ADDR_SPACE_BITS_PA20 40
47 -#define HPPA_PHYS_ADDR_SPACE_BITS_PA1X 32
48 -
49 -hwaddr hppa_abs_to_phys_pa1x(vaddr addr)
32 +hwaddr hppa_abs_to_phys_pa1x(uint8_t phys_addr_bits, vaddr addr)
33 {
51 - return extract64(addr, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA1X);
34 + return extract64(addr, 0, phys_addr_bits);
35 }
36
54 -hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr)
37 +hwaddr hppa_abs_to_phys_pa2_w1(uint8_t phys_addr_bits, vaddr addr)
38 {
39 /*
40 * Figure H-8 "62-bit Absolute Accesses when PSW W-bit is 1" describes
@@ -64,11 +47,10 @@ hwaddr hppa_abs_to_phys_pa2_w1(vaddr addr)
47 * Since the supported physical address space is below 54 bits, the
48 * H-8 algorithm is moot and all that is left is to truncate.
49 */
67 - QEMU_BUILD_BUG_ON(HPPA_PHYS_ADDR_SPACE_BITS_PA20 > 54);
68 - return sextract64(addr, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA20);
50 + return sextract64(addr, 0, phys_addr_bits);
51 }
52
71 -hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr)
53 +hwaddr hppa_abs_to_phys_pa2_w0(uint8_t phys_addr_bits, vaddr addr)
54 {
55 /*
56 * See Figure H-10, "Absolute Accesses when PSW W-bit is 0",
@@ -89,7 +71,7 @@ hwaddr hppa_abs_to_phys_pa2_w0(vaddr addr)
71 * is what can be seen on physical machines too.
72 */
73 addr = (uint32_t)addr;
92 - addr |= -1ull << (HPPA_PHYS_ADDR_SPACE_BITS_PA20 - 4);
74 + addr |= -1ull << (phys_addr_bits - 4);
75 }
76 return addr;
77 }
@@ -231,15 +213,16 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
213
214 /* Virtual translation disabled. Map absolute to physical. */
215 if (MMU_IDX_MMU_DISABLED(mmu_idx)) {
216 + const uint8_t phys_addr_bits = hppa_phys_addr_bits(env);
217 switch (mmu_idx) {
218 case MMU_ABS_W_IDX:
236 - phys = hppa_abs_to_phys_pa2_w1(addr);
219 + phys = hppa_abs_to_phys_pa2_w1(phys_addr_bits, addr);
220 break;
221 case MMU_ABS_IDX:
222 if (hppa_is_pa20(env)) {
240 - phys = hppa_abs_to_phys_pa2_w0(addr);
223 + phys = hppa_abs_to_phys_pa2_w0(phys_addr_bits, addr);
224 } else {
242 - phys = hppa_abs_to_phys_pa1x(addr);
225 + phys = hppa_abs_to_phys_pa1x(phys_addr_bits, addr);
226 }
227 break;
228 default:
@@ -580,7 +563,7 @@ static void itlbt_pa20(CPUHPPAState *env, target_ulong r1,
563 /* Align per the page size. */
564 ent->pa &= TARGET_PAGE_MASK << mask_shift;
565 /* Ignore the bits beyond physical address space. */
583 - ent->pa = sextract64(ent->pa, 0, HPPA_PHYS_ADDR_SPACE_BITS_PA20);
566 + ent->pa = sextract64(ent->pa, 0, hppa_phys_addr_bits(env));
567
568 ent->t = extract64(r2, 61, 1);
569 ent->d = extract64(r2, 60, 1);