This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
lock.c
227 lines (142 loc) · 3.62 KB
/
lock.c
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*++
Copyright (c) 2014 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
info@minocacorp.com for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
lock.c
Abstract:
This module implements "lock" services for the EFI core. Now don't get
excited, UEFI really is single threaded. This is more of a validation than
any real synchronization.
Author:
Evan Green 28-Feb-2014
Environment:
Firmware
--*/
//
// ------------------------------------------------------------------- Includes
//
#include "ueficore.h"
//
// ---------------------------------------------------------------- Definitions
//
//
// ------------------------------------------------------ Data Type Definitions
//
//
// ----------------------------------------------- Internal Function Prototypes
//
//
// -------------------------------------------------------------------- Globals
//
//
// ------------------------------------------------------------------ Functions
//
VOID
EfiCoreInitializeLock (
PEFI_LOCK Lock,
EFI_TPL Tpl
)
/*++
Routine Description:
This routine initializes an EFI lock.
Arguments:
Lock - Supplies a pointer to the lock to initialize.
Tpl - Supplies the Task Prioriry Level the lock is acquired at.
Return Value:
None.
--*/
{
Lock->Tpl = Tpl;
Lock->OwnerTpl = TPL_APPLICATION;
Lock->State = EfiLockReleased;
return;
}
EFI_STATUS
EfiCoreAcquireLockOrFail (
PEFI_LOCK Lock
)
/*++
Routine Description:
This routine attempts to acquire the given lock, and fails if it is already
held.
Arguments:
Lock - Supplies a pointer to the lock to try to acquire.
Return Value:
EFI_SUCCESS if the lock was successfully acquired.
EFI_ACCESS_DENIED if the lock was already held and could not be acquired.
--*/
{
ASSERT((Lock != NULL) && (Lock->State != EfiLockUninitialized));
if (Lock->State == EfiLockAcquired) {
return EFI_ACCESS_DENIED;
}
Lock->OwnerTpl = EfiCoreRaiseTpl(Lock->Tpl);
Lock->State = EfiLockAcquired;
return EFI_SUCCESS;
}
VOID
EfiCoreAcquireLock (
PEFI_LOCK Lock
)
/*++
Routine Description:
This routine raises to the task priority level of the given lock and
acquires the lock.
Arguments:
Lock - Supplies a pointer to the lock to acquire.
Return Value:
None.
--*/
{
ASSERT((Lock != NULL) && (Lock->State == EfiLockReleased));
Lock->OwnerTpl = EfiCoreRaiseTpl(Lock->Tpl);
Lock->State = EfiLockAcquired;
return;
}
VOID
EfiCoreReleaseLock (
PEFI_LOCK Lock
)
/*++
Routine Description:
This routine releases ownership of the given lock, and lowers back down
to the original TPL.
Arguments:
Lock - Supplies a pointer to the lock to release.
Return Value:
None.
--*/
{
EFI_TPL Tpl;
ASSERT((Lock != NULL) && (Lock->State == EfiLockAcquired));
Tpl = Lock->OwnerTpl;
Lock->State = EfiLockReleased;
EfiCoreRestoreTpl(Tpl);
return;
}
BOOLEAN
EfiCoreIsLockHeld (
PEFI_LOCK Lock
)
/*++
Routine Description:
This routine determines if the given lock is held.
Arguments:
Lock - Supplies a pointer to the lock to query.
Return Value:
TRUE if the lock is held.
FALSE if the lock is not held.
--*/
{
ASSERT((Lock != NULL) && (Lock->State != EfiLockUninitialized));
if (Lock->State == EfiLockAcquired) {
return TRUE;
}
return FALSE;
}
//
// --------------------------------------------------------- Internal Functions
//