Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame^] | 1 | /* |
| 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 | /* This file contains macro definitions for memlayout.ld linker scripts. */ |
| 21 | |
| 22 | #ifndef __MEMLAYOUT_H |
| 23 | #define __MEMLAYOUT_H |
| 24 | |
| 25 | #include <arch/memlayout.h> |
| 26 | |
| 27 | #define STR(x) #x |
| 28 | |
| 29 | #define SET_COUNTER(name, addr) \ |
| 30 | _ = ASSERT(. <= addr, STR(name overlaps the previous region!)); \ |
| 31 | . = addr; |
| 32 | |
| 33 | #define SYMBOL(name, addr) \ |
| 34 | SET_COUNTER(name, addr) \ |
| 35 | _##name = .; |
| 36 | |
| 37 | #define REGION(name, addr, size, expected_align) \ |
| 38 | SYMBOL(name, addr) \ |
| 39 | _ = ASSERT(. == ALIGN(expected_align), \ |
| 40 | STR(name must be aligned to expected_align!)); \ |
| 41 | SYMBOL(e##name, addr + size) |
| 42 | |
| 43 | /* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */ |
| 44 | #define SRAM_START(addr) SYMBOL(sram, addr) |
| 45 | |
| 46 | #define SRAM_END(addr) SYMBOL(esram, addr) |
| 47 | |
| 48 | #define DRAM_START(addr) SYMBOL(dram, addr) |
| 49 | |
| 50 | #define PRERAM_CBMEM_CONSOLE(addr, size) \ |
| 51 | REGION(preram_cbmem_console, addr, size, 4) |
| 52 | |
| 53 | /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */ |
| 54 | #define CBFS_CACHE(addr, size) REGION(cbfs_cache, addr, size, 4) |
| 55 | |
| 56 | /* TODO: This only works if you never access CBFS in romstage before RAM is up! |
| 57 | * If you need to change that assumption, you have some work ahead of you... */ |
| 58 | #if defined(__PRE_RAM__) && !defined(__ROMSTAGE__) |
| 59 | #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 60 | #define POSTRAM_CBFS_CACHE(addr, size) \ |
| 61 | REGION(unused_cbfs_cache, addr, size, 4) |
| 62 | #else |
| 63 | #define PRERAM_CBFS_CACHE(addr, size) \ |
| 64 | REGION(unused_cbfs_cache, addr, size, 4) |
| 65 | #define POSTRAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size) |
| 66 | #endif |
| 67 | |
| 68 | /* Careful: 'INCLUDE <filename>' must always be at the end of the output line */ |
| 69 | #ifdef __BOOTBLOCK__ |
| 70 | #define BOOTBLOCK(addr, sz) \ |
| 71 | SET_COUNTER(bootblock, addr) \ |
| 72 | _ = ASSERT(_ebootblock - _bootblock <= sz, \ |
| 73 | STR(Bootblock exceeded its allotted size! (sz))); \ |
| 74 | INCLUDE "lib/bootblock.bootblock.ld" |
| 75 | #else |
| 76 | #define BOOTBLOCK(addr, sz) \ |
| 77 | SET_COUNTER(bootblock, addr) \ |
| 78 | . += sz; |
| 79 | #endif |
| 80 | |
| 81 | #ifdef __ROMSTAGE__ |
| 82 | #define ROMSTAGE(addr, sz) \ |
| 83 | SET_COUNTER(romstage, addr) \ |
| 84 | _ = ASSERT(_eromstage - _romstage <= sz, \ |
| 85 | STR(Romstage exceeded its allotted size! (sz))); \ |
| 86 | INCLUDE "lib/romstage.romstage.ld" |
| 87 | #else |
| 88 | #define ROMSTAGE(addr, sz) \ |
| 89 | SET_COUNTER(romstage, addr) \ |
| 90 | . += sz; |
| 91 | #endif |
| 92 | |
| 93 | #ifdef __RAMSTAGE__ |
| 94 | #define RAMSTAGE(addr, sz) \ |
| 95 | SET_COUNTER(ramstage, addr) \ |
| 96 | _ = ASSERT(_eramstage - _ramstage <= sz, \ |
| 97 | STR(Ramstage exceeded its allotted size! (sz))); \ |
| 98 | INCLUDE "lib/ramstage.ramstage.ld" |
| 99 | #else |
| 100 | #define RAMSTAGE(addr, sz) \ |
| 101 | SET_COUNTER(ramstage, addr) \ |
| 102 | . += sz; |
| 103 | #endif |
| 104 | |
| 105 | #endif /* __MEMLAYOUT_H */ |