1 /*
2  * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef FCONF_H
8 #define FCONF_H
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 /* Public API */
14 #define FCONF_GET_PROPERTY(a, b, c)	a##__##b##_getter(c)
15 
16 /*
17  * This macro takes three arguments:
18  *   config:	Configuration identifier
19  *   name:	property namespace
20  *   callback:	populate() function
21  */
22 #define FCONF_REGISTER_POPULATOR(config, name, callback)			\
23 	__attribute__((used, section(".fconf_populator")))			\
24 	const struct fconf_populator (name##__populator) = {			\
25 		.config_type = (#config),					\
26 		.info = (#name),						\
27 		.populate = (callback)						\
28 	};
29 
30 /*
31  * Populator callback
32  *
33  * This structure are used by the fconf_populate function and should only be
34  * defined by the FCONF_REGISTER_POPULATOR macro.
35  */
36 struct fconf_populator {
37 	/* Description of the data loaded by the callback */
38 	const char *config_type;
39 	const char *info;
40 
41 	/* Callback used by fconf_populate function with a provided config dtb.
42 	 * Return 0 on success, err_code < 0 otherwise.
43 	 */
44 	int (*populate)(uintptr_t config);
45 };
46 
47 /* This function supports to load tb_fw_config and fw_config dtb */
48 int fconf_load_config(unsigned int image_id);
49 
50 /* Top level populate function
51  *
52  * This function takes a configuration dtb and calls all the registered
53  * populator callback with it.
54  *
55  *  Panic on error.
56  */
57 void fconf_populate(const char *config_type, uintptr_t config);
58 
59 /* FCONF specific getter */
60 #define fconf__dtb_getter(prop)	fconf_dtb_info.prop
61 
62 /* Structure used to locally keep a reference to the config dtb. */
63 struct fconf_dtb_info_t {
64 	uintptr_t base_addr;
65 	size_t size;
66 };
67 
68 extern struct fconf_dtb_info_t fconf_dtb_info;
69 
70 #endif /* FCONF_H */
71