blob: 8417374ad15f1de281bdac43b80b14999c9c54c9 [file] [log] [blame]
Varun Wadekar3cf31832015-08-25 17:03:14 +05301/*
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Varun Wadekar8336c942018-08-09 15:11:23 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar3cf31832015-08-25 17:03:14 +05304 *
dp-arm82cb2c12017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar3cf31832015-08-25 17:03:14 +05306 */
7
Varun Wadekar68c7de62016-03-18 13:07:33 -07008#include <string.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/debug.h>
12#include <lib/mmio.h>
13
14#include <mce.h>
Varun Wadekar71915662017-10-25 11:52:07 -070015#include <tegra186_private.h>
Varun Wadekarb47d97b2015-09-14 09:31:39 +053016#include <tegra_def.h>
Varun Wadekar68c7de62016-03-18 13:07:33 -070017#include <tegra_private.h>
Varun Wadekarb47d97b2015-09-14 09:31:39 +053018
Anthony Zhou592035d2017-03-21 15:50:09 +080019#define SCRATCH_SECURE_RSV1_SCRATCH_0 0x658U
20#define SCRATCH_SECURE_RSV1_SCRATCH_1 0x65CU
Varun Wadekarb47d97b2015-09-14 09:31:39 +053021
Anthony Zhou592035d2017-03-21 15:50:09 +080022#define CPU_RESET_MODE_AA64 1U
Varun Wadekarb47d97b2015-09-14 09:31:39 +053023
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +010024extern void memcpy16(void *dest, const void *src, unsigned int length);
25
Varun Wadekar3cf31832015-08-25 17:03:14 +053026/*******************************************************************************
27 * Setup secondary CPU vectors
28 ******************************************************************************/
29void plat_secondary_setup(void)
30{
Varun Wadekarb47d97b2015-09-14 09:31:39 +053031 uint32_t addr_low, addr_high;
Anthony Zhou592035d2017-03-21 15:50:09 +080032 const plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
Varun Wadekar71915662017-10-25 11:52:07 -070033 uint64_t cpu_reset_handler_base, cpu_reset_handler_size;
Varun Wadekarb47d97b2015-09-14 09:31:39 +053034
35 INFO("Setting up secondary CPU boot\n");
36
Varun Wadekar71915662017-10-25 11:52:07 -070037 /*
38 * The BL31 code resides in the TZSRAM which loses state
39 * when we enter System Suspend. Copy the wakeup trampoline
40 * code to TZDRAM to help us exit from System Suspend.
41 */
42 cpu_reset_handler_base = tegra186_get_cpu_reset_handler_base();
43 cpu_reset_handler_size = tegra186_get_cpu_reset_handler_size();
44 (void)memcpy16((void *)(uintptr_t)params_from_bl2->tzdram_base,
45 (const void *)(uintptr_t)cpu_reset_handler_base,
46 cpu_reset_handler_size);
Varun Wadekar68c7de62016-03-18 13:07:33 -070047
Varun Wadekar71915662017-10-25 11:52:07 -070048 /* TZDRAM base will be used as the "resume" address */
49 addr_low = (uint32_t)params_from_bl2->tzdram_base | CPU_RESET_MODE_AA64;
50 addr_high = (uint32_t)((params_from_bl2->tzdram_base >> 32U) & 0x7ffU);
Varun Wadekarb47d97b2015-09-14 09:31:39 +053051
Varun Wadekarb47d97b2015-09-14 09:31:39 +053052 /* save reset vector to be used during SYSTEM_SUSPEND exit */
Steven Kao601a8e52017-10-23 18:22:09 +080053 mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_LO,
Varun Wadekarb47d97b2015-09-14 09:31:39 +053054 addr_low);
Steven Kao601a8e52017-10-23 18:22:09 +080055 mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_HI,
Varun Wadekarb47d97b2015-09-14 09:31:39 +053056 addr_high);
Varun Wadekar3cf31832015-08-25 17:03:14 +053057}