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/PiSmmMemoryAttributesTable.h>
33 #include <Library/BaseLib.h>
34 #include <Library/IoLib.h>
35 #include <Library/TimerLib.h>
36 #include <Library/SynchronizationLib.h>
37 #include <Library/DebugLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/PcdLib.h>
40 #include <Library/CacheMaintenanceLib.h>
41 #include <Library/MtrrLib.h>
42 #include <Library/SmmCpuPlatformHookLib.h>
43 #include <Library/SmmServicesTableLib.h>
44 #include <Library/MemoryAllocationLib.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/UefiRuntimeServicesTableLib.h>
47 #include <Library/DebugAgentLib.h>
48 #include <Library/HobLib.h>
49 #include <Library/LocalApicLib.h>
50 #include <Library/UefiCpuLib.h>
51 #include <Library/CpuExceptionHandlerLib.h>
52 #include <Library/ReportStatusCodeLib.h>
53 #include <Library/SmmCpuFeaturesLib.h>
54 #include <Library/PeCoffGetEntryPointLib.h>
56 #include <AcpiCpuData.h>
57 #include <CpuHotPlugData.h>
59 #include <Register/Cpuid.h>
60 #include <Register/Msr.h>
62 #include "CpuService.h"
63 #include "SmmProfile.h"
66 // MSRs required for configuration of SMM Code Access Check
68 #define EFI_MSR_SMM_MCA_CAP 0x17D
69 #define SMM_CODE_ACCESS_CHK_BIT BIT58
71 #define SMM_FEATURE_CONTROL_LOCK_BIT BIT0
72 #define SMM_CODE_CHK_EN_BIT BIT2
77 #define IA32_PG_P BIT0
78 #define IA32_PG_RW BIT1
79 #define IA32_PG_U BIT2
80 #define IA32_PG_WT BIT3
81 #define IA32_PG_CD BIT4
82 #define IA32_PG_A BIT5
83 #define IA32_PG_D BIT6
84 #define IA32_PG_PS BIT7
85 #define IA32_PG_PAT_2M BIT12
86 #define IA32_PG_PAT_4K IA32_PG_PS
87 #define IA32_PG_PMNT BIT62
88 #define IA32_PG_NX BIT63
90 #define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)
92 // Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE
93 // X64 PAE PDPTE does not have such restriction
95 #define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)
97 #define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)
99 #define PAGING_4K_MASK 0xFFF
100 #define PAGING_2M_MASK 0x1FFFFF
101 #define PAGING_1G_MASK 0x3FFFFFFF
103 #define PAGING_PAE_INDEX_MASK 0x1FF
105 #define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
106 #define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
107 #define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
109 #define SMRR_MAX_ADDRESS BASE_4GB
119 PAGE_ATTRIBUTE Attribute
;
122 } PAGE_ATTRIBUTE_TABLE
;
125 // Size of Task-State Segment defined in IA32 Manual
128 #define TSS_X64_IST1_OFFSET 36
129 #define TSS_IA32_CR3_OFFSET 28
130 #define TSS_IA32_ESP_OFFSET 56
137 #define PROTECT_MODE_CODE_SEGMENT 0x08
138 #define LONG_MODE_CODE_SEGMENT 0x38
141 // The size 0x20 must be bigger than
142 // the size of template code of SmmInit. Currently,
143 // the size of SmmInit requires the 0x16 Bytes buffer
146 #define BACK_BUF_SIZE 0x20
148 #define EXCEPTION_VECTOR_NUMBER 0x20
150 #define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL
152 typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS
;
153 #define ARRIVAL_EXCEPTION_BLOCKED 0x1
154 #define ARRIVAL_EXCEPTION_DELAYED 0x2
155 #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4
158 // Private structure for the SMM CPU module that is stored in DXE Runtime memory
159 // Contains the SMM Configuration Protocols that is produced.
160 // Contains a mix of DXE and SMM contents. All the fields must be used properly.
162 #define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')
167 EFI_HANDLE SmmCpuHandle
;
169 EFI_PROCESSOR_INFORMATION
*ProcessorInfo
;
170 SMM_CPU_OPERATION
*Operation
;
171 UINTN
*CpuSaveStateSize
;
174 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion
[1];
175 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext
;
176 EFI_SMM_ENTRY_POINT SmmCoreEntry
;
178 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration
;
179 } SMM_CPU_PRIVATE_DATA
;
181 extern SMM_CPU_PRIVATE_DATA
*gSmmCpuPrivate
;
182 extern CPU_HOT_PLUG_DATA mCpuHotPlugData
;
183 extern UINTN mMaxNumberOfCpus
;
184 extern UINTN mNumberOfCpus
;
185 extern EFI_SMM_CPU_PROTOCOL mSmmCpu
;
188 /// The mode of the CPU at the time an SMI occurs
190 extern UINT8 mSmmSaveStateRegisterLma
;
193 // SMM CPU Protocol function prototypes.
197 Read information from the CPU save state.
199 @param This EFI_SMM_CPU_PROTOCOL instance
200 @param Width The number of bytes to read from the CPU save state.
201 @param Register Specifies the CPU register to read form the save state.
202 @param CpuIndex Specifies the zero-based index of the CPU save state
203 @param Buffer Upon return, this holds the CPU register value read from the save state.
205 @retval EFI_SUCCESS The register was read from Save State
206 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
207 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
213 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
215 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
221 Write data to the CPU save state.
223 @param This EFI_SMM_CPU_PROTOCOL instance
224 @param Width The number of bytes to read from the CPU save state.
225 @param Register Specifies the CPU register to write to the save state.
226 @param CpuIndex Specifies the zero-based index of the CPU save state
227 @param Buffer Upon entry, this holds the new CPU register value.
229 @retval EFI_SUCCESS The register was written from Save State
230 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
231 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct
237 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
239 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
241 IN CONST VOID
*Buffer
245 Read a CPU Save State register on the target processor.
247 This function abstracts the differences that whether the CPU Save State register is in the
248 IA32 CPU Save State Map or X64 CPU Save State Map.
250 This function supports reading a CPU Save State register in SMBase relocation handler.
252 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
253 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
254 @param[in] Width The number of bytes to read from the CPU save state.
255 @param[out] Buffer Upon return, this holds the CPU register value read from the save state.
257 @retval EFI_SUCCESS The register was read from Save State.
258 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
259 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
264 ReadSaveStateRegister (
266 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
272 Write value to a CPU Save State register on the target processor.
274 This function abstracts the differences that whether the CPU Save State register is in the
275 IA32 CPU Save State Map or X64 CPU Save State Map.
277 This function supports writing a CPU Save State register in SMBase relocation handler.
279 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
280 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
281 @param[in] Width The number of bytes to read from the CPU save state.
282 @param[in] Buffer Upon entry, this holds the new CPU register value.
284 @retval EFI_SUCCESS The register was written to Save State.
285 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
286 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct.
291 WriteSaveStateRegister (
293 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
295 IN CONST VOID
*Buffer
307 extern IA32_FAR_ADDRESS gSmmJmpAddr
;
309 extern CONST UINT8 gcSmmInitTemplate
[];
310 extern CONST UINT16 gcSmmInitSize
;
311 extern UINT32 gSmmCr0
;
312 extern UINT32 gSmmCr3
;
313 extern UINT32 gSmmCr4
;
314 extern UINTN gSmmInitStack
;
317 Semaphore operation for all processor relocate SMMBase.
321 SmmRelocationSemaphoreComplete (
326 /// The type of SMM CPU Information
330 volatile EFI_AP_PROCEDURE Procedure
;
331 volatile VOID
*Parameter
;
332 volatile UINT32
*Run
;
333 volatile BOOLEAN
*Present
;
334 } SMM_CPU_DATA_BLOCK
;
337 SmmCpuSyncModeTradition
,
338 SmmCpuSyncModeRelaxedAp
,
344 // Pointer to an array. The array should be located immediately after this structure
345 // so that UC cache-ability can be set together.
347 SMM_CPU_DATA_BLOCK
*CpuData
;
348 volatile UINT32
*Counter
;
349 volatile UINT32 BspIndex
;
350 volatile BOOLEAN
*InsideSmm
;
351 volatile BOOLEAN
*AllCpusInSync
;
352 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode
;
353 volatile BOOLEAN SwitchBsp
;
354 volatile BOOLEAN
*CandidateBsp
;
355 } SMM_DISPATCHER_MP_SYNC_DATA
;
357 #define MSR_SPIN_LOCK_INIT_NUM 15
364 #define SMM_PSD_OFFSET 0xfb00
367 /// All global semaphores' pointer
370 volatile UINT32
*Counter
;
371 volatile BOOLEAN
*InsideSmm
;
372 volatile BOOLEAN
*AllCpusInSync
;
374 SPIN_LOCK
*CodeAccessCheckLock
;
375 SPIN_LOCK
*MemoryMappedLock
;
376 } SMM_CPU_SEMAPHORE_GLOBAL
;
379 /// All semaphores for each processor
383 volatile UINT32
*Run
;
384 volatile BOOLEAN
*Present
;
385 } SMM_CPU_SEMAPHORE_CPU
;
388 /// All MSRs semaphores' pointer and counter
392 UINTN AvailableCounter
;
393 } SMM_CPU_SEMAPHORE_MSR
;
396 /// All semaphores' information
399 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal
;
400 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu
;
401 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr
;
402 } SMM_CPU_SEMAPHORES
;
404 extern IA32_DESCRIPTOR gcSmiGdtr
;
405 extern EFI_PHYSICAL_ADDRESS mGdtBuffer
;
406 extern UINTN mGdtBufferSize
;
407 extern IA32_DESCRIPTOR gcSmiIdtr
;
408 extern VOID
*gcSmiIdtrPtr
;
409 extern UINT64 gPhyMask
;
410 extern SMM_DISPATCHER_MP_SYNC_DATA
*mSmmMpSyncData
;
411 extern UINTN mSmmStackArrayBase
;
412 extern UINTN mSmmStackArrayEnd
;
413 extern UINTN mSmmStackSize
;
414 extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService
;
415 extern IA32_DESCRIPTOR gcSmiInitGdtr
;
416 extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores
;
417 extern UINTN mSemaphoreSize
;
418 extern SPIN_LOCK
*mPFLock
;
419 extern SPIN_LOCK
*mConfigSmmCodeAccessCheckLock
;
420 extern SPIN_LOCK
*mMemoryMappedLock
;
421 extern EFI_SMRAM_DESCRIPTOR
*mSmmCpuSmramRanges
;
422 extern UINTN mSmmCpuSmramRangeCount
;
423 extern UINT8 mPhysicalAddressBits
;
426 // Copy of the PcdPteMemoryEncryptionAddressOrMask
428 extern UINT64 mAddressEncMask
;
431 Create 4G PageTable in SMRAM.
433 @param[in] Is32BitPageTable Whether the page table is 32-bit PAE
434 @return PageTable Address
439 IN BOOLEAN Is32BitPageTable
444 Initialize global data for MP synchronization.
446 @param Stacks Base address of SMI stack buffer for all processors.
447 @param StackSize Stack size for each processor in SMM.
451 InitializeMpServiceData (
457 Initialize Timer for SMM AP Sync.
466 Start Timer for SMM AP Sync.
476 Check if the SMM AP Sync timer is timeout.
478 @param Timer The start timer from the begin.
488 Initialize IDT for SMM Stack Guard.
493 InitializeIDTSmmStackGuard (
498 Initialize Gdt for all processors.
500 @param[in] Cr3 CR3 value.
501 @param[out] GdtStepSize The step size for GDT table.
503 @return GdtBase for processor 0.
504 GdtBase for processor X is: GdtBase + (GdtStepSize * X)
509 OUT UINTN
*GdtStepSize
514 Register the SMM Foundation entry point.
516 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance
517 @param SmmEntryPoint SMM Foundation EntryPoint
519 @retval EFI_SUCCESS Successfully to register SMM foundation entry point
525 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL
*This
,
526 IN EFI_SMM_ENTRY_POINT SmmEntryPoint
530 Create PageTable for SMM use.
532 @return PageTable Address
541 Schedule a procedure to run on the specified CPU.
543 @param Procedure The address of the procedure to run
544 @param CpuIndex Target CPU number
545 @param ProcArguments The parameter to pass to the procedure
547 @retval EFI_INVALID_PARAMETER CpuNumber not valid
548 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
549 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
550 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
551 @retval EFI_SUCCESS - The procedure has been successfully scheduled
557 IN EFI_AP_PROCEDURE Procedure
,
559 IN OUT VOID
*ProcArguments OPTIONAL
563 Schedule a procedure to run on the specified CPU in a blocking fashion.
565 @param Procedure The address of the procedure to run
566 @param CpuIndex Target CPU Index
567 @param ProcArguments The parameter to pass to the procedure
569 @retval EFI_INVALID_PARAMETER CpuNumber not valid
570 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
571 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
572 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
573 @retval EFI_SUCCESS The procedure has been successfully scheduled
578 SmmBlockingStartupThisAp (
579 IN EFI_AP_PROCEDURE Procedure
,
581 IN OUT VOID
*ProcArguments OPTIONAL
585 This function sets the attributes for the memory region specified by BaseAddress and
586 Length from their current attributes to the attributes specified by Attributes.
588 @param[in] BaseAddress The physical address that is the start address of a memory region.
589 @param[in] Length The size in bytes of the memory region.
590 @param[in] Attributes The bit mask of attributes to set for the memory region.
592 @retval EFI_SUCCESS The attributes were set for the memory region.
593 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
594 BaseAddress and Length cannot be modified.
595 @retval EFI_INVALID_PARAMETER Length is zero.
596 Attributes specified an illegal combination of attributes that
597 cannot be set together.
598 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
599 the memory resource range.
600 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
601 resource range specified by BaseAddress and Length.
602 The bit mask of attributes is not support for the memory resource
603 range specified by BaseAddress and Length.
608 SmmSetMemoryAttributes (
609 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
615 This function clears the attributes for the memory region specified by BaseAddress and
616 Length from their current attributes to the attributes specified by Attributes.
618 @param[in] BaseAddress The physical address that is the start address of a memory region.
619 @param[in] Length The size in bytes of the memory region.
620 @param[in] Attributes The bit mask of attributes to clear for the memory region.
622 @retval EFI_SUCCESS The attributes were cleared for the memory region.
623 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
624 BaseAddress and Length cannot be modified.
625 @retval EFI_INVALID_PARAMETER Length is zero.
626 Attributes specified an illegal combination of attributes that
627 cannot be set together.
628 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
629 the memory resource range.
630 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
631 resource range specified by BaseAddress and Length.
632 The bit mask of attributes is not support for the memory resource
633 range specified by BaseAddress and Length.
638 SmmClearMemoryAttributes (
639 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
645 Initialize MP synchronization data.
650 InitializeMpSyncData (
656 Find out SMRAM information including SMRR base and SMRR size.
658 @param SmrrBase SMRR base
659 @param SmrrSize SMRR size
664 OUT UINT32
*SmrrBase
,
669 Relocate SmmBases for each processor.
671 Execute on first boot and all S3 resumes
681 Page Fault handler for SMM use.
683 @param InterruptType Defines the type of interrupt or exception that
684 occurred on the processor.This parameter is processor architecture specific.
685 @param SystemContext A pointer to the processor context when
686 the interrupt occurred on the processor.
691 IN EFI_EXCEPTION_TYPE InterruptType
,
692 IN EFI_SYSTEM_CONTEXT SystemContext
696 Perform the remaining tasks.
700 PerformRemainingTasks (
705 Perform the pre tasks.
714 Initialize MSR spin lock by MSR index.
716 @param MsrIndex MSR index value.
720 InitMsrSpinLockByIndex (
725 Hook return address of SMM Save State so that semaphore code
726 can be executed immediately after AP exits SMM to indicate to
727 the BSP that an AP has exited SMM after SMBASE relocation.
729 @param[in] CpuIndex The processor index.
730 @param[in] RebasedFlag A pointer to a flag that is set to TRUE
731 immediately after AP exits SMM.
737 IN
volatile BOOLEAN
*RebasedFlag
741 Configure SMM Code Access Check feature for all processors.
742 SMM Feature Control MSR will be locked after configuration.
745 ConfigSmmCodeAccessCheck (
750 Hook the code executed immediately after an RSM instruction on the currently
751 executing CPU. The mode of code executed immediately after RSM must be
752 detected, and the appropriate hook must be selected. Always clear the auto
753 HALT restart flag if it is set.
755 @param[in] CpuIndex The processor index for the currently
757 @param[in] CpuState Pointer to SMRAM Save State Map for the
758 currently executing CPU.
759 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
760 32-bit mode from 64-bit SMM.
761 @param[in] NewInstructionPointer Instruction pointer to use if resuming to
764 @retval The value of the original instruction pointer before it was hooked.
771 SMRAM_SAVE_STATE_MAP
*CpuState
,
772 UINT64 NewInstructionPointer32
,
773 UINT64 NewInstructionPointer
777 Get the size of the SMI Handler in bytes.
779 @retval The size, in bytes, of the SMI Handler.
789 Install the SMI handler for the CPU specified by CpuIndex. This function
790 is called by the CPU that was elected as monarch during System Management
793 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.
794 The value must be between 0 and the NumberOfCpus field
795 in the System Management System Table (SMST).
796 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
797 @param[in] SmiStack The stack to use when an SMI is processed by the
798 the CPU specified by CpuIndex.
799 @param[in] StackSize The size, in bytes, if the stack used when an SMI is
800 processed by the CPU specified by CpuIndex.
801 @param[in] GdtBase The base address of the GDT to use when an SMI is
802 processed by the CPU specified by CpuIndex.
803 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is
804 processed by the CPU specified by CpuIndex.
805 @param[in] IdtBase The base address of the IDT to use when an SMI is
806 processed by the CPU specified by CpuIndex.
807 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is
808 processed by the CPU specified by CpuIndex.
809 @param[in] Cr3 The base address of the page tables to use when an SMI
810 is processed by the CPU specified by CpuIndex.
827 Search module name by input IP address and output it.
829 @param CallerIpAddress Caller instruction pointer.
834 IN UINTN CallerIpAddress
838 This function sets memory attribute according to MemoryAttributesTable.
841 SetMemMapAttributes (
846 This function sets UEFI memory attribute according to UEFI memory map.
849 SetUefiMemMapAttributes (
854 Return if the Address is forbidden as SMM communication buffer.
856 @param[in] Address the address to be checked
858 @return TRUE The address is forbidden as SMM communication buffer.
859 @return FALSE The address is allowed as SMM communication buffer.
862 IsSmmCommBufferForbiddenAddress (
867 This function caches the UEFI memory map information.
875 This function sets memory attribute for page table.
878 SetPageTableAttributes (
883 Return page table base.
885 @return page table base.
893 This function sets the attributes for the memory region specified by BaseAddress and
894 Length from their current attributes to the attributes specified by Attributes.
896 @param[in] BaseAddress The physical address that is the start address of a memory region.
897 @param[in] Length The size in bytes of the memory region.
898 @param[in] Attributes The bit mask of attributes to set for the memory region.
899 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
901 @retval EFI_SUCCESS The attributes were set for the memory region.
902 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
903 BaseAddress and Length cannot be modified.
904 @retval EFI_INVALID_PARAMETER Length is zero.
905 Attributes specified an illegal combination of attributes that
906 cannot be set together.
907 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
908 the memory resource range.
909 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
910 resource range specified by BaseAddress and Length.
911 The bit mask of attributes is not support for the memory resource
912 range specified by BaseAddress and Length.
917 SmmSetMemoryAttributesEx (
918 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
920 IN UINT64 Attributes
,
921 OUT BOOLEAN
*IsSplitted OPTIONAL
925 This function clears the attributes for the memory region specified by BaseAddress and
926 Length from their current attributes to the attributes specified by Attributes.
928 @param[in] BaseAddress The physical address that is the start address of a memory region.
929 @param[in] Length The size in bytes of the memory region.
930 @param[in] Attributes The bit mask of attributes to clear for the memory region.
931 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
933 @retval EFI_SUCCESS The attributes were cleared for the memory region.
934 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
935 BaseAddress and Length cannot be modified.
936 @retval EFI_INVALID_PARAMETER Length is zero.
937 Attributes specified an illegal combination of attributes that
938 cannot be set together.
939 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
940 the memory resource range.
941 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
942 resource range specified by BaseAddress and Length.
943 The bit mask of attributes is not support for the memory resource
944 range specified by BaseAddress and Length.
949 SmmClearMemoryAttributesEx (
950 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
952 IN UINT64 Attributes
,
953 OUT BOOLEAN
*IsSplitted OPTIONAL
957 This API provides a way to allocate memory for page table.
959 This API can be called more once to allocate memory for page tables.
961 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
962 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
963 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
966 @param Pages The number of 4 KB pages to allocate.
968 @return A pointer to the allocated buffer or NULL if allocation fails.
972 AllocatePageTableMemory (
977 Allocate pages for code.
979 @param[in] Pages Number of pages to be allocated.
981 @return Allocated memory.
989 Allocate aligned pages for code.
991 @param[in] Pages Number of pages to be allocated.
992 @param[in] Alignment The requested alignment of the allocation.
993 Must be a power of two.
994 If Alignment is zero, then byte alignment is used.
996 @return Allocated memory.
999 AllocateAlignedCodePages (
1006 // S3 related global variable and function prototype.
1009 extern BOOLEAN mSmmS3Flag
;
1012 Initialize SMM S3 resume state structure used during S3 Resume.
1014 @param[in] Cr3 The base address of the page tables to use in SMM.
1018 InitSmmS3ResumeState (
1032 Restore SMM Configuration in S3 boot path.
1036 RestoreSmmConfigurationInS3 (
1041 Get ACPI S3 enable flag.
1045 GetAcpiS3EnableFlag (
1050 Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.
1052 @param[in] ApHltLoopCode The address of the safe hlt-loop function.
1053 @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.
1054 @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.
1058 TransferApToSafeState (
1059 IN UINTN ApHltLoopCode
,
1060 IN UINTN TopOfStack
,
1061 IN UINTN NumberToFinishAddress
1065 This function set given attributes of the memory region specified by
1066 BaseAddress and Length.
1068 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1069 @param BaseAddress The physical address that is the start address of
1071 @param Length The size in bytes of the memory region.
1072 @param Attributes The bit mask of attributes to set for the memory
1075 @retval EFI_SUCCESS The attributes were set for the memory region.
1076 @retval EFI_INVALID_PARAMETER Length is zero.
1077 Attributes specified an illegal combination of
1078 attributes that cannot be set together.
1079 @retval EFI_UNSUPPORTED The processor does not support one or more
1080 bytes of the memory resource range specified
1081 by BaseAddress and Length.
1082 The bit mask of attributes is not support for
1083 the memory resource range specified by
1084 BaseAddress and Length.
1089 EdkiiSmmSetMemoryAttributes (
1090 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1091 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1093 IN UINT64 Attributes
1097 This function clears given attributes of the memory region specified by
1098 BaseAddress and Length.
1100 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1101 @param BaseAddress The physical address that is the start address of
1103 @param Length The size in bytes of the memory region.
1104 @param Attributes The bit mask of attributes to set for the memory
1107 @retval EFI_SUCCESS The attributes were set for the memory region.
1108 @retval EFI_INVALID_PARAMETER Length is zero.
1109 Attributes specified an illegal combination of
1110 attributes that cannot be set together.
1111 @retval EFI_UNSUPPORTED The processor does not support one or more
1112 bytes of the memory resource range specified
1113 by BaseAddress and Length.
1114 The bit mask of attributes is not support for
1115 the memory resource range specified by
1116 BaseAddress and Length.
1121 EdkiiSmmClearMemoryAttributes (
1122 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1123 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1125 IN UINT64 Attributes
1129 This function retrieve the attributes of the memory region specified by
1130 BaseAddress and Length. If different attributes are got from different part
1131 of the memory region, EFI_NO_MAPPING will be returned.
1133 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1134 @param BaseAddress The physical address that is the start address of
1136 @param Length The size in bytes of the memory region.
1137 @param Attributes Pointer to attributes returned.
1139 @retval EFI_SUCCESS The attributes got for the memory region.
1140 @retval EFI_INVALID_PARAMETER Length is zero.
1142 @retval EFI_NO_MAPPING Attributes are not consistent cross the memory
1144 @retval EFI_UNSUPPORTED The processor does not support one or more
1145 bytes of the memory resource range specified
1146 by BaseAddress and Length.
1147 The bit mask of attributes is not support for
1148 the memory resource range specified by
1149 BaseAddress and Length.
1154 EdkiiSmmGetMemoryAttributes (
1155 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1156 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1158 IN UINT64
*Attributes
1162 This function fixes up the address of the global variable or function
1163 referred in SmmInit assembly files to be the absoute address.
1167 PiSmmCpuSmmInitFixupAddress (
1171 This function fixes up the address of the global variable or function
1172 referred in SmiEntry assembly files to be the absoute address.
1176 PiSmmCpuSmiEntryFixupAddress (