xref: /rk3399_ARM-atf/include/common/bl_common.ld.h (revision a7739bc7b16bf3e43f370864f8a800cf8943b391)
1 /*
2  * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef BL_COMMON_LD_H
8 #define BL_COMMON_LD_H
9 
10 #include <platform_def.h>
11 
12 #ifdef __aarch64__
13 #define STRUCT_ALIGN	8
14 #define BSS_ALIGN	16
15 #else
16 #define STRUCT_ALIGN	4
17 #define BSS_ALIGN	8
18 #endif
19 
20 #define CPU_OPS						\
21 	. = ALIGN(STRUCT_ALIGN);			\
22 	__CPU_OPS_START__ = .;				\
23 	KEEP(*(cpu_ops))				\
24 	__CPU_OPS_END__ = .;
25 
26 #define PARSER_LIB_DESCS				\
27 	. = ALIGN(STRUCT_ALIGN);			\
28 	__PARSER_LIB_DESCS_START__ = .;			\
29 	KEEP(*(.img_parser_lib_descs))			\
30 	__PARSER_LIB_DESCS_END__ = .;
31 
32 #define RT_SVC_DESCS					\
33 	. = ALIGN(STRUCT_ALIGN);			\
34 	__RT_SVC_DESCS_START__ = .;			\
35 	KEEP(*(rt_svc_descs))				\
36 	__RT_SVC_DESCS_END__ = .;
37 
38 #define PMF_SVC_DESCS					\
39 	. = ALIGN(STRUCT_ALIGN);			\
40 	__PMF_SVC_DESCS_START__ = .;			\
41 	KEEP(*(pmf_svc_descs))				\
42 	__PMF_SVC_DESCS_END__ = .;
43 
44 #define FCONF_POPULATOR					\
45 	. = ALIGN(STRUCT_ALIGN);			\
46 	__FCONF_POPULATOR_START__ = .;			\
47 	KEEP(*(.fconf_populator))			\
48 	__FCONF_POPULATOR_END__ = .;
49 
50 /*
51  * Keep the .got section in the RO section as it is patched prior to enabling
52  * the MMU and having the .got in RO is better for security. GOT is a table of
53  * addresses so ensure pointer size alignment.
54  */
55 #define GOT						\
56 	. = ALIGN(STRUCT_ALIGN);			\
57 	__GOT_START__ = .;				\
58 	*(.got)						\
59 	__GOT_END__ = .;
60 
61 #define RODATA_COMMON					\
62 	RT_SVC_DESCS					\
63 	FCONF_POPULATOR					\
64 	PMF_SVC_DESCS					\
65 	PARSER_LIB_DESCS				\
66 	CPU_OPS						\
67 	GOT
68 
69 #define STACK_SECTION					\
70 	stacks (NOLOAD) : {				\
71 		__STACKS_START__ = .;			\
72 		*(tzfw_normal_stacks)			\
73 		__STACKS_END__ = .;			\
74 	}
75 
76 /*
77  * If BL doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
78  * will be zero. For this reason, the only two valid values for
79  * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
80  * PLAT_PERCPU_BAKERY_LOCK_SIZE.
81  */
82 #ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
83 #define BAKERY_LOCK_SIZE_CHECK				\
84 	ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) ||	\
85 	       (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE), \
86 	       "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
87 #else
88 #define BAKERY_LOCK_SIZE_CHECK
89 #endif
90 
91 /*
92  * Bakery locks are stored in normal .bss memory
93  *
94  * Each lock's data is spread across multiple cache lines, one per CPU,
95  * but multiple locks can share the same cache line.
96  * The compiler will allocate enough memory for one CPU's bakery locks,
97  * the remaining cache lines are allocated by the linker script
98  */
99 #if !USE_COHERENT_MEM
100 #define BAKERY_LOCK_NORMAL				\
101 	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
102 	__BAKERY_LOCK_START__ = .;			\
103 	__PERCPU_BAKERY_LOCK_START__ = .;		\
104 	*(bakery_lock)					\
105 	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
106 	__PERCPU_BAKERY_LOCK_END__ = .;			\
107 	__PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__); \
108 	. = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
109 	__BAKERY_LOCK_END__ = .;			\
110 	BAKERY_LOCK_SIZE_CHECK
111 #else
112 #define BAKERY_LOCK_NORMAL
113 #endif
114 
115 /*
116  * Time-stamps are stored in normal .bss memory
117  *
118  * The compiler will allocate enough memory for one CPU's time-stamps,
119  * the remaining memory for other CPUs is allocated by the
120  * linker script
121  */
122 #define PMF_TIMESTAMP					\
123 	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
124 	__PMF_TIMESTAMP_START__ = .;			\
125 	KEEP(*(pmf_timestamp_array))			\
126 	. = ALIGN(CACHE_WRITEBACK_GRANULE);		\
127 	__PMF_PERCPU_TIMESTAMP_END__ = .;		\
128 	__PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); \
129 	. = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
130 	__PMF_TIMESTAMP_END__ = .;
131 
132 
133 /*
134  * The .bss section gets initialised to 0 at runtime.
135  * Its base address has bigger alignment for better performance of the
136  * zero-initialization code.
137  */
138 #define BSS_SECTION					\
139 	.bss (NOLOAD) : ALIGN(BSS_ALIGN) {		\
140 		__BSS_START__ = .;			\
141 		*(SORT_BY_ALIGNMENT(.bss*))		\
142 		*(COMMON)				\
143 		BAKERY_LOCK_NORMAL			\
144 		PMF_TIMESTAMP				\
145 		__BSS_END__ = .;			\
146 	}
147 
148 /*
149  * The xlat_table section is for full, aligned page tables (4K).
150  * Removing them from .bss avoids forcing 4K alignment on
151  * the .bss section. The tables are initialized to zero by the translation
152  * tables library.
153  */
154 #define XLAT_TABLE_SECTION				\
155 	xlat_table (NOLOAD) : {				\
156 		*(xlat_table)				\
157 	}
158 
159 #endif /* BL_COMMON_LD_H */
160