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 <[email protected]>
7 * Shaokun Zhang <[email protected]>
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 cpumap_print_to_pagebuf(true, buf, &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 static 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
hisi_uncore_pmu_init_irq(struct hisi_pmu * hisi_pmu,struct platform_device * pdev)182 int hisi_uncore_pmu_init_irq(struct hisi_pmu *hisi_pmu,
183 struct platform_device *pdev)
184 {
185 int irq, ret;
186
187 irq = platform_get_irq(pdev, 0);
188 if (irq < 0)
189 return irq;
190
191 ret = devm_request_irq(&pdev->dev, irq, hisi_uncore_pmu_isr,
192 IRQF_NOBALANCING | IRQF_NO_THREAD,
193 dev_name(&pdev->dev), hisi_pmu);
194 if (ret < 0) {
195 dev_err(&pdev->dev,
196 "Fail to request IRQ: %d ret: %d.\n", irq, ret);
197 return ret;
198 }
199
200 hisi_pmu->irq = irq;
201
202 return 0;
203 }
204 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_init_irq, "HISI_PMU");
205
hisi_uncore_pmu_event_init(struct perf_event * event)206 int hisi_uncore_pmu_event_init(struct perf_event *event)
207 {
208 struct hw_perf_event *hwc = &event->hw;
209 struct hisi_pmu *hisi_pmu;
210
211 if (event->attr.type != event->pmu->type)
212 return -ENOENT;
213
214 /*
215 * We do not support sampling as the counters are all
216 * shared by all CPU cores in a CPU die(SCCL). Also we
217 * do not support attach to a task(per-process mode)
218 */
219 if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
220 return -EOPNOTSUPP;
221
222 /*
223 * The uncore counters not specific to any CPU, so cannot
224 * support per-task
225 */
226 if (event->cpu < 0)
227 return -EINVAL;
228
229 /*
230 * Validate if the events in group does not exceed the
231 * available counters in hardware.
232 */
233 if (!hisi_validate_event_group(event))
234 return -EINVAL;
235
236 hisi_pmu = to_hisi_pmu(event->pmu);
237 if (event->attr.config > hisi_pmu->check_event)
238 return -EINVAL;
239
240 if (hisi_pmu->on_cpu == -1)
241 return -EINVAL;
242 /*
243 * We don't assign an index until we actually place the event onto
244 * hardware. Use -1 to signify that we haven't decided where to put it
245 * yet.
246 */
247 hwc->idx = -1;
248 hwc->config_base = event->attr.config;
249
250 if (hisi_pmu->ops->check_filter && hisi_pmu->ops->check_filter(event))
251 return -EINVAL;
252
253 /* Enforce to use the same CPU for all events in this PMU */
254 event->cpu = hisi_pmu->on_cpu;
255
256 return 0;
257 }
258 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_event_init, "HISI_PMU");
259
260 /*
261 * Set the counter to count the event that we're interested in,
262 * and enable interrupt and counter.
263 */
hisi_uncore_pmu_enable_event(struct perf_event * event)264 static void hisi_uncore_pmu_enable_event(struct perf_event *event)
265 {
266 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
267 struct hw_perf_event *hwc = &event->hw;
268
269 hisi_pmu->ops->write_evtype(hisi_pmu, hwc->idx,
270 HISI_GET_EVENTID(event));
271
272 if (hisi_pmu->ops->enable_filter)
273 hisi_pmu->ops->enable_filter(event);
274
275 hisi_pmu->ops->enable_counter_int(hisi_pmu, hwc);
276 hisi_pmu->ops->enable_counter(hisi_pmu, hwc);
277 }
278
279 /*
280 * Disable counter and interrupt.
281 */
hisi_uncore_pmu_disable_event(struct perf_event * event)282 static void hisi_uncore_pmu_disable_event(struct perf_event *event)
283 {
284 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
285 struct hw_perf_event *hwc = &event->hw;
286
287 hisi_pmu->ops->disable_counter(hisi_pmu, hwc);
288 hisi_pmu->ops->disable_counter_int(hisi_pmu, hwc);
289
290 if (hisi_pmu->ops->disable_filter)
291 hisi_pmu->ops->disable_filter(event);
292 }
293
hisi_uncore_pmu_set_event_period(struct perf_event * event)294 void hisi_uncore_pmu_set_event_period(struct perf_event *event)
295 {
296 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
297 struct hw_perf_event *hwc = &event->hw;
298
299 /*
300 * The HiSilicon PMU counters support 32 bits or 48 bits, depending on
301 * the PMU. We reduce it to 2^(counter_bits - 1) to account for the
302 * extreme interrupt latency. So we could hopefully handle the overflow
303 * interrupt before another 2^(counter_bits - 1) events occur and the
304 * counter overtakes its previous value.
305 */
306 u64 val = BIT_ULL(hisi_pmu->counter_bits - 1);
307
308 local64_set(&hwc->prev_count, val);
309 /* Write start value to the hardware event counter */
310 hisi_pmu->ops->write_counter(hisi_pmu, hwc, val);
311 }
312 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_set_event_period, "HISI_PMU");
313
hisi_uncore_pmu_event_update(struct perf_event * event)314 void hisi_uncore_pmu_event_update(struct perf_event *event)
315 {
316 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
317 struct hw_perf_event *hwc = &event->hw;
318 u64 delta, prev_raw_count, new_raw_count;
319
320 do {
321 /* Read the count from the counter register */
322 new_raw_count = hisi_pmu->ops->read_counter(hisi_pmu, hwc);
323 prev_raw_count = local64_read(&hwc->prev_count);
324 } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
325 new_raw_count) != prev_raw_count);
326 /*
327 * compute the delta
328 */
329 delta = (new_raw_count - prev_raw_count) &
330 HISI_MAX_PERIOD(hisi_pmu->counter_bits);
331 local64_add(delta, &event->count);
332 }
333 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_event_update, "HISI_PMU");
334
hisi_uncore_pmu_start(struct perf_event * event,int flags)335 void hisi_uncore_pmu_start(struct perf_event *event, int flags)
336 {
337 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
338 struct hw_perf_event *hwc = &event->hw;
339
340 if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
341 return;
342
343 WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
344 hwc->state = 0;
345 hisi_uncore_pmu_set_event_period(event);
346
347 if (flags & PERF_EF_RELOAD) {
348 u64 prev_raw_count = local64_read(&hwc->prev_count);
349
350 hisi_pmu->ops->write_counter(hisi_pmu, hwc, prev_raw_count);
351 }
352
353 hisi_uncore_pmu_enable_event(event);
354 perf_event_update_userpage(event);
355 }
356 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_start, "HISI_PMU");
357
hisi_uncore_pmu_stop(struct perf_event * event,int flags)358 void hisi_uncore_pmu_stop(struct perf_event *event, int flags)
359 {
360 struct hw_perf_event *hwc = &event->hw;
361
362 hisi_uncore_pmu_disable_event(event);
363 WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
364 hwc->state |= PERF_HES_STOPPED;
365
366 if (hwc->state & PERF_HES_UPTODATE)
367 return;
368
369 /* Read hardware counter and update the perf counter statistics */
370 hisi_uncore_pmu_event_update(event);
371 hwc->state |= PERF_HES_UPTODATE;
372 }
373 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_stop, "HISI_PMU");
374
hisi_uncore_pmu_add(struct perf_event * event,int flags)375 int hisi_uncore_pmu_add(struct perf_event *event, int flags)
376 {
377 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
378 struct hw_perf_event *hwc = &event->hw;
379 int idx;
380
381 hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
382
383 /* Get an available counter index for counting */
384 idx = hisi_pmu->ops->get_event_idx(event);
385 if (idx < 0)
386 return idx;
387
388 event->hw.idx = idx;
389 hisi_pmu->pmu_events.hw_events[idx] = event;
390
391 if (flags & PERF_EF_START)
392 hisi_uncore_pmu_start(event, PERF_EF_RELOAD);
393
394 return 0;
395 }
396 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_add, "HISI_PMU");
397
hisi_uncore_pmu_del(struct perf_event * event,int flags)398 void hisi_uncore_pmu_del(struct perf_event *event, int flags)
399 {
400 struct hisi_pmu *hisi_pmu = to_hisi_pmu(event->pmu);
401 struct hw_perf_event *hwc = &event->hw;
402
403 hisi_uncore_pmu_stop(event, PERF_EF_UPDATE);
404 hisi_uncore_pmu_clear_event_idx(hisi_pmu, hwc->idx);
405 perf_event_update_userpage(event);
406 hisi_pmu->pmu_events.hw_events[hwc->idx] = NULL;
407 }
408 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_del, "HISI_PMU");
409
hisi_uncore_pmu_read(struct perf_event * event)410 void hisi_uncore_pmu_read(struct perf_event *event)
411 {
412 /* Read hardware counter and update the perf counter statistics */
413 hisi_uncore_pmu_event_update(event);
414 }
415 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_read, "HISI_PMU");
416
hisi_uncore_pmu_enable(struct pmu * pmu)417 void hisi_uncore_pmu_enable(struct pmu *pmu)
418 {
419 struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
420 bool enabled = !bitmap_empty(hisi_pmu->pmu_events.used_mask,
421 hisi_pmu->num_counters);
422
423 if (!enabled)
424 return;
425
426 hisi_pmu->ops->start_counters(hisi_pmu);
427 }
428 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_enable, "HISI_PMU");
429
hisi_uncore_pmu_disable(struct pmu * pmu)430 void hisi_uncore_pmu_disable(struct pmu *pmu)
431 {
432 struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
433
434 hisi_pmu->ops->stop_counters(hisi_pmu);
435 }
436 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_disable, "HISI_PMU");
437
438
439 /*
440 * The Super CPU Cluster (SCCL) and CPU Cluster (CCL) IDs can be
441 * determined from the MPIDR_EL1, but the encoding varies by CPU:
442 *
443 * - For MT variants of TSV110:
444 * SCCL is Aff2[7:3], CCL is Aff2[2:0]
445 *
446 * - For other MT parts:
447 * SCCL is Aff3[7:0], CCL is Aff2[7:0]
448 *
449 * - For non-MT parts:
450 * SCCL is Aff2[7:0], CCL is Aff1[7:0]
451 */
hisi_read_sccl_and_ccl_id(int * scclp,int * cclp)452 static void hisi_read_sccl_and_ccl_id(int *scclp, int *cclp)
453 {
454 u64 mpidr = read_cpuid_mpidr();
455 int aff3 = MPIDR_AFFINITY_LEVEL(mpidr, 3);
456 int aff2 = MPIDR_AFFINITY_LEVEL(mpidr, 2);
457 int aff1 = MPIDR_AFFINITY_LEVEL(mpidr, 1);
458 bool mt = mpidr & MPIDR_MT_BITMASK;
459 int sccl, ccl;
460
461 if (mt && read_cpuid_part_number() == HISI_CPU_PART_TSV110) {
462 sccl = aff2 >> 3;
463 ccl = aff2 & 0x7;
464 } else if (mt) {
465 sccl = aff3;
466 ccl = aff2;
467 } else {
468 sccl = aff2;
469 ccl = aff1;
470 }
471
472 if (scclp)
473 *scclp = sccl;
474 if (cclp)
475 *cclp = ccl;
476 }
477
478 /*
479 * Check whether the CPU is associated with this uncore PMU
480 */
hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu * hisi_pmu)481 static bool hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu *hisi_pmu)
482 {
483 struct hisi_pmu_topology *topo = &hisi_pmu->topo;
484 int sccl_id, ccl_id;
485
486 if (topo->ccl_id == -1) {
487 /* If CCL_ID is -1, the PMU only shares the same SCCL */
488 hisi_read_sccl_and_ccl_id(&sccl_id, NULL);
489
490 return sccl_id == topo->sccl_id;
491 }
492
493 hisi_read_sccl_and_ccl_id(&sccl_id, &ccl_id);
494
495 return sccl_id == topo->sccl_id && ccl_id == topo->ccl_id;
496 }
497
hisi_uncore_pmu_online_cpu(unsigned int cpu,struct hlist_node * node)498 int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
499 {
500 struct hisi_pmu *hisi_pmu = hlist_entry_safe(node, struct hisi_pmu,
501 node);
502
503 /*
504 * If the CPU is not associated to PMU, initialize the hisi_pmu->on_cpu
505 * based on the locality if it hasn't been initialized yet. For PMUs
506 * do have associated CPUs, it'll be updated later.
507 */
508 if (!hisi_pmu_cpu_is_associated_pmu(hisi_pmu)) {
509 if (hisi_pmu->on_cpu != -1)
510 return 0;
511
512 hisi_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(hisi_pmu->dev));
513 WARN_ON(irq_set_affinity(hisi_pmu->irq, 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 WARN_ON(irq_set_affinity(hisi_pmu->irq, cpumask_of(cpu)));
529
530 return 0;
531 }
532 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_online_cpu, "HISI_PMU");
533
hisi_uncore_pmu_offline_cpu(unsigned int cpu,struct hlist_node * node)534 int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
535 {
536 struct hisi_pmu *hisi_pmu = hlist_entry_safe(node, struct hisi_pmu,
537 node);
538 unsigned int target;
539
540 /* Nothing to do if this CPU doesn't own the PMU */
541 if (hisi_pmu->on_cpu != cpu)
542 return 0;
543
544 /* Give up ownership of the PMU */
545 hisi_pmu->on_cpu = -1;
546
547 /*
548 * Migrate ownership of the PMU to a new CPU chosen from PMU's online
549 * associated CPUs if possible, if no associated CPU online then
550 * migrate to one online CPU.
551 */
552 target = cpumask_any_and_but(&hisi_pmu->associated_cpus,
553 cpu_online_mask, cpu);
554 if (target >= nr_cpu_ids)
555 target = cpumask_any_but(cpu_online_mask, cpu);
556
557 if (target >= nr_cpu_ids)
558 return 0;
559
560 perf_pmu_migrate_context(&hisi_pmu->pmu, cpu, target);
561 /* Use this CPU for event counting */
562 hisi_pmu->on_cpu = target;
563 WARN_ON(irq_set_affinity(hisi_pmu->irq, cpumask_of(target)));
564
565 return 0;
566 }
567 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_offline_cpu, "HISI_PMU");
568
569 /*
570 * Retrieve the topology information from the firmware for the hisi_pmu device.
571 * The topology ID will be -1 if we cannot initialize it, it may either due to
572 * the PMU doesn't locate on this certain topology or the firmware needs to be
573 * fixed.
574 */
hisi_uncore_pmu_init_topology(struct hisi_pmu * hisi_pmu,struct device * dev)575 void hisi_uncore_pmu_init_topology(struct hisi_pmu *hisi_pmu, struct device *dev)
576 {
577 struct hisi_pmu_topology *topo = &hisi_pmu->topo;
578
579 topo->sccl_id = -1;
580 topo->ccl_id = -1;
581 topo->index_id = -1;
582 topo->sub_id = -1;
583
584 if (device_property_read_u32(dev, "hisilicon,scl-id", &topo->sccl_id))
585 dev_dbg(dev, "no scl-id present\n");
586
587 if (device_property_read_u32(dev, "hisilicon,ccl-id", &topo->ccl_id))
588 dev_dbg(dev, "no ccl-id present\n");
589
590 if (device_property_read_u32(dev, "hisilicon,idx-id", &topo->index_id))
591 dev_dbg(dev, "no idx-id present\n");
592
593 if (device_property_read_u32(dev, "hisilicon,sub-id", &topo->sub_id))
594 dev_dbg(dev, "no sub-id present\n");
595 }
596 EXPORT_SYMBOL_NS_GPL(hisi_uncore_pmu_init_topology, "HISI_PMU");
597
hisi_pmu_init(struct hisi_pmu * hisi_pmu,struct module * module)598 void hisi_pmu_init(struct hisi_pmu *hisi_pmu, struct module *module)
599 {
600 struct pmu *pmu = &hisi_pmu->pmu;
601
602 pmu->module = module;
603 pmu->parent = hisi_pmu->dev;
604 pmu->task_ctx_nr = perf_invalid_context;
605 pmu->event_init = hisi_uncore_pmu_event_init;
606 pmu->pmu_enable = hisi_uncore_pmu_enable;
607 pmu->pmu_disable = hisi_uncore_pmu_disable;
608 pmu->add = hisi_uncore_pmu_add;
609 pmu->del = hisi_uncore_pmu_del;
610 pmu->start = hisi_uncore_pmu_start;
611 pmu->stop = hisi_uncore_pmu_stop;
612 pmu->read = hisi_uncore_pmu_read;
613 pmu->attr_groups = hisi_pmu->pmu_events.attr_groups;
614 pmu->capabilities = PERF_PMU_CAP_NO_EXCLUDE;
615 }
616 EXPORT_SYMBOL_NS_GPL(hisi_pmu_init, "HISI_PMU");
617
618 MODULE_DESCRIPTION("HiSilicon SoC uncore Performance Monitor driver framework");
619 MODULE_LICENSE("GPL v2");
620