xref: /openbmc/qemu/include/hw/timer/armv7m_systick.h (revision fe1127da)
1 /*
2  * ARMv7M SysTick timer
3  *
4  * Copyright (c) 2006-2007 CodeSourcery.
5  * Written by Paul Brook
6  * Copyright (c) 2017 Linaro Ltd
7  * Written by Peter Maydell
8  *
9  * This code is licensed under the GPL (version 2 or later).
10  */
11 
12 #ifndef HW_TIMER_ARMV7M_SYSTICK_H
13 #define HW_TIMER_ARMV7M_SYSTICK_H
14 
15 #include "hw/sysbus.h"
16 #include "qom/object.h"
17 #include "hw/ptimer.h"
18 
19 #define TYPE_SYSTICK "armv7m_systick"
20 
21 OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK)
22 
23 struct SysTickState {
24     /*< private >*/
25     SysBusDevice parent_obj;
26     /*< public >*/
27 
28     uint32_t control;
29     uint32_t reload;
30     int64_t tick;
31     ptimer_state *ptimer;
32     MemoryRegion iomem;
33     qemu_irq irq;
34 };
35 
36 /*
37  * Multiplication factor to convert from system clock ticks to qemu timer
38  * ticks. This should be set (by board code, usually) to a value
39  * equal to NANOSECONDS_PER_SECOND / frq, where frq is the clock frequency
40  * in Hz of the CPU.
41  *
42  * This value is used by the systick device when it is running in
43  * its "use the CPU clock" mode (ie when SYST_CSR.CLKSOURCE == 1) to
44  * set how fast the timer should tick.
45  *
46  * TODO: we should refactor this so that rather than using a global
47  * we use a device property or something similar. This is complicated
48  * because (a) the property would need to be plumbed through from the
49  * board code down through various layers to the systick device
50  * and (b) the property needs to be modifiable after realize, because
51  * the stellaris board uses this to implement the behaviour where the
52  * guest can reprogram the PLL registers to downclock the CPU, and the
53  * systick device needs to react accordingly. Possibly this should
54  * be deferred until we have a good API for modelling clock trees.
55  */
56 extern int system_clock_scale;
57 
58 #endif
59