* [PATCH v1 1/6] powercap: intel_rapl: Remove unused AVERAGE_POWER primitive
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 2/6] powercap: intel_rapl: Remove unused macro definitions Kuppuswamy Sathyanarayanan
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
The AVERAGE_POWER primitive and RAPL_PRIMITIVE_DERIVED flag are not
used anywhere in the code. Remove them to simplify the primitive
handling logic.
No functional changes.
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 13 -------------
include/linux/intel_rapl.h | 1 -
2 files changed, 14 deletions(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index 2b5c587b222b..8c838e2e457d 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -89,7 +89,6 @@
#define TPMI_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(60, 54)
/* Non HW constants */
-#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */
#define RAPL_PRIMITIVE_DUMMY BIT(2)
#define ENERGY_UNIT_SCALE 1000 /* scale from driver unit to powercap unit */
@@ -700,9 +699,6 @@ static struct rapl_primitive_info rpi_msr[NR_RAPL_PRIMITIVES] = {
19, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
[PSYS_TIME_WINDOW2] = PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW2, PSYS_TIME_WINDOW2_MASK,
51, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
- /* non-hardware */
- [AVERAGE_POWER] = PRIMITIVE_INFO_INIT(AVERAGE_POWER, 0, 0, 0, POWER_UNIT,
- RAPL_PRIMITIVE_DERIVED),
};
/* RAPL primitives for TPMI I/F */
@@ -742,9 +738,6 @@ static struct rapl_primitive_info rpi_tpmi[NR_RAPL_PRIMITIVES] = {
54, RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
[THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME, PERF_STATUS_THROTTLE_TIME_MASK,
0, RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
- /* non-hardware */
- [AVERAGE_POWER] = PRIMITIVE_INFO_INIT(AVERAGE_POWER, 0, 0, 0, POWER_UNIT,
- RAPL_PRIMITIVE_DERIVED),
};
static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
@@ -837,12 +830,6 @@ static int rapl_read_data_raw(struct rapl_domain *rd,
if (!ra.reg.val)
return -EINVAL;
- /* non-hardware data are collected by the polling thread */
- if (rpi->flag & RAPL_PRIMITIVE_DERIVED) {
- *data = rd->rdd.primitives[prim];
- return 0;
- }
-
ra.mask = rpi->mask;
if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra, pmu_ctx)) {
diff --git a/include/linux/intel_rapl.h b/include/linux/intel_rapl.h
index 6d694099a3ad..9e6bd654be1f 100644
--- a/include/linux/intel_rapl.h
+++ b/include/linux/intel_rapl.h
@@ -77,7 +77,6 @@ enum rapl_primitives {
PSYS_TIME_WINDOW1,
PSYS_TIME_WINDOW2,
/* below are not raw primitive data */
- AVERAGE_POWER,
NR_RAPL_PRIMITIVES,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 2/6] powercap: intel_rapl: Remove unused macro definitions
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 1/6] powercap: intel_rapl: Remove unused AVERAGE_POWER primitive Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 3/6] powercap: intel_rapl: Move primitive info to header for interface drivers Kuppuswamy Sathyanarayanan
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
Remove the following unused macro definitions from the RAPL common
driver:
* DOMAIN_STATE_INACTIVE and DOMAIN_STATE_POWER_LIMIT_SET
* IOSF_CPU_POWER_BUDGET_CTL_BYT and IOSF_CPU_POWER_BUDGET_CTL_TNG
* MAX_PRIM_NAME
No functional changes.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index 8c838e2e457d..fdcac4a173a8 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -96,15 +96,7 @@
/* per domain data, some are optional */
#define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2)
-#define DOMAIN_STATE_INACTIVE BIT(0)
-#define DOMAIN_STATE_POWER_LIMIT_SET BIT(1)
-
-/* Sideband MBI registers */
-#define IOSF_CPU_POWER_BUDGET_CTL_BYT 0x02
-#define IOSF_CPU_POWER_BUDGET_CTL_TNG 0xDF
-
#define PACKAGE_PLN_INT_SAVED BIT(0)
-#define MAX_PRIM_NAME 32
#define RAPL_EVENT_MASK GENMASK(7, 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 3/6] powercap: intel_rapl: Move primitive info to header for interface drivers
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 1/6] powercap: intel_rapl: Remove unused AVERAGE_POWER primitive Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 2/6] powercap: intel_rapl: Remove unused macro definitions Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 4/6] powercap: intel_rapl: Move TPMI primitives to TPMI driver Kuppuswamy Sathyanarayanan
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
RAPL primitive information varies across different RAPL interfaces
(MSR, TPMI, MMIO). Keeping them in the common code adds no benefit, but
requires interface-specific handling logic and makes the common layer
unnecessarily complex.
Move the primitive info infrastructure to the shared header to allow
interface drivers to configure RAPL primitives. Specific changes:
1. Move struct rapl_primitive_info, enum unit_type, and
PRIMITIVE_INFO_INIT macro to intel_rapl.h.
2. Change the @rpi field in struct rapl_if_priv from void * to
struct rapl_primitive_info * to improve type safety and eliminate
unnecessary casts.
No functional changes. This is a preparatory refactoring to allow
interface drivers to supply their own RAPL primitive settings.
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 32 ++--------------------------
include/linux/intel_rapl.h | 32 ++++++++++++++++++++++++++--
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index fdcac4a173a8..d6c2819b1212 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -100,13 +100,6 @@
#define RAPL_EVENT_MASK GENMASK(7, 0)
-enum unit_type {
- ARBITRARY_UNIT, /* no translation */
- POWER_UNIT,
- ENERGY_UNIT,
- TIME_UNIT,
-};
-
static const char *pl_names[NR_POWER_LIMITS] = {
[POWER_LIMIT1] = "long_term",
[POWER_LIMIT2] = "short_term",
@@ -208,27 +201,6 @@ static const struct rapl_defaults *get_defaults(struct rapl_package *rp)
return rp->priv->defaults;
}
-/* per domain data. used to describe individual knobs such that access function
- * can be consolidated into one instead of many inline functions.
- */
-struct rapl_primitive_info {
- const char *name;
- u64 mask;
- int shift;
- enum rapl_domain_reg_id id;
- enum unit_type unit;
- u32 flag;
-};
-
-#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \
- .name = #p, \
- .mask = m, \
- .shift = s, \
- .id = i, \
- .unit = u, \
- .flag = f \
- }
-
static void rapl_init_domains(struct rapl_package *rp);
static int rapl_read_data_raw(struct rapl_domain *rd,
enum rapl_primitives prim,
@@ -748,10 +720,10 @@ static int rapl_config(struct rapl_package *rp)
/* MMIO I/F shares the same register layout as MSR registers */
case RAPL_IF_MMIO:
case RAPL_IF_MSR:
- rp->priv->rpi = (void *)rpi_msr;
+ rp->priv->rpi = rpi_msr;
break;
case RAPL_IF_TPMI:
- rp->priv->rpi = (void *)rpi_tpmi;
+ rp->priv->rpi = rpi_tpmi;
break;
default:
return -EINVAL;
diff --git a/include/linux/intel_rapl.h b/include/linux/intel_rapl.h
index 9e6bd654be1f..01f290de3586 100644
--- a/include/linux/intel_rapl.h
+++ b/include/linux/intel_rapl.h
@@ -137,6 +137,34 @@ struct rapl_defaults {
bool spr_psys_bits;
};
+#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \
+ .name = #p, \
+ .mask = m, \
+ .shift = s, \
+ .id = i, \
+ .unit = u, \
+ .flag = f \
+ }
+
+enum unit_type {
+ ARBITRARY_UNIT, /* no translation */
+ POWER_UNIT,
+ ENERGY_UNIT,
+ TIME_UNIT,
+};
+
+/* per domain data. used to describe individual knobs such that access function
+ * can be consolidated into one instead of many inline functions.
+ */
+struct rapl_primitive_info {
+ const char *name;
+ u64 mask;
+ int shift;
+ enum rapl_domain_reg_id id;
+ enum unit_type unit;
+ u32 flag;
+};
+
/**
* struct rapl_if_priv: private data for different RAPL interfaces
* @control_type: Each RAPL interface must have its own powercap
@@ -152,7 +180,7 @@ struct rapl_defaults {
* @write_raw: Callback for writing RAPL interface specific
* registers.
* @defaults: pointer to default settings
- * @rpi: internal pointer to interface primitive info
+ * @rpi: pointer to interface primitive info
*/
struct rapl_if_priv {
enum rapl_if_type type;
@@ -164,7 +192,7 @@ struct rapl_if_priv {
int (*read_raw)(int id, struct reg_action *ra, bool pmu_ctx);
int (*write_raw)(int id, struct reg_action *ra);
const struct rapl_defaults *defaults;
- void *rpi;
+ struct rapl_primitive_info *rpi;
};
#ifdef CONFIG_PERF_EVENTS
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 4/6] powercap: intel_rapl: Move TPMI primitives to TPMI driver
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
` (2 preceding siblings ...)
2026-03-13 18:53 ` [PATCH v1 3/6] powercap: intel_rapl: Move primitive info to header for interface drivers Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 5/6] thermal: intel: int340x: processor: Move MMIO primitives to MMIO driver Kuppuswamy Sathyanarayanan
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
TPMI-specific RAPL primitives differ from those used by MSR and MMIO
interfaces. Keeping them in the common RAPL driver requires
interface-specific handling logic and makes the common layer
unnecessarily complex.
Move the TPMI primitive definitions and associated bitmasks into the
TPMI interface driver. This change includes:
1. Move TPMI-specific bitmask definitions from intel_rapl_common.c to
intel_rapl_tpmi.c.
2. Add TPMI-local struct rapl_primitive_info instance and assign it to
priv->rpi during TPMI probe.
3. Remove the RAPL TPMI related definitions from the common driver.
No functional changes are intended.
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 51 --------------------------
drivers/powercap/intel_rapl_tpmi.c | 53 ++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 51 deletions(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index d6c2819b1212..545b811fa930 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -79,15 +79,6 @@
#define PSYS_TIME_WINDOW1_MASK GENMASK_ULL(25, 19)
#define PSYS_TIME_WINDOW2_MASK GENMASK_ULL(57, 51)
-/* bitmasks for RAPL TPMI, used by primitive access functions */
-#define TPMI_POWER_LIMIT_MASK GENMASK_ULL(17, 0)
-#define TPMI_POWER_LIMIT_ENABLE BIT_ULL(62)
-#define TPMI_TIME_WINDOW_MASK GENMASK_ULL(24, 18)
-#define TPMI_INFO_SPEC_MASK GENMASK_ULL(17, 0)
-#define TPMI_INFO_MIN_MASK GENMASK_ULL(35, 18)
-#define TPMI_INFO_MAX_MASK GENMASK_ULL(53, 36)
-#define TPMI_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(60, 54)
-
/* Non HW constants */
#define RAPL_PRIMITIVE_DUMMY BIT(2)
@@ -665,45 +656,6 @@ static struct rapl_primitive_info rpi_msr[NR_RAPL_PRIMITIVES] = {
51, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
};
-/* RAPL primitives for TPMI I/F */
-static struct rapl_primitive_info rpi_tpmi[NR_RAPL_PRIMITIVES] = {
- /* name, mask, shift, msr index, unit divisor */
- [POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, TPMI_POWER_LIMIT_MASK, 0,
- RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
- [POWER_LIMIT2] = PRIMITIVE_INFO_INIT(POWER_LIMIT2, TPMI_POWER_LIMIT_MASK, 0,
- RAPL_DOMAIN_REG_PL2, POWER_UNIT, 0),
- [POWER_LIMIT4] = PRIMITIVE_INFO_INIT(POWER_LIMIT4, TPMI_POWER_LIMIT_MASK, 0,
- RAPL_DOMAIN_REG_PL4, POWER_UNIT, 0),
- [ENERGY_COUNTER] = PRIMITIVE_INFO_INIT(ENERGY_COUNTER, ENERGY_STATUS_MASK, 0,
- RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
- [PL1_LOCK] = PRIMITIVE_INFO_INIT(PL1_LOCK, POWER_HIGH_LOCK, 63,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL2_LOCK] = PRIMITIVE_INFO_INIT(PL2_LOCK, POWER_HIGH_LOCK, 63,
- RAPL_DOMAIN_REG_PL2, ARBITRARY_UNIT, 0),
- [PL4_LOCK] = PRIMITIVE_INFO_INIT(PL4_LOCK, POWER_HIGH_LOCK, 63,
- RAPL_DOMAIN_REG_PL4, ARBITRARY_UNIT, 0),
- [PL1_ENABLE] = PRIMITIVE_INFO_INIT(PL1_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL2_ENABLE] = PRIMITIVE_INFO_INIT(PL2_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
- RAPL_DOMAIN_REG_PL2, ARBITRARY_UNIT, 0),
- [PL4_ENABLE] = PRIMITIVE_INFO_INIT(PL4_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
- RAPL_DOMAIN_REG_PL4, ARBITRARY_UNIT, 0),
- [TIME_WINDOW1] = PRIMITIVE_INFO_INIT(TIME_WINDOW1, TPMI_TIME_WINDOW_MASK, 18,
- RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
- [TIME_WINDOW2] = PRIMITIVE_INFO_INIT(TIME_WINDOW2, TPMI_TIME_WINDOW_MASK, 18,
- RAPL_DOMAIN_REG_PL2, TIME_UNIT, 0),
- [THERMAL_SPEC_POWER] = PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER, TPMI_INFO_SPEC_MASK, 0,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MAX_POWER] = PRIMITIVE_INFO_INIT(MAX_POWER, TPMI_INFO_MAX_MASK, 36,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MIN_POWER] = PRIMITIVE_INFO_INIT(MIN_POWER, TPMI_INFO_MIN_MASK, 18,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MAX_TIME_WINDOW] = PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW, TPMI_INFO_MAX_TIME_WIN_MASK,
- 54, RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
- [THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME, PERF_STATUS_THROTTLE_TIME_MASK,
- 0, RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
-};
-
static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
{
struct rapl_primitive_info *rpi = rp->priv->rpi;
@@ -722,9 +674,6 @@ static int rapl_config(struct rapl_package *rp)
case RAPL_IF_MSR:
rp->priv->rpi = rpi_msr;
break;
- case RAPL_IF_TPMI:
- rp->priv->rpi = rpi_tpmi;
- break;
default:
return -EINVAL;
}
diff --git a/drivers/powercap/intel_rapl_tpmi.c b/drivers/powercap/intel_rapl_tpmi.c
index c06d687366fc..7f41491d9cd1 100644
--- a/drivers/powercap/intel_rapl_tpmi.c
+++ b/drivers/powercap/intel_rapl_tpmi.c
@@ -62,6 +62,58 @@ static DEFINE_MUTEX(tpmi_rapl_lock);
static struct powercap_control_type *tpmi_control_type;
+/* bitmasks for RAPL TPMI, used by primitive access functions */
+#define TPMI_POWER_LIMIT_MASK GENMASK_ULL(17, 0)
+#define TPMI_POWER_LIMIT_ENABLE BIT_ULL(62)
+#define TPMI_POWER_HIGH_LOCK BIT_ULL(63)
+#define TPMI_TIME_WINDOW_MASK GENMASK_ULL(24, 18)
+#define TPMI_INFO_SPEC_MASK GENMASK_ULL(17, 0)
+#define TPMI_INFO_MIN_MASK GENMASK_ULL(35, 18)
+#define TPMI_INFO_MAX_MASK GENMASK_ULL(53, 36)
+#define TPMI_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(60, 54)
+#define TPMI_ENERGY_STATUS_MASK GENMASK(31, 0)
+#define TPMI_PERF_STATUS_THROTTLE_TIME_MASK GENMASK(31, 0)
+
+/* RAPL primitives for TPMI I/F */
+static struct rapl_primitive_info rpi_tpmi[NR_RAPL_PRIMITIVES] = {
+ /* name, mask, shift, msr index, unit divisor */
+ [POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, TPMI_POWER_LIMIT_MASK, 0,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [POWER_LIMIT2] = PRIMITIVE_INFO_INIT(POWER_LIMIT2, TPMI_POWER_LIMIT_MASK, 0,
+ RAPL_DOMAIN_REG_PL2, POWER_UNIT, 0),
+ [POWER_LIMIT4] = PRIMITIVE_INFO_INIT(POWER_LIMIT4, TPMI_POWER_LIMIT_MASK, 0,
+ RAPL_DOMAIN_REG_PL4, POWER_UNIT, 0),
+ [ENERGY_COUNTER] = PRIMITIVE_INFO_INIT(ENERGY_COUNTER, TPMI_ENERGY_STATUS_MASK, 0,
+ RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
+ [PL1_LOCK] = PRIMITIVE_INFO_INIT(PL1_LOCK, TPMI_POWER_HIGH_LOCK, 63,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_LOCK] = PRIMITIVE_INFO_INIT(PL2_LOCK, TPMI_POWER_HIGH_LOCK, 63,
+ RAPL_DOMAIN_REG_PL2, ARBITRARY_UNIT, 0),
+ [PL4_LOCK] = PRIMITIVE_INFO_INIT(PL4_LOCK, TPMI_POWER_HIGH_LOCK, 63,
+ RAPL_DOMAIN_REG_PL4, ARBITRARY_UNIT, 0),
+ [PL1_ENABLE] = PRIMITIVE_INFO_INIT(PL1_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_ENABLE] = PRIMITIVE_INFO_INIT(PL2_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
+ RAPL_DOMAIN_REG_PL2, ARBITRARY_UNIT, 0),
+ [PL4_ENABLE] = PRIMITIVE_INFO_INIT(PL4_ENABLE, TPMI_POWER_LIMIT_ENABLE, 62,
+ RAPL_DOMAIN_REG_PL4, ARBITRARY_UNIT, 0),
+ [TIME_WINDOW1] = PRIMITIVE_INFO_INIT(TIME_WINDOW1, TPMI_TIME_WINDOW_MASK, 18,
+ RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [TIME_WINDOW2] = PRIMITIVE_INFO_INIT(TIME_WINDOW2, TPMI_TIME_WINDOW_MASK, 18,
+ RAPL_DOMAIN_REG_PL2, TIME_UNIT, 0),
+ [THERMAL_SPEC_POWER] = PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER, TPMI_INFO_SPEC_MASK, 0,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_POWER] = PRIMITIVE_INFO_INIT(MAX_POWER, TPMI_INFO_MAX_MASK, 36,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MIN_POWER] = PRIMITIVE_INFO_INIT(MIN_POWER, TPMI_INFO_MIN_MASK, 18,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_TIME_WINDOW] = PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW, TPMI_INFO_MAX_TIME_WIN_MASK,
+ 54, RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
+ [THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME,
+ TPMI_PERF_STATUS_THROTTLE_TIME_MASK,
+ 0, RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
+};
+
static int tpmi_rapl_read_raw(int id, struct reg_action *ra, bool atomic)
{
if (!ra->reg.mmio)
@@ -344,6 +396,7 @@ static int intel_rapl_tpmi_probe(struct auxiliary_device *auxdev,
trp->priv.write_raw = tpmi_rapl_write_raw;
trp->priv.control_type = tpmi_control_type;
trp->priv.defaults = &defaults_tpmi;
+ trp->priv.rpi = rpi_tpmi;
/* RAPL TPMI I/F is per physical package */
trp->rp = rapl_find_package_domain(info->package_id, &trp->priv, false);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 5/6] thermal: intel: int340x: processor: Move MMIO primitives to MMIO driver
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
` (3 preceding siblings ...)
2026-03-13 18:53 ` [PATCH v1 4/6] powercap: intel_rapl: Move TPMI primitives to TPMI driver Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-13 18:53 ` [PATCH v1 6/6] powercap: intel_rapl: Move MSR primitives to MSR driver Kuppuswamy Sathyanarayanan
2026-03-20 17:02 ` [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers srinivas pandruvada
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
MMIO-specific primitives differ from those used by the TPMI interface.
The MSR and MMIO interfaces shared the same primitives in the common
driver, but MMIO does not require many MSR-specific entries (like PSYS).
Keeping these in the common driver does not add any value and requires
interface-specific handling logic that makes the common layer
unnecessarily complex.
Move the MMIO primitive definitions and associated bitmasks into the
MMIO interface driver. This change includes:
1. Add MMIO-local struct rapl_primitive_info instance without
MSR-specific entries and assign it to priv->rpi during MMIO
initialization.
2. Remove the RAPL MMIO case from rapl_config() in the common driver.
No functional changes are intended.
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 1 -
.../int340x_thermal/processor_thermal_rapl.c | 72 +++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index 545b811fa930..ffa3f95d8aa2 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -670,7 +670,6 @@ static int rapl_config(struct rapl_package *rp)
{
switch (rp->priv->type) {
/* MMIO I/F shares the same register layout as MSR registers */
- case RAPL_IF_MMIO:
case RAPL_IF_MSR:
rp->priv->rpi = rpi_msr;
break;
diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c
index 5dbeb0a43c8c..f8b9745c1b8a 100644
--- a/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c
+++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c
@@ -11,6 +11,77 @@
static struct rapl_if_priv rapl_mmio_priv;
+/* bitmasks for RAPL MSRs, used by primitive access functions */
+#define MMIO_ENERGY_STATUS_MASK GENMASK(31, 0)
+
+#define MMIO_POWER_LIMIT1_MASK GENMASK(14, 0)
+#define MMIO_POWER_LIMIT1_ENABLE BIT(15)
+#define MMIO_POWER_LIMIT1_CLAMP BIT(16)
+
+#define MMIO_POWER_LIMIT2_MASK GENMASK_ULL(46, 32)
+#define MMIO_POWER_LIMIT2_ENABLE BIT_ULL(47)
+#define MMIO_POWER_LIMIT2_CLAMP BIT_ULL(48)
+
+#define MMIO_POWER_LOW_LOCK BIT(31)
+#define MMIO_POWER_HIGH_LOCK BIT_ULL(63)
+
+#define MMIO_POWER_LIMIT4_MASK GENMASK(12, 0)
+
+#define MMIO_TIME_WINDOW1_MASK GENMASK_ULL(23, 17)
+#define MMIO_TIME_WINDOW2_MASK GENMASK_ULL(55, 49)
+
+#define MMIO_POWER_INFO_MAX_MASK GENMASK_ULL(46, 32)
+#define MMIO_POWER_INFO_MIN_MASK GENMASK_ULL(30, 16)
+#define MMIO_POWER_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(53, 48)
+#define MMIO_POWER_INFO_THERMAL_SPEC_MASK GENMASK(14, 0)
+
+#define MMIO_PERF_STATUS_THROTTLE_TIME_MASK GENMASK(31, 0)
+#define MMIO_PP_POLICY_MASK GENMASK(4, 0)
+
+/* RAPL primitives for MMIO I/F */
+static struct rapl_primitive_info rpi_mmio[NR_RAPL_PRIMITIVES] = {
+ /* name, mask, shift, msr index, unit divisor */
+ [POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, MMIO_POWER_LIMIT1_MASK, 0,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [POWER_LIMIT2] = PRIMITIVE_INFO_INIT(POWER_LIMIT2, MMIO_POWER_LIMIT2_MASK, 32,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [POWER_LIMIT4] = PRIMITIVE_INFO_INIT(POWER_LIMIT4, MMIO_POWER_LIMIT4_MASK, 0,
+ RAPL_DOMAIN_REG_PL4, POWER_UNIT, 0),
+ [ENERGY_COUNTER] = PRIMITIVE_INFO_INIT(ENERGY_COUNTER, MMIO_ENERGY_STATUS_MASK, 0,
+ RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
+ [FW_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, MMIO_POWER_LOW_LOCK, 31,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [FW_HIGH_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, MMIO_POWER_HIGH_LOCK, 63,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL1_ENABLE] = PRIMITIVE_INFO_INIT(PL1_ENABLE, MMIO_POWER_LIMIT1_ENABLE, 15,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL1_CLAMP] = PRIMITIVE_INFO_INIT(PL1_CLAMP, MMIO_POWER_LIMIT1_CLAMP, 16,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_ENABLE] = PRIMITIVE_INFO_INIT(PL2_ENABLE, MMIO_POWER_LIMIT2_ENABLE, 47,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_CLAMP] = PRIMITIVE_INFO_INIT(PL2_CLAMP, MMIO_POWER_LIMIT2_CLAMP, 48,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [TIME_WINDOW1] = PRIMITIVE_INFO_INIT(TIME_WINDOW1, MMIO_TIME_WINDOW1_MASK, 17,
+ RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [TIME_WINDOW2] = PRIMITIVE_INFO_INIT(TIME_WINDOW2, MMIO_TIME_WINDOW2_MASK, 49,
+ RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [THERMAL_SPEC_POWER] = PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER,
+ MMIO_POWER_INFO_THERMAL_SPEC_MASK, 0,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_POWER] = PRIMITIVE_INFO_INIT(MAX_POWER, MMIO_POWER_INFO_MAX_MASK, 32,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MIN_POWER] = PRIMITIVE_INFO_INIT(MIN_POWER, MMIO_POWER_INFO_MIN_MASK, 16,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_TIME_WINDOW] = PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW,
+ MMIO_POWER_INFO_MAX_TIME_WIN_MASK, 48,
+ RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
+ [THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME,
+ MMIO_PERF_STATUS_THROTTLE_TIME_MASK, 0,
+ RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
+ [PRIORITY_LEVEL] = PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, MMIO_PP_POLICY_MASK, 0,
+ RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),
+};
+
static const struct rapl_mmio_regs rapl_mmio_default = {
.reg_unit = 0x5938,
.regs[RAPL_DOMAIN_PACKAGE] = { 0x59a0, 0x593c, 0x58f0, 0, 0x5930, 0x59b0},
@@ -75,6 +146,7 @@ int proc_thermal_rapl_add(struct pci_dev *pdev, struct proc_thermal_device *proc
rapl_mmio_priv.read_raw = rapl_mmio_read_raw;
rapl_mmio_priv.write_raw = rapl_mmio_write_raw;
rapl_mmio_priv.defaults = &rapl_defaults_mmio;
+ rapl_mmio_priv.rpi = rpi_mmio;
rapl_mmio_priv.control_type = powercap_register_control_type(NULL, "intel-rapl-mmio", NULL);
if (IS_ERR(rapl_mmio_priv.control_type)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 6/6] powercap: intel_rapl: Move MSR primitives to MSR driver
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
` (4 preceding siblings ...)
2026-03-13 18:53 ` [PATCH v1 5/6] thermal: intel: int340x: processor: Move MMIO primitives to MMIO driver Kuppuswamy Sathyanarayanan
@ 2026-03-13 18:53 ` Kuppuswamy Sathyanarayanan
2026-03-20 17:02 ` [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers srinivas pandruvada
6 siblings, 0 replies; 9+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2026-03-13 18:53 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, Srinivas Pandruvada, linux-pm,
linux-kernel
MSR-specific RAPL primitives differ from those used by TPMI and MMIO
interfaces. Keeping them in the common driver requires
interface-specific handling logic and makes the common layer
unnecessarily complex.
Move the MSR primitive definitions and associated bitmasks into the
MSR interface driver. This change includes:
1. Move MSR-specific bitmask definitions to RAPL MSR driver.
2. Add MSR-local struct rapl_primitive_info instance and assign it to
priv->rpi during MSR probe.
3. Remove the primitive assignment logic from rapl_config() in the
common driver.
No functional changes are intended.
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
drivers/powercap/intel_rapl_common.c | 105 ---------------------------
drivers/powercap/intel_rapl_msr.c | 99 +++++++++++++++++++++++++
2 files changed, 99 insertions(+), 105 deletions(-)
diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
index ffa3f95d8aa2..b2301b30e1ff 100644
--- a/drivers/powercap/intel_rapl_common.c
+++ b/drivers/powercap/intel_rapl_common.c
@@ -30,24 +30,8 @@
#include <asm/intel-family.h>
#include <asm/msr.h>
-/* bitmasks for RAPL MSRs, used by primitive access functions */
#define ENERGY_STATUS_MASK GENMASK(31, 0)
-#define POWER_LIMIT1_MASK GENMASK(14, 0)
-#define POWER_LIMIT1_ENABLE BIT(15)
-#define POWER_LIMIT1_CLAMP BIT(16)
-
-#define POWER_LIMIT2_MASK GENMASK_ULL(46, 32)
-#define POWER_LIMIT2_ENABLE BIT_ULL(47)
-#define POWER_LIMIT2_CLAMP BIT_ULL(48)
-#define POWER_HIGH_LOCK BIT_ULL(63)
-#define POWER_LOW_LOCK BIT(31)
-
-#define POWER_LIMIT4_MASK GENMASK(12, 0)
-
-#define TIME_WINDOW1_MASK GENMASK_ULL(23, 17)
-#define TIME_WINDOW2_MASK GENMASK_ULL(55, 49)
-
#define POWER_UNIT_OFFSET 0x00
#define POWER_UNIT_MASK GENMASK(3, 0)
@@ -57,28 +41,6 @@
#define TIME_UNIT_OFFSET 0x10
#define TIME_UNIT_MASK GENMASK(19, 16)
-#define POWER_INFO_MAX_MASK GENMASK_ULL(46, 32)
-#define POWER_INFO_MIN_MASK GENMASK_ULL(30, 16)
-#define POWER_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(53, 48)
-#define POWER_INFO_THERMAL_SPEC_MASK GENMASK(14, 0)
-
-#define PERF_STATUS_THROTTLE_TIME_MASK GENMASK(31, 0)
-#define PP_POLICY_MASK GENMASK(4, 0)
-
-/*
- * SPR has different layout for Psys Domain PowerLimit registers.
- * There are 17 bits of PL1 and PL2 instead of 15 bits.
- * The Enable bits and TimeWindow bits are also shifted as a result.
- */
-#define PSYS_POWER_LIMIT1_MASK GENMASK_ULL(16, 0)
-#define PSYS_POWER_LIMIT1_ENABLE BIT(17)
-
-#define PSYS_POWER_LIMIT2_MASK GENMASK_ULL(48, 32)
-#define PSYS_POWER_LIMIT2_ENABLE BIT_ULL(49)
-
-#define PSYS_TIME_WINDOW1_MASK GENMASK_ULL(25, 19)
-#define PSYS_TIME_WINDOW2_MASK GENMASK_ULL(57, 51)
-
/* Non HW constants */
#define RAPL_PRIMITIVE_DUMMY BIT(2)
@@ -598,64 +560,6 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
return div64_u64(value, scale);
}
-/* RAPL primitives for MSR and MMIO I/F */
-static struct rapl_primitive_info rpi_msr[NR_RAPL_PRIMITIVES] = {
- /* name, mask, shift, msr index, unit divisor */
- [POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, POWER_LIMIT1_MASK, 0,
- RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
- [POWER_LIMIT2] = PRIMITIVE_INFO_INIT(POWER_LIMIT2, POWER_LIMIT2_MASK, 32,
- RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
- [POWER_LIMIT4] = PRIMITIVE_INFO_INIT(POWER_LIMIT4, POWER_LIMIT4_MASK, 0,
- RAPL_DOMAIN_REG_PL4, POWER_UNIT, 0),
- [ENERGY_COUNTER] = PRIMITIVE_INFO_INIT(ENERGY_COUNTER, ENERGY_STATUS_MASK, 0,
- RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
- [FW_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, POWER_LOW_LOCK, 31,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [FW_HIGH_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, POWER_HIGH_LOCK, 63,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL1_ENABLE] = PRIMITIVE_INFO_INIT(PL1_ENABLE, POWER_LIMIT1_ENABLE, 15,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL1_CLAMP] = PRIMITIVE_INFO_INIT(PL1_CLAMP, POWER_LIMIT1_CLAMP, 16,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL2_ENABLE] = PRIMITIVE_INFO_INIT(PL2_ENABLE, POWER_LIMIT2_ENABLE, 47,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [PL2_CLAMP] = PRIMITIVE_INFO_INIT(PL2_CLAMP, POWER_LIMIT2_CLAMP, 48,
- RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
- [TIME_WINDOW1] = PRIMITIVE_INFO_INIT(TIME_WINDOW1, TIME_WINDOW1_MASK, 17,
- RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
- [TIME_WINDOW2] = PRIMITIVE_INFO_INIT(TIME_WINDOW2, TIME_WINDOW2_MASK, 49,
- RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
- [THERMAL_SPEC_POWER] = PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER,
- POWER_INFO_THERMAL_SPEC_MASK, 0,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MAX_POWER] = PRIMITIVE_INFO_INIT(MAX_POWER, POWER_INFO_MAX_MASK, 32,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MIN_POWER] = PRIMITIVE_INFO_INIT(MIN_POWER, POWER_INFO_MIN_MASK, 16,
- RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
- [MAX_TIME_WINDOW] = PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW,
- POWER_INFO_MAX_TIME_WIN_MASK, 48,
- RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
- [THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME,
- PERF_STATUS_THROTTLE_TIME_MASK, 0,
- RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
- [PRIORITY_LEVEL] = PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, PP_POLICY_MASK, 0,
- RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),
- [PSYS_POWER_LIMIT1] = PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT1, PSYS_POWER_LIMIT1_MASK, 0,
- RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
- [PSYS_POWER_LIMIT2] = PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT2, PSYS_POWER_LIMIT2_MASK,
- 32, RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
- [PSYS_PL1_ENABLE] = PRIMITIVE_INFO_INIT(PSYS_PL1_ENABLE, PSYS_POWER_LIMIT1_ENABLE,
- 17, RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT,
- 0),
- [PSYS_PL2_ENABLE] = PRIMITIVE_INFO_INIT(PSYS_PL2_ENABLE, PSYS_POWER_LIMIT2_ENABLE,
- 49, RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT,
- 0),
- [PSYS_TIME_WINDOW1] = PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW1, PSYS_TIME_WINDOW1_MASK,
- 19, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
- [PSYS_TIME_WINDOW2] = PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW2, PSYS_TIME_WINDOW2_MASK,
- 51, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
-};
-
static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
{
struct rapl_primitive_info *rpi = rp->priv->rpi;
@@ -668,15 +572,6 @@ static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
static int rapl_config(struct rapl_package *rp)
{
- switch (rp->priv->type) {
- /* MMIO I/F shares the same register layout as MSR registers */
- case RAPL_IF_MSR:
- rp->priv->rpi = rpi_msr;
- break;
- default:
- return -EINVAL;
- }
-
/* defaults_msr can be NULL on unsupported platforms */
if (!rp->priv->defaults || !rp->priv->rpi)
return -ENODEV;
diff --git a/drivers/powercap/intel_rapl_msr.c b/drivers/powercap/intel_rapl_msr.c
index b7c10ed75d69..cfb35973f0b5 100644
--- a/drivers/powercap/intel_rapl_msr.c
+++ b/drivers/powercap/intel_rapl_msr.c
@@ -44,6 +44,46 @@
#define TIME_UNIT_OFFSET 0x10
#define TIME_UNIT_MASK GENMASK(19, 16)
+/* bitmasks for RAPL MSRs, used by primitive access functions */
+#define ENERGY_STATUS_MASK GENMASK(31, 0)
+
+#define POWER_LIMIT1_MASK GENMASK(14, 0)
+#define POWER_LIMIT1_ENABLE BIT(15)
+#define POWER_LIMIT1_CLAMP BIT(16)
+
+#define POWER_LIMIT2_MASK GENMASK_ULL(46, 32)
+#define POWER_LIMIT2_ENABLE BIT_ULL(47)
+#define POWER_LIMIT2_CLAMP BIT_ULL(48)
+#define POWER_HIGH_LOCK BIT_ULL(63)
+#define POWER_LOW_LOCK BIT(31)
+
+#define POWER_LIMIT4_MASK GENMASK(12, 0)
+
+#define TIME_WINDOW1_MASK GENMASK_ULL(23, 17)
+#define TIME_WINDOW2_MASK GENMASK_ULL(55, 49)
+
+#define POWER_INFO_MAX_MASK GENMASK_ULL(46, 32)
+#define POWER_INFO_MIN_MASK GENMASK_ULL(30, 16)
+#define POWER_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(53, 48)
+#define POWER_INFO_THERMAL_SPEC_MASK GENMASK(14, 0)
+
+#define PERF_STATUS_THROTTLE_TIME_MASK GENMASK(31, 0)
+#define PP_POLICY_MASK GENMASK(4, 0)
+
+/*
+ * SPR has different layout for Psys Domain PowerLimit registers.
+ * There are 17 bits of PL1 and PL2 instead of 15 bits.
+ * The Enable bits and TimeWindow bits are also shifted as a result.
+ */
+#define PSYS_POWER_LIMIT1_MASK GENMASK_ULL(16, 0)
+#define PSYS_POWER_LIMIT1_ENABLE BIT(17)
+
+#define PSYS_POWER_LIMIT2_MASK GENMASK_ULL(48, 32)
+#define PSYS_POWER_LIMIT2_ENABLE BIT_ULL(49)
+
+#define PSYS_TIME_WINDOW1_MASK GENMASK_ULL(25, 19)
+#define PSYS_TIME_WINDOW2_MASK GENMASK_ULL(57, 51)
+
/* Sideband MBI registers */
#define IOSF_CPU_POWER_BUDGET_CTL_BYT 0x02
#define IOSF_CPU_POWER_BUDGET_CTL_TNG 0xDF
@@ -268,6 +308,64 @@ static u64 rapl_compute_time_window_atom(struct rapl_domain *rd, u64 value,
return value ? value * rd->time_unit : rd->time_unit;
}
+/* RAPL primitives for MSR I/F */
+static struct rapl_primitive_info rpi_msr[NR_RAPL_PRIMITIVES] = {
+ /* name, mask, shift, msr index, unit divisor */
+ [POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, POWER_LIMIT1_MASK, 0,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [POWER_LIMIT2] = PRIMITIVE_INFO_INIT(POWER_LIMIT2, POWER_LIMIT2_MASK, 32,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [POWER_LIMIT4] = PRIMITIVE_INFO_INIT(POWER_LIMIT4, POWER_LIMIT4_MASK, 0,
+ RAPL_DOMAIN_REG_PL4, POWER_UNIT, 0),
+ [ENERGY_COUNTER] = PRIMITIVE_INFO_INIT(ENERGY_COUNTER, ENERGY_STATUS_MASK, 0,
+ RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
+ [FW_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, POWER_LOW_LOCK, 31,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [FW_HIGH_LOCK] = PRIMITIVE_INFO_INIT(FW_LOCK, POWER_HIGH_LOCK, 63,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL1_ENABLE] = PRIMITIVE_INFO_INIT(PL1_ENABLE, POWER_LIMIT1_ENABLE, 15,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL1_CLAMP] = PRIMITIVE_INFO_INIT(PL1_CLAMP, POWER_LIMIT1_CLAMP, 16,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_ENABLE] = PRIMITIVE_INFO_INIT(PL2_ENABLE, POWER_LIMIT2_ENABLE, 47,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [PL2_CLAMP] = PRIMITIVE_INFO_INIT(PL2_CLAMP, POWER_LIMIT2_CLAMP, 48,
+ RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
+ [TIME_WINDOW1] = PRIMITIVE_INFO_INIT(TIME_WINDOW1, TIME_WINDOW1_MASK, 17,
+ RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [TIME_WINDOW2] = PRIMITIVE_INFO_INIT(TIME_WINDOW2, TIME_WINDOW2_MASK, 49,
+ RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [THERMAL_SPEC_POWER] = PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER,
+ POWER_INFO_THERMAL_SPEC_MASK, 0,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_POWER] = PRIMITIVE_INFO_INIT(MAX_POWER, POWER_INFO_MAX_MASK, 32,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MIN_POWER] = PRIMITIVE_INFO_INIT(MIN_POWER, POWER_INFO_MIN_MASK, 16,
+ RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
+ [MAX_TIME_WINDOW] = PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW,
+ POWER_INFO_MAX_TIME_WIN_MASK, 48,
+ RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
+ [THROTTLED_TIME] = PRIMITIVE_INFO_INIT(THROTTLED_TIME,
+ PERF_STATUS_THROTTLE_TIME_MASK, 0,
+ RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
+ [PRIORITY_LEVEL] = PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, PP_POLICY_MASK, 0,
+ RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),
+ [PSYS_POWER_LIMIT1] = PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT1, PSYS_POWER_LIMIT1_MASK, 0,
+ RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [PSYS_POWER_LIMIT2] = PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT2, PSYS_POWER_LIMIT2_MASK,
+ 32, RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
+ [PSYS_PL1_ENABLE] = PRIMITIVE_INFO_INIT(PSYS_PL1_ENABLE, PSYS_POWER_LIMIT1_ENABLE,
+ 17, RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT,
+ 0),
+ [PSYS_PL2_ENABLE] = PRIMITIVE_INFO_INIT(PSYS_PL2_ENABLE, PSYS_POWER_LIMIT2_ENABLE,
+ 49, RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT,
+ 0),
+ [PSYS_TIME_WINDOW1] = PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW1, PSYS_TIME_WINDOW1_MASK,
+ 19, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+ [PSYS_TIME_WINDOW2] = PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW2, PSYS_TIME_WINDOW2_MASK,
+ 51, RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
+};
+
static const struct rapl_defaults rapl_defaults_core = {
.floor_freq_reg_addr = 0,
.check_unit = rapl_default_check_unit,
@@ -418,6 +516,7 @@ static int rapl_msr_probe(struct platform_device *pdev)
rapl_msr_priv->read_raw = rapl_msr_read_raw;
rapl_msr_priv->write_raw = rapl_msr_write_raw;
rapl_msr_priv->defaults = (const struct rapl_defaults *)pdev->dev.platform_data;
+ rapl_msr_priv->rpi = rpi_msr;
if (id) {
rapl_msr_priv->limits[RAPL_DOMAIN_PACKAGE] |= BIT(POWER_LIMIT4);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers
2026-03-13 18:53 [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers Kuppuswamy Sathyanarayanan
` (5 preceding siblings ...)
2026-03-13 18:53 ` [PATCH v1 6/6] powercap: intel_rapl: Move MSR primitives to MSR driver Kuppuswamy Sathyanarayanan
@ 2026-03-20 17:02 ` srinivas pandruvada
2026-03-20 18:10 ` Rafael J. Wysocki
6 siblings, 1 reply; 9+ messages in thread
From: srinivas pandruvada @ 2026-03-20 17:02 UTC (permalink / raw)
To: Kuppuswamy Sathyanarayanan, Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel
On Fri, 2026-03-13 at 11:53 -0700, Kuppuswamy Sathyanarayanan wrote:
> RAPL supports multiple interfaces (MSR, MMIO, and TPMI), each with
> their
> own register layouts and bitmask definitions. Currently, the
> primitive
> tables and bitmasks for all three interfaces live in the common
> driver,
> which requires interface-specific handling logic in shared code and
> makes
> the common layer unnecessarily complex.
>
> This series cleans this up by moving each interface's primitive
> definitions into its own driver, so the common driver no longer needs
> to
> know anything about per-interface register layouts.
>
> All patches are no-functional-change refactoring.
>
> This series is based on top of the earlier RAPL cleanup series:
>
>
> https://lore.kernel.org/linux-pm/20260212233044.329790-1-sathyanarayanan.kuppuswamy@linux.intel.com/T/#t
>
For whole series:
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Patch Summary:
> Patch 1/6: Remove unused AVERAGE_POWER primitive and
> RAPL_PRIMITIVE_DERIVED
> flag from the common driver.
> Patch 2/6: Remove other unused macro definitions from the common
> driver.
> Patch 3/6: Move struct rapl_primitive_info, enum unit_type, and
> PRIMITIVE_INFO_INIT macro to intel_rapl.h to allow
> interface
> drivers to define their own primitive tables.
> Patch 4/6: Move TPMI primitive definitions and associated bitmasks
> into
> the TPMI interface driver.
> Patch 5/6: Move MMIO primitive definitions and associated bitmasks
> into
> the MMIO interface driver.
> Patch 6/6: Move MSR primitive definitions and associated bitmasks
> into
> the MSR interface driver.
>
> Kuppuswamy Sathyanarayanan (6):
> powercap: intel_rapl: Remove unused AVERAGE_POWER primitive
> powercap: intel_rapl: Remove unused macro definitions
> powercap: intel_rapl: Move primitive info to header for interface
> drivers
> powercap: intel_rapl: Move TPMI primitives to TPMI driver
> thermal: intel: int340x: processor: Move MMIO primitives to MMIO
> driver
> powercap: intel_rapl: Move MSR primitives to MSR driver
>
> drivers/powercap/intel_rapl_common.c | 206 ----------------
> --
> drivers/powercap/intel_rapl_msr.c | 99 +++++++++
> drivers/powercap/intel_rapl_tpmi.c | 53 +++++
> .../int340x_thermal/processor_thermal_rapl.c | 72 ++++++
> include/linux/intel_rapl.h | 33 ++-
> 5 files changed, 254 insertions(+), 209 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers
2026-03-20 17:02 ` [PATCH v1 0/6] powercap: intel_rapl: Move primitives to interface drivers srinivas pandruvada
@ 2026-03-20 18:10 ` Rafael J. Wysocki
0 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 18:10 UTC (permalink / raw)
To: srinivas pandruvada, Kuppuswamy Sathyanarayanan
Cc: Daniel Lezcano, Zhang Rui, Lukasz Luba, linux-pm, linux-kernel
On Fri, Mar 20, 2026 at 6:02 PM srinivas pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
>
> On Fri, 2026-03-13 at 11:53 -0700, Kuppuswamy Sathyanarayanan wrote:
> > RAPL supports multiple interfaces (MSR, MMIO, and TPMI), each with
> > their
> > own register layouts and bitmask definitions. Currently, the
> > primitive
> > tables and bitmasks for all three interfaces live in the common
> > driver,
> > which requires interface-specific handling logic in shared code and
> > makes
> > the common layer unnecessarily complex.
> >
> > This series cleans this up by moving each interface's primitive
> > definitions into its own driver, so the common driver no longer needs
> > to
> > know anything about per-interface register layouts.
> >
> > All patches are no-functional-change refactoring.
> >
> > This series is based on top of the earlier RAPL cleanup series:
> >
> >
> > https://lore.kernel.org/linux-pm/20260212233044.329790-1-sathyanarayanan.kuppuswamy@linux.intel.com/T/#t
> >
>
> For whole series:
>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Whole series applied as 7.1 material, thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread