Linux 4.16.11
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-etm3x-sysfs.c
blob6e547ec6feaddf3150cc3aa886d830f16f065f66
1 /*
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
12 * more details.
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)
26 unsigned long val;
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)
36 { unsigned long val;
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)
47 unsigned long val;
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)
79 int i, ret;
80 unsigned long val;
81 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
82 struct etm_config *config = &drvdata->config;
84 ret = kstrtoul(buf, 16, &val);
85 if (ret)
86 return ret;
88 if (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);
101 return size;
103 static DEVICE_ATTR_WO(reset);
105 static ssize_t mode_show(struct device *dev,
106 struct device_attribute *attr, char *buf)
108 unsigned long val;
109 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
110 struct etm_config *config = &drvdata->config;
112 val = config->mode;
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)
120 int ret;
121 unsigned long val;
122 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
123 struct etm_config *config = &drvdata->config;
125 ret = kstrtoul(buf, 16, &val);
126 if (ret)
127 return ret;
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;
134 else
135 config->enable_ctrl1 &= ~ETMTECR1_INC_EXC;
137 if (config->mode & ETM_MODE_CYCACC)
138 config->ctrl |= ETMCR_CYC_ACC;
139 else
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");
145 ret = -EINVAL;
146 goto err_unlock;
148 config->ctrl |= ETMCR_STALL_MODE;
149 } else
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");
155 ret = -EINVAL;
156 goto err_unlock;
158 config->ctrl |= ETMCR_TIMESTAMP_EN;
159 } else
160 config->ctrl &= ~ETMCR_TIMESTAMP_EN;
162 if (config->mode & ETM_MODE_CTXID)
163 config->ctrl |= ETMCR_CTXID_SIZE;
164 else
165 config->ctrl &= ~ETMCR_CTXID_SIZE;
167 if (config->mode & ETM_MODE_BBROAD)
168 config->ctrl |= ETMCR_BRANCH_BROADCAST;
169 else
170 config->ctrl &= ~ETMCR_BRANCH_BROADCAST;
172 if (config->mode & ETM_MODE_RET_STACK)
173 config->ctrl |= ETMCR_RETURN_STACK;
174 else
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);
182 return size;
184 err_unlock:
185 spin_unlock(&drvdata->spinlock);
186 return ret;
188 static DEVICE_ATTR_RW(mode);
190 static ssize_t trigger_event_show(struct device *dev,
191 struct device_attribute *attr, char *buf)
193 unsigned long val;
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)
205 int ret;
206 unsigned long val;
207 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
208 struct etm_config *config = &drvdata->config;
210 ret = kstrtoul(buf, 16, &val);
211 if (ret)
212 return ret;
214 config->trigger_event = val & ETM_EVENT_MASK;
216 return size;
218 static DEVICE_ATTR_RW(trigger_event);
220 static ssize_t enable_event_show(struct device *dev,
221 struct device_attribute *attr, char *buf)
223 unsigned long val;
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)
235 int ret;
236 unsigned long val;
237 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
238 struct etm_config *config = &drvdata->config;
240 ret = kstrtoul(buf, 16, &val);
241 if (ret)
242 return ret;
244 config->enable_event = val & ETM_EVENT_MASK;
246 return size;
248 static DEVICE_ATTR_RW(enable_event);
250 static ssize_t fifofull_level_show(struct device *dev,
251 struct device_attribute *attr, char *buf)
253 unsigned long val;
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)
265 int ret;
266 unsigned long val;
267 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
268 struct etm_config *config = &drvdata->config;
270 ret = kstrtoul(buf, 16, &val);
271 if (ret)
272 return ret;
274 config->fifofull_level = val;
276 return size;
278 static DEVICE_ATTR_RW(fifofull_level);
280 static ssize_t addr_idx_show(struct device *dev,
281 struct device_attribute *attr, char *buf)
283 unsigned long val;
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)
295 int ret;
296 unsigned long val;
297 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
298 struct etm_config *config = &drvdata->config;
300 ret = kstrtoul(buf, 16, &val);
301 if (ret)
302 return ret;
304 if (val >= drvdata->nr_addr_cmp)
305 return -EINVAL;
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);
315 return size;
317 static DEVICE_ATTR_RW(addr_idx);
319 static ssize_t addr_single_show(struct device *dev,
320 struct device_attribute *attr, char *buf)
322 u8 idx;
323 unsigned long val;
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);
332 return -EINVAL;
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)
345 u8 idx;
346 int ret;
347 unsigned long val;
348 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
349 struct etm_config *config = &drvdata->config;
351 ret = kstrtoul(buf, 16, &val);
352 if (ret)
353 return ret;
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);
360 return -EINVAL;
363 config->addr_val[idx] = val;
364 config->addr_type[idx] = ETM_ADDR_TYPE_SINGLE;
365 spin_unlock(&drvdata->spinlock);
367 return size;
369 static DEVICE_ATTR_RW(addr_single);
371 static ssize_t addr_range_show(struct device *dev,
372 struct device_attribute *attr, char *buf)
374 u8 idx;
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;
381 if (idx % 2 != 0) {
382 spin_unlock(&drvdata->spinlock);
383 return -EPERM;
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);
390 return -EPERM;
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)
404 u8 idx;
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)
410 return -EINVAL;
411 /* Lower address comparator cannot have a higher address value */
412 if (val1 > val2)
413 return -EINVAL;
415 spin_lock(&drvdata->spinlock);
416 idx = config->addr_idx;
417 if (idx % 2 != 0) {
418 spin_unlock(&drvdata->spinlock);
419 return -EPERM;
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);
426 return -EPERM;
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);
436 return size;
438 static DEVICE_ATTR_RW(addr_range);
440 static ssize_t addr_start_show(struct device *dev,
441 struct device_attribute *attr, char *buf)
443 u8 idx;
444 unsigned long val;
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);
453 return -EPERM;
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)
466 u8 idx;
467 int ret;
468 unsigned long val;
469 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
470 struct etm_config *config = &drvdata->config;
472 ret = kstrtoul(buf, 16, &val);
473 if (ret)
474 return ret;
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);
481 return -EPERM;
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);
490 return size;
492 static DEVICE_ATTR_RW(addr_start);
494 static ssize_t addr_stop_show(struct device *dev,
495 struct device_attribute *attr, char *buf)
497 u8 idx;
498 unsigned long val;
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);
507 return -EPERM;
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)
520 u8 idx;
521 int ret;
522 unsigned long val;
523 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
524 struct etm_config *config = &drvdata->config;
526 ret = kstrtoul(buf, 16, &val);
527 if (ret)
528 return ret;
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);
535 return -EPERM;
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);
544 return size;
546 static DEVICE_ATTR_RW(addr_stop);
548 static ssize_t addr_acctype_show(struct device *dev,
549 struct device_attribute *attr, char *buf)
551 unsigned long val;
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)
566 int ret;
567 unsigned long val;
568 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
569 struct etm_config *config = &drvdata->config;
571 ret = kstrtoul(buf, 16, &val);
572 if (ret)
573 return ret;
575 spin_lock(&drvdata->spinlock);
576 config->addr_acctype[config->addr_idx] = val;
577 spin_unlock(&drvdata->spinlock);
579 return size;
581 static DEVICE_ATTR_RW(addr_acctype);
583 static ssize_t cntr_idx_show(struct device *dev,
584 struct device_attribute *attr, char *buf)
586 unsigned long val;
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)
598 int ret;
599 unsigned long val;
600 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
601 struct etm_config *config = &drvdata->config;
603 ret = kstrtoul(buf, 16, &val);
604 if (ret)
605 return ret;
607 if (val >= drvdata->nr_cntr)
608 return -EINVAL;
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);
617 return size;
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)
624 unsigned long val;
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)
639 int ret;
640 unsigned long val;
641 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
642 struct etm_config *config = &drvdata->config;
644 ret = kstrtoul(buf, 16, &val);
645 if (ret)
646 return ret;
648 spin_lock(&drvdata->spinlock);
649 config->cntr_rld_val[config->cntr_idx] = val;
650 spin_unlock(&drvdata->spinlock);
652 return size;
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)
659 unsigned long val;
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)
674 int ret;
675 unsigned long val;
676 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
677 struct etm_config *config = &drvdata->config;
679 ret = kstrtoul(buf, 16, &val);
680 if (ret)
681 return ret;
683 spin_lock(&drvdata->spinlock);
684 config->cntr_event[config->cntr_idx] = val & ETM_EVENT_MASK;
685 spin_unlock(&drvdata->spinlock);
687 return size;
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)
694 unsigned long val;
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)
709 int ret;
710 unsigned long val;
711 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
712 struct etm_config *config = &drvdata->config;
714 ret = kstrtoul(buf, 16, &val);
715 if (ret)
716 return ret;
718 spin_lock(&drvdata->spinlock);
719 config->cntr_rld_event[config->cntr_idx] = val & ETM_EVENT_MASK;
720 spin_unlock(&drvdata->spinlock);
722 return size;
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)
729 int i, ret = 0;
730 u32 val;
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);
740 return ret;
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);
748 return ret;
751 static ssize_t cntr_val_store(struct device *dev,
752 struct device_attribute *attr,
753 const char *buf, size_t size)
755 int ret;
756 unsigned long val;
757 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
758 struct etm_config *config = &drvdata->config;
760 ret = kstrtoul(buf, 16, &val);
761 if (ret)
762 return ret;
764 spin_lock(&drvdata->spinlock);
765 config->cntr_val[config->cntr_idx] = val;
766 spin_unlock(&drvdata->spinlock);
768 return size;
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)
775 unsigned long val;
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)
787 int ret;
788 unsigned long val;
789 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
790 struct etm_config *config = &drvdata->config;
792 ret = kstrtoul(buf, 16, &val);
793 if (ret)
794 return ret;
796 config->seq_12_event = val & ETM_EVENT_MASK;
797 return size;
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)
804 unsigned long val;
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)
816 int ret;
817 unsigned long val;
818 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
819 struct etm_config *config = &drvdata->config;
821 ret = kstrtoul(buf, 16, &val);
822 if (ret)
823 return ret;
825 config->seq_21_event = val & ETM_EVENT_MASK;
826 return size;
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)
833 unsigned long val;
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)
845 int ret;
846 unsigned long val;
847 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
848 struct etm_config *config = &drvdata->config;
850 ret = kstrtoul(buf, 16, &val);
851 if (ret)
852 return ret;
854 config->seq_23_event = val & ETM_EVENT_MASK;
855 return size;
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)
862 unsigned long val;
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)
874 int ret;
875 unsigned long val;
876 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
877 struct etm_config *config = &drvdata->config;
879 ret = kstrtoul(buf, 16, &val);
880 if (ret)
881 return ret;
883 config->seq_31_event = val & ETM_EVENT_MASK;
884 return size;
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)
891 unsigned long val;
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)
903 int ret;
904 unsigned long val;
905 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
906 struct etm_config *config = &drvdata->config;
908 ret = kstrtoul(buf, 16, &val);
909 if (ret)
910 return ret;
912 config->seq_32_event = val & ETM_EVENT_MASK;
913 return size;
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)
920 unsigned long val;
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)
932 int ret;
933 unsigned long val;
934 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
935 struct etm_config *config = &drvdata->config;
937 ret = kstrtoul(buf, 16, &val);
938 if (ret)
939 return ret;
941 config->seq_13_event = val & ETM_EVENT_MASK;
942 return size;
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;
955 goto out;
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);
967 out:
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)
975 int ret;
976 unsigned long val;
977 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
978 struct etm_config *config = &drvdata->config;
980 ret = kstrtoul(buf, 16, &val);
981 if (ret)
982 return ret;
984 if (val > ETM_SEQ_STATE_MAX_VAL)
985 return -EINVAL;
987 config->seq_curr_state = val;
989 return size;
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)
996 unsigned long val;
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)
1008 int ret;
1009 unsigned long val;
1010 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1011 struct etm_config *config = &drvdata->config;
1013 ret = kstrtoul(buf, 16, &val);
1014 if (ret)
1015 return ret;
1017 if (val >= drvdata->nr_ctxid_cmp)
1018 return -EINVAL;
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);
1028 return size;
1030 static DEVICE_ATTR_RW(ctxid_idx);
1032 static ssize_t ctxid_pid_show(struct device *dev,
1033 struct device_attribute *attr, char *buf)
1035 unsigned long val;
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)
1050 int ret;
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);
1056 if (ret)
1057 return ret;
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);
1066 return size;
1068 static DEVICE_ATTR_RW(ctxid_pid);
1070 static ssize_t ctxid_mask_show(struct device *dev,
1071 struct device_attribute *attr, char *buf)
1073 unsigned long val;
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)
1085 int ret;
1086 unsigned long val;
1087 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1088 struct etm_config *config = &drvdata->config;
1090 ret = kstrtoul(buf, 16, &val);
1091 if (ret)
1092 return ret;
1094 config->ctxid_mask = val;
1095 return size;
1097 static DEVICE_ATTR_RW(ctxid_mask);
1099 static ssize_t sync_freq_show(struct device *dev,
1100 struct device_attribute *attr, char *buf)
1102 unsigned long val;
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)
1114 int ret;
1115 unsigned long val;
1116 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1117 struct etm_config *config = &drvdata->config;
1119 ret = kstrtoul(buf, 16, &val);
1120 if (ret)
1121 return ret;
1123 config->sync_freq = val & ETM_SYNC_MASK;
1124 return size;
1126 static DEVICE_ATTR_RW(sync_freq);
1128 static ssize_t timestamp_event_show(struct device *dev,
1129 struct device_attribute *attr, char *buf)
1131 unsigned long val;
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)
1143 int ret;
1144 unsigned long val;
1145 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1146 struct etm_config *config = &drvdata->config;
1148 ret = kstrtoul(buf, 16, &val);
1149 if (ret)
1150 return ret;
1152 config->timestamp_event = val & ETM_EVENT_MASK;
1153 return size;
1155 static DEVICE_ATTR_RW(timestamp_event);
1157 static ssize_t cpu_show(struct device *dev,
1158 struct device_attribute *attr, char *buf)
1160 int val;
1161 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1163 val = drvdata->cpu;
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)
1172 unsigned long val;
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)
1184 int ret;
1185 unsigned long val;
1186 struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
1188 ret = kstrtoul(buf, 16, &val);
1189 if (ret)
1190 return ret;
1192 drvdata->traceid = val & ETM_TRACEID_MASK;
1193 return size;
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,
1231 &dev_attr_cpu.attr,
1232 NULL,
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,
1260 NULL,
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,
1269 .name = "mgmt",
1272 const struct attribute_group *coresight_etm_groups[] = {
1273 &coresight_etm_group,
1274 &coresight_etm_mgmt_group,
1275 NULL,