blob: 0bfff01e7719a1755587d66075fb56c3fe4d653c [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __TIMER_H__
8#define __TIMER_H__
9
10#include <irq.h>
11
12typedef struct plat_timer {
13 int (*program)(unsigned long time_out_ms);
14 int (*cancel)(void);
15 int (*handler)(void);
16
17 /*
18 * Duration of the atomic time slice in milliseconds. All timer
19 * requests within the same time slice are merged into one. This value
20 * should be chosen such that it is greater than the time required to
21 * program the timer.
22 */
23 unsigned int timer_step_value;
24 unsigned int timer_irq;
25} plat_timer_t;
26
27/*
28 * Gets the platform specific timer implementation information and initialises
29 * the timer framework and peripheral.
30 * Returns 0 on success or return value of timer peripheral intialisation
31 * function.
32 */
33int tftf_initialise_timer(void);
34
35/*
36 * Requests the timer framework to send an interrupt after milli_secs.
37 * The interrupt is sent to the calling core of this api. The actual
38 * time the interrupt is received by the core can be greater than
39 * the requested time.
40 * Returns 0 on success and -1 on failure.
41 */
42int tftf_program_timer(unsigned long milli_secs);
43
44/*
45 * Requests the timer framework to send an interrupt after milli_secs and to
46 * suspend the CPU to the desired power state. The interrupt is sent to the
47 * calling core of this api. The actual time the interrupt is received by the
48 * core can be greater than the requested time.
49 *
50 * Return codes from tftf_program_timer calls and tftf_cpu_suspend are stored
51 * respectively in timer_rc and suspend_rc output parameters.
52 * If a function is not executed, the return value stored in the output
53 * parameters will be as if the correponding call succeeded. NULL pointers are
54 * accepted to discard the return codes.
55 * Returns 0 on success and -1 on failure.
56 */
57
58int tftf_program_timer_and_suspend(unsigned long milli_secs,
59 unsigned int pwr_state,
60 int *timer_rc, int *suspend_rc);
61
62/*
63 * Requests the timer framework to send an interrupt after milli_secs and to
64 * suspend the system. The interrupt is sent to the calling core of this api.
65 * The actual time the interrupt is received by the core can be greater than
66 * the requested time. For the system suspend to succeed, all cores other than
67 * the calling core should be in the OFF state.
68 *
69 * Return codes from tftf_program_timer calls and tftf_cpu_system suspend
70 * are stored respectively in timer_rc and suspend_rc output parameters.
71 * If a function is not executed, the return value stored in the output
72 * parameters will be as if the correponding call succeeded. NULL pointers are
73 * accepted to discard the return codes.
74 * Returns 0 on success and -1 on failure.
75 */
76int tftf_program_timer_and_sys_suspend(unsigned long milli_secs,
77 int *timer_rc, int *suspend_rc);
78
79/*
80 * Suspends the calling CPU for specified milliseconds.
81 *
82 * Returns 0 on success, and -1 otherwise.
83 */
84int tftf_timer_sleep(unsigned long milli_secs);
85
86/*
87 * Common handler for servicing all the timer interrupts. It in turn calls the
88 * peripheral specific handler. It also sends WAKE_SGI to all the cores which
89 * requested an interrupt within a time frame of timer_step_value.
90 * Also, if there are pending interrupt requests, reprograms the timer
91 * accordingly to fire an interrupt at the right time.
92 *
93 * Returns 0 on success.
94 */
95int tftf_timer_framework_handler(void *data);
96
97/*
98 * Cancels the previously programmed value by the called core.
99 * This api should be used only for cancelling the self interrupt request
100 * by a core.
101 * Returns 0 on success, negative value otherwise.
102 */
103int tftf_cancel_timer(void);
104
105/*
106 * It is used to register a handler which needs to be called when a timer
107 * interrupt is fired.
108 * Returns 0 on success, negative value otherwise.
109 */
110int tftf_timer_register_handler(irq_handler_t irq_handler);
111
112/*
113 * It is used to unregister a previously registered handler.
114 * Returns 0 on success, negative value otherwise.
115 */
116int tftf_timer_unregister_handler(void);
117
118/*
119 * Return the IRQ Number of the registered timer interrupt
120 */
121unsigned int tftf_get_timer_irq(void);
122
123/*
124 * Returns the timer step value in a platform and is used by test cases.
125 */
126unsigned int tftf_get_timer_step_value(void);
127
128/*
129 * Restore the GIC state after wake-up from system suspend
130 */
131void tftf_timer_gic_state_restore(void);
132
133#endif /* __TIMER_H__ */