1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2018-2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "scp_sgi575_scmi.h"
9 
10 #include <mod_scmi.h>
11 #include <mod_transport.h>
12 
13 #include <fwk_element.h>
14 #include <fwk_id.h>
15 #include <fwk_macros.h>
16 #include <fwk_module.h>
17 #include <fwk_module_idx.h>
18 
19 static const struct fwk_element service_table[] = {
20     [SCP_SGI575_SCMI_SERVICE_IDX_PSCI] = {
21         .name = "PSCI",
22         .data = &((struct mod_scmi_service_config) {
23             .transport_id = FWK_ID_ELEMENT_INIT(
24                 FWK_MODULE_IDX_TRANSPORT,
25                 SCP_SGI575_SCMI_SERVICE_IDX_PSCI),
26             .transport_api_id = FWK_ID_API_INIT(
27                 FWK_MODULE_IDX_TRANSPORT,
28                 MOD_TRANSPORT_API_IDX_SCMI_TO_TRANSPORT),
29             .transport_notification_init_id = FWK_ID_NOTIFICATION_INIT(
30                 FWK_MODULE_IDX_TRANSPORT,
31                 MOD_TRANSPORT_NOTIFICATION_IDX_INITIALIZED),
32             .scmi_agent_id = SCP_SCMI_AGENT_ID_PSCI,
33             .scmi_p2a_id = FWK_ID_NONE_INIT,
34         }),
35     },
36     [SCP_SGI575_SCMI_SERVICE_IDX_OSPM] = {
37         .name = "OSPM",
38         .data = &((struct mod_scmi_service_config) {
39             .transport_id = FWK_ID_ELEMENT_INIT(
40                 FWK_MODULE_IDX_TRANSPORT,
41                 SCP_SGI575_SCMI_SERVICE_IDX_OSPM),
42             .transport_api_id = FWK_ID_API_INIT(
43                 FWK_MODULE_IDX_TRANSPORT,
44                 MOD_TRANSPORT_API_IDX_SCMI_TO_TRANSPORT),
45             .transport_notification_init_id = FWK_ID_NOTIFICATION_INIT(
46                 FWK_MODULE_IDX_TRANSPORT,
47                 MOD_TRANSPORT_NOTIFICATION_IDX_INITIALIZED),
48             .scmi_agent_id = SCP_SCMI_AGENT_ID_OSPM,
49             .scmi_p2a_id = FWK_ID_NONE_INIT,
50         }),
51     },
52     [SCP_SGI575_SCMI_SERVICE_IDX_COUNT] = { 0 }
53 };
54 
get_service_table(fwk_id_t module_id)55 static const struct fwk_element *get_service_table(fwk_id_t module_id)
56 {
57     return service_table;
58 }
59 
60 #ifndef BUILD_HAS_MOD_RESOURCE_PERMS
61 
62 /* PSCI agent has no access to perf and sensor protocols */
63 static const uint32_t dis_protocol_list_psci[] = {
64     MOD_SCMI_PROTOCOL_ID_SENSOR,
65     MOD_SCMI_PROTOCOL_ID_PERF,
66 };
67 #endif
68 
69 static struct mod_scmi_agent agent_table[] = {
70     [SCP_SCMI_AGENT_ID_OSPM] = {
71         .type = SCMI_AGENT_TYPE_OSPM,
72         .name = "OSPM",
73     },
74     [SCP_SCMI_AGENT_ID_PSCI] = {
75         .type = SCMI_AGENT_TYPE_PSCI,
76         .name = "PSCI",
77     },
78 };
79 
80 const struct fwk_module_config config_scmi = {
81     .data = &((struct mod_scmi_config){
82         .protocol_count_max = 9,
83 #ifndef BUILD_HAS_MOD_RESOURCE_PERMS
84         .dis_protocol_count_psci = FWK_ARRAY_SIZE(dis_protocol_list_psci),
85         .dis_protocol_list_psci = dis_protocol_list_psci,
86 #endif
87         .agent_count = FWK_ARRAY_SIZE(agent_table) - 1,
88         .agent_table = agent_table,
89         .vendor_identifier = "arm",
90         .sub_vendor_identifier = "arm",
91     }),
92 
93     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_service_table),
94 };
95