1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *    Framework private module definitions.
9  */
10 
11 #ifndef FWK_INTERNAL_MODULE_H
12 #define FWK_INTERNAL_MODULE_H
13 
14 #include <internal/fwk_notification.h>
15 
16 #include <fwk_id.h>
17 #include <fwk_module.h>
18 #include <fwk_slist.h>
19 
20 #include <stddef.h>
21 
22 /*
23  * Module context.
24  */
25 struct fwk_module_context {
26     /* Module identifier */
27     fwk_id_t id;
28 
29     /* Module state */
30     enum fwk_module_state state;
31 
32     /* Module description */
33     const struct fwk_module *desc;
34 
35     /* Module configuration */
36     const struct fwk_module_config *config;
37 
38     /* Number of elements */
39     size_t element_count;
40 
41     /* Table of element contexts */
42     struct fwk_element_ctx *element_ctx_table;
43 
44 #ifdef BUILD_HAS_NOTIFICATION
45     /*
46      * Table of notification subscription lists. One list per type of
47      * notification defined by the module.
48      */
49     struct fwk_dlist *subscription_dlist_table;
50     #endif
51 
52     /* List of delayed response events */
53     struct fwk_slist delayed_response_list;
54 };
55 
56 /*
57  * Element context.
58  */
59 struct fwk_element_ctx {
60     /* Element state */
61     enum fwk_module_state state;
62 
63     /* Element description */
64     const struct fwk_element *desc;
65 
66     /* Number of sub-elements */
67     size_t sub_element_count;
68 
69 #ifdef BUILD_HAS_NOTIFICATION
70     /*
71      * Table of notification subscription lists. One list per type of
72      * notification defined by the element's module.
73      */
74     struct fwk_dlist *subscription_dlist_table;
75     #endif
76 
77     /* List of delayed response events */
78     struct fwk_slist delayed_response_list;
79 };
80 
81 /*!
82  * \internal
83  *
84  * \brief Start the module component.
85  *
86  * \details Starts each module and its elements, running through their
87  *      initialization routines.
88  *
89  * \return Status code representing the result of the operation.
90  */
91 int fwk_module_start(void);
92 
93 /*!
94  * \internal
95  *
96  * \brief Stop the module component.
97  *
98  * \details Stop each module and its elements, running through their
99  *      stop routines.
100  *
101  * \return Status code representing the result of the operation.
102  */
103 int fwk_module_stop(void);
104 
105 /*
106  * \brief Get a pointer to the context of a module or element.
107  *
108  * \param id Module or element identifier.
109  *      If the identifier provided does not refer to a valid module or element,
110  *      the behaviour of this function is undefined.
111  *
112  * \return Pointer to the module context.
113  */
114 struct fwk_module_context *fwk_module_get_ctx(fwk_id_t id);
115 
116 /*
117  * \brief Get the state of a module or element.
118  *
119  * \param id Module, element or sub-element identifier.
120  * \param state [out] State of the module or element.
121  *
122  * \retval ::FWK_SUCCESS The state was returned.
123  * \retval ::FWK_E_PARAM One or more parameters were invalid.
124  */
125 int fwk_module_get_state(fwk_id_t id, enum fwk_module_state *state);
126 
127 /*
128  * \brief Get a pointer to the framework context of an element.
129  *
130  * \param element_id Element identifier.
131  *      If the identifier provided does not refer to a valid element, the
132  *      behaviour of this function is undefined.
133  *
134  * \return Pointer to the element context.
135  */
136 struct fwk_element_ctx *fwk_module_get_element_ctx(fwk_id_t element_id);
137 
138 /*
139  * \brief Reset the module framework component.
140  *
141  * \note Only for testing.
142  */
143 void fwk_module_reset(void);
144 
145 #endif /* FWK_INTERNAL_MODULE_H */
146