MA-19082-2 imx8m: Use Trusty OS handle SNVS operation
authorJi Luo <ji.luo@nxp.com>
Thu, 18 Jul 2019 06:18:14 +0000 (14:18 +0800)
committerJi Luo <ji.luo@nxp.com>
Wed, 26 May 2021 13:23:00 +0000 (21:23 +0800)
This patch added Trusty OS in u-boot to handle
some snvs related operation.

Change-Id: Iba2b9e12381ce537b40959f14e831accbdecba8f
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
Signed-off-by: Ji Luo <ji.luo@nxp.com>
include/trusty/imx_snvs.h [new file with mode: 0644]
include/trusty/libtipc.h
include/trusty/trusty_dev.h
lib/trusty/ql-tipc/Makefile
lib/trusty/ql-tipc/arch/arm/trusty_dev.c
lib/trusty/ql-tipc/imx_snvs.c [new file with mode: 0644]
lib/trusty/ql-tipc/libtipc.c

diff --git a/include/trusty/imx_snvs.h b/include/trusty/imx_snvs.h
new file mode 100644 (file)
index 0000000..e2e2405
--- /dev/null
@@ -0,0 +1,11 @@
+
+#ifndef _IMX_SNVS_H_
+#define _IMX_SNVS_H_
+#include <trusty/trusty_ipc.h>
+
+uint32_t trusty_snvs_read(uint32_t target);
+void trusty_snvs_write(uint32_t target, uint32_t value);
+void trusty_snvs_update_lpcr(uint32_t target, uint32_t enable);
+int imx_snvs_init(struct trusty_ipc_dev *dev);
+
+#endif
index 4f078bb..f06e9e9 100644 (file)
@@ -28,6 +28,7 @@
 #include <trusty/keymaster.h>
 #include <trusty/sysdeps.h>
 #include <trusty/hwcrypto.h>
+#include <trusty/imx_snvs.h>
 
 /*
  * Initialize TIPC library
index 27ae8cc..899c869 100644 (file)
@@ -79,4 +79,10 @@ int trusty_dev_exec_ipc(struct trusty_dev *dev, struct ns_mem_page_info *buf,
 int trusty_dev_shutdown_ipc(struct trusty_dev *dev,
                             struct ns_mem_page_info *buf, uint32_t buf_size);
 
+/*
+ * Export Trusty fastcall API
+ */
+int32_t trusty_simple_fast_call32(uint32_t smcnr,
+                                  uint32_t a0, uint32_t a1, uint32_t a2);
+
 #endif /* TRUSTY_TRUSTY_DEV_H_ */
index 5ee616b..57b4822 100644 (file)
@@ -41,6 +41,7 @@ obj-y += \
     $(QL_TIPC)/libtipc.o \
     $(QL_TIPC)/rpmb_proxy.o \
     $(QL_TIPC)/util.o \
+    $(QL_TIPC)/imx_snvs.o \
     sysdeps/sysdeps_uboot.o \
     sysdeps/storage_ops_uboot.o
 
index bd9a5fb..fd8f2f3 100644 (file)
@@ -83,6 +83,14 @@ static unsigned long smc(unsigned long r0,
     return _r0;
 }
 
+int32_t trusty_simple_fast_call32(uint32_t smcnr,
+                                  uint32_t a0, uint32_t a1, uint32_t a2)
+{
+    trusty_assert(SMC_IS_FASTCALL(smcnr));
+
+    return smc(smcnr, a0, a1, a2);
+}
+
 static int32_t trusty_fast_call32(struct trusty_dev *dev, uint32_t smcnr,
                                   uint32_t a0, uint32_t a1, uint32_t a2)
 {
diff --git a/lib/trusty/ql-tipc/imx_snvs.c b/lib/trusty/ql-tipc/imx_snvs.c
new file mode 100644 (file)
index 0000000..972cb42
--- /dev/null
@@ -0,0 +1,53 @@
+#include <trusty/trusty_ipc.h>
+#include <trusty/util.h>
+#include <trusty/imx_snvs.h>
+#include <trusty/trusty_dev.h>
+#include "arch/arm/smcall.h"
+
+#define SMC_ENTITY_SNVS_RTC 53
+#define SMC_SNVS_PROBE SMC_FASTCALL_NR(SMC_ENTITY_SNVS_RTC, 0)
+#define SMC_SNVS_REGS_OP SMC_FASTCALL_NR(SMC_ENTITY_SNVS_RTC, 1)
+#define SMC_SNVS_LPCR_OP SMC_FASTCALL_NR(SMC_ENTITY_SNVS_RTC, 2)
+
+#define OPT_READ 0x1
+#define OPT_WRITE 0x2
+
+static struct trusty_ipc_dev *_dev = NULL;
+
+uint32_t trusty_snvs_read(uint32_t target) {
+    if (!_dev) {
+        trusty_error("trusty imx snvs driver is not initialized!\n");
+       return 0;
+    }
+    return trusty_simple_fast_call32(SMC_SNVS_REGS_OP, target, OPT_READ, 0);
+}
+
+void trusty_snvs_write(uint32_t target, uint32_t value) {
+    if (!_dev) {
+        trusty_error("trusty imx snvs driver is not initialized!\n");
+       return;
+    }
+    trusty_simple_fast_call32(SMC_SNVS_REGS_OP, target, OPT_WRITE, value);
+}
+
+void trusty_snvs_update_lpcr(uint32_t target, uint32_t enable) {
+    if (!_dev) {
+        trusty_error("trusty imx snvs driver is not initialized!\n");
+       return;
+    }
+    trusty_simple_fast_call32(SMC_SNVS_LPCR_OP, target, enable, 0);
+}
+
+int imx_snvs_init(struct trusty_ipc_dev *dev)
+{
+    trusty_assert(dev);
+    int error;
+    error = trusty_simple_fast_call32(SMC_SNVS_PROBE, 0, 0, 0);
+    if (error < 0) {
+        trusty_error("trusty imx snvs driver initialize failed! error=%d\n", error);
+        return error;
+    }
+    _dev = dev;
+    return 0;
+
+}
index f3bb3c8..d21b364 100644 (file)
@@ -33,6 +33,7 @@
 #include <trusty/util.h>
 #include <hang.h>
 #include <env.h>
+#include <trusty/imx_snvs.h>
 
 #define LOCAL_LOG 0
 
@@ -138,7 +139,16 @@ int trusty_ipc_init(void)
     trusty_info("Initializing Trusty Hardware Crypto client\n");
     rc = hwcrypto_tipc_init(_ipc_dev);
     if (rc != 0) {
-        trusty_error("Initlializing Trusty Keymaster client failed (%d)\n", rc);
+        trusty_error("Initlializing Trusty hwcrypto client failed (%d)\n", rc);
+        return rc;
+    }
+#endif
+
+#ifdef CONFIG_IMX8M
+    trusty_info("Initializing Trusty SNVS driver\n");
+    rc = imx_snvs_init(_ipc_dev);
+    if (rc != 0) {
+        trusty_error("Initlializing Trusty SNVS driver failed (%d)\n", rc);
         return rc;
     }
 #endif