From: Chao Liu <chao.liu@processmission.com>
To: Bin Meng <bin.meng@processmission.com>
Cc: QEMU <qemu-devel@nongnu.org>,
Alistair Francis <alistair.francis@wdc.com>,
Conor Dooley <conor@kernel.org>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sebastian Huber <sebastian.huber@embedded-brains.de>,
Weiwei Li <liwei1518@gmail.com>,
qemu-riscv@nongnu.org
Subject: Re: [PATCH 05/26] hw/riscv: pfsoc: Couple L2CC to L2-LIM
Date: Mon, 27 Jul 2026 13:30:34 +0800 [thread overview]
Message-ID: <ambs8ysJgsOR7DjM@ChaodeMacBook-Pro.local> (raw)
In-Reply-To: <20260723151853.2143177-6-bin.meng@processmission.com>
On Thu, Jul 23, 2026 at 11:18:32PM +0800, Bin Meng wrote:
> Instantiate the L2CC in the PolarFire SoC machine and connect its
> WayEnable register to the L2-LIM MemoryRegion. Back the complete 2 MiB
> aperture and shrink it by 128 KiB for each cache way enabled.
>
> Keep L2 Zero at its fixed aperture because it represents a cache
> allocation window rather than the remaining L2-LIM capacity.
>
> Signed-off-by: Bin Meng <bin.meng@processmission.com>
Reviewed-by: Chao Liu <chao.liu@processmission.com>
Thanks,
Chao
> ---
>
> include/hw/misc/mchp_pfsoc_l2cc.h | 1 +
> include/hw/riscv/microchip_pfsoc.h | 2 ++
> hw/misc/mchp_pfsoc_l2cc.c | 50 ++++++++++++++++++++++++++++++
> hw/riscv/microchip_pfsoc.c | 23 +++++++-------
> hw/riscv/Kconfig | 1 +
> 5 files changed, 66 insertions(+), 11 deletions(-)
>
> diff --git a/include/hw/misc/mchp_pfsoc_l2cc.h b/include/hw/misc/mchp_pfsoc_l2cc.h
> index 1b5b3888d5..3a175a6340 100644
> --- a/include/hw/misc/mchp_pfsoc_l2cc.h
> +++ b/include/hw/misc/mchp_pfsoc_l2cc.h
> @@ -22,6 +22,7 @@ typedef struct MchpPfSoCL2ccState {
> SysBusDevice parent;
> uint64_t regs[MCHP_PFSOC_L2CC_REG_NUM];
> RegisterInfo regs_info[MCHP_PFSOC_L2CC_REG_NUM];
> + MemoryRegion *l2lim;
> } MchpPfSoCL2ccState;
>
> #define TYPE_MCHP_PFSOC_L2CC "mchp.pfsoc.l2cc"
> diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
> index 612fd2b69c..0aeccedf77 100644
> --- a/include/hw/riscv/microchip_pfsoc.h
> +++ b/include/hw/riscv/microchip_pfsoc.h
> @@ -27,6 +27,7 @@
> #include "hw/cpu/cluster.h"
> #include "hw/dma/sifive_pdma.h"
> #include "hw/misc/mchp_pfsoc_dmc.h"
> +#include "hw/misc/mchp_pfsoc_l2cc.h"
> #include "hw/misc/mchp_pfsoc_ioscb.h"
> #include "hw/misc/mchp_pfsoc_sysreg.h"
> #include "hw/net/cadence_gem.h"
> @@ -43,6 +44,7 @@ typedef struct MicrochipPFSoCState {
> RISCVHartArrayState e_cpus;
> RISCVHartArrayState u_cpus;
> DeviceState *plic;
> + MchpPfSoCL2ccState l2cc;
> MchpPfSoCDdrSgmiiPhyState ddr_sgmii_phy;
> MchpPfSoCDdrCfgState ddr_cfg;
> MchpPfSoCIoscbState ioscb;
> diff --git a/hw/misc/mchp_pfsoc_l2cc.c b/hw/misc/mchp_pfsoc_l2cc.c
> index b320356572..7f3c2672c3 100644
> --- a/hw/misc/mchp_pfsoc_l2cc.c
> +++ b/hw/misc/mchp_pfsoc_l2cc.c
> @@ -11,6 +11,9 @@
>
> #include "qemu/osdep.h"
> #include "qemu/log.h"
> +#include "qemu/units.h"
> +#include "qapi/error.h"
> +#include "hw/core/qdev-properties.h"
> #include "hw/core/register.h"
> #include "hw/core/registerfields.h"
> #include "hw/misc/mchp_pfsoc_l2cc.h"
> @@ -39,6 +42,25 @@ REG64(L2_WAY_MASK_HART4_DCACHE, 0x868)
> REG64(L2_WAY_MASK_HART4_ICACHE, 0x870)
>
> #define L2_CONFIG_RESET 0x06091004
> +#define L2_LIM_WAY_COUNT 15
> +#define L2_WAY_SIZE (128 * KiB)
> +
> +static void mchp_pfsoc_l2cc_update_l2lim(MchpPfSoCL2ccState *s,
> + uint64_t way_enable)
> +{
> + uint64_t l2lim_size;
> +
> + if (way_enable >= L2_LIM_WAY_COUNT) {
> + l2lim_size = 0;
> + } else {
> + l2lim_size = (L2_LIM_WAY_COUNT - way_enable) * L2_WAY_SIZE;
> + }
> +
> + memory_region_transaction_begin();
> + memory_region_set_size(s->l2lim, l2lim_size);
> + memory_region_set_enabled(s->l2lim, l2lim_size != 0);
> + memory_region_transaction_commit();
> +}
>
> static uint64_t mchp_pfsoc_l2cc_way_enable_pre_write(RegisterInfo *reg,
> uint64_t value)
> @@ -48,6 +70,14 @@ static uint64_t mchp_pfsoc_l2cc_way_enable_pre_write(RegisterInfo *reg,
> return MAX(current, value);
> }
>
> +static void mchp_pfsoc_l2cc_way_enable_post_write(RegisterInfo *reg,
> + uint64_t value)
> +{
> + MchpPfSoCL2ccState *s = MCHP_PFSOC_L2CC(reg->opaque);
> +
> + mchp_pfsoc_l2cc_update_l2lim(s, value);
> +}
> +
> #define WAY_MASK_REGISTER(_name) \
> { \
> .name = "WAY_MASK_" #_name, \
> @@ -66,6 +96,7 @@ static const RegisterAccessInfo mchp_pfsoc_l2cc_regs_info[] = {
> .addr = A_L2_WAY_ENABLE,
> .rsvd = ~R_L2_WAY_ENABLE_VALUE_MASK,
> .pre_write = mchp_pfsoc_l2cc_way_enable_pre_write,
> + .post_write = mchp_pfsoc_l2cc_way_enable_post_write,
> },
> WAY_MASK_REGISTER(DMA),
> WAY_MASK_REGISTER(AXI4_PORT_0),
> @@ -157,11 +188,30 @@ static void mchp_pfsoc_l2cc_init(Object *obj)
> sysbus_init_mmio(SYS_BUS_DEVICE(obj), ®_array->mem);
> }
>
> +static void mchp_pfsoc_l2cc_realize(DeviceState *dev, Error **errp)
> +{
> + MchpPfSoCL2ccState *s = MCHP_PFSOC_L2CC(dev);
> +
> + if (!s->l2lim) {
> + error_setg(errp, TYPE_MCHP_PFSOC_L2CC ": 'l2-lim' link not set");
> + return;
> + }
> +
> + mchp_pfsoc_l2cc_update_l2lim(s, s->regs[R_L2_WAY_ENABLE]);
> +}
> +
> +static const Property mchp_pfsoc_l2cc_properties[] = {
> + DEFINE_PROP_LINK("l2-lim", MchpPfSoCL2ccState, l2lim,
> + TYPE_MEMORY_REGION, MemoryRegion *),
> +};
> +
> static void mchp_pfsoc_l2cc_class_init(ObjectClass *klass, const void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> device_class_set_legacy_reset(dc, mchp_pfsoc_l2cc_reset);
> + device_class_set_props(dc, mchp_pfsoc_l2cc_properties);
> + dc->realize = mchp_pfsoc_l2cc_realize;
> }
>
> static const TypeInfo mchp_pfsoc_l2cc_info = {
> diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
> index fd28ee75fe..248de4d022 100644
> --- a/hw/riscv/microchip_pfsoc.c
> +++ b/hw/riscv/microchip_pfsoc.c
> @@ -175,6 +175,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
> object_initialize_child(obj, "dma-controller", &s->dma,
> TYPE_SIFIVE_PDMA);
>
> + object_initialize_child(obj, "l2-cache-controller", &s->l2cc,
> + TYPE_MCHP_PFSOC_L2CC);
> +
> object_initialize_child(obj, "sysreg", &s->sysreg,
> TYPE_MCHP_PFSOC_SYSREG);
>
> @@ -260,18 +263,9 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
> RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
> iks->clint_timebase_freq, false);
>
> - /* L2 cache controller */
> - create_unimplemented_device("microchip.pfsoc.l2cc",
> - memmap[MICROCHIP_PFSOC_L2CC].base, memmap[MICROCHIP_PFSOC_L2CC].size);
> -
> /*
> - * Add L2-LIM at reset size.
> - * This should be reduced in size as the L2 Cache Controller WayEnable
> - * register is incremented. Unfortunately I don't see a nice (or any) way
> - * to handle reducing or blocking out the L2 LIM while still allowing it
> - * be re returned to all enabled after a reset. For the time being, just
> - * leave it enabled all the time. This won't break anything, but will be
> - * too generous to misbehaving guests.
> + * Back the complete L2-LIM aperture. The L2 cache controller resizes
> + * this MemoryRegion to 128 KiB for every way assigned to L2-LIM.
> */
> memory_region_init_ram(l2lim_mem, NULL, "microchip.pfsoc.l2lim",
> memmap[MICROCHIP_PFSOC_L2LIM].size, &error_fatal);
> @@ -279,6 +273,13 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
> memmap[MICROCHIP_PFSOC_L2LIM].base,
> l2lim_mem);
>
> + /* L2 cache controller */
> + object_property_set_link(OBJECT(&s->l2cc), "l2-lim",
> + OBJECT(l2lim_mem), &error_abort);
> + sysbus_realize(SYS_BUS_DEVICE(&s->l2cc), errp);
> + sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), 0,
> + memmap[MICROCHIP_PFSOC_L2CC].base);
> +
> /*
> * HSS decompresses into the L2 zero-device window and executes there.
> * Model it as RAM because QEMU does not model the backing L2 cache.
> diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
> index de37c08cae..22619481e4 100644
> --- a/hw/riscv/Kconfig
> +++ b/hw/riscv/Kconfig
> @@ -18,6 +18,7 @@ config MICROCHIP_PFSOC
> select DEVICE_TREE
> select MCHP_PFSOC_DMC
> select MCHP_PFSOC_IOSCB
> + select MCHP_PFSOC_L2CC
> select MCHP_PFSOC_MMUART
> select MCHP_PFSOC_SYSREG
> select RISCV_ACLINT
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-07-27 5:31 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 15:18 [PATCH 00/26] hw/riscv: Restore Microchip PolarFire SoC Icicle Kit firmware boot Bin Meng
2026-07-23 15:18 ` [PATCH 01/26] hw/riscv: pfsoc: Correct the L2LIM maximum mapped size Bin Meng
2026-07-27 5:23 ` Chao Liu
2026-07-23 15:18 ` [PATCH 02/26] hw/riscv: pfsoc: Map the L2 zero device window Bin Meng
2026-07-27 5:24 ` Chao Liu
2026-07-23 15:18 ` [PATCH 03/26] hw/misc: pfsoc: Support PolarFire SoC DDR training with newer version HSS Bin Meng
2026-07-23 15:18 ` [PATCH 04/26] hw/misc: pfsoc: Model L2 cache controller registers Bin Meng
2026-07-23 15:18 ` [PATCH 05/26] hw/riscv: pfsoc: Couple L2CC to L2-LIM Bin Meng
2026-07-27 5:30 ` Chao Liu [this message]
2026-07-23 15:18 ` [PATCH 06/26] tests/qtest: Add PolarFire SoC L2CC coverage Bin Meng
2026-07-23 15:18 ` [PATCH 15/26] hw/misc: pfsoc: Model PolarFire SoC serial number service Bin Meng
2026-07-23 15:18 ` [PATCH 16/26] hw/rtc: Add PolarFire SoC RTC model Bin Meng
2026-07-23 15:28 ` Conor Dooley
2026-07-23 15:55 ` Bin Meng
2026-07-23 15:58 ` Conor Dooley
2026-07-23 16:07 ` Bin Meng
2026-07-23 15:18 ` [PATCH 17/26] hw/riscv: pfsoc: Add PolarFire SoC RTC to Icicle Kit Bin Meng
2026-07-27 5:31 ` Chao Liu
2026-07-23 15:18 ` [PATCH 18/26] tests/qtest: Add PolarFire SoC RTC coverage Bin Meng
2026-07-23 15:18 ` [PATCH 19/26] hw/misc: pfsoc: Honor PolarFire service notification requests Bin Meng
2026-07-27 5:32 ` Chao Liu
2026-07-23 15:18 ` [PATCH 20/26] hw/riscv: pfsoc: Correct PolarFire SoC DDR aliases Bin Meng
2026-07-27 5:33 ` Chao Liu
2026-07-23 15:18 ` [PATCH 21/26] hw/riscv: pfsoc: Fix Icicle Kit RAM size at 2 GiB Bin Meng
2026-07-27 5:33 ` Chao Liu
2026-07-23 15:18 ` [PATCH 22/26] hw/riscv: pfsoc: Fix Icicle Kit hart count at five Bin Meng
2026-07-27 5:37 ` Chao Liu
2026-07-23 15:18 ` [PATCH 23/26] docs/system/riscv: Document Icicle Kit HSS boot Bin Meng
2026-07-23 15:18 ` [PATCH 24/26] docs/system/riscv: pfsoc: Document CLINT topology for direct Linux boot Bin Meng
2026-07-23 15:18 ` [PATCH 25/26] tests/functional/riscv64: Add Icicle Kit firmware boot test Bin Meng
2026-07-27 5:38 ` Chao Liu
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=ambs8ysJgsOR7DjM@ChaodeMacBook-Pro.local \
--to=chao.liu@processmission.com \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@processmission.com \
--cc=conor@kernel.org \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=sebastian.huber@embedded-brains.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox