Skip to content

Commit a2c32fa

Browse files
Victor Dingrafaeljw
authored andcommitted
powercap/intel_rapl_msr: Convert rapl_msr_priv into pointer
Changes the static struct rapl_msr_priv to a pointer to allow using a different RAPL MSR interface, preparing for supporting AMD's RAPL MSR interface. No functional changes. Signed-off-by: Victor Ding <[email protected]> Acked-by: Kim Phillips <[email protected]> [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 298ed2b commit a2c32fa

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

drivers/powercap/intel_rapl_msr.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
#define MSR_VR_CURRENT_CONFIG 0x00000601
3232

3333
/* private data for RAPL MSR Interface */
34-
static struct rapl_if_priv rapl_msr_priv = {
34+
static struct rapl_if_priv *rapl_msr_priv;
35+
36+
static struct rapl_if_priv rapl_msr_priv_intel = {
3537
.reg_unit = MSR_RAPL_POWER_UNIT,
3638
.regs[RAPL_DOMAIN_PACKAGE] = {
3739
MSR_PKG_POWER_LIMIT, MSR_PKG_ENERGY_STATUS, MSR_PKG_PERF_STATUS, 0, MSR_PKG_POWER_INFO },
@@ -58,9 +60,9 @@ static int rapl_cpu_online(unsigned int cpu)
5860
{
5961
struct rapl_package *rp;
6062

61-
rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
63+
rp = rapl_find_package_domain(cpu, rapl_msr_priv);
6264
if (!rp) {
63-
rp = rapl_add_package(cpu, &rapl_msr_priv);
65+
rp = rapl_add_package(cpu, rapl_msr_priv);
6466
if (IS_ERR(rp))
6567
return PTR_ERR(rp);
6668
}
@@ -73,7 +75,7 @@ static int rapl_cpu_down_prep(unsigned int cpu)
7375
struct rapl_package *rp;
7476
int lead_cpu;
7577

76-
rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
78+
rp = rapl_find_package_domain(cpu, rapl_msr_priv);
7779
if (!rp)
7880
return 0;
7981

@@ -136,40 +138,41 @@ static int rapl_msr_probe(struct platform_device *pdev)
136138
const struct x86_cpu_id *id = x86_match_cpu(pl4_support_ids);
137139
int ret;
138140

139-
rapl_msr_priv.read_raw = rapl_msr_read_raw;
140-
rapl_msr_priv.write_raw = rapl_msr_write_raw;
141+
rapl_msr_priv = &rapl_msr_priv_intel;
142+
rapl_msr_priv->read_raw = rapl_msr_read_raw;
143+
rapl_msr_priv->write_raw = rapl_msr_write_raw;
141144

142145
if (id) {
143-
rapl_msr_priv.limits[RAPL_DOMAIN_PACKAGE] = 3;
144-
rapl_msr_priv.regs[RAPL_DOMAIN_PACKAGE][RAPL_DOMAIN_REG_PL4] =
146+
rapl_msr_priv->limits[RAPL_DOMAIN_PACKAGE] = 3;
147+
rapl_msr_priv->regs[RAPL_DOMAIN_PACKAGE][RAPL_DOMAIN_REG_PL4] =
145148
MSR_VR_CURRENT_CONFIG;
146149
pr_info("PL4 support detected.\n");
147150
}
148151

149-
rapl_msr_priv.control_type = powercap_register_control_type(NULL, "intel-rapl", NULL);
150-
if (IS_ERR(rapl_msr_priv.control_type)) {
152+
rapl_msr_priv->control_type = powercap_register_control_type(NULL, "intel-rapl", NULL);
153+
if (IS_ERR(rapl_msr_priv->control_type)) {
151154
pr_debug("failed to register powercap control_type.\n");
152-
return PTR_ERR(rapl_msr_priv.control_type);
155+
return PTR_ERR(rapl_msr_priv->control_type);
153156
}
154157

155158
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powercap/rapl:online",
156159
rapl_cpu_online, rapl_cpu_down_prep);
157160
if (ret < 0)
158161
goto out;
159-
rapl_msr_priv.pcap_rapl_online = ret;
162+
rapl_msr_priv->pcap_rapl_online = ret;
160163

161164
return 0;
162165

163166
out:
164167
if (ret)
165-
powercap_unregister_control_type(rapl_msr_priv.control_type);
168+
powercap_unregister_control_type(rapl_msr_priv->control_type);
166169
return ret;
167170
}
168171

169172
static int rapl_msr_remove(struct platform_device *pdev)
170173
{
171-
cpuhp_remove_state(rapl_msr_priv.pcap_rapl_online);
172-
powercap_unregister_control_type(rapl_msr_priv.control_type);
174+
cpuhp_remove_state(rapl_msr_priv->pcap_rapl_online);
175+
powercap_unregister_control_type(rapl_msr_priv->control_type);
173176
return 0;
174177
}
175178

0 commit comments

Comments
 (0)