audk/UefiCpuPkg/Include/Library
Ruiyu Ni 2bbd7e2fbd UefiCpuPkg/MtrrLib: Update algorithm to calculate optimal settings
The new algorithm converts the problem calculating optimal
MTRR settings (using least MTRR registers) to the problem finding
the shortest path in a graph.
The memory required in extreme but rare case can be up to 256KB,
so using local stack buffer is impossible considering current
DxeIpl only allocates 128KB stack.

The patch changes existing MtrrSetMemoryAttributeInMtrrSettings() and
MtrrSetMemoryAttribute() to use the 4-page stack buffer for
calculation. The two APIs return BUFFER_TOO_SMALL when the buffer
is too small for calculation.

The patch adds a new API MtrrSetMemoryAttribute*s*InMtrrSettings() to
set multiple-range attributes in one function call.
Since every call to MtrrSetMemoryAttributeInMtrrSettings (without-s)
or MtrrSetMemoryAttribute() requires to calculate the MTRRs for the
whole physical memory, combining multiple calls in one API can
significantly reduce the calculation time.
In theory, if N times of call to without-s API costs N seconds,
the new API only costs 1 second.
The new API uses the buffer supplied from caller to calculate
MTRRs and returns BUFFER_TOO_SMALL when the buffer is too small for
calculation.

Test performed:
1. Random test
 a. Generate random memory settings, use the new algorithm to
    calculate the MTRRs.
 b. Read back the MTRRs and check the memory settings match
    the desired memory settings.
 c. Repeat the above #1 and #2 100000 times.
2. OVMF 32PEI + 64DXE boot to shell.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-10-16 13:09:46 +08:00
..
LocalApicLib.h UefiCpuPkg/LocalApicLib: Add EFIAPI for GetProcessorLocationByApicId() 2016-11-02 09:17:04 +08:00
MicrocodeFlashAccessLib.h UefiCpuPkg/Include: Add MicrocodeFlashAccessLib header. 2016-11-08 22:43:16 +08:00
MpInitLib.h UefiCpuPkg: Make the comments align with the functions 2016-12-14 21:34:42 +08:00
MtrrLib.h UefiCpuPkg/MtrrLib: Update algorithm to calculate optimal settings 2017-10-16 13:09:46 +08:00
PlatformSecLib.h UefiCpuPkg: Add PlatformSecLib 2015-10-19 19:09:56 +00:00
RegisterCpuFeaturesLib.h UefiCpuPkg: Add Processor Trace feature definition. 2017-08-04 12:26:44 +08:00
SmmCpuFeaturesLib.h UefiCpuPkg/PiSmmCpu: Add 2 APIs in SmmCpuFeaturesLib. 2015-11-27 13:48:03 +00:00
SmmCpuPlatformHookLib.h UefiCpuPkg: Add SmmCpuPlatformHookLib 2015-10-19 19:11:15 +00:00
UefiCpuLib.h Update the copyright notice format 2010-04-24 12:25:26 +00:00