Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
v6 cover Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
I also pushed this and the previous two patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-6].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot an OpenBMC image built for quanta-gsj. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash Controller
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. At the end of the series, qemu can boot an OpenBMC image built for one of these boards with some minor modifications.
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.
Changes since v5:
- Boot ROM included, as a git submodule and a binary blob, and loaded by default, so the -bios option is usually not necessary anymore.
- Two acceptance tests added (openbmc image boot, and direct kernel boot).
- npcm7xx_load_kernel() moved to SoC code.
- NPCM7XX_TIMER_REF_HZ definition moved to CLK header.
- Comments added clarifying available SPI flash chip selects.
- Error handling adjustments:
- Errors from CPU and GCR realization are propagated through the SoC since they may be triggered by user-configurable parameters.
- Machine init uses error_fatal instead of error_abort for SoC realization flash init. This makes error messages more helpful.
- Comments added to indicate whether peripherals may fail to realize.
- Use ERRP_GUARD() instead of Error *err when possible.
- Default CPU type is now set, and attempting to set it to anything else will fail.
- Format string fixes (use HWADDR_PRIx, etc.)
- Simplified memory size encoding and error checking in npcm7xx_gcr.
- Encapsulate non-obvious pointer subtraction into helper functions in the FIU and TIMER modules.
- Incorporate review feedback into the FIU module:
- Add select/deselect trace events.
- Use npcm7xx_fiu_{de,}select() consistently.
- Use extract/deposit in more places for consistency.
- Use -Wimplicit-fallthrough compatible fallthrough comments.
- Use qdev_init_gpio_out_named instead of sysbus_init_irq for chip selects.
- Incorporate review feedback into the TIMER module:
- Assert that we never pause a timer that has already expired, instead of trying to handle it. This should be safe since QEMU_CLOCK_VIRTUAL is stopped while this code is running.
- Simplify the switch blocks in the read and write handlers.
I made a change to error out if a flash drive was not specified, but reverted it because it caused make check to fail (qom-test). When specifying a NULL block device, the m25p flash device initializes its in-memory storage with 0xff and doesn't attempt to write anything back. This seems correct to me.
Changes since v4:
- OTP cleanups suggested by Philippe Mathieu-Daudé.
- Added fuse array definitions based on public Nuvoton bootblock code.
- Moved class structure to .c file since it's only used internally.
- Readability improvements.
- Split the first patch and folded parts of it into three other patches so that CONFIG_NPCM7XX is only enabled after the initial NPCM7xx machine support is added.
- DRAM init moved to machine init code.
- Consistently use lower-case hex literals.
- Switched to fine-grained unimplemented devices, based on public bootblock source code. Added a tiny SRAM that got left out previously.
- Simplified error handling in npcm7xx_realize() since the board code will abort anyway, and SoCs are not hot-pluggable.
Changes since v3:
- License headers are now GPL v2-or-later throughout.
- Added vmstate throughout (except the memory controller, which doesn't really have any state worth saving). Successfully booted a gsj image with two stop/savevm/quit/loadvm cycles along the way.
- JFFS2 really doesn't like it if I let qemu keep running after savevm, and then jump back in time with loadvm. I assume this is expected.
- Fixed an error API violation in npcm7xx_realize, removed pointless error check after object_property_set_link().
- Switched the OTP device to use an embedded array instead of a g_malloc0'd one because I couldn't figure out how to set up vmstate for the latter.
Changes since v2:
- Simplified the MAINTAINERS entry.
- Added link to OpenPOWER jenkins for gsj BMC images.
- Reverted the smpboot change, back to byte swapping.
- Adapted to upstream API changes:
- sysbus_init_child_obj -> object_initialize_child
- object_property_set_bool -> qdev_realize / sysbus_realize
- ssi_create_slave_no_init -> qdev_new
- qdev_init_nofail -> qdev_realize_and_unref
- ssi_auto_connect_slaves removed
- Moved Boot ROM loading from soc to machine init.
- Plumbed power-on-straps property from GCR to the machine init code so it can be properly initialized. Turns out npcm750 memory init doesn't work without this. npcm730 is fine either way, though I'm not sure why.
- Reworked the flash init code so it looks more like aspeed (i.e. the flash device gets added even if there's no drive).
Changes since v1 (requested by reviewers):
- Clarify the source of CLK reset values.
- Made smpboot a constant byte array, eliinated byte swapping.
- NPCM7xxState now stores an array of ARMCPUs, not pointers to ARMCPUs.
- Clarify why EL3 is disabled.
- Introduce NPCM7XX_NUM_IRQ constant.
- Set the number of CPUs according to SoC variant, and disallow command line overrides (i.e. you can no longer override the number of CPUs with the -smp parameter). This is trying to follow the spirit of
https://patchwork.kernel.org/patch/11595407/.
- Switch register operations to DEVICE_LITTLE_ENDIAN throughout.
- Machine documentation added (new patch).
Changes since v1 to support flash booting:
- GCR reset value changes to get past memory initialization when booting from flash (patches 2 and 5):
- INTCR2 now indicates that the DDR controller is initialized.
- INTCR3 is initialized according to DDR memory size. A realize() method was implemented to achieve this.
- Refactor the machine initialization a bit to make it easier to drop in machine-specific flash initialization (patch 6).
- Extend the series with additional patches to enable booting from flash:
- Boot ROM (through the -bios option).
- OTP (fuse) controller.
- Memory Controller stub (just enough to skip memory training).
- Flash controller.
- Board-specific flash initialization.
Thanks for reviewing,
Havard
Havard Skinnemoen (13):
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
roms: Add virtual Boot ROM for NPCM7xx SoCs
hw/arm: Load -bios image as a boot ROM for npcm7xx hw/nvram: NPCM7xx OTP device model
hw/mem: Stubbed out NPCM7xx Memory Controller model hw/ssi: NPCM7xx Flash Interface Unit device model hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj docs/system: Add Nuvoton machine documentation tests/acceptance: console boot tests for quanta-gsj
docs/system/arm/nuvoton.rst | 90 +++++ docs/system/target-arm.rst | 1 + Makefile | 1 + default-configs/arm-softmmu.mak | 1 + include/hw/arm/npcm7xx.h | 111 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 72 ++++ include/hw/misc/npcm7xx_gcr.h | 76 ++++ include/hw/nvram/npcm7xx_otp.h | 88 ++++ include/hw/ssi/npcm7xx_fiu.h | 100 +++++ include/hw/timer/npcm7xx_timer.h | 96 +++++ hw/arm/npcm7xx.c | 500 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 195 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 234 +++++++++++ hw/misc/npcm7xx_gcr.c | 227 +++++++++++ hw/nvram/npcm7xx_otp.c | 424 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 539 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 489 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 8 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/mem/Makefile.objs | 1 + hw/misc/Makefile.objs | 2 + hw/misc/trace-events | 8 + hw/nvram/Makefile.objs | 1 + hw/ssi/Makefile.objs | 1 + hw/ssi/trace-events | 11 + hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 65 +++ 35 files changed, 3488 insertions(+) create mode 100644 docs/system/arm/nuvoton.rst create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 include/hw/mem/npcm7xx_mc.h create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 include/hw/ssi/npcm7xx_fiu.h create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/arm/npcm7xx.c create mode 100644 hw/arm/npcm7xx_boards.c create mode 100644 hw/mem/npcm7xx_mc.c create mode 100644 hw/misc/npcm7xx_clk.c create mode 100644 hw/misc/npcm7xx_gcr.c create mode 100644 hw/nvram/npcm7xx_otp.c create mode 100644 hw/ssi/npcm7xx_fiu.c create mode 100644 hw/timer/npcm7xx_timer.c create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 1/13 hw/misc: Add NPCM7xx System Global Control Registers device model
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) and DDR memory initialization; 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.
--- include/hw/misc/npcm7xx_gcr.h | 76 ++++++++++++ hw/misc/npcm7xx_gcr.c | 227 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 ++ hw/arm/Kconfig | 3 + hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 6 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 hw/misc/npcm7xx_gcr.c
include/hw/misc/npcm7xx_gcr.h new file +76 -0
@@ -0,0 +1,76 @@ +/* +* 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 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. +*/ +#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; +uint32_t reset_intcr3; +}NPCM7xxGCRState ; + +#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" +#define NPCM7XX_GCR (obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR) + +#endif /* NPCM7XX_GCR_H */
hw/misc/npcm7xx_gcr.c new file +227 -0
227 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -747,6 +747,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/*/npcm7xx* +F: include/hw/*/npcm7xx* + nSeries M: Andrzej Zaborowski <[email protected]> M: Peter Maydell <[email protected]>
hw/arm/Kconfig +3 -0
@@ -354,6 +354,9 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP +config NPCM7XX + bool + config FSL_IMX25 bool select IMX
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/trace-events +4 -0
@@ -111,6 +111,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"
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 01/13] hw/misc: Add NPCM7xx System Global Control Registers device model
Quoted 24 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) and DDR memory initialization; 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 Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/misc/npcm7xx_gcr.h | 76 ++++++++++++ hw/misc/npcm7xx_gcr.c | 227 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 ++ hw/arm/Kconfig | 3 + hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 6 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 hw/misc/npcm7xx_gcr.c
...
Quoted 8 lines
hw/misc/npcm7xx_gcr.c new file +8
-0+static void npcm7xx_gcr_realize (DeviceState *dev,Error **errp) +{ +ERRP_GUARD (); +NPCM7xxGCRState *s =NPCM7XX_GCR (dev); +uint64_t dram_size; +Object *obj; + + obj =object_property_get_link (OBJECT (dev),"dram-mr" , errp);
hw/misc/npcm7xx_gcr.c line 149
Quoted 10 lines
hw/misc/npcm7xx_gcr.c new file +10
-0+if (!obj) { +error_prepend (errp,"%s: required dram-mr link not found: " , __func__); +return ; + } + dram_size =memory_region_size (MEMORY_REGION (obj)); +if (!is_power_of_2 (dram_size) || + dram_size <NPCM7XX_GCR_MIN_DRAM_SIZE || + dram_size >NPCM7XX_GCR_MAX_DRAM_SIZE ) { +error_setg (errp,"%s: unsupported DRAM size %" PRIu64, + __func__, dram_size);
Nitpicking if you ever have to respin, please use size_to_str() here,
hw/misc/npcm7xx_gcr.c line 154
Quoted 5 lines
hw/misc/npcm7xx_gcr.c new file +5
-0+error_append_hint (errp, +"DRAM size must be a power of two between %" PRIu64 +" and %" PRIu64" MiB, inclusive.\n" , +NPCM7XX_GCR_MIN_DRAM_SIZE / MiB, +NPCM7XX_GCR_MAX_DRAM_SIZE / MiB);
and here.
Quoted 10 lines
hw/misc/npcm7xx_gcr.c new file +10
-0+return ; + } + +/* Power-on reset value */ + s->reset_intcr3 =0x00001002 ; + +/* +* The GMMAP (Graphics Memory Map) field is used by u-boot to detect the +* DRAM size, and is normally initialized by the boot block as part of DRAM +* training. However, since we don't have a complete emulation of the
hw/misc/npcm7xx_gcr.c line 174
Quoted 10 lines
hw/misc/npcm7xx_gcr.c new file +10
-0+* memory controller and try to make it look like it has already been +* initialized, the boot block will skip this initialization, and we need +* to make sure this field is set correctly up front. +* +* WARNING: some versions of u-boot only looks at bits 8 and 9, so 2 GiB of +* DRAM will be interpreted as 128 MiB. +* +* 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 ;
Nice :)
Quoted 1 line
+}
[...]
PATCH v6 2/13 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.
--- include/hw/misc/npcm7xx_clk.h | 72 +++++++++++ hw/misc/npcm7xx_clk.c | 234 ++++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 4 files changed, 311 insertions(+) create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 hw/misc/npcm7xx_clk.c
include/hw/misc/npcm7xx_clk.h new file +72 -0
@@ -0,0 +1,72 @@ +/* +* 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 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. +*/ +#ifndef NPCM7XX_CLK_H +#define NPCM7XX_CLK_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* +* The reference clock frequency for the timer modules, and the SECCNT and +* CNTR25M registers in this module, is always 25 MHz. +*/ +#define NPCM7XX_TIMER_REF_HZ (25000000) + +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 */
hw/misc/npcm7xx_clk.c new file +234 -0
234 lines not on this page · raw message
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/trace-events +4 -0
@@ -111,6 +111,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
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 3/13 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.
--- include/hw/timer/npcm7xx_timer.h | 96 ++++++ hw/timer/npcm7xx_timer.c | 489 +++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + 4 files changed, 591 insertions(+) create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/timer/npcm7xx_timer.c
include/hw/timer/npcm7xx_timer.h new file +96 -0
@@ -0,0 +1,96 @@ +/* +* Nuvoton NPCM7xx Timer Controller +* +* 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 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. +*/ +#ifndef NPCM7XX_TIMER_H +#define NPCM7XX_TIMER_H + +#include "exec/memory.h" +#include "hw/sysbus.h" +#include "qemu/timer.h" + +/* Each Timer Module (TIM) instance holds five 25 MHz timers. */ +#define NPCM7XX_TIMERS_PER_CTRL (5) + +/** +* enum NPCM7xxTimerRegisters - 32-bit register indices. +*/ +enum NPCM7xxTimerRegisters { +NPCM7XX_TIMER_TCSR0 , +NPCM7XX_TIMER_TCSR1 , +NPCM7XX_TIMER_TICR0 , +NPCM7XX_TIMER_TICR1 , +NPCM7XX_TIMER_TDR0 , +NPCM7XX_TIMER_TDR1 , +NPCM7XX_TIMER_TISR , +NPCM7XX_TIMER_WTCR , +NPCM7XX_TIMER_TCSR2 , +NPCM7XX_TIMER_TCSR3 , +NPCM7XX_TIMER_TICR2 , +NPCM7XX_TIMER_TICR3 , +NPCM7XX_TIMER_TDR2 , +NPCM7XX_TIMER_TDR3 , +NPCM7XX_TIMER_TCSR4 =0x0040 /sizeof (uint32_t ), +NPCM7XX_TIMER_TICR4 =0x0048 /sizeof (uint32_t ), +NPCM7XX_TIMER_TDR4 =0x0050 /sizeof (uint32_t ), +NPCM7XX_TIMER_NR_REGS , +}; + +typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState ; + +/** +* struct NPCM7xxTimer - Individual timer state. +* @irq: GIC interrupt line to fire on expiration (if enabled). +* @qtimer: QEMU timer that notifies us on expiration. +* @expires_ns: Absolute virtual expiration time. +* @remaining_ns: Remaining time until expiration if timer is paused. +* @tcsr: The Timer Control and Status Register. +* @ticr: The Timer Initial Count Register. +*/ +typedef struct NPCM7xxTimer { +NPCM7xxTimerCtrlState *ctrl; + +qemu_irq irq; +QEMUTimer qtimer; +int64_t expires_ns; +int64_t remaining_ns; + +uint32_t tcsr; +uint32_t ticr; +}NPCM7xxTimer ; + +/** +* struct NPCM7xxTimerCtrlState - Timer Module device state. +* @parent: System bus device. +* @iomem: Memory region through which registers are accessed. +* @tisr: The Timer Interrupt Status Register. +* @wtcr: The Watchdog Timer Control Register. +* @timer: The five individual timers managed by this module. +*/ +struct NPCM7xxTimerCtrlState { +SysBusDevice parent; + +MemoryRegion iomem; + +uint32_t tisr; +uint32_t wtcr; + +NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL ]; +}; + +#define TYPE_NPCM7XX_TIMER "npcm7xx-timer" +#define NPCM7XX_TIMER (obj) \ + OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER) + +#endif /* NPCM7XX_TIMER_H */
hw/timer/npcm7xx_timer.c new file +489 -0
489 lines not on this page · raw message
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/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"
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 03/13] hw/timer: Add NPCM7xx Timer device model
Quoted 23 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).
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]>Reviewed-by Joel Stanley <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/timer/npcm7xx_timer.h | 96 ++++++ hw/timer/npcm7xx_timer.c | 489 +++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + 4 files changed, 591 insertions(+) create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/timer/npcm7xx_timer.c
...
Quoted 75 lines
hw/timer/npcm7xx_timer.c new file +75
-0+static hwaddr npcm7xx_tcsr_index (hwaddr reg) +{ +switch (reg) { +case NPCM7XX_TIMER_TCSR0 : +return 0 ; +case NPCM7XX_TIMER_TCSR1 : +return 1 ; +case NPCM7XX_TIMER_TCSR2 : +return 2 ; +case NPCM7XX_TIMER_TCSR3 : +return 3 ; +case NPCM7XX_TIMER_TCSR4 : +return 4 ; +default : +g_assert_not_reached (); + } +} + +static hwaddr npcm7xx_ticr_index (hwaddr reg) +{ +switch (reg) { +case NPCM7XX_TIMER_TICR0 : +return 0 ; +case NPCM7XX_TIMER_TICR1 : +return 1 ; +case NPCM7XX_TIMER_TICR2 : +return 2 ; +case NPCM7XX_TIMER_TICR3 : +return 3 ; +case NPCM7XX_TIMER_TICR4 : +return 4 ; +default : +g_assert_not_reached (); + } +} + +static hwaddr npcm7xx_tdr_index (hwaddr reg) +{ +switch (reg) { +case NPCM7XX_TIMER_TDR0 : +return 0 ; +case NPCM7XX_TIMER_TDR1 : +return 1 ; +case NPCM7XX_TIMER_TDR2 : +return 2 ; +case NPCM7XX_TIMER_TDR3 : +return 3 ; +case NPCM7XX_TIMER_TDR4 : +return 4 ; +default : +g_assert_not_reached (); + } +} + +static uint64_t npcm7xx_timer_read (void *opaque,hwaddr offset,unsigned size) +{ +NPCM7xxTimerCtrlState *s = opaque; +uint64_t value =0 ; +hwaddr reg; + + reg = offset /sizeof (uint32_t ); +switch (reg) { +case NPCM7XX_TIMER_TCSR0 : +case NPCM7XX_TIMER_TCSR1 : +case NPCM7XX_TIMER_TCSR2 : +case NPCM7XX_TIMER_TCSR3 : +case NPCM7XX_TIMER_TCSR4 : + value = s->timer[npcm7xx_tcsr_index (reg)].tcsr; +break ; + +case NPCM7XX_TIMER_TICR0 : +case NPCM7XX_TIMER_TICR1 : +case NPCM7XX_TIMER_TICR2 : +case NPCM7XX_TIMER_TICR3 : +case NPCM7XX_TIMER_TICR4 :
hw/timer/npcm7xx_timer.c line 297
Quoted 10 lines
hw/timer/npcm7xx_timer.c new file +10
-0+ value = s->timer[npcm7xx_ticr_index (reg)].ticr; +break ; + +case NPCM7XX_TIMER_TDR0 : +case NPCM7XX_TIMER_TDR1 : +case NPCM7XX_TIMER_TDR2 : +case NPCM7XX_TIMER_TDR3 : +case NPCM7XX_TIMER_TDR4 : + value =npcm7xx_timer_read_tdr (&s->timer[npcm7xx_tdr_index (reg)]); +break ;
Thanks for adding the register index getters, I'm not sure this is a matter of taste, but I find it easier to review.
Quoted 20 lines
hw/timer/npcm7xx_timer.c new file +20
-0+ +case NPCM7XX_TIMER_TISR : + value = s->tisr; +break ; + +case NPCM7XX_TIMER_WTCR : + value = s->wtcr; +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid offset 0x%04" HWADDR_PRIx"\n" , + __func__, offset); +break ; + } + +trace_npcm7xx_timer_read (DEVICE (s)->canonical_path, offset, value); + +return value; +}
...
Re: [PATCH v6 03/13] hw/timer: Add NPCM7xx Timer device model
In reply to Havard SkinnemoenQuoted 23 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).
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]>Reviewed-by Joel Stanley <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/timer/npcm7xx_timer.h | 96 ++++++ hw/timer/npcm7xx_timer.c | 489 +++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + 4 files changed, 591 insertions(+) create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/timer/npcm7xx_timer.c
...
Quoted 6 lines
hw/timer/npcm7xx_timer.c new file +6
-0+/* +* Raise the interrupt line if there's a pending interrupt and interrupts are +* enabled for this timer. If not, lower it. +*/ +static void npcm7xx_timer_check_interrupt (NPCM7xxTimer *t) +{
hw/timer/npcm7xx_timer.c line 98
Quoted 10 lines
hw/timer/npcm7xx_timer.c new file +10
-0+NPCM7xxTimerCtrlState *tc = t->ctrl; +int index =npcm7xx_timer_index (tc, t); + +if ((t->tcsr &NPCM7XX_TCSR_IE ) && (tc->tisr &BIT (index))) { +qemu_irq_raise (t->irq); +trace_npcm7xx_timer_irq (DEVICE (tc)->canonical_path, index,1 ); + }else { +qemu_irq_lower (t->irq); +trace_npcm7xx_timer_irq (DEVICE (tc)->canonical_path, index,0 ); + }
Maybe simpler:
bool pending = (t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index)); trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending); qemu_set_irq(t->irq, pending);
Anyway,
PATCH v6 4/13 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.
--- include/hw/arm/npcm7xx.h | 85 ++++++++ hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/Makefile.objs | 1 + 4 files changed, 498 insertions(+) create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 hw/arm/npcm7xx.c
include/hw/arm/npcm7xx.h new file +85 -0
@@ -0,0 +1,85 @@ +/* +* 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 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. +*/ +#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) + +/* The first half of the address space is reserved for DDR4 DRAM. */ +#define NPCM7XX_DRAM_BA (0x00000000) +#define NPCM7XX_DRAM_SZ (2 * GiB) + +/* 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; + +MemoryRegion sram; +MemoryRegion irom; +MemoryRegion ram3; +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; +/* Number of CPU cores enabled in this SoC class (may be 1 or 2). */ +uint32_t num_cpus; +}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_load_kernel - Loads memory with everything needed to boot +* @machine - The machine containing the SoC to be booted. +* @soc - The SoC containing the CPU to be booted. +* +* This will set up the ARM boot info structure for the specific NPCM7xx +* derivative and call arm_load_kernel() to set up loading of the kernel, etc. +* into memory, if requested by the user. +*/ +void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc); + +#endif /* NPCM7XX_H */
hw/arm/npcm7xx.c new file +407 -0
407 lines not on this page · raw message
hw/arm/Kconfig +5 -0
@@ -356,6 +356,11 @@ config XLNX_VERSAL config NPCM7XX bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP config FSL_IMX25 bool
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
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 04/13] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 327 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]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 85 ++++++++ hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/Makefile.objs | 1 + 4 files changed, 498 insertions(+) create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 hw/arm/npcm7xx.cinclude/hw/arm/npcm7xx.h new file +85
-0@@ -0,0 +1,85 @@ +/* +* 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 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. +*/ +#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) + +/* The first half of the address space is reserved for DDR4 DRAM. */ +#define NPCM7XX_DRAM_BA (0x00000000) +#define NPCM7XX_DRAM_SZ (2 * GiB) + +/* 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; + +MemoryRegion sram; +MemoryRegion irom; +MemoryRegion ram3; +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; +/* Number of CPU cores enabled in this SoC class (may be 1 or 2). */ +uint32_t num_cpus; +}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_load_kernel - Loads memory with everything needed to boot +* @machine - The machine containing the SoC to be booted. +* @soc - The SoC containing the CPU to be booted. +* +* This will set up the ARM boot info structure for the specific NPCM7xx +* derivative and call arm_load_kernel() to set up loading of the kernel, etc. +* into memory, if requested by the user. +*/ +void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc); + +#endif /* NPCM7XX_H */ hw/arm/npcm7xx.c new file +199
-0@@ -0,0 +1,407 @@ +/* +* 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 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 "exec/address-spaces.h" +#include "hw/arm/boot.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" + +/* +* 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) + +/* Internal AHB SRAM */ +#define NPCM7XX_RAM3_BA (0xc0008000) +#define NPCM7XX_RAM3_SZ (4 * KiB) + +/* 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 , +}; + +/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ +#define NPCM7XX_NUM_IRQ (160) + +/* 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 , +}; + +static 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[] = { +0xe59f2018 ,/* ldr r2, bootreg_addr */ +0xe3a00000 ,/* mov r0, #0 */ +0xe5820000 ,/* str r0, [r2] */ +0xe320f002 ,/* wfe */ +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]); + } + +rom_add_blob_fixed ("smpboot" , smpboot,sizeof (smpboot), +NPCM7XX_SMP_LOADER_START ); +} + +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 , +}; + +void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc) +{ +NPCM7xxClass *sc =NPCM7XX_GET_CLASS (soc); + + npcm7xx_binfo.ram_size = machine->ram_size; + npcm7xx_binfo.nb_cpus = sc->num_cpus; + +arm_load_kernel (&soc->cpu[0 ], machine, &npcm7xx_binfo); +} + +static qemu_irq npcm7xx_irq (NPCM7xxState *s,int n) +{ +return qdev_get_gpio_in (DEVICE (&s->a9mpcore), n); +} + +static void npcm7xx_init (Object *obj) +{ +NPCM7xxState *s =NPCM7XX (obj); +int i; + +for (i =0 ; i <NPCM7XX_MAX_NUM_CPUS ; i++) { +object_initialize_child (obj,"cpu[*]" , &s->cpu[i], +ARM_CPU_TYPE_NAME ("cortex-a9" )); + } + +object_initialize_child (obj,"a9mpcore" , &s->a9mpcore,TYPE_A9MPCORE_PRIV ); +object_initialize_child (obj,"gcr" , &s->gcr,TYPE_NPCM7XX_GCR ); +object_property_add_alias (obj,"power-on-straps" ,OBJECT (&s->gcr), +"power-on-straps" ); +object_initialize_child (obj,"clk" , &s->clk,TYPE_NPCM7XX_CLK ); + +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +object_initialize_child (obj,"tim[*]" , &s->tim[i],TYPE_NPCM7XX_TIMER ); + } +} + +static void npcm7xx_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxState *s =NPCM7XX (dev); +NPCM7xxClass *nc =NPCM7XX_GET_CLASS (s); +int i; + +if (memory_region_size (s->dram) >NPCM7XX_DRAM_SZ ) { +error_setg (errp,"%s: NPCM7xx cannot address more than %" PRIu64 +" MiB of DRAM" , __func__,NPCM7XX_DRAM_SZ / MiB); +return ; + } + +/* CPUs */ +for (i =0 ; i < nc->num_cpus; i++) { +object_property_set_int (OBJECT (&s->cpu[i]),"mp-affinity" , +arm_cpu_mp_affinity (i,NPCM7XX_MAX_NUM_CPUS ), + &error_abort); +object_property_set_int (OBJECT (&s->cpu[i]),"reset-cbar" , +NPCM7XX_GIC_CPU_IF_ADDR , &error_abort); +object_property_set_bool (OBJECT (&s->cpu[i]),"reset-hivecs" , true, + &error_abort); + +/* Disable security extensions. */ +object_property_set_bool (OBJECT (&s->cpu[i]),"has_el3" , false, + &error_abort); + +if (!qdev_realize (DEVICE (&s->cpu[i]),NULL , errp)) {
hw/arm/npcm7xx.c line 209
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+return ; + } + } + +/* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */ +object_property_set_int (OBJECT (&s->a9mpcore),"num-cpu" , nc->num_cpus, + &error_abort); +object_property_set_int (OBJECT (&s->a9mpcore),"num-irq" ,NPCM7XX_NUM_IRQ , + &error_abort); +sysbus_realize (SYS_BUS_DEVICE (&s->a9mpcore), &error_abort);
shouldn't we test the return value and use errp ? I don't know what was agreed upon.
Quoted 13 lines
hw/arm/npcm7xx.c new file +13
-0+sysbus_mmio_map (SYS_BUS_DEVICE (&s->a9mpcore),0 ,NPCM7XX_CPUP_BA ); + +for (i =0 ; i < nc->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 + nc->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). Can fail due to user input. */
hw/arm/npcm7xx.c line 232
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+object_property_set_int (OBJECT (&s->gcr),"disabled-modules" , + nc->disabled_modules, &error_abort); +object_property_add_const_link (OBJECT (&s->gcr),"dram-mr" ,OBJECT (s->dram)); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gcr), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gcr),0 ,NPCM7XX_GCR_BA ); + +/* Clock Control Registers (CLK). Cannot fail. */ +sysbus_realize (SYS_BUS_DEVICE (&s->clk), &error_abort);
same here.
hw/arm/npcm7xx.c line 242
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+sysbus_mmio_map (SYS_BUS_DEVICE (&s->clk),0 ,NPCM7XX_CLK_BA ); + +/* Timer Modules (TIM). Cannot fail. */ +QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_tim_addr) !=ARRAY_SIZE (s->tim)); +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +SysBusDevice *sbd =SYS_BUS_DEVICE (&s->tim[i]); +int first_irq; +int j; + +sysbus_realize (sbd, &error_abort);
and here.
Quoted 194 lines
hw/arm/npcm7xx.c new file +165
-0+sysbus_mmio_map (sbd,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 (sbd, 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 , &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_RAM2_BA , &s->sram); + +/* RAM3 (SRAM) */ +memory_region_init_ram (&s->ram3,OBJECT (dev),"ram3" , +NPCM7XX_RAM3_SZ , &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_RAM3_BA , &s->ram3); + +/* Internal ROM */ +memory_region_init_rom (&s->irom,OBJECT (dev),"irom" ,NPCM7XX_ROM_SZ , + &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_ROM_BA , &s->irom); + +create_unimplemented_device ("npcm7xx.shm" ,0xc0001000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.vdmx" ,0xe0800000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pcierc" ,0xe1000000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.kcs" ,0xf0007000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.rng" ,0xf000b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.adc" ,0xf000c000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gfxi" ,0xf000e000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[0]" ,0xf0010000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[1]" ,0xf0011000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[2]" ,0xf0012000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[3]" ,0xf0013000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[4]" ,0xf0014000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[5]" ,0xf0015000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[6]" ,0xf0016000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[7]" ,0xf0017000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[0]" ,0xf0080000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[1]" ,0xf0081000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[2]" ,0xf0082000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[3]" ,0xf0083000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[4]" ,0xf0084000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[5]" ,0xf0085000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[6]" ,0xf0086000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[7]" ,0xf0087000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[8]" ,0xf0088000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[9]" ,0xf0089000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[10]" ,0xf008a000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[11]" ,0xf008b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[12]" ,0xf008c000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[13]" ,0xf008d000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[14]" ,0xf008e000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[15]" ,0xf008f000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.espi" ,0xf009f000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.peci" ,0xf0100000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.siox[1]" ,0xf0101000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.siox[2]" ,0xf0102000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pwm[0]" ,0xf0103000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pwm[1]" ,0xf0104000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[0]" ,0xf0180000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[1]" ,0xf0181000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[2]" ,0xf0182000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[3]" ,0xf0183000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[4]" ,0xf0184000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[5]" ,0xf0185000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[6]" ,0xf0186000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[7]" ,0xf0187000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pspi1" ,0xf0200000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pspi2" ,0xf0201000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.ahbpci" ,0xf0400000 ,1 * MiB); +create_unimplemented_device ("npcm7xx.mcphy" ,0xf05f0000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.gmac1" ,0xf0802000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.gmac2" ,0xf0804000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.ehci" ,0xf0806000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.ohci" ,0xf0807000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.vcd" ,0xf0810000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.ece" ,0xf0820000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.vdma" ,0xf0822000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.emc1" ,0xf0825000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.emc2" ,0xf0826000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[0]" ,0xf0830000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[1]" ,0xf0831000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[2]" ,0xf0832000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[3]" ,0xf0833000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[4]" ,0xf0834000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[5]" ,0xf0835000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[6]" ,0xf0836000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[7]" ,0xf0837000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[8]" ,0xf0838000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[9]" ,0xf0839000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.sd" ,0xf0840000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.mmc" ,0xf0842000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.pcimbx" ,0xf0848000 ,512 * KiB); +create_unimplemented_device ("npcm7xx.aes" ,0xf0858000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.des" ,0xf0859000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.sha" ,0xf085a000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.secacc" ,0xf085b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.spixcs0" ,0xf8000000 ,16 * MiB); +create_unimplemented_device ("npcm7xx.spixcs1" ,0xf9000000 ,16 * MiB); +create_unimplemented_device ("npcm7xx.spix" ,0xfb001000 ,4 * KiB); +} + +static Property npcm7xx_properties[] = { +DEFINE_PROP_LINK ("dram-mr" , 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 ; + nc->num_cpus =2 ; +} + +static void npcm750_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxClass *nc =NPCM7XX_CLASS (oc); + +/* NPCM750 has 2 cores and a full set of peripherals */ + nc->disabled_modules =0x00000000 ; + nc->num_cpus =2 ; +} + +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);hw/arm/Kconfig +5
-0@@ -356,6 +356,11 @@ config XLNX_VERSAL config NPCM7XX bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP config FSL_IMX25 boolhw/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
Re: [PATCH v6 04/13] hw/arm: Add NPCM730 and NPCM750 SoC models
+Markus Armbruster
Quoted 334 lines · Cédric Le Goater
Quoted 332 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]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 85 ++++++++ hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/Makefile.objs | 1 + 4 files changed, 498 insertions(+) create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 hw/arm/npcm7xx.cinclude/hw/arm/npcm7xx.h new file +85
-0@@ -0,0 +1,85 @@ +/* +* 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 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. +*/ +#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) + +/* The first half of the address space is reserved for DDR4 DRAM. */ +#define NPCM7XX_DRAM_BA (0x00000000) +#define NPCM7XX_DRAM_SZ (2 * GiB) + +/* 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; + +MemoryRegion sram; +MemoryRegion irom; +MemoryRegion ram3; +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; +/* Number of CPU cores enabled in this SoC class (may be 1 or 2). */ +uint32_t num_cpus; +}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_load_kernel - Loads memory with everything needed to boot +* @machine - The machine containing the SoC to be booted. +* @soc - The SoC containing the CPU to be booted. +* +* This will set up the ARM boot info structure for the specific NPCM7xx +* derivative and call arm_load_kernel() to set up loading of the kernel, etc. +* into memory, if requested by the user. +*/ +void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc); + +#endif /* NPCM7XX_H */ hw/arm/npcm7xx.c new file +204
-0@@ -0,0 +1,407 @@ +/* +* 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 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 "exec/address-spaces.h" +#include "hw/arm/boot.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" + +/* +* 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) + +/* Internal AHB SRAM */ +#define NPCM7XX_RAM3_BA (0xc0008000) +#define NPCM7XX_RAM3_SZ (4 * KiB) + +/* 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 , +}; + +/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ +#define NPCM7XX_NUM_IRQ (160) + +/* 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 , +}; + +static 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[] = { +0xe59f2018 ,/* ldr r2, bootreg_addr */ +0xe3a00000 ,/* mov r0, #0 */ +0xe5820000 ,/* str r0, [r2] */ +0xe320f002 ,/* wfe */ +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]); + } + +rom_add_blob_fixed ("smpboot" , smpboot,sizeof (smpboot), +NPCM7XX_SMP_LOADER_START ); +} + +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 , +}; + +void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc) +{ +NPCM7xxClass *sc =NPCM7XX_GET_CLASS (soc); + + npcm7xx_binfo.ram_size = machine->ram_size; + npcm7xx_binfo.nb_cpus = sc->num_cpus; + +arm_load_kernel (&soc->cpu[0 ], machine, &npcm7xx_binfo); +} + +static qemu_irq npcm7xx_irq (NPCM7xxState *s,int n) +{ +return qdev_get_gpio_in (DEVICE (&s->a9mpcore), n); +} + +static void npcm7xx_init (Object *obj) +{ +NPCM7xxState *s =NPCM7XX (obj); +int i; + +for (i =0 ; i <NPCM7XX_MAX_NUM_CPUS ; i++) { +object_initialize_child (obj,"cpu[*]" , &s->cpu[i], +ARM_CPU_TYPE_NAME ("cortex-a9" )); + } + +object_initialize_child (obj,"a9mpcore" , &s->a9mpcore,TYPE_A9MPCORE_PRIV ); +object_initialize_child (obj,"gcr" , &s->gcr,TYPE_NPCM7XX_GCR ); +object_property_add_alias (obj,"power-on-straps" ,OBJECT (&s->gcr), +"power-on-straps" ); +object_initialize_child (obj,"clk" , &s->clk,TYPE_NPCM7XX_CLK ); + +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +object_initialize_child (obj,"tim[*]" , &s->tim[i],TYPE_NPCM7XX_TIMER ); + } +} + +static void npcm7xx_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxState *s =NPCM7XX (dev); +NPCM7xxClass *nc =NPCM7XX_GET_CLASS (s); +int i; + +if (memory_region_size (s->dram) >NPCM7XX_DRAM_SZ ) { +error_setg (errp,"%s: NPCM7xx cannot address more than %" PRIu64 +" MiB of DRAM" , __func__,NPCM7XX_DRAM_SZ / MiB); +return ; + } + +/* CPUs */ +for (i =0 ; i < nc->num_cpus; i++) { +object_property_set_int (OBJECT (&s->cpu[i]),"mp-affinity" , +arm_cpu_mp_affinity (i,NPCM7XX_MAX_NUM_CPUS ), + &error_abort); +object_property_set_int (OBJECT (&s->cpu[i]),"reset-cbar" , +NPCM7XX_GIC_CPU_IF_ADDR , &error_abort); +object_property_set_bool (OBJECT (&s->cpu[i]),"reset-hivecs" , true, + &error_abort); + +/* Disable security extensions. */ +object_property_set_bool (OBJECT (&s->cpu[i]),"has_el3" , false, + &error_abort); + +if (!qdev_realize (DEVICE (&s->cpu[i]),NULL , errp)) { +return ; + } + } + +/* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */
Quoted 8 lines
hw/arm/npcm7xx.c line 209
Quoted 5 lines
hw/arm/npcm7xx.c new file +5
-0+object_property_set_int (OBJECT (&s->a9mpcore),"num-cpu" , nc->num_cpus, + &error_abort); +object_property_set_int (OBJECT (&s->a9mpcore),"num-irq" ,NPCM7XX_NUM_IRQ , + &error_abort); +sysbus_realize (SYS_BUS_DEVICE (&s->a9mpcore), &error_abort);shouldn't we test the return value and use errp ? I don't know what was agreed upon.
I'm not sure if I got it 100% right, but what I tried to do was to see which submodules could possibly fail due to user input, and propagate errors from those modules only.
For example, the GCR can fail if the user-provided memory size can't be encoded into registers, so that one clearly needs to be propagated.
Other modules don't take any parameters at all, so they can only fail due to programming errors, hence error_abort.
I wasn't able to find any way command line options could cause the a9mpcore module to fail, but that's one of the cases I'm very unsure about, so I'll be happy to propagate errors from that if you (or anyone else) think it's needed.
I'm also not sure about the CPUs, but ended up going the other way since there's a -cpu option, and it's plausible that the user could cause it to fail even though I couldn't find any specific options to trigger an error.
Quoted 17 lines
Quoted 17 lines
hw/arm/npcm7xx.c new file +17
-0+sysbus_mmio_map (SYS_BUS_DEVICE (&s->a9mpcore),0 ,NPCM7XX_CPUP_BA ); + +for (i =0 ; i < nc->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 + nc->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). Can fail due to user input. */ +object_property_set_int (OBJECT (&s->gcr),"disabled-modules" , + nc->disabled_modules, &error_abort); +object_property_add_const_link (OBJECT (&s->gcr),"dram-mr" ,OBJECT (s->dram)); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gcr), errp)) {
Quoted 8 lines
hw/arm/npcm7xx.c line 232
Quoted 6 lines
hw/arm/npcm7xx.c new file +6
-0+return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gcr),0 ,NPCM7XX_GCR_BA ); + +/* Clock Control Registers (CLK). Cannot fail. */ +sysbus_realize (SYS_BUS_DEVICE (&s->clk), &error_abort);same here.
This module doesn't take any parameters, and it doesn't implement the realize() method, so any error could only be caused by a programming error.
Quoted 208 lines
hw/arm/npcm7xx.c line 242
Quoted 10 lines
hw/arm/npcm7xx.c new file +10
-0+sysbus_mmio_map (SYS_BUS_DEVICE (&s->clk),0 ,NPCM7XX_CLK_BA ); + +/* Timer Modules (TIM). Cannot fail. */ +QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_tim_addr) !=ARRAY_SIZE (s->tim)); +for (i =0 ; i <ARRAY_SIZE (s->tim); i++) { +SysBusDevice *sbd =SYS_BUS_DEVICE (&s->tim[i]); +int first_irq; +int j; + +sysbus_realize (sbd, &error_abort);and here.
Quoted 194 lines
hw/arm/npcm7xx.c new file +165
-0+sysbus_mmio_map (sbd,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 (sbd, 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 , &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_RAM2_BA , &s->sram); + +/* RAM3 (SRAM) */ +memory_region_init_ram (&s->ram3,OBJECT (dev),"ram3" , +NPCM7XX_RAM3_SZ , &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_RAM3_BA , &s->ram3); + +/* Internal ROM */ +memory_region_init_rom (&s->irom,OBJECT (dev),"irom" ,NPCM7XX_ROM_SZ , + &error_abort); +memory_region_add_subregion (get_system_memory (),NPCM7XX_ROM_BA , &s->irom); + +create_unimplemented_device ("npcm7xx.shm" ,0xc0001000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.vdmx" ,0xe0800000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pcierc" ,0xe1000000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.kcs" ,0xf0007000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.rng" ,0xf000b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.adc" ,0xf000c000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gfxi" ,0xf000e000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[0]" ,0xf0010000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[1]" ,0xf0011000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[2]" ,0xf0012000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[3]" ,0xf0013000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[4]" ,0xf0014000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[5]" ,0xf0015000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[6]" ,0xf0016000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.gpio[7]" ,0xf0017000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[0]" ,0xf0080000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[1]" ,0xf0081000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[2]" ,0xf0082000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[3]" ,0xf0083000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[4]" ,0xf0084000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[5]" ,0xf0085000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[6]" ,0xf0086000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[7]" ,0xf0087000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[8]" ,0xf0088000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[9]" ,0xf0089000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[10]" ,0xf008a000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[11]" ,0xf008b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[12]" ,0xf008c000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[13]" ,0xf008d000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[14]" ,0xf008e000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.smbus[15]" ,0xf008f000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.espi" ,0xf009f000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.peci" ,0xf0100000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.siox[1]" ,0xf0101000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.siox[2]" ,0xf0102000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pwm[0]" ,0xf0103000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pwm[1]" ,0xf0104000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[0]" ,0xf0180000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[1]" ,0xf0181000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[2]" ,0xf0182000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[3]" ,0xf0183000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[4]" ,0xf0184000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[5]" ,0xf0185000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[6]" ,0xf0186000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.mft[7]" ,0xf0187000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pspi1" ,0xf0200000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.pspi2" ,0xf0201000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.ahbpci" ,0xf0400000 ,1 * MiB); +create_unimplemented_device ("npcm7xx.mcphy" ,0xf05f0000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.gmac1" ,0xf0802000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.gmac2" ,0xf0804000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.ehci" ,0xf0806000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.ohci" ,0xf0807000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.vcd" ,0xf0810000 ,64 * KiB); +create_unimplemented_device ("npcm7xx.ece" ,0xf0820000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.vdma" ,0xf0822000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.emc1" ,0xf0825000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.emc2" ,0xf0826000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[0]" ,0xf0830000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[1]" ,0xf0831000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[2]" ,0xf0832000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[3]" ,0xf0833000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[4]" ,0xf0834000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[5]" ,0xf0835000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[6]" ,0xf0836000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[7]" ,0xf0837000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[8]" ,0xf0838000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.usbd[9]" ,0xf0839000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.sd" ,0xf0840000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.mmc" ,0xf0842000 ,8 * KiB); +create_unimplemented_device ("npcm7xx.pcimbx" ,0xf0848000 ,512 * KiB); +create_unimplemented_device ("npcm7xx.aes" ,0xf0858000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.des" ,0xf0859000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.sha" ,0xf085a000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.secacc" ,0xf085b000 ,4 * KiB); +create_unimplemented_device ("npcm7xx.spixcs0" ,0xf8000000 ,16 * MiB); +create_unimplemented_device ("npcm7xx.spixcs1" ,0xf9000000 ,16 * MiB); +create_unimplemented_device ("npcm7xx.spix" ,0xfb001000 ,4 * KiB); +} + +static Property npcm7xx_properties[] = { +DEFINE_PROP_LINK ("dram-mr" , 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 ; + nc->num_cpus =2 ; +} + +static void npcm750_class_init (ObjectClass *oc,void *data) +{ +NPCM7xxClass *nc =NPCM7XX_CLASS (oc); + +/* NPCM750 has 2 cores and a full set of peripherals */ + nc->disabled_modules =0x00000000 ; + nc->num_cpus =2 ; +} + +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);hw/arm/Kconfig +5
-0@@ -356,6 +356,11 @@ config XLNX_VERSAL config NPCM7XX bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP config FSL_IMX25 boolhw/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
Re: [PATCH v6 04/13] hw/arm: Add NPCM730 and NPCM750 SoC models
Quoted 35 lines · Havard Skinnemoen
+Markus Armbruster
Quoted 32 lines · Cédric Le Goater
Quoted 30 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]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 85 ++++++++ hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/Makefile.objs | 1 + 4 files changed, 498 insertions(+) create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 hw/arm/npcm7xx.c
...
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
hw/arm/npcm7xx.c new file +28
-0+static void npcm7xx_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxState *s =NPCM7XX (dev); +NPCM7xxClass *nc =NPCM7XX_GET_CLASS (s); +int i; + +if (memory_region_size (s->dram) >NPCM7XX_DRAM_SZ ) { +error_setg (errp,"%s: NPCM7xx cannot address more than %" PRIu64 +" MiB of DRAM" , __func__,NPCM7XX_DRAM_SZ / MiB); +return ; + } + +/* CPUs */ +for (i =0 ; i < nc->num_cpus; i++) { +object_property_set_int (OBJECT (&s->cpu[i]),"mp-affinity" , +arm_cpu_mp_affinity (i,NPCM7XX_MAX_NUM_CPUS ), + &error_abort); +object_property_set_int (OBJECT (&s->cpu[i]),"reset-cbar" , +NPCM7XX_GIC_CPU_IF_ADDR , &error_abort); +object_property_set_bool (OBJECT (&s->cpu[i]),"reset-hivecs" , true, + &error_abort); + +/* Disable security extensions. */ +object_property_set_bool (OBJECT (&s->cpu[i]),"has_el3" , false, + &error_abort); + +if (!qdev_realize (DEVICE (&s->cpu[i]),NULL , errp)) { +return ;
Quoted 8 lines
Quoted 8 lines
hw/arm/npcm7xx.c line 208
Quoted 8 lines
hw/arm/npcm7xx.c new file +8
-0+ } + } + +/* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */ +object_property_set_int (OBJECT (&s->a9mpcore),"num-cpu" , nc->num_cpus, + &error_abort); +object_property_set_int (OBJECT (&s->a9mpcore),"num-irq" ,NPCM7XX_NUM_IRQ , + &error_abort);
[1]
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
sysbus_realize(SYS_BUS_DEVICE(&s->a9mpcore), &error_abort);
[2]
Quoted 3 lines
Quoted 3 lines
shouldn't we test the return value and use errp ? I don't know what was agreed upon.
Per https://www.mail-archive.com/[email protected]/msg723217.html:
Quoted 10 lines
Quoted 2 lines
1. Internal code failing to set simple properties to predefined values is a programming error, so
error_abortis appropriate.That would be my advice.
Quoted 2 lines
2.
qdev_realize()may fail due to user input, so errors should be propagated.In general, yes. For a specific device, you may know it can't fail, and then
&error_abortmay be okay.
So it looks correct.
Quoted 20 lines
I'm not sure if I got it 100% right, but what I tried to do was to see which submodules could possibly fail due to user input, and propagate errors from those modules only.
For example, the GCR can fail if the user-provided memory size can't be encoded into registers, so that one clearly needs to be propagated.
Other modules don't take any parameters at all, so they can only fail due to programming errors, hence
error_abort.I wasn't able to find any way command line options could cause the a9mpcore module to fail, but that's one of the cases I'm very unsure about, so I'll be happy to propagate errors from that if you (or anyone else) think it's needed.
I'm also not sure about the CPUs, but ended up going the other way since there's a -cpu option, and it's plausible that the user could cause it to fail even though I couldn't find any specific options to trigger an error.
PATCH v6 5/13 hw/arm: Add two NPCM7xx-based machines
In reply to Havard SkinnemoenThis adds two new machines, both supported by OpenBMC:
- 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.
--- default-configs/arm-softmmu.mak | 1 + include/hw/arm/npcm7xx.h | 19 +++++ hw/arm/npcm7xx_boards.c | 144 ++++++++++++++++++++++++++++++++ hw/arm/Makefile.objs | 2 +- 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm7xx_boards.c
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
include/hw/arm/npcm7xx.h +19 -0
@@ -35,6 +35,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;
hw/arm/npcm7xx_boards.c new file +144 -0
144 lines not on this page · raw message
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
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 6/13 roms: Add virtual Boot ROM for NPCM7xx SoCs
In reply to Havard SkinnemoenThis is a minimalistic boot ROM written specifically for use with QEMU. It supports loading the second-stage loader from SPI flash into RAM, SMP boot, and not much else.
--- Makefile | 1 + .gitmodules | 3 +++ pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 +++++++ roms/vbootrom | 1 + 5 files changed, 12 insertions(+) create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom
Makefile +1 -0
@@ -838,6 +838,7 @@ s390-ccw.img s390-netboot.img \ slof.bin skiboot.lid \ palcode-clipper \ u-boot.e500 u-boot-sam460-20100605.bin \ +npcm7xx_bootrom.bin \ qemu_vga.ndrv \ edk2-licenses.txt \ hppa-firmware.img \
.gitmodules +3 -0
@@ -58,3 +58,6 @@ [submodule "roms/qboot"] path = roms/qboot url = https://github.com/bonzini/qboot +[submodule "roms/vbootrom"] + path = roms/vbootrom + url = https://github.com/google/vbootrom.git
pc-bios/npcm7xx_bootrom.bin new file binary +0 -0
roms/Makefile +7 -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)))) +arm_cross_prefix := $(call find-cross-prefix,arm) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
@@ -63,6 +64,7 @@ default help: @echo " skiboot -- update skiboot.lid" @echo " u-boot.e500 -- update u-boot.e500" @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " npcm7xx_bootrom -- update vbootrom for npcm7xx" @echo " efi -- update UEFI (edk2) platform firmware" @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine"
@@ -198,6 +200,10 @@ bios-microvm: $(MAKE) -C qboot cp qboot/bios.bin ../pc-bios/bios-microvm.bin +npcm7xx_bootrom: + $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix) + cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean
@@ -211,3 +217,4 @@ clean: $(MAKE) -f Makefile.edk2 clean $(MAKE) -C opensbi clean $(MAKE) -C qboot clean + $(MAKE) -C vbootrom clean
roms/vbootrom new file +1 -0
@@ -0,0 +1 @@ +Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 06/13] roms: Add virtual Boot ROM for NPCM7xx SoCs
Quoted 11 lines · Havard Skinnemoen
This is a minimalistic boot ROM written specifically for use with QEMU. It supports loading the second-stage loader from SPI flash into RAM, SMP boot, and not much else.
Signed-off-by Havard Skinnemoen <[email protected]>--- Makefile | 1 + .gitmodules | 3 +++ pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 +++++++ roms/vbootrom | 1 +
pc-bios/READMEMAINTAINERS
need an update.
C.
Quoted 89 lines
5 files changed, 12 insertions(+) create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootromMakefile +1
-0@@ -838,6 +838,7 @@ s390-ccw.img s390-netboot.img \ slof.bin skiboot.lid \ palcode-clipper \ u-boot.e500 u-boot-sam460-20100605.bin \ +npcm7xx_bootrom.bin \ qemu_vga.ndrv \ edk2-licenses.txt \ hppa-firmware.img \.gitmodules +3
-0@@ -58,3 +58,6 @@ [submodule "roms/qboot"] path = roms/qboot url = https://github.com/bonzini/qboot +[submodule "roms/vbootrom"] + path = roms/vbootrom + url = https://github.com/google/vbootrom.gitpc-bios/npcm7xx_bootrom.bin new file binary +0
-0roms/Makefile +7
-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)))) +arm_cross_prefix := $(call find-cross-prefix,arm) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64)@@ -63,6 +64,7 @@ default help: @echo " skiboot -- update skiboot.lid" @echo " u-boot.e500 -- update u-boot.e500" @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " npcm7xx_bootrom -- update vbootrom for npcm7xx" @echo " efi -- update UEFI (edk2) platform firmware" @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine"@@ -198,6 +200,10 @@ bios-microvm: $(MAKE) -C qboot cp qboot/bios.bin ../pc-bios/bios-microvm.bin +npcm7xx_bootrom: + $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix) + cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean@@ -211,3 +217,4 @@ clean: $(MAKE) -f Makefile.edk2 clean $(MAKE) -C opensbi clean $(MAKE) -C qboot clean + $(MAKE) -C vbootrom cleanroms/vbootrom new file +1
-0@@ -0,0 +1 @@ +Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac
PATCH v6 7/13 hw/arm: Load -bios image as a boot ROM for npcm7xx
In reply to Havard SkinnemoenIf a -bios option is specified on the command line, load the image into the internal ROM memory region, which contains the first instructions run by the CPU after reset.
If -bios is not specified, the vbootrom included with qemu is loaded by default.
--- hw/arm/npcm7xx_boards.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
hw/arm/npcm7xx_boards.c +31 -0
@@ -18,12 +18,41 @@#include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" +#include "hw/loader.h" #include "qapi/error.h" +#include "qemu-common.h" #include "qemu/units.h" +#include "sysemu/sysemu.h" #define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff +static const char npcm7xx_default_bootrom[] ="npcm7xx_bootrom.bin" ; + +static void npcm7xx_load_bootrom (NPCM7xxState *soc) +{ + g_autofree char *filename = NULL; +const char *bootrom; +int ret; + +if (bios_name) { + bootrom = bios_name; + }else { + bootrom = npcm7xx_default_bootrom; + } + + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bootrom); +if (!filename) { +error_report ("Could not find ROM image '%s'" , bootrom); +exit (1 ); + } + ret =load_image_mr (filename, &soc->irom); +if (ret <0 ) { +error_report ("Failed to load ROM image '%s'" , filename); +exit (1 ); + } +} +static void npcm7xx_connect_dram (NPCM7xxState *soc,MemoryRegion *dram) {memory_region_add_subregion (get_system_memory (),NPCM7XX_DRAM_BA , dram);
@@ -60,6 +89,7 @@ static void npcm750_evb_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (soc);npcm7xx_load_kernel (machine, soc); }
@@ -71,6 +101,7 @@ static void quanta_gsj_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (soc);npcm7xx_load_kernel (machine, soc); }
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 07/13] hw/arm: Load -bios image as a boot ROM for npcm7xx
Quoted 32 lines · Havard Skinnemoen
If a -bios option is specified on the command line, load the image into the internal ROM memory region, which contains the first instructions run by the CPU after reset.
If -bios is not specified, the vbootrom included with qemu is loaded by default.
Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- hw/arm/npcm7xx_boards.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)hw/arm/npcm7xx_boards.c +5
-0@@ -18,12 +18,41 @@#include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" +#include "hw/loader.h" #include "qapi/error.h" +#include "qemu-common.h" #include "qemu/units.h" +#include "sysemu/sysemu.h" #define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff +static const char npcm7xx_default_bootrom[] ="npcm7xx_bootrom.bin" ; +
hw/arm/npcm7xx_boards.c line 41
Quoted 10 lines
hw/arm/npcm7xx_boards.c +10
-0+static void npcm7xx_load_bootrom (NPCM7xxState *soc) +{ + g_autofree char *filename = NULL; +const char *bootrom; +int ret; + +if (bios_name) { + bootrom = bios_name; + }else { + bootrom = npcm7xx_default_bootrom;
you could simply assign bios_name. No need to resend for that.
C.
Quoted 34 lines
hw/arm/npcm7xx_boards.c +16
-0+ } + + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bootrom); +if (!filename) { +error_report ("Could not find ROM image '%s'" , bootrom); +exit (1 ); + } + ret =load_image_mr (filename, &soc->irom); +if (ret <0 ) { +error_report ("Failed to load ROM image '%s'" , filename); +exit (1 ); + } +} +static void npcm7xx_connect_dram (NPCM7xxState *soc,MemoryRegion *dram) {memory_region_add_subregion (get_system_memory (),NPCM7XX_DRAM_BA , dram);@@ -60,6 +89,7 @@ static void npcm750_evb_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (soc);npcm7xx_load_kernel (machine, soc); }@@ -71,6 +101,7 @@ static void quanta_gsj_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (soc);npcm7xx_load_kernel (machine, soc); }
PATCH v6 8/13 hw/nvram: NPCM7xx OTP device model
In reply to Havard SkinnemoenThis supports reading and writing OTP fuses and keys. Only fuse reading has been tested. Protection is not implemented.
--- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 88 +++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 424 +++++++++++++++++++++++++++++++++ hw/nvram/Makefile.objs | 1 + 5 files changed, 545 insertions(+) create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 hw/nvram/npcm7xx_otp.c
include/hw/arm/npcm7xx.h +3 -0
@@ -20,6 +20,7 @@#include "hw/cpu/a9mpcore.h" #include "hw/misc/npcm7xx_clk.h" #include "hw/misc/npcm7xx_gcr.h" +#include "hw/nvram/npcm7xx_otp.h" #include "hw/timer/npcm7xx_timer.h" #include "target/arm/cpu.h"
@@ -68,6 +69,8 @@ typedef struct NPCM7xxState {NPCM7xxGCRState gcr;NPCM7xxCLKState clk;NPCM7xxTimerCtrlState tim[3 ]; +NPCM7xxOTPState key_storage; +NPCM7xxOTPState fuse_array; } NPCM7xxState;#define TYPE_NPCM7XX "npcm7xx"
include/hw/nvram/npcm7xx_otp.h new file +88 -0
88 lines not on this page · raw message
hw/arm/npcm7xx.c +29 -0
@@ -34,6 +34,10 @@#define NPCM7XX_MMIO_BA (0x80000000)#define NPCM7XX_MMIO_SZ (0x7ffd0000) +/* OTP key storage and fuse strap array */ +#define NPCM7XX_OTP1_BA (0xf0189000) +#define NPCM7XX_OTP2_BA (0xf018a000) +/* Core system modules. */ #define NPCM7XX_L2C_BA (0xf03fc000)#define NPCM7XX_CPUP_BA (0xf03fe000)
@@ -144,6 +148,20 @@ void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)arm_load_kernel (&soc->cpu[0 ], machine, &npcm7xx_binfo); } +static void npcm7xx_init_fuses (NPCM7xxState *s) +{ +NPCM7xxClass *nc =NPCM7XX_GET_CLASS (s); +uint32_t value; + +/* +* The initial mask of disabled modules indicates the chip derivative (e.g. +* NPCM750 or NPCM730). +*/ + value =tswap32 (nc->disabled_modules); +npcm7xx_otp_array_write (&s->fuse_array, &value,NPCM7XX_FUSE_DERIVATIVE , +sizeof (value)); +} +static qemu_irq npcm7xx_irq (NPCM7xxState *s,int n) {return qdev_get_gpio_in (DEVICE (&s->a9mpcore), n);
@@ -164,6 +182,10 @@ static void npcm7xx_init(Object *obj)object_property_add_alias (obj,"power-on-straps" ,OBJECT (&s->gcr),"power-on-straps" );object_initialize_child (obj,"clk" , &s->clk,TYPE_NPCM7XX_CLK ); +object_initialize_child (obj,"otp1" , &s->key_storage, +TYPE_NPCM7XX_KEY_STORAGE ); +object_initialize_child (obj,"otp2" , &s->fuse_array, +TYPE_NPCM7XX_FUSE_ARRAY );for (i =0 ; i <ARRAY_SIZE (s->tim); i++) {object_initialize_child (obj,"tim[*]" , &s->tim[i],TYPE_NPCM7XX_TIMER );
@@ -232,6 +254,13 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&s->clk), &error_abort);sysbus_mmio_map (SYS_BUS_DEVICE (&s->clk),0 ,NPCM7XX_CLK_BA ); +/* OTP key storage and fuse strap array. Cannot fail. */ +sysbus_realize (SYS_BUS_DEVICE (&s->key_storage), &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->key_storage),0 ,NPCM7XX_OTP1_BA ); +sysbus_realize (SYS_BUS_DEVICE (&s->fuse_array), &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->fuse_array),0 ,NPCM7XX_OTP2_BA ); +npcm7xx_init_fuses (s); +/* Timer Modules (TIM). Cannot fail. */ QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_tim_addr) !=ARRAY_SIZE (s->tim));for (i =0 ; i <ARRAY_SIZE (s->tim); i++) {
hw/nvram/npcm7xx_otp.c new file +424 -0
424 lines not on this page · raw message
hw/nvram/Makefile.objs +1 -0
@@ -4,5 +4,6 @@ common-obj-$(CONFIG_AT24C) += eeprom_at24c.o common-obj-y += fw_cfg.o common-obj-$(CONFIG_CHRP_NVRAM) += chrp_nvram.o common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_otp.o common-obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o obj-$(CONFIG_PSERIES) += spapr_nvram.o
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 9/13 hw/mem: Stubbed out NPCM7xx Memory Controller model
In reply to Havard SkinnemoenThis just implements the bare minimum to cause the boot block to skip memory initialization.
--- include/hw/arm/npcm7xx.h | 2 + include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++ hw/arm/npcm7xx.c | 6 +++ hw/mem/npcm7xx_mc.c | 84 +++++++++++++++++++++++++++++++++++++ hw/mem/Makefile.objs | 1 + 5 files changed, 129 insertions(+) create mode 100644 include/hw/mem/npcm7xx_mc.h create mode 100644 hw/mem/npcm7xx_mc.c
include/hw/arm/npcm7xx.h +2 -0
@@ -18,6 +18,7 @@#include "hw/boards.h" #include "hw/cpu/a9mpcore.h" +#include "hw/mem/npcm7xx_mc.h" #include "hw/misc/npcm7xx_clk.h" #include "hw/misc/npcm7xx_gcr.h" #include "hw/nvram/npcm7xx_otp.h"
@@ -71,6 +72,7 @@ typedef struct NPCM7xxState {NPCM7xxTimerCtrlState tim[3 ];NPCM7xxOTPState key_storage;NPCM7xxOTPState fuse_array; +NPCM7xxMCState mc; } NPCM7xxState;#define TYPE_NPCM7XX "npcm7xx"
include/hw/mem/npcm7xx_mc.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Nuvoton NPCM7xx Memory Controller stub +* +* 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 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. +*/ +#ifndef NPCM7XX_MC_H +#define NPCM7XX_MC_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/** +* struct NPCM7xxMCState - Device state for the memory controller. +* @parent: System bus device. +* @mmio: Memory region through which registers are accessed. +*/ +typedef struct NPCM7xxMCState { +SysBusDevice parent; + +MemoryRegion mmio; +}NPCM7xxMCState ; + +#define TYPE_NPCM7XX_MC "npcm7xx-mc" +#define NPCM7XX_MC (obj) OBJECT_CHECK(NPCM7xxMCState, (obj), TYPE_NPCM7XX_MC) + +#endif /* NPCM7XX_MC_H */
hw/arm/npcm7xx.c +6 -0
@@ -43,6 +43,7 @@#define NPCM7XX_CPUP_BA (0xf03fe000)#define NPCM7XX_GCR_BA (0xf0800000)#define NPCM7XX_CLK_BA (0xf0801000) +#define NPCM7XX_MC_BA (0xf0824000)/* Internal AHB SRAM */ #define NPCM7XX_RAM3_BA (0xc0008000)
@@ -186,6 +187,7 @@ static void npcm7xx_init(Object *obj) TYPE_NPCM7XX_KEY_STORAGE);object_initialize_child (obj,"otp2" , &s->fuse_array,TYPE_NPCM7XX_FUSE_ARRAY ); +object_initialize_child (obj,"mc" , &s->mc,TYPE_NPCM7XX_MC );for (i =0 ; i <ARRAY_SIZE (s->tim); i++) {object_initialize_child (obj,"tim[*]" , &s->tim[i],TYPE_NPCM7XX_TIMER );
@@ -261,6 +263,10 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->fuse_array),0 ,NPCM7XX_OTP2_BA );npcm7xx_init_fuses (s); +/* Fake Memory Controller (MC). Cannot fail. */ +sysbus_realize (SYS_BUS_DEVICE (&s->mc), &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->mc),0 ,NPCM7XX_MC_BA ); +/* Timer Modules (TIM). Cannot fail. */ QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_tim_addr) !=ARRAY_SIZE (s->tim));for (i =0 ; i <ARRAY_SIZE (s->tim); i++) {
hw/mem/npcm7xx_mc.c new file +84 -0
84 lines not on this page · raw message
hw/mem/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ common-obj-$(CONFIG_DIMM) += pc-dimm.o common-obj-y += memory-device.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_mc.o common-obj-$(CONFIG_NVDIMM) += nvdimm.o
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 10/13 hw/ssi: NPCM7xx Flash Interface Unit device model
In reply to Havard SkinnemoenThis implements a device model for the NPCM7xx SPI flash controller.
Direct reads and writes, and user-mode transactions have been tested in various modes. Protection features are not implemented yet.
All the FIU instances are available in the SoC's address space, regardless of whether or not they're connected to actual flash chips.
--- include/hw/arm/npcm7xx.h | 2 + include/hw/ssi/npcm7xx_fiu.h | 100 +++++++ hw/arm/npcm7xx.c | 58 ++++ hw/ssi/npcm7xx_fiu.c | 539 +++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/ssi/Makefile.objs | 1 + hw/ssi/trace-events | 11 + 7 files changed, 712 insertions(+) create mode 100644 include/hw/ssi/npcm7xx_fiu.h create mode 100644 hw/ssi/npcm7xx_fiu.c
include/hw/arm/npcm7xx.h +2 -0
@@ -23,6 +23,7 @@#include "hw/misc/npcm7xx_gcr.h" #include "hw/nvram/npcm7xx_otp.h" #include "hw/timer/npcm7xx_timer.h" +#include "hw/ssi/npcm7xx_fiu.h" #include "target/arm/cpu.h" #define NPCM7XX_MAX_NUM_CPUS (2)
@@ -73,6 +74,7 @@ typedef struct NPCM7xxState {NPCM7xxOTPState key_storage;NPCM7xxOTPState fuse_array;NPCM7xxMCState mc; +NPCM7xxFIUState fiu[2 ]; } NPCM7xxState;#define TYPE_NPCM7XX "npcm7xx"
include/hw/ssi/npcm7xx_fiu.h new file +100 -0
100 lines not on this page · raw message
hw/arm/npcm7xx.c +58 -0
76 lines not on this page · raw message
hw/ssi/npcm7xx_fiu.c new file +539 -0
539 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -360,6 +360,7 @@ config NPCM7XX select ARM_GIC select PL310 # cache controller select SERIAL + select SSI select UNIMP config FSL_IMX25
hw/ssi/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o common-obj-$(CONFIG_STM32F2XX_SPI) += stm32f2xx_spi.o common-obj-$(CONFIG_MSF2) += mss-spi.o +common-obj-$(CONFIG_NPCM7XX) += npcm7xx_fiu.o common-obj-$(CONFIG_OMAP) += omap_spi.o common-obj-$(CONFIG_IMX) += imx_spi.o
hw/ssi/trace-events +11 -0
@@ -9,3 +9,14 @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x" aspeed_smc_dma_rw(const char *dir, uint32_t flash_addr, uint32_t dram_addr, uint32_t size) "%s flash:@0x%08x dram:@0x%08x size:0x%08x" aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64 aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect" + +# npcm7xx_fiu.c + +npcm7xx_fiu_enter_reset(const char *id, int reset_type) "%s reset type: %d" +npcm7xx_fiu_hold_reset(const char *id) "%s" +npcm7xx_fiu_select(const char *id, int cs) "%s select CS%d" +npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect CS%d" +npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64 +npcm7xx_fiu_flash_write(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 11/13 hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj
In reply to Havard SkinnemoenThis allows these NPCM7xx-based boards to boot from a flash image, e.g. one built with OpenBMC. For example like this:
IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
qemu-system-arm -machine quanta-gsj -nographic \
-drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on--- hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/arm/npcm7xx_boards.c +20 -0
@@ -19,6 +19,7 @@#include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" #include "hw/loader.h" +#include "hw/qdev-properties.h" #include "qapi/error.h" #include "qemu-common.h" #include "qemu/units.h"
@@ -53,6 +54,22 @@ static void npcm7xx_load_bootrom(NPCM7xxState *soc) } } +static void npcm7xx_connect_flash (NPCM7xxFIUState *fiu,int cs_no, +const char *flash_type,DriveInfo *dinfo) +{ +DeviceState *flash; +qemu_irq flash_cs; + + flash =qdev_new (flash_type); +if (dinfo) { +qdev_prop_set_drive (flash,"drive" ,blk_by_legacy_dinfo (dinfo)); + } +qdev_realize_and_unref (flash,BUS (fiu->spi), &error_fatal); + + flash_cs =qdev_get_gpio_in_named (flash,SSI_GPIO_CS ,0 ); +qdev_connect_gpio_out_named (DEVICE (fiu),"cs" , cs_no, flash_cs); +} +static void npcm7xx_connect_dram (NPCM7xxState *soc,MemoryRegion *dram) {memory_region_add_subregion (get_system_memory (),NPCM7XX_DRAM_BA , dram);
@@ -90,6 +107,7 @@ static void npcm750_evb_init(MachineState *machine)qdev_realize (DEVICE (soc),NULL , &error_fatal);npcm7xx_load_bootrom (soc); +npcm7xx_connect_flash (&soc->fiu[0 ],0 ,"w25q256" ,drive_get (IF_MTD ,0 ,0 ));npcm7xx_load_kernel (machine, soc); }
@@ -102,6 +120,8 @@ static void quanta_gsj_init(MachineState *machine)qdev_realize (DEVICE (soc),NULL , &error_fatal);npcm7xx_load_bootrom (soc); +npcm7xx_connect_flash (&soc->fiu[0 ],0 ,"mx25l25635e" , +drive_get (IF_MTD ,0 ,0 ));npcm7xx_load_kernel (machine, soc); }
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 12/13 docs/system: Add Nuvoton machine documentation
In reply to Havard Skinnemoen--- docs/system/arm/nuvoton.rst | 90 +++++++++++++++++++++++++++++++++++++ docs/system/target-arm.rst | 1 + 2 files changed, 91 insertions(+) create mode 100644 docs/system/arm/nuvoton.rst
docs/system/arm/nuvoton.rst new file +90 -0
@@ -0,0 +1,90 @@ +Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``) +===================================================== + +The `Nuvoton iBMC`_ chips (NPCM7xx) 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. + +.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/ + +The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise +segment. The following machines are based on this chip : + +- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board + +The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and +Hyperscale applications. The following machines are based on this chip : + +- ``quanta-gsj`` Quanta GSJ server BMC + +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. + +Supported devices +----------------- + + * SMP (Dual Core Cortex-A9) + * Cortex-A9MPCore built-in peripherals: SCU, GIC, Global Timer, Private Timer + and Watchdog. + * SRAM, ROM and DRAM mappings + * System Global Control Registers (GCR) + * Clock and reset controller (CLK) + * Timer controller (TIM) + * Serial ports (16550-based) + * DDR4 memory controller (dummy interface indicating memory training is done) + * OTP controllers (no protection features) + * Flash Interface Unit (FIU; no protection features) + +Missing devices +--------------- + + * GPIO controller + * LPC/eSPI host-to-BMC interface, including + + * Keyboard and mouse controller interface (KBCI) + * Keyboard Controller Style (KCS) channels + * BIOS POST code FIFO + * System Wake-up Control (SWC) + * Shared memory (SHM) + * eSPI slave interface + + * Ethernet controllers (GMAC and EMC) + * USB host (USBH) + * USB device (USBD) + * SMBus controller (SMBF) + * Peripheral SPI controller (PSPI) + * Analog to Digital Converter (ADC) + * SD/MMC host + * Random Number Generator (RNG) + * PECI interface + * Pulse Width Modulation (PWM) + * Tachometer + * PCI and PCIe root complex and bridges + * VDM and MCTP support + * Serial I/O expansion + * LPC/eSPI host + * Coprocessor + * Graphics + * Video capture + * Encoding compression engine + * Security features + +Boot options +------------ + +The Nuvoton machines can boot from an OpenBMC firmware image, or directly into +a kernel using the ``-kernel`` option. OpenBMC images for `quanta-gsj` and +possibly others can be downloaded from the OpenPOWER jenkins : + + https://openpower.xyz/ + +The firmware image should be attached as an MTD drive. Example : + +.. code-block:: bash + + $ qemu-system-arm -machine quanta-gsj -nographic \ + -drive file=image-bmc,if=mtd,bus=0,unit=0,format=raw
docs/system/target-arm.rst +1 -0
@@ -84,6 +84,7 @@ undocumented; you can get a complete list by running arm/aspeed arm/musicpal arm/nseries + arm/nuvoton arm/orangepi arm/palm arm/xscale
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v6 13/13 tests/acceptance: console boot tests for quanta-gsj
In reply to Havard SkinnemoenThis adds two acceptance tests for the quanta-gsj machine.
One test downloads a lightly patched openbmc flash image from github and verifies that it boots all the way to the login prompt.
The other test downloads a kernel, initrd and dtb built from the same openbmc source and verifies that the kernel detects all CPUs and boots to the point where it can't find the root filesystem (because we have no flash image in this case).
--- tests/acceptance/boot_linux_console.py | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
tests/acceptance/boot_linux_console.py +65 -0
@@ -569,6 +569,71 @@ class BootLinuxConsole(LinuxKernelTest): 'sda') # cubieboard's reboot is not functioning; omit reboot test. + def test_arm_quanta_gsj(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + # 25 MiB compressed, 32 MiB uncompressed. + image_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') + image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' + image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) + image_name = os.path.splitext(os.path.basename(image_path_gz))[0] + image_path = os.path.join(self.workdir, image_name) + archive.gzip_uncompress(image_path_gz, image_path) + + self.vm.set_console() + drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' + self.vm.add_args('-drive', drive_args) + self.vm.launch() + + self.wait_for_console_pattern('> BootBlock by Nuvoton') + self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') + self.wait_for_console_pattern('>Skip DDR init.') + self.wait_for_console_pattern('U-Boot ') + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern('OpenBMC Project Reference Distro') + self.wait_for_console_pattern('gsj login:') + + def test_arm_quanta_gsj_initrd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + initrd_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') + initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + kernel_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/uImage-gsj.bin') + kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + dtb_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') + dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' + dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200n8 ' + 'earlycon=uart8250,mmio32,0xf0001000') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern( + 'Give root password for system maintenance') + def test_arm_orangepi(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v6 13/13] tests/acceptance: console boot tests for quanta-gsj
Quoted 11 lines · Havard Skinnemoen
This adds two acceptance tests for the quanta-gsj machine.
One test downloads a lightly patched openbmc flash image from github and verifies that it boots all the way to the login prompt.
The other test downloads a kernel, initrd and dtb built from the same openbmc source and verifies that the kernel detects all CPUs and boots to the point where it can't find the root filesystem (because we have no flash image in this case).
Signed-off-by Havard Skinnemoen <[email protected]>
It looks good but I am not sure it's a good idea to have tests point to URLs like :
Philippe, Peter, is that OK ?
If so, Joel, Andrew, could we host FW images on the OpenBMC github ? and do the same for Aspeed.
Thanks,
C.
Quoted 81 lines
--- tests/acceptance/boot_linux_console.py | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)tests/acceptance/boot_linux_console.py +65
-0@@ -569,6 +569,71 @@ class BootLinuxConsole(LinuxKernelTest): 'sda') # cubieboard's reboot is not functioning; omit reboot test. + def test_arm_quanta_gsj(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + # 25 MiB compressed, 32 MiB uncompressed. + image_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') + image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' + image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) + image_name = os.path.splitext(os.path.basename(image_path_gz))[0] + image_path = os.path.join(self.workdir, image_name) + archive.gzip_uncompress(image_path_gz, image_path) + + self.vm.set_console() + drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' + self.vm.add_args('-drive', drive_args) + self.vm.launch() + + self.wait_for_console_pattern('> BootBlock by Nuvoton') + self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') + self.wait_for_console_pattern('>Skip DDR init.') + self.wait_for_console_pattern('U-Boot ') + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern('OpenBMC Project Reference Distro') + self.wait_for_console_pattern('gsj login:') + + def test_arm_quanta_gsj_initrd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + initrd_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') + initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + kernel_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/uImage-gsj.bin') + kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + dtb_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') + dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' + dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200n8 ' + 'earlycon=uart8250,mmio32,0xf0001000') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern( + 'Give root password for system maintenance') + def test_arm_orangepi(self): """ :avocado: tags=arch:arm
Re: [PATCH v6 13/13] tests/acceptance: console boot tests for quanta-gsj
Quoted 17 lines · Cédric Le Goater
Quoted 11 lines · Havard Skinnemoen
This adds two acceptance tests for the quanta-gsj machine.
One test downloads a lightly patched openbmc flash image from github and verifies that it boots all the way to the login prompt.
The other test downloads a kernel, initrd and dtb built from the same openbmc source and verifies that the kernel detects all CPUs and boots to the point where it can't find the root filesystem (because we have no flash image in this case).
Signed-off-by Havard Skinnemoen <[email protected]>It looks good but I am not sure it's a good idea to have tests point to URLs like :
Quoted 7 lines
Philippe, Peter, is that OK ?
If so, Joel, Andrew, could we host FW images on the OpenBMC github ? and do the same for Aspeed.
Yeah, we can do that if it would be preferred.
Nice work on adding a test Havard. I have been meaning to do the same for the aspeed machines for a while.
Quoted 87 lines
Thanks,
C.
Quoted 81 lines
--- tests/acceptance/boot_linux_console.py | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)tests/acceptance/boot_linux_console.py +65
-0@@ -569,6 +569,71 @@ class BootLinuxConsole(LinuxKernelTest): 'sda') # cubieboard's reboot is not functioning; omit reboot test. + def test_arm_quanta_gsj(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + # 25 MiB compressed, 32 MiB uncompressed. + image_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') + image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' + image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) + image_name = os.path.splitext(os.path.basename(image_path_gz))[0] + image_path = os.path.join(self.workdir, image_name) + archive.gzip_uncompress(image_path_gz, image_path) + + self.vm.set_console() + drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' + self.vm.add_args('-drive', drive_args) + self.vm.launch() + + self.wait_for_console_pattern('> BootBlock by Nuvoton') + self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') + self.wait_for_console_pattern('>Skip DDR init.') + self.wait_for_console_pattern('U-Boot ') + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern('OpenBMC Project Reference Distro') + self.wait_for_console_pattern('gsj login:') + + def test_arm_quanta_gsj_initrd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + initrd_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') + initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + kernel_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/uImage-gsj.bin') + kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + dtb_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') + dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' + dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200n8 ' + 'earlycon=uart8250,mmio32,0xf0001000') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern( + 'Give root password for system maintenance') + def test_arm_orangepi(self): """ :avocado: tags=arch:arm
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v6 13/13] tests/acceptance: console boot tests for quanta-gsj
Quoted 13 lines · Joel Stanley
Quoted 12 lines · Cédric Le Goater
Quoted 10 lines · Havard Skinnemoen
This adds two acceptance tests for the quanta-gsj machine.
One test downloads a lightly patched openbmc flash image from github and verifies that it boots all the way to the login prompt.
The other test downloads a kernel, initrd and dtb built from the same openbmc source and verifies that the kernel detects all CPUs and boots to the point where it can't find the root filesystem (because we have no flash image in this case).
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Signed-off-by Havard Skinnemoen <[email protected]>It looks good but I am not sure it's a good idea to have tests point to URLs like :
Philippe, Peter, is that OK ?
FWIW I'm happier having something to test than anything. If Havard destroys his repo, we can remove/move the test. However ...
Quoted 6 lines
Quoted 4 lines
If so, Joel, Andrew, could we host FW images on the OpenBMC github ? and do the same for Aspeed.
Yeah, we can do that if it would be preferred.
... this is certainly better.
Quoted 21 lines
Nice work on adding a test Havard. I have been meaning to do the same for the aspeed machines for a while.
Quoted 17 lines
Thanks,
C.
Quoted 12 lines
--- tests/acceptance/boot_linux_console.py | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)tests/acceptance/boot_linux_console.py +0
-0@@ -569,6 +569,71 @@ class BootLinuxConsole(LinuxKernelTest): 'sda') # cubieboard's reboot is not functioning; omit reboot test.
Quoted 11 lines
Quoted 11 lines
tests/acceptance/boot_linux_console.py class BootLinuxConsole(LinuxKernelTest): · line 582
Quoted 11 lines
tests/acceptance/boot_linux_console.py +11
-0+ def test_arm_quanta_gsj(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + # 25 MiB compressed, 32 MiB uncompressed. + image_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') + image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' + image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
This path is in the Avocado assets cache.
Quoted 1 line
Quoted 1 line
tests/acceptance/boot_linux_console.py class BootLinuxConsole(LinuxKernelTest): · line 583
Quoted 1 line
tests/acceptance/boot_linux_console.py +1
-0+ image_name = os.path.splitext(os.path.basename(image_path_gz))[0]
You take the basename, so it is not in the Avocado assets cache but in the local workdir, good. As this is a temporary file name, we don't care much if the name matches. This works too (and the reviewer doesn't have to wonder what is the path name):
image_name = "obmc.mtd"
I'm fine either ways, thanks for adding a pair of tests!
Quoted 59 lines
Quoted 58 lines
Quoted 57 lines
tests/acceptance/boot_linux_console.py +53
-0+ image_path = os.path.join(self.workdir, image_name) + archive.gzip_uncompress(image_path_gz, image_path) + + self.vm.set_console() + drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' + self.vm.add_args('-drive', drive_args) + self.vm.launch() + + self.wait_for_console_pattern('> BootBlock by Nuvoton') + self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') + self.wait_for_console_pattern('>Skip DDR init.') + self.wait_for_console_pattern('U-Boot ') + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern('OpenBMC Project Reference Distro') + self.wait_for_console_pattern('gsj login:') + + def test_arm_quanta_gsj_initrd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:quanta-gsj + """ + initrd_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') + initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + kernel_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/uImage-gsj.bin') + kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + dtb_url = ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') + dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' + dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200n8 ' + 'earlycon=uart8250,mmio32,0xf0001000') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern( + 'Give root password for system maintenance') + def test_arm_orangepi(self): """ :avocado: tags=arch:arm
Quoted 28 lines · Havard Skinnemoen
I also pushed this and the previous two patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-6].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot an OpenBMC image built for quanta-gsj. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash ControllerThese 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. At the end of the series, qemu can boot an OpenBMC image built for one of these boards with some minor modifications.
Quoted 5 lines
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.
I think this series is ready to go.
Patch 6 "roms: Add virtual Boot ROM for NPCM7xx SoCs" needs a few add-ons which can come later.
Patch 13 "tests/acceptance: console boot tests for quanta-gsj" needs an Acked-by by our test gurus. Aspeed needs the same kind of tests if possible. It depends on the pressure that the QEMU CI will put on the web servers hosting the images.
I think that the rest of the comments are minor and can be fixed as follow-ups when 5.2 is being assembled.
Thanks,
C.
Quoted 190 lines
Changes since v5:
- Boot ROM included, as a git submodule and a binary blob, and loaded by default, so the -bios option is usually not necessary anymore.
- Two acceptance tests added (openbmc image boot, and direct kernel boot).
-npcm7xx_load_kernel()moved to SoC code.
-NPCM7XX_TIMER_REF_HZdefinition moved to CLK header.
- Comments added clarifying available SPI flash chip selects.
- Error handling adjustments:
- Errors from CPU and GCR realization are propagated through the SoC since they may be triggered by user-configurable parameters.
- Machine init useserror_fatalinstead oferror_abortfor SoC realization flash init. This makes error messages more helpful.
- Comments added to indicate whether peripherals may fail to realize.
- UseERRP_GUARD()instead of Error *err when possible.
- Default CPU type is now set, and attempting to set it to anything else will fail.
- Format string fixes (useHWADDR_PRIx, etc.)
- Simplified memory size encoding and error checking innpcm7xx_gcr.
- Encapsulate non-obvious pointer subtraction into helper functions in the FIU and TIMER modules.
- Incorporate review feedback into the FIU module:
- Add select/deselect trace events.
- Use npcm7xx_fiu_{de,}select() consistently.
- Use extract/deposit in more places for consistency.
- Use -Wimplicit-fallthrough compatible fallthrough comments.
- Useqdev_init_gpio_out_namedinstead ofsysbus_init_irqfor chip selects.
- Incorporate review feedback into the TIMER module:
- Assert that we never pause a timer that has already expired, instead of trying to handle it. This should be safe sinceQEMU_CLOCK_VIRTUALis stopped while this code is running.
- Simplify the switch blocks in the read and write handlers.I made a change to error out if a flash drive was not specified, but reverted it because it caused make check to fail (qom-test). When specifying a NULL block device, the m25p flash device initializes its in-memory storage with
0xffand doesn't attempt to write anything back. This seems correct to me.Changes since v4:
- OTP cleanups suggested by Philippe Mathieu-Daudé.
- Added fuse array definitions based on public Nuvoton bootblock code.
- Moved class structure to .c file since it's only used internally.
- Readability improvements.
- Split the first patch and folded parts of it into three other patches so thatCONFIG_NPCM7XXis only enabled after the initial NPCM7xx machine support is added.
- DRAM init moved to machine init code.
- Consistently use lower-case hex literals.
- Switched to fine-grained unimplemented devices, based on public bootblock source code. Added a tiny SRAM that got left out previously.
- Simplified error handling innpcm7xx_realize()since the board code will abort anyway, and SoCs are not hot-pluggable.Changes since v3:
- License headers are now GPL v2-or-later throughout.
- Added vmstate throughout (except the memory controller, which doesn't really have any state worth saving). Successfully booted a gsj image with two stop/savevm/quit/loadvm cycles along the way.
- JFFS2 really doesn't like it if I let qemu keep running after savevm, and then jump back in time with loadvm. I assume this is expected.
- Fixed an error API violation innpcm7xx_realize, removed pointless error check afterobject_property_set_link().
- Switched the OTP device to use an embedded array instead of a g_malloc0'd one because I couldn't figure out how to set up vmstate for the latter.Changes since v2:
- Simplified the
MAINTAINERSentry.
- Added link to OpenPOWER jenkins for gsj BMC images.
- Reverted the smpboot change, back to byte swapping.
- Adapted to upstream API changes:
-sysbus_init_child_obj->object_initialize_child
-object_property_set_bool->qdev_realize/sysbus_realize
-ssi_create_slave_no_init->qdev_new
-qdev_init_nofail->qdev_realize_and_unref
-ssi_auto_connect_slavesremoved
- Moved Boot ROM loading from soc to machine init.
- Plumbed power-on-straps property from GCR to the machine init code so it can be properly initialized. Turns out npcm750 memory init doesn't work without this. npcm730 is fine either way, though I'm not sure why.
- Reworked the flash init code so it looks more like aspeed (i.e. the flash device gets added even if there's no drive).Changes since v1 (requested by reviewers):
- Clarify the source of CLK reset values.
- Made smpboot a constant byte array, eliinated byte swapping.
- NPCM7xxState now stores an array of ARMCPUs, not pointers to ARMCPUs.
- Clarify why EL3 is disabled.
- IntroduceNPCM7XX_NUM_IRQconstant.
- Set the number of CPUs according to SoC variant, and disallow command line overrides (i.e. you can no longer override the number of CPUs with the -smp parameter). This is trying to follow the spirit of
https://patchwork.kernel.org/patch/11595407/.
- Switch register operations toDEVICE_LITTLE_ENDIANthroughout.
- Machine documentation added (new patch).Changes since v1 to support flash booting:
- GCR reset value changes to get past memory initialization when booting from flash (patches 2 and 5):
- INTCR2 now indicates that the DDR controller is initialized.
- INTCR3 is initialized according to DDR memory size. Arealize()method was implemented to achieve this.
- Refactor the machine initialization a bit to make it easier to drop in machine-specific flash initialization (patch 6).
- Extend the series with additional patches to enable booting from flash:
- Boot ROM (through the -bios option).
- OTP (fuse) controller.
- Memory Controller stub (just enough to skip memory training).
- Flash controller.
- Board-specific flash initialization.Thanks for reviewing,
Havard
Havard Skinnemoen (13):
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
roms: Add virtual Boot ROM for NPCM7xx SoCs
hw/arm: Load -bios image as a boot ROM for npcm7xx hw/nvram: NPCM7xx OTP device model
hw/mem: Stubbed out NPCM7xx Memory Controller model hw/ssi: NPCM7xx Flash Interface Unit device model hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj docs/system: Add Nuvoton machine documentation tests/acceptance: console boot tests for quanta-gsjdocs/system/arm/nuvoton.rst | 90 +++++ docs/system/target-arm.rst | 1 + Makefile | 1 + default-configs/arm-softmmu.mak | 1 + include/hw/arm/npcm7xx.h | 111 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 72 ++++ include/hw/misc/npcm7xx_gcr.h | 76 ++++ include/hw/nvram/npcm7xx_otp.h | 88 ++++ include/hw/ssi/npcm7xx_fiu.h | 100 +++++ include/hw/timer/npcm7xx_timer.h | 96 +++++ hw/arm/npcm7xx.c | 500 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 195 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 234 +++++++++++ hw/misc/npcm7xx_gcr.c | 227 +++++++++++ hw/nvram/npcm7xx_otp.c | 424 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 539 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 489 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 8 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/mem/Makefile.objs | 1 + hw/misc/Makefile.objs | 2 + hw/misc/trace-events | 8 + hw/nvram/Makefile.objs | 1 + hw/ssi/Makefile.objs | 1 + hw/ssi/trace-events | 11 + hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 65 +++ 35 files changed, 3488 insertions(+) create mode 100644 docs/system/arm/nuvoton.rst create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 include/hw/mem/npcm7xx_mc.h create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 include/hw/ssi/npcm7xx_fiu.h create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/arm/npcm7xx.c create mode 100644 hw/arm/npcm7xx_boards.c create mode 100644 hw/mem/npcm7xx_mc.c create mode 100644 hw/misc/npcm7xx_clk.c create mode 100644 hw/misc/npcm7xx_gcr.c create mode 100644 hw/nvram/npcm7xx_otp.c create mode 100644 hw/ssi/npcm7xx_fiu.c create mode 100644 hw/timer/npcm7xx_timer.c create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom
Quoted 38 lines · Cédric Le Goater
Quoted 28 lines · Havard Skinnemoen
I also pushed this and the previous two patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-6].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot an OpenBMC image built for quanta-gsj. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash ControllerThese 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. At the end of the series, qemu can boot an OpenBMC image built for one of these boards with some minor modifications.
Quoted 5 lines
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.
I think this series is ready to go.
Quoted 7 lines
Patch 6 "roms: Add virtual Boot ROM for NPCM7xx SoCs" needs a few add-ons which can come later.
Patch 13 "tests/acceptance: console boot tests for quanta-gsj" needs an Acked-by by our test gurus. Aspeed needs the same kind of tests if possible. It depends on the pressure that the QEMU CI will put on the web servers hosting the images.
Hmm, I didn't expect this to be a problem when hosting the images on github...?
Quoted 2 lines
I think that the rest of the comments are minor and can be fixed as follow-ups when 5.2 is being assembled.
Great! Thanks a lot for reviewing and testing.
I've incorporated the feedback I got today, but I'm keeping them as separate commits for now. I can either fold them into a v7 series or post them as follow-ups.
Thanks!
Havard
Hi Havard,
Quoted 68 lines · Havard Skinnemoen
I also pushed this and the previous two patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-6].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot an OpenBMC image built for quanta-gsj. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash ControllerThese 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. At the end of the series, qemu can boot an OpenBMC image built for one of these boards with some minor modifications.
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.
Changes since v5:
- Boot ROM included, as a git submodule and a binary blob, and loaded by default, so the -bios option is usually not necessary anymore.
- Two acceptance tests added (openbmc image boot, and direct kernel boot).
-npcm7xx_load_kernel()moved to SoC code.
-NPCM7XX_TIMER_REF_HZdefinition moved to CLK header.
- Comments added clarifying available SPI flash chip selects.
- Error handling adjustments:
- Errors from CPU and GCR realization are propagated through the SoC since they may be triggered by user-configurable parameters.
- Machine init useserror_fatalinstead oferror_abortfor SoC realization flash init. This makes error messages more helpful.
- Comments added to indicate whether peripherals may fail to realize.
- UseERRP_GUARD()instead of Error *err when possible.
- Default CPU type is now set, and attempting to set it to anything else will fail.
- Format string fixes (useHWADDR_PRIx, etc.)
- Simplified memory size encoding and error checking innpcm7xx_gcr.
- Encapsulate non-obvious pointer subtraction into helper functions in the FIU and TIMER modules.
- Incorporate review feedback into the FIU module:
- Add select/deselect trace events.
- Use npcm7xx_fiu_{de,}select() consistently.
- Use extract/deposit in more places for consistency.
- Use -Wimplicit-fallthrough compatible fallthrough comments.
- Useqdev_init_gpio_out_namedinstead ofsysbus_init_irqfor chip selects.
- Incorporate review feedback into the TIMER module:
- Assert that we never pause a timer that has already expired, instead of trying to handle it. This should be safe sinceQEMU_CLOCK_VIRTUALis stopped while this code is running.
- Simplify the switch blocks in the read and write handlers.
Quoted 4 lines
I made a change to error out if a flash drive was not specified, but reverted it because it caused make check to fail (qom-test). When specifying a NULL block device, the m25p flash device initializes its in-memory storage with
0xffand doesn't attempt to write anything back. This seems correct to me.
I've been quite busy, now looking back a this series. Do you have a v7 in preparation or should I keep reviewing it?
Hopefully v7 would be the one Peter queue for merging once 5.2 window opens :)
Regards,
Phil.
Hi Philippe,
Quoted 72 lines · Philippe Mathieu-Daudé
Hi Havard,
Quoted 68 lines · Havard Skinnemoen
I also pushed this and the previous two patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-6].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750 SoCs to boot an OpenBMC image built for quanta-gsj. This includes device models for:
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash ControllerThese 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. At the end of the series, qemu can boot an OpenBMC image built for one of these boards with some minor modifications.
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.
Changes since v5:
- Boot ROM included, as a git submodule and a binary blob, and loaded by default, so the -bios option is usually not necessary anymore.
- Two acceptance tests added (openbmc image boot, and direct kernel boot).
-npcm7xx_load_kernel()moved to SoC code.
-NPCM7XX_TIMER_REF_HZdefinition moved to CLK header.
- Comments added clarifying available SPI flash chip selects.
- Error handling adjustments:
- Errors from CPU and GCR realization are propagated through the SoC since they may be triggered by user-configurable parameters.
- Machine init useserror_fatalinstead oferror_abortfor SoC realization flash init. This makes error messages more helpful.
- Comments added to indicate whether peripherals may fail to realize.
- UseERRP_GUARD()instead of Error *err when possible.
- Default CPU type is now set, and attempting to set it to anything else will fail.
- Format string fixes (useHWADDR_PRIx, etc.)
- Simplified memory size encoding and error checking innpcm7xx_gcr.
- Encapsulate non-obvious pointer subtraction into helper functions in the FIU and TIMER modules.
- Incorporate review feedback into the FIU module:
- Add select/deselect trace events.
- Use npcm7xx_fiu_{de,}select() consistently.
- Use extract/deposit in more places for consistency.
- Use -Wimplicit-fallthrough compatible fallthrough comments.
- Useqdev_init_gpio_out_namedinstead ofsysbus_init_irqfor chip selects.
- Incorporate review feedback into the TIMER module:
- Assert that we never pause a timer that has already expired, instead of trying to handle it. This should be safe sinceQEMU_CLOCK_VIRTUALis stopped while this code is running.
- Simplify the switch blocks in the read and write handlers.
Quoted 7 lines
Quoted 4 lines
I made a change to error out if a flash drive was not specified, but reverted it because it caused make check to fail (qom-test). When specifying a NULL block device, the m25p flash device initializes its in-memory storage with
0xffand doesn't attempt to write anything back. This seems correct to me.I've been quite busy, now looking back a this series. Do you have a v7 in preparation or should I keep reviewing it?
I have a few fixes queued up, but I didn't turn it into a v7 series yet. I can probably have that ready by tomorrow if you prefer.
Or I can wait a bit longer and queue up more fixes. The merge window is expected to open next week at the earliest right?
Quoted 2 lines
Hopefully v7 would be the one Peter queue for merging once 5.2 window opens :)
I hope so too :)
Havard