2009-05-27 23:09:39 +02:00
|
|
|
/** @file
|
|
|
|
MTRR setting library
|
|
|
|
|
2016-08-18 09:34:54 +02:00
|
|
|
Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 14:25:26 +02:00
|
|
|
This program and the accompanying materials
|
2009-05-27 23:09:39 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef _MTRR_LIB_H_
|
|
|
|
#define _MTRR_LIB_H_
|
|
|
|
|
|
|
|
//
|
2016-08-18 09:34:54 +02:00
|
|
|
// According to IA32 SDM, MTRRs number and MSR offset are always consistent
|
2009-05-27 23:09:39 +02:00
|
|
|
// for IA32 processor family
|
|
|
|
//
|
2010-02-05 07:33:42 +01:00
|
|
|
|
|
|
|
//
|
2010-02-05 23:27:07 +01:00
|
|
|
// The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.
|
2010-02-05 07:33:42 +01:00
|
|
|
//
|
2010-02-05 23:27:07 +01:00
|
|
|
#define MTRR_NUMBER_OF_VARIABLE_MTRR 32
|
2010-02-05 07:33:42 +01:00
|
|
|
//
|
|
|
|
// Firmware need reserve 2 MTRR for OS
|
2015-12-08 06:19:34 +01:00
|
|
|
// Note: It is replaced by PCD PcdCpuNumberOfReservedVariableMtrrs
|
2010-02-05 07:33:42 +01:00
|
|
|
//
|
|
|
|
#define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2
|
|
|
|
|
2009-05-27 23:09:39 +02:00
|
|
|
#define MTRR_NUMBER_OF_FIXED_MTRR 11
|
|
|
|
|
|
|
|
//
|
|
|
|
// Structure to describe a fixed MTRR
|
|
|
|
//
|
|
|
|
typedef struct {
|
|
|
|
UINT32 Msr;
|
|
|
|
UINT32 BaseAddress;
|
|
|
|
UINT32 Length;
|
|
|
|
} FIXED_MTRR;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Structure to describe a variable MTRR
|
|
|
|
//
|
|
|
|
typedef struct {
|
|
|
|
UINT64 BaseAddress;
|
|
|
|
UINT64 Length;
|
|
|
|
UINT64 Type;
|
|
|
|
UINT32 Msr;
|
|
|
|
BOOLEAN Valid;
|
|
|
|
BOOLEAN Used;
|
|
|
|
} VARIABLE_MTRR;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Structure to hold base and mask pair for variable MTRR register
|
|
|
|
//
|
|
|
|
typedef struct _MTRR_VARIABLE_SETTING_ {
|
2015-12-08 06:20:44 +01:00
|
|
|
UINT64 Base;
|
|
|
|
UINT64 Mask;
|
2009-05-27 23:09:39 +02:00
|
|
|
} MTRR_VARIABLE_SETTING;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Array for variable MTRRs
|
|
|
|
//
|
|
|
|
typedef struct _MTRR_VARIABLE_SETTINGS_ {
|
2016-08-18 09:34:54 +02:00
|
|
|
MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
|
|
|
|
} MTRR_VARIABLE_SETTINGS;
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
//
|
2016-08-18 09:34:54 +02:00
|
|
|
// Array for fixed MTRRs
|
2009-05-27 23:09:39 +02:00
|
|
|
//
|
|
|
|
typedef struct _MTRR_FIXED_SETTINGS_ {
|
|
|
|
UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];
|
|
|
|
} MTRR_FIXED_SETTINGS;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Structure to hold all MTRRs
|
|
|
|
//
|
|
|
|
typedef struct _MTRR_SETTINGS_ {
|
|
|
|
MTRR_FIXED_SETTINGS Fixed;
|
|
|
|
MTRR_VARIABLE_SETTINGS Variables;
|
|
|
|
UINT64 MtrrDefType;
|
|
|
|
} MTRR_SETTINGS;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Memory cache types
|
|
|
|
//
|
|
|
|
typedef enum {
|
2015-12-08 06:20:44 +01:00
|
|
|
CacheUncacheable = 0,
|
|
|
|
CacheWriteCombining = 1,
|
|
|
|
CacheWriteThrough = 4,
|
|
|
|
CacheWriteProtected = 5,
|
2016-08-23 04:38:02 +02:00
|
|
|
CacheWriteBack = 6,
|
|
|
|
CacheInvalid = 7
|
2009-05-27 23:09:39 +02:00
|
|
|
} MTRR_MEMORY_CACHE_TYPE;
|
|
|
|
|
|
|
|
#define MTRR_CACHE_UNCACHEABLE 0
|
|
|
|
#define MTRR_CACHE_WRITE_COMBINING 1
|
|
|
|
#define MTRR_CACHE_WRITE_THROUGH 4
|
|
|
|
#define MTRR_CACHE_WRITE_PROTECTED 5
|
|
|
|
#define MTRR_CACHE_WRITE_BACK 6
|
|
|
|
#define MTRR_CACHE_INVALID_TYPE 7
|
|
|
|
|
2010-02-05 07:33:42 +01:00
|
|
|
/**
|
|
|
|
Returns the variable MTRR count for the CPU.
|
|
|
|
|
|
|
|
@return Variable MTRR count
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
2010-04-17 01:36:53 +02:00
|
|
|
EFIAPI
|
2010-02-05 07:33:42 +01:00
|
|
|
GetVariableMtrrCount (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the firmware usable variable MTRR count for the CPU.
|
|
|
|
|
|
|
|
@return Firmware usable variable MTRR count
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
2010-04-17 01:36:53 +02:00
|
|
|
EFIAPI
|
2010-02-05 07:33:42 +01:00
|
|
|
GetFirmwareVariableMtrrCount (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2009-05-27 23:09:39 +02:00
|
|
|
/**
|
|
|
|
This function attempts to set the attributes for a memory range.
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] BaseAddress The physical address that is the start
|
|
|
|
address of a memory region.
|
|
|
|
@param[in] Length The size in bytes of the memory region.
|
|
|
|
@param[in] Attribute The bit mask of attributes to set for the
|
|
|
|
memory region.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@retval RETURN_SUCCESS The attributes were set for the memory
|
|
|
|
region.
|
2009-05-27 23:09:39 +02:00
|
|
|
@retval RETURN_INVALID_PARAMETER Length is zero.
|
2015-12-08 06:20:44 +01:00
|
|
|
@retval RETURN_UNSUPPORTED The processor does not support one or
|
|
|
|
more bytes of the memory resource range
|
|
|
|
specified by BaseAddress and Length.
|
|
|
|
@retval RETURN_UNSUPPORTED The bit mask of attributes is not support
|
|
|
|
for the memory resource range specified
|
|
|
|
by BaseAddress and Length.
|
|
|
|
@retval RETURN_ACCESS_DENIED The attributes for the memory resource
|
|
|
|
range specified by BaseAddress and Length
|
|
|
|
cannot be modified.
|
|
|
|
@retval RETURN_OUT_OF_RESOURCES There are not enough system resources to
|
|
|
|
modify the attributes of the memory
|
|
|
|
resource range.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MtrrSetMemoryAttribute (
|
|
|
|
IN PHYSICAL_ADDRESS BaseAddress,
|
|
|
|
IN UINT64 Length,
|
|
|
|
IN MTRR_MEMORY_CACHE_TYPE Attribute
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will get the memory cache type of the specific address.
|
|
|
|
This function is mainly for debugging purposes.
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] Address The specific address
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The memory cache type of the specific address
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_MEMORY_CACHE_TYPE
|
|
|
|
EFIAPI
|
|
|
|
MtrrGetMemoryAttribute (
|
|
|
|
IN PHYSICAL_ADDRESS Address
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will get the raw value in variable MTRRs
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[out] VariableSettings A buffer to hold variable MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
2016-08-18 09:34:54 +02:00
|
|
|
@return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable MTRR
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_VARIABLE_SETTINGS*
|
|
|
|
EFIAPI
|
|
|
|
MtrrGetVariableMtrr (
|
|
|
|
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-08-18 09:34:54 +02:00
|
|
|
This function sets variable MTRRs
|
2009-05-27 23:09:39 +02:00
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] VariableSettings A buffer to hold variable MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The pointer of VariableSettings
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_VARIABLE_SETTINGS*
|
|
|
|
EFIAPI
|
|
|
|
MtrrSetVariableMtrr (
|
|
|
|
IN MTRR_VARIABLE_SETTINGS *VariableSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function gets the content in fixed MTRRs
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[out] FixedSettings A buffer to hold fixed MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The pointer of FixedSettings
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_FIXED_SETTINGS*
|
|
|
|
EFIAPI
|
|
|
|
MtrrGetFixedMtrr (
|
|
|
|
OUT MTRR_FIXED_SETTINGS *FixedSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function sets fixed MTRRs
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] FixedSettings A buffer holding fixed MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The pointer of FixedSettings
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_FIXED_SETTINGS*
|
|
|
|
EFIAPI
|
|
|
|
MtrrSetFixedMtrr (
|
|
|
|
IN MTRR_FIXED_SETTINGS *FixedSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function gets the content in all MTRRs (variable and fixed)
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[out] MtrrSetting A buffer to hold all MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The pointer of MtrrSetting
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_SETTINGS *
|
|
|
|
EFIAPI
|
|
|
|
MtrrGetAllMtrrs (
|
|
|
|
OUT MTRR_SETTINGS *MtrrSetting
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function sets all MTRRs (variable and fixed)
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] MtrrSetting A buffer to hold all MTRRs content.
|
2009-05-27 23:09:39 +02:00
|
|
|
|
|
|
|
@return The pointer of MtrrSetting
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_SETTINGS *
|
|
|
|
EFIAPI
|
|
|
|
MtrrSetAllMtrrs (
|
|
|
|
IN MTRR_SETTINGS *MtrrSetting
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the attribute of variable MTRRs.
|
|
|
|
|
|
|
|
This function shadows the content of variable MTRRs into
|
|
|
|
an internal array: VariableMtrr
|
|
|
|
|
2015-12-08 06:20:44 +01:00
|
|
|
@param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR
|
|
|
|
@param[in] MtrrValidAddressMask The valid address mask for MTRR since the base address in
|
|
|
|
MTRR must align to 4K, so valid address mask equal to
|
|
|
|
MtrrValidBitsMask & 0xfffffffffffff000ULL
|
|
|
|
@param[out] VariableMtrr The array to shadow variable MTRRs content
|
|
|
|
|
2016-10-20 08:53:02 +02:00
|
|
|
@return The return value of this parameter indicates the number of
|
2010-02-05 23:27:07 +01:00
|
|
|
MTRRs which has been used.
|
2009-05-27 23:09:39 +02:00
|
|
|
**/
|
2010-02-05 23:27:07 +01:00
|
|
|
UINT32
|
2009-05-27 23:09:39 +02:00
|
|
|
EFIAPI
|
|
|
|
MtrrGetMemoryAttributeInVariableMtrr (
|
|
|
|
IN UINT64 MtrrValidBitsMask,
|
|
|
|
IN UINT64 MtrrValidAddressMask,
|
|
|
|
OUT VARIABLE_MTRR *VariableMtrr
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function prints all MTRRs for debugging.
|
|
|
|
**/
|
|
|
|
VOID
|
2010-04-17 01:36:53 +02:00
|
|
|
EFIAPI
|
2009-05-27 23:09:39 +02:00
|
|
|
MtrrDebugPrintAllMtrrs (
|
2010-07-13 05:08:54 +02:00
|
|
|
VOID
|
2009-05-27 23:09:39 +02:00
|
|
|
);
|
|
|
|
|
2010-03-10 03:38:39 +01:00
|
|
|
/**
|
|
|
|
Checks if MTRR is supported.
|
|
|
|
|
|
|
|
@retval TRUE MTRR is supported.
|
|
|
|
@retval FALSE MTRR is not supported.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2010-04-17 01:36:53 +02:00
|
|
|
EFIAPI
|
2010-03-10 03:38:39 +01:00
|
|
|
IsMtrrSupported (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2011-10-28 08:01:55 +02:00
|
|
|
/**
|
|
|
|
Returns the default MTRR cache type for the system.
|
|
|
|
|
|
|
|
@return The default MTRR cache type.
|
|
|
|
|
|
|
|
**/
|
|
|
|
MTRR_MEMORY_CACHE_TYPE
|
|
|
|
EFIAPI
|
|
|
|
MtrrGetDefaultMemoryType (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2015-12-08 06:26:26 +01:00
|
|
|
/**
|
|
|
|
This function attempts to set the attributes into MTRR setting buffer for a memory range.
|
|
|
|
|
|
|
|
@param[in, out] MtrrSetting MTRR setting buffer to be set.
|
|
|
|
@param[in] BaseAddress The physical address that is the start address
|
|
|
|
of a memory region.
|
|
|
|
@param[in] Length The size in bytes of the memory region.
|
|
|
|
@param[in] Attribute The bit mask of attributes to set for the
|
|
|
|
memory region.
|
|
|
|
|
|
|
|
@retval RETURN_SUCCESS The attributes were set for the memory region.
|
|
|
|
@retval RETURN_INVALID_PARAMETER Length is zero.
|
|
|
|
@retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the
|
|
|
|
memory resource range specified by BaseAddress and Length.
|
|
|
|
@retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource
|
|
|
|
range specified by BaseAddress and Length.
|
|
|
|
@retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by
|
|
|
|
BaseAddress and Length cannot be modified.
|
|
|
|
@retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
|
|
|
|
the memory resource range.
|
|
|
|
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MtrrSetMemoryAttributeInMtrrSettings (
|
|
|
|
IN OUT MTRR_SETTINGS *MtrrSetting,
|
|
|
|
IN PHYSICAL_ADDRESS BaseAddress,
|
|
|
|
IN UINT64 Length,
|
|
|
|
IN MTRR_MEMORY_CACHE_TYPE Attribute
|
|
|
|
);
|
|
|
|
|
2009-05-27 23:09:39 +02:00
|
|
|
#endif // _MTRR_LIB_H_
|