Skip to content

Commit a7e66ff

Browse files
committed
Merge tag 'tee-drv-misc-for-v4.17' of https://git.linaro.org:/people/jens.wiklander/linux-tee into next/drivers
Pull "Small fix and report OP-TEE revision information" from Jens Wiklander: * Adds one small fix correct max value of privileged device id allocation, this is only needed if there's more than TEE_NUM_DEVICES / 2 (16) tee drivers registered. One or two is a normal value. * Reports OP-TEE revision information (major, minro version and build id if available) * tag 'tee-drv-misc-for-v4.17' of https://git.linaro.org:/people/jens.wiklander/linux-tee: tee: optee: report OP-TEE revision information tee: optee: GET_OS_REVISION: document a2 as a build identifier tee: correct max value for id allocation
2 parents aa8f21a + 5c5f803 commit a7e66ff

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎drivers/tee/optee/core.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,27 @@ static bool optee_msg_api_uid_is_optee_api(optee_invoke_fn *invoke_fn)
356356
return false;
357357
}
358358

359+
static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
360+
{
361+
union {
362+
struct arm_smccc_res smccc;
363+
struct optee_smc_call_get_os_revision_result result;
364+
} res = {
365+
.result = {
366+
.build_id = 0
367+
}
368+
};
369+
370+
invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0,
371+
&res.smccc);
372+
373+
if (res.result.build_id)
374+
pr_info("revision %lu.%lu (%08lx)", res.result.major,
375+
res.result.minor, res.result.build_id);
376+
else
377+
pr_info("revision %lu.%lu", res.result.major, res.result.minor);
378+
}
379+
359380
static bool optee_msg_api_revision_is_compatible(optee_invoke_fn *invoke_fn)
360381
{
361382
union {
@@ -547,6 +568,8 @@ static struct optee *optee_probe(struct device_node *np)
547568
return ERR_PTR(-EINVAL);
548569
}
549570

571+
optee_msg_get_os_revision(invoke_fn);
572+
550573
if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
551574
pr_warn("api revision mismatch\n");
552575
return ERR_PTR(-EINVAL);

‎drivers/tee/optee/optee_smc.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,20 @@ struct optee_smc_calls_revision_result {
112112
* Trusted OS, not of the API.
113113
*
114114
* Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
115-
* described above.
115+
* described above. May optionally return a 32-bit build identifier in a2,
116+
* with zero meaning unspecified.
116117
*/
117118
#define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
118119
#define OPTEE_SMC_CALL_GET_OS_REVISION \
119120
OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
120121

122+
struct optee_smc_call_get_os_revision_result {
123+
unsigned long major;
124+
unsigned long minor;
125+
unsigned long build_id;
126+
unsigned long reserved1;
127+
};
128+
121129
/*
122130
* Call with struct optee_msg_arg as argument
123131
*

‎drivers/tee/tee_core.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
693693
{
694694
struct tee_device *teedev;
695695
void *ret;
696-
int rc;
696+
int rc, max_id;
697697
int offs = 0;
698698

699699
if (!teedesc || !teedesc->name || !teedesc->ops ||
@@ -707,16 +707,20 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
707707
goto err;
708708
}
709709

710-
if (teedesc->flags & TEE_DESC_PRIVILEGED)
710+
max_id = TEE_NUM_DEVICES / 2;
711+
712+
if (teedesc->flags & TEE_DESC_PRIVILEGED) {
711713
offs = TEE_NUM_DEVICES / 2;
714+
max_id = TEE_NUM_DEVICES;
715+
}
712716

713717
spin_lock(&driver_lock);
714-
teedev->id = find_next_zero_bit(dev_mask, TEE_NUM_DEVICES, offs);
715-
if (teedev->id < TEE_NUM_DEVICES)
718+
teedev->id = find_next_zero_bit(dev_mask, max_id, offs);
719+
if (teedev->id < max_id)
716720
set_bit(teedev->id, dev_mask);
717721
spin_unlock(&driver_lock);
718722

719-
if (teedev->id >= TEE_NUM_DEVICES) {
723+
if (teedev->id >= max_id) {
720724
ret = ERR_PTR(-ENOMEM);
721725
goto err;
722726
}

0 commit comments

Comments
 (0)