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> |
| 36 | #include <runtime_svc.h> |
| 37 | #include <uuid.h> |
| 38 | |
| 39 | /* Mediatek SiP Service UUID */ |
| 40 | DEFINE_SVC_UUID(mtk_sip_svc_uid, |
| 41 | 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5, |
| 42 | 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d); |
| 43 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 44 | #pragma weak mediatek_plat_sip_handler |
| 45 | uint64_t mediatek_plat_sip_handler(uint32_t smc_fid, |
| 46 | uint64_t x1, |
| 47 | uint64_t x2, |
| 48 | uint64_t x3, |
| 49 | uint64_t x4, |
| 50 | void *cookie, |
| 51 | void *handle, |
| 52 | uint64_t flags) |
| 53 | { |
| 54 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 55 | SMC_RET1(handle, SMC_UNK); |
| 56 | } |
| 57 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 58 | /* |
| 59 | * This function handles Mediatek defined SiP Calls */ |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 60 | uint64_t mediatek_sip_handler(uint32_t smc_fid, |
| 61 | uint64_t x1, |
| 62 | uint64_t x2, |
| 63 | uint64_t x3, |
| 64 | uint64_t x4, |
| 65 | void *cookie, |
| 66 | void *handle, |
| 67 | uint64_t flags) |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 68 | { |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 69 | uint32_t ns; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 70 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 71 | /* if parameter is sent from SMC32. Clean top 32 bits */ |
| 72 | clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4); |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 73 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 74 | /* Determine which security state this SMC originated from */ |
| 75 | ns = is_caller_non_secure(flags); |
| 76 | if (!ns) { |
| 77 | /* SiP SMC service secure world's call */ |
| 78 | ; |
| 79 | } else { |
| 80 | /* SiP SMC service normal world's call */ |
| 81 | switch (smc_fid) { |
| 82 | #if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE |
| 83 | case MTK_SIP_SET_AUTHORIZED_SECURE_REG: { |
| 84 | /* only use ret here */ |
| 85 | uint64_t ret; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 86 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 87 | ret = mt_sip_set_authorized_sreg((uint32_t)x1, |
| 88 | (uint32_t)x2); |
| 89 | SMC_RET1(handle, ret); |
| 90 | } |
| 91 | #endif |
| 92 | #if MTK_SIP_KERNEL_BOOT_ENABLE |
| 93 | case MTK_SIP_KERNEL_BOOT_AARCH32: |
| 94 | boot_to_kernel(x1, x2, x3, x4); |
| 95 | SMC_RET0(handle); |
| 96 | #endif |
| 97 | } |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 98 | } |
| 99 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 100 | return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4, |
| 101 | cookie, handle, flags); |
| 102 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * This function is responsible for handling all SiP calls from the NS world |
| 107 | */ |
| 108 | uint64_t sip_smc_handler(uint32_t smc_fid, |
| 109 | uint64_t x1, |
| 110 | uint64_t x2, |
| 111 | uint64_t x3, |
| 112 | uint64_t x4, |
| 113 | void *cookie, |
| 114 | void *handle, |
| 115 | uint64_t flags) |
| 116 | { |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 117 | switch (smc_fid) { |
| 118 | case SIP_SVC_CALL_COUNT: |
| 119 | /* Return the number of Mediatek SiP Service Calls. */ |
| 120 | SMC_RET1(handle, MTK_SIP_NUM_CALLS); |
| 121 | |
| 122 | case SIP_SVC_UID: |
| 123 | /* Return UID to the caller */ |
| 124 | SMC_UUID_RET(handle, mtk_sip_svc_uid); |
| 125 | |
| 126 | case SIP_SVC_VERSION: |
| 127 | /* Return the version of current implementation */ |
| 128 | SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, |
| 129 | MTK_SIP_SVC_VERSION_MINOR); |
| 130 | |
| 131 | default: |
| 132 | return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 133 | cookie, handle, flags); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | /* Define a runtime service descriptor for fast SMC calls */ |
| 138 | DECLARE_RT_SVC( |
| 139 | mediatek_sip_svc, |
| 140 | OEN_SIP_START, |
| 141 | OEN_SIP_END, |
| 142 | SMC_TYPE_FAST, |
| 143 | NULL, |
| 144 | sip_smc_handler |
| 145 | ); |