blob: 4ae7ef0fa99df1beb0d6ec7a484d7428bffef979 [file] [log] [blame]
Angel Pons57566302020-04-05 13:22:10 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Gabe Black5c8d3d22014-01-17 22:11:35 -08002
3#include <arch/cache.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -08004#include <arch/exception.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -08005#include <cbmem.h>
6#include <console/console.h>
Daisuke Nojiri512bfbc2014-08-15 17:07:39 -07007#include <reset.h>
Aaron Durbine4f3e7a2015-03-17 13:25:19 -05008#include <program_loading.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -07009#include <soc/addressmap.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070010#include <soc/cache.h>
11#include <soc/clk_rst.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070012#include <soc/clock.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080013#include <soc/display.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070014#include <soc/early_configs.h>
15#include <soc/nvidia/tegra/i2c.h>
16#include <soc/nvidia/tegra124/chip.h>
17#include <soc/power.h>
18#include <soc/sdram.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070019#include <symbols.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080020#include <timestamp.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070021
22#include "sdram_configs.h"
Gabe Black5c8d3d22014-01-17 22:11:35 -080023
Julius Wernerfd9defc2014-01-21 20:11:22 -080024static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -080025{
Kyösti Mälkkif48b38b2014-12-31 08:50:36 +020026 timestamp_init(0);
Jakub Czapigaad6157e2022-02-15 11:50:31 +010027 timestamp_add_now(TS_ROMSTAGE_START);
Gabe Black5c8d3d22014-01-17 22:11:35 -080028
Gabe Black5c8d3d22014-01-17 22:11:35 -080029 console_init();
30 exception_init();
31
Tom Warren64982c502014-01-23 13:37:50 -070032 sdram_init(get_sdram_config());
33
Gabe Black5cbbc702014-02-08 05:17:38 -080034 /* used for MMU and CBMEM setup, in MB */
Julius Wernerec5e5e02014-08-20 15:29:56 -070035 u32 dram_start_mb = (uintptr_t)_dram/MiB;
36 u32 dram_end_mb = sdram_max_addressable_mb();
37 u32 dram_size_mb = dram_end_mb - dram_start_mb;
Tom Warren64982c502014-01-23 13:37:50 -070038
Daisuke Nojiriefddcfb2014-09-04 09:55:34 -070039 configure_l2_cache();
Gabe Black5c8d3d22014-01-17 22:11:35 -080040 mmu_init();
Gabe Blackb9a4b712014-03-01 03:27:00 -080041 /* Device memory below DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070042 mmu_config_range(0, dram_start_mb, DCACHE_OFF);
43 /* SRAM is cached. MMU code will round size up to page size. */
Julius Werner7e0dea62019-02-20 18:39:22 -080044 mmu_config_range((uintptr_t)_sram/MiB,
45 DIV_ROUND_UP(REGION_SIZE(sram), MiB),
Julius Wernerec5e5e02014-08-20 15:29:56 -070046 DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080047 /* DRAM is cached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070048 mmu_config_range(dram_start_mb, dram_size_mb, DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080049 /* A window for DMA is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070050 mmu_config_range((uintptr_t)_dma_coherent/MiB,
Julius Werner7e0dea62019-02-20 18:39:22 -080051 REGION_SIZE(dma_coherent)/MiB, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -080052 /* The space above DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070053 if (dram_end_mb < 4096)
54 mmu_config_range(dram_end_mb, 4096 - dram_end_mb, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -080055 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -080056 dcache_mmu_enable();
57
Gabe Blackc8522062014-05-06 15:44:14 -070058 /*
59 * A watchdog reset only resets part of the system so it ends up in
60 * a funny state. If that happens, we need to reset the whole machine.
61 */
62 if (power_reset_status() == POWER_RESET_WATCHDOG) {
63 printk(BIOS_INFO, "Watchdog reset detected, rebooting.\n");
Nico Hubere8791362018-10-06 17:53:14 +020064 board_reset();
Gabe Blackc8522062014-05-06 15:44:14 -070065 }
66
Patrick Georgi3756de02015-06-30 14:32:15 +020067 /* FIXME: this may require coordination with moving timestamps */
Gabe Black5c8d3d22014-01-17 22:11:35 -080068 cbmem_initialize_empty();
69
Paul Kocialkowski7b0e0d92016-06-27 18:17:14 +020070 /* This was already called from verstage in vboot context. */
Julius Wernercd49cce2019-03-05 16:53:33 -080071 if (!CONFIG(VBOOT))
Paul Kocialkowski7b0e0d92016-06-27 18:17:14 +020072 early_mainboard_init();
Gabe Black4a12cfe2014-03-24 21:24:24 -070073
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050074 run_ramstage();
Gabe Black5c8d3d22014-01-17 22:11:35 -080075}
Julius Wernerfd9defc2014-01-21 20:11:22 -080076
77/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
78void main(void)
79{
Gabe Blackf220df62014-02-08 05:01:06 -080080 asm volatile ("bl arm_init_caches"
81 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -080082 romstage();
83}