xref: /rk3399_ARM-atf/plat/nvidia/tegra/soc/t186/plat_sip_calls.c (revision 0d5ec955b8f7900ca33abf88638d499742531159)
1 /*
2  * Copyright (c) 2015-2016, 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 
31 #include <arch.h>
32 #include <arch_helpers.h>
33 #include <assert.h>
34 #include <bl_common.h>
35 #include <context_mgmt.h>
36 #include <debug.h>
37 #include <errno.h>
38 #include <mce.h>
39 #include <memctrl.h>
40 #include <runtime_svc.h>
41 #include <t18x_ari.h>
42 #include <tegra_private.h>
43 
44 extern uint32_t tegra186_system_powerdn_state;
45 
46 /*******************************************************************************
47  * Tegra186 SiP SMCs
48  ******************************************************************************/
49 #define TEGRA_SIP_NEW_VIDEOMEM_REGION			0x82000003
50 #define TEGRA_SIP_SYSTEM_SHUTDOWN_STATE			0x82FFFE01
51 #define TEGRA_SIP_MCE_CMD_ENTER_CSTATE			0x82FFFF00
52 #define TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO		0x82FFFF01
53 #define TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME		0x82FFFF02
54 #define TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS		0x82FFFF03
55 #define TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS		0x82FFFF04
56 #define TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED		0x82FFFF05
57 #define TEGRA_SIP_MCE_CMD_ONLINE_CORE			0x82FFFF06
58 #define TEGRA_SIP_MCE_CMD_CC3_CTRL			0x82FFFF07
59 #define TEGRA_SIP_MCE_CMD_ECHO_DATA			0x82FFFF08
60 #define TEGRA_SIP_MCE_CMD_READ_VERSIONS			0x82FFFF09
61 #define TEGRA_SIP_MCE_CMD_ENUM_FEATURES			0x82FFFF0A
62 #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS	0x82FFFF0B
63 #define TEGRA_SIP_MCE_CMD_ENUM_READ_MCA			0x82FFFF0C
64 #define TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA		0x82FFFF0D
65 #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE		0x82FFFF0E
66 #define TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE		0x82FFFF0F
67 #define TEGRA_SIP_MCE_CMD_ENABLE_LATIC			0x82FFFF10
68 #define TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ		0x82FFFF11
69 
70 /*******************************************************************************
71  * This function is responsible for handling all T186 SiP calls
72  ******************************************************************************/
73 int plat_sip_handler(uint32_t smc_fid,
74 		     uint64_t x1,
75 		     uint64_t x2,
76 		     uint64_t x3,
77 		     uint64_t x4,
78 		     void *cookie,
79 		     void *handle,
80 		     uint64_t flags)
81 {
82 	int mce_ret;
83 
84 	switch (smc_fid) {
85 
86 	/*
87 	 * Micro Coded Engine (MCE) commands reside in the 0x82FFFF00 -
88 	 * 0x82FFFFFF SiP SMC space
89 	 */
90 	case TEGRA_SIP_MCE_CMD_ENTER_CSTATE:
91 	case TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO:
92 	case TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME:
93 	case TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS:
94 	case TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS:
95 	case TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED:
96 	case TEGRA_SIP_MCE_CMD_CC3_CTRL:
97 	case TEGRA_SIP_MCE_CMD_ECHO_DATA:
98 	case TEGRA_SIP_MCE_CMD_READ_VERSIONS:
99 	case TEGRA_SIP_MCE_CMD_ENUM_FEATURES:
100 	case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
101 	case TEGRA_SIP_MCE_CMD_ENUM_READ_MCA:
102 	case TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA:
103 	case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE:
104 	case TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE:
105 	case TEGRA_SIP_MCE_CMD_ENABLE_LATIC:
106 	case TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ:
107 
108 		/* clean up the high bits */
109 		smc_fid &= MCE_CMD_MASK;
110 
111 		/* execute the command and store the result */
112 		mce_ret = mce_command_handler(smc_fid, x1, x2, x3);
113 		write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X0, mce_ret);
114 
115 		return 0;
116 
117 	case TEGRA_SIP_SYSTEM_SHUTDOWN_STATE:
118 
119 		/* clean up the high bits */
120 		x1 = (uint32_t)x1;
121 
122 		/*
123 		 * SC8 is a special Tegra186 system state where the CPUs and
124 		 * DRAM are powered down but the other subsystem is still
125 		 * alive.
126 		 */
127 		if ((x1 == TEGRA_ARI_SYSTEM_SC8) ||
128 		    (x1 == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF)) {
129 
130 			tegra186_system_powerdn_state = x1;
131 			flush_dcache_range(
132 				(uintptr_t)&tegra186_system_powerdn_state,
133 				sizeof(tegra186_system_powerdn_state));
134 
135 		} else {
136 
137 			ERROR("%s: unhandled powerdn state (%d)\n", __func__,
138 				(uint32_t)x1);
139 			return -ENOTSUP;
140 		}
141 
142 		return 0;
143 
144 	default:
145 		break;
146 	}
147 
148 	return -ENOTSUP;
149 }
150