summaryrefslogtreecommitdiff
path: root/big-little/secure_world/events.c
blob: e128165166dce51b67e452308f91cbcb0aa46040 (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
83
84
85
86
87
88
89
/*
 * $Copyright:
 * ----------------------------------------------------------------
 * This confidential and proprietary software may be used only as
 * authorised by a licensing agreement from ARM Limited
 *  (C) COPYRIGHT 2008-2011 ARM Limited
 *       ALL RIGHTS RESERVED
 * The entire notice above must be reproduced on all authorised
 * copies and copies may only be made to the extent permitted
 * by a licensing agreement from ARM Limited.
 * ----------------------------------------------------------------
 * File:     events.c
 * ----------------------------------------------------------------
 * $
 */

#include "events.h"

/*
 * Set the specified event for that cpu.
 */
void _set_event(unsigned event_id, unsigned cpu_id, unsigned event_type)
{
        dsb();
        secure_event[cpu_id][event_id] = TRUE;
        dsb();
        sev();
        return;
}

inline unsigned _get_event(unsigned event_id, unsigned cpu_id)
{
        return secure_event[cpu_id][event_id];
}

void _reset_event(unsigned event_id, unsigned cpu_id, unsigned event_type)
{
        dsb();
        secure_event[cpu_id][event_id] = FALSE;
        dsb();
        return;
}

void _wait_for_event(unsigned event_id, unsigned cpu_id, unsigned event_type)
{
        dsb();
        do {
                wfe();
                isb();
                dsb();
        } while (FALSE == _get_event(event_id, cpu_id));

        return;
}

/*
 * Wait for events from each core. Its a little trickier than
 * waiting for a single event. The event register as per the
 * architecture is just a single bit to flag an event rather
 * than the number of events. If multiple events are sent by
 * the time we enter wfe() then each flag variable should be
 * checked.
 */
void _wait_for_events(unsigned event_id, unsigned event_type)
{
        unsigned ctr, event_count = 0, num_cpus = num_secondaries() + 1;;

        dsb();
        do {
                wfe();
                for (ctr = 0; ctr < num_cpus; ctr++) {
                        if (TRUE == _get_event(event_id, ctr)) {
                                event_count++;
                                _reset_event(event_id, ctr, event_type);
                        }
                }
        } while (event_count != num_cpus);

        return;
}

void _set_events(unsigned event_id, unsigned event_type)
{
        unsigned ctr;
        for (ctr = 0; ctr < (num_secondaries() + 1); ctr++) {
                _set_event(event_id, ctr, event_type);
        }
        return;
}