]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Include/Library/MtrrLib.h
UefiCpuPkg/MtrrLib: Update algorithm to calculate optimal settings
[mirror_edk2.git] / UefiCpuPkg / Include / Library / MtrrLib.h
index a63da4d1f5e92efac9008e920137a0977571c212..d05d8399159f1e48bde3b197ffa9bf92e7f47f70 100644 (file)
 #define  RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER  2\r
 \r
 #define  MTRR_NUMBER_OF_FIXED_MTRR      11\r
-//\r
-// Below macro is deprecated, and should not be used.\r
-//\r
-#define  FIRMWARE_VARIABLE_MTRR_NUMBER  6\r
-#define  MTRR_LIB_IA32_MTRR_CAP                      0x0FE\r
-#define  MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK            0x0FF\r
-#define  MTRR_LIB_IA32_MTRR_FIX64K_00000             0x250\r
-#define  MTRR_LIB_IA32_MTRR_FIX16K_80000             0x258\r
-#define  MTRR_LIB_IA32_MTRR_FIX16K_A0000             0x259\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_C0000              0x268\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_C8000              0x269\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_D0000              0x26A\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_D8000              0x26B\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_E0000              0x26C\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_E8000              0x26D\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_F0000              0x26E\r
-#define  MTRR_LIB_IA32_MTRR_FIX4K_F8000              0x26F\r
-#define  MTRR_LIB_IA32_VARIABLE_MTRR_BASE            0x200\r
-//\r
-// Below macro is deprecated, and should not be used.\r
-//\r
-#define  MTRR_LIB_IA32_VARIABLE_MTRR_END             0x20F\r
-#define  MTRR_LIB_IA32_MTRR_DEF_TYPE                 0x2FF\r
-#define  MTRR_LIB_MSR_VALID_MASK                     0xFFFFFFFFFULL\r
-#define  MTRR_LIB_CACHE_VALID_ADDRESS                0xFFFFFF000ULL\r
-#define  MTRR_LIB_CACHE_MTRR_ENABLED                 0x800\r
-#define  MTRR_LIB_CACHE_FIXED_MTRR_ENABLED           0x400\r
 \r
 //\r
 // Structure to describe a fixed MTRR\r
@@ -130,6 +103,12 @@ typedef enum {
 #define  MTRR_CACHE_WRITE_BACK       6\r
 #define  MTRR_CACHE_INVALID_TYPE     7\r
 \r
+typedef struct {\r
+  UINT64                 BaseAddress;\r
+  UINT64                 Length;\r
+  MTRR_MEMORY_CACHE_TYPE Type;\r
+} MTRR_MEMORY_RANGE;\r
+\r
 /**\r
   Returns the variable MTRR count for the CPU.\r
 \r
@@ -178,7 +157,7 @@ GetFirmwareVariableMtrrCount (
   @retval RETURN_OUT_OF_RESOURCES   There are not enough system resources to\r
                                     modify the attributes of the memory\r
                                     resource range.\r
-\r
+  @retval RETURN_BUFFER_TOO_SMALL   The scratch buffer is too small for MTRR calculation.\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -373,7 +352,7 @@ MtrrGetDefaultMemoryType (
                                     BaseAddress and Length cannot be modified.\r
   @retval RETURN_OUT_OF_RESOURCES   There are not enough system resources to modify the attributes of\r
                                     the memory resource range.\r
-\r
+  @retval RETURN_BUFFER_TOO_SMALL   The scratch buffer is too small for MTRR calculation.\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -384,4 +363,39 @@ MtrrSetMemoryAttributeInMtrrSettings (
   IN MTRR_MEMORY_CACHE_TYPE  Attribute\r
   );\r
 \r
+/**\r
+  This function attempts to set the attributes into MTRR setting buffer for multiple memory ranges.\r
+\r
+  @param[in, out]  MtrrSetting  MTRR setting buffer to be set.\r
+  @param[in]       Scratch      A temporary scratch buffer that is used to perform the calculation.\r
+  @param[in, out]  ScratchSize  Pointer to the size in bytes of the scratch buffer.\r
+                                It may be updated to the actual required size when the calculation\r
+                                needs more scratch buffer.\r
+  @param[in]       Ranges       Pointer to an array of MTRR_MEMORY_RANGE.\r
+                                When range overlap happens, the last one takes higher priority.\r
+                                When the function returns, either all the attributes are set successfully,\r
+                                or none of them is set.\r
+  @param[in]                    Count of MTRR_MEMORY_RANGE.\r
+\r
+  @retval RETURN_SUCCESS            The attributes were set for all the memory ranges.\r
+  @retval RETURN_INVALID_PARAMETER  Length in any range is zero.\r
+  @retval RETURN_UNSUPPORTED        The processor does not support one or more bytes of the\r
+                                    memory resource range specified by BaseAddress and Length in any range.\r
+  @retval RETURN_UNSUPPORTED        The bit mask of attributes is not support for the memory resource\r
+                                    range specified by BaseAddress and Length in any range.\r
+  @retval RETURN_OUT_OF_RESOURCES   There are not enough system resources to modify the attributes of\r
+                                    the memory resource ranges.\r
+  @retval RETURN_ACCESS_DENIED      The attributes for the memory resource range specified by\r
+                                    BaseAddress and Length cannot be modified.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The scratch buffer is too small for MTRR calculation.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+MtrrSetMemoryAttributesInMtrrSettings (\r
+  IN OUT MTRR_SETTINGS           *MtrrSetting,\r
+  IN     VOID                    *Scratch,\r
+  IN OUT UINTN                   *ScratchSize,\r
+  IN     CONST MTRR_MEMORY_RANGE *Ranges,\r
+  IN     UINTN                   RangeCount\r
+  );\r
 #endif // _MTRR_LIB_H_\r