[PATCH 00/13] hw/riscv: FDT creation helpers

Daniel Henrique Barboza posted 13 patches 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260615203734.954428-1-daniel.barboza@oss.qualcomm.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
hw/riscv/fdt-common.c         | 202 ++++++++++++++++++++++++++++++++++
hw/riscv/meson.build          |   1 +
hw/riscv/numa.c               |  20 ++--
hw/riscv/sifive_u.c           |  88 ++++-----------
hw/riscv/spike.c              | 123 ++++-----------------
hw/riscv/virt.c               | 182 +++++-------------------------
include/hw/riscv/fdt-common.h |  33 ++++++
include/hw/riscv/numa.h       |   8 ++
8 files changed, 322 insertions(+), 335 deletions(-)
create mode 100644 hw/riscv/fdt-common.c
create mode 100644 include/hw/riscv/fdt-common.h
[PATCH 00/13] hw/riscv: FDT creation helpers
Posted by Daniel Henrique Barboza 1 month, 1 week ago
Salutations,


We have a good amount of code repetition between boards, mostly because
we copied/pasted components from one to the other across the years.  But
now we want to upstream the RISC-V Server Platform, currently at v8 [1],
and this topic came in the review.  This is a work I've been ducking for
2 years now but seems like it's time we do something about it. 

The patches are mostly code moving work with some design decisions
here and there in the new helper file.  When needed I changed board code
first to be compatible with what would be the helper (usually the code
from 'virt', which is more modern) and then I moved stuff to a helper.

The result of this series in the FDTs:

- for 'virt': no changes;
- for 'spike': the /htif node changed places with /soc;
- for 'sifive_u': phandles values for cpu-intc changed because now we're
  generating them (see patch 1).  Aside from that the board now has a
  'cpu-map' subnode with cluster and core IDs;


This is not everything -  I have a shorter follow up FDT  series ready
to go as soon as we get this accepted.  Figured that 13 patches is
enough for one go.


Patches based on alistair/riscv-to-apply.next.


[1] https://lore.kernel.org/qemu-devel/20260610214133.1882563-1-daniel.barboza@oss.qualcomm.com/

Daniel Henrique Barboza (13):
  hw/riscv/sifive_u.c: add a FDT phandle to cpu-intc
  hw/riscv: add fdt-common helper
  hw/riscv/numa: make numa_enabled() public
  hw/riscv: add create_fdt_socket_memory() helper
  hw/riscv/sifive_u.c: add intc_phandles array
  hw/riscv/spike.c: add intc_phandles array
  hw/riscv: add create_fdt_clint() helper
  hw/riscv/sifive_u.c: add cpu-map, cluster and core DTs
  hw/riscv: add fdt_create_cpu_socket_subnode() helper
  hw/riscv: add create_fdt_socket_cpus()
  hw/riscv/spike.c: use create_fdt_socket_cpus()
  hw/riscv/fdt_common.c: create create_fdt_socket_cpu_internal()
  hw/riscv: add create_fdt_socket_cpu_sifive()

 hw/riscv/fdt-common.c         | 202 ++++++++++++++++++++++++++++++++++
 hw/riscv/meson.build          |   1 +
 hw/riscv/numa.c               |  20 ++--
 hw/riscv/sifive_u.c           |  88 ++++-----------
 hw/riscv/spike.c              | 123 ++++-----------------
 hw/riscv/virt.c               | 182 +++++-------------------------
 include/hw/riscv/fdt-common.h |  33 ++++++
 include/hw/riscv/numa.h       |   8 ++
 8 files changed, 322 insertions(+), 335 deletions(-)
 create mode 100644 hw/riscv/fdt-common.c
 create mode 100644 include/hw/riscv/fdt-common.h

-- 
2.43.0
Re: [PATCH 00/13] hw/riscv: FDT creation helpers
Posted by Alistair Francis 1 month, 1 week ago
On Tue, Jun 16, 2026 at 6:43 AM Daniel Henrique Barboza
<daniel.barboza@oss.qualcomm.com> wrote:
>
> Salutations,
>
>
> We have a good amount of code repetition between boards, mostly because
> we copied/pasted components from one to the other across the years.  But
> now we want to upstream the RISC-V Server Platform, currently at v8 [1],
> and this topic came in the review.  This is a work I've been ducking for
> 2 years now but seems like it's time we do something about it.
>
> The patches are mostly code moving work with some design decisions
> here and there in the new helper file.  When needed I changed board code
> first to be compatible with what would be the helper (usually the code
> from 'virt', which is more modern) and then I moved stuff to a helper.
>
> The result of this series in the FDTs:
>
> - for 'virt': no changes;
> - for 'spike': the /htif node changed places with /soc;
> - for 'sifive_u': phandles values for cpu-intc changed because now we're
>   generating them (see patch 1).  Aside from that the board now has a
>   'cpu-map' subnode with cluster and core IDs;
>
>
> This is not everything -  I have a shorter follow up FDT  series ready
> to go as soon as we get this accepted.  Figured that 13 patches is
> enough for one go.
>
>
> Patches based on alistair/riscv-to-apply.next.
>
>
> [1] https://lore.kernel.org/qemu-devel/20260610214133.1882563-1-daniel.barboza@oss.qualcomm.com/
>
> Daniel Henrique Barboza (13):
>   hw/riscv/sifive_u.c: add a FDT phandle to cpu-intc
>   hw/riscv: add fdt-common helper
>   hw/riscv/numa: make numa_enabled() public
>   hw/riscv: add create_fdt_socket_memory() helper
>   hw/riscv/sifive_u.c: add intc_phandles array
>   hw/riscv/spike.c: add intc_phandles array
>   hw/riscv: add create_fdt_clint() helper
>   hw/riscv/sifive_u.c: add cpu-map, cluster and core DTs
>   hw/riscv: add fdt_create_cpu_socket_subnode() helper
>   hw/riscv: add create_fdt_socket_cpus()
>   hw/riscv/spike.c: use create_fdt_socket_cpus()
>   hw/riscv/fdt_common.c: create create_fdt_socket_cpu_internal()
>   hw/riscv: add create_fdt_socket_cpu_sifive()

Thanks!

Applied to riscv-to-apply.next

@Joel Stanley , @Nicholas Piggin , @Portia Stephens FYI

Alistair

>
>  hw/riscv/fdt-common.c         | 202 ++++++++++++++++++++++++++++++++++
>  hw/riscv/meson.build          |   1 +
>  hw/riscv/numa.c               |  20 ++--
>  hw/riscv/sifive_u.c           |  88 ++++-----------
>  hw/riscv/spike.c              | 123 ++++-----------------
>  hw/riscv/virt.c               | 182 +++++-------------------------
>  include/hw/riscv/fdt-common.h |  33 ++++++
>  include/hw/riscv/numa.h       |   8 ++
>  8 files changed, 322 insertions(+), 335 deletions(-)
>  create mode 100644 hw/riscv/fdt-common.c
>  create mode 100644 include/hw/riscv/fdt-common.h
>
> --
> 2.43.0
>
>