1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(C) 2015 Linaro Limited. All rights reserved.
4 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
7 #include <linux/pm_runtime.h>
8 #include <linux/sysfs.h>
9 #include "coresight-etm.h"
10 #include "coresight-priv.h"
12 static ssize_t
nr_addr_cmp_show(struct device
*dev
,
13 struct device_attribute
*attr
, char *buf
)
16 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
18 val
= drvdata
->nr_addr_cmp
;
19 return sprintf(buf
, "%#lx\n", val
);
21 static DEVICE_ATTR_RO(nr_addr_cmp
);
23 static ssize_t
nr_cntr_show(struct device
*dev
,
24 struct device_attribute
*attr
, char *buf
)
26 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
28 val
= drvdata
->nr_cntr
;
29 return sprintf(buf
, "%#lx\n", val
);
31 static DEVICE_ATTR_RO(nr_cntr
);
33 static ssize_t
nr_ctxid_cmp_show(struct device
*dev
,
34 struct device_attribute
*attr
, char *buf
)
37 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
39 val
= drvdata
->nr_ctxid_cmp
;
40 return sprintf(buf
, "%#lx\n", val
);
42 static DEVICE_ATTR_RO(nr_ctxid_cmp
);
44 static ssize_t
etmsr_show(struct device
*dev
,
45 struct device_attribute
*attr
, char *buf
)
47 unsigned long flags
, val
;
48 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
50 pm_runtime_get_sync(drvdata
->dev
);
51 spin_lock_irqsave(&drvdata
->spinlock
, flags
);
52 CS_UNLOCK(drvdata
->base
);
54 val
= etm_readl(drvdata
, ETMSR
);
56 CS_LOCK(drvdata
->base
);
57 spin_unlock_irqrestore(&drvdata
->spinlock
, flags
);
58 pm_runtime_put(drvdata
->dev
);
60 return sprintf(buf
, "%#lx\n", val
);
62 static DEVICE_ATTR_RO(etmsr
);
64 static ssize_t
reset_store(struct device
*dev
,
65 struct device_attribute
*attr
,
66 const char *buf
, size_t size
)
70 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
71 struct etm_config
*config
= &drvdata
->config
;
73 ret
= kstrtoul(buf
, 16, &val
);
78 spin_lock(&drvdata
->spinlock
);
79 memset(config
, 0, sizeof(struct etm_config
));
80 config
->mode
= ETM_MODE_EXCLUDE
;
81 config
->trigger_event
= ETM_DEFAULT_EVENT_VAL
;
82 for (i
= 0; i
< drvdata
->nr_addr_cmp
; i
++) {
83 config
->addr_type
[i
] = ETM_ADDR_TYPE_NONE
;
86 etm_set_default(config
);
87 spin_unlock(&drvdata
->spinlock
);
92 static DEVICE_ATTR_WO(reset
);
94 static ssize_t
mode_show(struct device
*dev
,
95 struct device_attribute
*attr
, char *buf
)
98 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
99 struct etm_config
*config
= &drvdata
->config
;
102 return sprintf(buf
, "%#lx\n", val
);
105 static ssize_t
mode_store(struct device
*dev
,
106 struct device_attribute
*attr
,
107 const char *buf
, size_t size
)
111 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
112 struct etm_config
*config
= &drvdata
->config
;
114 ret
= kstrtoul(buf
, 16, &val
);
118 spin_lock(&drvdata
->spinlock
);
119 config
->mode
= val
& ETM_MODE_ALL
;
121 if (config
->mode
& ETM_MODE_EXCLUDE
)
122 config
->enable_ctrl1
|= ETMTECR1_INC_EXC
;
124 config
->enable_ctrl1
&= ~ETMTECR1_INC_EXC
;
126 if (config
->mode
& ETM_MODE_CYCACC
)
127 config
->ctrl
|= ETMCR_CYC_ACC
;
129 config
->ctrl
&= ~ETMCR_CYC_ACC
;
131 if (config
->mode
& ETM_MODE_STALL
) {
132 if (!(drvdata
->etmccr
& ETMCCR_FIFOFULL
)) {
133 dev_warn(drvdata
->dev
, "stall mode not supported\n");
137 config
->ctrl
|= ETMCR_STALL_MODE
;
139 config
->ctrl
&= ~ETMCR_STALL_MODE
;
141 if (config
->mode
& ETM_MODE_TIMESTAMP
) {
142 if (!(drvdata
->etmccer
& ETMCCER_TIMESTAMP
)) {
143 dev_warn(drvdata
->dev
, "timestamp not supported\n");
147 config
->ctrl
|= ETMCR_TIMESTAMP_EN
;
149 config
->ctrl
&= ~ETMCR_TIMESTAMP_EN
;
151 if (config
->mode
& ETM_MODE_CTXID
)
152 config
->ctrl
|= ETMCR_CTXID_SIZE
;
154 config
->ctrl
&= ~ETMCR_CTXID_SIZE
;
156 if (config
->mode
& ETM_MODE_BBROAD
)
157 config
->ctrl
|= ETMCR_BRANCH_BROADCAST
;
159 config
->ctrl
&= ~ETMCR_BRANCH_BROADCAST
;
161 if (config
->mode
& ETM_MODE_RET_STACK
)
162 config
->ctrl
|= ETMCR_RETURN_STACK
;
164 config
->ctrl
&= ~ETMCR_RETURN_STACK
;
166 if (config
->mode
& (ETM_MODE_EXCL_KERN
| ETM_MODE_EXCL_USER
))
167 etm_config_trace_mode(config
);
169 spin_unlock(&drvdata
->spinlock
);
174 spin_unlock(&drvdata
->spinlock
);
177 static DEVICE_ATTR_RW(mode
);
179 static ssize_t
trigger_event_show(struct device
*dev
,
180 struct device_attribute
*attr
, char *buf
)
183 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
184 struct etm_config
*config
= &drvdata
->config
;
186 val
= config
->trigger_event
;
187 return sprintf(buf
, "%#lx\n", val
);
190 static ssize_t
trigger_event_store(struct device
*dev
,
191 struct device_attribute
*attr
,
192 const char *buf
, size_t size
)
196 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
197 struct etm_config
*config
= &drvdata
->config
;
199 ret
= kstrtoul(buf
, 16, &val
);
203 config
->trigger_event
= val
& ETM_EVENT_MASK
;
207 static DEVICE_ATTR_RW(trigger_event
);
209 static ssize_t
enable_event_show(struct device
*dev
,
210 struct device_attribute
*attr
, char *buf
)
213 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
214 struct etm_config
*config
= &drvdata
->config
;
216 val
= config
->enable_event
;
217 return sprintf(buf
, "%#lx\n", val
);
220 static ssize_t
enable_event_store(struct device
*dev
,
221 struct device_attribute
*attr
,
222 const char *buf
, size_t size
)
226 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
227 struct etm_config
*config
= &drvdata
->config
;
229 ret
= kstrtoul(buf
, 16, &val
);
233 config
->enable_event
= val
& ETM_EVENT_MASK
;
237 static DEVICE_ATTR_RW(enable_event
);
239 static ssize_t
fifofull_level_show(struct device
*dev
,
240 struct device_attribute
*attr
, char *buf
)
243 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
244 struct etm_config
*config
= &drvdata
->config
;
246 val
= config
->fifofull_level
;
247 return sprintf(buf
, "%#lx\n", val
);
250 static ssize_t
fifofull_level_store(struct device
*dev
,
251 struct device_attribute
*attr
,
252 const char *buf
, size_t size
)
256 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
257 struct etm_config
*config
= &drvdata
->config
;
259 ret
= kstrtoul(buf
, 16, &val
);
263 config
->fifofull_level
= val
;
267 static DEVICE_ATTR_RW(fifofull_level
);
269 static ssize_t
addr_idx_show(struct device
*dev
,
270 struct device_attribute
*attr
, char *buf
)
273 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
274 struct etm_config
*config
= &drvdata
->config
;
276 val
= config
->addr_idx
;
277 return sprintf(buf
, "%#lx\n", val
);
280 static ssize_t
addr_idx_store(struct device
*dev
,
281 struct device_attribute
*attr
,
282 const char *buf
, size_t size
)
286 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
287 struct etm_config
*config
= &drvdata
->config
;
289 ret
= kstrtoul(buf
, 16, &val
);
293 if (val
>= drvdata
->nr_addr_cmp
)
297 * Use spinlock to ensure index doesn't change while it gets
298 * dereferenced multiple times within a spinlock block elsewhere.
300 spin_lock(&drvdata
->spinlock
);
301 config
->addr_idx
= val
;
302 spin_unlock(&drvdata
->spinlock
);
306 static DEVICE_ATTR_RW(addr_idx
);
308 static ssize_t
addr_single_show(struct device
*dev
,
309 struct device_attribute
*attr
, char *buf
)
313 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
314 struct etm_config
*config
= &drvdata
->config
;
316 spin_lock(&drvdata
->spinlock
);
317 idx
= config
->addr_idx
;
318 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
319 config
->addr_type
[idx
] == ETM_ADDR_TYPE_SINGLE
)) {
320 spin_unlock(&drvdata
->spinlock
);
324 val
= config
->addr_val
[idx
];
325 spin_unlock(&drvdata
->spinlock
);
327 return sprintf(buf
, "%#lx\n", val
);
330 static ssize_t
addr_single_store(struct device
*dev
,
331 struct device_attribute
*attr
,
332 const char *buf
, size_t size
)
337 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
338 struct etm_config
*config
= &drvdata
->config
;
340 ret
= kstrtoul(buf
, 16, &val
);
344 spin_lock(&drvdata
->spinlock
);
345 idx
= config
->addr_idx
;
346 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
347 config
->addr_type
[idx
] == ETM_ADDR_TYPE_SINGLE
)) {
348 spin_unlock(&drvdata
->spinlock
);
352 config
->addr_val
[idx
] = val
;
353 config
->addr_type
[idx
] = ETM_ADDR_TYPE_SINGLE
;
354 spin_unlock(&drvdata
->spinlock
);
358 static DEVICE_ATTR_RW(addr_single
);
360 static ssize_t
addr_range_show(struct device
*dev
,
361 struct device_attribute
*attr
, char *buf
)
364 unsigned long val1
, val2
;
365 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
366 struct etm_config
*config
= &drvdata
->config
;
368 spin_lock(&drvdata
->spinlock
);
369 idx
= config
->addr_idx
;
371 spin_unlock(&drvdata
->spinlock
);
374 if (!((config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
&&
375 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_NONE
) ||
376 (config
->addr_type
[idx
] == ETM_ADDR_TYPE_RANGE
&&
377 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_RANGE
))) {
378 spin_unlock(&drvdata
->spinlock
);
382 val1
= config
->addr_val
[idx
];
383 val2
= config
->addr_val
[idx
+ 1];
384 spin_unlock(&drvdata
->spinlock
);
386 return sprintf(buf
, "%#lx %#lx\n", val1
, val2
);
389 static ssize_t
addr_range_store(struct device
*dev
,
390 struct device_attribute
*attr
,
391 const char *buf
, size_t size
)
394 unsigned long val1
, val2
;
395 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
396 struct etm_config
*config
= &drvdata
->config
;
398 if (sscanf(buf
, "%lx %lx", &val1
, &val2
) != 2)
400 /* Lower address comparator cannot have a higher address value */
404 spin_lock(&drvdata
->spinlock
);
405 idx
= config
->addr_idx
;
407 spin_unlock(&drvdata
->spinlock
);
410 if (!((config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
&&
411 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_NONE
) ||
412 (config
->addr_type
[idx
] == ETM_ADDR_TYPE_RANGE
&&
413 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_RANGE
))) {
414 spin_unlock(&drvdata
->spinlock
);
418 config
->addr_val
[idx
] = val1
;
419 config
->addr_type
[idx
] = ETM_ADDR_TYPE_RANGE
;
420 config
->addr_val
[idx
+ 1] = val2
;
421 config
->addr_type
[idx
+ 1] = ETM_ADDR_TYPE_RANGE
;
422 config
->enable_ctrl1
|= (1 << (idx
/2));
423 spin_unlock(&drvdata
->spinlock
);
427 static DEVICE_ATTR_RW(addr_range
);
429 static ssize_t
addr_start_show(struct device
*dev
,
430 struct device_attribute
*attr
, char *buf
)
434 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
435 struct etm_config
*config
= &drvdata
->config
;
437 spin_lock(&drvdata
->spinlock
);
438 idx
= config
->addr_idx
;
439 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
440 config
->addr_type
[idx
] == ETM_ADDR_TYPE_START
)) {
441 spin_unlock(&drvdata
->spinlock
);
445 val
= config
->addr_val
[idx
];
446 spin_unlock(&drvdata
->spinlock
);
448 return sprintf(buf
, "%#lx\n", val
);
451 static ssize_t
addr_start_store(struct device
*dev
,
452 struct device_attribute
*attr
,
453 const char *buf
, size_t size
)
458 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
459 struct etm_config
*config
= &drvdata
->config
;
461 ret
= kstrtoul(buf
, 16, &val
);
465 spin_lock(&drvdata
->spinlock
);
466 idx
= config
->addr_idx
;
467 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
468 config
->addr_type
[idx
] == ETM_ADDR_TYPE_START
)) {
469 spin_unlock(&drvdata
->spinlock
);
473 config
->addr_val
[idx
] = val
;
474 config
->addr_type
[idx
] = ETM_ADDR_TYPE_START
;
475 config
->startstop_ctrl
|= (1 << idx
);
476 config
->enable_ctrl1
|= BIT(25);
477 spin_unlock(&drvdata
->spinlock
);
481 static DEVICE_ATTR_RW(addr_start
);
483 static ssize_t
addr_stop_show(struct device
*dev
,
484 struct device_attribute
*attr
, char *buf
)
488 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
489 struct etm_config
*config
= &drvdata
->config
;
491 spin_lock(&drvdata
->spinlock
);
492 idx
= config
->addr_idx
;
493 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
494 config
->addr_type
[idx
] == ETM_ADDR_TYPE_STOP
)) {
495 spin_unlock(&drvdata
->spinlock
);
499 val
= config
->addr_val
[idx
];
500 spin_unlock(&drvdata
->spinlock
);
502 return sprintf(buf
, "%#lx\n", val
);
505 static ssize_t
addr_stop_store(struct device
*dev
,
506 struct device_attribute
*attr
,
507 const char *buf
, size_t size
)
512 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
513 struct etm_config
*config
= &drvdata
->config
;
515 ret
= kstrtoul(buf
, 16, &val
);
519 spin_lock(&drvdata
->spinlock
);
520 idx
= config
->addr_idx
;
521 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
522 config
->addr_type
[idx
] == ETM_ADDR_TYPE_STOP
)) {
523 spin_unlock(&drvdata
->spinlock
);
527 config
->addr_val
[idx
] = val
;
528 config
->addr_type
[idx
] = ETM_ADDR_TYPE_STOP
;
529 config
->startstop_ctrl
|= (1 << (idx
+ 16));
530 config
->enable_ctrl1
|= ETMTECR1_START_STOP
;
531 spin_unlock(&drvdata
->spinlock
);
535 static DEVICE_ATTR_RW(addr_stop
);
537 static ssize_t
addr_acctype_show(struct device
*dev
,
538 struct device_attribute
*attr
, char *buf
)
541 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
542 struct etm_config
*config
= &drvdata
->config
;
544 spin_lock(&drvdata
->spinlock
);
545 val
= config
->addr_acctype
[config
->addr_idx
];
546 spin_unlock(&drvdata
->spinlock
);
548 return sprintf(buf
, "%#lx\n", val
);
551 static ssize_t
addr_acctype_store(struct device
*dev
,
552 struct device_attribute
*attr
,
553 const char *buf
, size_t size
)
557 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
558 struct etm_config
*config
= &drvdata
->config
;
560 ret
= kstrtoul(buf
, 16, &val
);
564 spin_lock(&drvdata
->spinlock
);
565 config
->addr_acctype
[config
->addr_idx
] = val
;
566 spin_unlock(&drvdata
->spinlock
);
570 static DEVICE_ATTR_RW(addr_acctype
);
572 static ssize_t
cntr_idx_show(struct device
*dev
,
573 struct device_attribute
*attr
, char *buf
)
576 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
577 struct etm_config
*config
= &drvdata
->config
;
579 val
= config
->cntr_idx
;
580 return sprintf(buf
, "%#lx\n", val
);
583 static ssize_t
cntr_idx_store(struct device
*dev
,
584 struct device_attribute
*attr
,
585 const char *buf
, size_t size
)
589 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
590 struct etm_config
*config
= &drvdata
->config
;
592 ret
= kstrtoul(buf
, 16, &val
);
596 if (val
>= drvdata
->nr_cntr
)
599 * Use spinlock to ensure index doesn't change while it gets
600 * dereferenced multiple times within a spinlock block elsewhere.
602 spin_lock(&drvdata
->spinlock
);
603 config
->cntr_idx
= val
;
604 spin_unlock(&drvdata
->spinlock
);
608 static DEVICE_ATTR_RW(cntr_idx
);
610 static ssize_t
cntr_rld_val_show(struct device
*dev
,
611 struct device_attribute
*attr
, char *buf
)
614 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
615 struct etm_config
*config
= &drvdata
->config
;
617 spin_lock(&drvdata
->spinlock
);
618 val
= config
->cntr_rld_val
[config
->cntr_idx
];
619 spin_unlock(&drvdata
->spinlock
);
621 return sprintf(buf
, "%#lx\n", val
);
624 static ssize_t
cntr_rld_val_store(struct device
*dev
,
625 struct device_attribute
*attr
,
626 const char *buf
, size_t size
)
630 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
631 struct etm_config
*config
= &drvdata
->config
;
633 ret
= kstrtoul(buf
, 16, &val
);
637 spin_lock(&drvdata
->spinlock
);
638 config
->cntr_rld_val
[config
->cntr_idx
] = val
;
639 spin_unlock(&drvdata
->spinlock
);
643 static DEVICE_ATTR_RW(cntr_rld_val
);
645 static ssize_t
cntr_event_show(struct device
*dev
,
646 struct device_attribute
*attr
, char *buf
)
649 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
650 struct etm_config
*config
= &drvdata
->config
;
652 spin_lock(&drvdata
->spinlock
);
653 val
= config
->cntr_event
[config
->cntr_idx
];
654 spin_unlock(&drvdata
->spinlock
);
656 return sprintf(buf
, "%#lx\n", val
);
659 static ssize_t
cntr_event_store(struct device
*dev
,
660 struct device_attribute
*attr
,
661 const char *buf
, size_t size
)
665 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
666 struct etm_config
*config
= &drvdata
->config
;
668 ret
= kstrtoul(buf
, 16, &val
);
672 spin_lock(&drvdata
->spinlock
);
673 config
->cntr_event
[config
->cntr_idx
] = val
& ETM_EVENT_MASK
;
674 spin_unlock(&drvdata
->spinlock
);
678 static DEVICE_ATTR_RW(cntr_event
);
680 static ssize_t
cntr_rld_event_show(struct device
*dev
,
681 struct device_attribute
*attr
, char *buf
)
684 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
685 struct etm_config
*config
= &drvdata
->config
;
687 spin_lock(&drvdata
->spinlock
);
688 val
= config
->cntr_rld_event
[config
->cntr_idx
];
689 spin_unlock(&drvdata
->spinlock
);
691 return sprintf(buf
, "%#lx\n", val
);
694 static ssize_t
cntr_rld_event_store(struct device
*dev
,
695 struct device_attribute
*attr
,
696 const char *buf
, size_t size
)
700 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
701 struct etm_config
*config
= &drvdata
->config
;
703 ret
= kstrtoul(buf
, 16, &val
);
707 spin_lock(&drvdata
->spinlock
);
708 config
->cntr_rld_event
[config
->cntr_idx
] = val
& ETM_EVENT_MASK
;
709 spin_unlock(&drvdata
->spinlock
);
713 static DEVICE_ATTR_RW(cntr_rld_event
);
715 static ssize_t
cntr_val_show(struct device
*dev
,
716 struct device_attribute
*attr
, char *buf
)
720 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
721 struct etm_config
*config
= &drvdata
->config
;
723 if (!local_read(&drvdata
->mode
)) {
724 spin_lock(&drvdata
->spinlock
);
725 for (i
= 0; i
< drvdata
->nr_cntr
; i
++)
726 ret
+= sprintf(buf
, "counter %d: %x\n",
727 i
, config
->cntr_val
[i
]);
728 spin_unlock(&drvdata
->spinlock
);
732 for (i
= 0; i
< drvdata
->nr_cntr
; i
++) {
733 val
= etm_readl(drvdata
, ETMCNTVRn(i
));
734 ret
+= sprintf(buf
, "counter %d: %x\n", i
, val
);
740 static ssize_t
cntr_val_store(struct device
*dev
,
741 struct device_attribute
*attr
,
742 const char *buf
, size_t size
)
746 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
747 struct etm_config
*config
= &drvdata
->config
;
749 ret
= kstrtoul(buf
, 16, &val
);
753 spin_lock(&drvdata
->spinlock
);
754 config
->cntr_val
[config
->cntr_idx
] = val
;
755 spin_unlock(&drvdata
->spinlock
);
759 static DEVICE_ATTR_RW(cntr_val
);
761 static ssize_t
seq_12_event_show(struct device
*dev
,
762 struct device_attribute
*attr
, char *buf
)
765 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
766 struct etm_config
*config
= &drvdata
->config
;
768 val
= config
->seq_12_event
;
769 return sprintf(buf
, "%#lx\n", val
);
772 static ssize_t
seq_12_event_store(struct device
*dev
,
773 struct device_attribute
*attr
,
774 const char *buf
, size_t size
)
778 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
779 struct etm_config
*config
= &drvdata
->config
;
781 ret
= kstrtoul(buf
, 16, &val
);
785 config
->seq_12_event
= val
& ETM_EVENT_MASK
;
788 static DEVICE_ATTR_RW(seq_12_event
);
790 static ssize_t
seq_21_event_show(struct device
*dev
,
791 struct device_attribute
*attr
, char *buf
)
794 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
795 struct etm_config
*config
= &drvdata
->config
;
797 val
= config
->seq_21_event
;
798 return sprintf(buf
, "%#lx\n", val
);
801 static ssize_t
seq_21_event_store(struct device
*dev
,
802 struct device_attribute
*attr
,
803 const char *buf
, size_t size
)
807 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
808 struct etm_config
*config
= &drvdata
->config
;
810 ret
= kstrtoul(buf
, 16, &val
);
814 config
->seq_21_event
= val
& ETM_EVENT_MASK
;
817 static DEVICE_ATTR_RW(seq_21_event
);
819 static ssize_t
seq_23_event_show(struct device
*dev
,
820 struct device_attribute
*attr
, char *buf
)
823 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
824 struct etm_config
*config
= &drvdata
->config
;
826 val
= config
->seq_23_event
;
827 return sprintf(buf
, "%#lx\n", val
);
830 static ssize_t
seq_23_event_store(struct device
*dev
,
831 struct device_attribute
*attr
,
832 const char *buf
, size_t size
)
836 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
837 struct etm_config
*config
= &drvdata
->config
;
839 ret
= kstrtoul(buf
, 16, &val
);
843 config
->seq_23_event
= val
& ETM_EVENT_MASK
;
846 static DEVICE_ATTR_RW(seq_23_event
);
848 static ssize_t
seq_31_event_show(struct device
*dev
,
849 struct device_attribute
*attr
, char *buf
)
852 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
853 struct etm_config
*config
= &drvdata
->config
;
855 val
= config
->seq_31_event
;
856 return sprintf(buf
, "%#lx\n", val
);
859 static ssize_t
seq_31_event_store(struct device
*dev
,
860 struct device_attribute
*attr
,
861 const char *buf
, size_t size
)
865 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
866 struct etm_config
*config
= &drvdata
->config
;
868 ret
= kstrtoul(buf
, 16, &val
);
872 config
->seq_31_event
= val
& ETM_EVENT_MASK
;
875 static DEVICE_ATTR_RW(seq_31_event
);
877 static ssize_t
seq_32_event_show(struct device
*dev
,
878 struct device_attribute
*attr
, char *buf
)
881 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
882 struct etm_config
*config
= &drvdata
->config
;
884 val
= config
->seq_32_event
;
885 return sprintf(buf
, "%#lx\n", val
);
888 static ssize_t
seq_32_event_store(struct device
*dev
,
889 struct device_attribute
*attr
,
890 const char *buf
, size_t size
)
894 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
895 struct etm_config
*config
= &drvdata
->config
;
897 ret
= kstrtoul(buf
, 16, &val
);
901 config
->seq_32_event
= val
& ETM_EVENT_MASK
;
904 static DEVICE_ATTR_RW(seq_32_event
);
906 static ssize_t
seq_13_event_show(struct device
*dev
,
907 struct device_attribute
*attr
, char *buf
)
910 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
911 struct etm_config
*config
= &drvdata
->config
;
913 val
= config
->seq_13_event
;
914 return sprintf(buf
, "%#lx\n", val
);
917 static ssize_t
seq_13_event_store(struct device
*dev
,
918 struct device_attribute
*attr
,
919 const char *buf
, size_t size
)
923 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
924 struct etm_config
*config
= &drvdata
->config
;
926 ret
= kstrtoul(buf
, 16, &val
);
930 config
->seq_13_event
= val
& ETM_EVENT_MASK
;
933 static DEVICE_ATTR_RW(seq_13_event
);
935 static ssize_t
seq_curr_state_show(struct device
*dev
,
936 struct device_attribute
*attr
, char *buf
)
938 unsigned long val
, flags
;
939 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
940 struct etm_config
*config
= &drvdata
->config
;
942 if (!local_read(&drvdata
->mode
)) {
943 val
= config
->seq_curr_state
;
947 pm_runtime_get_sync(drvdata
->dev
);
948 spin_lock_irqsave(&drvdata
->spinlock
, flags
);
950 CS_UNLOCK(drvdata
->base
);
951 val
= (etm_readl(drvdata
, ETMSQR
) & ETM_SQR_MASK
);
952 CS_LOCK(drvdata
->base
);
954 spin_unlock_irqrestore(&drvdata
->spinlock
, flags
);
955 pm_runtime_put(drvdata
->dev
);
957 return sprintf(buf
, "%#lx\n", val
);
960 static ssize_t
seq_curr_state_store(struct device
*dev
,
961 struct device_attribute
*attr
,
962 const char *buf
, size_t size
)
966 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
967 struct etm_config
*config
= &drvdata
->config
;
969 ret
= kstrtoul(buf
, 16, &val
);
973 if (val
> ETM_SEQ_STATE_MAX_VAL
)
976 config
->seq_curr_state
= val
;
980 static DEVICE_ATTR_RW(seq_curr_state
);
982 static ssize_t
ctxid_idx_show(struct device
*dev
,
983 struct device_attribute
*attr
, char *buf
)
986 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
987 struct etm_config
*config
= &drvdata
->config
;
989 val
= config
->ctxid_idx
;
990 return sprintf(buf
, "%#lx\n", val
);
993 static ssize_t
ctxid_idx_store(struct device
*dev
,
994 struct device_attribute
*attr
,
995 const char *buf
, size_t size
)
999 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1000 struct etm_config
*config
= &drvdata
->config
;
1002 ret
= kstrtoul(buf
, 16, &val
);
1006 if (val
>= drvdata
->nr_ctxid_cmp
)
1010 * Use spinlock to ensure index doesn't change while it gets
1011 * dereferenced multiple times within a spinlock block elsewhere.
1013 spin_lock(&drvdata
->spinlock
);
1014 config
->ctxid_idx
= val
;
1015 spin_unlock(&drvdata
->spinlock
);
1019 static DEVICE_ATTR_RW(ctxid_idx
);
1021 static ssize_t
ctxid_pid_show(struct device
*dev
,
1022 struct device_attribute
*attr
, char *buf
)
1025 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1026 struct etm_config
*config
= &drvdata
->config
;
1028 spin_lock(&drvdata
->spinlock
);
1029 val
= config
->ctxid_vpid
[config
->ctxid_idx
];
1030 spin_unlock(&drvdata
->spinlock
);
1032 return sprintf(buf
, "%#lx\n", val
);
1035 static ssize_t
ctxid_pid_store(struct device
*dev
,
1036 struct device_attribute
*attr
,
1037 const char *buf
, size_t size
)
1040 unsigned long vpid
, pid
;
1041 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1042 struct etm_config
*config
= &drvdata
->config
;
1044 ret
= kstrtoul(buf
, 16, &vpid
);
1048 pid
= coresight_vpid_to_pid(vpid
);
1050 spin_lock(&drvdata
->spinlock
);
1051 config
->ctxid_pid
[config
->ctxid_idx
] = pid
;
1052 config
->ctxid_vpid
[config
->ctxid_idx
] = vpid
;
1053 spin_unlock(&drvdata
->spinlock
);
1057 static DEVICE_ATTR_RW(ctxid_pid
);
1059 static ssize_t
ctxid_mask_show(struct device
*dev
,
1060 struct device_attribute
*attr
, char *buf
)
1063 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1064 struct etm_config
*config
= &drvdata
->config
;
1066 val
= config
->ctxid_mask
;
1067 return sprintf(buf
, "%#lx\n", val
);
1070 static ssize_t
ctxid_mask_store(struct device
*dev
,
1071 struct device_attribute
*attr
,
1072 const char *buf
, size_t size
)
1076 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1077 struct etm_config
*config
= &drvdata
->config
;
1079 ret
= kstrtoul(buf
, 16, &val
);
1083 config
->ctxid_mask
= val
;
1086 static DEVICE_ATTR_RW(ctxid_mask
);
1088 static ssize_t
sync_freq_show(struct device
*dev
,
1089 struct device_attribute
*attr
, char *buf
)
1092 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1093 struct etm_config
*config
= &drvdata
->config
;
1095 val
= config
->sync_freq
;
1096 return sprintf(buf
, "%#lx\n", val
);
1099 static ssize_t
sync_freq_store(struct device
*dev
,
1100 struct device_attribute
*attr
,
1101 const char *buf
, size_t size
)
1105 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1106 struct etm_config
*config
= &drvdata
->config
;
1108 ret
= kstrtoul(buf
, 16, &val
);
1112 config
->sync_freq
= val
& ETM_SYNC_MASK
;
1115 static DEVICE_ATTR_RW(sync_freq
);
1117 static ssize_t
timestamp_event_show(struct device
*dev
,
1118 struct device_attribute
*attr
, char *buf
)
1121 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1122 struct etm_config
*config
= &drvdata
->config
;
1124 val
= config
->timestamp_event
;
1125 return sprintf(buf
, "%#lx\n", val
);
1128 static ssize_t
timestamp_event_store(struct device
*dev
,
1129 struct device_attribute
*attr
,
1130 const char *buf
, size_t size
)
1134 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1135 struct etm_config
*config
= &drvdata
->config
;
1137 ret
= kstrtoul(buf
, 16, &val
);
1141 config
->timestamp_event
= val
& ETM_EVENT_MASK
;
1144 static DEVICE_ATTR_RW(timestamp_event
);
1146 static ssize_t
cpu_show(struct device
*dev
,
1147 struct device_attribute
*attr
, char *buf
)
1150 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1153 return scnprintf(buf
, PAGE_SIZE
, "%d\n", val
);
1156 static DEVICE_ATTR_RO(cpu
);
1158 static ssize_t
traceid_show(struct device
*dev
,
1159 struct device_attribute
*attr
, char *buf
)
1162 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1164 val
= etm_get_trace_id(drvdata
);
1166 return sprintf(buf
, "%#lx\n", val
);
1169 static ssize_t
traceid_store(struct device
*dev
,
1170 struct device_attribute
*attr
,
1171 const char *buf
, size_t size
)
1175 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1177 ret
= kstrtoul(buf
, 16, &val
);
1181 drvdata
->traceid
= val
& ETM_TRACEID_MASK
;
1184 static DEVICE_ATTR_RW(traceid
);
1186 static struct attribute
*coresight_etm_attrs
[] = {
1187 &dev_attr_nr_addr_cmp
.attr
,
1188 &dev_attr_nr_cntr
.attr
,
1189 &dev_attr_nr_ctxid_cmp
.attr
,
1190 &dev_attr_etmsr
.attr
,
1191 &dev_attr_reset
.attr
,
1192 &dev_attr_mode
.attr
,
1193 &dev_attr_trigger_event
.attr
,
1194 &dev_attr_enable_event
.attr
,
1195 &dev_attr_fifofull_level
.attr
,
1196 &dev_attr_addr_idx
.attr
,
1197 &dev_attr_addr_single
.attr
,
1198 &dev_attr_addr_range
.attr
,
1199 &dev_attr_addr_start
.attr
,
1200 &dev_attr_addr_stop
.attr
,
1201 &dev_attr_addr_acctype
.attr
,
1202 &dev_attr_cntr_idx
.attr
,
1203 &dev_attr_cntr_rld_val
.attr
,
1204 &dev_attr_cntr_event
.attr
,
1205 &dev_attr_cntr_rld_event
.attr
,
1206 &dev_attr_cntr_val
.attr
,
1207 &dev_attr_seq_12_event
.attr
,
1208 &dev_attr_seq_21_event
.attr
,
1209 &dev_attr_seq_23_event
.attr
,
1210 &dev_attr_seq_31_event
.attr
,
1211 &dev_attr_seq_32_event
.attr
,
1212 &dev_attr_seq_13_event
.attr
,
1213 &dev_attr_seq_curr_state
.attr
,
1214 &dev_attr_ctxid_idx
.attr
,
1215 &dev_attr_ctxid_pid
.attr
,
1216 &dev_attr_ctxid_mask
.attr
,
1217 &dev_attr_sync_freq
.attr
,
1218 &dev_attr_timestamp_event
.attr
,
1219 &dev_attr_traceid
.attr
,
1224 #define coresight_etm3x_reg(name, offset) \
1225 coresight_simple_reg32(struct etm_drvdata, name, offset)
1227 coresight_etm3x_reg(etmccr
, ETMCCR
);
1228 coresight_etm3x_reg(etmccer
, ETMCCER
);
1229 coresight_etm3x_reg(etmscr
, ETMSCR
);
1230 coresight_etm3x_reg(etmidr
, ETMIDR
);
1231 coresight_etm3x_reg(etmcr
, ETMCR
);
1232 coresight_etm3x_reg(etmtraceidr
, ETMTRACEIDR
);
1233 coresight_etm3x_reg(etmteevr
, ETMTEEVR
);
1234 coresight_etm3x_reg(etmtssvr
, ETMTSSCR
);
1235 coresight_etm3x_reg(etmtecr1
, ETMTECR1
);
1236 coresight_etm3x_reg(etmtecr2
, ETMTECR2
);
1238 static struct attribute
*coresight_etm_mgmt_attrs
[] = {
1239 &dev_attr_etmccr
.attr
,
1240 &dev_attr_etmccer
.attr
,
1241 &dev_attr_etmscr
.attr
,
1242 &dev_attr_etmidr
.attr
,
1243 &dev_attr_etmcr
.attr
,
1244 &dev_attr_etmtraceidr
.attr
,
1245 &dev_attr_etmteevr
.attr
,
1246 &dev_attr_etmtssvr
.attr
,
1247 &dev_attr_etmtecr1
.attr
,
1248 &dev_attr_etmtecr2
.attr
,
1252 static const struct attribute_group coresight_etm_group
= {
1253 .attrs
= coresight_etm_attrs
,
1256 static const struct attribute_group coresight_etm_mgmt_group
= {
1257 .attrs
= coresight_etm_mgmt_attrs
,
1261 const struct attribute_group
*coresight_etm_groups
[] = {
1262 &coresight_etm_group
,
1263 &coresight_etm_mgmt_group
,