blob: be02057b46e3df5f781e8692fb52659c51b43449 [file] [log] [blame]
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001/*
2 * Freescale Layerscape MC I/O wrapper
3 *
Yogesh Gaur318c32f2017-11-15 11:59:31 +05304 * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
5 * Copyright 2017 NXP
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07006 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <fsl-mc/fsl_mc_sys.h>
11#include <fsl-mc/fsl_mc_cmd.h>
12#include <fsl-mc/fsl_dprc.h>
13
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053014int dprc_get_container_id(struct fsl_mc_io *mc_io,
15 uint32_t cmd_flags,
16 int *container_id)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070017{
18 struct mc_command cmd = { 0 };
19 int err;
20
21 /* prepare command */
22 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053023 cmd_flags,
24 0);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070025
26 /* send command to mc*/
27 err = mc_send_command(mc_io, &cmd);
28 if (err)
29 return err;
30
31 /* retrieve response parameters */
32 DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id);
33
34 return 0;
35}
36
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053037int dprc_open(struct fsl_mc_io *mc_io,
38 uint32_t cmd_flags,
39 int container_id,
40 uint16_t *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070041{
42 struct mc_command cmd = { 0 };
43 int err;
44
45 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053046 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070047 0);
48 DPRC_CMD_OPEN(cmd, container_id);
49
50 /* send command to mc*/
51 err = mc_send_command(mc_io, &cmd);
52 if (err)
53 return err;
54
55 /* retrieve response parameters */
56 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
57
58 return 0;
59}
60
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053061int dprc_close(struct fsl_mc_io *mc_io,
62 uint32_t cmd_flags,
63 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070064{
65 struct mc_command cmd = { 0 };
66
67 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053068 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070069 token);
70
71 /* send command to mc*/
72 return mc_send_command(mc_io, &cmd);
73}
74
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053075int dprc_create_container(struct fsl_mc_io *mc_io,
76 uint32_t cmd_flags,
77 uint16_t token,
78 struct dprc_cfg *cfg,
79 int *child_container_id,
80 uint64_t *child_portal_paddr)
81{
82 struct mc_command cmd = { 0 };
83 int err;
84
85 /* prepare command */
86 DPRC_CMD_CREATE_CONTAINER(cmd, cfg);
87
88 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
89 cmd_flags,
90 token);
91
92 /* send command to mc*/
93 err = mc_send_command(mc_io, &cmd);
94 if (err)
95 return err;
96
97 /* retrieve response parameters */
98 DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id,
99 *child_portal_paddr);
100
101 return 0;
102}
103
104int dprc_destroy_container(struct fsl_mc_io *mc_io,
105 uint32_t cmd_flags,
106 uint16_t token,
107 int child_container_id)
108{
109 struct mc_command cmd = { 0 };
110
111 /* prepare command */
112 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
113 cmd_flags,
114 token);
115 DPRC_CMD_DESTROY_CONTAINER(cmd, child_container_id);
116
117 /* send command to mc*/
118 return mc_send_command(mc_io, &cmd);
119}
120
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700121int dprc_reset_container(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530122 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700123 uint16_t token,
124 int child_container_id)
125{
126 struct mc_command cmd = { 0 };
127
128 /* prepare command */
129 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530130 cmd_flags,
131 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700132 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
133
134 /* send command to mc*/
135 return mc_send_command(mc_io, &cmd);
136}
137
138int dprc_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530139 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700140 uint16_t token,
141 struct dprc_attributes *attr)
142{
143 struct mc_command cmd = { 0 };
144 int err;
145
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530148 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700149 token);
150
151 /* send command to mc*/
152 err = mc_send_command(mc_io, &cmd);
153 if (err)
154 return err;
155
156 /* retrieve response parameters */
157 DPRC_RSP_GET_ATTRIBUTES(cmd, attr);
158
159 return 0;
160}
161
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530162int dprc_get_obj_count(struct fsl_mc_io *mc_io,
163 uint32_t cmd_flags,
164 uint16_t token,
165 int *obj_count)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700166{
167 struct mc_command cmd = { 0 };
168 int err;
169
170 /* prepare command */
171 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530172 cmd_flags,
173 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700174
175 /* send command to mc*/
176 err = mc_send_command(mc_io, &cmd);
177 if (err)
178 return err;
179
180 /* retrieve response parameters */
181 DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count);
182
183 return 0;
184}
185
186int dprc_get_obj(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530187 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700188 uint16_t token,
189 int obj_index,
190 struct dprc_obj_desc *obj_desc)
191{
192 struct mc_command cmd = { 0 };
193 int err;
194
195 /* prepare command */
196 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530197 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700198 token);
199 DPRC_CMD_GET_OBJ(cmd, obj_index);
200
201 /* send command to mc*/
202 err = mc_send_command(mc_io, &cmd);
203 if (err)
204 return err;
205
206 /* retrieve response parameters */
207 DPRC_RSP_GET_OBJ(cmd, obj_desc);
208
209 return 0;
210}
211
212int dprc_get_res_count(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530213 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700214 uint16_t token,
215 char *type,
216 int *res_count)
217{
218 struct mc_command cmd = { 0 };
219 int err;
220
221 *res_count = 0;
222
223 /* prepare command */
224 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530225 cmd_flags,
226 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700227 DPRC_CMD_GET_RES_COUNT(cmd, type);
228
229 /* send command to mc*/
230 err = mc_send_command(mc_io, &cmd);
231 if (err)
232 return err;
233
234 /* retrieve response parameters */
235 DPRC_RSP_GET_RES_COUNT(cmd, *res_count);
236
237 return 0;
238}
239
240int dprc_get_res_ids(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530241 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700242 uint16_t token,
243 char *type,
244 struct dprc_res_ids_range_desc *range_desc)
245{
246 struct mc_command cmd = { 0 };
247 int err;
248
249 /* prepare command */
250 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530251 cmd_flags,
252 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700253 DPRC_CMD_GET_RES_IDS(cmd, range_desc, type);
254
255 /* send command to mc*/
256 err = mc_send_command(mc_io, &cmd);
257 if (err)
258 return err;
259
260 /* retrieve response parameters */
261 DPRC_RSP_GET_RES_IDS(cmd, range_desc);
262
263 return 0;
264}
265
266int dprc_get_obj_region(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530267 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700268 uint16_t token,
269 char *obj_type,
270 int obj_id,
271 uint8_t region_index,
272 struct dprc_region_desc *region_desc)
273{
274 struct mc_command cmd = { 0 };
275 int err;
276
277 /* prepare command */
278 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530279 cmd_flags,
280 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700281 DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index);
282
283 /* send command to mc*/
284 err = mc_send_command(mc_io, &cmd);
285 if (err)
286 return err;
287
288 /* retrieve response parameters */
289 DPRC_RSP_GET_OBJ_REGION(cmd, region_desc);
290
291 return 0;
292}
293
294int dprc_connect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530295 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700296 uint16_t token,
297 const struct dprc_endpoint *endpoint1,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530298 const struct dprc_endpoint *endpoint2,
299 const struct dprc_connection_cfg *cfg)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700300{
301 struct mc_command cmd = { 0 };
302
303 /* prepare command */
304 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530305 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700306 token);
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530307 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700308
309 /* send command to mc*/
310 return mc_send_command(mc_io, &cmd);
311}
312
313int dprc_disconnect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530314 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700315 uint16_t token,
316 const struct dprc_endpoint *endpoint)
317{
318 struct mc_command cmd = { 0 };
319
320 /* prepare command */
321 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530322 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700323 token);
324 DPRC_CMD_DISCONNECT(cmd, endpoint);
325
326 /* send command to mc*/
327 return mc_send_command(mc_io, &cmd);
328}
329
330int dprc_get_connection(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530331 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700332 uint16_t token,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530333 const struct dprc_endpoint *endpoint1,
334 struct dprc_endpoint *endpoint2,
335 int *state)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700336{
337 struct mc_command cmd = { 0 };
338 int err;
339
340 /* prepare command */
341 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530342 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700343 token);
344 DPRC_CMD_GET_CONNECTION(cmd, endpoint1);
345
346 /* send command to mc*/
347 err = mc_send_command(mc_io, &cmd);
348 if (err)
349 return err;
350
351 /* retrieve response parameters */
352 DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state);
353
354 return 0;
355}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530356
357int dprc_get_api_version(struct fsl_mc_io *mc_io,
358 u32 cmd_flags,
359 u16 *major_ver,
360 u16 *minor_ver)
361{
362 struct mc_command cmd = { 0 };
363 int err;
364
365 /* prepare command */
366 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
367 cmd_flags, 0);
368
369 /* send command to mc */
370 err = mc_send_command(mc_io, &cmd);
371 if (err)
372 return err;
373
374 /* retrieve response parameters */
375 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
376
377 return 0;
378}