Skip to content

Commit ed1dd89

Browse files
austriancoderlynxeye-dev
authored andcommitted
drm/etnaviv: rework perfmon query infrastructure
Report the correct perfmon domains and signals depending on the supported feature flags. Reported-by: Dan Carpenter <[email protected]> Fixes: 9e2c2e2 ("drm/etnaviv: add infrastructure to query perf counter") Cc: [email protected] Signed-off-by: Christian Gmeiner <[email protected]> Signed-off-by: Lucas Stach <[email protected]>
1 parent f56f157 commit ed1dd89

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

drivers/gpu/drm/etnaviv/etnaviv_perfmon.c

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct etnaviv_pm_domain {
3232
};
3333

3434
struct etnaviv_pm_domain_meta {
35+
unsigned int feature;
3536
const struct etnaviv_pm_domain *domains;
3637
u32 nr_domains;
3738
};
@@ -410,36 +411,78 @@ static const struct etnaviv_pm_domain doms_vg[] = {
410411

411412
static const struct etnaviv_pm_domain_meta doms_meta[] = {
412413
{
414+
.feature = chipFeatures_PIPE_3D,
413415
.nr_domains = ARRAY_SIZE(doms_3d),
414416
.domains = &doms_3d[0]
415417
},
416418
{
419+
.feature = chipFeatures_PIPE_2D,
417420
.nr_domains = ARRAY_SIZE(doms_2d),
418421
.domains = &doms_2d[0]
419422
},
420423
{
424+
.feature = chipFeatures_PIPE_VG,
421425
.nr_domains = ARRAY_SIZE(doms_vg),
422426
.domains = &doms_vg[0]
423427
}
424428
};
425429

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+
426467
int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
427468
struct drm_etnaviv_pm_domain *domain)
428469
{
429-
const struct etnaviv_pm_domain_meta *meta = &doms_meta[domain->pipe];
470+
const unsigned int nr_domains = num_pm_domains(gpu);
430471
const struct etnaviv_pm_domain *dom;
431472

432-
if (domain->iter >= meta->nr_domains)
473+
if (domain->iter >= nr_domains)
433474
return -EINVAL;
434475

435-
dom = meta->domains + domain->iter;
476+
dom = pm_domain(gpu, domain->iter);
477+
if (!dom)
478+
return -EINVAL;
436479

437480
domain->id = domain->iter;
438481
domain->nr_signals = dom->nr_signals;
439482
strncpy(domain->name, dom->name, sizeof(domain->name));
440483

441484
domain->iter++;
442-
if (domain->iter == meta->nr_domains)
485+
if (domain->iter == nr_domains)
443486
domain->iter = 0xff;
444487

445488
return 0;
@@ -448,14 +491,16 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
448491
int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
449492
struct drm_etnaviv_pm_signal *signal)
450493
{
451-
const struct etnaviv_pm_domain_meta *meta = &doms_meta[signal->pipe];
494+
const unsigned int nr_domains = num_pm_domains(gpu);
452495
const struct etnaviv_pm_domain *dom;
453496
const struct etnaviv_pm_signal *sig;
454497

455-
if (signal->domain >= meta->nr_domains)
498+
if (signal->domain >= nr_domains)
456499
return -EINVAL;
457500

458-
dom = meta->domains + signal->domain;
501+
dom = pm_domain(gpu, signal->domain);
502+
if (!dom)
503+
return -EINVAL;
459504

460505
if (signal->iter >= dom->nr_signals)
461506
return -EINVAL;

0 commit comments

Comments
 (0)