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> |
| 31 | #include <debug.h> |
| 32 | #include <mtk_sip_svc.h> |
| 33 | #include <runtime_svc.h> |
| 34 | #include <uuid.h> |
| 35 | |
| 36 | /* Mediatek SiP Service UUID */ |
| 37 | DEFINE_SVC_UUID(mtk_sip_svc_uid, |
| 38 | 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5, |
| 39 | 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d); |
| 40 | |
| 41 | /* |
| 42 | * This function handles Mediatek defined SiP Calls */ |
| 43 | static uint64_t mediatek_sip_handler(uint32_t smc_fid, |
| 44 | uint64_t x1, |
| 45 | uint64_t x2, |
| 46 | uint64_t x3, |
| 47 | uint64_t x4, |
| 48 | void *cookie, |
| 49 | void *handle) |
| 50 | { |
| 51 | uint64_t ret; |
| 52 | |
| 53 | switch (smc_fid) { |
| 54 | case MTK_SIP_SET_AUTHORIZED_SECURE_REG: |
| 55 | ret = mt_sip_set_authorized_sreg((uint32_t)x1, (uint32_t)x2); |
| 56 | SMC_RET1(handle, ret); |
| 57 | |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 58 | case MTK_SIP_PWR_ON_MTCMOS: |
| 59 | ret = mt_sip_pwr_on_mtcmos((uint32_t)x1); |
| 60 | SMC_RET1(handle, ret); |
| 61 | |
| 62 | case MTK_SIP_PWR_OFF_MTCMOS: |
| 63 | ret = mt_sip_pwr_off_mtcmos((uint32_t)x1); |
| 64 | SMC_RET1(handle, ret); |
| 65 | |
| 66 | case MTK_SIP_PWR_MTCMOS_SUPPORT: |
| 67 | ret = mt_sip_pwr_mtcmos_support(); |
| 68 | SMC_RET1(handle, ret); |
| 69 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 70 | default: |
| 71 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | SMC_RET1(handle, SMC_UNK); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * This function is responsible for handling all SiP calls from the NS world |
| 80 | */ |
| 81 | uint64_t sip_smc_handler(uint32_t smc_fid, |
| 82 | uint64_t x1, |
| 83 | uint64_t x2, |
| 84 | uint64_t x3, |
| 85 | uint64_t x4, |
| 86 | void *cookie, |
| 87 | void *handle, |
| 88 | uint64_t flags) |
| 89 | { |
| 90 | uint32_t ns; |
| 91 | |
| 92 | /* Determine which security state this SMC originated from */ |
| 93 | ns = is_caller_non_secure(flags); |
| 94 | if (!ns) |
| 95 | SMC_RET1(handle, SMC_UNK); |
| 96 | |
| 97 | switch (smc_fid) { |
| 98 | case SIP_SVC_CALL_COUNT: |
| 99 | /* Return the number of Mediatek SiP Service Calls. */ |
| 100 | SMC_RET1(handle, MTK_SIP_NUM_CALLS); |
| 101 | |
| 102 | case SIP_SVC_UID: |
| 103 | /* Return UID to the caller */ |
| 104 | SMC_UUID_RET(handle, mtk_sip_svc_uid); |
| 105 | |
| 106 | case SIP_SVC_VERSION: |
| 107 | /* Return the version of current implementation */ |
| 108 | SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, |
| 109 | MTK_SIP_SVC_VERSION_MINOR); |
| 110 | |
| 111 | default: |
| 112 | return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, |
| 113 | cookie, handle); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* Define a runtime service descriptor for fast SMC calls */ |
| 118 | DECLARE_RT_SVC( |
| 119 | mediatek_sip_svc, |
| 120 | OEN_SIP_START, |
| 121 | OEN_SIP_END, |
| 122 | SMC_TYPE_FAST, |
| 123 | NULL, |
| 124 | sip_smc_handler |
| 125 | ); |