]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Mde UEFI library functions.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials \r | |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | Module Name: UefiLib.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | /**\r | |
18 | Compare whether two names of languages are identical.\r | |
19 | \r | |
20 | @param Language1 Name of language 1.\r | |
21 | @param Language2 Name of language 2.\r | |
22 | \r | |
23 | @retval TRUE Language 1 and language 2 are the same.\r | |
24 | @retval FALSE Language 1 and language 2 are not the same.\r | |
25 | \r | |
26 | **/\r | |
27 | BOOLEAN\r | |
28 | CompareIso639LanguageCode (\r | |
29 | IN CONST CHAR8 *Language1,\r | |
30 | IN CONST CHAR8 *Language2\r | |
31 | )\r | |
32 | {\r | |
33 | return (BOOLEAN) (ReadUnaligned24 ((CONST UINT32 *) Language1) == ReadUnaligned24 ((CONST UINT32 *) Language2));\r | |
34 | }\r | |
35 | \r | |
36 | /**\r | |
37 | This function searches the list of configuration tables stored in the EFI System \r | |
38 | Table for a table with a GUID that matches TableGuid. If a match is found, \r | |
39 | then a pointer to the configuration table is returned in Table, and EFI_SUCCESS \r | |
40 | is returned. If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r | |
41 | \r | |
42 | @param TableGuid Pointer to table's GUID type..\r | |
43 | @param Table Pointer to the table associated with TableGuid in the EFI System Table.\r | |
44 | \r | |
45 | @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r | |
46 | @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.\r | |
47 | \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | EfiGetSystemConfigurationTable ( \r | |
52 | IN EFI_GUID *TableGuid,\r | |
53 | OUT VOID **Table\r | |
54 | )\r | |
55 | {\r | |
56 | EFI_SYSTEM_TABLE *SystemTable;\r | |
57 | UINTN Index;\r | |
58 | \r | |
59 | ASSERT (TableGuid != NULL);\r | |
60 | ASSERT (Table != NULL);\r | |
61 | \r | |
62 | SystemTable = gST;\r | |
63 | *Table = NULL;\r | |
64 | for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r | |
65 | if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r | |
66 | *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r | |
67 | return EFI_SUCCESS;\r | |
68 | }\r | |
69 | }\r | |
70 | \r | |
71 | return EFI_NOT_FOUND;\r | |
72 | }\r | |
73 | \r | |
74 | /**\r | |
75 | This function causes the notification function to be executed for every protocol \r | |
76 | of type ProtocolGuid instance that exists in the system when this function is \r | |
77 | invoked. In addition, every time a protocol of type ProtocolGuid instance is \r | |
78 | installed or reinstalled, the notification function is also executed.\r | |
79 | \r | |
80 | @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.\r | |
81 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
82 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
83 | @param NotifyContext The context parameter to pass to NotifyFunction.\r | |
84 | @param Registration A pointer to a memory location to receive the registration value.\r | |
85 | \r | |
86 | @return The notification event that was created. \r | |
87 | \r | |
88 | **/\r | |
89 | EFI_EVENT\r | |
90 | EFIAPI\r | |
91 | EfiCreateProtocolNotifyEvent(\r | |
92 | IN EFI_GUID *ProtocolGuid,\r | |
93 | IN EFI_TPL NotifyTpl,\r | |
94 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
95 | IN VOID *NotifyContext, OPTIONAL\r | |
96 | OUT VOID *Registration\r | |
97 | )\r | |
98 | {\r | |
99 | EFI_STATUS Status;\r | |
100 | EFI_EVENT Event;\r | |
101 | \r | |
102 | //\r | |
103 | // Create the event\r | |
104 | //\r | |
105 | \r | |
106 | Status = gBS->CreateEvent (\r | |
107 | EFI_EVENT_NOTIFY_SIGNAL,\r | |
108 | NotifyTpl,\r | |
109 | NotifyFunction,\r | |
110 | NotifyContext,\r | |
111 | &Event\r | |
112 | );\r | |
113 | ASSERT_EFI_ERROR (Status);\r | |
114 | \r | |
115 | //\r | |
116 | // Register for protocol notifactions on this event\r | |
117 | //\r | |
118 | \r | |
119 | Status = gBS->RegisterProtocolNotify (\r | |
120 | ProtocolGuid,\r | |
121 | Event,\r | |
122 | Registration\r | |
123 | );\r | |
124 | \r | |
125 | ASSERT_EFI_ERROR (Status);\r | |
126 | \r | |
127 | //\r | |
128 | // Kick the event so we will perform an initial pass of\r | |
129 | // current installed drivers\r | |
130 | //\r | |
131 | \r | |
132 | gBS->SignalEvent (Event);\r | |
133 | return Event;\r | |
134 | }\r | |
135 | \r | |
136 | /**\r | |
137 | This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r | |
138 | This event is signaled with EfiNamedEventSignal(). This provide the ability for \r | |
139 | one or more listeners on the same event named by the GUID specified by Name.\r | |
140 | \r | |
141 | @param Name Supplies GUID name of the event.\r | |
142 | @param NotifyTpl Supplies the task priority level of the event notifications.\r | |
143 | @param NotifyFunction Supplies the function to notify when the event is signaled.\r | |
144 | @param NotifyContext The context parameter to pass to NotifyFunction. \r | |
145 | @param Registration A pointer to a memory location to receive the registration value.\r | |
146 | \r | |
147 | @retval EFI_SUCCESS A named event was created.\r | |
148 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.\r | |
149 | \r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | EFIAPI\r | |
153 | EfiNamedEventListen (\r | |
154 | IN CONST EFI_GUID *Name,\r | |
155 | IN EFI_TPL NotifyTpl,\r | |
156 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
157 | IN CONST VOID *NotifyContext, OPTIONAL\r | |
158 | OUT VOID *Registration OPTIONAL\r | |
159 | )\r | |
160 | {\r | |
161 | EFI_STATUS Status;\r | |
162 | EFI_EVENT Event;\r | |
163 | VOID *RegistrationLocal;\r | |
164 | \r | |
165 | //\r | |
166 | // Create event\r | |
167 | //\r | |
168 | Status = gBS->CreateEvent (\r | |
169 | EFI_EVENT_NOTIFY_SIGNAL,\r | |
170 | NotifyTpl,\r | |
171 | NotifyFunction,\r | |
172 | (VOID *) NotifyContext,\r | |
173 | &Event\r | |
174 | );\r | |
175 | ASSERT_EFI_ERROR (Status);\r | |
176 | \r | |
177 | //\r | |
178 | // The Registration is not optional to RegisterProtocolNotify().\r | |
179 | // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r | |
180 | //\r | |
181 | if (Registration != NULL) {\r | |
182 | RegistrationLocal = Registration;\r | |
183 | } else {\r | |
184 | RegistrationLocal = &RegistrationLocal;\r | |
185 | }\r | |
186 | \r | |
187 | //\r | |
188 | // Register for an installation of protocol interface\r | |
189 | //\r | |
190 | \r | |
191 | Status = gBS->RegisterProtocolNotify (\r | |
192 | (EFI_GUID *) Name,\r | |
193 | Event,\r | |
194 | RegistrationLocal\r | |
195 | );\r | |
196 | ASSERT_EFI_ERROR (Status);\r | |
197 | \r | |
198 | return EFI_SUCCESS;\r | |
199 | }\r | |
200 | \r | |
201 | /**\r | |
202 | This function signals the named event specified by Name. The named event must \r | |
203 | have been created with EfiNamedEventListen().\r | |
204 | \r | |
205 | @param Name Supplies GUID name of the event.\r | |
206 | \r | |
207 | @retval EFI_SUCCESS A named event was signaled.\r | |
208 | @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.\r | |
209 | \r | |
210 | **/\r | |
211 | EFI_STATUS\r | |
212 | EFIAPI\r | |
213 | EfiNamedEventSignal (\r | |
214 | IN CONST EFI_GUID *Name\r | |
215 | )\r | |
216 | {\r | |
217 | EFI_STATUS Status;\r | |
218 | EFI_HANDLE Handle;\r | |
219 | \r | |
220 | Handle = NULL;\r | |
221 | Status = gBS->InstallProtocolInterface (\r | |
222 | &Handle,\r | |
223 | (EFI_GUID *) Name,\r | |
224 | EFI_NATIVE_INTERFACE,\r | |
225 | NULL\r | |
226 | );\r | |
227 | ASSERT_EFI_ERROR (Status);\r | |
228 | \r | |
229 | Status = gBS->UninstallProtocolInterface (\r | |
230 | Handle,\r | |
231 | (EFI_GUID *) Name,\r | |
232 | NULL\r | |
233 | );\r | |
234 | ASSERT_EFI_ERROR (Status);\r | |
235 | \r | |
236 | return EFI_SUCCESS;\r | |
237 | }\r | |
238 | \r | |
239 | \r | |
240 | /**\r | |
241 | This function initializes a basic mutual exclusion lock to the released state \r | |
242 | and returns the lock. Each lock provides mutual exclusion access at its task \r | |
243 | priority level. Since there is no preemption or multiprocessor support in EFI,\r | |
244 | acquiring the lock only consists of raising to the locks TPL.\r | |
245 | \r | |
246 | @param Lock A pointer to the lock data structure to initialize.\r | |
247 | @param Priority EFI TPL associated with the lock.\r | |
248 | \r | |
249 | @return The lock.\r | |
250 | \r | |
251 | **/\r | |
252 | EFI_LOCK *\r | |
253 | EFIAPI\r | |
254 | EfiInitializeLock (\r | |
255 | IN OUT EFI_LOCK *Lock,\r | |
256 | IN EFI_TPL Priority\r | |
257 | )\r | |
258 | {\r | |
259 | ASSERT (Lock != NULL);\r | |
260 | ASSERT (Priority <= EFI_TPL_HIGH_LEVEL);\r | |
261 | \r | |
262 | Lock->Tpl = Priority;\r | |
263 | Lock->OwnerTpl = EFI_TPL_APPLICATION;\r | |
264 | Lock->Lock = EfiLockReleased ;\r | |
265 | return Lock;\r | |
266 | }\r | |
267 | \r | |
268 | /**\r | |
269 |