Skip to content

Commit ab482f1

Browse files
Lifeng Zhengrafaeljw
authored andcommitted
ACPI: CPPC: Refactor register value get and set ABIs
Refactor register value get and set ABIs by using cppc_get_reg_val(), cppc_set_reg_val() and CPPC_REG_VAL_READ(). 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 e05c750 commit ab482f1

File tree

1 file changed

+7
-104
lines changed

1 file changed

+7
-104
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 7 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,44 +1608,14 @@ EXPORT_SYMBOL_GPL(cppc_set_epp_perf);
16081608
*/
16091609
int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps)
16101610
{
1611-
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum);
1612-
struct cpc_register_resource *auto_sel_reg;
1613-
u64 auto_sel;
1614-
1615-
if (!cpc_desc) {
1616-
pr_debug("No CPC descriptor for CPU:%d\n", cpunum);
1617-
return -ENODEV;
1618-
}
1619-
1620-
auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
1621-
1622-
if (!CPC_SUPPORTED(auto_sel_reg))
1623-
pr_warn_once("Autonomous mode is not unsupported!\n");
1624-
1625-
if (CPC_IN_PCC(auto_sel_reg)) {
1626-
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
1627-
struct cppc_pcc_data *pcc_ss_data = NULL;
1628-
int ret = 0;
1629-
1630-
if (pcc_ss_id < 0)
1631-
return -ENODEV;
1632-
1633-
pcc_ss_data = pcc_data[pcc_ss_id];
1634-
1635-
down_write(&pcc_ss_data->pcc_lock);
1636-
1637-
if (send_pcc_cmd(pcc_ss_id, CMD_READ) >= 0) {
1638-
cpc_read(cpunum, auto_sel_reg, &auto_sel);
1639-
perf_caps->auto_sel = (bool)auto_sel;
1640-
} else {
1641-
ret = -EIO;
1642-
}
1643-
1644-
up_write(&pcc_ss_data->pcc_lock);
1611+
u64 auto_sel;
1612+
int ret;
16451613

1614+
ret = cppc_get_reg_val(cpunum, AUTO_SEL_ENABLE, &auto_sel);
1615+
if (ret)
16461616
return ret;
1647-
}
16481617

1618+
perf_caps->auto_sel = (bool)auto_sel;
16491619
return 0;
16501620
}
16511621
EXPORT_SYMBOL_GPL(cppc_get_auto_sel_caps);
@@ -1657,43 +1627,7 @@ EXPORT_SYMBOL_GPL(cppc_get_auto_sel_caps);
16571627
*/
16581628
int cppc_set_auto_sel(int cpu, bool enable)
16591629
{
1660-
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
1661-
struct cpc_register_resource *auto_sel_reg;
1662-
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
1663-
struct cppc_pcc_data *pcc_ss_data = NULL;
1664-
int ret = -EINVAL;
1665-
1666-
if (!cpc_desc) {
1667-
pr_debug("No CPC descriptor for CPU:%d\n", cpu);
1668-
return -ENODEV;
1669-
}
1670-
1671-
auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
1672-
1673-
if (CPC_IN_PCC(auto_sel_reg)) {
1674-
if (pcc_ss_id < 0) {
1675-
pr_debug("Invalid pcc_ss_id\n");
1676-
return -ENODEV;
1677-
}
1678-
1679-
if (CPC_SUPPORTED(auto_sel_reg)) {
1680-
ret = cpc_write(cpu, auto_sel_reg, enable);
1681-
if (ret)
1682-
return ret;
1683-
}
1684-
1685-
pcc_ss_data = pcc_data[pcc_ss_id];
1686-
1687-
down_write(&pcc_ss_data->pcc_lock);
1688-
/* after writing CPC, transfer the ownership of PCC to platform */
1689-
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
1690-
up_write(&pcc_ss_data->pcc_lock);
1691-
} else {
1692-
ret = -ENOTSUPP;
1693-
pr_debug("_CPC in PCC is not supported\n");
1694-
}
1695-
1696-
return ret;
1630+
return cppc_set_reg_val(cpu, AUTO_SEL_ENABLE, enable);
16971631
}
16981632
EXPORT_SYMBOL_GPL(cppc_set_auto_sel);
16991633

@@ -1707,38 +1641,7 @@ EXPORT_SYMBOL_GPL(cppc_set_auto_sel);
17071641
*/
17081642
int cppc_set_enable(int cpu, bool enable)
17091643
{
1710-
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
1711-
struct cpc_register_resource *enable_reg;
1712-
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
1713-
struct cppc_pcc_data *pcc_ss_data = NULL;
1714-
int ret = -EINVAL;
1715-
1716-
if (!cpc_desc) {
1717-
pr_debug("No CPC descriptor for CPU:%d\n", cpu);
1718-
return -EINVAL;
1719-
}
1720-
1721-
enable_reg = &cpc_desc->cpc_regs[ENABLE];
1722-
1723-
if (CPC_IN_PCC(enable_reg)) {
1724-
1725-
if (pcc_ss_id < 0)
1726-
return -EIO;
1727-
1728-
ret = cpc_write(cpu, enable_reg, enable);
1729-
if (ret)
1730-
return ret;
1731-
1732-
pcc_ss_data = pcc_data[pcc_ss_id];
1733-
1734-
down_write(&pcc_ss_data->pcc_lock);
1735-
/* after writing CPC, transfer the ownership of PCC to platfrom */
1736-
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
1737-
up_write(&pcc_ss_data->pcc_lock);
1738-
return ret;
1739-
}
1740-
1741-
return cpc_write(cpu, enable_reg, enable);
1644+
return cppc_set_reg_val(cpu, ENABLE, enable);
17421645
}
17431646
EXPORT_SYMBOL_GPL(cppc_set_enable);
17441647

0 commit comments

Comments
 (0)