1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * HiSilicon SoC Hardware event counters support
4 *
5 * Copyright (C) 2017 HiSilicon Limited
6 * Author: Anurup M <anurup.m@huawei.com>
7 * Shaokun Zhang <zhangshaokun@hisilicon.com>
8 *
9 * This code is based on the uncore PMUs like arm-cci and arm-ccn.
10 */
11 #include <linux/bitmap.h>
12 #include <linux/bitops.h>
13 #include <linux/bug.h>
14 #include <linux/err.h>
15 #include <linux/errno.h>
16 #include <linux/interrupt.h>
17 #include <linux/property.h>
18
19 #include <asm/cputype.h>
20 #include <asm/local64.h>
21
22 #include "hisi_uncore_pmu.h"
23
24 #define HISI_MAX_PERIOD(nr) (GENMASK_ULL((nr) - 1, 0))
25
26 /*
27 * PMU event attributes
28 */
hisi_event_sysfs_show(struct device * dev,struct device_attribute * attr,char * page)29 ssize_t hisi_event_sysfs_show(struct device *dev,
30 struct device_attribute *attr, char *page)
31 {
32 struct dev_ext_attribute *eattr;
33
34 eattr = container_of(attr, struct dev_ext_attribute, attr);
35
36 return sysfs_emit(page, "config=0x%lx\n", (unsigned long)eattr->var);
37 }
38 EXPORT_SYMBOL_NS_GPL(hisi_event_sysfs_show, "HISI_PMU");
39
40 /*
41 * sysfs cpumask attributes. For uncore PMU, we only have a single CPU to show
42 */
hisi_cpumask_sysfs_show(struct device * dev,struct device_attribute * attr,char * buf)43 ssize_t hisi_cpumask_sysfs_show(struct device *dev,
44 struct device_attribute *attr, char *buf)
45 {
46 struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
47
48 return sysfs_emit(buf, "%d\n", hisi_pmu->on_cpu);
49 }
50 EXPORT_SYMBOL_NS_GPL(hisi_cpumask_sysfs_show, "HISI_PMU");
51
52 static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
53
hisi_associated_cpus_sysfs_show(struct device * dev,struct device_attribute * attr,char * buf)54 static ssize_t hisi_associated_cpus_sysfs_show(struct device *dev,
55 struct device_attribute *attr, char *buf)
56 {
57 struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
58
59 return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(&hisi_pmu->associated_cpus));
60 }
61 static DEVICE_ATTR(associated_cpus, 0444, hisi_associated_cpus_sysfs_show, NULL);
62
63 static struct attribute *hisi_pmu_cpumask_attrs[] = {
64 &dev_attr_cpumask.attr,
65 &dev_attr_associated_cpus.attr,
66 NULL
67 };
68
69 const struct attribute_group hisi_pmu_cpumask_attr_group = {
70 .attrs = hisi_pmu_cpumask_attrs,
71 };
72 EXPORT_SYMBOL_NS_GPL(hisi_pmu_cpumask_attr_group, "HISI_PMU");
73
hisi_uncore_pmu_identifier_attr_show(struct device * dev,struct device_attribute * attr,char * page)74 ssize_t hisi_uncore_pmu_identifier_attr_show(struct device *dev,
75 struct device_attribute *attr,
76 char *page)
77 {
78 struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
79
80 return sysfs_emit(page, "0x%08x\n", hisi_pmu->identifier);
81 }
82 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_identifier_attr_show, "HISI_PMU");
83
84 static struct device_attribute hisi_pmu_identifier_attr =
85 __ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL);
86
87 static struct attribute *hisi_pmu_identifier_attrs[] = {
88 &hisi_pmu_identifier_attr.attr,
89 NULL
90 };
91
92 const struct attribute_group hisi_pmu_identifier_group = {
93 .attrs = hisi_pmu_identifier_attrs,
94 };
95 EXPORT_SYMBOL_NS_GPL(hisi_pmu_identifier_group, "HISI_PMU");
96
hisi_validate_event_group(struct perf_event * event)97 static bool hisi_validate_event_group(struct perf_event *event)
98 {
99 struct perf_event *sibling, *leader = event->group_leader;
100 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
101 /* Include count for the event */
102 int counters = 1;
103
104 if (!is_software_event(leader)) {
105 /*
106 * We must NOT create groups containing mixed PMUs, although
107 * software events are acceptable
108 */
109 if (leader->pmu != event->pmu)
110 return false;
111
112 /* Increment counter for the leader */
113 if (leader != event)
114 counters++;
115 }
116
117 for_each_sibling_event(sibling, event->group_leader) {
118 if (is_software_event(sibling))
119 continue;
120 if (sibling->pmu != event->pmu)
121 return false;
122 /* Increment counter for each sibling */
123 counters++;
124 }
125
126 /* The group can not count events more than the counters in the HW */
127 return counters <= hisi_pmu->num_counters;
128 }
129
hisi_uncore_pmu_get_event_idx(struct perf_event * event)130 int hisi_uncore_pmu_get_event_idx(struct perf_event *event)
131 {
132 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
133 unsigned long *used_mask = hisi_pmu->pmu_events.used_mask;
134 u32 num_counters = hisi_pmu->num_counters;
135 int idx;
136
137 idx = find_first_zero_bit(used_mask, num_counters);
138 if (idx == num_counters)
139 return -EAGAIN;
140
141 set_bit(idx, used_mask);
142
143 return idx;
144 }
145 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_get_event_idx, "HISI_PMU");
146
hisi_uncore_pmu_clear_event_idx(struct hisi_pmu * hisi_pmu,int idx)147 static void hisi_uncore_pmu_clear_event_idx(struct hisi_pmu *hisi_pmu, int idx)
148 {
149 clear_bit(idx, hisi_pmu->pmu_events.used_mask);
150 }
151
hisi_uncore_pmu_isr(int irq,void * data)152 irqreturn_t hisi_uncore_pmu_isr(int irq, void *data)
153 {
154 struct hisi_pmu *hisi_pmu = data;
155 struct perf_event *event;
156 unsigned long overflown;
157 int idx;
158
159 overflown = hisi_pmu->ops->get_int_status(hisi_pmu);
160 if (!overflown)
161 return IRQ_NONE;
162
163 /*
164 * Find the counter index which overflowed if the bit was set
165 * and handle it.
166 */
167 for_each_set_bit(idx, &overflown, hisi_pmu->num_counters) {
168 /* Write 1 to clear the IRQ status flag */
169 hisi_pmu->ops->clear_int_status(hisi_pmu, idx);
170 /* Get the corresponding event struct */
171 event = hisi_pmu->pmu_events.hw_events[idx];
172 if (!event)
173 continue;
174
175 hisi_uncore_pmu_event_update(event);
176 hisi_uncore_pmu_set_event_period(event);
177 }
178
179 return IRQ_HANDLED;
180 }
181 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_isr, "HISI_PMU");
182
hisi_uncore_pmu_init_irq(struct hisi_pmu * hisi_pmu,struct platform_device * pdev)183 int hisi_uncore_pmu_init_irq(struct hisi_pmu *hisi_pmu,
184 struct platform_device *pdev)
185 {
186 int irq, ret;
187
188 irq = platform_get_irq(pdev, 0);
189 if (irq < 0)
190 return irq;
191
192 ret = devm_request_irq(&pdev->dev, irq, hisi_uncore_pmu_isr,
193 IRQF_NOBALANCING | IRQF_NO_THREAD,
194 dev_name(&pdev->dev), hisi_pmu);
195 if (ret < 0)
196 return ret;
197
198 hisi_pmu->irq = irq;
199
200 return 0;
201 }
202 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_init_irq, "HISI_PMU");
203
hisi_uncore_pmu_event_init(struct perf_event * event)204 int hisi_uncore_pmu_event_init(struct perf_event *event)
205 {
206 struct hw_perf_event *hwc = &event->hw;
207 struct hisi_pmu *hisi_pmu;
208
209 if (event->attr.type != event->pmu->type)
210 return -ENOENT;
211
212 /*
213 * We do not support sampling as the counters are all
214 * shared by all CPU cores in a CPU die(SCCL). Also we
215 * do not support attach to a task(per-process mode)
216 */
217 if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
218 return -EOPNOTSUPP;
219
220 /*
221 * The uncore counters not specific to any CPU, so cannot
222 * support per-task
223 */
224 if (event->cpu < 0)
225 return -EINVAL;
226
227 /*
228 * Validate if the events in group does not exceed the
229 * available counters in hardware.
230 */
231 if (!hisi_validate_event_group(event))
232 return -EINVAL;
233
234 hisi_pmu = to_hisi_pmu(event->pmu);
235 if ((event->attr.config & HISI_EVENTID_MASK) > hisi_pmu->check_event)
236 return -EINVAL;
237
238 if (hisi_pmu->on_cpu == -1)
239 return -EINVAL;
240 /*
241 * We don't assign an index until we actually place the event onto
242 * hardware. Use -1 to signify that we haven't decided where to put it
243 * yet.
244 */
245 hwc->idx = -1;
246 hwc->config_base = event->attr.config;
247
248 if (hisi_pmu->ops->check_filter && hisi_pmu->ops->check_filter(event))
249 return -EINVAL;
250
251 /* Enforce to use the same CPU for all events in this PMU */
252 event->cpu = hisi_pmu->on_cpu;
253
254 return 0;
255 }
256 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_event_init, "HISI_PMU");
257
258 /*
259 * Set the counter to count the event that we're interested in,
260 * and enable interrupt and counter.
261 */
hisi_uncore_pmu_enable_event(struct perf_event * event)262 static void hisi_uncore_pmu_enable_event(struct perf_event *event)
263 {
264 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
265 struct hw_perf_event *hwc = &event->hw;
266
267 hisi_pmu->ops->write_evtype(hisi_pmu, hwc->idx,
268 HISI_GET_EVENTID(event));
269
270 if (hisi_pmu->ops->enable_filter)
271 hisi_pmu->ops->enable_filter(event);
272
273 hisi_pmu->ops->enable_counter_int(hisi_pmu, hwc);
274 hisi_pmu->ops->enable_counter(hisi_pmu, hwc);
275 }
276
277 /*
278 * Disable counter and interrupt.
279 */
hisi_uncore_pmu_disable_event(struct perf_event * event)280 static void hisi_uncore_pmu_disable_event(struct perf_event *event)
281 {
282 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
283 struct hw_perf_event *hwc = &event->hw;
284
285 hisi_pmu->ops->disable_counter(hisi_pmu, hwc);
286 hisi_pmu->ops->disable_counter_int(hisi_pmu, hwc);
287
288 if (hisi_pmu->ops->disable_filter)
289 hisi_pmu->ops->disable_filter(event);
290 }
291
hisi_uncore_pmu_set_event_period(struct perf_event * event)292 void hisi_uncore_pmu_set_event_period(struct perf_event *event)
293 {
294 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
295 struct hw_perf_event *hwc = &event->hw;
296
297 /*
298 * The HiSilicon PMU counters support 32 bits or 48 bits, depending on
299 * the PMU. We reduce it to 2^(counter_bits - 1) to account for the
300 * extreme interrupt latency. So we could hopefully handle the overflow
301 * interrupt before another 2^(counter_bits - 1) events occur and the
302 * counter overtakes its previous value.
303 */
304 u64 val = BIT_ULL(hisi_pmu->counter_bits - 1);
305
306 local64_set(&hwc->prev_count, val);
307 /* Write start value to the hardware event counter */
308 hisi_pmu->ops->write_counter(hisi_pmu, hwc, val);
309 }
310 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_set_event_period, "HISI_PMU");
311
hisi_uncore_pmu_event_update(struct perf_event * event)312 void hisi_uncore_pmu_event_update(struct perf_event *event)
313 {
314 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
315 struct hw_perf_event *hwc = &event->hw;
316 u64 delta, prev_raw_count, new_raw_count;
317
318 do {
319 /* Read the count from the counter register */
320 new_raw_count = hisi_pmu->ops->read_counter(hisi_pmu, hwc);
321 prev_raw_count = local64_read(&hwc->prev_count);
322 } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
323 new_raw_count) != prev_raw_count);
324 /*
325 * compute the delta
326 */
327 delta = (new_raw_count - prev_raw_count) &
328 HISI_MAX_PERIOD(hisi_pmu->counter_bits);
329 local64_add(delta, &event->count);
330 }
331 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_event_update, "HISI_PMU");
332
hisi_uncore_pmu_start(struct perf_event * event,int flags)333 void hisi_uncore_pmu_start(struct perf_event *event, int flags)
334 {
335 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
336 struct hw_perf_event *hwc = &event->hw;
337
338 if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
339 return;
340
341 WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
342 hwc->state = 0;
343 hisi_uncore_pmu_set_event_period(event);
344
345 if (flags & PERF_EF_RELOAD) {
346 u64 prev_raw_count = local64_read(&hwc->prev_count);
347
348 hisi_pmu->ops->write_counter(hisi_pmu, hwc, prev_raw_count);
349 }
350
351 hisi_uncore_pmu_enable_event(event);
352 perf_event_update_userpage(event);
353 }
354 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_start, "HISI_PMU");
355
hisi_uncore_pmu_stop(struct perf_event * event,int flags)356 void hisi_uncore_pmu_stop(struct perf_event *event, int flags)
357 {
358 struct hw_perf_event *hwc = &event->hw;
359
360 hisi_uncore_pmu_disable_event(event);
361 WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
362 hwc->state |= PERF_HES_STOPPED;
363
364 if (hwc->state & PERF_HES_UPTODATE)
365 return;
366
367 /* Read hardware counter and update the perf counter statistics */
368 hisi_uncore_pmu_event_update(event);
369 hwc->state |= PERF_HES_UPTODATE;
370 }
371 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_stop, "HISI_PMU");
372
hisi_uncore_pmu_add(struct perf_event * event,int flags)373 int hisi_uncore_pmu_add(struct perf_event *event, int flags)
374 {
375 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
376 struct hw_perf_event *hwc = &event->hw;
377 int idx;
378
379 hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
380
381 /* Get an available counter index for counting */
382 idx = hisi_pmu->ops->get_event_idx(event);
383 if (idx < 0)
384 return idx;
385
386 event->hw.idx = idx;
387 hisi_pmu->pmu_events.hw_events[idx] = event;
388
389 if (flags & PERF_EF_START)
390 hisi_uncore_pmu_start(event, PERF_EF_RELOAD);
391
392 return 0;
393 }
394 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_add, "HISI_PMU");
395
hisi_uncore_pmu_del(struct perf_event * event,int flags)396 void hisi_uncore_pmu_del(struct perf_event *event, int flags)
397 {
398 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
399 struct hw_perf_event *hwc = &event->hw;
400
401 hisi_uncore_pmu_stop(event, PERF_EF_UPDATE);
402 hisi_uncore_pmu_clear_event_idx(hisi_pmu, hwc->idx);
403 perf_event_update_userpage(event);
404 hisi_pmu->pmu_events.hw_events[hwc->idx] = NULL;
405 }
406 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_del, "HISI_PMU");
407
hisi_uncore_pmu_read(struct perf_event * event)408 void hisi_uncore_pmu_read(struct perf_event *event)
409 {
410 /* Read hardware counter and update the perf counter statistics */
411 hisi_uncore_pmu_event_update(event);
412 }
413 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_read, "HISI_PMU");
414
hisi_uncore_pmu_enable(struct pmu * pmu)415 void hisi_uncore_pmu_enable(struct pmu *pmu)
416 {
417 struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
418 bool enabled = !bitmap_empty(hisi_pmu->pmu_events.used_mask,
419 hisi_pmu->num_counters);
420
421 if (!enabled)
422 return;
423
424 hisi_pmu->ops->start_counters(hisi_pmu);
425 }
426 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_enable, "HISI_PMU");
427
hisi_uncore_pmu_disable(struct pmu * pmu)428 void hisi_uncore_pmu_disable(struct pmu *pmu)
429 {
430 struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
431
432 hisi_pmu->ops->stop_counters(hisi_pmu);
433 }
434 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_disable, "HISI_PMU");
435
436
437 /*
438 * The Super CPU Cluster (SCCL) and CPU Cluster (CCL) IDs can be
439 * determined from the MPIDR_EL1, but the encoding varies by CPU:
440 *
441 * - For MT variants of TSV110:
442 * SCCL is Aff2[7:3], CCL is Aff2[2:0]
443 *
444 * - For other MT parts:
445 * SCCL is Aff3[7:0], CCL is Aff2[7:0]
446 *
447 * - For non-MT parts:
448 * SCCL is Aff2[7:0], CCL is Aff1[7:0]
449 */
hisi_read_sccl_and_ccl_id(int * scclp,int * cclp)450 static void hisi_read_sccl_and_ccl_id(int *scclp, int *cclp)
451 {
452 u64 mpidr = read_cpuid_mpidr();
453 int aff3 = MPIDR_AFFINITY_LEVEL(mpidr, 3);
454 int aff2 = MPIDR_AFFINITY_LEVEL(mpidr, 2);
455 int aff1 = MPIDR_AFFINITY_LEVEL(mpidr, 1);
456 bool mt = mpidr & MPIDR_MT_BITMASK;
457 int sccl, ccl;
458
459 if (mt && read_cpuid_part_number() == HISI_CPU_PART_TSV110) {
460 sccl = aff2 >> 3;
461 ccl = aff2 & 0x7;
462 } else if (mt) {
463 sccl = aff3;
464 ccl = aff2;
465 } else {
466 sccl = aff2;
467 ccl = aff1;
468 }
469
470 if (scclp)
471 *scclp = sccl;
472 if (cclp)
473 *cclp = ccl;
474 }
475
476 /*
477 * Check whether the CPU is associated with this uncore PMU
478 */
hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu * hisi_pmu)479 static bool hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu *hisi_pmu)
480 {
481 struct hisi_pmu_topology *topo = &hisi_pmu->topo;
482 int sccl_id, ccl_id;
483
484 if (topo->ccl_id == -1) {
485 /* If CCL_ID is -1, the PMU only shares the same SCCL */
486 hisi_read_sccl_and_ccl_id(&sccl_id, NULL);
487
488 return sccl_id == topo->sccl_id;
489 }
490
491 hisi_read_sccl_and_ccl_id(&sccl_id, &ccl_id);
492
493 return sccl_id == topo->sccl_id && ccl_id == topo->ccl_id;
494 }
495
hisi_uncore_pmu_online_cpu(unsigned int cpu,struct hlist_node * node)496 int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
497 {
498 struct hisi_pmu *hisi_pmu = hlist_entry_safe(node, struct hisi_pmu,
499 node);
500
501 /*
502 * If the CPU is not associated to PMU, initialize the hisi_pmu->on_cpu
503 * based on the locality if it hasn't been initialized yet. For PMUs
504 * do have associated CPUs, it'll be updated later.
505 */
506 if (!hisi_pmu_cpu_is_associated_pmu(hisi_pmu)) {
507 if (hisi_pmu->on_cpu != -1)
508 return 0;
509
510 hisi_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(hisi_pmu->dev));
511 if (hisi_pmu->irq > 0)
512 WARN_ON(irq_set_affinity(hisi_pmu->irq,
513 cpumask_of(hisi_pmu->on_cpu)));
514 return 0;
515 }
516
517 cpumask_set_cpu(cpu, &hisi_pmu->associated_cpus);
518
519 /* If another associated CPU is already managing this PMU, simply return. */
520 if (hisi_pmu->on_cpu != -1 &&
521 cpumask_test_cpu(hisi_pmu->on_cpu, &hisi_pmu->associated_cpus))
522 return 0;
523
524 /* Use this CPU in cpumask for event counting */
525 hisi_pmu->on_cpu = cpu;
526
527 /* Overflow interrupt also should use the same CPU */
528 if (hisi_pmu->irq > 0)
529 WARN_ON(irq_set_affinity(hisi_pmu->irq, cpumask_of(cpu)));
530
531 return 0;
532 }
533 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_online_cpu, "HISI_PMU");
534
hisi_uncore_pmu_offline_cpu(unsigned int cpu,struct hlist_node * node)535 int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
536 {
537 struct hisi_pmu *hisi_pmu = hlist_entry_safe(node, struct hisi_pmu,
538 node);
539 unsigned int target;
540
541 /* Nothing to do if this CPU doesn't own the PMU */
542 if (hisi_pmu->on_cpu != cpu)
543 return 0;
544
545 /* Give up ownership of the PMU */
546 hisi_pmu->on_cpu = -1;
547
548 /*
549 * Migrate ownership of the PMU to a new CPU chosen from PMU's online
550 * associated CPUs if possible, if no associated CPU online then
551 * migrate to one online CPU.
552 */
553 target = cpumask_any_and_but(&hisi_pmu->associated_cpus,
554 cpu_online_mask, cpu);
555 if (target >= nr_cpu_ids)
556 target = cpumask_any_but(cpu_online_mask, cpu);
557
558 if (target >= nr_cpu_ids)
559 return 0;
560
561 perf_pmu_migrate_context(&hisi_pmu->pmu, cpu, target);
562 /* Use this CPU for event counting */
563 hisi_pmu->on_cpu = target;
564
565 if (hisi_pmu->irq > 0)
566 WARN_ON(irq_set_affinity(hisi_pmu->irq, cpumask_of(target)));
567
568 return 0;
569 }
570 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_offline_cpu, "HISI_PMU");
571
572 /*
573 * Retrieve the topology information from the firmware for the hisi_pmu device.
574 * The topology ID will be -1 if we cannot initialize it, it may either due to
575 * the PMU doesn't locate on this certain topology or the firmware needs to be
576 * fixed.
577 */
hisi_uncore_pmu_init_topology(struct hisi_pmu * hisi_pmu,struct device * dev)578 void hisi_uncore_pmu_init_topology(struct hisi_pmu *hisi_pmu, struct device *dev)
579 {
580 struct hisi_pmu_topology *topo = &hisi_pmu->topo;
581
582 topo->sccl_id = -1;
583 topo->ccl_id = -1;
584 topo->index_id = -1;
585 topo->sub_id = -1;
586
587 if (device_property_read_u32(dev, "hisilicon,scl-id", &topo->sccl_id))
588 dev_dbg(dev, "no scl-id present\n");
589
590 if (device_property_read_u32(dev, "hisilicon,ccl-id", &topo->ccl_id))
591 dev_dbg(dev, "no ccl-id present\n");
592
593 if (device_property_read_u32(dev, "hisilicon,idx-id", &topo->index_id))
594 dev_dbg(dev, "no idx-id present\n");
595
596 if (device_property_read_u32(dev, "hisilicon,sub-id", &topo->sub_id))
597 dev_dbg(dev, "no sub-id present\n");
598 }
599 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_init_topology, "HISI_PMU");
600
hisi_pmu_init(struct hisi_pmu * hisi_pmu,struct module * module)601 void hisi_pmu_init(struct hisi_pmu *hisi_pmu, struct module *module)
602 {
603 struct pmu *pmu = &hisi_pmu->pmu;
604
605 pmu->module = module;
606 pmu->parent = hisi_pmu->dev;
607 pmu->task_ctx_nr = perf_invalid_context;
608 pmu->event_init = hisi_uncore_pmu_event_init;
609 pmu->pmu_enable = hisi_uncore_pmu_enable;
610 pmu->pmu_disable = hisi_uncore_pmu_disable;
611 pmu->add = hisi_uncore_pmu_add;
612 pmu->del = hisi_uncore_pmu_del;
613 pmu->start = hisi_uncore_pmu_start;
614 pmu->stop = hisi_uncore_pmu_stop;
615 pmu->read = hisi_uncore_pmu_read;
616 pmu->attr_groups = hisi_pmu->pmu_events.attr_groups;
617 pmu->capabilities = PERF_PMU_CAP_NO_EXCLUDE;
618 }
619 EXPORT_SYMBOL_NS_GPL(hisi_pmu_init, "HISI_PMU");
620
621 MODULE_DESCRIPTION("HiSilicon SoC uncore Performance Monitor driver framework");
622 MODULE_LICENSE("GPL v2");
623