Skip to content

Commit a6cbcdd

Browse files
spandruvadarafaeljw
authored andcommitted
ACPI / CPPC: Add support for functional fixed hardware address
The CPPC registers can also be accessed via functional fixed hardware addresse(FFH) in X86. Add support by modifying cpc_read and cpc_write to be able to read/write MSRs on x86 platform on per cpu basis. Also with this change, acpi_cppc_processor_probe doesn't bail out if address space id is not equal to PCC or memory address space and FFH is supported on the system. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 5448f14 commit a6cbcdd

3 files changed

Lines changed: 121 additions & 13 deletions

File tree

‎arch/x86/kernel/acpi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
obj-$(CONFIG_ACPI) += boot.o
22
obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o
33
obj-$(CONFIG_ACPI_APEI) += apei.o
4+
obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_msr.o
45

56
ifneq ($(CONFIG_ACPI_PROCESSOR),)
67
obj-y += cstate.o

‎arch/x86/kernel/acpi/cppc_msr.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* cppc_msr.c: MSR Interface for CPPC
3+
* Copyright (c) 2016, Intel Corporation.
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms and conditions of the GNU General Public License,
7+
* version 2, as published by the Free Software Foundation.
8+
*
9+
* This program is distributed in the hope it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
*/
15+
16+
#include <acpi/cppc_acpi.h>
17+
#include <asm/msr.h>
18+
19+
/* Refer to drivers/acpi/cppc_acpi.c for the description of functions */
20+
21+
bool cpc_ffh_supported(void)
22+
{
23+
return true;
24+
}
25+
26+
int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
27+
{
28+
int err;
29+
30+
err = rdmsrl_safe_on_cpu(cpunum, reg->address, val);
31+
if (!err) {
32+
u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
33+
reg->bit_offset);
34+
35+
*val &= mask;
36+
*val >>= reg->bit_offset;
37+
}
38+
return err;
39+
}
40+
41+
int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
42+
{
43+
u64 rd_val;
44+
int err;
45+
46+
err = rdmsrl_safe_on_cpu(cpunum, reg->address, &rd_val);
47+
if (!err) {
48+
u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
49+
reg->bit_offset);
50+
51+
val <<= reg->bit_offset;
52+
val &= mask;
53+
rd_val &= ~mask;
54+
rd_val |= val;
55+
err = wrmsrl_safe_on_cpu(cpunum, reg->address, rd_val);
56+
}
57+
return err;
58+
}

‎drivers/acpi/cppc_acpi.c‎

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,19 @@ static int register_pcc_channel(int pcc_subspace_idx)
579579
return 0;
580580
}
581581

582+
/**
583+
* cpc_ffh_supported() - check if FFH reading supported
584+
*
585+
* Check if the architecture has support for functional fixed hardware
586+
* read/write capability.
587+
*
588+
* Return: true for supported, false for not supported
589+
*/
590+
bool __weak cpc_ffh_supported(void)
591+
{
592+
return false;
593+
}
594+
582595
/*
583596
* An example CPC table looks like the following.
584597
*
@@ -728,9 +741,11 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
728741
cpc_ptr->cpc_regs[i-2].sys_mem_vaddr = addr;
729742
}
730743
} else {
731-
/* Support only PCC and SYS MEM type regs */
732-
pr_debug("Unsupported register type: %d\n", gas_t->space_id);
733-
goto out_free;
744+
if (gas_t->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE || !cpc_ffh_supported()) {
745+
/* Support only PCC ,SYS MEM and FFH type regs */
746+
pr_debug("Unsupported register type: %d\n", gas_t->space_id);
747+
goto out_free;
748+
}
734749
}
735750

736751
cpc_ptr->cpc_regs[i-2].type = ACPI_TYPE_BUFFER;
@@ -819,13 +834,43 @@ void acpi_cppc_processor_exit(struct acpi_processor *pr)
819834
}
820835
EXPORT_SYMBOL_GPL(acpi_cppc_processor_exit);
821836

837+
/**
838+
* cpc_read_ffh() - Read FFH register
839+
* @cpunum: cpu number to read
840+
* @reg: cppc register information
841+
* @val: place holder for return value
842+
*
843+
* Read bit_width bits from a specified address and bit_offset
844+
*
845+
* Return: 0 for success and error code
846+
*/
847+
int __weak cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
848+
{
849+
return -ENOTSUPP;
850+
}
851+
852+
/**
853+
* cpc_write_ffh() - Write FFH register
854+
* @cpunum: cpu number to write
855+
* @reg: cppc register information
856+
* @val: value to write
857+
*
858+
* Write value of bit_width bits to a specified address and bit_offset
859+
*
860+
* Return: 0 for success and error code
861+
*/
862+
int __weak cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
863+
{
864+
return -ENOTSUPP;
865+
}
866+
822867
/*
823868
* Since cpc_read and cpc_write are called while holding pcc_lock, it should be
824869
* as fast as possible. We have already mapped the PCC subspace during init, so
825870
* we can directly write to it.
826871
*/
827872

828-
static int cpc_read(struct cpc_register_resource *reg_res, u64 *val)
873+
static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
829874
{
830875
int ret_val = 0;
831876
void __iomem *vaddr = 0;
@@ -841,6 +886,8 @@ static int cpc_read(struct cpc_register_resource *reg_res, u64 *val)
841886
vaddr = GET_PCC_VADDR(reg->address);
842887
else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
843888
vaddr = reg_res->sys_mem_vaddr;
889+
else if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
890+
return cpc_read_ffh(cpu, reg, val);
844891
else
845892
return acpi_os_read_memory((acpi_physical_address)reg->address,
846893
val, reg->bit_width);
@@ -867,7 +914,7 @@ static int cpc_read(struct cpc_register_resource *reg_res, u64 *val)
867914
return ret_val;
868915
}
869916

870-
static int cpc_write(struct cpc_register_resource *reg_res, u64 val)
917+
static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
871918
{
872919
int ret_val = 0;
873920
void __iomem *vaddr = 0;
@@ -877,6 +924,8 @@ static int cpc_write(struct cpc_register_resource *reg_res, u64 val)
877924
vaddr = GET_PCC_VADDR(reg->address);
878925
else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
879926
vaddr = reg_res->sys_mem_vaddr;
927+
else if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
928+
return cpc_write_ffh(cpu, reg, val);
880929
else
881930
return acpi_os_write_memory((acpi_physical_address)reg->address,
882931
val, reg->bit_width);
@@ -941,13 +990,13 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
941990
}
942991
}
943992

944-
cpc_read(highest_reg, &high);
993+
cpc_read(cpunum, highest_reg, &high);
945994
perf_caps->highest_perf = high;
946995

947-
cpc_read(lowest_reg, &low);
996+
cpc_read(cpunum, lowest_reg, &low);
948997
perf_caps->lowest_perf = low;
949998

950-
cpc_read(nom_perf, &nom);
999+
cpc_read(cpunum, nom_perf, &nom);
9511000
perf_caps->nominal_perf = nom;
9521001

9531002
if (!high || !low || !nom)
@@ -1004,9 +1053,9 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
10041053
}
10051054
}
10061055

1007-
cpc_read(delivered_reg, &delivered);
1008-
cpc_read(reference_reg, &reference);
1009-
cpc_read(ref_perf_reg, &ref_perf);
1056+
cpc_read(cpunum, delivered_reg, &delivered);
1057+
cpc_read(cpunum, reference_reg, &reference);
1058+
cpc_read(cpunum, ref_perf_reg, &ref_perf);
10101059

10111060
/*
10121061
* Per spec, if ctr_wrap_time optional register is unsupported, then the
@@ -1015,7 +1064,7 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
10151064
*/
10161065
ctr_wrap_time = (u64)(~((u64)0));
10171066
if (CPC_SUPPORTED(ctr_wrap_reg))
1018-
cpc_read(ctr_wrap_reg, &ctr_wrap_time);
1067+
cpc_read(cpunum, ctr_wrap_reg, &ctr_wrap_time);
10191068

10201069
if (!delivered || !reference || !ref_perf) {
10211070
ret = -EFAULT;
@@ -1082,7 +1131,7 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
10821131
* Skip writing MIN/MAX until Linux knows how to come up with
10831132
* useful values.
10841133
*/
1085-
cpc_write(desired_reg, perf_ctrls->desired_perf);
1134+
cpc_write(cpu, desired_reg, perf_ctrls->desired_perf);
10861135

10871136
if (CPC_IN_PCC(desired_reg))
10881137
up_read(&pcc_data.pcc_lock); /* END Phase-I */

0 commit comments

Comments
 (0)