Lines Matching full:pmu
40 #define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu)
53 const char *identifier; /* system PMU identifier for userspace */
83 { .compatible = "fsl,imx8-ddr-pmu", .data = &imx8_devtype_data},
84 { .compatible = "fsl,imx8m-ddr-pmu", .data = &imx8m_devtype_data},
85 { .compatible = "fsl,imx8mq-ddr-pmu", .data = &imx8mq_devtype_data},
86 { .compatible = "fsl,imx8mm-ddr-pmu", .data = &imx8mm_devtype_data},
87 { .compatible = "fsl,imx8mn-ddr-pmu", .data = &imx8mn_devtype_data},
88 { .compatible = "fsl,imx8mp-ddr-pmu", .data = &imx8mp_devtype_data},
94 struct pmu pmu; member
111 struct ddr_pmu *pmu = dev_get_drvdata(dev); in ddr_perf_identifier_show() local
113 return sysfs_emit(page, "%s\n", pmu->devtype_data->identifier); in ddr_perf_identifier_show()
121 struct ddr_pmu *pmu = dev_get_drvdata(dev); in ddr_perf_identifier_attr_visible() local
123 if (!pmu->devtype_data->identifier) in ddr_perf_identifier_attr_visible()
147 static u32 ddr_perf_filter_cap_get(struct ddr_pmu *pmu, int cap) in ddr_perf_filter_cap_get() argument
149 u32 quirks = pmu->devtype_data->quirks; in ddr_perf_filter_cap_get()
168 struct ddr_pmu *pmu = dev_get_drvdata(dev); in ddr_perf_filter_cap_show() local
173 return sysfs_emit(buf, "%u\n", ddr_perf_filter_cap_get(pmu, cap)); in ddr_perf_filter_cap_show()
198 struct ddr_pmu *pmu = dev_get_drvdata(dev); in ddr_perf_cpumask_show() local
200 return cpumap_print_to_pagebuf(true, buf, cpumask_of(pmu->cpu)); in ddr_perf_cpumask_show()
317 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_is_enhanced_filtered() local
319 filt = pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED; in ddr_perf_is_enhanced_filtered()
324 static u32 ddr_perf_alloc_counter(struct ddr_pmu *pmu, int event) in ddr_perf_alloc_counter() argument
334 if (pmu->events[EVENT_CYCLES_COUNTER] == NULL) in ddr_perf_alloc_counter()
341 if (pmu->events[i] == NULL) in ddr_perf_alloc_counter()
348 static void ddr_perf_free_counter(struct ddr_pmu *pmu, int counter) in ddr_perf_free_counter() argument
350 pmu->events[counter] = NULL; in ddr_perf_free_counter()
353 static u32 ddr_perf_read_counter(struct ddr_pmu *pmu, int counter) in ddr_perf_read_counter() argument
355 struct perf_event *event = pmu->events[counter]; in ddr_perf_read_counter()
356 void __iomem *base = pmu->base; in ddr_perf_read_counter()
360 * axid-read and axid-write event if PMU core supports enhanced in ddr_perf_read_counter()
370 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_init() local
374 if (event->attr.type != event->pmu->type) in ddr_perf_event_init()
381 dev_warn(pmu->dev, "Can't provide per-task data!\n"); in ddr_perf_event_init()
390 if (event->group_leader->pmu != event->pmu && in ddr_perf_event_init()
394 if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) { in ddr_perf_event_init()
404 if (sibling->pmu != event->pmu && in ddr_perf_event_init()
409 event->cpu = pmu->cpu; in ddr_perf_event_init()
415 static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, in ddr_perf_counter_enable() argument
428 writel(0, pmu->base + reg); in ddr_perf_counter_enable()
431 writel(val, pmu->base + reg); in ddr_perf_counter_enable()
434 val = readl_relaxed(pmu->base + reg) & CNTL_EN_MASK; in ddr_perf_counter_enable()
435 writel(val, pmu->base + reg); in ddr_perf_counter_enable()
439 static bool ddr_perf_counter_overflow(struct ddr_pmu *pmu, int counter) in ddr_perf_counter_overflow() argument
443 val = readl_relaxed(pmu->base + counter * 4 + COUNTER_CNTL); in ddr_perf_counter_overflow()
448 static void ddr_perf_counter_clear(struct ddr_pmu *pmu, int counter) in ddr_perf_counter_clear() argument
453 val = readl_relaxed(pmu->base + reg); in ddr_perf_counter_clear()
455 writel(val, pmu->base + reg); in ddr_perf_counter_clear()
458 writel(val, pmu->base + reg); in ddr_perf_counter_clear()
463 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_update() local
469 new_raw_count = ddr_perf_read_counter(pmu, counter); in ddr_perf_event_update()
479 ret = ddr_perf_counter_overflow(pmu, counter); in ddr_perf_event_update()
481 dev_warn_ratelimited(pmu->dev, "events lost due to counter overflow (config 0x%llx)\n", in ddr_perf_event_update()
486 ddr_perf_counter_clear(pmu, counter); in ddr_perf_event_update()
491 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_start() local
497 ddr_perf_counter_enable(pmu, event->attr.config, counter, true); in ddr_perf_event_start()
504 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_add() local
510 if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) { in ddr_perf_event_add()
514 if (pmu->events[i] && in ddr_perf_event_add()
515 !ddr_perf_filters_compatible(event, pmu->events[i])) in ddr_perf_event_add()
522 writel(cfg1, pmu->base + COUNTER_DPCR1); in ddr_perf_event_add()
526 counter = ddr_perf_alloc_counter(pmu, cfg); in ddr_perf_event_add()
528 dev_dbg(pmu->dev, "There are not enough counters\n"); in ddr_perf_event_add()
532 pmu->events[counter] = event; in ddr_perf_event_add()
533 pmu->active_events++; in ddr_perf_event_add()
546 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_stop() local
550 ddr_perf_counter_enable(pmu, event->attr.config, counter, false); in ddr_perf_event_stop()
558 struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); in ddr_perf_event_del() local
564 ddr_perf_free_counter(pmu, counter); in ddr_perf_event_del()
565 pmu->active_events--; in ddr_perf_event_del()
569 static void ddr_perf_pmu_enable(struct pmu *pmu) in ddr_perf_pmu_enable() argument
571 struct ddr_pmu *ddr_pmu = to_ddr_pmu(pmu); in ddr_perf_pmu_enable()
581 static void ddr_perf_pmu_disable(struct pmu *pmu) in ddr_perf_pmu_disable() argument
583 struct ddr_pmu *ddr_pmu = to_ddr_pmu(pmu); in ddr_perf_pmu_disable()
592 static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base, in ddr_perf_init() argument
595 *pmu = (struct ddr_pmu) { in ddr_perf_init()
596 .pmu = (struct pmu) { in ddr_perf_init()
614 pmu->id = ida_alloc(&ddr_ida, GFP_KERNEL); in ddr_perf_init()
615 return pmu->id; in ddr_perf_init()
621 struct ddr_pmu *pmu = (struct ddr_pmu *) p; in ddr_perf_irq_handler() local
625 ddr_perf_counter_enable(pmu, in ddr_perf_irq_handler()
643 if (!pmu->events[i]) in ddr_perf_irq_handler()
646 event = pmu->events[i]; in ddr_perf_irq_handler()
651 ddr_perf_counter_enable(pmu, in ddr_perf_irq_handler()
661 struct ddr_pmu *pmu = hlist_entry_safe(node, struct ddr_pmu, node); in ddr_perf_offline_cpu() local
664 if (cpu != pmu->cpu) in ddr_perf_offline_cpu()
671 perf_pmu_migrate_context(&pmu->pmu, cpu, target); in ddr_perf_offline_cpu()
672 pmu->cpu = target; in ddr_perf_offline_cpu()
674 WARN_ON(irq_set_affinity(pmu->irq, cpumask_of(pmu->cpu))); in ddr_perf_offline_cpu()
681 struct ddr_pmu *pmu; in ddr_perf_probe() local
695 pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL); in ddr_perf_probe()
696 if (!pmu) in ddr_perf_probe()
699 num = ddr_perf_init(pmu, base, &pdev->dev); in ddr_perf_probe()
701 platform_set_drvdata(pdev, pmu); in ddr_perf_probe()
710 pmu->devtype_data = of_device_get_match_data(&pdev->dev); in ddr_perf_probe()
712 pmu->cpu = raw_smp_processor_id(); in ddr_perf_probe()
723 pmu->cpuhp_state = ret; in ddr_perf_probe()
725 /* Register the pmu instance for cpu hotplug */ in ddr_perf_probe()
726 ret = cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node); in ddr_perf_probe()
744 pmu); in ddr_perf_probe()
750 pmu->irq = irq; in ddr_perf_probe()
751 ret = irq_set_affinity(pmu->irq, cpumask_of(pmu->cpu)); in ddr_perf_probe()
753 dev_err(pmu->dev, "Failed to set interrupt affinity!\n"); in ddr_perf_probe()
757 ret = perf_pmu_register(&pmu->pmu, name, -1); in ddr_perf_probe()
764 cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node); in ddr_perf_probe()
766 cpuhp_remove_multi_state(pmu->cpuhp_state); in ddr_perf_probe()
768 ida_free(&ddr_ida, pmu->id); in ddr_perf_probe()
769 dev_warn(&pdev->dev, "i.MX8 DDR Perf PMU failed (%d), disabled\n", ret); in ddr_perf_probe()
775 struct ddr_pmu *pmu = platform_get_drvdata(pdev); in ddr_perf_remove() local
777 cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node); in ddr_perf_remove()
778 cpuhp_remove_multi_state(pmu->cpuhp_state); in ddr_perf_remove()
780 perf_pmu_unregister(&pmu->pmu); in ddr_perf_remove()
782 ida_free(&ddr_ida, pmu->id); in ddr_perf_remove()
788 .name = "imx-ddr-pmu",