hw/arm: Add NPCM8XX Support
v2 cover hw/arm: Add NPCM8XX Support
Changes since v1:
1. Updated vbootrom and pc-bios
2. Split out CLK/GCR patches into refactoring and adding new features
3. Fixed a few misc items from the patches.
---
NPCM8XX BMCs are the successors of the NPCM7XX BMCs. They feature quad-core ARM Cortex A35 that supports both 32 bits and 64 bits operations. This patch set aims to support basic functionalities of the NPCM7XX BMCs. The patch set includes:
1. We derive most devices from the 7XX models and
made some modifications.
2. We have constructed a minimum vBootROM similar to the 7XX one at
https://github.com/google/vbootrom/tree/master/npcm8xx
and included it in the patch set.
3. We added a new NPCM8XX SOC and an evaluation
board machine npcm845-evb.
The OpenBMC for NPCM845 evaluation board can be found at:
https://github.com/Nuvoton-Israel/openbmc/tree/npcm-v2.10/meta-evb/meta-evb-nuvoton/meta-evb-npcm845
The patch set can boot the evaluation board image built from the source above to login prompt.
Hao Wu (17):
docs/system/arm: Add Description for NPCM8XX SoC
roms: Update vbootrom to 1287b6e
pc-bios: Add NPCM8XX vBootrom
hw/ssi: Make flash size a property in NPCM7XX FIU hw/misc: Rename npcm7xx_gcr to npcm_gcr hw/misc: Move NPCM7XX GCR to NPCM GCR hw/misc: Add nr_regs and cold_reset_values to NPCM GCR hw/misc: Add support for NPCM8XX GCR
hw/misc: Store DRAM size in NPCM8XX GCR Module hw/misc: Support 8-bytes memop in NPCM GCR module hw/misc: Rename npcm7xx_clk to npcm_clk hw/misc: Move NPCM7XX CLK to NPCM CLK hw/misc: Add nr_regs and cold_reset_values to NPCM CLK hw/misc: Support NPCM8XX CLK Module Registers hw/net: Add NPCM8XX PCS Module
hw/arm: Add NPCM8XX SoC
hw/arm: Add NPCM845 Evaluation board
MAINTAINERS | 1 +
configs/devices/aarch64-softmmu/default.mak | 1 +
docs/system/arm/nuvoton.rst | 20 +-
hw/arm/Kconfig | 11 +
hw/arm/meson.build | 1 +
hw/arm/npcm7xx.c | 6 +
hw/arm/npcm8xx.c | 810 ++++++++++++++++++
hw/arm/npcm8xx_boards.c | 256 ++++++
hw/misc/meson.build | 4 +-
hw/misc/npcm7xx_gcr.c | 264 ------
hw/misc/{npcm7xx_clk.c => npcm_clk.c} | 238 +++--
hw/misc/npcm_gcr.c | 483 +++++++++++
hw/misc/trace-events | 12 +-
hw/net/meson.build | 1 +
hw/net/npcm_pcs.c | 410 +++++++++
hw/net/trace-events | 4 +-
hw/ssi/npcm7xx_fiu.c | 11 +-
include/hw/arm/npcm7xx.h | 8 +-
include/hw/arm/npcm8xx.h | 127 +++
include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} | 43 +-
include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} | 29 +-
include/hw/net/npcm_pcs.h | 42 +
include/hw/ssi/npcm7xx_fiu.h | 1 +
pc-bios/README | 8 +-
pc-bios/meson.build | 1 +
pc-bios/npcm7xx_bootrom.bin | Bin 768 -> 768 bytes
pc-bios/npcm8xx_bootrom.bin | Bin 0 -> 608 bytes
roms/Makefile | 6 +
roms/vbootrom | 2 +-
29 files changed, 2432 insertions(+), 368 deletions(-)
create mode 100644 hw/arm/npcm8xx.c
create mode 100644 hw/arm/npcm8xx_boards.c
delete mode 100644 hw/misc/npcm7xx_gcr.c
rename hw/misc/{npcm7xx_clk.c => npcm_clk.c} (81%)
create mode 100644 hw/misc/npcm_gcr.c
create mode 100644 hw/net/npcm_pcs.c
create mode 100644 include/hw/arm/npcm8xx.h
rename include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} (83%)
rename include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} (76%)
create mode 100644 include/hw/net/npcm_pcs.h
create mode 100644 pc-bios/npcm8xx_bootrom.binSignature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH v2 1/17 docs/system/arm: Add Description for NPCM8XX SoC
NPCM8XX SoC is the successor of the NPCM7XX. It features quad-core Cortex-A35 (Armv8, 64-bit) CPUs and some additional peripherals.
--- docs/system/arm/nuvoton.rst | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
docs/system/arm/nuvoton.rst +15 -5
@@ -1,12 +1,13 @@ Nuvoton iBMC boards (``kudo-bmc``, ``mori-bmc``, ``npcm750-evb``, ``quanta-gbs-bmc``, ``quanta-gsj``) ===================================================================================================== -The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are +The `Nuvoton iBMC`_ chips are a family of ARM-based SoCs that are designed to be used as Baseboard Management Controllers (BMCs) in various -servers. They all feature one or two ARM Cortex-A9 CPU cores, as well as an -assortment of peripherals targeted for either Enterprise or Data Center / -Hyperscale applications. The former is a superset of the latter, so NPCM750 has -all the peripherals of NPCM730 and more. +servers. Currently there are two families: NPCM7XX series and +NPCM8XX series. NPCM7XX series feature one or two ARM Cortex-A9 CPU cores, +while NPCM8XX feature 4 ARM Cortex-A35 CPU cores. Both series contain a +different assortment of peripherals targeted for either Enterprise or Data +Center / Hyperscale applications. .. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
@@ -27,6 +28,8 @@ There are also two more SoCs, NPCM710 and NPCM705, which are single-core variants of NPCM750 and NPCM730, respectively. These are currently not supported by QEMU. +The NPCM8xx SoC is the successor of the NPCM7xx SoC. + Supported devices -----------------
@@ -62,6 +65,8 @@ Missing devices * System Wake-up Control (SWC) * Shared memory (SHM) * eSPI slave interface + * Block-tranfer interface (8XX only) + * Virtual UART (8XX only) * Ethernet controller (GMAC) * USB device (USBD)
@@ -76,6 +81,11 @@ Missing devices * Video capture * Encoding compression engine * Security features + * I3C buses (8XX only) + * Temperator sensor interface (8XX only) + * Virtual UART (8XX only) + * Flash monitor (8XX only) + * JTAG master (8XX only) Boot options ------------
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 01/17] docs/system/arm: Add Description for NPCM8XX SoC
Quoted 3 lines · Hao Wu
NPCM8XX SoC is the successor of the NPCM7XX. It features quad-core Cortex-A35 (Armv8, 64-bit) CPUs and some additional peripherals.
This should go at the end of the series, once you've added the new machine types it documents.
docs/system/arm/nuvoton.rst line 2
Quoted 12 lines
Signed-off-by Hao Wu <[email protected]>--- docs/system/arm/nuvoton.rst | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)docs/system/arm/nuvoton.rst +0
-0@@ -1,12 +1,13 @@ Nuvoton iBMC boards (``kudo-bmc``, ``mori-bmc``, ``npcm750-evb``, ``quanta-gbs-bmc``, ``quanta-gsj``) =====================================================================================================
You should add the names of the new boards in the title.
docs/system/arm/nuvoton.rst line 10
Quoted 12 lines
docs/system/arm/nuvoton.rst +6
-5-The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are +The `Nuvoton iBMC`_ chips are a family of ARM-based SoCs that are designed to be used as Baseboard Management Controllers (BMCs) in various -servers. They all feature one or two ARM Cortex-A9 CPU cores, as well as an -assortment of peripherals targeted for either Enterprise or Data Center / -Hyperscale applications. The former is a superset of the latter, so NPCM750 has -all the peripherals of NPCM730 and more. +servers. Currently there are two families: NPCM7XX series and +NPCM8XX series. NPCM7XX series feature one or two ARM Cortex-A9 CPU cores, +while NPCM8XX feature 4 ARM Cortex-A35 CPU cores. Both series contain a +different assortment of peripherals targeted for either Enterprise or Data +Center / Hyperscale applications.
The correct capitalization for "Arm" is "Arm".
docs/system/arm/nuvoton.rst There are also two more SoCs, NPCM710 and NPCM705, which are single-core · line 31
Quoted 8 lines
docs/system/arm/nuvoton.rst +1
-0.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/@@ -27,6 +28,8 @@ There are also two more SoCs, NPCM710 and NPCM705, which are single-core variants of NPCM750 and NPCM730, respectively. These are currently not supported by QEMU. +The NPCM8xx SoC is the successor of the NPCM7xx SoC.
There should be a bullet-point list below here which lists the new machine types.
docs/system/arm/nuvoton.rst Missing devices · line 68
Quoted 9 lines
docs/system/arm/nuvoton.rst +2
-0+ Supported devices -----------------@@ -62,6 +65,8 @@ Missing devices * System Wake-up Control (SWC) * Shared memory (SHM) * eSPI slave interface + * Block-tranfer interface (8XX only)
Typo: "transfer"
docs/system/arm/nuvoton.rst Missing devices · line 85
Quoted 10 lines
docs/system/arm/nuvoton.rst +3
-0+ * Virtual UART (8XX only) * Ethernet controller (GMAC) * USB device (USBD)@@ -76,6 +81,11 @@ Missing devices * Video capture * Encoding compression engine * Security features + * I3C buses (8XX only) + * Temperator sensor interface (8XX only)
Typo: "Temperature"
docs/system/arm/nuvoton.rst Missing devices · line 88
Quoted 3 lines
docs/system/arm/nuvoton.rst +3
-0+ * Virtual UART (8XX only) + * Flash monitor (8XX only) + * JTAG master (8XX only)
thanks
-- PMM
PATCH v2 2/17 roms: Update vbootrom to 1287b6e
In reply to Hao WuThis newer vbootrom supports NPCM8xx. Similar to the NPCM7XX one it supports loading the UBoot from the SPI device and not more.
We updated the npcm7xx bootrom to be compiled from this version.
--- pc-bios/npcm7xx_bootrom.bin | Bin 768 -> 768 bytes roms/vbootrom | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-)
pc-bios/npcm7xx_bootrom.bin binary +0 -0
roms/vbootrom +1 -1
@@ -1 +1 @@ -Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac +Subproject commit 1287b6e42e839ba2ab0f06268c5b53ae60df3537
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 02/17] roms: Update vbootrom to 1287b6e
Quoted 8 lines · Hao Wu
This newer vbootrom supports NPCM8xx. Similar to the NPCM7XX one it supports loading the UBoot from the SPI device and not more.
We updated the npcm7xx bootrom to be compiled from this version.
Signed-off-by Hao Wu <[email protected]>---
thanks
-- PMM
PATCH v2 3/17 pc-bios: Add NPCM8XX vBootrom
In reply to Hao WuThe bootrom is a minimal bootrom used to load an NPCM8XX image. The source code is located in the same repo as the NPCM7XX one:
github.com/google/vbootrom/tree/master/npcm8xx.
--- MAINTAINERS | 1 + pc-bios/README | 8 ++++---- pc-bios/meson.build | 1 + pc-bios/npcm8xx_bootrom.bin | Bin 0 -> 608 bytes roms/Makefile | 6 ++++++ 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 pc-bios/npcm8xx_bootrom.bin
MAINTAINERS +1 -0
@@ -872,6 +872,7 @@ F: include/hw/*/npcm* F: tests/qtest/npcm* F: tests/qtest/adm1266-test.c F: pc-bios/npcm7xx_bootrom.bin +F: pc-bios/npcm8xx_bootrom.bin F: roms/vbootrom F: docs/system/arm/nuvoton.rst F: tests/functional/test_arm_quanta_gsj.py
pc-bios/README +4 -4
@@ -70,10 +70,10 @@ source code also contains code reused from other projects described here: https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md. -- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton - NPCM7xx BMC devices. It currently implements the bare minimum to load, parse, - initialize and run boot images stored in SPI flash, but may grow more - features over time as needed. The source code is available at: +- npcm{7xx,8xx}_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for + Nuvoton NPCM7xx/8xx BMC devices. It currently implements the bare minimum to + load, parse, initialize and run boot images stored in SPI flash, but may grow + more features over time as needed. The source code is available at: https://github.com/google/vbootrom - hppa-firmware.img (32-bit) and hppa-firmware64.img (64-bit) are firmware
pc-bios/meson.build +1 -0
@@ -80,6 +80,7 @@ blobs = [ 'opensbi-riscv32-generic-fw_dynamic.bin', 'opensbi-riscv64-generic-fw_dynamic.bin', 'npcm7xx_bootrom.bin', + 'npcm8xx_bootrom.bin', 'vof.bin', 'vof-nvram.bin', ]
pc-bios/npcm8xx_bootrom.bin new file binary +0 -0
roms/Makefile +6 -0
@@ -34,6 +34,7 @@ find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call find-cross-ld # finally strip off path + toolname so we get the prefix find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1)))) +aarch64_cross_prefix := $(call find-cross-prefix,aarch64) arm_cross_prefix := $(call find-cross-prefix,arm) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
@@ -66,6 +67,7 @@ default help: @echo " u-boot.e500 -- update u-boot.e500" @echo " u-boot.sam460 -- update u-boot.sam460" @echo " npcm7xx_bootrom -- update vbootrom for npcm7xx" + @echo " npcm8xx_bootrom -- update vbootrom for npcm8xx" @echo " efi -- update UEFI (edk2) platform firmware" @echo " opensbi32-generic -- update OpenSBI for 32-bit generic machine" @echo " opensbi64-generic -- update OpenSBI for 64-bit generic machine"
@@ -194,6 +196,10 @@ npcm7xx_bootrom: $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix) cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin +npcm8xx_bootrom: + $(MAKE) -C vbootrom CROSS_COMPILE=$(aarch64_cross_prefix) + cp vbootrom/npcm8xx_bootrom.bin ../pc-bios/npcm8xx_bootrom.bin + hppa-firmware: $(MAKE) -C seabios-hppa parisc cp seabios-hppa/out/hppa-firmware.img ../pc-bios/
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 03/17] pc-bios: Add NPCM8XX vBootrom
Quoted 6 lines · Hao Wu
The bootrom is a minimal bootrom used to load an NPCM8XX image. The source code is located in the same repo as the NPCM7XX one:
github.com/google/vbootrom/tree/master/npcm8xx.Signed-off-by Hao Wu <[email protected]>
thanks
-- PMM
PATCH v2 4/17 hw/ssi: Make flash size a property in NPCM7XX FIU
In reply to Hao WuThis allows different FIUs to have different flash sizes, useful in NPCM8XX which has multiple different sized FIU modules.
--- hw/arm/npcm7xx.c | 6 ++++++ hw/ssi/npcm7xx_fiu.c | 11 +++++++---- include/hw/ssi/npcm7xx_fiu.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-)
hw/arm/npcm7xx.c +6 -0
@@ -292,17 +292,21 @@ static const struct {hwaddr regs_addr;int cs_count;const hwaddr *flash_addr; +size_t flash_size; } npcm7xx_fiu[] = { { .name = "fiu0", .regs_addr = 0xfb000000, .cs_count = ARRAY_SIZE(npcm7xx_fiu0_flash_addr), .flash_addr = npcm7xx_fiu0_flash_addr, + .flash_size = 128 * MiB, + }, { .name = "fiu3", .regs_addr = 0xc0000000, .cs_count = ARRAY_SIZE(npcm7xx_fiu3_flash_addr), .flash_addr = npcm7xx_fiu3_flash_addr, + .flash_size = 128 * MiB, }, };
@@ -735,6 +739,8 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)object_property_set_int (OBJECT (sbd),"cs-count" , npcm7xx_fiu[i].cs_count, &error_abort); +object_property_set_int (OBJECT (sbd),"flash-size" , + npcm7xx_fiu[i].flash_size, &error_abort);sysbus_realize (sbd, &error_abort);sysbus_mmio_map (sbd,0 , npcm7xx_fiu[i].regs_addr);
hw/ssi/npcm7xx_fiu.c +7 -4
@@ -28,9 +28,6 @@#include "trace.h" -/* Up to 128 MiB of flash may be accessed directly as memory. */ -#define NPCM7XX_FIU_FLASH_WINDOW_SIZE (128 * MiB) -/* Each module has 4 KiB of register space. Only a fraction of it is used. */ #define NPCM7XX_FIU_CTRL_REGS_SIZE (4 * KiB)
@@ -507,6 +504,11 @@ static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp)return ; } +if (s->flash_size ==0 ) { +error_setg (errp,"%s: flash size must be set" , dev->canonical_path); +return ; + } + s->spi =ssi_create_bus (dev,"spi" ); s->cs_lines =g_new0 (qemu_irq, s->cs_count);qdev_init_gpio_out_named (DEVICE (s), s->cs_lines,"cs" , s->cs_count);
@@ -525,7 +527,7 @@ static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp) flash->fiu = s;memory_region_init_io (&flash->direct_access,OBJECT (s), &npcm7xx_fiu_flash_ops, &s->flash[i],"flash" , -NPCM7XX_FIU_FLASH_WINDOW_SIZE ); + s->flash_size);sysbus_init_mmio (sbd, &flash->direct_access); } }
@@ -543,6 +545,7 @@ static const VMStateDescription vmstate_npcm7xx_fiu = {static const Property npcm7xx_fiu_properties[] = {DEFINE_PROP_INT32 ("cs-count" , NPCM7xxFIUState, cs_count,0 ), +DEFINE_PROP_SIZE ("flash-size" , NPCM7xxFIUState, flash_size,0 ), };static void npcm7xx_fiu_class_init (ObjectClass *klass,void *data)
include/hw/ssi/npcm7xx_fiu.h +1 -0
@@ -60,6 +60,7 @@ struct NPCM7xxFIUState {int32_t cs_count;int32_t active_cs;qemu_irq *cs_lines; +size_t flash_size;NPCM7xxFIUFlash *flash;SSIBus *spi;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 04/17] hw/ssi: Make flash size a property in NPCM7XX FIU
Quoted 10 lines · Hao Wu
This allows different FIUs to have different flash sizes, useful in NPCM8XX which has multiple different sized FIU modules.
Signed-off-by Hao Wu <[email protected]>--- hw/arm/npcm7xx.c | 6 ++++++ hw/ssi/npcm7xx_fiu.c | 11 +++++++---- include/hw/ssi/npcm7xx_fiu.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH v2 5/17 hw/misc: Rename npcm7xx_gcr to npcm_gcr
In reply to Hao WuNPCM7XX and NPCM8XX have a different set of GCRs and the GCR module needs to fit both. This commit changes the name of the GCR module. Future commits will add the support for NPCM8XX GCRs.
---
hw/misc/meson.build | 2 +-
hw/misc/{npcm7xx_gcr.c => npcm_gcr.c} | 2 +-
include/hw/arm/npcm7xx.h | 2 +-
include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
rename hw/misc/{npcm7xx_gcr.c => npcm_gcr.c} (99%)
rename include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} (96%)hw/misc/meson.build +1 -1
@@ -68,7 +68,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( )) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( 'npcm7xx_clk.c', - 'npcm7xx_gcr.c', + 'npcm_gcr.c', 'npcm7xx_mft.c', 'npcm7xx_pwm.c', 'npcm7xx_rng.c',
hw/misc/npcm_gcr.c renamed from hw/misc/npcm7xx_gcr.c +1 -1
@@ -16,7 +16,7 @@#include "qemu/osdep.h" -#include "hw/misc/npcm7xx_gcr.h" +#include "hw/misc/npcm_gcr.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "qapi/error.h"
include/hw/arm/npcm7xx.h +1 -1
@@ -24,7 +24,7 @@#include "hw/i2c/npcm7xx_smbus.h" #include "hw/mem/npcm7xx_mc.h" #include "hw/misc/npcm7xx_clk.h" -#include "hw/misc/npcm7xx_gcr.h" +#include "hw/misc/npcm_gcr.h" #include "hw/misc/npcm7xx_mft.h" #include "hw/misc/npcm7xx_pwm.h" #include "hw/misc/npcm7xx_rng.h"
include/hw/misc/npcm_gcr.h renamed from include/hw/misc/npcm7xx_gcr.h +3 -3
@@ -13,8 +13,8 @@* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ -#ifndef NPCM7XX_GCR_H -#define NPCM7XX_GCR_H +#ifndef NPCM_GCR_H +#define NPCM_GCR_H #include "exec/memory.h" #include "hw/sysbus.h"
@@ -70,4 +70,4 @@ struct NPCM7xxGCRState {#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxGCRState, NPCM7XX_GCR) -#endif /* NPCM7XX_GCR_H */ +#endif /* NPCM_GCR_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 05/17] hw/misc: Rename npcm7xx_gcr to npcm_gcr
q
Quoted 6 lines · Hao Wu
NPCM7XX and NPCM8XX have a different set of GCRs and the GCR module needs to fit both. This commit changes the name of the GCR module. Future commits will add the support for NPCM8XX GCRs.
Signed-off-by Hao Wu <[email protected]>
Quoted 8 lines
---
hw/misc/meson.build | 2 +-
hw/misc/{npcm7xx_gcr.c => npcm_gcr.c} | 2 +-
include/hw/arm/npcm7xx.h | 2 +-
include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
rename hw/misc/{npcm7xx_gcr.c => npcm_gcr.c} (99%)
rename include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} (96%)thanks
-- PMM
PATCH v2 6/17 hw/misc: Move NPCM7XX GCR to NPCM GCR
In reply to Hao WuA lot of NPCM7XX and NPCM8XX GCR modules share the same code, this commit moves the NPCM7XX GCR to NPCM GCR for these properties.
--- hw/misc/npcm_gcr.c | 92 +++++++++++++++++++++----------------- hw/misc/trace-events | 6 +-- include/hw/arm/npcm7xx.h | 2 +- include/hw/misc/npcm_gcr.h | 7 +-- 4 files changed, 59 insertions(+), 48 deletions(-)
hw/misc/npcm_gcr.c +51 -41
@@ -84,10 +84,10 @@ static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS] = { [NPCM7XX_GCR_USB2PHYCTL] = 0x034730e4, }; -static uint64_t npcm7xx_gcr_read (void *opaque,hwaddr offset,unsigned size) +static uint64_t npcm_gcr_read (void *opaque,hwaddr offset,unsigned size) {uint32_t reg = offset /sizeof (uint32_t ); -NPCM7xxGCRState *s = opaque; +NPCMGCRState *s = opaque;if (reg >=NPCM7XX_GCR_NR_REGS ) { qemu_log_mask(LOG_GUEST_ERROR,
@@ -96,19 +96,19 @@ static uint64_t npcm7xx_gcr_read(void *opaque, hwaddr offset, unsigned size)return 0 ; } -trace_npcm7xx_gcr_read (offset, s->regs[reg]); +trace_npcm_gcr_read (offset, s->regs[reg]);return s->regs[reg]; } -static void npcm7xx_gcr_write (void *opaque,hwaddr offset, +static void npcm_gcr_write (void *opaque,hwaddr offset,uint64_t v,unsigned size) {uint32_t reg = offset /sizeof (uint32_t ); -NPCM7xxGCRState *s = opaque; +NPCMGCRState *s = opaque;uint32_t value = v; -trace_npcm7xx_gcr_write (offset, value); +trace_npcm_gcr_write (offset, value);if (reg >=NPCM7XX_GCR_NR_REGS ) { qemu_log_mask(LOG_GUEST_ERROR,
@@ -142,9 +142,9 @@ static void npcm7xx_gcr_write(void *opaque, hwaddr offset, s->regs[reg] = value; } -static const struct MemoryRegionOps npcm7xx_gcr_ops = { - .read = npcm7xx_gcr_read, - .write = npcm7xx_gcr_write, +static const struct MemoryRegionOps npcm_gcr_ops = { + .read = npcm_gcr_read, + .write = npcm_gcr_write, .endianness =DEVICE_LITTLE_ENDIAN , .valid = { .min_access_size =4 ,
@@ -155,7 +155,7 @@ static const struct MemoryRegionOps npcm7xx_gcr_ops = {static void npcm7xx_gcr_enter_reset (Object *obj,ResetType type) { -NPCM7xxGCRState *s =NPCM7XX_GCR (obj); +NPCMGCRState *s =NPCM_GCR (obj);QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values));
@@ -165,10 +165,10 @@ static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type) s->regs[NPCM7XX_GCR_INTCR3 ] = s->reset_intcr3; } -static void npcm7xx_gcr_realize (DeviceState *dev,Error **errp) +static void npcm_gcr_realize (DeviceState *dev,Error **errp) {ERRP_GUARD (); -NPCM7xxGCRState *s =NPCM7XX_GCR (dev); +NPCMGCRState *s =NPCM_GCR (dev);uint64_t dram_size;Object *obj;
@@ -210,55 +210,65 @@ static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp) s->reset_intcr3 |=ctz64 (dram_size /NPCM7XX_GCR_MIN_DRAM_SIZE ) <<8 ; } -static void npcm7xx_gcr_init (Object *obj) +static void npcm_gcr_init (Object *obj) { -NPCM7xxGCRState *s =NPCM7XX_GCR (obj); +NPCMGCRState *s =NPCM_GCR (obj); -memory_region_init_io (&s->iomem, obj, &npcm7xx_gcr_ops, s, -TYPE_NPCM7XX_GCR ,4 * KiB); +memory_region_init_io (&s->iomem, obj, &npcm_gcr_ops, s, +TYPE_NPCM_GCR ,4 * KiB);sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); } -static const VMStateDescription vmstate_npcm7xx_gcr = { - .name ="npcm7xx-gcr" , - .version_id =0 , - .minimum_version_id =0 , +static const VMStateDescription vmstate_npcm_gcr = { + .name ="npcm-gcr" , + .version_id =1 , + .minimum_version_id =1 , .fields = (const VMStateField []) { -VMSTATE_UINT32_ARRAY (regs, NPCM7xxGCRState,NPCM7XX_GCR_NR_REGS ), +VMSTATE_UINT32_ARRAY (regs, NPCMGCRState,NPCM7XX_GCR_NR_REGS ),VMSTATE_END_OF_LIST (), }, }; -static const Property npcm7xx_gcr_properties[] = { -DEFINE_PROP_UINT32 ("disabled-modules" , NPCM7xxGCRState, reset_mdlr,0 ), -DEFINE_PROP_UINT32 ("power-on-straps" , NPCM7xxGCRState, reset_pwron,0 ), +static const Property npcm_gcr_properties[] = { +DEFINE_PROP_UINT32 ("disabled-modules" , NPCMGCRState, reset_mdlr,0 ), +DEFINE_PROP_UINT32 ("power-on-straps" , NPCMGCRState, reset_pwron,0 ), }; -static void npcm7xx_gcr_class_init (ObjectClass *klass,void *data) +static void npcm_gcr_class_init (ObjectClass *klass,void *data) { -ResettableClass *rc =RESETTABLE_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass);QEMU_BUILD_BUG_ON (NPCM7XX_GCR_REGS_END >NPCM7XX_GCR_NR_REGS ); + dc->realize = npcm_gcr_realize; + dc->vmsd = &vmstate_npcm_gcr; + +device_class_set_props (dc, npcm_gcr_properties); +} + +static void npcm7xx_gcr_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); +QEMU_BUILD_BUG_ON (NPCM7XX_GCR_REGS_END !=NPCM7XX_GCR_NR_REGS ); dc->desc ="NPCM7xx System Global Control Registers" ; - dc->realize = npcm7xx_gcr_realize; - dc->vmsd = &vmstate_npcm7xx_gcr; rc->phases.enter = npcm7xx_gcr_enter_reset; -device_class_set_props (dc, npcm7xx_gcr_properties); } -static const TypeInfo npcm7xx_gcr_info = { - .name =TYPE_NPCM7XX_GCR , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (NPCM7xxGCRState), - .instance_init = npcm7xx_gcr_init, - .class_init = npcm7xx_gcr_class_init, +static const TypeInfo npcm_gcr_info[] = { + { + .name =TYPE_NPCM_GCR , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCMGCRState), + .instance_init = npcm_gcr_init, + .class_init = npcm_gcr_class_init, + .abstract = true, + }, + { + .name =TYPE_NPCM7XX_GCR , + .parent =TYPE_NPCM_GCR , + .class_init = npcm7xx_gcr_class_init, + }, }; - -static void npcm7xx_gcr_register_type (void ) -{ -type_register_static (&npcm7xx_gcr_info); -} -type_init (npcm7xx_gcr_register_type); +DEFINE_TYPES (npcm_gcr_info)
hw/misc/trace-events +3 -3
@@ -134,9 +134,9 @@ mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [% npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 -# npcm7xx_gcr.c -npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 -npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +# npcm_gcr.c +npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 # npcm7xx_mft.c npcm7xx_mft_read(const char *name, uint64_t offset, uint16_t value) "%s: offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
include/hw/arm/npcm7xx.h +1 -1
@@ -89,7 +89,7 @@ struct NPCM7xxState {MemoryRegion ram3;MemoryRegion *dram; -NPCM7xxGCRState gcr; +NPCMGCRState gcr;NPCM7xxCLKState clk;NPCM7xxTimerCtrlState tim[3 ];NPCM7xxADCState adc;
include/hw/misc/npcm_gcr.h +4 -3
@@ -55,7 +55,7 @@*/ #define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t)) -struct NPCM7xxGCRState { +typedef struct NPCMGCRState { SysBusDevice parent; MemoryRegion iomem;
@@ -65,9 +65,10 @@ struct NPCM7xxGCRState {uint32_t reset_pwron;uint32_t reset_mdlr;uint32_t reset_intcr3; -}; +} NPCMGCRState; +#define TYPE_NPCM_GCR "npcm-gcr"#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" -OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxGCRState, NPCM7XX_GCR) +OBJECT_DECLARE_SIMPLE_TYPE(NPCMGCRState, NPCM_GCR)#endif /* NPCM_GCR_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 06/17] hw/misc: Move NPCM7XX GCR to NPCM GCR
Quoted 7 lines · Hao Wu
A lot of NPCM7XX and NPCM8XX GCR modules share the same code, this commit moves the NPCM7XX GCR to NPCM GCR for these properties.
Signed-off-by Hao Wu <[email protected]>---
thanks
-- PMM
PATCH v2 7/17 hw/misc: Add nr_regs and cold_reset_values to NPCM GCR
In reply to Hao WuThese 2 values are different between NPCM7XX and NPCM8XX GCRs. So we add them to the class and assign different values to them.
--- hw/misc/npcm_gcr.c | 24 +++++++++++++++--------- include/hw/misc/npcm_gcr.h | 13 +++++++++++-- 2 files changed, 26 insertions(+), 11 deletions(-)
hw/misc/npcm_gcr.c +15 -9
@@ -69,7 +69,7 @@ enum NPCM7xxGCRRegisters { NPCM7XX_GCR_REGS_END, }; -static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS ] = { +static const uint32_t npcm7xx_cold_reset_values[NPCM7XX_GCR_NR_REGS ] = { [NPCM7XX_GCR_PDID ] =0x04a92750 ,/* Poleg A1 */ [NPCM7XX_GCR_MISCPE ] =0x0000ffff , [NPCM7XX_GCR_SPSWC ] =0x00000003 ,
@@ -88,8 +88,9 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size) {uint32_t reg = offset /sizeof (uint32_t );NPCMGCRState *s = opaque; +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (s); -if (reg >=NPCM7XX_GCR_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);
@@ -106,11 +107,12 @@ static void npcm_gcr_write(void *opaque, hwaddr offset, {uint32_t reg = offset /sizeof (uint32_t );NPCMGCRState *s = opaque; +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (s);uint32_t value = v; -trace_npcm_gcr_write (offset, value); +trace_npcm_gcr_write (offset, v); -if (reg >=NPCM7XX_GCR_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);
@@ -156,10 +158,10 @@ static const struct MemoryRegionOps npcm_gcr_ops = {static void npcm7xx_gcr_enter_reset (Object *obj,ResetType type) {NPCMGCRState *s =NPCM_GCR (obj); +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (obj); -QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); - -memcpy (s->regs, cold_reset_values,sizeof (s->regs)); +memcpy (s->regs, c->cold_reset_values, c->nr_regs *sizeof (uint32_t )); +/* These 3 registers are at the same location in both 7xx and 8xx. */ s->regs[NPCM7XX_GCR_PWRON ] = s->reset_pwron; s->regs[NPCM7XX_GCR_MDLR ] = s->reset_mdlr; s->regs[NPCM7XX_GCR_INTCR3 ] = s->reset_intcr3;
@@ -224,7 +226,7 @@ static const VMStateDescription vmstate_npcm_gcr = { .version_id = 1, .minimum_version_id = 1, .fields = (const VMStateField []) { -VMSTATE_UINT32_ARRAY (regs, NPCMGCRState,NPCM7XX_GCR_NR_REGS ), +VMSTATE_UINT32_ARRAY (regs, NPCMGCRState,NPCM_GCR_MAX_NR_REGS ),VMSTATE_END_OF_LIST (), }, };
@@ -238,7 +240,6 @@ static void npcm_gcr_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -QEMU_BUILD_BUG_ON (NPCM7XX_GCR_REGS_END >NPCM7XX_GCR_NR_REGS ); dc->realize = npcm_gcr_realize; dc->vmsd = &vmstate_npcm_gcr;
@@ -247,13 +248,17 @@ static void npcm_gcr_class_init(ObjectClass *klass, void *data)static void npcm7xx_gcr_class_init (ObjectClass *klass,void *data) { +NPCMGCRClass *c =NPCM_GCR_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass);ResettableClass *rc =RESETTABLE_CLASS (klass); +QEMU_BUILD_BUG_ON (NPCM7XX_GCR_REGS_END >NPCM_GCR_MAX_NR_REGS );QEMU_BUILD_BUG_ON (NPCM7XX_GCR_REGS_END !=NPCM7XX_GCR_NR_REGS ); dc->desc ="NPCM7xx System Global Control Registers" ; rc->phases.enter = npcm7xx_gcr_enter_reset; + c->nr_regs =NPCM7XX_GCR_NR_REGS ; + c->cold_reset_values = npcm7xx_cold_reset_values; }static const TypeInfo npcm_gcr_info[] = {
@@ -262,6 +267,7 @@ static const TypeInfo npcm_gcr_info[] = { .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(NPCMGCRState), .instance_init = npcm_gcr_init, + .class_size = sizeof(NPCMGCRClass), .class_init = npcm_gcr_class_init, .abstract = true, },
include/hw/misc/npcm_gcr.h +11 -2
@@ -18,6 +18,7 @@#include "exec/memory.h" #include "hw/sysbus.h" +#include "qom/object.h" /* * NPCM7XX PWRON STRAP bit fields
@@ -53,6 +54,7 @@* Number of registers in our device state structure. Don't change this without * incrementing the version_id in the vmstate. */ +#define NPCM_GCR_MAX_NR_REGS NPCM7XX_GCR_NR_REGS#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t)) typedef struct NPCMGCRState {
@@ -60,15 +62,22 @@ typedef struct NPCMGCRState {MemoryRegion iomem; -uint32_t regs[NPCM7XX_GCR_NR_REGS ]; +uint32_t regs[NPCM_GCR_MAX_NR_REGS ];uint32_t reset_pwron;uint32_t reset_mdlr;uint32_t reset_intcr3; } NPCMGCRState; +typedef struct NPCMGCRClass { +SysBusDeviceClass parent; + +size_t nr_regs; +const uint32_t *cold_reset_values; +}NPCMGCRClass ; +#define TYPE_NPCM_GCR "npcm-gcr"#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" -OBJECT_DECLARE_SIMPLE_TYPE(NPCMGCRState, NPCM_GCR) +OBJECT_DECLARE_TYPE(NPCMGCRState, NPCMGCRClass, NPCM_GCR)#endif /* NPCM_GCR_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 07/17] hw/misc: Add nr_regs and cold_reset_values to NPCM GCR
Quoted 15 lines · Hao Wu
These 2 values are different between NPCM7XX and NPCM8XX GCRs. So we add them to the class and assign different values to them.
Signed-off-by Hao Wu <[email protected]>--- hw/misc/npcm_gcr.c | 24 +++++++++++++++--------- include/hw/misc/npcm_gcr.h | 13 +++++++++++-- 2 files changed, 26 insertions(+), 11 deletions(-)
hw/misc/npcm_gcr.c static const struct MemoryRegionOps npcm_gcr_ops = { · line 163
Quoted 9 lines
hw/misc/npcm_gcr.c +2
-3@@ -156,10 +158,10 @@ static const struct MemoryRegionOps npcm_gcr_ops = {static void npcm7xx_gcr_enter_reset (Object *obj,ResetType type) {NPCMGCRState *s =NPCM_GCR (obj); +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (obj); -QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); - -memcpy (s->regs, cold_reset_values,sizeof (s->regs)); +memcpy (s->regs, c->cold_reset_values, c->nr_regs *sizeof (uint32_t ));
Previously we had a compile-time assert that we were copying the right amount of data. Making this a class-specific thing means we can't assert at compile time any more, but I think it's still worth a runtime assert that we aren't copying more data than will fit into s->regs.
Otherwise
thanks
-- PMM
PATCH v2 8/17 hw/misc: Add support for NPCM8XX GCR
In reply to Hao Wu--- hw/misc/npcm_gcr.c | 131 ++++++++++++++++++++++++++++++++++++- include/hw/misc/npcm_gcr.h | 6 +- 2 files changed, 134 insertions(+), 3 deletions(-)
hw/misc/npcm_gcr.c +130 -1
@@ -1,5 +1,5 @@/* -* Nuvoton NPCM7xx System Global Control Registers. +* Nuvoton NPCM7xx/8xx System Global Control Registers. * * Copyright 2020 Google LLC *
@@ -84,6 +84,118 @@ static const uint32_t npcm7xx_cold_reset_values[NPCM7XX_GCR_NR_REGS] = { [NPCM7XX_GCR_USB2PHYCTL] = 0x034730e4, }; +enum NPCM8xxGCRRegisters { +NPCM8XX_GCR_PDID , +NPCM8XX_GCR_PWRON , +NPCM8XX_GCR_MISCPE =0x014 /sizeof (uint32_t ), +NPCM8XX_GCR_FLOCKR2 =0x020 /sizeof (uint32_t ), +NPCM8XX_GCR_FLOCKR3 , +NPCM8XX_GCR_A35_MODE =0x034 /sizeof (uint32_t ), +NPCM8XX_GCR_SPSWC , +NPCM8XX_GCR_INTCR , +NPCM8XX_GCR_INTSR , +NPCM8XX_GCR_HIFCR =0x050 /sizeof (uint32_t ), +NPCM8XX_GCR_INTCR2 =0x060 /sizeof (uint32_t ), +NPCM8XX_GCR_SRCNT =0x068 /sizeof (uint32_t ), +NPCM8XX_GCR_RESSR , +NPCM8XX_GCR_RLOCKR1 , +NPCM8XX_GCR_FLOCKR1 , +NPCM8XX_GCR_DSCNT , +NPCM8XX_GCR_MDLR , +NPCM8XX_GCR_SCRPAD_C =0x080 /sizeof (uint32_t ), +NPCM8XX_GCR_SCRPAD_B , +NPCM8XX_GCR_DAVCLVLR =0x098 /sizeof (uint32_t ), +NPCM8XX_GCR_INTCR3 , +NPCM8XX_GCR_PCIRCTL =0x0a0 /sizeof (uint32_t ), +NPCM8XX_GCR_VSINTR , +NPCM8XX_GCR_SD2SUR1 =0x0b4 /sizeof (uint32_t ), +NPCM8XX_GCR_SD2SUR2 , +NPCM8XX_GCR_INTCR4 =0x0c0 /sizeof (uint32_t ), +NPCM8XX_GCR_CPCTL =0x0d0 /sizeof (uint32_t ), +NPCM8XX_GCR_CP2BST , +NPCM8XX_GCR_B2CPNT , +NPCM8XX_GCR_CPPCTL , +NPCM8XX_GCR_I2CSEGSEL =0x0e0 /sizeof (uint32_t ), +NPCM8XX_GCR_I2CSEGCTL , +NPCM8XX_GCR_VSRCR , +NPCM8XX_GCR_MLOCKR , +NPCM8XX_GCR_SCRPAD =0x13c /sizeof (uint32_t ), +NPCM8XX_GCR_USB1PHYCTL , +NPCM8XX_GCR_USB2PHYCTL , +NPCM8XX_GCR_USB3PHYCTL , +NPCM8XX_GCR_MFSEL1 =0x260 /sizeof (uint32_t ), +NPCM8XX_GCR_MFSEL2 , +NPCM8XX_GCR_MFSEL3 , +NPCM8XX_GCR_MFSEL4 , +NPCM8XX_GCR_MFSEL5 , +NPCM8XX_GCR_MFSEL6 , +NPCM8XX_GCR_MFSEL7 , +NPCM8XX_GCR_MFSEL_LK1 =0x280 /sizeof (uint32_t ), +NPCM8XX_GCR_MFSEL_LK2 , +NPCM8XX_GCR_MFSEL_LK3 , +NPCM8XX_GCR_MFSEL_LK4 , +NPCM8XX_GCR_MFSEL_LK5 , +NPCM8XX_GCR_MFSEL_LK6 , +NPCM8XX_GCR_MFSEL_LK7 , +NPCM8XX_GCR_MFSEL_SET1 =0x2a0 /sizeof (uint32_t ), +NPCM8XX_GCR_MFSEL_SET2 , +NPCM8XX_GCR_MFSEL_SET3 , +NPCM8XX_GCR_MFSEL_SET4 , +NPCM8XX_GCR_MFSEL_SET5 , +NPCM8XX_GCR_MFSEL_SET6 , +NPCM8XX_GCR_MFSEL_SET7 , +NPCM8XX_GCR_MFSEL_CLR1 =0x2c0 /sizeof (uint32_t ), +NPCM8XX_GCR_MFSEL_CLR2 , +NPCM8XX_GCR_MFSEL_CLR3 , +NPCM8XX_GCR_MFSEL_CLR4 , +NPCM8XX_GCR_MFSEL_CLR5 , +NPCM8XX_GCR_MFSEL_CLR6 , +NPCM8XX_GCR_MFSEL_CLR7 , +NPCM8XX_GCR_WD0RCRLK =0x400 /sizeof (uint32_t ), +NPCM8XX_GCR_WD1RCRLK , +NPCM8XX_GCR_WD2RCRLK , +NPCM8XX_GCR_SWRSTC1LK , +NPCM8XX_GCR_SWRSTC2LK , +NPCM8XX_GCR_SWRSTC3LK , +NPCM8XX_GCR_TIPRSTCLK , +NPCM8XX_GCR_CORSTCLK , +NPCM8XX_GCR_WD0RCRBLK , +NPCM8XX_GCR_WD1RCRBLK , +NPCM8XX_GCR_WD2RCRBLK , +NPCM8XX_GCR_SWRSTC1BLK , +NPCM8XX_GCR_SWRSTC2BLK , +NPCM8XX_GCR_SWRSTC3BLK , +NPCM8XX_GCR_TIPRSTCBLK , +NPCM8XX_GCR_CORSTCBLK , +/* 64 scratch pad registers start here. 0xe00 ~ 0xefc */ +NPCM8XX_GCR_SCRPAD_00 =0xe00 /sizeof (uint32_t ), +/* 32 semaphore registers start here. 0xf00 ~ 0xf7c */ +NPCM8XX_GCR_GP_SEMFR_00 =0xf00 /sizeof (uint32_t ), +NPCM8XX_GCR_REGS_END =0xf80 /sizeof (uint32_t ), +}; + +static const uint32_t npcm8xx_cold_reset_values[NPCM8XX_GCR_NR_REGS ] = { + [NPCM8XX_GCR_PDID ] =0x04a35850 ,/* Arbel A1 */ + [NPCM8XX_GCR_MISCPE ] =0x0000ffff , + [NPCM8XX_GCR_A35_MODE ] =0xfff4ff30 , + [NPCM8XX_GCR_SPSWC ] =0x00000003 , + [NPCM8XX_GCR_INTCR ] =0x0010035e , + [NPCM8XX_GCR_HIFCR ] =0x0000004e , + [NPCM8XX_GCR_SD2SUR1 ] =0xfdc80000 , + [NPCM8XX_GCR_SD2SUR2 ] =0x5200b130 , + [NPCM8XX_GCR_INTCR2 ] = (1U <<19 ),/* DDR initialized */ + [NPCM8XX_GCR_RESSR ] =0x80000000 , + [NPCM8XX_GCR_DAVCLVLR ] =0x5a00f3cf , + [NPCM8XX_GCR_INTCR3 ] =0x5e001002 , + [NPCM8XX_GCR_VSRCR ] =0x00004800 , + [NPCM8XX_GCR_SCRPAD ] =0x00000008 , + [NPCM8XX_GCR_USB1PHYCTL ] =0x034730e4 , + [NPCM8XX_GCR_USB2PHYCTL ] =0x034730e4 , + [NPCM8XX_GCR_USB3PHYCTL ] =0x034730e4 , +/* All 32 semaphores should be initialized to 1. */ + [NPCM8XX_GCR_GP_SEMFR_00 ...NPCM8XX_GCR_REGS_END -1 ] =0x00000001 , +}; +static uint64_t npcm_gcr_read (void *opaque,hwaddr offset,unsigned size) {uint32_t reg = offset /sizeof (uint32_t );
@@ -261,6 +373,18 @@ static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data) c->cold_reset_values = npcm7xx_cold_reset_values; } +static void npcm8xx_gcr_class_init (ObjectClass *klass,void *data) +{ +NPCMGCRClass *c =NPCM_GCR_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM8XX_GCR_REGS_END >NPCM_GCR_MAX_NR_REGS ); +QEMU_BUILD_BUG_ON (NPCM8XX_GCR_REGS_END !=NPCM8XX_GCR_NR_REGS ); + dc->desc ="NPCM8xx System Global Control Registers" ; + c->nr_regs =NPCM8XX_GCR_NR_REGS ; + c->cold_reset_values = npcm8xx_cold_reset_values; +} +static const TypeInfo npcm_gcr_info[] = { { .name =TYPE_NPCM_GCR ,
@@ -276,5 +400,10 @@ static const TypeInfo npcm_gcr_info[] = { .parent = TYPE_NPCM_GCR, .class_init = npcm7xx_gcr_class_init, }, + { + .name = TYPE_NPCM8XX_GCR, + .parent = TYPE_NPCM_GCR, + .class_init = npcm8xx_gcr_class_init, + }, };DEFINE_TYPES (npcm_gcr_info)
include/hw/misc/npcm_gcr.h +4 -2
@@ -1,5 +1,5 @@/* -* Nuvoton NPCM7xx System Global Control Registers. +* Nuvoton NPCM7xx/8xx System Global Control Registers. * * Copyright 2020 Google LLC *
@@ -54,8 +54,9 @@* Number of registers in our device state structure. Don't change this without * incrementing the version_id in the vmstate. */ -#define NPCM_GCR_MAX_NR_REGS NPCM7XX_GCR_NR_REGS +#define NPCM_GCR_MAX_NR_REGS NPCM8XX_GCR_NR_REGS#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t)) +#define NPCM8XX_GCR_NR_REGS (0xf80 / sizeof(uint32_t)) typedef struct NPCMGCRState { SysBusDevice parent;
@@ -78,6 +79,7 @@ typedef struct NPCMGCRClass {#define TYPE_NPCM_GCR "npcm-gcr"#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" +#define TYPE_NPCM8XX_GCR "npcm8xx-gcr" OBJECT_DECLARE_TYPE(NPCMGCRState, NPCMGCRClass, NPCM_GCR)#endif /* NPCM_GCR_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 08/17] hw/misc: Add support for NPCM8XX GCR
Quoted 7 lines · Hao Wu
Signed-off-by Hao Wu <[email protected]>--- hw/misc/npcm_gcr.c | 131 ++++++++++++++++++++++++++++++++++++- include/hw/misc/npcm_gcr.h | 6 +- 2 files changed, 134 insertions(+), 3 deletions(-)
thanks
-- PMM
PATCH v2 9/17 hw/misc: Store DRAM size in NPCM8XX GCR Module
In reply to Hao WuNPCM8XX boot block stores the DRAM size in SCRPAD_B register in GCR module. Since we don't simulate a detailed memory controller, we need to store this information directly similar to the NPCM7XX's INCTR3 register.
--- hw/misc/npcm_gcr.c | 24 ++++++++++++++++++++++++ include/hw/misc/npcm_gcr.h | 1 + 2 files changed, 25 insertions(+)
hw/misc/npcm_gcr.c +24 -0
@@ -279,6 +279,19 @@ static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type) s->regs[NPCM7XX_GCR_INTCR3 ] = s->reset_intcr3; } +static void npcm8xx_gcr_enter_reset (Object *obj,ResetType type) +{ +NPCMGCRState *s =NPCM_GCR (obj); +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (obj); + +memcpy (s->regs, c->cold_reset_values, c->nr_regs *sizeof (uint32_t )); +/* These 3 registers are at the same location in both 7xx and 8xx. */ + s->regs[NPCM8XX_GCR_PWRON ] = s->reset_pwron; + s->regs[NPCM8XX_GCR_MDLR ] = s->reset_mdlr; + s->regs[NPCM8XX_GCR_INTCR3 ] = s->reset_intcr3; + s->regs[NPCM8XX_GCR_SCRPAD_B ] = s->reset_scrpad_b; +} +static void npcm_gcr_realize (DeviceState *dev,Error **errp) {ERRP_GUARD ();
@@ -322,6 +335,14 @@ static void npcm_gcr_realize(DeviceState *dev, Error **errp)* https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408dbaad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244 */ s->reset_intcr3 |=ctz64 (dram_size /NPCM7XX_GCR_MIN_DRAM_SIZE ) <<8 ; + +/* +* The boot block starting from 0.0.6 for NPCM8xx SoCs stores the DRAM size +* in the SCRPAD2 registers. We need to set this field correctly since +* the initialization is skipped as we mentioned above. +* https://github.com/Nuvoton-Israel/u-boot/blob/npcm8mnx-v2019.01_tmp/board/nuvoton/arbel/arbel.c#L737 +*/ + s->reset_scrpad_b = dram_size; }static void npcm_gcr_init (Object *obj)
@@ -371,18 +392,21 @@ static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data) c->nr_regs =NPCM7XX_GCR_NR_REGS ; c->cold_reset_values = npcm7xx_cold_reset_values; + rc->phases.enter = npcm7xx_gcr_enter_reset; }static void npcm8xx_gcr_class_init (ObjectClass *klass,void *data) {NPCMGCRClass *c =NPCM_GCR_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass);QEMU_BUILD_BUG_ON (NPCM8XX_GCR_REGS_END >NPCM_GCR_MAX_NR_REGS );QEMU_BUILD_BUG_ON (NPCM8XX_GCR_REGS_END !=NPCM8XX_GCR_NR_REGS ); dc->desc ="NPCM8xx System Global Control Registers" ; c->nr_regs =NPCM8XX_GCR_NR_REGS ; c->cold_reset_values = npcm8xx_cold_reset_values; + rc->phases.enter = npcm8xx_gcr_enter_reset; }static const TypeInfo npcm_gcr_info[] = {
include/hw/misc/npcm_gcr.h +1 -0
@@ -68,6 +68,7 @@ typedef struct NPCMGCRState {uint32_t reset_pwron;uint32_t reset_mdlr;uint32_t reset_intcr3; +uint32_t reset_scrpad_b; } NPCMGCRState; typedef struct NPCMGCRClass {
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 09/17] hw/misc: Store DRAM size in NPCM8XX GCR Module
Quoted 11 lines · Hao Wu
NPCM8XX boot block stores the DRAM size in
SCRPAD_Bregister in GCR module. Since we don't simulate a detailed memory controller, we need to store this information directly similar to the NPCM7XX's INCTR3 register.Signed-off-by Hao Wu <[email protected]>--- hw/misc/npcm_gcr.c | 24 ++++++++++++++++++++++++ include/hw/misc/npcm_gcr.h | 1 + 2 files changed, 25 insertions(+)
thanks
-- PMM
PATCH v2 10/17 hw/misc: Support 8-bytes memop in NPCM GCR module
In reply to Hao WuThe NPCM8xx GCR device can be accessed with 64-bit memory operations. This patch supports that.
--- hw/misc/npcm_gcr.c | 94 +++++++++++++++++++++++++++++++++----------- hw/misc/trace-events | 4 +- 2 files changed, 74 insertions(+), 24 deletions(-)
hw/misc/npcm_gcr.c +72 -22
@@ -201,6 +201,7 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)uint32_t reg = offset /sizeof (uint32_t );NPCMGCRState *s = opaque;NPCMGCRClass *c =NPCM_GCR_GET_CLASS (s); +uint64_t value;if (reg >= c->nr_regs) { qemu_log_mask(LOG_GUEST_ERROR,
@@ -209,9 +210,21 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)return 0 ; } -trace_npcm_gcr_read (offset, s->regs[reg]); +switch (size) { +case 4 : + value = s->regs[reg]; +break ; + +case 8 : + value = s->regs[reg] + (((uint64_t )s->regs[reg +1 ]) <<32 ); +break ; + +default : +g_assert_not_reached (); + } -return s->regs[reg]; +trace_npcm_gcr_read (offset, value); +return value; } static void npcm_gcr_write(void *opaque, hwaddr offset,
@@ -231,29 +244,65 @@ static void npcm_gcr_write(void *opaque, hwaddr offset,return ; } -switch (reg) { -case NPCM7XX_GCR_PDID : -case NPCM7XX_GCR_PWRON : -case NPCM7XX_GCR_INTSR : -qemu_log_mask (LOG_GUEST_ERROR , -"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , - __func__, offset); -return ; - -case NPCM7XX_GCR_RESSR : -case NPCM7XX_GCR_CP2BST : -/* Write 1 to clear */ - value = s->regs[reg] & ~value; +switch (size) { +case 4 : +switch (reg) { +case NPCM7XX_GCR_PDID : +case NPCM7XX_GCR_PWRON : +case NPCM7XX_GCR_INTSR : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , + __func__, offset); +return ; + +case NPCM7XX_GCR_RESSR : +case NPCM7XX_GCR_CP2BST : +/* Write 1 to clear */ + value = s->regs[reg] & ~value; +break ; + +case NPCM7XX_GCR_RLOCKR1 : +case NPCM7XX_GCR_MDLR : +/* Write 1 to set */ + value |= s->regs[reg]; +break ; + }; + s->regs[reg] = value;break ; -case NPCM7XX_GCR_RLOCKR1 : -case NPCM7XX_GCR_MDLR : -/* Write 1 to set */ - value |= s->regs[reg]; +case 8 : + s->regs[reg] = value; + s->regs[reg +1 ] = v >>32 ;break ; - }; - s->regs[reg] = value; +default : +g_assert_not_reached (); + } +} + +static bool npcm_gcr_check_mem_op (void *opaque,hwaddr offset, +unsigned size,bool is_write, +MemTxAttrs attrs) +{ +NPCMGCRClass *c =NPCM_GCR_GET_CLASS (opaque); + +if (offset >= c->nr_regs *sizeof (uint32_t )) { +return false; + } + +switch (size) { +case 4 : +return true; +case 8 : +if (offset >=NPCM8XX_GCR_SCRPAD_00 *sizeof (uint32_t ) && + offset < (NPCM8XX_GCR_NR_REGS -1 ) *sizeof (uint32_t )) { +return true; + }else { +return false; + } +default : +return false; + } }static const struct MemoryRegionOps npcm_gcr_ops = {
@@ -262,7 +311,8 @@ static const struct MemoryRegionOps npcm_gcr_ops = { .endianness = DEVICE_LITTLE_ENDIAN, .valid = { .min_access_size = 4, - .max_access_size = 4, + .max_access_size = 8, + .accepts = npcm_gcr_check_mem_op, .unaligned = false, }, };
hw/misc/trace-events +2 -2
@@ -135,8 +135,8 @@ npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " valu npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 # npcm_gcr.c -npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 -npcm_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm_gcr_read(uint64_t offset, uint64_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx64 +npcm_gcr_write(uint64_t offset, uint64_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx64 # npcm7xx_mft.c npcm7xx_mft_read(const char *name, uint64_t offset, uint16_t value) "%s: offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 10/17] hw/misc: Support 8-bytes memop in NPCM GCR module
Quoted 24 lines · Hao Wu
The NPCM8xx GCR device can be accessed with 64-bit memory operations. This patch supports that.
Signed-off-by Hao Wu <[email protected]>--- hw/misc/npcm_gcr.c | 94 +++++++++++++++++++++++++++++++++----------- hw/misc/trace-events | 4 +- 2 files changed, 74 insertions(+), 24 deletions(-)hw/misc/npcm_gcr.c +1
-0@@ -201,6 +201,7 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)uint32_t reg = offset /sizeof (uint32_t );NPCMGCRState *s = opaque;NPCMGCRClass *c =NPCM_GCR_GET_CLASS (s); +uint64_t value;if (reg >= c->nr_regs) { qemu_log_mask(LOG_GUEST_ERROR,@@ -209,9 +210,21 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)return 0 ;
hw/misc/npcm_gcr.c static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size) · line 219
Quoted 10 lines
hw/misc/npcm_gcr.c +7
-1} -trace_npcm_gcr_read (offset, s->regs[reg]); +switch (size) { +case 4 : + value = s->regs[reg]; +break ; + +case 8 : + value = s->regs[reg] + (((uint64_t )s->regs[reg +1 ]) <<32 );
Maybe
value = deposit64(s->regs[reg], 32, 32, s->regs[reg + 1]);
?
(Mostly it's just the cast that makes me suggest a rephrase.)
Quoted 52 lines
hw/misc/npcm_gcr.c +30
-14+break ; + +default : +g_assert_not_reached (); + } -return s->regs[reg]; +trace_npcm_gcr_read (offset, value); +return value; } static void npcm_gcr_write(void *opaque, hwaddr offset,@@ -231,29 +244,65 @@ static void npcm_gcr_write(void *opaque, hwaddr offset,return ; } -switch (reg) { -case NPCM7XX_GCR_PDID : -case NPCM7XX_GCR_PWRON : -case NPCM7XX_GCR_INTSR : -qemu_log_mask (LOG_GUEST_ERROR , -"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , - __func__, offset); -return ; - -case NPCM7XX_GCR_RESSR : -case NPCM7XX_GCR_CP2BST : -/* Write 1 to clear */ - value = s->regs[reg] & ~value; +switch (size) { +case 4 : +switch (reg) { +case NPCM7XX_GCR_PDID : +case NPCM7XX_GCR_PWRON : +case NPCM7XX_GCR_INTSR : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , + __func__, offset); +return ; + +case NPCM7XX_GCR_RESSR : +case NPCM7XX_GCR_CP2BST : +/* Write 1 to clear */ + value = s->regs[reg] & ~value; +break ; + +case NPCM7XX_GCR_RLOCKR1 : +case NPCM7XX_GCR_MDLR : +/* Write 1 to set */ + value |= s->regs[reg]; +break ; + };
hw/misc/npcm_gcr.c static void npcm_gcr_write(void *opaque, hwaddr offset, · line 275
Quoted 10 lines
hw/misc/npcm_gcr.c +4
-4+ s->regs[reg] = value;break ; -case NPCM7XX_GCR_RLOCKR1 : -case NPCM7XX_GCR_MDLR : -/* Write 1 to set */ - value |= s->regs[reg]; +case 8 : + s->regs[reg] = value; + s->regs[reg +1 ] = v >>32 ;
s->regs[reg + 1] = extract64(v, 32, 32);
hw/misc/npcm_gcr.c static void npcm_gcr_write(void *opaque, hwaddr offset, · line 281
Quoted 8 lines
hw/misc/npcm_gcr.c +4
-2break ; - }; - s->regs[reg] = value; +default : +g_assert_not_reached (); + } +}
Otherwise
thanks
-- PMM
PATCH v2 11/17 hw/misc: Rename npcm7xx_clk to npcm_clk
In reply to Hao WuNPCM7XX and NPCM8XX have a different set of CLK registers. This commit changes the name of the clk files to be used by both NPCM7XX and NPCM8XX CLK modules.
---
hw/misc/meson.build | 2 +-
hw/misc/{npcm7xx_clk.c => npcm_clk.c} | 2 +-
include/hw/arm/npcm7xx.h | 2 +-
include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
rename hw/misc/{npcm7xx_clk.c => npcm_clk.c} (99%)
rename include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} (98%)hw/misc/meson.build +1 -1
@@ -67,7 +67,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( 'imx_rngc.c', )) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( - 'npcm7xx_clk.c', + 'npcm_clk.c', 'npcm_gcr.c', 'npcm7xx_mft.c', 'npcm7xx_pwm.c',
hw/misc/npcm_clk.c renamed from hw/misc/npcm7xx_clk.c +1 -1
@@ -16,7 +16,7 @@#include "qemu/osdep.h" -#include "hw/misc/npcm7xx_clk.h" +#include "hw/misc/npcm_clk.h" #include "hw/timer/npcm7xx_timer.h" #include "hw/qdev-clock.h" #include "migration/vmstate.h"
include/hw/arm/npcm7xx.h +1 -1
@@ -23,7 +23,7 @@#include "hw/gpio/npcm7xx_gpio.h" #include "hw/i2c/npcm7xx_smbus.h" #include "hw/mem/npcm7xx_mc.h" -#include "hw/misc/npcm7xx_clk.h" +#include "hw/misc/npcm_clk.h" #include "hw/misc/npcm_gcr.h" #include "hw/misc/npcm7xx_mft.h" #include "hw/misc/npcm7xx_pwm.h"
include/hw/misc/npcm_clk.h renamed from include/hw/misc/npcm7xx_clk.h +3 -3
@@ -13,8 +13,8 @@* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ -#ifndef NPCM7XX_CLK_H -#define NPCM7XX_CLK_H +#ifndef NPCM_CLK_H +#define NPCM_CLK_H #include "exec/memory.h" #include "hw/clock.h"
@@ -177,4 +177,4 @@ struct NPCM7xxCLKState {#define TYPE_NPCM7XX_CLK "npcm7xx-clk" OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxCLKState, NPCM7XX_CLK) -#endif /* NPCM7XX_CLK_H */ +#endif /* NPCM_CLK_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 11/17] hw/misc: Rename npcm7xx_clk to npcm_clk
Quoted 7 lines · Hao Wu
NPCM7XX and NPCM8XX have a different set of CLK registers. This commit changes the name of the clk files to be used by both NPCM7XX and NPCM8XX CLK modules.
Signed-off-by Hao Wu <[email protected]>---
thanks
-- PMM
PATCH v2 12/17 hw/misc: Move NPCM7XX CLK to NPCM CLK
In reply to Hao WuA lot of NPCM7XX and NPCM8XX CLK modules share the same code, this commit moves the NPCM7XX CLK to NPCM CLK for these properties.
--- hw/misc/npcm_clk.c | 106 +++++++++++++++++++++---------------- hw/misc/trace-events | 6 +-- include/hw/arm/npcm7xx.h | 2 +- include/hw/misc/npcm_clk.h | 22 ++++---- 4 files changed, 76 insertions(+), 60 deletions(-)
hw/misc/npcm_clk.c +60 -46
@@ -198,7 +198,7 @@ static NPCM7xxClockPLL find_pll_by_reg(enum NPCM7xxCLKRegisters reg) } } -static void npcm7xx_clk_update_all_plls (NPCM7xxCLKState *clk) +static void npcm7xx_clk_update_all_plls (NPCMCLKState *clk) {int i;
@@ -207,7 +207,7 @@ static void npcm7xx_clk_update_all_plls(NPCM7xxCLKState *clk) } } -static void npcm7xx_clk_update_all_sels (NPCM7xxCLKState *clk) +static void npcm7xx_clk_update_all_sels (NPCMCLKState *clk) {int i;
@@ -216,7 +216,7 @@ static void npcm7xx_clk_update_all_sels(NPCM7xxCLKState *clk) } } -static void npcm7xx_clk_update_all_dividers (NPCM7xxCLKState *clk) +static void npcm7xx_clk_update_all_dividers (NPCMCLKState *clk) {int i;
@@ -225,7 +225,7 @@ static void npcm7xx_clk_update_all_dividers(NPCM7xxCLKState *clk) } } -static void npcm7xx_clk_update_all_clocks (NPCM7xxCLKState *clk) +static void npcm7xx_clk_update_all_clocks (NPCMCLKState *clk) {clock_update_hz (clk->clkref,NPCM7XX_CLOCK_REF_HZ );npcm7xx_clk_update_all_plls (clk);
@@ -635,7 +635,7 @@ static void npcm7xx_clk_divider_init(Object *obj) }static void npcm7xx_init_clock_pll (NPCM7xxClockPLLState *pll, -NPCM7xxCLKState *clk,const PLLInitInfo *init_info) +NPCMCLKState *clk,const PLLInitInfo *init_info) { pll->name = init_info->name; pll->clk = clk;
@@ -647,7 +647,7 @@ static void npcm7xx_init_clock_pll(NPCM7xxClockPLLState *pll, }static void npcm7xx_init_clock_sel (NPCM7xxClockSELState *sel, -NPCM7xxCLKState *clk,const SELInitInfo *init_info) +NPCMCLKState *clk,const SELInitInfo *init_info) {int input_size = init_info->input_size;
@@ -664,7 +664,7 @@ static void npcm7xx_init_clock_sel(NPCM7xxClockSELState *sel, }static void npcm7xx_init_clock_divider (NPCM7xxClockDividerState *div, -NPCM7xxCLKState *clk,const DividerInitInfo *init_info) +NPCMCLKState *clk,const DividerInitInfo *init_info) { div->name = init_info->name; div->clk = clk;
@@ -683,7 +683,7 @@ static void npcm7xx_init_clock_divider(NPCM7xxClockDividerState *div, } } -static Clock *npcm7xx_get_clock (NPCM7xxCLKState *clk,ClockSrcType type, +static Clock *npcm7xx_get_clock (NPCMCLKState *clk,ClockSrcType type,int index) {switch (type) {
@@ -700,7 +700,7 @@ static Clock *npcm7xx_get_clock(NPCM7xxCLKState *clk, ClockSrcType type, } } -static void npcm7xx_connect_clocks (NPCM7xxCLKState *clk) +static void npcm7xx_connect_clocks (NPCMCLKState *clk) {int i, j;Clock *src;
@@ -724,10 +724,10 @@ static void npcm7xx_connect_clocks(NPCM7xxCLKState *clk) } } -static uint64_t npcm7xx_clk_read (void *opaque,hwaddr offset,unsigned size) +static uint64_t npcm_clk_read (void *opaque,hwaddr offset,unsigned size) {uint32_t reg = offset /sizeof (uint32_t ); -NPCM7xxCLKState *s = opaque; +NPCMCLKState *s = opaque;int64_t now_ns;uint32_t value =0 ;
@@ -766,19 +766,19 @@ static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)break ; }; -trace_npcm7xx_clk_read (offset, value); +trace_npcm_clk_read (offset, value);return value; } -static void npcm7xx_clk_write (void *opaque,hwaddr offset, +static void npcm_clk_write (void *opaque,hwaddr offset,uint64_t v,unsigned size) {uint32_t reg = offset /sizeof (uint32_t ); -NPCM7xxCLKState *s = opaque; +NPCMCLKState *s = opaque;uint32_t value = v; -trace_npcm7xx_clk_write (offset, value); +trace_npcm_clk_write (offset, value);if (reg >=NPCM7XX_CLK_NR_REGS ) { qemu_log_mask(LOG_GUEST_ERROR,
@@ -842,7 +842,7 @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset,static void npcm7xx_clk_perform_watchdog_reset (void *opaque,int n,int level) { -NPCM7xxCLKState *clk =NPCM7XX_CLK (opaque); +NPCMCLKState *clk =NPCM_CLK (opaque);uint32_t rcr;g_assert (n >=0 && n <=NPCM7XX_NR_WATCHDOGS );
@@ -856,9 +856,9 @@ static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n, } } -static const struct MemoryRegionOps npcm7xx_clk_ops = { - .read = npcm7xx_clk_read, - .write = npcm7xx_clk_write, +static const struct MemoryRegionOps npcm_clk_ops = { + .read = npcm_clk_read, + .write = npcm_clk_write, .endianness =DEVICE_LITTLE_ENDIAN , .valid = { .min_access_size =4 ,
@@ -867,9 +867,9 @@ static const struct MemoryRegionOps npcm7xx_clk_ops = { }, }; -static void npcm7xx_clk_enter_reset (Object *obj,ResetType type) +static void npcm_clk_enter_reset (Object *obj,ResetType type) { -NPCM7xxCLKState *s =NPCM7XX_CLK (obj); +NPCMCLKState *s =NPCM_CLK (obj);QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values));
@@ -882,7 +882,7 @@ static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)*/ } -static void npcm7xx_clk_init_clock_hierarchy (NPCM7xxCLKState *s) +static void npcm7xx_clk_init_clock_hierarchy (NPCMCLKState *s) {int i;
@@ -918,19 +918,19 @@ static void npcm7xx_clk_init_clock_hierarchy(NPCM7xxCLKState *s)clock_update_hz (s->clkref,NPCM7XX_CLOCK_REF_HZ ); } -static void npcm7xx_clk_init (Object *obj) +static void npcm_clk_init (Object *obj) { -NPCM7xxCLKState *s =NPCM7XX_CLK (obj); +NPCMCLKState *s =NPCM_CLK (obj); -memory_region_init_io (&s->iomem, obj, &npcm7xx_clk_ops, s, -TYPE_NPCM7XX_CLK ,4 * KiB); +memory_region_init_io (&s->iomem, obj, &npcm_clk_ops, s, +TYPE_NPCM_CLK ,4 * KiB);sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); } -static int npcm7xx_clk_post_load (void *opaque,int version_id) +static int npcm_clk_post_load (void *opaque,int version_id) {if (version_id >=1 ) { -NPCM7xxCLKState *clk = opaque; +NPCMCLKState *clk = opaque;npcm7xx_clk_update_all_clocks (clk); }
@@ -938,10 +938,10 @@ static int npcm7xx_clk_post_load(void *opaque, int version_id)return 0 ; } -static void npcm7xx_clk_realize (DeviceState *dev,Error **errp) +static void npcm_clk_realize (DeviceState *dev,Error **errp) {int i; -NPCM7xxCLKState *s =NPCM7XX_CLK (dev); +NPCMCLKState *s =NPCM_CLK (dev);qdev_init_gpio_in_named (DEVICE (s), npcm7xx_clk_perform_watchdog_reset,NPCM7XX_WATCHDOG_RESET_GPIO_IN ,NPCM7XX_NR_WATCHDOGS );
@@ -996,15 +996,15 @@ static const VMStateDescription vmstate_npcm7xx_clk_divider = { }, }; -static const VMStateDescription vmstate_npcm7xx_clk = { - .name ="npcm7xx-clk" , - .version_id =1 , - .minimum_version_id =1 , - .post_load = npcm7xx_clk_post_load, +static const VMStateDescription vmstate_npcm_clk = { + .name ="npcm-clk" , + .version_id =2 , + .minimum_version_id =2 , + .post_load = npcm_clk_post_load, .fields = (const VMStateField []) { -VMSTATE_UINT32_ARRAY (regs, NPCM7xxCLKState,NPCM7XX_CLK_NR_REGS ), -VMSTATE_INT64 (ref_ns, NPCM7xxCLKState), -VMSTATE_CLOCK (clkref, NPCM7xxCLKState), +VMSTATE_UINT32_ARRAY (regs, NPCMCLKState,NPCM_CLK_MAX_NR_REGS ), +VMSTATE_INT64 (ref_ns, NPCMCLKState), +VMSTATE_CLOCK (clkref, NPCMCLKState),VMSTATE_END_OF_LIST (), }, };
@@ -1033,17 +1033,23 @@ static void npcm7xx_clk_divider_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_npcm7xx_clk_divider; } -static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +static void npcm_clk_class_init (ObjectClass *klass,void *data) {ResettableClass *rc =RESETTABLE_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); -QEMU_BUILD_BUG_ON (NPCM7XX_CLK_REGS_END >NPCM7XX_CLK_NR_REGS ); + dc->vmsd = &vmstate_npcm_clk; + dc->realize = npcm_clk_realize; + rc->phases.enter = npcm_clk_enter_reset; +} + +static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +{ +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" ; - dc->vmsd = &vmstate_npcm7xx_clk; - dc->realize = npcm7xx_clk_realize; - rc->phases.enter = npcm7xx_clk_enter_reset; }static const TypeInfo npcm7xx_clk_pll_info = {
@@ -1070,11 +1076,18 @@ static const TypeInfo npcm7xx_clk_divider_info = { .class_init = npcm7xx_clk_divider_class_init, }; +static const TypeInfo npcm_clk_info = { + .name =TYPE_NPCM_CLK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCMCLKState), + .instance_init = npcm_clk_init, + .class_init = npcm_clk_class_init, + .abstract = true, +}; +static const TypeInfo npcm7xx_clk_info = { .name =TYPE_NPCM7XX_CLK , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (NPCM7xxCLKState), - .instance_init = npcm7xx_clk_init, + .parent =TYPE_NPCM_CLK , .class_init = npcm7xx_clk_class_init, };
@@ -1083,6 +1096,7 @@ static void npcm7xx_clk_register_type(void)type_register_static (&npcm7xx_clk_pll_info);type_register_static (&npcm7xx_clk_sel_info);type_register_static (&npcm7xx_clk_divider_info); +type_register_static (&npcm_clk_info);type_register_static (&npcm7xx_clk_info); }type_init (npcm7xx_clk_register_type);
hw/misc/trace-events +3 -3
@@ -130,9 +130,9 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, const char *name, uint64_t val) "reg=0x%"PRIx64 " [%s] val=0x%"PRIx64 mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [%s] val=0x%x" -# npcm7xx_clk.c -npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 -npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +# npcm_clk.c +npcm_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 # npcm_gcr.c npcm_gcr_read(uint64_t offset, uint64_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx64
include/hw/arm/npcm7xx.h +1 -1
@@ -90,7 +90,7 @@ struct NPCM7xxState {MemoryRegion *dram;NPCMGCRState gcr; -NPCM7xxCLKState clk; +NPCMCLKState clk;NPCM7xxTimerCtrlState tim[3 ];NPCM7xxADCState adc;NPCM7xxPWMState pwm[NPCM7XX_NR_PWM_MODULES ];
include/hw/misc/npcm_clk.h +12 -10
@@ -20,11 +20,12 @@#include "hw/clock.h" #include "hw/sysbus.h" +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))/* -* Number of registers in our device state structure. Don't change this without -* incrementing the version_id in the vmstate. +* Number of maximum registers in NPCM device state structure. Don't change +* this without incrementing the version_id in the vmstate. */ -#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) +#define NPCM_CLK_MAX_NR_REGS NPCM7XX_CLK_NR_REGS#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
@@ -80,7 +81,7 @@ typedef enum NPCM7xxClockDivider {NPCM7XX_CLOCK_NR_DIVIDERS , } NPCM7xxClockConverter; -typedef struct NPCM7xxCLKState NPCM7xxCLKState ; +typedef struct NPCMCLKState NPCMCLKState ;/** * struct NPCM7xxClockPLLState - A PLL module in CLK module.
@@ -94,7 +95,7 @@ typedef struct NPCM7xxClockPLLState {DeviceState parent;const char *name; -NPCM7xxCLKState *clk; +NPCMCLKState *clk;Clock *clock_in;Clock *clock_out;
@@ -115,7 +116,7 @@ typedef struct NPCM7xxClockSELState {DeviceState parent;const char *name; -NPCM7xxCLKState *clk; +NPCMCLKState *clk;uint8_t input_size;Clock *clock_in[NPCM7XX_CLK_SEL_MAX_INPUT ];Clock *clock_out;
@@ -140,7 +141,7 @@ typedef struct NPCM7xxClockDividerState {DeviceState parent;const char *name; -NPCM7xxCLKState *clk; +NPCMCLKState *clk;Clock *clock_in;Clock *clock_out;
@@ -155,7 +156,7 @@ typedef struct NPCM7xxClockDividerState { }; } NPCM7xxClockDividerState; -struct NPCM7xxCLKState { +struct NPCMCLKState {SysBusDevice parent;MemoryRegion iomem;
@@ -165,7 +166,7 @@ struct NPCM7xxCLKState {NPCM7xxClockSELState sels[NPCM7XX_CLOCK_NR_SELS ];NPCM7xxClockDividerState dividers[NPCM7XX_CLOCK_NR_DIVIDERS ]; -uint32_t regs[NPCM7XX_CLK_NR_REGS ]; +uint32_t regs[NPCM_CLK_MAX_NR_REGS ];/* Time reference for SECCNT and CNTR25M, initialized by power on reset */ int64_t ref_ns;
@@ -174,7 +175,8 @@ struct NPCM7xxCLKState {Clock *clkref; }; +#define TYPE_NPCM_CLK "npcm-clk" +OBJECT_DECLARE_SIMPLE_TYPE(NPCMCLKState, NPCM_CLK)#define TYPE_NPCM7XX_CLK "npcm7xx-clk" -OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxCLKState, NPCM7XX_CLK)#endif /* NPCM_CLK_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 12/17] hw/misc: Move NPCM7XX CLK to NPCM CLK
Quoted 4 lines · Hao Wu
A lot of NPCM7XX and NPCM8XX CLK modules share the same code, this commit moves the NPCM7XX CLK to NPCM CLK for these properties.
thanks
-- PMM
PATCH v2 13/17 hw/misc: Add nr_regs and cold_reset_values to NPCM CLK
In reply to Hao WuThese 2 values are different between NPCM7XX and NPCM8XX CLKs. So we add them to the class and assign different values to them.
--- hw/misc/npcm_clk.c | 17 +++++++++++------ include/hw/misc/npcm_clk.h | 9 ++++++++- 2 files changed, 19 insertions(+), 7 deletions(-)
hw/misc/npcm_clk.c +11 -6
@@ -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,9 @@ 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)); +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 +1046,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 +1085,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, };
include/hw/misc/npcm_clk.h +8 -1
@@ -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 */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 13/17] hw/misc: Add nr_regs and cold_reset_values to NPCM CLK
Quoted 15 lines · Hao Wu
These 2 values are different between NPCM7XX and NPCM8XX CLKs. So we add them to the class and assign different values to them.
Signed-off-by Hao Wu <[email protected]>--- hw/misc/npcm_clk.c | 17 +++++++++++------ include/hw/misc/npcm_clk.h | 9 ++++++++- 2 files changed, 19 insertions(+), 7 deletions(-)
hw/misc/npcm_clk.c static const struct MemoryRegionOps npcm_clk_ops = { · line 877
Quoted 9 lines
hw/misc/npcm_clk.c +2
-3@@ -870,10 +872,9 @@ 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)); +memcpy (s->regs, c->cold_reset_values,sizeof (s->regs));
Same remark about an assert as in the other patch. Otherwise
thanks
-- PMM
PATCH v2 14/17 hw/misc: Support NPCM8XX CLK Module Registers
In reply to Hao WuNPCM8XX adds a few new registers and have a different set of reset values to the CLK modules. This patch supports them.
This patch doesn't support the new clock values generated by these registers. Currently no modules use these new clock values so they are not necessary at this point.
Implementation of these clocks might be required when implementing these modules.
--- hw/misc/npcm_clk.c | 113 ++++++++++++++++++++++++++++++++++++- include/hw/misc/npcm_clk.h | 10 +++- 2 files changed, 120 insertions(+), 3 deletions(-)
hw/misc/npcm_clk.c +112 -1
@@ -1,5 +1,5 @@/* -* Nuvoton NPCM7xx Clock Control Registers. +* Nuvoton NPCM7xx/8xx Clock Control Registers. * * Copyright 2020 Google LLC *
@@ -75,6 +75,58 @@ enum NPCM7xxCLKRegisters { NPCM7XX_CLK_REGS_END, }; +enum NPCM8xxCLKRegisters { +NPCM8XX_CLK_CLKEN1 , +NPCM8XX_CLK_CLKSEL , +NPCM8XX_CLK_CLKDIV1 , +NPCM8XX_CLK_PLLCON0 , +NPCM8XX_CLK_PLLCON1 , +NPCM8XX_CLK_SWRSTR , +NPCM8XX_CLK_IPSRST1 =0x20 /sizeof (uint32_t ), +NPCM8XX_CLK_IPSRST2 , +NPCM8XX_CLK_CLKEN2 , +NPCM8XX_CLK_CLKDIV2 , +NPCM8XX_CLK_CLKEN3 , +NPCM8XX_CLK_IPSRST3 , +NPCM8XX_CLK_WD0RCR , +NPCM8XX_CLK_WD1RCR , +NPCM8XX_CLK_WD2RCR , +NPCM8XX_CLK_SWRSTC1 , +NPCM8XX_CLK_SWRSTC2 , +NPCM8XX_CLK_SWRSTC3 , +NPCM8XX_CLK_TIPRSTC , +NPCM8XX_CLK_PLLCON2 , +NPCM8XX_CLK_CLKDIV3 , +NPCM8XX_CLK_CORSTC , +NPCM8XX_CLK_PLLCONG , +NPCM8XX_CLK_AHBCKFI , +NPCM8XX_CLK_SECCNT , +NPCM8XX_CLK_CNTR25M , +/* Registers unique to NPCM8XX SoC */ +NPCM8XX_CLK_CLKEN4 , +NPCM8XX_CLK_IPSRST4 , +NPCM8XX_CLK_BUSTO , +NPCM8XX_CLK_CLKDIV4 , +NPCM8XX_CLK_WD0RCRB , +NPCM8XX_CLK_WD1RCRB , +NPCM8XX_CLK_WD2RCRB , +NPCM8XX_CLK_SWRSTC1B , +NPCM8XX_CLK_SWRSTC2B , +NPCM8XX_CLK_SWRSTC3B , +NPCM8XX_CLK_TIPRSTCB , +NPCM8XX_CLK_CORSTCB , +NPCM8XX_CLK_IPSRSTDIS1 , +NPCM8XX_CLK_IPSRSTDIS2 , +NPCM8XX_CLK_IPSRSTDIS3 , +NPCM8XX_CLK_IPSRSTDIS4 , +NPCM8XX_CLK_CLKENDIS1 , +NPCM8XX_CLK_CLKENDIS2 , +NPCM8XX_CLK_CLKENDIS3 , +NPCM8XX_CLK_CLKENDIS4 , +NPCM8XX_CLK_THRTL_CNT , +NPCM8XX_CLK_REGS_END , +}; +/* * These reset values were taken from version 0.91 of the NPCM750R data sheet. *
@@ -103,6 +155,46 @@ static const uint32_t npcm7xx_cold_reset_values[NPCM7XX_CLK_NR_REGS] = { [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, }; +/* +* These reset values were taken from version 0.92 of the NPCM8xx data sheet. +*/ +static const uint32_t npcm8xx_cold_reset_values[NPCM8XX_CLK_NR_REGS ] = { + [NPCM8XX_CLK_CLKEN1 ] =0xffffffff , + [NPCM8XX_CLK_CLKSEL ] =0x154aaaaa , + [NPCM8XX_CLK_CLKDIV1 ] =0x5413f855 , + [NPCM8XX_CLK_PLLCON0 ] =0x00222101 |PLLCON_LOKI , + [NPCM8XX_CLK_PLLCON1 ] =0x00202101 |PLLCON_LOKI , + [NPCM8XX_CLK_IPSRST1 ] =0x00001000 , + [NPCM8XX_CLK_IPSRST2 ] =0x80000000 , + [NPCM8XX_CLK_CLKEN2 ] =0xffffffff , + [NPCM8XX_CLK_CLKDIV2 ] =0xaa4f8f9f , + [NPCM8XX_CLK_CLKEN3 ] =0xffffffff , + [NPCM8XX_CLK_IPSRST3 ] =0x03000000 , + [NPCM8XX_CLK_WD0RCR ] =0xffffffff , + [NPCM8XX_CLK_WD1RCR ] =0xffffffff , + [NPCM8XX_CLK_WD2RCR ] =0xffffffff , + [NPCM8XX_CLK_SWRSTC1 ] =0x00000003 , + [NPCM8XX_CLK_SWRSTC2 ] =0x00000001 , + [NPCM8XX_CLK_SWRSTC3 ] =0x00000001 , + [NPCM8XX_CLK_TIPRSTC ] =0x00000001 , + [NPCM8XX_CLK_PLLCON2 ] =0x00c02105 |PLLCON_LOKI , + [NPCM8XX_CLK_CLKDIV3 ] =0x00009100 , + [NPCM8XX_CLK_CORSTC ] =0x04000003 , + [NPCM8XX_CLK_PLLCONG ] =0x01228606 |PLLCON_LOKI , + [NPCM8XX_CLK_AHBCKFI ] =0x000000c8 , + [NPCM8XX_CLK_CLKEN4 ] =0xffffffff , + [NPCM8XX_CLK_CLKDIV4 ] =0x70009000 , + [NPCM8XX_CLK_IPSRST4 ] =0x02000000 , + [NPCM8XX_CLK_WD0RCRB ] =0xfffffe71 , + [NPCM8XX_CLK_WD1RCRB ] =0xfffffe71 , + [NPCM8XX_CLK_WD2RCRB ] =0xfffffe71 , + [NPCM8XX_CLK_SWRSTC1B ] =0xfffffe71 , + [NPCM8XX_CLK_SWRSTC2B ] =0xfffffe71 , + [NPCM8XX_CLK_SWRSTC3B ] =0xfffffe71 , + [NPCM8XX_CLK_TIPRSTCB ] =0xfffffe71 , + [NPCM8XX_CLK_CORSTCB ] =0xfffffe71 , +}; +/* The number of watchdogs that can trigger a reset. */ #define NPCM7XX_NR_WATCHDOGS (3)
@@ -1056,6 +1148,18 @@ static void npcm7xx_clk_class_init(ObjectClass *klass, void *data) c->cold_reset_values = npcm7xx_cold_reset_values; } +static void npcm8xx_clk_class_init (ObjectClass *klass,void *data) +{ +NPCMCLKClass *c =NPCM_CLK_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM8XX_CLK_REGS_END >NPCM_CLK_MAX_NR_REGS ); +QEMU_BUILD_BUG_ON (NPCM8XX_CLK_REGS_END !=NPCM8XX_CLK_NR_REGS ); + dc->desc ="NPCM8xx Clock Control Registers" ; + c->nr_regs =NPCM8XX_CLK_NR_REGS ; + c->cold_reset_values = npcm8xx_cold_reset_values; +} +static const TypeInfo npcm7xx_clk_pll_info = { .name =TYPE_NPCM7XX_CLOCK_PLL , .parent =TYPE_DEVICE ,
@@ -1096,6 +1200,12 @@ static const TypeInfo npcm7xx_clk_info = { .class_init = npcm7xx_clk_class_init, }; +static const TypeInfo npcm8xx_clk_info = { + .name =TYPE_NPCM8XX_CLK , + .parent =TYPE_NPCM_CLK , + .class_init = npcm8xx_clk_class_init, +}; +static void npcm7xx_clk_register_type (void ) {type_register_static (&npcm7xx_clk_pll_info);
@@ -1103,5 +1213,6 @@ static void npcm7xx_clk_register_type(void)type_register_static (&npcm7xx_clk_divider_info);type_register_static (&npcm_clk_info);type_register_static (&npcm7xx_clk_info); +type_register_static (&npcm8xx_clk_info); }type_init (npcm7xx_clk_register_type);
include/hw/misc/npcm_clk.h +8 -2
@@ -1,5 +1,5 @@/* -* Nuvoton NPCM7xx Clock Control Registers. +* Nuvoton NPCM7xx/8xx Clock Control Registers. * * Copyright 2020 Google LLC *
@@ -21,11 +21,12 @@#include "hw/sysbus.h" #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) +#define NPCM8XX_CLK_NR_REGS (0xc4 / sizeof(uint32_t))/* * Number of maximum registers in NPCM device state structure. Don't change * this without incrementing the version_id in the vmstate. */ -#define NPCM_CLK_MAX_NR_REGS NPCM7XX_CLK_NR_REGS +#define NPCM_CLK_MAX_NR_REGS NPCM8XX_CLK_NR_REGS#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
@@ -162,6 +163,10 @@ struct NPCMCLKState {MemoryRegion iomem;/* Clock converters */ +/* +* TODO: Implement unique clock converters for NPCM8xx. +* NPCM8xx adds a few more clock outputs. +*/ NPCM7xxClockPLLState plls[NPCM7XX_CLOCK_NR_PLLS ];NPCM7xxClockSELState sels[NPCM7XX_CLOCK_NR_SELS ];NPCM7xxClockDividerState dividers[NPCM7XX_CLOCK_NR_DIVIDERS ];
@@ -185,5 +190,6 @@ typedef struct NPCMCLKClass {#define TYPE_NPCM_CLK "npcm-clk" OBJECT_DECLARE_TYPE(NPCMCLKState, NPCMCLKClass, NPCM_CLK)#define TYPE_NPCM7XX_CLK "npcm7xx-clk" +#define TYPE_NPCM8XX_CLK "npcm8xx-clk"#endif /* NPCM_CLK_H */
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 14/17] hw/misc: Support NPCM8XX CLK Module Registers
Quoted 10 lines · Hao Wu
NPCM8XX adds a few new registers and have a different set of reset values to the CLK modules. This patch supports them.
This patch doesn't support the new clock values generated by these registers. Currently no modules use these new clock values so they are not necessary at this point.
Implementation of these clocks might be required when implementing these modules.
Quoted 3 lines
Signed-off-by Hao Wu <[email protected]>Reviewed-by Titus Rwantare<[email protected]>---
thanks
-- PMM
PATCH v2 15/17 hw/net: Add NPCM8XX PCS Module
In reply to Hao WuThe PCS exists in NPCM8XX's GMAC1 and is used to control the SGMII PHY. This implementation contains all the default registers and the soft reset feature that are required to load the Linux kernel driver. Further features have not been implemented yet.
--- hw/net/meson.build | 1 + hw/net/npcm_pcs.c | 410 ++++++++++++++++++++++++++++++++++++++ hw/net/trace-events | 4 +- include/hw/net/npcm_pcs.h | 42 ++++ 4 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 hw/net/npcm_pcs.c create mode 100644 include/hw/net/npcm_pcs.h
hw/net/meson.build +1 -0
@@ -40,6 +40,7 @@ system_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c')) system_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c')) system_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c', 'npcm_gmac.c')) +system_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm_pcs.c')) system_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_llan.c'))
hw/net/npcm_pcs.c new file +410 -0
410 lines not on this page · raw message
hw/net/trace-events +2 -2
@@ -483,8 +483,8 @@ npcm_gmac_packet_tx_desc_data(const char* name, uint32_t tdes0, uint32_t tdes1) npcm_gmac_tx_desc_owner(const char* name, uint32_t desc_addr) "%s: TX Descriptor @0x%04" PRIX32 " is owned by software" # npcm_pcs.c -npcm_pcs_reg_read(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16 -npcm_pcs_reg_write(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16 +npcm_pcs_reg_read(const char *name, uint16_t indirect_access_base, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16 +npcm_pcs_reg_write(const char *name, uint16_t indirect_access_base, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16 # dp8398x.c dp8393x_raise_irq(int isr) "raise irq, isr is 0x%04x"
include/hw/net/npcm_pcs.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 15/17] hw/net: Add NPCM8XX PCS Module
Quoted 7 lines · Hao Wu
The PCS exists in NPCM8XX's GMAC1 and is used to control the SGMII PHY. This implementation contains all the default registers and the soft reset feature that are required to load the Linux kernel driver. Further features have not been implemented yet.
Signed-off-by Hao Wu <[email protected]>
Quoted 9 lines
--- hw/net/meson.build | 1 + hw/net/npcm_pcs.c | 410 ++++++++++++++++++++++++++++++++++++++ hw/net/trace-events | 4 +- include/hw/net/npcm_pcs.h | 42 ++++ 4 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 hw/net/npcm_pcs.c create mode 100644 include/hw/net/npcm_pcs.h
for basic structure, but it would be good if somebody who knows the hardware reviewed it for whether it's actually implementing the right thing.
thanks
-- PMM
PATCH v2 16/17 hw/arm: Add NPCM8XX SoC
In reply to Hao Wu--- configs/devices/aarch64-softmmu/default.mak | 1 + hw/arm/Kconfig | 11 + hw/arm/meson.build | 1 + hw/arm/npcm8xx.c | 810 ++++++++++++++++++++ include/hw/arm/npcm8xx.h | 107 +++ 5 files changed, 930 insertions(+) create mode 100644 hw/arm/npcm8xx.c create mode 100644 include/hw/arm/npcm8xx.h
configs/devices/aarch64-softmmu/default.mak +1 -0
@@ -8,3 +8,4 @@ include ../arm-softmmu/default.mak # CONFIG_XLNX_ZYNQMP_ARM=n # CONFIG_XLNX_VERSAL=n # CONFIG_SBSA_REF=n +CONFIG_NPCM8XX=y
hw/arm/Kconfig +11 -0
@@ -481,6 +481,17 @@ config NPCM7XX select PCA954X select USB_OHCI_SYSBUS +config NPCM8XX + bool + select ARM_GIC + select SMBUS + select PL310 # cache controller + select NPCM7XX + select SERIAL + select SSI + select UNIMP + + config FSL_IMX25 bool default y
hw/arm/meson.build +1 -0
@@ -12,6 +12,7 @@ arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) arm_ss.add(when: 'CONFIG_OLIMEX_STM32_H405', if_true: files('olimex-stm32-h405.c')) arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c')) +arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c')) arm_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview.c')) arm_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa-ref.c')) arm_ss.add(when: 'CONFIG_STELLARIS', if_true: files('stellaris.c'))
hw/arm/npcm8xx.c new file +810 -0
810 lines not on this page · raw message
include/hw/arm/npcm8xx.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 16/17] hw/arm: Add NPCM8XX SoC
Quoted 17 lines · Hao Wu
Signed-off-by Hao Wu <[email protected]>--- configs/devices/aarch64-softmmu/default.mak | 1 + hw/arm/Kconfig | 11 + hw/arm/meson.build | 1 + hw/arm/npcm8xx.c | 810 ++++++++++++++++++++ include/hw/arm/npcm8xx.h | 107 +++ 5 files changed, 930 insertions(+) create mode 100644 hw/arm/npcm8xx.c create mode 100644 include/hw/arm/npcm8xx.hconfigs/devices/aarch64-softmmu/default.mak +0
-0
configs/devices/aarch64-softmmu/default.mak include ../arm-softmmu/default.mak · line 11
Quoted 4 lines
configs/devices/aarch64-softmmu/default.mak +1
-0@@ -8,3 +8,4 @@ include ../arm-softmmu/default.mak # CONFIG_XLNX_ZYNQMP_ARM=n # CONFIG_XLNX_VERSAL=n # CONFIG_SBSA_REF=n +CONFIG_NPCM8XX=y
This should be a commented-out "n" (the way we arrange this has flipped around since you originally wrote the board support).
Quoted 7 lines
hw/arm/Kconfig +0
-0@@ -481,6 +481,17 @@ config NPCM7XX select PCA954X select USB_OHCI_SYSBUS
hw/arm/Kconfig config NPCM7XX · line 492
Quoted 10 lines
hw/arm/Kconfig +9
-0+config NPCM8XX + bool + select ARM_GIC + select SMBUS + select PL310 # cache controller + select NPCM7XX + select SERIAL + select SSI + select UNIMP
You want a "depends on TCG && ARM" clause: compare the other stanzas in the file.
(This is the other half of the flipping-around noted above).
Quoted 45 lines
hw/arm/Kconfig +0
-0config FSL_IMX25 bool default yhw/arm/meson.build +1
-0@@ -12,6 +12,7 @@ arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) arm_ss.add(when: 'CONFIG_OLIMEX_STM32_H405', if_true: files('olimex-stm32-h405.c')) arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c')) +arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c')) arm_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview.c')) arm_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa-ref.c')) arm_ss.add(when: 'CONFIG_STELLARIS', if_true: files('stellaris.c'))hw/arm/npcm8xx.c new file +24
-0@@ -0,0 +1,810 @@ +/* +* Nuvoton NPCM8xx SoC family. +* +* Copyright 2022 Google LLC +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +*/ + +#include "qemu/osdep.h" + +#include "hw/arm/boot.h" +#include "hw/arm/npcm8xx.h" +#include "hw/char/serial-mm.h" +#include "hw/intc/arm_gic.h" +#include "hw/loader.h" +#include "hw/misc/unimp.h"
hw/arm/npcm8xx.c line 34
Quoted 10 lines
hw/arm/npcm8xx.c new file +10
-0+#include "hw/qdev-clock.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/units.h" +#include "system/system.h" + +#define ARM_PHYS_TIMER_PPI 30 +#define ARM_VIRT_TIMER_PPI 27 +#define ARM_HYP_TIMER_PPI 26 +#define ARM_SEC_TIMER_PPI 29
We have defines for these basically-standardized IRQ numbers in include/hw/arm/bsa.h now.
hw/arm/npcm8xx.c line 41
Quoted 7 lines
hw/arm/npcm8xx.c new file +7
-0+ +/* +* This covers the whole MMIO space. We'll use this to catch any MMIO accesses +* that aren't handled by a device. +*/ +#define NPCM8XX_MMIO_BA (0x80000000) +#define NPCM8XX_MMIO_SZ (0x7ffd0000)
You don't need brackets around simple constants in a #define.
hw/arm/npcm8xx.c line 169
Quoted 3 lines
hw/arm/npcm8xx.c new file +3
-0+/* Total number of GIC interrupts, including internal Cortex-A35 interrupts. */ +#define NPCM8XX_NUM_IRQ (288) +#define NPCM8XX_PPI_BASE (cpu) ((NPCM8XX_NUM_IRQ - 32) + (cpu) * 32)
These "32"s should probably be "GIC_INTERNAL"s.
hw/arm/npcm8xx.c line 575
Quoted 5 lines
hw/arm/npcm8xx.c new file +5
-0+/* IRQ for watchdogs */ +sysbus_connect_irq (sbd,NPCM7XX_TIMERS_PER_CTRL , +npcm8xx_irq (s,NPCM8XX_WDG0_IRQ + i)); +/* GPIO that connects clk module with watchdog */ +/* TODO: Check this.*/
Good idea :-)
hw/arm/npcm8xx.c line 580
Quoted 5 lines
hw/arm/npcm8xx.c new file +5
-0+qdev_connect_gpio_out_named (DEVICE (&s->tim[i]), +NPCM7XX_WATCHDOG_RESET_GPIO_OUT ,0 , +qdev_get_gpio_in_named (DEVICE (&s->clk), +NPCM7XX_WATCHDOG_RESET_GPIO_IN , i)); + }
Otherwise looks OK, but again, review by somebody who knows the hardware would be nice.
thanks
-- PMM
PATCH v2 17/17 hw/arm: Add NPCM845 Evaluation board
In reply to Hao Wu--- hw/arm/meson.build | 2 +- hw/arm/npcm8xx_boards.c | 256 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm8xx.h | 20 +++ 3 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm8xx_boards.c
hw/arm/meson.build +1 -1
@@ -12,7 +12,7 @@ arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) arm_ss.add(when: 'CONFIG_OLIMEX_STM32_H405', if_true: files('olimex-stm32-h405.c')) arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c')) -arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c')) +arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c', 'npcm8xx_boards.c')) arm_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview.c')) arm_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa-ref.c')) arm_ss.add(when: 'CONFIG_STELLARIS', if_true: files('stellaris.c'))
hw/arm/npcm8xx_boards.c new file +256 -0
256 lines not on this page · raw message
include/hw/arm/npcm8xx.h +20 -0
@@ -52,6 +52,26 @@#define NPCM8XX_NR_PWM_MODULES 3 +typedef struct NPCM8xxMachine { +MachineState parent; +/* +* PWM fan splitter. each splitter connects to one PWM output and +* multiple MFT inputs. +*/ +SplitIRQ fan_splitter[NPCM8XX_NR_PWM_MODULES * +NPCM7XX_PWM_PER_MODULE ]; +}NPCM8xxMachine ; + + +typedef struct NPCM8xxMachineClass { +MachineClass parent; + +const char *soc_type; +}NPCM8xxMachineClass ; + +#define TYPE_NPCM8XX_MACHINE MACHINE_TYPE_NAME("npcm8xx") +OBJECT_DECLARE_TYPE(NPCM8xxMachine, NPCM8xxMachineClass, NPCM8XX_MACHINE) + typedef struct NPCM8xxState { DeviceState parent;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v2 17/17] hw/arm: Add NPCM845 Evaluation board
Quoted 8 lines · Hao Wu
Signed-off-by Hao Wu <[email protected]>--- hw/arm/meson.build | 2 +- hw/arm/npcm8xx_boards.c | 256 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm8xx.h | 20 +++ 3 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm8xx_boards.c
thanks
-- PMM