xref: /openbmc/qemu/include/hw/timer/armv7m_systick.h (revision 6e2e2e8a)
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 
18 #define TYPE_SYSTICK "armv7m_systick"
19 
20 OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK)
21 
22 struct SysTickState {
23     /*< private >*/
24     SysBusDevice parent_obj;
25     /*< public >*/
26 
27     uint32_t control;
28     uint32_t reload;
29     int64_t tick;
30     QEMUTimer *timer;
31     MemoryRegion iomem;
32     qemu_irq irq;
33 };
34 
35 /*
36  * Multiplication factor to convert from system clock ticks to qemu timer
37  * ticks. This should be set (by board code, usually) to a value
38  * equal to NANOSECONDS_PER_SECOND / frq, where frq is the clock frequency
39  * in Hz of the CPU.
40  *
41  * This value is used by the systick device when it is running in
42  * its "use the CPU clock" mode (ie when SYST_CSR.CLKSOURCE == 1) to
43  * set how fast the timer should tick.
44  *
45  * TODO: we should refactor this so that rather than using a global
46  * we use a device property or something similar. This is complicated
47  * because (a) the property would need to be plumbed through from the
48  * board code down through various layers to the systick device
49  * and (b) the property needs to be modifiable after realize, because
50  * the stellaris board uses this to implement the behaviour where the
51  * guest can reprogram the PLL registers to downclock the CPU, and the
52  * systick device needs to react accordingly. Possibly this should
53  * be deferred until we have a good API for modelling clock trees.
54  */
55 extern int system_clock_scale;
56 
57 #endif
58