blob: 357aa4808b5a1843798716c593be29a99957cbb1 [file] [log] [blame]
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001/*
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
Prabhakar Kushwaha87457d12015-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 Kushwahaa2a55e52015-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 Kushwaha87457d12015-07-07 15:40:06 +053023 cmd_flags,
24 0);
Prabhakar Kushwahaa2a55e52015-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 Kushwaha87457d12015-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 Kushwahaa2a55e52015-03-19 09:20:45 -070041{
42 struct mc_command cmd = { 0 };
43 int err;
44
45 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053046 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
Prabhakar Kushwahaa2a55e52015-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 Kushwaha87457d12015-07-07 15:40:06 +053061int dprc_close(struct fsl_mc_io *mc_io,
62 uint32_t cmd_flags,
63 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070064{
65 struct mc_command cmd = { 0 };
66
67 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053068 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070069 token);
70
71 /* send command to mc*/
72 return mc_send_command(mc_io, &cmd);
73}
74
75int dprc_reset_container(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053076 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070077 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053084 cmd_flags,
85 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070086 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
87
88 /* send command to mc*/
89 return mc_send_command(mc_io, &cmd);
90}
91
92int dprc_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053093 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070094 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530102 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700103 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
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530116int dprc_get_obj_count(struct fsl_mc_io *mc_io,
117 uint32_t cmd_flags,
118 uint16_t token,
119 int *obj_count)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700120{
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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530126 cmd_flags,
127 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700128
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
140int dprc_get_obj(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530141 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700142 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530151 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700152 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
166int dprc_get_res_count(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530167 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700168 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530179 cmd_flags,
180 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700181 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
194int dprc_get_res_ids(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530195 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700196 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530205 cmd_flags,
206 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700207 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
220int dprc_get_obj_region(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530221 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700222 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530233 cmd_flags,
234 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700235 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
248int dprc_connect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530249 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700250 uint16_t token,
251 const struct dprc_endpoint *endpoint1,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530252 const struct dprc_endpoint *endpoint2,
253 const struct dprc_connection_cfg *cfg)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700254{
255 struct mc_command cmd = { 0 };
256
257 /* prepare command */
258 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530259 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700260 token);
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530261 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700262
263 /* send command to mc*/
264 return mc_send_command(mc_io, &cmd);
265}
266
267int dprc_disconnect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530268 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700269 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,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530276 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700277 token);
278 DPRC_CMD_DISCONNECT(cmd, endpoint);
279
280 /* send command to mc*/
281 return mc_send_command(mc_io, &cmd);
282}
283
284int dprc_get_connection(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530285 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700286 uint16_t token,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530287 const struct dprc_endpoint *endpoint1,
288 struct dprc_endpoint *endpoint2,
289 int *state)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700290{
291 struct mc_command cmd = { 0 };
292 int err;
293
294 /* prepare command */
295 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530296 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700297 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}