]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
Merge branch 'master' of https://github.com/tianocore/edk2
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.h
CommitLineData
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
e524f680 5 Copyright (c) 2009 - 2016, 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
e42e9404 35\r
36#include <Guid/Apriori.h>\r
37#include <Guid/EventGroup.h>\r
38#include <Guid/EventLegacyBios.h>\r
84edd20b
SZ
39#include <Guid/ZeroGuid.h>\r
40#include <Guid/MemoryProfile.h>\r
e42e9404 41\r
42#include <Library/BaseLib.h>\r
43#include <Library/BaseMemoryLib.h>\r
44#include <Library/PeCoffLib.h>\r
e524f680 45#include <Library/PeCoffGetEntryPointLib.h>\r
e42e9404 46#include <Library/CacheMaintenanceLib.h>\r
47#include <Library/DebugLib.h>\r
48#include <Library/ReportStatusCodeLib.h>\r
49#include <Library/MemoryAllocationLib.h>\r
50#include <Library/DevicePathLib.h> \r
51#include <Library/UefiLib.h> \r
3c447c27 52#include <Library/UefiBootServicesTableLib.h>\r
53#include <Library/PcdLib.h>\r
495797c5 54#include <Library/SmmCorePlatformHookLib.h>\r
55#include <Library/PerformanceLib.h>\r
c2cb08df 56#include <Library/TimerLib.h>\r
3720ee6d 57#include <Library/HobLib.h>\r
842b1242 58#include <Library/SmmMemLib.h>\r
e42e9404 59\r
60#include "PiSmmCorePrivateData.h"\r
61\r
62//\r
63// Used to build a table of SMI Handlers that the SMM Core registers\r
64//\r
65typedef struct {\r
66 EFI_SMM_HANDLER_ENTRY_POINT2 Handler;\r
67 EFI_GUID *HandlerType;\r
68 EFI_HANDLE DispatchHandle;\r
69 BOOLEAN UnRegister;\r
70} SMM_CORE_SMI_HANDLERS;\r
71\r
72//\r
73// Structure for recording the state of an SMM Driver\r
74//\r
75#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')\r
76\r
77typedef struct {\r
78 UINTN Signature;\r
79 LIST_ENTRY Link; // mDriverList\r
80\r
81 LIST_ENTRY ScheduledLink; // mScheduledQueue\r
82\r
83 EFI_HANDLE FvHandle;\r
84 EFI_GUID FileName;\r
85 EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;\r
86 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
87\r
88 VOID *Depex;\r
89 UINTN DepexSize;\r
90\r
91 BOOLEAN Before;\r
92 BOOLEAN After;\r
93 EFI_GUID BeforeAfterGuid;\r
94\r
95 BOOLEAN Dependent;\r
e42e9404 96 BOOLEAN Scheduled;\r
e42e9404 97 BOOLEAN Initialized;\r
98 BOOLEAN DepexProtocolError;\r
99\r
100 EFI_HANDLE ImageHandle;\r
101 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
102 //\r
103 // Image EntryPoint in SMRAM\r
104 //\r
105 PHYSICAL_ADDRESS ImageEntryPoint;\r
106 //\r
107 // Image Buffer in SMRAM \r
108 //\r
109 PHYSICAL_ADDRESS ImageBuffer;\r
110 //\r
111 // Image Page Number\r
112 //\r
113 UINTN NumberOfPage;\r
114} EFI_SMM_DRIVER_ENTRY;\r
115\r
116#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')\r
117\r
118///\r
119/// IHANDLE - contains a list of protocol handles\r
120///\r
121typedef struct {\r
122 UINTN Signature;\r
123 /// All handles list of IHANDLE\r
124 LIST_ENTRY AllHandles;\r
125 /// List of PROTOCOL_INTERFACE's for this handle\r
126 LIST_ENTRY Protocols;\r
127 UINTN LocateRequest;\r
128} IHANDLE;\r
129\r
130#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r
131\r
132#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')\r
133\r
134///\r
135/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol\r
136/// database. Each handler that supports this protocol is listed, along\r
137/// with a list of registered notifies.\r
138///\r
139typedef struct {\r
140 UINTN Signature;\r
141 /// Link Entry inserted to mProtocolDatabase\r
142 LIST_ENTRY AllEntries;\r
143 /// ID of the protocol\r
144 EFI_GUID ProtocolID;\r
145 /// All protocol interfaces\r
146 LIST_ENTRY Protocols;\r
147 /// Registerd notification handlers\r
148 LIST_ENTRY Notify;\r
149} PROTOCOL_ENTRY;\r
150\r
151#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')\r
152\r
153///\r
154/// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked\r
155/// with a protocol interface structure\r
156///\r
157typedef struct {\r
158 UINTN Signature;\r
159 /// Link on IHANDLE.Protocols\r
160 LIST_ENTRY Link;\r
161 /// Back pointer\r
162 IHANDLE *Handle;\r
163 /// Link on PROTOCOL_ENTRY.Protocols\r
164 LIST_ENTRY ByProtocol;\r
165 /// The protocol ID\r
166 PROTOCOL_ENTRY *Protocol;\r
167 /// The interface value\r
168 VOID *Interface;\r
169} PROTOCOL_INTERFACE;\r
170\r
171#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')\r
172\r
173///\r
174/// PROTOCOL_NOTIFY - used for each register notification for a protocol\r
175///\r
176typedef struct {\r
177 UINTN Signature;\r
178 PROTOCOL_ENTRY *Protocol;\r
179 /// All notifications for this protocol\r
180 LIST_ENTRY Link;\r
181 /// Notification function\r
182 EFI_SMM_NOTIFY_FN Function;\r
183 /// Last position notified\r
184 LIST_ENTRY *Position;\r
185} PROTOCOL_NOTIFY;\r
186\r
187//\r
188// SMM Core Global Variables\r
189//\r
190extern SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r
191extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst;\r
192extern LIST_ENTRY gHandleList;\r
3c447c27 193extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase;\r
e42e9404 194\r
195/**\r
196 Called to initialize the memory service.\r
197\r
198 @param SmramRangeCount Number of SMRAM Regions\r
199 @param SmramRanges Pointer to SMRAM Descriptors\r
200\r
201**/\r
202VOID\r
203SmmInitializeMemoryServices (\r
204 IN UINTN SmramRangeCount,\r
205 IN EFI_SMRAM_DESCRIPTOR *SmramRanges\r
206 );\r
207\r
208/**\r
209 The SmmInstallConfigurationTable() function is used to maintain the list\r
210 of configuration tables that are stored in the System Management System\r
211 Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r
212 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r
213\r
214 @param SystemTable A pointer to the SMM System Table (SMST).\r
215 @param Guid A pointer to the GUID for the entry to add, update, or remove.\r
216 @param Table A pointer to the buffer of the table to add.\r
217 @param TableSize The size of the table to install.\r
218\r
219 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r
220 @retval EFI_INVALID_PARAMETER Guid is not valid.\r
221 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r
222 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r
223\r
224**/\r
225EFI_STATUS\r
226EFIAPI\r
227SmmInstallConfigurationTable (\r
228 IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r
229 IN CONST EFI_GUID *Guid,\r
230 IN VOID *Table,\r
231 IN UINTN TableSize\r
232 );\r
233\r
234/**\r
235 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which\r
236 Calls the private one which contains a BOOLEAN parameter for notifications\r
237\r
238 @param UserHandle The handle to install the protocol handler on,\r
239 or NULL if a new handle is to be allocated\r
240 @param Protocol The protocol to add to the handle\r
241 @param InterfaceType Indicates whether Interface is supplied in\r
242 native form.\r
243 @param Interface The interface for the protocol being added\r
244\r
245 @return Status code\r
246\r
247**/\r
248EFI_STATUS\r
249EFIAPI\r
250SmmInstallProtocolInterface (\r
251 IN OUT EFI_HANDLE *UserHandle,\r
252 IN EFI_GUID *Protocol,\r
253 IN EFI_INTERFACE_TYPE InterfaceType,\r
254 IN VOID *Interface\r
255 );\r
256\r
257/**\r
258 Allocates pages from the memory map.\r
259\r
260 @param Type The type of allocation to perform\r
261 @param MemoryType The type of memory to turn the allocated pages\r
262 into\r
263 @param NumberOfPages The number of pages to allocate\r
264 @param Memory A pointer to receive the base allocated memory\r
265 address\r
266\r
267 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
268 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
269 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r
270 @retval EFI_SUCCESS Pages successfully allocated.\r
271\r
272**/\r
273EFI_STATUS\r
274EFIAPI\r
275SmmAllocatePages (\r
276 IN EFI_ALLOCATE_TYPE Type,\r
277 IN EFI_MEMORY_TYPE MemoryType,\r
278 IN UINTN NumberOfPages,\r
279 OUT EFI_PHYSICAL_ADDRESS *Memory\r
280 );\r
281\r
84edd20b
SZ
282/**\r
283 Allocates pages from the memory map.\r
284\r
285 @param Type The type of allocation to perform\r
286 @param MemoryType The type of memory to turn the allocated pages\r
287 into\r
288 @param NumberOfPages The number of pages to allocate\r
289 @param Memory A pointer to receive the base allocated memory\r
290 address\r
291\r
292 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
293 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
294 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r
295 @retval EFI_SUCCESS Pages successfully allocated.\r
296\r
297**/\r
298EFI_STATUS\r
299EFIAPI\r
300SmmInternalAllocatePages (\r
301 IN EFI_ALLOCATE_TYPE Type,\r
302 IN EFI_MEMORY_TYPE MemoryType,\r
303 IN UINTN NumberOfPages,\r
304 OUT EFI_PHYSICAL_ADDRESS *Memory\r
305 );\r
306\r
e42e9404 307/**\r
308 Frees previous allocated pages.\r
309\r
310 @param Memory Base address of memory being freed\r
311 @param NumberOfPages The number of pages to free\r
312\r
313 @retval EFI_NOT_FOUND Could not find the entry that covers the range\r
314 @retval EFI_INVALID_PARAMETER Address not aligned\r
315 @return EFI_SUCCESS Pages successfully freed.\r
316\r
317**/\r
318EFI_STATUS\r
319EFIAPI\r
320SmmFreePages (\r
321 IN EFI_PHYSICAL_ADDRESS Memory,\r
322 IN UINTN NumberOfPages\r
323 );\r
324\r
84edd20b
SZ
325/**\r
326 Frees previous allocated pages.\r
327\r
328 @param Memory Base address of memory being freed\r
329 @param NumberOfPages The number of pages to free\r
330\r
331 @retval EFI_NOT_FOUND Could not find the entry that covers the range\r
332 @retval EFI_INVALID_PARAMETER Address not aligned\r
333 @return EFI_SUCCESS Pages successfully freed.\r
334\r
335**/\r
336EFI_STATUS\r
337EFIAPI\r
338SmmInternalFreePages (\r
339 IN EFI_PHYSICAL_ADDRESS Memory,\r
340 IN UINTN NumberOfPages\r
341 );\r
342\r
e42e9404 343/**\r
344 Allocate pool of a particular type.\r
345\r
346 @param PoolType Type of pool to allocate\r
347 @param Size The amount of pool to allocate\r
348 @param Buffer The address to return a pointer to the allocated\r
349 pool\r
350\r
351 @retval EFI_INVALID_PARAMETER PoolType not valid\r
352 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r
353 @retval EFI_SUCCESS Pool successfully allocated.\r
354\r
355**/\r
356EFI_STATUS\r
357EFIAPI\r
358SmmAllocatePool (\r
359 IN EFI_MEMORY_TYPE PoolType,\r
360 IN UINTN Size,\r
361 OUT VOID **Buffer\r
362 );\r
363\r
84edd20b
SZ
364/**\r
365 Allocate pool of a particular type.\r
366\r
367 @param PoolType Type of pool to allocate\r
368 @param Size The amount of pool to allocate\r
369 @param Buffer The address to return a pointer to the allocated\r
370 pool\r
371\r
372 @retval EFI_INVALID_PARAMETER PoolType not valid\r
373 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r
374 @retval EFI_SUCCESS Pool successfully allocated.\r
375\r
376**/\r
377EFI_STATUS\r
378EFIAPI\r
379SmmInternalAllocatePool (\r
380 IN EFI_MEMORY_TYPE PoolType,\r
381 IN UINTN Size,\r
382 OUT VOID **Buffer\r
383 );\r
384\r
e42e9404 385/**\r
386 Frees pool.\r
387\r
388 @param Buffer The allocated pool entry to free\r
389\r
390 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r
391 @retval EFI_SUCCESS Pool successfully freed.\r
392\r
393**/\r
394EFI_STATUS\r
395EFIAPI\r
396SmmFreePool (\r
397 IN VOID *Buffer\r
398 );\r
399\r
84edd20b
SZ
400/**\r
401 Frees pool.\r
402\r
403 @param Buffer The allocated pool entry to free\r
404\r
405 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r
406 @retval EFI_SUCCESS Pool successfully freed.\r
407\r
408**/\r
409EFI_STATUS\r
410EFIAPI\r
411SmmInternalFreePool (\r
412 IN VOID *Buffer\r
413 );\r
414\r
e42e9404 415/**\r
416 Installs a protocol interface into the boot services environment.\r
417\r
418 @param UserHandle The handle to install the protocol handler on,\r
419 or NULL if a new handle is to be allocated\r
420 @param Protocol The protocol to add to the handle\r
421 @param InterfaceType Indicates whether Interface is supplied in\r
422 native form.\r
423 @param Interface The interface for the protocol being added\r
424 @param Notify indicates whether notify the notification list\r
425 for this protocol\r
426\r
427 @retval EFI_INVALID_PARAMETER Invalid parameter\r
428 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate\r
429 @retval EFI_SUCCESS Protocol interface successfully installed\r
430\r
431**/\r
432EFI_STATUS\r
433SmmInstallProtocolInterfaceNotify (\r
434 IN OUT EFI_HANDLE *UserHandle,\r
435 IN EFI_GUID *Protocol,\r
436 IN EFI_INTERFACE_TYPE InterfaceType,\r
437 IN VOID *Interface,\r
438 IN BOOLEAN Notify\r
439 );\r
440\r
441/**\r
442 Uninstalls all instances of a protocol:interfacer from a handle.\r
443 If the last protocol interface is remove from the handle, the\r
444 handle is freed.\r
445\r
446 @param UserHandle The handle to remove the protocol handler from\r
447 @param Protocol The protocol, of protocol:interface, to remove\r
448 @param Interface The interface, of protocol:interface, to remove\r
449\r
450 @retval EFI_INVALID_PARAMETER Protocol is NULL.\r
451 @retval EFI_SUCCESS Protocol interface successfully uninstalled.\r
452\r
453**/\r
454EFI_STATUS\r
455EFIAPI\r
456SmmUninstallProtocolInterface (\r
457 IN EFI_HANDLE UserHandle,\r
458 IN EFI_GUID *Protocol,\r
459 IN VOID *Interface\r
460 );\r
461\r
462/**\r
463 Queries a handle to determine if it supports a specified protocol.\r
464\r
465 @param UserHandle The handle being queried.\r
466 @param Protocol The published unique identifier of the protocol.\r
467 @param Interface Supplies the address where a pointer to the\r
468 corresponding Protocol Interface is returned.\r
469\r
470 @return The requested protocol interface for the handle\r
471\r
472**/\r
473EFI_STATUS\r
474EFIAPI\r
475SmmHandleProtocol (\r
476 IN EFI_HANDLE UserHandle,\r
477 IN EFI_GUID *Protocol,\r
478 OUT VOID **Interface\r
479 );\r
480\r
481/**\r
482 Add a new protocol notification record for the request protocol.\r
483\r
484 @param Protocol The requested protocol to add the notify\r
485 registration\r
486 @param Function Points to the notification function\r
487 @param Registration Returns the registration record\r
488\r
489 @retval EFI_INVALID_PARAMETER Invalid parameter\r
490 @retval EFI_SUCCESS Successfully returned the registration record\r
491 that has been added\r
492\r
493**/\r
494EFI_STATUS\r
495EFIAPI\r
496SmmRegisterProtocolNotify (\r
497 IN CONST EFI_GUID *Protocol,\r
498 IN EFI_SMM_NOTIFY_FN Function,\r
499 OUT VOID **Registration\r
500 );\r
501\r
502/**\r
503 Locates the requested handle(s) and returns them in Buffer.\r
504\r
505 @param SearchType The type of search to perform to locate the\r
506 handles\r
507 @param Protocol The protocol to search for\r
508 @param SearchKey Dependant on SearchType\r
509 @param BufferSize On input the size of Buffer. On output the\r
510 size of data returned.\r
511 @param Buffer The buffer to return the results in\r
512\r
513 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is\r
514 returned in BufferSize.\r
515 @retval EFI_INVALID_PARAMETER Invalid parameter\r
516 @retval EFI_SUCCESS Successfully found the requested handle(s) and\r
517 returns them in Buffer.\r
518\r
519**/\r
520EFI_STATUS\r
521EFIAPI\r
522SmmLocateHandle (\r
523 IN EFI_LOCATE_SEARCH_TYPE SearchType,\r
524 IN EFI_GUID *Protocol OPTIONAL,\r
525 IN VOID *SearchKey OPTIONAL,\r
526 IN OUT UINTN *BufferSize,\r
527 OUT EFI_HANDLE *Buffer\r
528 );\r
529\r
530/**\r
531 Return the first Protocol Interface that matches the Protocol GUID. If\r
532 Registration is pasased in return a Protocol Instance that was just add\r
533 to the system. If Retistration is NULL return the first Protocol Interface\r
534 you find.\r
535\r
536 @param Protocol The protocol to search for\r
537 @param Registration Optional Registration Key returned from\r
538 RegisterProtocolNotify()\r
539 @param Interface Return the Protocol interface (instance).\r
540\r
541 @retval EFI_SUCCESS If a valid Interface is returned\r
542 @retval EFI_INVALID_PARAMETER Invalid parameter\r
543 @retval EFI_NOT_FOUND Protocol interface not found\r
544\r
545**/\r
546EFI_STATUS\r
547EFIAPI\r
548SmmLocateProtocol (\r
549 IN EFI_GUID *Protocol,\r
550 IN VOID *Registration OPTIONAL,\r
551 OUT VOID **Interface\r
552 );\r
553\r
554/**\r
555 Manage SMI of a particular type.\r
556\r
557 @param HandlerType Points to the handler type or NULL for root SMI handlers.\r
558 @param Context Points to an optional context buffer.\r
559 @param CommBuffer Points to the optional communication buffer.\r
560 @param CommBufferSize Points to the size of the optional communication buffer.\r
561\r
562 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.\r
563 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.\r
564 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.\r
565 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.\r
566\r
567**/\r
568EFI_STATUS\r
569EFIAPI\r
570SmiManage (\r
571 IN CONST EFI_GUID *HandlerType,\r
572 IN CONST VOID *Context OPTIONAL,\r
573 IN OUT VOID *CommBuffer OPTIONAL,\r
574 IN OUT UINTN *CommBufferSize OPTIONAL\r
575 );\r
576\r
577/**\r
578 Registers a handler to execute within SMM.\r
579\r
580 @param Handler Handler service funtion pointer.\r
581 @param HandlerType Points to the handler type or NULL for root SMI handlers.\r
582 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.\r
583\r
584 @retval EFI_SUCCESS Handler register success.\r
585 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.\r
586\r
587**/\r
588EFI_STATUS\r
589EFIAPI\r
590SmiHandlerRegister (\r
591 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r
592 IN CONST EFI_GUID *HandlerType OPTIONAL,\r
593 OUT EFI_HANDLE *DispatchHandle\r
594 );\r
595\r
596/**\r
597 Unregister a handler in SMM.\r
598\r
599 @param DispatchHandle The handle that was specified when the handler was registered.\r
600\r
601 @retval EFI_SUCCESS Handler function was successfully unregistered.\r
602 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.\r
603\r
604**/\r
605EFI_STATUS\r
606EFIAPI\r
607SmiHandlerUnRegister (\r
608 IN EFI_HANDLE DispatchHandle\r
609 );\r
610\r
611/**\r
612 This function is the main entry point for an SMM handler dispatch\r
613 or communicate-based callback.\r
614\r
615 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
616 @param Context Points to an optional handler context which was specified when the handler was registered.\r
617 @param CommBuffer A pointer to a collection of data in memory that will\r
618 be conveyed from a non-SMM environment into an SMM environment.\r
619 @param CommBufferSize The size of the CommBuffer.\r
620\r
621 @return Status Code\r
622\r
623**/\r
624EFI_STATUS\r
625EFIAPI\r
626SmmDriverDispatchHandler (\r
627 IN EFI_HANDLE DispatchHandle,\r
628 IN CONST VOID *Context, OPTIONAL\r
629 IN OUT VOID *CommBuffer, OPTIONAL\r
630 IN OUT UINTN *CommBufferSize OPTIONAL\r
631 );\r
632\r
633/**\r
634 This function is the main entry point for an SMM handler dispatch\r
635 or communicate-based callback.\r
636\r
637 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
638 @param Context Points to an optional handler context which was specified when the handler was registered.\r
639 @param CommBuffer A pointer to a collection of data in memory that will\r
640 be conveyed from a non-SMM environment into an SMM environment.\r
641 @param CommBufferSize The size of the CommBuffer.\r
642\r
643 @return Status Code\r
644\r
645**/\r
646EFI_STATUS\r
647EFIAPI\r
648SmmLegacyBootHandler (\r
649 IN EFI_HANDLE DispatchHandle,\r
650 IN CONST VOID *Context, OPTIONAL\r
651 IN OUT VOID *CommBuffer, OPTIONAL\r
652 IN OUT UINTN *CommBufferSize OPTIONAL\r
653 );\r
654\r
655/**\r
656 This function is the main entry point for an SMM handler dispatch\r
657 or communicate-based callback.\r
658\r
659 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
660 @param Context Points to an optional handler context which was specified when the handler was registered.\r
661 @param CommBuffer A pointer to a collection of data in memory that will\r
662 be conveyed from a non-SMM environment into an SMM environment.\r
663 @param CommBufferSize The size of the CommBuffer.\r
664\r
665 @return Status Code\r
666\r
667**/\r
668EFI_STATUS\r
669EFIAPI\r
670SmmReadyToLockHandler (\r
671 IN EFI_HANDLE DispatchHandle,\r
672 IN CONST VOID *Context, OPTIONAL\r
673 IN OUT VOID *CommBuffer, OPTIONAL\r
674 IN OUT UINTN *CommBufferSize OPTIONAL\r
675 );\r
676\r
46ece1ff
JY
677/**\r
678 This function is the main entry point for an SMM handler dispatch\r
679 or communicate-based callback.\r
680\r
681 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
682 @param Context Points to an optional handler context which was specified when the handler was registered.\r
683 @param CommBuffer A pointer to a collection of data in memory that will\r
684 be conveyed from a non-SMM environment into an SMM environment.\r
685 @param CommBufferSize The size of the CommBuffer.\r
686\r
687 @return Status Code\r
688\r
689**/\r
690EFI_STATUS\r
691EFIAPI\r
692SmmEndOfDxeHandler (\r
693 IN EFI_HANDLE DispatchHandle,\r
694 IN CONST VOID *Context, OPTIONAL\r
695 IN OUT VOID *CommBuffer, OPTIONAL\r
696 IN OUT UINTN *CommBufferSize OPTIONAL\r
697 );\r
698\r
53ec4d7f
SZ
699/**\r
700 This function is the main entry point for an SMM handler dispatch\r
701 or communicate-based callback.\r
702\r
703 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
704 @param Context Points to an optional handler context which was specified when the handler was registered.\r
705 @param CommBuffer A pointer to a collection of data in memory that will\r
706 be conveyed from a non-SMM environment into an SMM environment.\r
707 @param CommBufferSize The size of the CommBuffer.\r
708\r
709 @return Status Code\r
710\r
711**/\r
712EFI_STATUS\r
713EFIAPI\r
714SmmExitBootServicesHandler (\r
715 IN EFI_HANDLE DispatchHandle,\r
716 IN CONST VOID *Context, OPTIONAL\r
717 IN OUT VOID *CommBuffer, OPTIONAL\r
718 IN OUT UINTN *CommBufferSize OPTIONAL\r
719 );\r
720\r
721/**\r
722 This function is the main entry point for an SMM handler dispatch\r
723 or communicate-based callback.\r
724\r
725 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
726 @param Context Points to an optional handler context which was specified when the handler was registered.\r
727 @param CommBuffer A pointer to a collection of data in memory that will\r
728 be conveyed from a non-SMM environment into an SMM environment.\r
729 @param CommBufferSize The size of the CommBuffer.\r
730\r
731 @return Status Code\r
732\r
733**/\r
734EFI_STATUS\r
735EFIAPI\r
736SmmReadyToBootHandler (\r
737 IN EFI_HANDLE DispatchHandle,\r
738 IN CONST VOID *Context, OPTIONAL\r
739 IN OUT VOID *CommBuffer, OPTIONAL\r
740 IN OUT UINTN *CommBufferSize OPTIONAL\r
741 );\r
742\r
e42e9404 743/**\r
744 Place holder function until all the SMM System Table Service are available.\r
745\r
746 @param Arg1 Undefined\r
747 @param Arg2 Undefined\r
748 @param Arg3 Undefined\r
749 @param Arg4 Undefined\r
750 @param Arg5 Undefined\r
751\r
752 @return EFI_NOT_AVAILABLE_YET\r
753\r
754**/\r
755EFI_STATUS\r
756EFIAPI\r
757SmmEfiNotAvailableYetArg5 (\r
758 UINTN Arg1,\r
759 UINTN Arg2,\r
760 UINTN Arg3,\r
761 UINTN Arg4,\r
762 UINTN Arg5\r
763 );\r
764\r
765//\r
766//Functions used during debug buils\r
767//\r
768\r
769/**\r
770 Traverse the discovered list for any drivers that were discovered but not loaded\r
771 because the dependency experessions evaluated to false.\r
772\r
773**/\r
774VOID\r
775SmmDisplayDiscoveredNotDispatched (\r
776 VOID\r
777 );\r
778\r
779/**\r
780 Add free SMRAM region for use by memory service.\r
781\r
782 @param MemBase Base address of memory region.\r
783 @param MemLength Length of the memory region.\r
784 @param Type Memory type.\r
785 @param Attributes Memory region state.\r
786\r
787**/\r
788VOID\r
789SmmAddMemoryRegion (\r
790 IN EFI_PHYSICAL_ADDRESS MemBase,\r
791 IN UINT64 MemLength,\r
792 IN EFI_MEMORY_TYPE Type,\r
793 IN UINT64 Attributes\r
794 );\r
795\r
796/**\r
797 Finds the protocol entry for the requested protocol.\r
798\r
799 @param Protocol The ID of the protocol\r
800 @param Create Create a new entry if not found\r
801\r
802 @return Protocol entry\r
803\r
804**/\r
805PROTOCOL_ENTRY *\r
806SmmFindProtocolEntry (\r
807 IN EFI_GUID *Protocol,\r
808 IN BOOLEAN Create\r
809 );\r
810\r
811/**\r
812 Signal event for every protocol in protocol entry.\r
813\r
814 @param Prot Protocol interface\r
815\r
816**/\r
817VOID\r
818SmmNotifyProtocol (\r
819 IN PROTOCOL_INTERFACE *Prot\r
820 );\r
821\r
822/**\r
823 Finds the protocol instance for the requested handle and protocol.\r
824 Note: This function doesn't do parameters checking, it's caller's responsibility\r
825 to pass in valid parameters.\r
826\r
827 @param Handle The handle to search the protocol on\r
828 @param Protocol GUID of the protocol\r
829 @param Interface The interface for the protocol being searched\r
830\r
831 @return Protocol instance (NULL: Not found)\r
832\r
833**/\r
834PROTOCOL_INTERFACE *\r
835SmmFindProtocolInterface (\r
836 IN IHANDLE *Handle,\r
837 IN EFI_GUID *Protocol,\r
838 IN VOID *Interface\r
839 );\r
840\r
841/**\r
842 Removes Protocol from the protocol list (but not the handle list).\r
843\r
844 @param Handle The handle to remove protocol on.\r
845 @param Protocol GUID of the protocol to be moved\r
846 @param Interface The interface of the protocol\r
847\r
848 @return Protocol Entry\r
849\r
850**/\r
851PROTOCOL_INTERFACE *\r
852SmmRemoveInterfaceFromProtocol (\r
853 IN IHANDLE *Handle,\r
854 IN EFI_GUID *Protocol,\r
855 IN VOID *Interface\r
856 );\r
857\r
858/**\r
859 This is the POSTFIX version of the dependency evaluator. This code does\r
860 not need to handle Before or After, as it is not valid to call this\r
fa542a1e 861 routine in this case. POSTFIX means all the math is done on top of the stack.\r
e42e9404 862\r
863 @param DriverEntry DriverEntry element to update.\r
864\r
865 @retval TRUE If driver is ready to run.\r
866 @retval FALSE If driver is not ready to run or some fatal error\r
867 was found.\r
868\r
869**/\r
870BOOLEAN\r
871SmmIsSchedulable (\r
872 IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r
873 );\r
874\r
84edd20b
SZ
875//\r
876// SmramProfile\r
877//\r
878\r
879/**\r
880 Initialize SMRAM profile.\r
881\r
882**/\r
883VOID\r
884SmramProfileInit (\r
885 VOID\r
886 );\r
887\r
e524f680
SZ
888/**\r
889 Install SMRAM profile protocol.\r
890\r
891**/\r
892VOID\r
893SmramProfileInstallProtocol (\r
894 VOID\r
895 );\r
896\r
84edd20b
SZ
897/**\r
898 Register SMM image to SMRAM profile.\r
899\r
900 @param DriverEntry SMM image info.\r
901 @param RegisterToDxe Register image to DXE.\r
902\r
e524f680
SZ
903 @return EFI_SUCCESS Register successfully.\r
904 @return EFI_UNSUPPORTED Memory profile unsupported,\r
905 or memory profile for the image is not required.\r
906 @return EFI_OUT_OF_RESOURCES No enough resource for this register.\r
84edd20b
SZ
907\r
908**/\r
e524f680 909EFI_STATUS\r
84edd20b
SZ
910RegisterSmramProfileImage (\r
911 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
912 IN BOOLEAN RegisterToDxe\r
913 );\r
914\r
915/**\r
916 Unregister image from SMRAM profile.\r
917\r
918 @param DriverEntry SMM image info.\r
919 @param UnregisterToDxe Unregister image from DXE.\r
920\r
e524f680
SZ
921 @return EFI_SUCCESS Unregister successfully.\r
922 @return EFI_UNSUPPORTED Memory profile unsupported,\r
923 or memory profile for the image is not required.\r
924 @return EFI_NOT_FOUND The image is not found.\r
84edd20b
SZ
925\r
926**/\r
e524f680 927EFI_STATUS\r
84edd20b
SZ
928UnregisterSmramProfileImage (\r
929 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
930 IN BOOLEAN UnregisterToDxe\r
931 );\r
932\r
933/**\r
934 Update SMRAM profile information.\r
935\r
936 @param CallerAddress Address of caller who call Allocate or Free.\r
937 @param Action This Allocate or Free action.\r
938 @param MemoryType Memory type.\r
e524f680 939 EfiMaxMemoryType means the MemoryType is unknown.\r
84edd20b
SZ
940 @param Size Buffer size.\r
941 @param Buffer Buffer address.\r
e524f680
SZ
942 @param ActionString String for memory profile action.\r
943 Only needed for user defined allocate action.\r
84edd20b 944\r
e524f680
SZ
945 @return EFI_SUCCESS Memory profile is updated.\r
946 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
947 or memory profile for the image is not required,\r
948 or memory profile for the memory type is not required.\r
949 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
950 @return EFI_ABORTED Memory profile recording is not enabled.\r
951 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
952 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
84edd20b
SZ
953\r
954**/\r
e524f680
SZ
955EFI_STATUS\r
956EFIAPI\r
84edd20b 957SmmCoreUpdateProfile (\r
e524f680
SZ
958 IN PHYSICAL_ADDRESS CallerAddress,\r
959 IN MEMORY_PROFILE_ACTION Action,\r
960 IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool\r
961 IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool\r
962 IN VOID *Buffer,\r
963 IN CHAR8 *ActionString OPTIONAL\r
84edd20b
SZ
964 );\r
965\r
966/**\r
967 Register SMRAM profile handler.\r
968\r
969**/\r
970VOID\r
971RegisterSmramProfileHandler (\r
972 VOID\r
973 );\r
974\r
975/**\r
976 SMRAM profile ready to lock callback function.\r
977\r
978**/\r
979VOID\r
980SmramProfileReadyToLock (\r
981 VOID\r
982 );\r
983\r
84edd20b
SZ
984extern UINTN mFullSmramRangeCount;\r
985extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r
986\r
0b256fb1
JY
987extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;\r
988\r
63aa86b0
SZ
989//\r
990// Page management\r
991//\r
992\r
993typedef struct {\r
994 LIST_ENTRY Link;\r
995 UINTN NumberOfPages;\r
996} FREE_PAGE_LIST;\r
997\r
998extern LIST_ENTRY mSmmMemoryMap;\r
999\r
1000//\r
1001// Pool management\r
1002//\r
1003\r
1004//\r
1005// MIN_POOL_SHIFT must not be less than 5\r
1006//\r
1007#define MIN_POOL_SHIFT 6\r
1008#define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)\r
1009\r
1010//\r
1011// MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1\r
1012//\r
1013#define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)\r
1014#define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)\r
1015\r
1016//\r
1017// MAX_POOL_INDEX are calculated by maximum and minimum pool sizes\r
1018//\r
1019#define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)\r
1020\r
1021typedef struct {\r
1022 UINTN Size;\r
1023 BOOLEAN Available;\r
1024} POOL_HEADER;\r
1025\r
1026typedef struct {\r
1027 POOL_HEADER Header;\r
1028 LIST_ENTRY Link;\r
1029} FREE_POOL_HEADER;\r
1030\r
1031extern LIST_ENTRY mSmmPoolLists[MAX_POOL_INDEX];\r
1032\r
e42e9404 1033#endif\r