[PATCH v17 07/10] qcom-tgu: Add support to configure next action
From: Songwei Chai
Date: Fri Nov 13 2026 - 05:15:32 EST
Add "select" node for each step to determine if another step is taken,
trigger(s) are generated, counters/timers incremented/decremented, etc.
Reviewed-by: Jie Gan <jie.gan@xxxxxxxxxxxxxxxx>
Signed-off-by: Songwei Chai <songwei.chai@xxxxxxxxxxxxxxxx>
---
.../ABI/testing/sysfs-bus-amba-devices-tgu | 16 +++
drivers/hwtracing/qcom/tgu.c | 97 ++++++++++++++++++-
drivers/hwtracing/qcom/tgu.h | 17 +++-
3 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu b/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu
index b94da9497243..f487881b7def 100644
--- a/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu
+++ b/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu
@@ -21,3 +21,19 @@ KernelVersion: 7.5
Contact: Jinlong Mao <jinlong.mao@xxxxxxxxxxxxxxxx>, Songwei Chai <songwei.chai@xxxxxxxxxxxxxxxx>
Description:
(RW) Set/Get the decode mode with specific step for TGU.
+
+What: /sys/bus/amba/devices/<tgu-name>/step[0:7]_condition_select/reg[0:3]
+Date: November 2026
+KernelVersion: 7.5
+Contact: Jinlong Mao <jinlong.mao@xxxxxxxxxxxxxxxx>, Songwei Chai <songwei.chai@xxxxxxxxxxxxxxxx>
+Description:
+ (RW) Set/Get the next action with specific step for TGU.
+
+What: /sys/bus/amba/devices/<tgu-name>/step[0:7]_condition_select/default
+Date: November 2026
+KernelVersion: 7.5
+Contact: Jinlong Mao <jinlong.mao@xxxxxxxxxxxxxxxx>, Songwei Chai <songwei.chai@xxxxxxxxxxxxxxxx>
+Description:
+ (RW) Set/Get the default next action for a specific step of the
+ TGU. This is the last register of the condition select region
+ and is applied when none of the numbered select registers match.
diff --git a/drivers/hwtracing/qcom/tgu.c b/drivers/hwtracing/qcom/tgu.c
index 72b98a96d7f2..6e66752a7b8d 100644
--- a/drivers/hwtracing/qcom/tgu.c
+++ b/drivers/hwtracing/qcom/tgu.c
@@ -23,6 +23,18 @@ struct tgu_attribute {
u8 reg_num;
};
+/*
+ * The last register of the 'condition select' region is the next-action
+ * ('default') register. Its position depends on the runtime value of
+ * num_condition_select, so it is exposed as a dedicated statically named
+ * "default" attribute carrying a sentinel reg number, rather than renaming
+ * a shared static attribute at runtime.
+ *
+ * Must fit in struct tgu_attribute.reg_num (u8) while staying outside every
+ * legitimate reg_num range (0..23 across priority/decode/select).
+ */
+#define TGU_SELECT_DEFAULT_REG 0xff
+
/*
* drvdata->priority is a flat [priority][step][reg] array.
*/
@@ -41,6 +53,16 @@ static int calculate_array_location(struct tgu_drvdata *drvdata,
case TGU_CONDITION_DECODE:
return step_index * (drvdata->num_condition_decode) +
reg_index;
+ case TGU_CONDITION_SELECT:
+ /*
+ * The 'default' register is the last one in the select region;
+ * it is exposed with a sentinel reg number, translated here to
+ * its actual position.
+ */
+ if (reg_index == TGU_SELECT_DEFAULT_REG)
+ reg_index = drvdata->num_condition_select - 1;
+ return step_index * (drvdata->num_condition_select) +
+ reg_index;
default:
break;
}
@@ -90,6 +112,9 @@ static ssize_t tgu_dataset_show(struct device *dev,
case TGU_CONDITION_DECODE:
return sysfs_emit(buf, "0x%x\n",
drvdata->condition_decode[index]);
+ case TGU_CONDITION_SELECT:
+ return sysfs_emit(buf, "0x%x\n",
+ drvdata->condition_select[index]);
default:
break;
}
@@ -131,6 +156,10 @@ static ssize_t tgu_dataset_store(struct device *dev,
tgu_drvdata->condition_decode[index] = val;
ret = size;
break;
+ case TGU_CONDITION_SELECT:
+ tgu_drvdata->condition_select[index] = val;
+ ret = size;
+ break;
default:
ret = -EINVAL;
break;
@@ -169,6 +198,17 @@ static umode_t tgu_node_visible(struct kobject *kobject,
if (tgu_attr->reg_num < drvdata->num_condition_decode)
return attr->mode;
break;
+ case TGU_CONDITION_SELECT:
+ /*
+ * The next-action ('default') register is exposed as its own
+ * statically named attribute and is always present. The numbered
+ * data registers occupy the positions before it.
+ */
+ if (tgu_attr->reg_num == TGU_SELECT_DEFAULT_REG)
+ return attr->mode;
+ if (tgu_attr->reg_num < drvdata->num_condition_select - 1)
+ return attr->mode;
+ break;
default:
break;
}
@@ -207,6 +247,18 @@ static ssize_t tgu_write_all_hw_regs(struct tgu_drvdata *drvdata)
drvdata->base + CONDITION_DECODE_STEP(i, j));
}
}
+
+ for (i = 0; i < drvdata->num_step; i++) {
+ for (j = 0; j < drvdata->num_condition_select; j++) {
+ index = check_array_location(drvdata, i,
+ TGU_CONDITION_SELECT, j);
+ if (index == -EINVAL)
+ goto exit;
+
+ writel(drvdata->condition_select[index],
+ drvdata->base + CONDITION_SELECT_STEP(i, j));
+ }
+ }
/* Enable TGU to program the triggers */
writel(1, drvdata->base + TGU_CONTROL);
exit:
@@ -216,7 +268,8 @@ static ssize_t tgu_write_all_hw_regs(struct tgu_drvdata *drvdata)
static void tgu_set_dev_caps(struct tgu_drvdata *drvdata)
{
- int num_sense_input, num_reg, num_step, num_condition_decode;
+ int num_sense_input, num_reg, num_step;
+ int num_condition_decode, num_condition_select;
u32 devid;
devid = readl(drvdata->base + CORESIGHT_DEVID);
@@ -254,6 +307,17 @@ static void tgu_set_dev_caps(struct tgu_drvdata *drvdata)
num_condition_decode = TGU_MAX_CONDITION_DECODE;
}
drvdata->num_condition_decode = num_condition_decode;
+
+ /* The select region has an additional 'default' register. */
+ num_condition_select = TGU_DEVID_CONDITIONS(devid) + 1;
+
+ if (num_condition_select > TGU_MAX_CONDITION_SELECT) {
+ dev_warn(drvdata->dev,
+ "DEVID reports %d condition select regs, clamping to %d\n",
+ num_condition_select, TGU_MAX_CONDITION_SELECT);
+ num_condition_select = TGU_MAX_CONDITION_SELECT;
+ }
+ drvdata->num_condition_select = num_condition_select;
}
static int tgu_enable(struct tgu_drvdata *drvdata)
@@ -409,6 +473,29 @@ static const struct attribute_group tgu_common_grp = {
.name = "step" #step "_condition_decode" \
})
+#define STEP_SELECT(step_index, reg_num) \
+ tgu_dataset_rw(reg##reg_num, step_index, TGU_CONDITION_SELECT, reg_num)
+
+#define STEP_SELECT_DEFAULT(step_index) \
+ tgu_dataset_rw(default, step_index, TGU_CONDITION_SELECT, \
+ TGU_SELECT_DEFAULT_REG)
+
+#define STEP_SELECT_LIST(step_index) \
+ {STEP_SELECT(step_index, 0), \
+ STEP_SELECT(step_index, 1), \
+ STEP_SELECT(step_index, 2), \
+ STEP_SELECT(step_index, 3), \
+ STEP_SELECT_DEFAULT(step_index), \
+ NULL \
+ }
+
+#define CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(step)\
+ (&(const struct attribute_group){\
+ .attrs = (struct attribute*[])STEP_SELECT_LIST(step),\
+ .is_visible = tgu_node_visible,\
+ .name = "step" #step "_condition_select" \
+ })
+
static const struct attribute_group *tgu_attr_groups[] = {
&tgu_common_grp,
PRIORITY_ATTRIBUTE_GROUP_INIT(0, 0),
@@ -451,6 +538,14 @@ static const struct attribute_group *tgu_attr_groups[] = {
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(5),
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(6),
CONDITION_DECODE_ATTRIBUTE_GROUP_INIT(7),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(0),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(1),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(2),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(3),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(4),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(5),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(6),
+ CONDITION_SELECT_ATTRIBUTE_GROUP_INIT(7),
NULL,
};
diff --git a/drivers/hwtracing/qcom/tgu.h b/drivers/hwtracing/qcom/tgu.h
index 7d88ad8e730f..27eb1f81effa 100644
--- a/drivers/hwtracing/qcom/tgu.h
+++ b/drivers/hwtracing/qcom/tgu.h
@@ -46,6 +46,7 @@
#define STEP_SIZE 0x1D8
#define PRIORITY0_OFFSET 0x0074
#define CONDITION_DECODE_OFFSET 0x0050
+#define CONDITION_SELECT_OFFSET 0x0060
#define PRIORITY_STRIDE 0x0060
#define REG_SIZE 0x4
@@ -57,6 +58,8 @@
* TGU_MAX_STEPS matches the static step0..step7 sysfs tables.
* TGU_MAX_PRIORITY_REGS matches the static reg0..reg23 sysfs tables.
* TGU_MAX_CONDITION_DECODE decode region 0x50..0x5F holds 4 u32 registers
+ * TGU_MAX_CONDITION_SELECT select region 0x60..0x73 holds 5 u32 registers
+ * (the last one being the 'default' next-action)
*
* Each priority level's block spans a full PRIORITY_STRIDE (0x60 bytes),
* i.e. PRIORITY_STRIDE / REG_SIZE = 24 registers, all of them implemented.
@@ -65,6 +68,7 @@
#define TGU_MAX_STEPS 8
#define TGU_MAX_PRIORITY_REGS 24
#define TGU_MAX_CONDITION_DECODE 4
+#define TGU_MAX_CONDITION_SELECT 5
/* Maximum priority that TGU supports */
#define MAX_PRIORITY 4
@@ -72,7 +76,8 @@
/*
* Values for struct tgu_attribute.operation_index: TGU_PRIORITY0..
* TGU_PRIORITY3 select a priority level, TGU_CONDITION_DECODE selects the
- * condition decode registers instead.
+ * condition decode registers, and TGU_CONDITION_SELECT selects the
+ * condition select registers.
*/
enum operation_index {
TGU_PRIORITY0,
@@ -80,6 +85,7 @@ enum operation_index {
TGU_PRIORITY2,
TGU_PRIORITY3,
TGU_CONDITION_DECODE,
+ TGU_CONDITION_SELECT,
};
/* Calculate compare step addresses */
@@ -90,6 +96,9 @@ enum operation_index {
#define CONDITION_DECODE_STEP(step, decode) \
(CONDITION_DECODE_OFFSET + REG_SIZE * decode + STEP_SIZE * step)
+#define CONDITION_SELECT_STEP(step, select) \
+ (CONDITION_SELECT_OFFSET + REG_SIZE * select + STEP_SIZE * step)
+
/*
* Neutral ('NOT') value for the condition decode registers. This is the
* driver's default so that, before userspace programs a real decode, an
@@ -109,9 +118,13 @@ enum operation_index {
* sysfs writes and flushed to hardware by tgu_enable()
* @condition_decode: Per-step, per-register decode values staged by sysfs
* writes and flushed to hardware by tgu_enable()
+ * @condition_select: Per-step, per-register select values (including the
+ * trailing 'default' next-action register) staged by
+ * sysfs writes and flushed to hardware by tgu_enable()
* @num_reg: Number of priority registers implemented per priority level
* @num_step: Number of steps implemented
* @num_condition_decode: Maximum number of condition_decode
+ * @num_condition_select: Maximum number of condition_select
*
* This structure defines the data associated with a TGU device,
* including its base address, device pointer, the lock serialising
@@ -124,9 +137,11 @@ struct tgu_drvdata {
bool enabled;
unsigned int priority[TGU_MAX_STEPS * MAX_PRIORITY * TGU_MAX_PRIORITY_REGS];
unsigned int condition_decode[TGU_MAX_STEPS * TGU_MAX_CONDITION_DECODE];
+ unsigned int condition_select[TGU_MAX_STEPS * TGU_MAX_CONDITION_SELECT];
int num_reg;
int num_step;
int num_condition_decode;
+ int num_condition_select;
};
#endif
--
2.34.1