Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 22 | #include <bootblock_common.h> |
David Hendricks | bba8090 | 2013-03-14 15:24:57 -0700 | [diff] [blame^] | 23 | #include <arch/cache.h> |
David Hendricks | 3d7344a | 2013-01-08 21:05:06 -0800 | [diff] [blame] | 24 | #include <arch/hlt.h> |
David Hendricks | 50c0a50 | 2013-01-31 17:05:50 -0800 | [diff] [blame] | 25 | #include <arch/stages.h> |
Hung-Te Lin | fe18792 | 2013-02-01 01:09:24 +0800 | [diff] [blame] | 26 | #include <cbfs.h> |
Hung-Te Lin | b868d40 | 2013-02-06 22:01:18 +0800 | [diff] [blame] | 27 | #include <console/console.h> |
David Hendricks | 50c0a50 | 2013-01-31 17:05:50 -0800 | [diff] [blame] | 28 | |
| 29 | #include "stages.c" |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 30 | |
David Hendricks | bba8090 | 2013-03-14 15:24:57 -0700 | [diff] [blame^] | 31 | static 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 Hendricks | 3d7344a | 2013-01-08 21:05:06 -0800 | [diff] [blame] | 83 | static 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 Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 92 | |
David Hendricks | 50c0a50 | 2013-01-31 17:05:50 -0800 | [diff] [blame] | 93 | void main(void) |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 94 | { |
Hung-Te Lin | 5f83f6c | 2013-02-04 14:38:03 +0800 | [diff] [blame] | 95 | const char *stage_name = "fallback/romstage"; |
| 96 | void *entry; |
David Hendricks | bba8090 | 2013-03-14 15:24:57 -0700 | [diff] [blame^] | 97 | 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 Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 115 | |
| 116 | if (boot_cpu()) { |
David Hendricks | fba42a7 | 2013-01-17 15:07:35 -0800 | [diff] [blame] | 117 | bootblock_cpu_init(); |
David Hendricks | 211a5d5 | 2013-01-17 20:52:21 -0800 | [diff] [blame] | 118 | bootblock_mainboard_init(); |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 119 | } |
David Hendricks | 3d7344a | 2013-01-08 21:05:06 -0800 | [diff] [blame] | 120 | |
Hung-Te Lin | b868d40 | 2013-02-06 22:01:18 +0800 | [diff] [blame] | 121 | console_init(); |
Hung-Te Lin | 5f83f6c | 2013-02-04 14:38:03 +0800 | [diff] [blame] | 122 | printk(BIOS_INFO, "hello from bootblock\n"); |
David Hendricks | 211a5d5 | 2013-01-17 20:52:21 -0800 | [diff] [blame] | 123 | printk(BIOS_INFO, "bootblock main(): loading romstage\n"); |
Hung-Te Lin | 5f83f6c | 2013-02-04 14:38:03 +0800 | [diff] [blame] | 124 | entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, stage_name); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 125 | |
David Hendricks | 211a5d5 | 2013-01-17 20:52:21 -0800 | [diff] [blame] | 126 | printk(BIOS_INFO, "bootblock main(): jumping to romstage\n"); |
Hung-Te Lin | 5f83f6c | 2013-02-04 14:38:03 +0800 | [diff] [blame] | 127 | if (entry) stage_exit(entry); |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 128 | hlt(); |
| 129 | } |