TianoCore EDK2 master
|
#include "PiSmmCpuCommon.h"
Go to the source code of this file.
Functions | |
VOID | SmmWriteUnprotectReadOnlyPage (OUT BOOLEAN *WriteProtect) |
VOID | SmmWriteProtectReadOnlyPage (IN BOOLEAN WriteProtect) |
BOOLEAN | InitializePageTablePool (IN UINTN PoolPages) |
VOID * | AllocatePageTableMemory (IN UINTN Pages) |
VOID * | GetPageTableEntry (IN UINTN PageTableBase, IN BOOLEAN Enable5LevelPaging, IN PHYSICAL_ADDRESS Address, OUT PAGE_ATTRIBUTE *PageAttribute) |
UINT64 | GetAttributesFromPageEntry (IN UINT64 *PageEntry) |
RETURN_STATUS | ConvertMemoryPageAttributes (IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN BOOLEAN IsSet, OUT BOOLEAN *IsModified OPTIONAL) |
VOID EFIAPI | FlushTlbOnCurrentProcessor (IN OUT VOID *Buffer) |
VOID | FlushTlbForAll (VOID) |
EFI_STATUS | SmmSetMemoryAttributesEx (IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
EFI_STATUS | SmmClearMemoryAttributesEx (IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
EFI_STATUS | SmmSetMemoryAttributes (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
EFI_STATUS | SmmClearMemoryAttributes (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
EFI_STATUS | SetShadowStack (IN UINTN Cr3, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length) |
EFI_STATUS EFIAPI | SmmGetSystemConfigurationTable (IN EFI_GUID *TableGuid, OUT VOID **Table) |
VOID | PatchSmmSaveStateMap (VOID) |
VOID | PatchGdtIdtMap (VOID) |
VOID | SetMemMapWithNonPresentRange (UINT64 Base, UINT64 Limit, UINT64 Attribute, IA32_MAP_ENTRY *Map, UINTN Count) |
VOID | SetMemMapAttributes (EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable) |
EFI_STATUS EFIAPI | EdkiiSmmSetMemoryAttributes (IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
EFI_STATUS EFIAPI | EdkiiSmmClearMemoryAttributes (IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes) |
VOID | GenPageTable (IN OUT UINTN *PageTable, IN PAGING_MODE PagingMode, IN UINT64 LinearAddress, IN UINT64 Length, IN IA32_MAP_ATTRIBUTE MapAttribute, IN IA32_MAP_ATTRIBUTE MapMask) |
UINTN | GenSmmPageTable (IN PAGING_MODE PagingMode, IN UINT8 PhysicalAddressBits) |
EFI_STATUS EFIAPI | EdkiiSmmGetMemoryAttributes (IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, OUT UINT64 *Attributes) |
VOID | EnablePageTableProtection (VOID) |
BOOLEAN | IfReadOnlyPageTableNeeded (VOID) |
VOID | SetPageTableAttributes (VOID) |
Variables | |
BOOLEAN | mIsShadowStack = FALSE |
BOOLEAN | m5LevelPagingNeeded = FALSE |
PAGING_MODE | mPagingMode = PagingModeMax |
PAGE_TABLE_POOL * | mPageTablePool = NULL |
BOOLEAN | mIsReadOnlyPageTable = FALSE |
Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SmmCpuMemoryManagement.c.
This API provides a way to allocate memory for page table.
This API can be called more once to allocate memory for page tables.
Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
Pages | The number of 4 KB pages to allocate. |
Definition at line 152 of file SmmCpuMemoryManagement.c.
RETURN_STATUS ConvertMemoryPageAttributes | ( | IN UINTN | PageTableBase, |
IN PAGING_MODE | PagingMode, | ||
IN PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN UINT64 | Attributes, | ||
IN BOOLEAN | IsSet, | ||
OUT BOOLEAN *IsModified | OPTIONAL | ||
) |
This function modifies the page attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.
Caller should make sure BaseAddress and Length is at page boundary.
[in] | PageTableBase | The page table base. |
[in] | PagingMode | The paging mode. |
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
[in] | Attributes | The bit mask of attributes to modify for the memory region. |
[in] | IsSet | TRUE means to set attributes. FALSE means to clear attributes. |
[out] | IsModified | TRUE means page table modified. FALSE means page table not modified. |
RETURN_SUCCESS | The attributes were modified for the memory region. |
RETURN_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
RETURN_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be set together. |
RETURN_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
RETURN_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. |
Definition at line 331 of file SmmCpuMemoryManagement.c.
EFI_STATUS EFIAPI EdkiiSmmClearMemoryAttributes | ( | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL * | This, |
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function clears given attributes of the memory region specified by BaseAddress and Length.
This | The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. |
BaseAddress | The physical address that is the start address of a memory region. |
Length | The size in bytes of the memory region. |
Attributes | The bit mask of attributes to clear for the memory region. |
EFI_SUCCESS | The attributes were cleared for the memory region. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be cleared together. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not supported for the memory resource range specified by BaseAddress and Length. |
Definition at line 1160 of file SmmCpuMemoryManagement.c.
EFI_STATUS EFIAPI EdkiiSmmGetMemoryAttributes | ( | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL * | This, |
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
OUT UINT64 * | Attributes | ||
) |
This function retrieves the attributes of the memory region specified by BaseAddress and Length. If different attributes are got from different part of the memory region, EFI_NO_MAPPING will be returned.
This | The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. |
BaseAddress | The physical address that is the start address of a memory region. |
Length | The size in bytes of the memory region. |
Attributes | Pointer to attributes returned. |
EFI_SUCCESS | The attributes got for the memory region. |
EFI_INVALID_PARAMETER | Length is zero. Attributes is NULL. |
EFI_NO_MAPPING | Attributes are not consistent cross the memory region. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. |
Definition at line 1368 of file SmmCpuMemoryManagement.c.
EFI_STATUS EFIAPI EdkiiSmmSetMemoryAttributes | ( | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL * | This, |
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function set given attributes of the memory region specified by BaseAddress and Length.
This | The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance. |
BaseAddress | The physical address that is the start address of a memory region. |
Length | The size in bytes of the memory region. |
Attributes | The bit mask of attributes to set for the memory region. |
EFI_SUCCESS | The attributes were set for the memory region. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be set together. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not supported for the memory resource range specified by BaseAddress and Length. |
Definition at line 1125 of file SmmCpuMemoryManagement.c.
VOID EnablePageTableProtection | ( | VOID | ) |
Prevent the memory pages used for SMM page table from been overwritten.
Definition at line 1443 of file SmmCpuMemoryManagement.c.
VOID FlushTlbForAll | ( | VOID | ) |
FlushTlb for all processors.
Definition at line 527 of file SmmCpuMemoryManagement.c.
FlushTlb on current processor.
[in,out] | Buffer | Pointer to private data buffer. |
Definition at line 516 of file SmmCpuMemoryManagement.c.
VOID GenPageTable | ( | IN OUT UINTN * | PageTable, |
IN PAGING_MODE | PagingMode, | ||
IN UINT64 | LinearAddress, | ||
IN UINT64 | Length, | ||
IN IA32_MAP_ATTRIBUTE | MapAttribute, | ||
IN IA32_MAP_ATTRIBUTE | MapMask | ||
) |
Create page table based on input PagingMode, LinearAddress and Length.
[in,out] | PageTable | The pointer to the page table. |
[in] | PagingMode | The paging mode. |
[in] | LinearAddress | The start of the linear address range. |
[in] | Length | The length of the linear address range. |
[in] | MapAttribute | The MapAttribute of the linear address range |
[in] | MapMask | The MapMask used for attribute. The corresponding field in Attribute is ignored if that in MapMask is 0. |
Definition at line 1182 of file SmmCpuMemoryManagement.c.
Create page table based on input PagingMode and PhysicalAddressBits in smm.
[in] | PagingMode | The paging mode. |
[in] | PhysicalAddressBits | The bits of physical address to map. |
PageTable | Address |
Definition at line 1238 of file SmmCpuMemoryManagement.c.
UINT64 GetAttributesFromPageEntry | ( | IN UINT64 * | PageEntry | ) |
Return memory attributes of page entry.
[in] | PageEntry | The page entry. |
Definition at line 281 of file SmmCpuMemoryManagement.c.
VOID * GetPageTableEntry | ( | IN UINTN | PageTableBase, |
IN BOOLEAN | Enable5LevelPaging, | ||
IN PHYSICAL_ADDRESS | Address, | ||
OUT PAGE_ATTRIBUTE * | PageAttribute | ||
) |
Return page table entry to match the address.
[in] | PageTableBase | The page table base. |
[in] | Enable5LevelPaging | If PML5 paging is enabled. |
[in] | Address | The address to be checked. |
[out] | PageAttributes | The page attribute of the page entry. |
Definition at line 192 of file SmmCpuMemoryManagement.c.
BOOLEAN IfReadOnlyPageTableNeeded | ( | VOID | ) |
Return whether memory used by SMM page table need to be set as Read Only.
TRUE | Need to set SMM page table as Read Only. |
FALSE | Do not set SMM page table as Read Only. |
Definition at line 1483 of file SmmCpuMemoryManagement.c.
Initialize a buffer pool for page table use only.
To reduce the potential split operation on page table, the pages reserved for page table should be allocated in the times of PAGE_TABLE_POOL_UNIT_PAGES and at the boundary of PAGE_TABLE_POOL_ALIGNMENT. So the page pool is always initialized with number of pages greater than or equal to the given PoolPages.
Once the pages in the pool are used up, this method should be called again to reserve at least another PAGE_TABLE_POOL_UNIT_PAGES. But usually this won't happen in practice.
PoolPages | The least page number of the pool to be created. |
TRUE | The pool is initialized successfully. |
FALSE | The memory is out of resource. |
Definition at line 83 of file SmmCpuMemoryManagement.c.
VOID PatchGdtIdtMap | ( | VOID | ) |
This function sets GDT/IDT buffer to be RO and XP.
Definition at line 888 of file SmmCpuMemoryManagement.c.
VOID PatchSmmSaveStateMap | ( | VOID | ) |
This function sets SMM save state buffer to be RW and XP.
Definition at line 772 of file SmmCpuMemoryManagement.c.
VOID SetMemMapAttributes | ( | EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE * | MemoryAttributesTable | ) |
This function sets memory attribute according to MemoryAttributesTable.
MemoryAttributesTable | A pointer to the buffer of SmmMemoryAttributesTable. |
Definition at line 1001 of file SmmCpuMemoryManagement.c.
VOID SetMemMapWithNonPresentRange | ( | UINT64 | Base, |
UINT64 | Limit, | ||
UINT64 | Attribute, | ||
IA32_MAP_ENTRY * | Map, | ||
UINTN | Count | ||
) |
This function set [Base, Limit] to the input MemoryAttribute.
Base | Start address of range. |
Limit | Limit address of range. |
Attribute | The bit mask of attributes to modify for the memory region. |
Map | Pointer to the array of Cr3 IA32_MAP_ENTRY. |
Count | Count of IA32_MAP_ENTRY in Map. |
Definition at line 940 of file SmmCpuMemoryManagement.c.
VOID SetPageTableAttributes | ( | VOID | ) |
This function sets memory attribute for page table.
Definition at line 1507 of file SmmCpuMemoryManagement.c.
EFI_STATUS SetShadowStack | ( | IN UINTN | Cr3, |
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length | ||
) |
Set ShadowStack memory.
[in] | Cr3 | The page table base address. |
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
EFI_SUCCESS | The shadow stack memory is set. |
Definition at line 719 of file SmmCpuMemoryManagement.c.
EFI_STATUS SmmClearMemoryAttributes | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function clears the attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
[in] | Attributes | The bit mask of attributes to clear for the memory region. |
EFI_SUCCESS | The attributes were cleared for the memory region. |
EFI_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be cleared together. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not supported for the memory resource range specified by BaseAddress and Length. |
Definition at line 697 of file SmmCpuMemoryManagement.c.
EFI_STATUS SmmClearMemoryAttributesEx | ( | IN UINTN | PageTableBase, |
IN PAGING_MODE | PagingMode, | ||
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function clears the attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.
[in] | PageTableBase | The page table base. |
[in] | PagingMode | The paging mode. |
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
[in] | Attributes | The bit mask of attributes to clear for the memory region. |
EFI_SUCCESS | The attributes were cleared for the memory region. |
EFI_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be cleared together. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not supported for the memory resource range specified by BaseAddress and Length. |
Definition at line 615 of file SmmCpuMemoryManagement.c.
EFI_STATUS EFIAPI SmmGetSystemConfigurationTable | ( | IN EFI_GUID * | TableGuid, |
OUT VOID ** | Table | ||
) |
Retrieves a pointer to the system configuration table from the SMM System Table based on a specified GUID.
[in] | TableGuid | The pointer to table's GUID type. |
[out] | Table | The pointer to the table associated with TableGuid in the EFI System Table. |
EFI_SUCCESS | A configuration table matching TableGuid was found. |
EFI_NOT_FOUND | A configuration table matching TableGuid could not be found. |
Definition at line 747 of file SmmCpuMemoryManagement.c.
EFI_STATUS SmmSetMemoryAttributes | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function sets the attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
[in] | Attributes | The bit mask of attributes to set for the memory region. |
EFI_SUCCESS | The attributes were set for the memory region. |
EFI_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be set together. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not supported for the memory resource range specified by BaseAddress and Length. |
Definition at line 662 of file SmmCpuMemoryManagement.c.
EFI_STATUS SmmSetMemoryAttributesEx | ( | IN UINTN | PageTableBase, |
IN PAGING_MODE | PagingMode, | ||
IN EFI_PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN UINT64 | Attributes | ||
) |
This function sets the attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.
[in] | PageTableBase | The page table base. |
[in] | PagingMode | The paging mode. |
[in] | BaseAddress | The physical address that is the start address of a memory region. |
[in] | Length | The size in bytes of the memory region. |
[in] | Attributes | The bit mask of attributes to set for the memory region. |
EFI_SUCCESS | The attributes were set for the memory region. |
EFI_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
EFI_INVALID_PARAMETER | Length is zero. Attributes specified an illegal combination of attributes that cannot be set together. |
EFI_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. |
EFI_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. |
Definition at line 566 of file SmmCpuMemoryManagement.c.
VOID SmmWriteProtectReadOnlyPage | ( | IN BOOLEAN | WriteProtect | ) |
Write protect read-only pages.
[in] | WriteProtect | If Cr0.Bits.WP should be enabled. |
Definition at line 52 of file SmmCpuMemoryManagement.c.
VOID SmmWriteUnprotectReadOnlyPage | ( | OUT BOOLEAN * | WriteProtect | ) |
Write unprotect read-only pages if Cr0.Bits.WP is 1.
[out] | WriteProtect | If Cr0.Bits.WP is enabled. |
Definition at line 31 of file SmmCpuMemoryManagement.c.
BOOLEAN m5LevelPagingNeeded = FALSE |
Definition at line 11 of file SmmCpuMemoryManagement.c.
BOOLEAN mIsReadOnlyPageTable = FALSE |
Definition at line 22 of file SmmCpuMemoryManagement.c.
BOOLEAN mIsShadowStack = FALSE |
Definition at line 10 of file SmmCpuMemoryManagement.c.
PAGE_TABLE_POOL* mPageTablePool = NULL |
Definition at line 17 of file SmmCpuMemoryManagement.c.
PAGING_MODE mPagingMode = PagingModeMax |
Definition at line 12 of file SmmCpuMemoryManagement.c.