blob: dab0d4541c8876a6a956db29646d48b84dbb0293 [file] [log] [blame]
developer65014b82015-04-13 14:47:57 +08001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
developer65014b82015-04-13 14:47:57 +08005 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
developer65014b82015-04-13 14:47:57 +08007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
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
developer14f3fe32016-04-28 14:07:42 +080015#include <mtk_plat_common.h>
developer65014b82015-04-13 14:47:57 +080016#include <mtk_sip_svc.h>
developer73b982f2016-05-11 18:04:09 +080017#include <plat_sip_calls.h>
developer65014b82015-04-13 14:47:57 +080018
19/* Mediatek SiP Service UUID */
Roberto Vargaseace8f12018-04-26 13:36:53 +010020DEFINE_SVC_UUID2(mtk_sip_svc_uid,
21 0xa42b58f7, 0x6242, 0x7d4d, 0x80, 0xe5,
22 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d);
developer65014b82015-04-13 14:47:57 +080023
developer14f3fe32016-04-28 14:07:42 +080024#pragma weak mediatek_plat_sip_handler
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090025uintptr_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,
developer14f3fe32016-04-28 14:07:42 +080030 void *cookie,
31 void *handle,
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090032 u_register_t flags)
developer14f3fe32016-04-28 14:07:42 +080033{
34 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
35 SMC_RET1(handle, SMC_UNK);
36}
37
developer65014b82015-04-13 14:47:57 +080038/*
39 * This function handles Mediatek defined SiP Calls */
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090040uintptr_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,
developer14f3fe32016-04-28 14:07:42 +080045 void *cookie,
46 void *handle,
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090047 u_register_t flags)
developer65014b82015-04-13 14:47:57 +080048{
developer14f3fe32016-04-28 14:07:42 +080049 uint32_t ns;
developerb8925a22015-11-16 14:38:40 +080050
developer14f3fe32016-04-28 14:07:42 +080051 /* if parameter is sent from SMC32. Clean top 32 bits */
52 clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4);
developerb8925a22015-11-16 14:38:40 +080053
developer14f3fe32016-04-28 14:07:42 +080054 /* 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;
developerb8925a22015-11-16 14:38:40 +080066
developer14f3fe32016-04-28 14:07:42 +080067 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 Wrightff957ed2018-03-14 15:24:00 +000077 default:
78 /* Do nothing in default case */
79 break;
developer14f3fe32016-04-28 14:07:42 +080080 }
developer65014b82015-04-13 14:47:57 +080081 }
82
developer14f3fe32016-04-28 14:07:42 +080083 return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4,
84 cookie, handle, flags);
85
developer65014b82015-04-13 14:47:57 +080086}
87
88/*
89 * This function is responsible for handling all SiP calls from the NS world
90 */
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090091uintptr_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,
developer65014b82015-04-13 14:47:57 +080096 void *cookie,
97 void *handle,
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090098 u_register_t flags)
developer65014b82015-04-13 14:47:57 +080099{
developer65014b82015-04-13 14:47:57 +0800100 switch (smc_fid) {
101 case SIP_SVC_CALL_COUNT:
102 /* Return the number of Mediatek SiP Service Calls. */
developer73b982f2016-05-11 18:04:09 +0800103 SMC_RET1(handle,
104 MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS);
developer65014b82015-04-13 14:47:57 +0800105
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,
developer14f3fe32016-04-28 14:07:42 +0800117 cookie, handle, flags);
developer65014b82015-04-13 14:47:57 +0800118 }
119}
120
121/* Define a runtime service descriptor for fast SMC calls */
122DECLARE_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);