aboutsummaryrefslogtreecommitdiff
path: root/include/lib/events.h
blob: 34c5b2f76dda2f4d48da036958fe16932240dfe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (c) 2018, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef __EVENTS_H__
#define __EVENTS_H__

#include <spinlock.h>

typedef struct {
	/*
	 * Counter that keeps track of the minimum number of recipients of the
	 * event. When the event is sent, this counter is incremented. When it
	 * is received, it is decremented. Therefore, a zero value means that
	 * the event hasn't been sent yet, or that all recipients have already
	 * received it.
	 *
	 * Volatile is needed as it will enforce ordering relatively to
	 * accesses to the lock.
	 */
	volatile unsigned int cnt;

	/* Lock used to avoid concurrent accesses to the counter */
	spinlock_t lock;
} event_t;

/*
 * Initialise an event.
 *   event: Address of the event to initialise
 *
 * This function can be used either to initialise a newly created event
 * structure or to recycle one.
 *
 * Note: This function is not MP-safe. It can't use the event lock as it is
 * responsible for initialising it. Care must be taken to ensure this function
 * is called in the right circumstances.
 */
void tftf_init_event(event_t *event);

/*
 * Send an event to a CPU.
 *   event: Address of the variable that acts as a synchronisation object.
 *
 * Which CPU receives the event is determined on a first-come, first-served
 * basis. If several CPUs are waiting for the same event then the first CPU
 * which takes the event will reflect that in the event structure.
 *
 * Note: This is equivalent to calling:
 *   tftf_send_event_to(event, 1);
 */
void tftf_send_event(event_t *event);

/*
 * Send an event to all CPUs.
 *   event: Address of the variable that acts as a synchronisation object.
 *
 * Note: This is equivalent to calling:
 *   tftf_send_event_to(event, PLATFORM_CORE_COUNT);
 */
void tftf_send_event_to_all(event_t *event);

/*
 * Send an event to a given number of CPUs.
 *   event: Address of the variable that acts as a synchronisation object.
 *   cpus_count: Number of CPUs to send the event to.
 *
 * Which CPUs receive the event is determined on a first-come, first-served
 * basis. If more than 'cpus_count' CPUs are waiting for the same event then the
 * first 'cpus_count' CPUs which take the event will reflect that in the event
 * structure.
 */
void tftf_send_event_to(event_t *event, unsigned int cpus_count);

/*
 * Wait for an event.
 *   event: Address of the variable that acts as a synchronisation object.
 */
void tftf_wait_for_event(event_t *event);

#endif /* __EVENTS_H__ */