]>
Commit | Line | Data |
---|---|---|
e42e9404 | 1 | /** @file\r |
2 | The internal header file includes the common header files, defines\r | |
3 | internal structure and functions used by SmmCore module.\r | |
4 | \r | |
1bae3e0e | 5 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
e42e9404 | 6 | This program and the accompanying materials are licensed and made available \r |
7 | under the terms and conditions of the BSD License which accompanies this \r | |
8 | distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php \r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _SMM_CORE_H_\r | |
17 | #define _SMM_CORE_H_\r | |
18 | \r | |
19 | #include <PiSmm.h>\r | |
20 | \r | |
21 | #include <Protocol/DxeSmmReadyToLock.h>\r | |
22 | #include <Protocol/SmmReadyToLock.h>\r | |
46ece1ff | 23 | #include <Protocol/SmmEndOfDxe.h>\r |
e42e9404 | 24 | #include <Protocol/CpuIo2.h>\r |
25 | #include <Protocol/SmmCommunication.h>\r | |
26 | #include <Protocol/SmmAccess2.h>\r | |
27 | #include <Protocol/FirmwareVolume2.h> \r | |
28 | #include <Protocol/LoadedImage.h> \r | |
29 | #include <Protocol/DevicePath.h> \r | |
30 | #include <Protocol/Security.h> \r | |
bc2dfdbc | 31 | #include <Protocol/Security2.h>\r |
53ec4d7f SZ |
32 | #include <Protocol/SmmExitBootServices.h>\r |
33 | #include <Protocol/SmmLegacyBoot.h>\r | |
34 | #include <Protocol/SmmReadyToBoot.h>\r | |
e63da9f0 | 35 | #include <Protocol/SmmMemoryAttribute.h>\r |
7b9b55b2 | 36 | #include <Protocol/SmmSxDispatch2.h>\r |
e42e9404 | 37 | \r |
38 | #include <Guid/Apriori.h>\r | |
39 | #include <Guid/EventGroup.h>\r | |
40 | #include <Guid/EventLegacyBios.h>\r | |
84edd20b | 41 | #include <Guid/MemoryProfile.h>\r |
94a1bc12 | 42 | #include <Guid/LoadModuleAtFixedAddress.h>\r |
ca41f3f4 | 43 | #include <Guid/SmiHandlerProfile.h>\r |
a85e7127 | 44 | #include <Guid/EndOfS3Resume.h>\r |
1bae3e0e | 45 | #include <Guid/S3SmmInitDone.h>\r |
e42e9404 | 46 | \r |
47 | #include <Library/BaseLib.h>\r | |
48 | #include <Library/BaseMemoryLib.h>\r | |
49 | #include <Library/PeCoffLib.h>\r | |
e524f680 | 50 | #include <Library/PeCoffGetEntryPointLib.h>\r |
e42e9404 | 51 | #include <Library/CacheMaintenanceLib.h>\r |
52 | #include <Library/DebugLib.h>\r | |
53 | #include <Library/ReportStatusCodeLib.h>\r | |
54 | #include <Library/MemoryAllocationLib.h>\r | |
55 | #include <Library/DevicePathLib.h> \r | |
56 | #include <Library/UefiLib.h> \r | |
3c447c27 | 57 | #include <Library/UefiBootServicesTableLib.h>\r |
58 | #include <Library/PcdLib.h>\r | |
495797c5 | 59 | #include <Library/SmmCorePlatformHookLib.h>\r |
60 | #include <Library/PerformanceLib.h>\r | |
c2cb08df | 61 | #include <Library/TimerLib.h>\r |
3720ee6d | 62 | #include <Library/HobLib.h>\r |
842b1242 | 63 | #include <Library/SmmMemLib.h>\r |
e42e9404 | 64 | \r |
65 | #include "PiSmmCorePrivateData.h"\r | |
e63da9f0 | 66 | #include "HeapGuard.h"\r |
e42e9404 | 67 | \r |
68 | //\r | |
69 | // Used to build a table of SMI Handlers that the SMM Core registers\r | |
70 | //\r | |
71 | typedef struct {\r | |
72 | EFI_SMM_HANDLER_ENTRY_POINT2 Handler;\r | |
73 | EFI_GUID *HandlerType;\r | |
74 | EFI_HANDLE DispatchHandle;\r | |
75 | BOOLEAN UnRegister;\r | |
76 | } SMM_CORE_SMI_HANDLERS;\r | |
77 | \r | |
ca41f3f4 JY |
78 | //\r |
79 | // SMM_HANDLER - used for each SMM handler\r | |
80 | //\r | |
81 | \r | |
82 | #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')\r | |
83 | \r | |
84 | typedef struct {\r | |
85 | UINTN Signature;\r | |
86 | LIST_ENTRY AllEntries; // All entries\r | |
87 | \r | |
88 | EFI_GUID HandlerType; // Type of interrupt\r | |
89 | LIST_ENTRY SmiHandlers; // All handlers\r | |
90 | } SMI_ENTRY;\r | |
91 | \r | |
92 | #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')\r | |
93 | \r | |
94 | typedef struct {\r | |
95 | UINTN Signature;\r | |
96 | LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers\r | |
97 | EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point\r | |
98 | UINTN CallerAddr; // The address of caller who register the SMI handler.\r | |
99 | SMI_ENTRY *SmiEntry;\r | |
100 | VOID *Context; // for profile\r | |
101 | UINTN ContextSize; // for profile\r | |
102 | } SMI_HANDLER;\r | |
103 | \r | |
e42e9404 | 104 | //\r |
105 | // Structure for recording the state of an SMM Driver\r | |
106 | //\r | |
107 | #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')\r | |
108 | \r | |
109 | typedef struct {\r | |
110 | UINTN Signature;\r | |
111 | LIST_ENTRY Link; // mDriverList\r | |
112 | \r | |
113 | LIST_ENTRY ScheduledLink; // mScheduledQueue\r | |
114 | \r | |
115 | EFI_HANDLE FvHandle;\r | |
116 | EFI_GUID FileName;\r | |
117 | EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;\r | |
118 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r | |
119 | \r | |
120 | VOID *Depex;\r | |
121 | UINTN DepexSize;\r | |
122 | \r | |
123 | BOOLEAN Before;\r | |
124 | BOOLEAN After;\r | |
125 | EFI_GUID BeforeAfterGuid;\r | |
126 | \r | |
127 | BOOLEAN Dependent;\r | |
e42e9404 | 128 | BOOLEAN Scheduled;\r |
e42e9404 | 129 | BOOLEAN Initialized;\r |
130 | BOOLEAN DepexProtocolError;\r | |
131 | \r | |
132 | EFI_HANDLE ImageHandle;\r | |
133 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
134 | //\r | |
135 | // Image EntryPoint in SMRAM\r | |
136 | //\r | |
137 | PHYSICAL_ADDRESS ImageEntryPoint;\r | |
138 | //\r | |
139 | // Image Buffer in SMRAM \r | |
140 | //\r | |
141 | PHYSICAL_ADDRESS ImageBuffer;\r | |
142 | //\r | |
143 | // Image Page Number\r | |
144 | //\r | |
145 | UINTN NumberOfPage;\r | |
285a682c JY |
146 | EFI_HANDLE SmmImageHandle;\r |
147 | EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;\r | |
e42e9404 | 148 | } EFI_SMM_DRIVER_ENTRY;\r |
149 | \r | |
150 | #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')\r | |
151 | \r | |
152 | ///\r | |
153 | /// IHANDLE - contains a list of protocol handles\r | |
154 | ///\r | |
155 | typedef struct {\r | |
156 | UINTN Signature;\r | |
157 | /// All handles list of IHANDLE\r | |
158 | LIST_ENTRY AllHandles;\r | |
159 | /// List of PROTOCOL_INTERFACE's for this handle\r | |
160 | LIST_ENTRY Protocols;\r | |
161 | UINTN LocateRequest;\r | |
162 | } IHANDLE;\r | |
163 | \r | |
164 | #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r | |
165 | \r | |
166 | #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')\r | |
167 | \r | |
168 | ///\r | |
169 | /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol\r | |
170 | /// database. Each handler that supports this protocol is listed, along\r | |
171 | /// with a list of registered notifies.\r | |
172 | ///\r | |
173 | typedef struct {\r | |
174 | UINTN Signature;\r | |
175 | /// Link Entry inserted to mProtocolDatabase\r | |
176 | LIST_ENTRY AllEntries;\r | |
177 | /// ID of the protocol\r | |
178 | EFI_GUID ProtocolID;\r | |
179 | /// All protocol interfaces\r | |
180 | LIST_ENTRY Protocols;\r | |
181 | /// Registerd notification handlers\r | |
182 | LIST_ENTRY Notify;\r | |
183 | } PROTOCOL_ENTRY;\r | |
184 | \r | |
185 | #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')\r | |
186 | \r | |
187 | ///\r | |
188 | /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked\r | |
189 | /// with a protocol interface structure\r | |
190 | ///\r | |
191 | typedef struct {\r | |
192 | UINTN Signature;\r | |
193 | /// Link on IHANDLE.Protocols\r | |
194 | LIST_ENTRY Link;\r | |
195 | /// Back pointer\r | |
196 | IHANDLE *Handle;\r | |
197 | /// Link on PROTOCOL_ENTRY.Protocols\r | |
198 | LIST_ENTRY ByProtocol;\r | |
199 | /// The protocol ID\r | |
200 | PROTOCOL_ENTRY *Protocol;\r | |
201 | /// The interface value\r | |
202 | VOID *Interface;\r | |
203 | } PROTOCOL_INTERFACE;\r | |
204 | \r | |
205 | #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')\r | |
206 | \r | |
207 | ///\r | |
208 | /// PROTOCOL_NOTIFY - used for each register notification for a protocol\r | |
209 | ///\r | |
210 | typedef struct {\r | |
211 | UINTN Signature;\r | |
212 | PROTOCOL_ENTRY *Protocol;\r | |
213 | /// All notifications for this protocol\r | |
214 | LIST_ENTRY Link;\r | |
215 | /// Notification function\r | |
216 | EFI_SMM_NOTIFY_FN Function;\r | |
217 | /// Last position notified\r | |
218 | LIST_ENTRY *Position;\r | |
219 | } PROTOCOL_NOTIFY;\r | |
220 | \r | |
221 | //\r | |
222 | // SMM Core Global Variables\r | |
223 | //\r | |
224 | extern SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r | |
225 | extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst;\r | |
226 | extern LIST_ENTRY gHandleList;\r | |
3c447c27 | 227 | extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase;\r |
e42e9404 | 228 | \r |
229 | /**\r | |
230 | Called to initialize the memory service.\r | |
231 | \r | |
232 | @param SmramRangeCount Number of SMRAM Regions\r | |
233 | @param SmramRanges Pointer to SMRAM Descriptors\r | |
234 | \r | |
235 | **/\r | |
236 | VOID\r | |
237 | SmmInitializeMemoryServices (\r | |
238 | IN UINTN SmramRangeCount,\r | |
239 | IN EFI_SMRAM_DESCRIPTOR *SmramRanges\r | |
240 | );\r | |
241 | \r | |
242 | /**\r | |
243 | The SmmInstallConfigurationTable() function is used to maintain the list\r | |
244 | of configuration tables that are stored in the System Management System\r | |
245 | Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r | |
246 | must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r | |
247 | \r | |
248 | @param SystemTable A pointer to the SMM System Table (SMST).\r | |
249 | @param Guid A pointer to the GUID for the entry to add, update, or remove.\r | |
250 | @param Table A pointer to the buffer of the table to add.\r | |
251 | @param TableSize The size of the table to install.\r | |
252 | \r | |
253 | @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r | |
254 | @retval EFI_INVALID_PARAMETER Guid is not valid.\r | |
255 | @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r | |
256 | @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r | |
257 | \r | |
258 | **/\r | |
259 | EFI_STATUS\r | |
260 | EFIAPI\r | |
261 | SmmInstallConfigurationTable (\r | |
262 | IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r | |
263 | IN CONST EFI_GUID *Guid,\r | |
264 | IN VOID *Table,\r | |
265 | IN UINTN TableSize\r | |
266 | );\r | |
267 | \r | |
268 | /**\r | |
269 | Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which\r | |
270 | Calls the private one which contains a BOOLEAN parameter for notifications\r | |
271 | \r | |
272 | @param UserHandle The handle to install the protocol handler on,\r | |
273 | or NULL if a new handle is to be allocated\r | |
274 | @param Protocol The protocol to add to the handle\r | |
275 | @param InterfaceType Indicates whether Interface is supplied in\r | |
276 | native form.\r | |
277 | @param Interface The interface for the protocol being added\r | |
278 | \r | |
279 | @return Status code\r | |
280 | \r | |
281 | **/\r | |
282 | EFI_STATUS\r | |
283 | EFIAPI\r | |
284 | SmmInstallProtocolInterface (\r | |
285 | IN OUT EFI_HANDLE *UserHandle,\r | |
286 | IN EFI_GUID *Protocol,\r | |
287 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
288 | IN VOID *Interface\r | |
289 | );\r | |
290 | \r | |
291 | /**\r | |
292 | Allocates pages from the memory map.\r | |
293 | \r | |
294 | @param Type The type of allocation to perform\r | |
295 | @param MemoryType The type of memory to turn the allocated pages\r | |
296 | into\r | |
297 | @param NumberOfPages The number of pages to allocate\r | |
298 | @param Memory A pointer to receive the base allocated memory\r | |
299 | address\r | |
300 | \r | |
301 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r | |
302 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r | |
303 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r | |
304 | @retval EFI_SUCCESS Pages successfully allocated.\r | |
305 | \r | |
306 | **/\r | |
307 | EFI_STATUS\r | |
308 | EFIAPI\r | |
309 | SmmAllocatePages (\r | |
310 | IN EFI_ALLOCATE_TYPE Type,\r | |
311 | IN EFI_MEMORY_TYPE MemoryType,\r | |
312 | IN UINTN NumberOfPages,\r | |
313 | OUT EFI_PHYSICAL_ADDRESS *Memory\r | |
314 | );\r | |
315 | \r | |
84edd20b SZ |
316 | /**\r |
317 | Allocates pages from the memory map.\r | |
318 | \r | |
319 | @param Type The type of allocation to perform\r | |
320 | @param MemoryType The type of memory to turn the allocated pages\r | |
321 | into\r | |
322 | @param NumberOfPages The number of pages to allocate\r | |
323 | @param Memory A pointer to receive the base allocated memory\r | |
324 | address\r | |
e63da9f0 | 325 | @param NeedGuard Flag to indicate Guard page is needed or not\r |
84edd20b SZ |
326 | \r |
327 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r | |
328 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r | |
329 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r | |
330 | @retval EFI_SUCCESS Pages successfully allocated.\r | |
331 | \r | |
332 | **/\r | |
333 | EFI_STATUS\r | |
334 | EFIAPI\r | |
335 | SmmInternalAllocatePages (\r | |
336 | IN EFI_ALLOCATE_TYPE Type,\r | |
337 | IN EFI_MEMORY_TYPE MemoryType,\r | |
338 | IN UINTN NumberOfPages,\r | |
e63da9f0 JW |
339 | OUT EFI_PHYSICAL_ADDRESS *Memory,\r |
340 | IN BOOLEAN NeedGuard\r | |
84edd20b SZ |
341 | );\r |
342 | \r | |
e42e9404 | 343 | /**\r |
344 | Frees previous allocated pages.\r | |
345 | \r | |
346 | @param Memory Base address of memory being freed\r | |
347 | @param NumberOfPages The number of pages to free\r | |
348 | \r | |
349 | @retval EFI_NOT_FOUND Could not find the entry that covers the range\r | |
ddfae264 | 350 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r |
e42e9404 | 351 | @return EFI_SUCCESS Pages successfully freed.\r |
352 | \r | |
353 | **/\r | |
354 | EFI_STATUS\r | |
355 | EFIAPI\r | |
356 | SmmFreePages (\r | |
357 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
358 | IN UINTN NumberOfPages\r | |
359 | );\r | |
360 | \r | |
84edd20b SZ |
361 | /**\r |
362 | Frees previous allocated pages.\r | |
363 | \r | |
364 | @param Memory Base address of memory being freed\r | |
365 | @param NumberOfPages The number of pages to free\r | |
e63da9f0 JW |
366 | @param IsGuarded Flag to indicate if the memory is guarded\r |
367 | or not\r | |
84edd20b SZ |
368 | \r |
369 | @retval EFI_NOT_FOUND Could not find the entry that covers the range\r | |
ddfae264 | 370 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r |
84edd20b SZ |
371 | @return EFI_SUCCESS Pages successfully freed.\r |
372 | \r | |
373 | **/\r | |
374 | EFI_STATUS\r | |
375 | EFIAPI\r | |
376 | SmmInternalFreePages (\r | |
377 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
e63da9f0 JW |
378 | IN UINTN NumberOfPages,\r |
379 | IN BOOLEAN IsGuarded\r | |
84edd20b SZ |
380 | );\r |
381 | \r | |
e42e9404 | 382 | /**\r |
383 | Allocate pool of a particular type.\r | |
384 | \r | |
385 | @param PoolType Type of pool to allocate\r | |
386 | @param Size The amount of pool to allocate\r | |
387 | @param Buffer The address to return a pointer to the allocated\r | |
388 | pool\r | |
389 | \r | |
390 | @retval EFI_INVALID_PARAMETER PoolType not valid\r | |
391 | @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r | |
392 | @retval EFI_SUCCESS Pool successfully allocated.\r | |
393 | \r | |
394 | **/\r | |
395 | EFI_STATUS\r | |
396 | EFIAPI\r | |
397 | SmmAllocatePool (\r | |
398 | IN EFI_MEMORY_TYPE PoolType,\r | |
399 | IN UINTN Size,\r | |
400 | OUT VOID **Buffer\r | |
401 | );\r | |
402 | \r | |
84edd20b SZ |
403 | /**\r |
404 | Allocate pool of a particular type.\r | |
405 | \r | |
406 | @param PoolType Type of pool to allocate\r | |
407 | @param Size The amount of pool to allocate\r | |
408 | @param Buffer The address to return a pointer to the allocated\r | |
409 | pool\r | |
410 | \r | |
411 | @retval EFI_INVALID_PARAMETER PoolType not valid\r | |
412 | @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r | |
413 | @retval EFI_SUCCESS Pool successfully allocated.\r | |
414 | \r | |
415 | **/\r | |
416 | EFI_STATUS\r | |
417 | EFIAPI\r | |
418 | SmmInternalAllocatePool (\r | |
419 | IN EFI_MEMORY_TYPE PoolType,\r | |
420 | IN UINTN Size,\r | |
421 | OUT VOID **Buffer\r | |
422 | );\r | |
423 | \r | |
e42e9404 | 424 | /**\r |
425 | Frees pool.\r | |
426 | \r | |
427 | @param Buffer The allocated pool entry to free\r | |
428 | \r | |
429 | @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r | |
430 | @retval EFI_SUCCESS Pool successfully freed.\r | |
431 | \r | |
432 | **/\r | |
433 | EFI_STATUS\r | |
434 | EFIAPI\r | |
435 | SmmFreePool (\r | |
436 | IN VOID *Buffer\r | |
437 | );\r | |
438 | \r | |
84edd20b SZ |
439 | /**\r |
440 | Frees pool.\r | |
441 | \r | |
442 | @param Buffer The allocated pool entry to free\r | |
443 | \r | |
444 | @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r | |
445 | @retval EFI_SUCCESS Pool successfully freed.\r | |
446 | \r | |
447 | **/\r | |
448 | EFI_STATUS\r | |
449 | EFIAPI\r | |
450 | SmmInternalFreePool (\r | |
451 | IN VOID *Buffer\r | |
452 | );\r | |
453 | \r | |
e42e9404 | 454 | /**\r |
455 | Installs a protocol interface into the boot services environment.\r | |
456 | \r | |
457 | @param UserHandle The handle to install the protocol handler on,\r | |
458 | or NULL if a new handle is to be allocated\r | |
459 | @param Protocol The protocol to add to the handle\r | |
460 | @param InterfaceType Indicates whether Interface is supplied in\r | |
461 | native form.\r | |
462 | @param Interface The interface for the protocol being added\r | |
463 | @param Notify indicates whether notify the notification list\r | |
464 | for this protocol\r | |
465 | \r | |
466 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
467 | @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate\r | |
468 | @retval EFI_SUCCESS Protocol interface successfully installed\r | |
469 | \r | |
470 | **/\r | |
471 | EFI_STATUS\r | |
472 | SmmInstallProtocolInterfaceNotify (\r | |
473 | IN OUT EFI_HANDLE *UserHandle,\r | |
474 | IN EFI_GUID *Protocol,\r | |
475 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
476 | IN VOID *Interface,\r | |
477 | IN BOOLEAN Notify\r | |
478 | );\r | |
479 | \r | |
480 | /**\r | |
481 | Uninstalls all instances of a protocol:interfacer from a handle.\r | |
482 | If the last protocol interface is remove from the handle, the\r | |
483 | handle is freed.\r | |
484 | \r | |
485 | @param UserHandle The handle to remove the protocol handler from\r | |
486 | @param Protocol The protocol, of protocol:interface, to remove\r | |
487 | @param Interface The interface, of protocol:interface, to remove\r | |
488 | \r | |
489 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r | |
490 | @retval EFI_SUCCESS Protocol interface successfully uninstalled.\r | |
491 | \r | |
492 | **/\r | |
493 | EFI_STATUS\r | |
494 | EFIAPI\r | |
495 | SmmUninstallProtocolInterface (\r | |
496 | IN EFI_HANDLE UserHandle,\r | |
497 | IN EFI_GUID *Protocol,\r | |
498 | IN VOID *Interface\r | |
499 | );\r | |
500 | \r | |
501 | /**\r | |
502 | Queries a handle to determine if it supports a specified protocol.\r | |
503 | \r | |
504 | @param UserHandle The handle being queried.\r | |
505 | @param Protocol The published unique identifier of the protocol.\r | |
506 | @param Interface Supplies the address where a pointer to the\r | |
507 | corresponding Protocol Interface is returned.\r | |
508 | \r | |
509 | @return The requested protocol interface for the handle\r | |
510 | \r | |
511 | **/\r | |
512 | EFI_STATUS\r | |
513 | EFIAPI\r | |
514 | SmmHandleProtocol (\r | |
515 | IN EFI_HANDLE UserHandle,\r | |
516 | IN EFI_GUID *Protocol,\r | |
517 | OUT VOID **Interface\r | |
518 | );\r | |
519 | \r | |
520 | /**\r | |
521 | Add a new protocol notification record for the request protocol.\r | |
522 | \r | |
523 | @param Protocol The requested protocol to add the notify\r | |
524 | registration\r | |
525 | @param Function Points to the notification function\r | |
526 | @param Registration Returns the registration record\r | |
527 | \r | |
528 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
529 | @retval EFI_SUCCESS Successfully returned the registration record\r | |
530 | that has been added\r | |
531 | \r | |
532 | **/\r | |
533 | EFI_STATUS\r | |
534 | EFIAPI\r | |
535 | SmmRegisterProtocolNotify (\r | |
536 | IN CONST EFI_GUID *Protocol,\r | |
537 | IN EFI_SMM_NOTIFY_FN Function,\r | |
538 | OUT VOID **Registration\r | |
539 | );\r | |
540 | \r | |
541 | /**\r | |
542 | Locates the requested handle(s) and returns them in Buffer.\r | |
543 | \r | |
544 | @param SearchType The type of search to perform to locate the\r | |
545 | handles\r | |
546 | @param Protocol The protocol to search for\r | |
547 | @param SearchKey Dependant on SearchType\r | |
548 | @param BufferSize On input the size of Buffer. On output the\r | |
549 | size of data returned.\r | |
550 | @param Buffer The buffer to return the results in\r | |
551 | \r | |
552 | @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is\r | |
553 | returned in BufferSize.\r | |
554 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
555 | @retval EFI_SUCCESS Successfully found the requested handle(s) and\r | |
556 | returns them in Buffer.\r | |
557 | \r | |
558 | **/\r | |
559 | EFI_STATUS\r | |
560 | EFIAPI\r | |
561 | SmmLocateHandle (\r | |
562 | IN EFI_LOCATE_SEARCH_TYPE SearchType,\r | |
563 | IN EFI_GUID *Protocol OPTIONAL,\r | |
564 | IN VOID *SearchKey OPTIONAL,\r | |
565 | IN OUT UINTN *BufferSize,\r | |
566 | OUT EFI_HANDLE *Buffer\r | |
567 | );\r | |
568 | \r | |
569 | /**\r | |
570 | Return the first Protocol Interface that matches the Protocol GUID. If\r | |
571 | Registration is pasased in return a Protocol Instance that was just add\r | |
572 | to the system. If Retistration is NULL return the first Protocol Interface\r | |
573 | you find.\r | |
574 | \r | |
575 | @param Protocol The protocol to search for\r | |
576 | @param Registration Optional Registration Key returned from\r | |
577 | RegisterProtocolNotify()\r | |
578 | @param Interface Return the Protocol interface (instance).\r | |
579 | \r | |
580 | @retval EFI_SUCCESS If a valid Interface is returned\r | |
581 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
582 | @retval EFI_NOT_FOUND Protocol interface not found\r | |
583 | \r | |
584 | **/\r | |
585 | EFI_STATUS\r | |
586 | EFIAPI\r | |
587 | SmmLocateProtocol (\r | |
588 | IN EFI_GUID *Protocol,\r | |
589 | IN VOID *Registration OPTIONAL,\r | |
590 | OUT VOID **Interface\r | |
591 | );\r | |
592 | \r | |
285a682c JY |
593 | /**\r |
594 | Function returns an array of handles that support the requested protocol\r | |
595 | in a buffer allocated from pool. This is a version of SmmLocateHandle()\r | |
596 | that allocates a buffer for the caller.\r | |
597 | \r | |
598 | @param SearchType Specifies which handle(s) are to be returned.\r | |
599 | @param Protocol Provides the protocol to search by. This\r | |
600 | parameter is only valid for SearchType\r | |
601 | ByProtocol.\r | |
602 | @param SearchKey Supplies the search key depending on the\r | |
603 | SearchType.\r | |
604 | @param NumberHandles The number of handles returned in Buffer.\r | |
605 | @param Buffer A pointer to the buffer to return the requested\r | |
606 | array of handles that support Protocol.\r | |
607 | \r | |
608 | @retval EFI_SUCCESS The result array of handles was returned.\r | |
609 | @retval EFI_NOT_FOUND No handles match the search.\r | |
610 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the\r | |
611 | matching results.\r | |
612 | @retval EFI_INVALID_PARAMETER One or more paramters are not valid.\r | |
613 | \r | |
614 | **/\r | |
615 | EFI_STATUS\r | |
616 | EFIAPI\r | |
617 | SmmLocateHandleBuffer (\r | |
618 | IN EFI_LOCATE_SEARCH_TYPE SearchType,\r | |
619 | IN EFI_GUID *Protocol OPTIONAL,\r | |
620 | IN VOID *SearchKey OPTIONAL,\r | |
621 | IN OUT UINTN *NumberHandles,\r | |
622 | OUT EFI_HANDLE **Buffer\r | |
623 | );\r | |
624 | \r | |
e42e9404 | 625 | /**\r |
626 | Manage SMI of a particular type.\r | |
627 | \r | |
628 | @param HandlerType Points to the handler type or NULL for root SMI handlers.\r | |
629 | @param Context Points to an optional context buffer.\r | |
630 | @param CommBuffer Points to the optional communication buffer.\r | |
631 | @param CommBufferSize Points to the size of the optional communication buffer.\r | |
632 | \r | |
633 | @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.\r | |
634 | @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.\r | |
635 | @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.\r | |
636 | @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.\r | |
637 | \r | |
638 | **/\r | |
639 | EFI_STATUS\r | |
640 | EFIAPI\r | |
641 | SmiManage (\r | |
642 | IN CONST EFI_GUID *HandlerType,\r | |
643 | IN CONST VOID *Context OPTIONAL,\r | |
644 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
645 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
646 | );\r | |
647 | \r | |
648 | /**\r | |
649 | Registers a handler to execute within SMM.\r | |
650 | \r | |
651 | @param Handler Handler service funtion pointer.\r | |
652 | @param HandlerType Points to the handler type or NULL for root SMI handlers.\r | |
653 | @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.\r | |
654 | \r | |
655 | @retval EFI_SUCCESS Handler register success.\r | |
656 | @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.\r | |
657 | \r | |
658 | **/\r | |
659 | EFI_STATUS\r | |
660 | EFIAPI\r | |
661 | SmiHandlerRegister (\r | |
662 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r | |
663 | IN CONST EFI_GUID *HandlerType OPTIONAL,\r | |
664 | OUT EFI_HANDLE *DispatchHandle\r | |
665 | );\r | |
666 | \r | |
667 | /**\r | |
668 | Unregister a handler in SMM.\r | |
669 | \r | |
670 | @param DispatchHandle The handle that was specified when the handler was registered.\r | |
671 | \r | |
672 | @retval EFI_SUCCESS Handler function was successfully unregistered.\r | |
673 | @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.\r | |
674 | \r | |
675 | **/\r | |
676 | EFI_STATUS\r | |
677 | EFIAPI\r | |
678 | SmiHandlerUnRegister (\r | |
679 | IN EFI_HANDLE DispatchHandle\r | |
680 | );\r | |
681 | \r | |
682 | /**\r | |
683 | This function is the main entry point for an SMM handler dispatch\r | |
684 | or communicate-based callback.\r | |
685 | \r | |
686 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
687 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
688 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
689 | be conveyed from a non-SMM environment into an SMM environment.\r | |
690 | @param CommBufferSize The size of the CommBuffer.\r | |
691 | \r | |
692 | @return Status Code\r | |
693 | \r | |
694 | **/\r | |
695 | EFI_STATUS\r | |
696 | EFIAPI\r | |
697 | SmmDriverDispatchHandler (\r | |
698 | IN EFI_HANDLE DispatchHandle,\r | |
699 | IN CONST VOID *Context, OPTIONAL\r | |
700 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
701 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
702 | );\r | |
703 | \r | |
704 | /**\r | |
705 | This function is the main entry point for an SMM handler dispatch\r | |
706 | or communicate-based callback.\r | |
707 | \r | |
708 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
709 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
710 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
711 | be conveyed from a non-SMM environment into an SMM environment.\r | |
712 | @param CommBufferSize The size of the CommBuffer.\r | |
713 | \r | |
714 | @return Status Code\r | |
715 | \r | |
716 | **/\r | |
717 | EFI_STATUS\r | |
718 | EFIAPI\r | |
719 | SmmLegacyBootHandler (\r | |
720 | IN EFI_HANDLE DispatchHandle,\r | |
721 | IN CONST VOID *Context, OPTIONAL\r | |
722 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
723 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
724 | );\r | |
725 | \r | |
726 | /**\r | |
727 | This function is the main entry point for an SMM handler dispatch\r | |
728 | or communicate-based callback.\r | |
729 | \r | |
730 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
731 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
732 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
733 | be conveyed from a non-SMM environment into an SMM environment.\r | |
734 | @param CommBufferSize The size of the CommBuffer.\r | |
735 | \r | |
736 | @return Status Code\r | |
737 | \r | |
738 | **/\r | |
739 | EFI_STATUS\r | |
740 | EFIAPI\r | |
741 | SmmReadyToLockHandler (\r | |
742 | IN EFI_HANDLE DispatchHandle,\r | |
743 | IN CONST VOID *Context, OPTIONAL\r | |
744 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
745 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
746 | );\r | |
747 | \r | |
46ece1ff JY |
748 | /**\r |
749 | This function is the main entry point for an SMM handler dispatch\r | |
750 | or communicate-based callback.\r | |
751 | \r | |
752 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
753 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
754 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
755 | be conveyed from a non-SMM environment into an SMM environment.\r | |
756 | @param CommBufferSize The size of the CommBuffer.\r | |
757 | \r | |
758 | @return Status Code\r | |
759 | \r | |
760 | **/\r | |
761 | EFI_STATUS\r | |
762 | EFIAPI\r | |
763 | SmmEndOfDxeHandler (\r | |
764 | IN EFI_HANDLE DispatchHandle,\r | |
765 | IN CONST VOID *Context, OPTIONAL\r | |
766 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
767 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
768 | );\r | |
769 | \r | |
53ec4d7f SZ |
770 | /**\r |
771 | This function is the main entry point for an SMM handler dispatch\r | |
772 | or communicate-based callback.\r | |
773 | \r | |
774 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
775 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
776 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
777 | be conveyed from a non-SMM environment into an SMM environment.\r | |
778 | @param CommBufferSize The size of the CommBuffer.\r | |
779 | \r | |
780 | @return Status Code\r | |
781 | \r | |
782 | **/\r | |
783 | EFI_STATUS\r | |
784 | EFIAPI\r | |
785 | SmmExitBootServicesHandler (\r | |
786 | IN EFI_HANDLE DispatchHandle,\r | |
787 | IN CONST VOID *Context, OPTIONAL\r | |
788 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
789 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
790 | );\r | |
791 | \r | |
792 | /**\r | |
793 | This function is the main entry point for an SMM handler dispatch\r | |
794 | or communicate-based callback.\r | |
795 | \r | |
796 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
797 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
798 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
799 | be conveyed from a non-SMM environment into an SMM environment.\r | |
800 | @param CommBufferSize The size of the CommBuffer.\r | |
801 | \r | |
802 | @return Status Code\r | |
803 | \r | |
804 | **/\r | |
805 | EFI_STATUS\r | |
806 | EFIAPI\r | |
807 | SmmReadyToBootHandler (\r | |
808 | IN EFI_HANDLE DispatchHandle,\r | |
809 | IN CONST VOID *Context, OPTIONAL\r | |
810 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
811 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
812 | );\r | |
813 | \r | |
1bae3e0e SZ |
814 | /**\r |
815 | Software SMI handler that is called when the S3SmmInitDone signal is triggered.\r | |
816 | This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that\r | |
817 | S3 SMM initialization has been done.\r | |
818 | \r | |
819 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
820 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
821 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
822 | be conveyed from a non-SMM environment into an SMM environment.\r | |
823 | @param CommBufferSize The size of the CommBuffer.\r | |
824 | \r | |
825 | @return Status Code\r | |
826 | \r | |
827 | **/\r | |
828 | EFI_STATUS\r | |
829 | EFIAPI\r | |
830 | SmmS3SmmInitDoneHandler (\r | |
831 | IN EFI_HANDLE DispatchHandle,\r | |
832 | IN CONST VOID *Context, OPTIONAL\r | |
833 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
834 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
835 | );\r | |
836 | \r | |
d76c2da8 ED |
837 | /**\r |
838 | Software SMI handler that is called when the EndOfS3Resume event is trigged.\r | |
839 | This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that\r | |
840 | S3 resume has finished.\r | |
841 | \r | |
842 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
843 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
844 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
845 | be conveyed from a non-SMM environment into an SMM environment.\r | |
846 | @param CommBufferSize The size of the CommBuffer.\r | |
847 | \r | |
848 | @return Status Code\r | |
849 | \r | |
850 | **/\r | |
851 | EFI_STATUS\r | |
852 | EFIAPI\r | |
853 | SmmEndOfS3ResumeHandler (\r | |
854 | IN EFI_HANDLE DispatchHandle,\r | |
855 | IN CONST VOID *Context, OPTIONAL\r | |
856 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
857 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
858 | );\r | |
859 | \r | |
e42e9404 | 860 | /**\r |
861 | Place holder function until all the SMM System Table Service are available.\r | |
862 | \r | |
863 | @param Arg1 Undefined\r | |
864 | @param Arg2 Undefined\r | |
865 | @param Arg3 Undefined\r | |
866 | @param Arg4 Undefined\r | |
867 | @param Arg5 Undefined\r | |
868 | \r | |
869 | @return EFI_NOT_AVAILABLE_YET\r | |
870 | \r | |
871 | **/\r | |
872 | EFI_STATUS\r | |
873 | EFIAPI\r | |
874 | SmmEfiNotAvailableYetArg5 (\r | |
875 | UINTN Arg1,\r | |
876 | UINTN Arg2,\r | |
877 | UINTN Arg3,\r | |
878 | UINTN Arg4,\r | |
879 | UINTN Arg5\r | |
880 | );\r | |
881 | \r | |
882 | //\r | |
883 | //Functions used during debug buils\r | |
884 | //\r | |
885 | \r | |
886 | /**\r | |
887 | Traverse the discovered list for any drivers that were discovered but not loaded\r | |
888 | because the dependency experessions evaluated to false.\r | |
889 | \r | |
890 | **/\r | |
891 | VOID\r | |
892 | SmmDisplayDiscoveredNotDispatched (\r | |
893 | VOID\r | |
894 | );\r | |
895 | \r | |
896 | /**\r | |
897 | Add free SMRAM region for use by memory service.\r | |
898 | \r | |
899 | @param MemBase Base address of memory region.\r | |
900 | @param MemLength Length of the memory region.\r | |
901 | @param Type Memory type.\r | |
902 | @param Attributes Memory region state.\r | |
903 | \r | |
904 | **/\r | |
905 | VOID\r | |
906 | SmmAddMemoryRegion (\r | |
907 | IN EFI_PHYSICAL_ADDRESS MemBase,\r | |
908 | IN UINT64 MemLength,\r | |
909 | IN EFI_MEMORY_TYPE Type,\r | |
910 | IN UINT64 Attributes\r | |
911 | );\r | |
912 | \r | |
913 | /**\r | |
914 | Finds the protocol entry for the requested protocol.\r | |
915 | \r | |
916 | @param Protocol The ID of the protocol\r | |
917 | @param Create Create a new entry if not found\r | |
918 | \r | |
919 | @return Protocol entry\r | |
920 | \r | |
921 | **/\r | |
922 | PROTOCOL_ENTRY *\r | |
923 | SmmFindProtocolEntry (\r | |
924 | IN EFI_GUID *Protocol,\r | |
925 | IN BOOLEAN Create\r | |
926 | );\r | |
927 | \r | |
928 | /**\r | |
929 | Signal event for every protocol in protocol entry.\r | |
930 | \r | |
931 | @param Prot Protocol interface\r | |
932 | \r | |
933 | **/\r | |
934 | VOID\r | |
935 | SmmNotifyProtocol (\r | |
936 | IN PROTOCOL_INTERFACE *Prot\r | |
937 | );\r | |
938 | \r | |
939 | /**\r | |
940 | Finds the protocol instance for the requested handle and protocol.\r | |
941 | Note: This function doesn't do parameters checking, it's caller's responsibility\r | |
942 | to pass in valid parameters.\r | |
943 | \r | |
944 | @param Handle The handle to search the protocol on\r | |
945 | @param Protocol GUID of the protocol\r | |
946 | @param Interface The interface for the protocol being searched\r | |
947 | \r | |
948 | @return Protocol instance (NULL: Not found)\r | |
949 | \r | |
950 | **/\r | |
951 | PROTOCOL_INTERFACE *\r | |
952 | SmmFindProtocolInterface (\r | |
953 | IN IHANDLE *Handle,\r | |
954 | IN EFI_GUID *Protocol,\r | |
955 | IN VOID *Interface\r | |
956 | );\r | |
957 | \r | |
958 | /**\r | |
959 | Removes Protocol from the protocol list (but not the handle list).\r | |
960 | \r | |
961 | @param Handle The handle to remove protocol on.\r | |
962 | @param Protocol GUID of the protocol to be moved\r | |
963 | @param Interface The interface of the protocol\r | |
964 | \r | |
965 | @return Protocol Entry\r | |
966 | \r | |
967 | **/\r | |
968 | PROTOCOL_INTERFACE *\r | |
969 | SmmRemoveInterfaceFromProtocol (\r | |
970 | IN IHANDLE *Handle,\r | |
971 | IN EFI_GUID *Protocol,\r | |
972 | IN VOID *Interface\r | |
973 | );\r | |
974 | \r | |
975 | /**\r | |
976 | This is the POSTFIX version of the dependency evaluator. This code does\r | |
977 | not need to handle Before or After, as it is not valid to call this\r | |
fa542a1e | 978 | routine in this case. POSTFIX means all the math is done on top of the stack.\r |
e42e9404 | 979 | \r |
980 | @param DriverEntry DriverEntry element to update.\r | |
981 | \r | |
982 | @retval TRUE If driver is ready to run.\r | |
983 | @retval FALSE If driver is not ready to run or some fatal error\r | |
984 | was found.\r | |
985 | \r | |
986 | **/\r | |
987 | BOOLEAN\r | |
988 | SmmIsSchedulable (\r | |
989 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r | |
990 | );\r | |
991 | \r | |
84edd20b SZ |
992 | //\r |
993 | // SmramProfile\r | |
994 | //\r | |
995 | \r | |
996 | /**\r | |
997 | Initialize SMRAM profile.\r | |
998 | \r | |
999 | **/\r | |
1000 | VOID\r | |
1001 | SmramProfileInit (\r | |
1002 | VOID\r | |
1003 | );\r | |
1004 | \r | |
e524f680 SZ |
1005 | /**\r |
1006 | Install SMRAM profile protocol.\r | |
1007 | \r | |
1008 | **/\r | |
1009 | VOID\r | |
1010 | SmramProfileInstallProtocol (\r | |
1011 | VOID\r | |
1012 | );\r | |
1013 | \r | |
84edd20b SZ |
1014 | /**\r |
1015 | Register SMM image to SMRAM profile.\r | |
1016 | \r | |
1017 | @param DriverEntry SMM image info.\r | |
1018 | @param RegisterToDxe Register image to DXE.\r | |
1019 | \r | |
e524f680 SZ |
1020 | @return EFI_SUCCESS Register successfully.\r |
1021 | @return EFI_UNSUPPORTED Memory profile unsupported,\r | |
1022 | or memory profile for the image is not required.\r | |
1023 | @return EFI_OUT_OF_RESOURCES No enough resource for this register.\r | |
84edd20b SZ |
1024 | \r |
1025 | **/\r | |
e524f680 | 1026 | EFI_STATUS\r |
84edd20b SZ |
1027 | RegisterSmramProfileImage (\r |
1028 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r | |
1029 | IN BOOLEAN RegisterToDxe\r | |
1030 | );\r | |
1031 | \r | |
1032 | /**\r | |
1033 | Unregister image from SMRAM profile.\r | |
1034 | \r | |
1035 | @param DriverEntry SMM image info.\r | |
1036 | @param UnregisterToDxe Unregister image from DXE.\r | |
1037 | \r | |
e524f680 SZ |
1038 | @return EFI_SUCCESS Unregister successfully.\r |
1039 | @return EFI_UNSUPPORTED Memory profile unsupported,\r | |
1040 | or memory profile for the image is not required.\r | |
1041 | @return EFI_NOT_FOUND The image is not found.\r | |
84edd20b SZ |
1042 | \r |
1043 | **/\r | |
e524f680 | 1044 | EFI_STATUS\r |
84edd20b SZ |
1045 | UnregisterSmramProfileImage (\r |
1046 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r | |
1047 | IN BOOLEAN UnregisterToDxe\r | |
1048 | );\r | |
1049 | \r | |
1050 | /**\r | |
1051 | Update SMRAM profile information.\r | |
1052 | \r | |
1053 | @param CallerAddress Address of caller who call Allocate or Free.\r | |
1054 | @param Action This Allocate or Free action.\r | |
1055 | @param MemoryType Memory type.\r | |
e524f680 | 1056 | EfiMaxMemoryType means the MemoryType is unknown.\r |
84edd20b SZ |
1057 | @param Size Buffer size.\r |
1058 | @param Buffer Buffer address.\r | |
e524f680 SZ |
1059 | @param ActionString String for memory profile action.\r |
1060 | Only needed for user defined allocate action.\r | |
84edd20b | 1061 | \r |
e524f680 SZ |
1062 | @return EFI_SUCCESS Memory profile is updated.\r |
1063 | @return EFI_UNSUPPORTED Memory profile is unsupported,\r | |
1064 | or memory profile for the image is not required,\r | |
1065 | or memory profile for the memory type is not required.\r | |
1066 | @return EFI_ACCESS_DENIED It is during memory profile data getting.\r | |
1067 | @return EFI_ABORTED Memory profile recording is not enabled.\r | |
1068 | @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r | |
1069 | @return EFI_NOT_FOUND No matched allocate info found for free action.\r | |
84edd20b SZ |
1070 | \r |
1071 | **/\r | |
e524f680 SZ |
1072 | EFI_STATUS\r |
1073 | EFIAPI\r | |
84edd20b | 1074 | SmmCoreUpdateProfile (\r |
e524f680 SZ |
1075 | IN PHYSICAL_ADDRESS CallerAddress,\r |
1076 | IN MEMORY_PROFILE_ACTION Action,\r | |
1077 | IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool\r | |
1078 | IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool\r | |
1079 | IN VOID *Buffer,\r | |
1080 | IN CHAR8 *ActionString OPTIONAL\r | |
84edd20b SZ |
1081 | );\r |
1082 | \r | |
1083 | /**\r | |
1084 | Register SMRAM profile handler.\r | |
1085 | \r | |
1086 | **/\r | |
1087 | VOID\r | |
1088 | RegisterSmramProfileHandler (\r | |
1089 | VOID\r | |
1090 | );\r | |
1091 | \r | |
1092 | /**\r | |
1093 | SMRAM profile ready to lock callback function.\r | |
1094 | \r | |
1095 | **/\r | |
1096 | VOID\r | |
1097 | SmramProfileReadyToLock (\r | |
1098 | VOID\r | |
1099 | );\r | |
1100 | \r | |
285a682c JY |
1101 | /**\r |
1102 | Initialize MemoryAttributes support.\r | |
1103 | **/\r | |
1104 | VOID\r | |
1105 | EFIAPI\r | |
1106 | SmmCoreInitializeMemoryAttributesTable (\r | |
1107 | VOID\r | |
1108 | );\r | |
1109 | \r | |
1110 | /**\r | |
1111 | This function returns a copy of the current memory map. The map is an array of\r | |
1112 | memory descriptors, each of which describes a contiguous block of memory.\r | |
1113 | \r | |
1114 | @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the\r | |
1115 | MemoryMap buffer. On input, this is the size of\r | |
1116 | the buffer allocated by the caller. On output,\r | |
1117 | it is the size of the buffer returned by the\r | |
1118 | firmware if the buffer was large enough, or the\r | |
1119 | size of the buffer needed to contain the map if\r | |
1120 | the buffer was too small.\r | |
1121 | @param[in, out] MemoryMap A pointer to the buffer in which firmware places\r | |
1122 | the current memory map.\r | |
1123 | @param[out] MapKey A pointer to the location in which firmware\r | |
1124 | returns the key for the current memory map.\r | |
1125 | @param[out] DescriptorSize A pointer to the location in which firmware\r | |
1126 | returns the size, in bytes, of an individual\r | |
1127 | EFI_MEMORY_DESCRIPTOR.\r | |
1128 | @param[out] DescriptorVersion A pointer to the location in which firmware\r | |
1129 | returns the version number associated with the\r | |
1130 | EFI_MEMORY_DESCRIPTOR.\r | |
1131 | \r | |
1132 | @retval EFI_SUCCESS The memory map was returned in the MemoryMap\r | |
1133 | buffer.\r | |
1134 | @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current\r | |
1135 | buffer size needed to hold the memory map is\r | |
1136 | returned in MemoryMapSize.\r | |
1137 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r | |
1138 | \r | |
1139 | **/\r | |
1140 | EFI_STATUS\r | |
1141 | EFIAPI\r | |
1142 | SmmCoreGetMemoryMap (\r | |
1143 | IN OUT UINTN *MemoryMapSize,\r | |
1144 | IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r | |
1145 | OUT UINTN *MapKey,\r | |
1146 | OUT UINTN *DescriptorSize,\r | |
1147 | OUT UINT32 *DescriptorVersion\r | |
1148 | );\r | |
1149 | \r | |
ca41f3f4 JY |
1150 | /**\r |
1151 | Initialize SmiHandler profile feature.\r | |
1152 | **/\r | |
1153 | VOID\r | |
1154 | SmmCoreInitializeSmiHandlerProfile (\r | |
1155 | VOID\r | |
1156 | );\r | |
1157 | \r | |
1158 | /**\r | |
1159 | This function is called by SmmChildDispatcher module to report\r | |
1160 | a new SMI handler is registered, to SmmCore.\r | |
1161 | \r | |
1162 | @param This The protocol instance\r | |
1163 | @param HandlerGuid The GUID to identify the type of the handler.\r | |
1164 | For the SmmChildDispatch protocol, the HandlerGuid\r | |
1165 | must be the GUID of SmmChildDispatch protocol.\r | |
1166 | @param Handler The SMI handler.\r | |
1167 | @param CallerAddress The address of the module who registers the SMI handler.\r | |
1168 | @param Context The context of the SMI handler.\r | |
1169 | For the SmmChildDispatch protocol, the Context\r | |
1170 | must match the one defined for SmmChildDispatch protocol.\r | |
1171 | @param ContextSize The size of the context in bytes.\r | |
1172 | For the SmmChildDispatch protocol, the Context\r | |
1173 | must match the one defined for SmmChildDispatch protocol.\r | |
1174 | \r | |
1175 | @retval EFI_SUCCESS The information is recorded.\r | |
1176 | @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.\r | |
1177 | **/\r | |
1178 | EFI_STATUS\r | |
1179 | EFIAPI\r | |
1180 | SmiHandlerProfileRegisterHandler (\r | |
1181 | IN SMI_HANDLER_PROFILE_PROTOCOL *This,\r | |
1182 | IN EFI_GUID *HandlerGuid,\r | |
1183 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r | |
1184 | IN PHYSICAL_ADDRESS CallerAddress,\r | |
1185 | IN VOID *Context, OPTIONAL\r | |
1186 | IN UINTN ContextSize OPTIONAL\r | |
1187 | );\r | |
1188 | \r | |
1189 | /**\r | |
1190 | This function is called by SmmChildDispatcher module to report\r | |
1191 | an existing SMI handler is unregistered, to SmmCore.\r | |
1192 | \r | |
1193 | @param This The protocol instance\r | |
1194 | @param HandlerGuid The GUID to identify the type of the handler.\r | |
1195 | For the SmmChildDispatch protocol, the HandlerGuid\r | |
1196 | must be the GUID of SmmChildDispatch protocol.\r | |
1197 | @param Handler The SMI handler.\r | |
1c3ac4b9 JY |
1198 | @param Context The context of the SMI handler.\r |
1199 | If it is NOT NULL, it will be used to check what is registered.\r | |
1200 | @param ContextSize The size of the context in bytes.\r | |
1201 | If Context is NOT NULL, it will be used to check what is registered.\r | |
ca41f3f4 JY |
1202 | \r |
1203 | @retval EFI_SUCCESS The original record is removed.\r | |
1204 | @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.\r | |
1205 | **/\r | |
1206 | EFI_STATUS\r | |
1207 | EFIAPI\r | |
1208 | SmiHandlerProfileUnregisterHandler (\r | |
1209 | IN SMI_HANDLER_PROFILE_PROTOCOL *This,\r | |
1210 | IN EFI_GUID *HandlerGuid,\r | |
1c3ac4b9 JY |
1211 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r |
1212 | IN VOID *Context, OPTIONAL\r | |
1213 | IN UINTN ContextSize OPTIONAL\r | |
ca41f3f4 JY |
1214 | );\r |
1215 | \r | |
84edd20b SZ |
1216 | extern UINTN mFullSmramRangeCount;\r |
1217 | extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r | |
1218 | \r | |
285a682c JY |
1219 | extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;\r |
1220 | \r | |
0b256fb1 JY |
1221 | extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;\r |
1222 | \r | |
63aa86b0 SZ |
1223 | //\r |
1224 | // Page management\r | |
1225 | //\r | |
1226 | \r | |
1227 | typedef struct {\r | |
1228 | LIST_ENTRY Link;\r | |
1229 | UINTN NumberOfPages;\r | |
1230 | } FREE_PAGE_LIST;\r | |
1231 | \r | |
1232 | extern LIST_ENTRY mSmmMemoryMap;\r | |
1233 | \r | |
1234 | //\r | |
1235 | // Pool management\r | |
1236 | //\r | |
1237 | \r | |
1238 | //\r | |
1239 | // MIN_POOL_SHIFT must not be less than 5\r | |
1240 | //\r | |
1241 | #define MIN_POOL_SHIFT 6\r | |
1242 | #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)\r | |
1243 | \r | |
1244 | //\r | |
1245 | // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1\r | |
1246 | //\r | |
1247 | #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)\r | |
1248 | #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)\r | |
1249 | \r | |
1250 | //\r | |
1251 | // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes\r | |
1252 | //\r | |
1253 | #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)\r | |
1254 | \r | |
861c8dff SZ |
1255 | #define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')\r |
1256 | \r | |
63aa86b0 | 1257 | typedef struct {\r |
861c8dff SZ |
1258 | UINT32 Signature;\r |
1259 | BOOLEAN Available;\r | |
1260 | EFI_MEMORY_TYPE Type;\r | |
1261 | UINTN Size;\r | |
63aa86b0 SZ |
1262 | } POOL_HEADER;\r |
1263 | \r | |
861c8dff SZ |
1264 | #define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')\r |
1265 | \r | |
1266 | typedef struct {\r | |
1267 | UINT32 Signature;\r | |
1268 | UINT32 Reserved;\r | |
1269 | UINTN Size;\r | |
1270 | } POOL_TAIL;\r | |
1271 | \r | |
1272 | #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))\r | |
1273 | \r | |
1274 | #define HEAD_TO_TAIL(a) \\r | |
1275 | ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));\r | |
1276 | \r | |
63aa86b0 SZ |
1277 | typedef struct {\r |
1278 | POOL_HEADER Header;\r | |
1279 | LIST_ENTRY Link;\r | |
1280 | } FREE_POOL_HEADER;\r | |
1281 | \r | |
5f4d3e17 JY |
1282 | typedef enum {\r |
1283 | SmmPoolTypeCode,\r | |
1284 | SmmPoolTypeData,\r | |
1285 | SmmPoolTypeMax,\r | |
1286 | } SMM_POOL_TYPE;\r | |
1287 | \r | |
1288 | extern LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];\r | |
63aa86b0 | 1289 | \r |
e63da9f0 JW |
1290 | /**\r |
1291 | Internal Function. Allocate n pages from given free page node.\r | |
1292 | \r | |
1293 | @param Pages The free page node.\r | |
1294 | @param NumberOfPages Number of pages to be allocated.\r | |
1295 | @param MaxAddress Request to allocate memory below this address.\r | |
1296 | \r | |
1297 | @return Memory address of allocated pages.\r | |
1298 | \r | |
1299 | **/\r | |
1300 | UINTN\r | |
1301 | InternalAllocPagesOnOneNode (\r | |
1302 | IN OUT FREE_PAGE_LIST *Pages,\r | |
1303 | IN UINTN NumberOfPages,\r | |
1304 | IN UINTN MaxAddress\r | |
1305 | );\r | |
1306 | \r | |
1307 | /**\r | |
1308 | Update SMM memory map entry.\r | |
1309 | \r | |
1310 | @param[in] Type The type of allocation to perform.\r | |
1311 | @param[in] Memory The base of memory address.\r | |
1312 | @param[in] NumberOfPages The number of pages to allocate.\r | |
1313 | @param[in] AddRegion If this memory is new added region.\r | |
1314 | **/\r | |
1315 | VOID\r | |
1316 | ConvertSmmMemoryMapEntry (\r | |
1317 | IN EFI_MEMORY_TYPE Type,\r | |
1318 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
1319 | IN UINTN NumberOfPages,\r | |
1320 | IN BOOLEAN AddRegion\r | |
1321 | );\r | |
1322 | \r | |
1323 | /**\r | |
1324 | Internal function. Moves any memory descriptors that are on the\r | |
1325 | temporary descriptor stack to heap.\r | |
1326 | \r | |
1327 | **/\r | |
1328 | VOID\r | |
1329 | CoreFreeMemoryMapStack (\r | |
1330 | VOID\r | |
1331 | );\r | |
1332 | \r | |
1333 | /**\r | |
1334 | Frees previous allocated pages.\r | |
1335 | \r | |
1336 | @param[in] Memory Base address of memory being freed.\r | |
1337 | @param[in] NumberOfPages The number of pages to free.\r | |
1338 | @param[in] AddRegion If this memory is new added region.\r | |
1339 | \r | |
1340 | @retval EFI_NOT_FOUND Could not find the entry that covers the range.\r | |
1341 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r | |
1342 | @return EFI_SUCCESS Pages successfully freed.\r | |
1343 | \r | |
1344 | **/\r | |
1345 | EFI_STATUS\r | |
1346 | SmmInternalFreePagesEx (\r | |
1347 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
1348 | IN UINTN NumberOfPages,\r | |
1349 | IN BOOLEAN AddRegion\r | |
1350 | );\r | |
1351 | \r | |
1352 | /**\r | |
1353 | Hook function used to set all Guard pages after entering SMM mode.\r | |
1354 | **/\r | |
1355 | VOID\r | |
1356 | SmmEntryPointMemoryManagementHook (\r | |
1357 | VOID\r | |
1358 | );\r | |
1359 | \r | |
e42e9404 | 1360 | #endif\r |