2013-06-06 22:10:45 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
|
|
|
* Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <arch/acpi.h>
|
|
|
|
#include <arch/acpigen.h>
|
|
|
|
#include <arch/cpu.h>
|
|
|
|
#include <cpu/x86/msr.h>
|
|
|
|
#include <cpu/intel/speedstep.h>
|
|
|
|
#include <cpu/intel/turbo.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include "model_2065x.h"
|
|
|
|
#include "chip.h"
|
|
|
|
|
|
|
|
static int get_cores_per_package(void)
|
|
|
|
{
|
|
|
|
struct cpuinfo_x86 c;
|
|
|
|
struct cpuid_result result;
|
|
|
|
int cores = 1;
|
|
|
|
|
|
|
|
get_fms(&c, cpuid_eax(1));
|
|
|
|
if (c.x86 != 6)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
result = cpuid_ext(0xb, 1);
|
|
|
|
cores = result.ebx & 0xff;
|
|
|
|
|
|
|
|
return cores;
|
|
|
|
}
|
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
static void generate_cstate_entries(acpi_cstate_t *cstates,
|
2013-06-06 22:10:45 +02:00
|
|
|
int c1, int c2, int c3)
|
|
|
|
{
|
2014-11-04 21:09:23 +01:00
|
|
|
int cstate_count = 0;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Count number of active C-states */
|
|
|
|
if (c1 > 0)
|
|
|
|
++cstate_count;
|
|
|
|
if (c2 > 0)
|
|
|
|
++cstate_count;
|
|
|
|
if (c3 > 0)
|
|
|
|
++cstate_count;
|
|
|
|
if (!cstate_count)
|
2014-11-04 21:09:23 +01:00
|
|
|
return;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_package(cstate_count + 1);
|
|
|
|
acpigen_write_byte(cstate_count);
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Add an entry if the level is enabled */
|
|
|
|
if (c1 > 0) {
|
|
|
|
cstates[c1].ctype = 1;
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_CST_package_entry(&cstates[c1]);
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
if (c2 > 0) {
|
|
|
|
cstates[c2].ctype = 2;
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_CST_package_entry(&cstates[c2]);
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
if (c3 > 0) {
|
|
|
|
cstates[c3].ctype = 3;
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_CST_package_entry(&cstates[c3]);
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_pop_len();
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
static void generate_C_state_entries(void)
|
2013-06-06 22:10:45 +02:00
|
|
|
{
|
|
|
|
struct cpu_info *info;
|
|
|
|
struct cpu_driver *cpu;
|
2014-10-27 13:29:29 +01:00
|
|
|
struct device *lapic;
|
2013-06-06 22:10:45 +02:00
|
|
|
struct cpu_intel_model_2065x_config *conf = NULL;
|
|
|
|
|
|
|
|
/* Find the SpeedStep CPU in the device tree using magic APIC ID */
|
|
|
|
lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
|
|
|
|
if (!lapic)
|
2014-11-04 21:09:23 +01:00
|
|
|
return;
|
2013-06-06 22:10:45 +02:00
|
|
|
conf = lapic->chip_info;
|
|
|
|
if (!conf)
|
2014-11-04 21:09:23 +01:00
|
|
|
return;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Find CPU map of supported C-states */
|
|
|
|
info = cpu_info();
|
|
|
|
if (!info)
|
2014-11-04 21:09:23 +01:00
|
|
|
return;
|
2013-06-06 22:10:45 +02:00
|
|
|
cpu = find_cpu_driver(info->cpu);
|
|
|
|
if (!cpu || !cpu->cstates)
|
2014-11-04 21:09:23 +01:00
|
|
|
return;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
2014-11-05 10:28:28 +01:00
|
|
|
acpigen_write_method("_CST", 0);
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* If running on AC power */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_emit_byte(0xa0); /* IfOp */
|
|
|
|
acpigen_write_len_f(); /* PkgLength */
|
|
|
|
acpigen_emit_namestring("PWRS");
|
|
|
|
acpigen_emit_byte(0xa4); /* ReturnOp */
|
|
|
|
generate_cstate_entries(cpu->cstates, conf->c1_acpower,
|
|
|
|
conf->c2_acpower, conf->c3_acpower);
|
|
|
|
acpigen_pop_len();
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Else on battery power */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_emit_byte(0xa4); /* ReturnOp */
|
|
|
|
generate_cstate_entries(cpu->cstates, conf->c1_battery,
|
|
|
|
conf->c2_battery, conf->c3_battery);
|
|
|
|
acpigen_pop_len();
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static acpi_tstate_t tss_table_fine[] = {
|
|
|
|
{ 100, 1000, 0, 0x00, 0 },
|
|
|
|
{ 94, 940, 0, 0x1f, 0 },
|
|
|
|
{ 88, 880, 0, 0x1e, 0 },
|
|
|
|
{ 82, 820, 0, 0x1d, 0 },
|
|
|
|
{ 75, 760, 0, 0x1c, 0 },
|
|
|
|
{ 69, 700, 0, 0x1b, 0 },
|
|
|
|
{ 63, 640, 0, 0x1a, 0 },
|
|
|
|
{ 57, 580, 0, 0x19, 0 },
|
|
|
|
{ 50, 520, 0, 0x18, 0 },
|
|
|
|
{ 44, 460, 0, 0x17, 0 },
|
|
|
|
{ 38, 400, 0, 0x16, 0 },
|
|
|
|
{ 32, 340, 0, 0x15, 0 },
|
|
|
|
{ 25, 280, 0, 0x14, 0 },
|
|
|
|
{ 19, 220, 0, 0x13, 0 },
|
|
|
|
{ 13, 160, 0, 0x12, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static acpi_tstate_t tss_table_coarse[] = {
|
|
|
|
{ 100, 1000, 0, 0x00, 0 },
|
|
|
|
{ 88, 875, 0, 0x1f, 0 },
|
|
|
|
{ 75, 750, 0, 0x1e, 0 },
|
|
|
|
{ 63, 625, 0, 0x1d, 0 },
|
|
|
|
{ 50, 500, 0, 0x1c, 0 },
|
|
|
|
{ 38, 375, 0, 0x1b, 0 },
|
|
|
|
{ 25, 250, 0, 0x1a, 0 },
|
|
|
|
{ 13, 125, 0, 0x19, 0 },
|
|
|
|
};
|
|
|
|
|
2014-11-09 03:51:32 +01:00
|
|
|
static void generate_T_state_entries(int core, int cores_per_package)
|
2013-06-06 22:10:45 +02:00
|
|
|
{
|
|
|
|
/* Indicate SW_ALL coordination for T-states */
|
2014-11-09 03:51:32 +01:00
|
|
|
acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Indicate FFixedHW so OS will use MSR */
|
2014-11-09 03:51:32 +01:00
|
|
|
acpigen_write_empty_PTC();
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Set a T-state limit that can be modified in NVS */
|
2014-11-09 03:51:32 +01:00
|
|
|
acpigen_write_TPC("\\TLVL");
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CPUID.(EAX=6):EAX[5] indicates support
|
|
|
|
* for extended throttle levels.
|
|
|
|
*/
|
|
|
|
if (cpuid_eax(6) & (1 << 5))
|
2014-11-09 03:51:32 +01:00
|
|
|
acpigen_write_TSS_package(
|
2013-06-06 22:10:45 +02:00
|
|
|
ARRAY_SIZE(tss_table_fine), tss_table_fine);
|
|
|
|
else
|
2014-11-09 03:51:32 +01:00
|
|
|
acpigen_write_TSS_package(
|
2013-06-06 22:10:45 +02:00
|
|
|
ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int calculate_power(int tdp, int p1_ratio, int ratio)
|
|
|
|
{
|
|
|
|
u32 m;
|
|
|
|
u32 power;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
|
|
|
|
*
|
|
|
|
* Power = (ratio / p1_ratio) * m * tdp
|
|
|
|
*/
|
|
|
|
|
|
|
|
m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
|
|
|
|
m = (m * m) / 1000;
|
|
|
|
|
|
|
|
power = ((ratio * 100000 / p1_ratio) / 100);
|
|
|
|
power *= (m / 100) * (tdp / 1000);
|
|
|
|
power /= 1000;
|
|
|
|
|
|
|
|
return (int)power;
|
|
|
|
}
|
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
static void generate_P_state_entries(int core, int cores_per_package)
|
2013-06-06 22:10:45 +02:00
|
|
|
{
|
|
|
|
int ratio_min, ratio_max, ratio_turbo, ratio_step;
|
|
|
|
int coord_type, power_max, num_entries;
|
|
|
|
int ratio, power, clock, clock_max;
|
|
|
|
msr_t msr;
|
|
|
|
|
|
|
|
/* Determine P-state coordination type from MISC_PWR_MGMT[0] */
|
|
|
|
msr = rdmsr(MSR_MISC_PWR_MGMT);
|
|
|
|
if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
|
|
|
|
coord_type = SW_ANY;
|
|
|
|
else
|
|
|
|
coord_type = HW_ALL;
|
|
|
|
|
|
|
|
/* Get bus ratio limits and calculate clock speeds */
|
|
|
|
msr = rdmsr(MSR_PLATFORM_INFO);
|
|
|
|
ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
|
|
|
|
|
|
|
|
/* Determine if this CPU has configurable TDP */
|
|
|
|
if (cpu_config_tdp_levels()) {
|
|
|
|
/* Set max ratio to nominal TDP ratio */
|
|
|
|
msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
|
|
|
|
ratio_max = msr.lo & 0xff;
|
|
|
|
} else {
|
|
|
|
/* Max Non-Turbo Ratio */
|
|
|
|
ratio_max = (msr.lo >> 8) & 0xff;
|
|
|
|
}
|
2013-11-12 23:32:52 +01:00
|
|
|
clock_max = ratio_max * NEHALEM_BCLK + ratio_max / 3;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Calculate CPU TDP in mW */
|
|
|
|
power_max = 25000;
|
|
|
|
|
|
|
|
/* Write _PCT indicating use of FFixedHW */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_empty_PCT();
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Write _PPC with no limit on supported P-state */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_PPC_NVS();
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Write PSD indicating configured coordination type */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_PSD_package(core, cores_per_package, coord_type);
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Add P-state entries in _PSS table */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_name("_PSS");
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Determine ratio points */
|
|
|
|
ratio_step = PSS_RATIO_STEP;
|
|
|
|
num_entries = (ratio_max - ratio_min) / ratio_step;
|
|
|
|
while (num_entries > PSS_MAX_ENTRIES-1) {
|
|
|
|
ratio_step <<= 1;
|
|
|
|
num_entries >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* P[T] is Turbo state if enabled */
|
|
|
|
if (get_turbo_state() == TURBO_ENABLED) {
|
|
|
|
/* _PSS package count including Turbo */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_package(num_entries + 2);
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
|
|
|
|
ratio_turbo = msr.lo & 0xff;
|
|
|
|
|
|
|
|
/* Add entry for Turbo ratio */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_PSS_package(
|
2013-06-06 22:10:45 +02:00
|
|
|
clock_max + 1, /*MHz*/
|
|
|
|
power_max, /*mW*/
|
|
|
|
PSS_LATENCY_TRANSITION, /*lat1*/
|
|
|
|
PSS_LATENCY_BUSMASTER, /*lat2*/
|
|
|
|
ratio_turbo, /*control*/
|
|
|
|
ratio_turbo); /*status*/
|
|
|
|
} else {
|
|
|
|
/* _PSS package count without Turbo */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_package(num_entries + 1);
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* First regular entry is max non-turbo ratio */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_PSS_package(
|
2013-06-06 22:10:45 +02:00
|
|
|
clock_max, /*MHz*/
|
|
|
|
power_max, /*mW*/
|
|
|
|
PSS_LATENCY_TRANSITION, /*lat1*/
|
|
|
|
PSS_LATENCY_BUSMASTER, /*lat2*/
|
|
|
|
ratio_max, /*control*/
|
|
|
|
ratio_max); /*status*/
|
|
|
|
|
|
|
|
/* Generate the remaining entries */
|
|
|
|
for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
|
|
|
|
ratio >= ratio_min; ratio -= ratio_step) {
|
|
|
|
|
|
|
|
/* Calculate power at this ratio */
|
|
|
|
power = calculate_power(power_max, ratio_max, ratio);
|
2013-11-12 23:32:52 +01:00
|
|
|
clock = ratio * NEHALEM_BCLK + ratio / 3;
|
2013-06-06 22:10:45 +02:00
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_PSS_package(
|
2013-06-06 22:10:45 +02:00
|
|
|
clock, /*MHz*/
|
|
|
|
power, /*mW*/
|
|
|
|
PSS_LATENCY_TRANSITION, /*lat1*/
|
|
|
|
PSS_LATENCY_BUSMASTER, /*lat2*/
|
|
|
|
ratio, /*control*/
|
|
|
|
ratio); /*status*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix package length */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_pop_len();
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-12 22:18:55 +02:00
|
|
|
void generate_cpu_entries(device_t device)
|
2013-06-06 22:10:45 +02:00
|
|
|
{
|
|
|
|
int coreID, cpuID, pcontrol_blk = PMB0_BASE, plen = 6;
|
|
|
|
int totalcores = dev_count_cpu();
|
|
|
|
int cores_per_package = get_cores_per_package();
|
|
|
|
int numcpus = totalcores/cores_per_package;
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
|
|
|
|
numcpus, cores_per_package);
|
|
|
|
|
2014-08-11 19:24:55 +02:00
|
|
|
for (cpuID = 1; cpuID <= numcpus; cpuID++) {
|
2013-06-06 22:10:45 +02:00
|
|
|
for (coreID=1; coreID<=cores_per_package; coreID++) {
|
|
|
|
if (coreID>1) {
|
|
|
|
pcontrol_blk = 0;
|
|
|
|
plen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate processor \_PR.CPUx */
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_write_processor(
|
2013-06-06 22:10:45 +02:00
|
|
|
(cpuID-1)*cores_per_package+coreID-1,
|
|
|
|
pcontrol_blk, plen);
|
|
|
|
|
|
|
|
/* Generate P-state tables */
|
2014-11-04 21:09:23 +01:00
|
|
|
generate_P_state_entries(
|
2013-06-06 22:10:45 +02:00
|
|
|
cpuID-1, cores_per_package);
|
|
|
|
|
|
|
|
/* Generate C-state tables */
|
2014-11-04 21:09:23 +01:00
|
|
|
generate_C_state_entries();
|
2013-06-06 22:10:45 +02:00
|
|
|
|
|
|
|
/* Generate T-state tables */
|
2014-11-04 21:09:23 +01:00
|
|
|
generate_T_state_entries(
|
2013-06-06 22:10:45 +02:00
|
|
|
cpuID-1, cores_per_package);
|
|
|
|
|
2014-11-04 21:09:23 +01:00
|
|
|
acpigen_pop_len();
|
2013-06-06 22:10:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct chip_operations cpu_intel_model_2065x_ops = {
|
|
|
|
CHIP_NAME("Intel Nehalem CPU")
|
|
|
|
};
|