blob: 9c887a82e81391131aa08e9a90c370cfa43dd893 [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>
23#include <arch/stages.h>
24#include <device/device.h>
25#include <cbfs.h>
26#include <cbmem.h>
27#include <console/console.h>
Tom Warren64982c502014-01-23 13:37:50 -070028#include "sdram_configs.h"
Gabe Black5c8d3d22014-01-17 22:11:35 -080029#include "soc/nvidia/tegra124/chip.h"
Tom Warren64982c502014-01-23 13:37:50 -070030#include "soc/nvidia/tegra124/sdram.h"
Gabe Black5c8d3d22014-01-17 22:11:35 -080031#include <soc/display.h>
32#include <timestamp.h>
33
Gabe Black5c8d3d22014-01-17 22:11:35 -080034enum {
35 L2CTLR_ECC_PARITY = 0x1 << 21,
36 L2CTLR_TAG_RAM_LATENCY_MASK = 0x7 << 6,
37 L2CTLR_TAG_RAM_LATENCY_CYCLES_3 = 2 << 6,
38 L2CTLR_DATA_RAM_LATENCY_MASK = 0x7 << 0,
39 L2CTLR_DATA_RAM_LATENCY_CYCLES_3 = 2 << 0
40};
41
42enum {
43 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE = 0x1 << 27,
44 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT = 0x1 << 7,
45 L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL = 0x1 << 3
46};
47
48/* Configures L2 Control Register to use 3 cycles for DATA/TAG RAM latency. */
49static void configure_l2ctlr(void)
50{
51 uint32_t val;
52
53 val = read_l2ctlr();
54 val &= ~(L2CTLR_DATA_RAM_LATENCY_MASK | L2CTLR_TAG_RAM_LATENCY_MASK);
55 val |= (L2CTLR_DATA_RAM_LATENCY_CYCLES_3 | L2CTLR_TAG_RAM_LATENCY_CYCLES_3 |
56 L2CTLR_ECC_PARITY);
57 write_l2ctlr(val);
58}
59
60/* Configures L2 Auxiliary Control Register for Cortex A15. */
61static void configure_l2actlr(void)
62{
63 uint32_t val;
64
65 val = read_l2actlr();
66 val |= (L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL |
67 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT |
68 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE);
69 write_l2actlr(val);
70}
71
Julius Wernerfd9defc2014-01-21 20:11:22 -080072static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -080073{
Tom Warren64982c502014-01-23 13:37:50 -070074 int dram_size_mb;
Gabe Black5c8d3d22014-01-17 22:11:35 -080075#if CONFIG_COLLECT_TIMESTAMPS
76 uint64_t romstage_start_time = timestamp_get();
77#endif
78
Gabe Black5c8d3d22014-01-17 22:11:35 -080079 configure_l2ctlr();
80 configure_l2actlr();
81
82 console_init();
83 exception_init();
84
Tom Warren64982c502014-01-23 13:37:50 -070085 sdram_init(get_sdram_config());
86
87 /* used for MMU and CBMEM setup */
88 dram_size_mb = sdram_size_mb();
89
90 u32 dram_start = (CONFIG_SYS_SDRAM_BASE >> 20);
91 u32 dram_end = dram_start + dram_size_mb; /* plus one... */
92
Gabe Black5c8d3d22014-01-17 22:11:35 -080093 mmu_init();
Tom Warren64982c502014-01-23 13:37:50 -070094 mmu_config_range(0, dram_start, DCACHE_OFF);
95 mmu_config_range(dram_start, dram_size_mb, DCACHE_WRITEBACK);
Gabe Black5c8d3d22014-01-17 22:11:35 -080096 mmu_config_range(CONFIG_DRAM_DMA_START >> 20,
97 CONFIG_DRAM_DMA_SIZE >> 20, DCACHE_OFF);
Tom Warren64982c502014-01-23 13:37:50 -070098 mmu_config_range(dram_end, 4096 - dram_end, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -080099 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800100 dcache_mmu_enable();
101
102 /* For quality of the user experience, it's important to get
103 * the video going ASAP. Because there are long delays in some
104 * of the powerup steps, we do some very early setup here in
105 * romstage. The only thing setup_display does is manage
106 * 4 GPIOs, under control of the config struct members.
107 * In general, it is safe to enable panel power, and disable
108 * anything related to the backlight. If we get something wrong,
109 * we can easily fix it in ramstage by further GPIO manipulation,
110 * so we feel it is ok to do some setting at this point.
111 */
112
113 const struct device *soc = dev_find_slot(DEVICE_PATH_CPU_CLUSTER, 0);
114 printk(BIOS_SPEW, "s%s: soc is %p\n", __func__, soc);
115 if (soc && soc->chip_info) {
116 const struct soc_nvidia_tegra124_config *config =
117 soc->chip_info;
118 setup_display((struct soc_nvidia_tegra124_config *)config);
119 }
120
121 cbmem_initialize_empty();
122
123#if CONFIG_COLLECT_TIMESTAMPS
124 timestamp_init(0);
125 timestamp_add(TS_START_ROMSTAGE, romstage_start_time);
126 timestamp_add(TS_START_COPYRAM, timestamp_get());
127#endif
128 void *entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA,
129 "fallback/coreboot_ram");
130#if CONFIG_COLLECT_TIMESTAMPS
131 timestamp_add(TS_END_COPYRAM, timestamp_get());
132#endif
133 stage_exit(entry);
134}
Julius Wernerfd9defc2014-01-21 20:11:22 -0800135
136/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
137void main(void)
138{
Gabe Blackf220df62014-02-08 05:01:06 -0800139 asm volatile ("bl arm_init_caches"
140 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -0800141 romstage();
142}