blob: d8fef628b8109a713b3577f034800d3bb865f120 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
4#include <acpi/acpigen.h>
Elyes Haouasad65e8c2022-10-31 14:02:13 +01005#include <console/console.h>
6#include <cpu/cpu.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02007#include <cpu/intel/speedstep.h>
8#include <cpu/intel/turbo.h>
Elyes Haouasad65e8c2022-10-31 14:02:13 +01009#include <cpu/x86/msr.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020010#include <device/device.h>
Elyes Haouasad65e8c2022-10-31 14:02:13 +010011#include <types.h>
12
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020013#include "model_2065x.h"
14#include "chip.h"
15
16static int get_cores_per_package(void)
17{
18 struct cpuinfo_x86 c;
19 struct cpuid_result result;
20 int cores = 1;
21
22 get_fms(&c, cpuid_eax(1));
23 if (c.x86 != 6)
24 return 1;
25
26 result = cpuid_ext(0xb, 1);
27 cores = result.ebx & 0xff;
28
29 return cores;
30}
31
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010032static void generate_C_state_entries(void)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020033{
Angel Pons00d66602021-01-21 22:05:34 +010034 /* TODO */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020035}
36
37static acpi_tstate_t tss_table_fine[] = {
38 { 100, 1000, 0, 0x00, 0 },
39 { 94, 940, 0, 0x1f, 0 },
40 { 88, 880, 0, 0x1e, 0 },
41 { 82, 820, 0, 0x1d, 0 },
42 { 75, 760, 0, 0x1c, 0 },
43 { 69, 700, 0, 0x1b, 0 },
44 { 63, 640, 0, 0x1a, 0 },
45 { 57, 580, 0, 0x19, 0 },
46 { 50, 520, 0, 0x18, 0 },
47 { 44, 460, 0, 0x17, 0 },
48 { 38, 400, 0, 0x16, 0 },
49 { 32, 340, 0, 0x15, 0 },
50 { 25, 280, 0, 0x14, 0 },
51 { 19, 220, 0, 0x13, 0 },
52 { 13, 160, 0, 0x12, 0 },
53};
54
55static acpi_tstate_t tss_table_coarse[] = {
56 { 100, 1000, 0, 0x00, 0 },
57 { 88, 875, 0, 0x1f, 0 },
58 { 75, 750, 0, 0x1e, 0 },
59 { 63, 625, 0, 0x1d, 0 },
60 { 50, 500, 0, 0x1c, 0 },
61 { 38, 375, 0, 0x1b, 0 },
62 { 25, 250, 0, 0x1a, 0 },
63 { 13, 125, 0, 0x19, 0 },
64};
65
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010066static void generate_T_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020067{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020068 /* Indicate SW_ALL coordination for T-states */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010069 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020070
71 /* Indicate FFixedHW so OS will use MSR */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010072 acpigen_write_empty_PTC();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020073
74 /* Set a T-state limit that can be modified in NVS */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010075 acpigen_write_TPC("\\TLVL");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020076
77 /*
78 * CPUID.(EAX=6):EAX[5] indicates support
79 * for extended throttle levels.
80 */
81 if (cpuid_eax(6) & (1 << 5))
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010082 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020083 ARRAY_SIZE(tss_table_fine), tss_table_fine);
84 else
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010085 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020086 ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020087}
88
89static int calculate_power(int tdp, int p1_ratio, int ratio)
90{
91 u32 m;
92 u32 power;
93
94 /*
95 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
96 *
97 * Power = (ratio / p1_ratio) * m * tdp
98 */
99
100 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
101 m = (m * m) / 1000;
102
103 power = ((ratio * 100000 / p1_ratio) / 100);
104 power *= (m / 100) * (tdp / 1000);
105 power /= 1000;
106
107 return (int)power;
108}
109
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100110static void generate_P_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200111{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200112 int ratio_min, ratio_max, ratio_turbo, ratio_step;
113 int coord_type, power_max, num_entries;
114 int ratio, power, clock, clock_max;
115 msr_t msr;
116
117 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
118 msr = rdmsr(MSR_MISC_PWR_MGMT);
119 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
120 coord_type = SW_ANY;
121 else
122 coord_type = HW_ALL;
123
124 /* Get bus ratio limits and calculate clock speeds */
125 msr = rdmsr(MSR_PLATFORM_INFO);
126 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
127
Angel Pons9f0093d2021-01-21 22:17:23 +0100128 /* Max Non-Turbo Ratio */
129 ratio_max = (msr.lo >> 8) & 0xff;
130
Angel Pons95de2312020-02-17 13:08:53 +0100131 clock_max = ratio_max * IRONLAKE_BCLK + ratio_max / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200132
133 /* Calculate CPU TDP in mW */
134 power_max = 25000;
135
136 /* Write _PCT indicating use of FFixedHW */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100137 acpigen_write_empty_PCT();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200138
139 /* Write _PPC with no limit on supported P-state */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100140 acpigen_write_PPC_NVS();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200141
142 /* Write PSD indicating configured coordination type */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100143 acpigen_write_PSD_package(core, cores_per_package, coord_type);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200144
145 /* Add P-state entries in _PSS table */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100146 acpigen_write_name("_PSS");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200147
148 /* Determine ratio points */
149 ratio_step = PSS_RATIO_STEP;
150 num_entries = (ratio_max - ratio_min) / ratio_step;
151 while (num_entries > PSS_MAX_ENTRIES-1) {
152 ratio_step <<= 1;
153 num_entries >>= 1;
154 }
155
156 /* P[T] is Turbo state if enabled */
157 if (get_turbo_state() == TURBO_ENABLED) {
158 /* _PSS package count including Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100159 acpigen_write_package(num_entries + 2);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200160
161 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
162 ratio_turbo = msr.lo & 0xff;
163
164 /* Add entry for Turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100165 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200166 clock_max + 1, /*MHz*/
167 power_max, /*mW*/
168 PSS_LATENCY_TRANSITION, /*lat1*/
169 PSS_LATENCY_BUSMASTER, /*lat2*/
170 ratio_turbo, /*control*/
171 ratio_turbo); /*status*/
172 } else {
173 /* _PSS package count without Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100174 acpigen_write_package(num_entries + 1);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200175 }
176
177 /* First regular entry is max non-turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100178 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200179 clock_max, /*MHz*/
180 power_max, /*mW*/
181 PSS_LATENCY_TRANSITION, /*lat1*/
182 PSS_LATENCY_BUSMASTER, /*lat2*/
183 ratio_max, /*control*/
184 ratio_max); /*status*/
185
186 /* Generate the remaining entries */
187 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
188 ratio >= ratio_min; ratio -= ratio_step) {
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200189 /* Calculate power at this ratio */
190 power = calculate_power(power_max, ratio_max, ratio);
Angel Pons95de2312020-02-17 13:08:53 +0100191 clock = ratio * IRONLAKE_BCLK + ratio / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200192
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100193 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200194 clock, /*MHz*/
195 power, /*mW*/
196 PSS_LATENCY_TRANSITION, /*lat1*/
197 PSS_LATENCY_BUSMASTER, /*lat2*/
198 ratio, /*control*/
199 ratio); /*status*/
200 }
201
202 /* Fix package length */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100203 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200204}
205
Kyösti Mälkkid521b962023-04-12 21:44:49 +0300206static void generate_cpu_entry(int cpu, int core, int cores_per_package)
207{
208 /* Generate Scope(\_SB) { Device(CPUx */
209 acpigen_write_processor_device(cpu * cores_per_package + core);
210
211 /* Generate P-state tables */
212 generate_P_state_entries(cpu, cores_per_package);
213
214 /* Generate C-state tables */
215 generate_C_state_entries();
216
217 /* Generate T-state tables */
218 generate_T_state_entries(cpu, cores_per_package);
219
220 acpigen_write_processor_device_end();
221}
222
Furquan Shaikh7536a392020-04-24 21:59:21 -0700223void generate_cpu_entries(const struct device *device)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200224{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200225 int totalcores = dev_count_cpu();
226 int cores_per_package = get_cores_per_package();
Kyösti Mälkkie39a3e32023-04-12 16:39:12 +0300227 int numcpus = totalcores / cores_per_package;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200228
229 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
230 numcpus, cores_per_package);
231
Kyösti Mälkkid521b962023-04-12 21:44:49 +0300232 for (int cpu_id = 0; cpu_id < numcpus; cpu_id++)
233 for (int core_id = 0; core_id < cores_per_package; core_id++)
234 generate_cpu_entry(cpu_id, core_id, cores_per_package);
Arthur Heymans04008a92018-11-28 12:13:54 +0100235
236 /* PPKG is usually used for thermal management
237 of the first and only package. */
238 acpigen_write_processor_package("PPKG", 0, cores_per_package);
239
240 /* Add a method to notify processor nodes */
241 acpigen_write_processor_cnot(cores_per_package);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200242}
243
244struct chip_operations cpu_intel_model_2065x_ops = {
Angel Pons31b7ee42020-02-17 14:04:28 +0100245 CHIP_NAME("Intel Arrandale CPU")
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200246};