blob: ff57cbde95c71389c7faca6f936bc445229ca474 [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
Jens Wiklander5a440782024-06-25 12:36:20 +020035void tftf_initialise_timer_secondary_core(void);
36
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037/*
38 * Requests the timer framework to send an interrupt after milli_secs.
39 * The interrupt is sent to the calling core of this api. The actual
40 * time the interrupt is received by the core can be greater than
41 * the requested time.
42 * Returns 0 on success and -1 on failure.
43 */
44int tftf_program_timer(unsigned long milli_secs);
45
46/*
47 * Requests the timer framework to send an interrupt after milli_secs and to
48 * suspend the CPU to the desired power state. The interrupt is sent to the
49 * calling core of this api. The actual time the interrupt is received by the
50 * core can be greater than the requested time.
51 *
52 * Return codes from tftf_program_timer calls and tftf_cpu_suspend are stored
53 * respectively in timer_rc and suspend_rc output parameters.
54 * If a function is not executed, the return value stored in the output
55 * parameters will be as if the correponding call succeeded. NULL pointers are
56 * accepted to discard the return codes.
57 * Returns 0 on success and -1 on failure.
58 */
59
60int tftf_program_timer_and_suspend(unsigned long milli_secs,
61 unsigned int pwr_state,
62 int *timer_rc, int *suspend_rc);
63
64/*
65 * Requests the timer framework to send an interrupt after milli_secs and to
66 * suspend the system. The interrupt is sent to the calling core of this api.
67 * The actual time the interrupt is received by the core can be greater than
68 * the requested time. For the system suspend to succeed, all cores other than
69 * the calling core should be in the OFF state.
70 *
71 * Return codes from tftf_program_timer calls and tftf_cpu_system suspend
72 * are stored respectively in timer_rc and suspend_rc output parameters.
73 * If a function is not executed, the return value stored in the output
74 * parameters will be as if the correponding call succeeded. NULL pointers are
75 * accepted to discard the return codes.
76 * Returns 0 on success and -1 on failure.
77 */
78int tftf_program_timer_and_sys_suspend(unsigned long milli_secs,
79 int *timer_rc, int *suspend_rc);
80
81/*
82 * Suspends the calling CPU for specified milliseconds.
83 *
84 * Returns 0 on success, and -1 otherwise.
85 */
86int tftf_timer_sleep(unsigned long milli_secs);
87
88/*
89 * Common handler for servicing all the timer interrupts. It in turn calls the
90 * peripheral specific handler. It also sends WAKE_SGI to all the cores which
91 * requested an interrupt within a time frame of timer_step_value.
92 * Also, if there are pending interrupt requests, reprograms the timer
93 * accordingly to fire an interrupt at the right time.
94 *
95 * Returns 0 on success.
96 */
97int tftf_timer_framework_handler(void *data);
98
99/*
100 * Cancels the previously programmed value by the called core.
101 * This api should be used only for cancelling the self interrupt request
102 * by a core.
103 * Returns 0 on success, negative value otherwise.
104 */
105int tftf_cancel_timer(void);
106
107/*
108 * It is used to register a handler which needs to be called when a timer
109 * interrupt is fired.
110 * Returns 0 on success, negative value otherwise.
111 */
112int tftf_timer_register_handler(irq_handler_t irq_handler);
113
114/*
115 * It is used to unregister a previously registered handler.
116 * Returns 0 on success, negative value otherwise.
117 */
118int tftf_timer_unregister_handler(void);
119
120/*
121 * Return the IRQ Number of the registered timer interrupt
122 */
123unsigned int tftf_get_timer_irq(void);
124
125/*
126 * Returns the timer step value in a platform and is used by test cases.
127 */
128unsigned int tftf_get_timer_step_value(void);
129
130/*
131 * Restore the GIC state after wake-up from system suspend
132 */
133void tftf_timer_gic_state_restore(void);
134
135#endif /* __TIMER_H__ */