Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame^] | 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, int *container_id) |
| 15 | { |
| 16 | struct mc_command cmd = { 0 }; |
| 17 | int err; |
| 18 | |
| 19 | /* prepare command */ |
| 20 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID, |
| 21 | MC_CMD_PRI_LOW, 0); |
| 22 | |
| 23 | /* send command to mc*/ |
| 24 | err = mc_send_command(mc_io, &cmd); |
| 25 | if (err) |
| 26 | return err; |
| 27 | |
| 28 | /* retrieve response parameters */ |
| 29 | DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token) |
| 35 | { |
| 36 | struct mc_command cmd = { 0 }; |
| 37 | int err; |
| 38 | |
| 39 | /* prepare command */ |
| 40 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, MC_CMD_PRI_LOW, |
| 41 | 0); |
| 42 | DPRC_CMD_OPEN(cmd, container_id); |
| 43 | |
| 44 | /* send command to mc*/ |
| 45 | err = mc_send_command(mc_io, &cmd); |
| 46 | if (err) |
| 47 | return err; |
| 48 | |
| 49 | /* retrieve response parameters */ |
| 50 | *token = MC_CMD_HDR_READ_TOKEN(cmd.header); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int dprc_close(struct fsl_mc_io *mc_io, uint16_t token) |
| 56 | { |
| 57 | struct mc_command cmd = { 0 }; |
| 58 | |
| 59 | /* prepare command */ |
| 60 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, MC_CMD_PRI_HIGH, |
| 61 | token); |
| 62 | |
| 63 | /* send command to mc*/ |
| 64 | return mc_send_command(mc_io, &cmd); |
| 65 | } |
| 66 | |
| 67 | int dprc_reset_container(struct fsl_mc_io *mc_io, |
| 68 | uint16_t token, |
| 69 | int child_container_id) |
| 70 | { |
| 71 | struct mc_command cmd = { 0 }; |
| 72 | |
| 73 | /* prepare command */ |
| 74 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT, |
| 75 | MC_CMD_PRI_LOW, token); |
| 76 | DPRC_CMD_RESET_CONTAINER(cmd, child_container_id); |
| 77 | |
| 78 | /* send command to mc*/ |
| 79 | return mc_send_command(mc_io, &cmd); |
| 80 | } |
| 81 | |
| 82 | int dprc_get_attributes(struct fsl_mc_io *mc_io, |
| 83 | uint16_t token, |
| 84 | struct dprc_attributes *attr) |
| 85 | { |
| 86 | struct mc_command cmd = { 0 }; |
| 87 | int err; |
| 88 | |
| 89 | /* prepare command */ |
| 90 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR, |
| 91 | MC_CMD_PRI_LOW, |
| 92 | token); |
| 93 | |
| 94 | /* send command to mc*/ |
| 95 | err = mc_send_command(mc_io, &cmd); |
| 96 | if (err) |
| 97 | return err; |
| 98 | |
| 99 | /* retrieve response parameters */ |
| 100 | DPRC_RSP_GET_ATTRIBUTES(cmd, attr); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count) |
| 106 | { |
| 107 | struct mc_command cmd = { 0 }; |
| 108 | int err; |
| 109 | |
| 110 | /* prepare command */ |
| 111 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT, |
| 112 | MC_CMD_PRI_LOW, token); |
| 113 | |
| 114 | /* send command to mc*/ |
| 115 | err = mc_send_command(mc_io, &cmd); |
| 116 | if (err) |
| 117 | return err; |
| 118 | |
| 119 | /* retrieve response parameters */ |
| 120 | DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | int dprc_get_obj(struct fsl_mc_io *mc_io, |
| 126 | uint16_t token, |
| 127 | int obj_index, |
| 128 | struct dprc_obj_desc *obj_desc) |
| 129 | { |
| 130 | struct mc_command cmd = { 0 }; |
| 131 | int err; |
| 132 | |
| 133 | /* prepare command */ |
| 134 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ, |
| 135 | MC_CMD_PRI_LOW, |
| 136 | token); |
| 137 | DPRC_CMD_GET_OBJ(cmd, obj_index); |
| 138 | |
| 139 | /* send command to mc*/ |
| 140 | err = mc_send_command(mc_io, &cmd); |
| 141 | if (err) |
| 142 | return err; |
| 143 | |
| 144 | /* retrieve response parameters */ |
| 145 | DPRC_RSP_GET_OBJ(cmd, obj_desc); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | int dprc_get_res_count(struct fsl_mc_io *mc_io, |
| 151 | uint16_t token, |
| 152 | char *type, |
| 153 | int *res_count) |
| 154 | { |
| 155 | struct mc_command cmd = { 0 }; |
| 156 | int err; |
| 157 | |
| 158 | *res_count = 0; |
| 159 | |
| 160 | /* prepare command */ |
| 161 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT, |
| 162 | MC_CMD_PRI_LOW, token); |
| 163 | DPRC_CMD_GET_RES_COUNT(cmd, type); |
| 164 | |
| 165 | /* send command to mc*/ |
| 166 | err = mc_send_command(mc_io, &cmd); |
| 167 | if (err) |
| 168 | return err; |
| 169 | |
| 170 | /* retrieve response parameters */ |
| 171 | DPRC_RSP_GET_RES_COUNT(cmd, *res_count); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int dprc_get_res_ids(struct fsl_mc_io *mc_io, |
| 177 | uint16_t token, |
| 178 | char *type, |
| 179 | struct dprc_res_ids_range_desc *range_desc) |
| 180 | { |
| 181 | struct mc_command cmd = { 0 }; |
| 182 | int err; |
| 183 | |
| 184 | /* prepare command */ |
| 185 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS, |
| 186 | MC_CMD_PRI_LOW, token); |
| 187 | DPRC_CMD_GET_RES_IDS(cmd, range_desc, type); |
| 188 | |
| 189 | /* send command to mc*/ |
| 190 | err = mc_send_command(mc_io, &cmd); |
| 191 | if (err) |
| 192 | return err; |
| 193 | |
| 194 | /* retrieve response parameters */ |
| 195 | DPRC_RSP_GET_RES_IDS(cmd, range_desc); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | int dprc_get_obj_region(struct fsl_mc_io *mc_io, |
| 201 | uint16_t token, |
| 202 | char *obj_type, |
| 203 | int obj_id, |
| 204 | uint8_t region_index, |
| 205 | struct dprc_region_desc *region_desc) |
| 206 | { |
| 207 | struct mc_command cmd = { 0 }; |
| 208 | int err; |
| 209 | |
| 210 | /* prepare command */ |
| 211 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG, |
| 212 | MC_CMD_PRI_LOW, token); |
| 213 | DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index); |
| 214 | |
| 215 | /* send command to mc*/ |
| 216 | err = mc_send_command(mc_io, &cmd); |
| 217 | if (err) |
| 218 | return err; |
| 219 | |
| 220 | /* retrieve response parameters */ |
| 221 | DPRC_RSP_GET_OBJ_REGION(cmd, region_desc); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | int dprc_connect(struct fsl_mc_io *mc_io, |
| 227 | uint16_t token, |
| 228 | const struct dprc_endpoint *endpoint1, |
| 229 | const struct dprc_endpoint *endpoint2) |
| 230 | { |
| 231 | struct mc_command cmd = { 0 }; |
| 232 | |
| 233 | /* prepare command */ |
| 234 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT, |
| 235 | MC_CMD_PRI_LOW, |
| 236 | token); |
| 237 | DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2); |
| 238 | |
| 239 | /* send command to mc*/ |
| 240 | return mc_send_command(mc_io, &cmd); |
| 241 | } |
| 242 | |
| 243 | int dprc_disconnect(struct fsl_mc_io *mc_io, |
| 244 | uint16_t token, |
| 245 | const struct dprc_endpoint *endpoint) |
| 246 | { |
| 247 | struct mc_command cmd = { 0 }; |
| 248 | |
| 249 | /* prepare command */ |
| 250 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT, |
| 251 | MC_CMD_PRI_LOW, |
| 252 | token); |
| 253 | DPRC_CMD_DISCONNECT(cmd, endpoint); |
| 254 | |
| 255 | /* send command to mc*/ |
| 256 | return mc_send_command(mc_io, &cmd); |
| 257 | } |
| 258 | |
| 259 | int dprc_get_connection(struct fsl_mc_io *mc_io, |
| 260 | uint16_t token, |
| 261 | const struct dprc_endpoint *endpoint1, |
| 262 | struct dprc_endpoint *endpoint2, |
| 263 | int *state) |
| 264 | { |
| 265 | struct mc_command cmd = { 0 }; |
| 266 | int err; |
| 267 | |
| 268 | /* prepare command */ |
| 269 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, |
| 270 | MC_CMD_PRI_LOW, |
| 271 | token); |
| 272 | DPRC_CMD_GET_CONNECTION(cmd, endpoint1); |
| 273 | |
| 274 | /* send command to mc*/ |
| 275 | err = mc_send_command(mc_io, &cmd); |
| 276 | if (err) |
| 277 | return err; |
| 278 | |
| 279 | /* retrieve response parameters */ |
| 280 | DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state); |
| 281 | |
| 282 | return 0; |
| 283 | } |