2 * Copyright(C) 2015 Linaro Limited. All rights reserved.
3 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/pm_runtime.h>
19 #include <linux/sysfs.h>
20 #include "coresight-etm.h"
21 #include "coresight-priv.h"
23 static ssize_t
nr_addr_cmp_show(struct device
*dev
,
24 struct device_attribute
*attr
, char *buf
)
27 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
29 val
= drvdata
->nr_addr_cmp
;
30 return sprintf(buf
, "%#lx\n", val
);
32 static DEVICE_ATTR_RO(nr_addr_cmp
);
34 static ssize_t
nr_cntr_show(struct device
*dev
,
35 struct device_attribute
*attr
, char *buf
)
37 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
39 val
= drvdata
->nr_cntr
;
40 return sprintf(buf
, "%#lx\n", val
);
42 static DEVICE_ATTR_RO(nr_cntr
);
44 static ssize_t
nr_ctxid_cmp_show(struct device
*dev
,
45 struct device_attribute
*attr
, char *buf
)
48 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
50 val
= drvdata
->nr_ctxid_cmp
;
51 return sprintf(buf
, "%#lx\n", val
);
53 static DEVICE_ATTR_RO(nr_ctxid_cmp
);
55 static ssize_t
etmsr_show(struct device
*dev
,
56 struct device_attribute
*attr
, char *buf
)
58 unsigned long flags
, val
;
59 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
61 pm_runtime_get_sync(drvdata
->dev
);
62 spin_lock_irqsave(&drvdata
->spinlock
, flags
);
63 CS_UNLOCK(drvdata
->base
);
65 val
= etm_readl(drvdata
, ETMSR
);
67 CS_LOCK(drvdata
->base
);
68 spin_unlock_irqrestore(&drvdata
->spinlock
, flags
);
69 pm_runtime_put(drvdata
->dev
);
71 return sprintf(buf
, "%#lx\n", val
);
73 static DEVICE_ATTR_RO(etmsr
);
75 static ssize_t
reset_store(struct device
*dev
,
76 struct device_attribute
*attr
,
77 const char *buf
, size_t size
)
81 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
82 struct etm_config
*config
= &drvdata
->config
;
84 ret
= kstrtoul(buf
, 16, &val
);
89 spin_lock(&drvdata
->spinlock
);
90 memset(config
, 0, sizeof(struct etm_config
));
91 config
->mode
= ETM_MODE_EXCLUDE
;
92 config
->trigger_event
= ETM_DEFAULT_EVENT_VAL
;
93 for (i
= 0; i
< drvdata
->nr_addr_cmp
; i
++) {
94 config
->addr_type
[i
] = ETM_ADDR_TYPE_NONE
;
97 etm_set_default(config
);
98 spin_unlock(&drvdata
->spinlock
);
103 static DEVICE_ATTR_WO(reset
);
105 static ssize_t
mode_show(struct device
*dev
,
106 struct device_attribute
*attr
, char *buf
)
109 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
110 struct etm_config
*config
= &drvdata
->config
;
113 return sprintf(buf
, "%#lx\n", val
);
116 static ssize_t
mode_store(struct device
*dev
,
117 struct device_attribute
*attr
,
118 const char *buf
, size_t size
)
122 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
123 struct etm_config
*config
= &drvdata
->config
;
125 ret
= kstrtoul(buf
, 16, &val
);
129 spin_lock(&drvdata
->spinlock
);
130 config
->mode
= val
& ETM_MODE_ALL
;
132 if (config
->mode
& ETM_MODE_EXCLUDE
)
133 config
->enable_ctrl1
|= ETMTECR1_INC_EXC
;
135 config
->enable_ctrl1
&= ~ETMTECR1_INC_EXC
;
137 if (config
->mode
& ETM_MODE_CYCACC
)
138 config
->ctrl
|= ETMCR_CYC_ACC
;
140 config
->ctrl
&= ~ETMCR_CYC_ACC
;
142 if (config
->mode
& ETM_MODE_STALL
) {
143 if (!(drvdata
->etmccr
& ETMCCR_FIFOFULL
)) {
144 dev_warn(drvdata
->dev
, "stall mode not supported\n");
148 config
->ctrl
|= ETMCR_STALL_MODE
;
150 config
->ctrl
&= ~ETMCR_STALL_MODE
;
152 if (config
->mode
& ETM_MODE_TIMESTAMP
) {
153 if (!(drvdata
->etmccer
& ETMCCER_TIMESTAMP
)) {
154 dev_warn(drvdata
->dev
, "timestamp not supported\n");
158 config
->ctrl
|= ETMCR_TIMESTAMP_EN
;
160 config
->ctrl
&= ~ETMCR_TIMESTAMP_EN
;
162 if (config
->mode
& ETM_MODE_CTXID
)
163 config
->ctrl
|= ETMCR_CTXID_SIZE
;
165 config
->ctrl
&= ~ETMCR_CTXID_SIZE
;
167 if (config
->mode
& ETM_MODE_BBROAD
)
168 config
->ctrl
|= ETMCR_BRANCH_BROADCAST
;
170 config
->ctrl
&= ~ETMCR_BRANCH_BROADCAST
;
172 if (config
->mode
& ETM_MODE_RET_STACK
)
173 config
->ctrl
|= ETMCR_RETURN_STACK
;
175 config
->ctrl
&= ~ETMCR_RETURN_STACK
;
177 if (config
->mode
& (ETM_MODE_EXCL_KERN
| ETM_MODE_EXCL_USER
))
178 etm_config_trace_mode(config
);
180 spin_unlock(&drvdata
->spinlock
);
185 spin_unlock(&drvdata
->spinlock
);
188 static DEVICE_ATTR_RW(mode
);
190 static ssize_t
trigger_event_show(struct device
*dev
,
191 struct device_attribute
*attr
, char *buf
)
194 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
195 struct etm_config
*config
= &drvdata
->config
;
197 val
= config
->trigger_event
;
198 return sprintf(buf
, "%#lx\n", val
);
201 static ssize_t
trigger_event_store(struct device
*dev
,
202 struct device_attribute
*attr
,
203 const char *buf
, size_t size
)
207 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
208 struct etm_config
*config
= &drvdata
->config
;
210 ret
= kstrtoul(buf
, 16, &val
);
214 config
->trigger_event
= val
& ETM_EVENT_MASK
;
218 static DEVICE_ATTR_RW(trigger_event
);
220 static ssize_t
enable_event_show(struct device
*dev
,
221 struct device_attribute
*attr
, char *buf
)
224 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
225 struct etm_config
*config
= &drvdata
->config
;
227 val
= config
->enable_event
;
228 return sprintf(buf
, "%#lx\n", val
);
231 static ssize_t
enable_event_store(struct device
*dev
,
232 struct device_attribute
*attr
,
233 const char *buf
, size_t size
)
237 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
238 struct etm_config
*config
= &drvdata
->config
;
240 ret
= kstrtoul(buf
, 16, &val
);
244 config
->enable_event
= val
& ETM_EVENT_MASK
;
248 static DEVICE_ATTR_RW(enable_event
);
250 static ssize_t
fifofull_level_show(struct device
*dev
,
251 struct device_attribute
*attr
, char *buf
)
254 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
255 struct etm_config
*config
= &drvdata
->config
;
257 val
= config
->fifofull_level
;
258 return sprintf(buf
, "%#lx\n", val
);
261 static ssize_t
fifofull_level_store(struct device
*dev
,
262 struct device_attribute
*attr
,
263 const char *buf
, size_t size
)
267 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
268 struct etm_config
*config
= &drvdata
->config
;
270 ret
= kstrtoul(buf
, 16, &val
);
274 config
->fifofull_level
= val
;
278 static DEVICE_ATTR_RW(fifofull_level
);
280 static ssize_t
addr_idx_show(struct device
*dev
,
281 struct device_attribute
*attr
, char *buf
)
284 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
285 struct etm_config
*config
= &drvdata
->config
;
287 val
= config
->addr_idx
;
288 return sprintf(buf
, "%#lx\n", val
);
291 static ssize_t
addr_idx_store(struct device
*dev
,
292 struct device_attribute
*attr
,
293 const char *buf
, size_t size
)
297 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
298 struct etm_config
*config
= &drvdata
->config
;
300 ret
= kstrtoul(buf
, 16, &val
);
304 if (val
>= drvdata
->nr_addr_cmp
)
308 * Use spinlock to ensure index doesn't change while it gets
309 * dereferenced multiple times within a spinlock block elsewhere.
311 spin_lock(&drvdata
->spinlock
);
312 config
->addr_idx
= val
;
313 spin_unlock(&drvdata
->spinlock
);
317 static DEVICE_ATTR_RW(addr_idx
);
319 static ssize_t
addr_single_show(struct device
*dev
,
320 struct device_attribute
*attr
, char *buf
)
324 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
325 struct etm_config
*config
= &drvdata
->config
;
327 spin_lock(&drvdata
->spinlock
);
328 idx
= config
->addr_idx
;
329 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
330 config
->addr_type
[idx
] == ETM_ADDR_TYPE_SINGLE
)) {
331 spin_unlock(&drvdata
->spinlock
);
335 val
= config
->addr_val
[idx
];
336 spin_unlock(&drvdata
->spinlock
);
338 return sprintf(buf
, "%#lx\n", val
);
341 static ssize_t
addr_single_store(struct device
*dev
,
342 struct device_attribute
*attr
,
343 const char *buf
, size_t size
)
348 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
349 struct etm_config
*config
= &drvdata
->config
;
351 ret
= kstrtoul(buf
, 16, &val
);
355 spin_lock(&drvdata
->spinlock
);
356 idx
= config
->addr_idx
;
357 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
358 config
->addr_type
[idx
] == ETM_ADDR_TYPE_SINGLE
)) {
359 spin_unlock(&drvdata
->spinlock
);
363 config
->addr_val
[idx
] = val
;
364 config
->addr_type
[idx
] = ETM_ADDR_TYPE_SINGLE
;
365 spin_unlock(&drvdata
->spinlock
);
369 static DEVICE_ATTR_RW(addr_single
);
371 static ssize_t
addr_range_show(struct device
*dev
,
372 struct device_attribute
*attr
, char *buf
)
375 unsigned long val1
, val2
;
376 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
377 struct etm_config
*config
= &drvdata
->config
;
379 spin_lock(&drvdata
->spinlock
);
380 idx
= config
->addr_idx
;
382 spin_unlock(&drvdata
->spinlock
);
385 if (!((config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
&&
386 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_NONE
) ||
387 (config
->addr_type
[idx
] == ETM_ADDR_TYPE_RANGE
&&
388 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_RANGE
))) {
389 spin_unlock(&drvdata
->spinlock
);
393 val1
= config
->addr_val
[idx
];
394 val2
= config
->addr_val
[idx
+ 1];
395 spin_unlock(&drvdata
->spinlock
);
397 return sprintf(buf
, "%#lx %#lx\n", val1
, val2
);
400 static ssize_t
addr_range_store(struct device
*dev
,
401 struct device_attribute
*attr
,
402 const char *buf
, size_t size
)
405 unsigned long val1
, val2
;
406 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
407 struct etm_config
*config
= &drvdata
->config
;
409 if (sscanf(buf
, "%lx %lx", &val1
, &val2
) != 2)
411 /* Lower address comparator cannot have a higher address value */
415 spin_lock(&drvdata
->spinlock
);
416 idx
= config
->addr_idx
;
418 spin_unlock(&drvdata
->spinlock
);
421 if (!((config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
&&
422 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_NONE
) ||
423 (config
->addr_type
[idx
] == ETM_ADDR_TYPE_RANGE
&&
424 config
->addr_type
[idx
+ 1] == ETM_ADDR_TYPE_RANGE
))) {
425 spin_unlock(&drvdata
->spinlock
);
429 config
->addr_val
[idx
] = val1
;
430 config
->addr_type
[idx
] = ETM_ADDR_TYPE_RANGE
;
431 config
->addr_val
[idx
+ 1] = val2
;
432 config
->addr_type
[idx
+ 1] = ETM_ADDR_TYPE_RANGE
;
433 config
->enable_ctrl1
|= (1 << (idx
/2));
434 spin_unlock(&drvdata
->spinlock
);
438 static DEVICE_ATTR_RW(addr_range
);
440 static ssize_t
addr_start_show(struct device
*dev
,
441 struct device_attribute
*attr
, char *buf
)
445 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
446 struct etm_config
*config
= &drvdata
->config
;
448 spin_lock(&drvdata
->spinlock
);
449 idx
= config
->addr_idx
;
450 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
451 config
->addr_type
[idx
] == ETM_ADDR_TYPE_START
)) {
452 spin_unlock(&drvdata
->spinlock
);
456 val
= config
->addr_val
[idx
];
457 spin_unlock(&drvdata
->spinlock
);
459 return sprintf(buf
, "%#lx\n", val
);
462 static ssize_t
addr_start_store(struct device
*dev
,
463 struct device_attribute
*attr
,
464 const char *buf
, size_t size
)
469 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
470 struct etm_config
*config
= &drvdata
->config
;
472 ret
= kstrtoul(buf
, 16, &val
);
476 spin_lock(&drvdata
->spinlock
);
477 idx
= config
->addr_idx
;
478 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
479 config
->addr_type
[idx
] == ETM_ADDR_TYPE_START
)) {
480 spin_unlock(&drvdata
->spinlock
);
484 config
->addr_val
[idx
] = val
;
485 config
->addr_type
[idx
] = ETM_ADDR_TYPE_START
;
486 config
->startstop_ctrl
|= (1 << idx
);
487 config
->enable_ctrl1
|= BIT(25);
488 spin_unlock(&drvdata
->spinlock
);
492 static DEVICE_ATTR_RW(addr_start
);
494 static ssize_t
addr_stop_show(struct device
*dev
,
495 struct device_attribute
*attr
, char *buf
)
499 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
500 struct etm_config
*config
= &drvdata
->config
;
502 spin_lock(&drvdata
->spinlock
);
503 idx
= config
->addr_idx
;
504 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
505 config
->addr_type
[idx
] == ETM_ADDR_TYPE_STOP
)) {
506 spin_unlock(&drvdata
->spinlock
);
510 val
= config
->addr_val
[idx
];
511 spin_unlock(&drvdata
->spinlock
);
513 return sprintf(buf
, "%#lx\n", val
);
516 static ssize_t
addr_stop_store(struct device
*dev
,
517 struct device_attribute
*attr
,
518 const char *buf
, size_t size
)
523 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
524 struct etm_config
*config
= &drvdata
->config
;
526 ret
= kstrtoul(buf
, 16, &val
);
530 spin_lock(&drvdata
->spinlock
);
531 idx
= config
->addr_idx
;
532 if (!(config
->addr_type
[idx
] == ETM_ADDR_TYPE_NONE
||
533 config
->addr_type
[idx
] == ETM_ADDR_TYPE_STOP
)) {
534 spin_unlock(&drvdata
->spinlock
);
538 config
->addr_val
[idx
] = val
;
539 config
->addr_type
[idx
] = ETM_ADDR_TYPE_STOP
;
540 config
->startstop_ctrl
|= (1 << (idx
+ 16));
541 config
->enable_ctrl1
|= ETMTECR1_START_STOP
;
542 spin_unlock(&drvdata
->spinlock
);
546 static DEVICE_ATTR_RW(addr_stop
);
548 static ssize_t
addr_acctype_show(struct device
*dev
,
549 struct device_attribute
*attr
, char *buf
)
552 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
553 struct etm_config
*config
= &drvdata
->config
;
555 spin_lock(&drvdata
->spinlock
);
556 val
= config
->addr_acctype
[config
->addr_idx
];
557 spin_unlock(&drvdata
->spinlock
);
559 return sprintf(buf
, "%#lx\n", val
);
562 static ssize_t
addr_acctype_store(struct device
*dev
,
563 struct device_attribute
*attr
,
564 const char *buf
, size_t size
)
568 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
569 struct etm_config
*config
= &drvdata
->config
;
571 ret
= kstrtoul(buf
, 16, &val
);
575 spin_lock(&drvdata
->spinlock
);
576 config
->addr_acctype
[config
->addr_idx
] = val
;
577 spin_unlock(&drvdata
->spinlock
);
581 static DEVICE_ATTR_RW(addr_acctype
);
583 static ssize_t
cntr_idx_show(struct device
*dev
,
584 struct device_attribute
*attr
, char *buf
)
587 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
588 struct etm_config
*config
= &drvdata
->config
;
590 val
= config
->cntr_idx
;
591 return sprintf(buf
, "%#lx\n", val
);
594 static ssize_t
cntr_idx_store(struct device
*dev
,
595 struct device_attribute
*attr
,
596 const char *buf
, size_t size
)
600 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
601 struct etm_config
*config
= &drvdata
->config
;
603 ret
= kstrtoul(buf
, 16, &val
);
607 if (val
>= drvdata
->nr_cntr
)
610 * Use spinlock to ensure index doesn't change while it gets
611 * dereferenced multiple times within a spinlock block elsewhere.
613 spin_lock(&drvdata
->spinlock
);
614 config
->cntr_idx
= val
;
615 spin_unlock(&drvdata
->spinlock
);
619 static DEVICE_ATTR_RW(cntr_idx
);
621 static ssize_t
cntr_rld_val_show(struct device
*dev
,
622 struct device_attribute
*attr
, char *buf
)
625 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
626 struct etm_config
*config
= &drvdata
->config
;
628 spin_lock(&drvdata
->spinlock
);
629 val
= config
->cntr_rld_val
[config
->cntr_idx
];
630 spin_unlock(&drvdata
->spinlock
);
632 return sprintf(buf
, "%#lx\n", val
);
635 static ssize_t
cntr_rld_val_store(struct device
*dev
,
636 struct device_attribute
*attr
,
637 const char *buf
, size_t size
)
641 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
642 struct etm_config
*config
= &drvdata
->config
;
644 ret
= kstrtoul(buf
, 16, &val
);
648 spin_lock(&drvdata
->spinlock
);
649 config
->cntr_rld_val
[config
->cntr_idx
] = val
;
650 spin_unlock(&drvdata
->spinlock
);
654 static DEVICE_ATTR_RW(cntr_rld_val
);
656 static ssize_t
cntr_event_show(struct device
*dev
,
657 struct device_attribute
*attr
, char *buf
)
660 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
661 struct etm_config
*config
= &drvdata
->config
;
663 spin_lock(&drvdata
->spinlock
);
664 val
= config
->cntr_event
[config
->cntr_idx
];
665 spin_unlock(&drvdata
->spinlock
);
667 return sprintf(buf
, "%#lx\n", val
);
670 static ssize_t
cntr_event_store(struct device
*dev
,
671 struct device_attribute
*attr
,
672 const char *buf
, size_t size
)
676 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
677 struct etm_config
*config
= &drvdata
->config
;
679 ret
= kstrtoul(buf
, 16, &val
);
683 spin_lock(&drvdata
->spinlock
);
684 config
->cntr_event
[config
->cntr_idx
] = val
& ETM_EVENT_MASK
;
685 spin_unlock(&drvdata
->spinlock
);
689 static DEVICE_ATTR_RW(cntr_event
);
691 static ssize_t
cntr_rld_event_show(struct device
*dev
,
692 struct device_attribute
*attr
, char *buf
)
695 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
696 struct etm_config
*config
= &drvdata
->config
;
698 spin_lock(&drvdata
->spinlock
);
699 val
= config
->cntr_rld_event
[config
->cntr_idx
];
700 spin_unlock(&drvdata
->spinlock
);
702 return sprintf(buf
, "%#lx\n", val
);
705 static ssize_t
cntr_rld_event_store(struct device
*dev
,
706 struct device_attribute
*attr
,
707 const char *buf
, size_t size
)
711 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
712 struct etm_config
*config
= &drvdata
->config
;
714 ret
= kstrtoul(buf
, 16, &val
);
718 spin_lock(&drvdata
->spinlock
);
719 config
->cntr_rld_event
[config
->cntr_idx
] = val
& ETM_EVENT_MASK
;
720 spin_unlock(&drvdata
->spinlock
);
724 static DEVICE_ATTR_RW(cntr_rld_event
);
726 static ssize_t
cntr_val_show(struct device
*dev
,
727 struct device_attribute
*attr
, char *buf
)
731 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
732 struct etm_config
*config
= &drvdata
->config
;
734 if (!local_read(&drvdata
->mode
)) {
735 spin_lock(&drvdata
->spinlock
);
736 for (i
= 0; i
< drvdata
->nr_cntr
; i
++)
737 ret
+= sprintf(buf
, "counter %d: %x\n",
738 i
, config
->cntr_val
[i
]);
739 spin_unlock(&drvdata
->spinlock
);
743 for (i
= 0; i
< drvdata
->nr_cntr
; i
++) {
744 val
= etm_readl(drvdata
, ETMCNTVRn(i
));
745 ret
+= sprintf(buf
, "counter %d: %x\n", i
, val
);
751 static ssize_t
cntr_val_store(struct device
*dev
,
752 struct device_attribute
*attr
,
753 const char *buf
, size_t size
)
757 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
758 struct etm_config
*config
= &drvdata
->config
;
760 ret
= kstrtoul(buf
, 16, &val
);
764 spin_lock(&drvdata
->spinlock
);
765 config
->cntr_val
[config
->cntr_idx
] = val
;
766 spin_unlock(&drvdata
->spinlock
);
770 static DEVICE_ATTR_RW(cntr_val
);
772 static ssize_t
seq_12_event_show(struct device
*dev
,
773 struct device_attribute
*attr
, char *buf
)
776 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
777 struct etm_config
*config
= &drvdata
->config
;
779 val
= config
->seq_12_event
;
780 return sprintf(buf
, "%#lx\n", val
);
783 static ssize_t
seq_12_event_store(struct device
*dev
,
784 struct device_attribute
*attr
,
785 const char *buf
, size_t size
)
789 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
790 struct etm_config
*config
= &drvdata
->config
;
792 ret
= kstrtoul(buf
, 16, &val
);
796 config
->seq_12_event
= val
& ETM_EVENT_MASK
;
799 static DEVICE_ATTR_RW(seq_12_event
);
801 static ssize_t
seq_21_event_show(struct device
*dev
,
802 struct device_attribute
*attr
, char *buf
)
805 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
806 struct etm_config
*config
= &drvdata
->config
;
808 val
= config
->seq_21_event
;
809 return sprintf(buf
, "%#lx\n", val
);
812 static ssize_t
seq_21_event_store(struct device
*dev
,
813 struct device_attribute
*attr
,
814 const char *buf
, size_t size
)
818 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
819 struct etm_config
*config
= &drvdata
->config
;
821 ret
= kstrtoul(buf
, 16, &val
);
825 config
->seq_21_event
= val
& ETM_EVENT_MASK
;
828 static DEVICE_ATTR_RW(seq_21_event
);
830 static ssize_t
seq_23_event_show(struct device
*dev
,
831 struct device_attribute
*attr
, char *buf
)
834 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
835 struct etm_config
*config
= &drvdata
->config
;
837 val
= config
->seq_23_event
;
838 return sprintf(buf
, "%#lx\n", val
);
841 static ssize_t
seq_23_event_store(struct device
*dev
,
842 struct device_attribute
*attr
,
843 const char *buf
, size_t size
)
847 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
848 struct etm_config
*config
= &drvdata
->config
;
850 ret
= kstrtoul(buf
, 16, &val
);
854 config
->seq_23_event
= val
& ETM_EVENT_MASK
;
857 static DEVICE_ATTR_RW(seq_23_event
);
859 static ssize_t
seq_31_event_show(struct device
*dev
,
860 struct device_attribute
*attr
, char *buf
)
863 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
864 struct etm_config
*config
= &drvdata
->config
;
866 val
= config
->seq_31_event
;
867 return sprintf(buf
, "%#lx\n", val
);
870 static ssize_t
seq_31_event_store(struct device
*dev
,
871 struct device_attribute
*attr
,
872 const char *buf
, size_t size
)
876 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
877 struct etm_config
*config
= &drvdata
->config
;
879 ret
= kstrtoul(buf
, 16, &val
);
883 config
->seq_31_event
= val
& ETM_EVENT_MASK
;
886 static DEVICE_ATTR_RW(seq_31_event
);
888 static ssize_t
seq_32_event_show(struct device
*dev
,
889 struct device_attribute
*attr
, char *buf
)
892 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
893 struct etm_config
*config
= &drvdata
->config
;
895 val
= config
->seq_32_event
;
896 return sprintf(buf
, "%#lx\n", val
);
899 static ssize_t
seq_32_event_store(struct device
*dev
,
900 struct device_attribute
*attr
,
901 const char *buf
, size_t size
)
905 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
906 struct etm_config
*config
= &drvdata
->config
;
908 ret
= kstrtoul(buf
, 16, &val
);
912 config
->seq_32_event
= val
& ETM_EVENT_MASK
;
915 static DEVICE_ATTR_RW(seq_32_event
);
917 static ssize_t
seq_13_event_show(struct device
*dev
,
918 struct device_attribute
*attr
, char *buf
)
921 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
922 struct etm_config
*config
= &drvdata
->config
;
924 val
= config
->seq_13_event
;
925 return sprintf(buf
, "%#lx\n", val
);
928 static ssize_t
seq_13_event_store(struct device
*dev
,
929 struct device_attribute
*attr
,
930 const char *buf
, size_t size
)
934 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
935 struct etm_config
*config
= &drvdata
->config
;
937 ret
= kstrtoul(buf
, 16, &val
);
941 config
->seq_13_event
= val
& ETM_EVENT_MASK
;
944 static DEVICE_ATTR_RW(seq_13_event
);
946 static ssize_t
seq_curr_state_show(struct device
*dev
,
947 struct device_attribute
*attr
, char *buf
)
949 unsigned long val
, flags
;
950 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
951 struct etm_config
*config
= &drvdata
->config
;
953 if (!local_read(&drvdata
->mode
)) {
954 val
= config
->seq_curr_state
;
958 pm_runtime_get_sync(drvdata
->dev
);
959 spin_lock_irqsave(&drvdata
->spinlock
, flags
);
961 CS_UNLOCK(drvdata
->base
);
962 val
= (etm_readl(drvdata
, ETMSQR
) & ETM_SQR_MASK
);
963 CS_LOCK(drvdata
->base
);
965 spin_unlock_irqrestore(&drvdata
->spinlock
, flags
);
966 pm_runtime_put(drvdata
->dev
);
968 return sprintf(buf
, "%#lx\n", val
);
971 static ssize_t
seq_curr_state_store(struct device
*dev
,
972 struct device_attribute
*attr
,
973 const char *buf
, size_t size
)
977 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
978 struct etm_config
*config
= &drvdata
->config
;
980 ret
= kstrtoul(buf
, 16, &val
);
984 if (val
> ETM_SEQ_STATE_MAX_VAL
)
987 config
->seq_curr_state
= val
;
991 static DEVICE_ATTR_RW(seq_curr_state
);
993 static ssize_t
ctxid_idx_show(struct device
*dev
,
994 struct device_attribute
*attr
, char *buf
)
997 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
998 struct etm_config
*config
= &drvdata
->config
;
1000 val
= config
->ctxid_idx
;
1001 return sprintf(buf
, "%#lx\n", val
);
1004 static ssize_t
ctxid_idx_store(struct device
*dev
,
1005 struct device_attribute
*attr
,
1006 const char *buf
, size_t size
)
1010 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1011 struct etm_config
*config
= &drvdata
->config
;
1013 ret
= kstrtoul(buf
, 16, &val
);
1017 if (val
>= drvdata
->nr_ctxid_cmp
)
1021 * Use spinlock to ensure index doesn't change while it gets
1022 * dereferenced multiple times within a spinlock block elsewhere.
1024 spin_lock(&drvdata
->spinlock
);
1025 config
->ctxid_idx
= val
;
1026 spin_unlock(&drvdata
->spinlock
);
1030 static DEVICE_ATTR_RW(ctxid_idx
);
1032 static ssize_t
ctxid_pid_show(struct device
*dev
,
1033 struct device_attribute
*attr
, char *buf
)
1036 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1037 struct etm_config
*config
= &drvdata
->config
;
1039 spin_lock(&drvdata
->spinlock
);
1040 val
= config
->ctxid_vpid
[config
->ctxid_idx
];
1041 spin_unlock(&drvdata
->spinlock
);
1043 return sprintf(buf
, "%#lx\n", val
);
1046 static ssize_t
ctxid_pid_store(struct device
*dev
,
1047 struct device_attribute
*attr
,
1048 const char *buf
, size_t size
)
1051 unsigned long vpid
, pid
;
1052 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1053 struct etm_config
*config
= &drvdata
->config
;
1055 ret
= kstrtoul(buf
, 16, &vpid
);
1059 pid
= coresight_vpid_to_pid(vpid
);
1061 spin_lock(&drvdata
->spinlock
);
1062 config
->ctxid_pid
[config
->ctxid_idx
] = pid
;
1063 config
->ctxid_vpid
[config
->ctxid_idx
] = vpid
;
1064 spin_unlock(&drvdata
->spinlock
);
1068 static DEVICE_ATTR_RW(ctxid_pid
);
1070 static ssize_t
ctxid_mask_show(struct device
*dev
,
1071 struct device_attribute
*attr
, char *buf
)
1074 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1075 struct etm_config
*config
= &drvdata
->config
;
1077 val
= config
->ctxid_mask
;
1078 return sprintf(buf
, "%#lx\n", val
);
1081 static ssize_t
ctxid_mask_store(struct device
*dev
,
1082 struct device_attribute
*attr
,
1083 const char *buf
, size_t size
)
1087 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1088 struct etm_config
*config
= &drvdata
->config
;
1090 ret
= kstrtoul(buf
, 16, &val
);
1094 config
->ctxid_mask
= val
;
1097 static DEVICE_ATTR_RW(ctxid_mask
);
1099 static ssize_t
sync_freq_show(struct device
*dev
,
1100 struct device_attribute
*attr
, char *buf
)
1103 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1104 struct etm_config
*config
= &drvdata
->config
;
1106 val
= config
->sync_freq
;
1107 return sprintf(buf
, "%#lx\n", val
);
1110 static ssize_t
sync_freq_store(struct device
*dev
,
1111 struct device_attribute
*attr
,
1112 const char *buf
, size_t size
)
1116 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1117 struct etm_config
*config
= &drvdata
->config
;
1119 ret
= kstrtoul(buf
, 16, &val
);
1123 config
->sync_freq
= val
& ETM_SYNC_MASK
;
1126 static DEVICE_ATTR_RW(sync_freq
);
1128 static ssize_t
timestamp_event_show(struct device
*dev
,
1129 struct device_attribute
*attr
, char *buf
)
1132 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1133 struct etm_config
*config
= &drvdata
->config
;
1135 val
= config
->timestamp_event
;
1136 return sprintf(buf
, "%#lx\n", val
);
1139 static ssize_t
timestamp_event_store(struct device
*dev
,
1140 struct device_attribute
*attr
,
1141 const char *buf
, size_t size
)
1145 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1146 struct etm_config
*config
= &drvdata
->config
;
1148 ret
= kstrtoul(buf
, 16, &val
);
1152 config
->timestamp_event
= val
& ETM_EVENT_MASK
;
1155 static DEVICE_ATTR_RW(timestamp_event
);
1157 static ssize_t
cpu_show(struct device
*dev
,
1158 struct device_attribute
*attr
, char *buf
)
1161 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1164 return scnprintf(buf
, PAGE_SIZE
, "%d\n", val
);
1167 static DEVICE_ATTR_RO(cpu
);
1169 static ssize_t
traceid_show(struct device
*dev
,
1170 struct device_attribute
*attr
, char *buf
)
1173 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1175 val
= etm_get_trace_id(drvdata
);
1177 return sprintf(buf
, "%#lx\n", val
);
1180 static ssize_t
traceid_store(struct device
*dev
,
1181 struct device_attribute
*attr
,
1182 const char *buf
, size_t size
)
1186 struct etm_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
1188 ret
= kstrtoul(buf
, 16, &val
);
1192 drvdata
->traceid
= val
& ETM_TRACEID_MASK
;
1195 static DEVICE_ATTR_RW(traceid
);
1197 static struct attribute
*coresight_etm_attrs
[] = {
1198 &dev_attr_nr_addr_cmp
.attr
,
1199 &dev_attr_nr_cntr
.attr
,
1200 &dev_attr_nr_ctxid_cmp
.attr
,
1201 &dev_attr_etmsr
.attr
,
1202 &dev_attr_reset
.attr
,
1203 &dev_attr_mode
.attr
,
1204 &dev_attr_trigger_event
.attr
,
1205 &dev_attr_enable_event
.attr
,
1206 &dev_attr_fifofull_level
.attr
,
1207 &dev_attr_addr_idx
.attr
,
1208 &dev_attr_addr_single
.attr
,
1209 &dev_attr_addr_range
.attr
,
1210 &dev_attr_addr_start
.attr
,
1211 &dev_attr_addr_stop
.attr
,
1212 &dev_attr_addr_acctype
.attr
,
1213 &dev_attr_cntr_idx
.attr
,
1214 &dev_attr_cntr_rld_val
.attr
,
1215 &dev_attr_cntr_event
.attr
,
1216 &dev_attr_cntr_rld_event
.attr
,
1217 &dev_attr_cntr_val
.attr
,
1218 &dev_attr_seq_12_event
.attr
,
1219 &dev_attr_seq_21_event
.attr
,
1220 &dev_attr_seq_23_event
.attr
,
1221 &dev_attr_seq_31_event
.attr
,
1222 &dev_attr_seq_32_event
.attr
,
1223 &dev_attr_seq_13_event
.attr
,
1224 &dev_attr_seq_curr_state
.attr
,
1225 &dev_attr_ctxid_idx
.attr
,
1226 &dev_attr_ctxid_pid
.attr
,
1227 &dev_attr_ctxid_mask
.attr
,
1228 &dev_attr_sync_freq
.attr
,
1229 &dev_attr_timestamp_event
.attr
,
1230 &dev_attr_traceid
.attr
,
1235 #define coresight_etm3x_reg(name, offset) \
1236 coresight_simple_reg32(struct etm_drvdata, name, offset)
1238 coresight_etm3x_reg(etmccr
, ETMCCR
);
1239 coresight_etm3x_reg(etmccer
, ETMCCER
);
1240 coresight_etm3x_reg(etmscr
, ETMSCR
);
1241 coresight_etm3x_reg(etmidr
, ETMIDR
);
1242 coresight_etm3x_reg(etmcr
, ETMCR
);
1243 coresight_etm3x_reg(etmtraceidr
, ETMTRACEIDR
);
1244 coresight_etm3x_reg(etmteevr
, ETMTEEVR
);
1245 coresight_etm3x_reg(etmtssvr
, ETMTSSCR
);
1246 coresight_etm3x_reg(etmtecr1
, ETMTECR1
);
1247 coresight_etm3x_reg(etmtecr2
, ETMTECR2
);
1249 static struct attribute
*coresight_etm_mgmt_attrs
[] = {
1250 &dev_attr_etmccr
.attr
,
1251 &dev_attr_etmccer
.attr
,
1252 &dev_attr_etmscr
.attr
,
1253 &dev_attr_etmidr
.attr
,
1254 &dev_attr_etmcr
.attr
,
1255 &dev_attr_etmtraceidr
.attr
,
1256 &dev_attr_etmteevr
.attr
,
1257 &dev_attr_etmtssvr
.attr
,
1258 &dev_attr_etmtecr1
.attr
,
1259 &dev_attr_etmtecr2
.attr
,
1263 static const struct attribute_group coresight_etm_group
= {
1264 .attrs
= coresight_etm_attrs
,
1267 static const struct attribute_group coresight_etm_mgmt_group
= {
1268 .attrs
= coresight_etm_mgmt_attrs
,
1272 const struct attribute_group
*coresight_etm_groups
[] = {
1273 &coresight_etm_group
,
1274 &coresight_etm_mgmt_group
,