Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 1 | /* |
| 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. |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 14 | */ |
| 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> |
| 21 | #include <arch/io.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 22 | #include <halt.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 23 | |
| 24 | #include <cpu/intel/microcode/microcode.c> |
| 25 | |
Martin Roth | ffdee28 | 2017-06-24 13:43:40 -0600 | [diff] [blame] | 26 | #if IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_IBEXPEAK) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 27 | #include <southbridge/intel/ibexpeak/pch.h> |
| 28 | #include "model_2065x.h" |
| 29 | #else |
Vladimir Serbinenko | fe6bdd9 | 2013-11-19 18:01:03 +0100 | [diff] [blame] | 30 | #error "CPU must be paired with Intel Ibex Peak southbridge" |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 31 | #endif |
| 32 | |
Lee Leahy | 73a2894 | 2017-03-15 17:52:06 -0700 | [diff] [blame] | 33 | static void set_var_mtrr(unsigned int reg, unsigned int base, unsigned int size, |
| 34 | unsigned int type) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 35 | |
| 36 | { |
| 37 | /* Bit Bit 32-35 of MTRRphysMask should be set to 1 */ |
| 38 | /* FIXME: It only support 4G less range */ |
| 39 | msr_t basem, maskm; |
| 40 | basem.lo = base | type; |
| 41 | basem.hi = 0; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 42 | wrmsr(MTRR_PHYS_BASE(reg), basem); |
| 43 | maskm.lo = ~(size - 1) | MTRR_PHYS_MASK_VALID; |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 44 | maskm.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 45 | wrmsr(MTRR_PHYS_MASK(reg), maskm); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void enable_rom_caching(void) |
| 49 | { |
| 50 | msr_t msr; |
| 51 | |
| 52 | disable_cache(); |
Kyösti Mälkki | bbf013c | 2014-01-06 11:08:01 +0200 | [diff] [blame] | 53 | set_var_mtrr(1, CACHE_ROM_BASE, CACHE_ROM_SIZE, MTRR_TYPE_WRPROT); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 54 | enable_cache(); |
| 55 | |
| 56 | /* Enable Variable MTRRs */ |
| 57 | msr.hi = 0x00000000; |
| 58 | msr.lo = 0x00000800; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 59 | wrmsr(MTRR_DEF_TYPE_MSR, msr); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void set_flex_ratio_to_tdp_nominal(void) |
| 63 | { |
| 64 | msr_t flex_ratio, msr; |
| 65 | u32 soft_reset; |
| 66 | u8 nominal_ratio; |
| 67 | |
| 68 | /* Minimum CPU revision for configurable TDP support */ |
| 69 | if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID) |
| 70 | return; |
| 71 | |
| 72 | /* Check for Flex Ratio support */ |
| 73 | flex_ratio = rdmsr(MSR_FLEX_RATIO); |
| 74 | if (!(flex_ratio.lo & FLEX_RATIO_EN)) |
| 75 | return; |
| 76 | |
| 77 | /* Check for >0 configurable TDPs */ |
| 78 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 79 | if (((msr.hi >> 1) & 3) == 0) |
| 80 | return; |
| 81 | |
| 82 | /* Use nominal TDP ratio for flex ratio */ |
| 83 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 84 | nominal_ratio = msr.lo & 0xff; |
| 85 | |
| 86 | /* See if flex ratio is already set to nominal TDP ratio */ |
| 87 | if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio) |
| 88 | return; |
| 89 | |
| 90 | /* Set flex ratio to nominal TDP ratio */ |
| 91 | flex_ratio.lo &= ~0xff00; |
| 92 | flex_ratio.lo |= nominal_ratio << 8; |
| 93 | flex_ratio.lo |= FLEX_RATIO_LOCK; |
| 94 | wrmsr(MSR_FLEX_RATIO, flex_ratio); |
| 95 | |
| 96 | /* Set flex ratio in soft reset data register bits 11:6. |
| 97 | * RCBA region is enabled in southbridge bootblock */ |
| 98 | soft_reset = RCBA32(SOFT_RESET_DATA); |
| 99 | soft_reset &= ~(0x3f << 6); |
| 100 | soft_reset |= (nominal_ratio & 0x3f) << 6; |
| 101 | RCBA32(SOFT_RESET_DATA) = soft_reset; |
| 102 | |
| 103 | /* Set soft reset control to use register value */ |
| 104 | RCBA32_OR(SOFT_RESET_CTRL, 1); |
| 105 | |
| 106 | /* Issue warm reset, will be "CPU only" due to soft reset data */ |
| 107 | outb(0x0, 0xcf9); |
| 108 | outb(0x6, 0xcf9); |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 109 | halt(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void bootblock_cpu_init(void) |
| 113 | { |
| 114 | /* Set flex ratio and reset if needed */ |
| 115 | set_flex_ratio_to_tdp_nominal(); |
| 116 | enable_rom_caching(); |
| 117 | intel_update_microcode_from_cbfs(); |
| 118 | } |