1#
2# SPDX-License-Identifier: BSD-3-Clause
3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4#
5
6#
7# Common config options
8#
9arm_config_option(
10    NAME MAX_CPUS
11    HELP "Maximum number of CPUs supported by RMM"
12    TYPE STRING
13    DEFAULT 16)
14
15#
16# The RMM is mapped with 4K pages, and all RMM APIs use the same granularity.
17#
18arm_config_option(
19    NAME GRANULE_SHIFT
20    HELP "The shift value of granule size. i.e: GRANULE_SIZE == 1 << GRANULE_SHIFT"
21    TYPE STRING
22    DEFAULT 12)
23
24#
25# RMM_MAX_GRANULES. Maximum number of memory granules supported.
26#
27arm_config_option(
28    NAME RMM_MAX_GRANULES
29    HELP "Maximum number of memory granules supported"
30    TYPE STRING
31    DEFAULT 0x0)
32
33#
34# RMM_MAX_COH_GRANULES. Maximum number of coherent device granules supported.
35#
36arm_config_option(
37    NAME RMM_MAX_COH_GRANULES
38    HELP "Maximum number of coherent device granules supported"
39    TYPE STRING
40    DEFAULT 1)
41
42#
43# RMM_MAX_NCOH_GRANULES. Maximum number of non-coherent device granules supported.
44#
45arm_config_option(
46    NAME RMM_MAX_NCOH_GRANULES
47    HELP "Maximum number of non-coherent device granules supported"
48    TYPE STRING
49    DEFAULT 1)
50
51arm_config_option(
52    NAME RMM_NUM_PAGES_PER_STACK
53    HELP "Number of pages to use per CPU stack"
54    TYPE STRING
55    DEFAULT 5
56    ADVANCED)
57
58arm_config_option(
59    NAME RMM_DOCS
60    HELP "RMM Documentation build"
61    TYPE BOOL
62    DEFAULT OFF)
63
64# TODO: Move to lib/arch once MbedTLS compilation is moved to build phase.
65arm_config_option(
66    NAME RMM_FPU_USE_AT_REL2
67    HELP "Enable Advanced SIMD support in RMM"
68    TYPE BOOL
69    DEFAULT OFF)
70
71#
72# The number of 4K pages allocated for attestation buffer.
73#
74arm_config_option(
75    NAME RMM_CCA_TOKEN_BUFFER
76    HELP "Number of pages to allocate in Aux granules for Realm CCA token"
77    TYPE STRING
78    DEFAULT 1)
79
80arm_config_option(
81    NAME RMM_V1_1
82    HELP "Enable v1.1 features in RMM (experimental)"
83    TYPE BOOL
84    DEFAULT OFF)
85
86arm_config_option(
87    NAME ATTEST_EL3_TOKEN_SIGN
88    HELP "Use EL3 service to sign realm attestation token."
89    TYPE BOOL
90    DEFAULT OFF
91    ADVANCED)
92
93#
94# Enable the Stack protection compiler flag.
95# Having the PAUTH and BTI feature enabled makes the software-based
96# stack frame canary redundant. Enabling the software canary could
97# have a performance degradation. Hence the default is OFF.
98#
99arm_config_option(
100	NAME STACK_PROTECTOR
101	HELP "Enable Stack Protection Compiler Flags"
102	string OFF)
103
104#
105# Introduce a pseudo-library purely for applying flags to RMM's libraries.
106# This is applied to any targets created after this point.
107#
108
109add_library(rmm-common INTERFACE)
110
111target_compile_definitions(rmm-common
112    INTERFACE "$<$<CONFIG:Debug>:DEBUG>")
113
114if(MAX_CPUS EQUAL 0x0)
115    message(FATAL_ERROR "MAX_CPUS is not initialized")
116endif()
117
118target_compile_definitions(rmm-common
119    INTERFACE "MAX_CPUS=${MAX_CPUS}U")
120
121if(NOT(GRANULE_SHIFT EQUAL 12))
122    message(FATAL_ERROR "GRANULE_SHIFT is not initialized correctly")
123endif()
124
125target_compile_definitions(rmm-common
126    INTERFACE "GRANULE_SHIFT=U(${GRANULE_SHIFT})")
127
128if (RMM_MAX_GRANULES EQUAL 0x0)
129    message (FATAL_ERROR "RMM_MAX_GRANULES not configured")
130endif()
131
132target_compile_definitions(rmm-common
133    INTERFACE "RMM_MAX_GRANULES=U(${RMM_MAX_GRANULES})")
134
135if (RMM_MAX_COH_GRANULES EQUAL 0x0)
136    message (FATAL_ERROR "RMM_MAX_COH_GRANULES cannot be set to 0")
137endif()
138
139target_compile_definitions(rmm-common
140    INTERFACE "RMM_MAX_COH_GRANULES=U(${RMM_MAX_COH_GRANULES})")
141
142if (RMM_MAX_NCOH_GRANULES EQUAL 0x0)
143    message (FATAL_ERROR "RMM_MAX_NCOH_GRANULES cannot be set to 0")
144endif()
145
146target_compile_definitions(rmm-common
147    INTERFACE "RMM_MAX_NCOH_GRANULES=U(${RMM_MAX_NCOH_GRANULES})")
148
149target_compile_definitions(rmm-common
150    INTERFACE "RMM_NUM_PAGES_PER_STACK=UL(${RMM_NUM_PAGES_PER_STACK})")
151
152# Set stack protector option.
153if(STACK_PROTECTOR)
154	target_compile_definitions(rmm-common
155	INTERFACE "STACK_PROTECTOR_ENABLED=1")
156	message(STATUS "Stack Protector is Enabled.")
157	add_compile_options(-fstack-protector-strong)
158endif()
159
160if(RMM_FPU_USE_AT_REL2 AND RMM_ARCH STREQUAL aarch64)
161    target_compile_definitions(rmm-common
162        INTERFACE "RMM_FPU_USE_AT_REL2=1")
163endif()
164
165target_compile_definitions(rmm-common
166    INTERFACE "RMM_CCA_TOKEN_BUFFER=U(${RMM_CCA_TOKEN_BUFFER})")
167
168#
169# Project name and version
170#
171target_compile_definitions(rmm-common
172    INTERFACE "NAME=\"${PROJECT_NAME}\"")
173
174target_compile_definitions(rmm-common
175    INTERFACE "VERSION=\"${PROJECT_VERSION}\"")
176
177#
178# Get git commit information
179#
180Git_Get_Commit_Info(COMMIT_INFO)
181
182target_compile_definitions(rmm-common
183    INTERFACE "COMMIT_INFO=\"${COMMIT_INFO}\"")
184
185if(RMM_V1_1)
186    message(WARNING "RMM v1.1 features are experimental")
187    target_compile_definitions(rmm-common
188        INTERFACE "RMM_V1_1=1")
189endif()
190
191link_libraries(rmm-common)
192