blob: 2dd4c2d8bdca1f8ce65741d311aa3504fc54e089 [file] [log] [blame]
Gabe Black5c8d3d22014-01-17 22:11:35 -08001/*
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.
Gabe Black5c8d3d22014-01-17 22:11:35 -080014 */
15
16#include <arch/cache.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080017#include <arch/exception.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070018#include <arch/io.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080019#include <cbmem.h>
20#include <console/console.h>
Daisuke Nojiri512bfbc2014-08-15 17:07:39 -070021#include <reset.h>
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050022#include <program_loading.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070023#include <soc/addressmap.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070024#include <soc/cache.h>
25#include <soc/clk_rst.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070026#include <soc/clock.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080027#include <soc/display.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070028#include <soc/early_configs.h>
29#include <soc/nvidia/tegra/i2c.h>
30#include <soc/nvidia/tegra124/chip.h>
31#include <soc/power.h>
32#include <soc/sdram.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070033#include <symbols.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080034#include <timestamp.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070035
36#include "sdram_configs.h"
Gabe Black5c8d3d22014-01-17 22:11:35 -080037
Julius Wernerfd9defc2014-01-21 20:11:22 -080038static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -080039{
Kyösti Mälkkif48b38b2014-12-31 08:50:36 +020040 timestamp_init(0);
41 timestamp_add_now(TS_START_ROMSTAGE);
Gabe Black5c8d3d22014-01-17 22:11:35 -080042
Gabe Black5c8d3d22014-01-17 22:11:35 -080043 console_init();
44 exception_init();
45
Tom Warren64982c502014-01-23 13:37:50 -070046 sdram_init(get_sdram_config());
47
Gabe Black5cbbc702014-02-08 05:17:38 -080048 /* used for MMU and CBMEM setup, in MB */
Julius Wernerec5e5e02014-08-20 15:29:56 -070049 u32 dram_start_mb = (uintptr_t)_dram/MiB;
50 u32 dram_end_mb = sdram_max_addressable_mb();
51 u32 dram_size_mb = dram_end_mb - dram_start_mb;
Tom Warren64982c502014-01-23 13:37:50 -070052
Daisuke Nojiriefddcfb2014-09-04 09:55:34 -070053 configure_l2_cache();
Gabe Black5c8d3d22014-01-17 22:11:35 -080054 mmu_init();
Gabe Blackb9a4b712014-03-01 03:27:00 -080055 /* Device memory below DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070056 mmu_config_range(0, dram_start_mb, DCACHE_OFF);
57 /* SRAM is cached. MMU code will round size up to page size. */
Julius Werner7e0dea62019-02-20 18:39:22 -080058 mmu_config_range((uintptr_t)_sram/MiB,
59 DIV_ROUND_UP(REGION_SIZE(sram), MiB),
Julius Wernerec5e5e02014-08-20 15:29:56 -070060 DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080061 /* DRAM is cached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070062 mmu_config_range(dram_start_mb, dram_size_mb, DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080063 /* A window for DMA is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070064 mmu_config_range((uintptr_t)_dma_coherent/MiB,
Julius Werner7e0dea62019-02-20 18:39:22 -080065 REGION_SIZE(dma_coherent)/MiB, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -080066 /* The space above DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070067 if (dram_end_mb < 4096)
68 mmu_config_range(dram_end_mb, 4096 - dram_end_mb, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -080069 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -080070 dcache_mmu_enable();
71
Gabe Blackc8522062014-05-06 15:44:14 -070072 /*
73 * A watchdog reset only resets part of the system so it ends up in
74 * a funny state. If that happens, we need to reset the whole machine.
75 */
76 if (power_reset_status() == POWER_RESET_WATCHDOG) {
77 printk(BIOS_INFO, "Watchdog reset detected, rebooting.\n");
Nico Hubere8791362018-10-06 17:53:14 +020078 board_reset();
Gabe Blackc8522062014-05-06 15:44:14 -070079 }
80
Patrick Georgi3756de02015-06-30 14:32:15 +020081 /* FIXME: this may require coordination with moving timestamps */
Gabe Black5c8d3d22014-01-17 22:11:35 -080082 cbmem_initialize_empty();
83
Paul Kocialkowski7b0e0d92016-06-27 18:17:14 +020084 /* This was already called from verstage in vboot context. */
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070085 if (!IS_ENABLED(CONFIG_VBOOT))
Paul Kocialkowski7b0e0d92016-06-27 18:17:14 +020086 early_mainboard_init();
Gabe Black4a12cfe2014-03-24 21:24:24 -070087
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050088 run_ramstage();
Gabe Black5c8d3d22014-01-17 22:11:35 -080089}
Julius Wernerfd9defc2014-01-21 20:11:22 -080090
91/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
92void main(void)
93{
Gabe Blackf220df62014-02-08 05:01:06 -080094 asm volatile ("bl arm_init_caches"
95 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -080096 romstage();
97}