2 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.
4 Copyright (c) 2009 - 2018, 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>
28 #include <Protocol/SmmMemoryAttribute.h>
30 #include <Guid/AcpiS3Context.h>
31 #include <Guid/MemoryAttributesTable.h>
32 #include <Guid/PiSmmMemoryAttributesTable.h>
34 #include <Library/BaseLib.h>
35 #include <Library/IoLib.h>
36 #include <Library/TimerLib.h>
37 #include <Library/SynchronizationLib.h>
38 #include <Library/DebugLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/PcdLib.h>
41 #include <Library/CacheMaintenanceLib.h>
42 #include <Library/MtrrLib.h>
43 #include <Library/SmmCpuPlatformHookLib.h>
44 #include <Library/SmmServicesTableLib.h>
45 #include <Library/MemoryAllocationLib.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/UefiRuntimeServicesTableLib.h>
48 #include <Library/DebugAgentLib.h>
49 #include <Library/UefiLib.h>
50 #include <Library/HobLib.h>
51 #include <Library/LocalApicLib.h>
52 #include <Library/UefiCpuLib.h>
53 #include <Library/CpuExceptionHandlerLib.h>
54 #include <Library/ReportStatusCodeLib.h>
55 #include <Library/SmmCpuFeaturesLib.h>
56 #include <Library/PeCoffGetEntryPointLib.h>
58 #include <AcpiCpuData.h>
59 #include <CpuHotPlugData.h>
61 #include <Register/Cpuid.h>
62 #include <Register/Msr.h>
64 #include "CpuService.h"
65 #include "SmmProfile.h"
68 // MSRs required for configuration of SMM Code Access Check
70 #define EFI_MSR_SMM_MCA_CAP 0x17D
71 #define SMM_CODE_ACCESS_CHK_BIT BIT58
73 #define SMM_FEATURE_CONTROL_LOCK_BIT BIT0
74 #define SMM_CODE_CHK_EN_BIT BIT2
79 #define IA32_PG_P BIT0
80 #define IA32_PG_RW BIT1
81 #define IA32_PG_U BIT2
82 #define IA32_PG_WT BIT3
83 #define IA32_PG_CD BIT4
84 #define IA32_PG_A BIT5
85 #define IA32_PG_D BIT6
86 #define IA32_PG_PS BIT7
87 #define IA32_PG_PAT_2M BIT12
88 #define IA32_PG_PAT_4K IA32_PG_PS
89 #define IA32_PG_PMNT BIT62
90 #define IA32_PG_NX BIT63
92 #define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)
94 // Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE
95 // X64 PAE PDPTE does not have such restriction
97 #define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)
99 #define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)
101 #define PAGING_4K_MASK 0xFFF
102 #define PAGING_2M_MASK 0x1FFFFF
103 #define PAGING_1G_MASK 0x3FFFFFFF
105 #define PAGING_PAE_INDEX_MASK 0x1FF
107 #define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
108 #define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
109 #define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
111 #define SMRR_MAX_ADDRESS BASE_4GB
121 PAGE_ATTRIBUTE Attribute
;
124 } PAGE_ATTRIBUTE_TABLE
;
127 // Size of Task-State Segment defined in IA32 Manual
130 #define TSS_X64_IST1_OFFSET 36
131 #define TSS_IA32_CR3_OFFSET 28
132 #define TSS_IA32_ESP_OFFSET 56
139 #define PROTECT_MODE_CODE_SEGMENT 0x08
140 #define LONG_MODE_CODE_SEGMENT 0x38
143 // The size 0x20 must be bigger than
144 // the size of template code of SmmInit. Currently,
145 // the size of SmmInit requires the 0x16 Bytes buffer
148 #define BACK_BUF_SIZE 0x20
150 #define EXCEPTION_VECTOR_NUMBER 0x20
152 #define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL
154 typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS
;
155 #define ARRIVAL_EXCEPTION_BLOCKED 0x1
156 #define ARRIVAL_EXCEPTION_DELAYED 0x2
157 #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4
160 // Private structure for the SMM CPU module that is stored in DXE Runtime memory
161 // Contains the SMM Configuration Protocols that is produced.
162 // Contains a mix of DXE and SMM contents. All the fields must be used properly.
164 #define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')
169 EFI_HANDLE SmmCpuHandle
;
171 EFI_PROCESSOR_INFORMATION
*ProcessorInfo
;
172 SMM_CPU_OPERATION
*Operation
;
173 UINTN
*CpuSaveStateSize
;
176 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion
[1];
177 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext
;
178 EFI_SMM_ENTRY_POINT SmmCoreEntry
;
180 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration
;
181 } SMM_CPU_PRIVATE_DATA
;
183 extern SMM_CPU_PRIVATE_DATA
*gSmmCpuPrivate
;
184 extern CPU_HOT_PLUG_DATA mCpuHotPlugData
;
185 extern UINTN mMaxNumberOfCpus
;
186 extern UINTN mNumberOfCpus
;
187 extern EFI_SMM_CPU_PROTOCOL mSmmCpu
;
190 /// The mode of the CPU at the time an SMI occurs
192 extern UINT8 mSmmSaveStateRegisterLma
;
195 // SMM CPU Protocol function prototypes.
199 Read information from the CPU save state.
201 @param This EFI_SMM_CPU_PROTOCOL instance
202 @param Width The number of bytes to read from the CPU save state.
203 @param Register Specifies the CPU register to read form the save state.
204 @param CpuIndex Specifies the zero-based index of the CPU save state
205 @param Buffer Upon return, this holds the CPU register value read from the save state.
207 @retval EFI_SUCCESS The register was read from Save State
208 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
209 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
215 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
217 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
223 Write data to the CPU save state.
225 @param This EFI_SMM_CPU_PROTOCOL instance
226 @param Width The number of bytes to read from the CPU save state.
227 @param Register Specifies the CPU register to write to the save state.
228 @param CpuIndex Specifies the zero-based index of the CPU save state
229 @param Buffer Upon entry, this holds the new CPU register value.
231 @retval EFI_SUCCESS The register was written from Save State
232 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
233 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct
239 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
241 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
243 IN CONST VOID
*Buffer
247 Read a CPU Save State register on the target processor.
249 This function abstracts the differences that whether the CPU Save State register is in the
250 IA32 CPU Save State Map or X64 CPU Save State Map.
252 This function supports reading a CPU Save State register in SMBase relocation handler.
254 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
255 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
256 @param[in] Width The number of bytes to read from the CPU save state.
257 @param[out] Buffer Upon return, this holds the CPU register value read from the save state.
259 @retval EFI_SUCCESS The register was read from Save State.
260 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
261 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
266 ReadSaveStateRegister (
268 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
274 Write value to a CPU Save State register on the target processor.
276 This function abstracts the differences that whether the CPU Save State register is in the
277 IA32 CPU Save State Map or X64 CPU Save State Map.
279 This function supports writing a CPU Save State register in SMBase relocation handler.
281 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
282 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
283 @param[in] Width The number of bytes to read from the CPU save state.
284 @param[in] Buffer Upon entry, this holds the new CPU register value.
286 @retval EFI_SUCCESS The register was written to Save State.
287 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
288 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct.
293 WriteSaveStateRegister (
295 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
297 IN CONST VOID
*Buffer
300 extern CONST UINT8 gcSmmInitTemplate
[];
301 extern CONST UINT16 gcSmmInitSize
;
302 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0
;
303 extern UINT32 mSmmCr0
;
304 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3
;
305 extern UINT32 mSmmCr4
;
306 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4
;
307 X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack
;
310 Semaphore operation for all processor relocate SMMBase.
314 SmmRelocationSemaphoreComplete (
319 /// The type of SMM CPU Information
323 volatile EFI_AP_PROCEDURE Procedure
;
324 volatile VOID
*Parameter
;
325 volatile UINT32
*Run
;
326 volatile BOOLEAN
*Present
;
327 } SMM_CPU_DATA_BLOCK
;
330 SmmCpuSyncModeTradition
,
331 SmmCpuSyncModeRelaxedAp
,
337 // Pointer to an array. The array should be located immediately after this structure
338 // so that UC cache-ability can be set together.
340 SMM_CPU_DATA_BLOCK
*CpuData
;
341 volatile UINT32
*Counter
;
342 volatile UINT32 BspIndex
;
343 volatile BOOLEAN
*InsideSmm
;
344 volatile BOOLEAN
*AllCpusInSync
;
345 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode
;
346 volatile BOOLEAN SwitchBsp
;
347 volatile BOOLEAN
*CandidateBsp
;
348 } SMM_DISPATCHER_MP_SYNC_DATA
;
350 #define MSR_SPIN_LOCK_INIT_NUM 15
357 #define SMM_PSD_OFFSET 0xfb00
360 /// All global semaphores' pointer
363 volatile UINT32
*Counter
;
364 volatile BOOLEAN
*InsideSmm
;
365 volatile BOOLEAN
*AllCpusInSync
;
367 SPIN_LOCK
*CodeAccessCheckLock
;
368 SPIN_LOCK
*MemoryMappedLock
;
369 } SMM_CPU_SEMAPHORE_GLOBAL
;
372 /// All semaphores for each processor
376 volatile UINT32
*Run
;
377 volatile BOOLEAN
*Present
;
378 } SMM_CPU_SEMAPHORE_CPU
;
381 /// All MSRs semaphores' pointer and counter
385 UINTN AvailableCounter
;
386 } SMM_CPU_SEMAPHORE_MSR
;
389 /// All semaphores' information
392 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal
;
393 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu
;
394 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr
;
395 } SMM_CPU_SEMAPHORES
;
397 extern IA32_DESCRIPTOR gcSmiGdtr
;
398 extern EFI_PHYSICAL_ADDRESS mGdtBuffer
;
399 extern UINTN mGdtBufferSize
;
400 extern IA32_DESCRIPTOR gcSmiIdtr
;
401 extern VOID
*gcSmiIdtrPtr
;
402 extern UINT64 gPhyMask
;
403 extern SMM_DISPATCHER_MP_SYNC_DATA
*mSmmMpSyncData
;
404 extern UINTN mSmmStackArrayBase
;
405 extern UINTN mSmmStackArrayEnd
;
406 extern UINTN mSmmStackSize
;
407 extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService
;
408 extern IA32_DESCRIPTOR gcSmiInitGdtr
;
409 extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores
;
410 extern UINTN mSemaphoreSize
;
411 extern SPIN_LOCK
*mPFLock
;
412 extern SPIN_LOCK
*mConfigSmmCodeAccessCheckLock
;
413 extern SPIN_LOCK
*mMemoryMappedLock
;
414 extern EFI_SMRAM_DESCRIPTOR
*mSmmCpuSmramRanges
;
415 extern UINTN mSmmCpuSmramRangeCount
;
416 extern UINT8 mPhysicalAddressBits
;
419 // Copy of the PcdPteMemoryEncryptionAddressOrMask
421 extern UINT64 mAddressEncMask
;
424 Create 4G PageTable in SMRAM.
426 @param[in] Is32BitPageTable Whether the page table is 32-bit PAE
427 @return PageTable Address
432 IN BOOLEAN Is32BitPageTable
437 Initialize global data for MP synchronization.
439 @param Stacks Base address of SMI stack buffer for all processors.
440 @param StackSize Stack size for each processor in SMM.
444 InitializeMpServiceData (
450 Initialize Timer for SMM AP Sync.
459 Start Timer for SMM AP Sync.
469 Check if the SMM AP Sync timer is timeout.
471 @param Timer The start timer from the begin.
481 Initialize IDT for SMM Stack Guard.
486 InitializeIDTSmmStackGuard (
491 Initialize Gdt for all processors.
493 @param[in] Cr3 CR3 value.
494 @param[out] GdtStepSize The step size for GDT table.
496 @return GdtBase for processor 0.
497 GdtBase for processor X is: GdtBase + (GdtStepSize * X)
502 OUT UINTN
*GdtStepSize
507 Register the SMM Foundation entry point.
509 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance
510 @param SmmEntryPoint SMM Foundation EntryPoint
512 @retval EFI_SUCCESS Successfully to register SMM foundation entry point
518 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL
*This
,
519 IN EFI_SMM_ENTRY_POINT SmmEntryPoint
523 Create PageTable for SMM use.
525 @return PageTable Address
534 Schedule a procedure to run on the specified CPU.
536 @param Procedure The address of the procedure to run
537 @param CpuIndex Target CPU number
538 @param ProcArguments The parameter to pass to the procedure
540 @retval EFI_INVALID_PARAMETER CpuNumber not valid
541 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
542 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
543 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
544 @retval EFI_SUCCESS - The procedure has been successfully scheduled
550 IN EFI_AP_PROCEDURE Procedure
,
552 IN OUT VOID
*ProcArguments OPTIONAL
556 Schedule a procedure to run on the specified CPU in a blocking fashion.
558 @param Procedure The address of the procedure to run
559 @param CpuIndex Target CPU Index
560 @param ProcArguments The parameter to pass to the procedure
562 @retval EFI_INVALID_PARAMETER CpuNumber not valid
563 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
564 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
565 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
566 @retval EFI_SUCCESS The procedure has been successfully scheduled
571 SmmBlockingStartupThisAp (
572 IN EFI_AP_PROCEDURE Procedure
,
574 IN OUT VOID
*ProcArguments OPTIONAL
578 This function sets the attributes for the memory region specified by BaseAddress and
579 Length from their current attributes to the attributes specified by Attributes.
581 @param[in] BaseAddress The physical address that is the start address of a memory region.
582 @param[in] Length The size in bytes of the memory region.
583 @param[in] Attributes The bit mask of attributes to set for the memory region.
585 @retval EFI_SUCCESS The attributes were set for the memory region.
586 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
587 BaseAddress and Length cannot be modified.
588 @retval EFI_INVALID_PARAMETER Length is zero.
589 Attributes specified an illegal combination of attributes that
590 cannot be set together.
591 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
592 the memory resource range.
593 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
594 resource range specified by BaseAddress and Length.
595 The bit mask of attributes is not support for the memory resource
596 range specified by BaseAddress and Length.
601 SmmSetMemoryAttributes (
602 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
608 This function clears the attributes for the memory region specified by BaseAddress and
609 Length from their current attributes to the attributes specified by Attributes.
611 @param[in] BaseAddress The physical address that is the start address of a memory region.
612 @param[in] Length The size in bytes of the memory region.
613 @param[in] Attributes The bit mask of attributes to clear for the memory region.
615 @retval EFI_SUCCESS The attributes were cleared for the memory region.
616 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
617 BaseAddress and Length cannot be modified.
618 @retval EFI_INVALID_PARAMETER Length is zero.
619 Attributes specified an illegal combination of attributes that
620 cannot be set together.
621 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
622 the memory resource range.
623 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
624 resource range specified by BaseAddress and Length.
625 The bit mask of attributes is not support for the memory resource
626 range specified by BaseAddress and Length.
631 SmmClearMemoryAttributes (
632 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
638 Initialize MP synchronization data.
643 InitializeMpSyncData (
649 Find out SMRAM information including SMRR base and SMRR size.
651 @param SmrrBase SMRR base
652 @param SmrrSize SMRR size
657 OUT UINT32
*SmrrBase
,
662 Relocate SmmBases for each processor.
664 Execute on first boot and all S3 resumes
674 Page Fault handler for SMM use.
676 @param InterruptType Defines the type of interrupt or exception that
677 occurred on the processor.This parameter is processor architecture specific.
678 @param SystemContext A pointer to the processor context when
679 the interrupt occurred on the processor.
684 IN EFI_EXCEPTION_TYPE InterruptType
,
685 IN EFI_SYSTEM_CONTEXT SystemContext
689 Perform the remaining tasks.
693 PerformRemainingTasks (
698 Perform the pre tasks.
707 Initialize MSR spin lock by MSR index.
709 @param MsrIndex MSR index value.
713 InitMsrSpinLockByIndex (
718 Hook return address of SMM Save State so that semaphore code
719 can be executed immediately after AP exits SMM to indicate to
720 the BSP that an AP has exited SMM after SMBASE relocation.
722 @param[in] CpuIndex The processor index.
723 @param[in] RebasedFlag A pointer to a flag that is set to TRUE
724 immediately after AP exits SMM.
730 IN
volatile BOOLEAN
*RebasedFlag
734 Configure SMM Code Access Check feature for all processors.
735 SMM Feature Control MSR will be locked after configuration.
738 ConfigSmmCodeAccessCheck (
743 Hook the code executed immediately after an RSM instruction on the currently
744 executing CPU. The mode of code executed immediately after RSM must be
745 detected, and the appropriate hook must be selected. Always clear the auto
746 HALT restart flag if it is set.
748 @param[in] CpuIndex The processor index for the currently
750 @param[in] CpuState Pointer to SMRAM Save State Map for the
751 currently executing CPU.
752 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
753 32-bit mode from 64-bit SMM.
754 @param[in] NewInstructionPointer Instruction pointer to use if resuming to
757 @retval The value of the original instruction pointer before it was hooked.
764 SMRAM_SAVE_STATE_MAP
*CpuState
,
765 UINT64 NewInstructionPointer32
,
766 UINT64 NewInstructionPointer
770 Get the size of the SMI Handler in bytes.
772 @retval The size, in bytes, of the SMI Handler.
782 Install the SMI handler for the CPU specified by CpuIndex. This function
783 is called by the CPU that was elected as monarch during System Management
786 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.
787 The value must be between 0 and the NumberOfCpus field
788 in the System Management System Table (SMST).
789 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
790 @param[in] SmiStack The stack to use when an SMI is processed by the
791 the CPU specified by CpuIndex.
792 @param[in] StackSize The size, in bytes, if the stack used when an SMI is
793 processed by the CPU specified by CpuIndex.
794 @param[in] GdtBase The base address of the GDT to use when an SMI is
795 processed by the CPU specified by CpuIndex.
796 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is
797 processed by the CPU specified by CpuIndex.
798 @param[in] IdtBase The base address of the IDT to use when an SMI is
799 processed by the CPU specified by CpuIndex.
800 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is
801 processed by the CPU specified by CpuIndex.
802 @param[in] Cr3 The base address of the page tables to use when an SMI
803 is processed by the CPU specified by CpuIndex.
820 Search module name by input IP address and output it.
822 @param CallerIpAddress Caller instruction pointer.
827 IN UINTN CallerIpAddress
831 This function sets memory attribute according to MemoryAttributesTable.
834 SetMemMapAttributes (
839 This function sets UEFI memory attribute according to UEFI memory map.
842 SetUefiMemMapAttributes (
847 Return if the Address is forbidden as SMM communication buffer.
849 @param[in] Address the address to be checked
851 @return TRUE The address is forbidden as SMM communication buffer.
852 @return FALSE The address is allowed as SMM communication buffer.
855 IsSmmCommBufferForbiddenAddress (
860 This function caches the UEFI memory map information.
868 This function sets memory attribute for page table.
871 SetPageTableAttributes (
876 Return page table base.
878 @return page table base.
886 This function sets the attributes for the memory region specified by BaseAddress and
887 Length from their current attributes to the attributes specified by Attributes.
889 @param[in] BaseAddress The physical address that is the start address of a memory region.
890 @param[in] Length The size in bytes of the memory region.
891 @param[in] Attributes The bit mask of attributes to set for the memory region.
892 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
894 @retval EFI_SUCCESS The attributes were set for the memory region.
895 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
896 BaseAddress and Length cannot be modified.
897 @retval EFI_INVALID_PARAMETER Length is zero.
898 Attributes specified an illegal combination of attributes that
899 cannot be set together.
900 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
901 the memory resource range.
902 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
903 resource range specified by BaseAddress and Length.
904 The bit mask of attributes is not support for the memory resource
905 range specified by BaseAddress and Length.
910 SmmSetMemoryAttributesEx (
911 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
913 IN UINT64 Attributes
,
914 OUT BOOLEAN
*IsSplitted OPTIONAL
918 This function clears the attributes for the memory region specified by BaseAddress and
919 Length from their current attributes to the attributes specified by Attributes.
921 @param[in] BaseAddress The physical address that is the start address of a memory region.
922 @param[in] Length The size in bytes of the memory region.
923 @param[in] Attributes The bit mask of attributes to clear for the memory region.
924 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
926 @retval EFI_SUCCESS The attributes were cleared for the memory region.
927 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
928 BaseAddress and Length cannot be modified.
929 @retval EFI_INVALID_PARAMETER Length is zero.
930 Attributes specified an illegal combination of attributes that
931 cannot be set together.
932 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
933 the memory resource range.
934 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
935 resource range specified by BaseAddress and Length.
936 The bit mask of attributes is not support for the memory resource
937 range specified by BaseAddress and Length.
942 SmmClearMemoryAttributesEx (
943 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
945 IN UINT64 Attributes
,
946 OUT BOOLEAN
*IsSplitted OPTIONAL
950 This API provides a way to allocate memory for page table.
952 This API can be called more once to allocate memory for page tables.
954 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
955 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
956 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
959 @param Pages The number of 4 KB pages to allocate.
961 @return A pointer to the allocated buffer or NULL if allocation fails.
965 AllocatePageTableMemory (
970 Allocate pages for code.
972 @param[in] Pages Number of pages to be allocated.
974 @return Allocated memory.
982 Allocate aligned pages for code.
984 @param[in] Pages Number of pages to be allocated.
985 @param[in] Alignment The requested alignment of the allocation.
986 Must be a power of two.
987 If Alignment is zero, then byte alignment is used.
989 @return Allocated memory.
992 AllocateAlignedCodePages (
999 // S3 related global variable and function prototype.
1002 extern BOOLEAN mSmmS3Flag
;
1005 Initialize SMM S3 resume state structure used during S3 Resume.
1007 @param[in] Cr3 The base address of the page tables to use in SMM.
1011 InitSmmS3ResumeState (
1025 Restore SMM Configuration in S3 boot path.
1029 RestoreSmmConfigurationInS3 (
1034 Get ACPI S3 enable flag.
1038 GetAcpiS3EnableFlag (
1043 Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.
1045 @param[in] ApHltLoopCode The address of the safe hlt-loop function.
1046 @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.
1047 @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.
1051 TransferApToSafeState (
1052 IN UINTN ApHltLoopCode
,
1053 IN UINTN TopOfStack
,
1054 IN UINTN NumberToFinishAddress
1058 This function set given attributes of the memory region specified by
1059 BaseAddress and Length.
1061 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1062 @param BaseAddress The physical address that is the start address of
1064 @param Length The size in bytes of the memory region.
1065 @param Attributes The bit mask of attributes to set for the memory
1068 @retval EFI_SUCCESS The attributes were set for the memory region.
1069 @retval EFI_INVALID_PARAMETER Length is zero.
1070 Attributes specified an illegal combination of
1071 attributes that cannot be set together.
1072 @retval EFI_UNSUPPORTED The processor does not support one or more
1073 bytes of the memory resource range specified
1074 by BaseAddress and Length.
1075 The bit mask of attributes is not supported for
1076 the memory resource range specified by
1077 BaseAddress and Length.
1082 EdkiiSmmSetMemoryAttributes (
1083 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1084 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1086 IN UINT64 Attributes
1090 This function clears given attributes of the memory region specified by
1091 BaseAddress and Length.
1093 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1094 @param BaseAddress The physical address that is the start address of
1096 @param Length The size in bytes of the memory region.
1097 @param Attributes The bit mask of attributes to clear for the memory
1100 @retval EFI_SUCCESS The attributes were cleared for the memory region.
1101 @retval EFI_INVALID_PARAMETER Length is zero.
1102 Attributes specified an illegal combination of
1103 attributes that cannot be cleared together.
1104 @retval EFI_UNSUPPORTED The processor does not support one or more
1105 bytes of the memory resource range specified
1106 by BaseAddress and Length.
1107 The bit mask of attributes is not supported for
1108 the memory resource range specified by
1109 BaseAddress and Length.
1114 EdkiiSmmClearMemoryAttributes (
1115 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1116 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1118 IN UINT64 Attributes
1122 This function retrieves the attributes of the memory region specified by
1123 BaseAddress and Length. If different attributes are got from different part
1124 of the memory region, EFI_NO_MAPPING will be returned.
1126 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1127 @param BaseAddress The physical address that is the start address of
1129 @param Length The size in bytes of the memory region.
1130 @param Attributes Pointer to attributes returned.
1132 @retval EFI_SUCCESS The attributes got for the memory region.
1133 @retval EFI_INVALID_PARAMETER Length is zero.
1135 @retval EFI_NO_MAPPING Attributes are not consistent cross the memory
1137 @retval EFI_UNSUPPORTED The processor does not support one or more
1138 bytes of the memory resource range specified
1139 by BaseAddress and Length.
1144 EdkiiSmmGetMemoryAttributes (
1145 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1146 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1148 IN UINT64
*Attributes
1152 This function fixes up the address of the global variable or function
1153 referred in SmmInit assembly files to be the absoute address.
1157 PiSmmCpuSmmInitFixupAddress (
1161 This function fixes up the address of the global variable or function
1162 referred in SmiEntry assembly files to be the absoute address.
1166 PiSmmCpuSmiEntryFixupAddress (