Skip to content

Commit efd272e

Browse files
Songwei Chaijiegan0107
authored andcommitted
FROMLIST: coresight-tgu: add reset node to initialize
Add reset node to initialize the value of priority/condition_decode/condition_select/timer/counter nodes Link: https://lore.kernel.org/all/20250423-tgu_patch-v5-7-3b52c105cc63@quicinc.com/ Signed-off-by: Songwei Chai <quic_songchai@quicinc.com>
1 parent 7468662 commit efd272e

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

Documentation/ABI/testing/sysfs-bus-coresight-devices-tgu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ KernelVersion 6.15
4242
Contact: Jinlong Mao (QUIC) <quic_jinlmao@quicinc.com>, Sam Chai (QUIC) <quic_songchai@quicinc.com>
4343
Description:
4444
(RW) Set/Get the counter value with specific step for TGU.
45+
46+
What: /sys/bus/coresight/devices/<tgu-name>/reset_tgu
47+
Date: February 2025
48+
KernelVersion 6.15
49+
Contact: Jinlong Mao (QUIC) <quic_jinlmao@quicinc.com>, Sam Chai (QUIC) <quic_songchai@quicinc.com>
50+
Description:
51+
(Write) Write 1 to reset the dataset for TGU.

drivers/hwtracing/coresight/coresight-tgu.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,80 @@ static ssize_t enable_tgu_store(struct device *dev,
477477
}
478478
static DEVICE_ATTR_RW(enable_tgu);
479479

480+
/* reset_tgu_store - Reset Trace and Gating Unit (TGU) configuration. */
481+
static ssize_t reset_tgu_store(struct device *dev,
482+
struct device_attribute *attr, const char *buf,
483+
size_t size)
484+
{
485+
unsigned long value;
486+
struct tgu_drvdata *drvdata = dev_get_drvdata(dev->parent);
487+
int i, j, ret;
488+
489+
if (kstrtoul(buf, 0, &value) || value == 0)
490+
return -EINVAL;
491+
492+
if (!drvdata->enable) {
493+
ret = pm_runtime_get_sync(drvdata->dev);
494+
if (ret < 0) {
495+
pm_runtime_put(drvdata->dev);
496+
return ret;
497+
}
498+
}
499+
500+
spin_lock(&drvdata->spinlock);
501+
CS_UNLOCK(drvdata->base);
502+
503+
tgu_writel(drvdata, 0, TGU_CONTROL);
504+
505+
if (drvdata->value_table->priority)
506+
memset(drvdata->value_table->priority, 0,
507+
MAX_PRIORITY * drvdata->max_step *
508+
drvdata->max_reg * sizeof(unsigned int));
509+
510+
if (drvdata->value_table->condition_decode)
511+
memset(drvdata->value_table->condition_decode, 0,
512+
drvdata->max_condition_decode * drvdata->max_step *
513+
sizeof(unsigned int));
514+
515+
/* Initialize all condition registers to NOT(value=0x1000000) */
516+
for (i = 0; i < drvdata->max_step; i++) {
517+
for (j = 0; j < drvdata->max_condition_decode; j++) {
518+
drvdata->value_table
519+
->condition_decode[calculate_array_location(
520+
drvdata, i, TGU_CONDITION_DECODE, j)] =
521+
0x1000000;
522+
}
523+
}
524+
525+
if (drvdata->value_table->condition_select)
526+
memset(drvdata->value_table->condition_select, 0,
527+
drvdata->max_condition_select * drvdata->max_step *
528+
sizeof(unsigned int));
529+
530+
if (drvdata->value_table->timer)
531+
memset(drvdata->value_table->timer, 0,
532+
(drvdata->max_step) *
533+
(drvdata->max_timer) *
534+
sizeof(unsigned int));
535+
536+
if (drvdata->value_table->counter)
537+
memset(drvdata->value_table->counter, 0,
538+
(drvdata->max_step) *
539+
(drvdata->max_counter) *
540+
sizeof(unsigned int));
541+
542+
dev_dbg(dev, "Coresight-TGU reset complete\n");
543+
544+
CS_LOCK(drvdata->base);
545+
546+
drvdata->enable = false;
547+
spin_unlock(&drvdata->spinlock);
548+
pm_runtime_put(drvdata->dev);
549+
550+
return size;
551+
}
552+
static DEVICE_ATTR_WO(reset_tgu);
553+
480554
static const struct coresight_ops_helper tgu_helper_ops = {
481555
.enable = tgu_enable,
482556
.disable = tgu_disable,
@@ -488,6 +562,7 @@ static const struct coresight_ops tgu_ops = {
488562

489563
static struct attribute *tgu_common_attrs[] = {
490564
&dev_attr_enable_tgu.attr,
565+
&dev_attr_reset_tgu.attr,
491566
NULL,
492567
};
493568

0 commit comments

Comments
 (0)