From: JunWei Li <vae1207@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, chenhuacai@canaan-creative.com,
JunWei Li <vae1207@gmail.com>
Subject: [PATCH 2/3] hw/riscv: wire up K230 PMU in the SoC
Date: Sat, 29 Aug 2026 10:02:28 +0800 [thread overview]
Message-ID: <20260829020229.389742-3-vae1207@gmail.com> (raw)
In-Reply-To: <20260829020229.389742-1-vae1207@gmail.com>
Instantiate the PMU device, map its MMIO region at 0x91000000 and connect its interrupt line to the small-core PLIC source 81 (TRM 2.4 interrupt bit 65 + 16). Replace the previous unimplemented PMU window.
Signed-off-by: JunWei Li <vae1207@gmail.com>
---
hw/riscv/Kconfig | 1 +
hw/riscv/k230.c | 12 +++++++++---
include/hw/riscv/k230.h | 3 +++
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
index de37c08cae..0e61e6be3d 100644
--- a/hw/riscv/Kconfig
+++ b/hw/riscv/Kconfig
@@ -162,3 +162,4 @@ config K230
select SERIAL_MM
select UNIMP
select K230_WDT
+ select K230_PMU
diff --git a/hw/riscv/k230.c b/hw/riscv/k230.c
index 656f28190c..906a5c1240 100644
--- a/hw/riscv/k230.c
+++ b/hw/riscv/k230.c
@@ -110,6 +110,7 @@ static void k230_soc_init(Object *obj)
object_initialize_child(obj, "c908-cpu", cpu0, TYPE_RISCV_HART_ARRAY);
object_initialize_child(obj, "k230-wdt0", &s->wdt[0], TYPE_K230_WDT);
object_initialize_child(obj, "k230-wdt1", &s->wdt[1], TYPE_K230_WDT);
+ object_initialize_child(obj, "k230-pmu", &s->pmu, TYPE_K230_PMU);
qdev_prop_set_uint32(DEVICE(cpu0), "hartid-base", 0);
qdev_prop_set_string(DEVICE(cpu0), "cpu-type", TYPE_RISCV_CPU_THEAD_C908);
@@ -191,6 +192,14 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)
k230_create_uart(sys_mem, DEVICE(s->c908_plic), i);
}
+ /* PMU */
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->pmu), errp)) {
+ return;
+ }
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->pmu), 0, memmap[K230_DEV_PMU].base);
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmu), 0,
+ qdev_get_gpio_in(DEVICE(s->c908_plic), K230_PMU_IRQ));
+
/* Watchdog */
for (int i = 0; i < 2; i++) {
if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) {
@@ -259,9 +268,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)
create_unimplemented_device("3d-engine", memmap[K230_DEV_3D_ENGINE].base,
memmap[K230_DEV_3D_ENGINE].size);
- create_unimplemented_device("pmu", memmap[K230_DEV_PMU].base,
- memmap[K230_DEV_PMU].size);
-
create_unimplemented_device("rtc", memmap[K230_DEV_RTC].base,
memmap[K230_DEV_RTC].size);
diff --git a/include/hw/riscv/k230.h b/include/hw/riscv/k230.h
index 592e1c26bf..5e4845a274 100644
--- a/include/hw/riscv/k230.h
+++ b/include/hw/riscv/k230.h
@@ -16,6 +16,7 @@
#define HW_K230_H
#include "hw/core/boards.h"
+#include "hw/misc/k230_pmu.h"
#include "hw/riscv/riscv_hart.h"
#include "hw/watchdog/k230_wdt.h"
@@ -37,6 +38,7 @@ typedef struct K230SoCState {
MemoryRegion bootrom;
DeviceState *c908_plic;
+ K230PmuState pmu;
} K230SoCState;
#define TYPE_RISCV_K230_MACHINE MACHINE_TYPE_NAME("k230")
@@ -127,6 +129,7 @@ enum {
K230_UART2_IRQ = 18,
K230_UART3_IRQ = 19,
K230_UART4_IRQ = 20,
+ K230_PMU_IRQ = 81,
K230_WDT0_IRQ = 107,
K230_WDT1_IRQ = 108,
};
--
2.20.1
next prev parent reply other threads:[~2026-08-29 4:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-29 2:02 [PATCH 0/3] hw/misc: add K230 PMU device model JunWei Li
2026-08-29 2:02 ` [PATCH 1/3] hw/misc: add K230 PMU device JunWei Li
2026-08-29 2:02 ` JunWei Li [this message]
2026-08-29 2:02 ` [PATCH 3/3] tests/qtest: add k230-pmu-test JunWei Li
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=20260829020229.389742-3-vae1207@gmail.com \
--to=vae1207@gmail.com \
--cc=chenhuacai@canaan-creative.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
/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.