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