1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *     System Control and Management Interface (SCMI) support.
9  */
10 
11 #ifndef MOD_INTERNAL_SCMI_H
12 #define MOD_INTERNAL_SCMI_H
13 
14 #include <mod_scmi.h>
15 #include <mod_scmi_header.h>
16 
17 #include <fwk_id.h>
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 /* SCMI service context */
23 struct scmi_service_ctx {
24     /* Pointer to SCMI service configuration data */
25     const struct mod_scmi_service_config *config;
26 
27     /*
28      * Identifier of the transport entity used by the service to read/respond
29      * to SCMI messages.
30      */
31     fwk_id_t transport_id;
32 
33     /* Pointer to the transport API used to read and respond to messages */
34     const struct mod_scmi_to_transport_api *transport_api;
35 
36     /*
37      * Copy of the pointer to the 'respond' function within the transport API.
38      */
39     int (*respond)(fwk_id_t transport_id, const void *payload, size_t size);
40 
41     /*
42      * Copy of the pointer to the 'transmit' function within the transport API.
43      */
44     int (*transmit)(
45         fwk_id_t transport_id,
46         uint32_t message_header,
47         const void *payload,
48         size_t size,
49         bool request_ack_by_interrupt);
50 
51     /* SCMI message token, used by the agent to identify individual messages */
52     uint16_t scmi_token;
53 
54     /* SCMI identifier of the protocol processing the current message */
55     unsigned int scmi_protocol_id;
56 
57     /* SCMI identifier of the message currently being processed */
58     unsigned int scmi_message_id;
59 
60     /* SCMI type of the message currently being processed */
61     enum mod_scmi_message_type scmi_message_type;
62 };
63 
64 struct scmi_protocol {
65     /* SCMI protocol message handler */
66     mod_scmi_message_handler_t *message_handler;
67 
68     /* SCMI protocol framework identifier */
69     fwk_id_t id;
70 
71 #ifdef BUILD_HAS_SCMI_NOTIFICATIONS
72     /* SCMI protocol notification message handler */
73     mod_scmi_notification_message_handler_t *notification_handler;
74 #endif
75 };
76 
77 struct mod_scmi_ctx {
78     /* SCMI module configuration data */
79     struct mod_scmi_config *config;
80 
81     /* Table of bound protocols */
82     struct scmi_protocol *protocol_table;
83 
84     /* Number of bound protocols */
85     unsigned int protocol_count;
86 
87     /* Table of bound protocols as requesters */
88     struct scmi_protocol *protocol_requester_table;
89 
90     /* Number of bound protocols as requesters */
91     unsigned int protocol_requester_count;
92 
93     /*
94      * SCMI protocol identifier to the index of the entry in protocol_table[]
95      * dedicated to the protocol.
96      */
97     uint8_t scmi_protocol_id_to_idx[MOD_SCMI_PROTOCOL_ID_MAX + 1];
98 
99     /*
100      * SCMI protocol identifier to the index of the entry in
101      * protocol_requester_table[] dedicated to the protocol.
102      */
103     uint8_t scmi_protocol_requester_id_to_idx[MOD_SCMI_PROTOCOL_ID_MAX + 1];
104 
105     /* Table of service contexts */
106     struct scmi_service_ctx *service_ctx_table;
107 
108 #ifdef BUILD_HAS_MOD_RESOURCE_PERMS
109     /* SCMI Resource Permissions API */
110     const struct mod_res_permissions_api *res_perms_api;
111 #endif
112 #ifdef BUILD_HAS_SCMI_NOTIFICATIONS
113     /* Table of scmi notification subscribers */
114     struct scmi_notification_subscribers *scmi_notif_subscribers;
115 #endif
116 };
117 
118 #endif /* MOD_INTERNAL_SCMI_H */
119