1 /* 2 * Freescale Layerscape MC I/O wrapper 3 * 4 * Copyright (C) 2013-2015 Freescale Semiconductor, Inc. 5 * Author: German Rivera <German.Rivera@freescale.com> 6 * 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 14 int dprc_get_container_id(struct fsl_mc_io *mc_io, 15 uint32_t cmd_flags, 16 int *container_id) 17 { 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, 23 cmd_flags, 24 0); 25 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 37 int dprc_open(struct fsl_mc_io *mc_io, 38 uint32_t cmd_flags, 39 int container_id, 40 uint16_t *token) 41 { 42 struct mc_command cmd = { 0 }; 43 int err; 44 45 /* prepare command */ 46 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, 47 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 61 int dprc_close(struct fsl_mc_io *mc_io, 62 uint32_t cmd_flags, 63 uint16_t token) 64 { 65 struct mc_command cmd = { 0 }; 66 67 /* prepare command */ 68 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, 69 token); 70 71 /* send command to mc*/ 72 return mc_send_command(mc_io, &cmd); 73 } 74 75 int dprc_reset_container(struct fsl_mc_io *mc_io, 76 uint32_t cmd_flags, 77 uint16_t token, 78 int child_container_id) 79 { 80 struct mc_command cmd = { 0 }; 81 82 /* prepare command */ 83 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT, 84 cmd_flags, 85 token); 86 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id); 87 88 /* send command to mc*/ 89 return mc_send_command(mc_io, &cmd); 90 } 91 92 int dprc_get_attributes(struct fsl_mc_io *mc_io, 93 uint32_t cmd_flags, 94 uint16_t token, 95 struct dprc_attributes *attr) 96 { 97 struct mc_command cmd = { 0 }; 98 int err; 99 100 /* prepare command */ 101 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR, 102 cmd_flags, 103 token); 104 105 /* send command to mc*/ 106 err = mc_send_command(mc_io, &cmd); 107 if (err) 108 return err; 109 110 /* retrieve response parameters */ 111 DPRC_RSP_GET_ATTRIBUTES(cmd, attr); 112 113 return 0; 114 } 115 116 int dprc_get_obj_count(struct fsl_mc_io *mc_io, 117 uint32_t cmd_flags, 118 uint16_t token, 119 int *obj_count) 120 { 121 struct mc_command cmd = { 0 }; 122 int err; 123 124 /* prepare command */ 125 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT, 126 cmd_flags, 127 token); 128 129 /* send command to mc*/ 130 err = mc_send_command(mc_io, &cmd); 131 if (err) 132 return err; 133 134 /* retrieve response parameters */ 135 DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count); 136 137 return 0; 138 } 139 140 int dprc_get_obj(struct fsl_mc_io *mc_io, 141 uint32_t cmd_flags, 142 uint16_t token, 143 int obj_index, 144 struct dprc_obj_desc *obj_desc) 145 { 146 struct mc_command cmd = { 0 }; 147 int err; 148 149 /* prepare command */ 150 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ, 151 cmd_flags, 152 token); 153 DPRC_CMD_GET_OBJ(cmd, obj_index); 154 155 /* send command to mc*/ 156 err = mc_send_command(mc_io, &cmd); 157 if (err) 158 return err; 159 160 /* retrieve response parameters */ 161 DPRC_RSP_GET_OBJ(cmd, obj_desc); 162 163 return 0; 164 } 165 166 int dprc_get_res_count(struct fsl_mc_io *mc_io, 167 uint32_t cmd_flags, 168 uint16_t token, 169 char *type, 170 int *res_count) 171 { 172 struct mc_command cmd = { 0 }; 173 int err; 174 175 *res_count = 0; 176 177 /* prepare command */ 178 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT, 179 cmd_flags, 180 token); 181 DPRC_CMD_GET_RES_COUNT(cmd, type); 182 183 /* send command to mc*/ 184 err = mc_send_command(mc_io, &cmd); 185 if (err) 186 return err; 187 188 /* retrieve response parameters */ 189 DPRC_RSP_GET_RES_COUNT(cmd, *res_count); 190 191 return 0; 192 } 193 194 int dprc_get_res_ids(struct fsl_mc_io *mc_io, 195 uint32_t cmd_flags, 196 uint16_t token, 197 char *type, 198 struct dprc_res_ids_range_desc *range_desc) 199 { 200 struct mc_command cmd = { 0 }; 201 int err; 202 203 /* prepare command */ 204 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS, 205 cmd_flags, 206 token); 207 DPRC_CMD_GET_RES_IDS(cmd, range_desc, type); 208 209 /* send command to mc*/ 210 err = mc_send_command(mc_io, &cmd); 211 if (err) 212 return err; 213 214 /* retrieve response parameters */ 215 DPRC_RSP_GET_RES_IDS(cmd, range_desc); 216 217 return 0; 218 } 219 220 int dprc_get_obj_region(struct fsl_mc_io *mc_io, 221 uint32_t cmd_flags, 222 uint16_t token, 223 char *obj_type, 224 int obj_id, 225 uint8_t region_index, 226 struct dprc_region_desc *region_desc) 227 { 228 struct mc_command cmd = { 0 }; 229 int err; 230 231 /* prepare command */ 232 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG, 233 cmd_flags, 234 token); 235 DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index); 236 237 /* send command to mc*/ 238 err = mc_send_command(mc_io, &cmd); 239 if (err) 240 return err; 241 242 /* retrieve response parameters */ 243 DPRC_RSP_GET_OBJ_REGION(cmd, region_desc); 244 245 return 0; 246 } 247 248 int dprc_connect(struct fsl_mc_io *mc_io, 249 uint32_t cmd_flags, 250 uint16_t token, 251 const struct dprc_endpoint *endpoint1, 252 const struct dprc_endpoint *endpoint2, 253 const struct dprc_connection_cfg *cfg) 254 { 255 struct mc_command cmd = { 0 }; 256 257 /* prepare command */ 258 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT, 259 cmd_flags, 260 token); 261 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg); 262 263 /* send command to mc*/ 264 return mc_send_command(mc_io, &cmd); 265 } 266 267 int dprc_disconnect(struct fsl_mc_io *mc_io, 268 uint32_t cmd_flags, 269 uint16_t token, 270 const struct dprc_endpoint *endpoint) 271 { 272 struct mc_command cmd = { 0 }; 273 274 /* prepare command */ 275 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT, 276 cmd_flags, 277 token); 278 DPRC_CMD_DISCONNECT(cmd, endpoint); 279 280 /* send command to mc*/ 281 return mc_send_command(mc_io, &cmd); 282 } 283 284 int dprc_get_connection(struct fsl_mc_io *mc_io, 285 uint32_t cmd_flags, 286 uint16_t token, 287 const struct dprc_endpoint *endpoint1, 288 struct dprc_endpoint *endpoint2, 289 int *state) 290 { 291 struct mc_command cmd = { 0 }; 292 int err; 293 294 /* prepare command */ 295 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, 296 cmd_flags, 297 token); 298 DPRC_CMD_GET_CONNECTION(cmd, endpoint1); 299 300 /* send command to mc*/ 301 err = mc_send_command(mc_io, &cmd); 302 if (err) 303 return err; 304 305 /* retrieve response parameters */ 306 DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state); 307 308 return 0; 309 } 310