Skip to content

Commit 37fde7d

Browse files
Songwei Chaijiegan0107
authored andcommitted
FROMLIST: coresight-tgu: add support to configure next action
Add "select" node for each step to determine if another step is taken, trigger(s) are generated, counters/timers incremented/decremented, etc. Link: https://lore.kernel.org/all/20250423-tgu_patch-v5-5-3b52c105cc63@quicinc.com/ Signed-off-by: Songwei Chai <quic_songchai@quicinc.com>
1 parent ae78def commit 37fde7d

3 files changed

Lines changed: 95 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ Date: February 2025
2020
KernelVersion 6.15
2121
Contact: Jinlong Mao (QUIC) <quic_jinlmao@quicinc.com>, Sam Chai (QUIC) <quic_songchai@quicinc.com>
2222
Description:
23-
(RW) Set/Get the decode mode with specific step for TGU.
23+
(RW) Set/Get the decode mode with specific step for TGU.
24+
25+
What: /sys/bus/coresight/devices/<tgu-name>/step[0:7]_condition_select/reg[0:3]
26+
Date: February 2025
27+
KernelVersion 6.15
28+
Contact: Jinlong Mao (QUIC) <quic_jinlmao@quicinc.com>, Sam Chai (QUIC) <quic_songchai@quicinc.com>
29+
Description:
30+
(RW) Set/Get the next action with specific step for TGU.

drivers/hwtracing/coresight/coresight-tgu.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ static int calculate_array_location(struct tgu_drvdata *drvdata,
3636
ret = step_index * (drvdata->max_condition_decode) +
3737
reg_index;
3838
break;
39+
case TGU_CONDITION_SELECT:
40+
ret = step_index * (drvdata->max_condition_select) + reg_index;
41+
break;
3942
default:
4043
break;
4144
}
@@ -81,6 +84,12 @@ static ssize_t tgu_dataset_show(struct device *dev,
8184
drvdata, tgu_attr->step_index,
8285
tgu_attr->operation_index,
8386
tgu_attr->reg_num)]);
87+
case TGU_CONDITION_SELECT:
88+
return sysfs_emit(buf, "0x%x\n",
89+
drvdata->value_table->condition_select[calculate_array_location(
90+
drvdata, tgu_attr->step_index,
91+
tgu_attr->operation_index,
92+
tgu_attr->reg_num)]);
8493
default:
8594
break;
8695
}
@@ -127,6 +136,13 @@ static ssize_t tgu_dataset_store(struct device *dev,
127136
tgu_attr->reg_num)] = val;
128137
ret = size;
129138
break;
139+
case TGU_CONDITION_SELECT:
140+
tgu_drvdata->value_table->condition_select[calculate_array_location(
141+
tgu_drvdata, tgu_attr->step_index,
142+
tgu_attr->operation_index,
143+
tgu_attr->reg_num)] = val;
144+
ret = size;
145+
break;
130146
default:
131147
break;
132148
}
@@ -162,6 +178,16 @@ static umode_t tgu_node_visible(struct kobject *kobject,
162178
attr->mode :
163179
0;
164180
break;
181+
case TGU_CONDITION_SELECT:
182+
/* 'default' register is at the end of 'select' region */
183+
if (tgu_attr->reg_num ==
184+
drvdata->max_condition_select - 1)
185+
attr->name = "default";
186+
ret = (tgu_attr->reg_num <
187+
drvdata->max_condition_select) ?
188+
attr->mode :
189+
0;
190+
break;
165191
default:
166192
break;
167193
}
@@ -206,6 +232,20 @@ static ssize_t tgu_write_all_hw_regs(struct tgu_drvdata *drvdata)
206232
CONDITION_DECODE_STEP(i, j));
207233
}
208234
}
235+
236+
for (i = 0; i < drvdata->max_step; i++) {
237+
for (j = 0; j < drvdata->max_condition_select; j++) {
238+
ret = check_array_location(drvdata, i, TGU_CONDITION_SELECT, j);
239+
if (ret == -EINVAL)
240+
goto exit;
241+
242+
tgu_writel(drvdata,
243+
drvdata->value_table->condition_select
244+
[calculate_array_location(drvdata, i,
245+
TGU_CONDITION_SELECT, j)],
246+
CONDITION_SELECT_STEP(i, j));
247+
}
248+
}
209249
/* Enable TGU to program the triggers */
210250
tgu_writel(drvdata, 1, TGU_CONTROL);
211251
exit:
@@ -250,6 +290,8 @@ static void tgu_set_conditions(struct tgu_drvdata *drvdata)
250290

251291
num_conditions = TGU_DEVID_CONDITIONS(devid);
252292
drvdata->max_condition_decode = num_conditions;
293+
/* select region has an additional 'default' register */
294+
drvdata->max_condition_select = num_conditions + 1;
253295
}
254296

255297
static int tgu_enable(struct coresight_device *csdev, enum cs_mode mode,
@@ -397,6 +439,14 @@ static const struct attribute_group *tgu_attr_groups[] = {
397439
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(5),
398440
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(6),
399441
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(7),
442+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(0),
443+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(1),
444+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(2),
445+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(3),
446+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(4),
447+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(5),
448+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(6),
449+
CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(7),
400450
NULL,
401451
};
402452

@@ -458,6 +508,15 @@ static int tgu_probe(struct amba_device *adev, const struct amba_id *id)
458508
if (!drvdata->value_table->condition_decode)
459509
return -ENOMEM;
460510

511+
drvdata->value_table->condition_select = devm_kzalloc(
512+
dev,
513+
drvdata->max_condition_select * drvdata->max_step *
514+
sizeof(*(drvdata->value_table->condition_select)),
515+
GFP_KERNEL);
516+
517+
if (!drvdata->value_table->condition_select)
518+
return -ENOMEM;
519+
461520
drvdata->enable = false;
462521
desc.type = CORESIGHT_DEV_TYPE_HELPER;
463522
desc.pdata = adev->dev.platform_data;

drivers/hwtracing/coresight/coresight-tgu.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define STEP_OFFSET 0x1D8
5151
#define PRIORITY_START_OFFSET 0x0074
5252
#define CONDITION_DECODE_OFFSET 0x0050
53+
#define CONDITION_SELECT_OFFSET 0x0060
5354
#define PRIORITY_OFFSET 0x60
5455
#define REG_OFFSET 0x4
5556

@@ -61,6 +62,9 @@
6162
#define CONDITION_DECODE_STEP(step, decode) \
6263
(CONDITION_DECODE_OFFSET + REG_OFFSET * decode + STEP_OFFSET * step)
6364

65+
#define CONDITION_SELECT_STEP(step, select) \
66+
(CONDITION_SELECT_OFFSET + REG_OFFSET * select + STEP_OFFSET * step)
67+
6468
#define tgu_dataset_rw(name, step_index, type, reg_num) \
6569
(&((struct tgu_attribute[]){ { \
6670
__ATTR(name, 0644, tgu_dataset_show, tgu_dataset_store), \
@@ -76,6 +80,9 @@
7680
#define STEP_DECODE(step_index, reg_num) \
7781
tgu_dataset_rw(reg##reg_num, step_index, TGU_CONDITION_DECODE, reg_num)
7882

83+
#define STEP_SELECT(step_index, reg_num) \
84+
tgu_dataset_rw(reg##reg_num, step_index, TGU_CONDITION_SELECT, reg_num)
85+
7986
#define STEP_PRIORITY_LIST(step_index, priority) \
8087
{STEP_PRIORITY(step_index, 0, priority), \
8188
STEP_PRIORITY(step_index, 1, priority), \
@@ -106,6 +113,15 @@
106113
NULL \
107114
}
108115

116+
#define STEP_SELECT_LIST(n) \
117+
{STEP_SELECT(n, 0), \
118+
STEP_SELECT(n, 1), \
119+
STEP_SELECT(n, 2), \
120+
STEP_SELECT(n, 3), \
121+
STEP_SELECT(n, 4), \
122+
NULL \
123+
}
124+
109125
#define PRIORITY_ATTRIBUTE_GROUP_INIT(step, priority)\
110126
(&(const struct attribute_group){\
111127
.attrs = (struct attribute*[])STEP_PRIORITY_LIST(step, priority),\
@@ -120,13 +136,20 @@
120136
.name = "step" #step "_condition_decode" \
121137
})
122138

139+
#define CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(step)\
140+
(&(const struct attribute_group){\
141+
.attrs = (struct attribute*[])STEP_SELECT_LIST(step),\
142+
.is_visible = tgu_node_visible,\
143+
.name = "step" #step "_condition_select" \
144+
})
145+
123146
enum operation_index {
124147
TGU_PRIORITY0,
125148
TGU_PRIORITY1,
126149
TGU_PRIORITY2,
127150
TGU_PRIORITY3,
128-
TGU_CONDITION_DECODE
129-
151+
TGU_CONDITION_DECODE,
152+
TGU_CONDITION_SELECT
130153
};
131154

132155
/* Maximum priority that TGU supports */
@@ -142,6 +165,7 @@ struct tgu_attribute {
142165
struct value_table {
143166
unsigned int *priority;
144167
unsigned int *condition_decode;
168+
unsigned int *condition_select;
145169
};
146170

147171
/**
@@ -155,6 +179,7 @@ struct value_table {
155179
* @max_reg: Maximum number of registers
156180
* @max_step: Maximum step size
157181
* @max_condition_decode: Maximum number of condition_decode
182+
* @max_condition_select: Maximum number of condition_select
158183
*
159184
* This structure defines the data associated with a TGU device,
160185
* including its base address, device pointers, clock, spinlock for
@@ -171,6 +196,7 @@ struct tgu_drvdata {
171196
int max_reg;
172197
int max_step;
173198
int max_condition_decode;
199+
int max_condition_select;
174200
};
175201

176202
#endif

0 commit comments

Comments
 (0)