blob: 4dd43532b93fd2d415a69879e3c647f1d4720df1 [file] [log] [blame]
Varun Wadekar7a269e22015-06-10 14:04:32 +05301/*
2 * Copyright (c) 2015, 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
Varun Wadekar0f3baa02015-07-16 11:36:33 +053031#include <arch.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053032#include <arch_helpers.h>
33#include <assert.h>
34#include <bl_common.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053035#include <debug.h>
36#include <errno.h>
37#include <memctrl.h>
38#include <runtime_svc.h>
39#include <tegra_private.h>
40
Varun Wadekar0f3baa02015-07-16 11:36:33 +053041/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080042 * Common Tegra SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053043 ******************************************************************************/
Varun Wadekar7a269e22015-06-10 14:04:32 +053044#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003
Varun Wadekardc799302015-12-28 16:36:42 -080045#define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005
46#define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006
Varun Wadekar7a269e22015-06-10 14:04:32 +053047
48/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080049 * SoC specific SiP handler
50 ******************************************************************************/
51#pragma weak plat_sip_handler
52int plat_sip_handler(uint32_t smc_fid,
53 uint64_t x1,
54 uint64_t x2,
55 uint64_t x3,
56 uint64_t x4,
57 void *cookie,
58 void *handle,
59 uint64_t flags)
60{
61 return -ENOTSUP;
62}
63
64/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070065 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053066 ******************************************************************************/
Varun Wadekar923d04a2015-12-09 18:18:53 -080067uint64_t tegra_sip_handler(uint32_t smc_fid,
Varun Wadekar7a269e22015-06-10 14:04:32 +053068 uint64_t x1,
69 uint64_t x2,
70 uint64_t x3,
71 uint64_t x4,
72 void *cookie,
73 void *handle,
74 uint64_t flags)
75{
Varun Wadekar7a269e22015-06-10 14:04:32 +053076 int err;
77
Varun Wadekar923d04a2015-12-09 18:18:53 -080078 /* Check if this is a SoC specific SiP */
79 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
80 if (err == 0)
81 SMC_RET1(handle, err);
82
Varun Wadekar7a269e22015-06-10 14:04:32 +053083 switch (smc_fid) {
84
85 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
86
Varun Wadekar0f3baa02015-07-16 11:36:33 +053087 /* clean up the high bits */
Varun Wadekar0f3baa02015-07-16 11:36:33 +053088 x2 = (uint32_t)x2;
89
Varun Wadekar7a269e22015-06-10 14:04:32 +053090 /*
91 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
92 * or falls outside of the valid DRAM range
93 */
94 err = bl31_check_ns_address(x1, x2);
95 if (err)
96 SMC_RET1(handle, err);
97
98 /*
99 * Check if Video Memory is aligned to 1MB.
100 */
101 if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) {
102 ERROR("Unaligned Video Memory base address!\n");
103 SMC_RET1(handle, -ENOTSUP);
104 }
105
106 /* new video memory carveout settings */
107 tegra_memctrl_videomem_setup(x1, x2);
108
109 SMC_RET1(handle, 0);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530110 break;
Varun Wadekar7a269e22015-06-10 14:04:32 +0530111
Varun Wadekardc799302015-12-28 16:36:42 -0800112 /*
113 * The NS world registers the address of its handler to be
114 * used for processing the FIQ. This is normally used by the
115 * NS FIQ debugger driver to detect system hangs by programming
116 * a watchdog timer to fire a FIQ interrupt.
117 */
118 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
119
120 if (!x1)
121 SMC_RET1(handle, SMC_UNK);
122
123 /*
124 * TODO: Check if x1 contains a valid DRAM address
125 */
126
127 /* store the NS world's entrypoint */
128 tegra_fiq_set_ns_entrypoint(x1);
129
130 SMC_RET1(handle, 0);
131 break;
132
133 /*
134 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
135 * CPU context when the FIQ interrupt was triggered. This allows the
136 * NS world to understand the CPU state when the watchdog interrupt
137 * triggered.
138 */
139 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
140
141 /* retrieve context registers when FIQ triggered */
142 tegra_fiq_get_intr_context();
143
144 SMC_RET0(handle);
145 break;
146
Varun Wadekar7a269e22015-06-10 14:04:32 +0530147 default:
148 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
149 break;
150 }
151
152 SMC_RET1(handle, SMC_UNK);
153}
154
155/* Define a runtime service descriptor for fast SMC calls */
156DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800157 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530158
159 OEN_SIP_START,
160 OEN_SIP_END,
161 SMC_TYPE_FAST,
162 NULL,
Varun Wadekar923d04a2015-12-09 18:18:53 -0800163 tegra_sip_handler
Varun Wadekar7a269e22015-06-10 14:04:32 +0530164);