Skip to content

Commit e05c750

Browse files
Lifeng Zhengrafaeljw
authored andcommitted
ACPI: CPPC: Add cppc_set_reg_val()
Add cppc_set_reg_val() as a generic function for setting CPPC register values, with this features: 1. Check register. If a register is writeable, it must be a buffer and can not be null. 2. Extract the operations if register is in PCC out as cppc_set_reg_val_in_pcc(). This function can be used to reduce some existing code duplication. 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 b5ef45e commit e05c750

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,55 @@ static int cppc_get_reg_val(int cpu, enum cppc_regs reg_idx, u64 *val)
12321232
return cpc_read(cpu, reg, val);
12331233
}
12341234

1235+
static int cppc_set_reg_val_in_pcc(int cpu, struct cpc_register_resource *reg, u64 val)
1236+
{
1237+
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
1238+
struct cppc_pcc_data *pcc_ss_data = NULL;
1239+
int ret;
1240+
1241+
if (pcc_ss_id < 0) {
1242+
pr_debug("Invalid pcc_ss_id\n");
1243+
return -ENODEV;
1244+
}
1245+
1246+
ret = cpc_write(cpu, reg, val);
1247+
if (ret)
1248+
return ret;
1249+
1250+
pcc_ss_data = pcc_data[pcc_ss_id];
1251+
1252+
down_write(&pcc_ss_data->pcc_lock);
1253+
/* after writing CPC, transfer the ownership of PCC to platform */
1254+
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
1255+
up_write(&pcc_ss_data->pcc_lock);
1256+
1257+
return ret;
1258+
}
1259+
1260+
static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)
1261+
{
1262+
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
1263+
struct cpc_register_resource *reg;
1264+
1265+
if (!cpc_desc) {
1266+
pr_debug("No CPC descriptor for CPU:%d\n", cpu);
1267+
return -ENODEV;
1268+
}
1269+
1270+
reg = &cpc_desc->cpc_regs[reg_idx];
1271+
1272+
/* if a register is writeable, it must be a buffer and not null */
1273+
if ((reg->type != ACPI_TYPE_BUFFER) || IS_NULL_REG(&reg->cpc_entry.reg)) {
1274+
pr_debug("CPC register is not supported\n");
1275+
return -EOPNOTSUPP;
1276+
}
1277+
1278+
if (CPC_IN_PCC(reg))
1279+
return cppc_set_reg_val_in_pcc(cpu, reg, val);
1280+
1281+
return cpc_write(cpu, reg, val);
1282+
}
1283+
12351284
/**
12361285
* cppc_get_desired_perf - Get the desired performance register value.
12371286
* @cpunum: CPU from which to get desired performance.

0 commit comments

Comments
 (0)