17d116dccSCC Ma /* 27d116dccSCC Ma * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 37d116dccSCC Ma * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 57d116dccSCC Ma */ 67d116dccSCC Ma #include <assert.h> 7cf906b2aSLeon Chen #include <console.h> 87d116dccSCC Ma #include <debug.h> 9cf906b2aSLeon Chen #include <mmio.h> 10cf906b2aSLeon Chen #include <mtk_plat_common.h> 117d116dccSCC Ma #include <mtk_sip_svc.h> 12b659b1a7SJimmy Huang #include <plat_sip_calls.h> 137d116dccSCC Ma #include <runtime_svc.h> 147d116dccSCC Ma #include <uuid.h> 157d116dccSCC Ma 167d116dccSCC Ma /* Mediatek SiP Service UUID */ 177d116dccSCC Ma DEFINE_SVC_UUID(mtk_sip_svc_uid, 187d116dccSCC Ma 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5, 197d116dccSCC Ma 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d); 207d116dccSCC Ma 21cf906b2aSLeon Chen #pragma weak mediatek_plat_sip_handler 22*57d1e5faSMasahiro Yamada uintptr_t mediatek_plat_sip_handler(uint32_t smc_fid, 23*57d1e5faSMasahiro Yamada u_register_t x1, 24*57d1e5faSMasahiro Yamada u_register_t x2, 25*57d1e5faSMasahiro Yamada u_register_t x3, 26*57d1e5faSMasahiro Yamada u_register_t x4, 277d116dccSCC Ma void *cookie, 28cf906b2aSLeon Chen void *handle, 29*57d1e5faSMasahiro Yamada u_register_t flags) 307d116dccSCC Ma { 317d116dccSCC Ma ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); 32cf906b2aSLeon Chen SMC_RET1(handle, SMC_UNK); 337d116dccSCC Ma } 347d116dccSCC Ma 35cf906b2aSLeon Chen /* 36cf906b2aSLeon Chen * This function handles Mediatek defined SiP Calls */ 37*57d1e5faSMasahiro Yamada uintptr_t mediatek_sip_handler(uint32_t smc_fid, 38*57d1e5faSMasahiro Yamada u_register_t x1, 39*57d1e5faSMasahiro Yamada u_register_t x2, 40*57d1e5faSMasahiro Yamada u_register_t x3, 41*57d1e5faSMasahiro Yamada u_register_t x4, 42cf906b2aSLeon Chen void *cookie, 43cf906b2aSLeon Chen void *handle, 44*57d1e5faSMasahiro Yamada u_register_t flags) 45cf906b2aSLeon Chen { 46cf906b2aSLeon Chen uint32_t ns; 47cf906b2aSLeon Chen 48cf906b2aSLeon Chen /* if parameter is sent from SMC32. Clean top 32 bits */ 49cf906b2aSLeon Chen clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4); 50cf906b2aSLeon Chen 51cf906b2aSLeon Chen /* Determine which security state this SMC originated from */ 52cf906b2aSLeon Chen ns = is_caller_non_secure(flags); 53cf906b2aSLeon Chen if (!ns) { 54cf906b2aSLeon Chen /* SiP SMC service secure world's call */ 55cf906b2aSLeon Chen ; 56cf906b2aSLeon Chen } else { 57cf906b2aSLeon Chen /* SiP SMC service normal world's call */ 58cf906b2aSLeon Chen switch (smc_fid) { 59cf906b2aSLeon Chen #if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE 60cf906b2aSLeon Chen case MTK_SIP_SET_AUTHORIZED_SECURE_REG: { 61cf906b2aSLeon Chen /* only use ret here */ 62cf906b2aSLeon Chen uint64_t ret; 63cf906b2aSLeon Chen 64cf906b2aSLeon Chen ret = mt_sip_set_authorized_sreg((uint32_t)x1, 65cf906b2aSLeon Chen (uint32_t)x2); 66cf906b2aSLeon Chen SMC_RET1(handle, ret); 67cf906b2aSLeon Chen } 68cf906b2aSLeon Chen #endif 69cf906b2aSLeon Chen #if MTK_SIP_KERNEL_BOOT_ENABLE 70cf906b2aSLeon Chen case MTK_SIP_KERNEL_BOOT_AARCH32: 71cf906b2aSLeon Chen boot_to_kernel(x1, x2, x3, x4); 72cf906b2aSLeon Chen SMC_RET0(handle); 73cf906b2aSLeon Chen #endif 74649c48f5SJonathan Wright default: 75649c48f5SJonathan Wright /* Do nothing in default case */ 76649c48f5SJonathan Wright break; 77cf906b2aSLeon Chen } 78cf906b2aSLeon Chen } 79cf906b2aSLeon Chen 80cf906b2aSLeon Chen return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4, 81cf906b2aSLeon Chen cookie, handle, flags); 82cf906b2aSLeon Chen 837d116dccSCC Ma } 847d116dccSCC Ma 857d116dccSCC Ma /* 867d116dccSCC Ma * This function is responsible for handling all SiP calls from the NS world 877d116dccSCC Ma */ 88*57d1e5faSMasahiro Yamada uintptr_t sip_smc_handler(uint32_t smc_fid, 89*57d1e5faSMasahiro Yamada u_register_t x1, 90*57d1e5faSMasahiro Yamada u_register_t x2, 91*57d1e5faSMasahiro Yamada u_register_t x3, 92*57d1e5faSMasahiro Yamada u_register_t x4, 937d116dccSCC Ma void *cookie, 947d116dccSCC Ma void *handle, 95*57d1e5faSMasahiro Yamada u_register_t flags) 967d116dccSCC Ma { 977d116dccSCC Ma switch (smc_fid) { 987d116dccSCC Ma case SIP_SVC_CALL_COUNT: 997d116dccSCC Ma /* Return the number of Mediatek SiP Service Calls. */ 100b659b1a7SJimmy Huang SMC_RET1(handle, 101b659b1a7SJimmy Huang MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS); 1027d116dccSCC Ma 1037d116dccSCC Ma case SIP_SVC_UID: 1047d116dccSCC Ma /* Return UID to the caller */ 1057d116dccSCC Ma SMC_UUID_RET(handle, mtk_sip_svc_uid); 1067d116dccSCC Ma 1077d116dccSCC Ma case SIP_SVC_VERSION: 1087d116dccSCC Ma /* Return the version of current implementation */ 1097d116dccSCC Ma SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR, 1107d116dccSCC Ma MTK_SIP_SVC_VERSION_MINOR); 1117d116dccSCC Ma 1127d116dccSCC Ma default: 1137d116dccSCC Ma return mediatek_sip_handler(smc_fid, x1, x2, x3, x4, 114cf906b2aSLeon Chen cookie, handle, flags); 1157d116dccSCC Ma } 1167d116dccSCC Ma } 1177d116dccSCC Ma 1187d116dccSCC Ma /* Define a runtime service descriptor for fast SMC calls */ 1197d116dccSCC Ma DECLARE_RT_SVC( 1207d116dccSCC Ma mediatek_sip_svc, 1217d116dccSCC Ma OEN_SIP_START, 1227d116dccSCC Ma OEN_SIP_END, 1237d116dccSCC Ma SMC_TYPE_FAST, 1247d116dccSCC Ma NULL, 1257d116dccSCC Ma sip_smc_handler 1267d116dccSCC Ma ); 127