cpu/intel/common: rework code previously moved to common cpu code

Rework the code moved to common code in CB:46274. This involves
simplification by using appropriate helpers for MSR and CPUID, using
macros instead of plain values for MSRs and cpu features and adding
documentation to the header.

Change-Id: I7615fc26625c44931577216ea42f0a733b99e131
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46588
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Michael Niewöhner 2020-10-20 14:27:09 +02:00 committed by Nico Huber
parent 10ae1cf2cd
commit 062b92ef65
4 changed files with 18 additions and 28 deletions

View File

@ -33,10 +33,16 @@ bool intel_ht_sibling(void);
*/ */
void set_aesni_lock(void); void set_aesni_lock(void);
/* Enable local CPU APIC TPR (Task Priority Register) updates */
void enable_lapic_tpr(void); void enable_lapic_tpr(void);
/* Enable DCA (Direct Cache Access) */
void configure_dca_cap(void); void configure_dca_cap(void);
/*
* Set EPB (Energy Performance Bias)
* Possible values are 0 (performance) to 15 (powersave).
*/
void set_energy_perf_bias(u8 policy); void set_energy_perf_bias(u8 policy);
#endif #endif

View File

@ -8,6 +8,8 @@
#include <cpu/x86/msr.h> #include <cpu/x86/msr.h>
#include "common.h" #include "common.h"
#define CPUID_6_ECX_EPB (1 << 3)
void set_vmx_and_lock(void) void set_vmx_and_lock(void)
{ {
set_feature_ctrl_vmx(); set_feature_ctrl_vmx();
@ -290,42 +292,22 @@ void set_aesni_lock(void)
void enable_lapic_tpr(void) void enable_lapic_tpr(void)
{ {
msr_t msr; msr_unset(MSR_PIC_MSG_CONTROL, TPR_UPDATES_DISABLE);
msr = rdmsr(MSR_PIC_MSG_CONTROL);
msr.lo &= ~(1 << 10); /* Enable APIC TPR updates */
wrmsr(MSR_PIC_MSG_CONTROL, msr);
} }
void configure_dca_cap(void) void configure_dca_cap(void)
{ {
uint32_t feature_flag; if (cpu_get_feature_flags_ecx() & CPUID_DCA)
msr_t msr; msr_set(IA32_PLATFORM_DCA_CAP, DCA_TYPE0_EN);
/* Check feature flag in CPUID.(EAX=1):ECX[18]==1 */
feature_flag = cpu_get_feature_flags_ecx();
if (feature_flag & CPUID_DCA) {
msr = rdmsr(IA32_PLATFORM_DCA_CAP);
msr.lo |= 1;
wrmsr(IA32_PLATFORM_DCA_CAP, msr);
}
} }
void set_energy_perf_bias(u8 policy) void set_energy_perf_bias(u8 policy)
{ {
msr_t msr; u8 epb = policy & ENERGY_POLICY_MASK;
int ecx;
/* Determine if energy efficient policy is supported. */ if (!(cpuid_ecx(6) & CPUID_6_ECX_EPB))
ecx = cpuid_ecx(0x6);
if (!(ecx & (1 << 3)))
return; return;
/* Energy Policy is bits 3:0 */ msr_unset_and_set(IA32_ENERGY_PERF_BIAS, ENERGY_POLICY_MASK, epb);
msr = rdmsr(IA32_ENERGY_PERF_BIAS); printk(BIOS_DEBUG, "cpu: energy policy set to %u\n", epb);
msr.lo &= ~0xf;
msr.lo |= policy & 0xf;
wrmsr(IA32_ENERGY_PERF_BIAS, msr);
printk(BIOS_DEBUG, "cpu: energy policy set to %u\n", policy);
} }

View File

@ -10,5 +10,6 @@
#define AESNI_LOCK (1 << 0) #define AESNI_LOCK (1 << 0)
#define MSR_PIC_MSG_CONTROL 0x2e #define MSR_PIC_MSG_CONTROL 0x2e
#define TPR_UPDATES_DISABLE (1 << 10)
#endif /* CPU_INTEL_MSR_H */ #endif /* CPU_INTEL_MSR_H */

View File

@ -48,11 +48,12 @@
#define ENERGY_POLICY_PERFORMANCE 0 #define ENERGY_POLICY_PERFORMANCE 0
#define ENERGY_POLICY_NORMAL 6 #define ENERGY_POLICY_NORMAL 6
#define ENERGY_POLICY_POWERSAVE 15 #define ENERGY_POLICY_POWERSAVE 15
#define ENERGY_POLICY_MASK 0xf
#define IA32_PACKAGE_THERM_INTERRUPT 0x1b2 #define IA32_PACKAGE_THERM_INTERRUPT 0x1b2
#define IA32_PLATFORM_DCA_CAP 0x1f8
#define SMRR_PHYSBASE_MSR 0x1F2 #define SMRR_PHYSBASE_MSR 0x1F2
#define SMRR_PHYSMASK_MSR 0x1F3 #define SMRR_PHYSMASK_MSR 0x1F3
#define IA32_PLATFORM_DCA_CAP 0x1f8 #define IA32_PLATFORM_DCA_CAP 0x1f8
#define DCA_TYPE0_EN (1 << 0)
#define IA32_PAT 0x277 #define IA32_PAT 0x277
#define IA32_MC0_CTL 0x400 #define IA32_MC0_CTL 0x400
#define IA32_MC0_STATUS 0x401 #define IA32_MC0_STATUS 0x401