Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <debug.h> |
| 9 | #include <mmio.h> |
| 10 | #include <plat_sip_calls.h> |
| 11 | #include <rockchip_sip_svc.h> |
| 12 | #include <runtime_svc.h> |
| 13 | #include <uuid.h> |
| 14 | |
| 15 | /* Rockchip SiP Service UUID */ |
Roberto Vargas | eace8f1 | 2018-04-26 13:36:53 +0100 | [diff] [blame] | 16 | DEFINE_SVC_UUID2(rk_sip_svc_uid, |
| 17 | 0xe2c76fe8, 0x3e31, 0xe611, 0xb7, 0x0d, |
| 18 | 0x8f, 0x88, 0xee, 0x74, 0x7b, 0x72); |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 19 | |
| 20 | #pragma weak rockchip_plat_sip_handler |
Masahiro Yamada | 5ac9d96 | 2018-04-19 01:18:48 +0900 | [diff] [blame] | 21 | uintptr_t rockchip_plat_sip_handler(uint32_t smc_fid, |
| 22 | u_register_t x1, |
| 23 | u_register_t x2, |
| 24 | u_register_t x3, |
| 25 | u_register_t x4, |
| 26 | void *cookie, |
| 27 | void *handle, |
| 28 | u_register_t flags) |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 29 | { |
| 30 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 31 | SMC_RET1(handle, SMC_UNK); |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * This function is responsible for handling all SiP calls from the NS world |
| 36 | */ |
Masahiro Yamada | 5ac9d96 | 2018-04-19 01:18:48 +0900 | [diff] [blame] | 37 | uintptr_t sip_smc_handler(uint32_t smc_fid, |
| 38 | u_register_t x1, |
| 39 | u_register_t x2, |
| 40 | u_register_t x3, |
| 41 | u_register_t x4, |
| 42 | void *cookie, |
| 43 | void *handle, |
| 44 | u_register_t flags) |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 45 | { |
| 46 | uint32_t ns; |
| 47 | |
| 48 | /* Determine which security state this SMC originated from */ |
| 49 | ns = is_caller_non_secure(flags); |
| 50 | if (!ns) |
| 51 | SMC_RET1(handle, SMC_UNK); |
| 52 | |
| 53 | switch (smc_fid) { |
| 54 | case SIP_SVC_CALL_COUNT: |
| 55 | /* Return the number of Rockchip SiP Service Calls. */ |
| 56 | SMC_RET1(handle, |
| 57 | RK_COMMON_SIP_NUM_CALLS + RK_PLAT_SIP_NUM_CALLS); |
| 58 | |
| 59 | case SIP_SVC_UID: |
| 60 | /* Return UID to the caller */ |
| 61 | SMC_UUID_RET(handle, rk_sip_svc_uid); |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 62 | |
| 63 | case SIP_SVC_VERSION: |
| 64 | /* Return the version of current implementation */ |
| 65 | SMC_RET2(handle, RK_SIP_SVC_VERSION_MAJOR, |
| 66 | RK_SIP_SVC_VERSION_MINOR); |
Caesar Wang | c1bf646 | 2016-06-21 14:44:01 +0800 | [diff] [blame] | 67 | |
| 68 | default: |
| 69 | return rockchip_plat_sip_handler(smc_fid, x1, x2, x3, x4, |
| 70 | cookie, handle, flags); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /* Define a runtime service descriptor for fast SMC calls */ |
| 75 | DECLARE_RT_SVC( |
| 76 | rockchip_sip_svc, |
| 77 | OEN_SIP_START, |
| 78 | OEN_SIP_END, |
| 79 | SMC_TYPE_FAST, |
| 80 | NULL, |
| 81 | sip_smc_handler |
| 82 | ); |