On Sat Jun 29, 2024 at 1:16 PM AEST, David Gibson wrote: > On Fri, Jun 28, 2024 at 04:20:02PM +0100, Peter Maydell wrote: > > On Thu, 27 Jun 2024 at 14:39, Akihiko Odaki <akihiko.od...@daynix.com> > > wrote: > > > > > > FDT properties are aligned by 4 bytes, not 8 bytes. > > > > > > Signed-off-by: Akihiko Odaki <akihiko.od...@daynix.com> > > > --- > > > hw/ppc/vof.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c > > > index e3b430a81f4f..b5b6514d79fc 100644 > > > --- a/hw/ppc/vof.c > > > +++ b/hw/ppc/vof.c > > > @@ -646,7 +646,7 @@ static void vof_dt_memory_available(void *fdt, GArray > > > *claimed, uint64_t base) > > > mem0_reg = fdt_getprop(fdt, offset, "reg", &proplen); > > > g_assert(mem0_reg && proplen == sizeof(uint32_t) * (ac + sc)); > > > if (sc == 2) { > > > - mem0_end = be64_to_cpu(*(uint64_t *)(mem0_reg + sizeof(uint32_t) > > > * ac)); > > > + mem0_end = ldq_be_p(mem0_reg + sizeof(uint32_t) * ac); > > > } else { > > > mem0_end = be32_to_cpu(*(uint32_t *)(mem0_reg + sizeof(uint32_t) > > > * ac)); > > > } > > > > I did wonder if there was a better way to do what this is doing, > > but neither we (in system/device_tree.c) nor libfdt seem to > > provide one. > > libfdt does provide unaligned access helpers (fdt32_ld() etc.), but > not an automatic aligned-or-unaligned helper. Maybe we should add that?
Runtime test if the pointer is aligned? What about just fdt_prop32_ld() and fdt_prop64_ld() where you know it's 4 byte aligned. Then just do 2 x 4 byte loads for the 64-bit, I don't think performance would matter so much to try get a single load. Thanks, Nick