@@ -32,6 +32,7 @@ struct etnaviv_pm_domain {
32
32
};
33
33
34
34
struct etnaviv_pm_domain_meta {
35
+ unsigned int feature ;
35
36
const struct etnaviv_pm_domain * domains ;
36
37
u32 nr_domains ;
37
38
};
@@ -410,36 +411,78 @@ static const struct etnaviv_pm_domain doms_vg[] = {
410
411
411
412
static const struct etnaviv_pm_domain_meta doms_meta [] = {
412
413
{
414
+ .feature = chipFeatures_PIPE_3D ,
413
415
.nr_domains = ARRAY_SIZE (doms_3d ),
414
416
.domains = & doms_3d [0 ]
415
417
},
416
418
{
419
+ .feature = chipFeatures_PIPE_2D ,
417
420
.nr_domains = ARRAY_SIZE (doms_2d ),
418
421
.domains = & doms_2d [0 ]
419
422
},
420
423
{
424
+ .feature = chipFeatures_PIPE_VG ,
421
425
.nr_domains = ARRAY_SIZE (doms_vg ),
422
426
.domains = & doms_vg [0 ]
423
427
}
424
428
};
425
429
430
+ static unsigned int num_pm_domains (const struct etnaviv_gpu * gpu )
431
+ {
432
+ unsigned int num = 0 , i ;
433
+
434
+ for (i = 0 ; i < ARRAY_SIZE (doms_meta ); i ++ ) {
435
+ const struct etnaviv_pm_domain_meta * meta = & doms_meta [i ];
436
+
437
+ if (gpu -> identity .features & meta -> feature )
438
+ num += meta -> nr_domains ;
439
+ }
440
+
441
+ return num ;
442
+ }
443
+
444
+ static const struct etnaviv_pm_domain * pm_domain (const struct etnaviv_gpu * gpu ,
445
+ unsigned int index )
446
+ {
447
+ const struct etnaviv_pm_domain * domain = NULL ;
448
+ unsigned int offset = 0 , i ;
449
+
450
+ for (i = 0 ; i < ARRAY_SIZE (doms_meta ); i ++ ) {
451
+ const struct etnaviv_pm_domain_meta * meta = & doms_meta [i ];
452
+
453
+ if (!(gpu -> identity .features & meta -> feature ))
454
+ continue ;
455
+
456
+ if (meta -> nr_domains < (index - offset )) {
457
+ offset += meta -> nr_domains ;
458
+ continue ;
459
+ }
460
+
461
+ domain = meta -> domains + (index - offset );
462
+ }
463
+
464
+ return domain ;
465
+ }
466
+
426
467
int etnaviv_pm_query_dom (struct etnaviv_gpu * gpu ,
427
468
struct drm_etnaviv_pm_domain * domain )
428
469
{
429
- const struct etnaviv_pm_domain_meta * meta = & doms_meta [ domain -> pipe ] ;
470
+ const unsigned int nr_domains = num_pm_domains ( gpu ) ;
430
471
const struct etnaviv_pm_domain * dom ;
431
472
432
- if (domain -> iter >= meta -> nr_domains )
473
+ if (domain -> iter >= nr_domains )
433
474
return - EINVAL ;
434
475
435
- dom = meta -> domains + domain -> iter ;
476
+ dom = pm_domain (gpu , domain -> iter );
477
+ if (!dom )
478
+ return - EINVAL ;
436
479
437
480
domain -> id = domain -> iter ;
438
481
domain -> nr_signals = dom -> nr_signals ;
439
482
strncpy (domain -> name , dom -> name , sizeof (domain -> name ));
440
483
441
484
domain -> iter ++ ;
442
- if (domain -> iter == meta -> nr_domains )
485
+ if (domain -> iter == nr_domains )
443
486
domain -> iter = 0xff ;
444
487
445
488
return 0 ;
@@ -448,14 +491,16 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
448
491
int etnaviv_pm_query_sig (struct etnaviv_gpu * gpu ,
449
492
struct drm_etnaviv_pm_signal * signal )
450
493
{
451
- const struct etnaviv_pm_domain_meta * meta = & doms_meta [ signal -> pipe ] ;
494
+ const unsigned int nr_domains = num_pm_domains ( gpu ) ;
452
495
const struct etnaviv_pm_domain * dom ;
453
496
const struct etnaviv_pm_signal * sig ;
454
497
455
- if (signal -> domain >= meta -> nr_domains )
498
+ if (signal -> domain >= nr_domains )
456
499
return - EINVAL ;
457
500
458
- dom = meta -> domains + signal -> domain ;
501
+ dom = pm_domain (gpu , signal -> domain );
502
+ if (!dom )
503
+ return - EINVAL ;
459
504
460
505
if (signal -> iter >= dom -> nr_signals )
461
506
return - EINVAL ;
0 commit comments