blob: 7012e178078525dd95d084f4250be67598182203 [file] [log] [blame]
Stefan Reinauer52db0b92012-12-07 17:15:04 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Google Inc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
Stefan Reinauer52db0b92012-12-07 17:15:04 -080022#include <bootblock_common.h>
David Hendricksbba80902013-03-14 15:24:57 -070023#include <arch/cache.h>
David Hendricks3d7344a2013-01-08 21:05:06 -080024#include <arch/hlt.h>
David Hendricks50c0a502013-01-31 17:05:50 -080025#include <arch/stages.h>
Hung-Te Linfe187922013-02-01 01:09:24 +080026#include <cbfs.h>
Hung-Te Linb868d402013-02-06 22:01:18 +080027#include <console/console.h>
David Hendricks50c0a502013-01-31 17:05:50 -080028
29#include "stages.c"
Stefan Reinauer52db0b92012-12-07 17:15:04 -080030
David Hendricksbba80902013-03-14 15:24:57 -070031static void armv7_invalidate_caches(void)
32{
33 uint32_t clidr;
34 int level;
35
36 /* Invalidate branch predictor */
37 bpiall();
38
39 /* Iterate thru each cache identified in CLIDR and invalidate */
40 clidr = read_clidr();
41 for (level = 0; level < 7; level++) {
42 unsigned int ctype = (clidr >> (level * 3)) & 0x7;
43 uint32_t csselr;
44
45 switch(ctype) {
46 case 0x0:
47 /* no cache */
48 break;
49 case 0x1:
50 /* icache only */
51 csselr = (level << 1) | 1;
52 write_csselr(csselr);
53 icache_invalidate_all();
54 break;
55 case 0x2:
56 case 0x4:
57 /* dcache only or unified cache */
58 dcache_invalidate_all();
59 break;
60 case 0x3:
61 /* separate icache and dcache */
62 csselr = (level << 1) | 1;
63 write_csselr(csselr);
64 icache_invalidate_all();
65
66 csselr = level < 1;
67 write_csselr(csselr);
68 dcache_invalidate_all();
69 break;
70 default:
71 /* reserved */
72 break;
73 }
74 }
75
76 /* Invalidate TLB */
77 /* FIXME: ARMv7 Architecture Ref. Manual claims that the distinction
78 * instruction vs. data TLBs is deprecated in ARMv7. But that doesn't
79 * really seem true for Cortex-A15? */
80 tlb_invalidate_all();
81}
82
David Hendricks3d7344a2013-01-08 21:05:06 -080083static int boot_cpu(void)
84{
85 /*
86 * FIXME: This is a stub for now. All non-boot CPUs should be
87 * waiting for an interrupt. We could move the chunk of assembly
88 * which puts them to sleep in here...
89 */
90 return 1;
91}
Stefan Reinauer52db0b92012-12-07 17:15:04 -080092
David Hendricks50c0a502013-01-31 17:05:50 -080093void main(void)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080094{
Hung-Te Lin5f83f6c2013-02-04 14:38:03 +080095 const char *stage_name = "fallback/romstage";
96 void *entry;
David Hendricksbba80902013-03-14 15:24:57 -070097 uint32_t sctlr;
98
99 /* Globally disable MMU, caches, and branch prediction (these should
100 * be disabled by default on reset) */
101 sctlr = read_sctlr();
102 sctlr &= ~(SCTLR_M | SCTLR_C | SCTLR_Z | SCTLR_I);
103 write_sctlr(sctlr);
104
105 armv7_invalidate_caches();
106
107 /*
108 * Re-enable caches and branch prediction. MMU will be set up later.
109 * Note: If booting from USB, we need to disable branch prediction
110 * before copying from USB into RAM (FIXME: why?)
111 */
112 sctlr = read_sctlr();
113 sctlr |= SCTLR_C | SCTLR_Z | SCTLR_I;
114 write_sctlr(sctlr);
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800115
116 if (boot_cpu()) {
David Hendricksfba42a72013-01-17 15:07:35 -0800117 bootblock_cpu_init();
David Hendricks211a5d52013-01-17 20:52:21 -0800118 bootblock_mainboard_init();
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800119 }
David Hendricks3d7344a2013-01-08 21:05:06 -0800120
Hung-Te Linb868d402013-02-06 22:01:18 +0800121 console_init();
Hung-Te Lin5f83f6c2013-02-04 14:38:03 +0800122 printk(BIOS_INFO, "hello from bootblock\n");
David Hendricks211a5d52013-01-17 20:52:21 -0800123 printk(BIOS_INFO, "bootblock main(): loading romstage\n");
Hung-Te Lin5f83f6c2013-02-04 14:38:03 +0800124 entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, stage_name);
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +0800125
David Hendricks211a5d52013-01-17 20:52:21 -0800126 printk(BIOS_INFO, "bootblock main(): jumping to romstage\n");
Hung-Te Lin5f83f6c2013-02-04 14:38:03 +0800127 if (entry) stage_exit(entry);
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800128 hlt();
129}