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