Skip to content

Commit 71bb2c5

Browse files
Kuppuswamy Sathyanarayananrafaeljw
authored andcommitted
powercap: intel_rapl: Use GENMASK() and BIT() macros
Replace hardcoded bitmasks and bit shift operations with standard GENMASK(), GENMASK_ULL(), BIT(), and BIT_ULL() macros for better readability and to follow kernel coding conventions. No functional changes. Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Link: https://patch.msgid.link/20260212233044.329790-7-sathyanarayanan.kuppuswamy@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 923860a commit 71bb2c5

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

drivers/powercap/intel_rapl_common.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,62 +31,62 @@
3131
#include <asm/msr.h>
3232

3333
/* bitmasks for RAPL MSRs, used by primitive access functions */
34-
#define ENERGY_STATUS_MASK 0xffffffff
34+
#define ENERGY_STATUS_MASK GENMASK(31, 0)
3535

36-
#define POWER_LIMIT1_MASK 0x7FFF
36+
#define POWER_LIMIT1_MASK GENMASK(14, 0)
3737
#define POWER_LIMIT1_ENABLE BIT(15)
3838
#define POWER_LIMIT1_CLAMP BIT(16)
3939

40-
#define POWER_LIMIT2_MASK (0x7FFFULL<<32)
40+
#define POWER_LIMIT2_MASK GENMASK_ULL(46, 32)
4141
#define POWER_LIMIT2_ENABLE BIT_ULL(47)
4242
#define POWER_LIMIT2_CLAMP BIT_ULL(48)
4343
#define POWER_HIGH_LOCK BIT_ULL(63)
4444
#define POWER_LOW_LOCK BIT(31)
4545

46-
#define POWER_LIMIT4_MASK 0x1FFF
46+
#define POWER_LIMIT4_MASK GENMASK(12, 0)
4747

48-
#define TIME_WINDOW1_MASK (0x7FULL<<17)
49-
#define TIME_WINDOW2_MASK (0x7FULL<<49)
48+
#define TIME_WINDOW1_MASK GENMASK_ULL(23, 17)
49+
#define TIME_WINDOW2_MASK GENMASK_ULL(55, 49)
5050

5151
#define POWER_UNIT_OFFSET 0x00
52-
#define POWER_UNIT_MASK 0x0F
52+
#define POWER_UNIT_MASK GENMASK(3, 0)
5353

5454
#define ENERGY_UNIT_OFFSET 0x08
55-
#define ENERGY_UNIT_MASK 0x1F00
55+
#define ENERGY_UNIT_MASK GENMASK(12, 8)
5656

5757
#define TIME_UNIT_OFFSET 0x10
58-
#define TIME_UNIT_MASK 0xF0000
58+
#define TIME_UNIT_MASK GENMASK(19, 16)
5959

60-
#define POWER_INFO_MAX_MASK (0x7fffULL<<32)
61-
#define POWER_INFO_MIN_MASK (0x7fffULL<<16)
62-
#define POWER_INFO_MAX_TIME_WIN_MASK (0x3fULL<<48)
63-
#define POWER_INFO_THERMAL_SPEC_MASK 0x7fff
60+
#define POWER_INFO_MAX_MASK GENMASK_ULL(46, 32)
61+
#define POWER_INFO_MIN_MASK GENMASK_ULL(30, 16)
62+
#define POWER_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(53, 48)
63+
#define POWER_INFO_THERMAL_SPEC_MASK GENMASK(14, 0)
6464

65-
#define PERF_STATUS_THROTTLE_TIME_MASK 0xffffffff
66-
#define PP_POLICY_MASK 0x1F
65+
#define PERF_STATUS_THROTTLE_TIME_MASK GENMASK(31, 0)
66+
#define PP_POLICY_MASK GENMASK(4, 0)
6767

6868
/*
6969
* SPR has different layout for Psys Domain PowerLimit registers.
7070
* There are 17 bits of PL1 and PL2 instead of 15 bits.
7171
* The Enable bits and TimeWindow bits are also shifted as a result.
7272
*/
73-
#define PSYS_POWER_LIMIT1_MASK 0x1FFFF
73+
#define PSYS_POWER_LIMIT1_MASK GENMASK_ULL(16, 0)
7474
#define PSYS_POWER_LIMIT1_ENABLE BIT(17)
7575

76-
#define PSYS_POWER_LIMIT2_MASK (0x1FFFFULL<<32)
76+
#define PSYS_POWER_LIMIT2_MASK GENMASK_ULL(48, 32)
7777
#define PSYS_POWER_LIMIT2_ENABLE BIT_ULL(49)
7878

79-
#define PSYS_TIME_WINDOW1_MASK (0x7FULL<<19)
80-
#define PSYS_TIME_WINDOW2_MASK (0x7FULL<<51)
79+
#define PSYS_TIME_WINDOW1_MASK GENMASK_ULL(25, 19)
80+
#define PSYS_TIME_WINDOW2_MASK GENMASK_ULL(57, 51)
8181

8282
/* bitmasks for RAPL TPMI, used by primitive access functions */
83-
#define TPMI_POWER_LIMIT_MASK 0x3FFFF
83+
#define TPMI_POWER_LIMIT_MASK GENMASK_ULL(17, 0)
8484
#define TPMI_POWER_LIMIT_ENABLE BIT_ULL(62)
85-
#define TPMI_TIME_WINDOW_MASK (0x7FULL<<18)
86-
#define TPMI_INFO_SPEC_MASK 0x3FFFF
87-
#define TPMI_INFO_MIN_MASK (0x3FFFFULL << 18)
88-
#define TPMI_INFO_MAX_MASK (0x3FFFFULL << 36)
89-
#define TPMI_INFO_MAX_TIME_WIN_MASK (0x7FULL << 54)
85+
#define TPMI_TIME_WINDOW_MASK GENMASK_ULL(24, 18)
86+
#define TPMI_INFO_SPEC_MASK GENMASK_ULL(17, 0)
87+
#define TPMI_INFO_MIN_MASK GENMASK_ULL(35, 18)
88+
#define TPMI_INFO_MAX_MASK GENMASK_ULL(53, 36)
89+
#define TPMI_INFO_MAX_TIME_WIN_MASK GENMASK_ULL(60, 54)
9090

9191
/* Non HW constants */
9292
#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */
@@ -111,9 +111,9 @@
111111
#define TPMI_POWER_UNIT_OFFSET POWER_UNIT_OFFSET
112112
#define TPMI_POWER_UNIT_MASK POWER_UNIT_MASK
113113
#define TPMI_ENERGY_UNIT_OFFSET 0x06
114-
#define TPMI_ENERGY_UNIT_MASK 0x7C0
114+
#define TPMI_ENERGY_UNIT_MASK GENMASK_ULL(10, 6)
115115
#define TPMI_TIME_UNIT_OFFSET 0x0C
116-
#define TPMI_TIME_UNIT_MASK 0xF000
116+
#define TPMI_TIME_UNIT_MASK GENMASK_ULL(15, 12)
117117

118118
#define RAPL_EVENT_MASK GENMASK(7, 0)
119119

@@ -1102,8 +1102,8 @@ static void set_floor_freq_atom(struct rapl_domain *rd, bool enable)
11021102
&power_ctrl_orig_val);
11031103
mdata = power_ctrl_orig_val;
11041104
if (enable) {
1105-
mdata &= ~(0x7f << 8);
1106-
mdata |= 1 << 8;
1105+
mdata &= ~GENMASK(14, 8);
1106+
mdata |= BIT(8);
11071107
}
11081108
iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_CR_WRITE,
11091109
defaults->floor_freq_reg_addr, mdata);
@@ -1136,7 +1136,7 @@ static u64 rapl_compute_time_window_core(struct rapl_domain *rd, u64 value,
11361136
if (y > 0x1f)
11371137
return 0x7f;
11381138

1139-
f = div64_u64(4 * (value - (1ULL << y)), 1ULL << y);
1139+
f = div64_u64(4 * (value - BIT_ULL(y)), BIT_ULL(y));
11401140
value = (y & 0x1f) | ((f & 0x3) << 5);
11411141
}
11421142
return value;

0 commit comments

Comments
 (0)