blob: 1cb14add0abf42c690b925e58c632a67f8bcdf89 [file] [log] [blame]
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07001/*
Jeetesh Burman254b57d2018-07-06 19:58:30 +05302 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Anthony Zhou9de77f62019-11-13 18:36:07 +08007#include <assert.h>
8#include <string.h>
9
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070010#include <arch_helpers.h>
11#include <common/debug.h>
12#include <lib/mmio.h>
Anthony Zhou9de77f62019-11-13 18:36:07 +080013
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070014#include <mce.h>
Varun Wadekare0c222f2017-11-10 13:23:34 -080015#include <tegra194_private.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070016#include <tegra_def.h>
17#include <tegra_private.h>
18
Jeetesh Burman254b57d2018-07-06 19:58:30 +053019extern uint64_t tegra_bl31_phys_base;
20
Anthony Zhou8bf6d4e2017-09-20 17:44:43 +080021#define MISCREG_AA64_RST_LOW 0x2004U
22#define MISCREG_AA64_RST_HIGH 0x2008U
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070023
Anthony Zhou8bf6d4e2017-09-20 17:44:43 +080024#define CPU_RESET_MODE_AA64 1U
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070025
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070026/*******************************************************************************
27 * Setup secondary CPU vectors
28 ******************************************************************************/
29void plat_secondary_setup(void)
30{
31 uint32_t addr_low, addr_high;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070032 plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
Jeetesh Burman254b57d2018-07-06 19:58:30 +053033 uint64_t cpu_reset_handler_base, cpu_reset_handler_size, tzdram_addr;
34 uint64_t src_len_bytes = BL_END - tegra_bl31_phys_base;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070035
36 INFO("Setting up secondary CPU boot\n");
37
Jeetesh Burman254b57d2018-07-06 19:58:30 +053038 tzdram_addr = params_from_bl2->tzdram_base +
39 tegra194_get_cpu_reset_handler_size();
40
Varun Wadekare0c222f2017-11-10 13:23:34 -080041 /*
42 * The BL31 code resides in the TZSRAM which loses state
43 * when we enter System Suspend. Copy the wakeup trampoline
44 * code to TZDRAM to help us exit from System Suspend.
45 */
46 cpu_reset_handler_base = tegra194_get_cpu_reset_handler_base();
47 cpu_reset_handler_size = tegra194_get_cpu_reset_handler_size();
48 memcpy((void *)((uintptr_t)params_from_bl2->tzdram_base),
49 (void *)((uintptr_t)cpu_reset_handler_base),
50 cpu_reset_handler_size);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070051
Varun Wadekare0c222f2017-11-10 13:23:34 -080052 /* TZDRAM base will be used as the "resume" address */
53 addr_low = (uint32_t)params_from_bl2->tzdram_base | CPU_RESET_MODE_AA64;
54 addr_high = (uint32_t)((params_from_bl2->tzdram_base >> 32U) & 0x7ffU);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070055
56 /* write lower 32 bits first, then the upper 11 bits */
57 mmio_write_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_LOW, addr_low);
Anthony Zhou9de77f62019-11-13 18:36:07 +080058 assert(mmio_read_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_LOW) == addr_low);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070059 mmio_write_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_HIGH, addr_high);
Anthony Zhou9de77f62019-11-13 18:36:07 +080060 assert(mmio_read_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_HIGH) == addr_high);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070061
62 /* save reset vector to be used during SYSTEM_SUSPEND exit */
Steven Kao4607f172017-10-23 18:35:14 +080063 mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_LO,
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070064 addr_low);
Anthony Zhou9de77f62019-11-13 18:36:07 +080065 assert(mmio_read_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_LO) == addr_low);
Steven Kao4607f172017-10-23 18:35:14 +080066 mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_HI,
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070067 addr_high);
Anthony Zhou9de77f62019-11-13 18:36:07 +080068 assert(mmio_read_32(TEGRA_SCRATCH_BASE + SCRATCH_RESET_VECTOR_HI) == addr_high);
Jeetesh Burman254b57d2018-07-06 19:58:30 +053069 mmio_write_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV72_LO,
70 (uint32_t)tzdram_addr);
Anthony Zhou9de77f62019-11-13 18:36:07 +080071 assert(mmio_read_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV72_LO) == (uint32_t)tzdram_addr);
Jeetesh Burman254b57d2018-07-06 19:58:30 +053072 mmio_write_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV72_HI,
73 (uint32_t)src_len_bytes);
Anthony Zhou9de77f62019-11-13 18:36:07 +080074 assert(mmio_read_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV72_HI) == (uint32_t)src_len_bytes);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070075}