Revert incompatible change:

1) No API change from old version.
2) Change MACRO:
#define  MTRR_NUMBER_OF_VARIABLE_MTRR  32 // the semantics are changed from NUMBER to MAX_NUMBER.
#define  FIRMWARE_VARIABLE_MTRR_NUMBER  6 // wrong and deprecated
#define  MTRR_LIB_IA32_VARIABLE_MTRR_END 0x20F // wrong and deprecated
#define  RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER  2 // add new one.


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9941 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jyao1 2010-02-05 22:27:07 +00:00
parent 3aa4215f72
commit 3ba736f39c
2 changed files with 33 additions and 50 deletions

View File

@ -21,15 +21,19 @@
// //
// //
// We can not use Pcd as macro to define structure, so we have to define MAX_MTRR_NUMBER_OF_VARIABLE_MTRR // The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.
// //
#define MAX_MTRR_NUMBER_OF_VARIABLE_MTRR 32 #define MTRR_NUMBER_OF_VARIABLE_MTRR 32
// //
// Firmware need reserve 2 MTRR for OS // Firmware need reserve 2 MTRR for OS
// //
#define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2 #define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2
#define MTRR_NUMBER_OF_FIXED_MTRR 11 #define MTRR_NUMBER_OF_FIXED_MTRR 11
//
// Below macro is deprecated, and should not be used.
//
#define FIRMWARE_VARIABLE_MTRR_NUMBER 6
#define MTRR_LIB_IA32_MTRR_CAP 0x0FE #define MTRR_LIB_IA32_MTRR_CAP 0x0FE
#define MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK 0x0FF #define MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK 0x0FF
#define MTRR_LIB_IA32_MTRR_FIX64K_00000 0x250 #define MTRR_LIB_IA32_MTRR_FIX64K_00000 0x250
@ -44,6 +48,10 @@
#define MTRR_LIB_IA32_MTRR_FIX4K_F0000 0x26E #define MTRR_LIB_IA32_MTRR_FIX4K_F0000 0x26E
#define MTRR_LIB_IA32_MTRR_FIX4K_F8000 0x26F #define MTRR_LIB_IA32_MTRR_FIX4K_F8000 0x26F
#define MTRR_LIB_IA32_VARIABLE_MTRR_BASE 0x200 #define MTRR_LIB_IA32_VARIABLE_MTRR_BASE 0x200
//
// Below macro is deprecated, and should not be used.
//
#define MTRR_LIB_IA32_VARIABLE_MTRR_END 0x20F
#define MTRR_LIB_IA32_MTRR_DEF_TYPE 0x2FF #define MTRR_LIB_IA32_MTRR_DEF_TYPE 0x2FF
#define MTRR_LIB_MSR_VALID_MASK 0xFFFFFFFFFULL #define MTRR_LIB_MSR_VALID_MASK 0xFFFFFFFFFULL
#define MTRR_LIB_CACHE_VALID_ADDRESS 0xFFFFFF000ULL #define MTRR_LIB_CACHE_VALID_ADDRESS 0xFFFFFF000ULL
@ -83,7 +91,7 @@ typedef struct _MTRR_VARIABLE_SETTING_ {
// Array for variable MTRRs // Array for variable MTRRs
// //
typedef struct _MTRR_VARIABLE_SETTINGS_ { typedef struct _MTRR_VARIABLE_SETTINGS_ {
MTRR_VARIABLE_SETTING Mtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR]; MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
} MTRR_VARIABLE_SETTINGS; } MTRR_VARIABLE_SETTINGS;
// //
@ -286,21 +294,15 @@ MtrrSetAllMtrrs (
@param MtrrValidAddressMask The valid address mask for MTRR since the base address in @param MtrrValidAddressMask The valid address mask for MTRR since the base address in
MTRR must align to 4K, so valid address mask equal to MTRR must align to 4K, so valid address mask equal to
MtrrValidBitsMask & 0xfffffffffffff000ULL MtrrValidBitsMask & 0xfffffffffffff000ULL
@param VariableMtrrCount On input, it means the array number of variable MTRRs passed in.
On output, it means the number of MTRRs which has been used if EFI_SUCCESS,
or the number of MTRR required if BUFFER_TOO_SMALL.
@param VariableMtrr The array to shadow variable MTRRs content @param VariableMtrr The array to shadow variable MTRRs content
@return The ruturn value of this paramter indicates the number of
@retval RETURN_SUCCESS The variable MTRRs are returned. MTRRs which has been used.
@retval RETURN_BUFFER_TOO_SMALL The input buffer is too small to hold the variable MTRRs.
**/ **/
RETURN_STATUS UINT32
EFIAPI EFIAPI
MtrrGetMemoryAttributeInVariableMtrr ( MtrrGetMemoryAttributeInVariableMtrr (
IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidBitsMask,
IN UINT64 MtrrValidAddressMask, IN UINT64 MtrrValidAddressMask,
IN OUT UINT32 *VariableMtrrCount,
OUT VARIABLE_MTRR *VariableMtrr OUT VARIABLE_MTRR *VariableMtrr
); );

View File

@ -300,49 +300,35 @@ ProgramFixedMtrr (
/** /**
Get the attribute of variable MTRRs. Get the attribute of variable MTRRs.
This function shadows the content of variable MTRRs into This function shadows the content of variable MTRRs into an
an internal array: VariableMtrr internal array: VariableMtrr.
@param MtrrValidBitsMask The mask for the valid bit of the MTRR @param MtrrValidBitsMask The mask for the valid bit of the MTRR
@param MtrrValidAddressMask The valid address mask for MTRR since the base address in @param MtrrValidAddressMask The valid address mask for MTRR
MTRR must align to 4K, so valid address mask equal to
MtrrValidBitsMask & 0xfffffffffffff000ULL
@param VariableMtrrCount On input, it means the array number of variable MTRRs passed in.
On output, it means the number of MTRRs which has been used if EFI_SUCCESS,
or the number of MTRR required if BUFFER_TOO_SMALL.
@param VariableMtrr The array to shadow variable MTRRs content @param VariableMtrr The array to shadow variable MTRRs content
@retval RETURN_SUCCESS The variable MTRRs are returned. @return The return value of this paramter indicates the
@retval RETURN_BUFFER_TOO_SMALL The input buffer is too small to hold the variable MTRRs. number of MTRRs which has been used.
**/ **/
RETURN_STATUS UINT32
EFIAPI EFIAPI
MtrrGetMemoryAttributeInVariableMtrr ( MtrrGetMemoryAttributeInVariableMtrr (
IN UINT64 MtrrValidBitsMask, IN UINT64 MtrrValidBitsMask,
IN UINT64 MtrrValidAddressMask, IN UINT64 MtrrValidAddressMask,
IN OUT UINT32 *VariableMtrrCount,
OUT VARIABLE_MTRR *VariableMtrr OUT VARIABLE_MTRR *VariableMtrr
) )
{ {
UINTN Index; UINTN Index;
UINT32 MsrNum; UINT32 MsrNum;
UINT32 UsedMtrr; UINT32 UsedMtrr;
UINTN FirmwareVariableMtrrCount; UINT32 FirmwareVariableMtrrCount;
UINT32 VariableMtrrEnd; UINT32 VariableMtrrEnd;
//
// Check if input buffer is large enough
//
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount (); FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();
if (*VariableMtrrCount < FirmwareVariableMtrrCount) {
*VariableMtrrCount = (UINT32)FirmwareVariableMtrrCount;
return RETURN_BUFFER_TOO_SMALL;
}
VariableMtrrEnd = MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (2 * GetVariableMtrrCount ()) - 1; VariableMtrrEnd = MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (2 * GetVariableMtrrCount ()) - 1;
ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * (*VariableMtrrCount)); ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * MTRR_NUMBER_OF_VARIABLE_MTRR);
UsedMtrr = 0; UsedMtrr = 0;
for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE, Index = 0; for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE, Index = 0;
@ -368,8 +354,7 @@ MtrrGetMemoryAttributeInVariableMtrr (
Index++; Index++;
} }
} }
*VariableMtrrCount = UsedMtrr; return UsedMtrr;
return RETURN_SUCCESS;
} }
@ -882,7 +867,7 @@ MtrrSetMemoryAttribute (
BOOLEAN Positive; BOOLEAN Positive;
UINT32 MsrNum; UINT32 MsrNum;
UINTN MtrrNumber; UINTN MtrrNumber;
VARIABLE_MTRR VariableMtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR]; VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT32 UsedMtrr; UINT32 UsedMtrr;
UINT64 MtrrValidBitsMask; UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask; UINT64 MtrrValidAddressMask;
@ -960,8 +945,7 @@ MtrrSetMemoryAttribute (
// //
// Check for overlap // Check for overlap
// //
UsedMtrr = MAX_MTRR_NUMBER_OF_VARIABLE_MTRR; UsedMtrr = MtrrGetMemoryAttributeInVariableMtrr (MtrrValidBitsMask, MtrrValidAddressMask, VariableMtrr);
MtrrGetMemoryAttributeInVariableMtrr (MtrrValidBitsMask, MtrrValidAddressMask, &UsedMtrr, VariableMtrr);
OverLap = CheckMemoryAttributeOverlap (BaseAddress, BaseAddress + Length - 1, VariableMtrr); OverLap = CheckMemoryAttributeOverlap (BaseAddress, BaseAddress + Length - 1, VariableMtrr);
if (OverLap) { if (OverLap) {
Status = CombineMemoryAttribute (MemoryType, &BaseAddress, &Length, VariableMtrr, &UsedMtrr, &OverwriteExistingMtrr); Status = CombineMemoryAttribute (MemoryType, &BaseAddress, &Length, VariableMtrr, &UsedMtrr, &OverwriteExistingMtrr);
@ -1127,11 +1111,10 @@ MtrrGetMemoryAttribute (
UINT64 MtrrType; UINT64 MtrrType;
UINT64 TempMtrrType; UINT64 TempMtrrType;
MTRR_MEMORY_CACHE_TYPE CacheType; MTRR_MEMORY_CACHE_TYPE CacheType;
VARIABLE_MTRR VariableMtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR]; VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT64 MtrrValidBitsMask; UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask; UINT64 MtrrValidAddressMask;
UINTN VariableMtrrCount; UINTN VariableMtrrCount;
UINT32 UsedMtrr;
// //
// Check if MTRR is enabled, if not, return UC as attribute // Check if MTRR is enabled, if not, return UC as attribute
@ -1169,11 +1152,9 @@ MtrrGetMemoryAttribute (
} }
} }
MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask); MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);
UsedMtrr = MAX_MTRR_NUMBER_OF_VARIABLE_MTRR;
MtrrGetMemoryAttributeInVariableMtrr( MtrrGetMemoryAttributeInVariableMtrr(
MtrrValidBitsMask, MtrrValidBitsMask,
MtrrValidAddressMask, MtrrValidAddressMask,
&UsedMtrr,
VariableMtrr VariableMtrr
); );