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 | |
| 58 | default: |
| 59 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | SMC_RET1(handle, SMC_UNK); |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * This function is responsible for handling all SiP calls from the NS world |
| 68 | */ |
| 69 | uint64_t sip_smc_handler(uint32_t smc_fid, |
| 70 | uint64_t x1, |
| 71 | uint64_t x2, |
| 72 | uint64_t x3, |
| 73 | uint64_t x4, |
| 74 | void *cookie, |
| 75 | void *handle, |
| 76 | uint64_t flags) |
| 77 | { |
| 78 | uint32_t ns; |
| 79 | |
| 80 | /* Determine which security state this SMC originated from */ |
| 81 | ns = is_caller_non_secure(flags); |
| 82 | if (!ns) |
| 83 | SMC_RET1(handle, SMC_UNK); |
| 84 | |
| 85 | switch (smc_fid) { |
| 86 | case SIP_SVC_CALL_COUNT: |
| 87 | /* Return the number of Mediatek SiP Service Calls. */ |
| 88 | SMC_RET1(handle, MTK_SIP_NUM_CALLS); |
| 89 | |
| 90 | case SIP_SVC_UID: |
| 91 | /* Return UID to the caller */ |
| 92 | SMC_UUID_RET(handle, mtk_sip_svc_uid); |
| 93 | |
| 94 | case SIP_SVC_VERSION: |
| 95 | /* Return the version of current implementation */ |
| 96 | SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, |
| 97 | MTK_SIP_SVC_VERSION_MINOR); |
| 98 | |
| 99 | default: |
| 100 | return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, |
| 101 | cookie, handle); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /* Define a runtime service descriptor for fast SMC calls */ |
| 106 | DECLARE_RT_SVC( |
| 107 | mediatek_sip_svc, |
| 108 | OEN_SIP_START, |
| 109 | OEN_SIP_END, |
| 110 | SMC_TYPE_FAST, |
| 111 | NULL, |
| 112 | sip_smc_handler |
| 113 | ); |