stm322mp1: add BSEC service
authorYann Gautier <yann.gautier@st.com>
Thu, 17 Jan 2019 13:53:24 +0000 (14:53 +0100)
committerYann Gautier <yann.gautier@st.com>
Fri, 18 Jan 2019 14:45:08 +0000 (15:45 +0100)
This service, called with SMC from Non secure world, allows access to
some configurations saved in OTP fuses.

Change-Id: I92ba5614b2cb4a03260119e2cf74f2cd626a3431
Signed-off-by: Yann Gautier <yann.gautier@st.com>
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Signed-off-by: Mathieu Belou <mathieu.belou@st.com>
Signed-off-by: Nicolas Le Bayon <nicolas.le.bayon@st.com>
plat/st/stm32mp1/include/stm32mp1_smc.h
plat/st/stm32mp1/services/bsec_svc.c [new file with mode: 0644]
plat/st/stm32mp1/services/bsec_svc.h [new file with mode: 0644]
plat/st/stm32mp1/services/stm32mp1_svc_setup.c
plat/st/stm32mp1/sp_min/sp_min-stm32mp1.mk
plat/st/stm32mp1/sp_min/sp_min_setup.c

index accd795ad45fc968d5f245ef4814e1e1528aec57..b87275839370d765cb349cba6692e3fccfa61b3e 100644 (file)
  * https://developer.arm.com/docs/den0028/latest
  */
 
+/* Secure Service access from Non-secure */
+
+/*
+ * STM32_SMC_BSEC call API
+ *
+ * Argument a0: (input) SMCC ID
+ *             (output) status return code
+ * Argument a1: (input) Service ID (STM32_SMC_BSEC_xxx)
+ * Argument a2: (input) OTP index
+ *             (output) OTP read value, if applicable
+ * Argument a3: (input) OTP value if applicable
+ */
+#define STM32_SMC_BSEC                 0x82001003
+
 /* SMC function IDs for SiP Service queries */
 #define STM32_SIP_SVC_CALL_COUNT       0x8200ff00
 #define STM32_SIP_SVC_UID              0x8200ff01
 #define STM32_SIP_SVC_VERSION_MINOR    0x1
 
 /* Number of STM32 SiP Calls implemented */
-#define STM32_COMMON_SIP_NUM_CALLS     3
+#define STM32_COMMON_SIP_NUM_CALLS     4
+
+/* Service for BSEC */
+#define STM32_SMC_READ_SHADOW          0x01
+#define STM32_SMC_PROG_OTP             0x02
+#define STM32_SMC_WRITE_SHADOW         0x03
+#define STM32_SMC_READ_OTP             0x04
 
 #endif /* STM32MP1_SMC_H */
diff --git a/plat/st/stm32mp1/services/bsec_svc.c b/plat/st/stm32mp1/services/bsec_svc.c
new file mode 100644 (file)
index 0000000..2a60e43
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016-2019, STMicroelectronics - All Rights Reserved
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <platform_def.h>
+
+#include <common/debug.h>
+#include <drivers/st/bsec.h>
+
+#include <stm32mp1_smc.h>
+
+#include "bsec_svc.h"
+
+uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3,
+                  uint32_t *ret_otp_value)
+{
+       uint32_t result;
+       uint32_t tmp_data = 0U;
+
+       switch (x1) {
+       case STM32_SMC_READ_SHADOW:
+               result = bsec_read_otp(ret_otp_value, x2);
+               break;
+       case STM32_SMC_PROG_OTP:
+               *ret_otp_value = 0U;
+               result = bsec_program_otp(x3, x2);
+               break;
+       case STM32_SMC_WRITE_SHADOW:
+               *ret_otp_value = 0;
+               result = bsec_write_otp(x3, x2);
+               break;
+       case STM32_SMC_READ_OTP:
+               *ret_otp_value = 0;
+               result = bsec_read_otp(&tmp_data, x2);
+               if (result != BSEC_OK) {
+                       break;
+               }
+
+               result = bsec_shadow_register(x2);
+               if (result != BSEC_OK) {
+                       break;
+               }
+
+               result = bsec_read_otp(ret_otp_value, x2);
+               if (result != BSEC_OK) {
+                       break;
+               }
+
+               result = bsec_write_otp(tmp_data, x2);
+               break;
+
+       default:
+               result = BSEC_ERROR;
+               break;
+       }
+
+       return result;
+}
diff --git a/plat/st/stm32mp1/services/bsec_svc.h b/plat/st/stm32mp1/services/bsec_svc.h
new file mode 100644 (file)
index 0000000..06752ef
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2016-2019, STMicroelectronics - All Rights Reserved
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef BSEC_SVC_H
+#define BSEC_SVC_H
+
+#include <stdint.h>
+
+/* version of this service */
+/* must be increase at each structure modification */
+#define BSEC_SERVICE_VERSION           0x01U
+
+uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3,
+                  uint32_t *ret_otp_value);
+
+#endif /* BSEC_SVC_H */
index dec2dad11dc5e8a69b76563e85816c19840366e4..72af9ff335b9081d1b24e20fdd827397a5f98b4f 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <stm32mp1_smc.h>
 
+#include "bsec_svc.h"
+
 /* STM32 SiP Service UUID */
 DEFINE_SVC_UUID2(stm32_sip_svc_uid,
                 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e,
@@ -58,6 +60,11 @@ static uintptr_t stm32mp1_svc_smc_handler(uint32_t smc_fid, u_register_t x1,
                ret2_enabled = true;
                break;
 
+       case STM32_SMC_BSEC:
+               ret1 = bsec_main(x1, x2, x3, &ret2);
+               ret2_enabled = true;
+               break;
+
        default:
                WARN("Unimplemented STM32MP1 Service Call: 0x%x\n", smc_fid);
                ret1 = SMC_UNK;
index f78e43d65b2286c034cf254096e1b805382cd587..4188cc58ae3d275b3a1fccde92e4b5fa54ef9caf 100644 (file)
@@ -21,4 +21,5 @@ BL32_SOURCES          +=      drivers/arm/gic/common/gic_common.c     \
 BL32_SOURCES           +=      plat/common/plat_psci_common.c
 
 # stm32mp1 specific services
-BL32_SOURCES           +=      plat/st/stm32mp1/services/stm32mp1_svc_setup.c
+BL32_SOURCES           +=      plat/st/stm32mp1/services/bsec_svc.c            \
+                               plat/st/stm32mp1/services/stm32mp1_svc_setup.c
index a0bdbf681fba05beb2fd79201cb9ca08f366ab82..0bc5076f7014777d3e29aa3e0af269900ad96bb4 100644 (file)
@@ -16,6 +16,7 @@
 #include <drivers/arm/gicv2.h>
 #include <drivers/arm/tzc400.h>
 #include <drivers/generic_delay_timer.h>
+#include <drivers/st/bsec.h>
 #include <drivers/st/stm32_console.h>
 #include <drivers/st/stm32mp1_clk.h>
 #include <dt-bindings/clock/stm32mp1-clks.h>
@@ -111,6 +112,10 @@ void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
                panic();
        }
 
+       if (bsec_probe() != 0) {
+               panic();
+       }
+
        if (stm32mp1_clk_probe() < 0) {
                panic();
        }