blob: e0a2865ab8f55b2d51125b50674bb517a223707b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07002/*
3 * Freescale Layerscape MC I/O wrapper
4 *
Yogesh Gaura6f2a6e2018-05-09 10:52:17 +05305 * Copyright 2013-2016 Freescale Semiconductor, Inc.
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05306 * Copyright 2017 NXP
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07007 */
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 Kushwaha87457d12015-07-07 15:40:06 +053013int dprc_get_container_id(struct fsl_mc_io *mc_io,
14 uint32_t cmd_flags,
15 int *container_id)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070016{
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 Kushwaha87457d12015-07-07 15:40:06 +053022 cmd_flags,
23 0);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070024
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 Kushwaha87457d12015-07-07 15:40:06 +053036int dprc_open(struct fsl_mc_io *mc_io,
37 uint32_t cmd_flags,
38 int container_id,
39 uint16_t *token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070040{
41 struct mc_command cmd = { 0 };
42 int err;
43
44 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053045 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070046 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 Kushwaha87457d12015-07-07 15:40:06 +053060int dprc_close(struct fsl_mc_io *mc_io,
61 uint32_t cmd_flags,
62 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070063{
64 struct mc_command cmd = { 0 };
65
66 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053067 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070068 token);
69
70 /* send command to mc*/
71 return mc_send_command(mc_io, &cmd);
72}
73
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053074int 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
103int 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 Kushwahaa2a55e52015-03-19 09:20:45 -0700120int dprc_reset_container(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530121 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700122 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 Kushwaha87457d12015-07-07 15:40:06 +0530129 cmd_flags,
130 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700131 DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
132
133 /* send command to mc*/
134 return mc_send_command(mc_io, &cmd);
135}
136
137int dprc_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530138 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700139 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 Kushwaha87457d12015-07-07 15:40:06 +0530147 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700148 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 Kushwaha87457d12015-07-07 15:40:06 +0530161int dprc_get_obj_count(struct fsl_mc_io *mc_io,
162 uint32_t cmd_flags,
163 uint16_t token,
164 int *obj_count)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700165{
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 Kushwaha87457d12015-07-07 15:40:06 +0530171 cmd_flags,
172 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700173
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
185int dprc_get_obj(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530186 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700187 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 Kushwaha87457d12015-07-07 15:40:06 +0530196 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700197 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
211int dprc_get_res_count(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530212 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700213 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 Kushwaha87457d12015-07-07 15:40:06 +0530224 cmd_flags,
225 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700226 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
239int dprc_get_res_ids(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530240 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700241 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 Kushwaha87457d12015-07-07 15:40:06 +0530250 cmd_flags,
251 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700252 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
265int dprc_get_obj_region(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530266 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700267 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 Kushwaha87457d12015-07-07 15:40:06 +0530278 cmd_flags,
279 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700280 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
293int dprc_connect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530294 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700295 uint16_t token,
296 const struct dprc_endpoint *endpoint1,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530297 const struct dprc_endpoint *endpoint2,
298 const struct dprc_connection_cfg *cfg)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700299{
300 struct mc_command cmd = { 0 };
301
302 /* prepare command */
303 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530304 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700305 token);
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530306 DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700307
308 /* send command to mc*/
309 return mc_send_command(mc_io, &cmd);
310}
311
312int dprc_disconnect(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530313 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700314 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 Kushwaha87457d12015-07-07 15:40:06 +0530321 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700322 token);
323 DPRC_CMD_DISCONNECT(cmd, endpoint);
324
325 /* send command to mc*/
326 return mc_send_command(mc_io, &cmd);
327}
328
329int dprc_get_connection(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530330 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700331 uint16_t token,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530332 const struct dprc_endpoint *endpoint1,
333 struct dprc_endpoint *endpoint2,
334 int *state)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700335{
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 Kushwaha87457d12015-07-07 15:40:06 +0530341 cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700342 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 Gaur2557c5a2017-11-15 11:59:31 +0530355
356int 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}