PiSmmCore.h 44 KB

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