Skip to content

Commit c19faf5

Browse files
AristoChenjenswi-linaro
authored andcommitted
tee: optee: store OS revision for TEE core
Collect OP-TEE OS revision from secure world for both SMC and FF-A ABIs, store it in the OP-TEE driver, and expose it through the generic get_tee_revision() callback. Signed-off-by: Aristo Chen <aristo.chen@canonical.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
1 parent 241bdf7 commit c19faf5

4 files changed

Lines changed: 94 additions & 17 deletions

File tree

drivers/tee/optee/core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ int optee_set_dma_mask(struct optee *optee, u_int pa_width)
6363
return dma_coerce_mask_and_coherent(&optee->teedev->dev, mask);
6464
}
6565

66+
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len)
67+
{
68+
struct optee *optee = tee_get_drvdata(teedev);
69+
u64 build_id;
70+
71+
if (!optee)
72+
return -ENODEV;
73+
if (!buf || !len)
74+
return -EINVAL;
75+
76+
build_id = optee->revision.os_build_id;
77+
if (build_id)
78+
scnprintf(buf, len, "%u.%u (%016llx)",
79+
optee->revision.os_major,
80+
optee->revision.os_minor,
81+
(unsigned long long)build_id);
82+
else
83+
scnprintf(buf, len, "%u.%u", optee->revision.os_major,
84+
optee->revision.os_minor);
85+
86+
return 0;
87+
}
88+
6689
static void optee_bus_scan(struct work_struct *work)
6790
{
6891
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));

drivers/tee/optee/ffa_abi.c

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,39 @@ static int optee_ffa_reclaim_protmem(struct optee *optee,
775775
* with a matching configuration.
776776
*/
777777

778+
static bool optee_ffa_get_os_revision(struct ffa_device *ffa_dev,
779+
const struct ffa_ops *ops,
780+
struct optee_revision *revision)
781+
{
782+
const struct ffa_msg_ops *msg_ops = ops->msg_ops;
783+
struct ffa_send_direct_data data = {
784+
.data0 = OPTEE_FFA_GET_OS_VERSION,
785+
};
786+
int rc;
787+
788+
msg_ops->mode_32bit_set(ffa_dev);
789+
790+
rc = msg_ops->sync_send_receive(ffa_dev, &data);
791+
if (rc) {
792+
pr_err("Unexpected error %d\n", rc);
793+
return false;
794+
}
795+
796+
if (revision) {
797+
revision->os_major = data.data0;
798+
revision->os_minor = data.data1;
799+
revision->os_build_id = data.data2;
800+
}
801+
802+
if (data.data2)
803+
pr_info("revision %lu.%lu (%08lx)",
804+
data.data0, data.data1, data.data2);
805+
else
806+
pr_info("revision %lu.%lu", data.data0, data.data1);
807+
808+
return true;
809+
}
810+
778811
static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
779812
const struct ffa_ops *ops)
780813
{
@@ -798,20 +831,6 @@ static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
798831
return false;
799832
}
800833

801-
data = (struct ffa_send_direct_data){
802-
.data0 = OPTEE_FFA_GET_OS_VERSION,
803-
};
804-
rc = msg_ops->sync_send_receive(ffa_dev, &data);
805-
if (rc) {
806-
pr_err("Unexpected error %d\n", rc);
807-
return false;
808-
}
809-
if (data.data2)
810-
pr_info("revision %lu.%lu (%08lx)",
811-
data.data0, data.data1, data.data2);
812-
else
813-
pr_info("revision %lu.%lu", data.data0, data.data1);
814-
815834
return true;
816835
}
817836

@@ -900,6 +919,7 @@ static int optee_ffa_open(struct tee_context *ctx)
900919

901920
static const struct tee_driver_ops optee_ffa_clnt_ops = {
902921
.get_version = optee_ffa_get_version,
922+
.get_tee_revision = optee_get_revision,
903923
.open = optee_ffa_open,
904924
.release = optee_release,
905925
.open_session = optee_open_session,
@@ -918,6 +938,7 @@ static const struct tee_desc optee_ffa_clnt_desc = {
918938

919939
static const struct tee_driver_ops optee_ffa_supp_ops = {
920940
.get_version = optee_ffa_get_version,
941+
.get_tee_revision = optee_get_revision,
921942
.open = optee_ffa_open,
922943
.release = optee_release_supp,
923944
.supp_recv = optee_supp_recv,
@@ -1060,6 +1081,11 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
10601081
if (!optee)
10611082
return -ENOMEM;
10621083

1084+
if (!optee_ffa_get_os_revision(ffa_dev, ffa_ops, &optee->revision)) {
1085+
rc = -EINVAL;
1086+
goto err_free_optee;
1087+
}
1088+
10631089
pool = optee_ffa_shm_pool_alloc_pages();
10641090
if (IS_ERR(pool)) {
10651091
rc = PTR_ERR(pool);

drivers/tee/optee/optee_private.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ struct optee_ffa {
171171

172172
struct optee;
173173

174+
/**
175+
* struct optee_revision - OP-TEE OS revision reported by secure world
176+
* @os_major: OP-TEE OS major version
177+
* @os_minor: OP-TEE OS minor version
178+
* @os_build_id: OP-TEE OS build identifier (0 if unspecified)
179+
*
180+
* Values come from OPTEE_SMC_CALL_GET_OS_REVISION (SMC ABI) or
181+
* OPTEE_FFA_GET_OS_VERSION (FF-A ABI); this is the trusted OS revision, not an
182+
* FF-A ABI version.
183+
*/
184+
struct optee_revision {
185+
u32 os_major;
186+
u32 os_minor;
187+
u64 os_build_id;
188+
};
189+
190+
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len);
191+
174192
/**
175193
* struct optee_ops - OP-TEE driver internal operations
176194
* @do_call_with_arg: enters OP-TEE in secure world
@@ -249,6 +267,7 @@ struct optee {
249267
bool in_kernel_rpmb_routing;
250268
struct work_struct scan_bus_work;
251269
struct work_struct rpmb_scan_bus_work;
270+
struct optee_revision revision;
252271
};
253272

254273
struct optee_session {

drivers/tee/optee/smc_abi.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ static int optee_smc_open(struct tee_context *ctx)
12421242

12431243
static const struct tee_driver_ops optee_clnt_ops = {
12441244
.get_version = optee_get_version,
1245+
.get_tee_revision = optee_get_revision,
12451246
.open = optee_smc_open,
12461247
.release = optee_release,
12471248
.open_session = optee_open_session,
@@ -1261,6 +1262,7 @@ static const struct tee_desc optee_clnt_desc = {
12611262

12621263
static const struct tee_driver_ops optee_supp_ops = {
12631264
.get_version = optee_get_version,
1265+
.get_tee_revision = optee_get_revision,
12641266
.open = optee_smc_open,
12651267
.release = optee_release_supp,
12661268
.supp_recv = optee_supp_recv,
@@ -1323,7 +1325,8 @@ static bool optee_msg_api_uid_is_optee_image_load(optee_invoke_fn *invoke_fn)
13231325
}
13241326
#endif
13251327

1326-
static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
1328+
static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn,
1329+
struct optee_revision *revision)
13271330
{
13281331
union {
13291332
struct arm_smccc_res smccc;
@@ -1337,6 +1340,12 @@ static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
13371340
invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0,
13381341
&res.smccc);
13391342

1343+
if (revision) {
1344+
revision->os_major = res.result.major;
1345+
revision->os_minor = res.result.minor;
1346+
revision->os_build_id = res.result.build_id;
1347+
}
1348+
13401349
if (res.result.build_id)
13411350
pr_info("revision %lu.%lu (%0*lx)", res.result.major,
13421351
res.result.minor, (int)sizeof(res.result.build_id) * 2,
@@ -1745,8 +1754,6 @@ static int optee_probe(struct platform_device *pdev)
17451754
return -EINVAL;
17461755
}
17471756

1748-
optee_msg_get_os_revision(invoke_fn);
1749-
17501757
if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
17511758
pr_warn("api revision mismatch\n");
17521759
return -EINVAL;
@@ -1815,6 +1822,8 @@ static int optee_probe(struct platform_device *pdev)
18151822
goto err_free_shm_pool;
18161823
}
18171824

1825+
optee_msg_get_os_revision(invoke_fn, &optee->revision);
1826+
18181827
optee->ops = &optee_ops;
18191828
optee->smc.invoke_fn = invoke_fn;
18201829
optee->smc.sec_caps = sec_caps;

0 commit comments

Comments
 (0)