Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * arch/arm/mach-tegra/reset.c |
| 4 | * |
| 5 | * Copyright (C) 2011,2012 NVIDIA Corporation. |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 8 | #include <linux/bitops.h> |
| 9 | #include <linux/cpumask.h> |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/io.h> |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 12 | |
Thierry Reding | 4cb5d9e | 2019-04-10 10:47:28 +0200 | [diff] [blame] | 13 | #include <linux/firmware/trusted_foundations.h> |
| 14 | |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 15 | #include <soc/tegra/fuse.h> |
| 16 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 17 | #include <asm/cacheflush.h> |
Alexandre Courbot | 265c89c | 2013-11-24 15:30:51 +0900 | [diff] [blame] | 18 | #include <asm/firmware.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 19 | #include <asm/hardware/cache-l2x0.h> |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 20 | |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 21 | #include "iomap.h" |
Stephen Warren | bb1de88 | 2012-10-04 14:16:59 -0600 | [diff] [blame] | 22 | #include "irammap.h" |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 23 | #include "reset.h" |
Joseph Lo | d3f2936 | 2012-10-31 17:41:16 +0800 | [diff] [blame] | 24 | #include "sleep.h" |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 25 | |
| 26 | #define TEGRA_IRAM_RESET_BASE (TEGRA_IRAM_BASE + \ |
| 27 | TEGRA_IRAM_RESET_HANDLER_OFFSET) |
| 28 | |
| 29 | static bool is_enabled; |
| 30 | |
Alexandre Courbot | ad14ece | 2013-11-24 15:30:50 +0900 | [diff] [blame] | 31 | static void __init tegra_cpu_reset_handler_set(const u32 reset_address) |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 32 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 33 | 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 Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 38 | /* |
| 39 | * NOTE: This must be the one and only write to the EVP CPU reset |
| 40 | * vector in the entire system. |
| 41 | */ |
Alexandre Courbot | ad14ece | 2013-11-24 15:30:50 +0900 | [diff] [blame] | 42 | writel(reset_address, evp_cpu_reset); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 43 | 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 Reding | c090e11 | 2014-07-11 11:06:20 +0200 | [diff] [blame] | 50 | reg = readl(sb_ctrl); |
| 51 | reg |= 2; |
| 52 | writel(reg, sb_ctrl); |
| 53 | wmb(); |
Alexandre Courbot | ad14ece | 2013-11-24 15:30:50 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static 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 Courbot | 265c89c | 2013-11-24 15:30:51 +0900 | [diff] [blame] | 61 | int err; |
Alexandre Courbot | ad14ece | 2013-11-24 15:30:50 +0900 | [diff] [blame] | 62 | |
| 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 Courbot | 265c89c | 2013-11-24 15:30:51 +0900 | [diff] [blame] | 69 | 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. Silva | 9b76ad3 | 2019-07-28 18:10:21 -0500 | [diff] [blame] | 73 | /* fall through */ |
Alexandre Courbot | 265c89c | 2013-11-24 15:30:51 +0900 | [diff] [blame] | 74 | 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 Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void __init tegra_cpu_reset_handler_init(void) |
| 84 | { |
Dmitry Osipenko | 2af6597 | 2019-03-18 01:52:08 +0300 | [diff] [blame] | 85 | __tegra_cpu_reset_handler_data[TEGRA_RESET_TF_PRESENT] = |
| 86 | trusted_foundations_registered(); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 87 | |
| 88 | #ifdef CONFIG_SMP |
| 89 | __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] = |
Joseph Lo | 9e32366 | 2013-01-04 17:32:22 +0800 | [diff] [blame] | 90 | *((u32 *)cpu_possible_mask); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 91 | __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_SECONDARY] = |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 92 | __pa_symbol((void *)secondary_startup); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 93 | #endif |
| 94 | |
Joseph Lo | d3f2936 | 2012-10-31 17:41:16 +0800 | [diff] [blame] | 95 | #ifdef CONFIG_PM_SLEEP |
Joseph Lo | 5b795d0 | 2013-08-12 17:40:00 +0800 | [diff] [blame] | 96 | __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP1] = |
Stephen Warren | fddb770 | 2013-08-20 16:19:15 -0600 | [diff] [blame] | 97 | TEGRA_IRAM_LPx_RESUME_AREA; |
Joseph Lo | d3f2936 | 2012-10-31 17:41:16 +0800 | [diff] [blame] | 98 | __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP2] = |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 99 | __pa_symbol((void *)tegra_resume); |
Joseph Lo | d3f2936 | 2012-10-31 17:41:16 +0800 | [diff] [blame] | 100 | #endif |
| 101 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 102 | tegra_cpu_reset_handler_enable(); |
| 103 | } |