blob: 9d11ef053df5736717f0cdcb152b1d8be6c772b1 [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
3#include <types.h>
4#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpi.h>
6#include <acpi/acpigen.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02007#include <arch/cpu.h>
8#include <cpu/x86/msr.h>
9#include <cpu/intel/speedstep.h>
10#include <cpu/intel/turbo.h>
11#include <device/device.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020012#include "model_2065x.h"
13#include "chip.h"
14
15static int get_cores_per_package(void)
16{
17 struct cpuinfo_x86 c;
18 struct cpuid_result result;
19 int cores = 1;
20
21 get_fms(&c, cpuid_eax(1));
22 if (c.x86 != 6)
23 return 1;
24
25 result = cpuid_ext(0xb, 1);
26 cores = result.ebx & 0xff;
27
28 return cores;
29}
30
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010031static void generate_C_state_entries(void)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020032{
Angel Pons00d66602021-01-21 22:05:34 +010033 /* TODO */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020034}
35
36static acpi_tstate_t tss_table_fine[] = {
37 { 100, 1000, 0, 0x00, 0 },
38 { 94, 940, 0, 0x1f, 0 },
39 { 88, 880, 0, 0x1e, 0 },
40 { 82, 820, 0, 0x1d, 0 },
41 { 75, 760, 0, 0x1c, 0 },
42 { 69, 700, 0, 0x1b, 0 },
43 { 63, 640, 0, 0x1a, 0 },
44 { 57, 580, 0, 0x19, 0 },
45 { 50, 520, 0, 0x18, 0 },
46 { 44, 460, 0, 0x17, 0 },
47 { 38, 400, 0, 0x16, 0 },
48 { 32, 340, 0, 0x15, 0 },
49 { 25, 280, 0, 0x14, 0 },
50 { 19, 220, 0, 0x13, 0 },
51 { 13, 160, 0, 0x12, 0 },
52};
53
54static acpi_tstate_t tss_table_coarse[] = {
55 { 100, 1000, 0, 0x00, 0 },
56 { 88, 875, 0, 0x1f, 0 },
57 { 75, 750, 0, 0x1e, 0 },
58 { 63, 625, 0, 0x1d, 0 },
59 { 50, 500, 0, 0x1c, 0 },
60 { 38, 375, 0, 0x1b, 0 },
61 { 25, 250, 0, 0x1a, 0 },
62 { 13, 125, 0, 0x19, 0 },
63};
64
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010065static void generate_T_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020066{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020067 /* Indicate SW_ALL coordination for T-states */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010068 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020069
70 /* Indicate FFixedHW so OS will use MSR */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010071 acpigen_write_empty_PTC();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020072
73 /* Set a T-state limit that can be modified in NVS */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010074 acpigen_write_TPC("\\TLVL");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020075
76 /*
77 * CPUID.(EAX=6):EAX[5] indicates support
78 * for extended throttle levels.
79 */
80 if (cpuid_eax(6) & (1 << 5))
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010081 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020082 ARRAY_SIZE(tss_table_fine), tss_table_fine);
83 else
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010084 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020085 ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020086}
87
88static int calculate_power(int tdp, int p1_ratio, int ratio)
89{
90 u32 m;
91 u32 power;
92
93 /*
94 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
95 *
96 * Power = (ratio / p1_ratio) * m * tdp
97 */
98
99 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
100 m = (m * m) / 1000;
101
102 power = ((ratio * 100000 / p1_ratio) / 100);
103 power *= (m / 100) * (tdp / 1000);
104 power /= 1000;
105
106 return (int)power;
107}
108
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100109static void generate_P_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200110{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200111 int ratio_min, ratio_max, ratio_turbo, ratio_step;
112 int coord_type, power_max, num_entries;
113 int ratio, power, clock, clock_max;
114 msr_t msr;
115
116 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
117 msr = rdmsr(MSR_MISC_PWR_MGMT);
118 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
119 coord_type = SW_ANY;
120 else
121 coord_type = HW_ALL;
122
123 /* Get bus ratio limits and calculate clock speeds */
124 msr = rdmsr(MSR_PLATFORM_INFO);
125 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
126
Angel Pons9f0093d2021-01-21 22:17:23 +0100127 /* Max Non-Turbo Ratio */
128 ratio_max = (msr.lo >> 8) & 0xff;
129
Angel Pons95de2312020-02-17 13:08:53 +0100130 clock_max = ratio_max * IRONLAKE_BCLK + ratio_max / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200131
132 /* Calculate CPU TDP in mW */
133 power_max = 25000;
134
135 /* Write _PCT indicating use of FFixedHW */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100136 acpigen_write_empty_PCT();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200137
138 /* Write _PPC with no limit on supported P-state */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100139 acpigen_write_PPC_NVS();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200140
141 /* Write PSD indicating configured coordination type */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100142 acpigen_write_PSD_package(core, cores_per_package, coord_type);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200143
144 /* Add P-state entries in _PSS table */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100145 acpigen_write_name("_PSS");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200146
147 /* Determine ratio points */
148 ratio_step = PSS_RATIO_STEP;
149 num_entries = (ratio_max - ratio_min) / ratio_step;
150 while (num_entries > PSS_MAX_ENTRIES-1) {
151 ratio_step <<= 1;
152 num_entries >>= 1;
153 }
154
155 /* P[T] is Turbo state if enabled */
156 if (get_turbo_state() == TURBO_ENABLED) {
157 /* _PSS package count including Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100158 acpigen_write_package(num_entries + 2);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200159
160 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
161 ratio_turbo = msr.lo & 0xff;
162
163 /* Add entry for Turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100164 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200165 clock_max + 1, /*MHz*/
166 power_max, /*mW*/
167 PSS_LATENCY_TRANSITION, /*lat1*/
168 PSS_LATENCY_BUSMASTER, /*lat2*/
169 ratio_turbo, /*control*/
170 ratio_turbo); /*status*/
171 } else {
172 /* _PSS package count without Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100173 acpigen_write_package(num_entries + 1);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200174 }
175
176 /* First regular entry is max non-turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100177 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200178 clock_max, /*MHz*/
179 power_max, /*mW*/
180 PSS_LATENCY_TRANSITION, /*lat1*/
181 PSS_LATENCY_BUSMASTER, /*lat2*/
182 ratio_max, /*control*/
183 ratio_max); /*status*/
184
185 /* Generate the remaining entries */
186 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
187 ratio >= ratio_min; ratio -= ratio_step) {
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200188 /* Calculate power at this ratio */
189 power = calculate_power(power_max, ratio_max, ratio);
Angel Pons95de2312020-02-17 13:08:53 +0100190 clock = ratio * IRONLAKE_BCLK + ratio / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200191
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100192 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200193 clock, /*MHz*/
194 power, /*mW*/
195 PSS_LATENCY_TRANSITION, /*lat1*/
196 PSS_LATENCY_BUSMASTER, /*lat2*/
197 ratio, /*control*/
198 ratio); /*status*/
199 }
200
201 /* Fix package length */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100202 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200203}
204
Furquan Shaikh7536a392020-04-24 21:59:21 -0700205void generate_cpu_entries(const struct device *device)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200206{
Angel Pons772c0972021-06-04 12:57:21 +0200207 int coreID, cpuID;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200208 int totalcores = dev_count_cpu();
209 int cores_per_package = get_cores_per_package();
210 int numcpus = totalcores/cores_per_package;
211
212 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
213 numcpus, cores_per_package);
214
Martin Roth9944b282014-08-11 11:24:55 -0600215 for (cpuID = 1; cpuID <= numcpus; cpuID++) {
Lee Leahy9d62e7e2017-03-15 17:40:50 -0700216 for (coreID = 1; coreID <= cores_per_package; coreID++) {
Christian Walterbe3979c2019-12-18 15:07:59 +0100217 /* Generate processor \_SB.CPUx */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100218 acpigen_write_processor(
Angel Pons772c0972021-06-04 12:57:21 +0200219 (cpuID-1)*cores_per_package+coreID-1, 0, 0);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200220
221 /* Generate P-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100222 generate_P_state_entries(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200223 cpuID-1, cores_per_package);
224
225 /* Generate C-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100226 generate_C_state_entries();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200227
228 /* Generate T-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100229 generate_T_state_entries(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200230 cpuID-1, cores_per_package);
231
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100232 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200233 }
234 }
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};