developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | #include <assert.h> |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 31 | #include <console.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 32 | #include <debug.h> |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 33 | #include <mmio.h> |
| 34 | #include <mtk_plat_common.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 35 | #include <mtk_sip_svc.h> |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 36 | #include <plat_sip_calls.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 37 | #include <runtime_svc.h> |
| 38 | #include <uuid.h> |
| 39 | |
| 40 | /* Mediatek SiP Service UUID */ |
| 41 | DEFINE_SVC_UUID(mtk_sip_svc_uid, |
| 42 | 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5, |
| 43 | 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d); |
| 44 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 45 | #pragma weak mediatek_plat_sip_handler |
| 46 | uint64_t mediatek_plat_sip_handler(uint32_t smc_fid, |
| 47 | uint64_t x1, |
| 48 | uint64_t x2, |
| 49 | uint64_t x3, |
| 50 | uint64_t x4, |
| 51 | void *cookie, |
| 52 | void *handle, |
| 53 | uint64_t flags) |
| 54 | { |
| 55 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 56 | SMC_RET1(handle, SMC_UNK); |
| 57 | } |
| 58 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 59 | /* |
| 60 | * This function handles Mediatek defined SiP Calls */ |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 61 | uint64_t mediatek_sip_handler(uint32_t smc_fid, |
| 62 | uint64_t x1, |
| 63 | uint64_t x2, |
| 64 | uint64_t x3, |
| 65 | uint64_t x4, |
| 66 | void *cookie, |
| 67 | void *handle, |
| 68 | uint64_t flags) |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 69 | { |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 70 | uint32_t ns; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 71 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 72 | /* if parameter is sent from SMC32. Clean top 32 bits */ |
| 73 | clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4); |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 74 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 75 | /* Determine which security state this SMC originated from */ |
| 76 | ns = is_caller_non_secure(flags); |
| 77 | if (!ns) { |
| 78 | /* SiP SMC service secure world's call */ |
| 79 | ; |
| 80 | } else { |
| 81 | /* SiP SMC service normal world's call */ |
| 82 | switch (smc_fid) { |
| 83 | #if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE |
| 84 | case MTK_SIP_SET_AUTHORIZED_SECURE_REG: { |
| 85 | /* only use ret here */ |
| 86 | uint64_t ret; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 87 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 88 | ret = mt_sip_set_authorized_sreg((uint32_t)x1, |
| 89 | (uint32_t)x2); |
| 90 | SMC_RET1(handle, ret); |
| 91 | } |
| 92 | #endif |
| 93 | #if MTK_SIP_KERNEL_BOOT_ENABLE |
| 94 | case MTK_SIP_KERNEL_BOOT_AARCH32: |
| 95 | boot_to_kernel(x1, x2, x3, x4); |
| 96 | SMC_RET0(handle); |
| 97 | #endif |
| 98 | } |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 99 | } |
| 100 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 101 | return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4, |
| 102 | cookie, handle, flags); |
| 103 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
| 107 | * This function is responsible for handling all SiP calls from the NS world |
| 108 | */ |
| 109 | uint64_t sip_smc_handler(uint32_t smc_fid, |
| 110 | uint64_t x1, |
| 111 | uint64_t x2, |
| 112 | uint64_t x3, |
| 113 | uint64_t x4, |
| 114 | void *cookie, |
| 115 | void *handle, |
| 116 | uint64_t flags) |
| 117 | { |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 118 | switch (smc_fid) { |
| 119 | case SIP_SVC_CALL_COUNT: |
| 120 | /* Return the number of Mediatek SiP Service Calls. */ |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 121 | SMC_RET1(handle, |
| 122 | MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 123 | |
| 124 | case SIP_SVC_UID: |
| 125 | /* Return UID to the caller */ |
| 126 | SMC_UUID_RET(handle, mtk_sip_svc_uid); |
| 127 | |
| 128 | case SIP_SVC_VERSION: |
| 129 | /* Return the version of current implementation */ |
| 130 | SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, |
| 131 | MTK_SIP_SVC_VERSION_MINOR); |
| 132 | |
| 133 | default: |
| 134 | return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 135 | cookie, handle, flags); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | /* Define a runtime service descriptor for fast SMC calls */ |
| 140 | DECLARE_RT_SVC( |
| 141 | mediatek_sip_svc, |
| 142 | OEN_SIP_START, |
| 143 | OEN_SIP_END, |
| 144 | SMC_TYPE_FAST, |
| 145 | NULL, |
| 146 | sip_smc_handler |
| 147 | ); |