blob: eaa1870d7a10cc411b582a9633bbe6ff282292e9 [file] [log] [blame]
Stefan Reinauer5c554632012-04-04 00:09:50 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer5c554632012-04-04 00:09:50 +020014 */
15
16#include <stdint.h>
17#include <arch/cpu.h>
18#include <cpu/x86/cache.h>
19#include <cpu/x86/msr.h>
20#include <cpu/x86/mtrr.h>
Duncan Laurie22935e12012-07-09 09:58:35 -070021#include <arch/io.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010022#include <halt.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020023
Stefan Reinauer3f8989e2012-04-25 22:58:23 +020024#include <cpu/intel/microcode/microcode.c>
Duncan Laurie22935e12012-07-09 09:58:35 -070025#include "model_206ax.h"
26
27#if CONFIG_SOUTHBRIDGE_INTEL_BD82X6X || CONFIG_SOUTHBRIDGE_INTEL_C216
28/* Needed for RCBA access to set Soft Reset Data register */
29#include <southbridge/intel/bd82x6x/pch.h>
30#else
31#error "CPU must be paired with Intel BD82X6X or C216 southbridge"
32#endif
Stefan Reinauer5c554632012-04-04 00:09:50 +020033
34static void set_var_mtrr(
35 unsigned reg, unsigned base, unsigned size, unsigned type)
36
37{
38 /* Bit Bit 32-35 of MTRRphysMask should be set to 1 */
39 /* FIXME: It only support 4G less range */
40 msr_t basem, maskm;
41 basem.lo = base | type;
42 basem.hi = 0;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070043 wrmsr(MTRR_PHYS_BASE(reg), basem);
44 maskm.lo = ~(size - 1) | MTRR_PHYS_MASK_VALID;
Stefan Reinauer5c554632012-04-04 00:09:50 +020045 maskm.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070046 wrmsr(MTRR_PHYS_MASK(reg), maskm);
Stefan Reinauer5c554632012-04-04 00:09:50 +020047}
48
49static void enable_rom_caching(void)
50{
51 msr_t msr;
52
53 disable_cache();
Kyösti Mälkkibbf013c2014-01-06 11:08:01 +020054 set_var_mtrr(1, CACHE_ROM_BASE, CACHE_ROM_SIZE, MTRR_TYPE_WRPROT);
Stefan Reinauer5c554632012-04-04 00:09:50 +020055 enable_cache();
56
57 /* Enable Variable MTRRs */
58 msr.hi = 0x00000000;
59 msr.lo = 0x00000800;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070060 wrmsr(MTRR_DEF_TYPE_MSR, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +020061}
62
Duncan Laurie22935e12012-07-09 09:58:35 -070063static void set_flex_ratio_to_tdp_nominal(void)
64{
65 msr_t flex_ratio, msr;
66 u32 soft_reset;
67 u8 nominal_ratio;
68
69 /* Minimum CPU revision for configurable TDP support */
70 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
71 return;
72
73 /* Check for Flex Ratio support */
74 flex_ratio = rdmsr(MSR_FLEX_RATIO);
75 if (!(flex_ratio.lo & FLEX_RATIO_EN))
76 return;
77
78 /* Check for >0 configurable TDPs */
79 msr = rdmsr(MSR_PLATFORM_INFO);
80 if (((msr.hi >> 1) & 3) == 0)
81 return;
82
83 /* Use nominal TDP ratio for flex ratio */
84 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
85 nominal_ratio = msr.lo & 0xff;
86
87 /* See if flex ratio is already set to nominal TDP ratio */
88 if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
89 return;
90
91 /* Set flex ratio to nominal TDP ratio */
92 flex_ratio.lo &= ~0xff00;
93 flex_ratio.lo |= nominal_ratio << 8;
94 flex_ratio.lo |= FLEX_RATIO_LOCK;
95 wrmsr(MSR_FLEX_RATIO, flex_ratio);
96
97 /* Set flex ratio in soft reset data register bits 11:6.
98 * RCBA region is enabled in southbridge bootblock */
99 soft_reset = RCBA32(SOFT_RESET_DATA);
100 soft_reset &= ~(0x3f << 6);
101 soft_reset |= (nominal_ratio & 0x3f) << 6;
102 RCBA32(SOFT_RESET_DATA) = soft_reset;
103
104 /* Set soft reset control to use register value */
105 RCBA32_OR(SOFT_RESET_CTRL, 1);
106
107 /* Issue warm reset, will be "CPU only" due to soft reset data */
108 outb(0x0, 0xcf9);
109 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100110 halt();
Duncan Laurie22935e12012-07-09 09:58:35 -0700111}
112
Stefan Reinauer5c554632012-04-04 00:09:50 +0200113static void bootblock_cpu_init(void)
114{
Duncan Laurie22935e12012-07-09 09:58:35 -0700115 /* Set flex ratio and reset if needed */
116 set_flex_ratio_to_tdp_nominal();
Stefan Reinauer5c554632012-04-04 00:09:50 +0200117 enable_rom_caching();
Vadim Bendebury537b4e02012-06-19 12:56:57 -0700118 intel_update_microcode_from_cbfs();
Stefan Reinauer5c554632012-04-04 00:09:50 +0200119}