developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, 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 |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 5 | */ |
| 6 | #include <assert.h> |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 7 | #include <console.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 8 | #include <debug.h> |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 9 | #include <mmio.h> |
| 10 | #include <mtk_plat_common.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 11 | #include <mtk_sip_svc.h> |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 12 | #include <plat_sip_calls.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 13 | #include <runtime_svc.h> |
| 14 | #include <uuid.h> |
| 15 | |
| 16 | /* Mediatek SiP Service UUID */ |
| 17 | DEFINE_SVC_UUID(mtk_sip_svc_uid, |
| 18 | 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5, |
| 19 | 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d); |
| 20 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 21 | #pragma weak mediatek_plat_sip_handler |
| 22 | uint64_t mediatek_plat_sip_handler(uint32_t smc_fid, |
| 23 | uint64_t x1, |
| 24 | uint64_t x2, |
| 25 | uint64_t x3, |
| 26 | uint64_t x4, |
| 27 | void *cookie, |
| 28 | void *handle, |
| 29 | uint64_t flags) |
| 30 | { |
| 31 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 32 | SMC_RET1(handle, SMC_UNK); |
| 33 | } |
| 34 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 35 | /* |
| 36 | * This function handles Mediatek defined SiP Calls */ |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 37 | uint64_t mediatek_sip_handler(uint32_t smc_fid, |
| 38 | uint64_t x1, |
| 39 | uint64_t x2, |
| 40 | uint64_t x3, |
| 41 | uint64_t x4, |
| 42 | void *cookie, |
| 43 | void *handle, |
| 44 | uint64_t flags) |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 45 | { |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 46 | uint32_t ns; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 47 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 48 | /* if parameter is sent from SMC32. Clean top 32 bits */ |
| 49 | clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4); |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 50 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 51 | /* Determine which security state this SMC originated from */ |
| 52 | ns = is_caller_non_secure(flags); |
| 53 | if (!ns) { |
| 54 | /* SiP SMC service secure world's call */ |
| 55 | ; |
| 56 | } else { |
| 57 | /* SiP SMC service normal world's call */ |
| 58 | switch (smc_fid) { |
| 59 | #if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE |
| 60 | case MTK_SIP_SET_AUTHORIZED_SECURE_REG: { |
| 61 | /* only use ret here */ |
| 62 | uint64_t ret; |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 63 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 64 | ret = mt_sip_set_authorized_sreg((uint32_t)x1, |
| 65 | (uint32_t)x2); |
| 66 | SMC_RET1(handle, ret); |
| 67 | } |
| 68 | #endif |
| 69 | #if MTK_SIP_KERNEL_BOOT_ENABLE |
| 70 | case MTK_SIP_KERNEL_BOOT_AARCH32: |
| 71 | boot_to_kernel(x1, x2, x3, x4); |
| 72 | SMC_RET0(handle); |
| 73 | #endif |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 74 | default: |
| 75 | /* Do nothing in default case */ |
| 76 | break; |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 77 | } |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 78 | } |
| 79 | |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 80 | return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4, |
| 81 | cookie, handle, flags); |
| 82 | |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* |
| 86 | * This function is responsible for handling all SiP calls from the NS world |
| 87 | */ |
| 88 | uint64_t sip_smc_handler(uint32_t smc_fid, |
| 89 | uint64_t x1, |
| 90 | uint64_t x2, |
| 91 | uint64_t x3, |
| 92 | uint64_t x4, |
| 93 | void *cookie, |
| 94 | void *handle, |
| 95 | uint64_t flags) |
| 96 | { |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 97 | switch (smc_fid) { |
| 98 | case SIP_SVC_CALL_COUNT: |
| 99 | /* Return the number of Mediatek SiP Service Calls. */ |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 100 | SMC_RET1(handle, |
| 101 | MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 102 | |
| 103 | case SIP_SVC_UID: |
| 104 | /* Return UID to the caller */ |
| 105 | SMC_UUID_RET(handle, mtk_sip_svc_uid); |
| 106 | |
| 107 | case SIP_SVC_VERSION: |
| 108 | /* Return the version of current implementation */ |
| 109 | SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, |
| 110 | MTK_SIP_SVC_VERSION_MINOR); |
| 111 | |
| 112 | default: |
| 113 | return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, |
developer | 14f3fe3 | 2016-04-28 14:07:42 +0800 | [diff] [blame] | 114 | cookie, handle, flags); |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | /* Define a runtime service descriptor for fast SMC calls */ |
| 119 | DECLARE_RT_SVC( |
| 120 | mediatek_sip_svc, |
| 121 | OEN_SIP_START, |
| 122 | OEN_SIP_END, |
| 123 | SMC_TYPE_FAST, |
| 124 | NULL, |
| 125 | sip_smc_handler |
| 126 | ); |