1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale Layerscape MC I/O wrapper
5 * Copyright 2013-2016 Freescale Semiconductor, Inc.
9 #include <fsl-mc/fsl_mc_sys.h>
10 #include <fsl-mc/fsl_mc_cmd.h>
11 #include <fsl-mc/fsl_dprc.h>
13 int dprc_get_container_id(struct fsl_mc_io *mc_io,
17 struct mc_command cmd = { 0 };
21 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
25 /* send command to mc*/
26 err = mc_send_command(mc_io, &cmd);
30 /* retrieve response parameters */
31 DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id);
36 int dprc_open(struct fsl_mc_io *mc_io,
41 struct mc_command cmd = { 0 };
45 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
47 DPRC_CMD_OPEN(cmd, container_id);
49 /* send command to mc*/
50 err = mc_send_command(mc_io, &cmd);
54 /* retrieve response parameters */
55 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
60 int dprc_close(struct fsl_mc_io *mc_io,
64 struct mc_command cmd = { 0 };
67 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
70 /* send command to mc*/
71 return mc_send_command(mc_io, &cmd);
74 int dprc_create_container(struct fsl_mc_io *mc_io,
78 int *child_container_id,
79 uint64_t *child_portal_paddr)
81 struct mc_command cmd = { 0 };
85 DPRC_CMD_CREATE_CONTAINER(cmd, cfg);
87 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
91 /* send command to mc*/
92 err = mc_send_command(mc_io, &cmd);
96 /* retrieve response parameters */
97 DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id,
103 int dprc_destroy_container(struct fsl_mc_io *mc_io,
106 int child_container_id)
108 struct mc_command cmd = { 0 };
110 /* prepare command */
111 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
114 DPRC_CMD_DESTROY_CONTAINER(cmd, child_container_id);
116 /* send command to mc*/
117 return mc_send_command(mc_io, &cmd);
120 int dprc_reset_container(struct fsl_mc_io *mc_io,
123 int child_container_id)
125 struct mc_command cmd = { 0 };
127 /* prepare command */
128 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
131 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
133 /* send command to mc*/
134 return mc_send_command(mc_io, &cmd);
137 int dprc_get_attributes(struct fsl_mc_io *mc_io,
140 struct dprc_attributes *attr)
142 struct mc_command cmd = { 0 };
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
150 /* send command to mc*/
151 err = mc_send_command(mc_io, &cmd);
155 /* retrieve response parameters */
156 DPRC_RSP_GET_ATTRIBUTES(cmd, attr);
161 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
166 struct mc_command cmd = { 0 };
169 /* prepare command */
170 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
174 /* send command to mc*/
175 err = mc_send_command(mc_io, &cmd);
179 /* retrieve response parameters */
180 DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count);
185 int dprc_get_obj(struct fsl_mc_io *mc_io,
189 struct dprc_obj_desc *obj_desc)
191 struct mc_command cmd = { 0 };
194 /* prepare command */
195 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
198 DPRC_CMD_GET_OBJ(cmd, obj_index);
200 /* send command to mc*/
201 err = mc_send_command(mc_io, &cmd);
205 /* retrieve response parameters */
206 DPRC_RSP_GET_OBJ(cmd, obj_desc);
211 int dprc_get_res_count(struct fsl_mc_io *mc_io,
217 struct mc_command cmd = { 0 };
222 /* prepare command */
223 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
226 DPRC_CMD_GET_RES_COUNT(cmd, type);
228 /* send command to mc*/
229 err = mc_send_command(mc_io, &cmd);
233 /* retrieve response parameters */
234 DPRC_RSP_GET_RES_COUNT(cmd, *res_count);
239 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
243 struct dprc_res_ids_range_desc *range_desc)
245 struct mc_command cmd = { 0 };
248 /* prepare command */
249 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
252 DPRC_CMD_GET_RES_IDS(cmd, range_desc, type);
254 /* send command to mc*/
255 err = mc_send_command(mc_io, &cmd);
259 /* retrieve response parameters */
260 DPRC_RSP_GET_RES_IDS(cmd, range_desc);
265 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
270 uint8_t region_index,
271 struct dprc_region_desc *region_desc)
273 struct mc_command cmd = { 0 };
276 /* prepare command */
277 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
280 DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index);
282 /* send command to mc*/
283 err = mc_send_command(mc_io, &cmd);
287 /* retrieve response parameters */
288 DPRC_RSP_GET_OBJ_REGION(cmd, region_desc);
293 int dprc_connect(struct fsl_mc_io *mc_io,
296 const struct dprc_endpoint *endpoint1,
297 const struct dprc_endpoint *endpoint2,
298 const struct dprc_connection_cfg *cfg)
300 struct mc_command cmd = { 0 };
302 /* prepare command */
303 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
306 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
308 /* send command to mc*/
309 return mc_send_command(mc_io, &cmd);
312 int dprc_disconnect(struct fsl_mc_io *mc_io,
315 const struct dprc_endpoint *endpoint)
317 struct mc_command cmd = { 0 };
319 /* prepare command */
320 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
323 DPRC_CMD_DISCONNECT(cmd, endpoint);
325 /* send command to mc*/
326 return mc_send_command(mc_io, &cmd);
329 int dprc_get_connection(struct fsl_mc_io *mc_io,
332 const struct dprc_endpoint *endpoint1,
333 struct dprc_endpoint *endpoint2,
336 struct mc_command cmd = { 0 };
339 /* prepare command */
340 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
343 DPRC_CMD_GET_CONNECTION(cmd, endpoint1);
345 /* send command to mc*/
346 err = mc_send_command(mc_io, &cmd);
350 /* retrieve response parameters */
351 DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state);
356 int dprc_get_api_version(struct fsl_mc_io *mc_io,
361 struct mc_command cmd = { 0 };
364 /* prepare command */
365 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
368 /* send command to mc */
369 err = mc_send_command(mc_io, &cmd);
373 /* retrieve response parameters */
374 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);