Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
Subsystems (2)
v8 cover Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single NPCM7XX_FOO_NR_REGS definition behind in the .h file. A QEMU_BUILD_BUG_ON should alert anyone accidentally expanding the register enum that they need to update the corresponding NR_REGS define, which in turn has a comment reminding them to update the vmstate version_id as well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97
Changes since v6:
- Use size_to_str to report DRAM sizes in npcm7xx_gcr.
- Simplify the interrupt logic in npcm7xx_timer.
- Update global bios_name instead of temporary.
- Add npcm7xx_bootrom to MAINTAINERS and pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.
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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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.297.g1956fa8f8d-goog
PATCH v8 1/14 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 | 43 ++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 + hw/arm/Kconfig | 3 + hw/misc/meson.build | 3 + hw/misc/trace-events | 4 + 6 files changed, 330 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 +43 -0
@@ -0,0 +1,43 @@ +/* +* 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" + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t)) + +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 +269 -0
269 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -749,6 +749,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
@@ -355,6 +355,9 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP +config NPCM7XX + bool + config FSL_IMX25 bool select IMX
hw/misc/meson.build +3 -0
@@ -50,6 +50,9 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( )) softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_gcr.c', +)) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( 'omap_clk.c', 'omap_gpmc.c',
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.297.g1956fa8f8d-goog
PATCH v8 3/14 hw/timer: Add NPCM7xx Timer device model
In reply to Havard Skinnemoen viaThe 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 | 78 +++++ hw/timer/npcm7xx_timer.c | 509 +++++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + 4 files changed, 593 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 +78 -0
@@ -0,0 +1,78 @@ +/* +* 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) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) + +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 +509 -0
509 lines not on this page · raw message
hw/timer/meson.build +1 -0
@@ -23,6 +23,7 @@ softmmu_ss.add(when: 'CONFIG_LM32', if_true: files('lm32_timer.c')) softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-sysctl.c')) softmmu_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c')) softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-timer.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c')) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c')) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c'))
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.297.g1956fa8f8d-goog
PATCH v8 2/14 hw/misc: Add NPCM7xx Clock Controller device model
In reply to Havard Skinnemoen viaEnough 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 | 48 ++++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 4 files changed, 319 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 +48 -0
@@ -0,0 +1,48 @@ +/* +* 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) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) + +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 +266 -0
266 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -51,6 +51,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_clk.c', 'npcm7xx_gcr.c', )) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
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.297.g1956fa8f8d-goog
Re: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 172 lines · Havard Skinnemoen via
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/misc/npcm7xx_clk.h | 48 ++++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 4 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 hw/misc/npcm7xx_clk.cinclude/hw/misc/npcm7xx_clk.h new file +48
-0@@ -0,0 +1,48 @@ +/* +* 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) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) + +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 +89
-0@@ -0,0 +1,266 @@ +/* +* 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. +*/ + +#include "qemu/osdep.h" + +#include "hw/misc/npcm7xx_clk.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +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_REGS_END , +}; + +/* +* These reset values were taken from version 0.91 of the NPCM750R data sheet. +* +* All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on +* core domain reset, but this reset type is not yet supported by QEMU. +*/ +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS ] = { + [NPCM7XX_CLK_CLKEN1 ] =0xffffffff , + [NPCM7XX_CLK_CLKSEL ] =0x004aaaaa , + [NPCM7XX_CLK_CLKDIV1 ] =0x5413f855 , + [NPCM7XX_CLK_PLLCON0 ] =0x00222101 |PLLCON_LOKI , + [NPCM7XX_CLK_PLLCON1 ] =0x00202101 |PLLCON_LOKI , + [NPCM7XX_CLK_IPSRST1 ] =0x00001000 , + [NPCM7XX_CLK_IPSRST2 ] =0x80000000 , + [NPCM7XX_CLK_CLKEN2 ] =0xffffffff , + [NPCM7XX_CLK_CLKDIV2 ] =0xaa4f8f9f , + [NPCM7XX_CLK_CLKEN3 ] =0xffffffff , + [NPCM7XX_CLK_IPSRST3 ] =0x03000000 , + [NPCM7XX_CLK_WD0RCR ] =0xffffffff , + [NPCM7XX_CLK_WD1RCR ] =0xffffffff , + [NPCM7XX_CLK_WD2RCR ] =0xffffffff , + [NPCM7XX_CLK_SWRSTC1 ] =0x00000003 , + [NPCM7XX_CLK_PLLCON2 ] =0x00c02105 |PLLCON_LOKI , + [NPCM7XX_CLK_CORSTC ] =0x04000003 , + [NPCM7XX_CLK_PLLCONG ] =0x01228606 |PLLCON_LOKI , + [NPCM7XX_CLK_AHBCKFI ] =0x000000c8 , +}; +
hw/misc/npcm7xx_clk.c line 99
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+static uint64_t npcm7xx_clk_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +int64_t now_ns; +uint32_t value =0 ; + +if (reg >=NPCM7XX_CLK_NR_REGS ) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
I find "out of range" not clear, but this might be the correct terminology.
Quoted 47 lines
hw/misc/npcm7xx_clk.c new file +47
-0+ __func__, offset); +return 0 ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is write-only\n" , + __func__, offset); +break ; + +case NPCM7XX_CLK_SECCNT : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + value = (now_ns - s->ref_ns) /NANOSECONDS_PER_SECOND ; +break ; + +case NPCM7XX_CLK_CNTR25M : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* +* This register counts 25 MHz cycles, updating every 640 ns. It rolls +* over to zero every second. +* +* The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000. +*/ + value = (((now_ns - s->ref_ns) /640 ) <<4 ) %NPCM7XX_TIMER_REF_HZ ; +break ; + +default : + value = s->regs[reg]; +break ; + }; + +trace_npcm7xx_clk_read (offset, value); + +return value; +} + +static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) {
hw/misc/npcm7xx_clk.c line 156
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: offset 0x%04" HWADDR_PRIx" out of range\n" , + __func__, offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value);
Isn't this sufficient?
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
Quoted 53 lines
hw/misc/npcm7xx_clk.c new file +53
-0+ value =0 ; +break ; + +case NPCM7XX_CLK_PLLCON0 : +case NPCM7XX_CLK_PLLCON1 : +case NPCM7XX_CLK_PLLCON2 : +case NPCM7XX_CLK_PLLCONG : +if (value &PLLCON_PWDEN ) { +/* Power down -- clear lock and indicate loss of lock */ + value &= ~PLLCON_LOKI ; + value |=PLLCON_LOKS ; + }else { +/* Normal mode -- assume always locked */ + value |=PLLCON_LOKI ; +/* Keep LOKS unchanged unless cleared by writing 1 */ +if (value &PLLCON_LOKS ) { + value &= ~PLLCON_LOKS ; + }else { + value |= (value &PLLCON_LOKS ); + } + } +break ; + +case NPCM7XX_CLK_CNTR25M : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , + __func__, offset); +return ; + } + + s->regs[reg] = value; +} + +static const struct MemoryRegionOps npcm7xx_clk_ops = { + .read = npcm7xx_clk_read, + .write = npcm7xx_clk_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_clk_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); + +switch (type) { +case RESET_TYPE_COLD : +memcpy (s->regs, cold_reset_values,sizeof (cold_reset_values));
hw/misc/npcm7xx_clk.c line 219
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+ s->ref_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +return ; + } + +/* +* A small number of registers need to be reset on a core domain reset, +* but no such reset type exists yet. +*/ +qemu_log_mask (LOG_UNIMP ,"%s: reset type %d not implemented." , + __func__, type);
Clean :)
Quoted 7 lines
hw/misc/npcm7xx_clk.c new file +7
-0+} + +static void npcm7xx_clk_init (Object *obj) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + + memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
hw/misc/npcm7xx_clk.c line 236
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+ TYPE_NPCM7XX_CLK, 4 * KiB); +sysbus_init_mmio (&s->parent, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_clk = { + .name ="npcm7xx-clk" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxCLKState,NPCM7XX_CLK_NR_REGS ),
Quoted 58 lines
hw/misc/npcm7xx_clk.c new file +30
-0+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_CLK_REGS_END >NPCM7XX_CLK_NR_REGS ); + + dc->desc ="NPCM7xx Clock Control Registers" ; + dc->vmsd = &vmstate_npcm7xx_clk; + rc->phases.enter = npcm7xx_clk_enter_reset; +} + +static const TypeInfo npcm7xx_clk_info = { + .name =TYPE_NPCM7XX_CLK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxCLKState), + .instance_init = npcm7xx_clk_init, + .class_init = npcm7xx_clk_class_init, +}; + +static void npcm7xx_clk_register_type (void ) +{ +type_register_static (&npcm7xx_clk_info); +} +type_init (npcm7xx_clk_register_type);hw/misc/meson.build +1
-0@@ -51,6 +51,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_clk.c', 'npcm7xx_gcr.c', )) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(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
Re: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 248 lines · Philippe Mathieu-Daudé
Quoted 172 lines · Havard Skinnemoen via
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/misc/npcm7xx_clk.h | 48 ++++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 4 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 hw/misc/npcm7xx_clk.cinclude/hw/misc/npcm7xx_clk.h new file +48
-0@@ -0,0 +1,48 @@ +/* +* 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) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) + +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 +89
-0@@ -0,0 +1,266 @@ +/* +* 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. +*/ + +#include "qemu/osdep.h" + +#include "hw/misc/npcm7xx_clk.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +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_REGS_END , +}; + +/* +* These reset values were taken from version 0.91 of the NPCM750R data sheet. +* +* All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on +* core domain reset, but this reset type is not yet supported by QEMU. +*/ +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS ] = { + [NPCM7XX_CLK_CLKEN1 ] =0xffffffff , + [NPCM7XX_CLK_CLKSEL ] =0x004aaaaa , + [NPCM7XX_CLK_CLKDIV1 ] =0x5413f855 , + [NPCM7XX_CLK_PLLCON0 ] =0x00222101 |PLLCON_LOKI , + [NPCM7XX_CLK_PLLCON1 ] =0x00202101 |PLLCON_LOKI , + [NPCM7XX_CLK_IPSRST1 ] =0x00001000 , + [NPCM7XX_CLK_IPSRST2 ] =0x80000000 , + [NPCM7XX_CLK_CLKEN2 ] =0xffffffff , + [NPCM7XX_CLK_CLKDIV2 ] =0xaa4f8f9f , + [NPCM7XX_CLK_CLKEN3 ] =0xffffffff , + [NPCM7XX_CLK_IPSRST3 ] =0x03000000 , + [NPCM7XX_CLK_WD0RCR ] =0xffffffff , + [NPCM7XX_CLK_WD1RCR ] =0xffffffff , + [NPCM7XX_CLK_WD2RCR ] =0xffffffff , + [NPCM7XX_CLK_SWRSTC1 ] =0x00000003 , + [NPCM7XX_CLK_PLLCON2 ] =0x00c02105 |PLLCON_LOKI , + [NPCM7XX_CLK_CORSTC ] =0x04000003 , + [NPCM7XX_CLK_PLLCONG ] =0x01228606 |PLLCON_LOKI , + [NPCM7XX_CLK_AHBCKFI ] =0x000000c8 , +}; +hw/misc/npcm7xx_clk.c line 99
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+static uint64_t npcm7xx_clk_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +int64_t now_ns; +uint32_t value =0 ; + +if (reg >=NPCM7XX_CLK_NR_REGS ) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n",I find "out of range" not clear, but this might be the correct terminology.
Quoted 47 lines
hw/misc/npcm7xx_clk.c new file +47
-0+ __func__, offset); +return 0 ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is write-only\n" , + __func__, offset); +break ; + +case NPCM7XX_CLK_SECCNT : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + value = (now_ns - s->ref_ns) /NANOSECONDS_PER_SECOND ; +break ; + +case NPCM7XX_CLK_CNTR25M : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* +* This register counts 25 MHz cycles, updating every 640 ns. It rolls +* over to zero every second. +* +* The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000. +*/ + value = (((now_ns - s->ref_ns) /640 ) <<4 ) %NPCM7XX_TIMER_REF_HZ ; +break ; + +default : + value = s->regs[reg]; +break ; + }; + +trace_npcm7xx_clk_read (offset, value); + +return value; +} + +static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) {hw/misc/npcm7xx_clk.c line 156
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: offset 0x%04" HWADDR_PRIx" out of range\n" , + __func__, offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value);Isn't this sufficient?
Quoted 1 line
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
It's not quite that easy; this register holds 4 bits, each of which maps to a separate register which defines the modules to reset. It's not that hard, but a little more than I'd like to add to the series at this point. I'll send a followup patch once the initial series is in.
Quoted 79 lines
Quoted 54 lines
hw/misc/npcm7xx_clk.c new file +53
-0+ value =0 ; +break ; + +case NPCM7XX_CLK_PLLCON0 : +case NPCM7XX_CLK_PLLCON1 : +case NPCM7XX_CLK_PLLCON2 : +case NPCM7XX_CLK_PLLCONG : +if (value &PLLCON_PWDEN ) { +/* Power down -- clear lock and indicate loss of lock */ + value &= ~PLLCON_LOKI ; + value |=PLLCON_LOKS ; + }else { +/* Normal mode -- assume always locked */ + value |=PLLCON_LOKI ; +/* Keep LOKS unchanged unless cleared by writing 1 */ +if (value &PLLCON_LOKS ) { + value &= ~PLLCON_LOKS ; + }else { + value |= (value &PLLCON_LOKS ); + } + } +break ; + +case NPCM7XX_CLK_CNTR25M : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , + __func__, offset); +return ; + } + + s->regs[reg] = value; +} + +static const struct MemoryRegionOps npcm7xx_clk_ops = { + .read = npcm7xx_clk_read, + .write = npcm7xx_clk_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_clk_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); + +switch (type) { +case RESET_TYPE_COLD : +memcpy (s->regs, cold_reset_values,sizeof (cold_reset_values));hw/misc/npcm7xx_clk.c line 219
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+ s->ref_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +return ; + } + +/* +* A small number of registers need to be reset on a core domain reset, +* but no such reset type exists yet. +*/ +qemu_log_mask (LOG_UNIMP ,"%s: reset type %d not implemented." , + __func__, type);Clean :)
Quoted 12 lines
hw/misc/npcm7xx_clk.c new file +12
-0+} + +static void npcm7xx_clk_init (Object *obj) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +memory_region_init_io (&s->iomem, obj, &npcm7xx_clk_ops, s, +TYPE_NPCM7XX_CLK ,4 * KiB); +sysbus_init_mmio (&s->parent, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_clk = {
Quoted 8 lines
hw/misc/npcm7xx_clk.c line 236
Quoted 5 lines
hw/misc/npcm7xx_clk.c new file +5
-0+ .name = "npcm7xx-clk", + .version_id = 0, + .minimum_version_id = 0, + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxCLKState,NPCM7XX_CLK_NR_REGS ),Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thank you!
Quoted 58 lines
Quoted 58 lines
hw/misc/npcm7xx_clk.c new file +30
-0+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_CLK_REGS_END >NPCM7XX_CLK_NR_REGS ); + + dc->desc ="NPCM7xx Clock Control Registers" ; + dc->vmsd = &vmstate_npcm7xx_clk; + rc->phases.enter = npcm7xx_clk_enter_reset; +} + +static const TypeInfo npcm7xx_clk_info = { + .name =TYPE_NPCM7XX_CLK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxCLKState), + .instance_init = npcm7xx_clk_init, + .class_init = npcm7xx_clk_class_init, +}; + +static void npcm7xx_clk_register_type (void ) +{ +type_register_static (&npcm7xx_clk_info); +} +type_init (npcm7xx_clk_register_type);hw/misc/meson.build +1
-0@@ -51,6 +51,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_clk.c', 'npcm7xx_gcr.c', )) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(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
Re: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 250 lines · Havard Skinnemoen
Quoted 248 lines · Philippe Mathieu-Daudé
Quoted 172 lines · Havard Skinnemoen via
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/misc/npcm7xx_clk.h | 48 ++++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 4 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 hw/misc/npcm7xx_clk.cinclude/hw/misc/npcm7xx_clk.h new file +48
-0@@ -0,0 +1,48 @@ +/* +* 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) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) + +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 +89
-0@@ -0,0 +1,266 @@ +/* +* 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. +*/ + +#include "qemu/osdep.h" + +#include "hw/misc/npcm7xx_clk.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +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_REGS_END , +}; + +/* +* These reset values were taken from version 0.91 of the NPCM750R data sheet. +* +* All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on +* core domain reset, but this reset type is not yet supported by QEMU. +*/ +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS ] = { + [NPCM7XX_CLK_CLKEN1 ] =0xffffffff , + [NPCM7XX_CLK_CLKSEL ] =0x004aaaaa , + [NPCM7XX_CLK_CLKDIV1 ] =0x5413f855 , + [NPCM7XX_CLK_PLLCON0 ] =0x00222101 |PLLCON_LOKI , + [NPCM7XX_CLK_PLLCON1 ] =0x00202101 |PLLCON_LOKI , + [NPCM7XX_CLK_IPSRST1 ] =0x00001000 , + [NPCM7XX_CLK_IPSRST2 ] =0x80000000 , + [NPCM7XX_CLK_CLKEN2 ] =0xffffffff , + [NPCM7XX_CLK_CLKDIV2 ] =0xaa4f8f9f , + [NPCM7XX_CLK_CLKEN3 ] =0xffffffff , + [NPCM7XX_CLK_IPSRST3 ] =0x03000000 , + [NPCM7XX_CLK_WD0RCR ] =0xffffffff , + [NPCM7XX_CLK_WD1RCR ] =0xffffffff , + [NPCM7XX_CLK_WD2RCR ] =0xffffffff , + [NPCM7XX_CLK_SWRSTC1 ] =0x00000003 , + [NPCM7XX_CLK_PLLCON2 ] =0x00c02105 |PLLCON_LOKI , + [NPCM7XX_CLK_CORSTC ] =0x04000003 , + [NPCM7XX_CLK_PLLCONG ] =0x01228606 |PLLCON_LOKI , + [NPCM7XX_CLK_AHBCKFI ] =0x000000c8 , +}; +hw/misc/npcm7xx_clk.c line 99
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+static uint64_t npcm7xx_clk_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +int64_t now_ns; +uint32_t value =0 ; + +if (reg >=NPCM7XX_CLK_NR_REGS ) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n",I find "out of range" not clear, but this might be the correct terminology.
Quoted 47 lines
hw/misc/npcm7xx_clk.c new file +47
-0+ __func__, offset); +return 0 ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is write-only\n" , + __func__, offset); +break ; + +case NPCM7XX_CLK_SECCNT : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + value = (now_ns - s->ref_ns) /NANOSECONDS_PER_SECOND ; +break ; + +case NPCM7XX_CLK_CNTR25M : + now_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* +* This register counts 25 MHz cycles, updating every 640 ns. It rolls +* over to zero every second. +* +* The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000. +*/ + value = (((now_ns - s->ref_ns) /640 ) <<4 ) %NPCM7XX_TIMER_REF_HZ ; +break ; + +default : + value = s->regs[reg]; +break ; + }; + +trace_npcm7xx_clk_read (offset, value); + +return value; +} + +static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) {hw/misc/npcm7xx_clk.c line 156
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: offset 0x%04" HWADDR_PRIx" out of range\n" , + __func__, offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value);Isn't this sufficient?
Quoted 6 lines
Quoted 1 line
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);It's not quite that easy; this register holds 4 bits, each of which maps to a separate register which defines the modules to reset. It's not that hard, but a little more than I'd like to add to the series at this point. I'll send a followup patch once the initial series is in.
Actually, I'm not sure if this would have any effect on being able to reboot. Running with -d unimp shows:
reboot: Restarting systemnpcm7xx_timer_write: WTCR write not implemented: 0x00000083 Reboot failed -- System halted
So we need to implement watchdog support, which is something we were planning to do fairly soon.
Quoted 148 lines
Quoted 79 lines
Quoted 54 lines
hw/misc/npcm7xx_clk.c new file +53
-0+ value =0 ; +break ; + +case NPCM7XX_CLK_PLLCON0 : +case NPCM7XX_CLK_PLLCON1 : +case NPCM7XX_CLK_PLLCON2 : +case NPCM7XX_CLK_PLLCONG : +if (value &PLLCON_PWDEN ) { +/* Power down -- clear lock and indicate loss of lock */ + value &= ~PLLCON_LOKI ; + value |=PLLCON_LOKS ; + }else { +/* Normal mode -- assume always locked */ + value |=PLLCON_LOKI ; +/* Keep LOKS unchanged unless cleared by writing 1 */ +if (value &PLLCON_LOKS ) { + value &= ~PLLCON_LOKS ; + }else { + value |= (value &PLLCON_LOKS ); + } + } +break ; + +case NPCM7XX_CLK_CNTR25M : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: register @ 0x%04" HWADDR_PRIx" is read-only\n" , + __func__, offset); +return ; + } + + s->regs[reg] = value; +} + +static const struct MemoryRegionOps npcm7xx_clk_ops = { + .read = npcm7xx_clk_read, + .write = npcm7xx_clk_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_clk_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +QEMU_BUILD_BUG_ON (sizeof (s->regs) !=sizeof (cold_reset_values)); + +switch (type) { +case RESET_TYPE_COLD : +memcpy (s->regs, cold_reset_values,sizeof (cold_reset_values));hw/misc/npcm7xx_clk.c line 219
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+ s->ref_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +return ; + } + +/* +* A small number of registers need to be reset on a core domain reset, +* but no such reset type exists yet. +*/ +qemu_log_mask (LOG_UNIMP ,"%s: reset type %d not implemented." , + __func__, type);Clean :)
Quoted 12 lines
hw/misc/npcm7xx_clk.c new file +12
-0+} + +static void npcm7xx_clk_init (Object *obj) +{ +NPCM7xxCLKState *s =NPCM7XX_CLK (obj); + +memory_region_init_io (&s->iomem, obj, &npcm7xx_clk_ops, s, +TYPE_NPCM7XX_CLK ,4 * KiB); +sysbus_init_mmio (&s->parent, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_clk = {Quoted 8 lines
hw/misc/npcm7xx_clk.c line 236
Quoted 5 lines
hw/misc/npcm7xx_clk.c new file +5
-0+ .name = "npcm7xx-clk", + .version_id = 0, + .minimum_version_id = 0, + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxCLKState,NPCM7XX_CLK_NR_REGS ),Reviewed-by Philippe Mathieu-Daudé <[email protected]>Thank you!
Quoted 58 lines
Quoted 58 lines
hw/misc/npcm7xx_clk.c new file +30
-0+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_clk_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_CLK_REGS_END >NPCM7XX_CLK_NR_REGS ); + + dc->desc ="NPCM7xx Clock Control Registers" ; + dc->vmsd = &vmstate_npcm7xx_clk; + rc->phases.enter = npcm7xx_clk_enter_reset; +} + +static const TypeInfo npcm7xx_clk_info = { + .name =TYPE_NPCM7XX_CLK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxCLKState), + .instance_init = npcm7xx_clk_init, + .class_init = npcm7xx_clk_class_init, +}; + +static void npcm7xx_clk_register_type (void ) +{ +type_register_static (&npcm7xx_clk_info); +} +type_init (npcm7xx_clk_register_type);hw/misc/meson.build +1
-0@@ -51,6 +51,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_clk.c', 'npcm7xx_gcr.c', )) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(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
Re: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 20 lines · Havard Skinnemoen
Quoted 19 lines · Havard Skinnemoen
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Havard Skinnemoen via
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>---
[...]
Quoted 33 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) {hw/misc/npcm7xx_clk.c line 156
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: offset 0x%04" HWADDR_PRIx" out of range\n" , + __func__, offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value);Isn't this sufficient?
Quoted 6 lines
Quoted 1 line
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);It's not quite that easy; this register holds 4 bits, each of which maps to a separate register which defines the modules to reset. It's not that hard, but a little more than I'd like to add to the series at this point. I'll send a followup patch once the initial series is in.
Actually, I'm not sure if this would have any effect on being able to reboot. Running with -d unimp shows:
Quoted 6 lines
reboot: Restarting system
npcm7xx_timer_write: WTCR write not implemented:0x00000083Reboot failed -- System haltedSo we need to implement watchdog support, which is something we were planning to do fairly soon.
Well this seems a guest implementation decision to prefer wait the watchdog to kick (hard reset?) rather than doing a soft reset.
Two different issues IMO. Anyway this is certainly not blocking your series to get merged.
Regards,
Phil.
Re: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model
Quoted 63 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Havard Skinnemoen
Quoted 19 lines · Havard Skinnemoen
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Havard Skinnemoen via
Enough functionality to boot the Linux kernel has been implemented. This includes:
- Correct power-on reset values so the various clock rates can be accurately calculated.
- Clock enables stick around when written.In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them.
Reviewed-by Tyrone Ting <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>---
[...]
Quoted 33 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+static void npcm7xx_clk_write (void *opaque,hwaddr offset, +uint64_t v,unsigned size) +{ +uint32_t reg = offset /sizeof (uint32_t ); +NPCM7xxCLKState *s = opaque; +uint32_t value = v; + +trace_npcm7xx_clk_write (offset, value); + +if (reg >=NPCM7XX_CLK_NR_REGS ) {hw/misc/npcm7xx_clk.c line 156
Quoted 10 lines
hw/misc/npcm7xx_clk.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: offset 0x%04" HWADDR_PRIx" out of range\n" , + __func__, offset); +return ; + } + +switch (reg) { +case NPCM7XX_CLK_SWRSTR : +qemu_log_mask (LOG_UNIMP ,"%s: SW reset not implemented: 0x%02x\n" , + __func__, value);Isn't this sufficient?
Quoted 6 lines
Quoted 1 line
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);It's not quite that easy; this register holds 4 bits, each of which maps to a separate register which defines the modules to reset. It's not that hard, but a little more than I'd like to add to the series at this point. I'll send a followup patch once the initial series is in.
Actually, I'm not sure if this would have any effect on being able to reboot. Running with -d unimp shows:
Quoted 6 lines
reboot: Restarting system
npcm7xx_timer_write: WTCR write not implemented:0x00000083Reboot failed -- System haltedSo we need to implement watchdog support, which is something we were planning to do fairly soon.
Quoted 6 lines
Well this seems a guest implementation decision to prefer wait the watchdog to kick (hard reset?) rather than doing a soft reset.
Two different issues IMO. Anyway this is certainly not blocking your series to get merged.
I agree, we need to implement both. I just wanted to note that implementing SWRST alone may not be enough to make reboots work with the current image. The SW reset registers are actually very similar to the WD reset registers, so implementing WD reset should make it almost trivial to add SW reset as well.
It looks like the kernel has a driver that can use SW reset to reboot, but the DT is missing a property needed to set up the restart handler.
https://elixir.bootlin.com/linux/v5.8.7/source/drivers/reset/reset-npcm.c#L269
Havard
PATCH v8 4/14 hw/arm: Add NPCM730 and NPCM750 SoC models
In reply to Havard Skinnemoen viaThe 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/meson.build | 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
@@ -357,6 +357,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/meson.build +1 -0
@@ -13,6 +13,7 @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c')) arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) +arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c')) arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c')) arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c')) arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
PATCH v8 5/14 hw/arm: Add two NPCM7xx-based machines
In reply to Havard Skinnemoen viaThis 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/meson.build | 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/meson.build +1 -1
@@ -13,7 +13,7 @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c')) arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) -arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c')) +arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c')) arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c')) arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c')) arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
PATCH v8 7/14 hw/arm: Load -bios image as a boot ROM for npcm7xx
In reply to Havard Skinnemoen viaIf 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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
hw/arm/npcm7xx_boards.c +33 -0
@@ -18,12 +18,43 @@#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 (MachineState *machine,NPCM7xxState *soc) +{ + g_autofree char *filename = NULL; +int ret; + +if (machine->kernel_filename) { +/* Don't load the bootrom if user requested direct kernel boot. */ +return ; + } + +if (!bios_name) { + bios_name = npcm7xx_default_bootrom; + } + + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Could not find ROM image '%s'" , bios_name); +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 +91,7 @@ static void npcm750_evb_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (machine, soc);npcm7xx_load_kernel (machine, soc); }
@@ -71,6 +103,7 @@ static void quanta_gsj_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (machine, soc);npcm7xx_load_kernel (machine, soc); }
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 07/14] hw/arm: Load -bios image as a boot ROM for npcm7xx
Quoted 31 lines · Havard Skinnemoen via
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]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- hw/arm/npcm7xx_boards.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)hw/arm/npcm7xx_boards.c +3
-0@@ -18,12 +18,43 @@#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
hw/arm/npcm7xx_boards.c line 39
Quoted 10 lines
hw/arm/npcm7xx_boards.c +10
-0+static const char npcm7xx_default_bootrom[] ="npcm7xx_bootrom.bin" ; + +static void npcm7xx_load_bootrom (MachineState *machine,NPCM7xxState *soc) +{ + g_autofree char *filename = NULL; +int ret; + +if (machine->kernel_filename) { +/* Don't load the bootrom if user requested direct kernel boot. */ +return ;
Wondering why not load it always if available, and what would happen if booting from a kernel (without bootrom) and running "reboot" (via SysRq) in the guest I got:
# echo b > /proc/sysrq-trigger sysrq: Resetting CPU0: stopping CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.4.32-7dc9442-dirty-8978043 #1 Hardware name: NPCM7XX Chip family Backtrace: [<b0107c4c>] (dump_backtrace) from [<b010823c>] (show_stack+0x20/0x24) r7:00000000 r6:600f0193 r5:00000000 r4:b0b5b1b8 [<b010821c>] (show_stack) from [<b077b230>] (dump_stack+0x94/0xa8) [<b077b19c>] (dump_stack) from [<b010a20c>] (handle_IPI+0x1f0/0x38c) r7:00000000 r6:00000004 r5:b0b5eb64 r4:b0b729e0 [<b010a01c>] (handle_IPI) from [<b0102264>] (gic_handle_irq+0x9c/0xa0) r10:10c5387d r9:b0b01ef8 r8:d0803100 r7:d0802100 r6:d080210c r5:b0b37db4 r4:b0b04504 [<b01021c8>] (gic_handle_irq) from [<b0101a8c>] (__irq_svc+0x6c/0x90) Exception stack(0xb0b01ef8 to 0xb0b01f40) 1ee0: 00000000 00012f74 1f00: cfbc1774 b01112e0 b0b00000 00000000 b0b03e28 b0b03e6c b0b5e72c b08e5ea8 1f20: 10c5387d b0b01f54 b0b01f58 b0b01f48 b0104114 b0104118 600f0013 ffffffff r9:b0b00000 r8:b0b5e72c r7:b0b01f2c r6:ffffffff r5:600f0013 r4:b0104118 [<b01040d4>] (arch_cpu_idle) from [<b014b240>] (do_idle+0xec/0x140) [<b014b154>] (do_idle) from [<b014b56c>] (cpu_startup_entry+0x28/0x2c) r9:410fc090 r8:0810c000 r7:00000000 r6:b0a53a40 r5:00000001 r4:000000ce [<b014b544>] (cpu_startup_entry) from [<b0794f6c>] (rest_init+0xb4/0xbc) [<b0794eb8>] (rest_init) from [<b0a00c50>] (arch_call_rest_init+0x18/0x1c) r5:00000001 r4:b0b72754 [<b0a00c38>] (arch_call_rest_init) from [<b0a010f4>] (start_kernel+0x428/0x458) [<b0a00ccc>] (start_kernel) from [<00000000>] (0x0) Reboot failed -- System halted
So not a problem so far...
But still I'd keep loading the bootrom regardless -kernel.
Quoted 38 lines
hw/arm/npcm7xx_boards.c +20
-0+ } + +if (!bios_name) { + bios_name = npcm7xx_default_bootrom; + } + + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Could not find ROM image '%s'" , bios_name); +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 +91,7 @@ static void npcm750_evb_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (machine, soc);npcm7xx_load_kernel (machine, soc); }@@ -71,6 +103,7 @@ static void quanta_gsj_init(MachineState *machine)npcm7xx_connect_dram (soc, machine->ram);qdev_realize (DEVICE (soc),NULL , &error_fatal); +npcm7xx_load_bootrom (machine, soc);npcm7xx_load_kernel (machine, soc); }
Re: [PATCH v8 07/14] hw/arm: Load -bios image as a boot ROM for npcm7xx
Quoted 83 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Havard Skinnemoen via
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]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- hw/arm/npcm7xx_boards.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)hw/arm/npcm7xx_boards.c +1
-0@@ -18,12 +18,43 @@#include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" +#include "hw/loader.h" #include "qapi/error.h" hw/arm/npcm7xx_boards.c line 32
Quoted 10 lines
hw/arm/npcm7xx_boards.c +5
-0+#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(MachineState *machine, NPCM7xxState*soc)
hw/arm/npcm7xx_boards.c
Quoted 6 lines
hw/arm/npcm7xx_boards.c +6
-0+{ + g_autofree char *filename = NULL; +int ret; + +if (machine->kernel_filename) { +/* Don't load the bootrom if user requested direct kernel boot. */
hw/arm/npcm7xx_boards.c line 39
Quoted 1 line
hw/arm/npcm7xx_boards.c +1
-0+return ;Wondering why not load it always if available, and what would happen if booting from a kernel (without bootrom) and running "reboot" (via SysRq) in the guest I got:
# echo b > /proc/sysrq-trigger sysrq: Resetting CPU0: stopping CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.4.32-7dc9442-dirty-8978043 #1 Hardware name: NPCM7XX Chip family Backtrace: [<b0107c4c>] (dump_backtrace) from [<b010823c>] (show_stack+0x20/0x24) r7:00000000 r6:600f0193 r5:00000000 r4:b0b5b1b8 [<b010821c>] (show_stack) from [<b077b230>] (dump_stack+0x94/0xa8) [<b077b19c>] (dump_stack) from [<b010a20c>] (handle_IPI+0x1f0/0x38c) r7:00000000 r6:00000004 r5:b0b5eb64 r4:b0b729e0 [<b010a01c>] (handle_IPI) from [<b0102264>] (gic_handle_irq+0x9c/0xa0) r10:10c5387d r9:b0b01ef8 r8:d0803100 r7:d0802100 r6:d080210c r5:b0b37db4 r4:b0b04504 [<b01021c8>] (gic_handle_irq) from [<b0101a8c>] (__irq_svc+0x6c/0x90) Exception stack(0xb0b01ef8 to 0xb0b01f40) 1ee0: 00000000 00012f74 1f00: cfbc1774 b01112e0 b0b00000 00000000 b0b03e28 b0b03e6c b0b5e72c b08e5ea8 1f20: 10c5387d b0b01f54 b0b01f58 b0b01f48 b0104114 b0104118 600f0013 ffffffff r9:b0b00000 r8:b0b5e72c r7:b0b01f2c r6:ffffffff r5:600f0013 r4:b0104118 [<b01040d4>] (arch_cpu_idle) from [<b014b240>] (do_idle+0xec/0x140) [<b014b154>] (do_idle) from [<b014b56c>] (cpu_startup_entry+0x28/0x2c) r9:410fc090 r8:0810c000 r7:00000000 r6:b0a53a40 r5:00000001 r4:000000ce [<b014b544>] (cpu_startup_entry) from [<b0794f6c>] (rest_init+0xb4/0xbc) [<b0794eb8>] (rest_init) from [<b0a00c50>] (arch_call_rest_init+0x18/0x1c) r5:00000001 r4:b0b72754 [<b0a00c38>] (arch_call_rest_init) from [<b0a010f4>] (start_kernel+0x428/0x458) [<b0a00ccc>] (start_kernel) from [<00000000>] (0x0) Reboot failed -- System halted
Quoted 5 lines
So not a problem so far...
Reviewed-by Philippe Mathieu-Daudé <[email protected]>But still I'd keep loading the bootrom regardless -kernel.
So you mean something like this?
@@ -35,11 +35,6 @@ static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
g_autofree char *filename = NULL;
int ret;- if (machine->kernel_filename) {
- /* Don't load the bootrom if user requested direct kernel boot. */
- return;
- }
-
if (!bios_name) {
bios_name = npcm7xx_default_bootrom;
}
@@ -47,7 +42,11 @@ static void npcm7xx_load_bootrom(MachineState *machine,
NPCM7xxState *soc)
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (!filename) {
error_report("Could not find ROM image '%s'", bios_name);- exit(1);
+ if (!machine->kernel_filename) {
+ /* We can't boot without a bootrom or a kernel image. */
+ exit(1);
+ }
+ return;
}
ret = load_image_mr(filename, &soc->irom);
if (ret < 0) {I'm not sure if it will make much of a difference, as (IIUC) arm_load_kernel installs a reset hook to jump directly into the kernel, bypassing the bootrom entirely. I'm assuming a watchdog or SW reset would trigger the same reset hook and jump right back into the kernel, though I could be wrong.
Anyway, I can make the above change in any case.
Havard
PATCH v8 9/14 hw/mem: Stubbed out NPCM7xx Memory Controller model
In reply to Havard Skinnemoen viaThis 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/meson.build | 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/meson.build +1 -0
@@ -1,6 +1,7 @@ mem_ss = ss.source_set() mem_ss.add(files('memory-device.c')) mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c')) +mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c')) mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c')) softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
PATCH v8 6/14 roms: Add virtual Boot ROM for NPCM7xx SoCs
In reply to Havard Skinnemoen viaThis 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 +++ MAINTAINERS | 2 ++ pc-bios/README | 6 ++++++ pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 +++++++ roms/vbootrom | 1 + 7 files changed, 20 insertions(+) create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom
Makefile +1 -0
@@ -246,6 +246,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
@@ -61,3 +61,6 @@ [submodule "meson"] path = meson url = https://github.com/mesonbuild/meson/ +[submodule "roms/vbootrom"] + path = roms/vbootrom + url = https://github.com/google/vbootrom.git
MAINTAINERS +2 -0
@@ -756,6 +756,8 @@ L: [email protected] S: Supported F: hw/*/npcm7xx* F: include/hw/*/npcm7xx* +F: pc-bios/npcm7xx_bootrom.bin +F: roms/vbootrom nSeries M: Andrzej Zaborowski <[email protected]>
pc-bios/README +6 -0
@@ -71,3 +71,9 @@ ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI source code also contains code reused from other projects desribed here: https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md. + +- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton + NPCM7xx BMC devices. It currently implements the bare minimum to load, parse, + initialize and run boot images stored in SPI flash, but may grow more + features over time as needed. The source code is available at: + https://github.com/google/vbootrom
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-generic -- update OpenSBI for 32-bit generic machine" @echo " opensbi64-generic -- update OpenSBI for 64-bit generic machine"
@@ -186,6 +188,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
@@ -199,3 +205,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.297.g1956fa8f8d-goog
Re: [PATCH v8 06/14] roms: Add virtual Boot ROM for NPCM7xx SoCs
Quoted 5 lines · Havard Skinnemoen via
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]>
Quoted 11 lines
--- Makefile | 1 + .gitmodules | 3 +++ MAINTAINERS | 2 ++ pc-bios/README | 6 ++++++ pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 +++++++ roms/vbootrom | 1 + 7 files changed, 20 insertions(+) create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom
This seems to need yet another rebase...
PATCH v8 10/14 hw/ssi: NPCM7xx Flash Interface Unit device model
In reply to Havard Skinnemoen viaThis 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 | 73 +++++ hw/arm/npcm7xx.c | 58 ++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + 7 files changed, 718 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 +73 -0
73 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 +572 -0
572 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -361,6 +361,7 @@ config NPCM7XX select ARM_GIC select PL310 # cache controller select SERIAL + select SSI select UNIMP config FSL_IMX25
hw/ssi/meson.build +1 -0
@@ -1,5 +1,6 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c')) softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c')) softmmu_ss.add(when: 'CONFIG_PL022', if_true: files('pl022.c')) softmmu_ss.add(when: 'CONFIG_SSI', if_true: files('ssi.c')) softmmu_ss.add(when: 'CONFIG_STM32F2XX_SPI', if_true: files('stm32f2xx_spi.c'))
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.297.g1956fa8f8d-goog
PATCH v8 13/14 docs/system: Add Nuvoton machine documentation
In reply to Havard Skinnemoen via--- 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
@@ -86,6 +86,7 @@ undocumented; you can get a complete list by running arm/musicpal arm/gumstix arm/nseries + arm/nuvoton arm/orangepi arm/palm arm/xscale
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 13/14] docs/system: Add Nuvoton machine documentation
Quoted 88 lines · Havard Skinnemoen via
Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- docs/system/arm/nuvoton.rst | 90 +++++++++++++++++++++++++++++++++++++ docs/system/target-arm.rst | 1 + 2 files changed, 91 insertions(+) create mode 100644 docs/system/arm/nuvoton.rstdocs/system/arm/nuvoton.rst new file +74
-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
docs/system/arm/nuvoton.rst line 84
Quoted 10 lines
docs/system/arm/nuvoton.rst new file +10
-0+ +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/ +
Maybe mention the usual root password is '0penBmc'?
Otherwise:
Quoted 19 lines
docs/system/arm/nuvoton.rst new file +6
-0+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=rawdocs/system/target-arm.rst +1
-0@@ -86,6 +86,7 @@ undocumented; you can get a complete list by running arm/musicpal arm/gumstix arm/nseries + arm/nuvoton arm/orangepi arm/palm arm/xscale
PATCH v8 8/14 hw/nvram: NPCM7xx OTP device model
In reply to Havard Skinnemoen viaThis 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 | 79 ++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + 5 files changed, 551 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 +79 -0
79 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 +439 -0
439 lines not on this page · raw message
hw/nvram/meson.build +1 -0
@@ -4,6 +4,7 @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c')) softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c')) softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 08/14] hw/nvram: NPCM7xx OTP device model
Quoted 590 lines · Havard Skinnemoen via
This supports reading and writing OTP fuses and keys. Only fuse reading has been tested. Protection is not implemented.
Reviewed-by Avi Fishman <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 79 ++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + 5 files changed, 551 insertions(+) create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 hw/nvram/npcm7xx_otp.cinclude/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 +79
-0@@ -0,0 +1,79 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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_OTP_H +#define NPCM7XX_OTP_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* Each OTP module holds 8192 bits of one-time programmable storage */ +#define NPCM7XX_OTP_ARRAY_BITS (8192) +#define NPCM7XX_OTP_ARRAY_BYTES (NPCM7XX_OTP_ARRAY_BITS / BITS_PER_BYTE) + +/* Fuse array offsets */ +#define NPCM7XX_FUSE_FUSTRAP (0) +#define NPCM7XX_FUSE_CP_FUSTRAP (12) +#define NPCM7XX_FUSE_DAC_CALIB (16) +#define NPCM7XX_FUSE_ADC_CALIB (24) +#define NPCM7XX_FUSE_DERIVATIVE (64) +#define NPCM7XX_FUSE_TEST_SIG (72) +#define NPCM7XX_FUSE_DIE_LOCATION (74) +#define NPCM7XX_FUSE_GP1 (80) +#define NPCM7XX_FUSE_GP2 (128) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_OTP_NR_REGS (0x18 / sizeof(uint32_t)) + +/** +* struct NPCM7xxOTPState - Device state for one OTP module. +* @parent: System bus device. +* @mmio: Memory region through which registers are accessed. +* @regs: Register contents. +* @array: OTP storage array. +*/ +typedef struct NPCM7xxOTPState { +SysBusDevice parent; + +MemoryRegion mmio; +uint32_t regs[NPCM7XX_OTP_NR_REGS ]; +uint8_t array[NPCM7XX_OTP_ARRAY_BYTES ]; +}NPCM7xxOTPState ; + +#define TYPE_NPCM7XX_OTP "npcm7xx-otp" +#define NPCM7XX_OTP (obj) OBJECT_CHECK(NPCM7xxOTPState, (obj), TYPE_NPCM7XX_OTP) + +#define TYPE_NPCM7XX_KEY_STORAGE "npcm7xx-key-storage" +#define TYPE_NPCM7XX_FUSE_ARRAY "npcm7xx-fuse-array" + +typedef struct NPCM7xxOTPClass NPCM7xxOTPClass ; + +/** +* npcm7xx_otp_array_write - ECC encode and write data to OTP array. +* @s: OTP module. +* @data: Data to be encoded and written. +* @offset: Offset of first byte to be written in the OTP array. +* @len: Number of bytes before ECC encoding. +* +* Each nibble of data is encoded into a byte, so the number of bytes written +* to the array will be @len * 2. +*/ +extern void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len); + +#endif /* NPCM7XX_OTP_H */ 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 +401
-0@@ -0,0 +1,439 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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 "hw/nvram/npcm7xx_otp.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +/* Each module has 4 KiB of register space. Only a fraction of it is used. */ +#define NPCM7XX_OTP_REGS_SIZE (4 * KiB) + +/* 32-bit register indices. */ +typedef enum NPCM7xxOTPRegister { +NPCM7XX_OTP_FST , +NPCM7XX_OTP_FADDR , +NPCM7XX_OTP_FDATA , +NPCM7XX_OTP_FCFG , +/* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */ +NPCM7XX_OTP_FKEYIND =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FUSTRAP =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FCTL , +NPCM7XX_OTP_REGS_END , +}NPCM7xxOTPRegister ; + +/* Register field definitions. */ +#define FST_RIEN BIT(2) +#define FST_RDST BIT(1) +#define FST_RDY BIT(0) +#define FST_RO_MASK (FST_RDST | FST_RDY) + +#define FADDR_BYTEADDR (rv) extract32((rv), 0, 10) +#define FADDR_BITPOS (rv) extract32((rv), 10, 3) + +#define FDATA_CLEAR 0x00000001 + +#define FCFG_FDIS BIT(31) +#define FCFG_FCFGLK_MASK 0x00ff0000 + +#define FCTL_PROG_CMD1 0x00000001 +#define FCTL_PROG_CMD2 0xbf79e5d0 +#define FCTL_READ_CMD 0x00000002 + +/** +* struct NPCM7xxOTPClass - OTP module class. +* @parent: System bus device class. +* @mmio_ops: MMIO register operations for this type of module. +* +* The two OTP modules (key-storage and fuse-array) have slightly different +* behavior, so we give them different MMIO register operations. +*/ +struct NPCM7xxOTPClass { +SysBusDeviceClass parent; + +const MemoryRegionOps *mmio_ops; +}; + +#define NPCM7XX_OTP_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP) +#define NPCM7XX_OTP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP) + +static uint8_t ecc_encode_nibble (uint8_t n) +{ +uint8_t result = n; + + result |= (((n >>0 ) &1 ) ^ ((n >>1 ) &1 )) <<4 ; + result |= (((n >>2 ) &1 ) ^ ((n >>3 ) &1 )) <<5 ; + result |= (((n >>0 ) &1 ) ^ ((n >>2 ) &1 )) <<6 ; + result |= (((n >>1 ) &1 ) ^ ((n >>3 ) &1 )) <<7 ; + +return result; +} + +void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len) +{ +const uint8_t *src = data; +uint8_t *dst = &s->array[offset]; + +while (len-- >0 ) { +uint8_t c = *src++; + + *dst++ =ecc_encode_nibble (extract8 (c,0 ,4 )); + *dst++ =ecc_encode_nibble (extract8 (c,4 ,4 )); + } +} + +/* Common register read handler for both OTP classes. */ +static uint64_t npcm7xx_otp_read (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg) +{ +uint32_t value =0 ; + +switch (reg) { +case NPCM7XX_OTP_FST : +case NPCM7XX_OTP_FADDR : +case NPCM7XX_OTP_FDATA : +case NPCM7XX_OTP_FCFG : + value = s->regs[reg]; +break ; + +case NPCM7XX_OTP_FCTL : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: read from write-only FCTL register\n" , +DEVICE (s)->canonical_path); +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: read from invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +break ; + } + +return value; +} + +/* Read a byte from the OTP array into the data register. */ +static void npcm7xx_otp_read_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + + s->regs[NPCM7XX_OTP_FDATA ] = s->array[FADDR_BYTEADDR (faddr)]; + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Program a byte from the data register into the OTP array. */ +static void npcm7xx_otp_program_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + +/* Bits can only go 0->1, never 1->0. */ + s->array[FADDR_BYTEADDR (faddr)] |= (1U <<FADDR_BITPOS (faddr)); + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Compute the next value of the FCFG register. */ +static uint32_t npcm7xx_otp_compute_fcfg (uint32_t cur_value,uint32_t new_value) +{ +uint32_t lock_mask; +uint32_t value; + +/* +* FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15) +* and FRDLK (0..7) that are read-only. +*/ + lock_mask = (cur_value &FCFG_FCFGLK_MASK ) >>8 ; + lock_mask |= lock_mask >>8 ; +/* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */ + value = cur_value & (FCFG_FDIS |FCFG_FCFGLK_MASK ); +/* Preserve read-only bits in FPRGLK and FRDLK */ + value |= cur_value & lock_mask; +/* Set all bits that aren't read-only. */ + value |= new_value & ~lock_mask; + +return value; +} + +/* Common register write handler for both OTP classes. */ +static void npcm7xx_otp_write (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg, +uint32_t value) +{ +switch (reg) { +case NPCM7XX_OTP_FST : +/* RDST is cleared by writing 1 to it. */ +if (value &FST_RDST ) { + s->regs[NPCM7XX_OTP_FST ] &= ~FST_RDST ; + } +/* Preserve read-only and write-one-to-clear bits */ + value &= ~FST_RO_MASK ; + value |= s->regs[NPCM7XX_OTP_FST ] &FST_RO_MASK ; +break ; + +case NPCM7XX_OTP_FADDR : +break ; + +case NPCM7XX_OTP_FDATA : +/* +* This register is cleared by writing a magic value to it; no other +* values can be written. +*/ +if (value ==FDATA_CLEAR ) { + value =0 ; + }else { + value = s->regs[NPCM7XX_OTP_FDATA ]; + } +break ; + +case NPCM7XX_OTP_FCFG : + value =npcm7xx_otp_compute_fcfg (s->regs[NPCM7XX_OTP_FCFG ], value); +break ; + +case NPCM7XX_OTP_FCTL : +switch (value) { +case FCTL_READ_CMD : +npcm7xx_otp_read_array (s); +break ; + +case FCTL_PROG_CMD1 : +/* +* Programming requires writing two separate magic values to this +* register; this is the first one. Just store it so it can be +* verified later when the second magic value is received. +*/ +break ; + +case FCTL_PROG_CMD2 : +/* +* Only initiate programming if we received the first half of the +* command immediately before this one. +*/ +if (s->regs[NPCM7XX_OTP_FCTL ] ==FCTL_PROG_CMD1 ) { +npcm7xx_otp_program_array (s); + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unrecognized FCNTL value 0x%" PRIx32"\n" , +DEVICE (s)->canonical_path, value); +break ; + } +if (value !=FCTL_PROG_CMD1 ) { + value =0 ; + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: write to invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +return ; + } + + s->regs[reg] = value; +} + +/* Register read handler specific to the fuse array OTP module. */ +static uint64_t npcm7xx_fuse_array_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; +uint32_t value; + +/* +* Only the Fuse Strap register needs special handling; all other registers +* work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { + value =npcm7xx_otp_read (s, reg); + }else { +/* FUSTRAP is stored as three copies in the OTP array. */ +uint32_t fustrap[3 ]; + +memcpy (fustrap, &s->array[0 ],sizeof (fustrap)); + +/* Determine value by a majority vote on each bit. */ + value = (fustrap[0 ] & fustrap[1 ]) | (fustrap[0 ] & fustrap[2 ]) | + (fustrap[1 ] & fustrap[2 ]); + } + +return value; +} + +/* Register write handler specific to the fuse array OTP module. */ +static void npcm7xx_fuse_array_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* The Fuse Strap register is read-only. Other registers are handled by +* common code. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { +npcm7xx_otp_write (s, reg, v); + } +} + +static const MemoryRegionOps npcm7xx_fuse_array_ops = { + .read = npcm7xx_fuse_array_read, + .write = npcm7xx_fuse_array_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +/* Register read handler specific to the key storage OTP module. */ +static uint64_t npcm7xx_key_storage_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +return npcm7xx_otp_read (s, reg); + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + +return s->regs[NPCM7XX_OTP_FKEYIND ]; +} + +/* Register write handler specific to the key storage OTP module. */ +static void npcm7xx_key_storage_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +npcm7xx_otp_write (s, reg, v); +return ; + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + + s->regs[NPCM7XX_OTP_FKEYIND ] = v; +} + +static const MemoryRegionOps npcm7xx_key_storage_ops = { + .read = npcm7xx_key_storage_read, + .write = npcm7xx_key_storage_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_otp_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxOTPState *s =NPCM7XX_OTP (obj); + +memset (s->regs,0 ,sizeof (s->regs)); + + s->regs[NPCM7XX_OTP_FST ] =0x00000001 ; + s->regs[NPCM7XX_OTP_FCFG ] =0x20000000 ; +} + +static void npcm7xx_otp_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_GET_CLASS (dev); +NPCM7xxOTPState *s =NPCM7XX_OTP (dev); +SysBusDevice *sbd = &s->parent; + +memset (s->array,0 ,sizeof (s->array)); + +memory_region_init_io (&s->mmio,OBJECT (s), oc->mmio_ops, s,"regs" , +NPCM7XX_OTP_REGS_SIZE ); +sysbus_init_mmio (sbd, &s->mmio); +} + +static const VMStateDescription vmstate_npcm7xx_otp = { + .name ="npcm7xx-otp" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxOTPState,NPCM7XX_OTP_NR_REGS ), +VMSTATE_UINT8_ARRAY (array, NPCM7xxOTPState,NPCM7XX_OTP_ARRAY_BYTES ), +VMSTATE_END_OF_LIST (), + }, +}; + +static void npcm7xx_otp_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_OTP_REGS_END >NPCM7XX_OTP_NR_REGS ); + + dc->realize = npcm7xx_otp_realize;
hw/nvram/npcm7xx_otp.c line 411
Quoted 10 lines
hw/nvram/npcm7xx_otp.c new file +10
-0+ dc->vmsd = &vmstate_npcm7xx_otp; + rc->phases.enter = npcm7xx_otp_enter_reset; +} + +static void npcm7xx_key_storage_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); + + oc->mmio_ops = &npcm7xx_key_storage_ops; +}
Hello,
With this series applied, when I build with --enable-sanitizers and run ./qemu-system-arm:
==373753==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61000000b400 at pc 0x557496abbefc bp 0x7ffdd5851210 sp 0x7ffdd5851208 WRITE of size 8 at 0x61000000b400 thread T0
#0 0x557496abbefb in npcm7xx_key_storage_class_init /../hw/nvram/npcm7xx_otp.c:410:18
#1 0x5574998a8780 in type_initialize /../qom/object.c:362:9
#2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5
#3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f)
#4 0x5574998a9a41 in object_class_foreach /../qom/object.c:1052:5
#5 0x5574998ab28a in object_class_get_list /../qom/object.c:1109:5
#6 0x557498e6f8e1 in select_machine /../softmmu/vl.c:2438:24
#7 0x557498e5a921 in qemu_init /../softmmu/vl.c:3842:21
#8 0x557495b181d7 in main /../softmmu/main.c:49:5
#9 0x7fc269e7dcc9 in __libc_start_main csu/../csu/libc-start.c:308:16
#10 0x557495a6d9b9 in _start (/qemu-system-arm+0x35959b9)0x61000000b400 is located 0 bytes to the right of 192-byte region [0x61000000b340,0x61000000b400) allocated by thread T0 here:
#0 0x557495ae6272 in calloc (/qemu-system-arm+0x360e272)
#1 0x7fc26b43f210 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x56210)
#2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5
#3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f)SUMMARY: AddressSanitizer: heap-buffer-overflow /../hw/nvram/npcm7xx_otp.c:410:18 in npcm7xx_key_storage_class_init
-Alex
Quoted 44 lines
hw/nvram/npcm7xx_otp.c new file +28
-0+ +static void npcm7xx_fuse_array_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); + + oc->mmio_ops = &npcm7xx_fuse_array_ops; +} + +static const TypeInfo npcm7xx_otp_types[] = { + { + .name =TYPE_NPCM7XX_OTP , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxOTPState), + .class_init = npcm7xx_otp_class_init, + .abstract = true, + }, + { + .name =TYPE_NPCM7XX_KEY_STORAGE , + .parent =TYPE_NPCM7XX_OTP , + .class_init = npcm7xx_key_storage_class_init, + }, + { + .name =TYPE_NPCM7XX_FUSE_ARRAY , + .parent =TYPE_NPCM7XX_OTP , + .class_init = npcm7xx_fuse_array_class_init, + }, +}; +DEFINE_TYPES (npcm7xx_otp_types);hw/nvram/meson.build +1
-0@@ -4,6 +4,7 @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c')) softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c')) softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 08/14] hw/nvram: NPCM7xx OTP device model
Quoted 631 lines · Alexander Bulekov
Quoted 590 lines · Havard Skinnemoen via
This supports reading and writing OTP fuses and keys. Only fuse reading has been tested. Protection is not implemented.
Reviewed-by Avi Fishman <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 79 ++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + 5 files changed, 551 insertions(+) create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 hw/nvram/npcm7xx_otp.cinclude/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 +79
-0@@ -0,0 +1,79 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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_OTP_H +#define NPCM7XX_OTP_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* Each OTP module holds 8192 bits of one-time programmable storage */ +#define NPCM7XX_OTP_ARRAY_BITS (8192) +#define NPCM7XX_OTP_ARRAY_BYTES (NPCM7XX_OTP_ARRAY_BITS / BITS_PER_BYTE) + +/* Fuse array offsets */ +#define NPCM7XX_FUSE_FUSTRAP (0) +#define NPCM7XX_FUSE_CP_FUSTRAP (12) +#define NPCM7XX_FUSE_DAC_CALIB (16) +#define NPCM7XX_FUSE_ADC_CALIB (24) +#define NPCM7XX_FUSE_DERIVATIVE (64) +#define NPCM7XX_FUSE_TEST_SIG (72) +#define NPCM7XX_FUSE_DIE_LOCATION (74) +#define NPCM7XX_FUSE_GP1 (80) +#define NPCM7XX_FUSE_GP2 (128) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_OTP_NR_REGS (0x18 / sizeof(uint32_t)) + +/** +* struct NPCM7xxOTPState - Device state for one OTP module. +* @parent: System bus device. +* @mmio: Memory region through which registers are accessed. +* @regs: Register contents. +* @array: OTP storage array. +*/ +typedef struct NPCM7xxOTPState { +SysBusDevice parent; + +MemoryRegion mmio; +uint32_t regs[NPCM7XX_OTP_NR_REGS ]; +uint8_t array[NPCM7XX_OTP_ARRAY_BYTES ]; +}NPCM7xxOTPState ; + +#define TYPE_NPCM7XX_OTP "npcm7xx-otp" +#define NPCM7XX_OTP (obj) OBJECT_CHECK(NPCM7xxOTPState, (obj), TYPE_NPCM7XX_OTP) + +#define TYPE_NPCM7XX_KEY_STORAGE "npcm7xx-key-storage" +#define TYPE_NPCM7XX_FUSE_ARRAY "npcm7xx-fuse-array" + +typedef struct NPCM7xxOTPClass NPCM7xxOTPClass ; + +/** +* npcm7xx_otp_array_write - ECC encode and write data to OTP array. +* @s: OTP module. +* @data: Data to be encoded and written. +* @offset: Offset of first byte to be written in the OTP array. +* @len: Number of bytes before ECC encoding. +* +* Each nibble of data is encoded into a byte, so the number of bytes written +* to the array will be @len * 2. +*/ +extern void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len); + +#endif /* NPCM7XX_OTP_H */ 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 +401
-0@@ -0,0 +1,439 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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 "hw/nvram/npcm7xx_otp.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +/* Each module has 4 KiB of register space. Only a fraction of it is used. */ +#define NPCM7XX_OTP_REGS_SIZE (4 * KiB) + +/* 32-bit register indices. */ +typedef enum NPCM7xxOTPRegister { +NPCM7XX_OTP_FST , +NPCM7XX_OTP_FADDR , +NPCM7XX_OTP_FDATA , +NPCM7XX_OTP_FCFG , +/* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */ +NPCM7XX_OTP_FKEYIND =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FUSTRAP =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FCTL , +NPCM7XX_OTP_REGS_END , +}NPCM7xxOTPRegister ; + +/* Register field definitions. */ +#define FST_RIEN BIT(2) +#define FST_RDST BIT(1) +#define FST_RDY BIT(0) +#define FST_RO_MASK (FST_RDST | FST_RDY) + +#define FADDR_BYTEADDR (rv) extract32((rv), 0, 10) +#define FADDR_BITPOS (rv) extract32((rv), 10, 3) + +#define FDATA_CLEAR 0x00000001 + +#define FCFG_FDIS BIT(31) +#define FCFG_FCFGLK_MASK 0x00ff0000 + +#define FCTL_PROG_CMD1 0x00000001 +#define FCTL_PROG_CMD2 0xbf79e5d0 +#define FCTL_READ_CMD 0x00000002 + +/** +* struct NPCM7xxOTPClass - OTP module class. +* @parent: System bus device class. +* @mmio_ops: MMIO register operations for this type of module. +* +* The two OTP modules (key-storage and fuse-array) have slightly different +* behavior, so we give them different MMIO register operations. +*/ +struct NPCM7xxOTPClass { +SysBusDeviceClass parent; + +const MemoryRegionOps *mmio_ops; +}; + +#define NPCM7XX_OTP_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP) +#define NPCM7XX_OTP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP) + +static uint8_t ecc_encode_nibble (uint8_t n) +{ +uint8_t result = n; + + result |= (((n >>0 ) &1 ) ^ ((n >>1 ) &1 )) <<4 ; + result |= (((n >>2 ) &1 ) ^ ((n >>3 ) &1 )) <<5 ; + result |= (((n >>0 ) &1 ) ^ ((n >>2 ) &1 )) <<6 ; + result |= (((n >>1 ) &1 ) ^ ((n >>3 ) &1 )) <<7 ; + +return result; +} + +void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len) +{ +const uint8_t *src = data; +uint8_t *dst = &s->array[offset]; + +while (len-- >0 ) { +uint8_t c = *src++; + + *dst++ =ecc_encode_nibble (extract8 (c,0 ,4 )); + *dst++ =ecc_encode_nibble (extract8 (c,4 ,4 )); + } +} + +/* Common register read handler for both OTP classes. */ +static uint64_t npcm7xx_otp_read (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg) +{ +uint32_t value =0 ; + +switch (reg) { +case NPCM7XX_OTP_FST : +case NPCM7XX_OTP_FADDR : +case NPCM7XX_OTP_FDATA : +case NPCM7XX_OTP_FCFG : + value = s->regs[reg]; +break ; + +case NPCM7XX_OTP_FCTL : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: read from write-only FCTL register\n" , +DEVICE (s)->canonical_path); +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: read from invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +break ; + } + +return value; +} + +/* Read a byte from the OTP array into the data register. */ +static void npcm7xx_otp_read_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + + s->regs[NPCM7XX_OTP_FDATA ] = s->array[FADDR_BYTEADDR (faddr)]; + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Program a byte from the data register into the OTP array. */ +static void npcm7xx_otp_program_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + +/* Bits can only go 0->1, never 1->0. */ + s->array[FADDR_BYTEADDR (faddr)] |= (1U <<FADDR_BITPOS (faddr)); + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Compute the next value of the FCFG register. */ +static uint32_t npcm7xx_otp_compute_fcfg (uint32_t cur_value,uint32_t new_value) +{ +uint32_t lock_mask; +uint32_t value; + +/* +* FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15) +* and FRDLK (0..7) that are read-only. +*/ + lock_mask = (cur_value &FCFG_FCFGLK_MASK ) >>8 ; + lock_mask |= lock_mask >>8 ; +/* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */ + value = cur_value & (FCFG_FDIS |FCFG_FCFGLK_MASK ); +/* Preserve read-only bits in FPRGLK and FRDLK */ + value |= cur_value & lock_mask; +/* Set all bits that aren't read-only. */ + value |= new_value & ~lock_mask; + +return value; +} + +/* Common register write handler for both OTP classes. */ +static void npcm7xx_otp_write (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg, +uint32_t value) +{ +switch (reg) { +case NPCM7XX_OTP_FST : +/* RDST is cleared by writing 1 to it. */ +if (value &FST_RDST ) { + s->regs[NPCM7XX_OTP_FST ] &= ~FST_RDST ; + } +/* Preserve read-only and write-one-to-clear bits */ + value &= ~FST_RO_MASK ; + value |= s->regs[NPCM7XX_OTP_FST ] &FST_RO_MASK ; +break ; + +case NPCM7XX_OTP_FADDR : +break ; + +case NPCM7XX_OTP_FDATA : +/* +* This register is cleared by writing a magic value to it; no other +* values can be written. +*/ +if (value ==FDATA_CLEAR ) { + value =0 ; + }else { + value = s->regs[NPCM7XX_OTP_FDATA ]; + } +break ; + +case NPCM7XX_OTP_FCFG : + value =npcm7xx_otp_compute_fcfg (s->regs[NPCM7XX_OTP_FCFG ], value); +break ; + +case NPCM7XX_OTP_FCTL : +switch (value) { +case FCTL_READ_CMD : +npcm7xx_otp_read_array (s); +break ; + +case FCTL_PROG_CMD1 : +/* +* Programming requires writing two separate magic values to this +* register; this is the first one. Just store it so it can be +* verified later when the second magic value is received. +*/ +break ; + +case FCTL_PROG_CMD2 : +/* +* Only initiate programming if we received the first half of the +* command immediately before this one. +*/ +if (s->regs[NPCM7XX_OTP_FCTL ] ==FCTL_PROG_CMD1 ) { +npcm7xx_otp_program_array (s); + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unrecognized FCNTL value 0x%" PRIx32"\n" , +DEVICE (s)->canonical_path, value); +break ; + } +if (value !=FCTL_PROG_CMD1 ) { + value =0 ; + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: write to invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +return ; + } + + s->regs[reg] = value; +} + +/* Register read handler specific to the fuse array OTP module. */ +static uint64_t npcm7xx_fuse_array_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; +uint32_t value; + +/* +* Only the Fuse Strap register needs special handling; all other registers +* work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { + value =npcm7xx_otp_read (s, reg); + }else { +/* FUSTRAP is stored as three copies in the OTP array. */ +uint32_t fustrap[3 ]; + +memcpy (fustrap, &s->array[0 ],sizeof (fustrap)); + +/* Determine value by a majority vote on each bit. */ + value = (fustrap[0 ] & fustrap[1 ]) | (fustrap[0 ] & fustrap[2 ]) | + (fustrap[1 ] & fustrap[2 ]); + } + +return value; +} + +/* Register write handler specific to the fuse array OTP module. */ +static void npcm7xx_fuse_array_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* The Fuse Strap register is read-only. Other registers are handled by +* common code. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { +npcm7xx_otp_write (s, reg, v); + } +} + +static const MemoryRegionOps npcm7xx_fuse_array_ops = { + .read = npcm7xx_fuse_array_read, + .write = npcm7xx_fuse_array_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +/* Register read handler specific to the key storage OTP module. */ +static uint64_t npcm7xx_key_storage_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +return npcm7xx_otp_read (s, reg); + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + +return s->regs[NPCM7XX_OTP_FKEYIND ]; +} + +/* Register write handler specific to the key storage OTP module. */ +static void npcm7xx_key_storage_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +npcm7xx_otp_write (s, reg, v); +return ; + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + + s->regs[NPCM7XX_OTP_FKEYIND ] = v; +} + +static const MemoryRegionOps npcm7xx_key_storage_ops = { + .read = npcm7xx_key_storage_read, + .write = npcm7xx_key_storage_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_otp_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxOTPState *s =NPCM7XX_OTP (obj); + +memset (s->regs,0 ,sizeof (s->regs)); + + s->regs[NPCM7XX_OTP_FST ] =0x00000001 ; + s->regs[NPCM7XX_OTP_FCFG ] =0x20000000 ; +} + +static void npcm7xx_otp_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_GET_CLASS (dev); +NPCM7xxOTPState *s =NPCM7XX_OTP (dev); +SysBusDevice *sbd = &s->parent; + +memset (s->array,0 ,sizeof (s->array)); + +memory_region_init_io (&s->mmio,OBJECT (s), oc->mmio_ops, s,"regs" , +NPCM7XX_OTP_REGS_SIZE ); +sysbus_init_mmio (sbd, &s->mmio); +} + +static const VMStateDescription vmstate_npcm7xx_otp = { + .name ="npcm7xx-otp" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxOTPState,NPCM7XX_OTP_NR_REGS ), +VMSTATE_UINT8_ARRAY (array, NPCM7xxOTPState,NPCM7XX_OTP_ARRAY_BYTES ), +VMSTATE_END_OF_LIST (), + }, +}; + +static void npcm7xx_otp_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_OTP_REGS_END >NPCM7XX_OTP_NR_REGS ); + + dc->realize = npcm7xx_otp_realize;hw/nvram/npcm7xx_otp.c line 411
Quoted 10 lines
hw/nvram/npcm7xx_otp.c new file +10
-0+ dc->vmsd = &vmstate_npcm7xx_otp; + rc->phases.enter = npcm7xx_otp_enter_reset; +} + +static void npcm7xx_key_storage_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); + + oc->mmio_ops = &npcm7xx_key_storage_ops; +}Hello,
With this series applied, when I build with --enable-sanitizers and run ./qemu-system-arm:==373753==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x61000000b400at pc0x557496abbefcbp0x7ffdd5851210sp0x7ffdd5851208WRITE of size 8 at0x61000000b400thread T0#0 0x557496abbefb in npcm7xx_key_storage_class_init /../hw/nvram/npcm7xx_otp.c:410:18 #1 0x5574998a8780 in type_initialize /../qom/object.c:362:9 #2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5 #3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f) #4 0x5574998a9a41 in object_class_foreach /../qom/object.c:1052:5 #5 0x5574998ab28a in object_class_get_list /../qom/object.c:1109:5 #6 0x557498e6f8e1 in select_machine /../softmmu/vl.c:2438:24 #7 0x557498e5a921 in qemu_init /../softmmu/vl.c:3842:21 #8 0x557495b181d7 in main /../softmmu/main.c:49:5 #9 0x7fc269e7dcc9 in __libc_start_main csu/../csu/libc-start.c:308:16 #10 0x557495a6d9b9 in _start (/qemu-system-arm+0x35959b9)
0x61000000b400is located 0 bytes to the right of 192-byte region [0x61000000b340,0x61000000b400) allocated by thread T0 here:#0 0x557495ae6272 in calloc (/qemu-system-arm+0x360e272) #1 0x7fc26b43f210 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x56210) #2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5 #3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f)SUMMARY: AddressSanitizer: heap-buffer-overflow /../hw/nvram/npcm7xx_otp.c:410:18 in
npcm7xx_key_storage_class_init-Alex
Quoted 13 lines
hw/nvram/npcm7xx_otp.c line 424
Quoted 13 lines
hw/nvram/npcm7xx_otp.c new file +13
-0+ +static void npcm7xx_fuse_array_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); + + oc->mmio_ops = &npcm7xx_fuse_array_ops; +} + +static const TypeInfo npcm7xx_otp_types[] = { + { + .name =TYPE_NPCM7XX_OTP , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxOTPState),
Adding this fixes it for me:
.class_size = sizeof(NPCM7xxOTPClass),
-Alex
Quoted 31 lines
Quoted 31 lines
hw/nvram/npcm7xx_otp.c new file +15
-0+ .class_init = npcm7xx_otp_class_init, + .abstract = true, + }, + { + .name = TYPE_NPCM7XX_KEY_STORAGE, + .parent = TYPE_NPCM7XX_OTP, + .class_init = npcm7xx_key_storage_class_init, + }, + { + .name = TYPE_NPCM7XX_FUSE_ARRAY, + .parent = TYPE_NPCM7XX_OTP, + .class_init = npcm7xx_fuse_array_class_init, + }, +}; +DEFINE_TYPES (npcm7xx_otp_types);hw/nvram/meson.build +1
-0@@ -4,6 +4,7 @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c')) softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c')) softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 08/14] hw/nvram: NPCM7xx OTP device model
Quoted 633 lines · Alexander Bulekov
Quoted 631 lines · Alexander Bulekov
Quoted 590 lines · Havard Skinnemoen via
This supports reading and writing OTP fuses and keys. Only fuse reading has been tested. Protection is not implemented.
Reviewed-by Avi Fishman <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 79 ++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + 5 files changed, 551 insertions(+) create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 hw/nvram/npcm7xx_otp.cinclude/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 +79
-0@@ -0,0 +1,79 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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_OTP_H +#define NPCM7XX_OTP_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* Each OTP module holds 8192 bits of one-time programmable storage */ +#define NPCM7XX_OTP_ARRAY_BITS (8192) +#define NPCM7XX_OTP_ARRAY_BYTES (NPCM7XX_OTP_ARRAY_BITS / BITS_PER_BYTE) + +/* Fuse array offsets */ +#define NPCM7XX_FUSE_FUSTRAP (0) +#define NPCM7XX_FUSE_CP_FUSTRAP (12) +#define NPCM7XX_FUSE_DAC_CALIB (16) +#define NPCM7XX_FUSE_ADC_CALIB (24) +#define NPCM7XX_FUSE_DERIVATIVE (64) +#define NPCM7XX_FUSE_TEST_SIG (72) +#define NPCM7XX_FUSE_DIE_LOCATION (74) +#define NPCM7XX_FUSE_GP1 (80) +#define NPCM7XX_FUSE_GP2 (128) + +/* +* Number of registers in our device state structure. Don't change this without +* incrementing the version_id in the vmstate. +*/ +#define NPCM7XX_OTP_NR_REGS (0x18 / sizeof(uint32_t)) + +/** +* struct NPCM7xxOTPState - Device state for one OTP module. +* @parent: System bus device. +* @mmio: Memory region through which registers are accessed. +* @regs: Register contents. +* @array: OTP storage array. +*/ +typedef struct NPCM7xxOTPState { +SysBusDevice parent; + +MemoryRegion mmio; +uint32_t regs[NPCM7XX_OTP_NR_REGS ]; +uint8_t array[NPCM7XX_OTP_ARRAY_BYTES ]; +}NPCM7xxOTPState ; + +#define TYPE_NPCM7XX_OTP "npcm7xx-otp" +#define NPCM7XX_OTP (obj) OBJECT_CHECK(NPCM7xxOTPState, (obj), TYPE_NPCM7XX_OTP) + +#define TYPE_NPCM7XX_KEY_STORAGE "npcm7xx-key-storage" +#define TYPE_NPCM7XX_FUSE_ARRAY "npcm7xx-fuse-array" + +typedef struct NPCM7xxOTPClass NPCM7xxOTPClass ; + +/** +* npcm7xx_otp_array_write - ECC encode and write data to OTP array. +* @s: OTP module. +* @data: Data to be encoded and written. +* @offset: Offset of first byte to be written in the OTP array. +* @len: Number of bytes before ECC encoding. +* +* Each nibble of data is encoded into a byte, so the number of bytes written +* to the array will be @len * 2. +*/ +extern void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len); + +#endif /* NPCM7XX_OTP_H */ 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 +401
-0@@ -0,0 +1,439 @@ +/* +* Nuvoton NPCM7xx OTP (Fuse Array) Interface +* +* 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 "hw/nvram/npcm7xx_otp.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +/* Each module has 4 KiB of register space. Only a fraction of it is used. */ +#define NPCM7XX_OTP_REGS_SIZE (4 * KiB) + +/* 32-bit register indices. */ +typedef enum NPCM7xxOTPRegister { +NPCM7XX_OTP_FST , +NPCM7XX_OTP_FADDR , +NPCM7XX_OTP_FDATA , +NPCM7XX_OTP_FCFG , +/* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */ +NPCM7XX_OTP_FKEYIND =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FUSTRAP =0x0010 /sizeof (uint32_t ), +NPCM7XX_OTP_FCTL , +NPCM7XX_OTP_REGS_END , +}NPCM7xxOTPRegister ; + +/* Register field definitions. */ +#define FST_RIEN BIT(2) +#define FST_RDST BIT(1) +#define FST_RDY BIT(0) +#define FST_RO_MASK (FST_RDST | FST_RDY) + +#define FADDR_BYTEADDR (rv) extract32((rv), 0, 10) +#define FADDR_BITPOS (rv) extract32((rv), 10, 3) + +#define FDATA_CLEAR 0x00000001 + +#define FCFG_FDIS BIT(31) +#define FCFG_FCFGLK_MASK 0x00ff0000 + +#define FCTL_PROG_CMD1 0x00000001 +#define FCTL_PROG_CMD2 0xbf79e5d0 +#define FCTL_READ_CMD 0x00000002 + +/** +* struct NPCM7xxOTPClass - OTP module class. +* @parent: System bus device class. +* @mmio_ops: MMIO register operations for this type of module. +* +* The two OTP modules (key-storage and fuse-array) have slightly different +* behavior, so we give them different MMIO register operations. +*/ +struct NPCM7xxOTPClass { +SysBusDeviceClass parent; + +const MemoryRegionOps *mmio_ops; +}; + +#define NPCM7XX_OTP_CLASS (klass) \ + OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP) +#define NPCM7XX_OTP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP) + +static uint8_t ecc_encode_nibble (uint8_t n) +{ +uint8_t result = n; + + result |= (((n >>0 ) &1 ) ^ ((n >>1 ) &1 )) <<4 ; + result |= (((n >>2 ) &1 ) ^ ((n >>3 ) &1 )) <<5 ; + result |= (((n >>0 ) &1 ) ^ ((n >>2 ) &1 )) <<6 ; + result |= (((n >>1 ) &1 ) ^ ((n >>3 ) &1 )) <<7 ; + +return result; +} + +void npcm7xx_otp_array_write (NPCM7xxOTPState *s,const void *data, +unsigned int offset,unsigned int len) +{ +const uint8_t *src = data; +uint8_t *dst = &s->array[offset]; + +while (len-- >0 ) { +uint8_t c = *src++; + + *dst++ =ecc_encode_nibble (extract8 (c,0 ,4 )); + *dst++ =ecc_encode_nibble (extract8 (c,4 ,4 )); + } +} + +/* Common register read handler for both OTP classes. */ +static uint64_t npcm7xx_otp_read (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg) +{ +uint32_t value =0 ; + +switch (reg) { +case NPCM7XX_OTP_FST : +case NPCM7XX_OTP_FADDR : +case NPCM7XX_OTP_FDATA : +case NPCM7XX_OTP_FCFG : + value = s->regs[reg]; +break ; + +case NPCM7XX_OTP_FCTL : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: read from write-only FCTL register\n" , +DEVICE (s)->canonical_path); +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: read from invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +break ; + } + +return value; +} + +/* Read a byte from the OTP array into the data register. */ +static void npcm7xx_otp_read_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + + s->regs[NPCM7XX_OTP_FDATA ] = s->array[FADDR_BYTEADDR (faddr)]; + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Program a byte from the data register into the OTP array. */ +static void npcm7xx_otp_program_array (NPCM7xxOTPState *s) +{ +uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR ]; + +/* Bits can only go 0->1, never 1->0. */ + s->array[FADDR_BYTEADDR (faddr)] |= (1U <<FADDR_BITPOS (faddr)); + s->regs[NPCM7XX_OTP_FST ] |=FST_RDST |FST_RDY ; +} + +/* Compute the next value of the FCFG register. */ +static uint32_t npcm7xx_otp_compute_fcfg (uint32_t cur_value,uint32_t new_value) +{ +uint32_t lock_mask; +uint32_t value; + +/* +* FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15) +* and FRDLK (0..7) that are read-only. +*/ + lock_mask = (cur_value &FCFG_FCFGLK_MASK ) >>8 ; + lock_mask |= lock_mask >>8 ; +/* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */ + value = cur_value & (FCFG_FDIS |FCFG_FCFGLK_MASK ); +/* Preserve read-only bits in FPRGLK and FRDLK */ + value |= cur_value & lock_mask; +/* Set all bits that aren't read-only. */ + value |= new_value & ~lock_mask; + +return value; +} + +/* Common register write handler for both OTP classes. */ +static void npcm7xx_otp_write (NPCM7xxOTPState *s,NPCM7xxOTPRegister reg, +uint32_t value) +{ +switch (reg) { +case NPCM7XX_OTP_FST : +/* RDST is cleared by writing 1 to it. */ +if (value &FST_RDST ) { + s->regs[NPCM7XX_OTP_FST ] &= ~FST_RDST ; + } +/* Preserve read-only and write-one-to-clear bits */ + value &= ~FST_RO_MASK ; + value |= s->regs[NPCM7XX_OTP_FST ] &FST_RO_MASK ; +break ; + +case NPCM7XX_OTP_FADDR : +break ; + +case NPCM7XX_OTP_FDATA : +/* +* This register is cleared by writing a magic value to it; no other +* values can be written. +*/ +if (value ==FDATA_CLEAR ) { + value =0 ; + }else { + value = s->regs[NPCM7XX_OTP_FDATA ]; + } +break ; + +case NPCM7XX_OTP_FCFG : + value =npcm7xx_otp_compute_fcfg (s->regs[NPCM7XX_OTP_FCFG ], value); +break ; + +case NPCM7XX_OTP_FCTL : +switch (value) { +case FCTL_READ_CMD : +npcm7xx_otp_read_array (s); +break ; + +case FCTL_PROG_CMD1 : +/* +* Programming requires writing two separate magic values to this +* register; this is the first one. Just store it so it can be +* verified later when the second magic value is received. +*/ +break ; + +case FCTL_PROG_CMD2 : +/* +* Only initiate programming if we received the first half of the +* command immediately before this one. +*/ +if (s->regs[NPCM7XX_OTP_FCTL ] ==FCTL_PROG_CMD1 ) { +npcm7xx_otp_program_array (s); + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unrecognized FCNTL value 0x%" PRIx32"\n" , +DEVICE (s)->canonical_path, value); +break ; + } +if (value !=FCTL_PROG_CMD1 ) { + value =0 ; + } +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: write to invalid offset 0x%zx\n" , +DEVICE (s)->canonical_path, reg *sizeof (uint32_t )); +return ; + } + + s->regs[reg] = value; +} + +/* Register read handler specific to the fuse array OTP module. */ +static uint64_t npcm7xx_fuse_array_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; +uint32_t value; + +/* +* Only the Fuse Strap register needs special handling; all other registers +* work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { + value =npcm7xx_otp_read (s, reg); + }else { +/* FUSTRAP is stored as three copies in the OTP array. */ +uint32_t fustrap[3 ]; + +memcpy (fustrap, &s->array[0 ],sizeof (fustrap)); + +/* Determine value by a majority vote on each bit. */ + value = (fustrap[0 ] & fustrap[1 ]) | (fustrap[0 ] & fustrap[2 ]) | + (fustrap[1 ] & fustrap[2 ]); + } + +return value; +} + +/* Register write handler specific to the fuse array OTP module. */ +static void npcm7xx_fuse_array_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* The Fuse Strap register is read-only. Other registers are handled by +* common code. +*/ +if (reg !=NPCM7XX_OTP_FUSTRAP ) { +npcm7xx_otp_write (s, reg, v); + } +} + +static const MemoryRegionOps npcm7xx_fuse_array_ops = { + .read = npcm7xx_fuse_array_read, + .write = npcm7xx_fuse_array_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +/* Register read handler specific to the key storage OTP module. */ +static uint64_t npcm7xx_key_storage_read (void *opaque,hwaddr addr, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +return npcm7xx_otp_read (s, reg); + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + +return s->regs[NPCM7XX_OTP_FKEYIND ]; +} + +/* Register write handler specific to the key storage OTP module. */ +static void npcm7xx_key_storage_write (void *opaque,hwaddr addr,uint64_t v, +unsigned int size) +{ +NPCM7xxOTPRegister reg = addr /sizeof (uint32_t ); +NPCM7xxOTPState *s = opaque; + +/* +* Only the Fuse Key Index register needs special handling; all other +* registers work the same way for both kinds of OTP modules. +*/ +if (reg !=NPCM7XX_OTP_FKEYIND ) { +npcm7xx_otp_write (s, reg, v); +return ; + } + +qemu_log_mask (LOG_UNIMP ,"%s: FKEYIND is not implemented\n" , __func__); + + s->regs[NPCM7XX_OTP_FKEYIND ] = v; +} + +static const MemoryRegionOps npcm7xx_key_storage_ops = { + .read = npcm7xx_key_storage_read, + .write = npcm7xx_key_storage_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false, + }, +}; + +static void npcm7xx_otp_enter_reset (Object *obj,ResetType type) +{ +NPCM7xxOTPState *s =NPCM7XX_OTP (obj); + +memset (s->regs,0 ,sizeof (s->regs)); + + s->regs[NPCM7XX_OTP_FST ] =0x00000001 ; + s->regs[NPCM7XX_OTP_FCFG ] =0x20000000 ; +} + +static void npcm7xx_otp_realize (DeviceState *dev,Error **errp) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_GET_CLASS (dev); +NPCM7xxOTPState *s =NPCM7XX_OTP (dev); +SysBusDevice *sbd = &s->parent; + +memset (s->array,0 ,sizeof (s->array)); + +memory_region_init_io (&s->mmio,OBJECT (s), oc->mmio_ops, s,"regs" , +NPCM7XX_OTP_REGS_SIZE ); +sysbus_init_mmio (sbd, &s->mmio); +} + +static const VMStateDescription vmstate_npcm7xx_otp = { + .name ="npcm7xx-otp" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, NPCM7xxOTPState,NPCM7XX_OTP_NR_REGS ), +VMSTATE_UINT8_ARRAY (array, NPCM7xxOTPState,NPCM7XX_OTP_ARRAY_BYTES ), +VMSTATE_END_OF_LIST (), + }, +}; + +static void npcm7xx_otp_class_init (ObjectClass *klass,void *data) +{ +ResettableClass *rc =RESETTABLE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + +QEMU_BUILD_BUG_ON (NPCM7XX_OTP_REGS_END >NPCM7XX_OTP_NR_REGS ); + + dc->realize = npcm7xx_otp_realize;hw/nvram/npcm7xx_otp.c line 411
Quoted 10 lines
hw/nvram/npcm7xx_otp.c new file +10
-0+ dc->vmsd = &vmstate_npcm7xx_otp; + rc->phases.enter = npcm7xx_otp_enter_reset; +} + +static void npcm7xx_key_storage_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); + + oc->mmio_ops = &npcm7xx_key_storage_ops; +}Hello,
With this series applied, when I build with --enable-sanitizers and run ./qemu-system-arm:==373753==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x61000000b400at pc0x557496abbefcbp0x7ffdd5851210sp0x7ffdd5851208WRITE of size 8 at0x61000000b400thread T0#0 0x557496abbefb in npcm7xx_key_storage_class_init /../hw/nvram/npcm7xx_otp.c:410:18 #1 0x5574998a8780 in type_initialize /../qom/object.c:362:9 #2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5 #3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f) #4 0x5574998a9a41 in object_class_foreach /../qom/object.c:1052:5 #5 0x5574998ab28a in object_class_get_list /../qom/object.c:1109:5 #6 0x557498e6f8e1 in select_machine /../softmmu/vl.c:2438:24 #7 0x557498e5a921 in qemu_init /../softmmu/vl.c:3842:21 #8 0x557495b181d7 in main /../softmmu/main.c:49:5 #9 0x7fc269e7dcc9 in __libc_start_main csu/../csu/libc-start.c:308:16 #10 0x557495a6d9b9 in _start (/qemu-system-arm+0x35959b9)
0x61000000b400is located 0 bytes to the right of 192-byte region [0x61000000b340,0x61000000b400) allocated by thread T0 here:#0 0x557495ae6272 in calloc (/qemu-system-arm+0x360e272) #1 0x7fc26b43f210 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x56210) #2 0x5574998a9bef in object_class_foreach_tramp /../qom/object.c:1030:5 #3 0x7fc26b427b2f in g_hash_table_foreach (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x3eb2f)SUMMARY: AddressSanitizer: heap-buffer-overflow /../hw/nvram/npcm7xx_otp.c:410:18 in
npcm7xx_key_storage_class_init-Alex
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
hw/nvram/npcm7xx_otp.c new file +5
-0+ +static void npcm7xx_fuse_array_class_init (ObjectClass *klass,void *data) +{ +NPCM7xxOTPClass *oc =NPCM7XX_OTP_CLASS (klass); +Quoted 8 lines
hw/nvram/npcm7xx_otp.c line 424
Quoted 8 lines
hw/nvram/npcm7xx_otp.c new file +8
-0+ oc->mmio_ops = &npcm7xx_fuse_array_ops; +} + +static const TypeInfo npcm7xx_otp_types[] = { + { + .name =TYPE_NPCM7XX_OTP , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (NPCM7xxOTPState),Adding this fixes it for me:
.class_size = sizeof(NPCM7xxOTPClass),
You're absolutely right. I'll send out another series with this fix. Thanks for catching this.
Havard
PATCH v8 11/14 hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj
In reply to Havard Skinnemoen viaThis 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"
@@ -55,6 +56,22 @@ static void npcm7xx_load_bootrom(MachineState *machine, 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);
@@ -92,6 +109,7 @@ static void npcm750_evb_init(MachineState *machine)qdev_realize (DEVICE (soc),NULL , &error_fatal);npcm7xx_load_bootrom (machine, soc); +npcm7xx_connect_flash (&soc->fiu[0 ],0 ,"w25q256" ,drive_get (IF_MTD ,0 ,0 ));npcm7xx_load_kernel (machine, soc); }
@@ -104,6 +122,8 @@ static void quanta_gsj_init(MachineState *machine)qdev_realize (DEVICE (soc),NULL , &error_fatal);npcm7xx_load_bootrom (machine, 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.297.g1956fa8f8d-goog
PATCH v8 12/14 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks
In reply to Havard Skinnemoen viaWhen booting directly into a kernel, bypassing the boot loader, the CPU and UART clocks are not set up correctly. This makes the system appear very slow, and causes the initrd boot test to fail when optimization is off.
The UART clock must run at 24 MHz. The default 25 MHz reference clock cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works perfectly with the default /20 divider.
The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs at 800 MHz by default, so we need to double the feedback divider as well to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz).
We don't bother checking for PLL lock because we know our emulated PLLs lock instantly.
--- include/hw/arm/npcm7xx.h | 1 + hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/hw/arm/npcm7xx.h +1 -0
@@ -37,6 +37,7 @@#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 */ +#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000)/* Boot ROM */ typedef struct NPCM7xxMachine { MachineState parent;
hw/arm/npcm7xx.c +32 -0
@@ -55,6 +55,13 @@#define NPCM7XX_ROM_BA (0xffff0000)#define NPCM7XX_ROM_SZ (64 * KiB) +/* Clock configuration values to be fixed up when bypassing bootloader */ + +/* Run PLL1 at 1600 MHz */ +#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101) +/* Run the CPU from PLL1 and UART from PLL2 */ +#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9) +/* * Interrupt lines going into the GIC. This does not include internal Cortex-A9 * interrupts.
@@ -132,6 +139,29 @@ static const struct { }, }; +static void npcm7xx_write_board_setup (ARMCPU *cpu, +const struct arm_boot_info *info) +{ +uint32_t board_setup[] = { +0xe59f0010 ,/* ldr r0, clk_base_addr */ +0xe59f1010 ,/* ldr r1, pllcon1_value */ +0xe5801010 ,/* str r1, [r0, #16] */ +0xe59f100c ,/* ldr r1, clksel_value */ +0xe5801004 ,/* str r1, [r0, #4] */ +0xe12fff1e ,/* bx lr */ +NPCM7XX_CLK_BA , +NPCM7XX_PLLCON1_FIXUP_VAL , +NPCM7XX_CLKSEL_FIXUP_VAL , + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (board_setup); i++) { + board_setup[i] =tswap32 (board_setup[i]); + } +rom_add_blob_fixed ("board-setup" , board_setup,sizeof (board_setup), + info->board_setup_addr); +} +static void npcm7xx_write_secondary_boot (ARMCPU *cpu,const struct arm_boot_info *info) {
@@ -170,6 +200,8 @@ static struct arm_boot_info npcm7xx_binfo = { .gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR, .write_secondary_boot = npcm7xx_write_secondary_boot, .board_id = -1, + .board_setup_addr = NPCM7XX_BOARD_SETUP_ADDR, + .write_board_setup = npcm7xx_write_board_setup, };void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc)
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Re: [PATCH v8 12/14] hw/arm/npcm7xx: add board setup stub for CPU and UART clocks
Quoted 83 lines · Havard Skinnemoen via
When booting directly into a kernel, bypassing the boot loader, the CPU and UART clocks are not set up correctly. This makes the system appear very slow, and causes the initrd boot test to fail when optimization is off.
The UART clock must run at 24 MHz. The default 25 MHz reference clock cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works perfectly with the default /20 divider.
The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs at 800 MHz by default, so we need to double the feedback divider as well to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz).
We don't bother checking for PLL lock because we know our emulated PLLs lock instantly.
Signed-off-by Havard Skinnemoen <[email protected]>--- include/hw/arm/npcm7xx.h | 1 + hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)include/hw/arm/npcm7xx.h +1
-0@@ -37,6 +37,7 @@#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 */ +#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000)/* Boot ROM */ typedef struct NPCM7xxMachine { MachineState parent;hw/arm/npcm7xx.c +30
-0@@ -55,6 +55,13 @@#define NPCM7XX_ROM_BA (0xffff0000)#define NPCM7XX_ROM_SZ (64 * KiB) +/* Clock configuration values to be fixed up when bypassing bootloader */ + +/* Run PLL1 at 1600 MHz */ +#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101) +/* Run the CPU from PLL1 and UART from PLL2 */ +#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9) +/* * Interrupt lines going into the GIC. This does not include internal Cortex-A9 * interrupts. @@ -132,6 +139,29 @@ static const struct { }, }; +static void npcm7xx_write_board_setup (ARMCPU *cpu, +const struct arm_boot_info *info) +{ +uint32_t board_setup[] = { +0xe59f0010 ,/* ldr r0, clk_base_addr */ +0xe59f1010 ,/* ldr r1, pllcon1_value */ +0xe5801010 ,/* str r1, [r0, #16] */ +0xe59f100c ,/* ldr r1, clksel_value */ +0xe5801004 ,/* str r1, [r0, #4] */ +0xe12fff1e ,/* bx lr */ +NPCM7XX_CLK_BA , +NPCM7XX_PLLCON1_FIXUP_VAL , +NPCM7XX_CLKSEL_FIXUP_VAL , + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (board_setup); i++) { + board_setup[i] =tswap32 (board_setup[i]); + } +rom_add_blob_fixed ("board-setup" , board_setup,sizeof (board_setup), + info->board_setup_addr); +} +static void npcm7xx_write_secondary_boot (ARMCPU *cpu,const struct arm_boot_info *info) {
hw/arm/npcm7xx.c static struct arm_boot_info npcm7xx_binfo = { · line 207
Quoted 8 lines
hw/arm/npcm7xx.c +2
-0@@ -170,6 +200,8 @@ static struct arm_boot_info npcm7xx_binfo = { .gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR, .write_secondary_boot = npcm7xx_write_secondary_boot, .board_id = -1, + .board_setup_addr = NPCM7XX_BOARD_SETUP_ADDR, + .write_board_setup = npcm7xx_write_board_setup, };void npcm7xx_load_kernel (MachineState *machine,NPCM7xxState *soc)
Very very clean :) :)
PATCH v8 14/14 tests/acceptance: console boot tests for quanta-gsj
In reply to Havard Skinnemoen viaThis 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 | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
tests/acceptance/boot_linux_console.py +83 -0
@@ -568,6 +568,89 @@ 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 = 'obmc.mtd' + 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() + + # Disable drivers and services that stall for a long time during boot, + # to avoid running past the 90-second timeout. These may be removed + # as the corresponding device support is added. + kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + ( + 'console=${console} ' + 'mem=${mem} ' + 'initcall_blacklist=npcm_i2c_bus_driver_init ' + 'systemd.mask=systemd-random-seed.service ' + 'systemd.mask=dropbearkey.service ' + ) + + 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 ') + interrupt_interactive_console_until_pattern( + self, 'Hit any key to stop autoboot:', 'U-Boot>') + exec_command_and_wait_for_pattern( + self, "setenv bootargs ${bootargs} " + kernel_command_line, + 'U-Boot>') + exec_command_and_wait_for_pattern( + self, 'run romboot', 'Booting Kernel from flash') + 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.297.g1956fa8f8d-goog
Quoted 28 lines · Havard Skinnemoen via
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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.
Series:
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage over all the new npcm.*\.c files. The only thing I found specific to the new code, so far:
cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio write 0xf0009040 0x4 0xc4c4c4c4
write 0xf0009040 0x4 0x4
EOF
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns > 0) Bail out! ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns > 0) Aborted
I'm doing the same for the quanta-gsj machine, but I'm not sure whether it will cover more code, so I'm happy to leave a:
for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Quoted 254 lines · Havard Skinnemoen via
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. AQEMU_BUILD_BUG_ONshould alert anyone accidentally expanding the register enum that they need to update the correspondingNR_REGSdefine, which in turn has a comment reminding them to update the vmstateversion_idas well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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/vbootromSignature · 1 line
2.28.0.297.g1956fa8f8d-goog
Quoted 9 lines · Alexander Bulekov
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage over all the new npcm.*\.c files. The only thing I found specific to the new code, so far:cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio write
0xf00090400x40xc4c4c4c4
write0xf00090400x40x4
EOF
This is an odd test because with -qtest the timer is not running, so this can not really happen on real hw.
The fix is:
- g_assert(t->remaining_ns > 0);
+ g_assert(qtest_enabled() || t->remaining_ns > 0);
Quoted 5 lines
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (
t->remaining_ns> 0) Bail out! ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns> 0) Aborted
Quoted 7 lines
I'm doing the same for the quanta-gsj machine, but I'm not sure whether it will cover more code, so I'm happy to leave a:
Tested-by Alexander Bulekov <[email protected]>for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Very nice from you for testing running the fuzzer!
Regards,
Phil.
Quoted 258 lines · Havard Skinnemoen via
Quoted 254 lines
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. AQEMU_BUILD_BUG_ONshould alert anyone accidentally expanding the register enum that they need to update the correspondingNR_REGSdefine, which in turn has a comment reminding them to update the vmstateversion_idas well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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/vbootromSignature · 1 line
2.28.0.297.g1956fa8f8d-goog
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Alexander Bulekov
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage over all the new npcm.*\.c files. The only thing I found specific to the new code, so far:cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio write
0xf00090400x40xc4c4c4c4
write0xf00090400x40x4
EOFThis is an odd test because with -qtest the timer is not running, so this can not really happen on real hw.
The fix is:
Review
Quoted 2 lines
(quoted diff) +1
-1- g_assert(t->remaining_ns > 0); + g_assert(qtest_enabled() || t->remaining_ns > 0);
Alex corrected me on IRC, qtest is irrelevant here. The problem is he disables the timer twice.
So maybe something like:
static void npcm7xx_timer_pause(NPCM7xxTimer *t)
{
int64_t now;+ if (!timer_pending(&t->qtimer)) {
+ return;
+ }
timer_del(&t->qtimer);
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
t->remaining_ns = t->expires_ns - now;
g_assert(t->remaining_ns > 0);}
Quoted 279 lines
Quoted 6 lines
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (
t->remaining_ns> 0) Bail out! ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns> 0) AbortedQuoted 7 lines
I'm doing the same for the quanta-gsj machine, but I'm not sure whether it will cover more code, so I'm happy to leave a:
Tested-by Alexander Bulekov <[email protected]>for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Very nice from you for testing running the fuzzer!
Regards,
Phil.
Quoted 258 lines · Havard Skinnemoen via
Quoted 254 lines
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. AQEMU_BUILD_BUG_ONshould alert anyone accidentally expanding the register enum that they need to update the correspondingNR_REGSdefine, which in turn has a comment reminding them to update the vmstateversion_idas well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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/vbootromSignature · 1 line
2.28.0.297.g1956fa8f8d-goog
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Alexander Bulekov
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage over all the new npcm.*\.c files. The only thing I found specific to the new code, so far:cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio write
0xf00090400x40xc4c4c4c4
write0xf00090400x40x4
EOFThis is an odd test because with -qtest the timer is not running, so this can not really happen on real hw.
The fix is:
Review
Quoted 2 lines
(quoted diff) +1
-1- g_assert(t->remaining_ns > 0); + g_assert(qtest_enabled() || t->remaining_ns > 0);Alex corrected me on IRC, qtest is irrelevant here. The problem is he disables the timer twice.
So maybe something like:
static void
npcm7xx_timer_pause(NPCM7xxTimer *t){ int64_t now;
Review
Quoted 8 lines
(quoted diff) +3
-0+ if (!timer_pending(&t->qtimer)) { + return; + } timer_del(&t->qtimer); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); t->remaining_ns = t->expires_ns - now; g_assert(t->remaining_ns > 0); }
Thanks, that makes sense. I was worried that making the assert conditional on qtest_enabled() might hide real issues.
This fuzz testing is great, it would have been hard to find this bug without it. Thanks a lot Alex for running it.
Havard
Quoted 279 lines
Quoted 279 lines
Quoted 6 lines
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (
t->remaining_ns> 0) Bail out! ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns> 0) AbortedQuoted 7 lines
I'm doing the same for the quanta-gsj machine, but I'm not sure whether it will cover more code, so I'm happy to leave a:
Tested-by Alexander Bulekov <[email protected]>for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Very nice from you for testing running the fuzzer!
Regards,
Phil.
Quoted 258 lines · Havard Skinnemoen via
Quoted 254 lines
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. AQEMU_BUILD_BUG_ONshould alert anyone accidentally expanding the register enum that they need to update the correspondingNR_REGSdefine, which in turn has a comment reminding them to update the vmstateversion_idas well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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--
2.28.0.297.g1956fa8f8d-goog
Quoted 41 lines · Havard Skinnemoen
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Alexander Bulekov
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage over all the new npcm.*\.c files. The only thing I found specific to the new code, so far:cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio write
0xf00090400x40xc4c4c4c4
write0xf00090400x40x4
EOFThis is an odd test because with -qtest the timer is not running, so this can not really happen on real hw.
The fix is:
Review
Quoted 2 lines
(quoted diff) +1
-1- g_assert(t->remaining_ns > 0); + g_assert(qtest_enabled() || t->remaining_ns > 0);Alex corrected me on IRC, qtest is irrelevant here. The problem is he disables the timer twice.
So maybe something like:
static void
npcm7xx_timer_pause(NPCM7xxTimer *t){ int64_t now;Review
Quoted 8 lines
(quoted diff) +3
-0+ if (!timer_pending(&t->qtimer)) { + return; + } timer_del(&t->qtimer); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); t->remaining_ns = t->expires_ns - now; g_assert(t->remaining_ns > 0); }
Quoted 2 lines
Thanks, that makes sense. I was worried that making the assert conditional on
qtest_enabled()might hide real issues.
Hmm, that didn't help, though it might make sense to keep it there anyway.
What the test case does is:
1. Enable the timer (with zero expiration time) and reset it at the same time.
2. Disable the timer zero cycles after it was enabled.
It also touches a bunch of other bits (including reserved bits), but they should be irrelevant.
I think there are two issues here.
When the Reset bit is set, the Enable bit should be forced to zero. This is easy to fix.
If the timer is enabled with zero expiration time, and immediately disabled without advancing the virtual time, npcm7xx_timer_pause() is called while the timer is active, but t->expires_ns == qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL). So t->remaining_ns becomes zero and triggers the assertion.
If I revert a change that Philippe asked me to do earlier:
timer_del(&t->qtimer);
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
t->remaining_ns = t->expires_ns - now;- g_assert(t->remaining_ns > 0);
+ if (t->remaining_ns <= 0) {
+ npcm7xx_timer_reached_zero(t);
+ }
}
it doesn't crash:
$ cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio --trace npcm7xx_timer* write 0xf0009040 0x4 0xc4c4c4c4 write 0xf0009040 0x4 0x4 EOF [I 1599613445.620379] OPENED [R +0.180771] write 0xf0009040 0x4 0xc4c4c4c4 [email protected]:npcm7xx_timer_write /machine/soc/tim[1] offset: 0x0040 value 0xc4c4c4c4 OK [S +0.180816] OK [R +0.180833] write 0xf0009040 0x4 0x4 [email protected]:npcm7xx_timer_write /machine/soc/tim[1] offset: 0x0040 value 0x00000000 [email protected]:npcm7xx_timer_irq /machine/soc/tim[1] timer 4 state 0 OK [S +0.180927] OK [I +0.181319] CLOSED [I +4.003267] CLOSED
Note that the npcm7xx_timer_irq trace event is a sign of the first bug, but fixing that might mask the second bug. If we write the same pattern, only without the Reset bit, this would be the correct behavior (and it still causes the v8 code to crash).
I think this device deserves a qtest. I wonder if we'd trigger the assertion if we set a nonzero expiration time, but happen to clear the Enable bit on the exact cycle it's supposed to expire. That would be a more realistic scenario, as it wouldn't require multiple register writes in the same virtual clock cycle.
I probably won't add the qtest to the same series, as I'd like someone from Nuvoton to get a chance to review it first.
Havard
Quoted 285 lines
This fuzz testing is great, it would have been hard to find this bug without it. Thanks a lot Alex for running it.
Havard
Quoted 279 lines
Quoted 279 lines
Quoted 6 lines
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (
t->remaining_ns> 0) Bail out! ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion failed: (t->remaining_ns> 0) AbortedQuoted 7 lines
I'm doing the same for the quanta-gsj machine, but I'm not sure whether it will cover more code, so I'm happy to leave a:
Tested-by Alexander Bulekov <[email protected]>for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Very nice from you for testing running the fuzzer!
Regards,
Phil.
Quoted 258 lines · Havard Skinnemoen via
Quoted 254 lines
I also pushed this and the previous patchsets to my qemu fork on github. The branches are named npcm7xx-v[1-8].
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 v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. AQEMU_BUILD_BUG_ONshould alert anyone accidentally expanding the register enum that they need to update the correspondingNR_REGSdefine, which in turn has a comment reminding them to update the vmstateversion_idas well.
- Skip loading the bootrom if a kernel filename is provided by the user.
- New patch adding a board setup stub to tweak clocks before booting directly into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed up the flash boot acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptance test.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 (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks 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 | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532 +++++++++++++++++++++++ hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++ hw/timer/npcm7xx_timer.c | 509 ++++++++++++++++++++++ .gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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--
2.28.0.297.g1956fa8f8d-goog
Quoted 110 lines · Havard Skinnemoen
Quoted 2 lines · Havard Skinnemoen
On Tue, Sep 8, 2020 at 9:58 AM Philippe Mathieu-Daudé <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Alexander Bulekov
Quoted 2 lines
Hi Havard,
I fuzzed the npcm750-evb machine until I hit over 85% coverage overall
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
the new npcm.*\.c files. The only thing I found specific to the new code, so far:
cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest
stdio
Quoted 30 lines
Quoted 21 lines
Review
Quoted 11 lines
Quoted 3 lines
write
0xf00090400x40xc4c4c4c4
write0xf00090400x40x4
EOFThis is an odd test because with -qtest the timer is not running, so this can not really happen on real hw.
The fix is:
(quoted diff) +1
-1- g_assert(t->remaining_ns > 0); + g_assert(qtest_enabled() || t->remaining_ns > 0);Alex corrected me on IRC, qtest is irrelevant here. The problem is he disables the timer twice.
So maybe something like:
static void
npcm7xx_timer_pause(NPCM7xxTimer *t){ int64_t now;Review
Quoted 8 lines
(quoted diff) +3
-0+ if (!timer_pending(&t->qtimer)) { + return; + } timer_del(&t->qtimer); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); t->remaining_ns = t->expires_ns - now; g_assert(t->remaining_ns > 0); }Quoted 2 lines
Thanks, that makes sense. I was worried that making the assert conditional on
qtest_enabled()might hide real issues.Hmm, that didn't help, though it might make sense to keep it there anyway.
What the test case does is:
1. Enable the timer (with zero expiration time) and reset it at the same
time.
2. Disable the timer zero cycles after it was enabled.It also touches a bunch of other bits (including reserved bits), but they should be irrelevant.
I think there are two issues here.
When the Reset bit is set, the Enable bit should be forced to zero. This is easy to fix.
If the timer is enabled with zero expiration time, and immediately disabled without advancing the virtual time,
npcm7xx_timer_pause()is called while the timer is active, butt->expires_ns==qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL). Sot->remaining_nsbecomes zero and triggers the assertion.If I revert a change that Philippe asked me to do earlier:
timer_del(&t->qtimer); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); t->remaining_ns = t->expires_ns - now;(quoted diff) +3
-1- g_assert(t->remaining_ns > 0); + if (t->remaining_ns <= 0) { + npcm7xx_timer_reached_zero(t); + } }it doesn't crash:
$ cat << EOF | ./qemu-system-arm -machine npcm750-evb -m 128M -qtest stdio --trace npcm7xx_timer* write 0xf0009040 0x4 0xc4c4c4c4 write 0xf0009040 0x4 0x4 EOF [I 1599613445.620379] OPENED [R +0.180771] write 0xf0009040 0x4 0xc4c4c4c4 [email protected]:npcm7xx_timer_write /machine/soc/tim[1] offset: 0x0040 value 0xc4c4c4c4 OK [S +0.180816] OK [R +0.180833] write 0xf0009040 0x4 0x4 [email protected]:npcm7xx_timer_write /machine/soc/tim[1] offset: 0x0040 value 0x00000000 [email protected]:npcm7xx_timer_irq /machine/soc/tim[1] timer 4 state 0 OK [S +0.180927] OK [I +0.181319] CLOSED [I +4.003267] CLOSEDNote that the
npcm7xx_timer_irqtrace event is a sign of the first bug, but fixing that might mask the second bug. If we write the same pattern, only without the Reset bit, this would be the correct behavior (and it still causes the v8 code to crash).
Quoted 6 lines
I think this device deserves a qtest. I wonder if we'd trigger the assertion if we set a nonzero expiration time, but happen to clear the Enable bit on the exact cycle it's supposed to expire. That would be a more realistic scenario, as it wouldn't require multiple register writes in the same virtual clock cycle.
I wrote some qtests, and found several more bugs, but I wasn't able to trigger this particular failure mode. I was able to reproduce both of the bugs found by the fuzzer though.
I'll refresh the patch series tonight or tomorrow, and also send the qtest to Nuvoton (and probably send it to the list within the next few weeks or so).
Quoted 362 lines
I probably won't add the qtest to the same series, as I'd like someone from Nuvoton to get a chance to review it first.
Havard
Quoted 9 lines
This fuzz testing is great, it would have been hard to find this bug without it. Thanks a lot Alex for running it.
Havard
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause:
assertion failed: (
t->remaining_ns> 0)Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Bail out!
ERROR:../hw/timer/npcm7xx_timer.c:160:npcm7xx_timer_pause: assertion
failed: (t->remaining_ns> 0)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Aborted
I'm doing the same for the quanta-gsj machine, but I'm not sure
whether
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
it will cover more code, so I'm happy to leave a:
Tested-by Alexander Bulekov <[email protected]>for the patches that add new virtual-device code (1-5, 7-12 ?) -Alex
Very nice from you for testing running the fuzzer!
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Phil.
Quoted 4 lines · Havard Skinnemoen via
Quoted 1 line
I also pushed this and the previous patchsets to my qemu fork on
github.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
The branches are named npcm7xx-v[1-8].
https://github.com/hskinnemoen/qemu
This patch series models enough of the Nuvoton NPCM730 and NPCM750
SoCs to boot
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
an OpenBMC image built for quanta-gsj. This includes device models
for:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
- Global Configuration Registers
- Clock Control
- Timers
- Fuses
- Memory Controller
- Flash ControllerThese modules, along with the existing Cortex A9 CPU cores and
built-in
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
peripherals, are integrated into a NPCM730 or NPCM750 SoC, which
in turn form
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the foundation for the quanta-gsj and npcm750-evb machines,
respectively. The
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
two SoCs are very similar; the only difference is that NPCM730 is
missing some
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
peripherals that NPCM750 has, and which are not considered
essential for
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
datacenter use (e.g. graphics controllers). For more information,
see
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
https://www.nuvoton.com/products/cloud-computing/ibmc/
Both quanta-gsj and npcm750-evb correspond to real boards
supported by OpenBMC.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
At the end of the series, qemu can boot an OpenBMC image built for
one of these
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
boards with some minor modifications.
The patches in this series were developed by Google and reviewed
by Nuvoton. We
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
will be maintaining the machine and peripheral support together.
The data sheet for these SoCs is not generally available. Please
let me know if
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
more comments are needed to understand the device behavior.
Changes since v7:
- Move register enums to .c files throughout, leaving a single
NPCM7XX_FOO_NR_REGSdefinition behind in the .h file. A
QEMU_BUILD_BUG_ONQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
should alert anyone accidentally expanding the register enum
that they need
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to update the corresponding
NR_REGSdefine, which in turn hasa comment
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
reminding them to update the vmstate
version_idas well.
- Skip loading the bootrom if a kernel filename is provided bythe user.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- New patch adding a board setup stub to tweak clocks before
booting directly
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
into the kernel.
- Add stuff to meson files instead of Makefiles.
- Try to disable the slowest drivers and services to speed upthe flash boot
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
acceptance test a bit. This is somewhat based on the following systemd-analyze blame report:
https://gist.github.com/hskinnemoen/475cb0676530cd2cebaa1754cf16ca97
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Changes since v6:
- Use
size_to_strto report DRAM sizes innpcm7xx_gcr.
- Simplify the interrupt logic innpcm7xx_timer.
- Update globalbios_nameinstead of temporary.
- Addnpcm7xx_bootromtoMAINTAINERSand pc-bios/README.
- Use a predefined name for the gsj boot image in the acceptancetest.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Changes since v5:
- Boot ROM included, as a git submodule and a binary blob, and
loaded by
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
default, so the -bios option is usually not necessary anymore.
- Two acceptance tests added (openbmc image boot, and directkernel boot).
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
-
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 throughthe SoC
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
since they may be triggered by user-configurable
parameters.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Machine init uses
error_fatalinstead oferror_abortforSoC
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
realization flash init. This makes error messages more
helpful.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Comments added to indicate whether peripherals may fail to
realize.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
- Use
ERRP_GUARD()instead of Error *err when possible.
- Default CPU type is now set, and attempting to set it toanything else
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
will fail.
- Format string fixes (useHWADDR_PRIx, etc.)
- Simplified memory size encoding and error checking in
npcm7xx_gcr.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Encapsulate non-obvious pointer subtraction into helper
functions in the
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
selects.
- Incorporate review feedback into the TIMER module:
- Assert that we never pause a timer that has alreadyexpired, instead of
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
trying to handle it. This should be safe since
QEMU_CLOCK_VIRTUALisQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
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
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
it because it caused make check to fail (qom-test). When
specifying a NULL
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
block device, the m25p flash device initializes its in-memory
storage with
0xffQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and doesn't attempt to write anything back. This seems correct to
me.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Changes since v4:
- OTP cleanups suggested by Philippe Mathieu-Daudé.
- Added fuse array definitions based on public Nuvotonbootblock code.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Moved class structure to .c file since it's only used
internally.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
- Readability improvements.
- Split the first patch and folded parts of it into three otherpatches so
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
that
CONFIG_NPCM7XXis only enabled after the initial NPCM7xxmachine
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
support is added.
- DRAM init moved to machine init code.
- Consistently use lower-case hex literals.
- Switched to fine-grained unimplemented devices, based onpublic bootblock
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
source code. Added a tiny SRAM that got left out previously.
- Simplified error handling innpcm7xx_realize()since the boardcode will
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
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, whichdoesn't
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
really have any state worth saving). Successfully booted a gsj
image
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
with two stop/savevm/quit/loadvm cycles along the way.
- JFFS2 really doesn't like it if I let qemu keep runningafter savevm,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and then jump back in time with loadvm. I assume this is
expected.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Fixed an error API violation in
npcm7xx_realize, removedpointless error
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
check after
object_property_set_link().
- Switched the OTP device to use an embedded array instead of ag_malloc0'd
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
one because I couldn't figure out how to set up vmstate for
the latter.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
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 initcode so it
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
can be properly initialized. Turns out npcm750 memory init
doesn't work
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
without this. npcm730 is fine either way, though I'm not sure
why.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Reworked the flash init code so it looks more like aspeed
(i.e. the flash
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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 toARMCPUs.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- Clarify why EL3 is disabled.
- IntroduceNPCM7XX_NUM_IRQconstant.
- Set the number of CPUs according to SoC variant, and disallowcommand line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
overrides (i.e. you can no longer override the number of CPUs
with the -smp
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
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
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from flash (patches 2 and 5):
- INTCR2 now indicates that the DDR controller isinitialized.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- INTCR3 is initialized according to DDR memory size. A
realize()Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
method was implemented to achieve this.
- Refactor the machine initialization a bit to make it easier todrop in
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
machine-specific flash initialization (patch 6).
- Extend the series with additional patches to enable bootingfrom flash:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- Boot ROM (through the -bios option).
- OTP (fuse) controller.
- Memory Controller stub (just enough to skip memorytraining).
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
- Flash controller.
- Board-specific flash initialization.Thanks for reviewing,
Havard
Havard Skinnemoen (14):
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 hw/arm/npcm7xx: add board setup stub for CPU and UART clocks docs/system: Add Nuvoton machine documentation tests/acceptance: console boot tests for quanta-gsjQuoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
docs/system/arm/nuvoton.rst | 90 ++++ docs/system/target-arm.rst | 1 + Makefile | 1 + default-configs/arm-softmmu.mak | 1 +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/hw/arm/npcm7xx.h | 112 +++++ include/hw/mem/npcm7xx_mc.h | 36 ++ include/hw/misc/npcm7xx_clk.h | 48 +++ include/hw/misc/npcm7xx_gcr.h | 43 ++ include/hw/nvram/npcm7xx_otp.h | 79 ++++ include/hw/ssi/npcm7xx_fiu.h | 73 ++++ include/hw/timer/npcm7xx_timer.h | 78 ++++ hw/arm/npcm7xx.c | 532+++++++++++++++++++++++
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/arm/npcm7xx_boards.c | 197 +++++++++ hw/mem/npcm7xx_mc.c | 84 ++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++ hw/ssi/npcm7xx_fiu.c | 572+++++++++++++++++++++++++
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/timer/npcm7xx_timer.c | 509++++++++++++++++++++++
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 41 lines
.gitmodules | 3 + MAINTAINERS | 10 + hw/arm/Kconfig | 9 + hw/arm/meson.build | 1 + hw/mem/meson.build | 1 + hw/misc/meson.build | 4 + hw/misc/trace-events | 8 + hw/nvram/meson.build | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + pc-bios/README | 6 + pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 + roms/vbootrom | 1 + tests/acceptance/boot_linux_console.py | 83 ++++ 36 files changed, 3582 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--
2.28.0.297.g1956fa8f8d-goog