From: Chao Liu <chao.liu@processmission.com>
To: Ralf Ramsauer <ralf@vmexit.de>
Cc: qemu-devel@nongnu.org,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>,
qemu-riscv@nongnu.org, Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Weiwei Li <liwei1518@gmail.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
Bin Meng <bmeng.cn@gmail.com>,
Lukas Landgraf <lukas.landgraf@st.oth-regensburg.de>
Subject: Re: [PATCH v3 3/4] hw/riscv/sifive_u: derive PLIC contexts from the harts
Date: Fri, 23 Oct 2026 11:06:46 +0800 [thread overview]
Message-ID: <atrPNiR6nZotQMyl@MacBook-Pro-4.local> (raw)
In-Reply-To: <f5bffbbaf8272e743f184e9f5681ec5931800e23.1792700406.git.ralf@vmexit.de>
On Thu, Oct 22, 2026 at 10:22:17PM +0800, Ralf Ramsauer wrote:
> From: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
>
> The PLIC device is created from riscv_plic_hart_config_string(), which
> gives a hart a supervisor context only if that hart has supervisor mode.
> The device tree instead hardcodes the fu540 topology: no supervisor
> context for the management hart, one for every other hart.
>
> Both agree as long as the application harts keep the default CPU type.
> The board sets no valid_cpu_types, though, and passes machine->cpu_type
> on to the U cluster, so -cpu rv64,s=false,u=false builds a PLIC without
> any supervisor context while the device tree still advertises one per
> application hart. Contexts are numbered by their position in
> 'interrupts-extended', so from the second hart on the numbering drifts
> apart, as it does on the virt machine.
>
> Ask the harts instead of assuming, like create_fdt_socket_plic() does.
> No change for the default CPU type: the E51 management hart has no RVS,
> the U54 application harts have.
>
> Signed-off-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Chao Liu <chao.liu@processmission.com>
Thanks,
Chao
> ---
> hw/riscv/sifive_u.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index b7d5e7b4da..8f50c67a14 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -99,6 +99,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> MachineState *ms = MACHINE(s);
> void *fdt;
> int cpu;
> + RISCVCPU *hart;
> uint32_t *cells, cells_length;
> char *nodename;
> uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1;
> @@ -195,18 +196,18 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
> g_free(nodename);
>
> plic_phandle = phandle++;
> - cells_length = ms->smp.cpus * 4 - 2;
> - cells = g_new0(uint32_t, cells_length);
> + cells = g_new0(uint32_t, ms->smp.cpus * 4 - 2);
> + cells_length = 0;
> for (cpu = 0; cpu < ms->smp.cpus; cpu++) {
> /* cpu 0 is the management hart that does not have S-mode */
> - if (cpu == 0) {
> - cells[0] = cpu_to_be32(intc_phandles[cpu]);
> - cells[1] = cpu_to_be32(IRQ_M_EXT);
> - } else {
> - cells[cpu * 4 - 2] = cpu_to_be32(intc_phandles[cpu]);
> - cells[cpu * 4 - 1] = cpu_to_be32(IRQ_M_EXT);
> - cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]);
> - cells[cpu * 4 + 1] = cpu_to_be32(IRQ_S_EXT);
> + hart = cpu ? &s->soc.u_cpus.harts[cpu - 1] : &s->soc.e_cpus.harts[0];
> +
> + cells[cells_length++] = cpu_to_be32(intc_phandles[cpu]);
> + cells[cells_length++] = cpu_to_be32(IRQ_M_EXT);
> +
> + if (riscv_cpu_has_supervisor_mode(hart)) {
> + cells[cells_length++] = cpu_to_be32(intc_phandles[cpu]);
> + cells[cells_length++] = cpu_to_be32(IRQ_S_EXT);
> }
> }
>
> --
> 2.54.0
>
next prev parent reply other threads:[~2026-10-23 3:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 20:22 [PATCH v3 0/4] hw/riscv: describe only the PLIC contexts that exist Ralf Ramsauer
2026-10-22 20:22 ` [PATCH v3 1/4] target/riscv: add riscv_cpu_has_supervisor_mode() Ralf Ramsauer
2026-10-23 2:19 ` Chao Liu
2026-10-22 20:22 ` [PATCH v3 2/4] hw/riscv/virt: only describe PLIC contexts that exist Ralf Ramsauer
2026-10-23 3:05 ` Chao Liu
2026-10-22 20:22 ` [PATCH v3 3/4] hw/riscv/sifive_u: derive PLIC contexts from the harts Ralf Ramsauer
2026-10-23 3:06 ` Chao Liu [this message]
2026-10-22 20:22 ` [PATCH v3 4/4] hw/riscv: share the PLIC interrupt cells between boards Ralf Ramsauer
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=atrPNiR6nZotQMyl@MacBook-Pro-4.local \
--to=chao.liu@processmission.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng.cn@gmail.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=liwei1518@gmail.com \
--cc=lukas.landgraf@st.oth-regensburg.de \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=ralf.ramsauer@oth-regensburg.de \
--cc=ralf@vmexit.de \
--cc=zhiwei_liu@linux.alibaba.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.