Yann Gautier | 05be8d8 | 2019-01-17 14:51:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2019, STMicroelectronics - All Rights Reserved |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdbool.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <common/debug.h> |
| 11 | #include <common/runtime_svc.h> |
| 12 | #include <lib/psci/psci.h> |
| 13 | #include <tools_share/uuid.h> |
| 14 | |
| 15 | #include <stm32mp1_smc.h> |
| 16 | |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 17 | #include "bsec_svc.h" |
| 18 | |
Yann Gautier | 05be8d8 | 2019-01-17 14:51:25 +0100 | [diff] [blame] | 19 | /* STM32 SiP Service UUID */ |
| 20 | DEFINE_SVC_UUID2(stm32_sip_svc_uid, |
| 21 | 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e, |
| 22 | 0x26, 0x4d, 0x59, 0x94, 0xc2, 0x14); |
| 23 | |
| 24 | /* Setup STM32MP1 Standard Services */ |
| 25 | static int32_t stm32mp1_svc_setup(void) |
| 26 | { |
| 27 | /* |
| 28 | * PSCI is the only specification implemented as a Standard Service. |
| 29 | * Invoke PSCI setup from here. |
| 30 | */ |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * Top-level Standard Service SMC handler. This handler will in turn dispatch |
| 36 | * calls to PSCI SMC handler. |
| 37 | */ |
| 38 | static uintptr_t stm32mp1_svc_smc_handler(uint32_t smc_fid, u_register_t x1, |
| 39 | u_register_t x2, u_register_t x3, |
| 40 | u_register_t x4, void *cookie, |
| 41 | void *handle, u_register_t flags) |
| 42 | { |
| 43 | uint32_t ret1 = 0U, ret2 = 0U; |
| 44 | bool ret_uid = false, ret2_enabled = false; |
| 45 | |
| 46 | switch (smc_fid) { |
| 47 | case STM32_SIP_SVC_CALL_COUNT: |
| 48 | ret1 = STM32_COMMON_SIP_NUM_CALLS; |
| 49 | break; |
| 50 | |
| 51 | case STM32_SIP_SVC_UID: |
| 52 | /* Return UUID to the caller */ |
| 53 | ret_uid = true; |
| 54 | break; |
| 55 | |
| 56 | case STM32_SIP_SVC_VERSION: |
| 57 | /* Return the version of current implementation */ |
| 58 | ret1 = STM32_SIP_SVC_VERSION_MAJOR; |
| 59 | ret2 = STM32_SIP_SVC_VERSION_MINOR; |
| 60 | ret2_enabled = true; |
| 61 | break; |
| 62 | |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 63 | case STM32_SMC_BSEC: |
| 64 | ret1 = bsec_main(x1, x2, x3, &ret2); |
| 65 | ret2_enabled = true; |
| 66 | break; |
| 67 | |
Yann Gautier | 05be8d8 | 2019-01-17 14:51:25 +0100 | [diff] [blame] | 68 | default: |
| 69 | WARN("Unimplemented STM32MP1 Service Call: 0x%x\n", smc_fid); |
| 70 | ret1 = SMC_UNK; |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | if (ret_uid) { |
| 75 | SMC_UUID_RET(handle, stm32_sip_svc_uid); |
| 76 | } |
| 77 | |
| 78 | if (ret2_enabled) { |
| 79 | SMC_RET2(handle, ret1, ret2); |
| 80 | } |
| 81 | |
| 82 | SMC_RET1(handle, ret1); |
| 83 | } |
| 84 | |
| 85 | /* Register Standard Service Calls as runtime service */ |
| 86 | DECLARE_RT_SVC(stm32mp1_sip_svc, |
| 87 | OEN_SIP_START, |
| 88 | OEN_SIP_END, |
| 89 | SMC_TYPE_FAST, |
| 90 | stm32mp1_svc_setup, |
| 91 | stm32mp1_svc_smc_handler |
| 92 | ); |