bl_common.ld.h 4.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef BL_COMMON_LD_H
#define BL_COMMON_LD_H

10
11
12
13
#include <platform_def.h>

#ifdef __aarch64__
#define STRUCT_ALIGN	8
14
#define BSS_ALIGN	16
15
16
#else
#define STRUCT_ALIGN	4
17
#define BSS_ALIGN	8
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#endif

#define CPU_OPS						\
	. = ALIGN(STRUCT_ALIGN);			\
	__CPU_OPS_START__ = .;				\
	KEEP(*(cpu_ops))				\
	__CPU_OPS_END__ = .;

#define PARSER_LIB_DESCS				\
	. = ALIGN(STRUCT_ALIGN);			\
	__PARSER_LIB_DESCS_START__ = .;			\
	KEEP(*(.img_parser_lib_descs))			\
	__PARSER_LIB_DESCS_END__ = .;

#define RT_SVC_DESCS					\
	. = ALIGN(STRUCT_ALIGN);			\
	__RT_SVC_DESCS_START__ = .;			\
	KEEP(*(rt_svc_descs))				\
	__RT_SVC_DESCS_END__ = .;

#define PMF_SVC_DESCS					\
	. = ALIGN(STRUCT_ALIGN);			\
	__PMF_SVC_DESCS_START__ = .;			\
	KEEP(*(pmf_svc_descs))				\
	__PMF_SVC_DESCS_END__ = .;

#define FCONF_POPULATOR					\
	. = ALIGN(STRUCT_ALIGN);			\
	__FCONF_POPULATOR_START__ = .;			\
	KEEP(*(.fconf_populator))			\
	__FCONF_POPULATOR_END__ = .;

/*
 * Keep the .got section in the RO section as it is patched prior to enabling
 * the MMU and having the .got in RO is better for security. GOT is a table of
 * addresses so ensure pointer size alignment.
 */
#define GOT						\
	. = ALIGN(STRUCT_ALIGN);			\
	__GOT_START__ = .;				\
	*(.got)						\
	__GOT_END__ = .;

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * The base xlat table
 *
 * It is put into the rodata section if PLAT_RO_XLAT_TABLES=1,
 * or into the bss section otherwise.
 */
#define BASE_XLAT_TABLE					\
	. = ALIGN(16);					\
	*(base_xlat_table)

#if PLAT_RO_XLAT_TABLES
#define BASE_XLAT_TABLE_RO		BASE_XLAT_TABLE
#define BASE_XLAT_TABLE_BSS
#else
#define BASE_XLAT_TABLE_RO
#define BASE_XLAT_TABLE_BSS		BASE_XLAT_TABLE
#endif

79
80
81
82
83
84
#define RODATA_COMMON					\
	RT_SVC_DESCS					\
	FCONF_POPULATOR					\
	PMF_SVC_DESCS					\
	PARSER_LIB_DESCS				\
	CPU_OPS						\
85
86
	GOT						\
	BASE_XLAT_TABLE_RO
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#define STACK_SECTION					\
	stacks (NOLOAD) : {				\
		__STACKS_START__ = .;			\
		*(tzfw_normal_stacks)			\
		__STACKS_END__ = .;			\
	}

/*
 * If BL doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
 * will be zero. For this reason, the only two valid values for
 * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
 * PLAT_PERCPU_BAKERY_LOCK_SIZE.
 */
#ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
#define BAKERY_LOCK_SIZE_CHECK				\
	ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) ||	\
	       (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE), \
	       "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
#else
#define BAKERY_LOCK_SIZE_CHECK
#endif

/*
 * Bakery locks are stored in normal .bss memory
 *
 * Each lock's data is spread across multiple cache lines, one per CPU,
 * but multiple locks can share the same cache line.
 * The compiler will allocate enough memory for one CPU's bakery locks,
 * the remaining cache lines are allocated by the linker script
 */
#if !USE_COHERENT_MEM
#define BAKERY_LOCK_NORMAL				\
	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
	__BAKERY_LOCK_START__ = .;			\
	__PERCPU_BAKERY_LOCK_START__ = .;		\
	*(bakery_lock)					\
	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
	__PERCPU_BAKERY_LOCK_END__ = .;			\
	__PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__); \
	. = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
	__BAKERY_LOCK_END__ = .;			\
	BAKERY_LOCK_SIZE_CHECK
#else
#define BAKERY_LOCK_NORMAL
#endif

/*
 * Time-stamps are stored in normal .bss memory
 *
 * The compiler will allocate enough memory for one CPU's time-stamps,
 * the remaining memory for other CPUs is allocated by the
 * linker script
 */
#define PMF_TIMESTAMP					\
	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
	__PMF_TIMESTAMP_START__ = .;			\
	KEEP(*(pmf_timestamp_array))			\
	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
	__PMF_PERCPU_TIMESTAMP_END__ = .;		\
	__PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); \
	. = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
	__PMF_TIMESTAMP_END__ = .;

151
152
153
154
155
156
157
158
159
160
161
162
163

/*
 * The .bss section gets initialised to 0 at runtime.
 * Its base address has bigger alignment for better performance of the
 * zero-initialization code.
 */
#define BSS_SECTION					\
	.bss (NOLOAD) : ALIGN(BSS_ALIGN) {		\
		__BSS_START__ = .;			\
		*(SORT_BY_ALIGNMENT(.bss*))		\
		*(COMMON)				\
		BAKERY_LOCK_NORMAL			\
		PMF_TIMESTAMP				\
164
		BASE_XLAT_TABLE_BSS			\
165
166
167
		__BSS_END__ = .;			\
	}

168
169
170
171
172
173
174
175
176
177
178
179
/*
 * The xlat_table section is for full, aligned page tables (4K).
 * Removing them from .bss avoids forcing 4K alignment on
 * the .bss section. The tables are initialized to zero by the translation
 * tables library.
 */
#define XLAT_TABLE_SECTION				\
	xlat_table (NOLOAD) : {				\
		*(xlat_table)				\
	}

#endif /* BL_COMMON_LD_H */