Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
| 4 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
| 6 | #include <acpi/acpigen.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 7 | #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 Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 12 | #include "model_2065x.h" |
| 13 | #include "chip.h" |
| 14 | |
| 15 | static 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 Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 31 | static void generate_C_state_entries(void) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 32 | { |
Angel Pons | 00d6660 | 2021-01-21 22:05:34 +0100 | [diff] [blame] | 33 | /* TODO */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static 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 | |
| 54 | static 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 Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 65 | static void generate_T_state_entries(int core, int cores_per_package) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 66 | { |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 67 | /* Indicate SW_ALL coordination for T-states */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 68 | acpigen_write_TSD_package(core, cores_per_package, SW_ALL); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 69 | |
| 70 | /* Indicate FFixedHW so OS will use MSR */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 71 | acpigen_write_empty_PTC(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 72 | |
| 73 | /* Set a T-state limit that can be modified in NVS */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 74 | acpigen_write_TPC("\\TLVL"); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * CPUID.(EAX=6):EAX[5] indicates support |
| 78 | * for extended throttle levels. |
| 79 | */ |
| 80 | if (cpuid_eax(6) & (1 << 5)) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 81 | acpigen_write_TSS_package( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 82 | ARRAY_SIZE(tss_table_fine), tss_table_fine); |
| 83 | else |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 84 | acpigen_write_TSS_package( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 85 | ARRAY_SIZE(tss_table_coarse), tss_table_coarse); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static 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 Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 109 | static void generate_P_state_entries(int core, int cores_per_package) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 110 | { |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 111 | 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 Pons | 9f0093d | 2021-01-21 22:17:23 +0100 | [diff] [blame^] | 127 | /* Max Non-Turbo Ratio */ |
| 128 | ratio_max = (msr.lo >> 8) & 0xff; |
| 129 | |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 130 | clock_max = ratio_max * IRONLAKE_BCLK + ratio_max / 3; |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 131 | |
| 132 | /* Calculate CPU TDP in mW */ |
| 133 | power_max = 25000; |
| 134 | |
| 135 | /* Write _PCT indicating use of FFixedHW */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 136 | acpigen_write_empty_PCT(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 137 | |
| 138 | /* Write _PPC with no limit on supported P-state */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 139 | acpigen_write_PPC_NVS(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 140 | |
| 141 | /* Write PSD indicating configured coordination type */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 142 | acpigen_write_PSD_package(core, cores_per_package, coord_type); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 143 | |
| 144 | /* Add P-state entries in _PSS table */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 145 | acpigen_write_name("_PSS"); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 146 | |
| 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 Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 158 | acpigen_write_package(num_entries + 2); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 159 | |
| 160 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 161 | ratio_turbo = msr.lo & 0xff; |
| 162 | |
| 163 | /* Add entry for Turbo ratio */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 164 | acpigen_write_PSS_package( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 165 | 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 Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 173 | acpigen_write_package(num_entries + 1); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* First regular entry is max non-turbo ratio */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 177 | acpigen_write_PSS_package( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 178 | 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) { |
| 188 | |
| 189 | /* Calculate power at this ratio */ |
| 190 | power = calculate_power(power_max, ratio_max, ratio); |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 191 | clock = ratio * IRONLAKE_BCLK + ratio / 3; |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 192 | |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 193 | acpigen_write_PSS_package( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 194 | 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 Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 203 | acpigen_pop_len(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 206 | void generate_cpu_entries(const struct device *device) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 207 | { |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 208 | int coreID, cpuID, pcontrol_blk = PMB0_BASE, plen = 6; |
| 209 | int totalcores = dev_count_cpu(); |
| 210 | int cores_per_package = get_cores_per_package(); |
| 211 | int numcpus = totalcores/cores_per_package; |
| 212 | |
| 213 | printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n", |
| 214 | numcpus, cores_per_package); |
| 215 | |
Martin Roth | 9944b28 | 2014-08-11 11:24:55 -0600 | [diff] [blame] | 216 | for (cpuID = 1; cpuID <= numcpus; cpuID++) { |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 217 | for (coreID = 1; coreID <= cores_per_package; coreID++) { |
| 218 | if (coreID > 1) { |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 219 | pcontrol_blk = 0; |
| 220 | plen = 0; |
| 221 | } |
| 222 | |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 223 | /* Generate processor \_SB.CPUx */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 224 | acpigen_write_processor( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 225 | (cpuID-1)*cores_per_package+coreID-1, |
| 226 | pcontrol_blk, plen); |
| 227 | |
| 228 | /* Generate P-state tables */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 229 | generate_P_state_entries( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 230 | cpuID-1, cores_per_package); |
| 231 | |
| 232 | /* Generate C-state tables */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 233 | generate_C_state_entries(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 234 | |
| 235 | /* Generate T-state tables */ |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 236 | generate_T_state_entries( |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 237 | cpuID-1, cores_per_package); |
| 238 | |
Vladimir Serbinenko | 226d784 | 2014-11-04 21:09:23 +0100 | [diff] [blame] | 239 | acpigen_pop_len(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 240 | } |
| 241 | } |
Arthur Heymans | 04008a9 | 2018-11-28 12:13:54 +0100 | [diff] [blame] | 242 | |
| 243 | /* PPKG is usually used for thermal management |
| 244 | of the first and only package. */ |
| 245 | acpigen_write_processor_package("PPKG", 0, cores_per_package); |
| 246 | |
| 247 | /* Add a method to notify processor nodes */ |
| 248 | acpigen_write_processor_cnot(cores_per_package); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | struct chip_operations cpu_intel_model_2065x_ops = { |
Angel Pons | 31b7ee4 | 2020-02-17 14:04:28 +0100 | [diff] [blame] | 252 | CHIP_NAME("Intel Arrandale CPU") |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 253 | }; |