blob: f2077bbb274a179f4e7b2ab2dc0dc375ca864919 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <arch/cache.h>
21#include <arch/cpu.h>
22#include <arch/exception.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070023#include <arch/io.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080024#include <cbfs.h>
25#include <cbmem.h>
26#include <console/console.h>
Daisuke Nojiri512bfbc2014-08-15 17:07:39 -070027#include <reset.h>
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050028#include <program_loading.h>
Aaron Durbincad7c4e2014-03-20 15:08:54 -050029#include <romstage_handoff.h>
30#include <vendorcode/google/chromeos/chromeos.h>
Tom Warren64982c502014-01-23 13:37:50 -070031#include "sdram_configs.h"
Gabe Black4a12cfe2014-03-24 21:24:24 -070032#include <soc/nvidia/tegra/i2c.h>
Daisuke Nojiri1b05d882014-08-27 11:48:03 -070033#include <soc/nvidia/tegra124/cache.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070034#include <soc/nvidia/tegra124/chip.h>
35#include <soc/nvidia/tegra124/clk_rst.h>
Daisuke Nojiri1b05d882014-08-27 11:48:03 -070036#include <soc/nvidia/tegra124/early_configs.h>
Gabe Blackc8522062014-05-06 15:44:14 -070037#include <soc/nvidia/tegra124/power.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070038#include <soc/nvidia/tegra124/sdram.h>
39#include <soc/addressmap.h>
40#include <soc/clock.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080041#include <soc/display.h>
Julius Wernerec5e5e02014-08-20 15:29:56 -070042#include <symbols.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080043#include <timestamp.h>
44
Julius Wernerfd9defc2014-01-21 20:11:22 -080045static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -080046{
Kyösti Mälkkif48b38b2014-12-31 08:50:36 +020047 timestamp_init(0);
48 timestamp_add_now(TS_START_ROMSTAGE);
Gabe Black5c8d3d22014-01-17 22:11:35 -080049
Gabe Black5c8d3d22014-01-17 22:11:35 -080050 console_init();
51 exception_init();
52
Tom Warren64982c502014-01-23 13:37:50 -070053 sdram_init(get_sdram_config());
54
Gabe Black5cbbc702014-02-08 05:17:38 -080055 /* used for MMU and CBMEM setup, in MB */
Julius Wernerec5e5e02014-08-20 15:29:56 -070056 u32 dram_start_mb = (uintptr_t)_dram/MiB;
57 u32 dram_end_mb = sdram_max_addressable_mb();
58 u32 dram_size_mb = dram_end_mb - dram_start_mb;
Tom Warren64982c502014-01-23 13:37:50 -070059
Daisuke Nojiriefddcfb2014-09-04 09:55:34 -070060 configure_l2_cache();
Gabe Black5c8d3d22014-01-17 22:11:35 -080061 mmu_init();
Gabe Blackb9a4b712014-03-01 03:27:00 -080062 /* Device memory below DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070063 mmu_config_range(0, dram_start_mb, DCACHE_OFF);
64 /* SRAM is cached. MMU code will round size up to page size. */
65 mmu_config_range((uintptr_t)_sram/MiB, div_round_up(_sram_size, MiB),
66 DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080067 /* DRAM is cached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070068 mmu_config_range(dram_start_mb, dram_size_mb, DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -080069 /* A window for DMA is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070070 mmu_config_range((uintptr_t)_dma_coherent/MiB,
71 _dma_coherent_size/MiB, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -080072 /* The space above DRAM is uncached. */
Julius Wernerec5e5e02014-08-20 15:29:56 -070073 if (dram_end_mb < 4096)
74 mmu_config_range(dram_end_mb, 4096 - dram_end_mb, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -080075 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -080076 dcache_mmu_enable();
77
Gabe Blackc8522062014-05-06 15:44:14 -070078 /*
79 * A watchdog reset only resets part of the system so it ends up in
80 * a funny state. If that happens, we need to reset the whole machine.
81 */
82 if (power_reset_status() == POWER_RESET_WATCHDOG) {
83 printk(BIOS_INFO, "Watchdog reset detected, rebooting.\n");
Daisuke Nojiri512bfbc2014-08-15 17:07:39 -070084 hard_reset();
Gabe Blackc8522062014-05-06 15:44:14 -070085 }
86
Gabe Black5c8d3d22014-01-17 22:11:35 -080087 cbmem_initialize_empty();
88
Daisuke Nojiri1b05d882014-08-27 11:48:03 -070089 timestamp_init(0);
90 timestamp_add(TS_START_ROMSTAGE, romstage_start_time);
Gabe Black4a12cfe2014-03-24 21:24:24 -070091
Daisuke Nojiri1b05d882014-08-27 11:48:03 -070092 early_mainboard_init();
Gabe Black4a12cfe2014-03-24 21:24:24 -070093
Aaron Durbincad7c4e2014-03-20 15:08:54 -050094 vboot_verify_firmware(romstage_handoff_find_or_add());
95
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050096 run_ramstage();
Gabe Black5c8d3d22014-01-17 22:11:35 -080097}
Julius Wernerfd9defc2014-01-21 20:11:22 -080098
99/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
100void main(void)
101{
Gabe Blackf220df62014-02-08 05:01:06 -0800102 asm volatile ("bl arm_init_caches"
103 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -0800104 romstage();
105}