2 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.
4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _CPU_PISMMCPUDXESMM_H_
18 #define _CPU_PISMMCPUDXESMM_H_
22 #include <Protocol/MpService.h>
23 #include <Protocol/SmmConfiguration.h>
24 #include <Protocol/SmmCpu.h>
25 #include <Protocol/SmmAccess2.h>
26 #include <Protocol/SmmReadyToLock.h>
27 #include <Protocol/SmmCpuService.h>
29 #include <Guid/AcpiS3Context.h>
30 #include <Guid/PiSmmMemoryAttributesTable.h>
32 #include <Library/BaseLib.h>
33 #include <Library/IoLib.h>
34 #include <Library/TimerLib.h>
35 #include <Library/SynchronizationLib.h>
36 #include <Library/DebugLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/PcdLib.h>
39 #include <Library/CacheMaintenanceLib.h>
40 #include <Library/MtrrLib.h>
41 #include <Library/SmmCpuPlatformHookLib.h>
42 #include <Library/SmmServicesTableLib.h>
43 #include <Library/MemoryAllocationLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/UefiRuntimeServicesTableLib.h>
46 #include <Library/DebugAgentLib.h>
47 #include <Library/HobLib.h>
48 #include <Library/LocalApicLib.h>
49 #include <Library/UefiCpuLib.h>
50 #include <Library/CpuExceptionHandlerLib.h>
51 #include <Library/ReportStatusCodeLib.h>
52 #include <Library/SmmCpuFeaturesLib.h>
53 #include <Library/PeCoffGetEntryPointLib.h>
55 #include <AcpiCpuData.h>
56 #include <CpuHotPlugData.h>
58 #include <Register/Cpuid.h>
59 #include <Register/Msr.h>
61 #include "CpuService.h"
62 #include "SmmProfile.h"
65 // MSRs required for configuration of SMM Code Access Check
67 #define EFI_MSR_SMM_MCA_CAP 0x17D
68 #define SMM_CODE_ACCESS_CHK_BIT BIT58
70 #define SMM_FEATURE_CONTROL_LOCK_BIT BIT0
71 #define SMM_CODE_CHK_EN_BIT BIT2
76 #define IA32_PG_P BIT0
77 #define IA32_PG_RW BIT1
78 #define IA32_PG_U BIT2
79 #define IA32_PG_WT BIT3
80 #define IA32_PG_CD BIT4
81 #define IA32_PG_A BIT5
82 #define IA32_PG_D BIT6
83 #define IA32_PG_PS BIT7
84 #define IA32_PG_PAT_2M BIT12
85 #define IA32_PG_PAT_4K IA32_PG_PS
86 #define IA32_PG_PMNT BIT62
87 #define IA32_PG_NX BIT63
89 #define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)
91 // Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE
92 // X64 PAE PDPTE does not have such restriction
94 #define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)
96 #define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)
98 #define PAGING_4K_MASK 0xFFF
99 #define PAGING_2M_MASK 0x1FFFFF
100 #define PAGING_1G_MASK 0x3FFFFFFF
102 #define PAGING_PAE_INDEX_MASK 0x1FF
104 #define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
105 #define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
106 #define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
108 #define SMRR_MAX_ADDRESS BASE_4GB
118 PAGE_ATTRIBUTE Attribute
;
121 } PAGE_ATTRIBUTE_TABLE
;
124 // Size of Task-State Segment defined in IA32 Manual
127 #define TSS_X64_IST1_OFFSET 36
128 #define TSS_IA32_CR3_OFFSET 28
129 #define TSS_IA32_ESP_OFFSET 56
136 #define PROTECT_MODE_CODE_SEGMENT 0x08
137 #define LONG_MODE_CODE_SEGMENT 0x38
140 // The size 0x20 must be bigger than
141 // the size of template code of SmmInit. Currently,
142 // the size of SmmInit requires the 0x16 Bytes buffer
145 #define BACK_BUF_SIZE 0x20
147 #define EXCEPTION_VECTOR_NUMBER 0x20
149 #define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL
151 typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS
;
152 #define ARRIVAL_EXCEPTION_BLOCKED 0x1
153 #define ARRIVAL_EXCEPTION_DELAYED 0x2
154 #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4
157 // Private structure for the SMM CPU module that is stored in DXE Runtime memory
158 // Contains the SMM Configuration Protocols that is produced.
159 // Contains a mix of DXE and SMM contents. All the fields must be used properly.
161 #define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')
166 EFI_HANDLE SmmCpuHandle
;
168 EFI_PROCESSOR_INFORMATION
*ProcessorInfo
;
169 SMM_CPU_OPERATION
*Operation
;
170 UINTN
*CpuSaveStateSize
;
173 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion
[1];
174 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext
;
175 EFI_SMM_ENTRY_POINT SmmCoreEntry
;
177 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration
;
178 } SMM_CPU_PRIVATE_DATA
;
180 extern SMM_CPU_PRIVATE_DATA
*gSmmCpuPrivate
;
181 extern CPU_HOT_PLUG_DATA mCpuHotPlugData
;
182 extern UINTN mMaxNumberOfCpus
;
183 extern UINTN mNumberOfCpus
;
184 extern EFI_SMM_CPU_PROTOCOL mSmmCpu
;
187 /// The mode of the CPU at the time an SMI occurs
189 extern UINT8 mSmmSaveStateRegisterLma
;
192 // SMM CPU Protocol function prototypes.
196 Read information from the CPU save state.
198 @param This EFI_SMM_CPU_PROTOCOL instance
199 @param Width The number of bytes to read from the CPU save state.
200 @param Register Specifies the CPU register to read form the save state.
201 @param CpuIndex Specifies the zero-based index of the CPU save state
202 @param Buffer Upon return, this holds the CPU register value read from the save state.
204 @retval EFI_SUCCESS The register was read from Save State
205 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
206 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
212 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
214 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
220 Write data to the CPU save state.
222 @param This EFI_SMM_CPU_PROTOCOL instance
223 @param Width The number of bytes to read from the CPU save state.
224 @param Register Specifies the CPU register to write to the save state.
225 @param CpuIndex Specifies the zero-based index of the CPU save state
226 @param Buffer Upon entry, this holds the new CPU register value.
228 @retval EFI_SUCCESS The register was written from Save State
229 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
230 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct
236 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
238 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
240 IN CONST VOID
*Buffer
244 Read a CPU Save State register on the target processor.
246 This function abstracts the differences that whether the CPU Save State register is in the
247 IA32 CPU Save State Map or X64 CPU Save State Map.
249 This function supports reading a CPU Save State register in SMBase relocation handler.
251 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
252 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
253 @param[in] Width The number of bytes to read from the CPU save state.
254 @param[out] Buffer Upon return, this holds the CPU register value read from the save state.
256 @retval EFI_SUCCESS The register was read from Save State.
257 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
258 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
263 ReadSaveStateRegister (
265 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
271 Write value to a CPU Save State register on the target processor.
273 This function abstracts the differences that whether the CPU Save State register is in the
274 IA32 CPU Save State Map or X64 CPU Save State Map.
276 This function supports writing a CPU Save State register in SMBase relocation handler.
278 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
279 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
280 @param[in] Width The number of bytes to read from the CPU save state.
281 @param[in] Buffer Upon entry, this holds the new CPU register value.
283 @retval EFI_SUCCESS The register was written to Save State.
284 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
285 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct.
290 WriteSaveStateRegister (
292 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
294 IN CONST VOID
*Buffer
306 extern IA32_FAR_ADDRESS gSmmJmpAddr
;
308 extern CONST UINT8 gcSmmInitTemplate
[];
309 extern CONST UINT16 gcSmmInitSize
;
310 extern UINT32 gSmmCr0
;
311 extern UINT32 gSmmCr3
;
312 extern UINT32 gSmmCr4
;
313 extern UINTN gSmmInitStack
;
316 Semaphore operation for all processor relocate SMMBase.
320 SmmRelocationSemaphoreComplete (
325 /// The type of SMM CPU Information
329 volatile EFI_AP_PROCEDURE Procedure
;
330 volatile VOID
*Parameter
;
331 volatile UINT32
*Run
;
332 volatile BOOLEAN
*Present
;
333 } SMM_CPU_DATA_BLOCK
;
336 SmmCpuSyncModeTradition
,
337 SmmCpuSyncModeRelaxedAp
,
343 // Pointer to an array. The array should be located immediately after this structure
344 // so that UC cache-ability can be set together.
346 SMM_CPU_DATA_BLOCK
*CpuData
;
347 volatile UINT32
*Counter
;
348 volatile UINT32 BspIndex
;
349 volatile BOOLEAN
*InsideSmm
;
350 volatile BOOLEAN
*AllCpusInSync
;
351 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode
;
352 volatile BOOLEAN SwitchBsp
;
353 volatile BOOLEAN
*CandidateBsp
;
354 } SMM_DISPATCHER_MP_SYNC_DATA
;
356 #define MSR_SPIN_LOCK_INIT_NUM 15
363 #define SMM_PSD_OFFSET 0xfb00
366 /// All global semaphores' pointer
369 volatile UINT32
*Counter
;
370 volatile BOOLEAN
*InsideSmm
;
371 volatile BOOLEAN
*AllCpusInSync
;
373 SPIN_LOCK
*CodeAccessCheckLock
;
374 SPIN_LOCK
*MemoryMappedLock
;
375 } SMM_CPU_SEMAPHORE_GLOBAL
;
378 /// All semaphores for each processor
382 volatile UINT32
*Run
;
383 volatile BOOLEAN
*Present
;
384 } SMM_CPU_SEMAPHORE_CPU
;
387 /// All MSRs semaphores' pointer and counter
391 UINTN AvailableCounter
;
392 } SMM_CPU_SEMAPHORE_MSR
;
395 /// All semaphores' information
398 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal
;
399 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu
;
400 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr
;
401 } SMM_CPU_SEMAPHORES
;
403 extern IA32_DESCRIPTOR gcSmiGdtr
;
404 extern EFI_PHYSICAL_ADDRESS mGdtBuffer
;
405 extern UINTN mGdtBufferSize
;
406 extern IA32_DESCRIPTOR gcSmiIdtr
;
407 extern VOID
*gcSmiIdtrPtr
;
408 extern UINT64 gPhyMask
;
409 extern SMM_DISPATCHER_MP_SYNC_DATA
*mSmmMpSyncData
;
410 extern UINTN mSmmStackArrayBase
;
411 extern UINTN mSmmStackArrayEnd
;
412 extern UINTN mSmmStackSize
;
413 extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService
;
414 extern IA32_DESCRIPTOR gcSmiInitGdtr
;
415 extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores
;
416 extern UINTN mSemaphoreSize
;
417 extern SPIN_LOCK
*mPFLock
;
418 extern SPIN_LOCK
*mConfigSmmCodeAccessCheckLock
;
419 extern SPIN_LOCK
*mMemoryMappedLock
;
420 extern EFI_SMRAM_DESCRIPTOR
*mSmmCpuSmramRanges
;
421 extern UINTN mSmmCpuSmramRangeCount
;
422 extern UINT8 mPhysicalAddressBits
;
425 // Copy of the PcdPteMemoryEncryptionAddressOrMask
427 extern UINT64 mAddressEncMask
;
430 Create 4G PageTable in SMRAM.
432 @param[in] Is32BitPageTable Whether the page table is 32-bit PAE
433 @return PageTable Address
438 IN BOOLEAN Is32BitPageTable
443 Initialize global data for MP synchronization.
445 @param Stacks Base address of SMI stack buffer for all processors.
446 @param StackSize Stack size for each processor in SMM.
450 InitializeMpServiceData (
456 Initialize Timer for SMM AP Sync.
465 Start Timer for SMM AP Sync.
475 Check if the SMM AP Sync timer is timeout.
477 @param Timer The start timer from the begin.
487 Initialize IDT for SMM Stack Guard.
492 InitializeIDTSmmStackGuard (
497 Initialize Gdt for all processors.
499 @param[in] Cr3 CR3 value.
500 @param[out] GdtStepSize The step size for GDT table.
502 @return GdtBase for processor 0.
503 GdtBase for processor X is: GdtBase + (GdtStepSize * X)
508 OUT UINTN
*GdtStepSize
512 This function sets GDT/IDT buffer to be RO and XP.
521 Register the SMM Foundation entry point.
523 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance
524 @param SmmEntryPoint SMM Foundation EntryPoint
526 @retval EFI_SUCCESS Successfully to register SMM foundation entry point
532 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL
*This
,
533 IN EFI_SMM_ENTRY_POINT SmmEntryPoint
537 Create PageTable for SMM use.
539 @return PageTable Address
548 Schedule a procedure to run on the specified CPU.
550 @param Procedure The address of the procedure to run
551 @param CpuIndex Target CPU number
552 @param ProcArguments The parameter to pass to the procedure
554 @retval EFI_INVALID_PARAMETER CpuNumber not valid
555 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
556 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
557 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
558 @retval EFI_SUCCESS - The procedure has been successfully scheduled
564 IN EFI_AP_PROCEDURE Procedure
,
566 IN OUT VOID
*ProcArguments OPTIONAL
570 Schedule a procedure to run on the specified CPU in a blocking fashion.
572 @param Procedure The address of the procedure to run
573 @param CpuIndex Target CPU Index
574 @param ProcArguments The parameter to pass to the procedure
576 @retval EFI_INVALID_PARAMETER CpuNumber not valid
577 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
578 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
579 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
580 @retval EFI_SUCCESS The procedure has been successfully scheduled
585 SmmBlockingStartupThisAp (
586 IN EFI_AP_PROCEDURE Procedure
,
588 IN OUT VOID
*ProcArguments OPTIONAL
592 This function sets the attributes for the memory region specified by BaseAddress and
593 Length from their current attributes to the attributes specified by Attributes.
595 @param[in] BaseAddress The physical address that is the start address of a memory region.
596 @param[in] Length The size in bytes of the memory region.
597 @param[in] Attributes The bit mask of attributes to set for the memory region.
599 @retval EFI_SUCCESS The attributes were set for the memory region.
600 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
601 BaseAddress and Length cannot be modified.
602 @retval EFI_INVALID_PARAMETER Length is zero.
603 Attributes specified an illegal combination of attributes that
604 cannot be set together.
605 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
606 the memory resource range.
607 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
608 resource range specified by BaseAddress and Length.
609 The bit mask of attributes is not support for the memory resource
610 range specified by BaseAddress and Length.
615 SmmSetMemoryAttributes (
616 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
622 This function clears the attributes for the memory region specified by BaseAddress and
623 Length from their current attributes to the attributes specified by Attributes.
625 @param[in] BaseAddress The physical address that is the start address of a memory region.
626 @param[in] Length The size in bytes of the memory region.
627 @param[in] Attributes The bit mask of attributes to clear for the memory region.
629 @retval EFI_SUCCESS The attributes were cleared for the memory region.
630 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
631 BaseAddress and Length cannot be modified.
632 @retval EFI_INVALID_PARAMETER Length is zero.
633 Attributes specified an illegal combination of attributes that
634 cannot be set together.
635 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
636 the memory resource range.
637 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
638 resource range specified by BaseAddress and Length.
639 The bit mask of attributes is not support for the memory resource
640 range specified by BaseAddress and Length.
645 SmmClearMemoryAttributes (
646 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
652 Initialize MP synchronization data.
657 InitializeMpSyncData (
663 Find out SMRAM information including SMRR base and SMRR size.
665 @param SmrrBase SMRR base
666 @param SmrrSize SMRR size
671 OUT UINT32
*SmrrBase
,
676 Relocate SmmBases for each processor.
678 Execute on first boot and all S3 resumes
688 Page Fault handler for SMM use.
690 @param InterruptType Defines the type of interrupt or exception that
691 occurred on the processor.This parameter is processor architecture specific.
692 @param SystemContext A pointer to the processor context when
693 the interrupt occurred on the processor.
698 IN EFI_EXCEPTION_TYPE InterruptType
,
699 IN EFI_SYSTEM_CONTEXT SystemContext
703 Perform the remaining tasks.
707 PerformRemainingTasks (
712 Perform the pre tasks.
721 Initialize MSR spin lock by MSR index.
723 @param MsrIndex MSR index value.
727 InitMsrSpinLockByIndex (
732 Hook return address of SMM Save State so that semaphore code
733 can be executed immediately after AP exits SMM to indicate to
734 the BSP that an AP has exited SMM after SMBASE relocation.
736 @param[in] CpuIndex The processor index.
737 @param[in] RebasedFlag A pointer to a flag that is set to TRUE
738 immediately after AP exits SMM.
744 IN
volatile BOOLEAN
*RebasedFlag
748 Configure SMM Code Access Check feature for all processors.
749 SMM Feature Control MSR will be locked after configuration.
752 ConfigSmmCodeAccessCheck (
757 Hook the code executed immediately after an RSM instruction on the currently
758 executing CPU. The mode of code executed immediately after RSM must be
759 detected, and the appropriate hook must be selected. Always clear the auto
760 HALT restart flag if it is set.
762 @param[in] CpuIndex The processor index for the currently
764 @param[in] CpuState Pointer to SMRAM Save State Map for the
765 currently executing CPU.
766 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
767 32-bit mode from 64-bit SMM.
768 @param[in] NewInstructionPointer Instruction pointer to use if resuming to
771 @retval The value of the original instruction pointer before it was hooked.
778 SMRAM_SAVE_STATE_MAP
*CpuState
,
779 UINT64 NewInstructionPointer32
,
780 UINT64 NewInstructionPointer
784 Get the size of the SMI Handler in bytes.
786 @retval The size, in bytes, of the SMI Handler.
796 Install the SMI handler for the CPU specified by CpuIndex. This function
797 is called by the CPU that was elected as monarch during System Management
800 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.
801 The value must be between 0 and the NumberOfCpus field
802 in the System Management System Table (SMST).
803 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
804 @param[in] SmiStack The stack to use when an SMI is processed by the
805 the CPU specified by CpuIndex.
806 @param[in] StackSize The size, in bytes, if the stack used when an SMI is
807 processed by the CPU specified by CpuIndex.
808 @param[in] GdtBase The base address of the GDT to use when an SMI is
809 processed by the CPU specified by CpuIndex.
810 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is
811 processed by the CPU specified by CpuIndex.
812 @param[in] IdtBase The base address of the IDT to use when an SMI is
813 processed by the CPU specified by CpuIndex.
814 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is
815 processed by the CPU specified by CpuIndex.
816 @param[in] Cr3 The base address of the page tables to use when an SMI
817 is processed by the CPU specified by CpuIndex.
834 Search module name by input IP address and output it.
836 @param CallerIpAddress Caller instruction pointer.
841 IN UINTN CallerIpAddress
845 This function sets memory attribute according to MemoryAttributesTable.
848 SetMemMapAttributes (
853 This function sets UEFI memory attribute according to UEFI memory map.
856 SetUefiMemMapAttributes (
861 Return if the Address is forbidden as SMM communication buffer.
863 @param[in] Address the address to be checked
865 @return TRUE The address is forbidden as SMM communication buffer.
866 @return FALSE The address is allowed as SMM communication buffer.
869 IsSmmCommBufferForbiddenAddress (
874 This function caches the UEFI memory map information.
882 This function sets memory attribute for page table.
885 SetPageTableAttributes (
890 Return page table base.
892 @return page table base.
900 This function sets the attributes for the memory region specified by BaseAddress and
901 Length from their current attributes to the attributes specified by Attributes.
903 @param[in] BaseAddress The physical address that is the start address of a memory region.
904 @param[in] Length The size in bytes of the memory region.
905 @param[in] Attributes The bit mask of attributes to set for the memory region.
906 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
908 @retval EFI_SUCCESS The attributes were set for the memory region.
909 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
910 BaseAddress and Length cannot be modified.
911 @retval EFI_INVALID_PARAMETER Length is zero.
912 Attributes specified an illegal combination of attributes that
913 cannot be set together.
914 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
915 the memory resource range.
916 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
917 resource range specified by BaseAddress and Length.
918 The bit mask of attributes is not support for the memory resource
919 range specified by BaseAddress and Length.
924 SmmSetMemoryAttributesEx (
925 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
927 IN UINT64 Attributes
,
928 OUT BOOLEAN
*IsSplitted OPTIONAL
932 This function clears the attributes for the memory region specified by BaseAddress and
933 Length from their current attributes to the attributes specified by Attributes.
935 @param[in] BaseAddress The physical address that is the start address of a memory region.
936 @param[in] Length The size in bytes of the memory region.
937 @param[in] Attributes The bit mask of attributes to clear for the memory region.
938 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
940 @retval EFI_SUCCESS The attributes were cleared for the memory region.
941 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
942 BaseAddress and Length cannot be modified.
943 @retval EFI_INVALID_PARAMETER Length is zero.
944 Attributes specified an illegal combination of attributes that
945 cannot be set together.
946 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
947 the memory resource range.
948 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
949 resource range specified by BaseAddress and Length.
950 The bit mask of attributes is not support for the memory resource
951 range specified by BaseAddress and Length.
956 SmmClearMemoryAttributesEx (
957 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
959 IN UINT64 Attributes
,
960 OUT BOOLEAN
*IsSplitted OPTIONAL
964 This API provides a way to allocate memory for page table.
966 This API can be called more once to allocate memory for page tables.
968 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
969 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
970 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
973 @param Pages The number of 4 KB pages to allocate.
975 @return A pointer to the allocated buffer or NULL if allocation fails.
979 AllocatePageTableMemory (
984 Allocate pages for code.
986 @param[in] Pages Number of pages to be allocated.
988 @return Allocated memory.
996 Allocate aligned pages for code.
998 @param[in] Pages Number of pages to be allocated.
999 @param[in] Alignment The requested alignment of the allocation.
1000 Must be a power of two.
1001 If Alignment is zero, then byte alignment is used.
1003 @return Allocated memory.
1006 AllocateAlignedCodePages (
1013 // S3 related global variable and function prototype.
1016 extern BOOLEAN mSmmS3Flag
;
1019 Initialize SMM S3 resume state structure used during S3 Resume.
1021 @param[in] Cr3 The base address of the page tables to use in SMM.
1025 InitSmmS3ResumeState (
1039 Restore SMM Configuration in S3 boot path.
1043 RestoreSmmConfigurationInS3 (
1048 Get ACPI S3 enable flag.
1052 GetAcpiS3EnableFlag (
1057 Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.
1059 @param[in] ApHltLoopCode The address of the safe hlt-loop function.
1060 @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.
1061 @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.
1065 TransferApToSafeState (
1066 IN UINTN ApHltLoopCode
,
1067 IN UINTN TopOfStack
,
1068 IN UINTN NumberToFinishAddress