Convert CMSDK timer, watchdog, dualtimer to Clock framework
Subsystems (2)
cover Convert CMSDK timer, watchdog, dualtimer to Clock framework
This patchset converts the CMSDK timer, watchdog and dualtimer devices to use the Clock framework instead of an integer property specifying a frequency in Hz. The series is quito a lot of patches but they should be mostly small and I hope easy to review.
The motivation here is the upcoming Arm SSE-300 model: this has a new kind of timer device, which I wanted to write in the modern style with a Clock input. That meant the ARMSSE container object needed to know about Clocks, so converting the existing devices it used to Clocks seemed like a good first step.
The series as a whole is a migration compat break for the machines
involved: mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1, lm3s811evb, lm3s6965evb.
Series structure:
* patches adding new clock and ptimer API functions
* add tests for the devices
* add Clock inputs to devices, which do nothing for now
* wire up the clocks in the code that uses the devices
* make the devices use the clocks and ignore the frq properties
* remove the setting of the frq properties in code using the devices
* remove the frq properties from the devices
The new ptimer and clock functions are probably the most interesting part:
* ptimer_set_period_from_clock(ptimer, clk, divisor)
is for setting the period of a ptimer directly from a Clock (possibly accounting for the frequency being divided by some integer first) -- this avoids possible rounding errors if we went via ptimer_set_period() or ptimer_set_freq()
* clock_has_source()
returns true if an input Clock has been connected to an output clock; this is for devices to be able to check in their realize method that a mandatory clock was wired up by the board
(More detailed info and rationale in patches 1 and 2.)
A couple of bits of food-for-thought as a result of working with the relatively-new Clock APIs:
* it might be worth thinking about whether we can have a fairly lightweight implementation of a clock-divider or clock-multiplier, because I feel they are pretty common. (For this series I opted just to handle this via the ptimer_set_period_from_clock() divisor argumuent.)
* it feels a little awkward that devices with an input Clock need to do ptimer_set_period_from_clock() or similar both in their realize method (to cope with fixed-frequency input clocks, because the clock callback functions are not called when board setup code creates and configures those) and in the clock callback function (to cope with variable-frequency clocks)
* I found it odd that ptimer's period representation is 64.32 fixedpoint 2^-32 ns units, whereas Clock's is only 32.32 (so ptimer can handle much larger periods than Clock can.) I forget why we didn't go for the same representation in Clock as we have for ptimer...
* there's no MAINTAINERS entry for the Clock framework
I don't think these need to be blockers on this series, though.
thanks
-- PMM
Peter Maydell (25):
ptimer: Add new ptimer_set_period_from_clock() function
clock: Add new clock_has_source() function
tests: Add a simple test of the CMSDK APB timer
tests: Add a simple test of the CMSDK APB watchdog
tests: Add a simple test of the CMSDK APB dual timer hw/timer/cmsdk-apb-timer: Rename CMSDKAPBTIMER struct to CMSDKAPBTimer hw/timer/cmsdk-apb-timer: Add Clock input hw/timer/cmsdk-apb-dualtimer: Add Clock input hw/watchdog/cmsdk-apb-watchdog: Add Clock input hw/arm/armsse: Rename "MAINCLK" property to "MAINCLK_FRQ" hw/arm/armsse: Wire up clocks
hw/arm/mps2: Inline CMSDK_APB_TIMER creation
hw/arm/mps2: Create and connect SYSCLK Clock hw/arm/mps2-tz: Create and connect ARMSSE Clocks hw/arm/musca: Create and connect ARMSSE Clocks hw/arm/stellaris: Convert SSYS to QOM device hw/arm/stellaris: Create Clock input for watchdog hw/timer/cmsdk-apb-timer: Convert to use Clock input hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input tests/qtest/cmsdk-apb-watchdog-test: Test clock changes hw/arm/armsse: Use Clock to set system_clock_scale
arm: Don't set freq properties on CMSDK timer, dualtimer, watchdog,
ARMSSE
arm: Remove frq properties on CMSDK timer, dualtimer, watchdog, ARMSSE hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS
docs/devel/clocks.rst | 16 +++ include/hw/arm/armsse.h | 14 +- include/hw/clock.h | 15 ++ include/hw/ptimer.h | 22 +++ include/hw/timer/cmsdk-apb-dualtimer.h | 5 +- include/hw/timer/cmsdk-apb-timer.h | 34 ++--- include/hw/watchdog/cmsdk-apb-watchdog.h | 5 +- include/qemu/typedefs.h | 1 + hw/arm/armsse.c | 47 +++++-- hw/arm/mps2-tz.c | 14 +- hw/arm/mps2.c | 28 +++- hw/arm/musca.c | 13 +- hw/arm/stellaris.c | 170 +++++++++++++++++------ hw/core/ptimer.c | 34 +++++ hw/timer/cmsdk-apb-dualtimer.c | 53 +++++-- hw/timer/cmsdk-apb-timer.c | 55 ++++---- hw/watchdog/cmsdk-apb-watchdog.c | 29 ++-- tests/qtest/cmsdk-apb-dualtimer-test.c | 131 +++++++++++++++++ tests/qtest/cmsdk-apb-timer-test.c | 76 ++++++++++ tests/qtest/cmsdk-apb-watchdog-test.c | 132 ++++++++++++++++++ MAINTAINERS | 3 + tests/qtest/meson.build | 3 + 22 files changed, 758 insertions(+), 142 deletions(-) create mode 100644 tests/qtest/cmsdk-apb-dualtimer-test.c create mode 100644 tests/qtest/cmsdk-apb-timer-test.c create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c
Signature · 1 line
2.20.1
PATCH 1/25 ptimer: Add new ptimer_set_period_from_clock() function
The ptimer API currently provides two methods for setting the period:ptimer_set_period(), which takes a period in nanoseconds, and ptimer_set_freq(), which takes a frequency in Hz. Neither of these lines up nicely with the Clock API, because although both the Clock and the ptimer track the frequency using a representation of whole and fractional nanoseconds, conversion via either period-in-ns or frequency-in-Hz will introduce a rounding error.
Add a new function ptimer_set_period_from_clock() which takes the Clock object directly to avoid the rounding issues. This includes a facility for the user to specify that there is a frequency divider between the Clock proper and the timer, as some timer devices like the CMSDK APB dualtimer need this.
To avoid having to drag in clock.h from ptimer.h we add the Clock type to typedefs.h.
---
Side note, I forget why we didn't go for 64.32 fixedpoint for the Clock too. I kinda feel we might run into the "clocks can't handle periods greater than 4 seconds" limit some day. Hopefully we can backwards-compatibly expand it if that day ever comes...
The 'divisor' functionality seemed like the simplest way to get to what I needed for the dualtimer; perhaps we should think about whether we can have generic lightweight support for clock frequency divider/multipliers...
--- include/hw/ptimer.h | 22 ++++++++++++++++++++++ include/qemu/typedefs.h | 1 + hw/core/ptimer.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+)
include/hw/ptimer.h +22 -0
@@ -165,6 +165,28 @@ void ptimer_transaction_commit(ptimer_state *s);*/ void ptimer_set_period (ptimer_state *s,int64_t period); +/** +* ptimer_set_period_from_clock - Set counter increment from a Clock +* @s: ptimer to configure +* @clk: pointer to Clock object to take period from +* @divisor: value to scale the clock frequency down by +* +* If the ptimer is being driven from a Clock, this is the preferred +* way to tell the ptimer about the period, because it avoids any +* possible rounding errors that might happen if the internal +* representation of the Clock period was converted to either a period +* in ns or a frequency in Hz. +* +* If the ptimer should run at the same frequency as the clock, +* pass 1 as the @divisor; if the ptimer should run at half the +* frequency, pass 2, and so on. +* +* This function will assert if it is called outside a +* ptimer_transaction_begin/commit block. +*/ +void ptimer_set_period_from_clock (ptimer_state *s,const Clock *clock, +unsigned int divisor); +/** * ptimer_set_freq - Set counter frequency in Hz * @s: ptimer to configure
include/qemu/typedefs.h +1 -0
@@ -34,6 +34,7 @@ typedef struct BlockDriverState BlockDriverState;typedef struct BusClass BusClass ;typedef struct BusState BusState ;typedef struct Chardev Chardev ; +typedef struct Clock Clock ;typedef struct CompatProperty CompatProperty ;typedef struct CoMutex CoMutex ;typedef struct CPUAddressSpace CPUAddressSpace ;
hw/core/ptimer.c +34 -0
@@ -15,6 +15,7 @@#include "sysemu/qtest.h" #include "block/aio.h" #include "sysemu/cpus.h" +#include "hw/clock.h" #define DELTA_ADJUST 1#define DELTA_NO_ADJUST -1
@@ -348,6 +349,39 @@ void ptimer_set_period(ptimer_state *s, int64_t period) } } +/* Set counter increment interval from a Clock */ +void ptimer_set_period_from_clock (ptimer_state *s,const Clock *clk, +unsigned int divisor) +{ +/* +* The raw clock period is a 64-bit value in units of 2^-32 ns; +* put another way it's a 32.32 fixed-point ns value. Our internal +* representation of the period is 64.32 fixed point ns, so +* the conversion is simple. +*/ +uint64_t raw_period =clock_get (clk); +uint64_t period_frac; + +assert (s->in_transaction); + s->delta =ptimer_get_count (s); + s->period =extract64 (raw_period,32 ,32 ); + period_frac =extract64 (raw_period,0 ,32 ); +/* +* divisor specifies a possible frequency divisor between the +* clock and the timer, so it is a multiplier on the period. +* We do the multiply after splitting the raw period out into +* period and frac to avoid having to do a 32*64->96 multiply. +*/ + s->period *= divisor; + period_frac *= divisor; + s->period +=extract64 (period_frac,32 ,32 ); + s->period_frac = (uint32_t )period_frac; + +if (s->enabled) { + s->need_reload = true; + } +} +/* Set counter frequency in Hz. */ void ptimer_set_freq (ptimer_state *s,uint32_t freq) {
Signature · 1 line
2.20.1
Re: [PATCH 01/25] ptimer: Add new ptimer_set_period_from_clock() function
Quoted 14 lines · Peter Maydell
The ptimer API currently provides two methods for setting the period:
ptimer_set_period(), which takes a period in nanoseconds, andptimer_set_freq(), which takes a frequency in Hz. Neither of these lines up nicely with the Clock API, because although both the Clock and the ptimer track the frequency using a representation of whole and fractional nanoseconds, conversion via either period-in-ns or frequency-in-Hz will introduce a rounding error.Add a new function
ptimer_set_period_from_clock()which takes the Clock object directly to avoid the rounding issues. This includes a facility for the user to specify that there is a frequency divider between the Clock proper and the timer, as some timer devices like the CMSDK APB dualtimer need this.
Quoted 4 lines
To avoid having to drag in
clock.hfromptimer.hwe add the Clock type totypedefs.h.Signed-off-by Peter Maydell <[email protected]>
Quoted 116 lines
---
Side note, I forget why we didn't go for 64.32 fixedpoint for the Clock too. I kinda feel we might run into the "clocks can't handle periods greater than 4 seconds" limit some day. Hopefully we can backwards-compatibly expand it if that day ever comes...The 'divisor' functionality seemed like the simplest way to get to what I needed for the dualtimer; perhaps we should think about whether we can have generic lightweight support for clock frequency divider/multipliers...
--- include/hw/ptimer.h | 22 ++++++++++++++++++++++ include/qemu/typedefs.h | 1 + hw/core/ptimer.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+)include/hw/ptimer.h +22
-0@@ -165,6 +165,28 @@ void ptimer_transaction_commit(ptimer_state *s);*/ void ptimer_set_period (ptimer_state *s,int64_t period); +/** +* ptimer_set_period_from_clock - Set counter increment from a Clock +* @s: ptimer to configure +* @clk: pointer to Clock object to take period from +* @divisor: value to scale the clock frequency down by +* +* If the ptimer is being driven from a Clock, this is the preferred +* way to tell the ptimer about the period, because it avoids any +* possible rounding errors that might happen if the internal +* representation of the Clock period was converted to either a period +* in ns or a frequency in Hz. +* +* If the ptimer should run at the same frequency as the clock, +* pass 1 as the @divisor; if the ptimer should run at half the +* frequency, pass 2, and so on. +* +* This function will assert if it is called outside a +* ptimer_transaction_begin/commit block. +*/ +void ptimer_set_period_from_clock (ptimer_state *s,const Clock *clock, +unsigned int divisor); +/** * ptimer_set_freq - Set counter frequency in Hz * @s: ptimer to configure include/qemu/typedefs.h +1
-0@@ -34,6 +34,7 @@ typedef struct BlockDriverState BlockDriverState;typedef struct BusClass BusClass ;typedef struct BusState BusState ;typedef struct Chardev Chardev ; +typedef struct Clock Clock ;typedef struct CompatProperty CompatProperty ;typedef struct CoMutex CoMutex ;typedef struct CPUAddressSpace CPUAddressSpace ;hw/core/ptimer.c +34
-0@@ -15,6 +15,7 @@#include "sysemu/qtest.h" #include "block/aio.h" #include "sysemu/cpus.h" +#include "hw/clock.h" #define DELTA_ADJUST 1#define DELTA_NO_ADJUST -1@@ -348,6 +349,39 @@ void ptimer_set_period(ptimer_state *s, int64_t period) } } +/* Set counter increment interval from a Clock */ +void ptimer_set_period_from_clock (ptimer_state *s,const Clock *clk, +unsigned int divisor) +{ +/* +* The raw clock period is a 64-bit value in units of 2^-32 ns; +* put another way it's a 32.32 fixed-point ns value. Our internal +* representation of the period is 64.32 fixed point ns, so +* the conversion is simple. +*/ +uint64_t raw_period =clock_get (clk); +uint64_t period_frac; + +assert (s->in_transaction); + s->delta =ptimer_get_count (s); + s->period =extract64 (raw_period,32 ,32 ); + period_frac =extract64 (raw_period,0 ,32 ); +/* +* divisor specifies a possible frequency divisor between the +* clock and the timer, so it is a multiplier on the period. +* We do the multiply after splitting the raw period out into +* period and frac to avoid having to do a 32*64->96 multiply. +*/ + s->period *= divisor; + period_frac *= divisor; + s->period +=extract64 (period_frac,32 ,32 ); + s->period_frac = (uint32_t )period_frac; + +if (s->enabled) { + s->need_reload = true; + } +} +/* Set counter frequency in Hz. */ void ptimer_set_freq (ptimer_state *s,uint32_t freq) {Signature · 1 line
2.20.1
PATCH 2/25 clock: Add new clock_has_source() function
In reply to Peter MaydellAdd a function for checking whether a clock has a source. This is useful for devices which have input clocks that must be wired up by the board as it allows them to fail in realize rather than ploughing on with a zero-period clock.
--- docs/devel/clocks.rst | 16 ++++++++++++++++ include/hw/clock.h | 15 +++++++++++++++ 2 files changed, 31 insertions(+)
docs/devel/clocks.rst +16 -0
@@ -235,6 +235,22 @@ object during device instance init. For example: /* set initial value to 10ns / 100MHz */ clock_set_ns(clk, 10); +To enforce that the clock is wired up by the board code, you can +call ``clock_has_source()`` in your device's realize method: + +.. code-block:: c + + if (!clock_has_source(s->clk)) { + error_setg(errp, "MyDevice: clk input must be connected"); + return; + } + +Note that this only checks that the clock has been wired up; it is +still possible that the output clock connected to it is disabled +or has not yet been configured, in which case the period will be +zero. You should use the clock callback to find out when the clock +period changes. + Fetching clock frequency/period -------------------------------
include/hw/clock.h +15 -0
@@ -139,6 +139,21 @@ void clock_clear_callback(Clock *clk);*/ void clock_set_source (Clock *clk,Clock *src); +/** +* clock_has_source: +* @clk: the clock +* +* Returns true if the clock has a source clock connected to it. +* This is useful for devices which have input clocks which must +* be connected by the board/SoC code which creates them. The +* device code can use this to check in its realize method that +* the clock has been connected. +*/ +static inline bool clock_has_source (const Clock *clk) +{ +return clk->source !=NULL ; +} +/** * clock_set: * @clk: the clock to initialize.
Signature · 1 line
2.20.1
Re: [PATCH 02/25] clock: Add new clock_has_source() function
Quoted 6 lines · Peter Maydell
Add a function for checking whether a clock has a source. This is useful for devices which have input clocks that must be wired up by the board as it allows them to fail in realize rather than ploughing on with a zero-period clock.
Signed-off-by Peter Maydell <[email protected]>
Quoted 61 lines
--- docs/devel/clocks.rst | 16 ++++++++++++++++ include/hw/clock.h | 15 +++++++++++++++ 2 files changed, 31 insertions(+)docs/devel/clocks.rst +16
-0@@ -235,6 +235,22 @@ object during device instance init. For example: /* set initial value to 10ns / 100MHz */ clock_set_ns(clk, 10); +To enforce that the clock is wired up by the board code, you can +call ``clock_has_source()`` in your device's realize method: + +.. code-block:: c + + if (!clock_has_source(s->clk)) { + error_setg(errp, "MyDevice: clk input must be connected"); + return; + } + +Note that this only checks that the clock has been wired up; it is +still possible that the output clock connected to it is disabled +or has not yet been configured, in which case the period will be +zero. You should use the clock callback to find out when the clock +period changes. + Fetching clock frequency/period -------------------------------include/hw/clock.h +15
-0@@ -139,6 +139,21 @@ void clock_clear_callback(Clock *clk);*/ void clock_set_source (Clock *clk,Clock *src); +/** +* clock_has_source: +* @clk: the clock +* +* Returns true if the clock has a source clock connected to it. +* This is useful for devices which have input clocks which must +* be connected by the board/SoC code which creates them. The +* device code can use this to check in its realize method that +* the clock has been connected. +*/ +static inline bool clock_has_source (const Clock *clk) +{ +return clk->source !=NULL ; +} +/** * clock_set: * @clk: the clock to initialize. Signature · 1 line
2.20.1
Re: [PATCH 02/25] clock: Add new clock_has_source() function
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
Add a function for checking whether a clock has a source. This is useful for devices which have input clocks that must be wired up by the board as it allows them to fail in realize rather than ploughing on with a zero-period clock.
Signed-off-by Peter Maydell <[email protected]>--- docs/devel/clocks.rst | 16 ++++++++++++++++ include/hw/clock.h | 15 +++++++++++++++ 2 files changed, 31 insertions(+)
PATCH 3/25 tests: Add a simple test of the CMSDK APB timer
In reply to Peter MaydellAdd a simple test of the CMSDK APB timer, since we're about to do some refactoring of how it is clocked.
--- tests/qtest/cmsdk-apb-timer-test.c | 76 ++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 78 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-timer-test.c
tests/qtest/cmsdk-apb-timer-test.c new file +76 -0
@@ -0,0 +1,76 @@ +/* +* QTest testcase for the CMSDK APB timer device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* IoTKit/ARMSSE-200 timer0; driven at 25MHz in mps2-an385, so 40ns per tick */ +#define TIMER_BASE 0x40000000 + +#define CTRL 0 +#define VALUE 4 +#define RELOAD 8 +#define INTSTATUS 0xc + +static void test_timer (void ) +{ +g_assert_true (readl (TIMER_BASE +INTSTATUS ) ==0 ); + +/* Start timer: will fire after 40000 ns */ +writel (TIMER_BASE +RELOAD ,1000 ); +writel (TIMER_BASE +CTRL ,9 ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (20001 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (20000 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 0); + +/* VALUE reloads at the following tick */ +clock_step (40 ); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 1000); + +/* Check write-1-to-clear behaviour of INTSTATUS */ +writel (TIMER_BASE +INTSTATUS ,0 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); +writel (TIMER_BASE +INTSTATUS ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +CTRL ,0 ); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine mps2-an385" ); + +qtest_add_func ("/cmsdk-apb-timer/timer" , test_timer); + + r =g_test_run (); + +qtest_end (); + +return r; +}
MAINTAINERS +1 -0
@@ -581,6 +581,7 @@ F: include/hw/rtc/pl031.h F: include/hw/arm/primecell.h F: hw/timer/cmsdk-apb-timer.c F: include/hw/timer/cmsdk-apb-timer.h +F: tests/qtest/cmsdk-apb-timer-test.c F: hw/timer/cmsdk-apb-dualtimer.c F: include/hw/timer/cmsdk-apb-dualtimer.h F: hw/char/cmsdk-apb-uart.c
tests/qtest/meson.build +1 -0
@@ -141,6 +141,7 @@ qtests_npcm7xx = \ 'npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] qtests_arm = \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ ['arm-cpu-features',
Signature · 1 line
2.20.1
Re: [PATCH 03/25] tests: Add a simple test of the CMSDK APB timer
Quoted 10 lines · Peter Maydell
Add a simple test of the CMSDK APB timer, since we're about to do some refactoring of how it is clocked.
Signed-off-by Peter Maydell <[email protected]>--- tests/qtest/cmsdk-apb-timer-test.c | 76 ++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 78 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-timer-test.c
Re: [PATCH 03/25] tests: Add a simple test of the CMSDK APB timer
In reply to Peter MaydellQuoted 4 lines · Peter Maydell
Add a simple test of the CMSDK APB timer, since we're about to do some refactoring of how it is clocked.
Signed-off-by Peter Maydell <[email protected]>
Quoted 116 lines
--- tests/qtest/cmsdk-apb-timer-test.c | 76 ++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 78 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-timer-test.ctests/qtest/cmsdk-apb-timer-test.c new file +76
-0@@ -0,0 +1,76 @@ +/* +* QTest testcase for the CMSDK APB timer device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* IoTKit/ARMSSE-200 timer0; driven at 25MHz in mps2-an385, so 40ns per tick */ +#define TIMER_BASE 0x40000000 + +#define CTRL 0 +#define VALUE 4 +#define RELOAD 8 +#define INTSTATUS 0xc + +static void test_timer (void ) +{ +g_assert_true (readl (TIMER_BASE +INTSTATUS ) ==0 ); + +/* Start timer: will fire after 40000 ns */ +writel (TIMER_BASE +RELOAD ,1000 ); +writel (TIMER_BASE +CTRL ,9 ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (20001 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (20000 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 0); + +/* VALUE reloads at the following tick */ +clock_step (40 ); + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 1000); + +/* Check write-1-to-clear behaviour of INTSTATUS */ +writel (TIMER_BASE +INTSTATUS ,0 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); +writel (TIMER_BASE +INTSTATUS ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +CTRL ,0 ); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine mps2-an385" ); + +qtest_add_func ("/cmsdk-apb-timer/timer" , test_timer); + + r =g_test_run (); + +qtest_end (); + +return r; +}MAINTAINERS +1
-0@@ -581,6 +581,7 @@ F: include/hw/rtc/pl031.h F: include/hw/arm/primecell.h F: hw/timer/cmsdk-apb-timer.c F: include/hw/timer/cmsdk-apb-timer.h +F: tests/qtest/cmsdk-apb-timer-test.c F: hw/timer/cmsdk-apb-dualtimer.c F: include/hw/timer/cmsdk-apb-dualtimer.h F: hw/char/cmsdk-apb-uart.ctests/qtest/meson.build +1
-0@@ -141,6 +141,7 @@ qtests_npcm7xx = \ 'npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] qtests_arm = \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ ['arm-cpu-features',Signature · 1 line
2.20.1
PATCH 4/25 tests: Add a simple test of the CMSDK APB watchdog
In reply to Peter MaydellAdd a simple test of the CMSDK watchdog, since we're about to do some refactoring of how it is clocked.
--- tests/qtest/cmsdk-apb-watchdog-test.c | 80 +++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c
tests/qtest/cmsdk-apb-watchdog-test.c new file +80 -0
@@ -0,0 +1,80 @@ +/* +* QTest testcase for the CMSDK APB watchdog device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* +* lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, +* which is 80ns per tick. +*/ +#define WDOG_BASE 0x40000000 + +#define WDOGLOAD 0 +#define WDOGVALUE 4 +#define WDOGCONTROL 8 +#define WDOGINTCLR 0xc +#define WDOGRIS 0x10 +#define WDOGMIS 0x14 +#define WDOGLOCK 0xc00 + +static void test_watchdog (void ) +{ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +writel (WDOG_BASE +WDOGCONTROL ,1 ); +writel (WDOG_BASE +WDOGLOAD ,1000 ); + +/* Step to just past the 500th tick */ +clock_step (500 *80 +1 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (500 *80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); + +/* VALUE reloads at following tick */ +clock_step (80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + +/* Writing any value to WDOGINTCLR clears the interrupt and reloads */ +clock_step (500 *80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); +writel (WDOG_BASE +WDOGINTCLR ,0 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine lm3s811evb" ); + +qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); + + r =g_test_run (); + +qtest_end (); + +return r; +}
MAINTAINERS +1 -0
@@ -588,6 +588,7 @@ F: hw/char/cmsdk-apb-uart.c F: include/hw/char/cmsdk-apb-uart.h F: hw/watchdog/cmsdk-apb-watchdog.c F: include/hw/watchdog/cmsdk-apb-watchdog.h +F: tests/qtest/cmsdk-apb-watchdog-test.c F: hw/misc/tz-ppc.c F: include/hw/misc/tz-ppc.h F: hw/misc/tz-mpc.c
tests/qtest/meson.build +1 -0
@@ -142,6 +142,7 @@ qtests_npcm7xx = \ 'npcm7xx_watchdog_timer-test'] qtests_arm = \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ ['arm-cpu-features',
Signature · 1 line
2.20.1
Re: [PATCH 04/25] tests: Add a simple test of the CMSDK APB watchdog
Quoted 4 lines · Peter Maydell
Add a simple test of the CMSDK watchdog, since we're about to do some refactoring of how it is clocked.
Signed-off-by Peter Maydell <[email protected]>
Quoted 120 lines
--- tests/qtest/cmsdk-apb-watchdog-test.c | 80 +++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.ctests/qtest/cmsdk-apb-watchdog-test.c new file +80
-0@@ -0,0 +1,80 @@ +/* +* QTest testcase for the CMSDK APB watchdog device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* +* lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, +* which is 80ns per tick. +*/ +#define WDOG_BASE 0x40000000 + +#define WDOGLOAD 0 +#define WDOGVALUE 4 +#define WDOGCONTROL 8 +#define WDOGINTCLR 0xc +#define WDOGRIS 0x10 +#define WDOGMIS 0x14 +#define WDOGLOCK 0xc00 + +static void test_watchdog (void ) +{ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +writel (WDOG_BASE +WDOGCONTROL ,1 ); +writel (WDOG_BASE +WDOGLOAD ,1000 ); + +/* Step to just past the 500th tick */ +clock_step (500 *80 +1 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (500 *80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); + +/* VALUE reloads at following tick */ +clock_step (80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + +/* Writing any value to WDOGINTCLR clears the interrupt and reloads */ +clock_step (500 *80 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); +writel (WDOG_BASE +WDOGINTCLR ,0 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine lm3s811evb" ); + +qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); + + r =g_test_run (); + +qtest_end (); + +return r; +}MAINTAINERS +1
-0@@ -588,6 +588,7 @@ F: hw/char/cmsdk-apb-uart.c F: include/hw/char/cmsdk-apb-uart.h F: hw/watchdog/cmsdk-apb-watchdog.c F: include/hw/watchdog/cmsdk-apb-watchdog.h +F: tests/qtest/cmsdk-apb-watchdog-test.c F: hw/misc/tz-ppc.c F: include/hw/misc/tz-ppc.h F: hw/misc/tz-mpc.ctests/qtest/meson.build +1
-0@@ -142,6 +142,7 @@ qtests_npcm7xx = \ 'npcm7xx_watchdog_timer-test'] qtests_arm = \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ ['arm-cpu-features',Signature · 1 line
2.20.1
Re: [PATCH 04/25] tests: Add a simple test of the CMSDK APB watchdog
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
Add a simple test of the CMSDK watchdog, since we're about to do some refactoring of how it is clocked.
Signed-off-by Peter Maydell <[email protected]>--- tests/qtest/cmsdk-apb-watchdog-test.c | 80 +++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c
PATCH 5/25 tests: Add a simple test of the CMSDK APB dual timer
In reply to Peter MaydellAdd a simple test of the CMSDK dual timer, since we're about to do some refactoring of how it is clocked.
--- tests/qtest/cmsdk-apb-dualtimer-test.c | 131 +++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 133 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-dualtimer-test.c
tests/qtest/cmsdk-apb-dualtimer-test.c new file +131 -0
@@ -0,0 +1,131 @@ +/* +* QTest testcase for the CMSDK APB dualtimer device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* IoTKit/ARMSSE dualtimer; driven at 25MHz in mps2-an385, so 40ns per tick */ +#define TIMER_BASE 0x40002000 + +#define TIMER1LOAD 0 +#define TIMER1VALUE 4 +#define TIMER1CONTROL 8 +#define TIMER1INTCLR 0xc +#define TIMER1RIS 0x10 +#define TIMER1MIS 0x14 +#define TIMER1BGLOAD 0x18 + +#define TIMER2LOAD 0x20 +#define TIMER2VALUE 0x24 +#define TIMER2CONTROL 0x28 +#define TIMER2INTCLR 0x2c +#define TIMER2RIS 0x30 +#define TIMER2MIS 0x34 +#define TIMER2BGLOAD 0x38 + +#define CTRL_ENABLE (1 << 7) +#define CTRL_PERIODIC (1 << 6) +#define CTRL_INTEN (1 << 5) +#define CTRL_PRESCALE_1 (0 << 2) +#define CTRL_PRESCALE_16 (1 << 2) +#define CTRL_PRESCALE_256 (2 << 2) +#define CTRL_32BIT (1 << 1) +#define CTRL_ONESHOT (1 << 0) + +static void test_dualtimer (void ) +{ +g_assert_true (readl (TIMER_BASE +TIMER1RIS ) ==0 ); + +/* Start timer: will fire after 40000 ns */ +writel (TIMER_BASE +TIMER1LOAD ,1000 ); +/* enable in free-running, wrapping, interrupt mode */ +writel (TIMER_BASE +TIMER1CONTROL ,CTRL_ENABLE |CTRL_INTEN ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (20001 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (20000 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0); + +/* +* We are in free-running wrapping 16-bit mode, so on the following +* tick VALUE should have wrapped round to 0xffff. +*/ +clock_step (40 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0xffff); + +/* Check that any write to INTCLR clears interrupt */ +writel (TIMER_BASE +TIMER1INTCLR ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +TIMER1CONTROL ,0 ); +} + +static void test_prescale (void ) +{ +g_assert_true (readl (TIMER_BASE +TIMER2RIS ) ==0 ); + +/* Start timer: will fire after 40 * 256 * 1000 == 1024000 ns */ +writel (TIMER_BASE +TIMER2LOAD ,1000 ); +/* enable in periodic, wrapping, interrupt mode, prescale 256 */ +writel (TIMER_BASE +TIMER2CONTROL , +CTRL_ENABLE |CTRL_INTEN |CTRL_PERIODIC |CTRL_PRESCALE_256 ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (40 *256 *501 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (40 *256 *500 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 0); + +/* In periodic mode the tick VALUE now reloads */ +clock_step (256 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 1000); + +/* Check that any write to INTCLR clears interrupt */ +writel (TIMER_BASE +TIMER2INTCLR ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +TIMER2CONTROL ,0 ); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine mps2-an385" ); + +qtest_add_func ("/cmsdk-apb-dualtimer/dualtimer" , test_dualtimer); +qtest_add_func ("/cmsdk-apb-dualtimer/prescale" , test_prescale); + + r =g_test_run (); + +qtest_end (); + +return r; +}
MAINTAINERS +1 -0
@@ -584,6 +584,7 @@ F: include/hw/timer/cmsdk-apb-timer.h F: tests/qtest/cmsdk-apb-timer-test.c F: hw/timer/cmsdk-apb-dualtimer.c F: include/hw/timer/cmsdk-apb-dualtimer.h +F: tests/qtest/cmsdk-apb-dualtimer-test.c F: hw/char/cmsdk-apb-uart.c F: include/hw/char/cmsdk-apb-uart.h F: hw/watchdog/cmsdk-apb-watchdog.c
tests/qtest/meson.build +1 -0
@@ -141,6 +141,7 @@ qtests_npcm7xx = \ 'npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] qtests_arm = \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \
Signature · 1 line
2.20.1
Re: [PATCH 05/25] tests: Add a simple test of the CMSDK APB dual timer
Quoted 110 lines · Peter Maydell
Add a simple test of the CMSDK dual timer, since we're about to do some refactoring of how it is clocked.
Signed-off-by Peter Maydell <[email protected]>--- tests/qtest/cmsdk-apb-dualtimer-test.c | 131 +++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 133 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-dualtimer-test.ctests/qtest/cmsdk-apb-dualtimer-test.c new file +93
-0@@ -0,0 +1,131 @@ +/* +* QTest testcase for the CMSDK APB dualtimer device +* +* Copyright (c) 2021 Linaro Limited +* +* 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 "libqtest-single.h" + +/* IoTKit/ARMSSE dualtimer; driven at 25MHz in mps2-an385, so 40ns per tick */ +#define TIMER_BASE 0x40002000 + +#define TIMER1LOAD 0 +#define TIMER1VALUE 4 +#define TIMER1CONTROL 8 +#define TIMER1INTCLR 0xc +#define TIMER1RIS 0x10 +#define TIMER1MIS 0x14 +#define TIMER1BGLOAD 0x18 + +#define TIMER2LOAD 0x20 +#define TIMER2VALUE 0x24 +#define TIMER2CONTROL 0x28 +#define TIMER2INTCLR 0x2c +#define TIMER2RIS 0x30 +#define TIMER2MIS 0x34 +#define TIMER2BGLOAD 0x38 + +#define CTRL_ENABLE (1 << 7) +#define CTRL_PERIODIC (1 << 6) +#define CTRL_INTEN (1 << 5) +#define CTRL_PRESCALE_1 (0 << 2) +#define CTRL_PRESCALE_16 (1 << 2) +#define CTRL_PRESCALE_256 (2 << 2) +#define CTRL_32BIT (1 << 1) +#define CTRL_ONESHOT (1 << 0) + +static void test_dualtimer (void ) +{ +g_assert_true (readl (TIMER_BASE +TIMER1RIS ) ==0 ); + +/* Start timer: will fire after 40000 ns */ +writel (TIMER_BASE +TIMER1LOAD ,1000 ); +/* enable in free-running, wrapping, interrupt mode */ +writel (TIMER_BASE +TIMER1CONTROL ,CTRL_ENABLE |CTRL_INTEN ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (20001 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (20000 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0); + +/* +* We are in free-running wrapping 16-bit mode, so on the following +* tick VALUE should have wrapped round to 0xffff. +*/ +clock_step (40 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0xffff); + +/* Check that any write to INTCLR clears interrupt */ +writel (TIMER_BASE +TIMER1INTCLR ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +TIMER1CONTROL ,0 ); +} + +static void test_prescale (void ) +{ +g_assert_true (readl (TIMER_BASE +TIMER2RIS ) ==0 ); + +/* Start timer: will fire after 40 * 256 * 1000 == 1024000 ns */ +writel (TIMER_BASE +TIMER2LOAD ,1000 ); +/* enable in periodic, wrapping, interrupt mode, prescale 256 */ +writel (TIMER_BASE +TIMER2CONTROL , +CTRL_ENABLE |CTRL_INTEN |CTRL_PERIODIC |CTRL_PRESCALE_256 ); + +/* Step to just past the 500th tick and check VALUE */ +clock_step (40 *256 *501 );
tests/qtest/cmsdk-apb-dualtimer-test.c line 103
Quoted 10 lines
tests/qtest/cmsdk-apb-dualtimer-test.c new file +10
-0+ g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 500); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (40 *256 *500 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 1); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 0); + +/* In periodic mode the tick VALUE now reloads */ +clock_step (256 );
Shouldn't it be "clock_step(40 * 256)", i.e. 1 tick?
Quoted 55 lines
tests/qtest/cmsdk-apb-dualtimer-test.c new file +28
-0+ g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 1000); + +/* Check that any write to INTCLR clears interrupt */ +writel (TIMER_BASE +TIMER2INTCLR ,1 ); + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); + +/* Turn off the timer */ +writel (TIMER_BASE +TIMER2CONTROL ,0 ); +} + +int main (int argc,char **argv) +{ +QTestState *s; +int r; + +g_test_init (&argc, &argv,NULL ); + + s =qtest_start ("-machine mps2-an385" ); + +qtest_add_func ("/cmsdk-apb-dualtimer/dualtimer" , test_dualtimer); +qtest_add_func ("/cmsdk-apb-dualtimer/prescale" , test_prescale); + + r =g_test_run (); + +qtest_end (); + +return r; +}MAINTAINERS +1
-0@@ -584,6 +584,7 @@ F: include/hw/timer/cmsdk-apb-timer.h F: tests/qtest/cmsdk-apb-timer-test.c F: hw/timer/cmsdk-apb-dualtimer.c F: include/hw/timer/cmsdk-apb-dualtimer.h +F: tests/qtest/cmsdk-apb-dualtimer-test.c F: hw/char/cmsdk-apb-uart.c F: include/hw/char/cmsdk-apb-uart.h F: hw/watchdog/cmsdk-apb-watchdog.ctests/qtest/meson.build +1
-0@@ -141,6 +141,7 @@ qtests_npcm7xx = \ 'npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] qtests_arm = \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \Signature · 1 line
2.20.1
PATCH 6/25 hw/timer/cmsdk-apb-timer: Rename CMSDKAPBTIMER struct to CMSDKAPBTimer
In reply to Peter MaydellThe state struct for the CMSDK APB timer device doesn't follow our usual naming convention of camelcase -- "CMSDK" and "APB" are both acronyms, but "TIMER" is not so should not be all-uppercase. Globally rename the struct to "CMSDKAPBTimer" (bringing it into line with CMSDKAPBWatchdog and CMSDKAPBDualTimer; CMSDKAPBUART remains as-is because "UART" is an acronym).
Commit created with:
perl -p -i -e 's/CMSDKAPBTIMER/CMSDKAPBTimer/g' hw/timer/cmsdk-apb-timer.c include/hw/arm/armsse.h include/hw/timer/cmsdk-apb-timer.h
--- include/hw/arm/armsse.h | 6 +++--- include/hw/timer/cmsdk-apb-timer.h | 4 ++-- hw/timer/cmsdk-apb-timer.c | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 19 deletions(-)
include/hw/arm/armsse.h +3 -3
@@ -153,9 +153,9 @@ struct ARMSSE {TZPPC apb_ppc0;TZPPC apb_ppc1;TZMPC mpc[IOTS_NUM_MPC ]; -CMSDKAPBTIMER timer0; -CMSDKAPBTIMER timer1; -CMSDKAPBTIMER s32ktimer; +CMSDKAPBTimer timer0; +CMSDKAPBTimer timer1; +CMSDKAPBTimer s32ktimer;qemu_or_irq ppc_irq_orgate;SplitIRQ sec_resp_splitter;SplitIRQ ppc_irq_splitter[NUM_PPCS ];
include/hw/timer/cmsdk-apb-timer.h +2 -2
@@ -18,9 +18,9 @@#include "qom/object.h" #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" -OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTIMER, CMSDK_APB_TIMER) +OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER) -struct CMSDKAPBTIMER { +struct CMSDKAPBTimer {/*< private >*/ SysBusDevice parent_obj;
hw/timer/cmsdk-apb-timer.c +14 -14
@@ -67,14 +67,14 @@ static const int timer_id[] = { 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */ }; -static void cmsdk_apb_timer_update (CMSDKAPBTIMER *s) +static void cmsdk_apb_timer_update (CMSDKAPBTimer *s) {qemu_set_irq (s->timerint, !!(s->intstatus &R_INTSTATUS_IRQ_MASK )); }static uint64_t cmsdk_apb_timer_read (void *opaque,hwaddr offset,unsigned size) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);uint64_t r;switch (offset) {
@@ -106,7 +106,7 @@ static uint64_t cmsdk_apb_timer_read(void *opaque, hwaddr offset, unsigned size)static void cmsdk_apb_timer_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);trace_cmsdk_apb_timer_write (offset, value, size);
@@ -181,7 +181,7 @@ static const MemoryRegionOps cmsdk_apb_timer_ops = {static void cmsdk_apb_timer_tick (void *opaque) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);if (s->ctrl &R_CTRL_IRQEN_MASK ) { s->intstatus |=R_INTSTATUS_IRQ_MASK ;
@@ -191,7 +191,7 @@ static void cmsdk_apb_timer_tick(void *opaque)static void cmsdk_apb_timer_reset (DeviceState *dev) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (dev); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev);trace_cmsdk_apb_timer_reset (); s->ctrl =0 ;
@@ -206,7 +206,7 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)static void cmsdk_apb_timer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (obj); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (obj);memory_region_init_io (&s->iomem, obj, &cmsdk_apb_timer_ops, s,"cmsdk-apb-timer" ,0x1000 );
@@ -216,7 +216,7 @@ static void cmsdk_apb_timer_init(Object *obj)static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (dev); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev);if (s->pclk_frq ==0 ) {error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" );
@@ -239,17 +239,17 @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField []) { -VMSTATE_PTIMER (timer,CMSDKAPBTIMER ), -VMSTATE_UINT32 (ctrl,CMSDKAPBTIMER ), -VMSTATE_UINT32 (value,CMSDKAPBTIMER ), -VMSTATE_UINT32 (reload,CMSDKAPBTIMER ), -VMSTATE_UINT32 (intstatus,CMSDKAPBTIMER ), +VMSTATE_PTIMER (timer, CMSDKAPBTimer), +VMSTATE_UINT32 (ctrl, CMSDKAPBTimer), +VMSTATE_UINT32 (value, CMSDKAPBTimer), +VMSTATE_UINT32 (reload, CMSDKAPBTimer), +VMSTATE_UINT32 (intstatus, CMSDKAPBTimer),VMSTATE_END_OF_LIST () } };static Property cmsdk_apb_timer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" ,CMSDKAPBTIMER , pclk_frq,0 ), +DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBTimer, pclk_frq,0 ),DEFINE_PROP_END_OF_LIST (), };
@@ -266,7 +266,7 @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data)static const TypeInfo cmsdk_apb_timer_info = { .name =TYPE_CMSDK_APB_TIMER , .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (CMSDKAPBTIMER ), + .instance_size =sizeof (CMSDKAPBTimer), .instance_init = cmsdk_apb_timer_init, .class_init = cmsdk_apb_timer_class_init, };
Signature · 1 line
2.20.1
Re: [PATCH 06/25] hw/timer/cmsdk-apb-timer: Rename CMSDKAPBTIMER struct to CMSDKAPBTimer
Quoted 10 lines · Peter Maydell
The state struct for the CMSDK APB timer device doesn't follow our usual naming convention of camelcase -- "CMSDK" and "APB" are both acronyms, but "TIMER" is not so should not be all-uppercase. Globally rename the struct to "CMSDKAPBTimer" (bringing it into line with CMSDKAPBWatchdog and CMSDKAPBDualTimer; CMSDKAPBUART remains as-is because "UART" is an acronym).
Commit created with:
perl -p -i -e 's/CMSDKAPBTIMER/CMSDKAPBTimer/g'hw/timer/cmsdk-apb-timer.cinclude/hw/arm/armsse.hinclude/hw/timer/cmsdk-apb-timer.h
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>--- include/hw/arm/armsse.h | 6 +++--- include/hw/timer/cmsdk-apb-timer.h | 4 ++-- hw/timer/cmsdk-apb-timer.c | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 19 deletions(-)
Re: [PATCH 06/25] hw/timer/cmsdk-apb-timer: Rename CMSDKAPBTIMER struct to CMSDKAPBTimer
In reply to Peter MaydellQuoted 11 lines · Peter Maydell
The state struct for the CMSDK APB timer device doesn't follow our usual naming convention of camelcase -- "CMSDK" and "APB" are both acronyms, but "TIMER" is not so should not be all-uppercase. Globally rename the struct to "CMSDKAPBTimer" (bringing it into line with CMSDKAPBWatchdog and CMSDKAPBDualTimer; CMSDKAPBUART remains as-is because "UART" is an acronym).
Commit created with:
perl -p -i -e 's/CMSDKAPBTIMER/CMSDKAPBTimer/g'hw/timer/cmsdk-apb-timer.cinclude/hw/arm/armsse.hinclude/hw/timer/cmsdk-apb-timer.hSigned-off-by Peter Maydell <[email protected]>
Quoted 141 lines
--- include/hw/arm/armsse.h | 6 +++--- include/hw/timer/cmsdk-apb-timer.h | 4 ++-- hw/timer/cmsdk-apb-timer.c | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 19 deletions(-)include/hw/arm/armsse.h +3
-3@@ -153,9 +153,9 @@ struct ARMSSE {TZPPC apb_ppc0;TZPPC apb_ppc1;TZMPC mpc[IOTS_NUM_MPC ]; -CMSDKAPBTIMER timer0; -CMSDKAPBTIMER timer1; -CMSDKAPBTIMER s32ktimer; +CMSDKAPBTimer timer0; +CMSDKAPBTimer timer1; +CMSDKAPBTimer s32ktimer;qemu_or_irq ppc_irq_orgate;SplitIRQ sec_resp_splitter;SplitIRQ ppc_irq_splitter[NUM_PPCS ];include/hw/timer/cmsdk-apb-timer.h +2
-2@@ -18,9 +18,9 @@#include "qom/object.h" #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" -OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTIMER, CMSDK_APB_TIMER) +OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER) -struct CMSDKAPBTIMER { +struct CMSDKAPBTimer {/*< private >*/ SysBusDevice parent_obj;hw/timer/cmsdk-apb-timer.c +14
-14@@ -67,14 +67,14 @@ static const int timer_id[] = { 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */ }; -static void cmsdk_apb_timer_update (CMSDKAPBTIMER *s) +static void cmsdk_apb_timer_update (CMSDKAPBTimer *s) {qemu_set_irq (s->timerint, !!(s->intstatus &R_INTSTATUS_IRQ_MASK )); }static uint64_t cmsdk_apb_timer_read (void *opaque,hwaddr offset,unsigned size) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);uint64_t r;switch (offset) {@@ -106,7 +106,7 @@ static uint64_t cmsdk_apb_timer_read(void *opaque, hwaddr offset, unsigned size)static void cmsdk_apb_timer_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);trace_cmsdk_apb_timer_write (offset, value, size);@@ -181,7 +181,7 @@ static const MemoryRegionOps cmsdk_apb_timer_ops = {static void cmsdk_apb_timer_tick (void *opaque) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (opaque); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque);if (s->ctrl &R_CTRL_IRQEN_MASK ) { s->intstatus |=R_INTSTATUS_IRQ_MASK ;@@ -191,7 +191,7 @@ static void cmsdk_apb_timer_tick(void *opaque)static void cmsdk_apb_timer_reset (DeviceState *dev) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (dev); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev);trace_cmsdk_apb_timer_reset (); s->ctrl =0 ;@@ -206,7 +206,7 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)static void cmsdk_apb_timer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (obj); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (obj);memory_region_init_io (&s->iomem, obj, &cmsdk_apb_timer_ops, s,"cmsdk-apb-timer" ,0x1000 );@@ -216,7 +216,7 @@ static void cmsdk_apb_timer_init(Object *obj)static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp) { -CMSDKAPBTIMER *s =CMSDK_APB_TIMER (dev); +CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev);if (s->pclk_frq ==0 ) {error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" );@@ -239,17 +239,17 @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField []) { -VMSTATE_PTIMER (timer,CMSDKAPBTIMER ), -VMSTATE_UINT32 (ctrl,CMSDKAPBTIMER ), -VMSTATE_UINT32 (value,CMSDKAPBTIMER ), -VMSTATE_UINT32 (reload,CMSDKAPBTIMER ), -VMSTATE_UINT32 (intstatus,CMSDKAPBTIMER ), +VMSTATE_PTIMER (timer, CMSDKAPBTimer), +VMSTATE_UINT32 (ctrl, CMSDKAPBTimer), +VMSTATE_UINT32 (value, CMSDKAPBTimer), +VMSTATE_UINT32 (reload, CMSDKAPBTimer), +VMSTATE_UINT32 (intstatus, CMSDKAPBTimer),VMSTATE_END_OF_LIST () } };static Property cmsdk_apb_timer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" ,CMSDKAPBTIMER , pclk_frq,0 ), +DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBTimer, pclk_frq,0 ),DEFINE_PROP_END_OF_LIST (), };@@ -266,7 +266,7 @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data)static const TypeInfo cmsdk_apb_timer_info = { .name =TYPE_CMSDK_APB_TIMER , .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (CMSDKAPBTIMER ), + .instance_size =sizeof (CMSDKAPBTimer), .instance_init = cmsdk_apb_timer_init, .class_init = cmsdk_apb_timer_class_init, };Signature · 1 line
2.20.1
PATCH 7/25 hw/timer/cmsdk-apb-timer: Add Clock input
In reply to Peter MaydellAs the first step in converting the CMSDK_APB_TIMER device to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.
Since the device doesn't already have a doc comment for its "QEMU interface", we add one including the new Clock.
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
--- include/hw/timer/cmsdk-apb-timer.h | 9 +++++++++ hw/timer/cmsdk-apb-timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/hw/timer/cmsdk-apb-timer.h +9 -0
@@ -15,11 +15,19 @@#include "hw/qdev-properties.h" #include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer"OBJECT_DECLARE_SIMPLE_TYPE (CMSDKAPBTimer,CMSDK_APB_TIMER ) +/* +* QEMU interface: +* + QOM property "pclk-frq": frequency at which the timer is clocked +* + Clock input "pclk": clock for the timer +* + sysbus MMIO region 0: the register bank +* + sysbus IRQ 0: timer interrupt TIMERINT + */struct CMSDKAPBTimer {/*< private >*/ SysBusDevice parent_obj;
@@ -29,6 +37,7 @@ struct CMSDKAPBTimer {qemu_irq timerint;uint32_t pclk_frq;struct ptimer_state *timer; +Clock *pclk;uint32_t ctrl;uint32_t value;
hw/timer/cmsdk-apb-timer.c +5 -2
@@ -35,6 +35,7 @@#include "hw/sysbus.h" #include "hw/irq.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/timer/cmsdk-apb-timer.h" #include "migration/vmstate.h"
@@ -212,6 +213,7 @@ static void cmsdk_apb_timer_init(Object *obj) s, "cmsdk-apb-timer", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->timerint); + s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" ,NULL ,NULL ); }static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp)
@@ -236,10 +238,11 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp)static const VMStateDescription cmsdk_apb_timer_vmstate = { .name ="cmsdk-apb-timer" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) {VMSTATE_PTIMER (timer, CMSDKAPBTimer), +VMSTATE_CLOCK (pclk, CMSDKAPBTimer),VMSTATE_UINT32 (ctrl, CMSDKAPBTimer),VMSTATE_UINT32 (value, CMSDKAPBTimer),VMSTATE_UINT32 (reload, CMSDKAPBTimer),
Signature · 1 line
2.20.1
Re: [PATCH 07/25] hw/timer/cmsdk-apb-timer: Add Clock input
Quoted 9 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_TIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.Since the device doesn't already have a doc comment for its "QEMU interface", we add one including the new Clock.
Quoted 8 lines
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
Signed-off-by Peter Maydell <[email protected]>--- include/hw/timer/cmsdk-apb-timer.h | 9 +++++++++ hw/timer/cmsdk-apb-timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
Re: [PATCH 07/25] hw/timer/cmsdk-apb-timer: Add Clock input
In reply to Peter MaydellQuoted 6 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_TIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.
Quoted 7 lines
Since the device doesn't already have a doc comment for its "QEMU interface", we add one including the new Clock.
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
Signed-off-by Peter Maydell <[email protected]>
Quoted 74 lines
--- include/hw/timer/cmsdk-apb-timer.h | 9 +++++++++ hw/timer/cmsdk-apb-timer.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-)include/hw/timer/cmsdk-apb-timer.h +9
-0@@ -15,11 +15,19 @@#include "hw/qdev-properties.h" #include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer"OBJECT_DECLARE_SIMPLE_TYPE (CMSDKAPBTimer,CMSDK_APB_TIMER ) +/* +* QEMU interface: +* + QOM property "pclk-frq": frequency at which the timer is clocked +* + Clock input "pclk": clock for the timer +* + sysbus MMIO region 0: the register bank +* + sysbus IRQ 0: timer interrupt TIMERINT + */struct CMSDKAPBTimer {/*< private >*/ SysBusDevice parent_obj;@@ -29,6 +37,7 @@ struct CMSDKAPBTimer {qemu_irq timerint;uint32_t pclk_frq;struct ptimer_state *timer; +Clock *pclk;uint32_t ctrl;uint32_t value;hw/timer/cmsdk-apb-timer.c +5
-2@@ -35,6 +35,7 @@#include "hw/sysbus.h" #include "hw/irq.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/timer/cmsdk-apb-timer.h" #include "migration/vmstate.h" @@ -212,6 +213,7 @@ static void cmsdk_apb_timer_init(Object *obj) s, "cmsdk-apb-timer", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->timerint); + s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" ,NULL ,NULL ); }static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp)@@ -236,10 +238,11 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp)static const VMStateDescription cmsdk_apb_timer_vmstate = { .name ="cmsdk-apb-timer" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) {VMSTATE_PTIMER (timer, CMSDKAPBTimer), +VMSTATE_CLOCK (pclk, CMSDKAPBTimer),VMSTATE_UINT32 (ctrl, CMSDKAPBTimer),VMSTATE_UINT32 (value, CMSDKAPBTimer),VMSTATE_UINT32 (reload, CMSDKAPBTimer),Signature · 1 line
2.20.1
PATCH 8/25 hw/timer/cmsdk-apb-dualtimer: Add Clock input
In reply to Peter MaydellAs the first step in converting the CMSDK_APB_DUALTIMER device to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.
We take the opportunity to correct the name of the clock input to match the hardware -- the dual timer names the clock which drives the timers TIMCLK. (It does also have a 'pclk' input, which is used only for the register and APB bus logic; on the SSE-200 these clocks are both connected together.)
This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1.
--- include/hw/timer/cmsdk-apb-dualtimer.h | 3 +++ hw/timer/cmsdk-apb-dualtimer.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/hw/timer/cmsdk-apb-dualtimer.h +3 -0
@@ -17,6 +17,7 @@* * QEMU interface: * + QOM property "pclk-frq": frequency at which the timer is clocked +* + Clock input "TIMCLK": clock (for both timers) * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: combined timer interrupt TIMINTC * + sysbus IRO 1: timer block 1 interrupt TIMINT1
@@ -28,6 +29,7 @@#include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_DUALTIMER "cmsdk-apb-dualtimer"
@@ -62,6 +64,7 @@ struct CMSDKAPBDualTimer {MemoryRegion iomem;qemu_irq timerintc;uint32_t pclk_frq; +Clock *timclk;CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES ];uint32_t timeritcr;
hw/timer/cmsdk-apb-dualtimer.c +5 -2
@@ -25,6 +25,7 @@#include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/timer/cmsdk-apb-dualtimer.h" #include "migration/vmstate.h"
@@ -445,6 +446,7 @@ static void cmsdk_apb_dualtimer_init(Object *obj)for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) {sysbus_init_irq (sbd, &s->timermod[i].timerint); } + s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" ,NULL ,NULL ); }static void cmsdk_apb_dualtimer_realize (DeviceState *dev,Error **errp)
@@ -485,9 +487,10 @@ static const VMStateDescription cmsdk_dualtimermod_vmstate = {static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { .name ="cmsdk-apb-dualtimer" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (timclk, CMSDKAPBDualTimer), VMSTATE_STRUCT_ARRAY(timermod, CMSDKAPBDualTimer, CMSDK_APB_DUALTIMER_NUM_MODULES, 1, cmsdk_dualtimermod_vmstate,
Signature · 1 line
2.20.1
Re: [PATCH 08/25] hw/timer/cmsdk-apb-dualtimer: Add Clock input
Quoted 16 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_DUALTIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.We take the opportunity to correct the name of the clock input to match the hardware -- the dual timer names the clock which drives the timers TIMCLK. (It does also have a 'pclk' input, which is used only for the register and APB bus logic; on the SSE-200 these clocks are both connected together.)
This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- include/hw/timer/cmsdk-apb-dualtimer.h | 3 +++ hw/timer/cmsdk-apb-dualtimer.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
Re: [PATCH 08/25] hw/timer/cmsdk-apb-dualtimer: Add Clock input
In reply to Peter MaydellQuoted 12 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_DUALTIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the pclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.We take the opportunity to correct the name of the clock input to match the hardware -- the dual timer names the clock which drives the timers TIMCLK. (It does also have a 'pclk' input, which is used only for the register and APB bus logic; on the SSE-200 these clocks are both connected together.)
Quoted 5 lines
This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1.
Signed-off-by Peter Maydell <[email protected]>
Quoted 69 lines
--- include/hw/timer/cmsdk-apb-dualtimer.h | 3 +++ hw/timer/cmsdk-apb-dualtimer.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/hw/timer/cmsdk-apb-dualtimer.h +3
-0@@ -17,6 +17,7 @@* * QEMU interface: * + QOM property "pclk-frq": frequency at which the timer is clocked +* + Clock input "TIMCLK": clock (for both timers) * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: combined timer interrupt TIMINTC * + sysbus IRO 1: timer block 1 interrupt TIMINT1 @@ -28,6 +29,7 @@#include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_DUALTIMER "cmsdk-apb-dualtimer"@@ -62,6 +64,7 @@ struct CMSDKAPBDualTimer {MemoryRegion iomem;qemu_irq timerintc;uint32_t pclk_frq; +Clock *timclk;CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES ];uint32_t timeritcr;hw/timer/cmsdk-apb-dualtimer.c +5
-2@@ -25,6 +25,7 @@#include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/timer/cmsdk-apb-dualtimer.h" #include "migration/vmstate.h" @@ -445,6 +446,7 @@ static void cmsdk_apb_dualtimer_init(Object *obj)for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) {sysbus_init_irq (sbd, &s->timermod[i].timerint); } + s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" ,NULL ,NULL ); }static void cmsdk_apb_dualtimer_realize (DeviceState *dev,Error **errp)@@ -485,9 +487,10 @@ static const VMStateDescription cmsdk_dualtimermod_vmstate = {static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { .name ="cmsdk-apb-dualtimer" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (timclk, CMSDKAPBDualTimer), VMSTATE_STRUCT_ARRAY(timermod, CMSDKAPBDualTimer, CMSDK_APB_DUALTIMER_NUM_MODULES, 1, cmsdk_dualtimermod_vmstate,Signature · 1 line
2.20.1
PATCH 9/25 hw/watchdog/cmsdk-apb-watchdog: Add Clock input
In reply to Peter MaydellAs the first step in converting the CMSDK_APB_TIMER device to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the wdogclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.
This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1, lm3s811evb, lm3s6965evb.
--- include/hw/watchdog/cmsdk-apb-watchdog.h | 3 +++ hw/watchdog/cmsdk-apb-watchdog.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/hw/watchdog/cmsdk-apb-watchdog.h +3 -0
@@ -17,6 +17,7 @@* * QEMU interface: * + QOM property "wdogclk-frq": frequency at which the watchdog is clocked +* + Clock input "WDOGCLK": clock for the watchdog's timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: watchdog interrupt *
@@ -33,6 +34,7 @@#include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_WATCHDOG "cmsdk-apb-watchdog"
@@ -54,6 +56,7 @@ struct CMSDKAPBWatchdog {uint32_t wdogclk_frq;bool is_luminary;struct ptimer_state *timer; +Clock *wdogclk;uint32_t control;uint32_t intstatus;
hw/watchdog/cmsdk-apb-watchdog.c +5 -2
@@ -30,6 +30,7 @@#include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/watchdog/cmsdk-apb-watchdog.h" #include "migration/vmstate.h"
@@ -318,6 +319,7 @@ static void cmsdk_apb_watchdog_init(Object *obj) s, "cmsdk-apb-watchdog", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->wdogint); + s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" ,NULL ,NULL ); s->is_luminary = false; s->id = cmsdk_apb_watchdog_id;
@@ -346,9 +348,10 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp)static const VMStateDescription cmsdk_apb_watchdog_vmstate = { .name ="cmsdk-apb-watchdog" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (wdogclk, CMSDKAPBWatchdog),VMSTATE_PTIMER (timer, CMSDKAPBWatchdog),VMSTATE_UINT32 (control, CMSDKAPBWatchdog),VMSTATE_UINT32 (intstatus, CMSDKAPBWatchdog),
Signature · 1 line
2.20.1
Re: [PATCH 09/25] hw/watchdog/cmsdk-apb-watchdog: Add Clock input
Quoted 10 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_TIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the wdogclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1, lm3s811evb, lm3s6965evb.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- include/hw/watchdog/cmsdk-apb-watchdog.h | 3 +++ hw/watchdog/cmsdk-apb-watchdog.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
Re: [PATCH 09/25] hw/watchdog/cmsdk-apb-watchdog: Add Clock input
In reply to Peter MaydellQuoted 11 lines · Peter Maydell
As the first step in converting the
CMSDK_APB_TIMERdevice to the Clock framework, add a Clock input. For the moment we do nothing with this clock; we will change the behaviour from using the wdogclk-frq property to using the Clock once all the users of this device have been converted to wire up the Clock.This is a migration compatibility break for machines mps2-an385, mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, musca-b1, lm3s811evb, lm3s6965evb.
Signed-off-by Peter Maydell <[email protected]>
Quoted 69 lines
--- include/hw/watchdog/cmsdk-apb-watchdog.h | 3 +++ hw/watchdog/cmsdk-apb-watchdog.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/hw/watchdog/cmsdk-apb-watchdog.h +3
-0@@ -17,6 +17,7 @@* * QEMU interface: * + QOM property "wdogclk-frq": frequency at which the watchdog is clocked +* + Clock input "WDOGCLK": clock for the watchdog's timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: watchdog interrupt * @@ -33,6 +34,7 @@#include "hw/sysbus.h" #include "hw/ptimer.h" +#include "hw/clock.h" #include "qom/object.h" #define TYPE_CMSDK_APB_WATCHDOG "cmsdk-apb-watchdog"@@ -54,6 +56,7 @@ struct CMSDKAPBWatchdog {uint32_t wdogclk_frq;bool is_luminary;struct ptimer_state *timer; +Clock *wdogclk;uint32_t control;uint32_t intstatus;hw/watchdog/cmsdk-apb-watchdog.c +5
-2@@ -30,6 +30,7 @@#include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/registerfields.h" +#include "hw/qdev-clock.h" #include "hw/watchdog/cmsdk-apb-watchdog.h" #include "migration/vmstate.h" @@ -318,6 +319,7 @@ static void cmsdk_apb_watchdog_init(Object *obj) s, "cmsdk-apb-watchdog", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->wdogint); + s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" ,NULL ,NULL ); s->is_luminary = false; s->id = cmsdk_apb_watchdog_id;@@ -346,9 +348,10 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp)static const VMStateDescription cmsdk_apb_watchdog_vmstate = { .name ="cmsdk-apb-watchdog" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (wdogclk, CMSDKAPBWatchdog),VMSTATE_PTIMER (timer, CMSDKAPBWatchdog),VMSTATE_UINT32 (control, CMSDKAPBWatchdog),VMSTATE_UINT32 (intstatus, CMSDKAPBWatchdog),Signature · 1 line
2.20.1
PATCH 10/25 hw/arm/armsse: Rename "MAINCLK" property to "MAINCLK_FRQ"
In reply to Peter MaydellWhile we transition the ARMSSE code from integer properties specifying clock frequencies to Clock objects, we want to have the device provide both at once. We want the final name of the main input Clock to be "MAINCLK", following the hardware name. Unfortunately creating an input Clock with a name X creates an under-the-hood QOM property X; for "MAINCLK" this clashes with the existing UINT32 property of that name.
Rename the UINT32 property to MAINCLK_FRQ so it can coexist with the MAINCLK Clock; once the transition is complete MAINCLK_FRQ will be deleted.
Commit created with:
perl -p -i -e 's/MAINCLK/MAINCLK_FRQ/g' hw/arm/{armsse,mps2-tz,musca}.c include/hw/arm/armsse.h
--- include/hw/arm/armsse.h | 2 +- hw/arm/armsse.c | 6 +++--- hw/arm/mps2-tz.c | 2 +- hw/arm/musca.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
include/hw/arm/armsse.h +1 -1
@@ -39,7 +39,7 @@* QEMU interface: * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. -* + QOM property "MAINCLK" is the frequency of the main system clock +* + QOM property "MAINCLK_FRQ" is the frequency of the main system clock * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. * (In hardware, the SSE-200 permits the number of expansion interrupts * for the two CPUs to be configured separately, but we restrict it to
hw/arm/armsse.c +3 -3
@@ -47,7 +47,7 @@ static Property iotkit_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK" ,ARMSSE , mainclk_frq,0 ), +DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),
@@ -59,7 +59,7 @@ static Property armsse_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK" ,ARMSSE , mainclk_frq,0 ), +DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),
@@ -448,7 +448,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) }if (!s->mainclk_frq) { -error_setg (errp,"MAINCLK property was not set" ); +error_setg (errp,"MAINCLK_FRQ property was not set" );return ; }
hw/arm/mps2-tz.c +1 -1
@@ -402,7 +402,7 @@ static void mps2tz_common_init(MachineState *machine)object_property_set_link (OBJECT (&mms->iotkit),"memory" ,OBJECT (system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ ); -qdev_prop_set_uint32 (iotkitdev,"MAINCLK" ,SYSCLK_FRQ ); +qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ );sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);/*
hw/arm/musca.c +1 -1
@@ -375,7 +375,7 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"EXP_NUMIRQ" , mmc->num_irqs);qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width); -qdev_prop_set_uint32 (ssedev,"MAINCLK" ,SYSCLK_FRQ ); +qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ );/* * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0.
Signature · 1 line
2.20.1
Re: [PATCH 10/25] hw/arm/armsse: Rename "MAINCLK" property to "MAINCLK_FRQ"
Quoted 15 lines · Peter Maydell
While we transition the ARMSSE code from integer properties specifying clock frequencies to Clock objects, we want to have the device provide both at once. We want the final name of the main input Clock to be "MAINCLK", following the hardware name. Unfortunately creating an input Clock with a name X creates an under-the-hood QOM property X; for "MAINCLK" this clashes with the existing UINT32 property of that name.
Rename the UINT32 property to
MAINCLK_FRQso it can coexist with the MAINCLK Clock; once the transition is completeMAINCLK_FRQwill be deleted.Commit created with:
perl -p -i -e 's/MAINCLK/MAINCLK_FRQ/g'hw/arm/{armsse,mps2-tz,musca}.cinclude/hw/arm/armsse.h
Quoted 7 lines
Signed-off-by Peter Maydell <[email protected]>--- include/hw/arm/armsse.h | 2 +- hw/arm/armsse.c | 6 +++--- hw/arm/mps2-tz.c | 2 +- hw/arm/musca.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
Re: [PATCH 10/25] hw/arm/armsse: Rename "MAINCLK" property to "MAINCLK_FRQ"
In reply to Peter MaydellQuoted 8 lines · Peter Maydell
While we transition the ARMSSE code from integer properties specifying clock frequencies to Clock objects, we want to have the device provide both at once. We want the final name of the main input Clock to be "MAINCLK", following the hardware name. Unfortunately creating an input Clock with a name X creates an under-the-hood QOM property X; for "MAINCLK" this clashes with the existing UINT32 property of that name.
Quoted 8 lines
Rename the UINT32 property to
MAINCLK_FRQso it can coexist with the MAINCLK Clock; once the transition is completeMAINCLK_FRQwill be deleted.Commit created with:
perl -p -i -e 's/MAINCLK/MAINCLK_FRQ/g'hw/arm/{armsse,mps2-tz,musca}.cinclude/hw/arm/armsse.hSigned-off-by Peter Maydell <[email protected]>
Quoted 80 lines
--- include/hw/arm/armsse.h | 2 +- hw/arm/armsse.c | 6 +++--- hw/arm/mps2-tz.c | 2 +- hw/arm/musca.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)include/hw/arm/armsse.h +1
-1@@ -39,7 +39,7 @@* QEMU interface: * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. -* + QOM property "MAINCLK" is the frequency of the main system clock +* + QOM property "MAINCLK_FRQ" is the frequency of the main system clock * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. * (In hardware, the SSE-200 permits the number of expansion interrupts * for the two CPUs to be configured separately, but we restrict it to hw/arm/armsse.c +3
-3@@ -47,7 +47,7 @@ static Property iotkit_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK" ,ARMSSE , mainclk_frq,0 ), +DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),@@ -59,7 +59,7 @@ static Property armsse_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK" ,ARMSSE , mainclk_frq,0 ), +DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),@@ -448,7 +448,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) }if (!s->mainclk_frq) { -error_setg (errp,"MAINCLK property was not set" ); +error_setg (errp,"MAINCLK_FRQ property was not set" );return ; }hw/arm/mps2-tz.c +1
-1@@ -402,7 +402,7 @@ static void mps2tz_common_init(MachineState *machine)object_property_set_link (OBJECT (&mms->iotkit),"memory" ,OBJECT (system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ ); -qdev_prop_set_uint32 (iotkitdev,"MAINCLK" ,SYSCLK_FRQ ); +qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ );sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);/* hw/arm/musca.c +1
-1@@ -375,7 +375,7 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"EXP_NUMIRQ" , mmc->num_irqs);qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width); -qdev_prop_set_uint32 (ssedev,"MAINCLK" ,SYSCLK_FRQ ); +qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ );/* * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0. Signature · 1 line
2.20.1
PATCH 11/25 hw/arm/armsse: Wire up clocks
In reply to Peter MaydellCreate two input clocks on the ARMSSE devices, one for the normal MAINCLK, and one for the 32KHz S32KCLK, and wire these up to the appropriate devices. The old property-based clock frequency setting will remain in place until conversion is complete.
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
--- include/hw/arm/armsse.h | 6 ++++++ hw/arm/armsse.c | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
include/hw/arm/armsse.h +6 -0
@@ -37,6 +37,8 @@* per-CPU identity and control register blocks * * QEMU interface: +* + Clock input "MAINCLK": clock for CPUs and most peripherals +* + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. * + QOM property "MAINCLK_FRQ" is the frequency of the main system clock
@@ -103,6 +105,7 @@#include "hw/misc/armsse-mhu.h" #include "hw/misc/unimp.h" #include "hw/or-irq.h" +#include "hw/clock.h" #include "hw/core/split-irq.h" #include "hw/cpu/cluster.h" #include "qom/object.h"
@@ -209,6 +212,9 @@ struct ARMSSE {uint32_t nsccfg; +Clock *mainclk; +Clock *s32kclk; +/* Properties */ MemoryRegion *board_memory;uint32_t exp_numirq;
hw/arm/armsse.c +15 -2
@@ -21,6 +21,7 @@#include "hw/arm/armsse.h" #include "hw/arm/boot.h" #include "hw/irq.h" +#include "hw/qdev-clock.h" /* Format of the System Information block SYS_CONFIG register */ typedef enum SysConfigFormat {
@@ -241,6 +242,9 @@ static void armsse_init(Object *obj)assert (info->sram_banks <=MAX_SRAM_BANKS );assert (info->num_cpus <=SSE_MAX_CPUS ); + s->mainclk =qdev_init_clock_in (DEVICE (s),"MAINCLK" ,NULL ,NULL ); + s->s32kclk =qdev_init_clock_in (DEVICE (s),"S32KCLK" ,NULL ,NULL ); +memory_region_init (&s->container, obj,"armsse-container" ,UINT64_MAX );for (i =0 ; i < info->num_cpus; i++) {
@@ -711,6 +715,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)* map its upstream ends to the right place in the container. */ qdev_prop_set_uint32 (DEVICE (&s->timer0),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->timer0),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer0), errp)) {return ; }
@@ -721,6 +726,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) &error_abort);qdev_prop_set_uint32 (DEVICE (&s->timer1),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->timer1),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer1), errp)) {return ; }
@@ -731,6 +737,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) &error_abort);qdev_prop_set_uint32 (DEVICE (&s->dualtimer),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->dualtimer),"TIMCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->dualtimer), errp)) {return ; }
@@ -889,6 +896,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)* 0x4002f000: S32K timer */ qdev_prop_set_uint32 (DEVICE (&s->s32ktimer),"pclk-frq" ,S32KCLK ); +qdev_connect_clock_in (DEVICE (&s->s32ktimer),"pclk" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32ktimer), errp)) {return ; }
@@ -982,6 +990,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0));qdev_prop_set_uint32 (DEVICE (&s->s32kwatchdog),"wdogclk-frq" ,S32KCLK ); +qdev_connect_clock_in (DEVICE (&s->s32kwatchdog),"WDOGCLK" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32kwatchdog), errp)) {return ; }
@@ -992,6 +1001,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ qdev_prop_set_uint32 (DEVICE (&s->nswatchdog),"wdogclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->nswatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->nswatchdog), errp)) {return ; }
@@ -1000,6 +1010,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->nswatchdog),0 ,0x40081000 );qdev_prop_set_uint32 (DEVICE (&s->swatchdog),"wdogclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->swatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->swatchdog), errp)) {return ; }
@@ -1127,9 +1138,11 @@ static void armsse_idau_check(IDAUInterface *ii, uint32_t address,static const VMStateDescription armsse_vmstate = { .name ="iotkit" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (mainclk,ARMSSE ), +VMSTATE_CLOCK (s32kclk,ARMSSE ),VMSTATE_UINT32 (nsccfg,ARMSSE ),VMSTATE_END_OF_LIST () }
Signature · 1 line
2.20.1
Re: [PATCH 11/25] hw/arm/armsse: Wire up clocks
Quoted 5 lines · Peter Maydell
Create two input clocks on the ARMSSE devices, one for the normal MAINCLK, and one for the 32KHz S32KCLK, and wire these up to the appropriate devices. The old property-based clock frequency setting will remain in place until conversion is complete.
Quoted 8 lines
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
Signed-off-by Peter Maydell <[email protected]>--- include/hw/arm/armsse.h | 6 ++++++ hw/arm/armsse.c | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
Re: [PATCH 11/25] hw/arm/armsse: Wire up clocks
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
Create two input clocks on the ARMSSE devices, one for the normal MAINCLK, and one for the 32KHz S32KCLK, and wire these up to the appropriate devices. The old property-based clock frequency setting will remain in place until conversion is complete.
This is a migration compatibility break for machines mps2-an505, mps2-an521, musca-a, musca-b1.
Signed-off-by Peter Maydell <[email protected]>
Quoted 131 lines
--- include/hw/arm/armsse.h | 6 ++++++ hw/arm/armsse.c | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)include/hw/arm/armsse.h +6
-0@@ -37,6 +37,8 @@* per-CPU identity and control register blocks * * QEMU interface: +* + Clock input "MAINCLK": clock for CPUs and most peripherals +* + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. * + QOM property "MAINCLK_FRQ" is the frequency of the main system clock @@ -103,6 +105,7 @@#include "hw/misc/armsse-mhu.h" #include "hw/misc/unimp.h" #include "hw/or-irq.h" +#include "hw/clock.h" #include "hw/core/split-irq.h" #include "hw/cpu/cluster.h" #include "qom/object.h" @@ -209,6 +212,9 @@ struct ARMSSE {uint32_t nsccfg; +Clock *mainclk; +Clock *s32kclk; +/* Properties */ MemoryRegion *board_memory;uint32_t exp_numirq;hw/arm/armsse.c +15
-2@@ -21,6 +21,7 @@#include "hw/arm/armsse.h" #include "hw/arm/boot.h" #include "hw/irq.h" +#include "hw/qdev-clock.h" /* Format of the System Information block SYS_CONFIG register */ typedef enum SysConfigFormat {@@ -241,6 +242,9 @@ static void armsse_init(Object *obj)assert (info->sram_banks <=MAX_SRAM_BANKS );assert (info->num_cpus <=SSE_MAX_CPUS ); + s->mainclk =qdev_init_clock_in (DEVICE (s),"MAINCLK" ,NULL ,NULL ); + s->s32kclk =qdev_init_clock_in (DEVICE (s),"S32KCLK" ,NULL ,NULL ); +memory_region_init (&s->container, obj,"armsse-container" ,UINT64_MAX );for (i =0 ; i < info->num_cpus; i++) {@@ -711,6 +715,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)* map its upstream ends to the right place in the container. */ qdev_prop_set_uint32 (DEVICE (&s->timer0),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->timer0),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer0), errp)) {return ; }@@ -721,6 +726,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) &error_abort);qdev_prop_set_uint32 (DEVICE (&s->timer1),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->timer1),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer1), errp)) {return ; }@@ -731,6 +737,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) &error_abort);qdev_prop_set_uint32 (DEVICE (&s->dualtimer),"pclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->dualtimer),"TIMCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->dualtimer), errp)) {return ; }@@ -889,6 +896,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)* 0x4002f000: S32K timer */ qdev_prop_set_uint32 (DEVICE (&s->s32ktimer),"pclk-frq" ,S32KCLK ); +qdev_connect_clock_in (DEVICE (&s->s32ktimer),"pclk" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32ktimer), errp)) {return ; }@@ -982,6 +990,7 @@ static void armsse_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0));qdev_prop_set_uint32 (DEVICE (&s->s32kwatchdog),"wdogclk-frq" ,S32KCLK ); +qdev_connect_clock_in (DEVICE (&s->s32kwatchdog),"WDOGCLK" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32kwatchdog), errp)) {return ; }@@ -992,6 +1001,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ qdev_prop_set_uint32 (DEVICE (&s->nswatchdog),"wdogclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->nswatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->nswatchdog), errp)) {return ; }@@ -1000,6 +1010,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->nswatchdog),0 ,0x40081000 );qdev_prop_set_uint32 (DEVICE (&s->swatchdog),"wdogclk-frq" , s->mainclk_frq); +qdev_connect_clock_in (DEVICE (&s->swatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->swatchdog), errp)) {return ; }@@ -1127,9 +1138,11 @@ static void armsse_idau_check(IDAUInterface *ii, uint32_t address,static const VMStateDescription armsse_vmstate = { .name ="iotkit" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { +VMSTATE_CLOCK (mainclk,ARMSSE ), +VMSTATE_CLOCK (s32kclk,ARMSSE ),VMSTATE_UINT32 (nsccfg,ARMSSE ),VMSTATE_END_OF_LIST () }Signature · 1 line
2.20.1
PATCH 12/25 hw/arm/mps2: Inline CMSDK_APB_TIMER creation
In reply to Peter MaydellThe old-style convenience function cmsdk_apb_timer_create() for creating CMSDK_APB_TIMER objects is used in only two places in mps2.c. Most of the rest of the code in that file uses the new "initialize in place" coding style.
We want to connect up a Clock object which should be done between the object creation and realization; rather than adding a Clock* argument to the convenience function, convert the timer creation code in mps2.c to the same style as is used already for the watchdog, dualtimer and other devices, and delete the now-unused convenience function.
--- include/hw/timer/cmsdk-apb-timer.h | 21 --------------------- hw/arm/mps2.c | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 23 deletions(-)
include/hw/timer/cmsdk-apb-timer.h +0 -21
@@ -45,25 +45,4 @@ struct CMSDKAPBTimer { uint32_t intstatus; }; -/** -* cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER -* @addr: location in system memory to map registers -* @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) -*/ -static inline DeviceState *cmsdk_apb_timer_create (hwaddr addr, -qemu_irq timerint, -uint32_t pclk_frq) -{ -DeviceState *dev; -SysBusDevice *s; - - dev =qdev_new (TYPE_CMSDK_APB_TIMER ); - s =SYS_BUS_DEVICE (dev); -qdev_prop_set_uint32 (dev,"pclk-frq" , pclk_frq); -sysbus_realize_and_unref (s, &error_fatal); -sysbus_mmio_map (s,0 , addr); -sysbus_connect_irq (s,0 , timerint); -return dev; -} -#endif
hw/arm/mps2.c +16 -2
@@ -83,6 +83,7 @@ struct MPS2MachineState {/* CMSDK APB subsystem */ CMSDKAPBDualTimer dualtimer;CMSDKAPBWatchdog watchdog; +CMSDKAPBTimer timer[2 ]; };#define TYPE_MPS2_MACHINE "mps2"
@@ -330,8 +331,21 @@ static void mps2_common_init(MachineState *machine) }/* CMSDK APB subsystem */ -cmsdk_apb_timer_create (0x40000000 ,qdev_get_gpio_in (armv7m,8 ),SYSCLK_FRQ ); -cmsdk_apb_timer_create (0x40001000 ,qdev_get_gpio_in (armv7m,9 ),SYSCLK_FRQ ); +for (i =0 ; i <ARRAY_SIZE (mms->timer); i++) { + g_autofree char *name = g_strdup_printf("timer%d", i); +hwaddr base =0x40000000 + i *0x1000 ; +int irqno =8 + i; +SysBusDevice *sbd; + +object_initialize_child (OBJECT (mms), name, &mms->timer[i], +TYPE_CMSDK_APB_TIMER ); + sbd =SYS_BUS_DEVICE (&mms->timer[i]); +qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ ); +sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_mmio_map (sbd,0 , base); +sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (armv7m, irqno)); + } +object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER );qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ );
Signature · 1 line
2.20.1
Re: [PATCH 12/25] hw/arm/mps2: Inline CMSDK_APB_TIMER creation
Quoted 12 lines · Peter Maydell
The old-style convenience function
cmsdk_apb_timer_create()for creatingCMSDK_APB_TIMERobjects is used in only two places inmps2.c. Most of the rest of the code in that file uses the new "initialize in place" coding style.We want to connect up a Clock object which should be done between the object creation and realization; rather than adding a Clock* argument to the convenience function, convert the timer creation code in
mps2.cto the same style as is used already for the watchdog, dualtimer and other devices, and delete the now-unused convenience function.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- include/hw/timer/cmsdk-apb-timer.h | 21 --------------------- hw/arm/mps2.c | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 23 deletions(-)
Re: [PATCH 12/25] hw/arm/mps2: Inline CMSDK_APB_TIMER creation
In reply to Peter MaydellQuoted 5 lines · Peter Maydell
The old-style convenience function
cmsdk_apb_timer_create()for creatingCMSDK_APB_TIMERobjects is used in only two places inmps2.c. Most of the rest of the code in that file uses the new "initialize in place" coding style.
Quoted 8 lines
We want to connect up a Clock object which should be done between the object creation and realization; rather than adding a Clock* argument to the convenience function, convert the timer creation code in
mps2.cto the same style as is used already for the watchdog, dualtimer and other devices, and delete the now-unused convenience function.Signed-off-by Peter Maydell <[email protected]>
Quoted 74 lines
--- include/hw/timer/cmsdk-apb-timer.h | 21 --------------------- hw/arm/mps2.c | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 23 deletions(-)include/hw/timer/cmsdk-apb-timer.h +0
-21@@ -45,25 +45,4 @@ struct CMSDKAPBTimer { uint32_t intstatus; }; -/** -* cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER -* @addr: location in system memory to map registers -* @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) -*/ -static inline DeviceState *cmsdk_apb_timer_create (hwaddr addr, -qemu_irq timerint, -uint32_t pclk_frq) -{ -DeviceState *dev; -SysBusDevice *s; - - dev =qdev_new (TYPE_CMSDK_APB_TIMER ); - s =SYS_BUS_DEVICE (dev); -qdev_prop_set_uint32 (dev,"pclk-frq" , pclk_frq); -sysbus_realize_and_unref (s, &error_fatal); -sysbus_mmio_map (s,0 , addr); -sysbus_connect_irq (s,0 , timerint); -return dev; -} -#endif hw/arm/mps2.c +16
-2@@ -83,6 +83,7 @@ struct MPS2MachineState {/* CMSDK APB subsystem */ CMSDKAPBDualTimer dualtimer;CMSDKAPBWatchdog watchdog; +CMSDKAPBTimer timer[2 ]; };#define TYPE_MPS2_MACHINE "mps2"@@ -330,8 +331,21 @@ static void mps2_common_init(MachineState *machine) }/* CMSDK APB subsystem */ -cmsdk_apb_timer_create (0x40000000 ,qdev_get_gpio_in (armv7m,8 ),SYSCLK_FRQ ); -cmsdk_apb_timer_create (0x40001000 ,qdev_get_gpio_in (armv7m,9 ),SYSCLK_FRQ ); +for (i =0 ; i <ARRAY_SIZE (mms->timer); i++) { + g_autofree char *name = g_strdup_printf("timer%d", i); +hwaddr base =0x40000000 + i *0x1000 ; +int irqno =8 + i; +SysBusDevice *sbd; + +object_initialize_child (OBJECT (mms), name, &mms->timer[i], +TYPE_CMSDK_APB_TIMER ); + sbd =SYS_BUS_DEVICE (&mms->timer[i]); +qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ ); +sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_mmio_map (sbd,0 , base); +sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (armv7m, irqno)); + } +object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER );qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ );Signature · 1 line
2.20.1
PATCH 13/25 hw/arm/mps2: Create and connect SYSCLK Clock
In reply to Peter MaydellCreate a fixed-frequency Clock object to be the SYSCLK, and wire it up to the devices that require it.
--- hw/arm/mps2.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/arm/mps2.c +9 -0
@@ -46,6 +46,7 @@#include "hw/net/lan9118.h" #include "net/net.h" #include "hw/watchdog/cmsdk-apb-watchdog.h" +#include "hw/qdev-clock.h" #include "qom/object.h" typedef enum MPS2FPGAType {
@@ -84,6 +85,7 @@ struct MPS2MachineState {CMSDKAPBDualTimer dualtimer;CMSDKAPBWatchdog watchdog;CMSDKAPBTimer timer[2 ]; +Clock *sysclk; };#define TYPE_MPS2_MACHINE "mps2"
@@ -140,6 +142,10 @@ static void mps2_common_init(MachineState *machine)exit (EXIT_FAILURE ); } +/* This clock doesn't need migration because it is fixed-frequency */ + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); +/* The FPGA images have an odd combination of different RAMs, * because in hardware they are different implementations and * connected to different buses, giving varying performance/size
@@ -341,6 +347,7 @@ static void mps2_common_init(MachineState *machine) TYPE_CMSDK_APB_TIMER); sbd =SYS_BUS_DEVICE (&mms->timer[i]);qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->timer[i]),"pclk" , mms->sysclk);sysbus_realize_and_unref (sbd, &error_fatal);sysbus_mmio_map (sbd,0 , base);sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (armv7m, irqno));
@@ -349,6 +356,7 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER );qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->dualtimer),"TIMCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->dualtimer), &error_fatal);sysbus_connect_irq (SYS_BUS_DEVICE (&mms->dualtimer),0 ,qdev_get_gpio_in (armv7m,10 ));
@@ -356,6 +364,7 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"watchdog" , &mms->watchdog,TYPE_CMSDK_APB_WATCHDOG );qdev_prop_set_uint32 (DEVICE (&mms->watchdog),"wdogclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->watchdog),"WDOGCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->watchdog), &error_fatal);sysbus_connect_irq (SYS_BUS_DEVICE (&mms->watchdog),0 ,qdev_get_gpio_in_named (armv7m,"NMI" ,0 ));
Signature · 1 line
2.20.1
Re: [PATCH 13/25] hw/arm/mps2: Create and connect SYSCLK Clock
Quoted 7 lines · Peter Maydell
Create a fixed-frequency Clock object to be the SYSCLK, and wire it up to the devices that require it.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/mps2.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Re: [PATCH 13/25] hw/arm/mps2: Create and connect SYSCLK Clock
In reply to Peter MaydellQuoted 4 lines · Peter Maydell
Create a fixed-frequency Clock object to be the SYSCLK, and wire it up to the devices that require it.
Signed-off-by Peter Maydell <[email protected]>
Quoted 62 lines
--- hw/arm/mps2.c | 9 +++++++++ 1 file changed, 9 insertions(+)hw/arm/mps2.c +9
-0@@ -46,6 +46,7 @@#include "hw/net/lan9118.h" #include "net/net.h" #include "hw/watchdog/cmsdk-apb-watchdog.h" +#include "hw/qdev-clock.h" #include "qom/object.h" typedef enum MPS2FPGAType {@@ -84,6 +85,7 @@ struct MPS2MachineState {CMSDKAPBDualTimer dualtimer;CMSDKAPBWatchdog watchdog;CMSDKAPBTimer timer[2 ]; +Clock *sysclk; };#define TYPE_MPS2_MACHINE "mps2"@@ -140,6 +142,10 @@ static void mps2_common_init(MachineState *machine)exit (EXIT_FAILURE ); } +/* This clock doesn't need migration because it is fixed-frequency */ + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); +/* The FPGA images have an odd combination of different RAMs, * because in hardware they are different implementations and * connected to different buses, giving varying performance/size @@ -341,6 +347,7 @@ static void mps2_common_init(MachineState *machine) TYPE_CMSDK_APB_TIMER); sbd =SYS_BUS_DEVICE (&mms->timer[i]);qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->timer[i]),"pclk" , mms->sysclk);sysbus_realize_and_unref (sbd, &error_fatal);sysbus_mmio_map (sbd,0 , base);sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (armv7m, irqno));@@ -349,6 +356,7 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER );qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->dualtimer),"TIMCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->dualtimer), &error_fatal);sysbus_connect_irq (SYS_BUS_DEVICE (&mms->dualtimer),0 ,qdev_get_gpio_in (armv7m,10 ));@@ -356,6 +364,7 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"watchdog" , &mms->watchdog,TYPE_CMSDK_APB_WATCHDOG );qdev_prop_set_uint32 (DEVICE (&mms->watchdog),"wdogclk-frq" ,SYSCLK_FRQ ); +qdev_connect_clock_in (DEVICE (&mms->watchdog),"WDOGCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->watchdog), &error_fatal);sysbus_connect_irq (SYS_BUS_DEVICE (&mms->watchdog),0 ,qdev_get_gpio_in_named (armv7m,"NMI" ,0 ));Signature · 1 line
2.20.1
PATCH 14/25 hw/arm/mps2-tz: Create and connect ARMSSE Clocks
In reply to Peter MaydellCreate and connect the two clocks needed by the ARMSSE.
--- hw/arm/mps2-tz.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/arm/mps2-tz.c +13 -0
@@ -62,6 +62,7 @@#include "hw/net/lan9118.h" #include "net/net.h" #include "hw/core/split-irq.h" +#include "hw/qdev-clock.h" #include "qom/object.h" #define MPS2TZ_NUMIRQ 92
@@ -100,6 +101,8 @@ struct MPS2TZMachineState {qemu_or_irq uart_irq_orgate;DeviceState *lan9118;SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ ]; +Clock *sysclk; +Clock *s32kclk; };#define TYPE_MPS2TZ_MACHINE "mps2tz"
@@ -110,6 +113,8 @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)/* Main SYSCLK frequency in Hz */ #define SYSCLK_FRQ 20000000 +/* Slow 32Khz S32KCLK frequency in Hz */ +#define S32KCLK_FRQ (32 * 1000)/* Create an alias of an entire original MemoryRegion @orig * located at @base in the memory map.
@@ -396,6 +401,12 @@ static void mps2tz_common_init(MachineState *machine)exit (EXIT_FAILURE ); } +/* These clocks don't need migration because they are fixed-frequency */ + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); + mms->s32kclk =clock_new (OBJECT (machine),"S32KCLK" ); +clock_set_hz (mms->s32kclk,S32KCLK_FRQ ); +object_initialize_child (OBJECT (machine),TYPE_IOTKIT , &mms->iotkit, mmc->armsse_type); iotkitdev =DEVICE (&mms->iotkit);
@@ -403,6 +414,8 @@ static void mps2tz_common_init(MachineState *machine) OBJECT(system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ );qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ ); +qdev_connect_clock_in (iotkitdev,"MAINCLK" , mms->sysclk); +qdev_connect_clock_in (iotkitdev,"S32KCLK" , mms->s32kclk);sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);/*
Signature · 1 line
2.20.1
Re: [PATCH 14/25] hw/arm/mps2-tz: Create and connect ARMSSE Clocks
Quoted 6 lines · Peter Maydell
Create and connect the two clocks needed by the ARMSSE.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/mps2-tz.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Re: [PATCH 14/25] hw/arm/mps2-tz: Create and connect ARMSSE Clocks
In reply to Peter MaydellQuoted 3 lines · Peter Maydell
Create and connect the two clocks needed by the ARMSSE.
Signed-off-by Peter Maydell <[email protected]>
Quoted 59 lines
--- hw/arm/mps2-tz.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/arm/mps2-tz.c +13
-0@@ -62,6 +62,7 @@#include "hw/net/lan9118.h" #include "net/net.h" #include "hw/core/split-irq.h" +#include "hw/qdev-clock.h" #include "qom/object.h" #define MPS2TZ_NUMIRQ 92@@ -100,6 +101,8 @@ struct MPS2TZMachineState {qemu_or_irq uart_irq_orgate;DeviceState *lan9118;SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ ]; +Clock *sysclk; +Clock *s32kclk; };#define TYPE_MPS2TZ_MACHINE "mps2tz"@@ -110,6 +113,8 @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)/* Main SYSCLK frequency in Hz */ #define SYSCLK_FRQ 20000000 +/* Slow 32Khz S32KCLK frequency in Hz */ +#define S32KCLK_FRQ (32 * 1000)/* Create an alias of an entire original MemoryRegion @orig * located at @base in the memory map. @@ -396,6 +401,12 @@ static void mps2tz_common_init(MachineState *machine)exit (EXIT_FAILURE ); } +/* These clocks don't need migration because they are fixed-frequency */ + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); + mms->s32kclk =clock_new (OBJECT (machine),"S32KCLK" ); +clock_set_hz (mms->s32kclk,S32KCLK_FRQ ); +object_initialize_child (OBJECT (machine),TYPE_IOTKIT , &mms->iotkit, mmc->armsse_type); iotkitdev =DEVICE (&mms->iotkit);@@ -403,6 +414,8 @@ static void mps2tz_common_init(MachineState *machine) OBJECT(system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ );qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ ); +qdev_connect_clock_in (iotkitdev,"MAINCLK" , mms->sysclk); +qdev_connect_clock_in (iotkitdev,"S32KCLK" , mms->s32kclk);sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);/* Signature · 1 line
2.20.1
PATCH 15/25 hw/arm/musca: Create and connect ARMSSE Clocks
In reply to Peter MaydellCreate and connect the two clocks needed by the ARMSSE.
--- hw/arm/musca.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/arm/musca.c +12 -0
@@ -33,6 +33,7 @@#include "hw/misc/tz-ppc.h" #include "hw/misc/unimp.h" #include "hw/rtc/pl031.h" +#include "hw/qdev-clock.h" #include "qom/object.h" #define MUSCA_NUMIRQ_MAX 96
@@ -82,6 +83,8 @@ struct MuscaMachineState {UnimplementedDeviceState sdio;UnimplementedDeviceState gpio;UnimplementedDeviceState cryptoisland; +Clock *sysclk; +Clock *s32kclk; };#define TYPE_MUSCA_MACHINE "musca"
@@ -96,6 +99,8 @@ OBJECT_DECLARE_TYPE(MuscaMachineState, MuscaMachineClass, MUSCA_MACHINE)* don't model that in our SSE-200 model yet. */ #define SYSCLK_FRQ 40000000 +/* Slow 32Khz S32KCLK frequency in Hz */ +#define S32KCLK_FRQ (32 * 1000)static qemu_irq get_sse_irq_in (MuscaMachineState *mms,int irqno) {
@@ -367,6 +372,11 @@ static void musca_init(MachineState *machine)exit (1 ); } + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); + mms->s32kclk =clock_new (OBJECT (machine),"S32KCLK" ); +clock_set_hz (mms->s32kclk,S32KCLK_FRQ ); +object_initialize_child (OBJECT (machine),"sse-200" , &mms->sse,TYPE_SSE200 ); ssedev =DEVICE (&mms->sse);
@@ -376,6 +386,8 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width);qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ ); +qdev_connect_clock_in (ssedev,"MAINCLK" , mms->sysclk); +qdev_connect_clock_in (ssedev,"S32KCLK" , mms->s32kclk);/* * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0.
Signature · 1 line
2.20.1
Re: [PATCH 15/25] hw/arm/musca: Create and connect ARMSSE Clocks
Quoted 6 lines · Peter Maydell
Create and connect the two clocks needed by the ARMSSE.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/musca.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Re: [PATCH 15/25] hw/arm/musca: Create and connect ARMSSE Clocks
In reply to Peter MaydellQuoted 3 lines · Peter Maydell
Create and connect the two clocks needed by the ARMSSE.
Signed-off-by Peter Maydell <[email protected]>
Quoted 58 lines
--- hw/arm/musca.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)hw/arm/musca.c +12
-0@@ -33,6 +33,7 @@#include "hw/misc/tz-ppc.h" #include "hw/misc/unimp.h" #include "hw/rtc/pl031.h" +#include "hw/qdev-clock.h" #include "qom/object.h" #define MUSCA_NUMIRQ_MAX 96@@ -82,6 +83,8 @@ struct MuscaMachineState {UnimplementedDeviceState sdio;UnimplementedDeviceState gpio;UnimplementedDeviceState cryptoisland; +Clock *sysclk; +Clock *s32kclk; };#define TYPE_MUSCA_MACHINE "musca"@@ -96,6 +99,8 @@ OBJECT_DECLARE_TYPE(MuscaMachineState, MuscaMachineClass, MUSCA_MACHINE)* don't model that in our SSE-200 model yet. */ #define SYSCLK_FRQ 40000000 +/* Slow 32Khz S32KCLK frequency in Hz */ +#define S32KCLK_FRQ (32 * 1000)static qemu_irq get_sse_irq_in (MuscaMachineState *mms,int irqno) {@@ -367,6 +372,11 @@ static void musca_init(MachineState *machine)exit (1 ); } + mms->sysclk =clock_new (OBJECT (machine),"SYSCLK" ); +clock_set_hz (mms->sysclk,SYSCLK_FRQ ); + mms->s32kclk =clock_new (OBJECT (machine),"S32KCLK" ); +clock_set_hz (mms->s32kclk,S32KCLK_FRQ ); +object_initialize_child (OBJECT (machine),"sse-200" , &mms->sse,TYPE_SSE200 ); ssedev =DEVICE (&mms->sse);@@ -376,6 +386,8 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width);qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ ); +qdev_connect_clock_in (ssedev,"MAINCLK" , mms->sysclk); +qdev_connect_clock_in (ssedev,"S32KCLK" , mms->s32kclk);/* * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0. Signature · 1 line
2.20.1
PATCH 16/25 hw/arm/stellaris: Convert SSYS to QOM device
In reply to Peter MaydellConvert the SSYS code in the Stellaris boards (which encapsulates the system registers) to a proper QOM device. This will provide us with somewhere to put the output Clock whose frequency depends on the setting of the PLL configuration registers.
This is a migration compatibility break for lm3s811evb, lm3s6965evb.
We use 3-phase reset here because the Clock will need to propagate its value in the hold phase.
For the moment we reset the device during the board creation so that the system_clock_scale global gets set; this will be removed in a subsequent commit.
--- hw/arm/stellaris.c | 132 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 25 deletions(-)
hw/arm/stellaris.c +107 -25
@@ -357,7 +357,12 @@ static void stellaris_gptm_realize(DeviceState *dev, Error **errp)/* System controller. */ -typedef struct { +#define TYPE_STELLARIS_SYS "stellaris-sys" +OBJECT_DECLARE_SIMPLE_TYPE(ssys_state, STELLARIS_SYS) + +struct ssys_state { +SysBusDevice parent_obj; +MemoryRegion iomem;uint32_t pborctl;uint32_t ldopctl;
@@ -371,11 +376,18 @@ typedef struct {uint32_t dcgc[3 ];uint32_t clkvclr;uint32_t ldoarst; +qemu_irq irq; +/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1; -qemu_irq irq; -stellaris_board_info *board; -} ssys_state; +uint32_t did0; +uint32_t did1; +uint32_t dc0; +uint32_t dc1; +uint32_t dc2; +uint32_t dc3; +uint32_t dc4; +};static void ssys_update (ssys_state *s) {
@@ -430,7 +442,7 @@ static uint32_t pllcfg_fury[16] = {static int ssys_board_class (const ssys_state *s) { -uint32_t did0 = s->board->did0; +uint32_t did0 = s->did0;switch (did0 &DID0_VER_MASK ) {case DID0_VER_0 :return DID0_CLASS_SANDSTORM ;
@@ -456,19 +468,19 @@ static uint64_t ssys_read(void *opaque, hwaddr offset,switch (offset) {case 0x000 :/* DID0 */ -return s->board->did0; +return s->did0;case 0x004 :/* DID1 */ -return s->board->did1; +return s->did1;case 0x008 :/* DC0 */ -return s->board->dc0; +return s->dc0;case 0x010 :/* DC1 */ -return s->board->dc1; +return s->dc1;case 0x014 :/* DC2 */ -return s->board->dc2; +return s->dc2;case 0x018 :/* DC3 */ -return s->board->dc3; +return s->dc3;case 0x01c :/* DC4 */ -return s->board->dc4; +return s->dc4;case 0x030 :/* PBORCTL */ return s->pborctl;case 0x034 :/* LDOPCTL */
@@ -646,9 +658,9 @@ static const MemoryRegionOps ssys_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void ssys_reset (void *opaque) +static void stellaris_sys_reset_enter (Object *obj,ResetType type) { -ssys_state *s = (ssys_state *)opaque; +ssys_state *s =STELLARIS_SYS (obj); s->pborctl =0x7ffd ; s->rcc =0x078e3ac0 ;
@@ -661,9 +673,19 @@ static void ssys_reset(void *opaque) s->rcgc[0 ] =1 ; s->scgc[0 ] =1 ; s->dcgc[0 ] =1 ; +} + +static void stellaris_sys_reset_hold (Object *obj) +{ +ssys_state *s =STELLARIS_SYS (obj); +ssys_calculate_system_clock (s); } +static void stellaris_sys_reset_exit (Object *obj) +{ +} +static int stellaris_sys_post_load (void *opaque,int version_id) {ssys_state *s = opaque;
@@ -695,27 +717,66 @@ static const VMStateDescription vmstate_stellaris_sys = { } }; +static Property stellaris_sys_properties[] = { +DEFINE_PROP_UINT32 ("user0" , ssys_state, user0,0 ), +DEFINE_PROP_UINT32 ("user1" , ssys_state, user1,0 ), +DEFINE_PROP_UINT32 ("did0" , ssys_state, did0,0 ), +DEFINE_PROP_UINT32 ("did1" , ssys_state, did1,0 ), +DEFINE_PROP_UINT32 ("dc0" , ssys_state, dc0,0 ), +DEFINE_PROP_UINT32 ("dc1" , ssys_state, dc1,0 ), +DEFINE_PROP_UINT32 ("dc2" , ssys_state, dc2,0 ), +DEFINE_PROP_UINT32 ("dc3" , ssys_state, dc3,0 ), +DEFINE_PROP_UINT32 ("dc4" , ssys_state, dc4,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void stellaris_sys_instance_init (Object *obj) +{ +ssys_state *s =STELLARIS_SYS (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (s); + +memory_region_init_io (&s->iomem, obj, &ssys_ops, s,"ssys" ,0x00001000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); +} +static int stellaris_sys_init (uint32_t base,qemu_irq irq,stellaris_board_info * board,uint8_t *macaddr) { -ssys_state *s; +DeviceState *dev =qdev_new (TYPE_STELLARIS_SYS ); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); - s =g_new0 (ssys_state,1 ); - s->irq = irq; - s->board = board;/* Most devices come preprogrammed with a MAC address in the user data. */ - s->user0 = macaddr[0 ] | (macaddr[1 ] <<8 ) | (macaddr[2 ] <<16 ); - s->user1 = macaddr[3 ] | (macaddr[4 ] <<8 ) | (macaddr[5 ] <<16 ); +qdev_prop_set_uint32 (dev,"user0" , + macaddr[0 ] | (macaddr[1 ] <<8 ) | (macaddr[2 ] <<16 )); +qdev_prop_set_uint32 (dev,"user1" , + macaddr[3 ] | (macaddr[4 ] <<8 ) | (macaddr[5 ] <<16 )); +qdev_prop_set_uint32 (dev,"did0" , board->did0); +qdev_prop_set_uint32 (dev,"did1" , board->did1); +qdev_prop_set_uint32 (dev,"dc0" , board->dc0); +qdev_prop_set_uint32 (dev,"dc1" , board->dc1); +qdev_prop_set_uint32 (dev,"dc2" , board->dc2); +qdev_prop_set_uint32 (dev,"dc3" , board->dc3); +qdev_prop_set_uint32 (dev,"dc4" , board->dc4); + +sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_mmio_map (sbd,0 , base); +sysbus_connect_irq (sbd,0 , irq); + +/* +* Normally we should not be resetting devices like this during +* board creation. For the moment we need to do so, because +* system_clock_scale will only get set when the STELLARIS_SYS +* device is reset, and we need its initial value to pass to +* the watchdog device. This hack can be removed once the +* watchdog has been converted to use a Clock input instead. +*/ +device_cold_reset (dev); -memory_region_init_io (&s->iomem,NULL , &ssys_ops, s,"ssys" ,0x00001000 ); -memory_region_add_subregion (get_system_memory (), base, &s->iomem); -ssys_reset (s); -vmstate_register (NULL ,VMSTATE_INSTANCE_ID_ANY , &vmstate_stellaris_sys, s);return 0 ; } -/* I2C controller. */ #define TYPE_STELLARIS_I2C "stellaris-i2c"
@@ -1553,11 +1614,32 @@ static const TypeInfo stellaris_adc_info = { .class_init = stellaris_adc_class_init, }; +static void stellaris_sys_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); + + dc->vmsd = &vmstate_stellaris_sys; + rc->phases.enter = stellaris_sys_reset_enter; + rc->phases.hold = stellaris_sys_reset_hold; + rc->phases.exit = stellaris_sys_reset_exit; +device_class_set_props (dc, stellaris_sys_properties); +} + +static const TypeInfo stellaris_sys_info = { + .name =TYPE_STELLARIS_SYS , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (ssys_state), + .instance_init = stellaris_sys_instance_init, + .class_init = stellaris_sys_class_init, +}; +static void stellaris_register_types (void ) {type_register_static (&stellaris_i2c_info);type_register_static (&stellaris_gptm_info);type_register_static (&stellaris_adc_info); +type_register_static (&stellaris_sys_info); }type_init (stellaris_register_types)
Signature · 1 line
2.20.1
Re: [PATCH 16/25] hw/arm/stellaris: Convert SSYS to QOM device
Hi Peter,
Quoted 45 lines · Peter Maydell
Convert the SSYS code in the Stellaris boards (which encapsulates the system registers) to a proper QOM device. This will provide us with somewhere to put the output Clock whose frequency depends on the setting of the PLL configuration registers.
This is a migration compatibility break for lm3s811evb, lm3s6965evb.
We use 3-phase reset here because the Clock will need to propagate its value in the hold phase.
For the moment we reset the device during the board creation so that the
system_clock_scaleglobal gets set; this will be removed in a subsequent commit.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 132 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 25 deletions(-)hw/arm/stellaris.c +8
-1@@ -357,7 +357,12 @@ static void stellaris_gptm_realize(DeviceState *dev, Error **errp)/* System controller. */ -typedef struct { +#define TYPE_STELLARIS_SYS "stellaris-sys" +OBJECT_DECLARE_SIMPLE_TYPE(ssys_state, STELLARIS_SYS) + +struct ssys_state { +SysBusDevice parent_obj; +MemoryRegion iomem;uint32_t pborctl;uint32_t ldopctl;@@ -371,11 +376,18 @@ typedef struct {uint32_t dcgc[3 ];uint32_t clkvclr;uint32_t ldoarst; +qemu_irq irq; +/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1;
hw/arm/stellaris.c typedef struct { · line 389
Quoted 10 lines
hw/arm/stellaris.c +7
-3-qemu_irq irq; -stellaris_board_info *board; -} ssys_state; +uint32_t did0; +uint32_t did1; +uint32_t dc0; +uint32_t dc1; +uint32_t dc2; +uint32_t dc3; +uint32_t dc4;
Shouldn't these be class properties?
Quoted 1 line
hw/arm/stellaris.c +1
-0+};
Re: [PATCH 16/25] hw/arm/stellaris: Convert SSYS to QOM device
Quoted 37 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 33 lines · Peter Maydell
Convert the SSYS code in the Stellaris boards (which encapsulates the system registers) to a proper QOM device. This will provide us with somewhere to put the output Clock whose frequency depends on the setting of the PLL configuration registers.
This is a migration compatibility break for lm3s811evb, lm3s6965evb.
We use 3-phase reset here because the Clock will need to propagate its value in the hold phase.
For the moment we reset the device during the board creation so that the
system_clock_scaleglobal gets set; this will be removed in a subsequent commit.hw/arm/stellaris.c +7
-3+ +struct ssys_state { +SysBusDevice parent_obj; +MemoryRegion iomem;uint32_t pborctl;uint32_t ldopctl;@@ -371,11 +376,18 @@ typedef struct {uint32_t dcgc[3 ];uint32_t clkvclr;uint32_t ldoarst; +qemu_irq irq; +/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1; -qemu_irq irq; -stellaris_board_info *board; -} ssys_state; +uint32_t did0;
Quoted 8 lines
hw/arm/stellaris.c typedef struct { · line 389
Quoted 6 lines
hw/arm/stellaris.c +6
-0+uint32_t did1; +uint32_t dc0; +uint32_t dc1; +uint32_t dc2; +uint32_t dc3; +uint32_t dc4;Shouldn't these be class properties?
Could you elaborate on what you think the code ought to look like? I just used the usual thing of defining uint32 qdev properties so we can set these values when we create the device, as a replacement for the existing code which either reaches directly into the state struct to set the user0/user1 values or sets the stellaris_board_info pointer in the state struct.
thanks
-- PMM
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 16/25] hw/arm/stellaris: Convert SSYS to QOM device
Quoted 44 lines · Peter Maydell
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 33 lines · Peter Maydell
Convert the SSYS code in the Stellaris boards (which encapsulates the system registers) to a proper QOM device. This will provide us with somewhere to put the output Clock whose frequency depends on the setting of the PLL configuration registers.
This is a migration compatibility break for lm3s811evb, lm3s6965evb.
We use 3-phase reset here because the Clock will need to propagate its value in the hold phase.
For the moment we reset the device during the board creation so that the
system_clock_scaleglobal gets set; this will be removed in a subsequent commit.hw/arm/stellaris.c +7
-3+ +struct ssys_state { +SysBusDevice parent_obj; +MemoryRegion iomem;uint32_t pborctl;uint32_t ldopctl;@@ -371,11 +376,18 @@ typedef struct {uint32_t dcgc[3 ];uint32_t clkvclr;uint32_t ldoarst; +qemu_irq irq; +/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1; -qemu_irq irq; -stellaris_board_info *board; -} ssys_state; +uint32_t did0;Quoted 8 lines
hw/arm/stellaris.c typedef struct { · line 389
Quoted 6 lines
hw/arm/stellaris.c +6
-0+uint32_t did1; +uint32_t dc0; +uint32_t dc1; +uint32_t dc2; +uint32_t dc3; +uint32_t dc4;Shouldn't these be class properties?
Quoted 1 line
Could you elaborate on what you think the code ought to look like?
I am thinking something similar how Igor asked me to implement RaspiMachineClass::board_rev in hw/arm/raspi.c, as the did/dc registers are read-only. Anyhow this is 1/ probably not necessary and 2/ out of the scope of this series, this patch is already complex enough, and the work is done.
Quoted 5 lines
I just used the usual thing of defining uint32 qdev properties so we can set these values when we create the device, as a replacement for the existing code which either reaches directly into the state struct to set the user0/user1 values or sets the
stellaris_board_infopointer in the state struct.
No problem.
Re: [PATCH 16/25] hw/arm/stellaris: Convert SSYS to QOM device
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
Convert the SSYS code in the Stellaris boards (which encapsulates the system registers) to a proper QOM device. This will provide us with somewhere to put the output Clock whose frequency depends on the setting of the PLL configuration registers.
This is a migration compatibility break for lm3s811evb, lm3s6965evb.
Quoted 8 lines
We use 3-phase reset here because the Clock will need to propagate its value in the hold phase.
For the moment we reset the device during the board creation so that the
system_clock_scaleglobal gets set; this will be removed in a subsequent commit.Signed-off-by Peter Maydell <[email protected]>
Quoted 226 lines
--- hw/arm/stellaris.c | 132 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 25 deletions(-)hw/arm/stellaris.c +107
-25@@ -357,7 +357,12 @@ static void stellaris_gptm_realize(DeviceState *dev, Error **errp)/* System controller. */ -typedef struct { +#define TYPE_STELLARIS_SYS "stellaris-sys" +OBJECT_DECLARE_SIMPLE_TYPE(ssys_state, STELLARIS_SYS) + +struct ssys_state { +SysBusDevice parent_obj; +MemoryRegion iomem;uint32_t pborctl;uint32_t ldopctl;@@ -371,11 +376,18 @@ typedef struct {uint32_t dcgc[3 ];uint32_t clkvclr;uint32_t ldoarst; +qemu_irq irq; +/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1; -qemu_irq irq; -stellaris_board_info *board; -} ssys_state; +uint32_t did0; +uint32_t did1; +uint32_t dc0; +uint32_t dc1; +uint32_t dc2; +uint32_t dc3; +uint32_t dc4; +};static void ssys_update (ssys_state *s) {@@ -430,7 +442,7 @@ static uint32_t pllcfg_fury[16] = {static int ssys_board_class (const ssys_state *s) { -uint32_t did0 = s->board->did0; +uint32_t did0 = s->did0;switch (did0 &DID0_VER_MASK ) {case DID0_VER_0 :return DID0_CLASS_SANDSTORM ;@@ -456,19 +468,19 @@ static uint64_t ssys_read(void *opaque, hwaddr offset,switch (offset) {case 0x000 :/* DID0 */ -return s->board->did0; +return s->did0;case 0x004 :/* DID1 */ -return s->board->did1; +return s->did1;case 0x008 :/* DC0 */ -return s->board->dc0; +return s->dc0;case 0x010 :/* DC1 */ -return s->board->dc1; +return s->dc1;case 0x014 :/* DC2 */ -return s->board->dc2; +return s->dc2;case 0x018 :/* DC3 */ -return s->board->dc3; +return s->dc3;case 0x01c :/* DC4 */ -return s->board->dc4; +return s->dc4;case 0x030 :/* PBORCTL */ return s->pborctl;case 0x034 :/* LDOPCTL */ @@ -646,9 +658,9 @@ static const MemoryRegionOps ssys_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void ssys_reset (void *opaque) +static void stellaris_sys_reset_enter (Object *obj,ResetType type) { -ssys_state *s = (ssys_state *)opaque; +ssys_state *s =STELLARIS_SYS (obj); s->pborctl =0x7ffd ; s->rcc =0x078e3ac0 ;@@ -661,9 +673,19 @@ static void ssys_reset(void *opaque) s->rcgc[0 ] =1 ; s->scgc[0 ] =1 ; s->dcgc[0 ] =1 ; +} + +static void stellaris_sys_reset_hold (Object *obj) +{ +ssys_state *s =STELLARIS_SYS (obj); +ssys_calculate_system_clock (s); } +static void stellaris_sys_reset_exit (Object *obj) +{ +} +static int stellaris_sys_post_load (void *opaque,int version_id) {ssys_state *s = opaque;@@ -695,27 +717,66 @@ static const VMStateDescription vmstate_stellaris_sys = { } }; +static Property stellaris_sys_properties[] = { +DEFINE_PROP_UINT32 ("user0" , ssys_state, user0,0 ), +DEFINE_PROP_UINT32 ("user1" , ssys_state, user1,0 ), +DEFINE_PROP_UINT32 ("did0" , ssys_state, did0,0 ), +DEFINE_PROP_UINT32 ("did1" , ssys_state, did1,0 ), +DEFINE_PROP_UINT32 ("dc0" , ssys_state, dc0,0 ), +DEFINE_PROP_UINT32 ("dc1" , ssys_state, dc1,0 ), +DEFINE_PROP_UINT32 ("dc2" , ssys_state, dc2,0 ), +DEFINE_PROP_UINT32 ("dc3" , ssys_state, dc3,0 ), +DEFINE_PROP_UINT32 ("dc4" , ssys_state, dc4,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void stellaris_sys_instance_init (Object *obj) +{ +ssys_state *s =STELLARIS_SYS (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (s); + +memory_region_init_io (&s->iomem, obj, &ssys_ops, s,"ssys" ,0x00001000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); +} +static int stellaris_sys_init (uint32_t base,qemu_irq irq,stellaris_board_info * board,uint8_t *macaddr) { -ssys_state *s; +DeviceState *dev =qdev_new (TYPE_STELLARIS_SYS ); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); - s =g_new0 (ssys_state,1 ); - s->irq = irq; - s->board = board;/* Most devices come preprogrammed with a MAC address in the user data. */ - s->user0 = macaddr[0 ] | (macaddr[1 ] <<8 ) | (macaddr[2 ] <<16 ); - s->user1 = macaddr[3 ] | (macaddr[4 ] <<8 ) | (macaddr[5 ] <<16 ); +qdev_prop_set_uint32 (dev,"user0" , + macaddr[0 ] | (macaddr[1 ] <<8 ) | (macaddr[2 ] <<16 )); +qdev_prop_set_uint32 (dev,"user1" , + macaddr[3 ] | (macaddr[4 ] <<8 ) | (macaddr[5 ] <<16 )); +qdev_prop_set_uint32 (dev,"did0" , board->did0); +qdev_prop_set_uint32 (dev,"did1" , board->did1); +qdev_prop_set_uint32 (dev,"dc0" , board->dc0); +qdev_prop_set_uint32 (dev,"dc1" , board->dc1); +qdev_prop_set_uint32 (dev,"dc2" , board->dc2); +qdev_prop_set_uint32 (dev,"dc3" , board->dc3); +qdev_prop_set_uint32 (dev,"dc4" , board->dc4); + +sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_mmio_map (sbd,0 , base); +sysbus_connect_irq (sbd,0 , irq); + +/* +* Normally we should not be resetting devices like this during +* board creation. For the moment we need to do so, because +* system_clock_scale will only get set when the STELLARIS_SYS +* device is reset, and we need its initial value to pass to +* the watchdog device. This hack can be removed once the +* watchdog has been converted to use a Clock input instead. +*/ +device_cold_reset (dev); -memory_region_init_io (&s->iomem,NULL , &ssys_ops, s,"ssys" ,0x00001000 ); -memory_region_add_subregion (get_system_memory (), base, &s->iomem); -ssys_reset (s); -vmstate_register (NULL ,VMSTATE_INSTANCE_ID_ANY , &vmstate_stellaris_sys, s);return 0 ; } -/* I2C controller. */ #define TYPE_STELLARIS_I2C "stellaris-i2c"@@ -1553,11 +1614,32 @@ static const TypeInfo stellaris_adc_info = { .class_init = stellaris_adc_class_init, }; +static void stellaris_sys_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); + + dc->vmsd = &vmstate_stellaris_sys; + rc->phases.enter = stellaris_sys_reset_enter; + rc->phases.hold = stellaris_sys_reset_hold; + rc->phases.exit = stellaris_sys_reset_exit; +device_class_set_props (dc, stellaris_sys_properties); +} + +static const TypeInfo stellaris_sys_info = { + .name =TYPE_STELLARIS_SYS , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (ssys_state), + .instance_init = stellaris_sys_instance_init, + .class_init = stellaris_sys_class_init, +}; +static void stellaris_register_types (void ) {type_register_static (&stellaris_i2c_info);type_register_static (&stellaris_gptm_info);type_register_static (&stellaris_adc_info); +type_register_static (&stellaris_sys_info); }type_init (stellaris_register_types)Signature · 1 line
2.20.1
PATCH 17/25 hw/arm/stellaris: Create Clock input for watchdog
In reply to Peter MaydellCreate and connect the Clock input for the watchdog device on the Stellaris boards. Because the Stellaris boards model the ability to change the clock rate by programming PLL registers, we have to create an output Clock on the ssys_state device and wire it up to the watchdog.
Note that the old comment on ssys_calculate_system_clock() got the units wrong -- system_clock_scale is in nanoseconds, not milliseconds. Improve the commentary to clarify how we are calculating the period.
--- hw/arm/stellaris.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-)
hw/arm/stellaris.c +31 -12
@@ -26,6 +26,7 @@#include "hw/watchdog/cmsdk-apb-watchdog.h" #include "migration/vmstate.h" #include "hw/misc/unimp.h" +#include "hw/qdev-clock.h" #include "cpu.h" #include "qom/object.h"
@@ -377,6 +378,7 @@ struct ssys_state {uint32_t clkvclr;uint32_t ldoarst;qemu_irq irq; +Clock *sysclk;/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1;
@@ -555,15 +557,26 @@ static bool ssys_use_rcc2(ssys_state *s) }/* -* Caculate the sys. clock period in ms. +* Calculate the system clock period. We only want to propagate +* this change to the rest of the system if we're not being called +* from migration post-load. */ -static void ssys_calculate_system_clock (ssys_state *s) +static void ssys_calculate_system_clock (ssys_state *s,bool propagate_clock) { +/* +* SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input +* clock is 200MHz, which is a period of 5 ns. Dividing the clock +* frequency by X is the same as multiplying the period by X. +*/ if (ssys_use_rcc2 (s)) { system_clock_scale =5 * (((s->rcc2 >>23 ) &0x3f ) +1 ); }else { system_clock_scale =5 * (((s->rcc >>23 ) &0xf ) +1 ); } +clock_set_ns (s->sysclk, system_clock_scale); +if (propagate_clock) { +clock_propagate (s->sysclk); + } } static void ssys_write(void *opaque, hwaddr offset,
@@ -598,7 +611,7 @@ static void ssys_write(void *opaque, hwaddr offset, s->int_status |= (1 <<6 ); } s->rcc = value; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, true);break ;case 0x070 :/* RCC2 */ if (ssys_board_class (s) ==DID0_CLASS_SANDSTORM ) {
@@ -610,7 +623,7 @@ static void ssys_write(void *opaque, hwaddr offset, s->int_status |= (1 <<6 ); } s->rcc2 = value; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, true);break ;case 0x100 :/* RCGC0 */ s->rcgc[0 ] = value;
@@ -679,7 +692,8 @@ static void stellaris_sys_reset_hold(Object *obj) {ssys_state *s =STELLARIS_SYS (obj); -ssys_calculate_system_clock (s); +/* OK to propagate clocks from the hold phase */ +ssys_calculate_system_clock (s, true); }static void stellaris_sys_reset_exit (Object *obj)
@@ -690,7 +704,7 @@ static int stellaris_sys_post_load(void *opaque, int version_id) {ssys_state *s = opaque; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, false);return 0 ; }
@@ -713,6 +727,7 @@ static const VMStateDescription vmstate_stellaris_sys = {VMSTATE_UINT32_ARRAY (dcgc, ssys_state,3 ),VMSTATE_UINT32 (clkvclr, ssys_state),VMSTATE_UINT32 (ldoarst, ssys_state), +/* No field for sysclk -- handled in post-load instead */ VMSTATE_END_OF_LIST() } };
@@ -738,11 +753,12 @@ static void stellaris_sys_instance_init(Object *obj)memory_region_init_io (&s->iomem, obj, &ssys_ops, s,"ssys" ,0x00001000 );sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->irq); + s->sysclk =qdev_init_clock_out (DEVICE (s),"SYSCLK" ); } -static int stellaris_sys_init (uint32_t base,qemu_irq irq, -stellaris_board_info * board, -uint8_t *macaddr) +static DeviceState *stellaris_sys_init (uint32_t base,qemu_irq irq, +stellaris_board_info *board, +uint8_t *macaddr) {DeviceState *dev =qdev_new (TYPE_STELLARIS_SYS );SysBusDevice *sbd =SYS_BUS_DEVICE (dev);
@@ -774,7 +790,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq,*/ device_cold_reset (dev); -return 0 ; +return dev; }/* I2C controller. */
@@ -1341,6 +1357,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)int flash_size;I2CBus *i2c;DeviceState *dev; +DeviceState *ssys_dev;int i;int j;
@@ -1391,8 +1408,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) } } -stellaris_sys_init (0x400fe000 ,qdev_get_gpio_in (nvic,28 ), - board, nd_table[0 ].macaddr.a); + ssys_dev =stellaris_sys_init (0x400fe000 ,qdev_get_gpio_in (nvic,28 ), + board, nd_table[0 ].macaddr.a);if (board->dc1 & (1 <<3 )) {/* watchdog present */
@@ -1401,6 +1418,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)/* system_clock_scale is valid now */ uint32_t mainclk =NANOSECONDS_PER_SECOND / system_clock_scale;qdev_prop_set_uint32 (dev,"wdogclk-frq" , mainclk); +qdev_connect_clock_in (dev,"WDOGCLK" , +qdev_get_clock_out (ssys_dev,"SYSCLK" ));sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev),
Signature · 1 line
2.20.1
Re: [PATCH 17/25] hw/arm/stellaris: Create Clock input for watchdog
Hi Peter,
Quoted 15 lines · Peter Maydell
Create and connect the Clock input for the watchdog device on the Stellaris boards. Because the Stellaris boards model the ability to change the clock rate by programming PLL registers, we have to create an output Clock on the
ssys_statedevice and wire it up to the watchdog.Note that the old comment on
ssys_calculate_system_clock()got the units wrong --system_clock_scaleis in nanoseconds, not milliseconds. Improve the commentary to clarify how we are calculating the period.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-)
...
Quoted 5 lines
/*
- * Caculate the sys. clock period in ms.
+ * Calculate the system clock period. We only want to propagate
+ * this change to the rest of the system if we're not being called
+ * from migration post-load.
This part was not trivial to understand. I read the Clock API doc again then found:
Care should be taken not to use ``clock_update[_ns|_hz]()`` or ``clock_propagate()`` during the whole migration procedure because it will trigger side effects to other devices in an unknown state.
Quoted 19 lines
*/
hw/arm/stellaris.c +10
-1-static void ssys_calculate_system_clock (ssys_state *s) +static void ssys_calculate_system_clock (ssys_state *s,bool propagate_clock) { +/* +* SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input +* clock is 200MHz, which is a period of 5 ns. Dividing the clock +* frequency by X is the same as multiplying the period by X. +*/ if (ssys_use_rcc2 (s)) { system_clock_scale =5 * (((s->rcc2 >>23 ) &0x3f ) +1 ); }else { system_clock_scale =5 * (((s->rcc >>23 ) &0xf ) +1 ); } +clock_set_ns (s->sysclk, system_clock_scale); +if (propagate_clock) { +clock_propagate (s->sysclk); + } }
...
hw/arm/stellaris.c static int stellaris_sys_post_load(void *opaque, int version_id) · line 707
Quoted 7 lines
static void
stellaris_sys_reset_exit(Object *obj)hw/arm/stellaris.c +1
-1@@ -690,7 +704,7 @@ static int stellaris_sys_post_load(void *opaque, int version_id) {ssys_state *s = opaque; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, false);
So this makes sense.
I'll keep reviewing and come back to this patch later.
Regards,
Phil.
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 17/25] hw/arm/stellaris: Create Clock input for watchdog
Quoted 56 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Peter Maydell
Create and connect the Clock input for the watchdog device on the Stellaris boards. Because the Stellaris boards model the ability to change the clock rate by programming PLL registers, we have to create an output Clock on the
ssys_statedevice and wire it up to the watchdog.Note that the old comment on
ssys_calculate_system_clock()got the units wrong --system_clock_scaleis in nanoseconds, not milliseconds. Improve the commentary to clarify how we are calculating the period.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-)...
Quoted 5 lines
/*
- * Caculate the sys. clock period in ms.
+ * Calculate the system clock period. We only want to propagate
+ * this change to the rest of the system if we're not being called
+ * from migration post-load.This part was not trivial to understand. I read the Clock API doc again then found:
Care should be taken not to use ``clock_update[_ns|_hz]()`` or ``clock_propagate()`` during the whole migration procedure because it will trigger side effects to other devices in an unknown state.
Quoted 19 lines
*/
hw/arm/stellaris.c +10
-1-static void ssys_calculate_system_clock (ssys_state *s) +static void ssys_calculate_system_clock (ssys_state *s,bool propagate_clock) { +/* +* SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input +* clock is 200MHz, which is a period of 5 ns. Dividing the clock +* frequency by X is the same as multiplying the period by X. +*/ if (ssys_use_rcc2 (s)) { system_clock_scale =5 * (((s->rcc2 >>23 ) &0x3f ) +1 ); }else { system_clock_scale =5 * (((s->rcc >>23 ) &0xf ) +1 ); } +clock_set_ns (s->sysclk, system_clock_scale); +if (propagate_clock) { +clock_propagate (s->sysclk); + } }...
Quoted 5 lines
static void
stellaris_sys_reset_exit(Object *obj)hw/arm/stellaris.c +0
-0@@ -690,7 +704,7 @@ static int stellaris_sys_post_load(void *opaque, int version_id) {ssys_state *s = opaque;
Quoted 6 lines
hw/arm/stellaris.c static int stellaris_sys_post_load(void *opaque, int version_id) · line 707
Quoted 2 lines
hw/arm/stellaris.c +1
-1-ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, false);So this makes sense.
I'll keep reviewing and come back to this patch later.
Re: [PATCH 17/25] hw/arm/stellaris: Create Clock input for watchdog
In reply to Peter MaydellQuoted 6 lines · Peter Maydell
Create and connect the Clock input for the watchdog device on the Stellaris boards. Because the Stellaris boards model the ability to change the clock rate by programming PLL registers, we have to create an output Clock on the
ssys_statedevice and wire it up to the watchdog.
Quoted 6 lines
Note that the old comment on
ssys_calculate_system_clock()got the units wrong --system_clock_scaleis in nanoseconds, not milliseconds. Improve the commentary to clarify how we are calculating the period.Signed-off-by Peter Maydell <[email protected]>
Quoted 154 lines
--- hw/arm/stellaris.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-)hw/arm/stellaris.c +31
-12@@ -26,6 +26,7 @@#include "hw/watchdog/cmsdk-apb-watchdog.h" #include "migration/vmstate.h" #include "hw/misc/unimp.h" +#include "hw/qdev-clock.h" #include "cpu.h" #include "qom/object.h" @@ -377,6 +378,7 @@ struct ssys_state {uint32_t clkvclr;uint32_t ldoarst;qemu_irq irq; +Clock *sysclk;/* Properties (all read-only registers) */ uint32_t user0;uint32_t user1;@@ -555,15 +557,26 @@ static bool ssys_use_rcc2(ssys_state *s) }/* -* Caculate the sys. clock period in ms. +* Calculate the system clock period. We only want to propagate +* this change to the rest of the system if we're not being called +* from migration post-load. */ -static void ssys_calculate_system_clock (ssys_state *s) +static void ssys_calculate_system_clock (ssys_state *s,bool propagate_clock) { +/* +* SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input +* clock is 200MHz, which is a period of 5 ns. Dividing the clock +* frequency by X is the same as multiplying the period by X. +*/ if (ssys_use_rcc2 (s)) { system_clock_scale =5 * (((s->rcc2 >>23 ) &0x3f ) +1 ); }else { system_clock_scale =5 * (((s->rcc >>23 ) &0xf ) +1 ); } +clock_set_ns (s->sysclk, system_clock_scale); +if (propagate_clock) { +clock_propagate (s->sysclk); + } } static void ssys_write(void *opaque, hwaddr offset,@@ -598,7 +611,7 @@ static void ssys_write(void *opaque, hwaddr offset, s->int_status |= (1 <<6 ); } s->rcc = value; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, true);break ;case 0x070 :/* RCC2 */ if (ssys_board_class (s) ==DID0_CLASS_SANDSTORM ) {@@ -610,7 +623,7 @@ static void ssys_write(void *opaque, hwaddr offset, s->int_status |= (1 <<6 ); } s->rcc2 = value; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, true);break ;case 0x100 :/* RCGC0 */ s->rcgc[0 ] = value;@@ -679,7 +692,8 @@ static void stellaris_sys_reset_hold(Object *obj) {ssys_state *s =STELLARIS_SYS (obj); -ssys_calculate_system_clock (s); +/* OK to propagate clocks from the hold phase */ +ssys_calculate_system_clock (s, true); }static void stellaris_sys_reset_exit (Object *obj)@@ -690,7 +704,7 @@ static int stellaris_sys_post_load(void *opaque, int version_id) {ssys_state *s = opaque; -ssys_calculate_system_clock (s); +ssys_calculate_system_clock (s, false);return 0 ; }@@ -713,6 +727,7 @@ static const VMStateDescription vmstate_stellaris_sys = {VMSTATE_UINT32_ARRAY (dcgc, ssys_state,3 ),VMSTATE_UINT32 (clkvclr, ssys_state),VMSTATE_UINT32 (ldoarst, ssys_state), +/* No field for sysclk -- handled in post-load instead */ VMSTATE_END_OF_LIST() } };@@ -738,11 +753,12 @@ static void stellaris_sys_instance_init(Object *obj)memory_region_init_io (&s->iomem, obj, &ssys_ops, s,"ssys" ,0x00001000 );sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->irq); + s->sysclk =qdev_init_clock_out (DEVICE (s),"SYSCLK" ); } -static int stellaris_sys_init (uint32_t base,qemu_irq irq, -stellaris_board_info * board, -uint8_t *macaddr) +static DeviceState *stellaris_sys_init (uint32_t base,qemu_irq irq, +stellaris_board_info *board, +uint8_t *macaddr) {DeviceState *dev =qdev_new (TYPE_STELLARIS_SYS );SysBusDevice *sbd =SYS_BUS_DEVICE (dev);@@ -774,7 +790,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq,*/ device_cold_reset (dev); -return 0 ; +return dev; }/* I2C controller. */ @@ -1341,6 +1357,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)int flash_size;I2CBus *i2c;DeviceState *dev; +DeviceState *ssys_dev;int i;int j;@@ -1391,8 +1408,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) } } -stellaris_sys_init (0x400fe000 ,qdev_get_gpio_in (nvic,28 ), - board, nd_table[0 ].macaddr.a); + ssys_dev =stellaris_sys_init (0x400fe000 ,qdev_get_gpio_in (nvic,28 ), + board, nd_table[0 ].macaddr.a);if (board->dc1 & (1 <<3 )) {/* watchdog present */ @@ -1401,6 +1418,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)/* system_clock_scale is valid now */ uint32_t mainclk =NANOSECONDS_PER_SECOND / system_clock_scale;qdev_prop_set_uint32 (dev,"wdogclk-frq" , mainclk); +qdev_connect_clock_in (dev,"WDOGCLK" , +qdev_get_clock_out (ssys_dev,"SYSCLK" ));sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev),Signature · 1 line
2.20.1
PATCH 18/25 hw/timer/cmsdk-apb-timer: Convert to use Clock input
In reply to Peter MaydellSwitch the CMSDK APB timer device over to using its Clock input; the pclk-frq property is now ignored.
--- hw/timer/cmsdk-apb-timer.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
hw/timer/cmsdk-apb-timer.c +14 -4
@@ -204,6 +204,15 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)ptimer_transaction_commit (s->timer); } +static void cmsdk_apb_timer_clk_update (void *opaque) +{ +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->pclk,1 ); +ptimer_transaction_commit (s->timer); +} +static void cmsdk_apb_timer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);
@@ -213,15 +222,16 @@ static void cmsdk_apb_timer_init(Object *obj) s, "cmsdk-apb-timer", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->timerint); - s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" ,NULL ,NULL ); + s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" , + cmsdk_apb_timer_clk_update, s); }static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp) {CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev); -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->pclk)) { +error_setg (errp,"CMSDK APB timer: pclk clock must be connected" );return ; }
@@ -232,7 +242,7 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);ptimer_transaction_begin (s->timer); -ptimer_set_freq (s->timer, s->pclk_frq); +ptimer_set_period_from_clock (s->timer, s->pclk,1 );ptimer_transaction_commit (s->timer); }
Signature · 1 line
2.20.1
Re: [PATCH 18/25] hw/timer/cmsdk-apb-timer: Convert to use Clock input
Quoted 49 lines · Peter Maydell
Switch the CMSDK APB timer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>--- hw/timer/cmsdk-apb-timer.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)hw/timer/cmsdk-apb-timer.c +13
-3@@ -204,6 +204,15 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)ptimer_transaction_commit (s->timer); } +static void cmsdk_apb_timer_clk_update (void *opaque) +{ +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->pclk,1 ); +ptimer_transaction_commit (s->timer); +} +static void cmsdk_apb_timer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);@@ -213,15 +222,16 @@ static void cmsdk_apb_timer_init(Object *obj) s, "cmsdk-apb-timer", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->timerint); - s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" ,NULL ,NULL ); + s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" , + cmsdk_apb_timer_clk_update, s); }static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp) {CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev); -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->pclk)) { +error_setg (errp,"CMSDK APB timer: pclk clock must be connected" );return ; }
hw/timer/cmsdk-apb-timer.c static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) · line 247
Quoted 7 lines
hw/timer/cmsdk-apb-timer.c +1
-1@@ -232,7 +242,7 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);ptimer_transaction_begin (s->timer); -ptimer_set_freq (s->timer, s->pclk_frq); +ptimer_set_period_from_clock (s->timer, s->pclk,1 );ptimer_transaction_commit (s->timer); }
Nice to see how ptimer_set_period_from_clock() fits :)
Re: [PATCH 18/25] hw/timer/cmsdk-apb-timer: Convert to use Clock input
In reply to Peter MaydellQuoted 4 lines · Peter Maydell
Switch the CMSDK APB timer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>
Quoted 56 lines
--- hw/timer/cmsdk-apb-timer.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)hw/timer/cmsdk-apb-timer.c +14
-4@@ -204,6 +204,15 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)ptimer_transaction_commit (s->timer); } +static void cmsdk_apb_timer_clk_update (void *opaque) +{ +CMSDKAPBTimer *s =CMSDK_APB_TIMER (opaque); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->pclk,1 ); +ptimer_transaction_commit (s->timer); +} +static void cmsdk_apb_timer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);@@ -213,15 +222,16 @@ static void cmsdk_apb_timer_init(Object *obj) s, "cmsdk-apb-timer", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->timerint); - s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" ,NULL ,NULL ); + s->pclk =qdev_init_clock_in (DEVICE (s),"pclk" , + cmsdk_apb_timer_clk_update, s); }static void cmsdk_apb_timer_realize (DeviceState *dev,Error **errp) {CMSDKAPBTimer *s =CMSDK_APB_TIMER (dev); -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->pclk)) { +error_setg (errp,"CMSDK APB timer: pclk clock must be connected" );return ; }@@ -232,7 +242,7 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);ptimer_transaction_begin (s->timer); -ptimer_set_freq (s->timer, s->pclk_frq); +ptimer_set_period_from_clock (s->timer, s->pclk,1 );ptimer_transaction_commit (s->timer); }Signature · 1 line
2.20.1
PATCH 19/25 hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input
In reply to Peter MaydellSwitch the CMSDK APB dualtimer device over to using its Clock input; the pclk-frq property is now ignored.
--- hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)
hw/timer/cmsdk-apb-dualtimer.c +37 -5
@@ -106,6 +106,22 @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s)qemu_set_irq (s->timerintc, timintc); } +static int cmsdk_dualtimermod_divisor (CMSDKAPBDualTimerModule *m) +{ +/* Return the divisor set by the current CONTROL.PRESCALE value */ +switch (FIELD_EX32 (m->control,CONTROL ,PRESCALE )) { +case 0 : +return 1 ; +case 1 : +return 16 ; +case 2 : +case 3 :/* UNDEFINED, we treat like 2 (and complained when it was set) */ +return 256 ; +default : +g_assert_not_reached (); + } +} +static void cmsdk_dualtimermod_write_control (CMSDKAPBDualTimerModule *m,uint32_t newctrl) {
@@ -146,7 +162,7 @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,default :g_assert_not_reached (); } -ptimer_set_freq (m->timer, m->parent->pclk_frq / divisor); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, divisor); }if (changed &R_CONTROL_MODE_MASK ) {
@@ -414,7 +430,8 @@ static void cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m)* limit must both be set to 0xffff, so we wrap at 16 bits. */ ptimer_set_limit (m->timer,0xffff ,1 ); -ptimer_set_freq (m->timer, m->parent->pclk_frq); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, +cmsdk_dualtimermod_divisor (m));ptimer_transaction_commit (m->timer); }
@@ -432,6 +449,20 @@ static void cmsdk_apb_dualtimer_reset(DeviceState *dev) s->timeritop =0 ; } +static void cmsdk_apb_dualtimer_clk_update (void *opaque) +{ +CMSDKAPBDualTimer *s =CMSDK_APB_DUALTIMER (opaque); +int i; + +for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) { +CMSDKAPBDualTimerModule *m = &s->timermod[i]; +ptimer_transaction_begin (m->timer); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, +cmsdk_dualtimermod_divisor (m)); +ptimer_transaction_commit (m->timer); + } +} +static void cmsdk_apb_dualtimer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);
@@ -446,7 +477,8 @@ static void cmsdk_apb_dualtimer_init(Object *obj)for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) {sysbus_init_irq (sbd, &s->timermod[i].timerint); } - s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" ,NULL ,NULL ); + s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" , + cmsdk_apb_dualtimer_clk_update, s); }static void cmsdk_apb_dualtimer_realize (DeviceState *dev,Error **errp)
@@ -454,8 +486,8 @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)CMSDKAPBDualTimer *s =CMSDK_APB_DUALTIMER (dev);int i; -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->timclk)) { +error_setg (errp,"CMSDK APB dualtimer: TIMCLK clock must be connected" );return ; }
Signature · 1 line
2.20.1
Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input
Quoted 36 lines · Peter Maydell
Switch the CMSDK APB dualtimer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>--- hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)hw/timer/cmsdk-apb-dualtimer.c +16
-0@@ -106,6 +106,22 @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s)qemu_set_irq (s->timerintc, timintc); } +static int cmsdk_dualtimermod_divisor (CMSDKAPBDualTimerModule *m) +{ +/* Return the divisor set by the current CONTROL.PRESCALE value */ +switch (FIELD_EX32 (m->control,CONTROL ,PRESCALE )) { +case 0 : +return 1 ; +case 1 : +return 16 ; +case 2 : +case 3 :/* UNDEFINED, we treat like 2 (and complained when it was set) */ +return 256 ; +default : +g_assert_not_reached (); + } +} +static void cmsdk_dualtimermod_write_control (CMSDKAPBDualTimerModule *m,uint32_t newctrl) {
hw/timer/cmsdk-apb-dualtimer.c static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m, · line 165
Quoted 5 lines
hw/timer/cmsdk-apb-dualtimer.c +1
-1@@ -146,7 +162,7 @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,default :g_assert_not_reached (); } -ptimer_set_freq (m->timer, m->parent->pclk_frq / divisor); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, divisor);
Just a small cosmetic note, maybe you can use your new cmsdk_dualtimermod_divisor function to factor out the switch above? Something like:
if (changed & R_CONTROL_PRESCALE_MASK) {
if (FIELD_EX32(newctrl, CONTROL, PRESCALE) == 3) {
qemu_log_mask(LOG_GUEST_ERROR,
"CMSDK APB dual-timer: CONTROL.PRESCALE==0b11"
" is undefined behaviour\n");
}
ptimer_set_period_from_clock(m->timer, m->parent->timclk,
cmsdk_dualtimermod_divisor(m));
}With or without this modification:
Luc
Quoted 58 lines
hw/timer/cmsdk-apb-dualtimer.c +20
-4}if (changed &R_CONTROL_MODE_MASK ) {@@ -414,7 +430,8 @@ static void cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m)* limit must both be set to 0xffff, so we wrap at 16 bits. */ ptimer_set_limit (m->timer,0xffff ,1 ); -ptimer_set_freq (m->timer, m->parent->pclk_frq); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, +cmsdk_dualtimermod_divisor (m));ptimer_transaction_commit (m->timer); }@@ -432,6 +449,20 @@ static void cmsdk_apb_dualtimer_reset(DeviceState *dev) s->timeritop =0 ; } +static void cmsdk_apb_dualtimer_clk_update (void *opaque) +{ +CMSDKAPBDualTimer *s =CMSDK_APB_DUALTIMER (opaque); +int i; + +for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) { +CMSDKAPBDualTimerModule *m = &s->timermod[i]; +ptimer_transaction_begin (m->timer); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, +cmsdk_dualtimermod_divisor (m)); +ptimer_transaction_commit (m->timer); + } +} +static void cmsdk_apb_dualtimer_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);@@ -446,7 +477,8 @@ static void cmsdk_apb_dualtimer_init(Object *obj)for (i =0 ; i <ARRAY_SIZE (s->timermod); i++) {sysbus_init_irq (sbd, &s->timermod[i].timerint); } - s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" ,NULL ,NULL ); + s->timclk =qdev_init_clock_in (DEVICE (s),"TIMCLK" , + cmsdk_apb_dualtimer_clk_update, s); }static void cmsdk_apb_dualtimer_realize (DeviceState *dev,Error **errp)@@ -454,8 +486,8 @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)CMSDKAPBDualTimer *s =CMSDK_APB_DUALTIMER (dev);int i; -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->timclk)) { +error_setg (errp,"CMSDK APB dualtimer: TIMCLK clock must be connected" );return ; }Signature · 1 line
2.20.1
Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input
Quoted 48 lines · Luc Michel
Quoted 36 lines · Peter Maydell
Switch the CMSDK APB dualtimer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>--- hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)hw/timer/cmsdk-apb-dualtimer.c +16
-0@@ -106,6 +106,22 @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s)qemu_set_irq (s->timerintc, timintc); } +static int cmsdk_dualtimermod_divisor (CMSDKAPBDualTimerModule *m) +{ +/* Return the divisor set by the current CONTROL.PRESCALE value */ +switch (FIELD_EX32 (m->control,CONTROL ,PRESCALE )) { +case 0 : +return 1 ; +case 1 : +return 16 ; +case 2 : +case 3 :/* UNDEFINED, we treat like 2 (and complained when it was set) */ +return 256 ; +default : +g_assert_not_reached (); + } +} +static void cmsdk_dualtimermod_write_control (CMSDKAPBDualTimerModule *m,uint32_t newctrl) {hw/timer/cmsdk-apb-dualtimer.c static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m, · line 165
Quoted 5 lines
hw/timer/cmsdk-apb-dualtimer.c +1
-1@@ -146,7 +162,7 @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,default :g_assert_not_reached (); } -ptimer_set_freq (m->timer, m->parent->pclk_frq / divisor); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, divisor);Just a small cosmetic note, maybe you can use your new
cmsdk_dualtimermod_divisorfunction to factor out the switch above? Something like:
Quoted 10 lines
if (changed & R_CONTROL_PRESCALE_MASK) {
if (FIELD_EX32(newctrl, CONTROL, PRESCALE) == 3) {
qemu_log_mask(LOG_GUEST_ERROR,
"CMSDK APB dual-timer: CONTROL.PRESCALE==0b11"
" is undefined behaviour\n");
}
ptimer_set_period_from_clock(m->timer, m->parent->timclk,
cmsdk_dualtimermod_divisor(m));
}Nope, because cmsdk_dualtimermod_divisor() uses the current m->control value, and at this point in the code we need the divisor from the new control value which isn't in m->control yet. I liked the slight duplication better than either having to pass m->control in in all the other callsites or trying to refactor the control write handling so that m->control is updated before this point in the code.
thanks
-- PMM
Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input
Quoted 60 lines · Peter Maydell
Quoted 48 lines · Luc Michel
Quoted 36 lines · Peter Maydell
Switch the CMSDK APB dualtimer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>--- hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)hw/timer/cmsdk-apb-dualtimer.c +16
-0@@ -106,6 +106,22 @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s)qemu_set_irq (s->timerintc, timintc); } +static int cmsdk_dualtimermod_divisor (CMSDKAPBDualTimerModule *m) +{ +/* Return the divisor set by the current CONTROL.PRESCALE value */ +switch (FIELD_EX32 (m->control,CONTROL ,PRESCALE )) { +case 0 : +return 1 ; +case 1 : +return 16 ; +case 2 : +case 3 :/* UNDEFINED, we treat like 2 (and complained when it was set) */ +return 256 ; +default : +g_assert_not_reached (); + } +} +static void cmsdk_dualtimermod_write_control (CMSDKAPBDualTimerModule *m,uint32_t newctrl) {hw/timer/cmsdk-apb-dualtimer.c static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m, · line 165
Quoted 5 lines
hw/timer/cmsdk-apb-dualtimer.c +1
-1@@ -146,7 +162,7 @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,default :g_assert_not_reached (); } -ptimer_set_freq (m->timer, m->parent->pclk_frq / divisor); +ptimer_set_period_from_clock (m->timer, m->parent->timclk, divisor);Just a small cosmetic note, maybe you can use your new
cmsdk_dualtimermod_divisorfunction to factor out the switch above? Something like:Quoted 10 lines
if (changed & R_CONTROL_PRESCALE_MASK) { if (FIELD_EX32(newctrl, CONTROL, PRESCALE) == 3) { qemu_log_mask(LOG_GUEST_ERROR, "CMSDK APB dual-timer: CONTROL.PRESCALE==0b11" " is undefined behaviour\n"); } ptimer_set_period_from_clock(m->timer, m->parent->timclk, cmsdk_dualtimermod_divisor(m)); }
Quoted 7 lines
Nope, because
cmsdk_dualtimermod_divisor()uses the currentm->controlvalue, and at this point in the code we need the divisor from the new control value which isn't inm->controlyet. I liked the slight duplication better than either having to passm->controlin in all the other callsites or trying to refactor the control write handling so thatm->controlis updated before this point in the code.
Oops yes I missed that. Sure make sense, forget what I said.
Quoted 3 lines
thanks
-- PMM
Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
Switch the CMSDK APB dualtimer device over to using its Clock input; the pclk-frq property is now ignored.
Signed-off-by Peter Maydell <[email protected]>--- hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-)
...
hw/timer/cmsdk-apb-dualtimer.c static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp) · line 492
Quoted 10 lines
hw/timer/cmsdk-apb-dualtimer.c +2
-2@@ -454,8 +486,8 @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)CMSDKAPBDualTimer *s =CMSDK_APB_DUALTIMER (dev);int i; -if (s->pclk_frq ==0 ) { -error_setg (errp,"CMSDK APB timer: pclk-frq property must be set" ); +if (!clock_has_source (s->timclk)) { +error_setg (errp,"CMSDK APB dualtimer: TIMCLK clock must be connected" );return ; }
PATCH 20/25 hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input
In reply to Peter MaydellSwitch the CMSDK APB watchdog device over to using its Clock input; the wdogclk_frq property is now ignored.
--- hw/watchdog/cmsdk-apb-watchdog.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
hw/watchdog/cmsdk-apb-watchdog.c +14 -4
@@ -310,6 +310,15 @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev)ptimer_transaction_commit (s->timer); } +static void cmsdk_apb_watchdog_clk_update (void *opaque) +{ +CMSDKAPBWatchdog *s =CMSDK_APB_WATCHDOG (opaque); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->wdogclk,1 ); +ptimer_transaction_commit (s->timer); +} +static void cmsdk_apb_watchdog_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);
@@ -319,7 +328,8 @@ static void cmsdk_apb_watchdog_init(Object *obj) s, "cmsdk-apb-watchdog", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->wdogint); - s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" ,NULL ,NULL ); + s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" , + cmsdk_apb_watchdog_clk_update, s); s->is_luminary = false; s->id = cmsdk_apb_watchdog_id;
@@ -329,9 +339,9 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) {CMSDKAPBWatchdog *s =CMSDK_APB_WATCHDOG (dev); -if (s->wdogclk_frq ==0 ) { +if (!clock_has_source (s->wdogclk)) {error_setg (errp, -"CMSDK APB watchdog: wdogclk-frq property must be set" ); +"CMSDK APB watchdog: WDOGCLK clock must be connected" );return ; }
@@ -342,7 +352,7 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);ptimer_transaction_begin (s->timer); -ptimer_set_freq (s->timer, s->wdogclk_frq); +ptimer_set_period_from_clock (s->timer, s->wdogclk,1 );ptimer_transaction_commit (s->timer); }
Signature · 1 line
2.20.1
Re: [PATCH 20/25] hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input
Quoted 7 lines · Peter Maydell
Switch the CMSDK APB watchdog device over to using its Clock input; the
wdogclk_frqproperty is now ignored.Signed-off-by Peter Maydell <[email protected]>--- hw/watchdog/cmsdk-apb-watchdog.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
Re: [PATCH 20/25] hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input
In reply to Peter MaydellQuoted 4 lines · Peter Maydell
Switch the CMSDK APB watchdog device over to using its Clock input; the
wdogclk_frqproperty is now ignored.Signed-off-by Peter Maydell <[email protected]>
Quoted 58 lines
--- hw/watchdog/cmsdk-apb-watchdog.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)hw/watchdog/cmsdk-apb-watchdog.c +14
-4@@ -310,6 +310,15 @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev)ptimer_transaction_commit (s->timer); } +static void cmsdk_apb_watchdog_clk_update (void *opaque) +{ +CMSDKAPBWatchdog *s =CMSDK_APB_WATCHDOG (opaque); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->wdogclk,1 ); +ptimer_transaction_commit (s->timer); +} +static void cmsdk_apb_watchdog_init (Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);@@ -319,7 +328,8 @@ static void cmsdk_apb_watchdog_init(Object *obj) s, "cmsdk-apb-watchdog", 0x1000);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->wdogint); - s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" ,NULL ,NULL ); + s->wdogclk =qdev_init_clock_in (DEVICE (s),"WDOGCLK" , + cmsdk_apb_watchdog_clk_update, s); s->is_luminary = false; s->id = cmsdk_apb_watchdog_id;@@ -329,9 +339,9 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) {CMSDKAPBWatchdog *s =CMSDK_APB_WATCHDOG (dev); -if (s->wdogclk_frq ==0 ) { +if (!clock_has_source (s->wdogclk)) {error_setg (errp, -"CMSDK APB watchdog: wdogclk-frq property must be set" ); +"CMSDK APB watchdog: WDOGCLK clock must be connected" );return ; }@@ -342,7 +352,7 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);ptimer_transaction_begin (s->timer); -ptimer_set_freq (s->timer, s->wdogclk_frq); +ptimer_set_period_from_clock (s->timer, s->wdogclk,1 );ptimer_transaction_commit (s->timer); }Signature · 1 line
2.20.1
PATCH 21/25 tests/qtest/cmsdk-apb-watchdog-test: Test clock changes
In reply to Peter MaydellNow that the CMSDK APB watchdog uses its Clock input, it will correctly respond when the system clock frequency is changed using the RCC register on in the Stellaris board system registers. Test that when the RCC register is written it causes the watchdog timer to change speed.
--- tests/qtest/cmsdk-apb-watchdog-test.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
tests/qtest/cmsdk-apb-watchdog-test.c +52 -0
@@ -15,6 +15,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "libqtest-single.h" /*
@@ -31,6 +32,11 @@#define WDOGMIS 0x14#define WDOGLOCK 0xc00 +#define SSYS_BASE 0x400fe000 +#define RCC 0x60 +#define SYSDIV_SHIFT 23 +#define SYSDIV_LENGTH 4 +static void test_watchdog (void ) { g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0);
@@ -61,6 +67,50 @@ static void test_watchdog(void) g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); } +static void test_clock_change (void ) +{ +uint32_t rcc; + +/* +* Test that writing to the stellaris board's RCC register to +* change the system clock frequency causes the watchdog +* to change the speed it counts at. +*/ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +writel (WDOG_BASE +WDOGCONTROL ,1 ); +writel (WDOG_BASE +WDOGLOAD ,1000 ); + +/* Step to just past the 500th tick */ +clock_step (80 *500 +1 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + +/* Rewrite RCC.SYSDIV from 16 to 8, so the clock is now 40ns per tick */ + rcc =readl (SSYS_BASE +RCC ); + g_assert_cmpuint(extract32(rcc, SYSDIV_SHIFT, SYSDIV_LENGTH), ==, 0xf); + rcc =deposit32 (rcc,SYSDIV_SHIFT ,SYSDIV_LENGTH ,7 ); +writel (SSYS_BASE +RCC , rcc); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (40 *500 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); + +/* VALUE reloads at following tick */ +clock_step (41 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + +/* Writing any value to WDOGINTCLR clears the interrupt and reloads */ +clock_step (40 *500 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); +writel (WDOG_BASE +WDOGINTCLR ,0 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +} +int main (int argc,char **argv) {QTestState *s;
@@ -71,6 +121,8 @@ int main(int argc, char **argv) s =qtest_start ("-machine lm3s811evb" );qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); +qtest_add_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , + test_clock_change); r =g_test_run ();
Signature · 1 line
2.20.1
Re: [PATCH 21/25] tests/qtest/cmsdk-apb-watchdog-test: Test clock changes
Quoted 10 lines · Peter Maydell
Now that the CMSDK APB watchdog uses its Clock input, it will correctly respond when the system clock frequency is changed using the RCC register on in the Stellaris board system registers. Test that when the RCC register is written it causes the watchdog timer to change speed.
Signed-off-by Peter Maydell <[email protected]>--- tests/qtest/cmsdk-apb-watchdog-test.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
...
Quoted 6 lines
tests/qtest/cmsdk-apb-watchdog-test.c +6
-0+static void test_clock_change (void ) +{ +uint32_t rcc; + +/* +* Test that writing to the stellaris board's RCC register to
tests/qtest/cmsdk-apb-watchdog-test.c static void test_watchdog(void) · line 85
Quoted 10 lines
tests/qtest/cmsdk-apb-watchdog-test.c +10
-0+* change the system clock frequency causes the watchdog +* to change the speed it counts at. +*/ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +writel (WDOG_BASE +WDOGCONTROL ,1 ); +writel (WDOG_BASE +WDOGLOAD ,1000 ); + +/* Step to just past the 500th tick */ +clock_step (80 *500 +1 );
I was wondering about asking you to change that 40000 in patch #3. Since you use that clearer form here, it would be nice to have it in #3 too.
Otherwise,
Re: [PATCH 21/25] tests/qtest/cmsdk-apb-watchdog-test: Test clock changes
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
Now that the CMSDK APB watchdog uses its Clock input, it will correctly respond when the system clock frequency is changed using the RCC register on in the Stellaris board system registers. Test that when the RCC register is written it causes the watchdog timer to change speed.
Signed-off-by Peter Maydell <[email protected]>
Quoted 91 lines
--- tests/qtest/cmsdk-apb-watchdog-test.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)tests/qtest/cmsdk-apb-watchdog-test.c +52
-0@@ -15,6 +15,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "libqtest-single.h" /* @@ -31,6 +32,11 @@#define WDOGMIS 0x14#define WDOGLOCK 0xc00 +#define SSYS_BASE 0x400fe000 +#define RCC 0x60 +#define SYSDIV_SHIFT 23 +#define SYSDIV_LENGTH 4 +static void test_watchdog (void ) { g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0);@@ -61,6 +67,50 @@ static void test_watchdog(void) g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); } +static void test_clock_change (void ) +{ +uint32_t rcc; + +/* +* Test that writing to the stellaris board's RCC register to +* change the system clock frequency causes the watchdog +* to change the speed it counts at. +*/ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +writel (WDOG_BASE +WDOGCONTROL ,1 ); +writel (WDOG_BASE +WDOGLOAD ,1000 ); + +/* Step to just past the 500th tick */ +clock_step (80 *500 +1 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + +/* Rewrite RCC.SYSDIV from 16 to 8, so the clock is now 40ns per tick */ + rcc =readl (SSYS_BASE +RCC ); + g_assert_cmpuint(extract32(rcc, SYSDIV_SHIFT, SYSDIV_LENGTH), ==, 0xf); + rcc =deposit32 (rcc,SYSDIV_SHIFT ,SYSDIV_LENGTH ,7 ); +writel (SSYS_BASE +RCC , rcc); + +/* Just past the 1000th tick: timer should have fired */ +clock_step (40 *500 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); + +/* VALUE reloads at following tick */ +clock_step (41 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + +/* Writing any value to WDOGINTCLR clears the interrupt and reloads */ +clock_step (40 *500 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); +writel (WDOG_BASE +WDOGINTCLR ,0 ); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +} +int main (int argc,char **argv) {QTestState *s;@@ -71,6 +121,8 @@ int main(int argc, char **argv) s =qtest_start ("-machine lm3s811evb" );qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); +qtest_add_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , + test_clock_change); r =g_test_run ();Signature · 1 line
2.20.1
PATCH 22/25 hw/arm/armsse: Use Clock to set system_clock_scale
In reply to Peter MaydellUse the MAINCLK Clock input to set the system_clock_scale variable rather than using the mainclk_frq property.
---
At some point we should make the SysTick take a Clock itself so that we can get rid of the system_clock_scale global entirely. (In fact we want two Clocks: one that is the CPU clock and one for the 'external reference clock' whose period is currently hardcoded at 1000ns in systick_scale()...)
--- hw/arm/armsse.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
hw/arm/armsse.c +17 -4
@@ -232,6 +232,16 @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)qdev_connect_gpio_out (dev_splitter,2 , s->sec_resp_cfg_in); } +static void armsse_mainclk_update (void *opaque) +{ +ARMSSE *s =ARM_SSE (opaque); +/* +* Set system_clock_scale from our Clock input; this is what +* controls the tick rate of the CPU SysTick timer. +*/ + system_clock_scale =clock_ticks_to_ns (s->mainclk,1 ); +} +static void armsse_init (Object *obj) {ARMSSE *s =ARM_SSE (obj);
@@ -451,9 +461,11 @@ static void armsse_realize(DeviceState *dev, Error **errp)return ; } -if (!s->mainclk_frq) { -error_setg (errp,"MAINCLK_FRQ property was not set" ); -return ; +if (!clock_has_source (s->mainclk)) { +error_setg (errp,"MAINCLK clock was not connected" ); + } +if (!clock_has_source (s->s32kclk)) { +error_setg (errp,"S32KCLK clock was not connected" ); }assert (info->num_cpus <=SSE_MAX_CPUS );
@@ -1115,7 +1127,8 @@ static void armsse_realize(DeviceState *dev, Error **errp)*/ sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->container); - system_clock_scale =NANOSECONDS_PER_SECOND / s->mainclk_frq; +/* Set initial system_clock_scale from MAINCLK */ +armsse_mainclk_update (s); } static void armsse_idau_check(IDAUInterface *ii, uint32_t address,
Signature · 1 line
2.20.1
Re: [PATCH 22/25] hw/arm/armsse: Use Clock to set system_clock_scale
Quoted 10 lines · Peter Maydell
Use the MAINCLK Clock input to set the
system_clock_scalevariable rather than using themainclk_frqproperty.Signed-off-by Peter Maydell <[email protected]>---
At some point we should make the SysTick take a Clock itself so that we can get rid of thesystem_clock_scaleglobal entirely. (In fact we want two Clocks: one that is the CPU clock and one for the 'external reference clock' whose period is currently hardcoded at 1000ns insystick_scale()...)
Quoted 3 lines
--- hw/arm/armsse.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
Re: [PATCH 22/25] hw/arm/armsse: Use Clock to set system_clock_scale
In reply to Peter MaydellQuoted 22 lines · Peter Maydell
Use the MAINCLK Clock input to set the
system_clock_scalevariable rather than using themainclk_frqproperty.Signed-off-by Peter Maydell <[email protected]>---
At some point we should make the SysTick take a Clock itself so that we can get rid of thesystem_clock_scaleglobal entirely. (In fact we want two Clocks: one that is the CPU clock and one for the 'external reference clock' whose period is currently hardcoded at 1000ns insystick_scale()...)--- hw/arm/armsse.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)hw/arm/armsse.c +0
-0@@ -232,6 +232,16 @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)qdev_connect_gpio_out (dev_splitter,2 , s->sec_resp_cfg_in); }
hw/arm/armsse.c static void armsse_forward_sec_resp_cfg(ARMSSE *s) · line 244
Quoted 10 lines
hw/arm/armsse.c +10
-0+static void armsse_mainclk_update (void *opaque) +{ +ARMSSE *s =ARM_SSE (opaque); +/* +* Set system_clock_scale from our Clock input; this is what +* controls the tick rate of the CPU SysTick timer. +*/ + system_clock_scale =clock_ticks_to_ns (s->mainclk,1 ); +} +
I think you forgot to connect this callback to the clock itself (the qdev_init_clock_in call in armsse_init).
Moreover on a clock change event, shouldn't the SysTick timer be recomputed? I guess this will be better fixed in the SysTick itself once it takes the two Clock inputs as you said.
Signature · 1 line
Luc
Quoted 31 lines
hw/arm/armsse.c +7
-4static void armsse_init (Object *obj) {ARMSSE *s =ARM_SSE (obj);@@ -451,9 +461,11 @@ static void armsse_realize(DeviceState *dev, Error **errp)return ; } -if (!s->mainclk_frq) { -error_setg (errp,"MAINCLK_FRQ property was not set" ); -return ; +if (!clock_has_source (s->mainclk)) { +error_setg (errp,"MAINCLK clock was not connected" ); + } +if (!clock_has_source (s->s32kclk)) { +error_setg (errp,"S32KCLK clock was not connected" ); }assert (info->num_cpus <=SSE_MAX_CPUS );@@ -1115,7 +1127,8 @@ static void armsse_realize(DeviceState *dev, Error **errp)*/ sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->container); - system_clock_scale =NANOSECONDS_PER_SECOND / s->mainclk_frq; +/* Set initial system_clock_scale from MAINCLK */ +armsse_mainclk_update (s); } static void armsse_idau_check(IDAUInterface *ii, uint32_t address,Signature · 1 line
2.20.1
Re: [PATCH 22/25] hw/arm/armsse: Use Clock to set system_clock_scale
Quoted 24 lines · Luc Michel
Quoted 22 lines · Peter Maydell
Use the MAINCLK Clock input to set the
system_clock_scalevariable rather than using themainclk_frqproperty.Signed-off-by Peter Maydell <[email protected]>---
At some point we should make the SysTick take a Clock itself so that we can get rid of thesystem_clock_scaleglobal entirely. (In fact we want two Clocks: one that is the CPU clock and one for the 'external reference clock' whose period is currently hardcoded at 1000ns insystick_scale()...)--- hw/arm/armsse.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)hw/arm/armsse.c +0
-0@@ -232,6 +232,16 @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)qdev_connect_gpio_out (dev_splitter,2 , s->sec_resp_cfg_in); }
Quoted 12 lines
hw/arm/armsse.c static void armsse_forward_sec_resp_cfg(ARMSSE *s) · line 244
Quoted 10 lines
hw/arm/armsse.c +10
-0+static void armsse_mainclk_update (void *opaque) +{ +ARMSSE *s =ARM_SSE (opaque); +/* +* Set system_clock_scale from our Clock input; this is what +* controls the tick rate of the CPU SysTick timer. +*/ + system_clock_scale =clock_ticks_to_ns (s->mainclk,1 ); +} +I think you forgot to connect this callback to the clock itself (the
qdev_init_clock_incall inarmsse_init).
Whoops, yes :-) As it happens all ARMSSE users are fixed-frequency so this doesn't make a guest-visible difference, but it was definitely my intention that this was a clock update callback.
Quoted 2 lines
Moreover on a clock change event, shouldn't the SysTick timer be recomputed?
Systick correctly handles the system_clock_scale global being changed at runtime, so once this callback is actually wired up to its Clock that should just work.
thanks
-- PMM
PATCH 23/25 arm: Don't set freq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
In reply to Peter MaydellRemove all the code that sets frequency properties on the CMSDK timer, dualtimer and watchdog devices and on the ARMSSE SoC device:
these properties are unused now that the devices rely on their Clock inputs instead.
--- hw/arm/armsse.c | 7 ------- hw/arm/mps2-tz.c | 1 - hw/arm/mps2.c | 3 --- hw/arm/musca.c | 1 - hw/arm/stellaris.c | 3 --- 5 files changed, 15 deletions(-)
hw/arm/armsse.c +0 -7
@@ -726,7 +726,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)* it to the appropriate PPC port; then we can realize the PPC and * map its upstream ends to the right place in the container. */ -qdev_prop_set_uint32 (DEVICE (&s->timer0),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->timer0),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer0), errp)) {return ;
@@ -737,7 +736,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)object_property_set_link (OBJECT (&s->apb_ppc0),"port[0]" ,OBJECT (mr), &error_abort); -qdev_prop_set_uint32 (DEVICE (&s->timer1),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->timer1),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer1), errp)) {return ;
@@ -748,7 +746,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)object_property_set_link (OBJECT (&s->apb_ppc0),"port[1]" ,OBJECT (mr), &error_abort); -qdev_prop_set_uint32 (DEVICE (&s->dualtimer),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->dualtimer),"TIMCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->dualtimer), errp)) {return ;
@@ -907,7 +904,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* Devices behind APB PPC1: * 0x4002f000: S32K timer */ -qdev_prop_set_uint32 (DEVICE (&s->s32ktimer),"pclk-frq" ,S32KCLK );qdev_connect_clock_in (DEVICE (&s->s32ktimer),"pclk" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32ktimer), errp)) {return ;
@@ -1001,7 +997,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)qdev_connect_gpio_out (DEVICE (&s->nmi_orgate),0 ,qdev_get_gpio_in_named (DEVICE (&s->armv7m),"NMI" ,0 )); -qdev_prop_set_uint32 (DEVICE (&s->s32kwatchdog),"wdogclk-frq" ,S32KCLK );qdev_connect_clock_in (DEVICE (&s->s32kwatchdog),"WDOGCLK" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32kwatchdog), errp)) {return ;
@@ -1012,7 +1007,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ -qdev_prop_set_uint32 (DEVICE (&s->nswatchdog),"wdogclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->nswatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->nswatchdog), errp)) {return ;
@@ -1021,7 +1015,6 @@ static void armsse_realize(DeviceState *dev, Error **errp) armsse_get_common_irq_in(s, 1));sysbus_mmio_map (SYS_BUS_DEVICE (&s->nswatchdog),0 ,0x40081000 ); -qdev_prop_set_uint32 (DEVICE (&s->swatchdog),"wdogclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->swatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->swatchdog), errp)) {return ;
hw/arm/mps2-tz.c +0 -1
@@ -413,7 +413,6 @@ static void mps2tz_common_init(MachineState *machine)object_property_set_link (OBJECT (&mms->iotkit),"memory" ,OBJECT (system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ ); -qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ );qdev_connect_clock_in (iotkitdev,"MAINCLK" , mms->sysclk);qdev_connect_clock_in (iotkitdev,"S32KCLK" , mms->s32kclk);sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);
hw/arm/mps2.c +0 -3
@@ -346,7 +346,6 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms), name, &mms->timer[i],TYPE_CMSDK_APB_TIMER ); sbd =SYS_BUS_DEVICE (&mms->timer[i]); -qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->timer[i]),"pclk" , mms->sysclk);sysbus_realize_and_unref (sbd, &error_fatal);sysbus_mmio_map (sbd,0 , base);
@@ -355,7 +354,6 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER ); -qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->dualtimer),"TIMCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->dualtimer), &error_fatal); sysbus_connect_irq(SYS_BUS_DEVICE(&mms->dualtimer), 0,
@@ -363,7 +361,6 @@ static void mps2_common_init(MachineState *machine)sysbus_mmio_map (SYS_BUS_DEVICE (&mms->dualtimer),0 ,0x40002000 );object_initialize_child (OBJECT (mms),"watchdog" , &mms->watchdog,TYPE_CMSDK_APB_WATCHDOG ); -qdev_prop_set_uint32 (DEVICE (&mms->watchdog),"wdogclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->watchdog),"WDOGCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->watchdog), &error_fatal); sysbus_connect_irq(SYS_BUS_DEVICE(&mms->watchdog), 0,
hw/arm/musca.c +0 -1
@@ -385,7 +385,6 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"EXP_NUMIRQ" , mmc->num_irqs);qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width); -qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ );qdev_connect_clock_in (ssedev,"MAINCLK" , mms->sysclk);qdev_connect_clock_in (ssedev,"S32KCLK" , mms->s32kclk);/*
hw/arm/stellaris.c +0 -3
@@ -1415,9 +1415,6 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)if (board->dc1 & (1 <<3 )) {/* watchdog present */ dev =qdev_new (TYPE_LUMINARY_WATCHDOG ); -/* system_clock_scale is valid now */ -uint32_t mainclk =NANOSECONDS_PER_SECOND / system_clock_scale; -qdev_prop_set_uint32 (dev,"wdogclk-frq" , mainclk);qdev_connect_clock_in (dev,"WDOGCLK" ,qdev_get_clock_out (ssys_dev,"SYSCLK" ));
Signature · 1 line
2.20.1
Re: [PATCH 23/25] arm: Don't set freq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
Quoted 5 lines · Peter Maydell
Remove all the code that sets frequency properties on the CMSDK timer, dualtimer and watchdog devices and on the ARMSSE SoC device:
these properties are unused now that the devices rely on their Clock inputs instead.
Quoted 8 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/armsse.c | 7 ------- hw/arm/mps2-tz.c | 1 - hw/arm/mps2.c | 3 --- hw/arm/musca.c | 1 - hw/arm/stellaris.c | 3 --- 5 files changed, 15 deletions(-)
Re: [PATCH 23/25] arm: Don't set freq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
In reply to Peter MaydellQuoted 6 lines · Peter Maydell
Remove all the code that sets frequency properties on the CMSDK timer, dualtimer and watchdog devices and on the ARMSSE SoC device:
these properties are unused now that the devices rely on their Clock inputs instead.Signed-off-by Peter Maydell <[email protected]>
Quoted 137 lines
--- hw/arm/armsse.c | 7 ------- hw/arm/mps2-tz.c | 1 - hw/arm/mps2.c | 3 --- hw/arm/musca.c | 1 - hw/arm/stellaris.c | 3 --- 5 files changed, 15 deletions(-)hw/arm/armsse.c +0
-7@@ -726,7 +726,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)* it to the appropriate PPC port; then we can realize the PPC and * map its upstream ends to the right place in the container. */ -qdev_prop_set_uint32 (DEVICE (&s->timer0),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->timer0),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer0), errp)) {return ;@@ -737,7 +736,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)object_property_set_link (OBJECT (&s->apb_ppc0),"port[0]" ,OBJECT (mr), &error_abort); -qdev_prop_set_uint32 (DEVICE (&s->timer1),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->timer1),"pclk" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer1), errp)) {return ;@@ -748,7 +746,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)object_property_set_link (OBJECT (&s->apb_ppc0),"port[1]" ,OBJECT (mr), &error_abort); -qdev_prop_set_uint32 (DEVICE (&s->dualtimer),"pclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->dualtimer),"TIMCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->dualtimer), errp)) {return ;@@ -907,7 +904,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* Devices behind APB PPC1: * 0x4002f000: S32K timer */ -qdev_prop_set_uint32 (DEVICE (&s->s32ktimer),"pclk-frq" ,S32KCLK );qdev_connect_clock_in (DEVICE (&s->s32ktimer),"pclk" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32ktimer), errp)) {return ;@@ -1001,7 +997,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)qdev_connect_gpio_out (DEVICE (&s->nmi_orgate),0 ,qdev_get_gpio_in_named (DEVICE (&s->armv7m),"NMI" ,0 )); -qdev_prop_set_uint32 (DEVICE (&s->s32kwatchdog),"wdogclk-frq" ,S32KCLK );qdev_connect_clock_in (DEVICE (&s->s32kwatchdog),"WDOGCLK" , s->s32kclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->s32kwatchdog), errp)) {return ;@@ -1012,7 +1007,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ -qdev_prop_set_uint32 (DEVICE (&s->nswatchdog),"wdogclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->nswatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->nswatchdog), errp)) {return ;@@ -1021,7 +1015,6 @@ static void armsse_realize(DeviceState *dev, Error **errp) armsse_get_common_irq_in(s, 1));sysbus_mmio_map (SYS_BUS_DEVICE (&s->nswatchdog),0 ,0x40081000 ); -qdev_prop_set_uint32 (DEVICE (&s->swatchdog),"wdogclk-frq" , s->mainclk_frq);qdev_connect_clock_in (DEVICE (&s->swatchdog),"WDOGCLK" , s->mainclk);if (!sysbus_realize (SYS_BUS_DEVICE (&s->swatchdog), errp)) {return ;hw/arm/mps2-tz.c +0
-1@@ -413,7 +413,6 @@ static void mps2tz_common_init(MachineState *machine)object_property_set_link (OBJECT (&mms->iotkit),"memory" ,OBJECT (system_memory), &error_abort);qdev_prop_set_uint32 (iotkitdev,"EXP_NUMIRQ" ,MPS2TZ_NUMIRQ ); -qdev_prop_set_uint32 (iotkitdev,"MAINCLK_FRQ" ,SYSCLK_FRQ );qdev_connect_clock_in (iotkitdev,"MAINCLK" , mms->sysclk);qdev_connect_clock_in (iotkitdev,"S32KCLK" , mms->s32kclk);sysbus_realize (SYS_BUS_DEVICE (&mms->iotkit), &error_fatal);hw/arm/mps2.c +0
-3@@ -346,7 +346,6 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms), name, &mms->timer[i],TYPE_CMSDK_APB_TIMER ); sbd =SYS_BUS_DEVICE (&mms->timer[i]); -qdev_prop_set_uint32 (DEVICE (&mms->timer[i]),"pclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->timer[i]),"pclk" , mms->sysclk);sysbus_realize_and_unref (sbd, &error_fatal);sysbus_mmio_map (sbd,0 , base);@@ -355,7 +354,6 @@ static void mps2_common_init(MachineState *machine)object_initialize_child (OBJECT (mms),"dualtimer" , &mms->dualtimer,TYPE_CMSDK_APB_DUALTIMER ); -qdev_prop_set_uint32 (DEVICE (&mms->dualtimer),"pclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->dualtimer),"TIMCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->dualtimer), &error_fatal); sysbus_connect_irq(SYS_BUS_DEVICE(&mms->dualtimer), 0,@@ -363,7 +361,6 @@ static void mps2_common_init(MachineState *machine)sysbus_mmio_map (SYS_BUS_DEVICE (&mms->dualtimer),0 ,0x40002000 );object_initialize_child (OBJECT (mms),"watchdog" , &mms->watchdog,TYPE_CMSDK_APB_WATCHDOG ); -qdev_prop_set_uint32 (DEVICE (&mms->watchdog),"wdogclk-frq" ,SYSCLK_FRQ );qdev_connect_clock_in (DEVICE (&mms->watchdog),"WDOGCLK" , mms->sysclk);sysbus_realize (SYS_BUS_DEVICE (&mms->watchdog), &error_fatal); sysbus_connect_irq(SYS_BUS_DEVICE(&mms->watchdog), 0,hw/arm/musca.c +0
-1@@ -385,7 +385,6 @@ static void musca_init(MachineState *machine)qdev_prop_set_uint32 (ssedev,"EXP_NUMIRQ" , mmc->num_irqs);qdev_prop_set_uint32 (ssedev,"init-svtor" , mmc->init_svtor);qdev_prop_set_uint32 (ssedev,"SRAM_ADDR_WIDTH" , mmc->sram_addr_width); -qdev_prop_set_uint32 (ssedev,"MAINCLK_FRQ" ,SYSCLK_FRQ );qdev_connect_clock_in (ssedev,"MAINCLK" , mms->sysclk);qdev_connect_clock_in (ssedev,"S32KCLK" , mms->s32kclk);/* hw/arm/stellaris.c +0
-3@@ -1415,9 +1415,6 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)if (board->dc1 & (1 <<3 )) {/* watchdog present */ dev =qdev_new (TYPE_LUMINARY_WATCHDOG ); -/* system_clock_scale is valid now */ -uint32_t mainclk =NANOSECONDS_PER_SECOND / system_clock_scale; -qdev_prop_set_uint32 (dev,"wdogclk-frq" , mainclk);qdev_connect_clock_in (dev,"WDOGCLK" ,qdev_get_clock_out (ssys_dev,"SYSCLK" ));Signature · 1 line
2.20.1
PATCH 24/25 arm: Remove frq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
In reply to Peter MaydellNow no users are setting the frq properties on the CMSDK timer, dualtimer, watchdog or ARMSSE SoC devices, we can remove the properties and the struct fields that back them.
--- include/hw/arm/armsse.h | 2 -- include/hw/timer/cmsdk-apb-dualtimer.h | 2 -- include/hw/timer/cmsdk-apb-timer.h | 2 -- include/hw/watchdog/cmsdk-apb-watchdog.h | 2 -- hw/arm/armsse.c | 2 -- hw/timer/cmsdk-apb-dualtimer.c | 6 ------ hw/timer/cmsdk-apb-timer.c | 6 ------ hw/watchdog/cmsdk-apb-watchdog.c | 6 ------ 8 files changed, 28 deletions(-)
include/hw/arm/armsse.h +0 -2
@@ -41,7 +41,6 @@* + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. -* + QOM property "MAINCLK_FRQ" is the frequency of the main system clock * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. * (In hardware, the SSE-200 permits the number of expansion interrupts * for the two CPUs to be configured separately, but we restrict it to
@@ -218,7 +217,6 @@ struct ARMSSE {/* Properties */ MemoryRegion *board_memory;uint32_t exp_numirq; -uint32_t mainclk_frq;uint32_t sram_addr_width;uint32_t init_svtor;bool cpu_fpu[SSE_MAX_CPUS ];
include/hw/timer/cmsdk-apb-dualtimer.h +0 -2
@@ -16,7 +16,6 @@* https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit * * QEMU interface: -* + QOM property "pclk-frq": frequency at which the timer is clocked * + Clock input "TIMCLK": clock (for both timers) * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: combined timer interrupt TIMINTC
@@ -63,7 +62,6 @@ struct CMSDKAPBDualTimer {/*< public >*/ MemoryRegion iomem;qemu_irq timerintc; -uint32_t pclk_frq;Clock *timclk;CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES ];
include/hw/timer/cmsdk-apb-timer.h +0 -2
@@ -23,7 +23,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER)/* * QEMU interface: -* + QOM property "pclk-frq": frequency at which the timer is clocked * + Clock input "pclk": clock for the timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: timer interrupt TIMERINT
@@ -35,7 +34,6 @@ struct CMSDKAPBTimer {/*< public >*/ MemoryRegion iomem;qemu_irq timerint; -uint32_t pclk_frq;struct ptimer_state *timer;Clock *pclk;
include/hw/watchdog/cmsdk-apb-watchdog.h +0 -2
@@ -16,7 +16,6 @@* https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit * * QEMU interface: -* + QOM property "wdogclk-frq": frequency at which the watchdog is clocked * + Clock input "WDOGCLK": clock for the watchdog's timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: watchdog interrupt
@@ -53,7 +52,6 @@ struct CMSDKAPBWatchdog {/*< public >*/ MemoryRegion iomem;qemu_irq wdogint; -uint32_t wdogclk_frq;bool is_luminary;struct ptimer_state *timer;Clock *wdogclk;
hw/arm/armsse.c +0 -2
@@ -48,7 +48,6 @@ static Property iotkit_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),
@@ -60,7 +59,6 @@ static Property armsse_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),
hw/timer/cmsdk-apb-dualtimer.c +0 -6
@@ -533,11 +533,6 @@ static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { } }; -static Property cmsdk_apb_dualtimer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBDualTimer, pclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_dualtimer_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -545,7 +540,6 @@ static void cmsdk_apb_dualtimer_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_dualtimer_realize; dc->vmsd = &cmsdk_apb_dualtimer_vmstate; dc->reset = cmsdk_apb_dualtimer_reset; -device_class_set_props (dc, cmsdk_apb_dualtimer_properties); }static const TypeInfo cmsdk_apb_dualtimer_info = {
hw/timer/cmsdk-apb-timer.c +0 -6
@@ -261,11 +261,6 @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { } }; -static Property cmsdk_apb_timer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBTimer, pclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_timer_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -273,7 +268,6 @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_timer_realize; dc->vmsd = &cmsdk_apb_timer_vmstate; dc->reset = cmsdk_apb_timer_reset; -device_class_set_props (dc, cmsdk_apb_timer_properties); }static const TypeInfo cmsdk_apb_timer_info = {
hw/watchdog/cmsdk-apb-watchdog.c +0 -6
@@ -373,11 +373,6 @@ static const VMStateDescription cmsdk_apb_watchdog_vmstate = { } }; -static Property cmsdk_apb_watchdog_properties[] = { -DEFINE_PROP_UINT32 ("wdogclk-frq" , CMSDKAPBWatchdog, wdogclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_watchdog_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -385,7 +380,6 @@ static void cmsdk_apb_watchdog_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_watchdog_realize; dc->vmsd = &cmsdk_apb_watchdog_vmstate; dc->reset = cmsdk_apb_watchdog_reset; -device_class_set_props (dc, cmsdk_apb_watchdog_properties); }static const TypeInfo cmsdk_apb_watchdog_info = {
Signature · 1 line
2.20.1
Re: [PATCH 24/25] arm: Remove frq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
Quoted 1 line · Peter Maydell
Now no users are setting the frq properties on the CMSDK timer,
"Now that no ..."? No clue, double "no*" sounds odd to me :)
Quoted 4 lines
dualtimer, watchdog or ARMSSE SoC devices, we can remove the properties and the struct fields that back them.
Signed-off-by Peter Maydell <[email protected]>
Quoted 10 lines
--- include/hw/arm/armsse.h | 2 -- include/hw/timer/cmsdk-apb-dualtimer.h | 2 -- include/hw/timer/cmsdk-apb-timer.h | 2 -- include/hw/watchdog/cmsdk-apb-watchdog.h | 2 -- hw/arm/armsse.c | 2 -- hw/timer/cmsdk-apb-dualtimer.c | 6 ------ hw/timer/cmsdk-apb-timer.c | 6 ------ hw/watchdog/cmsdk-apb-watchdog.c | 6 ------ 8 files changed, 28 deletions(-)
Re: [PATCH 24/25] arm: Remove frq properties on CMSDK timer, dualtimer, watchdog, ARMSSE
In reply to Peter MaydellQuoted 5 lines · Peter Maydell
Now no users are setting the frq properties on the CMSDK timer, dualtimer, watchdog or ARMSSE SoC devices, we can remove the properties and the struct fields that back them.
Signed-off-by Peter Maydell <[email protected]>
Quoted 186 lines
--- include/hw/arm/armsse.h | 2 -- include/hw/timer/cmsdk-apb-dualtimer.h | 2 -- include/hw/timer/cmsdk-apb-timer.h | 2 -- include/hw/watchdog/cmsdk-apb-watchdog.h | 2 -- hw/arm/armsse.c | 2 -- hw/timer/cmsdk-apb-dualtimer.c | 6 ------ hw/timer/cmsdk-apb-timer.c | 6 ------ hw/watchdog/cmsdk-apb-watchdog.c | 6 ------ 8 files changed, 28 deletions(-)include/hw/arm/armsse.h +0
-2@@ -41,7 +41,6 @@* + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals * + QOM property "memory" is a MemoryRegion containing the devices provided * by the board model. -* + QOM property "MAINCLK_FRQ" is the frequency of the main system clock * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. * (In hardware, the SSE-200 permits the number of expansion interrupts * for the two CPUs to be configured separately, but we restrict it to @@ -218,7 +217,6 @@ struct ARMSSE {/* Properties */ MemoryRegion *board_memory;uint32_t exp_numirq; -uint32_t mainclk_frq;uint32_t sram_addr_width;uint32_t init_svtor;bool cpu_fpu[SSE_MAX_CPUS ];include/hw/timer/cmsdk-apb-dualtimer.h +0
-2@@ -16,7 +16,6 @@* https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit * * QEMU interface: -* + QOM property "pclk-frq": frequency at which the timer is clocked * + Clock input "TIMCLK": clock (for both timers) * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: combined timer interrupt TIMINTC @@ -63,7 +62,6 @@ struct CMSDKAPBDualTimer {/*< public >*/ MemoryRegion iomem;qemu_irq timerintc; -uint32_t pclk_frq;Clock *timclk;CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES ];include/hw/timer/cmsdk-apb-timer.h +0
-2@@ -23,7 +23,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER)/* * QEMU interface: -* + QOM property "pclk-frq": frequency at which the timer is clocked * + Clock input "pclk": clock for the timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: timer interrupt TIMERINT @@ -35,7 +34,6 @@ struct CMSDKAPBTimer {/*< public >*/ MemoryRegion iomem;qemu_irq timerint; -uint32_t pclk_frq;struct ptimer_state *timer;Clock *pclk;include/hw/watchdog/cmsdk-apb-watchdog.h +0
-2@@ -16,7 +16,6 @@* https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit * * QEMU interface: -* + QOM property "wdogclk-frq": frequency at which the watchdog is clocked * + Clock input "WDOGCLK": clock for the watchdog's timer * + sysbus MMIO region 0: the register bank * + sysbus IRQ 0: watchdog interrupt @@ -53,7 +52,6 @@ struct CMSDKAPBWatchdog {/*< public >*/ MemoryRegion iomem;qemu_irq wdogint; -uint32_t wdogclk_frq;bool is_luminary;struct ptimer_state *timer;Clock *wdogclk;hw/arm/armsse.c +0
-2@@ -48,7 +48,6 @@ static Property iotkit_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),@@ -60,7 +59,6 @@ static Property armsse_properties[] = {DEFINE_PROP_LINK ("memory" ,ARMSSE , board_memory,TYPE_MEMORY_REGION , MemoryRegion *),DEFINE_PROP_UINT32 ("EXP_NUMIRQ" ,ARMSSE , exp_numirq,64 ), -DEFINE_PROP_UINT32 ("MAINCLK_FRQ" ,ARMSSE , mainclk_frq,0 ),DEFINE_PROP_UINT32 ("SRAM_ADDR_WIDTH" ,ARMSSE , sram_addr_width,15 ),DEFINE_PROP_UINT32 ("init-svtor" ,ARMSSE , init_svtor,0x10000000 ), DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),hw/timer/cmsdk-apb-dualtimer.c +0
-6@@ -533,11 +533,6 @@ static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { } }; -static Property cmsdk_apb_dualtimer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBDualTimer, pclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_dualtimer_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -545,7 +540,6 @@ static void cmsdk_apb_dualtimer_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_dualtimer_realize; dc->vmsd = &cmsdk_apb_dualtimer_vmstate; dc->reset = cmsdk_apb_dualtimer_reset; -device_class_set_props (dc, cmsdk_apb_dualtimer_properties); }static const TypeInfo cmsdk_apb_dualtimer_info = {hw/timer/cmsdk-apb-timer.c +0
-6@@ -261,11 +261,6 @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { } }; -static Property cmsdk_apb_timer_properties[] = { -DEFINE_PROP_UINT32 ("pclk-frq" , CMSDKAPBTimer, pclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_timer_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -273,7 +268,6 @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_timer_realize; dc->vmsd = &cmsdk_apb_timer_vmstate; dc->reset = cmsdk_apb_timer_reset; -device_class_set_props (dc, cmsdk_apb_timer_properties); }static const TypeInfo cmsdk_apb_timer_info = {hw/watchdog/cmsdk-apb-watchdog.c +0
-6@@ -373,11 +373,6 @@ static const VMStateDescription cmsdk_apb_watchdog_vmstate = { } }; -static Property cmsdk_apb_watchdog_properties[] = { -DEFINE_PROP_UINT32 ("wdogclk-frq" , CMSDKAPBWatchdog, wdogclk_frq,0 ), -DEFINE_PROP_END_OF_LIST (), -}; -static void cmsdk_apb_watchdog_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -385,7 +380,6 @@ static void cmsdk_apb_watchdog_class_init(ObjectClass *klass, void *data) dc->realize = cmsdk_apb_watchdog_realize; dc->vmsd = &cmsdk_apb_watchdog_vmstate; dc->reset = cmsdk_apb_watchdog_reset; -device_class_set_props (dc, cmsdk_apb_watchdog_properties); }static const TypeInfo cmsdk_apb_watchdog_info = {Signature · 1 line
2.20.1
PATCH 25/25 hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS
In reply to Peter MaydellNow that the watchdog device uses its Clock input rather than being passed the value of system_clock_scale at creation time, we can remove the hack where we reset the STELLARIS_SYS at board creation time to force it to set system_clock_scale. Instead it will be reset at the usual point in startup and will inform the watchdog of the clock frequency at that point.
--- hw/arm/stellaris.c | 10 ---------- 1 file changed, 10 deletions(-)
hw/arm/stellaris.c +0 -10
@@ -780,16 +780,6 @@ static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq,sysbus_mmio_map (sbd,0 , base);sysbus_connect_irq (sbd,0 , irq); -/* -* Normally we should not be resetting devices like this during -* board creation. For the moment we need to do so, because -* system_clock_scale will only get set when the STELLARIS_SYS -* device is reset, and we need its initial value to pass to -* the watchdog device. This hack can be removed once the -* watchdog has been converted to use a Clock input instead. -*/ -device_cold_reset (dev); -return dev; }
Signature · 1 line
2.20.1
Re: [PATCH 25/25] hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS
Quoted 8 lines · Peter Maydell
Now that the watchdog device uses its Clock input rather than being passed the value of
system_clock_scaleat creation time, we can remove the hack where we reset theSTELLARIS_SYSat board creation time to force it to setsystem_clock_scale. Instead it will be reset at the usual point in startup and will inform the watchdog of the clock frequency at that point.Signed-off-by Peter Maydell <[email protected]>
Quoted 28 lines
--- hw/arm/stellaris.c | 10 ---------- 1 file changed, 10 deletions(-)hw/arm/stellaris.c +0
-10@@ -780,16 +780,6 @@ static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq,sysbus_mmio_map (sbd,0 , base);sysbus_connect_irq (sbd,0 , irq); -/* -* Normally we should not be resetting devices like this during -* board creation. For the moment we need to do so, because -* system_clock_scale will only get set when the STELLARIS_SYS -* device is reset, and we need its initial value to pass to -* the watchdog device. This hack can be removed once the -* watchdog has been converted to use a Clock input instead. -*/ -device_cold_reset (dev); -return dev; }Signature · 1 line
2.20.1
Re: [PATCH 25/25] hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS
In reply to Peter MaydellQuoted 11 lines · Peter Maydell
Now that the watchdog device uses its Clock input rather than being passed the value of
system_clock_scaleat creation time, we can remove the hack where we reset theSTELLARIS_SYSat board creation time to force it to setsystem_clock_scale. Instead it will be reset at the usual point in startup and will inform the watchdog of the clock frequency at that point.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 10 ---------- 1 file changed, 10 deletions(-)