]>
Commit | Line | Data |
---|---|---|
720d3c5f | 1 | /** @file\r |
2 | Provides synchronization functions.\r | |
3 | \r | |
9095d37b | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
720d3c5f | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #ifndef __SYNCHRONIZATION_LIB__\r | |
10 | #define __SYNCHRONIZATION_LIB__\r | |
11 | \r | |
12 | ///\r | |
13 | /// Definitions for SPIN_LOCK\r | |
14 | ///\r | |
2f88bd3a | 15 | typedef volatile UINTN SPIN_LOCK;\r |
720d3c5f | 16 | \r |
17 | /**\r | |
1a2f870c | 18 | Retrieves the architecture-specific spin lock alignment requirements for\r |
720d3c5f | 19 | optimal spin lock performance.\r |
20 | \r | |
21 | This function retrieves the spin lock alignment requirements for optimal\r | |
9095d37b | 22 | performance on a given CPU architecture. The spin lock alignment is byte alignment.\r |
744265eb | 23 | It must be a power of two and is returned by this function. If there are no alignment\r |
720d3c5f | 24 | requirements, then 1 must be returned. The spin lock synchronization\r |
25 | functions must function correctly if the spin lock size and alignment values\r | |
26 | returned by this function are not used at all. These values are hints to the\r | |
27 | consumers of the spin lock synchronization functions to obtain optimal spin\r | |
28 | lock performance.\r | |
29 | \r | |
1a2f870c | 30 | @return The architecture-specific spin lock alignment.\r |
720d3c5f | 31 | \r |
32 | **/\r | |
33 | UINTN\r | |
34 | EFIAPI\r | |
35 | GetSpinLockProperties (\r | |
36 | VOID\r | |
37 | );\r | |
38 | \r | |
720d3c5f | 39 | /**\r |
40 | Initializes a spin lock to the released state and returns the spin lock.\r | |
41 | \r | |
42 | This function initializes the spin lock specified by SpinLock to the released\r | |
43 | state, and returns SpinLock. Optimal performance can be achieved by calling\r | |
44 | GetSpinLockProperties() to determine the size and alignment requirements for\r | |
45 | SpinLock.\r | |
46 | \r | |
47 | If SpinLock is NULL, then ASSERT().\r | |
48 | \r | |
49 | @param SpinLock A pointer to the spin lock to initialize to the released\r | |
50 | state.\r | |
51 | \r | |
52 | @return SpinLock in release state.\r | |
53 | \r | |
54 | **/\r | |
55 | SPIN_LOCK *\r | |
56 | EFIAPI\r | |
57 | InitializeSpinLock (\r | |
2f88bd3a | 58 | OUT SPIN_LOCK *SpinLock\r |
720d3c5f | 59 | );\r |
60 | \r | |
720d3c5f | 61 | /**\r |
62 | Waits until a spin lock can be placed in the acquired state.\r | |
63 | \r | |
64 | This function checks the state of the spin lock specified by SpinLock. If\r | |
65 | SpinLock is in the released state, then this function places SpinLock in the\r | |
66 | acquired state and returns SpinLock. Otherwise, this function waits\r | |
67 | indefinitely for the spin lock to be released, and then places it in the\r | |
68 | acquired state and returns SpinLock. All state transitions of SpinLock must\r | |
69 | be performed using MP safe mechanisms.\r | |
70 | \r | |
71 | If SpinLock is NULL, then ASSERT().\r | |
72 | If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r | |
73 | If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in\r | |
74 | PcdSpinLockTimeout microseconds, then ASSERT().\r | |
75 | \r | |
76 | @param SpinLock A pointer to the spin lock to place in the acquired state.\r | |
77 | \r | |
78 | @return SpinLock acquired lock.\r | |
79 | \r | |
80 | **/\r | |
81 | SPIN_LOCK *\r | |
82 | EFIAPI\r | |
83 | AcquireSpinLock (\r | |
2f88bd3a | 84 | IN OUT SPIN_LOCK *SpinLock\r |
720d3c5f | 85 | );\r |
86 | \r | |
720d3c5f | 87 | /**\r |
88 | Attempts to place a spin lock in the acquired state.\r | |
89 | \r | |
90 | This function checks the state of the spin lock specified by SpinLock. If\r | |
91 | SpinLock is in the released state, then this function places SpinLock in the\r | |
92 | acquired state and returns TRUE. Otherwise, FALSE is returned. All state\r | |
93 | transitions of SpinLock must be performed using MP safe mechanisms.\r | |
94 | \r | |
95 | If SpinLock is NULL, then ASSERT().\r | |
96 | If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r | |
97 | \r | |
98 | @param SpinLock A pointer to the spin lock to place in the acquired state.\r | |
99 | \r | |
100 | @retval TRUE SpinLock was placed in the acquired state.\r | |
101 | @retval FALSE SpinLock could not be acquired.\r | |
102 | \r | |
103 | **/\r | |
104 | BOOLEAN\r | |
105 | EFIAPI\r | |
106 | AcquireSpinLockOrFail (\r | |
2f88bd3a | 107 | IN OUT SPIN_LOCK *SpinLock\r |
720d3c5f | 108 | );\r |
109 | \r | |
720d3c5f | 110 | /**\r |
111 | Releases a spin lock.\r | |
112 | \r | |
113 | This function places the spin lock specified by SpinLock in the release state\r | |
114 | and returns SpinLock.\r | |
115 | \r | |
116 | If SpinLock is NULL, then ASSERT().\r | |
117 | If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r | |
118 | \r | |
119 | @param SpinLock A pointer to the spin lock to release.\r | |
120 | \r | |
121 | @return SpinLock released lock.\r | |
122 | \r | |
123 | **/\r | |
124 | SPIN_LOCK *\r | |
125 | EFIAPI\r | |
126 | ReleaseSpinLock (\r | |
2f88bd3a | 127 | IN OUT SPIN_LOCK *SpinLock\r |
720d3c5f | 128 | );\r |
129 | \r | |
720d3c5f | 130 | /**\r |
1a2f870c | 131 | Performs an atomic increment of a 32-bit unsigned integer.\r |
720d3c5f | 132 | \r |
133 | Performs an atomic increment of the 32-bit unsigned integer specified by\r | |
134 | Value and returns the incremented value. The increment operation must be\r | |
17634d02 | 135 | performed using MP safe mechanisms.\r |
720d3c5f | 136 | \r |
137 | If Value is NULL, then ASSERT().\r | |
138 | \r | |
139 | @param Value A pointer to the 32-bit value to increment.\r | |
140 | \r | |
141 | @return The incremented value.\r | |
142 | \r | |
143 | **/\r | |
144 | UINT32\r | |
145 | EFIAPI\r | |
146 | InterlockedIncrement (\r | |
2f88bd3a | 147 | IN volatile UINT32 *Value\r |
720d3c5f | 148 | );\r |
149 | \r | |
720d3c5f | 150 | /**\r |
1a2f870c | 151 | Performs an atomic decrement of a 32-bit unsigned integer.\r |
720d3c5f | 152 | \r |
153 | Performs an atomic decrement of the 32-bit unsigned integer specified by\r | |
154 | Value and returns the decremented value. The decrement operation must be\r | |
17634d02 | 155 | performed using MP safe mechanisms.\r |
720d3c5f | 156 | \r |
157 | If Value is NULL, then ASSERT().\r | |
158 | \r | |
159 | @param Value A pointer to the 32-bit value to decrement.\r | |
160 | \r | |
161 | @return The decremented value.\r | |
162 | \r | |
163 | **/\r | |
164 | UINT32\r | |
165 | EFIAPI\r | |
166 | InterlockedDecrement (\r | |
2f88bd3a | 167 | IN volatile UINT32 *Value\r |
720d3c5f | 168 | );\r |
169 | \r | |
9b89163e AB |
170 | /**\r |
171 | Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r | |
172 | \r | |
173 | Performs an atomic compare exchange operation on the 16-bit unsigned integer\r | |
174 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
175 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
176 | then Value is returned. The compare exchange operation must be performed using\r | |
177 | MP safe mechanisms.\r | |
178 | \r | |
179 | If Value is NULL, then ASSERT().\r | |
180 | \r | |
181 | @param Value A pointer to the 16-bit value for the compare exchange\r | |
182 | operation.\r | |
183 | @param CompareValue 16-bit value used in compare operation.\r | |
184 | @param ExchangeValue 16-bit value used in exchange operation.\r | |
185 | \r | |
186 | @return The original *Value before exchange.\r | |
187 | **/\r | |
188 | UINT16\r | |
189 | EFIAPI\r | |
190 | InterlockedCompareExchange16 (\r | |
2f88bd3a MK |
191 | IN OUT volatile UINT16 *Value,\r |
192 | IN UINT16 CompareValue,\r | |
193 | IN UINT16 ExchangeValue\r | |
9b89163e AB |
194 | );\r |
195 | \r | |
720d3c5f | 196 | /**\r |
197 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
198 | \r | |
199 | Performs an atomic compare exchange operation on the 32-bit unsigned integer\r | |
200 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
201 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
202 | then Value is returned. The compare exchange operation must be performed using\r | |
203 | MP safe mechanisms.\r | |
204 | \r | |
205 | If Value is NULL, then ASSERT().\r | |
206 | \r | |
207 | @param Value A pointer to the 32-bit value for the compare exchange\r | |
208 | operation.\r | |
209 | @param CompareValue 32-bit value used in compare operation.\r | |
210 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
211 | \r | |
212 | @return The original *Value before exchange.\r | |
213 | \r | |
214 | **/\r | |
215 | UINT32\r | |
216 | EFIAPI\r | |
217 | InterlockedCompareExchange32 (\r | |
2f88bd3a MK |
218 | IN OUT volatile UINT32 *Value,\r |
219 | IN UINT32 CompareValue,\r | |
220 | IN UINT32 ExchangeValue\r | |
720d3c5f | 221 | );\r |
222 | \r | |
720d3c5f | 223 | /**\r |
224 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
225 | \r | |
226 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
227 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
228 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
229 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
230 | \r | |
231 | If Value is NULL, then ASSERT().\r | |
232 | \r | |
233 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
234 | operation.\r | |
235 | @param CompareValue 64-bit value used in compare operation.\r | |
236 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
237 | \r | |
238 | @return The original *Value before exchange.\r | |
239 | \r | |
240 | **/\r | |
241 | UINT64\r | |
242 | EFIAPI\r | |
243 | InterlockedCompareExchange64 (\r | |
2f88bd3a MK |
244 | IN OUT volatile UINT64 *Value,\r |
245 | IN UINT64 CompareValue,\r | |
246 | IN UINT64 ExchangeValue\r | |
720d3c5f | 247 | );\r |
248 | \r | |
720d3c5f | 249 | /**\r |
250 | Performs an atomic compare exchange operation on a pointer value.\r | |
251 | \r | |
252 | Performs an atomic compare exchange operation on the pointer value specified\r | |
253 | by Value. If Value is equal to CompareValue, then Value is set to\r | |
254 | ExchangeValue and CompareValue is returned. If Value is not equal to\r | |
255 | CompareValue, then Value is returned. The compare exchange operation must be\r | |
256 | performed using MP safe mechanisms.\r | |
257 | \r | |
258 | If Value is NULL, then ASSERT().\r | |
259 | \r | |
260 | @param Value A pointer to the pointer value for the compare exchange\r | |
261 | operation.\r | |
262 | @param CompareValue Pointer value used in compare operation.\r | |
263 | @param ExchangeValue Pointer value used in exchange operation.\r | |
264 | \r | |
265 | @return The original *Value before exchange.\r | |
266 | **/\r | |
267 | VOID *\r | |
268 | EFIAPI\r | |
269 | InterlockedCompareExchangePointer (\r | |
2f88bd3a MK |
270 | IN OUT VOID *volatile *Value,\r |
271 | IN VOID *CompareValue,\r | |
272 | IN VOID *ExchangeValue\r | |
720d3c5f | 273 | );\r |
274 | \r | |
275 | #endif\r |