1212#include "regs/xe_mchbar_regs.h"
1313#include "regs/xe_pcode_regs.h"
1414#include "xe_device.h"
15- #include "xe_gt.h"
1615#include "xe_hwmon.h"
1716#include "xe_mmio.h"
1817#include "xe_pcode.h"
@@ -65,8 +64,8 @@ struct xe_hwmon_energy_info {
6564struct xe_hwmon {
6665 /** @hwmon_dev: hwmon device for xe */
6766 struct device * hwmon_dev ;
68- /** @gt: primary gt */
69- struct xe_gt * gt ;
67+ /** @xe: Xe device */
68+ struct xe_device * xe ;
7069 /** @hwmon_lock: lock for rw attributes*/
7170 struct mutex hwmon_lock ;
7271 /** @scl_shift_power: pkg power unit */
@@ -82,7 +81,7 @@ struct xe_hwmon {
8281static struct xe_reg xe_hwmon_get_reg (struct xe_hwmon * hwmon , enum xe_hwmon_reg hwmon_reg ,
8382 int channel )
8483{
85- struct xe_device * xe = gt_to_xe ( hwmon -> gt ) ;
84+ struct xe_device * xe = hwmon -> xe ;
8685
8786 switch (hwmon_reg ) {
8887 case REG_PKG_RAPL_LIMIT :
@@ -148,8 +147,9 @@ static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg
148147static void xe_hwmon_power_max_read (struct xe_hwmon * hwmon , int channel , long * value )
149148{
150149 u64 reg_val , min , max ;
151- struct xe_device * xe = gt_to_xe ( hwmon -> gt ) ;
150+ struct xe_device * xe = hwmon -> xe ;
152151 struct xe_reg rapl_limit , pkg_power_sku ;
152+ struct xe_gt * mmio = xe_root_mmio_gt (xe );
153153
154154 rapl_limit = xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , channel );
155155 pkg_power_sku = xe_hwmon_get_reg (hwmon , REG_PKG_POWER_SKU , channel );
@@ -166,7 +166,7 @@ static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, int channel, long *v
166166
167167 mutex_lock (& hwmon -> hwmon_lock );
168168
169- reg_val = xe_mmio_read32 (hwmon -> gt , rapl_limit );
169+ reg_val = xe_mmio_read32 (mmio , rapl_limit );
170170 /* Check if PL1 limit is disabled */
171171 if (!(reg_val & PKG_PWR_LIM_1_EN )) {
172172 * value = PL1_DISABLE ;
@@ -176,7 +176,7 @@ static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, int channel, long *v
176176 reg_val = REG_FIELD_GET (PKG_PWR_LIM_1 , reg_val );
177177 * value = mul_u64_u32_shr (reg_val , SF_POWER , hwmon -> scl_shift_power );
178178
179- reg_val = xe_mmio_read64_2x32 (hwmon -> gt , pkg_power_sku );
179+ reg_val = xe_mmio_read64_2x32 (mmio , pkg_power_sku );
180180 min = REG_FIELD_GET (PKG_MIN_PWR , reg_val );
181181 min = mul_u64_u32_shr (min , SF_POWER , hwmon -> scl_shift_power );
182182 max = REG_FIELD_GET (PKG_MAX_PWR , reg_val );
@@ -190,6 +190,7 @@ static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, int channel, long *v
190190
191191static int xe_hwmon_power_max_write (struct xe_hwmon * hwmon , int channel , long value )
192192{
193+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
193194 int ret = 0 ;
194195 u64 reg_val ;
195196 struct xe_reg rapl_limit ;
@@ -200,10 +201,10 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
200201
201202 /* Disable PL1 limit and verify, as limit cannot be disabled on all platforms */
202203 if (value == PL1_DISABLE ) {
203- reg_val = xe_mmio_rmw32 (hwmon -> gt , rapl_limit , PKG_PWR_LIM_1_EN , 0 );
204- reg_val = xe_mmio_read32 (hwmon -> gt , rapl_limit );
204+ reg_val = xe_mmio_rmw32 (mmio , rapl_limit , PKG_PWR_LIM_1_EN , 0 );
205+ reg_val = xe_mmio_read32 (mmio , rapl_limit );
205206 if (reg_val & PKG_PWR_LIM_1_EN ) {
206- drm_warn (& gt_to_xe ( hwmon -> gt ) -> drm , "PL1 disable is not supported!\n" );
207+ drm_warn (& hwmon -> xe -> drm , "PL1 disable is not supported!\n" );
207208 ret = - EOPNOTSUPP ;
208209 }
209210 goto unlock ;
@@ -212,7 +213,7 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
212213 /* Computation in 64-bits to avoid overflow. Round to nearest. */
213214 reg_val = DIV_ROUND_CLOSEST_ULL ((u64 )value << hwmon -> scl_shift_power , SF_POWER );
214215 reg_val = PKG_PWR_LIM_1_EN | REG_FIELD_PREP (PKG_PWR_LIM_1 , reg_val );
215- reg_val = xe_mmio_rmw32 (hwmon -> gt , rapl_limit , PKG_PWR_LIM_1_EN | PKG_PWR_LIM_1 , reg_val );
216+ reg_val = xe_mmio_rmw32 (mmio , rapl_limit , PKG_PWR_LIM_1_EN | PKG_PWR_LIM_1 , reg_val );
216217
217218unlock :
218219 mutex_unlock (& hwmon -> hwmon_lock );
@@ -221,6 +222,7 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
221222
222223static void xe_hwmon_power_rated_max_read (struct xe_hwmon * hwmon , int channel , long * value )
223224{
225+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
224226 struct xe_reg reg = xe_hwmon_get_reg (hwmon , REG_PKG_POWER_SKU , channel );
225227 u64 reg_val ;
226228
@@ -229,7 +231,7 @@ static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, int channel, l
229231 * for this register can be skipped.
230232 * See xe_hwmon_power_is_visible.
231233 */
232- reg_val = xe_mmio_read32 (hwmon -> gt , reg );
234+ reg_val = xe_mmio_read32 (mmio , reg );
233235 reg_val = REG_FIELD_GET (PKG_TDP , reg_val );
234236 * value = mul_u64_u32_shr (reg_val , SF_POWER , hwmon -> scl_shift_power );
235237}
@@ -257,11 +259,12 @@ static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, int channel, l
257259static void
258260xe_hwmon_energy_get (struct xe_hwmon * hwmon , int channel , long * energy )
259261{
262+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
260263 struct xe_hwmon_energy_info * ei = & hwmon -> ei [channel ];
261264 u64 reg_val ;
262265
263- reg_val = xe_mmio_read32 (hwmon -> gt , xe_hwmon_get_reg (hwmon , REG_PKG_ENERGY_STATUS ,
264- channel ));
266+ reg_val = xe_mmio_read32 (mmio , xe_hwmon_get_reg (hwmon , REG_PKG_ENERGY_STATUS ,
267+ channel ));
265268
266269 if (reg_val >= ei -> reg_val_prev )
267270 ei -> accum_energy += reg_val - ei -> reg_val_prev ;
@@ -279,19 +282,20 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at
279282 char * buf )
280283{
281284 struct xe_hwmon * hwmon = dev_get_drvdata (dev );
285+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
282286 u32 x , y , x_w = 2 ; /* 2 bits */
283287 u64 r , tau4 , out ;
284288 int sensor_index = to_sensor_dev_attr (attr )-> index ;
285289
286- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
290+ xe_pm_runtime_get (hwmon -> xe );
287291
288292 mutex_lock (& hwmon -> hwmon_lock );
289293
290- r = xe_mmio_read32 (hwmon -> gt , xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , sensor_index ));
294+ r = xe_mmio_read32 (mmio , xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , sensor_index ));
291295
292296 mutex_unlock (& hwmon -> hwmon_lock );
293297
294- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
298+ xe_pm_runtime_put (hwmon -> xe );
295299
296300 x = REG_FIELD_GET (PKG_PWR_LIM_1_TIME_X , r );
297301 y = REG_FIELD_GET (PKG_PWR_LIM_1_TIME_Y , r );
@@ -319,6 +323,7 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a
319323 const char * buf , size_t count )
320324{
321325 struct xe_hwmon * hwmon = dev_get_drvdata (dev );
326+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
322327 u32 x , y , rxy , x_w = 2 ; /* 2 bits */
323328 u64 tau4 , r , max_win ;
324329 unsigned long val ;
@@ -371,16 +376,16 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a
371376
372377 rxy = REG_FIELD_PREP (PKG_PWR_LIM_1_TIME_X , x ) | REG_FIELD_PREP (PKG_PWR_LIM_1_TIME_Y , y );
373378
374- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
379+ xe_pm_runtime_get (hwmon -> xe );
375380
376381 mutex_lock (& hwmon -> hwmon_lock );
377382
378- r = xe_mmio_rmw32 (hwmon -> gt , xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , sensor_index ),
383+ r = xe_mmio_rmw32 (mmio , xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , sensor_index ),
379384 PKG_PWR_LIM_1_TIME , rxy );
380385
381386 mutex_unlock (& hwmon -> hwmon_lock );
382387
383- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
388+ xe_pm_runtime_put (hwmon -> xe );
384389
385390 return count ;
386391}
@@ -406,11 +411,11 @@ static umode_t xe_hwmon_attributes_visible(struct kobject *kobj,
406411 struct xe_hwmon * hwmon = dev_get_drvdata (dev );
407412 int ret = 0 ;
408413
409- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
414+ xe_pm_runtime_get (hwmon -> xe );
410415
411416 ret = xe_reg_is_valid (xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , index )) ? attr -> mode : 0 ;
412417
413- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
418+ xe_pm_runtime_put (hwmon -> xe );
414419
415420 return ret ;
416421}
@@ -435,20 +440,24 @@ static const struct hwmon_channel_info * const hwmon_info[] = {
435440};
436441
437442/* I1 is exposed as power_crit or as curr_crit depending on bit 31 */
438- static int xe_hwmon_pcode_read_i1 (struct xe_gt * gt , u32 * uval )
443+ static int xe_hwmon_pcode_read_i1 (const struct xe_hwmon * hwmon , u32 * uval )
439444{
445+ struct xe_tile * root_tile = xe_device_get_root_tile (hwmon -> xe );
446+
440447 /* Avoid Illegal Subcommand error */
441- if (gt_to_xe ( gt ) -> info .platform == XE_DG2 )
448+ if (hwmon -> xe -> info .platform == XE_DG2 )
442449 return - ENXIO ;
443450
444- return xe_pcode_read (gt_to_tile ( gt ) , PCODE_MBOX (PCODE_POWER_SETUP ,
451+ return xe_pcode_read (root_tile , PCODE_MBOX (PCODE_POWER_SETUP ,
445452 POWER_SETUP_SUBCOMMAND_READ_I1 , 0 ),
446453 uval , NULL );
447454}
448455
449- static int xe_hwmon_pcode_write_i1 (struct xe_gt * gt , u32 uval )
456+ static int xe_hwmon_pcode_write_i1 (const struct xe_hwmon * hwmon , u32 uval )
450457{
451- return xe_pcode_write (gt_to_tile (gt ), PCODE_MBOX (PCODE_POWER_SETUP ,
458+ struct xe_tile * root_tile = xe_device_get_root_tile (hwmon -> xe );
459+
460+ return xe_pcode_write (root_tile , PCODE_MBOX (PCODE_POWER_SETUP ,
452461 POWER_SETUP_SUBCOMMAND_WRITE_I1 , 0 ),
453462 (uval & POWER_SETUP_I1_DATA_MASK ));
454463}
@@ -461,7 +470,7 @@ static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel,
461470
462471 mutex_lock (& hwmon -> hwmon_lock );
463472
464- ret = xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval );
473+ ret = xe_hwmon_pcode_read_i1 (hwmon , & uval );
465474 if (ret )
466475 goto unlock ;
467476
@@ -481,17 +490,18 @@ static int xe_hwmon_power_curr_crit_write(struct xe_hwmon *hwmon, int channel,
481490 mutex_lock (& hwmon -> hwmon_lock );
482491
483492 uval = DIV_ROUND_CLOSEST_ULL (value << POWER_SETUP_I1_SHIFT , scale_factor );
484- ret = xe_hwmon_pcode_write_i1 (hwmon -> gt , uval );
493+ ret = xe_hwmon_pcode_write_i1 (hwmon , uval );
485494
486495 mutex_unlock (& hwmon -> hwmon_lock );
487496 return ret ;
488497}
489498
490499static void xe_hwmon_get_voltage (struct xe_hwmon * hwmon , int channel , long * value )
491500{
501+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
492502 u64 reg_val ;
493503
494- reg_val = xe_mmio_read32 (hwmon -> gt , xe_hwmon_get_reg (hwmon , REG_GT_PERF_STATUS , channel ));
504+ reg_val = xe_mmio_read32 (mmio , xe_hwmon_get_reg (hwmon , REG_GT_PERF_STATUS , channel ));
495505 /* HW register value in units of 2.5 millivolt */
496506 * value = DIV_ROUND_CLOSEST (REG_FIELD_GET (VOLTAGE_MASK , reg_val ) * 2500 , SF_VOLTAGE );
497507}
@@ -510,7 +520,7 @@ xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
510520 channel )) ? 0444 : 0 ;
511521 case hwmon_power_crit :
512522 if (channel == CHANNEL_PKG )
513- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
523+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
514524 !(uval & POWER_SETUP_I1_WATTS )) ? 0 : 0644 ;
515525 break ;
516526 case hwmon_power_label :
@@ -563,10 +573,10 @@ xe_hwmon_curr_is_visible(const struct xe_hwmon *hwmon, u32 attr, int channel)
563573
564574 switch (attr ) {
565575 case hwmon_curr_crit :
566- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
576+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
567577 (uval & POWER_SETUP_I1_WATTS )) ? 0 : 0644 ;
568578 case hwmon_curr_label :
569- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
579+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
570580 (uval & POWER_SETUP_I1_WATTS )) ? 0 : 0444 ;
571581 break ;
572582 default :
@@ -654,7 +664,7 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
654664 struct xe_hwmon * hwmon = (struct xe_hwmon * )drvdata ;
655665 int ret ;
656666
657- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
667+ xe_pm_runtime_get (hwmon -> xe );
658668
659669 switch (type ) {
660670 case hwmon_power :
@@ -674,7 +684,7 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
674684 break ;
675685 }
676686
677- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
687+ xe_pm_runtime_put (hwmon -> xe );
678688
679689 return ret ;
680690}
@@ -686,7 +696,7 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
686696 struct xe_hwmon * hwmon = dev_get_drvdata (dev );
687697 int ret ;
688698
689- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
699+ xe_pm_runtime_get (hwmon -> xe );
690700
691701 switch (type ) {
692702 case hwmon_power :
@@ -706,7 +716,7 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
706716 break ;
707717 }
708718
709- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
719+ xe_pm_runtime_put (hwmon -> xe );
710720
711721 return ret ;
712722}
@@ -718,7 +728,7 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
718728 struct xe_hwmon * hwmon = dev_get_drvdata (dev );
719729 int ret ;
720730
721- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
731+ xe_pm_runtime_get (hwmon -> xe );
722732
723733 switch (type ) {
724734 case hwmon_power :
@@ -732,7 +742,7 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
732742 break ;
733743 }
734744
735- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
745+ xe_pm_runtime_put (hwmon -> xe );
736746
737747 return ret ;
738748}
@@ -771,6 +781,7 @@ static const struct hwmon_chip_info hwmon_chip_info = {
771781static void
772782xe_hwmon_get_preregistration_info (struct xe_device * xe )
773783{
784+ struct xe_gt * mmio = xe_root_mmio_gt (xe );
774785 struct xe_hwmon * hwmon = xe -> hwmon ;
775786 long energy ;
776787 u64 val_sku_unit = 0 ;
@@ -783,7 +794,7 @@ xe_hwmon_get_preregistration_info(struct xe_device *xe)
783794 */
784795 pkg_power_sku_unit = xe_hwmon_get_reg (hwmon , REG_PKG_POWER_SKU_UNIT , 0 );
785796 if (xe_reg_is_valid (pkg_power_sku_unit )) {
786- val_sku_unit = xe_mmio_read32 (hwmon -> gt , pkg_power_sku_unit );
797+ val_sku_unit = xe_mmio_read32 (mmio , pkg_power_sku_unit );
787798 hwmon -> scl_shift_power = REG_FIELD_GET (PKG_PWR_UNIT , val_sku_unit );
788799 hwmon -> scl_shift_energy = REG_FIELD_GET (PKG_ENERGY_UNIT , val_sku_unit );
789800 hwmon -> scl_shift_time = REG_FIELD_GET (PKG_TIME_UNIT , val_sku_unit );
@@ -828,8 +839,8 @@ void xe_hwmon_register(struct xe_device *xe)
828839 if (devm_add_action_or_reset (dev , xe_hwmon_mutex_destroy , hwmon ))
829840 return ;
830841
831- /* primary GT to access device level properties */
832- hwmon -> gt = xe -> tiles [ 0 ]. primary_gt ;
842+ /* There's only one instance of hwmon per device */
843+ hwmon -> xe = xe ;
833844
834845 xe_hwmon_get_preregistration_info (xe );
835846
0 commit comments