We currently only report an implementation ID when doing devinfo on the
tee device. Improve upon that by translating the ID to a string and
printing the OP-TEE revision if possible.

Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org>
---
v1 -> v2:
  - use IS_ERR_OR_NULL to guard param getting
  - use new get_param_value helper
---
 drivers/tee/optee/smc_abi.c | 17 ++++++++++++-----
 drivers/tee/tee_core.c      | 20 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index aab8ebb186ed..56af3b1b2b29 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -549,8 +549,10 @@ static bool optee_msg_api_uid_is_optee_api(optee_invoke_fn 
*invoke_fn)
        return false;
 }
 
-static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
+static void optee_msg_get_os_revision(struct device *dev,
+                                     optee_invoke_fn *invoke_fn)
 {
+       struct param_d *param;
        union {
                struct arm_smccc_res smccc;
                struct optee_smc_call_get_os_revision_result result;
@@ -564,10 +566,15 @@ static void optee_msg_get_os_revision(optee_invoke_fn 
*invoke_fn)
                  &res.smccc);
 
        if (res.result.build_id)
-               pr_info("revision %lu.%lu (%08lx)\n", res.result.major,
-                       res.result.minor, res.result.build_id);
+               param = dev_add_param_fixed(dev, "revision", "%lu.%lu (%08lx)",
+                                           res.result.major, res.result.minor,
+                                           res.result.build_id);
        else
-               pr_info("revision %lu.%lu\n", res.result.major, 
res.result.minor);
+               param = dev_add_param_fixed(dev, "revision", "%lu.%lu",
+                                   res.result.major, res.result.minor);
+
+       if (!IS_ERR_OR_NULL(param))
+               pr_info("revision %s\n", get_param_value(param));
 }
 
 static bool optee_msg_api_revision_is_compatible(optee_invoke_fn *invoke_fn)
@@ -662,7 +669,7 @@ static int optee_probe(struct device *dev)
                return -EINVAL;
        }
 
-       optee_msg_get_os_revision(invoke_fn);
+       optee_msg_get_os_revision(dev, invoke_fn);
 
        if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
                pr_warn("api revision mismatch\n");
diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
index 653b04ff06af..a4bb9af46933 100644
--- a/drivers/tee/tee_core.c
+++ b/drivers/tee/tee_core.c
@@ -487,9 +487,27 @@ static void tee_devinfo(struct device *dev)
 {
        struct tee_device *teedev = dev->priv;
        struct tee_ioctl_version_data vers;
+       const char *impl = NULL, *rev;
 
        teedev->desc->ops->get_version(teedev, &vers);
-       printf("Implementation ID: %d\n", vers.impl_id);
+
+       switch (vers.impl_id) {
+       case TEE_IMPL_ID_OPTEE:
+               impl = "optee";
+               break;
+       case TEE_IMPL_ID_AMDTEE:
+               impl = "amdtee";
+               break;
+       }
+
+       printf("Implementation ID: %d%s%s%s\n", vers.impl_id,
+              impl ? " ( " : "", impl, impl ? ")" : "");
+       if (!dev->parent)
+               return;
+
+       rev = dev_get_param(dev->parent, "revision");
+       if (rev)
+               printf("Revision: %s\n", rev);
 }
 
 /**
-- 
2.39.5


Reply via email to