summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJi Luo <ji.luo@nxp.com>2019-07-18 14:18:14 +0800
committerJi Luo <ji.luo@nxp.com>2022-04-20 09:33:10 +0800
commit1f2477f5ba77c5c2d2b7db79bb4bc8ec7a129ed3 (patch)
tree4c795a2983bc947b4d3879e19a392440fcdebc14 /lib
parent8834497fef043ad5b91c59b771e83d48c4422d3a (diff)
MA-19082-2 imx8m: Use Trusty OS handle SNVS operation
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> (cherry picked from commit ea729b07661bf849cdbd6ca7c3f6c9948fd38dc7)
Diffstat (limited to 'lib')
-rw-r--r--lib/trusty/ql-tipc/Makefile1
-rw-r--r--lib/trusty/ql-tipc/arch/arm/trusty_dev.c8
-rw-r--r--lib/trusty/ql-tipc/imx_snvs.c53
-rw-r--r--lib/trusty/ql-tipc/libtipc.c12
4 files changed, 73 insertions, 1 deletions
diff --git a/lib/trusty/ql-tipc/Makefile b/lib/trusty/ql-tipc/Makefile
index 5ee616ba93..57b48223e2 100644
--- a/lib/trusty/ql-tipc/Makefile
+++ b/lib/trusty/ql-tipc/Makefile
@@ -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
diff --git a/lib/trusty/ql-tipc/arch/arm/trusty_dev.c b/lib/trusty/ql-tipc/arch/arm/trusty_dev.c
index bd9a5fbfb6..fd8f2f367e 100644
--- a/lib/trusty/ql-tipc/arch/arm/trusty_dev.c
+++ b/lib/trusty/ql-tipc/arch/arm/trusty_dev.c
@@ -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
index 0000000000..972cb427f3
--- /dev/null
+++ b/lib/trusty/ql-tipc/imx_snvs.c
@@ -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;
+
+}
diff --git a/lib/trusty/ql-tipc/libtipc.c b/lib/trusty/ql-tipc/libtipc.c
index f3bb3c8f70..d21b364c73 100644
--- a/lib/trusty/ql-tipc/libtipc.c
+++ b/lib/trusty/ql-tipc/libtipc.c
@@ -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