Skip to content

Commit f35e5b3

Browse files
Lifeng Zhengrafaeljw
authored andcommitted
ACPI: CPPC: Add three functions related to autonomous selection
cppc_set_epp() - write energy performance preference register value, based on ACPI 6.5, s8.4.6.1.7 cppc_get_auto_act_window() - read autonomous activity window register value, based on ACPI 6.5, s8.4.6.1.6 cppc_set_auto_act_window() - write autonomous activity window register value, based on ACPI 6.5, s8.4.6.1.6 Reviewed-by: Pierre Gondois <[email protected]> Signed-off-by: Lifeng Zheng <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2605e4a commit f35e5b3

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,89 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
16011601
}
16021602
EXPORT_SYMBOL_GPL(cppc_set_epp_perf);
16031603

1604+
/**
1605+
* cppc_set_epp() - Write the EPP register.
1606+
* @cpu: CPU on which to write register.
1607+
* @epp_val: Value to write to the EPP register.
1608+
*/
1609+
int cppc_set_epp(int cpu, u64 epp_val)
1610+
{
1611+
if (epp_val > CPPC_ENERGY_PERF_MAX)
1612+
return -EINVAL;
1613+
1614+
return cppc_set_reg_val(cpu, ENERGY_PERF, epp_val);
1615+
}
1616+
EXPORT_SYMBOL_GPL(cppc_set_epp);
1617+
1618+
/**
1619+
* cppc_get_auto_act_window() - Read autonomous activity window register.
1620+
* @cpu: CPU from which to read register.
1621+
* @auto_act_window: Return address.
1622+
*
1623+
* According to ACPI 6.5, s8.4.6.1.6, the value read from the autonomous
1624+
* activity window register consists of two parts: a 7 bits value indicate
1625+
* significand and a 3 bits value indicate exponent.
1626+
*/
1627+
int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
1628+
{
1629+
unsigned int exp;
1630+
u64 val, sig;
1631+
int ret;
1632+
1633+
if (auto_act_window == NULL)
1634+
return -EINVAL;
1635+
1636+
ret = cppc_get_reg_val(cpu, AUTO_ACT_WINDOW, &val);
1637+
if (ret)
1638+
return ret;
1639+
1640+
sig = val & CPPC_AUTO_ACT_WINDOW_MAX_SIG;
1641+
exp = (val >> CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) & CPPC_AUTO_ACT_WINDOW_MAX_EXP;
1642+
*auto_act_window = sig * int_pow(10, exp);
1643+
1644+
return 0;
1645+
}
1646+
EXPORT_SYMBOL_GPL(cppc_get_auto_act_window);
1647+
1648+
/**
1649+
* cppc_set_auto_act_window() - Write autonomous activity window register.
1650+
* @cpu: CPU on which to write register.
1651+
* @auto_act_window: usec value to write to the autonomous activity window register.
1652+
*
1653+
* According to ACPI 6.5, s8.4.6.1.6, the value to write to the autonomous
1654+
* activity window register consists of two parts: a 7 bits value indicate
1655+
* significand and a 3 bits value indicate exponent.
1656+
*/
1657+
int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
1658+
{
1659+
/* The max value to store is 1270000000 */
1660+
u64 max_val = CPPC_AUTO_ACT_WINDOW_MAX_SIG * int_pow(10, CPPC_AUTO_ACT_WINDOW_MAX_EXP);
1661+
int exp = 0;
1662+
u64 val;
1663+
1664+
if (auto_act_window > max_val)
1665+
return -EINVAL;
1666+
1667+
/*
1668+
* The max significand is 127, when auto_act_window is larger than
1669+
* 129, discard the precision of the last digit and increase the
1670+
* exponent by 1.
1671+
*/
1672+
while (auto_act_window > CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH) {
1673+
auto_act_window /= 10;
1674+
exp += 1;
1675+
}
1676+
1677+
/* For 128 and 129, cut it to 127. */
1678+
if (auto_act_window > CPPC_AUTO_ACT_WINDOW_MAX_SIG)
1679+
auto_act_window = CPPC_AUTO_ACT_WINDOW_MAX_SIG;
1680+
1681+
val = (exp << CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) + auto_act_window;
1682+
1683+
return cppc_set_reg_val(cpu, AUTO_ACT_WINDOW, val);
1684+
}
1685+
EXPORT_SYMBOL_GPL(cppc_set_auto_act_window);
1686+
16041687
/**
16051688
* cppc_get_auto_sel() - Read autonomous selection register.
16061689
* @cpu: CPU from which to read register.

include/acpi/cppc_acpi.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
#define CMD_READ 0
3333
#define CMD_WRITE 1
3434

35+
#define CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE (7)
36+
#define CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE (3)
37+
#define CPPC_AUTO_ACT_WINDOW_MAX_SIG ((1 << CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) - 1)
38+
#define CPPC_AUTO_ACT_WINDOW_MAX_EXP ((1 << CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE) - 1)
39+
/* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */
40+
#define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129
41+
42+
#define CPPC_ENERGY_PERF_MAX (0xFF)
43+
3544
/* Each register has the folowing format. */
3645
struct cpc_reg {
3746
u8 descriptor;
@@ -159,6 +168,9 @@ extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
159168
extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
160169
extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
161170
extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
171+
extern int cppc_set_epp(int cpu, u64 epp_val);
172+
extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);
173+
extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window);
162174
extern int cppc_get_auto_sel(int cpu, bool *enable);
163175
extern int cppc_set_auto_sel(int cpu, bool enable);
164176
extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
@@ -229,6 +241,18 @@ static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
229241
{
230242
return -EOPNOTSUPP;
231243
}
244+
static inline int cppc_set_epp(int cpu, u64 epp_val)
245+
{
246+
return -EOPNOTSUPP;
247+
}
248+
static inline int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
249+
{
250+
return -EOPNOTSUPP;
251+
}
252+
static inline int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
253+
{
254+
return -EOPNOTSUPP;
255+
}
232256
static inline int cppc_get_auto_sel(int cpu, bool *enable)
233257
{
234258
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)