blob: 6c89944e9fa94661b8a33ae8dded8da9c6cac388 [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>
35#include <context_mgmt.h>
36#include <debug.h>
37#include <errno.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053038#include <tegra_private.h>
39
Varun Wadekar0f3baa02015-07-16 11:36:33 +053040#define NS_SWITCH_AARCH32 1
41#define SCR_RW_BITPOS __builtin_ctz(SCR_RW_BIT)
42
43/*******************************************************************************
Varun Wadekarcbdace12015-09-03 14:32:44 +053044 * Tegra132 SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053045 ******************************************************************************/
Varun Wadekar0f3baa02015-07-16 11:36:33 +053046#define TEGRA_SIP_AARCH_SWITCH 0x82000004
47
48/*******************************************************************************
49 * SPSR settings for AARCH32/AARCH64 modes
50 ******************************************************************************/
51#define SPSR32 SPSR_MODE32(MODE32_svc, SPSR_T_ARM, SPSR_E_LITTLE, \
52 DAIF_FIQ_BIT | DAIF_IRQ_BIT | DAIF_ABT_BIT)
53#define SPSR64 SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS)
Varun Wadekar7a269e22015-06-10 14:04:32 +053054
55/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080056 * This function is responsible for handling all T132 SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053057 ******************************************************************************/
Varun Wadekar923d04a2015-12-09 18:18:53 -080058int plat_sip_handler(uint32_t smc_fid,
59 uint64_t x1,
60 uint64_t x2,
61 uint64_t x3,
62 uint64_t x4,
63 void *cookie,
64 void *handle,
65 uint64_t flags)
Varun Wadekar7a269e22015-06-10 14:04:32 +053066{
Varun Wadekar7a269e22015-06-10 14:04:32 +053067 switch (smc_fid) {
68
Varun Wadekar0f3baa02015-07-16 11:36:33 +053069 case TEGRA_SIP_AARCH_SWITCH:
70
71 /* clean up the high bits */
72 x1 = (uint32_t)x1;
73 x2 = (uint32_t)x2;
74
75 if (!x1 || x2 > NS_SWITCH_AARCH32) {
76 ERROR("%s: invalid parameters\n", __func__);
Varun Wadekar923d04a2015-12-09 18:18:53 -080077 return -EINVAL;
Varun Wadekar0f3baa02015-07-16 11:36:33 +053078 }
79
80 /* x1 = ns entry point */
81 cm_set_elr_spsr_el3(NON_SECURE, x1,
82 (x2 == NS_SWITCH_AARCH32) ? SPSR32 : SPSR64);
83
84 /* switch NS world mode */
85 cm_write_scr_el3_bit(NON_SECURE, SCR_RW_BITPOS, !x2);
86
87 INFO("CPU switched to AARCH%s mode\n",
88 (x2 == NS_SWITCH_AARCH32) ? "32" : "64");
Varun Wadekar923d04a2015-12-09 18:18:53 -080089 return 0;
Varun Wadekar7a269e22015-06-10 14:04:32 +053090
91 default:
92 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
93 break;
94 }
95
Varun Wadekar923d04a2015-12-09 18:18:53 -080096 return -ENOTSUP;
Varun Wadekar7a269e22015-06-10 14:04:32 +053097}