Add support for Intel Sandybridge CPU
[coreboot.git] / src / cpu / intel / model_206ax / finalize.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <cpu/cpu.h>
24 #include <cpu/x86/msr.h>
25 #include "model_206ax.h"
26
27 static void msr_set_bit(unsigned reg, unsigned bit)
28 {
29         msr_t msr = rdmsr(reg);
30
31         if (bit < 32) {
32                 if (msr.lo & (1 << bit))
33                         return;
34                 msr.lo |= 1 << bit;
35         } else {
36                 if (msr.hi & (1 << (bit - 32)))
37                         return;
38                 msr.hi |= 1 << (bit - 32);
39         }
40
41         wrmsr(reg, msr);
42 }
43
44 void intel_model_206ax_finalize_smm(void)
45 {
46         msr_set_bit(IA32_FEATURE_CONTROL, 0);
47         msr_set_bit(MSR_PMG_CST_CONFIG_CONTROL, 15);
48
49         /* Lock AES-NI only if supported */
50         if (cpuid_ecx(1) & (1 << 25))
51                 msr_set_bit(MSR_FEATURE_CONFIG, 0);
52
53         msr_set_bit(MSR_PP0_CURRENT_CONFIG, 31);
54         msr_set_bit(MSR_PP1_CURRENT_CONFIG, 31);
55         msr_set_bit(MSR_PKG_POWER_LIMIT, 63);
56         msr_set_bit(MSR_PP0_POWER_LIMIT, 31);
57         msr_set_bit(MSR_PP1_POWER_LIMIT, 31);
58         msr_set_bit(MSR_MISC_PWR_MGMT, 22);
59         msr_set_bit(MSR_LT_LOCK_MEMORY, 0);
60 }