1/* Copyright 2013-2014 Freescale Semiconductor Inc.
2*
3* Redistribution and use in source and binary forms, with or without
4* modification, are permitted provided that the following conditions are met:
5* * Redistributions of source code must retain the above copyright
6* notice, this list of conditions and the following disclaimer.
7* * Redistributions in binary form must reproduce the above copyright
8* notice, this list of conditions and the following disclaimer in the
9* documentation and/or other materials provided with the distribution.
10* * Neither the name of the above-listed copyright holders nor the
11* names of any contributors may be used to endorse or promote products
12* derived from this software without specific prior written permission.
13*
14*
15* ALTERNATIVELY, this software may be distributed under the terms of the
16* GNU General Public License ("GPL") as published by the Free Software
17* Foundation, either version 2 of that License or (at your option) any
18* later version.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*/
32#include "../include/mc-sys.h"
33#include "../include/mc-cmd.h"
34#include "../include/dprc.h"
35#include "dprc-cmd.h"
36
37int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token)
38{
39	struct mc_command cmd = { 0 };
40	int err;
41
42	/* prepare command */
43	cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, MC_CMD_PRI_LOW,
44					  0);
45	cmd.params[0] |= mc_enc(0, 32, container_id);
46
47	/* send command to mc*/
48	err = mc_send_command(mc_io, &cmd);
49	if (err)
50		return err;
51
52	/* retrieve response parameters */
53	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
54
55	return 0;
56}
57EXPORT_SYMBOL(dprc_open);
58
59int dprc_close(struct fsl_mc_io *mc_io, uint16_t token)
60{
61	struct mc_command cmd = { 0 };
62
63	/* prepare command */
64	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, MC_CMD_PRI_HIGH,
65					  token);
66
67	/* send command to mc*/
68	return mc_send_command(mc_io, &cmd);
69}
70EXPORT_SYMBOL(dprc_close);
71
72int dprc_create_container(struct fsl_mc_io *mc_io,
73			  uint16_t token,
74			  struct dprc_cfg *cfg,
75			  int *child_container_id,
76			  uint64_t *child_portal_paddr)
77{
78	struct mc_command cmd = { 0 };
79	int err;
80
81	/* prepare command */
82	cmd.params[0] |= mc_enc(32, 16, cfg->icid);
83	cmd.params[0] |= mc_enc(0, 32, cfg->options);
84	cmd.params[1] |= mc_enc(32, 32, cfg->portal_id);
85
86	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
87					  MC_CMD_PRI_LOW, token);
88
89	/* send command to mc*/
90	err = mc_send_command(mc_io, &cmd);
91	if (err)
92		return err;
93
94	/* retrieve response parameters */
95	*child_container_id = mc_dec(cmd.params[1], 0, 32);
96	*child_portal_paddr = mc_dec(cmd.params[2], 0, 64);
97
98	return 0;
99}
100
101int dprc_destroy_container(struct fsl_mc_io *mc_io,
102			   uint16_t token,
103			   int child_container_id)
104{
105	struct mc_command cmd = { 0 };
106
107	/* prepare command */
108	cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
109					  MC_CMD_PRI_LOW, token);
110	cmd.params[0] |= mc_enc(0, 32, child_container_id);
111
112	/* send command to mc*/
113	return mc_send_command(mc_io, &cmd);
114}
115
116int dprc_reset_container(struct fsl_mc_io *mc_io,
117			 uint16_t token,
118			 int child_container_id)
119{
120	struct mc_command cmd = { 0 };
121
122	/* prepare command */
123	cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
124					  MC_CMD_PRI_LOW, token);
125	cmd.params[0] |= mc_enc(0, 32, child_container_id);
126
127	/* send command to mc*/
128	return mc_send_command(mc_io, &cmd);
129}
130
131int dprc_get_irq(struct fsl_mc_io *mc_io,
132		 uint16_t token,
133		 uint8_t irq_index,
134		 int *type,
135		 uint64_t *irq_paddr,
136		 uint32_t *irq_val,
137		 int *user_irq_id)
138{
139	struct mc_command cmd = { 0 };
140	int err;
141
142	/* prepare command */
143	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
144					  MC_CMD_PRI_LOW,
145					  token);
146	cmd.params[0] |= mc_enc(32, 8, irq_index);
147
148	/* send command to mc*/
149	err = mc_send_command(mc_io, &cmd);
150	if (err)
151		return err;
152
153	/* retrieve response parameters */
154	*irq_val = mc_dec(cmd.params[0], 0, 32);
155	*irq_paddr = mc_dec(cmd.params[1], 0, 64);
156	*user_irq_id = mc_dec(cmd.params[2], 0, 32);
157	*type = mc_dec(cmd.params[2], 32, 32);
158
159	return 0;
160}
161
162int dprc_set_irq(struct fsl_mc_io *mc_io,
163		 uint16_t token,
164		 uint8_t irq_index,
165		 uint64_t irq_paddr,
166		 uint32_t irq_val,
167		 int user_irq_id)
168{
169	struct mc_command cmd = { 0 };
170
171	/* prepare command */
172	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
173					  MC_CMD_PRI_LOW,
174					  token);
175	cmd.params[0] |= mc_enc(32, 8, irq_index);
176	cmd.params[0] |= mc_enc(0, 32, irq_val);
177	cmd.params[1] |= mc_enc(0, 64, irq_paddr);
178	cmd.params[2] |= mc_enc(0, 32, user_irq_id);
179
180	/* send command to mc*/
181	return mc_send_command(mc_io, &cmd);
182}
183
184int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
185			uint16_t token,
186			uint8_t irq_index,
187			uint8_t *en)
188{
189	struct mc_command cmd = { 0 };
190	int err;
191
192	/* prepare command */
193	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
194					  MC_CMD_PRI_LOW, token);
195	cmd.params[0] |= mc_enc(32, 8, irq_index);
196
197	/* send command to mc*/
198	err = mc_send_command(mc_io, &cmd);
199	if (err)
200		return err;
201
202	/* retrieve response parameters */
203	*en = mc_dec(cmd.params[0], 0, 8);
204
205	return 0;
206}
207
208int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
209			uint16_t token,
210			uint8_t irq_index,
211			uint8_t en)
212{
213	struct mc_command cmd = { 0 };
214
215	/* prepare command */
216	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
217					  MC_CMD_PRI_LOW, token);
218	cmd.params[0] |= mc_enc(0, 8, en);
219	cmd.params[0] |= mc_enc(32, 8, irq_index);
220
221	/* send command to mc*/
222	return mc_send_command(mc_io, &cmd);
223}
224
225int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
226		      uint16_t token,
227		      uint8_t irq_index,
228		      uint32_t *mask)
229{
230	struct mc_command cmd = { 0 };
231	int err;
232
233	/* prepare command */
234	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
235					  MC_CMD_PRI_LOW, token);
236	cmd.params[0] |= mc_enc(32, 8, irq_index);
237
238	/* send command to mc*/
239	err = mc_send_command(mc_io, &cmd);
240	if (err)
241		return err;
242
243	/* retrieve response parameters */
244	*mask = mc_dec(cmd.params[0], 0, 32);
245
246	return 0;
247}
248
249int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
250		      uint16_t token,
251		      uint8_t irq_index,
252		      uint32_t mask)
253{
254	struct mc_command cmd = { 0 };
255
256	/* prepare command */
257	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
258					  MC_CMD_PRI_LOW, token);
259	cmd.params[0] |= mc_enc(0, 32, mask);
260	cmd.params[0] |= mc_enc(32, 8, irq_index);
261
262	/* send command to mc*/
263	return mc_send_command(mc_io, &cmd);
264}
265
266int dprc_get_irq_status(struct fsl_mc_io *mc_io,
267			uint16_t token,
268			uint8_t irq_index,
269			uint32_t *status)
270{
271	struct mc_command cmd = { 0 };
272	int err;
273
274	/* prepare command */
275	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
276					  MC_CMD_PRI_LOW, token);
277	cmd.params[0] |= mc_enc(32, 8, irq_index);
278
279	/* send command to mc*/
280	err = mc_send_command(mc_io, &cmd);
281	if (err)
282		return err;
283
284	/* retrieve response parameters */
285	*status = mc_dec(cmd.params[0], 0, 32);
286
287	return 0;
288}
289
290int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
291			  uint16_t token,
292			  uint8_t irq_index,
293			  uint32_t status)
294{
295	struct mc_command cmd = { 0 };
296
297	/* prepare command */
298	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
299					  MC_CMD_PRI_LOW, token);
300	cmd.params[0] |= mc_enc(0, 32, status);
301	cmd.params[0] |= mc_enc(32, 8, irq_index);
302
303	/* send command to mc*/
304	return mc_send_command(mc_io, &cmd);
305}
306
307int dprc_get_attributes(struct fsl_mc_io *mc_io,
308			uint16_t token,
309			struct dprc_attributes *attr)
310{
311	struct mc_command cmd = { 0 };
312	int err;
313
314	/* prepare command */
315	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
316					  MC_CMD_PRI_LOW,
317					  token);
318
319	/* send command to mc*/
320	err = mc_send_command(mc_io, &cmd);
321	if (err)
322		return err;
323
324	/* retrieve response parameters */
325	attr->container_id = mc_dec(cmd.params[0], 0, 32);
326	attr->icid = mc_dec(cmd.params[0], 32, 16);
327	attr->options = mc_dec(cmd.params[1], 0, 32);
328	attr->portal_id = mc_dec(cmd.params[1], 32, 32);
329	attr->version.major = mc_dec(cmd.params[2], 0, 16);
330	attr->version.minor = mc_dec(cmd.params[2], 16, 16);
331
332	return 0;
333}
334
335int dprc_set_res_quota(struct fsl_mc_io *mc_io,
336		       uint16_t token,
337		       int child_container_id,
338		       char *type,
339		       uint16_t quota)
340{
341	struct mc_command cmd = { 0 };
342
343	/* prepare command */
344	cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
345					  MC_CMD_PRI_LOW, token);
346	cmd.params[0] |= mc_enc(0, 32, child_container_id);
347	cmd.params[0] |= mc_enc(32, 16, quota);
348	cmd.params[1] |= mc_enc(0, 8, type[0]);
349	cmd.params[1] |= mc_enc(8, 8, type[1]);
350	cmd.params[1] |= mc_enc(16, 8, type[2]);
351	cmd.params[1] |= mc_enc(24, 8, type[3]);
352	cmd.params[1] |= mc_enc(32, 8, type[4]);
353	cmd.params[1] |= mc_enc(40, 8, type[5]);
354	cmd.params[1] |= mc_enc(48, 8, type[6]);
355	cmd.params[1] |= mc_enc(56, 8, type[7]);
356	cmd.params[2] |= mc_enc(0, 8, type[8]);
357	cmd.params[2] |= mc_enc(8, 8, type[9]);
358	cmd.params[2] |= mc_enc(16, 8, type[10]);
359	cmd.params[2] |= mc_enc(24, 8, type[11]);
360	cmd.params[2] |= mc_enc(32, 8, type[12]);
361	cmd.params[2] |= mc_enc(40, 8, type[13]);
362	cmd.params[2] |= mc_enc(48, 8, type[14]);
363	cmd.params[2] |= mc_enc(56, 8, '\0');
364
365	/* send command to mc*/
366	return mc_send_command(mc_io, &cmd);
367}
368
369int dprc_get_res_quota(struct fsl_mc_io *mc_io,
370		       uint16_t token,
371		       int child_container_id,
372		       char *type,
373		       uint16_t *quota)
374{
375	struct mc_command cmd = { 0 };
376	int err;
377
378	/* prepare command */
379	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
380					  MC_CMD_PRI_LOW, token);
381	cmd.params[0] |= mc_enc(0, 32, child_container_id);
382	cmd.params[1] |= mc_enc(0, 8, type[0]);
383	cmd.params[1] |= mc_enc(8, 8, type[1]);
384	cmd.params[1] |= mc_enc(16, 8, type[2]);
385	cmd.params[1] |= mc_enc(24, 8, type[3]);
386	cmd.params[1] |= mc_enc(32, 8, type[4]);
387	cmd.params[1] |= mc_enc(40, 8, type[5]);
388	cmd.params[1] |= mc_enc(48, 8, type[6]);
389	cmd.params[1] |= mc_enc(56, 8, type[7]);
390	cmd.params[2] |= mc_enc(0, 8, type[8]);
391	cmd.params[2] |= mc_enc(8, 8, type[9]);
392	cmd.params[2] |= mc_enc(16, 8, type[10]);
393	cmd.params[2] |= mc_enc(24, 8, type[11]);
394	cmd.params[2] |= mc_enc(32, 8, type[12]);
395	cmd.params[2] |= mc_enc(40, 8, type[13]);
396	cmd.params[2] |= mc_enc(48, 8, type[14]);
397	cmd.params[2] |= mc_enc(56, 8, '\0');
398
399	/* send command to mc*/
400	err = mc_send_command(mc_io, &cmd);
401	if (err)
402		return err;
403
404	/* retrieve response parameters */
405	*quota = mc_dec(cmd.params[0], 32, 16);
406
407	return 0;
408}
409
410int dprc_assign(struct fsl_mc_io *mc_io,
411		uint16_t token,
412		int container_id,
413		struct dprc_res_req *res_req)
414{
415	struct mc_command cmd = { 0 };
416
417	/* prepare command */
418	cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
419					  MC_CMD_PRI_LOW, token);
420	cmd.params[0] |= mc_enc(0, 32, container_id);
421	cmd.params[0] |= mc_enc(32, 32, res_req->options);
422	cmd.params[1] |= mc_enc(0, 32, res_req->num);
423	cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
424	cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
425	cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
426	cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
427	cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
428	cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
429	cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
430	cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
431	cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
432	cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
433	cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
434	cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
435	cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
436	cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
437	cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
438	cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
439	cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
440
441	/* send command to mc*/
442	return mc_send_command(mc_io, &cmd);
443}
444
445int dprc_unassign(struct fsl_mc_io *mc_io,
446		  uint16_t token,
447		  int child_container_id,
448		  struct dprc_res_req *res_req)
449{
450	struct mc_command cmd = { 0 };
451
452	/* prepare command */
453	cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
454					  MC_CMD_PRI_LOW,
455					  token);
456	cmd.params[0] |= mc_enc(0, 32, child_container_id);
457	cmd.params[0] |= mc_enc(32, 32, res_req->options);
458	cmd.params[1] |= mc_enc(0, 32, res_req->num);
459	cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
460	cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
461	cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
462	cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
463	cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
464	cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
465	cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
466	cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
467	cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
468	cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
469	cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
470	cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
471	cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
472	cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
473	cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
474	cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
475	cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
476
477	/* send command to mc*/
478	return mc_send_command(mc_io, &cmd);
479}
480
481int dprc_get_pool_count(struct fsl_mc_io *mc_io,
482			uint16_t token,
483			int *pool_count)
484{
485	struct mc_command cmd = { 0 };
486	int err;
487
488	/* prepare command */
489	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
490					  MC_CMD_PRI_LOW, token);
491
492	/* send command to mc*/
493	err = mc_send_command(mc_io, &cmd);
494	if (err)
495		return err;
496
497	/* retrieve response parameters */
498	*pool_count = mc_dec(cmd.params[0], 0, 32);
499
500	return 0;
501}
502
503int dprc_get_pool(struct fsl_mc_io *mc_io,
504		  uint16_t token,
505		  int pool_index,
506		  char *type)
507{
508	struct mc_command cmd = { 0 };
509	int err;
510
511	/* prepare command */
512	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
513					  MC_CMD_PRI_LOW,
514					  token);
515	cmd.params[0] |= mc_enc(0, 32, pool_index);
516
517	/* send command to mc*/
518	err = mc_send_command(mc_io, &cmd);
519	if (err)
520		return err;
521
522	/* retrieve response parameters */
523	type[0] = mc_dec(cmd.params[1], 0, 8);
524	type[1] = mc_dec(cmd.params[1], 8, 8);
525	type[2] = mc_dec(cmd.params[1], 16, 8);
526	type[3] = mc_dec(cmd.params[1], 24, 8);
527	type[4] = mc_dec(cmd.params[1], 32, 8);
528	type[5] = mc_dec(cmd.params[1], 40, 8);
529	type[6] = mc_dec(cmd.params[1], 48, 8);
530	type[7] = mc_dec(cmd.params[1], 56, 8);
531	type[8] = mc_dec(cmd.params[2], 0, 8);
532	type[9] = mc_dec(cmd.params[2], 8, 8);
533	type[10] = mc_dec(cmd.params[2], 16, 8);
534	type[11] = mc_dec(cmd.params[2], 24, 8);
535	type[12] = mc_dec(cmd.params[2], 32, 8);
536	type[13] = mc_dec(cmd.params[2], 40, 8);
537	type[14] = mc_dec(cmd.params[2], 48, 8);
538	type[15] = '\0';
539
540	return 0;
541}
542
543int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count)
544{
545	struct mc_command cmd = { 0 };
546	int err;
547
548	/* prepare command */
549	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
550					  MC_CMD_PRI_LOW, token);
551
552	/* send command to mc*/
553	err = mc_send_command(mc_io, &cmd);
554	if (err)
555		return err;
556
557	/* retrieve response parameters */
558	*obj_count = mc_dec(cmd.params[0], 32, 32);
559
560	return 0;
561}
562EXPORT_SYMBOL(dprc_get_obj_count);
563
564int dprc_get_obj(struct fsl_mc_io *mc_io,
565		 uint16_t token,
566		 int obj_index,
567		 struct dprc_obj_desc *obj_desc)
568{
569	struct mc_command cmd = { 0 };
570	int err;
571
572	/* prepare command */
573	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
574					  MC_CMD_PRI_LOW,
575					  token);
576	cmd.params[0] |= mc_enc(0, 32, obj_index);
577
578	/* send command to mc*/
579	err = mc_send_command(mc_io, &cmd);
580	if (err)
581		return err;
582
583	/* retrieve response parameters */
584	obj_desc->id = mc_dec(cmd.params[0], 32, 32);
585	obj_desc->vendor = mc_dec(cmd.params[1], 0, 16);
586	obj_desc->irq_count = mc_dec(cmd.params[1], 16, 8);
587	obj_desc->region_count = mc_dec(cmd.params[1], 24, 8);
588	obj_desc->state = mc_dec(cmd.params[1], 32, 32);
589	obj_desc->ver_major = mc_dec(cmd.params[2], 0, 16);
590	obj_desc->ver_minor = mc_dec(cmd.params[2], 16, 16);
591	obj_desc->type[0] = mc_dec(cmd.params[3], 0, 8);
592	obj_desc->type[1] = mc_dec(cmd.params[3], 8, 8);
593	obj_desc->type[2] = mc_dec(cmd.params[3], 16, 8);
594	obj_desc->type[3] = mc_dec(cmd.params[3], 24, 8);
595	obj_desc->type[4] = mc_dec(cmd.params[3], 32, 8);
596	obj_desc->type[5] = mc_dec(cmd.params[3], 40, 8);
597	obj_desc->type[6] = mc_dec(cmd.params[3], 48, 8);
598	obj_desc->type[7] = mc_dec(cmd.params[3], 56, 8);
599	obj_desc->type[8] = mc_dec(cmd.params[4], 0, 8);
600	obj_desc->type[9] = mc_dec(cmd.params[4], 8, 8);
601	obj_desc->type[10] = mc_dec(cmd.params[4], 16, 8);
602	obj_desc->type[11] = mc_dec(cmd.params[4], 24, 8);
603	obj_desc->type[12] = mc_dec(cmd.params[4], 32, 8);
604	obj_desc->type[13] = mc_dec(cmd.params[4], 40, 8);
605	obj_desc->type[14] = mc_dec(cmd.params[4], 48, 8);
606	obj_desc->type[15] = '\0';
607
608	return 0;
609}
610EXPORT_SYMBOL(dprc_get_obj);
611
612int dprc_get_res_count(struct fsl_mc_io *mc_io,
613		       uint16_t token,
614		       char *type,
615		       int *res_count)
616{
617	struct mc_command cmd = { 0 };
618	int err;
619
620	*res_count = 0;
621
622	/* prepare command */
623	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
624					  MC_CMD_PRI_LOW, token);
625	cmd.params[1] |= mc_enc(0, 8, type[0]);
626	cmd.params[1] |= mc_enc(8, 8, type[1]);
627	cmd.params[1] |= mc_enc(16, 8, type[2]);
628	cmd.params[1] |= mc_enc(24, 8, type[3]);
629	cmd.params[1] |= mc_enc(32, 8, type[4]);
630	cmd.params[1] |= mc_enc(40, 8, type[5]);
631	cmd.params[1] |= mc_enc(48, 8, type[6]);
632	cmd.params[1] |= mc_enc(56, 8, type[7]);
633	cmd.params[2] |= mc_enc(0, 8, type[8]);
634	cmd.params[2] |= mc_enc(8, 8, type[9]);
635	cmd.params[2] |= mc_enc(16, 8, type[10]);
636	cmd.params[2] |= mc_enc(24, 8, type[11]);
637	cmd.params[2] |= mc_enc(32, 8, type[12]);
638	cmd.params[2] |= mc_enc(40, 8, type[13]);
639	cmd.params[2] |= mc_enc(48, 8, type[14]);
640	cmd.params[2] |= mc_enc(56, 8, '\0');
641
642	/* send command to mc*/
643	err = mc_send_command(mc_io, &cmd);
644	if (err)
645		return err;
646
647	/* retrieve response parameters */
648	*res_count = mc_dec(cmd.params[0], 0, 32);
649
650	return 0;
651}
652EXPORT_SYMBOL(dprc_get_res_count);
653
654int dprc_get_res_ids(struct fsl_mc_io *mc_io,
655		     uint16_t token,
656		     char *type,
657		     struct dprc_res_ids_range_desc *range_desc)
658{
659	struct mc_command cmd = { 0 };
660	int err;
661
662	/* prepare command */
663	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
664					  MC_CMD_PRI_LOW, token);
665	cmd.params[0] |= mc_enc(42, 7, range_desc->iter_status);
666	cmd.params[1] |= mc_enc(0, 32, range_desc->base_id);
667	cmd.params[1] |= mc_enc(32, 32, range_desc->last_id);
668	cmd.params[2] |= mc_enc(0, 8, type[0]);
669	cmd.params[2] |= mc_enc(8, 8, type[1]);
670	cmd.params[2] |= mc_enc(16, 8, type[2]);
671	cmd.params[2] |= mc_enc(24, 8, type[3]);
672	cmd.params[2] |= mc_enc(32, 8, type[4]);
673	cmd.params[2] |= mc_enc(40, 8, type[5]);
674	cmd.params[2] |= mc_enc(48, 8, type[6]);
675	cmd.params[2] |= mc_enc(56, 8, type[7]);
676	cmd.params[3] |= mc_enc(0, 8, type[8]);
677	cmd.params[3] |= mc_enc(8, 8, type[9]);
678	cmd.params[3] |= mc_enc(16, 8, type[10]);
679	cmd.params[3] |= mc_enc(24, 8, type[11]);
680	cmd.params[3] |= mc_enc(32, 8, type[12]);
681	cmd.params[3] |= mc_enc(40, 8, type[13]);
682	cmd.params[3] |= mc_enc(48, 8, type[14]);
683	cmd.params[3] |= mc_enc(56, 8, '\0');
684
685	/* send command to mc*/
686	err = mc_send_command(mc_io, &cmd);
687	if (err)
688		return err;
689
690	/* retrieve response parameters */
691	range_desc->iter_status = mc_dec(cmd.params[0], 42, 7);
692	range_desc->base_id = mc_dec(cmd.params[1], 0, 32);
693	range_desc->last_id = mc_dec(cmd.params[1], 32, 32);
694
695	return 0;
696}
697EXPORT_SYMBOL(dprc_get_res_ids);
698
699int dprc_get_portal_paddr(struct fsl_mc_io *mc_io,
700			  uint16_t token,
701			  int portal_id,
702			  uint64_t *portal_addr)
703{
704	struct mc_command cmd = { 0 };
705	int err;
706
707	/* prepare command */
708	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_PORTAL_PADDR,
709					  MC_CMD_PRI_LOW, token);
710	cmd.params[0] |= mc_enc(0, 32, portal_id);
711
712	/* send command to mc*/
713	err = mc_send_command(mc_io, &cmd);
714	if (err)
715		return err;
716
717	/* retrieve response parameters */
718	*portal_addr = mc_dec(cmd.params[1], 0, 64);
719
720	return 0;
721}
722EXPORT_SYMBOL(dprc_get_portal_paddr);
723
724int dprc_get_obj_region(struct fsl_mc_io *mc_io,
725			uint16_t token,
726			char *obj_type,
727			int obj_id,
728			uint8_t region_index,
729			struct dprc_region_desc *region_desc)
730{
731	struct mc_command cmd = { 0 };
732	int err;
733
734	/* prepare command */
735	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
736					  MC_CMD_PRI_LOW, token);
737	cmd.params[0] |= mc_enc(0, 32, obj_id);
738	cmd.params[0] |= mc_enc(48, 8, region_index);
739	cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
740	cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
741	cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
742	cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
743	cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
744	cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
745	cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
746	cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
747	cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
748	cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
749	cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
750	cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
751	cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
752	cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
753	cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
754	cmd.params[4] |= mc_enc(56, 8, '\0');
755
756	/* send command to mc*/
757	err = mc_send_command(mc_io, &cmd);
758	if (err)
759		return err;
760
761	/* retrieve response parameters */
762	region_desc->base_paddr = mc_dec(cmd.params[1], 0, 64);
763	region_desc->size = mc_dec(cmd.params[2], 0, 32);
764
765	return 0;
766}
767EXPORT_SYMBOL(dprc_get_obj_region);
768
769int dprc_connect(struct fsl_mc_io *mc_io,
770		 uint16_t token,
771		 const struct dprc_endpoint *endpoint1,
772		 const struct dprc_endpoint *endpoint2)
773{
774	struct mc_command cmd = { 0 };
775
776	/* prepare command */
777	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
778					  MC_CMD_PRI_LOW,
779					  token);
780	cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
781	cmd.params[0] |= mc_enc(32, 32, endpoint1->interface_id);
782	cmd.params[1] |= mc_enc(0, 32, endpoint2->id);
783	cmd.params[1] |= mc_enc(32, 32, endpoint2->interface_id);
784	cmd.params[2] |= mc_enc(0, 8, endpoint1->type[0]);
785	cmd.params[2] |= mc_enc(8, 8, endpoint1->type[1]);
786	cmd.params[2] |= mc_enc(16, 8, endpoint1->type[2]);
787	cmd.params[2] |= mc_enc(24, 8, endpoint1->type[3]);
788	cmd.params[2] |= mc_enc(32, 8, endpoint1->type[4]);
789	cmd.params[2] |= mc_enc(40, 8, endpoint1->type[5]);
790	cmd.params[2] |= mc_enc(48, 8, endpoint1->type[6]);
791	cmd.params[2] |= mc_enc(56, 8, endpoint1->type[7]);
792	cmd.params[3] |= mc_enc(0, 8, endpoint1->type[8]);
793	cmd.params[3] |= mc_enc(8, 8, endpoint1->type[9]);
794	cmd.params[3] |= mc_enc(16, 8, endpoint1->type[10]);
795	cmd.params[3] |= mc_enc(24, 8, endpoint1->type[11]);
796	cmd.params[3] |= mc_enc(32, 8, endpoint1->type[12]);
797	cmd.params[3] |= mc_enc(40, 8, endpoint1->type[13]);
798	cmd.params[3] |= mc_enc(48, 8, endpoint1->type[14]);
799	cmd.params[3] |= mc_enc(56, 8, endpoint1->type[15]);
800	cmd.params[5] |= mc_enc(0, 8, endpoint2->type[0]);
801	cmd.params[5] |= mc_enc(8, 8, endpoint2->type[1]);
802	cmd.params[5] |= mc_enc(16, 8, endpoint2->type[2]);
803	cmd.params[5] |= mc_enc(24, 8, endpoint2->type[3]);
804	cmd.params[5] |= mc_enc(32, 8, endpoint2->type[4]);
805	cmd.params[5] |= mc_enc(40, 8, endpoint2->type[5]);
806	cmd.params[5] |= mc_enc(48, 8, endpoint2->type[6]);
807	cmd.params[5] |= mc_enc(56, 8, endpoint2->type[7]);
808	cmd.params[6] |= mc_enc(0, 8, endpoint2->type[8]);
809	cmd.params[6] |= mc_enc(8, 8, endpoint2->type[9]);
810	cmd.params[6] |= mc_enc(16, 8, endpoint2->type[10]);
811	cmd.params[6] |= mc_enc(24, 8, endpoint2->type[11]);
812	cmd.params[6] |= mc_enc(32, 8, endpoint2->type[12]);
813	cmd.params[6] |= mc_enc(40, 8, endpoint2->type[13]);
814	cmd.params[6] |= mc_enc(48, 8, endpoint2->type[14]);
815	cmd.params[6] |= mc_enc(56, 8, endpoint2->type[15]);
816
817	/* send command to mc*/
818	return mc_send_command(mc_io, &cmd);
819}
820
821int dprc_disconnect(struct fsl_mc_io *mc_io,
822		    uint16_t token,
823		    const struct dprc_endpoint *endpoint)
824{
825	struct mc_command cmd = { 0 };
826
827	/* prepare command */
828	cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
829					  MC_CMD_PRI_LOW,
830					  token);
831	cmd.params[0] |= mc_enc(0, 32, endpoint->id);
832	cmd.params[0] |= mc_enc(32, 32, endpoint->interface_id);
833	cmd.params[1] |= mc_enc(0, 8, endpoint->type[0]);
834	cmd.params[1] |= mc_enc(8, 8, endpoint->type[1]);
835	cmd.params[1] |= mc_enc(16, 8, endpoint->type[2]);
836	cmd.params[1] |= mc_enc(24, 8, endpoint->type[3]);
837	cmd.params[1] |= mc_enc(32, 8, endpoint->type[4]);
838	cmd.params[1] |= mc_enc(40, 8, endpoint->type[5]);
839	cmd.params[1] |= mc_enc(48, 8, endpoint->type[6]);
840	cmd.params[1] |= mc_enc(56, 8, endpoint->type[7]);
841	cmd.params[2] |= mc_enc(0, 8, endpoint->type[8]);
842	cmd.params[2] |= mc_enc(8, 8, endpoint->type[9]);
843	cmd.params[2] |= mc_enc(16, 8, endpoint->type[10]);
844	cmd.params[2] |= mc_enc(24, 8, endpoint->type[11]);
845	cmd.params[2] |= mc_enc(32, 8, endpoint->type[12]);
846	cmd.params[2] |= mc_enc(40, 8, endpoint->type[13]);
847	cmd.params[2] |= mc_enc(48, 8, endpoint->type[14]);
848	cmd.params[2] |= mc_enc(56, 8, endpoint->type[15]);
849
850	/* send command to mc*/
851	return mc_send_command(mc_io, &cmd);
852}
853
854int dprc_get_connection(struct fsl_mc_io *mc_io,
855			uint16_t token,
856					const struct dprc_endpoint *endpoint1,
857					struct dprc_endpoint *endpoint2,
858					int *state)
859{
860	struct mc_command cmd = { 0 };
861	int err;
862
863	/* prepare command */
864	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
865					  MC_CMD_PRI_LOW,
866					  token);
867	cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
868	cmd.params[0] |= mc_enc(32, 32, endpoint1->interface_id);
869	cmd.params[1] |= mc_enc(0, 8, endpoint1->type[0]);
870	cmd.params[1] |= mc_enc(8, 8, endpoint1->type[1]);
871	cmd.params[1] |= mc_enc(16, 8, endpoint1->type[2]);
872	cmd.params[1] |= mc_enc(24, 8, endpoint1->type[3]);
873	cmd.params[1] |= mc_enc(32, 8, endpoint1->type[4]);
874	cmd.params[1] |= mc_enc(40, 8, endpoint1->type[5]);
875	cmd.params[1] |= mc_enc(48, 8, endpoint1->type[6]);
876	cmd.params[1] |= mc_enc(56, 8, endpoint1->type[7]);
877	cmd.params[2] |= mc_enc(0, 8, endpoint1->type[8]);
878	cmd.params[2] |= mc_enc(8, 8, endpoint1->type[9]);
879	cmd.params[2] |= mc_enc(16, 8, endpoint1->type[10]);
880	cmd.params[2] |= mc_enc(24, 8, endpoint1->type[11]);
881	cmd.params[2] |= mc_enc(32, 8, endpoint1->type[12]);
882	cmd.params[2] |= mc_enc(40, 8, endpoint1->type[13]);
883	cmd.params[2] |= mc_enc(48, 8, endpoint1->type[14]);
884	cmd.params[2] |= mc_enc(56, 8, endpoint1->type[15]);
885
886	/* send command to mc*/
887	err = mc_send_command(mc_io, &cmd);
888	if (err)
889		return err;
890
891	/* retrieve response parameters */
892	endpoint2->id = mc_dec(cmd.params[3], 0, 32);
893	endpoint2->interface_id = mc_dec(cmd.params[3], 32, 32);
894	endpoint2->type[0] = mc_dec(cmd.params[4], 0, 8);
895	endpoint2->type[1] = mc_dec(cmd.params[4], 8, 8);
896	endpoint2->type[2] = mc_dec(cmd.params[4], 16, 8);
897	endpoint2->type[3] = mc_dec(cmd.params[4], 24, 8);
898	endpoint2->type[4] = mc_dec(cmd.params[4], 32, 8);
899	endpoint2->type[5] = mc_dec(cmd.params[4], 40, 8);
900	endpoint2->type[6] = mc_dec(cmd.params[4], 48, 8);
901	endpoint2->type[7] = mc_dec(cmd.params[4], 56, 8);
902	endpoint2->type[8] = mc_dec(cmd.params[5], 0, 8);
903	endpoint2->type[9] = mc_dec(cmd.params[5], 8, 8);
904	endpoint2->type[10] = mc_dec(cmd.params[5], 16, 8);
905	endpoint2->type[11] = mc_dec(cmd.params[5], 24, 8);
906	endpoint2->type[12] = mc_dec(cmd.params[5], 32, 8);
907	endpoint2->type[13] = mc_dec(cmd.params[5], 40, 8);
908	endpoint2->type[14] = mc_dec(cmd.params[5], 48, 8);
909	endpoint2->type[15] = mc_dec(cmd.params[5], 56, 8);
910	*state = mc_dec(cmd.params[6], 0, 32);
911
912	return 0;
913}
914