Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Freescale Layerscape MC I/O wrapper |
| 4 | * |
Yogesh Gaur | a6f2a6e | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 5 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 6 | * Copyright 2017 NXP |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 13 | int dprc_get_container_id(struct fsl_mc_io *mc_io, |
| 14 | uint32_t cmd_flags, |
| 15 | int *container_id) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 16 | { |
| 17 | struct mc_command cmd = { 0 }; |
| 18 | int err; |
| 19 | |
| 20 | /* prepare command */ |
| 21 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 22 | cmd_flags, |
| 23 | 0); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 24 | |
| 25 | /* send command to mc*/ |
| 26 | err = mc_send_command(mc_io, &cmd); |
| 27 | if (err) |
| 28 | return err; |
| 29 | |
| 30 | /* retrieve response parameters */ |
| 31 | DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 36 | int dprc_open(struct fsl_mc_io *mc_io, |
| 37 | uint32_t cmd_flags, |
| 38 | int container_id, |
| 39 | uint16_t *token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 40 | { |
| 41 | struct mc_command cmd = { 0 }; |
| 42 | int err; |
| 43 | |
| 44 | /* prepare command */ |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 45 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 46 | 0); |
| 47 | DPRC_CMD_OPEN(cmd, container_id); |
| 48 | |
| 49 | /* send command to mc*/ |
| 50 | err = mc_send_command(mc_io, &cmd); |
| 51 | if (err) |
| 52 | return err; |
| 53 | |
| 54 | /* retrieve response parameters */ |
| 55 | *token = MC_CMD_HDR_READ_TOKEN(cmd.header); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 60 | int dprc_close(struct fsl_mc_io *mc_io, |
| 61 | uint32_t cmd_flags, |
| 62 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 63 | { |
| 64 | struct mc_command cmd = { 0 }; |
| 65 | |
| 66 | /* prepare command */ |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 67 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 68 | token); |
| 69 | |
| 70 | /* send command to mc*/ |
| 71 | return mc_send_command(mc_io, &cmd); |
| 72 | } |
| 73 | |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 74 | int 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 | /* prepare command */ |
| 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 | /* send command to mc*/ |
| 92 | err = mc_send_command(mc_io, &cmd); |
| 93 | if (err) |
| 94 | return err; |
| 95 | |
| 96 | /* retrieve response parameters */ |
| 97 | DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id, |
| 98 | *child_portal_paddr); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int 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 | /* prepare command */ |
| 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 | /* send command to mc*/ |
| 117 | return mc_send_command(mc_io, &cmd); |
| 118 | } |
| 119 | |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 120 | int dprc_reset_container(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 121 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 122 | uint16_t token, |
| 123 | int child_container_id) |
| 124 | { |
| 125 | struct mc_command cmd = { 0 }; |
| 126 | |
| 127 | /* prepare command */ |
| 128 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 129 | cmd_flags, |
| 130 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 131 | DPRC_CMD_RESET_CONTAINER(cmd, child_container_id); |
| 132 | |
| 133 | /* send command to mc*/ |
| 134 | return mc_send_command(mc_io, &cmd); |
| 135 | } |
| 136 | |
| 137 | int dprc_get_attributes(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 138 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 139 | uint16_t token, |
| 140 | struct dprc_attributes *attr) |
| 141 | { |
| 142 | struct mc_command cmd = { 0 }; |
| 143 | int err; |
| 144 | |
| 145 | /* prepare command */ |
| 146 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 147 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 148 | token); |
| 149 | |
| 150 | /* send command to mc*/ |
| 151 | err = mc_send_command(mc_io, &cmd); |
| 152 | if (err) |
| 153 | return err; |
| 154 | |
| 155 | /* retrieve response parameters */ |
| 156 | DPRC_RSP_GET_ATTRIBUTES(cmd, attr); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 161 | int dprc_get_obj_count(struct fsl_mc_io *mc_io, |
| 162 | uint32_t cmd_flags, |
| 163 | uint16_t token, |
| 164 | int *obj_count) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 165 | { |
| 166 | struct mc_command cmd = { 0 }; |
| 167 | int err; |
| 168 | |
| 169 | /* prepare command */ |
| 170 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 171 | cmd_flags, |
| 172 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 173 | |
| 174 | /* send command to mc*/ |
| 175 | err = mc_send_command(mc_io, &cmd); |
| 176 | if (err) |
| 177 | return err; |
| 178 | |
| 179 | /* retrieve response parameters */ |
| 180 | DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count); |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | int dprc_get_obj(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 186 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | /* prepare command */ |
| 195 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 196 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 197 | token); |
| 198 | DPRC_CMD_GET_OBJ(cmd, obj_index); |
| 199 | |
| 200 | /* send command to mc*/ |
| 201 | err = mc_send_command(mc_io, &cmd); |
| 202 | if (err) |
| 203 | return err; |
| 204 | |
| 205 | /* retrieve response parameters */ |
| 206 | DPRC_RSP_GET_OBJ(cmd, obj_desc); |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | int dprc_get_res_count(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 212 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | /* prepare command */ |
| 223 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 224 | cmd_flags, |
| 225 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 226 | DPRC_CMD_GET_RES_COUNT(cmd, type); |
| 227 | |
| 228 | /* send command to mc*/ |
| 229 | err = mc_send_command(mc_io, &cmd); |
| 230 | if (err) |
| 231 | return err; |
| 232 | |
| 233 | /* retrieve response parameters */ |
| 234 | DPRC_RSP_GET_RES_COUNT(cmd, *res_count); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | int dprc_get_res_ids(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 240 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | /* prepare command */ |
| 249 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 250 | cmd_flags, |
| 251 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 252 | DPRC_CMD_GET_RES_IDS(cmd, range_desc, type); |
| 253 | |
| 254 | /* send command to mc*/ |
| 255 | err = mc_send_command(mc_io, &cmd); |
| 256 | if (err) |
| 257 | return err; |
| 258 | |
| 259 | /* retrieve response parameters */ |
| 260 | DPRC_RSP_GET_RES_IDS(cmd, range_desc); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | int dprc_get_obj_region(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 266 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | /* prepare command */ |
| 277 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 278 | cmd_flags, |
| 279 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 280 | DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index); |
| 281 | |
| 282 | /* send command to mc*/ |
| 283 | err = mc_send_command(mc_io, &cmd); |
| 284 | if (err) |
| 285 | return err; |
| 286 | |
| 287 | /* retrieve response parameters */ |
| 288 | DPRC_RSP_GET_OBJ_REGION(cmd, region_desc); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | int dprc_connect(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 294 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 295 | uint16_t token, |
| 296 | const struct dprc_endpoint *endpoint1, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 297 | const struct dprc_endpoint *endpoint2, |
| 298 | const struct dprc_connection_cfg *cfg) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 299 | { |
| 300 | struct mc_command cmd = { 0 }; |
| 301 | |
| 302 | /* prepare command */ |
| 303 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 304 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 305 | token); |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 306 | DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 307 | |
| 308 | /* send command to mc*/ |
| 309 | return mc_send_command(mc_io, &cmd); |
| 310 | } |
| 311 | |
| 312 | int dprc_disconnect(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 313 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 314 | uint16_t token, |
| 315 | const struct dprc_endpoint *endpoint) |
| 316 | { |
| 317 | struct mc_command cmd = { 0 }; |
| 318 | |
| 319 | /* prepare command */ |
| 320 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 321 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 322 | token); |
| 323 | DPRC_CMD_DISCONNECT(cmd, endpoint); |
| 324 | |
| 325 | /* send command to mc*/ |
| 326 | return mc_send_command(mc_io, &cmd); |
| 327 | } |
| 328 | |
| 329 | int dprc_get_connection(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 330 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 331 | uint16_t token, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 332 | const struct dprc_endpoint *endpoint1, |
| 333 | struct dprc_endpoint *endpoint2, |
| 334 | int *state) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 335 | { |
| 336 | struct mc_command cmd = { 0 }; |
| 337 | int err; |
| 338 | |
| 339 | /* prepare command */ |
| 340 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 341 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 342 | token); |
| 343 | DPRC_CMD_GET_CONNECTION(cmd, endpoint1); |
| 344 | |
| 345 | /* send command to mc*/ |
| 346 | err = mc_send_command(mc_io, &cmd); |
| 347 | if (err) |
| 348 | return err; |
| 349 | |
| 350 | /* retrieve response parameters */ |
| 351 | DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state); |
| 352 | |
| 353 | return 0; |
| 354 | } |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 355 | |
| 356 | int 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 | /* prepare command */ |
| 365 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION, |
| 366 | cmd_flags, 0); |
| 367 | |
| 368 | /* send command to mc */ |
| 369 | err = mc_send_command(mc_io, &cmd); |
| 370 | if (err) |
| 371 | return err; |
| 372 | |
| 373 | /* retrieve response parameters */ |
| 374 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 375 | |
| 376 | return 0; |
| 377 | } |