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 | |
| 17 | /* STM32 SiP Service UUID */ |
| 18 | DEFINE_SVC_UUID2(stm32_sip_svc_uid, |
| 19 | 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e, |
| 20 | 0x26, 0x4d, 0x59, 0x94, 0xc2, 0x14); |
| 21 | |
| 22 | /* Setup STM32MP1 Standard Services */ |
| 23 | static int32_t stm32mp1_svc_setup(void) |
| 24 | { |
| 25 | /* |
| 26 | * PSCI is the only specification implemented as a Standard Service. |
| 27 | * Invoke PSCI setup from here. |
| 28 | */ |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * Top-level Standard Service SMC handler. This handler will in turn dispatch |
| 34 | * calls to PSCI SMC handler. |
| 35 | */ |
| 36 | static uintptr_t stm32mp1_svc_smc_handler(uint32_t smc_fid, u_register_t x1, |
| 37 | u_register_t x2, u_register_t x3, |
| 38 | u_register_t x4, void *cookie, |
| 39 | void *handle, u_register_t flags) |
| 40 | { |
| 41 | uint32_t ret1 = 0U, ret2 = 0U; |
| 42 | bool ret_uid = false, ret2_enabled = false; |
| 43 | |
| 44 | switch (smc_fid) { |
| 45 | case STM32_SIP_SVC_CALL_COUNT: |
| 46 | ret1 = STM32_COMMON_SIP_NUM_CALLS; |
| 47 | break; |
| 48 | |
| 49 | case STM32_SIP_SVC_UID: |
| 50 | /* Return UUID to the caller */ |
| 51 | ret_uid = true; |
| 52 | break; |
| 53 | |
| 54 | case STM32_SIP_SVC_VERSION: |
| 55 | /* Return the version of current implementation */ |
| 56 | ret1 = STM32_SIP_SVC_VERSION_MAJOR; |
| 57 | ret2 = STM32_SIP_SVC_VERSION_MINOR; |
| 58 | ret2_enabled = true; |
| 59 | break; |
| 60 | |
| 61 | default: |
| 62 | WARN("Unimplemented STM32MP1 Service Call: 0x%x\n", smc_fid); |
| 63 | ret1 = SMC_UNK; |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | if (ret_uid) { |
| 68 | SMC_UUID_RET(handle, stm32_sip_svc_uid); |
| 69 | } |
| 70 | |
| 71 | if (ret2_enabled) { |
| 72 | SMC_RET2(handle, ret1, ret2); |
| 73 | } |
| 74 | |
| 75 | SMC_RET1(handle, ret1); |
| 76 | } |
| 77 | |
| 78 | /* Register Standard Service Calls as runtime service */ |
| 79 | DECLARE_RT_SVC(stm32mp1_sip_svc, |
| 80 | OEN_SIP_START, |
| 81 | OEN_SIP_END, |
| 82 | SMC_TYPE_FAST, |
| 83 | stm32mp1_svc_setup, |
| 84 | stm32mp1_svc_smc_handler |
| 85 | ); |