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