Skip to content

Commit 241bdf7

Browse files
AristoChenjenswi-linaro
authored andcommitted
tee: add revision sysfs attribute
Add a generic TEE revision sysfs attribute backed by a new optional get_tee_revision() callback. The revision string is diagnostic-only and must not be used to infer feature support. Signed-off-by: Aristo Chen <aristo.chen@canonical.com> Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
1 parent 8f0b4cc commit 241bdf7

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

Documentation/ABI/testing/sysfs-class-tee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ Description:
1313
space if the variable is absent. The primary purpose
1414
of this variable is to let systemd know whether
1515
tee-supplicant is needed in the early boot with initramfs.
16+
17+
What: /sys/class/tee/tee{,priv}X/revision
18+
Date: Jan 2026
19+
KernelVersion: 6.19
20+
Contact: op-tee@lists.trustedfirmware.org
21+
Description:
22+
Read-only revision string reported by the TEE driver. This is
23+
for diagnostics only and must not be used to infer feature
24+
support. Use TEE_IOC_VERSION for capability and compatibility
25+
checks.

drivers/tee/tee_core.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,56 @@ static struct attribute *tee_dev_attrs[] = {
11461146
NULL
11471147
};
11481148

1149-
ATTRIBUTE_GROUPS(tee_dev);
1149+
static const struct attribute_group tee_dev_group = {
1150+
.attrs = tee_dev_attrs,
1151+
};
1152+
1153+
static ssize_t revision_show(struct device *dev,
1154+
struct device_attribute *attr, char *buf)
1155+
{
1156+
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
1157+
char version[TEE_REVISION_STR_SIZE];
1158+
int ret;
1159+
1160+
if (!teedev->desc->ops->get_tee_revision)
1161+
return -ENODEV;
1162+
1163+
ret = teedev->desc->ops->get_tee_revision(teedev, version,
1164+
sizeof(version));
1165+
if (ret)
1166+
return ret;
1167+
1168+
return sysfs_emit(buf, "%s\n", version);
1169+
}
1170+
static DEVICE_ATTR_RO(revision);
1171+
1172+
static struct attribute *tee_revision_attrs[] = {
1173+
&dev_attr_revision.attr,
1174+
NULL
1175+
};
1176+
1177+
static umode_t tee_revision_attr_is_visible(struct kobject *kobj,
1178+
struct attribute *attr, int n)
1179+
{
1180+
struct device *dev = kobj_to_dev(kobj);
1181+
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
1182+
1183+
if (teedev->desc->ops->get_tee_revision)
1184+
return attr->mode;
1185+
1186+
return 0;
1187+
}
1188+
1189+
static const struct attribute_group tee_revision_group = {
1190+
.attrs = tee_revision_attrs,
1191+
.is_visible = tee_revision_attr_is_visible,
1192+
};
1193+
1194+
static const struct attribute_group *tee_dev_groups[] = {
1195+
&tee_dev_group,
1196+
&tee_revision_group,
1197+
NULL
1198+
};
11501199

11511200
static const struct class tee_class = {
11521201
.name = "tee",

include/linux/tee_core.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ struct tee_device {
7676
/**
7777
* struct tee_driver_ops - driver operations vtable
7878
* @get_version: returns version of driver
79+
* @get_tee_revision: returns revision string (diagnostic only);
80+
* do not infer feature support from this, use
81+
* TEE_IOC_VERSION instead
7982
* @open: called for a context when the device file is opened
8083
* @close_context: called when the device file is closed
8184
* @release: called to release the context
@@ -95,9 +98,12 @@ struct tee_device {
9598
* client closes the device file, even if there are existing references to the
9699
* context. The TEE driver can use @close_context to start cleaning up.
97100
*/
101+
98102
struct tee_driver_ops {
99103
void (*get_version)(struct tee_device *teedev,
100104
struct tee_ioctl_version_data *vers);
105+
int (*get_tee_revision)(struct tee_device *teedev,
106+
char *buf, size_t len);
101107
int (*open)(struct tee_context *ctx);
102108
void (*close_context)(struct tee_context *ctx);
103109
void (*release)(struct tee_context *ctx);
@@ -123,6 +129,9 @@ struct tee_driver_ops {
123129
int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm);
124130
};
125131

132+
/* Size for TEE revision string buffer used by get_tee_revision(). */
133+
#define TEE_REVISION_STR_SIZE 128
134+
126135
/**
127136
* struct tee_desc - Describes the TEE driver to the subsystem
128137
* @name: name of driver

0 commit comments

Comments
 (0)