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