Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 16 | #include <arch/io.h> |
Julius Werner | 96195ee | 2014-10-20 13:25:21 -0700 | [diff] [blame] | 17 | #include <console/console.h> |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 18 | #include <soc/addressmap.h> |
Julius Werner | 96195ee | 2014-10-20 13:25:21 -0700 | [diff] [blame] | 19 | #include <soc/clk_rst.h> |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 20 | #include <soc/cpu.h> |
Julius Werner | 96195ee | 2014-10-20 13:25:21 -0700 | [diff] [blame] | 21 | #include <soc/pmc.h> |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 22 | |
| 23 | #define EVP_CPU_RESET_VECTOR (void *)(uintptr_t)(TEGRA_EVP_BASE + 0x100) |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 24 | #define PMC_REGS (void *)(uintptr_t)(TEGRA_PMC_BASE) |
| 25 | |
| 26 | static void enable_core_clocks(int cpu) |
| 27 | { |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 28 | const uint32_t cpu0_clocks = CRC_RST_CPUG_CLR_CPU0 | |
| 29 | CRC_RST_CPUG_CLR_DBG0 | |
| 30 | CRC_RST_CPUG_CLR_CORE0 | |
| 31 | CRC_RST_CPUG_CLR_CX0; |
| 32 | const uint32_t cpu1_clocks = CRC_RST_CPUG_CLR_CPU1 | |
| 33 | CRC_RST_CPUG_CLR_DBG1 | |
| 34 | CRC_RST_CPUG_CLR_CORE1 | |
| 35 | CRC_RST_CPUG_CLR_CX1; |
| 36 | |
| 37 | /* Clear reset of CPU components. */ |
| 38 | if (cpu == 0) |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 39 | write32(CLK_RST_REG(rst_cpug_cmplx_clr), cpu0_clocks); |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 40 | else |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 41 | write32(CLK_RST_REG(rst_cpug_cmplx_clr), cpu1_clocks); |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void set_armv8_32bit_reset_vector(uintptr_t entry) |
| 45 | { |
| 46 | void * const evp_cpu_reset_vector = EVP_CPU_RESET_VECTOR; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 47 | write32(evp_cpu_reset_vector, entry); |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void set_armv8_64bit_reset_vector(uintptr_t entry) |
| 51 | { |
| 52 | struct tegra_pmc_regs * const pmc = PMC_REGS; |
| 53 | |
| 54 | /* Currently assume 32-bit addresses only. */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 55 | write32(&pmc->secure_scratch34, entry); |
| 56 | write32(&pmc->secure_scratch35, 0); |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Aaron Durbin | d806090 | 2014-11-25 16:47:56 -0600 | [diff] [blame] | 59 | void cpu_prepare_startup(void *entry_64) |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 60 | { |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 61 | /* Warm reset vector is pulled from the PMC scratch registers. */ |
| 62 | set_armv8_64bit_reset_vector((uintptr_t)entry_64); |
| 63 | |
| 64 | /* |
| 65 | * The Denver cores start in 32-bit mode. Therefore a trampoline |
| 66 | * is needed to get into 64-bit mode. Point the cold reset vector |
| 67 | * to the traompoline location. |
| 68 | */ |
| 69 | set_armv8_32bit_reset_vector((uintptr_t)reset_entry_32bit); |
Aaron Durbin | d806090 | 2014-11-25 16:47:56 -0600 | [diff] [blame] | 70 | } |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 71 | |
Aaron Durbin | d806090 | 2014-11-25 16:47:56 -0600 | [diff] [blame] | 72 | void start_cpu_silent(int cpu, void *entry_64) |
| 73 | { |
| 74 | cpu_prepare_startup(entry_64); |
Aaron Durbin | 4058d7b | 2014-08-22 10:24:27 -0500 | [diff] [blame] | 75 | enable_core_clocks(cpu); |
| 76 | } |
Aaron Durbin | d806090 | 2014-11-25 16:47:56 -0600 | [diff] [blame] | 77 | |
| 78 | void start_cpu(int cpu, void *entry_64) |
| 79 | { |
| 80 | printk(BIOS_DEBUG, "Starting CPU%d @ %p trampolining to %p.\n", |
| 81 | cpu, reset_entry_32bit, entry_64); |
| 82 | |
| 83 | start_cpu_silent(cpu, entry_64); |
| 84 | } |