@@ -159,8 +159,8 @@ static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 att
159159 return ret ;
160160}
161161
162- static int xe_hwmon_pcode_write_power_limit (const struct xe_hwmon * hwmon , u32 attr , u8 channel ,
163- u32 uval )
162+ static int xe_hwmon_pcode_rmw_power_limit (const struct xe_hwmon * hwmon , u32 attr , u8 channel ,
163+ u32 clr , u32 set )
164164{
165165 struct xe_tile * root_tile = xe_device_get_root_tile (hwmon -> xe );
166166 u32 val0 , val1 ;
@@ -179,7 +179,7 @@ static int xe_hwmon_pcode_write_power_limit(const struct xe_hwmon *hwmon, u32 at
179179 channel , val0 , val1 , ret );
180180
181181 if (attr == PL1_HWMON_ATTR )
182- val0 = uval ;
182+ val0 = ( val0 & ~ clr ) | set ;
183183 else
184184 return - EIO ;
185185
@@ -339,7 +339,7 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, u32 attr, int channe
339339 if (hwmon -> xe -> info .has_mbx_power_limits ) {
340340 drm_dbg (& hwmon -> xe -> drm , "disabling %s on channel %d\n" ,
341341 PWR_ATTR_TO_STR (attr ), channel );
342- xe_hwmon_pcode_write_power_limit (hwmon , attr , channel , 0 );
342+ xe_hwmon_pcode_rmw_power_limit (hwmon , attr , channel , PWR_LIM_EN , 0 );
343343 xe_hwmon_pcode_read_power_limit (hwmon , attr , channel , & reg_val );
344344 } else {
345345 reg_val = xe_mmio_rmw32 (mmio , rapl_limit , PWR_LIM_EN , 0 );
@@ -370,10 +370,9 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, u32 attr, int channe
370370 }
371371
372372 if (hwmon -> xe -> info .has_mbx_power_limits )
373- ret = xe_hwmon_pcode_write_power_limit (hwmon , attr , channel , reg_val );
373+ ret = xe_hwmon_pcode_rmw_power_limit (hwmon , attr , channel , PWR_LIM , reg_val );
374374 else
375- reg_val = xe_mmio_rmw32 (mmio , rapl_limit , PWR_LIM_EN | PWR_LIM_VAL ,
376- reg_val );
375+ reg_val = xe_mmio_rmw32 (mmio , rapl_limit , PWR_LIM , reg_val );
377376unlock :
378377 mutex_unlock (& hwmon -> hwmon_lock );
379378 return ret ;
@@ -563,14 +562,11 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a
563562
564563 mutex_lock (& hwmon -> hwmon_lock );
565564
566- if (hwmon -> xe -> info .has_mbx_power_limits ) {
567- ret = xe_hwmon_pcode_read_power_limit (hwmon , power_attr , channel , (u32 * )& r );
568- r = (r & ~PWR_LIM_TIME ) | rxy ;
569- xe_hwmon_pcode_write_power_limit (hwmon , power_attr , channel , r );
570- } else {
565+ if (hwmon -> xe -> info .has_mbx_power_limits )
566+ xe_hwmon_pcode_rmw_power_limit (hwmon , power_attr , channel , PWR_LIM_TIME , rxy );
567+ else
571568 r = xe_mmio_rmw32 (mmio , xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , channel ),
572569 PWR_LIM_TIME , rxy );
573- }
574570
575571 mutex_unlock (& hwmon -> hwmon_lock );
576572
@@ -1138,12 +1134,12 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)
11381134 } else {
11391135 drm_info (& hwmon -> xe -> drm , "Using mailbox commands for power limits\n" );
11401136 /* Write default limits to read from pcode from now on. */
1141- xe_hwmon_pcode_write_power_limit (hwmon , PL1_HWMON_ATTR ,
1142- CHANNEL_CARD ,
1143- hwmon -> pl1_on_boot [CHANNEL_CARD ]);
1144- xe_hwmon_pcode_write_power_limit (hwmon , PL1_HWMON_ATTR ,
1145- CHANNEL_PKG ,
1146- hwmon -> pl1_on_boot [CHANNEL_PKG ]);
1137+ xe_hwmon_pcode_rmw_power_limit (hwmon , PL1_HWMON_ATTR ,
1138+ CHANNEL_CARD , PWR_LIM | PWR_LIM_TIME ,
1139+ hwmon -> pl1_on_boot [CHANNEL_CARD ]);
1140+ xe_hwmon_pcode_rmw_power_limit (hwmon , PL1_HWMON_ATTR ,
1141+ CHANNEL_PKG , PWR_LIM | PWR_LIM_TIME ,
1142+ hwmon -> pl1_on_boot [CHANNEL_PKG ]);
11471143 hwmon -> scl_shift_power = PWR_UNIT ;
11481144 hwmon -> scl_shift_energy = ENERGY_UNIT ;
11491145 hwmon -> scl_shift_time = TIME_UNIT ;
0 commit comments