blob: fa3974972e551ca01fb5271abfde1f12e4c24250 [file] [log] [blame]
Varun Wadekar921b9062015-08-25 17:03:14 +05301/*
Varun Wadekar59c3aa02015-09-09 11:33:08 +05302 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
Varun Wadekar921b9062015-08-25 17:03:14 +05303 *
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>
Varun Wadekard64db962016-09-23 14:28:16 -070037#include <denver.h>
Varun Wadekar921b9062015-08-25 17:03:14 +053038#include <errno.h>
Varun Wadekar59c3aa02015-09-09 11:33:08 +053039#include <mce.h>
Varun Wadekara7c1ea72016-02-03 09:51:25 -080040#include <memctrl.h>
Varun Wadekar921b9062015-08-25 17:03:14 +053041#include <runtime_svc.h>
Varun Wadekar59c3aa02015-09-09 11:33:08 +053042#include <t18x_ari.h>
Varun Wadekar921b9062015-08-25 17:03:14 +053043#include <tegra_private.h>
44
Varun Wadekard66ee542016-02-29 10:24:30 -080045extern uint32_t tegra186_system_powerdn_state;
46
Varun Wadekar921b9062015-08-25 17:03:14 +053047/*******************************************************************************
Varun Wadekard64db962016-09-23 14:28:16 -070048 * Offset to read the ref_clk counter value
49 ******************************************************************************/
50#define REF_CLK_OFFSET 4
51
52/*******************************************************************************
Varun Wadekar921b9062015-08-25 17:03:14 +053053 * Tegra186 SiP SMCs
54 ******************************************************************************/
Varun Wadekard66ee542016-02-29 10:24:30 -080055#define TEGRA_SIP_SYSTEM_SHUTDOWN_STATE 0x82FFFE01
Varun Wadekard64db962016-09-23 14:28:16 -070056#define TEGRA_SIP_GET_ACTMON_CLK_COUNTERS 0x82FFFE02
Varun Wadekar59c3aa02015-09-09 11:33:08 +053057#define TEGRA_SIP_MCE_CMD_ENTER_CSTATE 0x82FFFF00
58#define TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO 0x82FFFF01
59#define TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME 0x82FFFF02
60#define TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS 0x82FFFF03
61#define TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS 0x82FFFF04
62#define TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED 0x82FFFF05
63#define TEGRA_SIP_MCE_CMD_ONLINE_CORE 0x82FFFF06
64#define TEGRA_SIP_MCE_CMD_CC3_CTRL 0x82FFFF07
65#define TEGRA_SIP_MCE_CMD_ECHO_DATA 0x82FFFF08
66#define TEGRA_SIP_MCE_CMD_READ_VERSIONS 0x82FFFF09
67#define TEGRA_SIP_MCE_CMD_ENUM_FEATURES 0x82FFFF0A
68#define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS 0x82FFFF0B
69#define TEGRA_SIP_MCE_CMD_ENUM_READ_MCA 0x82FFFF0C
70#define TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA 0x82FFFF0D
71#define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE 0x82FFFF0E
72#define TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE 0x82FFFF0F
Varun Wadekarad2824f2016-03-28 13:44:35 -070073#define TEGRA_SIP_MCE_CMD_ENABLE_LATIC 0x82FFFF10
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070074#define TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ 0x82FFFF11
Krishna Sitaramanb429d562016-07-19 16:36:13 -070075#define TEGRA_SIP_MCE_CMD_MISC_CCPLEX 0x82FFFF12
Varun Wadekar921b9062015-08-25 17:03:14 +053076
77/*******************************************************************************
Varun Wadekar59c3aa02015-09-09 11:33:08 +053078 * This function is responsible for handling all T186 SiP calls
Varun Wadekar921b9062015-08-25 17:03:14 +053079 ******************************************************************************/
Varun Wadekar59c3aa02015-09-09 11:33:08 +053080int plat_sip_handler(uint32_t smc_fid,
81 uint64_t x1,
82 uint64_t x2,
83 uint64_t x3,
84 uint64_t x4,
85 void *cookie,
86 void *handle,
87 uint64_t flags)
Varun Wadekar921b9062015-08-25 17:03:14 +053088{
Varun Wadekar59c3aa02015-09-09 11:33:08 +053089 int mce_ret;
Varun Wadekard64db962016-09-23 14:28:16 -070090 int impl, cpu;
91 uint32_t base, core_clk_ctr, ref_clk_ctr;
Varun Wadekar921b9062015-08-25 17:03:14 +053092
93 switch (smc_fid) {
94
Varun Wadekar59c3aa02015-09-09 11:33:08 +053095 /*
96 * Micro Coded Engine (MCE) commands reside in the 0x82FFFF00 -
97 * 0x82FFFFFF SiP SMC space
98 */
99 case TEGRA_SIP_MCE_CMD_ENTER_CSTATE:
100 case TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO:
101 case TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME:
102 case TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS:
103 case TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS:
104 case TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED:
105 case TEGRA_SIP_MCE_CMD_CC3_CTRL:
106 case TEGRA_SIP_MCE_CMD_ECHO_DATA:
107 case TEGRA_SIP_MCE_CMD_READ_VERSIONS:
108 case TEGRA_SIP_MCE_CMD_ENUM_FEATURES:
109 case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
110 case TEGRA_SIP_MCE_CMD_ENUM_READ_MCA:
111 case TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA:
112 case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE:
113 case TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE:
Varun Wadekarad2824f2016-03-28 13:44:35 -0700114 case TEGRA_SIP_MCE_CMD_ENABLE_LATIC:
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700115 case TEGRA_SIP_MCE_CMD_UNCORE_PERFMON_REQ:
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700116 case TEGRA_SIP_MCE_CMD_MISC_CCPLEX:
Varun Wadekar921b9062015-08-25 17:03:14 +0530117
118 /* clean up the high bits */
Varun Wadekar59c3aa02015-09-09 11:33:08 +0530119 smc_fid &= MCE_CMD_MASK;
Varun Wadekar921b9062015-08-25 17:03:14 +0530120
Varun Wadekar59c3aa02015-09-09 11:33:08 +0530121 /* execute the command and store the result */
122 mce_ret = mce_command_handler(smc_fid, x1, x2, x3);
123 write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X0, mce_ret);
Varun Wadekar921b9062015-08-25 17:03:14 +0530124
Varun Wadekar59c3aa02015-09-09 11:33:08 +0530125 return 0;
Varun Wadekar921b9062015-08-25 17:03:14 +0530126
Varun Wadekard66ee542016-02-29 10:24:30 -0800127 case TEGRA_SIP_SYSTEM_SHUTDOWN_STATE:
128
129 /* clean up the high bits */
130 x1 = (uint32_t)x1;
131
132 /*
133 * SC8 is a special Tegra186 system state where the CPUs and
134 * DRAM are powered down but the other subsystem is still
135 * alive.
136 */
137 if ((x1 == TEGRA_ARI_SYSTEM_SC8) ||
138 (x1 == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF)) {
139
140 tegra186_system_powerdn_state = x1;
141 flush_dcache_range(
142 (uintptr_t)&tegra186_system_powerdn_state,
143 sizeof(tegra186_system_powerdn_state));
144
145 } else {
146
147 ERROR("%s: unhandled powerdn state (%d)\n", __func__,
148 (uint32_t)x1);
149 return -ENOTSUP;
150 }
151
152 return 0;
153
Varun Wadekard64db962016-09-23 14:28:16 -0700154 /*
155 * This function ID reads the Activity monitor's core/ref clock
156 * counter values for a core/cluster.
157 *
158 * x1 = MPIDR of the target core
159 * x2 = MIDR of the target core
160 */
161 case TEGRA_SIP_GET_ACTMON_CLK_COUNTERS:
162
163 cpu = (uint32_t)x1 & MPIDR_CPU_MASK;
164 impl = ((uint32_t)x2 >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
165
166 /* sanity check target CPU number */
167 if (cpu > PLATFORM_MAX_CPUS_PER_CLUSTER)
168 return -EINVAL;
169
170 /* get the base address for the current CPU */
171 base = (impl == DENVER_IMPL) ? TEGRA_DENVER_ACTMON_CTR_BASE :
172 TEGRA_ARM_ACTMON_CTR_BASE;
173
174 /* read the clock counter values */
175 core_clk_ctr = mmio_read_32(base + (8 * cpu));
176 ref_clk_ctr = mmio_read_32(base + (8 * cpu) + REF_CLK_OFFSET);
177
178 /* return the counter values as two different parameters */
179 write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X1, core_clk_ctr);
180 write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X2, ref_clk_ctr);
181
182 return 0;
183
Varun Wadekar921b9062015-08-25 17:03:14 +0530184 default:
Varun Wadekar921b9062015-08-25 17:03:14 +0530185 break;
186 }
187
Varun Wadekar59c3aa02015-09-09 11:33:08 +0530188 return -ENOTSUP;
Varun Wadekar921b9062015-08-25 17:03:14 +0530189}