TianoCore EDK2 master
Loading...
Searching...
No Matches
Synchronization.c
Go to the documentation of this file.
1
10#include <Library/DebugLib.h>
11
12UINT32
13EFIAPI
14AsmInternalSyncCompareExchange16 (
15 IN volatile UINT32 *,
16 IN UINT64,
17 IN UINT64,
18 IN UINT64
19 );
20
21UINT32
22EFIAPI
23AsmInternalSyncCompareExchange32 (
24 IN volatile UINT32 *,
25 IN UINT64,
26 IN UINT64
27 );
28
29UINT64
30EFIAPI
31AsmInternalSyncCompareExchange64 (
32 IN volatile UINT64 *,
33 IN UINT64,
34 IN UINT64
35 );
36
37UINT32
38EFIAPI
39AsmInternalSyncIncrement (
40 IN volatile UINT32 *
41 );
42
43UINT32
44EFIAPI
45AsmInternalSyncDecrement (
46 IN volatile UINT32 *
47 );
48
68UINT16
69EFIAPI
71 IN volatile UINT16 *Value,
72 IN UINT16 CompareValue,
73 IN UINT16 ExchangeValue
74 )
75{
76 UINT32 RetValue;
77 UINT32 Shift;
78 UINT64 Mask;
79 UINT64 LocalCompareValue;
80 UINT64 LocalExchangeValue;
81 volatile UINT32 *Ptr32;
82
83 /* Check that ptr is naturally aligned */
84 ASSERT (!((UINT64)Value & (sizeof (UINT16) - 1)));
85
86 /* Mask inputs to the correct size. */
87 Mask = (((~0UL) - (1UL << (0)) + 1) & (~0UL >> (64 - 1 - ((sizeof (UINT16) * 8) - 1))));
88 LocalCompareValue = ((UINT64)CompareValue) & Mask;
89 LocalExchangeValue = ((UINT64)ExchangeValue) & Mask;
90
91 /*
92 * Calculate a shift & mask that correspond to the value we wish to
93 * compare & exchange within the naturally aligned 4 byte integer
94 * that includes it.
95 */
96 Shift = (UINT64)Value & 0x3;
97 Shift *= 8; /* BITS_PER_BYTE */
98 LocalCompareValue <<= Shift;
99 LocalExchangeValue <<= Shift;
100 Mask <<= Shift;
101
102 /*
103 * Calculate a pointer to the naturally aligned 4 byte integer that
104 * includes our byte of interest, and load its value.
105 */
106 Ptr32 = (UINT32 *)((UINT64)Value & ~0x3);
107
108 RetValue = AsmInternalSyncCompareExchange16 (
109 Ptr32,
110 Mask,
111 LocalCompareValue,
112 LocalExchangeValue
113 );
114
115 return (RetValue & Mask) >> Shift;
116}
117
137UINT32
138EFIAPI
140 IN volatile UINT32 *Value,
141 IN UINT32 CompareValue,
142 IN UINT32 ExchangeValue
143 )
144{
145 UINT32 RetValue;
146
147 RetValue = AsmInternalSyncCompareExchange32 (
148 Value,
149 CompareValue,
150 ExchangeValue
151 );
152
153 return RetValue;
154}
155
172UINT64
173EFIAPI
175 IN volatile UINT64 *Value,
176 IN UINT64 CompareValue,
177 IN UINT64 ExchangeValue
178 )
179{
180 UINT64 RetValue;
181
182 RetValue = AsmInternalSyncCompareExchange64 (
183 Value,
184 CompareValue,
185 ExchangeValue
186 );
187
188 return RetValue;
189}
190
204UINT32
205EFIAPI
207 IN volatile UINT32 *Value
208 )
209{
210 return AsmInternalSyncIncrement (Value);
211}
212
226UINT32
227EFIAPI
229 IN volatile UINT32 *Value
230 )
231{
232 return AsmInternalSyncDecrement (Value);
233}
UINT32 EFIAPI InternalSyncDecrement(IN volatile UINT32 *Value)
UINT32 EFIAPI InternalSyncIncrement(IN volatile UINT32 *Value)
UINT64 EFIAPI InternalSyncCompareExchange64(IN volatile UINT64 *Value, IN UINT64 CompareValue, IN UINT64 ExchangeValue)
UINT32 EFIAPI InternalSyncCompareExchange32(IN volatile UINT32 *Value, IN UINT32 CompareValue, IN UINT32 ExchangeValue)
UINT16 EFIAPI InternalSyncCompareExchange16(IN volatile UINT16 *Value, IN UINT16 CompareValue, IN UINT16 ExchangeValue)
#define IN
Definition: Base.h:279