Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
cover Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot a minimal Linux kernel. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
These modules, along with the existing Cortex A9 CPU cores and built-in peripherals, are integrated into a NPCM730 or NPCM750 SoC, which in turn form the foundation for the quanta-gsj and npcm750-evb machines, respectively. The two SoCs are very similar; the only difference is that NPCM730 is missing some peripherals that NPCM750 has, and which are not considered essential for datacenter use (e.g. graphics controllers). For more information, see
https://www.nuvoton.com/products/cloud-computing/ibmc/
Both quanta-gsj and npcm750-evb correspond to real boards supported by OpenBMC. While this initial series uses a stripped-down kernel for testing, future series will be tested using OpenBMC images built from public sources. I'm currently putting the finishing touches on flash controller support, which is necessary to boot a full OpenBMC image, and will be enabled by the next series.
The patches in this series were developed by Google and reviewed by Nuvoton. We will be maintaining the machine and peripheral support together.
The data sheet for these SoCs is not generally available. Please let me know if more comments are needed to understand the device behavior.
Thanks for reviewing,
Havard
Havard Skinnemoen (6):
npcm7xx: Add config symbol
hw/misc: Add NPCM7xx System Global Control Registers device model hw/misc: Add NPCM7xx Clock Controller device model hw/timer: Add NPCM7xx Timer device model
hw/arm: Add NPCM730 and NPCM750 SoC models
hw/arm: Add two NPCM7xx-based machines
MAINTAINERS | 12 + default-configs/arm-softmmu.mak | 1 + hw/arm/Kconfig | 8 + hw/arm/Makefile.objs | 1 + hw/arm/npcm7xx.c | 328 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 108 ++++++++ hw/misc/Makefile.objs | 2 + hw/misc/npcm7xx_clk.c | 210 +++++++++++++++ hw/misc/npcm7xx_gcr.c | 160 +++++++++++ hw/misc/trace-events | 8 + hw/timer/Makefile.objs | 1 + hw/timer/npcm7xx_timer.c | 437 +++++++++++++++++++++++++++++++ hw/timer/trace-events | 5 + include/hw/arm/npcm7xx.h | 98 +++++++ include/hw/misc/npcm7xx_clk.h | 65 +++++ include/hw/misc/npcm7xx_gcr.h | 74 ++++++ include/hw/timer/npcm7xx_timer.h | 95 +++++++ 17 files changed, 1613 insertions(+) create mode 100644 hw/arm/npcm7xx.c create mode 100644 hw/arm/npcm7xx_boards.c create mode 100644 hw/misc/npcm7xx_clk.c create mode 100644 hw/misc/npcm7xx_gcr.c create mode 100644 hw/timer/npcm7xx_timer.c create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 include/hw/timer/npcm7xx_timer.h
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
PATCH 1/6 npcm7xx: Add config symbol
Add a config symbol for the NPCM7xx BMC SoC family that subsequent patches can use in Makefiles.
--- default-configs/arm-softmmu.mak | 1 + hw/arm/Kconfig | 8 ++++++++ 2 files changed, 9 insertions(+)
default-configs/arm-softmmu.mak +1 -0
@@ -27,6 +27,7 @@ CONFIG_GUMSTIX=y CONFIG_SPITZ=y CONFIG_TOSA=y CONFIG_Z2=y +CONFIG_NPCM7XX=y CONFIG_COLLIE=y CONFIG_ASPEED_SOC=y CONFIG_NETDUINO2=y
hw/arm/Kconfig +8 -0
@@ -354,6 +354,14 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP +config NPCM7XX + bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP + config FSL_IMX25 bool select IMX
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 1/6] npcm7xx: Add config symbol
Quoted 6 lines · Havard Skinnemoen
Add a config symbol for the NPCM7xx BMC SoC family that subsequent patches can use in Makefiles.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
Quoted 40 lines
--- default-configs/arm-softmmu.mak | 1 + hw/arm/Kconfig | 8 ++++++++ 2 files changed, 9 insertions(+)default-configs/arm-softmmu.mak +1
-0@@ -27,6 +27,7 @@ CONFIG_GUMSTIX=y CONFIG_SPITZ=y CONFIG_TOSA=y CONFIG_Z2=y +CONFIG_NPCM7XX=y CONFIG_COLLIE=y CONFIG_ASPEED_SOC=y CONFIG_NETDUINO2=yhw/arm/Kconfig +8
-1@@ -354,6 +354,14 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP +config NPCM7XX + bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP + config FSL_IMX25 bool select IMX --2.27.0.rc0.183.gde8f92d652-goog
PATCH 2/6 hw/misc: Add NPCM7xx System Global Control Registers device model
In reply to Havard SkinnemoenImplement a device model for the System Global Control Registers in the NPCM730 and NPCM750 BMC SoCs.
This is primarily used to enable SMP boot (the boot ROM spins reading the SCRPAD register); other registers are best effort for now.
The reset values of the MDLR and PWRON registers are determined by the SoC variant (730 vs 750) and board straps respectively.
--- MAINTAINERS | 8 ++ hw/misc/Makefile.objs | 1 + hw/misc/npcm7xx_gcr.c | 160 ++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 4 + include/hw/misc/npcm7xx_gcr.h | 74 ++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 hw/misc/npcm7xx_gcr.c create mode 100644 include/hw/misc/npcm7xx_gcr.h
MAINTAINERS +8 -0
@@ -715,6 +715,14 @@ S: Odd Fixes F: hw/arm/musicpal.c F: docs/system/arm/musicpal.rst +Nuvoton NPCM7xx +M: Havard Skinnemoen <[email protected]> +M: Tyrone Ting <[email protected]> +L: [email protected] +S: Supported +F: hw/misc/npcm7xx* +F: include/hw/misc/npcm7xx* + nSeries M: Andrzej Zaborowski <[email protected]> M: Peter Maydell <[email protected]>
hw/misc/Makefile.objs +1 -0
@@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) += imx_rngc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) += mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) += omap_clk.o common-obj-$(CONFIG_OMAP) += omap_gpmc.o common-obj-$(CONFIG_OMAP) += omap_l4.o
hw/misc/npcm7xx_gcr.c new file +160 -0
160 lines not on this page · raw message
hw/misc/trace-events +4 -0
@@ -103,6 +103,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64 mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x" +# 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 + # stm32f4xx_syscfg stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
include/hw/misc/npcm7xx_gcr.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 2/6] hw/misc: Add NPCM7xx System Global Control Registers device model
Quoted 4 lines · Havard Skinnemoen
Implement a device model for the System Global Control Registers in the NPCM730 and NPCM750 BMC SoCs.
Quoted 8 lines
This is primarily used to enable SMP boot (the boot ROM spins reading the SCRPAD register); other registers are best effort for now.
The reset values of the MDLR and PWRON registers are determined by the SoC variant (730 vs 750) and board straps respectively.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
This looks similar to the aspeed scu model :)
Re: [PATCH 2/6] hw/misc: Add NPCM7xx System Global Control Registers device model
In reply to Havard SkinnemoenQuoted 11 lines · Havard Skinnemoen
Implement a device model for the System Global Control Registers in the NPCM730 and NPCM750 BMC SoCs.
This is primarily used to enable SMP boot (the boot ROM spins reading the SCRPAD register); other registers are best effort for now.
The reset values of the MDLR and PWRON registers are determined by the SoC variant (730 vs 750) and board straps respectively.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
It's nice to have header files on the top and I would have used a list of #define for NPCM7xxGCRRegisters in npcm7xx_gcr.c. Anyhow :
C.
Quoted 136 lines
--- MAINTAINERS | 8 ++ hw/misc/Makefile.objs | 1 + hw/misc/npcm7xx_gcr.c | 160 ++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 4 + include/hw/misc/npcm7xx_gcr.h | 74 ++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 hw/misc/npcm7xx_gcr.c create mode 100644 include/hw/misc/npcm7xx_gcr.hMAINTAINERS +8
-0@@ -715,6 +715,14 @@ S: Odd Fixes F: hw/arm/musicpal.c F: docs/system/arm/musicpal.rst +Nuvoton NPCM7xx +M: Havard Skinnemoen <[email protected]> +M: Tyrone Ting <[email protected]> +L: [email protected] +S: Supported +F: hw/misc/npcm7xx* +F: include/hw/misc/npcm7xx* + nSeries M: Andrzej Zaborowski <[email protected]> M: Peter Maydell <[email protected]>hw/misc/Makefile.objs +1
-0@@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) += imx_rngc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) += mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) += omap_clk.o common-obj-$(CONFIG_OMAP) += omap_gpmc.o common-obj-$(CONFIG_OMAP) += omap_l4.ohw/misc/npcm7xx_gcr.c new file +89
-0@@ -0,0 +1,160 @@ +/* +* Nuvoton NPCM7xx System Global Control Registers. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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/misc/npcm7xx_gcr.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +#include "trace.h" + +static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS ] = { + [NPCM7XX_GCR_PDID ] =0x04A92750 ,/* Poleg A1 */ + [NPCM7XX_GCR_MISCPE ] =0x0000FFFF , + [NPCM7XX_GCR_SPSWC ] =0x00000003 , + [NPCM7XX_GCR_INTCR ] =0x0000035E , + [NPCM7XX_GCR_HIFCR ] =0x0000004E , + [NPCM7XX_GCR_RESSR ] =0x80000000 , + [NPCM7XX_GCR_DSCNT ] =0x000000c0 , + [NPCM7XX_GCR_DAVCLVLR ] =0x5A00F3CF , + [NPCM7XX_GCR_INTCR3 ] =0x00001002 , + [NPCM7XX_GCR_SCRPAD ] =0x00000008 , + [NPCM7XX_GCR_USB1PHYCTL ] =0x034730E4 , + [NPCM7XX_GCR_USB2PHYCTL ] =0x034730E4 , +}; + +static uint64_t npcm7xx_gcr_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxGCRState *s = opaque; + +if (reg >=NPCM7XX_GCR_NR_REGS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: offset 0x%04x out of range\n" , + __func__, (unsigned int )offset); +return 0 ; + } + +trace_npcm7xx_gcr_read (offset, s->regs[reg]); + +return s->regs[reg]; +} + +static void npcm7xx_gcr_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxGCRState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_gcr_write (offset, value); + +if (reg >=NPCM7XX_GCR_NR_REGS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: offset 0x%04x out of range\n" , + __func__, (unsigned int )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%04x is read-only\n" , + __func__, (unsigned int )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];
hw/misc/npcm7xx_gcr.c line 99
Quoted 10 lines
hw/misc/npcm7xx_gcr.c new file +10
-0+break ; + }; + + s->regs[reg] = value; +} + +static const struct MemoryRegionOps npcm7xx_gcr_ops = { + .read = npcm7xx_gcr_read, + .write = npcm7xx_gcr_write, + .endianness =DEVICE_NATIVE_ENDIAN ,
DEVICE_LITTLE_ENDIAN
Quoted 157 lines
hw/misc/npcm7xx_gcr.c new file +61
-0+ .valid = { + .min_access_size = 4, + .max_access_size = 4, + .unaligned = false, + }, +}; + +static void npcm7xx_gcr_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxGCRState *s =NPCM7XX_GCR (obj); + +QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); + +switch (type) { +case RESET_TYPE_COLD : +memcpy (s->regs, cold_reset_values,sizeof (s->regs)); + s->regs[NPCM7XX_GCR_PWRON ] = s->reset_pwron; + s->regs[NPCM7XX_GCR_MDLR ] = s->reset_mdlr; +break ; + } +} + +static void npcm7xx_gcr_init (Object *obj) +{ +NPCM7xxGCRState *s =NPCM7XX_GCR (obj); + +memory_region_init_io (&s->iomem, obj, &npcm7xx_gcr_ops, s, +TYPE_NPCM7XX_GCR ,4 * KiB); +sysbus_init_mmio (&s->parent, &s->iomem); +} + +static Property npcm7xx_gcr_properties[] = { +DEFINE_PROP_UINT32 ("disabled-modules" , NPCM7xxGCRState, reset_mdlr,0 ), +DEFINE_PROP_UINT32 ("power-on-straps" , NPCM7xxGCRState, reset_pwron,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void npcm7xx_gcr_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="NPCM7xx System Global Control Registers" ; + 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 void npcm7xx_gcr_register_type (void ) +{ +type_register_static (&npcm7xx_gcr_info); +} +type_init (npcm7xx_gcr_register_type);hw/misc/trace-events +4
-0@@ -103,6 +103,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64 mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x" +# 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 + # stm32f4xx_syscfg stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"include/hw/misc/npcm7xx_gcr.h new file +74
-0@@ -0,0 +1,74 @@ +/* +* Nuvoton NPCM7xx System Global Control Registers. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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. +*/ +#ifndef NPCM7XX_GCR_H +#define NPCM7XX_GCR_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +enum NPCM7xxGCRRegisters { +NPCM7XX_GCR_PDID , +NPCM7XX_GCR_PWRON , +NPCM7XX_GCR_MFSEL1 =0x0C /sizeof (uint32_t ), +NPCM7XX_GCR_MFSEL2 , +NPCM7XX_GCR_MISCPE , +NPCM7XX_GCR_SPSWC =0x038 /sizeof (uint32_t ), +NPCM7XX_GCR_INTCR , +NPCM7XX_GCR_INTSR , +NPCM7XX_GCR_HIFCR =0x050 /sizeof (uint32_t ), +NPCM7XX_GCR_INTCR2 =0x060 /sizeof (uint32_t ), +NPCM7XX_GCR_MFSEL3 , +NPCM7XX_GCR_SRCNT , +NPCM7XX_GCR_RESSR , +NPCM7XX_GCR_RLOCKR1 , +NPCM7XX_GCR_FLOCKR1 , +NPCM7XX_GCR_DSCNT , +NPCM7XX_GCR_MDLR , +NPCM7XX_GCR_SCRPAD3 , +NPCM7XX_GCR_SCRPAD2 , +NPCM7XX_GCR_DAVCLVLR =0x098 /sizeof (uint32_t ), +NPCM7XX_GCR_INTCR3 , +NPCM7XX_GCR_VSINTR =0x0AC /sizeof (uint32_t ), +NPCM7XX_GCR_MFSEL4 , +NPCM7XX_GCR_CPBPNTR =0x0C4 /sizeof (uint32_t ), +NPCM7XX_GCR_CPCTL =0x0D0 /sizeof (uint32_t ), +NPCM7XX_GCR_CP2BST , +NPCM7XX_GCR_B2CPNT , +NPCM7XX_GCR_CPPCTL , +NPCM7XX_GCR_I2CSEGSEL , +NPCM7XX_GCR_I2CSEGCTL , +NPCM7XX_GCR_VSRCR , +NPCM7XX_GCR_MLOCKR , +NPCM7XX_GCR_SCRPAD =0x013C /sizeof (uint32_t ), +NPCM7XX_GCR_USB1PHYCTL , +NPCM7XX_GCR_USB2PHYCTL , +NPCM7XX_GCR_NR_REGS , +}; + +typedef struct NPCM7xxGCRState { +SysBusDevice parent; + +MemoryRegion iomem; + +uint32_t regs[NPCM7XX_GCR_NR_REGS ]; + +uint32_t reset_pwron; +uint32_t reset_mdlr; +}NPCM7xxGCRState ; + +#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" +#define NPCM7XX_GCR (obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR) + +#endif /* NPCM7XX_GCR_H */
PATCH 3/6 hw/misc: Add NPCM7xx Clock Controller device model
In reply to Havard SkinnemoenEnough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.
In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
--- hw/misc/Makefile.objs | 1 + hw/misc/npcm7xx_clk.c | 210 ++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 4 + include/hw/misc/npcm7xx_clk.h | 65 +++++++++++ 4 files changed, 280 insertions(+) create mode 100644 hw/misc/npcm7xx_clk.c create mode 100644 include/hw/misc/npcm7xx_clk.h
hw/misc/Makefile.objs +1 -0
@@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) += imx_rngc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) += mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_clk.o common-obj-$(CONFIG_NPCM7XX) += npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) += omap_clk.o common-obj-$(CONFIG_OMAP) += omap_gpmc.o
hw/misc/npcm7xx_clk.c new file +210 -0
210 lines not on this page · raw message
hw/misc/trace-events +4 -0
@@ -103,6 +103,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64 mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " 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 + # 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
include/hw/misc/npcm7xx_clk.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 3/6] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 8 lines · Havard Skinnemoen
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.
Quoted 5 lines
In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
hw/misc/npcm7xx_clk.c line 30
Quoted 7 lines
+++
b/hw/misc/npcm7xx_clk.chw/misc/npcm7xx_clk.c new file +5
-0+#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS ] = {
Can you add a comment to mention where these come from? If it's the data sheet, note which version you're using.
Quoted 20 lines
hw/misc/npcm7xx_clk.c new file +20
-0+ [NPCM7XX_CLK_CLKEN1] = 0xffffffff, + [NPCM7XX_CLK_CLKSEL] = 0x004aaaaa, + [NPCM7XX_CLK_CLKDIV1] = 0x5413f855, + [NPCM7XX_CLK_PLLCON0] = 0x00222101 | PLLCON_LOKI, + [NPCM7XX_CLK_PLLCON1] = 0x00202101 | PLLCON_LOKI, + [NPCM7XX_CLK_IPSRST1] = 0x00001000, + [NPCM7XX_CLK_IPSRST2] = 0x80000000, + [NPCM7XX_CLK_CLKEN2] = 0xffffffff, + [NPCM7XX_CLK_CLKDIV2] = 0xaa4f8f9f, + [NPCM7XX_CLK_CLKEN3] = 0xffffffff, + [NPCM7XX_CLK_IPSRST3] = 0x03000000, + [NPCM7XX_CLK_WD0RCR] = 0xffffffff, + [NPCM7XX_CLK_WD1RCR] = 0xffffffff, + [NPCM7XX_CLK_WD2RCR] = 0xffffffff, + [NPCM7XX_CLK_SWRSTC1] = 0x00000003, + [NPCM7XX_CLK_PLLCON2] = 0x00c02105 | PLLCON_LOKI, + [NPCM7XX_CLK_CORSTC] = 0x04000003, + [NPCM7XX_CLK_PLLCONG] = 0x01228606 | PLLCON_LOKI, + [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, +};
Re: [PATCH 3/6] hw/misc: Add NPCM7xx Clock Controller device model
In reply to Havard SkinnemoenQuoted 7 lines · Havard Skinnemoen
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.
Quoted 5 lines
In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
Quoted 324 lines
--- hw/misc/Makefile.objs | 1 + hw/misc/npcm7xx_clk.c | 210 ++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 4 + include/hw/misc/npcm7xx_clk.h | 65 +++++++++++ 4 files changed, 280 insertions(+) create mode 100644 hw/misc/npcm7xx_clk.c create mode 100644 include/hw/misc/npcm7xx_clk.hhw/misc/Makefile.objs +1
-0@@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) += imx_rngc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) += mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_clk.o common-obj-$(CONFIG_NPCM7XX) += npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) += omap_clk.o common-obj-$(CONFIG_OMAP) += omap_gpmc.ohw/misc/npcm7xx_clk.c new file +210
-0@@ -0,0 +1,210 @@ +/* +* Nuvoton NPCM7xx Clock Control Registers. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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/misc/npcm7xx_clk.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS ] = { + [NPCM7XX_CLK_CLKEN1 ] =0xffffffff , + [NPCM7XX_CLK_CLKSEL ] =0x004aaaaa , + [NPCM7XX_CLK_CLKDIV1 ] =0x5413f855 , + [NPCM7XX_CLK_PLLCON0 ] =0x00222101 |PLLCON_LOKI , + [NPCM7XX_CLK_PLLCON1 ] =0x00202101 |PLLCON_LOKI , + [NPCM7XX_CLK_IPSRST1 ] =0x00001000 , + [NPCM7XX_CLK_IPSRST2 ] =0x80000000 , + [NPCM7XX_CLK_CLKEN2 ] =0xffffffff , + [NPCM7XX_CLK_CLKDIV2 ] =0xaa4f8f9f , + [NPCM7XX_CLK_CLKEN3 ] =0xffffffff , + [NPCM7XX_CLK_IPSRST3 ] =0x03000000 , + [NPCM7XX_CLK_WD0RCR ] =0xffffffff , + [NPCM7XX_CLK_WD1RCR ] =0xffffffff , + [NPCM7XX_CLK_WD2RCR ] =0xffffffff , + [NPCM7XX_CLK_SWRSTC1 ] =0x00000003 , + [NPCM7XX_CLK_PLLCON2 ] =0x00c02105 |PLLCON_LOKI , + [NPCM7XX_CLK_CORSTC ] =0x04000003 , + [NPCM7XX_CLK_PLLCONG ] =0x01228606 |PLLCON_LOKI , + [NPCM7XX_CLK_AHBCKFI ] =0x000000c8 , +}; + +static uint64_t npcm7xx_clk_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +int64_t now_ns; +uint32_t value =0 ; + +if (reg >=NPCM7XX_CLK_NR_REGS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: offset 0x%04x out of range\n" , + __func__, (unsigned int )offset); +return 0 ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: register @ 0x%04x is write-only\n" , + __func__, (unsigned int )offset); +break ; + +case NPCM7XX_CLK_SECCNT : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + value = (now_ns - s->ref_ns) /NANOSECONDS_PER_SECOND ; +break ; + +case NPCM7XX_CLK_CNTR25M : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* +* This register counts 25 MHz cycles, updating every 640 ns. It rolls +* over to zero every second. +* +* The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000. +*/ + value = (((now_ns - s->ref_ns) /640 ) <<4 ) %25000000 ; +break ; + +default : + value = s->regs[reg]; +break ; + }; + +trace_npcm7xx_clk_read (offset, value); + +return value; +} + +static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: offset 0x%04x out of range\n" , + __func__, (unsigned int )offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value); + value =0 ; +break ; + +case NPCM7XX_CLK_PLLCON0 : +case NPCM7XX_CLK_PLLCON1 : +case NPCM7XX_CLK_PLLCON2 : +case NPCM7XX_CLK_PLLCONG : +if (value &PLLCON_PWDEN ) { +/* Power down -- clear lock and indicate loss of lock */ + value &= ~PLLCON_LOKI ; + value |=PLLCON_LOKS ; + }else { +/* Normal mode -- assume always locked */ + value |=PLLCON_LOKI ; +/* Keep LOKS unchanged unless cleared by writing 1 */ +if (value &PLLCON_LOKS ) { + value &= ~PLLCON_LOKS ; + }else { + value |= (value &PLLCON_LOKS ); + } + } +break ; + +case NPCM7XX_CLK_CNTR25M : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: register @ 0x%04x is read-only\n" , + __func__, (unsigned int )offset); +return ; + } + + s->regs[reg] = value; +} + +static const struct MemoryRegionOps npcm7xx_clk_ops = { + .read = npcm7xx_clk_read, + .write = npcm7xx_clk_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_clk_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); + +switch (type) { +case RESET_TYPE_COLD : +memcpy (s->regs, cold_reset_values,sizeof (cold_reset_values)); + s->ref_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +return ; + } + +/* +* A small number of registers need to be reset on a core domain reset, +* but no such reset type exists yet. +*/ +qemu_log_mask (LOG_UNIMP ,"%s: reset type %d not implemented." , + __func__, type); +} + +static void npcm7xx_clk_init (Object *obj) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +memory_region_init_io (&s->iomem, obj, &npcm7xx_clk_ops, s, +TYPE_NPCM7XX_CLK ,4 * KiB); +sysbus_init_mmio (&s->parent, &s->iomem); +} + +static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="NPCM7xx Clock Control Registers" ; + rc->phases.enter = npcm7xx_clk_enter_reset; +} + +static const TypeInfo npcm7xx_clk_info = { + .name =TYPE_NPCM7XX_CLK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxCLKState), + .instance_init = npcm7xx_clk_init, + .class_init = npcm7xx_clk_class_init, +}; + +static void npcm7xx_clk_register_type (void ) +{ +type_register_static (&npcm7xx_clk_info); +} +type_init (npcm7xx_clk_register_type);hw/misc/trace-events +4
-0@@ -103,6 +103,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64 mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " 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 + # 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" PRIx32include/hw/misc/npcm7xx_clk.h new file +65
-0@@ -0,0 +1,65 @@ +/* +* Nuvoton NPCM7xx Clock Control Registers. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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. +*/ +#ifndef NPCM7XX_CLK_H +#define NPCM7XX_CLK_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +enum NPCM7xxCLKRegisters { +NPCM7XX_CLK_CLKEN1 , +NPCM7XX_CLK_CLKSEL , +NPCM7XX_CLK_CLKDIV1 , +NPCM7XX_CLK_PLLCON0 , +NPCM7XX_CLK_PLLCON1 , +NPCM7XX_CLK_SWRSTR , +NPCM7XX_CLK_IPSRST1 =0x20 /sizeof (uint32_t ), +NPCM7XX_CLK_IPSRST2 , +NPCM7XX_CLK_CLKEN2 , +NPCM7XX_CLK_CLKDIV2 , +NPCM7XX_CLK_CLKEN3 , +NPCM7XX_CLK_IPSRST3 , +NPCM7XX_CLK_WD0RCR , +NPCM7XX_CLK_WD1RCR , +NPCM7XX_CLK_WD2RCR , +NPCM7XX_CLK_SWRSTC1 , +NPCM7XX_CLK_SWRSTC2 , +NPCM7XX_CLK_SWRSTC3 , +NPCM7XX_CLK_SWRSTC4 , +NPCM7XX_CLK_PLLCON2 , +NPCM7XX_CLK_CLKDIV3 , +NPCM7XX_CLK_CORSTC , +NPCM7XX_CLK_PLLCONG , +NPCM7XX_CLK_AHBCKFI , +NPCM7XX_CLK_SECCNT , +NPCM7XX_CLK_CNTR25M , +NPCM7XX_CLK_NR_REGS , +}; + +typedef struct NPCM7xxCLKState { +SysBusDevice parent; + +MemoryRegion iomem; + +uint32_t regs[NPCM7XX_CLK_NR_REGS ]; + +/* Time reference for SECCNT and CNTR25M, initialized by power on reset */ +int64_t ref_ns; +}NPCM7xxCLKState ; + +#define TYPE_NPCM7XX_CLK "npcm7xx-clk" +#define NPCM7XX_CLK (obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX_CLK) + +#endif /* NPCM7XX_CLK_H */
PATCH 4/6 hw/timer: Add NPCM7xx Timer device model
In reply to Havard SkinnemoenThe NPCM730 and NPCM750 SoCs have three timer modules each holding five timers and some shared registers (e.g. interrupt status).
Each timer runs at 25 MHz divided by a prescaler, and counts down from a configurable initial value to zero. When zero is reached, the interrupt flag for the timer is set, and the timer is disabled (one-shot mode) or reloaded from its initial value (periodic mode).
This implementation is sufficient to boot a Linux kernel configured for NPCM750. Note that the kernel does not seem to actually turn on the interrupts.
--- MAINTAINERS | 2 + hw/timer/Makefile.objs | 1 + hw/timer/npcm7xx_timer.c | 437 +++++++++++++++++++++++++++++++ hw/timer/trace-events | 5 + include/hw/timer/npcm7xx_timer.h | 95 +++++++ 5 files changed, 540 insertions(+) create mode 100644 hw/timer/npcm7xx_timer.c create mode 100644 include/hw/timer/npcm7xx_timer.h
MAINTAINERS +2 -0
@@ -721,7 +721,9 @@ M: Tyrone Ting <[email protected]> L: [email protected] S: Supported F: hw/misc/npcm7xx* +F: hw/timer/npcm7xx* F: include/hw/misc/npcm7xx* +F: include/hw/timer/npcm7xx* nSeries M: Andrzej Zaborowski <[email protected]>
hw/timer/Makefile.objs +1 -0
@@ -14,6 +14,7 @@ common-obj-$(CONFIG_IMX) += imx_epit.o common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_timer.o common-obj-$(CONFIG_NRF51_SOC) += nrf51_timer.o common-obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o
hw/timer/npcm7xx_timer.c new file +437 -0
437 lines not on this page · raw message
hw/timer/trace-events +5 -0
@@ -66,6 +66,11 @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset" +# npcm7xx_timer.c +npcm7xx_timer_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 +npcm7xx_timer_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 +npcm7xx_timer_irq(const char *id, int timer, int state) "%s timer %d state %d" + # nrf51_timer.c nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
include/hw/timer/npcm7xx_timer.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 4/6] hw/timer: Add NPCM7xx Timer device model
Quoted 9 lines · Havard Skinnemoen
The NPCM730 and NPCM750 SoCs have three timer modules each holding five timers and some shared registers (e.g. interrupt status).
Each timer runs at 25 MHz divided by a prescaler, and counts down from a configurable initial value to zero. When zero is reached, the interrupt flag for the timer is set, and the timer is disabled (one-shot mode) or reloaded from its initial value (periodic mode).
Quoted 6 lines
This implementation is sufficient to boot a Linux kernel configured for NPCM750. Note that the kernel does not seem to actually turn on the interrupts.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
PATCH 5/6 hw/arm: Add NPCM730 and NPCM750 SoC models
In reply to Havard SkinnemoenThe Nuvoton NPCM7xx SoC family are used to implement Baseboard Management Controllers in servers. While the family includes four SoCs, this patch implements limited support for two of them: NPCM730 (targeted for Data Center applications) and NPCM750 (targeted for Enterprise applications).
This patch includes little more than the bare minimum needed to boot a Linux kernel built with NPCM7xx support in direct-kernel mode:
- Two Cortex-A9 CPU cores with built-in periperhals.
- Global Configuration Registers.
- Clock Management.
- 3 Timer Modules with 5 timers each.
- 4 serial ports.
The chips themselves have a lot more features, some of which will be added to the model at a later stage.
--- MAINTAINERS | 2 + hw/arm/Makefile.objs | 1 + hw/arm/npcm7xx.c | 328 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm7xx.h | 79 ++++++++++ 4 files changed, 410 insertions(+) create mode 100644 hw/arm/npcm7xx.c create mode 100644 include/hw/arm/npcm7xx.h
MAINTAINERS +2 -0
@@ -720,8 +720,10 @@ M: Havard Skinnemoen <[email protected]> M: Tyrone Ting <[email protected]> L: [email protected] S: Supported +F: hw/arm/npcm7xx* F: hw/misc/npcm7xx* F: hw/timer/npcm7xx* +F: include/hw/arm/npcm7xx* F: include/hw/misc/npcm7xx* F: include/hw/timer/npcm7xx*
hw/arm/Makefile.objs +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o +obj-$(CONFIG_NPCM7XX) += npcm7xx.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o
hw/arm/npcm7xx.c new file +328 -0
328 lines not on this page · raw message
include/hw/arm/npcm7xx.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 16 lines · Havard Skinnemoen
The Nuvoton NPCM7xx SoC family are used to implement Baseboard Management Controllers in servers. While the family includes four SoCs, this patch implements limited support for two of them: NPCM730 (targeted for Data Center applications) and NPCM750 (targeted for Enterprise applications).
This patch includes little more than the bare minimum needed to boot a Linux kernel built with NPCM7xx support in direct-kernel mode:
- Two Cortex-A9 CPU cores with built-in periperhals.
- Global Configuration Registers.
- Clock Management.
- 3 Timer Modules with 5 timers each.
- 4 serial ports.
Quoted 5 lines
The chips themselves have a lot more features, some of which will be added to the model at a later stage.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
This looks okay from my perspective. You will want to get Cedric or Peter to take a closer look though.
We have started adding about the systems that are supported by qemu, including how to boot the machine, what is supported and the limitations of the modelling. See docs/system/arm/aspeed.rst for an example.
Cheers,
Joel
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
In reply to Havard SkinnemoenQuoted 153 lines · Havard Skinnemoen
The Nuvoton NPCM7xx SoC family are used to implement Baseboard Management Controllers in servers. While the family includes four SoCs, this patch implements limited support for two of them: NPCM730 (targeted for Data Center applications) and NPCM750 (targeted for Enterprise applications).
This patch includes little more than the bare minimum needed to boot a Linux kernel built with NPCM7xx support in direct-kernel mode:
- Two Cortex-A9 CPU cores with built-in periperhals.
- Global Configuration Registers.
- Clock Management.
- 3 Timer Modules with 5 timers each.
- 4 serial ports.The chips themselves have a lot more features, some of which will be added to the model at a later stage.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- MAINTAINERS | 2 + hw/arm/Makefile.objs | 1 + hw/arm/npcm7xx.c | 328 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm7xx.h | 79 ++++++++++ 4 files changed, 410 insertions(+) create mode 100644 hw/arm/npcm7xx.c create mode 100644 include/hw/arm/npcm7xx.hMAINTAINERS +2
-0@@ -720,8 +720,10 @@ M: Havard Skinnemoen <[email protected]> M: Tyrone Ting <[email protected]> L: [email protected] S: Supported +F: hw/arm/npcm7xx* F: hw/misc/npcm7xx* F: hw/timer/npcm7xx* +F: include/hw/arm/npcm7xx* F: include/hw/misc/npcm7xx* F: include/hw/timer/npcm7xx*hw/arm/Makefile.objs +1
-0@@ -41,6 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o +obj-$(CONFIG_NPCM7XX) += npcm7xx.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.ohw/arm/npcm7xx.c new file +91
-0@@ -0,0 +1,328 @@ +/* +* Nuvoton NPCM7xx SoC family. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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 "exec/address-spaces.h" +#include "hw/arm/npcm7xx.h" +#include "hw/char/serial.h" +#include "hw/loader.h" +#include "hw/misc/unimp.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/units.h" +#include "sysemu/sysemu.h" + +/* The first half of the address space is reserved for DDR4 DRAM. */ +#define NPCM7XX_DRAM_BA (0x00000000) +#define NPCM7XX_DRAM_SZ (2 * GiB) + +/* +* This covers the whole MMIO space. We'll use this to catch any MMIO accesses +* that aren't handled by any device. +*/ +#define NPCM7XX_MMIO_BA (0x80000000) +#define NPCM7XX_MMIO_SZ (0x7FFD0000) + +/* Core system modules. */ +#define NPCM7XX_L2C_BA (0xF03FC000) +#define NPCM7XX_CPUP_BA (0xF03FE000) +#define NPCM7XX_GCR_BA (0xF0800000) +#define NPCM7XX_CLK_BA (0xF0801000) + +/* Memory blocks at the end of the address space */ +#define NPCM7XX_RAM2_BA (0xFFFD0000) +#define NPCM7XX_RAM2_SZ (128 * KiB) +#define NPCM7XX_ROM_BA (0xFFFF0000) +#define NPCM7XX_ROM_SZ (64 * KiB) + +/* +* Interrupt lines going into the GIC. This does not include internal Cortex-A9 +* interrupts. +*/ +enum NPCM7xxInterrupt { +NPCM7XX_UART0_IRQ =2 , +NPCM7XX_UART1_IRQ , +NPCM7XX_UART2_IRQ , +NPCM7XX_UART3_IRQ , +NPCM7XX_TIMER0_IRQ =32 ,/* Timer Module 0 */ +NPCM7XX_TIMER1_IRQ , +NPCM7XX_TIMER2_IRQ , +NPCM7XX_TIMER3_IRQ , +NPCM7XX_TIMER4_IRQ , +NPCM7XX_TIMER5_IRQ ,/* Timer Module 1 */ +NPCM7XX_TIMER6_IRQ , +NPCM7XX_TIMER7_IRQ , +NPCM7XX_TIMER8_IRQ , +NPCM7XX_TIMER9_IRQ , +NPCM7XX_TIMER10_IRQ ,/* Timer Module 2 */ +NPCM7XX_TIMER11_IRQ , +NPCM7XX_TIMER12_IRQ , +NPCM7XX_TIMER13_IRQ , +NPCM7XX_TIMER14_IRQ , +}; + +/* Register base address for each Timer Module */ +static const hwaddr npcm7xx_tim_addr[] = { +0xF0008000 , +0xF0009000 , +0xF000A000 , +}; + +/* Register base address for each 16550 UART */ +static const hwaddr npcm7xx_uart_addr[] = { +0xF0001000 , +0xF0002000 , +0xF0003000 , +0xF0004000 , +}; +
hw/arm/npcm7xx.c line 101
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+void npcm7xx_write_secondary_boot (ARMCPU *cpu,const struct arm_boot_info *info) +{ +/* +* The default smpboot stub halts the secondary CPU with a 'wfi' +* instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kernel +* does not send an IPI to wake it up, so the second CPU fails to boot. So +* we need to provide our own smpboot stub that can not use 'wfi', it has +* to spin the secondary CPU until the first CPU writes to the SCRPAD reg. +*/ +uint32_t smpboot[] = {
static const uint32 ?
Quoted 4 lines
hw/arm/npcm7xx.c new file +4
-0+0xe59f2018 ,/* ldr r2, bootreg_addr */ +0xe3a00000 ,/* mov r0, #0 */ +0xe5820000 ,/* str r0, [r2] */ + 0xe320f002, /* wfe */
hw/arm/npcm7xx.c line 115
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+0xe5921000 ,/* ldr r1, [r2] */ +0xe1110001 ,/* tst r1, r1 */ +0x0afffffb ,/* beq <wfe> */ +0xe12fff11 ,/* bx r1 */ + NPCM7XX_SMP_BOOTREG_ADDR, + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (smpboot); i++) { + smpboot[i] =tswap32 (smpboot[i]);
ah ! why do we need to swap the instructions ?
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+ } + +rom_add_blob_fixed ("smpboot" , smpboot,sizeof (smpboot), +NPCM7XX_SMP_LOADER_START ); +} + +static qemu_irq npcm7xx_irq (NPCM7xxState *s,int n) +{ +return qdev_get_gpio_in (DEVICE (&s->a9mpcore), n); +}
hw/arm/npcm7xx.c line 135
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+ +static void npcm7xx_init (Object *obj) +{ +NPCM7xxState *s =NPCM7XX (obj); +int i; + +for (i =0 ; i <NPCM7XX_MAX_NUM_CPUS ; i++) { + s->cpu[i] =ARM_CPU ( +object_new_with_props (ARM_CPU_TYPE_NAME ("cortex-a9" ), + obj,"cpu[*]" , &error_abort,NULL ));
why allocate ? Can't you use :
ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS];
and call object_initialize_child() ?
Quoted 33 lines
hw/arm/npcm7xx.c new file +33
-0+ } + +sysbus_init_child_obj (obj,"a9mpcore" , &s->a9mpcore, +sizeof (s->a9mpcore),TYPE_A9MPCORE_PRIV ); +sysbus_init_child_obj (obj,"gcr" ,OBJECT (&s->gcr),sizeof (s->gcr), +TYPE_NPCM7XX_GCR ); +sysbus_init_child_obj (obj,"clk" ,OBJECT (&s->clk),sizeof (s->clk), +TYPE_NPCM7XX_CLK ); + +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +sysbus_init_child_obj (obj,"tim[*]" ,OBJECT (&s->tim[i]), +sizeof (s->tim[i]),TYPE_NPCM7XX_TIMER ); + } +} + +static void npcm7xx_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxState *s =NPCM7XX (dev); +NPCM7xxClass *sc =NPCM7XX_GET_CLASS (s); +Error *err =NULL ; +int i; + +/* I/O space -- unimplemented unless overridden below. */ +create_unimplemented_device ("npcm7xx.io" ,NPCM7XX_MMIO_BA ,NPCM7XX_MMIO_SZ ); + +/* CPUs */ +if (s->num_cpus >NPCM7XX_MAX_NUM_CPUS ) { +warn_report ("%s: invalid number of CPUs %d, using maximum %d" , +object_get_typename (OBJECT (s)), s->num_cpus, +NPCM7XX_MAX_NUM_CPUS ); + s->num_cpus =NPCM7XX_MAX_NUM_CPUS ; + } +
hw/arm/npcm7xx.c line 178
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+for (i =0 ; i < s->num_cpus; i++) { +object_property_set_int (OBJECT (s->cpu[i]), +arm_cpu_mp_affinity (i,NPCM7XX_MAX_NUM_CPUS ), +"mp-affinity" , &error_abort); +object_property_set_int (OBJECT (s->cpu[i]),NPCM7XX_GIC_CPU_IF_ADDR , +"reset-cbar" , &error_abort); +object_property_set_bool (OBJECT (s->cpu[i]), true, +"reset-hivecs" , &error_abort); + +/* TODO: Not sure why this is needed. */
It's disabling the security extensions.
hw/arm/npcm7xx.c line 189
Quoted 11 lines
hw/arm/npcm7xx.c new file +11
-0+if (object_property_find (OBJECT (s->cpu[i]),"has_el3" ,NULL )) { +object_property_set_bool (OBJECT (s->cpu[i]), false,"has_el3" , + &error_abort); + } + +object_property_set_bool (OBJECT (s->cpu[i]), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + }
With this pattern, which initializes all possible CPU objects and only realizes the requested ones, some CPU objects are left unrealized in the QOM tree. It's is better to unparent them.
If the board has a fixed number of CPUs and you don't plan to activate only a few of them for debug/test, I would make the "num_cpus" a class property. See the Aspeed boards.
hw/arm/npcm7xx.c line 194
Quoted 5 lines
hw/arm/npcm7xx.c new file +5
-0+ +/* A9MPCORE peripherals */ +object_property_set_int (OBJECT (&s->a9mpcore), s->num_cpus,"num-cpu" , + &error_abort); +object_property_set_int (OBJECT (&s->a9mpcore),160 ,"num-irq" , &error_abort);
160 needs a define.
Quoted 220 lines
hw/arm/npcm7xx.c new file +134
-0+object_property_set_bool (OBJECT (&s->a9mpcore), true,"realized" , + &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->a9mpcore),0 ,NPCM7XX_CPUP_BA ); + +for (i =0 ; i < s->num_cpus; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (&s->a9mpcore), i, +qdev_get_gpio_in (DEVICE (s->cpu[i]),ARM_CPU_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->a9mpcore), i + s->num_cpus, +qdev_get_gpio_in (DEVICE (s->cpu[i]),ARM_CPU_FIQ )); + } + +/* L2 cache controller */ +sysbus_create_simple ("l2x0" ,NPCM7XX_L2C_BA ,NULL ); + +/* System Global Control Registers (GCR) */ +object_property_set_int (OBJECT (&s->gcr), sc->disabled_modules, +"disabled-modules" , &err); +object_property_set_bool (OBJECT (&s->gcr), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gcr),0 ,NPCM7XX_GCR_BA ); + +/* Clock Control Registers (CLK) */ +object_property_set_bool (OBJECT (&s->clk), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->clk),0 ,NPCM7XX_CLK_BA ); + +/* Timer Modules (TIM) */ +QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_tim_addr) !=ARRAY_SIZE (s->tim)); +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +Object *t =OBJECT (&s->tim[i]); +int first_irq; +int j; + +object_property_set_bool (t, true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (t),0 , npcm7xx_tim_addr[i]); + + first_irq =NPCM7XX_TIMER0_IRQ + i *NPCM7XX_TIMERS_PER_CTRL ; +for (j =0 ; j <NPCM7XX_TIMERS_PER_CTRL ; j++) { +qemu_irq irq =npcm7xx_irq (s, first_irq + j); +sysbus_connect_irq (SYS_BUS_DEVICE (t), j, irq); + } + } + +/* UART0..3 (16550 compatible) */ +for (i =0 ; i <ARRAY_SIZE (npcm7xx_uart_addr); i++) { +serial_mm_init (get_system_memory (), npcm7xx_uart_addr[i],2 , +npcm7xx_irq (s,NPCM7XX_UART0_IRQ + i),115200 , +serial_hd (i),DEVICE_LITTLE_ENDIAN ); + } + +/* RAM2 (SRAM) */ +memory_region_init_ram (&s->sram,OBJECT (dev),"ram2" , +NPCM7XX_RAM2_SZ , &err); +if (err) { +error_propagate (errp, err); +return ; + } +memory_region_add_subregion (get_system_memory (),NPCM7XX_RAM2_BA , &s->sram); + +/* Internal ROM */ +memory_region_init_rom (&s->irom,OBJECT (dev),"irom" ,NPCM7XX_ROM_SZ , &err); +if (err) { +error_propagate (errp, err); +return ; + } +memory_region_add_subregion (get_system_memory (),NPCM7XX_ROM_BA , &s->irom); + +/* External DDR4 SDRAM */ +memory_region_add_subregion (get_system_memory (),NPCM7XX_DRAM_BA , s->dram); +} + +static Property npcm7xx_properties[] = { +DEFINE_PROP_INT32 ("num-cpus" , NPCM7xxState, num_cpus,-1 ), +DEFINE_PROP_LINK ("dram" , NPCM7xxState, dram,TYPE_MEMORY_REGION , + MemoryRegion *), +DEFINE_PROP_END_OF_LIST (), +}; + +static void npcm7xx_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = npcm7xx_realize; + dc->user_creatable = false; +device_class_set_props (dc, npcm7xx_properties); +} + +static void npcm730_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxClass *nc =NPCM7XX_CLASS (oc); + +/* NPCM730 is optimized for data center use, so no graphics, etc. */ + nc->disabled_modules =0x00300395 ; +} + +static void npcm750_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxClass *nc =NPCM7XX_CLASS (oc); + +/* NPCM750 has everything */ + nc->disabled_modules =0x00000000 ; +} + +static const TypeInfo npcm7xx_soc_types[] = { + { + .name =TYPE_NPCM7XX , + .parent =TYPE_DEVICE , + .instance_size =sizeof (NPCM7xxState), + .instance_init = npcm7xx_init, + .class_size =sizeof (NPCM7xxClass), + .class_init = npcm7xx_class_init, + .abstract = true, + }, { + .name =TYPE_NPCM730 , + .parent =TYPE_NPCM7XX , + .class_init = npcm730_class_init, + }, { + .name =TYPE_NPCM750 , + .parent =TYPE_NPCM7XX , + .class_init = npcm750_class_init, + }, +}; + +DEFINE_TYPES (npcm7xx_soc_types);include/hw/arm/npcm7xx.h new file +79
-0@@ -0,0 +1,79 @@ +/* +* Nuvoton NPCM7xx SoC family. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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. +*/ +#ifndef NPCM7XX_H +#define NPCM7XX_H + +#include "hw/boards.h" +#include "hw/cpu/a9mpcore.h" +#include "hw/misc/npcm7xx_clk.h" +#include "hw/misc/npcm7xx_gcr.h" +#include "hw/timer/npcm7xx_timer.h" +#include "target/arm/cpu.h" + +#define NPCM7XX_MAX_NUM_CPUS (2) + +/* Magic addresses for setting up direct kernel booting and SMP boot stubs. */ +#define NPCM7XX_LOADER_START (0x00000000)/* Start of SDRAM */ +#define NPCM7XX_SMP_LOADER_START (0xFFFF0000)/* Boot ROM */ +#define NPCM7XX_SMP_BOOTREG_ADDR (0xF080013C)/* GCR.SCRPAD */ +#define NPCM7XX_GIC_CPU_IF_ADDR (0xF03FE100)/* GIC within A9 */ + +typedef struct NPCM7xxState { +DeviceState parent; + +ARMCPU *cpu[NPCM7XX_MAX_NUM_CPUS ]; +A9MPPrivState a9mpcore; +int32_t num_cpus; + +MemoryRegion sram; +MemoryRegion irom; +MemoryRegion *dram; + +NPCM7xxGCRState gcr; +NPCM7xxCLKState clk; +NPCM7xxTimerCtrlState tim[3 ]; +}NPCM7xxState ; + +#define TYPE_NPCM7XX "npcm7xx" +#define NPCM7XX (obj) OBJECT_CHECK(NPCM7xxState, (obj), TYPE_NPCM7XX) + +#define TYPE_NPCM730 "npcm730" +#define TYPE_NPCM750 "npcm750" + +typedef struct NPCM7xxClass { +DeviceClass parent; + +/* Bitmask of modules that are permanently disabled on this chip. */ +uint32_t disabled_modules; +}NPCM7xxClass ; + +#define NPCM7XX_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxClass, (klass), TYPE_NPCM7XX) +#define NPCM7XX_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxClass, (obj), TYPE_NPCM7XX) + +/** +* npcm7xx_write_secondary_boot - Write stub for booting secondary CPU. +* @cpu: The CPU to be booted. +* @info: Boot info structure for the board. +* +* This will write a short code stub to the internal ROM that will keep the +* secondary CPU spinning until the primary CPU writes an address to the SCRPAD +* register in the GCR, after which the secondary CPU will jump there. +*/ +extern void npcm7xx_write_secondary_boot (ARMCPU *cpu, +const struct arm_boot_info *info); + +#endif /* NPCM7XX_H */
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 10 lines · Cédric Le Goater
Quoted 1 line · Havard Skinnemoen
+void npcm7xx_write_secondary_boot(ARMCPU *cpu, const struct
arm_boot_info*info)hw/arm/npcm7xx.c
Quoted 4 lines
hw/arm/npcm7xx.c new file +4
-0+{ +/* +* The default smpboot stub halts the secondary CPU with a 'wfi' +* instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kernel
Quoted 1 line
+ * does not send an IPI to wake it up, so the second CPU fails to
boot. So
Quoted 9 lines
Quoted 1 line
+ * we need to provide our own smpboot stub that can not use 'wfi',
it has
Quoted 1 line
+ * to spin the secondary CPU until the first CPU writes to the
SCRPAD reg.
Review
Quoted 2 lines
(quoted diff) +2
-0+ */ + uint32_t smpboot[] = {static const uint32 ?
I think that would be unsafe due to the byte swapping, but I'll do it if we can get rid of that somehow.
Quoted 16 lines
Quoted 5 lines
hw/arm/npcm7xx.c new file +4
-0+0xe59f2018 ,/* ldr r2, bootreg_addr */ +0xe3a00000 ,/* mov r0, #0 */ +0xe5820000 ,/* str r0, [r2] */ + 0xe320f002, /* wfe */hw/arm/npcm7xx.c line 115
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+0xe5921000 ,/* ldr r1, [r2] */ +0xe1110001 ,/* tst r1, r1 */ +0x0afffffb ,/* beq <wfe> */ +0xe12fff11 ,/* bx r1 */ + NPCM7XX_SMP_BOOTREG_ADDR, + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (smpboot); i++) { + smpboot[i] =tswap32 (smpboot[i]);
Quoted 2 lines
ah ! why do we need to swap the instructions ?
I probably stole this from
https://elixir.bootlin.com/qemu/latest/source/hw/arm/exynos4210.c#L134
although there are several other examples of this pattern.
IIUC, it's necessary for the target to see the instruction words specified above when its endianness is different from the host. But perhaps I can specify it as a byte array instead. Would that work?
If that works, I should be able to drop the byte swapping and make the smpboot array constant. I don't think I'll be able to test it thoroughly though, as I don't have access to a big endian host.
Quoted 12 lines
+static void
npcm7xx_init(Object *obj)hw/arm/npcm7xx.c line 135
Quoted 8 lines
hw/arm/npcm7xx.c new file +8
-0+{ +NPCM7xxState *s =NPCM7XX (obj); +int i; + +for (i =0 ; i <NPCM7XX_MAX_NUM_CPUS ; i++) { + s->cpu[i] =ARM_CPU ( +object_new_with_props (ARM_CPU_TYPE_NAME ("cortex-a9" ), + obj,"cpu[*]" , &error_abort,NULL ));why allocate ? Can't you use :
Quoted 4 lines
ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS];and call
object_initialize_child()?
OK, I will try that.
Quoted 6 lines
+ for (i = 0; i <
s->num_cpus; i++) {Review
Quoted 2 lines
(quoted diff) +2
-0+ object_property_set_int(OBJECT(s->cpu[i]), + arm_cpu_mp_affinity(i,
NPCM7XX_MAX_NUM_CPUS),Review
Quoted 2 lines
(quoted diff) +2
-0+ "mp-affinity", &error_abort); + object_property_set_int(OBJECT(s->cpu[i]),
Quoted 9 lines
NPCM7XX_GIC_CPU_IF_ADDR,hw/arm/npcm7xx.c line 178
Quoted 5 lines
hw/arm/npcm7xx.c new file +5
-0+ "reset-cbar", &error_abort); +object_property_set_bool (OBJECT (s->cpu[i]), true, +"reset-hivecs" , &error_abort); + +/* TODO: Not sure why this is needed. */ It's disabling the security extensions.
Thanks, I'll update the comment.
Quoted 15 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if (object_property_find(OBJECT(s->cpu[i]), "has_el3", NULL)) { + object_property_set_bool(OBJECT(s->cpu[i]), false,"
has_el3",hw/arm/npcm7xx.c
Quoted 4 lines
hw/arm/npcm7xx.c new file +4
-0+ &error_abort); + } + + object_property_set_bool(OBJECT(s->cpu[i]), true, "realized",&err);
hw/arm/npcm7xx.c line 189
Quoted 5 lines
hw/arm/npcm7xx.c new file +5
-0+if (err) { +error_propagate (errp, err); +return ; + } + }
Quoted 8 lines
With this pattern, which initializes all possible CPU objects and only realizes the requested ones, some CPU objects are left unrealized in the QOM tree. It's is better to unparent them.
If the board has a fixed number of CPUs and you don't plan to activate only a few of them for debug/test, I would make the "
num_cpus" a class property. See the Aspeed boards.
Will do, thanks.
Quoted 10 lines
hw/arm/npcm7xx.c
Quoted 3 lines
hw/arm/npcm7xx.c new file +3
-0+ +/* A9MPCORE peripherals */ + object_property_set_int(OBJECT(&s->a9mpcore), s->num_cpus,"num-cpu",
Review
Quoted 2 lines
(quoted diff) +2
-0+ &error_abort); + object_property_set_int(OBJECT(&s->a9mpcore), 160, "num-irq",
&error_abort);160 needs a define.
Will do, thanks.
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 36 lines · Havard Skinnemoen
On Tue, Jun 9, 2020 at 12:24 AM Cédric Le Goater <[email protected] <mailto:[email protected]>> wrote:
On 5/21/20 9:21 PM, Havard Skinnemoen wrote:
> +voidnpcm7xx_write_secondary_boot(ARMCPU *cpu, const struct arm_boot_info *info)> +{
> + /*
> + * The default smpboot stub halts the secondary CPU with a 'wfi' > + * instruction, but thearch/arm/mach-npcm/platsmp.cin the Linux kernel > + * does not send an IPI to wake it up, so the second CPU fails to boot. So > + * we need to provide our own smpboot stub that can not use 'wfi', it has > + * to spin the secondary CPU until the first CPU writes to the SCRPAD reg. > + */
> +uint32_tsmpboot[] = {static const uint32 ?
I think that would be unsafe due to the byte swapping, but I'll do it if we can get rid of that somehow.
Quoted 6 lines
+ 0xe59f2018, /* ldr r2,
bootreg_addr*/ + 0xe3a00000, /* mov r0, #0 */
+ 0xe5820000, /* str r0, [r2] */ + 0xe320f002, /* wfe */
+ 0xe5921000, /* ldr r1, [r2] */ + 0xe1110001, /* tst r1, r1 */Quoted 8 lines
+ 0x0afffffb, /* beq <wfe> */
+ 0xe12fff11, /* bx r1 */
+NPCM7XX_SMP_BOOTREG_ADDR,
+ };
+ int i;
+
+ for (i = 0; i <ARRAY_SIZE(smpboot); i++) {
+ smpboot[i] =tswap32(smpboot[i]);
Quoted 4 lines
ah ! why do we need to swap the instructions ?
I probably stole this from https://elixir.bootlin.com/qemu/latest/source/hw/arm/exynos4210.c#L134 although there are several other examples of this pattern.
Some don't some do. This is a bit confusing.
Peter, should we fix the boards not doing the tswap in the secondary bootloader ?
I still have access to a PP64 BE host to test.
Thanks,
C.
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 1 line · Cédric Le Goater
Some don't some do. This is a bit confusing.
Probably the usual thing of people not noticing that they need to do something for big-endian hosts and nobody testing the minor platforms there.
Quoted 2 lines
Peter, should we fix the boards not doing the tswap in the secondary bootloader ?
Yes, we should -- it's an actual bug as well as just not being very consistent.
Quoted 1 line
I still have access to a PP64 BE host to test.
In an ideal world the bugs would cause "make check" and/or "make check-acceptance" to fail on BE hosts :-)
thanks
-- PMM
Re: [PATCH 5/6] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 10 lines · Peter Maydell
Quoted 1 line · Cédric Le Goater
Some don't some do. This is a bit confusing.
Probably the usual thing of people not noticing that they need to do something for big-endian hosts and nobody testing the minor platforms there.
Quoted 2 lines
Peter, should we fix the boards not doing the tswap in the secondary bootloader ?
Quoted 7 lines
Yes, we should -- it's an actual bug as well as just not being very consistent.
Quoted 1 line
I still have access to a PP64 BE host to test.
In an ideal world the bugs would cause "make check" and/or "make check-acceptance" to fail on BE hosts :-)
I gave it a try manually with an Aspeed machine and the kernel fails to boot.
Download an OpenBMC witherspoon flash image :
and run :
qemu-system-arm -M witherspoon-bmc -nic user -drive file=obmc-phosphor-image-witherspoon.ubi.mtd,format=raw,if=mtd -nographic
The kernel hangs right after activating the translation :
#ifdef CONFIG_MMU
ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg orrne r0, r0, #1 @ MMU enabled movne r1, #0xfffffffd @ domain 0 = client bic r6, r6, #1 << 31 @ 32-bit translation system bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer mcrne p15, 0, r1, c3, c0, 0 @ load domain access control mcrne p15, 0, r6, c2, c0, 2 @ load ttb control #endif mcr p15, 0, r0, c7, c5, 4 @ ISB *there* --> mcr p15, 0, r0, c1, c0, 0 @ load control register mrc p15, 0, r0, c1, c0, 0 @ and read it back mov r0, #0 mcr p15, 0, r0, c7, c5, 4 @ ISB mov pc, r12
C.
PATCH 6/6 hw/arm: Add two NPCM7xx-based machines
In reply to Havard SkinnemoenThis adds two new machines:
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
- quanta-gsj: A board with a NPCM730 chip.
They rely on the NPCM7xx SoC device to do the heavy lifting. They are almost completely identical at the moment, apart from the SoC type, which currently only changes the reset contents of one register (GCR.MDLR), but they might grow apart a bit more as more functionality is added.
Both machines can boot the Linux kernel into /bin/sh.
--- hw/arm/Makefile.objs | 2 +- hw/arm/npcm7xx_boards.c | 108 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm7xx.h | 19 +++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm7xx_boards.c
hw/arm/Makefile.objs +1 -1
@@ -41,7 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o -obj-$(CONFIG_NPCM7XX) += npcm7xx.o +obj-$(CONFIG_NPCM7XX) += npcm7xx.o npcm7xx_boards.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o
hw/arm/npcm7xx_boards.c new file +108 -0
108 lines not on this page · raw message
include/hw/arm/npcm7xx.h +19 -0
@@ -30,6 +30,25 @@#define NPCM7XX_SMP_BOOTREG_ADDR (0xF080013C)/* GCR.SCRPAD */ #define NPCM7XX_GIC_CPU_IF_ADDR (0xF03FE100)/* GIC within A9 */ +typedef struct NPCM7xxMachine { +MachineState parent; +}NPCM7xxMachine ; + +#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx") +#define NPCM7XX_MACHINE (obj) \ + OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE) + +typedef struct NPCM7xxMachineClass { +MachineClass parent; + +const char *soc_type; +}NPCM7xxMachineClass ; + +#define NPCM7XX_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxMachineClass, (klass), TYPE_NPCM7XX_MACHINE) +#define NPCM7XX_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxMachineClass, (obj), TYPE_NPCM7XX_MACHINE) + typedef struct NPCM7xxState { DeviceState parent;
Signature · 1 line
2.27.0.rc0.183.gde8f92d652-goog
Re: [PATCH 6/6] hw/arm: Add two NPCM7xx-based machines
Quoted 5 lines · Havard Skinnemoen
This adds two new machines:
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
- quanta-gsj: A board with a NPCM730 chip.
You could note that these are the two boards supported by OpenBMC.
Quoted 10 lines
They rely on the NPCM7xx SoC device to do the heavy lifting. They are almost completely identical at the moment, apart from the SoC type, which currently only changes the reset contents of one register (GCR.MDLR), but they might grow apart a bit more as more functionality is added.
Both machines can boot the Linux kernel into
/bin/sh.Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
Re: [PATCH 6/6] hw/arm: Add two NPCM7xx-based machines
In reply to Havard SkinnemoenQuoted 11 lines · Havard Skinnemoen
This adds two new machines:
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
- quanta-gsj: A board with a NPCM730 chip.They rely on the NPCM7xx SoC device to do the heavy lifting. They are almost completely identical at the moment, apart from the SoC type, which currently only changes the reset contents of one register (GCR.MDLR), but they might grow apart a bit more as more functionality is added.
Quoted 4 lines
Both machines can boot the Linux kernel into
/bin/sh.Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>
Quoted 165 lines
--- hw/arm/Makefile.objs | 2 +- hw/arm/npcm7xx_boards.c | 108 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/npcm7xx.h | 19 +++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm7xx_boards.chw/arm/Makefile.objs +1
-1@@ -41,7 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o -obj-$(CONFIG_NPCM7XX) += npcm7xx.o +obj-$(CONFIG_NPCM7XX) += npcm7xx.o npcm7xx_boards.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.ohw/arm/npcm7xx_boards.c new file +108
-0@@ -0,0 +1,108 @@ +/* +* Machine definitions for boards featuring an NPCM7xx SoC. +* +* Copyright 2020 Google LLC +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* 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/npcm7xx.h" +#include "hw/core/cpu.h" +#include "qapi/error.h" +#include "qemu/units.h" + +static struct arm_boot_info npcm7xx_binfo = { + .loader_start =NPCM7XX_LOADER_START , + .smp_loader_start =NPCM7XX_SMP_LOADER_START , + .smp_bootreg_addr =NPCM7XX_SMP_BOOTREG_ADDR , + .gic_cpu_if_addr =NPCM7XX_GIC_CPU_IF_ADDR , + .write_secondary_boot = npcm7xx_write_secondary_boot, + .board_id =-1 , +}; + +static void npcm7xx_machine_init (MachineState *machine) +{ +NPCM7xxMachineClass *nmc =NPCM7XX_MACHINE_GET_CLASS (machine); +NPCM7xxState *soc; + + soc =NPCM7XX (object_new_with_props (nmc->soc_type,OBJECT (machine),"soc" , + &error_abort,NULL )); +object_property_set_int (OBJECT (soc), machine->smp.cpus,"num-cpus" , + &error_abort); +object_property_set_link (OBJECT (soc),OBJECT (machine->ram),"dram" , + &error_abort); +object_property_set_bool (OBJECT (soc), true,"realized" , &error_abort); + + npcm7xx_binfo.ram_size = machine->ram_size; + npcm7xx_binfo.nb_cpus = machine->smp.cpus; + +arm_load_kernel (soc->cpu[0 ], machine, &npcm7xx_binfo); +} + +static void npcm7xx_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = npcm7xx_machine_init; + mc->max_cpus =NPCM7XX_MAX_NUM_CPUS ; + mc->default_cpus =NPCM7XX_MAX_NUM_CPUS ; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; + mc->default_ram_id ="ram" ; +} + +/* +* Schematics: +* https://github.com/Nuvoton-Israel/nuvoton-info/blob/master/npcm7xx-poleg/evaluation-board/board_deliverables/NPCM750x_EB_ver.A1.1_COMPLETE.pdf +*/ +static void npcm750_evb_machine_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxMachineClass *nmc =NPCM7XX_MACHINE_CLASS (oc); +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="Nuvoton NPCM750 Evaluation Board (Cortex A9)" ; + nmc->soc_type =TYPE_NPCM750 ; + mc->default_ram_size =512 * MiB; +}; + +static void gsj_machine_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxMachineClass *nmc =NPCM7XX_MACHINE_CLASS (oc); +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="Quanta GSJ (Cortex A9)" ; + nmc->soc_type =TYPE_NPCM730 ; + mc->default_ram_size =512 * MiB; +}; + +static const TypeInfo npcm7xx_machine_types[] = { + { + .name =TYPE_NPCM7XX_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (NPCM7xxMachine), + .class_size =sizeof (NPCM7xxMachineClass), + .class_init = npcm7xx_machine_class_init, + .abstract = true, + }, { + .name =MACHINE_TYPE_NAME ("npcm750-evb" ), + .parent =TYPE_NPCM7XX_MACHINE , + .class_init = npcm750_evb_machine_class_init, + }, { + .name =MACHINE_TYPE_NAME ("quanta-gsj" ), + .parent =TYPE_NPCM7XX_MACHINE , + .class_init = gsj_machine_class_init, + }, +}; + +DEFINE_TYPES (npcm7xx_machine_types)include/hw/arm/npcm7xx.h +19
-0@@ -30,6 +30,25 @@#define NPCM7XX_SMP_BOOTREG_ADDR (0xF080013C)/* GCR.SCRPAD */ #define NPCM7XX_GIC_CPU_IF_ADDR (0xF03FE100)/* GIC within A9 */ +typedef struct NPCM7xxMachine { +MachineState parent; +}NPCM7xxMachine ; + +#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx") +#define NPCM7XX_MACHINE (obj) \ + OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE) + +typedef struct NPCM7xxMachineClass { +MachineClass parent; + +const char *soc_type; +}NPCM7xxMachineClass ; + +#define NPCM7XX_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxMachineClass, (klass), TYPE_NPCM7XX_MACHINE) +#define NPCM7XX_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxMachineClass, (obj), TYPE_NPCM7XX_MACHINE) + typedef struct NPCM7xxState { DeviceState parent;
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
Broken pipe/tmp/qemu-test/src/tests/qtest/libqtest.c:166: kill_qemu() tried to terminate QEMU process but encountered exit status 1 (expected 0)
TEST iotest-qcow2: 089
ERROR - too few tests run (expected 68, got 21)
make: *** [check-qtest-aarch64] Error 1
make: *** Waiting for unfinished jobs....
TEST iotest-qcow2: 090
TEST iotest-qcow2: 097
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=935cc7f201a94a2e865cf081636a2cf4', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-evkby52n/src/docker-src.2020-05-22-00.39.52.17361:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=935cc7f201a94a2e865cf081636a2cf4
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-evkby52n/src'
make: *** [docker-run-test-quick@centos7] Error 2
real 17m34.256s
user 0m9.006s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 4 lines · Havard Skinnemoen
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot
a minimal Linux kernel. This includes device models for:
Does anyone have comments on this series? I'm currently finishing up a second patch series that adds flash support and a few other things so qemu can boot a full OpenBMC flash image built for npcm7xx.
If you prefer, I can combine them both into one series and send it to the list.
This series can be found here:
https://patchwork.kernel.org/project/qemu-devel/list/?series=291809
Thanks,
Havard
Quoted 8 lines · Havard Skinnemoen
Quoted 3 lines · Havard Skinnemoen
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot a minimal Linux kernel. This includes device models for:
Does anyone have comments on this series? I'm currently finishing up a second patch series that adds flash support and a few other things so qemu can boot a full OpenBMC flash image built for npcm7xx.
I had a look and they appear good to me. Note that I'm less in to the gory details of Qemu than some of our other reviewers, so you should seek a more detailed review from someone else.
I look forward further support so I can test the OpenBMC kernel against Nuvoton boards in the same way as the Aspeed ones.
Cheers,
Joel
Quoted 8 lines
If you prefer, I can combine them both into one series and send it to the list.
This series can be found here: https://patchwork.kernel.org/project/qemu-devel/list/?series=291809
Thanks,
Havard
Quoted 7 lines · Joel Stanley
I had a look and they appear good to me. Note that I'm less in to the gory details of Qemu than some of our other reviewers, so you should seek a more detailed review from someone else.
I look forward further support so I can test the OpenBMC kernel against Nuvoton boards in the same way as the Aspeed ones.
Great to hear that, and thanks for your review. I hope to post an updated patchset soon.
Havard
Quoted 9 lines · Havard Skinnemoen
On Thu, May 21, 2020 at 12:21 PM Havard Skinnemoen <[email protected] <mailto:[email protected]>> wrote:
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot a minimal Linux kernel. This includes device models for:
Does anyone have comments on this series? I'm currently finishing up a second patch series that adds flash support and a few other things so qemu can boot a full OpenBMC flash image built for npcm7xx.
If you prefer, I can combine them both into one series and send it to the list.
The first series was nicely presented I think, but you can extend it in v2. Documentation needs an update in :
docs/system/target-arm.rst
Thanks,
C.
Quoted 4 lines · Cédric Le Goater
The first series was nicely presented I think, but you can extend it in v2. Documentation needs an update in :
docs/system/target-arm.rst
To expand on that: the new boards should have at least some basic documentation in a new docs/system/arm/something.rst (we have one .rst file usually for each "family" of boards which are similar enough to make sense to document as a group), which is added to the toctree in target-arm.rst (note that it is supposed to be kept in alpha-order-of-document-title-text). aspeed.rst should give an idea of what ought to be documented: a basic summary of what the machine is, what is supported, what is not implemented, any machine options that the board has, that sort of thing.
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 1 line · Cédric Le Goater
The first series was nicely presented I think, but you can extend it in
v2.
Quoted 3 lines
Documentation needs an update in :
docs/system/target-arm.rst
Quoted 10 lines
To expand on that: the new boards should have at least some basic documentation in a new
docs/system/arm/something.rst(we have one .rst file usually for each "family" of boards which are similar enough to make sense to document as a group), which is added to the toctree intarget-arm.rst(note that it is supposed to be kept in alpha-order-of-document-title-text).aspeed.rstshould give an idea of what ought to be documented: a basic summary of what the machine is, what is supported, what is not implemented, any machine options that the board has, that sort of thing.
Thanks for the feedback. I will include documentation in v2 of this patchset, and also address your other comments.
Havard