blob: 742b2ef7946effecbc9829ae40a43bb725f3ee16 [file] [log] [blame]
Martin Roth433659a2014-05-12 21:55:00 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 * Copyright (C) 2014 Sage Electronic Engineering, LLC.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of 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.
Martin Roth433659a2014-05-12 21:55:00 -060015 */
16
17#include <stdlib.h>
18#include <console/console.h>
19#include <cpu/cpu.h>
20#include <cpu/intel/microcode.h>
21#include <cpu/intel/turbo.h>
22#include <cpu/x86/cache.h>
23#include <cpu/x86/lapic.h>
24#include <cpu/x86/mp.h>
25#include <cpu/x86/msr.h>
26#include <cpu/x86/mtrr.h>
27#include <cpu/x86/smm.h>
28#include <reg_script.h>
29
Ben Gardnerfa6014a2015-12-08 21:20:25 -060030#include <soc/msr.h>
31#include <soc/pattrs.h>
32#include <soc/ramstage.h>
Ben Gardnerfa6014a2015-12-08 21:20:25 -060033#include <soc/smm.h>
Martin Roth433659a2014-05-12 21:55:00 -060034
Martin Roth433659a2014-05-12 21:55:00 -060035/* Core level MSRs */
Aaron Durbin2a07a4d2016-05-03 11:31:32 -050036static const struct reg_script core_msr_script[] = {
Martin Roth433659a2014-05-12 21:55:00 -060037 /* Dynamic L2 shrink enable and threshold */
38 REG_MSR_RMW(MSR_PMG_CST_CONFIG_CONTROL, ~0x3f000f, 0xe0008),
39 /* Disable C1E */
40 REG_MSR_RMW(MSR_POWER_CTL, ~0x2, 0),
41 REG_MSR_OR(MSR_POWER_MISC, 0x44),
42 REG_SCRIPT_END
43};
44
Martin Roth433659a2014-05-12 21:55:00 -060045static void baytrail_core_init(device_t cpu)
46{
47 printk(BIOS_DEBUG, "Init BayTrail core.\n");
48
49 /* On bay trail the turbo disable bit is actually scoped at building
50 * block level -- not package. For non-bsp cores that are within a
51 * building block enable turbo. The cores within the BSP's building
52 * block will just see it already enabled and move on. */
53 if (lapicid())
54 enable_turbo();
55
56 /* Set core MSRs */
57 reg_script_run(core_msr_script);
58
59 /* Set this core to max frequency ratio */
60 set_max_freq();
61}
62
63static struct device_operations cpu_dev_ops = {
64 .init = baytrail_core_init,
65};
66
67static struct cpu_device_id cpu_table[] = {
68 { X86_VENDOR_INTEL, 0x30671 },
69 { X86_VENDOR_INTEL, 0x30672 },
70 { X86_VENDOR_INTEL, 0x30673 },
71 { X86_VENDOR_INTEL, 0x30678 },
Herve ELterc7e6cae2014-11-19 16:05:28 +010072 { X86_VENDOR_INTEL, 0x30679 },
Martin Roth433659a2014-05-12 21:55:00 -060073 { 0, 0 },
74};
75
76static const struct cpu_driver driver __cpu_driver = {
77 .ops = &cpu_dev_ops,
78 .id_table = cpu_table,
79};
80
Martin Roth433659a2014-05-12 21:55:00 -060081/*
Aaron Durbin2a07a4d2016-05-03 11:31:32 -050082 * MP and SMM loading initialization.
Martin Roth433659a2014-05-12 21:55:00 -060083 */
84
85struct smm_relocation_attrs {
86 uint32_t smbase;
87 uint32_t smrr_base;
88 uint32_t smrr_mask;
89};
90
91static struct smm_relocation_attrs relo_attrs;
92
Aaron Durbin2a07a4d2016-05-03 11:31:32 -050093static void pre_mp_init(void)
Martin Roth433659a2014-05-12 21:55:00 -060094{
Aaron Durbin2a07a4d2016-05-03 11:31:32 -050095 x86_mtrr_check();
Martin Roth433659a2014-05-12 21:55:00 -060096
Elyes HAOUAS038e7242016-07-29 18:31:16 +020097 /* Enable the local CPU apics */
Aaron Durbin2a07a4d2016-05-03 11:31:32 -050098 setup_lapic();
Martin Roth433659a2014-05-12 21:55:00 -060099}
100
Aaron Durbin2a07a4d2016-05-03 11:31:32 -0500101static int get_cpu_count(void)
102{
103 const struct pattrs *pattrs = pattrs_get();
104
105 return pattrs->num_cpus;
106}
107
108static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize,
109 size_t *smm_save_state_size)
110{
111 /* All range registers are aligned to 4KiB */
112 const uint32_t rmask = ~((1 << 12) - 1);
113
114 /* Initialize global tracking state. */
115 relo_attrs.smbase = (uint32_t)smm_region_start();
116 relo_attrs.smrr_base = relo_attrs.smbase | MTRR_TYPE_WRBACK;
117 relo_attrs.smrr_mask = ~(smm_region_size() - 1) & rmask;
118 relo_attrs.smrr_mask |= MTRR_PHYS_MASK_VALID;
119
120 *perm_smbase = relo_attrs.smbase;
121 *perm_smsize = smm_region_size() - CONFIG_SMM_RESERVED_SIZE;
122 *smm_save_state_size = sizeof(em64t100_smm_state_save_area_t);
123}
124
125/* The APIC id space on Bay Trail is sparse. Each id is separated by 2. */
126static int adjust_apic_id(int index, int apic_id)
127{
128 return 2 * index;
129}
130
131static void get_microcode_info(const void **microcode, int *parallel)
132{
133 const struct pattrs *pattrs = pattrs_get();
134
135 *microcode = pattrs->microcode_patch;
136 *parallel = 1;
137}
138
139static void relocation_handler(int cpu, uintptr_t curr_smbase,
140 uintptr_t staggered_smbase)
Martin Roth433659a2014-05-12 21:55:00 -0600141{
Martin Roth433659a2014-05-12 21:55:00 -0600142 msr_t smrr;
143 em64t100_smm_state_save_area_t *smm_state;
Martin Roth433659a2014-05-12 21:55:00 -0600144
145 /* Set up SMRR. */
146 smrr.lo = relo_attrs.smrr_base;
147 smrr.hi = 0;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700148 wrmsr(SMRR_PHYS_BASE, smrr);
Martin Roth433659a2014-05-12 21:55:00 -0600149 smrr.lo = relo_attrs.smrr_mask;
150 smrr.hi = 0;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700151 wrmsr(SMRR_PHYS_MASK, smrr);
Martin Roth433659a2014-05-12 21:55:00 -0600152
Aaron Durbin2a07a4d2016-05-03 11:31:32 -0500153 smm_state = (void *)(SMM_EM64T100_SAVE_STATE_OFFSET + curr_smbase);
154 smm_state->smbase = staggered_smbase;
Martin Roth433659a2014-05-12 21:55:00 -0600155}
156
Aaron Durbin0e556322016-04-29 23:15:12 -0500157static void enable_smis(void)
Martin Roth433659a2014-05-12 21:55:00 -0600158{
Aaron Durbin2a07a4d2016-05-03 11:31:32 -0500159 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER))
160 southcluster_smm_enable_smi();
Martin Roth433659a2014-05-12 21:55:00 -0600161}
Aaron Durbin2a07a4d2016-05-03 11:31:32 -0500162
163static const struct mp_ops mp_ops = {
164 .pre_mp_init = pre_mp_init,
165 .get_cpu_count = get_cpu_count,
166 .get_smm_info = get_smm_info,
167 .get_microcode_info = get_microcode_info,
168 .adjust_cpu_apic_entry = adjust_apic_id,
169 .pre_mp_smm_init = southcluster_smm_clear_state,
170 .relocation_handler = relocation_handler,
171 .post_mp_init = enable_smis,
172};
173
174void baytrail_init_cpus(device_t dev)
175{
176 struct bus *cpu_bus = dev->link_list;
177
178 if (mp_init_with_smm(cpu_bus, &mp_ops)) {
179 printk(BIOS_ERR, "MP initialization failure.\n");
180 }
181}