blob: a5296286b2a7a506e12d9c8f99dd02b01d66e2f1 [file] [log] [blame]
Julius Wernerec5e5e02014-08-20 15:29:56 -07001/*
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
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Julius Wernerec5e5e02014-08-20 15:29:56 -070018 */
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
Aaron Durbin1936f6c2015-07-03 17:04:21 -050050#define TIMESTAMP(addr, size) \
51 REGION(timestamp, addr, size, 8)
52
Julius Wernerec5e5e02014-08-20 15:29:56 -070053#define PRERAM_CBMEM_CONSOLE(addr, size) \
54 REGION(preram_cbmem_console, addr, size, 4)
55
56/* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
57#define CBFS_CACHE(addr, size) REGION(cbfs_cache, addr, size, 4)
58
59/* TODO: This only works if you never access CBFS in romstage before RAM is up!
60 * If you need to change that assumption, you have some work ahead of you... */
61#if defined(__PRE_RAM__) && !defined(__ROMSTAGE__)
62 #define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
63 #define POSTRAM_CBFS_CACHE(addr, size) \
64 REGION(unused_cbfs_cache, addr, size, 4)
65#else
66 #define PRERAM_CBFS_CACHE(addr, size) \
67 REGION(unused_cbfs_cache, addr, size, 4)
68 #define POSTRAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
69#endif
70
71/* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
72#ifdef __BOOTBLOCK__
73 #define BOOTBLOCK(addr, sz) \
74 SET_COUNTER(bootblock, addr) \
75 _ = ASSERT(_ebootblock - _bootblock <= sz, \
76 STR(Bootblock exceeded its allotted size! (sz))); \
77 INCLUDE "lib/bootblock.bootblock.ld"
78#else
79 #define BOOTBLOCK(addr, sz) \
80 SET_COUNTER(bootblock, addr) \
81 . += sz;
82#endif
83
84#ifdef __ROMSTAGE__
85 #define ROMSTAGE(addr, sz) \
86 SET_COUNTER(romstage, addr) \
87 _ = ASSERT(_eromstage - _romstage <= sz, \
88 STR(Romstage exceeded its allotted size! (sz))); \
89 INCLUDE "lib/romstage.romstage.ld"
90#else
91 #define ROMSTAGE(addr, sz) \
92 SET_COUNTER(romstage, addr) \
93 . += sz;
94#endif
95
96#ifdef __RAMSTAGE__
97 #define RAMSTAGE(addr, sz) \
98 SET_COUNTER(ramstage, addr) \
99 _ = ASSERT(_eramstage - _ramstage <= sz, \
100 STR(Ramstage exceeded its allotted size! (sz))); \
101 INCLUDE "lib/ramstage.ramstage.ld"
102#else
103 #define RAMSTAGE(addr, sz) \
104 SET_COUNTER(ramstage, addr) \
105 . += sz;
106#endif
107
Julius Wernerec5e5e02014-08-20 15:29:56 -0700108#endif /* __MEMLAYOUT_H */