TianoCore EDK2 master
|
#include <Uefi.h>
#include <Register/Intel/Cpuid.h>
#include <Register/Intel/Msr.h>
#include <Library/MtrrLib.h>
#include <Library/BaseLib.h>
#include <Library/CpuLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
Go to the source code of this file.
Data Structures | |
struct | MTRR_CONTEXT |
struct | MTRR_LIB_ADDRESS |
Macros | |
#define | OR_SEED 0x0101010101010101ull |
#define | CLEAR_SEED 0xFFFFFFFFFFFFFFFFull |
#define | MAX_WEIGHT MAX_UINT8 |
#define | SCRATCH_BUFFER_SIZE (4 * SIZE_4KB) |
#define | MTRR_LIB_ASSERT_ALIGNED(B, L) ASSERT ((B & ~(L - 1)) == B); |
#define | M(x, y) ((x) * VertexCount + (y)) |
#define | O(x, y) ((y) * VertexCount + (x)) |
Functions | |
VOID | MtrrDebugPrintAllMtrrsWorker (IN MTRR_SETTINGS *MtrrSetting) |
BOOLEAN | MtrrLibIsMtrrSupported (OUT BOOLEAN *FixedMtrrSupported OPTIONAL, OUT UINT32 *VariableMtrrCount OPTIONAL) |
UINT32 | GetVariableMtrrCountWorker (VOID) |
UINT32 EFIAPI | GetVariableMtrrCount (VOID) |
UINT32 | GetFirmwareVariableMtrrCountWorker (VOID) |
UINT32 EFIAPI | GetFirmwareVariableMtrrCount (VOID) |
MTRR_MEMORY_CACHE_TYPE | MtrrGetDefaultMemoryTypeWorker (IN CONST MTRR_SETTINGS *MtrrSetting) |
MTRR_MEMORY_CACHE_TYPE EFIAPI | MtrrGetDefaultMemoryType (VOID) |
VOID | MtrrLibPreMtrrChange (OUT MTRR_CONTEXT *MtrrContext) |
VOID | MtrrLibPostMtrrChangeEnableCache (IN MTRR_CONTEXT *MtrrContext) |
VOID | MtrrLibPostMtrrChange (IN MTRR_CONTEXT *MtrrContext) |
MTRR_FIXED_SETTINGS * | MtrrGetFixedMtrrWorker (OUT MTRR_FIXED_SETTINGS *FixedSettings) |
MTRR_FIXED_SETTINGS *EFIAPI | MtrrGetFixedMtrr (OUT MTRR_FIXED_SETTINGS *FixedSettings) |
MTRR_VARIABLE_SETTINGS * | MtrrGetVariableMtrrWorker (IN MTRR_SETTINGS *MtrrSetting, IN UINT32 VariableMtrrCount, OUT MTRR_VARIABLE_SETTINGS *VariableSettings) |
RETURN_STATUS | MtrrLibProgramFixedMtrr (IN MTRR_MEMORY_CACHE_TYPE Type, IN OUT UINT64 *Base, IN OUT UINT64 *Length, IN OUT UINT32 *LastMsrIndex, OUT UINT64 *ClearMask, OUT UINT64 *OrMask) |
UINT32 | MtrrGetMemoryAttributeInVariableMtrrWorker (IN MTRR_VARIABLE_SETTINGS *VariableSettings, IN UINTN VariableMtrrCount, IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT VARIABLE_MTRR *VariableMtrr) |
UINT32 | MtrrLibGetRawVariableRanges (IN CONST MTRR_VARIABLE_SETTINGS *VariableSettings, IN UINTN VariableMtrrCount, IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT MTRR_MEMORY_RANGE *VariableMtrr) |
UINT32 EFIAPI | MtrrGetMemoryAttributeInVariableMtrr (IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidAddressMask, OUT VARIABLE_MTRR *VariableMtrr) |
UINT64 | MtrrLibBiggestAlignment (UINT64 Address, UINT64 Alignment0) |
BOOLEAN | MtrrLibTypeLeftPrecedeRight (IN MTRR_MEMORY_CACHE_TYPE Left, IN MTRR_MEMORY_CACHE_TYPE Right) |
VOID | MtrrLibInitializeMtrrMask (OUT UINT64 *MtrrValidBitsMask, OUT UINT64 *MtrrValidAddressMask) |
MTRR_MEMORY_CACHE_TYPE | MtrrLibPrecedence (IN MTRR_MEMORY_CACHE_TYPE MtrrType1, IN MTRR_MEMORY_CACHE_TYPE MtrrType2) |
MTRR_MEMORY_CACHE_TYPE | MtrrGetMemoryAttributeByAddressWorker (IN MTRR_SETTINGS *MtrrSetting, IN PHYSICAL_ADDRESS Address) |
MTRR_MEMORY_CACHE_TYPE EFIAPI | MtrrGetMemoryAttribute (IN PHYSICAL_ADDRESS Address) |
RETURN_STATUS | MtrrLibSetMemoryType (IN MTRR_MEMORY_RANGE *Ranges, IN UINTN Capacity, IN OUT UINTN *Count, IN UINT64 BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Type) |
UINT8 | MtrrLibGetNumberOfTypes (IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount, IN UINT64 BaseAddress, IN UINT64 Length, IN OUT UINT8 *Types OPTIONAL) |
VOID | MtrrLibCalculateLeastMtrrs (IN UINT16 VertexCount, IN MTRR_LIB_ADDRESS *Vertices, IN OUT CONST UINT8 *Weight, IN UINT16 Start, IN UINT16 Stop, IN BOOLEAN IncludeOptional) |
RETURN_STATUS | MtrrLibAppendVariableMtrr (IN OUT MTRR_MEMORY_RANGE *Mtrrs, IN UINT32 MtrrCapacity, IN OUT UINT32 *MtrrCount, IN UINT64 BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Type) |
MTRR_MEMORY_CACHE_TYPE | MtrrLibLowestType (IN UINT8 TypeBits) |
RETURN_STATUS | MtrrLibCalculateSubtractivePath (IN MTRR_MEMORY_CACHE_TYPE DefaultType, IN UINT64 A0, IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount, IN UINT16 VertexCount, IN MTRR_LIB_ADDRESS *Vertices, IN OUT UINT8 *Weight, IN UINT16 Start, IN UINT16 Stop, IN UINT8 Types, IN UINT8 TypeCount, IN OUT MTRR_MEMORY_RANGE *Mtrrs OPTIONAL, IN UINT32 MtrrCapacity OPTIONAL, IN OUT UINT32 *MtrrCount OPTIONAL) |
RETURN_STATUS | MtrrLibCalculateMtrrs (IN MTRR_MEMORY_CACHE_TYPE DefaultType, IN UINT64 A0, IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount, IN VOID *Scratch, IN OUT UINTN *ScratchSize, IN OUT MTRR_MEMORY_RANGE *Mtrrs, IN UINT32 MtrrCapacity, IN OUT UINT32 *MtrrCount) |
RETURN_STATUS | MtrrLibApplyFixedMtrrs (IN CONST MTRR_FIXED_SETTINGS *Fixed, IN OUT MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCapacity, IN OUT UINTN *RangeCount) |
RETURN_STATUS | MtrrLibApplyVariableMtrrs (IN CONST MTRR_MEMORY_RANGE *VariableMtrr, IN UINT32 VariableMtrrCount, IN OUT MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCapacity, IN OUT UINTN *RangeCount) |
UINT8 | MtrrLibGetCompatibleTypes (IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount) |
VOID | MtrrLibMergeVariableMtrr (MTRR_MEMORY_RANGE *DstMtrrs, UINT32 DstMtrrCount, MTRR_MEMORY_RANGE *SrcMtrrs, UINT32 SrcMtrrCount, BOOLEAN *Modified) |
RETURN_STATUS | MtrrLibSetMemoryRanges (IN MTRR_MEMORY_CACHE_TYPE DefaultType, IN UINT64 A0, IN MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount, IN VOID *Scratch, IN OUT UINTN *ScratchSize, OUT MTRR_MEMORY_RANGE *VariableMtrr, IN UINT32 VariableMtrrCapacity, OUT UINT32 *VariableMtrrCount) |
RETURN_STATUS | MtrrLibSetBelow1MBMemoryAttribute (IN OUT UINT64 *ClearMasks, IN OUT UINT64 *OrMasks, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Type) |
RETURN_STATUS EFIAPI | MtrrSetMemoryAttributesInMtrrSettings (IN OUT MTRR_SETTINGS *MtrrSetting, IN VOID *Scratch, IN OUT UINTN *ScratchSize, IN CONST MTRR_MEMORY_RANGE *Ranges, IN UINTN RangeCount) |
RETURN_STATUS EFIAPI | MtrrSetMemoryAttributeInMtrrSettings (IN OUT MTRR_SETTINGS *MtrrSetting, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute) |
RETURN_STATUS EFIAPI | MtrrSetMemoryAttribute (IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute) |
VOID | MtrrSetVariableMtrrWorker (IN MTRR_VARIABLE_SETTINGS *VariableSettings) |
VOID | MtrrSetFixedMtrrWorker (IN MTRR_FIXED_SETTINGS *FixedSettings) |
MTRR_SETTINGS *EFIAPI | MtrrGetAllMtrrs (OUT MTRR_SETTINGS *MtrrSetting) |
MTRR_SETTINGS *EFIAPI | MtrrSetAllMtrrs (IN MTRR_SETTINGS *MtrrSetting) |
BOOLEAN EFIAPI | IsMtrrSupported (VOID) |
RETURN_STATUS EFIAPI | MtrrGetMemoryAttributesInMtrrSettings (IN CONST MTRR_SETTINGS *MtrrSetting OPTIONAL, OUT MTRR_MEMORY_RANGE *Ranges, IN OUT UINTN *RangeCount) |
VOID EFIAPI | MtrrDebugPrintAllMtrrs (VOID) |
Variables | |
CONST FIXED_MTRR | mMtrrLibFixedMtrrTable [] |
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * | mMtrrMemoryCacheTypeShortName [] |
MTRR setting library
Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file MtrrLib.c.
#define MTRR_LIB_ASSERT_ALIGNED | ( | B, | |
L | |||
) | ASSERT ((B & ~(L - 1)) == B); |
UINT32 EFIAPI GetFirmwareVariableMtrrCount | ( | VOID | ) |
UINT32 GetFirmwareVariableMtrrCountWorker | ( | VOID | ) |
UINT32 EFIAPI GetVariableMtrrCount | ( | VOID | ) |
UINT32 GetVariableMtrrCountWorker | ( | VOID | ) |
BOOLEAN EFIAPI IsMtrrSupported | ( | VOID | ) |
VOID EFIAPI MtrrDebugPrintAllMtrrs | ( | VOID | ) |
VOID MtrrDebugPrintAllMtrrsWorker | ( | IN MTRR_SETTINGS * | MtrrSetting | ) |
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs | ( | OUT MTRR_SETTINGS * | MtrrSetting | ) |
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetDefaultMemoryType | ( | VOID | ) |
MTRR_MEMORY_CACHE_TYPE MtrrGetDefaultMemoryTypeWorker | ( | IN CONST MTRR_SETTINGS * | MtrrSetting | ) |
Worker function returns the default MTRR cache type for the system.
If MtrrSetting is not NULL, returns the default MTRR cache type from input MTRR settings buffer. If MtrrSetting is NULL, returns the default MTRR cache type from MSR.
[in] | MtrrSetting | A buffer holding all MTRRs content. |
MTRR_FIXED_SETTINGS *EFIAPI MtrrGetFixedMtrr | ( | OUT MTRR_FIXED_SETTINGS * | FixedSettings | ) |
MTRR_FIXED_SETTINGS * MtrrGetFixedMtrrWorker | ( | OUT MTRR_FIXED_SETTINGS * | FixedSettings | ) |
MTRR_MEMORY_CACHE_TYPE EFIAPI MtrrGetMemoryAttribute | ( | IN PHYSICAL_ADDRESS | Address | ) |
MTRR_MEMORY_CACHE_TYPE MtrrGetMemoryAttributeByAddressWorker | ( | IN MTRR_SETTINGS * | MtrrSetting, |
IN PHYSICAL_ADDRESS | Address | ||
) |
Worker function will get the memory cache type of the specific address.
If MtrrSetting is not NULL, gets the memory cache type from input MTRR settings buffer. If MtrrSetting is NULL, gets the memory cache type from MTRRs.
[in] | MtrrSetting | A buffer holding all MTRRs content. |
[in] | Address | The specific address |
UINT32 EFIAPI MtrrGetMemoryAttributeInVariableMtrr | ( | IN UINT64 | MtrrValidBitsMask, |
IN UINT64 | MtrrValidAddressMask, | ||
OUT VARIABLE_MTRR * | VariableMtrr | ||
) |
Gets the attribute of variable MTRRs.
This function shadows the content of variable MTRRs into an internal array: VariableMtrr.
[in] | MtrrValidBitsMask | The mask for the valid bit of the MTRR |
[in] | MtrrValidAddressMask | The valid address mask for MTRR |
[out] | VariableMtrr | The array to shadow variable MTRRs content |
UINT32 MtrrGetMemoryAttributeInVariableMtrrWorker | ( | IN MTRR_VARIABLE_SETTINGS * | VariableSettings, |
IN UINTN | VariableMtrrCount, | ||
IN UINT64 | MtrrValidBitsMask, | ||
IN UINT64 | MtrrValidAddressMask, | ||
OUT VARIABLE_MTRR * | VariableMtrr | ||
) |
Worker function gets the attribute of variable MTRRs.
This function shadows the content of variable MTRRs into an internal array: VariableMtrr.
[in] | VariableSettings | The variable MTRR values to shadow |
[in] | VariableMtrrCount | The number of variable MTRRs |
[in] | MtrrValidBitsMask | The mask for the valid bit of the MTRR |
[in] | MtrrValidAddressMask | The valid address mask for MTRR |
[out] | VariableMtrr | The array to shadow variable MTRRs content |
RETURN_STATUS EFIAPI MtrrGetMemoryAttributesInMtrrSettings | ( | IN CONST MTRR_SETTINGS *MtrrSetting | OPTIONAL, |
OUT MTRR_MEMORY_RANGE * | Ranges, | ||
IN OUT UINTN * | RangeCount | ||
) |
This function returns a Ranges array containing the memory cache types of all memory addresses.
[in] | MtrrSetting | MTRR setting buffer to parse. |
[out] | Ranges | Pointer to an array of MTRR_MEMORY_RANGE. |
[in,out] | RangeCount | Count of MTRR_MEMORY_RANGE. On input, the maximum entries the Ranges can hold. On output, the actual entries that the function returns. |
RETURN_INVALID_PARAMETER | RangeCount is NULL. |
RETURN_INVALID_PARAMETER | *RangeCount is not 0 but Ranges is NULL. |
RETURN_BUFFER_TOO_SMALL | *RangeCount is too small. |
RETURN_SUCCESS | Ranges are successfully returned. |
MTRR_VARIABLE_SETTINGS * MtrrGetVariableMtrrWorker | ( | IN MTRR_SETTINGS * | MtrrSetting, |
IN UINT32 | VariableMtrrCount, | ||
OUT MTRR_VARIABLE_SETTINGS * | VariableSettings | ||
) |
Worker function will get the raw value in variable MTRRs
If MtrrSetting is not NULL, gets the variable MTRRs raw value from input MTRR settings buffer. If MtrrSetting is NULL, gets the variable MTRRs raw value from MTRRs.
[in] | MtrrSetting | A buffer holding all MTRRs content. |
[in] | VariableMtrrCount | Number of variable MTRRs. |
[out] | VariableSettings | A buffer to hold variable MTRRs content. |
RETURN_STATUS MtrrLibAppendVariableMtrr | ( | IN OUT MTRR_MEMORY_RANGE * | Mtrrs, |
IN UINT32 | MtrrCapacity, | ||
IN OUT UINT32 * | MtrrCount, | ||
IN UINT64 | BaseAddress, | ||
IN UINT64 | Length, | ||
IN MTRR_MEMORY_CACHE_TYPE | Type | ||
) |
Append the MTRR setting to MTRR setting array.
Mtrrs | Array holding all MTRR settings. |
MtrrCapacity | Capacity of the MTRR array. |
MtrrCount | The count of MTRR settings in array. |
BaseAddress | Base address. |
Length | Length. |
Type | Memory type. |
RETURN_SUCCESS | MTRR setting is appended to array. |
RETURN_OUT_OF_RESOURCES | Array is full. |
RETURN_STATUS MtrrLibApplyFixedMtrrs | ( | IN CONST MTRR_FIXED_SETTINGS * | Fixed, |
IN OUT MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCapacity, | ||
IN OUT UINTN * | RangeCount | ||
) |
Apply the fixed MTRR settings to memory range array.
Fixed | The fixed MTRR settings. |
Ranges | Return the memory range array holding memory type settings for all memory address. |
RangeCapacity | The capacity of memory range array. |
RangeCount | Return the count of memory range. |
RETURN_SUCCESS | The memory range array is returned successfully. |
RETURN_OUT_OF_RESOURCES | The count of memory ranges exceeds capacity. |
RETURN_STATUS MtrrLibApplyVariableMtrrs | ( | IN CONST MTRR_MEMORY_RANGE * | VariableMtrr, |
IN UINT32 | VariableMtrrCount, | ||
IN OUT MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCapacity, | ||
IN OUT UINTN * | RangeCount | ||
) |
Apply the variable MTRR settings to memory range array.
VariableMtrr | The variable MTRR array. |
VariableMtrrCount | The count of variable MTRRs. |
Ranges | Return the memory range array with new MTRR settings applied. |
RangeCapacity | The capacity of memory range array. |
RangeCount | Return the count of memory range. |
RETURN_SUCCESS | The memory range array is returned successfully. |
RETURN_OUT_OF_RESOURCES | The count of memory ranges exceeds capacity. |
UINT64 MtrrLibBiggestAlignment | ( | UINT64 | Address, |
UINT64 | Alignment0 | ||
) |
Return the biggest alignment (lowest set bit) of address. The function is equivalent to: 1 << LowBitSet64 (Address).
Address | The address to return the alignment. |
Alignment0 | The alignment to return when Address is 0. |
VOID MtrrLibCalculateLeastMtrrs | ( | IN UINT16 | VertexCount, |
IN MTRR_LIB_ADDRESS * | Vertices, | ||
IN OUT CONST UINT8 * | Weight, | ||
IN UINT16 | Start, | ||
IN UINT16 | Stop, | ||
IN BOOLEAN | IncludeOptional | ||
) |
Calculate the least MTRR number from vertex Start to Stop and update the Previous of all vertices from Start to Stop is updated to reflect how the memory range is covered by MTRR.
VertexCount | The count of vertices in the graph. |
Vertices | Array holding all vertices. |
Weight | 2-dimention array holding weights between vertices. |
Start | Start vertex. |
Stop | Stop vertex. |
IncludeOptional | TRUE to count the optional weight. |
RETURN_STATUS MtrrLibCalculateMtrrs | ( | IN MTRR_MEMORY_CACHE_TYPE | DefaultType, |
IN UINT64 | A0, | ||
IN CONST MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCount, | ||
IN VOID * | Scratch, | ||
IN OUT UINTN * | ScratchSize, | ||
IN OUT MTRR_MEMORY_RANGE * | Mtrrs, | ||
IN UINT32 | MtrrCapacity, | ||
IN OUT UINT32 * | MtrrCount | ||
) |
Calculate MTRR settings to cover the specified memory ranges.
DefaultType | Default memory type. |
A0 | Alignment to use when base address is 0. |
Ranges | Memory range array holding the memory type settings for all memory address. |
RangeCount | Count of memory ranges. |
Scratch | A temporary scratch buffer that is used to perform the calculation. This is an optional parameter that may be NULL. |
ScratchSize | Pointer to the size in bytes of the scratch buffer. It may be updated to the actual required size when the calculation needs more scratch buffer. |
Mtrrs | Array holding all MTRR settings. |
MtrrCapacity | Capacity of the MTRR array. |
MtrrCount | The count of MTRR settings in array. |
RETURN_SUCCESS | Variable MTRRs are allocated successfully. |
RETURN_OUT_OF_RESOURCES | Count of variable MTRRs exceeds capacity. |
RETURN_BUFFER_TOO_SMALL | The scratch buffer is too small for MTRR calculation. |
RETURN_STATUS MtrrLibCalculateSubtractivePath | ( | IN MTRR_MEMORY_CACHE_TYPE | DefaultType, |
IN UINT64 | A0, | ||
IN CONST MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCount, | ||
IN UINT16 | VertexCount, | ||
IN MTRR_LIB_ADDRESS * | Vertices, | ||
IN OUT UINT8 * | Weight, | ||
IN UINT16 | Start, | ||
IN UINT16 | Stop, | ||
IN UINT8 | Types, | ||
IN UINT8 | TypeCount, | ||
IN OUT MTRR_MEMORY_RANGE *Mtrrs | OPTIONAL, | ||
IN UINT32 MtrrCapacity | OPTIONAL, | ||
IN OUT UINT32 *MtrrCount | OPTIONAL | ||
) |
Calculate the subtractive path from vertex Start to Stop.
DefaultType | Default memory type. |
A0 | Alignment to use when base address is 0. |
Ranges | Array holding memory type settings for all memory regions. |
RangeCount | The count of memory ranges the array holds. |
VertexCount | The count of vertices in the graph. |
Vertices | Array holding all vertices. |
Weight | 2-dimention array holding weights between vertices. |
Start | Start vertex. |
Stop | Stop vertex. |
Types | Type bit mask of memory range from Start to Stop. |
TypeCount | Number of different memory types from Start to Stop. |
Mtrrs | Array holding all MTRR settings. |
MtrrCapacity | Capacity of the MTRR array. |
MtrrCount | The count of MTRR settings in array. |
RETURN_SUCCESS | The subtractive path is calculated successfully. |
RETURN_OUT_OF_RESOURCES | The MTRR setting array is full. |
UINT8 MtrrLibGetCompatibleTypes | ( | IN CONST MTRR_MEMORY_RANGE * | Ranges, |
IN UINTN | RangeCount | ||
) |
UINT8 MtrrLibGetNumberOfTypes | ( | IN CONST MTRR_MEMORY_RANGE * | Ranges, |
IN UINTN | RangeCount, | ||
IN UINT64 | BaseAddress, | ||
IN UINT64 | Length, | ||
IN OUT UINT8 *Types | OPTIONAL | ||
) |
Return the number of memory types in range [BaseAddress, BaseAddress + Length).
Ranges | Array holding memory type settings for all memory regions. |
RangeCount | The count of memory ranges the array holds. |
BaseAddress | Base address. |
Length | Length. |
Types | Return bit mask to indicate all memory types in the specified range. |
Number | of memory types. |
UINT32 MtrrLibGetRawVariableRanges | ( | IN CONST MTRR_VARIABLE_SETTINGS * | VariableSettings, |
IN UINTN | VariableMtrrCount, | ||
IN UINT64 | MtrrValidBitsMask, | ||
IN UINT64 | MtrrValidAddressMask, | ||
OUT MTRR_MEMORY_RANGE * | VariableMtrr | ||
) |
Convert variable MTRRs to a RAW MTRR_MEMORY_RANGE array. One MTRR_MEMORY_RANGE element is created for each MTRR setting. The routine doesn't remove the overlap or combine the near-by region.
[in] | VariableSettings | The variable MTRR values to shadow |
[in] | VariableMtrrCount | The number of variable MTRRs |
[in] | MtrrValidBitsMask | The mask for the valid bit of the MTRR |
[in] | MtrrValidAddressMask | The valid address mask for MTRR |
[out] | VariableMtrr | The array to shadow variable MTRRs content |
VOID MtrrLibInitializeMtrrMask | ( | OUT UINT64 * | MtrrValidBitsMask, |
OUT UINT64 * | MtrrValidAddressMask | ||
) |
Initializes the valid bits mask and valid address mask for MTRRs.
This function initializes the valid bits mask and valid address mask for MTRRs.
[out] | MtrrValidBitsMask | The mask for the valid bit of the MTRR |
[out] | MtrrValidAddressMask | The valid address mask for the MTRR |
BOOLEAN MtrrLibIsMtrrSupported | ( | OUT BOOLEAN *FixedMtrrSupported | OPTIONAL, |
OUT UINT32 *VariableMtrrCount | OPTIONAL | ||
) |
Return whether MTRR is supported.
[out] | FixedMtrrSupported | Return whether fixed MTRR is supported. |
[out] | VariableMtrrCount | Return the max number of variable MTRRs. |
TRUE | MTRR is supported when either fixed MTRR is supported or max number of variable MTRRs is not 0. |
FALSE | MTRR is not supported when both fixed MTRR is not supported and max number of variable MTRRs is 0. |
MTRR_MEMORY_CACHE_TYPE MtrrLibLowestType | ( | IN UINT8 | TypeBits | ) |
VOID MtrrLibMergeVariableMtrr | ( | MTRR_MEMORY_RANGE * | DstMtrrs, |
UINT32 | DstMtrrCount, | ||
MTRR_MEMORY_RANGE * | SrcMtrrs, | ||
UINT32 | SrcMtrrCount, | ||
BOOLEAN * | Modified | ||
) |
Overwrite the destination MTRR settings with the source MTRR settings. This routine is to make sure the modification to destination MTRR settings is as small as possible.
DstMtrrs | Destination MTRR settings. |
DstMtrrCount | Count of destination MTRR settings. |
SrcMtrrs | Source MTRR settings. |
SrcMtrrCount | Count of source MTRR settings. |
Modified | Flag array to indicate which destination MTRR setting is modified. |
VOID MtrrLibPostMtrrChange | ( | IN MTRR_CONTEXT * | MtrrContext | ) |
VOID MtrrLibPostMtrrChangeEnableCache | ( | IN MTRR_CONTEXT * | MtrrContext | ) |
MTRR_MEMORY_CACHE_TYPE MtrrLibPrecedence | ( | IN MTRR_MEMORY_CACHE_TYPE | MtrrType1, |
IN MTRR_MEMORY_CACHE_TYPE | MtrrType2 | ||
) |
Determines the real attribute of a memory range.
This function is to arbitrate the real attribute of the memory when there are 2 MTRRs covers the same memory range. For further details, please refer the IA32 Software Developer's Manual, Volume 3, Section "MTRR Precedences".
[in] | MtrrType1 | The first kind of Memory type |
[in] | MtrrType2 | The second kind of memory type |
VOID MtrrLibPreMtrrChange | ( | OUT MTRR_CONTEXT * | MtrrContext | ) |
RETURN_STATUS MtrrLibProgramFixedMtrr | ( | IN MTRR_MEMORY_CACHE_TYPE | Type, |
IN OUT UINT64 * | Base, | ||
IN OUT UINT64 * | Length, | ||
IN OUT UINT32 * | LastMsrIndex, | ||
OUT UINT64 * | ClearMask, | ||
OUT UINT64 * | OrMask | ||
) |
Programs fixed MTRRs registers.
[in] | Type | The memory type to set. |
[in,out] | Base | The base address of memory range. |
[in,out] | Length | The length of memory range. |
[in,out] | LastMsrIndex | On input, the last index of the fixed MTRR MSR to program. On return, the current index of the fixed MTRR MSR to program. |
[out] | ClearMask | The bits to clear in the fixed MTRR MSR. |
[out] | OrMask | The bits to set in the fixed MTRR MSR. |
RETURN_SUCCESS | The cache type was updated successfully |
RETURN_UNSUPPORTED | The requested range or cache type was invalid for the fixed MTRRs. |
RETURN_STATUS MtrrLibSetBelow1MBMemoryAttribute | ( | IN OUT UINT64 * | ClearMasks, |
IN OUT UINT64 * | OrMasks, | ||
IN PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN MTRR_MEMORY_CACHE_TYPE | Type | ||
) |
Set the below-1MB memory attribute to fixed MTRR buffer. Modified flag array indicates which fixed MTRR is modified.
[in,out] | ClearMasks | The bits (when set) to clear in the fixed MTRR MSR. |
[in,out] | OrMasks | The bits to set in the fixed MTRR MSR. |
[in] | BaseAddress | Base address. |
[in] | Length | Length. |
[in] | Type | Memory type. |
RETURN_SUCCESS | The memory attribute is set successfully. |
RETURN_UNSUPPORTED | The requested range or cache type was invalid for the fixed MTRRs. |
RETURN_STATUS MtrrLibSetMemoryRanges | ( | IN MTRR_MEMORY_CACHE_TYPE | DefaultType, |
IN UINT64 | A0, | ||
IN MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCount, | ||
IN VOID * | Scratch, | ||
IN OUT UINTN * | ScratchSize, | ||
OUT MTRR_MEMORY_RANGE * | VariableMtrr, | ||
IN UINT32 | VariableMtrrCapacity, | ||
OUT UINT32 * | VariableMtrrCount | ||
) |
Calculate the variable MTRR settings for all memory ranges.
DefaultType | Default memory type. |
A0 | Alignment to use when base address is 0. |
Ranges | Memory range array holding the memory type settings for all memory address. |
RangeCount | Count of memory ranges. |
Scratch | Scratch buffer to be used in MTRR calculation. |
ScratchSize | Pointer to the size of scratch buffer. |
VariableMtrr | Array holding all MTRR settings. |
VariableMtrrCapacity | Capacity of the MTRR array. |
VariableMtrrCount | The count of MTRR settings in array. |
RETURN_SUCCESS | Variable MTRRs are allocated successfully. |
RETURN_OUT_OF_RESOURCES | Count of variable MTRRs exceeds capacity. |
RETURN_BUFFER_TOO_SMALL | The scratch buffer is too small for MTRR calculation. The required scratch buffer size is returned through ScratchSize. |
RETURN_STATUS MtrrLibSetMemoryType | ( | IN MTRR_MEMORY_RANGE * | Ranges, |
IN UINTN | Capacity, | ||
IN OUT UINTN * | Count, | ||
IN UINT64 | BaseAddress, | ||
IN UINT64 | Length, | ||
IN MTRR_MEMORY_CACHE_TYPE | Type | ||
) |
Update the Ranges array to change the specified range identified by BaseAddress and Length to Type.
Ranges | Array holding memory type settings for all memory regions. |
Capacity | The maximum count of memory ranges the array can hold. |
Count | Return the new memory range count in the array. |
BaseAddress | The base address of the memory range to change type. |
Length | The length of the memory range to change type. |
Type | The new type of the specified memory range. |
RETURN_SUCCESS | The type of the specified memory range is changed successfully. |
RETURN_ALREADY_STARTED | The type of the specified memory range equals to the desired type. |
RETURN_OUT_OF_RESOURCES | The new type set causes the count of memory range exceeds capacity. |
BOOLEAN MtrrLibTypeLeftPrecedeRight | ( | IN MTRR_MEMORY_CACHE_TYPE | Left, |
IN MTRR_MEMORY_CACHE_TYPE | Right | ||
) |
Return whether the left MTRR type precedes the right MTRR type.
The MTRR type precedence rules are:
Left | The left MTRR type. |
Right | The right MTRR type. |
TRUE | Left precedes Right. |
FALSE | Left doesn't precede Right. |
MTRR_SETTINGS *EFIAPI MtrrSetAllMtrrs | ( | IN MTRR_SETTINGS * | MtrrSetting | ) |
This function sets all MTRRs includes Variable and Fixed.
The behavior of this function is to program everything in MtrrSetting to hardware. MTRRs might not be enabled because the enable bit is clear in MtrrSetting->MtrrDefType.
[in] | MtrrSetting | A buffer holding all MTRRs content. |
The | pointer of MtrrSetting |
VOID MtrrSetFixedMtrrWorker | ( | IN MTRR_FIXED_SETTINGS * | FixedSettings | ) |
RETURN_STATUS EFIAPI MtrrSetMemoryAttribute | ( | IN PHYSICAL_ADDRESS | BaseAddress, |
IN UINT64 | Length, | ||
IN MTRR_MEMORY_CACHE_TYPE | Attribute | ||
) |
This function attempts to set the attributes for a memory range.
[in] | BaseAddress | The physical address that is the start address of a memory range. |
[in] | Length | The size in bytes of the memory range. |
[in] | Attributes | The bit mask of attributes to set for the memory range. |
RETURN_SUCCESS | The attributes were set for the memory range. |
RETURN_INVALID_PARAMETER | Length is zero. |
RETURN_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. |
RETURN_UNSUPPORTED | The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. |
RETURN_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
RETURN_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. Multiple memory range attributes setting by calling this API multiple times may fail with status RETURN_OUT_OF_RESOURCES. It may not mean the number of CPU MTRRs are too small to set such memory attributes. Pass the multiple memory range attributes to one call of MtrrSetMemoryAttributesInMtrrSettings() may succeed. |
RETURN_BUFFER_TOO_SMALL | The fixed internal scratch buffer is too small for MTRR calculation. Caller should use MtrrSetMemoryAttributesInMtrrSettings() to specify external scratch buffer. |
RETURN_STATUS EFIAPI MtrrSetMemoryAttributeInMtrrSettings | ( | IN OUT MTRR_SETTINGS * | MtrrSetting, |
IN PHYSICAL_ADDRESS | BaseAddress, | ||
IN UINT64 | Length, | ||
IN MTRR_MEMORY_CACHE_TYPE | Attribute | ||
) |
This function attempts to set the attributes into MTRR setting buffer for a memory range.
[in,out] | MtrrSetting | MTRR setting buffer to be set. |
[in] | BaseAddress | The physical address that is the start address of a memory range. |
[in] | Length | The size in bytes of the memory range. |
[in] | Attribute | The bit mask of attributes to set for the memory range. |
RETURN_SUCCESS | The attributes were set for the memory range. |
RETURN_INVALID_PARAMETER | Length is zero. |
RETURN_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. |
RETURN_UNSUPPORTED | The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. |
RETURN_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
RETURN_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource range. Multiple memory range attributes setting by calling this API multiple times may fail with status RETURN_OUT_OF_RESOURCES. It may not mean the number of CPU MTRRs are too small to set such memory attributes. Pass the multiple memory range attributes to one call of MtrrSetMemoryAttributesInMtrrSettings() may succeed. |
RETURN_BUFFER_TOO_SMALL | The fixed internal scratch buffer is too small for MTRR calculation. Caller should use MtrrSetMemoryAttributesInMtrrSettings() to specify external scratch buffer. |
RETURN_STATUS EFIAPI MtrrSetMemoryAttributesInMtrrSettings | ( | IN OUT MTRR_SETTINGS * | MtrrSetting, |
IN VOID * | Scratch, | ||
IN OUT UINTN * | ScratchSize, | ||
IN CONST MTRR_MEMORY_RANGE * | Ranges, | ||
IN UINTN | RangeCount | ||
) |
This function attempts to set the attributes into MTRR setting buffer for multiple memory ranges.
[in,out] | MtrrSetting | MTRR setting buffer to be set. |
[in] | Scratch | A temporary scratch buffer that is used to perform the calculation. |
[in,out] | ScratchSize | Pointer to the size in bytes of the scratch buffer. It may be updated to the actual required size when the calculation needs more scratch buffer. |
[in] | Ranges | Pointer to an array of MTRR_MEMORY_RANGE. When range overlap happens, the last one takes higher priority. When the function returns, either all the attributes are set successfully, or none of them is set. |
[in] | RangeCount | Count of MTRR_MEMORY_RANGE. |
RETURN_SUCCESS | The attributes were set for all the memory ranges. |
RETURN_INVALID_PARAMETER | Length in any range is zero. |
RETURN_UNSUPPORTED | The processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length in any range. |
RETURN_UNSUPPORTED | The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length in any range. |
RETURN_OUT_OF_RESOURCES | There are not enough system resources to modify the attributes of the memory resource ranges. |
RETURN_ACCESS_DENIED | The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. |
RETURN_BUFFER_TOO_SMALL | The scratch buffer is too small for MTRR calculation. |
VOID MtrrSetVariableMtrrWorker | ( | IN MTRR_VARIABLE_SETTINGS * | VariableSettings | ) |
CONST FIXED_MTRR mMtrrLibFixedMtrrTable[] |
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8* mMtrrMemoryCacheTypeShortName[] |