Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_pm.h> |
| 4 | #include <acpi/acpigen.h> |
Felix Held | 8f7f4bf | 2022-08-03 22:10:05 +0200 | [diff] [blame] | 5 | #include <amdblocks/cppc.h> |
Elyes Haouas | f743e0c | 2022-10-31 13:46:00 +0100 | [diff] [blame] | 6 | #include <cpu/cpu.h> |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 7 | #include <soc/msr.h> |
Felix Held | d5ab24c | 2022-08-08 22:57:31 +0200 | [diff] [blame] | 8 | #include <types.h> |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 9 | |
Felix Held | 9a7670f | 2022-08-03 21:03:12 +0200 | [diff] [blame] | 10 | static void cpu_init_cppc_config(struct cppc_config *config, u32 version) |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 11 | { |
Felix Held | d5ab24c | 2022-08-08 22:57:31 +0200 | [diff] [blame] | 12 | uint32_t lowest_freq_mhz; |
| 13 | uint32_t nominal_freq_mhz; |
| 14 | |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 15 | config->version = version; |
| 16 | |
Michael Niewöhner | 38107fa | 2021-10-05 22:22:21 +0200 | [diff] [blame] | 17 | config->entries[CPPC_HIGHEST_PERF] = CPPC_REG_MSR(MSR_CPPC_CAPABILITY_1, SHIFT_CPPC_CAPABILITY_1_HIGHEST_PERF, 8); |
| 18 | config->entries[CPPC_NOMINAL_PERF] = CPPC_REG_MSR(MSR_CPPC_CAPABILITY_1, SHIFT_CPPC_CAPABILITY_1_NOMINAL_PERF, 8); |
| 19 | config->entries[CPPC_LOWEST_NONL_PERF] = CPPC_REG_MSR(MSR_CPPC_CAPABILITY_1, SHIFT_CPPC_CAPABILITY_1_LOW_NON_LIN_PERF, 8); |
| 20 | config->entries[CPPC_LOWEST_PERF] = CPPC_REG_MSR(MSR_CPPC_CAPABILITY_1, SHIFT_CPPC_CAPABILITY_1_LOWEST_PERF, 8); |
| 21 | config->entries[CPPC_GUARANTEED_PERF] = CPPC_UNSUPPORTED; |
| 22 | config->entries[CPPC_DESIRED_PERF] = CPPC_REG_MSR(MSR_CPPC_REQUEST, SHIFT_CPPC_REQUEST_DES_PERF, 8); |
| 23 | config->entries[CPPC_MIN_PERF] = CPPC_REG_MSR(MSR_CPPC_REQUEST, SHIFT_CPPC_REQUEST_MIN_PERF, 8); |
| 24 | config->entries[CPPC_MAX_PERF] = CPPC_REG_MSR(MSR_CPPC_REQUEST, SHIFT_CPPC_REQUEST_MAX_PERF, 8); |
| 25 | config->entries[CPPC_PERF_REDUCE_TOLERANCE] = CPPC_UNSUPPORTED; |
| 26 | config->entries[CPPC_TIME_WINDOW] = CPPC_UNSUPPORTED; |
| 27 | config->entries[CPPC_COUNTER_WRAP] = CPPC_UNSUPPORTED; |
| 28 | config->entries[CPPC_REF_PERF_COUNTER] = CPPC_REG_MSR(MSR_MAX_PERFORMANCE_FREQUENCY_CLOCK_COUNT, 0, 64); |
| 29 | config->entries[CPPC_DELIVERED_PERF_COUNTER] = CPPC_REG_MSR(MSR_ACTUAL_PERFORMANCE_FREQUENCY_CLOCK_COUNT, 0, 64); |
Zheng Bao | b72c110 | 2022-08-25 17:09:34 +0800 | [diff] [blame] | 30 | config->entries[CPPC_PERF_LIMITED] = CPPC_REG_MSR(MSR_CPPC_STATUS, 0, 2); |
Michael Niewöhner | 38107fa | 2021-10-05 22:22:21 +0200 | [diff] [blame] | 31 | config->entries[CPPC_ENABLE] = CPPC_REG_MSR(MSR_CPPC_ENABLE, 0, 1); |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 32 | |
Michael Niewöhner | f72c7b1 | 2021-10-05 21:42:57 +0200 | [diff] [blame] | 33 | if (version < 2) |
| 34 | return; |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 35 | |
Zheng Bao | b72c110 | 2022-08-25 17:09:34 +0800 | [diff] [blame] | 36 | config->entries[CPPC_AUTO_SELECT] = CPPC_DWORD(1); |
Michael Niewöhner | 38107fa | 2021-10-05 22:22:21 +0200 | [diff] [blame] | 37 | config->entries[CPPC_AUTO_ACTIVITY_WINDOW] = CPPC_UNSUPPORTED; |
| 38 | config->entries[CPPC_PERF_PREF] = CPPC_REG_MSR(MSR_CPPC_REQUEST, SHIFT_CPPC_REQUEST_ENERGY_PERF_PREF, 8); |
| 39 | config->entries[CPPC_REF_PERF] = CPPC_UNSUPPORTED; |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 40 | |
Michael Niewöhner | f72c7b1 | 2021-10-05 21:42:57 +0200 | [diff] [blame] | 41 | if (version < 3) |
| 42 | return; |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 43 | |
Felix Held | d5ab24c | 2022-08-08 22:57:31 +0200 | [diff] [blame] | 44 | config->entries[CPPC_LOWEST_FREQ] = |
| 45 | get_ccx_cppc_min_frequency(&lowest_freq_mhz) == CB_SUCCESS ? |
| 46 | CPPC_DWORD(lowest_freq_mhz) : CPPC_UNSUPPORTED; |
| 47 | config->entries[CPPC_NOMINAL_FREQ] = |
| 48 | get_ccx_cppc_nom_frequency(&nominal_freq_mhz) == CB_SUCCESS ? |
| 49 | CPPC_DWORD(nominal_freq_mhz) : CPPC_UNSUPPORTED; |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Julian Schroeder | 577e146 | 2021-07-09 16:10:08 -0500 | [diff] [blame] | 52 | void generate_cppc_entries(unsigned int core_id) |
| 53 | { |
| 54 | /* Generate GCPC package in first logical core */ |
| 55 | if (core_id == 0) { |
| 56 | struct cppc_config cppc_config; |
| 57 | cpu_init_cppc_config(&cppc_config, CPPC_VERSION_3); |
| 58 | acpigen_write_CPPC_package(&cppc_config); |
| 59 | } |
| 60 | |
| 61 | /* Write _CPC entry for each logical core */ |
| 62 | acpigen_write_CPPC_method(); |
| 63 | } |