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/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/UefiLib.h>
49 #include <Library/HobLib.h>
50 #include <Library/LocalApicLib.h>
51 #include <Library/UefiCpuLib.h>
52 #include <Library/CpuExceptionHandlerLib.h>
53 #include <Library/ReportStatusCodeLib.h>
54 #include <Library/SmmCpuFeaturesLib.h>
55 #include <Library/PeCoffGetEntryPointLib.h>
57 #include <AcpiCpuData.h>
58 #include <CpuHotPlugData.h>
60 #include <Register/Cpuid.h>
61 #include <Register/Msr.h>
63 #include "CpuService.h"
64 #include "SmmProfile.h"
67 // MSRs required for configuration of SMM Code Access Check
69 #define EFI_MSR_SMM_MCA_CAP 0x17D
70 #define SMM_CODE_ACCESS_CHK_BIT BIT58
72 #define SMM_FEATURE_CONTROL_LOCK_BIT BIT0
73 #define SMM_CODE_CHK_EN_BIT BIT2
78 #define IA32_PG_P BIT0
79 #define IA32_PG_RW BIT1
80 #define IA32_PG_U BIT2
81 #define IA32_PG_WT BIT3
82 #define IA32_PG_CD BIT4
83 #define IA32_PG_A BIT5
84 #define IA32_PG_D BIT6
85 #define IA32_PG_PS BIT7
86 #define IA32_PG_PAT_2M BIT12
87 #define IA32_PG_PAT_4K IA32_PG_PS
88 #define IA32_PG_PMNT BIT62
89 #define IA32_PG_NX BIT63
91 #define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)
93 // Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE
94 // X64 PAE PDPTE does not have such restriction
96 #define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)
98 #define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)
100 #define PAGING_4K_MASK 0xFFF
101 #define PAGING_2M_MASK 0x1FFFFF
102 #define PAGING_1G_MASK 0x3FFFFFFF
104 #define PAGING_PAE_INDEX_MASK 0x1FF
106 #define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
107 #define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
108 #define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
110 #define SMRR_MAX_ADDRESS BASE_4GB
120 PAGE_ATTRIBUTE Attribute
;
123 } PAGE_ATTRIBUTE_TABLE
;
126 // Size of Task-State Segment defined in IA32 Manual
129 #define TSS_X64_IST1_OFFSET 36
130 #define TSS_IA32_CR3_OFFSET 28
131 #define TSS_IA32_ESP_OFFSET 56
138 #define PROTECT_MODE_CODE_SEGMENT 0x08
139 #define LONG_MODE_CODE_SEGMENT 0x38
142 // The size 0x20 must be bigger than
143 // the size of template code of SmmInit. Currently,
144 // the size of SmmInit requires the 0x16 Bytes buffer
147 #define BACK_BUF_SIZE 0x20
149 #define EXCEPTION_VECTOR_NUMBER 0x20
151 #define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL
153 typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS
;
154 #define ARRIVAL_EXCEPTION_BLOCKED 0x1
155 #define ARRIVAL_EXCEPTION_DELAYED 0x2
156 #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4
159 // Private structure for the SMM CPU module that is stored in DXE Runtime memory
160 // Contains the SMM Configuration Protocols that is produced.
161 // Contains a mix of DXE and SMM contents. All the fields must be used properly.
163 #define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')
168 EFI_HANDLE SmmCpuHandle
;
170 EFI_PROCESSOR_INFORMATION
*ProcessorInfo
;
171 SMM_CPU_OPERATION
*Operation
;
172 UINTN
*CpuSaveStateSize
;
175 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion
[1];
176 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext
;
177 EFI_SMM_ENTRY_POINT SmmCoreEntry
;
179 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration
;
180 } SMM_CPU_PRIVATE_DATA
;
182 extern SMM_CPU_PRIVATE_DATA
*gSmmCpuPrivate
;
183 extern CPU_HOT_PLUG_DATA mCpuHotPlugData
;
184 extern UINTN mMaxNumberOfCpus
;
185 extern UINTN mNumberOfCpus
;
186 extern EFI_SMM_CPU_PROTOCOL mSmmCpu
;
189 /// The mode of the CPU at the time an SMI occurs
191 extern UINT8 mSmmSaveStateRegisterLma
;
194 // SMM CPU Protocol function prototypes.
198 Read information from the CPU save state.
200 @param This EFI_SMM_CPU_PROTOCOL instance
201 @param Width The number of bytes to read from the CPU save state.
202 @param Register Specifies the CPU register to read form the save state.
203 @param CpuIndex Specifies the zero-based index of the CPU save state
204 @param Buffer Upon return, this holds the CPU register value read from the save state.
206 @retval EFI_SUCCESS The register was read from Save State
207 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
208 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
214 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
216 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
222 Write data to the CPU save state.
224 @param This EFI_SMM_CPU_PROTOCOL instance
225 @param Width The number of bytes to read from the CPU save state.
226 @param Register Specifies the CPU register to write to the save state.
227 @param CpuIndex Specifies the zero-based index of the CPU save state
228 @param Buffer Upon entry, this holds the new CPU register value.
230 @retval EFI_SUCCESS The register was written from Save State
231 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor
232 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct
238 IN CONST EFI_SMM_CPU_PROTOCOL
*This
,
240 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
242 IN CONST VOID
*Buffer
246 Read a CPU Save State register on the target processor.
248 This function abstracts the differences that whether the CPU Save State register is in the
249 IA32 CPU Save State Map or X64 CPU Save State Map.
251 This function supports reading a CPU Save State register in SMBase relocation handler.
253 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
254 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
255 @param[in] Width The number of bytes to read from the CPU save state.
256 @param[out] Buffer Upon return, this holds the CPU register value read from the save state.
258 @retval EFI_SUCCESS The register was read from Save State.
259 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
260 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
265 ReadSaveStateRegister (
267 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
273 Write value to a CPU Save State register on the target processor.
275 This function abstracts the differences that whether the CPU Save State register is in the
276 IA32 CPU Save State Map or X64 CPU Save State Map.
278 This function supports writing a CPU Save State register in SMBase relocation handler.
280 @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
281 @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
282 @param[in] Width The number of bytes to read from the CPU save state.
283 @param[in] Buffer Upon entry, this holds the new CPU register value.
285 @retval EFI_SUCCESS The register was written to Save State.
286 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
287 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct.
292 WriteSaveStateRegister (
294 IN EFI_SMM_SAVE_STATE_REGISTER Register
,
296 IN CONST VOID
*Buffer
299 extern CONST UINT8 gcSmmInitTemplate
[];
300 extern CONST UINT16 gcSmmInitSize
;
301 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0
;
302 extern UINT32 mSmmCr0
;
303 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3
;
304 extern UINT32 mSmmCr4
;
305 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4
;
306 X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack
;
309 Semaphore operation for all processor relocate SMMBase.
313 SmmRelocationSemaphoreComplete (
318 /// The type of SMM CPU Information
322 volatile EFI_AP_PROCEDURE Procedure
;
323 volatile VOID
*Parameter
;
324 volatile UINT32
*Run
;
325 volatile BOOLEAN
*Present
;
326 } SMM_CPU_DATA_BLOCK
;
329 SmmCpuSyncModeTradition
,
330 SmmCpuSyncModeRelaxedAp
,
336 // Pointer to an array. The array should be located immediately after this structure
337 // so that UC cache-ability can be set together.
339 SMM_CPU_DATA_BLOCK
*CpuData
;
340 volatile UINT32
*Counter
;
341 volatile UINT32 BspIndex
;
342 volatile BOOLEAN
*InsideSmm
;
343 volatile BOOLEAN
*AllCpusInSync
;
344 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode
;
345 volatile BOOLEAN SwitchBsp
;
346 volatile BOOLEAN
*CandidateBsp
;
347 } SMM_DISPATCHER_MP_SYNC_DATA
;
349 #define MSR_SPIN_LOCK_INIT_NUM 15
356 #define SMM_PSD_OFFSET 0xfb00
359 /// All global semaphores' pointer
362 volatile UINT32
*Counter
;
363 volatile BOOLEAN
*InsideSmm
;
364 volatile BOOLEAN
*AllCpusInSync
;
366 SPIN_LOCK
*CodeAccessCheckLock
;
367 SPIN_LOCK
*MemoryMappedLock
;
368 } SMM_CPU_SEMAPHORE_GLOBAL
;
371 /// All semaphores for each processor
375 volatile UINT32
*Run
;
376 volatile BOOLEAN
*Present
;
377 } SMM_CPU_SEMAPHORE_CPU
;
380 /// All MSRs semaphores' pointer and counter
384 UINTN AvailableCounter
;
385 } SMM_CPU_SEMAPHORE_MSR
;
388 /// All semaphores' information
391 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal
;
392 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu
;
393 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr
;
394 } SMM_CPU_SEMAPHORES
;
396 extern IA32_DESCRIPTOR gcSmiGdtr
;
397 extern EFI_PHYSICAL_ADDRESS mGdtBuffer
;
398 extern UINTN mGdtBufferSize
;
399 extern IA32_DESCRIPTOR gcSmiIdtr
;
400 extern VOID
*gcSmiIdtrPtr
;
401 extern UINT64 gPhyMask
;
402 extern SMM_DISPATCHER_MP_SYNC_DATA
*mSmmMpSyncData
;
403 extern UINTN mSmmStackArrayBase
;
404 extern UINTN mSmmStackArrayEnd
;
405 extern UINTN mSmmStackSize
;
406 extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService
;
407 extern IA32_DESCRIPTOR gcSmiInitGdtr
;
408 extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores
;
409 extern UINTN mSemaphoreSize
;
410 extern SPIN_LOCK
*mPFLock
;
411 extern SPIN_LOCK
*mConfigSmmCodeAccessCheckLock
;
412 extern SPIN_LOCK
*mMemoryMappedLock
;
413 extern EFI_SMRAM_DESCRIPTOR
*mSmmCpuSmramRanges
;
414 extern UINTN mSmmCpuSmramRangeCount
;
415 extern UINT8 mPhysicalAddressBits
;
418 // Copy of the PcdPteMemoryEncryptionAddressOrMask
420 extern UINT64 mAddressEncMask
;
423 Create 4G PageTable in SMRAM.
425 @param[in] Is32BitPageTable Whether the page table is 32-bit PAE
426 @return PageTable Address
431 IN BOOLEAN Is32BitPageTable
436 Initialize global data for MP synchronization.
438 @param Stacks Base address of SMI stack buffer for all processors.
439 @param StackSize Stack size for each processor in SMM.
443 InitializeMpServiceData (
449 Initialize Timer for SMM AP Sync.
458 Start Timer for SMM AP Sync.
468 Check if the SMM AP Sync timer is timeout.
470 @param Timer The start timer from the begin.
480 Initialize IDT for SMM Stack Guard.
485 InitializeIDTSmmStackGuard (
490 Initialize Gdt for all processors.
492 @param[in] Cr3 CR3 value.
493 @param[out] GdtStepSize The step size for GDT table.
495 @return GdtBase for processor 0.
496 GdtBase for processor X is: GdtBase + (GdtStepSize * X)
501 OUT UINTN
*GdtStepSize
506 Register the SMM Foundation entry point.
508 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance
509 @param SmmEntryPoint SMM Foundation EntryPoint
511 @retval EFI_SUCCESS Successfully to register SMM foundation entry point
517 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL
*This
,
518 IN EFI_SMM_ENTRY_POINT SmmEntryPoint
522 Create PageTable for SMM use.
524 @return PageTable Address
533 Schedule a procedure to run on the specified CPU.
535 @param Procedure The address of the procedure to run
536 @param CpuIndex Target CPU number
537 @param ProcArguments The parameter to pass to the procedure
539 @retval EFI_INVALID_PARAMETER CpuNumber not valid
540 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
541 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
542 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
543 @retval EFI_SUCCESS - The procedure has been successfully scheduled
549 IN EFI_AP_PROCEDURE Procedure
,
551 IN OUT VOID
*ProcArguments OPTIONAL
555 Schedule a procedure to run on the specified CPU in a blocking fashion.
557 @param Procedure The address of the procedure to run
558 @param CpuIndex Target CPU Index
559 @param ProcArguments The parameter to pass to the procedure
561 @retval EFI_INVALID_PARAMETER CpuNumber not valid
562 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP
563 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM
564 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy
565 @retval EFI_SUCCESS The procedure has been successfully scheduled
570 SmmBlockingStartupThisAp (
571 IN EFI_AP_PROCEDURE Procedure
,
573 IN OUT VOID
*ProcArguments OPTIONAL
577 This function sets the attributes for the memory region specified by BaseAddress and
578 Length from their current attributes to the attributes specified by Attributes.
580 @param[in] BaseAddress The physical address that is the start address of a memory region.
581 @param[in] Length The size in bytes of the memory region.
582 @param[in] Attributes The bit mask of attributes to set for the memory region.
584 @retval EFI_SUCCESS The attributes were set for the memory region.
585 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
586 BaseAddress and Length cannot be modified.
587 @retval EFI_INVALID_PARAMETER Length is zero.
588 Attributes specified an illegal combination of attributes that
589 cannot be set together.
590 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
591 the memory resource range.
592 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
593 resource range specified by BaseAddress and Length.
594 The bit mask of attributes is not support for the memory resource
595 range specified by BaseAddress and Length.
600 SmmSetMemoryAttributes (
601 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
607 This function clears the attributes for the memory region specified by BaseAddress and
608 Length from their current attributes to the attributes specified by Attributes.
610 @param[in] BaseAddress The physical address that is the start address of a memory region.
611 @param[in] Length The size in bytes of the memory region.
612 @param[in] Attributes The bit mask of attributes to clear for the memory region.
614 @retval EFI_SUCCESS The attributes were cleared for the memory region.
615 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
616 BaseAddress and Length cannot be modified.
617 @retval EFI_INVALID_PARAMETER Length is zero.
618 Attributes specified an illegal combination of attributes that
619 cannot be set together.
620 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
621 the memory resource range.
622 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
623 resource range specified by BaseAddress and Length.
624 The bit mask of attributes is not support for the memory resource
625 range specified by BaseAddress and Length.
630 SmmClearMemoryAttributes (
631 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
637 Initialize MP synchronization data.
642 InitializeMpSyncData (
648 Find out SMRAM information including SMRR base and SMRR size.
650 @param SmrrBase SMRR base
651 @param SmrrSize SMRR size
656 OUT UINT32
*SmrrBase
,
661 Relocate SmmBases for each processor.
663 Execute on first boot and all S3 resumes
673 Page Fault handler for SMM use.
675 @param InterruptType Defines the type of interrupt or exception that
676 occurred on the processor.This parameter is processor architecture specific.
677 @param SystemContext A pointer to the processor context when
678 the interrupt occurred on the processor.
683 IN EFI_EXCEPTION_TYPE InterruptType
,
684 IN EFI_SYSTEM_CONTEXT SystemContext
688 Perform the remaining tasks.
692 PerformRemainingTasks (
697 Perform the pre tasks.
706 Initialize MSR spin lock by MSR index.
708 @param MsrIndex MSR index value.
712 InitMsrSpinLockByIndex (
717 Hook return address of SMM Save State so that semaphore code
718 can be executed immediately after AP exits SMM to indicate to
719 the BSP that an AP has exited SMM after SMBASE relocation.
721 @param[in] CpuIndex The processor index.
722 @param[in] RebasedFlag A pointer to a flag that is set to TRUE
723 immediately after AP exits SMM.
729 IN
volatile BOOLEAN
*RebasedFlag
733 Configure SMM Code Access Check feature for all processors.
734 SMM Feature Control MSR will be locked after configuration.
737 ConfigSmmCodeAccessCheck (
742 Hook the code executed immediately after an RSM instruction on the currently
743 executing CPU. The mode of code executed immediately after RSM must be
744 detected, and the appropriate hook must be selected. Always clear the auto
745 HALT restart flag if it is set.
747 @param[in] CpuIndex The processor index for the currently
749 @param[in] CpuState Pointer to SMRAM Save State Map for the
750 currently executing CPU.
751 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
752 32-bit mode from 64-bit SMM.
753 @param[in] NewInstructionPointer Instruction pointer to use if resuming to
756 @retval The value of the original instruction pointer before it was hooked.
763 SMRAM_SAVE_STATE_MAP
*CpuState
,
764 UINT64 NewInstructionPointer32
,
765 UINT64 NewInstructionPointer
769 Get the size of the SMI Handler in bytes.
771 @retval The size, in bytes, of the SMI Handler.
781 Install the SMI handler for the CPU specified by CpuIndex. This function
782 is called by the CPU that was elected as monarch during System Management
785 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.
786 The value must be between 0 and the NumberOfCpus field
787 in the System Management System Table (SMST).
788 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
789 @param[in] SmiStack The stack to use when an SMI is processed by the
790 the CPU specified by CpuIndex.
791 @param[in] StackSize The size, in bytes, if the stack used when an SMI is
792 processed by the CPU specified by CpuIndex.
793 @param[in] GdtBase The base address of the GDT to use when an SMI is
794 processed by the CPU specified by CpuIndex.
795 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is
796 processed by the CPU specified by CpuIndex.
797 @param[in] IdtBase The base address of the IDT to use when an SMI is
798 processed by the CPU specified by CpuIndex.
799 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is
800 processed by the CPU specified by CpuIndex.
801 @param[in] Cr3 The base address of the page tables to use when an SMI
802 is processed by the CPU specified by CpuIndex.
819 Search module name by input IP address and output it.
821 @param CallerIpAddress Caller instruction pointer.
826 IN UINTN CallerIpAddress
830 This function sets memory attribute according to MemoryAttributesTable.
833 SetMemMapAttributes (
838 This function sets UEFI memory attribute according to UEFI memory map.
841 SetUefiMemMapAttributes (
846 Return if the Address is forbidden as SMM communication buffer.
848 @param[in] Address the address to be checked
850 @return TRUE The address is forbidden as SMM communication buffer.
851 @return FALSE The address is allowed as SMM communication buffer.
854 IsSmmCommBufferForbiddenAddress (
859 This function caches the UEFI memory map information.
867 This function sets memory attribute for page table.
870 SetPageTableAttributes (
875 Return page table base.
877 @return page table base.
885 This function sets the attributes for the memory region specified by BaseAddress and
886 Length from their current attributes to the attributes specified by Attributes.
888 @param[in] BaseAddress The physical address that is the start address of a memory region.
889 @param[in] Length The size in bytes of the memory region.
890 @param[in] Attributes The bit mask of attributes to set for the memory region.
891 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
893 @retval EFI_SUCCESS The attributes were set for the memory region.
894 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
895 BaseAddress and Length cannot be modified.
896 @retval EFI_INVALID_PARAMETER Length is zero.
897 Attributes specified an illegal combination of attributes that
898 cannot be set together.
899 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
900 the memory resource range.
901 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
902 resource range specified by BaseAddress and Length.
903 The bit mask of attributes is not support for the memory resource
904 range specified by BaseAddress and Length.
909 SmmSetMemoryAttributesEx (
910 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
912 IN UINT64 Attributes
,
913 OUT BOOLEAN
*IsSplitted OPTIONAL
917 This function clears the attributes for the memory region specified by BaseAddress and
918 Length from their current attributes to the attributes specified by Attributes.
920 @param[in] BaseAddress The physical address that is the start address of a memory region.
921 @param[in] Length The size in bytes of the memory region.
922 @param[in] Attributes The bit mask of attributes to clear for the memory region.
923 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.
925 @retval EFI_SUCCESS The attributes were cleared for the memory region.
926 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by
927 BaseAddress and Length cannot be modified.
928 @retval EFI_INVALID_PARAMETER Length is zero.
929 Attributes specified an illegal combination of attributes that
930 cannot be set together.
931 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
932 the memory resource range.
933 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory
934 resource range specified by BaseAddress and Length.
935 The bit mask of attributes is not support for the memory resource
936 range specified by BaseAddress and Length.
941 SmmClearMemoryAttributesEx (
942 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
944 IN UINT64 Attributes
,
945 OUT BOOLEAN
*IsSplitted OPTIONAL
949 This API provides a way to allocate memory for page table.
951 This API can be called more once to allocate memory for page tables.
953 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
954 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
955 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
958 @param Pages The number of 4 KB pages to allocate.
960 @return A pointer to the allocated buffer or NULL if allocation fails.
964 AllocatePageTableMemory (
969 Allocate pages for code.
971 @param[in] Pages Number of pages to be allocated.
973 @return Allocated memory.
981 Allocate aligned pages for code.
983 @param[in] Pages Number of pages to be allocated.
984 @param[in] Alignment The requested alignment of the allocation.
985 Must be a power of two.
986 If Alignment is zero, then byte alignment is used.
988 @return Allocated memory.
991 AllocateAlignedCodePages (
998 // S3 related global variable and function prototype.
1001 extern BOOLEAN mSmmS3Flag
;
1004 Initialize SMM S3 resume state structure used during S3 Resume.
1006 @param[in] Cr3 The base address of the page tables to use in SMM.
1010 InitSmmS3ResumeState (
1024 Restore SMM Configuration in S3 boot path.
1028 RestoreSmmConfigurationInS3 (
1033 Get ACPI S3 enable flag.
1037 GetAcpiS3EnableFlag (
1042 Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.
1044 @param[in] ApHltLoopCode The address of the safe hlt-loop function.
1045 @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.
1046 @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.
1050 TransferApToSafeState (
1051 IN UINTN ApHltLoopCode
,
1052 IN UINTN TopOfStack
,
1053 IN UINTN NumberToFinishAddress
1057 This function set given attributes of the memory region specified by
1058 BaseAddress and Length.
1060 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1061 @param BaseAddress The physical address that is the start address of
1063 @param Length The size in bytes of the memory region.
1064 @param Attributes The bit mask of attributes to set for the memory
1067 @retval EFI_SUCCESS The attributes were set for the memory region.
1068 @retval EFI_INVALID_PARAMETER Length is zero.
1069 Attributes specified an illegal combination of
1070 attributes that cannot be set together.
1071 @retval EFI_UNSUPPORTED The processor does not support one or more
1072 bytes of the memory resource range specified
1073 by BaseAddress and Length.
1074 The bit mask of attributes is not supported for
1075 the memory resource range specified by
1076 BaseAddress and Length.
1081 EdkiiSmmSetMemoryAttributes (
1082 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1083 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1085 IN UINT64 Attributes
1089 This function clears given attributes of the memory region specified by
1090 BaseAddress and Length.
1092 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1093 @param BaseAddress The physical address that is the start address of
1095 @param Length The size in bytes of the memory region.
1096 @param Attributes The bit mask of attributes to clear for the memory
1099 @retval EFI_SUCCESS The attributes were cleared for the memory region.
1100 @retval EFI_INVALID_PARAMETER Length is zero.
1101 Attributes specified an illegal combination of
1102 attributes that cannot be cleared together.
1103 @retval EFI_UNSUPPORTED The processor does not support one or more
1104 bytes of the memory resource range specified
1105 by BaseAddress and Length.
1106 The bit mask of attributes is not supported for
1107 the memory resource range specified by
1108 BaseAddress and Length.
1113 EdkiiSmmClearMemoryAttributes (
1114 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1115 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1117 IN UINT64 Attributes
1121 This function retrieves the attributes of the memory region specified by
1122 BaseAddress and Length. If different attributes are got from different part
1123 of the memory region, EFI_NO_MAPPING will be returned.
1125 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.
1126 @param BaseAddress The physical address that is the start address of
1128 @param Length The size in bytes of the memory region.
1129 @param Attributes Pointer to attributes returned.
1131 @retval EFI_SUCCESS The attributes got for the memory region.
1132 @retval EFI_INVALID_PARAMETER Length is zero.
1134 @retval EFI_NO_MAPPING Attributes are not consistent cross the memory
1136 @retval EFI_UNSUPPORTED The processor does not support one or more
1137 bytes of the memory resource range specified
1138 by BaseAddress and Length.
1143 EdkiiSmmGetMemoryAttributes (
1144 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL
*This
,
1145 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
1147 IN UINT64
*Attributes
1151 This function fixes up the address of the global variable or function
1152 referred in SmmInit assembly files to be the absoute address.
1156 PiSmmCpuSmmInitFixupAddress (
1160 This function fixes up the address of the global variable or function
1161 referred in SmiEntry assembly files to be the absoute address.
1165 PiSmmCpuSmiEntryFixupAddress (