]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
powercap: intel_rapl: Move primitive info to header for interface drivers
authorKuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Tue, 31 Mar 2026 21:19:46 +0000 (14:19 -0700)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 1 Apr 2026 14:03:05 +0000 (16:03 +0200)
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>
Link: https://patch.msgid.link/20260331211950.3329932-4-sathyanarayanan.kuppuswamy@linux.intel.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/powercap/intel_rapl_common.c
include/linux/intel_rapl.h

index f2637cc2cc6a8055aad9d6c130982f883469b1db..ffc9d0378257a26cb97216b3e1279c1852419385 100644 (file)
 
 #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;
index 9e6bd654be1f0af729f0e94ee48962f012942f3c..01f290de3586a7adddf0f986dc7b7a212f639bd0 100644 (file)
@@ -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