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  *      SCMI base protocol definitions.
9  */
10 
11 #ifndef INTERNAL_MOD_SCMI_BASE_H
12 #define INTERNAL_MOD_SCMI_BASE_H
13 
14 #include <internal/mod_scmi.h>
15 
16 #include <mod_scmi.h>
17 
18 #include <fwk_id.h>
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 /*
24  * PROTOCOL_ATTRIBUTES
25  */
26 #define SCMI_PROTOCOL_VERSION_BASE UINT32_C(0x20000)
27 
28 #define SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_PROTOCOLS_POS 0U
29 #define SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_AGENTS_POS    8U
30 
31 #define SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_PROTOCOLS_MASK 0xFFU
32 #define SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_AGENTS_MASK    0xFF00U
33 
34 #define SCMI_BASE_PROTOCOL_ATTRIBUTES(NUM_PROTOCOLS, NUM_AGENTS) \
35     ((((NUM_PROTOCOLS) << SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_PROTOCOLS_POS) & \
36       SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_PROTOCOLS_MASK) | \
37      (((NUM_AGENTS) << SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_AGENTS_POS) & \
38       SCMI_BASE_PROTOCOL_ATTRIBUTES_NUM_AGENTS_MASK))
39 
40 /*
41  * BASE_DISCOVER_VENDOR
42  */
43 struct scmi_base_discover_vendor_p2a {
44     int32_t status;
45     char vendor_identifier[16];
46 };
47 
48 /*
49  * BASE_DISCOVER_SUB_VENDOR
50  */
51 struct scmi_base_discover_sub_vendor_p2a {
52     int32_t status;
53     char sub_vendor_identifier[16];
54 };
55 
56 /*
57  * BASE_DISCOVER_IMPLEMENTATION_VERSION
58  * No special structure right now, see protocol_version.
59  */
60 
61 /*
62  * BASE_DISCOVER_LIST_PROTOCOLS
63  */
64 struct scmi_base_discover_list_protocols_a2p {
65     uint32_t skip;
66 };
67 
68 struct scmi_base_discover_list_protocols_p2a {
69     int32_t status;
70     uint32_t num_protocols;
71     uint32_t protocols[];
72 };
73 
74 /*
75  * BASE_DISCOVER_AGENT
76  */
77 struct scmi_base_discover_agent_a2p {
78     uint32_t agent_id;
79 };
80 
81 #if (SCMI_PROTOCOL_VERSION_BASE >= UINT32_C(0x20000))
82 struct scmi_base_discover_agent_p2a {
83     int32_t status;
84     uint32_t agent_id;
85     char name[16];
86 };
87 #else
88 struct scmi_base_discover_agent_p2a {
89     int32_t status;
90     char name[16];
91 };
92 #endif
93 
94 /*
95  * BASE_SET_DEVICE_PERMISSIONS
96  */
97 struct __attribute((packed)) scmi_base_set_device_permissions_a2p {
98     uint32_t agent_id;
99     uint32_t device_id;
100     uint32_t flags;
101 };
102 
103 struct __attribute((packed)) scmi_base_set_device_permissions_p2a {
104     int32_t status;
105 };
106 
107 /*
108  * BASE_SET_PROTOCOL_PERMISSIONS
109  */
110 struct __attribute((packed)) scmi_base_set_protocol_permissions_a2p {
111     uint32_t agent_id;
112     uint32_t device_id;
113     uint32_t command_id;
114     uint32_t flags;
115 };
116 
117 struct __attribute((packed)) scmi_base_set_protocol_permissions_p2a {
118     int32_t status;
119 };
120 
121 /*
122  * BASE_RESET_AGENT_CONFIG
123  */
124 struct __attribute((packed)) scmi_base_reset_agent_config_a2p {
125     uint32_t agent_id;
126     uint32_t flags;
127 };
128 
129 struct __attribute((packed)) scmi_base_reset_agent_config_p2a {
130     int32_t status;
131 };
132 
133 int scmi_base_message_handler(
134     fwk_id_t protocol_id,
135     fwk_id_t service_id,
136     const uint32_t *payload,
137     size_t payload_size,
138     unsigned int message_id);
139 
140 void scmi_base_set_api(const struct mod_scmi_from_protocol_api *api);
141 void scmi_base_set_shared_ctx(struct mod_scmi_ctx *scmi_ctx_param);
142 
143 #endif /* INTERNAL_MOD_SCMI_BASE_H */
144