blob: 76a65df42d10f2968de89c8e935215ab1da11977 [file] [log] [blame]
Thomas Gleixner9c92ab62019-05-29 07:17:56 -07001// SPDX-License-Identifier: GPL-2.0-only
Peter De Schrijverb36ab972012-02-10 01:47:45 +02002/*
3 * arch/arm/mach-tegra/reset.c
4 *
5 * Copyright (C) 2011,2012 NVIDIA Corporation.
Peter De Schrijverb36ab972012-02-10 01:47:45 +02006 */
7
Thierry Redinga0524ac2014-07-11 09:44:49 +02008#include <linux/bitops.h>
9#include <linux/cpumask.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020010#include <linux/init.h>
11#include <linux/io.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020012
Thierry Reding4cb5d9e2019-04-10 10:47:28 +020013#include <linux/firmware/trusted_foundations.h>
14
Thierry Reding304664e2014-07-11 09:52:41 +020015#include <soc/tegra/fuse.h>
16
Peter De Schrijverb36ab972012-02-10 01:47:45 +020017#include <asm/cacheflush.h>
Alexandre Courbot265c89c2013-11-24 15:30:51 +090018#include <asm/firmware.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020019#include <asm/hardware/cache-l2x0.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020020
Stephen Warren2be39c02012-10-04 14:24:09 -060021#include "iomap.h"
Stephen Warrenbb1de882012-10-04 14:16:59 -060022#include "irammap.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020023#include "reset.h"
Joseph Lod3f29362012-10-31 17:41:16 +080024#include "sleep.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020025
26#define TEGRA_IRAM_RESET_BASE (TEGRA_IRAM_BASE + \
27 TEGRA_IRAM_RESET_HANDLER_OFFSET)
28
29static bool is_enabled;
30
Alexandre Courbotad14ece2013-11-24 15:30:50 +090031static void __init tegra_cpu_reset_handler_set(const u32 reset_address)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020032{
Peter De Schrijverb36ab972012-02-10 01:47:45 +020033 void __iomem *evp_cpu_reset =
34 IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE + 0x100);
35 void __iomem *sb_ctrl = IO_ADDRESS(TEGRA_SB_BASE);
36 u32 reg;
37
Peter De Schrijverb36ab972012-02-10 01:47:45 +020038 /*
39 * NOTE: This must be the one and only write to the EVP CPU reset
40 * vector in the entire system.
41 */
Alexandre Courbotad14ece2013-11-24 15:30:50 +090042 writel(reset_address, evp_cpu_reset);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020043 wmb();
44 reg = readl(evp_cpu_reset);
45
46 /*
47 * Prevent further modifications to the physical reset vector.
48 * NOTE: Has no effect on chips prior to Tegra30.
49 */
Thierry Redingc090e112014-07-11 11:06:20 +020050 reg = readl(sb_ctrl);
51 reg |= 2;
52 writel(reg, sb_ctrl);
53 wmb();
Alexandre Courbotad14ece2013-11-24 15:30:50 +090054}
55
56static void __init tegra_cpu_reset_handler_enable(void)
57{
58 void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_RESET_BASE);
59 const u32 reset_address = TEGRA_IRAM_RESET_BASE +
60 tegra_cpu_reset_handler_offset;
Alexandre Courbot265c89c2013-11-24 15:30:51 +090061 int err;
Alexandre Courbotad14ece2013-11-24 15:30:50 +090062
63 BUG_ON(is_enabled);
64 BUG_ON(tegra_cpu_reset_handler_size > TEGRA_IRAM_RESET_HANDLER_SIZE);
65
66 memcpy(iram_base, (void *)__tegra_cpu_reset_handler_start,
67 tegra_cpu_reset_handler_size);
68
Alexandre Courbot265c89c2013-11-24 15:30:51 +090069 err = call_firmware_op(set_cpu_boot_addr, 0, reset_address);
70 switch (err) {
71 case -ENOSYS:
72 tegra_cpu_reset_handler_set(reset_address);
Gustavo A. R. Silva9b76ad32019-07-28 18:10:21 -050073 /* fall through */
Alexandre Courbot265c89c2013-11-24 15:30:51 +090074 case 0:
75 is_enabled = true;
76 break;
77 default:
78 pr_crit("Cannot set CPU reset handler: %d\n", err);
79 BUG();
80 }
Peter De Schrijverb36ab972012-02-10 01:47:45 +020081}
82
83void __init tegra_cpu_reset_handler_init(void)
84{
Dmitry Osipenko2af65972019-03-18 01:52:08 +030085 __tegra_cpu_reset_handler_data[TEGRA_RESET_TF_PRESENT] =
86 trusted_foundations_registered();
Peter De Schrijverb36ab972012-02-10 01:47:45 +020087
88#ifdef CONFIG_SMP
89 __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] =
Joseph Lo9e323662013-01-04 17:32:22 +080090 *((u32 *)cpu_possible_mask);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020091 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_SECONDARY] =
Florian Fainelli64fc2a92017-01-15 03:59:29 +010092 __pa_symbol((void *)secondary_startup);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020093#endif
94
Joseph Lod3f29362012-10-31 17:41:16 +080095#ifdef CONFIG_PM_SLEEP
Joseph Lo5b795d02013-08-12 17:40:00 +080096 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP1] =
Stephen Warrenfddb7702013-08-20 16:19:15 -060097 TEGRA_IRAM_LPx_RESUME_AREA;
Joseph Lod3f29362012-10-31 17:41:16 +080098 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP2] =
Florian Fainelli64fc2a92017-01-15 03:59:29 +010099 __pa_symbol((void *)tegra_resume);
Joseph Lod3f29362012-10-31 17:41:16 +0800100#endif
101
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200102 tegra_cpu_reset_handler_enable();
103}