From: Hao Wu <wuhaotsh@google.com>
To: peter.maydell@linaro.org
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, wuhaotsh@google.com,
venture@google.com, Avi.Fishman@nuvoton.com, kfting@nuvoton.com,
hskinnemoen@google.com, titusr@google.com,
chli30@nuvoton.corp-partner.google.com
Subject: [PATCH v3 12/17] hw/misc: Add nr_regs and cold_reset_values to NPCM CLK
Date: Wed, 5 Feb 2025 17:31:00 -0800 [thread overview]
Message-ID: <20250206013105.3228344-13-wuhaotsh@google.com> (raw)
In-Reply-To: <20250206013105.3228344-1-wuhaotsh@google.com>
These 2 values are different between NPCM7XX and NPCM8XX
CLKs. So we add them to the class and assign different values
to them.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Hao Wu <wuhaotsh@google.com>
---
hw/misc/npcm_clk.c | 19 +++++++++++++------
include/hw/misc/npcm_clk.h | 9 ++++++++-
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/hw/misc/npcm_clk.c b/hw/misc/npcm_clk.c
index 0ecf0df3bb..9ad66ce212 100644
--- a/hw/misc/npcm_clk.c
+++ b/hw/misc/npcm_clk.c
@@ -81,7 +81,7 @@ enum NPCM7xxCLKRegisters {
* All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on
* core domain reset, but this reset type is not yet supported by QEMU.
*/
-static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
+static const uint32_t npcm7xx_cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
[NPCM7XX_CLK_CLKEN1] = 0xffffffff,
[NPCM7XX_CLK_CLKSEL] = 0x004aaaaa,
[NPCM7XX_CLK_CLKDIV1] = 0x5413f855,
@@ -728,10 +728,11 @@ static uint64_t npcm_clk_read(void *opaque, hwaddr offset, unsigned size)
{
uint32_t reg = offset / sizeof(uint32_t);
NPCMCLKState *s = opaque;
+ NPCMCLKClass *c = NPCM_CLK_GET_CLASS(s);
int64_t now_ns;
uint32_t value = 0;
- if (reg >= NPCM7XX_CLK_NR_REGS) {
+ if (reg >= c->nr_regs) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: offset 0x%04" HWADDR_PRIx " out of range\n",
__func__, offset);
@@ -776,11 +777,12 @@ static void npcm_clk_write(void *opaque, hwaddr offset,
{
uint32_t reg = offset / sizeof(uint32_t);
NPCMCLKState *s = opaque;
+ NPCMCLKClass *c = NPCM_CLK_GET_CLASS(s);
uint32_t value = v;
trace_npcm_clk_write(offset, value);
- if (reg >= NPCM7XX_CLK_NR_REGS) {
+ if (reg >= c->nr_regs) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: offset 0x%04" HWADDR_PRIx " out of range\n",
__func__, offset);
@@ -870,10 +872,11 @@ static const struct MemoryRegionOps npcm_clk_ops = {
static void npcm_clk_enter_reset(Object *obj, ResetType type)
{
NPCMCLKState *s = NPCM_CLK(obj);
+ NPCMCLKClass *c = NPCM_CLK_GET_CLASS(s);
- QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
-
- memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values));
+ g_assert(sizeof(s->regs) >= sizeof(c->cold_reset_values));
+ g_assert(sizeof(s->regs) >= c->nr_regs * sizeof(uint32_t));
+ memcpy(s->regs, c->cold_reset_values, sizeof(s->regs));
s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
npcm7xx_clk_update_all_clocks(s);
/*
@@ -1045,11 +1048,14 @@ static void npcm_clk_class_init(ObjectClass *klass, void *data)
static void npcm7xx_clk_class_init(ObjectClass *klass, void *data)
{
+ NPCMCLKClass *c = NPCM_CLK_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM_CLK_MAX_NR_REGS);
QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END != NPCM7XX_CLK_NR_REGS);
dc->desc = "NPCM7xx Clock Control Registers";
+ c->nr_regs = NPCM7XX_CLK_NR_REGS;
+ c->cold_reset_values = npcm7xx_cold_reset_values;
}
static const TypeInfo npcm7xx_clk_pll_info = {
@@ -1081,6 +1087,7 @@ static const TypeInfo npcm_clk_info = {
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(NPCMCLKState),
.instance_init = npcm_clk_init,
+ .class_size = sizeof(NPCMCLKClass),
.class_init = npcm_clk_class_init,
.abstract = true,
};
diff --git a/include/hw/misc/npcm_clk.h b/include/hw/misc/npcm_clk.h
index db03b46a52..f47614ac8d 100644
--- a/include/hw/misc/npcm_clk.h
+++ b/include/hw/misc/npcm_clk.h
@@ -175,8 +175,15 @@ struct NPCMCLKState {
Clock *clkref;
};
+typedef struct NPCMCLKClass {
+ SysBusDeviceClass parent;
+
+ size_t nr_regs;
+ const uint32_t *cold_reset_values;
+} NPCMCLKClass;
+
#define TYPE_NPCM_CLK "npcm-clk"
-OBJECT_DECLARE_SIMPLE_TYPE(NPCMCLKState, NPCM_CLK)
+OBJECT_DECLARE_TYPE(NPCMCLKState, NPCMCLKClass, NPCM_CLK)
#define TYPE_NPCM7XX_CLK "npcm7xx-clk"
#endif /* NPCM_CLK_H */
--
2.48.1.362.g079036d154-goog
next prev parent reply other threads:[~2025-02-06 1:36 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 1:30 [PATCH v3 00/17] hw/arm: Add NPCM8XX Support Hao Wu
2025-02-06 1:30 ` [PATCH v3 01/17] roms: Update vbootrom to 1287b6e Hao Wu
2025-02-06 1:30 ` [PATCH v3 02/17] pc-bios: Add NPCM8XX vBootrom Hao Wu
2025-02-06 1:30 ` [PATCH v3 03/17] hw/ssi: Make flash size a property in NPCM7XX FIU Hao Wu
2025-02-06 9:06 ` Philippe Mathieu-Daudé
2025-02-06 1:30 ` [PATCH v3 04/17] hw/misc: Rename npcm7xx_gcr to npcm_gcr Hao Wu
2025-02-06 1:30 ` [PATCH v3 05/17] hw/misc: Move NPCM7XX GCR to NPCM GCR Hao Wu
2025-02-06 1:30 ` [PATCH v3 06/17] hw/misc: Add nr_regs and cold_reset_values " Hao Wu
2025-02-06 1:30 ` [PATCH v3 07/17] hw/misc: Add support for NPCM8XX GCR Hao Wu
2025-02-06 9:13 ` Philippe Mathieu-Daudé
2025-02-06 1:30 ` [PATCH v3 08/17] hw/misc: Store DRAM size in NPCM8XX GCR Module Hao Wu
2025-02-06 1:30 ` [PATCH v3 09/17] hw/misc: Support 8-bytes memop in NPCM GCR module Hao Wu
2025-02-06 9:19 ` Philippe Mathieu-Daudé
2025-02-06 1:30 ` [PATCH v3 10/17] hw/misc: Rename npcm7xx_clk to npcm_clk Hao Wu
2025-02-06 1:30 ` [PATCH v3 11/17] hw/misc: Move NPCM7XX CLK to NPCM CLK Hao Wu
2025-02-06 1:31 ` Hao Wu [this message]
2025-02-06 9:22 ` [PATCH v3 12/17] hw/misc: Add nr_regs and cold_reset_values " Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 13/17] hw/misc: Support NPCM8XX CLK Module Registers Hao Wu
2025-02-06 9:24 ` Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 14/17] hw/net: Add NPCM8XX PCS Module Hao Wu
2025-02-06 1:31 ` [PATCH v3 15/17] hw/arm: Add NPCM8XX SoC Hao Wu
2025-02-06 1:31 ` [PATCH v3 16/17] hw/arm: Add NPCM845 Evaluation board Hao Wu
2025-02-06 9:27 ` Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 17/17] docs/system/arm: Add Description for NPCM8XX SoC Hao Wu
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=20250206013105.3228344-13-wuhaotsh@google.com \
--to=wuhaotsh@google.com \
--cc=Avi.Fishman@nuvoton.com \
--cc=chli30@nuvoton.corp-partner.google.com \
--cc=hskinnemoen@google.com \
--cc=kfting@nuvoton.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=titusr@google.com \
--cc=venture@google.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.