1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Description:
8 * System Information Hardware Abstraction module.
9 */
10
11 #include <mod_system_info.h>
12
13 #include <fwk_assert.h>
14 #include <fwk_id.h>
15 #include <fwk_module.h>
16 #include <fwk_status.h>
17
18 #include <stddef.h>
19
20 /* Pointer to the config data for module use. */
21 static const struct mod_system_info_config *config;
22
23 /* Pointer to the data provided by the driver module. */
24 static struct mod_system_info *system_info;
25
26 /* Pointer to the driver function which provides the system info data. */
27 static struct mod_system_info_get_driver_data_api *get_driver_data;
28
get_system_info(const struct mod_system_info ** sys_info)29 static int get_system_info(const struct mod_system_info **sys_info)
30 {
31 if (system_info == NULL) {
32 system_info = get_driver_data->get_driver_data();
33 if (system_info == NULL)
34 return FWK_E_SUPPORT;
35 }
36
37 *sys_info = system_info;
38 return FWK_SUCCESS;
39 }
40
41 /*
42 * API to be used by the modules that need a copy of the system ID information
43 * data.
44 */
45 static struct mod_system_info_get_info_api get_system_info_api = {
46 .get_system_info = get_system_info,
47 };
48
49 /*
50 * Framework handlers
51 */
system_info_init(fwk_id_t module_id,unsigned int element_count,const void * data)52 static int system_info_init(fwk_id_t module_id, unsigned int element_count,
53 const void *data)
54 {
55 fwk_assert(data != NULL);
56
57 /* No elements support */
58 if (element_count > 0)
59 return FWK_E_DATA;
60
61 config = data;
62 return FWK_SUCCESS;
63 }
64
system_info_bind(fwk_id_t id,unsigned int round)65 static int system_info_bind(fwk_id_t id, unsigned int round)
66 {
67 int status = FWK_SUCCESS;
68
69 if (round == 1) {
70 if (!fwk_id_is_equal(config->system_info_driver_module_id,
71 FWK_ID_NONE)) {
72
73 /* If module ID is provided, API ID shouldn't be NONE */
74 fwk_assert(!fwk_id_is_equal(config->system_info_driver_data_api_id,
75 FWK_ID_NONE));
76
77 status = fwk_module_bind(config->system_info_driver_module_id,
78 config->system_info_driver_data_api_id,
79 &get_driver_data);
80 if (status != FWK_SUCCESS)
81 return FWK_E_PANIC;
82 }
83 }
84 return status;
85 }
86
system_info_process_bind_request(fwk_id_t requester_id,fwk_id_t targer_id,fwk_id_t api_id,const void ** api)87 static int system_info_process_bind_request(fwk_id_t requester_id,
88 fwk_id_t targer_id, fwk_id_t api_id, const void **api)
89 {
90 switch (fwk_id_get_api_idx(api_id)) {
91 case MOD_SYSTEM_INFO_GET_API_IDX:
92 *api = &get_system_info_api;
93 break;
94 default:
95 return FWK_E_PARAM;
96 }
97 return FWK_SUCCESS;
98 }
99
100 const struct fwk_module module_system_info = {
101 .type = FWK_MODULE_TYPE_HAL,
102 .init = system_info_init,
103 .bind = system_info_bind,
104 .process_bind_request = system_info_process_bind_request,
105 .api_count = MOD_SYSTEM_INFO_API_COUNT,
106 };
107