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