12
12
#include "regs/xe_mchbar_regs.h"
13
13
#include "regs/xe_pcode_regs.h"
14
14
#include "xe_device.h"
15
- #include "xe_gt.h"
16
15
#include "xe_hwmon.h"
17
16
#include "xe_mmio.h"
18
17
#include "xe_pcode.h"
@@ -65,8 +64,8 @@ struct xe_hwmon_energy_info {
65
64
struct xe_hwmon {
66
65
/** @hwmon_dev: hwmon device for xe */
67
66
struct device * hwmon_dev ;
68
- /** @gt: primary gt */
69
- struct xe_gt * gt ;
67
+ /** @xe: Xe device */
68
+ struct xe_device * xe ;
70
69
/** @hwmon_lock: lock for rw attributes*/
71
70
struct mutex hwmon_lock ;
72
71
/** @scl_shift_power: pkg power unit */
@@ -82,7 +81,7 @@ struct xe_hwmon {
82
81
static struct xe_reg xe_hwmon_get_reg (struct xe_hwmon * hwmon , enum xe_hwmon_reg hwmon_reg ,
83
82
int channel )
84
83
{
85
- struct xe_device * xe = gt_to_xe ( hwmon -> gt ) ;
84
+ struct xe_device * xe = hwmon -> xe ;
86
85
87
86
switch (hwmon_reg ) {
88
87
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
148
147
static void xe_hwmon_power_max_read (struct xe_hwmon * hwmon , int channel , long * value )
149
148
{
150
149
u64 reg_val , min , max ;
151
- struct xe_device * xe = gt_to_xe ( hwmon -> gt ) ;
150
+ struct xe_device * xe = hwmon -> xe ;
152
151
struct xe_reg rapl_limit , pkg_power_sku ;
152
+ struct xe_gt * mmio = xe_root_mmio_gt (xe );
153
153
154
154
rapl_limit = xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , channel );
155
155
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
166
166
167
167
mutex_lock (& hwmon -> hwmon_lock );
168
168
169
- reg_val = xe_mmio_read32 (hwmon -> gt , rapl_limit );
169
+ reg_val = xe_mmio_read32 (mmio , rapl_limit );
170
170
/* Check if PL1 limit is disabled */
171
171
if (!(reg_val & PKG_PWR_LIM_1_EN )) {
172
172
* value = PL1_DISABLE ;
@@ -176,7 +176,7 @@ static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, int channel, long *v
176
176
reg_val = REG_FIELD_GET (PKG_PWR_LIM_1 , reg_val );
177
177
* value = mul_u64_u32_shr (reg_val , SF_POWER , hwmon -> scl_shift_power );
178
178
179
- reg_val = xe_mmio_read64_2x32 (hwmon -> gt , pkg_power_sku );
179
+ reg_val = xe_mmio_read64_2x32 (mmio , pkg_power_sku );
180
180
min = REG_FIELD_GET (PKG_MIN_PWR , reg_val );
181
181
min = mul_u64_u32_shr (min , SF_POWER , hwmon -> scl_shift_power );
182
182
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
190
190
191
191
static int xe_hwmon_power_max_write (struct xe_hwmon * hwmon , int channel , long value )
192
192
{
193
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
193
194
int ret = 0 ;
194
195
u64 reg_val ;
195
196
struct xe_reg rapl_limit ;
@@ -200,10 +201,10 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
200
201
201
202
/* Disable PL1 limit and verify, as limit cannot be disabled on all platforms */
202
203
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 );
205
206
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" );
207
208
ret = - EOPNOTSUPP ;
208
209
}
209
210
goto unlock ;
@@ -212,7 +213,7 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
212
213
/* Computation in 64-bits to avoid overflow. Round to nearest. */
213
214
reg_val = DIV_ROUND_CLOSEST_ULL ((u64 )value << hwmon -> scl_shift_power , SF_POWER );
214
215
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 );
216
217
217
218
unlock :
218
219
mutex_unlock (& hwmon -> hwmon_lock );
@@ -221,6 +222,7 @@ static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long va
221
222
222
223
static void xe_hwmon_power_rated_max_read (struct xe_hwmon * hwmon , int channel , long * value )
223
224
{
225
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
224
226
struct xe_reg reg = xe_hwmon_get_reg (hwmon , REG_PKG_POWER_SKU , channel );
225
227
u64 reg_val ;
226
228
@@ -229,7 +231,7 @@ static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, int channel, l
229
231
* for this register can be skipped.
230
232
* See xe_hwmon_power_is_visible.
231
233
*/
232
- reg_val = xe_mmio_read32 (hwmon -> gt , reg );
234
+ reg_val = xe_mmio_read32 (mmio , reg );
233
235
reg_val = REG_FIELD_GET (PKG_TDP , reg_val );
234
236
* value = mul_u64_u32_shr (reg_val , SF_POWER , hwmon -> scl_shift_power );
235
237
}
@@ -257,11 +259,12 @@ static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, int channel, l
257
259
static void
258
260
xe_hwmon_energy_get (struct xe_hwmon * hwmon , int channel , long * energy )
259
261
{
262
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
260
263
struct xe_hwmon_energy_info * ei = & hwmon -> ei [channel ];
261
264
u64 reg_val ;
262
265
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 ));
265
268
266
269
if (reg_val >= ei -> reg_val_prev )
267
270
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
279
282
char * buf )
280
283
{
281
284
struct xe_hwmon * hwmon = dev_get_drvdata (dev );
285
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
282
286
u32 x , y , x_w = 2 ; /* 2 bits */
283
287
u64 r , tau4 , out ;
284
288
int sensor_index = to_sensor_dev_attr (attr )-> index ;
285
289
286
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
290
+ xe_pm_runtime_get (hwmon -> xe );
287
291
288
292
mutex_lock (& hwmon -> hwmon_lock );
289
293
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 ));
291
295
292
296
mutex_unlock (& hwmon -> hwmon_lock );
293
297
294
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
298
+ xe_pm_runtime_put (hwmon -> xe );
295
299
296
300
x = REG_FIELD_GET (PKG_PWR_LIM_1_TIME_X , r );
297
301
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
319
323
const char * buf , size_t count )
320
324
{
321
325
struct xe_hwmon * hwmon = dev_get_drvdata (dev );
326
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
322
327
u32 x , y , rxy , x_w = 2 ; /* 2 bits */
323
328
u64 tau4 , r , max_win ;
324
329
unsigned long val ;
@@ -371,16 +376,16 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a
371
376
372
377
rxy = REG_FIELD_PREP (PKG_PWR_LIM_1_TIME_X , x ) | REG_FIELD_PREP (PKG_PWR_LIM_1_TIME_Y , y );
373
378
374
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
379
+ xe_pm_runtime_get (hwmon -> xe );
375
380
376
381
mutex_lock (& hwmon -> hwmon_lock );
377
382
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 ),
379
384
PKG_PWR_LIM_1_TIME , rxy );
380
385
381
386
mutex_unlock (& hwmon -> hwmon_lock );
382
387
383
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
388
+ xe_pm_runtime_put (hwmon -> xe );
384
389
385
390
return count ;
386
391
}
@@ -406,11 +411,11 @@ static umode_t xe_hwmon_attributes_visible(struct kobject *kobj,
406
411
struct xe_hwmon * hwmon = dev_get_drvdata (dev );
407
412
int ret = 0 ;
408
413
409
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
414
+ xe_pm_runtime_get (hwmon -> xe );
410
415
411
416
ret = xe_reg_is_valid (xe_hwmon_get_reg (hwmon , REG_PKG_RAPL_LIMIT , index )) ? attr -> mode : 0 ;
412
417
413
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
418
+ xe_pm_runtime_put (hwmon -> xe );
414
419
415
420
return ret ;
416
421
}
@@ -435,20 +440,24 @@ static const struct hwmon_channel_info * const hwmon_info[] = {
435
440
};
436
441
437
442
/* 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 )
439
444
{
445
+ struct xe_tile * root_tile = xe_device_get_root_tile (hwmon -> xe );
446
+
440
447
/* Avoid Illegal Subcommand error */
441
- if (gt_to_xe ( gt ) -> info .platform == XE_DG2 )
448
+ if (hwmon -> xe -> info .platform == XE_DG2 )
442
449
return - ENXIO ;
443
450
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 ,
445
452
POWER_SETUP_SUBCOMMAND_READ_I1 , 0 ),
446
453
uval , NULL );
447
454
}
448
455
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 )
450
457
{
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 ,
452
461
POWER_SETUP_SUBCOMMAND_WRITE_I1 , 0 ),
453
462
(uval & POWER_SETUP_I1_DATA_MASK ));
454
463
}
@@ -461,7 +470,7 @@ static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel,
461
470
462
471
mutex_lock (& hwmon -> hwmon_lock );
463
472
464
- ret = xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval );
473
+ ret = xe_hwmon_pcode_read_i1 (hwmon , & uval );
465
474
if (ret )
466
475
goto unlock ;
467
476
@@ -481,17 +490,18 @@ static int xe_hwmon_power_curr_crit_write(struct xe_hwmon *hwmon, int channel,
481
490
mutex_lock (& hwmon -> hwmon_lock );
482
491
483
492
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 );
485
494
486
495
mutex_unlock (& hwmon -> hwmon_lock );
487
496
return ret ;
488
497
}
489
498
490
499
static void xe_hwmon_get_voltage (struct xe_hwmon * hwmon , int channel , long * value )
491
500
{
501
+ struct xe_gt * mmio = xe_root_mmio_gt (hwmon -> xe );
492
502
u64 reg_val ;
493
503
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 ));
495
505
/* HW register value in units of 2.5 millivolt */
496
506
* value = DIV_ROUND_CLOSEST (REG_FIELD_GET (VOLTAGE_MASK , reg_val ) * 2500 , SF_VOLTAGE );
497
507
}
@@ -510,7 +520,7 @@ xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
510
520
channel )) ? 0444 : 0 ;
511
521
case hwmon_power_crit :
512
522
if (channel == CHANNEL_PKG )
513
- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
523
+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
514
524
!(uval & POWER_SETUP_I1_WATTS )) ? 0 : 0644 ;
515
525
break ;
516
526
case hwmon_power_label :
@@ -563,10 +573,10 @@ xe_hwmon_curr_is_visible(const struct xe_hwmon *hwmon, u32 attr, int channel)
563
573
564
574
switch (attr ) {
565
575
case hwmon_curr_crit :
566
- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
576
+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
567
577
(uval & POWER_SETUP_I1_WATTS )) ? 0 : 0644 ;
568
578
case hwmon_curr_label :
569
- return (xe_hwmon_pcode_read_i1 (hwmon -> gt , & uval ) ||
579
+ return (xe_hwmon_pcode_read_i1 (hwmon , & uval ) ||
570
580
(uval & POWER_SETUP_I1_WATTS )) ? 0 : 0444 ;
571
581
break ;
572
582
default :
@@ -654,7 +664,7 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
654
664
struct xe_hwmon * hwmon = (struct xe_hwmon * )drvdata ;
655
665
int ret ;
656
666
657
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
667
+ xe_pm_runtime_get (hwmon -> xe );
658
668
659
669
switch (type ) {
660
670
case hwmon_power :
@@ -674,7 +684,7 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
674
684
break ;
675
685
}
676
686
677
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
687
+ xe_pm_runtime_put (hwmon -> xe );
678
688
679
689
return ret ;
680
690
}
@@ -686,7 +696,7 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
686
696
struct xe_hwmon * hwmon = dev_get_drvdata (dev );
687
697
int ret ;
688
698
689
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
699
+ xe_pm_runtime_get (hwmon -> xe );
690
700
691
701
switch (type ) {
692
702
case hwmon_power :
@@ -706,7 +716,7 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
706
716
break ;
707
717
}
708
718
709
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
719
+ xe_pm_runtime_put (hwmon -> xe );
710
720
711
721
return ret ;
712
722
}
@@ -718,7 +728,7 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
718
728
struct xe_hwmon * hwmon = dev_get_drvdata (dev );
719
729
int ret ;
720
730
721
- xe_pm_runtime_get (gt_to_xe ( hwmon -> gt ) );
731
+ xe_pm_runtime_get (hwmon -> xe );
722
732
723
733
switch (type ) {
724
734
case hwmon_power :
@@ -732,7 +742,7 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
732
742
break ;
733
743
}
734
744
735
- xe_pm_runtime_put (gt_to_xe ( hwmon -> gt ) );
745
+ xe_pm_runtime_put (hwmon -> xe );
736
746
737
747
return ret ;
738
748
}
@@ -771,6 +781,7 @@ static const struct hwmon_chip_info hwmon_chip_info = {
771
781
static void
772
782
xe_hwmon_get_preregistration_info (struct xe_device * xe )
773
783
{
784
+ struct xe_gt * mmio = xe_root_mmio_gt (xe );
774
785
struct xe_hwmon * hwmon = xe -> hwmon ;
775
786
long energy ;
776
787
u64 val_sku_unit = 0 ;
@@ -783,7 +794,7 @@ xe_hwmon_get_preregistration_info(struct xe_device *xe)
783
794
*/
784
795
pkg_power_sku_unit = xe_hwmon_get_reg (hwmon , REG_PKG_POWER_SKU_UNIT , 0 );
785
796
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 );
787
798
hwmon -> scl_shift_power = REG_FIELD_GET (PKG_PWR_UNIT , val_sku_unit );
788
799
hwmon -> scl_shift_energy = REG_FIELD_GET (PKG_ENERGY_UNIT , val_sku_unit );
789
800
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)
828
839
if (devm_add_action_or_reset (dev , xe_hwmon_mutex_destroy , hwmon ))
829
840
return ;
830
841
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 ;
833
844
834
845
xe_hwmon_get_preregistration_info (xe );
835
846
0 commit comments