blob: 80eea776af5a7e6231d55be1b05c26b2e0b136b6 [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
72void main(void)
73{
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
79 // Globally disable MMU, caches and branch prediction (these should
80 // already be disabled by default on reset).
81 uint32_t sctlr = read_sctlr();
82 sctlr &= ~(SCTLR_M | SCTLR_C | SCTLR_Z | SCTLR_I);
83 write_sctlr(sctlr);
84
85 arm_invalidate_caches();
86
87 // Renable icache and branch prediction.
88 sctlr = read_sctlr();
89 sctlr |= SCTLR_Z | SCTLR_I;
90 write_sctlr(sctlr);
91
92 configure_l2ctlr();
93 configure_l2actlr();
94
95 console_init();
96 exception_init();
97
Tom Warren64982c502014-01-23 13:37:50 -070098 sdram_init(get_sdram_config());
99
100 /* used for MMU and CBMEM setup */
101 dram_size_mb = sdram_size_mb();
102
103 u32 dram_start = (CONFIG_SYS_SDRAM_BASE >> 20);
104 u32 dram_end = dram_start + dram_size_mb; /* plus one... */
105
Gabe Black5c8d3d22014-01-17 22:11:35 -0800106 mmu_init();
Tom Warren64982c502014-01-23 13:37:50 -0700107 mmu_config_range(0, dram_start, DCACHE_OFF);
108 mmu_config_range(dram_start, dram_size_mb, DCACHE_WRITEBACK);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800109 mmu_config_range(CONFIG_DRAM_DMA_START >> 20,
110 CONFIG_DRAM_DMA_SIZE >> 20, DCACHE_OFF);
Tom Warren64982c502014-01-23 13:37:50 -0700111 mmu_config_range(dram_end, 4096 - dram_end, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800112 mmu_disable_range(0, 1);
113 dcache_invalidate_all();
114 dcache_mmu_enable();
115
116 /* For quality of the user experience, it's important to get
117 * the video going ASAP. Because there are long delays in some
118 * of the powerup steps, we do some very early setup here in
119 * romstage. The only thing setup_display does is manage
120 * 4 GPIOs, under control of the config struct members.
121 * In general, it is safe to enable panel power, and disable
122 * anything related to the backlight. If we get something wrong,
123 * we can easily fix it in ramstage by further GPIO manipulation,
124 * so we feel it is ok to do some setting at this point.
125 */
126
127 const struct device *soc = dev_find_slot(DEVICE_PATH_CPU_CLUSTER, 0);
128 printk(BIOS_SPEW, "s%s: soc is %p\n", __func__, soc);
129 if (soc && soc->chip_info) {
130 const struct soc_nvidia_tegra124_config *config =
131 soc->chip_info;
132 setup_display((struct soc_nvidia_tegra124_config *)config);
133 }
134
135 cbmem_initialize_empty();
136
137#if CONFIG_COLLECT_TIMESTAMPS
138 timestamp_init(0);
139 timestamp_add(TS_START_ROMSTAGE, romstage_start_time);
140 timestamp_add(TS_START_COPYRAM, timestamp_get());
141#endif
142 void *entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA,
143 "fallback/coreboot_ram");
144#if CONFIG_COLLECT_TIMESTAMPS
145 timestamp_add(TS_END_COPYRAM, timestamp_get());
146#endif
147 stage_exit(entry);
148}