Skip to content

Commit 5561f25

Browse files
committed
Merge branch 'pm-cpufreq'
Merge cpufreq updates for 5.17-rc1: - Add new P-state driver for AMD processors (Huang Rui). - Fix initialization of min and max frequency QoS requests in the cpufreq core (Rafael Wysocki). - Fix EPP handling on Alder Lake in intel_pstate (Srinivas Pandruvada). - Make intel_pstate update cpuinfo.max_freq when notified of HWP capabilities changes and drop a redundant function call from that driver (Rafael Wysocki). - Improve IRQ support in the Qcom cpufreq driver (Ard Biesheuvel, Stephen Boyd, Vladimir Zapolskiy). - Fix double devm_remap() in the Mediatek cpufreq driver (Hector Yuan). - Introduce thermal pressure helpers for cpufreq CPU cooling (Lukasz Luba). - Make cpufreq use default_groups in kobj_type (Greg Kroah-Hartman). * pm-cpufreq: (32 commits) x86, sched: Fix undefined reference to init_freq_invariance_cppc() build error cpufreq: amd-pstate: Fix Kconfig dependencies for AMD P-State cpufreq: amd-pstate: Fix struct amd_cpudata kernel-doc comment MAINTAINERS: Add AMD P-State driver maintainer entry Documentation: amd-pstate: Add AMD P-State driver introduction cpufreq: amd-pstate: Add AMD P-State performance attributes cpufreq: amd-pstate: Add AMD P-State frequencies attributes cpufreq: amd-pstate: Add boost mode support for AMD P-State cpufreq: amd-pstate: Add trace for AMD P-State module cpufreq: amd-pstate: Introduce the support for the processors with shared memory solution cpufreq: amd-pstate: Add fast switch function for AMD P-State cpufreq: amd-pstate: Introduce a new AMD P-State driver to support future processors ACPI: CPPC: Add CPPC enable register function ACPI: CPPC: Check present CPUs for determining _CPC is valid ACPI: CPPC: Implement support for SystemIO registers x86/msr: Add AMD CPPC MSR definitions x86/cpufeatures: Add AMD Collaborative Processor Performance Control feature flag cpufreq: use default_groups in kobj_type cpufreq: mediatek-hw: Fix double devm_remap in hotplug case cpufreq: intel_pstate: Update cpuinfo.max_freq on HWP_CAP changes ...
2 parents 4ecc933 + 6c4ab1b commit 5561f25

27 files changed

+1445
-93
lines changed

Documentation/admin-guide/acpi/cppc_sysfs.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Collaborative Processor Performance Control (CPPC)
55
==================================================
66

7+
.. _cppc_sysfs:
8+
79
CPPC
810
====
911

Documentation/admin-guide/pm/amd-pstate.rst

Lines changed: 382 additions & 0 deletions
Large diffs are not rendered by default.

Documentation/admin-guide/pm/working-state.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Working-State Power Management
1111
intel_idle
1212
cpufreq
1313
intel_pstate
14+
amd-pstate
1415
cpufreq_drivers
1516
intel_epb
1617
intel-speed-select

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,13 @@ S: Supported
993993
T: git https://gitlab.freedesktop.org/agd5f/linux.git
994994
F: drivers/gpu/drm/amd/pm/
995995

996+
AMD PSTATE DRIVER
997+
M: Huang Rui <ray.huang@amd.com>
998+
L: linux-pm@vger.kernel.org
999+
S: Supported
1000+
F: Documentation/admin-guide/pm/amd-pstate.rst
1001+
F: drivers/cpufreq/amd-pstate*
1002+
9961003
AMD PTDMA DRIVER
9971004
M: Sanjay R Mehta <sanju.mehta@amd.com>
9981005
L: dmaengine@vger.kernel.org

arch/arm/include/asm/topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/* Replace task scheduler's default thermal pressure API */
2525
#define arch_scale_thermal_pressure topology_get_thermal_pressure
26-
#define arch_set_thermal_pressure topology_set_thermal_pressure
26+
#define arch_update_thermal_pressure topology_update_thermal_pressure
2727

2828
#else
2929

arch/arm64/include/asm/topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void update_freq_counters_refs(void);
3232

3333
/* Replace task scheduler's default thermal pressure API */
3434
#define arch_scale_thermal_pressure topology_get_thermal_pressure
35-
#define arch_set_thermal_pressure topology_set_thermal_pressure
35+
#define arch_update_thermal_pressure topology_update_thermal_pressure
3636

3737
#include <asm-generic/topology.h>
3838

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
#define X86_FEATURE_AMD_SSBD (13*32+24) /* "" Speculative Store Bypass Disable */
316316
#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */
317317
#define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */
318+
#define X86_FEATURE_CPPC (13*32+27) /* Collaborative Processor Performance Control */
318319

319320
/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
320321
#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */

arch/x86/include/asm/msr-index.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,23 @@
486486

487487
#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f
488488

489+
/* AMD Collaborative Processor Performance Control MSRs */
490+
#define MSR_AMD_CPPC_CAP1 0xc00102b0
491+
#define MSR_AMD_CPPC_ENABLE 0xc00102b1
492+
#define MSR_AMD_CPPC_CAP2 0xc00102b2
493+
#define MSR_AMD_CPPC_REQ 0xc00102b3
494+
#define MSR_AMD_CPPC_STATUS 0xc00102b4
495+
496+
#define AMD_CPPC_LOWEST_PERF(x) (((x) >> 0) & 0xff)
497+
#define AMD_CPPC_LOWNONLIN_PERF(x) (((x) >> 8) & 0xff)
498+
#define AMD_CPPC_NOMINAL_PERF(x) (((x) >> 16) & 0xff)
499+
#define AMD_CPPC_HIGHEST_PERF(x) (((x) >> 24) & 0xff)
500+
501+
#define AMD_CPPC_MAX_PERF(x) (((x) & 0xff) << 0)
502+
#define AMD_CPPC_MIN_PERF(x) (((x) & 0xff) << 8)
503+
#define AMD_CPPC_DES_PERF(x) (((x) & 0xff) << 16)
504+
#define AMD_CPPC_ENERGY_PERF_PREF(x) (((x) & 0xff) << 24)
505+
489506
/* Fam 17h MSRs */
490507
#define MSR_F17H_IRPERF 0xc00000e9
491508

arch/x86/include/asm/topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static inline void arch_set_max_freq_ratio(bool turbo_disabled)
221221
}
222222
#endif
223223

224-
#ifdef CONFIG_ACPI_CPPC_LIB
224+
#if defined(CONFIG_ACPI_CPPC_LIB) && defined(CONFIG_SMP)
225225
void init_freq_invariance_cppc(void);
226226
#define init_freq_invariance_cppc init_freq_invariance_cppc
227227
#endif

drivers/acpi/cppc_acpi.c

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
118118
*/
119119
#define NUM_RETRIES 500ULL
120120

121+
#define OVER_16BTS_MASK ~0xFFFFULL
122+
121123
#define define_one_cppc_ro(_name) \
122124
static struct kobj_attribute _name = \
123125
__ATTR(_name, 0444, show_##_name, NULL)
@@ -411,7 +413,7 @@ bool acpi_cpc_valid(void)
411413
struct cpc_desc *cpc_ptr;
412414
int cpu;
413415

414-
for_each_possible_cpu(cpu) {
416+
for_each_present_cpu(cpu) {
415417
cpc_ptr = per_cpu(cpc_desc_ptr, cpu);
416418
if (!cpc_ptr)
417419
return false;
@@ -746,9 +748,26 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
746748
goto out_free;
747749
cpc_ptr->cpc_regs[i-2].sys_mem_vaddr = addr;
748750
}
751+
} else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
752+
if (gas_t->access_width < 1 || gas_t->access_width > 3) {
753+
/*
754+
* 1 = 8-bit, 2 = 16-bit, and 3 = 32-bit.
755+
* SystemIO doesn't implement 64-bit
756+
* registers.
757+
*/
758+
pr_debug("Invalid access width %d for SystemIO register\n",
759+
gas_t->access_width);
760+
goto out_free;
761+
}
762+
if (gas_t->address & OVER_16BTS_MASK) {
763+
/* SystemIO registers use 16-bit integer addresses */
764+
pr_debug("Invalid IO port %llu for SystemIO register\n",
765+
gas_t->address);
766+
goto out_free;
767+
}
749768
} else {
750769
if (gas_t->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE || !cpc_ffh_supported()) {
751-
/* Support only PCC ,SYS MEM and FFH type regs */
770+
/* Support only PCC, SystemMemory, SystemIO, and FFH type regs. */
752771
pr_debug("Unsupported register type: %d\n", gas_t->space_id);
753772
goto out_free;
754773
}
@@ -923,7 +942,21 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
923942
}
924943

925944
*val = 0;
926-
if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0)
945+
946+
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
947+
u32 width = 8 << (reg->access_width - 1);
948+
acpi_status status;
949+
950+
status = acpi_os_read_port((acpi_io_address)reg->address,
951+
(u32 *)val, width);
952+
if (ACPI_FAILURE(status)) {
953+
pr_debug("Error: Failed to read SystemIO port %llx\n",
954+
reg->address);
955+
return -EFAULT;
956+
}
957+
958+
return 0;
959+
} else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0)
927960
vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
928961
else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
929962
vaddr = reg_res->sys_mem_vaddr;
@@ -962,7 +995,20 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
962995
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
963996
struct cpc_reg *reg = &reg_res->cpc_entry.reg;
964997

965-
if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0)
998+
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
999+
u32 width = 8 << (reg->access_width - 1);
1000+
acpi_status status;
1001+
1002+
status = acpi_os_write_port((acpi_io_address)reg->address,
1003+
(u32)val, width);
1004+
if (ACPI_FAILURE(status)) {
1005+
pr_debug("Error: Failed to write SystemIO port %llx\n",
1006+
reg->address);
1007+
return -EFAULT;
1008+
}
1009+
1010+
return 0;
1011+
} else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0)
9661012
vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
9671013
else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
9681014
vaddr = reg_res->sys_mem_vaddr;
@@ -1229,6 +1275,51 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
12291275
}
12301276
EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs);
12311277

1278+
/**
1279+
* cppc_set_enable - Set to enable CPPC on the processor by writing the
1280+
* Continuous Performance Control package EnableRegister field.
1281+
* @cpu: CPU for which to enable CPPC register.
1282+
* @enable: 0 - disable, 1 - enable CPPC feature on the processor.
1283+
*
1284+
* Return: 0 for success, -ERRNO or -EIO otherwise.
1285+
*/
1286+
int cppc_set_enable(int cpu, bool enable)
1287+
{
1288+
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
1289+
struct cpc_register_resource *enable_reg;
1290+
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
1291+
struct cppc_pcc_data *pcc_ss_data = NULL;
1292+
int ret = -EINVAL;
1293+
1294+
if (!cpc_desc) {
1295+
pr_debug("No CPC descriptor for CPU:%d\n", cpu);
1296+
return -EINVAL;
1297+
}
1298+
1299+
enable_reg = &cpc_desc->cpc_regs[ENABLE];
1300+
1301+
if (CPC_IN_PCC(enable_reg)) {
1302+
1303+
if (pcc_ss_id < 0)
1304+
return -EIO;
1305+
1306+
ret = cpc_write(cpu, enable_reg, enable);
1307+
if (ret)
1308+
return ret;
1309+
1310+
pcc_ss_data = pcc_data[pcc_ss_id];
1311+
1312+
down_write(&pcc_ss_data->pcc_lock);
1313+
/* after writing CPC, transfer the ownership of PCC to platfrom */
1314+
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
1315+
up_write(&pcc_ss_data->pcc_lock);
1316+
return ret;
1317+
}
1318+
1319+
return cpc_write(cpu, enable_reg, enable);
1320+
}
1321+
EXPORT_SYMBOL_GPL(cppc_set_enable);
1322+
12321323
/**
12331324
* cppc_set_perf - Set a CPU's performance controls.
12341325
* @cpu: CPU for which to set performance controls.

0 commit comments

Comments
 (0)