imx: add imx8qm/imx8qx SRTC SIP runtime service support
authorAnson Huang <Anson.Huang@nxp.com>
Tue, 15 Jan 2019 02:34:04 +0000 (10:34 +0800)
committerAnson Huang <Anson.Huang@nxp.com>
Thu, 17 Jan 2019 02:49:48 +0000 (10:49 +0800)
On i.MX8QM/i.MX8QX with system controller inside, the SRTC is
managed by SCFW(system controller firmware) and some functions
like setting SRTC's time etc. can ONLY be requested from secure
world, so SIP runtime service is needed for such kind of operations,
this patch adds SRTC SIP runtime service support for i.MX8QM and
i.MX8QX.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
plat/imx/common/imx_sip_handler.c [new file with mode: 0644]
plat/imx/common/imx_sip_svc.c [new file with mode: 0644]
plat/imx/common/include/imx_sip_svc.h [new file with mode: 0644]
plat/imx/imx8qm/platform.mk
plat/imx/imx8qx/platform.mk

diff --git a/plat/imx/common/imx_sip_handler.c b/plat/imx/common/imx_sip_handler.c
new file mode 100644 (file)
index 0000000..a414a44
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2019 NXP
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <std_svc.h>
+#include <platform_def.h>
+#include <common/debug.h>
+#include <common/runtime_svc.h>
+#include <imx_sip_svc.h>
+#include <sci/sci.h>
+
+static int imx_srtc_set_time(uint32_t year_mon,
+                       unsigned long day_hour,
+                       unsigned long min_sec)
+{
+       return sc_timer_set_rtc_time(ipc_handle,
+               year_mon >> 16, year_mon & 0xffff,
+               day_hour >> 16, day_hour & 0xffff,
+               min_sec >> 16, min_sec & 0xffff);
+}
+
+int imx_srtc_handler(uint32_t smc_fid,
+                   void *handle,
+                   u_register_t x1,
+                   u_register_t x2,
+                   u_register_t x3,
+                   u_register_t x4)
+{
+       int ret;
+
+       switch (x1) {
+       case IMX_SIP_SRTC_SET_TIME:
+               ret = imx_srtc_set_time(x2, x3, x4);
+               break;
+       default:
+               ret = SMC_UNK;
+       }
+
+       SMC_RET1(handle, ret);
+}
diff --git a/plat/imx/common/imx_sip_svc.c b/plat/imx/common/imx_sip_svc.c
new file mode 100644 (file)
index 0000000..23ff0bb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdint.h>
+#include <common/debug.h>
+#include <common/runtime_svc.h>
+#include <lib/pmf/pmf.h>
+#include <tools_share/uuid.h>
+#include <imx_sip_svc.h>
+
+static int32_t imx_sip_setup(void)
+{
+       return 0;
+}
+
+static uintptr_t imx_sip_handler(unsigned int smc_fid,
+                       u_register_t x1,
+                       u_register_t x2,
+                       u_register_t x3,
+                       u_register_t x4,
+                       void *cookie,
+                       void *handle,
+                       u_register_t flags)
+{
+       switch (smc_fid) {
+#if (defined(PLAT_IMX8QM) || defined(PLAT_IMX8QX))
+       case  IMX_SIP_SRTC:
+               return imx_srtc_handler(smc_fid, handle, x1, x2, x3, x4);
+#endif
+       default:
+               WARN("Unimplemented i.MX SiP Service Call: 0x%x\n", smc_fid);
+               SMC_RET1(handle, SMC_UNK);
+               break;
+       }
+}
+
+/* Define a runtime service descriptor for fast SMC calls */
+DECLARE_RT_SVC(
+               imx_sip_svc,
+               OEN_SIP_START,
+               OEN_SIP_END,
+               SMC_TYPE_FAST,
+               imx_sip_setup,
+               imx_sip_handler
+);
diff --git a/plat/imx/common/include/imx_sip_svc.h b/plat/imx/common/include/imx_sip_svc.h
new file mode 100644 (file)
index 0000000..0d21f75
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __IMX_SIP_SVC_H__
+#define __IMX_SIP_SVC_H__
+
+/* SMC function IDs for SiP Service queries */
+#define IMX_SIP_SRTC                   0xC2000002
+#define IMX_SIP_SRTC_SET_TIME          0x00
+
+#if (defined(PLAT_IMX8QM) || defined(PLAT_IMX8QX))
+int imx_srtc_handler(uint32_t smc_fid, void *handle, u_register_t x1,
+                    u_register_t x2, u_register_t x3, u_register_t x4);
+#endif
+
+#endif /* __IMX_SIP_SVC_H__ */
index dc45e901d885950e8deb5c35b1dbcc9cdf0b0f58..9113d33eb8828e53540d2645af198b9d21c7bbfd 100644 (file)
@@ -22,6 +22,8 @@ BL31_SOURCES          +=      plat/imx/common/lpuart_console.S        \
                                plat/imx/imx8qm/imx8qm_psci.c           \
                                plat/imx/common/imx8_topology.c         \
                                plat/imx/common/imx8_psci.c             \
+                               plat/imx/common/imx_sip_svc.c           \
+                               plat/imx/common/imx_sip_handler.c       \
                                lib/xlat_tables/aarch64/xlat_tables.c           \
                                lib/xlat_tables/xlat_tables_common.c            \
                                lib/cpus/aarch64/cortex_a53.S                   \
index a831bf2f05f1181fc4b3b8ee63a38ca686917020..eeb1f34ed4955b23708ede07a3c87506aa9f7738 100644 (file)
@@ -21,6 +21,8 @@ BL31_SOURCES          +=      plat/imx/common/lpuart_console.S        \
                                plat/imx/imx8qx/imx8qx_psci.c           \
                                plat/imx/common/imx8_topology.c         \
                                plat/imx/common/imx8_psci.c             \
+                               plat/imx/common/imx_sip_svc.c           \
+                               plat/imx/common/imx_sip_handler.c       \
                                plat/common/plat_psci_common.c          \
                                lib/xlat_tables/xlat_tables_common.c    \
                                lib/xlat_tables/aarch64/xlat_tables.c   \