On Wed, Feb 11, 2026 at 11:59:45AM +1000, Richard Henderson wrote:
> On 2/10/26 21:33, Anton Johansson wrote:
> > Replaces the only remaining use of TARGET_PHYS_ADDR_SPACE_BITS for RISCV
> > with the fixed size of the riscv64 physical address space.
> > 
> > Better would be to somehow determine if a 32-bit or 64-bit cpu is
> > running and set accordingly, but I'm not sure how that would be done
> > from the device instance init function. This field is unused anyway.
> > 
For runtime detection, we should use riscv_cpu_is_32bit() (implemented in
target/riscv/cpu.c, declared in target/riscv/cpu.h).

That said, I don't think the IOMMU device should call riscv_cpu_is_32bit()
directly, since it does not have a reliable CPUState handle in its init path. 

Following Richard's suggestion, it would be better to add a pas-bits property
on the IOMMU and set it from virt_machine_init() (or equivalent machine code),
where the CPU width is already known(we can use riscv_cpu_is_32bit() fn get it).

Thanks,
Chao
> > Signed-off-by: Anton Johansson <[email protected]>
> > ---
> >   hw/riscv/riscv-iommu.c | 12 +++++++++---
> >   1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> > diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
> > index b46b337375..c3d48541b7 100644
> > --- a/hw/riscv/riscv-iommu.c
> > +++ b/hw/riscv/riscv-iommu.c
> > @@ -2453,9 +2453,15 @@ static void riscv_iommu_instance_init(Object *obj)
> >       /* Enable translation debug interface */
> >       s->cap = RISCV_IOMMU_CAP_DBG;
> > -    /* Report QEMU target physical address space limits */
> > -    s->cap = set_field(s->cap, RISCV_IOMMU_CAP_PAS,
> > -                       TARGET_PHYS_ADDR_SPACE_BITS);
> > +    /*
> > +     * Report QEMU target physical address space limits.
> > +     *
> > +     * Currently set to the riscv64 limit of 56 bits (44 bit PPN),
> > +     * riscv32 would use 34 bits (22 bit PPN).
> > +     *
> > +     * This field is currently unused.
> > +     */
> > +    s->cap = set_field(s->cap, RISCV_IOMMU_CAP_PAS, 56);
> 
> Probably better to make this a property.
> 
> The iommu object already has a number of them, set by virt_machine_init, and
> that function already has a handle on the cpus being instantiated.
> 
> 
> r~
> 

Reply via email to