Skip to content

arm: Get rid of system_clock_scale global

Peter Maydell qemu-arm qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest25 patches 65 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/25arm: Move M-profile RAS register block into its own deviceMAINTAINERS hw/arm/armv7m.c hw/intc/armv7m_nvic.c +5 more+148 -578 replies
2/25arm: Move systick device creation from NVIC to ARMv7M objecthw/arm/armv7m.c hw/intc/armv7m_nvic.c include/hw/arm/armv7m.h +1 more+137 -772 replies
3/25arm: Move system PPB container handling to armv7mhw/arm/armv7m.c hw/intc/armv7m_nvic.c include/hw/arm/armv7m.h +1 more+107 -1452 replies
4/25hw/timer/armv7m_systick: Add usual QEMU interface commentinclude/hw/timer/armv7m_systick.h+7 -02 replies
5/25hw/timer/armv7m_systick: Add input clockshw/timer/armv7m_systick.c include/hw/timer/armv7m_systick.h+15 -22 replies
6/25hw/arm/armv7m: Create input clockshw/arm/armv7m.c include/hw/arm/armv7m.h+29 -02 replies
7/25armsse: Wire up systick cpuclk clockhw/arm/armsse.c+3 -02 replies
8/25hw/arm/mps2.c: Connect up armv7m clockshw/arm/mps2.c+15 -01 reply
9/25clock: Provide builtin multiplier/dividerdocs/devel/clocks.rst hw/core/clock-vmstate.c hw/core/clock.c +1 more+100 -512 replies
10/25hw/arm: Don't allocate separate MemoryRegions in stm32 SoC realizehw/arm/stm32f100_soc.c hw/arm/stm32f205_soc.c include/hw/arm/stm32f100_soc.h +1 more+22 -205 replies
11/25hw/arm/stm32f100: Wire up sysclk and refclkhw/arm/stm32f100_soc.c hw/arm/stm32vldiscovery.c include/hw/arm/stm32f100_soc.h+41 -53 replies
12/25hw/arm/stm32f205: Wire up sysclk and refclkhw/arm/netduino2.c hw/arm/stm32f205_soc.c include/hw/arm/stm32f205_soc.h+41 -53 replies
13/25hw/arm/stm32f405: Wire up sysclk and refclkhw/arm/netduinoplus2.c hw/arm/stm32f405_soc.c include/hw/arm/stm32f405_soc.h+40 -53 replies
14/25hw/arm/stm32vldiscovery: Delete trailing blank linehw/arm/stm32vldiscovery.c+0 -13 replies
15/25hw/arm/nrf51: Wire up sysclkhw/arm/nrf51_soc.c include/hw/arm/nrf51_soc.h+22 -01 reply
16/25hw/arm/stellaris: split stellaris_sys_init()hw/arm/stellaris.c+25 -311 reply
17/25hw/arm/stellaris: Wire sysclk up to armv7mhw/arm/stellaris.c+4 -11 reply
18/25hw/arm/msf2_soc: Don't allocate separate MemoryRegionshw/arm/msf2-soc.c include/hw/arm/msf2-soc.h+11 -101 reply
19/25hw/arm/msf2: Use Clock input to MSF2_SOC instead of m3clk propertyhw/arm/msf2-soc.c hw/arm/msf2-som.c include/hw/arm/msf2-soc.h+25 -133 replies
20/25hw/arm/msf2-soc: Wire up refclkhw/arm/msf2-soc.c include/hw/arm/msf2-soc.h+24 -01 reply
21/25hw/timer/armv7m_systick: Use clock inputs instead of system_clock_scalehw/timer/armv7m_systick.c+82 -283 replies
22/25hw/arm/stellaris: Fix code style issues in GPTM codehw/arm/stellaris.c+8 -51 reply
23/25hw/arm/stellaris: Split stellaris-gptm into its own filehw/arm/Kconfig hw/arm/stellaris.c hw/timer/Kconfig +3 more+368 -3201 reply
24/25hw/timer/stellaris-gptm: Use Clock input instead of system_clock_scalehw/arm/stellaris.c hw/timer/stellaris-gptm.c include/hw/timer/stellaris-gptm.h+34 -71 reply
25/25arm: Remove system_clock_scale globalhw/arm/armsse.c hw/arm/mps2.c hw/arm/msf2-soc.c +7 more+5 -551 reply

Reviews trailers per patch

All 25 patches have a Reviewed-by or Acked-by.

PatchAlexandre IoossAlistair FrancisLuc MichelPhilippe Mathieu-DaudéDamien Hedde
1/25R-b R-b R-b R-b
2/25A-b R-b
3/25R-b R-b
4/25R-b R-b
5/25R-b R-b
6/25R-b R-b
7/25A-b R-b
8/25R-b
9/25R-b R-b R-b R-b R-b
10/25R-b R-b R-b
11/25R-b R-b R-b
12/25R-b R-b R-b
13/25R-b R-b R-b
14/25R-b R-b R-b
15/25R-b
16/25R-b
17/25R-b
18/25R-b
19/25R-b
20/25R-b
21/25R-b
22/25R-b
23/25R-b
24/25R-b
25/25R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [PATCH for-6.2 00/25] arm: Get rid of system_clock_scale global

This is mostly a (big) refactoring to use Clocks instead of a global. Review of the new multiplier/divider functionality I've added to the Clock API would also be interesting. If you're a maintainer for an M-profile board that isn't covered by 'make check-acceptance' then I'd appreciate it if you have time to test that this series didn't accidentally break your board...

The Arm v7M systick timer can run off one of two clocks (guest-selectable by writing the SYST_CSR.CLKSOURCE control register bit):
* the main CPU clock
* a separate 'reference clock' which the SoC and board may or may not wire up

Currently we model this as:
* the global variable system_clock_scale is set to the period in ns of the CPU clock by the board or SoC level code
* the reference clock is a fixed 1MHz, hardcoded in armv7m_systick.c

This is very old code, dating back to the first v7M support in 2007. We now have a Clock API, so we can model clocks using something a bit more complicat^Wsophisticated than a global variable.

The series starts with some refactoring to move the creation of various sub-devices including the systick timers out of the nvic object and into the 'armv7m' container object. The NVIC was doing some of this for historical reasons, but it makes more sense to have all of the "create subdevices and map them into the right place in the peripheral region of the address space" be in one place. This also means that when we start wiring Clocks up we don't have to go via the NVIC to get from the armv7m object to the systick timers.

We then add clock inputs to the systick device, which are initially ignored. Subsequent patches wire up those clock inputs in SoC and board level code. Once all the boards have wired up their clocks, we can change the systick device to use those instead of the system_clock_scale global. Finally we can delete all the places setting the global.

For some of the boards the systick reference clock is a fixed multiple/division of the CPU clock. To support this, the "clock:
Provide builtin multiplier/divider" patch enhances the Clock API to let you configure a Clock such that all its children are run at a given ratio of the parent clock.

For the different boards I have taken a variety of approaches:
* sometimes the refclk frequency was easy to determine from the SoC docs, and the patches implement that, changing the behaviour from the old 1MHz fixed refclk. This is in effect a very minor bugfix.
* in a few cases I couldn't determine the refclk frequency, so I have implemented those boards to retain the old 1MHz value, as at least no-behavioural-change
* some SoCs don't wire up the refclk at all; with this series we will correctly implement that (the SYST_CSR.CLKSOURCE control register bit in the systick device is then read-only), so again a minor bugfix
In some SoCs the refclk should theoretically be guest-programmable; we didn't implement that before and we still don't. I've put in a few comments noting this missing feature where relevant.

The other user of the system_clock_scale global is the GPTM timer in the stellaris board, so there's a patch converting that to also use Clock input.

There are also a few patches implementing minor cleanups I noticed along the way that I felt would be in the way if I didn't fix them up first.

NB: this series is a migration compat break for all the M-profile boards, because it adds Clock objects to vmstate structs.

I've tested this with 'make check-acceptance', which tests the emcraft-sf2 board, and I've run some stellaris and various MPS images I have locally. Other affected boards (microbit, netduino2, netduinoplus2, stm32vldiscovery) are untested (though 'make check' confirms that they at least don't crash on startup...). Testing from maintainers of those boards would be appreciated.

thanks
-- PMM

Peter Maydell (25):
arm: Move M-profile RAS register block into its own device
arm: Move systick device creation from NVIC to ARMv7M object
arm: Move system PPB container handling to armv7m hw/timer/armv7m_systick: Add usual QEMU interface comment hw/timer/armv7m_systick: Add input clocks
hw/arm/armv7m: Create input clocks
armsse: Wire up systick cpuclk clock
hw/arm/mps2.c: Connect up armv7m clocks
clock: Provide builtin multiplier/divider
hw/arm: Don't allocate separate MemoryRegions in stm32 SoC realize hw/arm/stm32f100: Wire up sysclk and refclk hw/arm/stm32f205: Wire up sysclk and refclk hw/arm/stm32f405: Wire up sysclk and refclk hw/arm/stm32vldiscovery: Delete trailing blank line hw/arm/nrf51: Wire up sysclk
hw/arm/stellaris: split stellaris_sys_init() hw/arm/stellaris: Wire sysclk up to armv7m hw/arm/msf2_soc: Don't allocate separate MemoryRegions hw/arm/msf2: Use Clock input to MSF2_SOC instead of m3clk property hw/arm/msf2-soc: Wire up refclk
hw/timer/armv7m_systick: Use clock inputs instead of
system_clock_scale
hw/arm/stellaris: Fix code style issues in GPTM code hw/arm/stellaris: Split stellaris-gptm into its own file hw/timer/stellaris-gptm: Use Clock input instead of system_clock_scale
arm: Remove system_clock_scale global

 docs/devel/clocks.rst             |  23 ++
 include/hw/arm/armv7m.h           |  24 ++
 include/hw/arm/msf2-soc.h         |   8 +-
 include/hw/arm/nrf51_soc.h        |   2 +
 include/hw/arm/stm32f100_soc.h    |   8 +
 include/hw/arm/stm32f205_soc.h    |   8 +
 include/hw/arm/stm32f405_soc.h    |   3 +
 include/hw/clock.h                |  29 +++
 include/hw/intc/armv7m_nvic.h     |   8 -
 include/hw/misc/armv7m_ras.h      |  37 +++
 include/hw/timer/armv7m_systick.h |  36 ++-
 include/hw/timer/stellaris-gptm.h |  51 ++++
 hw/arm/armsse.c                   |  20 +-
 hw/arm/armv7m.c                   | 260 +++++++++++++++++++-
 hw/arm/mps2.c                     |  17 +-
 hw/arm/msf2-soc.c                 |  68 +++--
 hw/arm/msf2-som.c                 |   7 +-
 hw/arm/netduino2.c                |  12 +-
 hw/arm/netduinoplus2.c            |  12 +-
 hw/arm/nrf51_soc.c                |  20 +-
 hw/arm/stellaris.c                | 396 ++++--------------------------
 hw/arm/stm32f100_soc.c            |  47 +++-
 hw/arm/stm32f205_soc.c            |  47 +++-
 hw/arm/stm32f405_soc.c            |  30 +++
 hw/arm/stm32vldiscovery.c         |  13 +-
 hw/core/clock-vmstate.c           |  24 +-
 hw/core/clock.c                   |  29 ++-
 hw/intc/armv7m_nvic.c             | 274 +--------------------
 hw/misc/armv7m_ras.c              |  93 +++++++
 hw/timer/armv7m_systick.c         | 116 ++++++---
 hw/timer/stellaris-gptm.c         | 332 +++++++++++++++++++++++++
 MAINTAINERS                       |   2 +
 hw/arm/Kconfig                    |   1 +
 hw/misc/meson.build               |   2 +
 hw/timer/Kconfig                  |   3 +
 hw/timer/meson.build              |   1 +
 36 files changed, 1292 insertions(+), 771 deletions(-)
 create mode 100644 include/hw/misc/armv7m_ras.h
 create mode 100644 include/hw/timer/stellaris-gptm.h
 create mode 100644 hw/misc/armv7m_ras.c
 create mode 100644 hw/timer/stellaris-gptm.c
Signature · 1 line
2.20.1