blob: d690a57ab66fe6db1da2da143214e1fe960a8856 [file] [log] [blame]
Martin Roth58562402015-10-11 10:36:26 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 coresystems GmbH
5 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
6 * Copyright (C) 2013 Sage Electronic Engineering, LLC.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; version 2 of
11 * the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Martin Roth58562402015-10-11 10:36:26 +020017 */
18
19#include <types.h>
20#include <console/console.h>
21#include <arch/acpi.h>
22#include <arch/acpigen.h>
23#include <arch/cpu.h>
24#include <cpu/x86/msr.h>
25#include <cpu/intel/speedstep.h>
26#include <cpu/intel/turbo.h>
27#include <device/device.h>
28#include <device/pci.h>
29#include "model_406dx.h"
30#include "chip.h"
31
32static int get_cores_per_package(void)
33{
34 struct cpuinfo_x86 c;
35 struct cpuid_result result;
36 int cores = 1;
37
38 get_fms(&c, cpuid_eax(1));
39 if (c.x86 != 6)
40 return 1;
41
42 result = cpuid_ext(0xb, 1);
43 cores = result.ebx & 0xff;
44
45 return cores;
46}
47
48static void generate_C_state_entries(void)
49{
50 struct cpu_info *info;
51 struct cpu_driver *cpu;
52 struct device *lapic;
53 struct cpu_intel_model_406dx_config *conf = NULL;
54
55 /* Find the SpeedStep CPU in the device tree using magic APIC ID */
56 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
57 if (!lapic)
58 return;
59 conf = lapic->chip_info;
60 if (!conf)
61 return;
62
63 /* Find CPU map of supported C-states */
64 info = cpu_info();
65 if (!info)
66 return;
67 cpu = find_cpu_driver(info->cpu);
68 if (!cpu || !cpu->cstates)
69 return;
70
71 acpigen_emit_byte(0x14); /* MethodOp */
72 acpigen_write_len_f(); /* PkgLength */
73 acpigen_emit_namestring("_CST");
74 acpigen_emit_byte(0x00); /* No Arguments */
75
76 /* If running on AC power */
77 acpigen_emit_byte(0xa0); /* IfOp */
78 acpigen_write_len_f(); /* PkgLength */
79 acpigen_emit_namestring("PWRS");
80 acpigen_emit_byte(0xa4); /* ReturnOp */
81 acpigen_pop_len();
82
83 /* Else on battery power */
84 acpigen_emit_byte(0xa4); /* ReturnOp */
85 acpigen_pop_len();
86}
87
88static acpi_tstate_t tss_table_fine[] = {
89 { 100, 1000, 0, 0x00, 0 },
90 { 94, 940, 0, 0x1f, 0 },
91 { 88, 880, 0, 0x1e, 0 },
92 { 82, 820, 0, 0x1d, 0 },
93 { 75, 760, 0, 0x1c, 0 },
94 { 69, 700, 0, 0x1b, 0 },
95 { 63, 640, 0, 0x1a, 0 },
96 { 57, 580, 0, 0x19, 0 },
97 { 50, 520, 0, 0x18, 0 },
98 { 44, 460, 0, 0x17, 0 },
99 { 38, 400, 0, 0x16, 0 },
100 { 32, 340, 0, 0x15, 0 },
101 { 25, 280, 0, 0x14, 0 },
102 { 19, 220, 0, 0x13, 0 },
103 { 13, 160, 0, 0x12, 0 },
104};
105
106static acpi_tstate_t tss_table_coarse[] = {
107 { 100, 1000, 0, 0x00, 0 },
108 { 88, 875, 0, 0x1f, 0 },
109 { 75, 750, 0, 0x1e, 0 },
110 { 63, 625, 0, 0x1d, 0 },
111 { 50, 500, 0, 0x1c, 0 },
112 { 38, 375, 0, 0x1b, 0 },
113 { 25, 250, 0, 0x1a, 0 },
114 { 13, 125, 0, 0x19, 0 },
115};
116
117static void generate_T_state_entries(int core, int cores_per_package)
118{
119 /* Indicate SW_ALL coordination for T-states */
120 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
121
122 /* Indicate FFixedHW so OS will use MSR */
123 acpigen_write_empty_PTC();
124
125 /* Set a T-state limit that can be modified in NVS */
126 acpigen_write_TPC("\\TLVL");
127
128 /*
129 * CPUID.(EAX=6):EAX[5] indicates support
130 * for extended throttle levels.
131 */
132 if (cpuid_eax(6) & (1 << 5))
133 acpigen_write_TSS_package(
134 ARRAY_SIZE(tss_table_fine), tss_table_fine);
135 else
136 acpigen_write_TSS_package(
137 ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
138}
139
140static int calculate_power(int tdp, int p1_ratio, int ratio)
141{
142 u32 m;
143 u32 power;
144
145 /*
146 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
147 *
148 * Power = (ratio / p1_ratio) * m * tdp
149 */
150
151 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
152 m = (m * m) / 1000;
153
154 power = ((ratio * 100000 / p1_ratio) / 100);
155 power *= (m / 100) * (tdp / 1000);
156 power /= 1000;
157
158 return (int)power;
159}
160
161static void generate_P_state_entries(int core, int cores_per_package)
162{
163 int ratio_min, ratio_max, ratio_turbo, ratio_step;
164 int coord_type, power_max, num_entries;
165 int ratio, power, clock, clock_max;
166 msr_t msr;
167
168 /* Rangeley uses hardware only control */
169 coord_type = HW_ALL;
170
171 /* Get bus ratio limits and calculate clock speeds */
172 msr = rdmsr(MSR_PLATFORM_INFO);
173 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
174
175 /* Determine if this CPU has configurable TDP */
176 if (cpu_config_tdp_levels()) {
177 /* Set max ratio to nominal TDP ratio */
178 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
179 ratio_max = msr.lo & 0xff;
180 } else {
181 /* Max Non-Turbo Ratio */
182 ratio_max = (msr.lo >> 8) & 0xff;
183 }
184 clock_max = ratio_max * RANGELEY_BCLK;
185
186 /* Calculate CPU TDP in mW */
187 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
188 power_max = 2 << ((msr.lo & 0xf) - 1);
189
190
191 /* Write _PCT indicating use of FFixedHW */
192 acpigen_write_empty_PCT();
193
194 /* Write _PPC with no limit on supported P-state */
195 acpigen_write_PPC_NVS();
196
197 /* Write PSD indicating configured coordination type */
198 acpigen_write_PSD_package(core, cores_per_package, coord_type);
199
200 /* Add P-state entries in _PSS table */
201 acpigen_write_name("_PSS");
202
203 /* Determine ratio points */
204 ratio_step = PSS_RATIO_STEP;
205 num_entries = (ratio_max - ratio_min) / ratio_step;
206 while (num_entries > PSS_MAX_ENTRIES-1) {
207 ratio_step <<= 1;
208 num_entries >>= 1;
209 }
210
211 /* P[T] is Turbo state if enabled */
212 if (get_turbo_state() == TURBO_ENABLED) {
213 /* _PSS package count including Turbo */
214 acpigen_write_package(num_entries + 2);
215
216 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
217 ratio_turbo = msr.lo & 0xff;
218
219 /* Add entry for Turbo ratio */
220 acpigen_write_PSS_package(
221 clock_max + 1, /*MHz*/
222 power_max, /*mW*/
223 PSS_LATENCY_TRANSITION, /*lat1*/
224 PSS_LATENCY_BUSMASTER, /*lat2*/
225 ratio_turbo << 8, /*control*/
226 ratio_turbo << 8); /*status*/
227 } else {
228 /* _PSS package count without Turbo */
229 acpigen_write_package(num_entries + 1);
230 }
231
232 /* First regular entry is max non-turbo ratio */
233 acpigen_write_PSS_package(
234 clock_max, /*MHz*/
235 power_max, /*mW*/
236 PSS_LATENCY_TRANSITION, /*lat1*/
237 PSS_LATENCY_BUSMASTER, /*lat2*/
238 ratio_max << 8, /*control*/
239 ratio_max << 8); /*status*/
240
241 /* Generate the remaining entries */
242 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
243 ratio >= ratio_min; ratio -= ratio_step) {
244
245 /* Calculate power at this ratio */
246 power = calculate_power(power_max, ratio_max, ratio);
247 clock = ratio * RANGELEY_BCLK;
248
249 acpigen_write_PSS_package(
250 clock, /*MHz*/
251 power, /*mW*/
252 PSS_LATENCY_TRANSITION, /*lat1*/
253 PSS_LATENCY_BUSMASTER, /*lat2*/
254 ratio << 8, /*control*/
255 ratio << 8); /*status*/
256 }
257
258 /* Fix package length */
259 acpigen_pop_len();
260}
261
262void generate_cpu_entries(device_t device)
263{
264 int coreID, cpuID, pcontrol_blk = PMB0_BASE, plen = 6;
265 int totalcores = dev_count_cpu();
266 int cores_per_package = get_cores_per_package();
267 int numcpus = totalcores/cores_per_package;
268
269 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
270 numcpus, cores_per_package);
271
272 for (cpuID = 1; cpuID <= numcpus; cpuID++) {
273 for (coreID=1; coreID<=cores_per_package; coreID++) {
274 if (coreID>1) {
275 pcontrol_blk = 0;
276 plen = 0;
277 }
278
279 /* Generate processor \_PR.CPUx */
280 acpigen_write_processor(
281 (cpuID-1)*cores_per_package+coreID-1,
282 pcontrol_blk, plen);
283
284 /* Generate P-state tables */
285 generate_P_state_entries(
286 cpuID-1, cores_per_package);
287
288 /* Generate C-state tables */
289 generate_C_state_entries();
290
291 /* Generate T-state tables */
292 generate_T_state_entries(
293 cpuID-1, cores_per_package);
294
295 acpigen_pop_len();
296 }
297 }
298}
299
300struct chip_operations cpu_intel_model_406dx_ops = {
301 CHIP_NAME("Intel Rangeley CPU")
302};