TianoCore EDK2 master
Loading...
Searching...
No Matches
CacheLib.c File Reference
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/CacheLib.h>
#include <Library/CacheAsRamLib.h>
#include "CacheLibInternal.h"

Go to the source code of this file.

Data Structures

struct  EFI_FIXED_MTRR
 

Functions

EFI_STATUS SearchForExactMtrr (IN EFI_PHYSICAL_ADDRESS MemoryAddress, IN UINT64 MemoryLength, IN UINT64 ValidMtrrAddressMask, OUT UINT32 *UsedMsrNum, OUT EFI_MEMORY_CACHE_TYPE *MemoryCacheType)
 
BOOLEAN IsDefaultType (IN EFI_MEMORY_CACHE_TYPE MemoryCacheType)
 
UINT32 CheckMtrrAlignment (IN UINT64 BaseAddress, IN UINT64 Size)
 
INT8 CheckDirection (IN UINT64 Input)
 
VOID EfiDisableCacheMtrr (OUT UINT64 *OldMtrr)
 
VOID EfiRecoverCacheMtrr (IN BOOLEAN EnableMtrr, IN UINT64 OldMtrr)
 
VOID EfiProgramMtrr (IN UINT32 MtrrNumber, IN EFI_PHYSICAL_ADDRESS MemoryAddress, IN UINT64 MemoryLength, IN EFI_MEMORY_CACHE_TYPE MemoryCacheType, IN UINT64 ValidMtrrAddressMask)
 
UINT64 Power2MaxMemory (IN UINT64 MemoryAddress, IN UINT64 MemoryLength)
 
EFI_STATUS ProgramFixedMtrr (IN EFI_MEMORY_CACHE_TYPE MemoryCacheType, IN UINT64 *Base, IN UINT64 *Len)
 
BOOLEAN CheckMtrrOverlap (IN EFI_PHYSICAL_ADDRESS Start, IN EFI_PHYSICAL_ADDRESS End)
 
EFI_STATUS EFIAPI SetCacheAttributes (IN EFI_PHYSICAL_ADDRESS MemoryAddress, IN UINT64 MemoryLength, IN EFI_MEMORY_CACHE_TYPE MemoryCacheType)
 
EFI_STATUS EFIAPI ResetCacheAttributes (VOID)
 

Variables

EFI_FIXED_MTRR mFixedMtrrTable []
 

Detailed Description

Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CacheLib.c.

Function Documentation

◆ CheckDirection()

INT8 CheckDirection ( IN UINT64  Input)

Given the input, check if the number of MTRR is lesser. if positive or subtractive.

Parameters
[in]InputLength of Memory to program MTRR.
Return values
Zerodo positive.
Non-Zerodo subtractive.

Definition at line 96 of file CacheLib.c.

◆ CheckMtrrAlignment()

UINT32 CheckMtrrAlignment ( IN UINT64  BaseAddress,
IN UINT64  Size 
)

Return MTRR alignment requirement for base address and size.

Parameters
[in]BaseAddressBase address.
[in]SizeSize.
Return values
ZeroAligned.
Non-ZeroNot aligned.

Definition at line 255 of file CacheLib.c.

◆ CheckMtrrOverlap()

BOOLEAN CheckMtrrOverlap ( IN EFI_PHYSICAL_ADDRESS  Start,
IN EFI_PHYSICAL_ADDRESS  End 
)

Check if there is a valid variable MTRR that overlaps the given range.

Parameters
[in]StartBase Address of the range to check.
[in]EndEnd address of the range to check.
Return values
TRUEMtrr overlap.
FALSEMtrr not overlap.

Definition at line 354 of file CacheLib.c.

◆ EfiDisableCacheMtrr()

VOID EfiDisableCacheMtrr ( OUT UINT64 *  OldMtrr)

Disable cache and its mtrr.

Parameters
[out]OldMtrrTo return the Old MTRR value

Definition at line 110 of file CacheLib.c.

◆ EfiProgramMtrr()

VOID EfiProgramMtrr ( IN UINT32  MtrrNumber,
IN EFI_PHYSICAL_ADDRESS  MemoryAddress,
IN UINT64  MemoryLength,
IN EFI_MEMORY_CACHE_TYPE  MemoryCacheType,
IN UINT64  ValidMtrrAddressMask 
)

Programming MTRR according to Memory address, length, and type.

Parameters
[in]MtrrNumberthe variable MTRR index number
[in]MemoryAddressthe address of target memory
[in]MemoryLengththe length of target memory
[in]MemoryCacheTypethe cache type of target memory
[in]ValidMtrrAddressMaskthe MTRR address mask

Definition at line 166 of file CacheLib.c.

◆ EfiRecoverCacheMtrr()

VOID EfiRecoverCacheMtrr ( IN BOOLEAN  EnableMtrr,
IN UINT64  OldMtrr 
)

Recover cache MTRR.

Parameters
[in]EnableMtrrWhether to enable the MTRR
[in]OldMtrrThe saved old MTRR value to restore when not to enable the MTRR

Definition at line 133 of file CacheLib.c.

◆ IsDefaultType()

BOOLEAN IsDefaultType ( IN EFI_MEMORY_CACHE_TYPE  MemoryCacheType)

Check if CacheType match current default setting.

Parameters
[in]MemoryCacheTypeinput cache type to be checked.
Return values
TRUEMemoryCacheType is default MTRR setting.
FALSEMemoryCacheType is NOT default MTRR setting.

Check if CacheType match current default setting.

Parameters
[in]MemoryCacheTypeinput cache type to be checked.
Return values
TRUEMemoryCacheType is default MTRR setting.
TRUEMemoryCacheType is NOT default MTRR setting.

Definition at line 698 of file CacheLib.c.

◆ Power2MaxMemory()

UINT64 Power2MaxMemory ( IN UINT64  MemoryAddress,
IN UINT64  MemoryLength 
)

Calculate the maximum value which is a power of 2, but less the MemoryLength.

Parameters
[in]MemoryAddressMemory address.
[in]MemoryLengthThe number to pass in.
Returns
The maximum value which is align to power of 2 and less the MemoryLength

Definition at line 208 of file CacheLib.c.

◆ ProgramFixedMtrr()

EFI_STATUS ProgramFixedMtrr ( IN EFI_MEMORY_CACHE_TYPE  MemoryCacheType,
IN UINT64 *  Base,
IN UINT64 *  Len 
)

Programs fixed MTRRs registers.

Parameters
[in]MemoryCacheTypeThe memory type to set.
[in]BaseThe base address of memory range.
[in]LengthThe length of memory range.
Return values
RETURN_SUCCESSThe cache type was updated successfully
RETURN_UNSUPPORTEDThe requested range or cache type was invalid for the fixed MTRRs.

Definition at line 290 of file CacheLib.c.

◆ ResetCacheAttributes()

EFI_STATUS EFIAPI ResetCacheAttributes ( VOID  )

Reset all the MTRRs to a known state.

Return values
EFI_SUCCESSAll MTRRs have been reset successfully.

Definition at line 582 of file CacheLib.c.

◆ SearchForExactMtrr()

EFI_STATUS SearchForExactMtrr ( IN EFI_PHYSICAL_ADDRESS  MemoryAddress,
IN UINT64  MemoryLength,
IN UINT64  ValidMtrrAddressMask,
OUT UINT32 *  UsedMsrNum,
OUT EFI_MEMORY_CACHE_TYPE *  UsedMemoryCacheType 
)

Search the memory cache type for specific memory from MTRR.

Parameters
[in]MemoryAddressthe address of target memory
[in]MemoryLengththe length of target memory
[in]ValidMtrrAddressMaskthe MTRR address mask
[out]UsedMsrNumthe used MSR number
[out]UsedMemoryCacheTypethe cache type for the target memory
Return values
EFI_SUCCESSThe memory is found in MTRR and cache type is returned
EFI_NOT_FOUNDThe memory is not found in MTRR

Definition at line 649 of file CacheLib.c.

◆ SetCacheAttributes()

EFI_STATUS EFIAPI SetCacheAttributes ( IN EFI_PHYSICAL_ADDRESS  MemoryAddress,
IN UINT64  MemoryLength,
IN EFI_MEMORY_CACHE_TYPE  MemoryCacheType 
)

Given the memory range and cache type, programs the MTRRs.

Parameters
[in]MemoryAddressBase Address of Memory to program MTRR.
[in]MemoryLengthLength of Memory to program MTRR.
[in]MemoryCacheTypeCache Type.
Return values
EFI_SUCCESSMtrr are set successfully.
EFI_LOAD_ERRORNo empty MTRRs to use.
EFI_INVALID_PARAMETERThe input parameter is not valid.
othersAn error occurs when setting MTTR.

Definition at line 377 of file CacheLib.c.

Variable Documentation

◆ mFixedMtrrTable

EFI_FIXED_MTRR mFixedMtrrTable[]
Initial value:
= {
{ EFI_MSR_IA32_MTRR_FIX64K_00000, 0, 0x10000 },
{ EFI_MSR_IA32_MTRR_FIX16K_80000, 0x80000, 0x4000 },
{ EFI_MSR_IA32_MTRR_FIX16K_A0000, 0xA0000, 0x4000 },
{ EFI_MSR_IA32_MTRR_FIX4K_C0000, 0xC0000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_C8000, 0xC8000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_D0000, 0xD0000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_D8000, 0xD8000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_E0000, 0xE0000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_E8000, 0xE8000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_F0000, 0xF0000, 0x1000 },
{ EFI_MSR_IA32_MTRR_FIX4K_F8000, 0xF8000, 0x1000 }
}

Definition at line 71 of file CacheLib.c.