1
2
3
4
5
6
7
8
9#include <fsl-mc/fsl_mc_sys.h>
10#include <fsl-mc/fsl_mc_cmd.h>
11#include <fsl-mc/fsl_dprc.h>
12
13int dprc_get_container_id(struct fsl_mc_io *mc_io,
14 uint32_t cmd_flags,
15 int *container_id)
16{
17 struct mc_command cmd = { 0 };
18 int err;
19
20
21 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
22 cmd_flags,
23 0);
24
25
26 err = mc_send_command(mc_io, &cmd);
27 if (err)
28 return err;
29
30
31 DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id);
32
33 return 0;
34}
35
36int dprc_open(struct fsl_mc_io *mc_io,
37 uint32_t cmd_flags,
38 int container_id,
39 uint16_t *token)
40{
41 struct mc_command cmd = { 0 };
42 int err;
43
44
45 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
46 0);
47 DPRC_CMD_OPEN(cmd, container_id);
48
49
50 err = mc_send_command(mc_io, &cmd);
51 if (err)
52 return err;
53
54
55 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
56
57 return 0;
58}
59
60int dprc_close(struct fsl_mc_io *mc_io,
61 uint32_t cmd_flags,
62 uint16_t token)
63{
64 struct mc_command cmd = { 0 };
65
66
67 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
68 token);
69
70
71 return mc_send_command(mc_io, &cmd);
72}
73
74int dprc_create_container(struct fsl_mc_io *mc_io,
75 uint32_t cmd_flags,
76 uint16_t token,
77 struct dprc_cfg *cfg,
78 int *child_container_id,
79 uint64_t *child_portal_paddr)
80{
81 struct mc_command cmd = { 0 };
82 int err;
83
84
85 DPRC_CMD_CREATE_CONTAINER(cmd, cfg);
86
87 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
88 cmd_flags,
89 token);
90
91
92 err = mc_send_command(mc_io, &cmd);
93 if (err)
94 return err;
95
96
97 DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id,
98 *child_portal_paddr);
99
100 return 0;
101}
102
103int dprc_destroy_container(struct fsl_mc_io *mc_io,
104 uint32_t cmd_flags,
105 uint16_t token,
106 int child_container_id)
107{
108 struct mc_command cmd = { 0 };
109
110
111 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
112 cmd_flags,
113 token);
114 DPRC_CMD_DESTROY_CONTAINER(cmd, child_container_id);
115
116
117 return mc_send_command(mc_io, &cmd);
118}
119
120int dprc_reset_container(struct fsl_mc_io *mc_io,
121 uint32_t cmd_flags,
122 uint16_t token,
123 int child_container_id)
124{
125 struct mc_command cmd = { 0 };
126
127
128 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
129 cmd_flags,
130 token);
131 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
132
133
134 return mc_send_command(mc_io, &cmd);
135}
136
137int dprc_get_attributes(struct fsl_mc_io *mc_io,
138 uint32_t cmd_flags,
139 uint16_t token,
140 struct dprc_attributes *attr)
141{
142 struct mc_command cmd = { 0 };
143 int err;
144
145
146 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
147 cmd_flags,
148 token);
149
150
151 err = mc_send_command(mc_io, &cmd);
152 if (err)
153 return err;
154
155
156 DPRC_RSP_GET_ATTRIBUTES(cmd, attr);
157
158 return 0;
159}
160
161int dprc_get_obj_count(struct fsl_mc_io *mc_io,
162 uint32_t cmd_flags,
163 uint16_t token,
164 int *obj_count)
165{
166 struct mc_command cmd = { 0 };
167 int err;
168
169
170 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
171 cmd_flags,
172 token);
173
174
175 err = mc_send_command(mc_io, &cmd);
176 if (err)
177 return err;
178
179
180 DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count);
181
182 return 0;
183}
184
185int dprc_get_obj(struct fsl_mc_io *mc_io,
186 uint32_t cmd_flags,
187 uint16_t token,
188 int obj_index,
189 struct dprc_obj_desc *obj_desc)
190{
191 struct mc_command cmd = { 0 };
192 int err;
193
194
195 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
196 cmd_flags,
197 token);
198 DPRC_CMD_GET_OBJ(cmd, obj_index);
199
200
201 err = mc_send_command(mc_io, &cmd);
202 if (err)
203 return err;
204
205
206 DPRC_RSP_GET_OBJ(cmd, obj_desc);
207
208 return 0;
209}
210
211int dprc_get_res_count(struct fsl_mc_io *mc_io,
212 uint32_t cmd_flags,
213 uint16_t token,
214 char *type,
215 int *res_count)
216{
217 struct mc_command cmd = { 0 };
218 int err;
219
220 *res_count = 0;
221
222
223 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
224 cmd_flags,
225 token);
226 DPRC_CMD_GET_RES_COUNT(cmd, type);
227
228
229 err = mc_send_command(mc_io, &cmd);
230 if (err)
231 return err;
232
233
234 DPRC_RSP_GET_RES_COUNT(cmd, *res_count);
235
236 return 0;
237}
238
239int dprc_get_res_ids(struct fsl_mc_io *mc_io,
240 uint32_t cmd_flags,
241 uint16_t token,
242 char *type,
243 struct dprc_res_ids_range_desc *range_desc)
244{
245 struct mc_command cmd = { 0 };
246 int err;
247
248
249 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
250 cmd_flags,
251 token);
252 DPRC_CMD_GET_RES_IDS(cmd, range_desc, type);
253
254
255 err = mc_send_command(mc_io, &cmd);
256 if (err)
257 return err;
258
259
260 DPRC_RSP_GET_RES_IDS(cmd, range_desc);
261
262 return 0;
263}
264
265int dprc_get_obj_region(struct fsl_mc_io *mc_io,
266 uint32_t cmd_flags,
267 uint16_t token,
268 char *obj_type,
269 int obj_id,
270 uint8_t region_index,
271 struct dprc_region_desc *region_desc)
272{
273 struct mc_command cmd = { 0 };
274 int err;
275
276
277 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
278 cmd_flags,
279 token);
280 DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index);
281
282
283 err = mc_send_command(mc_io, &cmd);
284 if (err)
285 return err;
286
287
288 DPRC_RSP_GET_OBJ_REGION(cmd, region_desc);
289
290 return 0;
291}
292
293int dprc_connect(struct fsl_mc_io *mc_io,
294 uint32_t cmd_flags,
295 uint16_t token,
296 const struct dprc_endpoint *endpoint1,
297 const struct dprc_endpoint *endpoint2,
298 const struct dprc_connection_cfg *cfg)
299{
300 struct mc_command cmd = { 0 };
301
302
303 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
304 cmd_flags,
305 token);
306 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
307
308
309 return mc_send_command(mc_io, &cmd);
310}
311
312int dprc_disconnect(struct fsl_mc_io *mc_io,
313 uint32_t cmd_flags,
314 uint16_t token,
315 const struct dprc_endpoint *endpoint)
316{
317 struct mc_command cmd = { 0 };
318
319
320 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
321 cmd_flags,
322 token);
323 DPRC_CMD_DISCONNECT(cmd, endpoint);
324
325
326 return mc_send_command(mc_io, &cmd);
327}
328
329int dprc_get_connection(struct fsl_mc_io *mc_io,
330 uint32_t cmd_flags,
331 uint16_t token,
332 const struct dprc_endpoint *endpoint1,
333 struct dprc_endpoint *endpoint2,
334 int *state)
335{
336 struct mc_command cmd = { 0 };
337 int err;
338
339
340 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
341 cmd_flags,
342 token);
343 DPRC_CMD_GET_CONNECTION(cmd, endpoint1);
344
345
346 err = mc_send_command(mc_io, &cmd);
347 if (err)
348 return err;
349
350
351 DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state);
352
353 return 0;
354}
355
356int dprc_get_api_version(struct fsl_mc_io *mc_io,
357 u32 cmd_flags,
358 u16 *major_ver,
359 u16 *minor_ver)
360{
361 struct mc_command cmd = { 0 };
362 int err;
363
364
365 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
366 cmd_flags, 0);
367
368
369 err = mc_send_command(mc_io, &cmd);
370 if (err)
371 return err;
372
373
374 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
375
376 return 0;
377}
378