xref: /rk3399_ARM-atf/include/plat/marvell/odyssey/csr/ody-require.h (revision 12d80bbbf6031228bdd910eccb03bb185e8df527)
1*4b8b8d74SJaiprakash Singh /***********************license start***********************************
2*4b8b8d74SJaiprakash Singh * Copyright (C) 2021-2026 Marvell.
3*4b8b8d74SJaiprakash Singh * SPDX-License-Identifier: BSD-3-Clause
4*4b8b8d74SJaiprakash Singh * https://spdx.org/licenses
5*4b8b8d74SJaiprakash Singh ***********************license end**************************************/
6*4b8b8d74SJaiprakash Singh 
7*4b8b8d74SJaiprakash Singh /**
8*4b8b8d74SJaiprakash Singh  * @file
9*4b8b8d74SJaiprakash Singh  *
10*4b8b8d74SJaiprakash Singh  * Functions and macros to control what parts of the ODY are linked in
11*4b8b8d74SJaiprakash Singh  *
12*4b8b8d74SJaiprakash Singh  * <hr>$Revision: 49448 $<hr>
13*4b8b8d74SJaiprakash Singh  * @defgroup require Component linking control
14*4b8b8d74SJaiprakash Singh  * @{
15*4b8b8d74SJaiprakash Singh  */
16*4b8b8d74SJaiprakash Singh 
17*4b8b8d74SJaiprakash Singh /**
18*4b8b8d74SJaiprakash Singh  * Optional parts of the ODY code are pulled in by adding
19*4b8b8d74SJaiprakash Singh  * REQUIRE() lines to the function ody_require_depends().
20*4b8b8d74SJaiprakash Singh  * Component symbols are defined as weak so that they are not
21*4b8b8d74SJaiprakash Singh  * linked in unless a REQUIRE() pulls them in.
22*4b8b8d74SJaiprakash Singh  */
23*4b8b8d74SJaiprakash Singh #define REQUIRE(component)                                  \
24*4b8b8d74SJaiprakash Singh do {                                                          \
25*4b8b8d74SJaiprakash Singh 	extern char __ody_require_symbol_##component;           \
26*4b8b8d74SJaiprakash Singh 	ody_warn_if(__ody_require_symbol_##component,           \
27*4b8b8d74SJaiprakash Singh 	    "Require of %s failed\n", #component);              \
28*4b8b8d74SJaiprakash Singh } while (0)
29*4b8b8d74SJaiprakash Singh 
30*4b8b8d74SJaiprakash Singh /**
31*4b8b8d74SJaiprakash Singh  * The following macro defines a special symbol in a C file to
32*4b8b8d74SJaiprakash Singh  * define it as a require component. Referencing this symbol
33*4b8b8d74SJaiprakash Singh  * causes all objects defined in the C file to be pulled in. This
34*4b8b8d74SJaiprakash Singh  * symbol should only be referenced by using the REQUIRE()
35*4b8b8d74SJaiprakash Singh  * macro in the function ody_require_depends().
36*4b8b8d74SJaiprakash Singh  */
37*4b8b8d74SJaiprakash Singh #define REQUIRE_DEFINE(component)           \
38*4b8b8d74SJaiprakash Singh 	char __ody_require_symbol_##component;      \
39*4b8b8d74SJaiprakash Singh 	char __ody_is_required_symbol_##component
40*4b8b8d74SJaiprakash Singh 
41*4b8b8d74SJaiprakash Singh /**
42*4b8b8d74SJaiprakash Singh  * Return if a component has been required. Useful for if
43*4b8b8d74SJaiprakash Singh  * statements around referencing of weak symbols.
44*4b8b8d74SJaiprakash Singh  */
45*4b8b8d74SJaiprakash Singh #define IS_REQUIRED(component)                                          \
46*4b8b8d74SJaiprakash Singh ({int is_required;                                                      \
47*4b8b8d74SJaiprakash Singh do {                                                                      \
48*4b8b8d74SJaiprakash Singh 	extern char __ody_is_required_symbol_##component __attribute__((weak));\
49*4b8b8d74SJaiprakash Singh 	is_required = (&__ody_is_required_symbol_##component != NULL);      \
50*4b8b8d74SJaiprakash Singh } while (0);                                                            \
51*4b8b8d74SJaiprakash Singh is_required; })
52*4b8b8d74SJaiprakash Singh 
53*4b8b8d74SJaiprakash Singh 
54*4b8b8d74SJaiprakash Singh /**
55*4b8b8d74SJaiprakash Singh  * The require macros use weak symbols to control if components
56*4b8b8d74SJaiprakash Singh  * are linked in. All directly referenced symbols in a component
57*4b8b8d74SJaiprakash Singh  * must be defined a weak. This causes the component to only be
58*4b8b8d74SJaiprakash Singh  * pulled in by the linker if the symbol defined by
59*4b8b8d74SJaiprakash Singh  * REQUIRE_DEFINE is used.
60*4b8b8d74SJaiprakash Singh  */
61*4b8b8d74SJaiprakash Singh #define WEAK __attribute__((weak))
62*4b8b8d74SJaiprakash Singh 
63*4b8b8d74SJaiprakash Singh /**
64*4b8b8d74SJaiprakash Singh  * This function is not defined by the ODY libraries. It must be
65*4b8b8d74SJaiprakash Singh  * defined by all ODY applications. It should be empty except for
66*4b8b8d74SJaiprakash Singh  * containing REQUIRE() lines. The ody-init code has a strong
67*4b8b8d74SJaiprakash Singh  * reference to ody_requires_depends() which then contains strong
68*4b8b8d74SJaiprakash Singh  * references to all needed components.
69*4b8b8d74SJaiprakash Singh  */
70*4b8b8d74SJaiprakash Singh extern void __ody_require_depends(void);
71*4b8b8d74SJaiprakash Singh 
72*4b8b8d74SJaiprakash Singh /** @} */
73