qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Peter Maydell
Subject: [PATCH for-6.2 00/25] arm: Get rid of system_clock_scale global
Date: Thu, 12 Aug 2021 10:33:31 +0100

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

-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]