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