UefiCpuPkg/RegisterCpuFeaturesLib: Add "Test Then Write" Macros.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2040 Add below new micros which test the current value before write the new value. Only write new value when current value not same as new value. CPU_REGISTER_TABLE_TEST_THEN_WRITE32 CPU_REGISTER_TABLE_TEST_THEN_WRITE64 CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD Also add below API: CpuRegisterTableTestThenWrite Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Cc: Star Zeng <star.zeng@intel.com>
This commit is contained in:
@@ -348,6 +348,32 @@ CpuRegisterTableWrite (
|
||||
IN UINT64 Value
|
||||
);
|
||||
|
||||
/**
|
||||
Adds an entry in specified register table.
|
||||
|
||||
This function adds an entry in specified register table, with given register type,
|
||||
register index, bit section and value.
|
||||
|
||||
Driver will test the current value before setting new value.
|
||||
|
||||
@param[in] ProcessorNumber The index of the CPU to add a register table entry
|
||||
@param[in] RegisterType Type of the register to program
|
||||
@param[in] Index Index of the register to program
|
||||
@param[in] ValueMask Mask of bits in register to write
|
||||
@param[in] Value Value to write
|
||||
|
||||
@note This service could be called by BSP only.
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
CpuRegisterTableTestThenWrite (
|
||||
IN UINTN ProcessorNumber,
|
||||
IN REGISTER_TYPE RegisterType,
|
||||
IN UINT64 Index,
|
||||
IN UINT64 ValueMask,
|
||||
IN UINT64 Value
|
||||
);
|
||||
|
||||
/**
|
||||
Adds an entry in specified Pre-SMM register table.
|
||||
|
||||
@@ -390,6 +416,26 @@ PreSmmCpuRegisterTableWrite (
|
||||
CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a 32-bit register write entry in specified register table.
|
||||
|
||||
This macro adds an entry in specified register table, with given register type,
|
||||
register index, and value.
|
||||
|
||||
Driver will test the current value before setting new value.
|
||||
|
||||
@param[in] ProcessorNumber The index of the CPU to add a register table entry.
|
||||
@param[in] RegisterType Type of the register to program
|
||||
@param[in] Index Index of the register to program
|
||||
@param[in] Value Value to write
|
||||
|
||||
@note This service could be called by BSP only.
|
||||
**/
|
||||
#define CPU_REGISTER_TABLE_TEST_THEN_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
|
||||
do { \
|
||||
CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a 64-bit register write entry in specified register table.
|
||||
|
||||
@@ -408,6 +454,26 @@ PreSmmCpuRegisterTableWrite (
|
||||
CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a 64-bit register write entry in specified register table.
|
||||
|
||||
This macro adds an entry in specified register table, with given register type,
|
||||
register index, and value.
|
||||
|
||||
Driver will test the current value before setting new value.
|
||||
|
||||
@param[in] ProcessorNumber The index of the CPU to add a register table entry.
|
||||
@param[in] RegisterType Type of the register to program
|
||||
@param[in] Index Index of the register to program
|
||||
@param[in] Value Value to write
|
||||
|
||||
@note This service could be called by BSP only.
|
||||
**/
|
||||
#define CPU_REGISTER_TABLE_TEST_THEN_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
|
||||
do { \
|
||||
CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a bit field write entry in specified register table.
|
||||
|
||||
@@ -431,6 +497,31 @@ PreSmmCpuRegisterTableWrite (
|
||||
CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a bit field write entry in specified register table.
|
||||
|
||||
This macro adds an entry in specified register table, with given register type,
|
||||
register index, bit field section, and value.
|
||||
|
||||
Driver will test the current value before setting new value.
|
||||
|
||||
@param[in] ProcessorNumber The index of the CPU to add a register table entry.
|
||||
@param[in] RegisterType Type of the register to program.
|
||||
@param[in] Index Index of the register to program.
|
||||
@param[in] Type The data type name of a register structure.
|
||||
@param[in] Field The bit fiel name in register structure to write.
|
||||
@param[in] Value Value to write to the bit field.
|
||||
|
||||
@note This service could be called by BSP only.
|
||||
**/
|
||||
#define CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
|
||||
do { \
|
||||
UINT64 ValueMask; \
|
||||
ValueMask = MAX_UINT64; \
|
||||
((Type *)(&ValueMask))->Field = 0; \
|
||||
CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
|
||||
} while(FALSE);
|
||||
|
||||
/**
|
||||
Adds a 32-bit register write entry in specified register table.
|
||||
|
||||
|
Reference in New Issue
Block a user