1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <linux/kernel.h>
33#include "../include/mc.h"
34#include "dprc.h"
35
36#include "dprc-cmd.h"
37
38
39
40
41
42
43
44
45
46
47
48
49int dprc_open(struct fsl_mc_io *mc_io,
50 u32 cmd_flags,
51 int container_id,
52 u16 *token)
53{
54 struct mc_command cmd = { 0 };
55 struct dprc_cmd_open *cmd_params;
56 int err;
57
58
59 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
60 0);
61 cmd_params = (struct dprc_cmd_open *)cmd.params;
62 cmd_params->container_id = cpu_to_le32(container_id);
63
64
65 err = mc_send_command(mc_io, &cmd);
66 if (err)
67 return err;
68
69
70 *token = mc_cmd_hdr_read_token(&cmd);
71
72 return 0;
73}
74EXPORT_SYMBOL(dprc_open);
75
76
77
78
79
80
81
82
83
84
85
86
87int dprc_close(struct fsl_mc_io *mc_io,
88 u32 cmd_flags,
89 u16 token)
90{
91 struct mc_command cmd = { 0 };
92
93
94 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
95 token);
96
97
98 return mc_send_command(mc_io, &cmd);
99}
100EXPORT_SYMBOL(dprc_close);
101
102
103
104
105
106
107
108
109
110
111
112
113
114int dprc_get_irq(struct fsl_mc_io *mc_io,
115 u32 cmd_flags,
116 u16 token,
117 u8 irq_index,
118 int *type,
119 struct dprc_irq_cfg *irq_cfg)
120{
121 struct mc_command cmd = { 0 };
122 struct dprc_cmd_get_irq *cmd_params;
123 struct dprc_rsp_get_irq *rsp_params;
124 int err;
125
126
127 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
128 cmd_flags,
129 token);
130 cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
131 cmd_params->irq_index = irq_index;
132
133
134 err = mc_send_command(mc_io, &cmd);
135 if (err)
136 return err;
137
138
139 rsp_params = (struct dprc_rsp_get_irq *)cmd.params;
140 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
141 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
142 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
143 *type = le32_to_cpu(rsp_params->type);
144
145 return 0;
146}
147
148
149
150
151
152
153
154
155
156
157
158int dprc_set_irq(struct fsl_mc_io *mc_io,
159 u32 cmd_flags,
160 u16 token,
161 u8 irq_index,
162 struct dprc_irq_cfg *irq_cfg)
163{
164 struct mc_command cmd = { 0 };
165 struct dprc_cmd_set_irq *cmd_params;
166
167
168 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
169 cmd_flags,
170 token);
171 cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
172 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
173 cmd_params->irq_index = irq_index;
174 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
175 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
176
177
178 return mc_send_command(mc_io, &cmd);
179}
180
181
182
183
184
185
186
187
188
189
190
191int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
192 u32 cmd_flags,
193 u16 token,
194 u8 irq_index,
195 u8 *en)
196{
197 struct mc_command cmd = { 0 };
198 struct dprc_cmd_get_irq_enable *cmd_params;
199 struct dprc_rsp_get_irq_enable *rsp_params;
200 int err;
201
202
203 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
204 cmd_flags, token);
205 cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
206 cmd_params->irq_index = irq_index;
207
208
209 err = mc_send_command(mc_io, &cmd);
210 if (err)
211 return err;
212
213
214 rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
215 *en = rsp_params->enabled & DPRC_ENABLE;
216
217 return 0;
218}
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
236 u32 cmd_flags,
237 u16 token,
238 u8 irq_index,
239 u8 en)
240{
241 struct mc_command cmd = { 0 };
242 struct dprc_cmd_set_irq_enable *cmd_params;
243
244
245 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
246 cmd_flags, token);
247 cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
248 cmd_params->enable = en & DPRC_ENABLE;
249 cmd_params->irq_index = irq_index;
250
251
252 return mc_send_command(mc_io, &cmd);
253}
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
269 u32 cmd_flags,
270 u16 token,
271 u8 irq_index,
272 u32 *mask)
273{
274 struct mc_command cmd = { 0 };
275 struct dprc_cmd_get_irq_mask *cmd_params;
276 struct dprc_rsp_get_irq_mask *rsp_params;
277 int err;
278
279
280 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
281 cmd_flags, token);
282 cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
283 cmd_params->irq_index = irq_index;
284
285
286 err = mc_send_command(mc_io, &cmd);
287 if (err)
288 return err;
289
290
291 rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
292 *mask = le32_to_cpu(rsp_params->mask);
293
294 return 0;
295}
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
314 u32 cmd_flags,
315 u16 token,
316 u8 irq_index,
317 u32 mask)
318{
319 struct mc_command cmd = { 0 };
320 struct dprc_cmd_set_irq_mask *cmd_params;
321
322
323 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
324 cmd_flags, token);
325 cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
326 cmd_params->mask = cpu_to_le32(mask);
327 cmd_params->irq_index = irq_index;
328
329
330 return mc_send_command(mc_io, &cmd);
331}
332
333
334
335
336
337
338
339
340
341
342
343
344
345int dprc_get_irq_status(struct fsl_mc_io *mc_io,
346 u32 cmd_flags,
347 u16 token,
348 u8 irq_index,
349 u32 *status)
350{
351 struct mc_command cmd = { 0 };
352 struct dprc_cmd_get_irq_status *cmd_params;
353 struct dprc_rsp_get_irq_status *rsp_params;
354 int err;
355
356
357 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
358 cmd_flags, token);
359 cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
360 cmd_params->status = cpu_to_le32(*status);
361 cmd_params->irq_index = irq_index;
362
363
364 err = mc_send_command(mc_io, &cmd);
365 if (err)
366 return err;
367
368
369 rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
370 *status = le32_to_cpu(rsp_params->status);
371
372 return 0;
373}
374
375
376
377
378
379
380
381
382
383
384
385
386
387int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
388 u32 cmd_flags,
389 u16 token,
390 u8 irq_index,
391 u32 status)
392{
393 struct mc_command cmd = { 0 };
394 struct dprc_cmd_clear_irq_status *cmd_params;
395
396
397 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
398 cmd_flags, token);
399 cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
400 cmd_params->status = cpu_to_le32(status);
401 cmd_params->irq_index = irq_index;
402
403
404 return mc_send_command(mc_io, &cmd);
405}
406
407
408
409
410
411
412
413
414
415
416int dprc_get_attributes(struct fsl_mc_io *mc_io,
417 u32 cmd_flags,
418 u16 token,
419 struct dprc_attributes *attr)
420{
421 struct mc_command cmd = { 0 };
422 struct dprc_rsp_get_attributes *rsp_params;
423 int err;
424
425
426 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
427 cmd_flags,
428 token);
429
430
431 err = mc_send_command(mc_io, &cmd);
432 if (err)
433 return err;
434
435
436 rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
437 attr->container_id = le32_to_cpu(rsp_params->container_id);
438 attr->icid = le16_to_cpu(rsp_params->icid);
439 attr->options = le32_to_cpu(rsp_params->options);
440 attr->portal_id = le32_to_cpu(rsp_params->portal_id);
441
442 return 0;
443}
444
445
446
447
448
449
450
451
452
453
454int dprc_get_obj_count(struct fsl_mc_io *mc_io,
455 u32 cmd_flags,
456 u16 token,
457 int *obj_count)
458{
459 struct mc_command cmd = { 0 };
460 struct dprc_rsp_get_obj_count *rsp_params;
461 int err;
462
463
464 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
465 cmd_flags, token);
466
467
468 err = mc_send_command(mc_io, &cmd);
469 if (err)
470 return err;
471
472
473 rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
474 *obj_count = le32_to_cpu(rsp_params->obj_count);
475
476 return 0;
477}
478EXPORT_SYMBOL(dprc_get_obj_count);
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495int dprc_get_obj(struct fsl_mc_io *mc_io,
496 u32 cmd_flags,
497 u16 token,
498 int obj_index,
499 struct fsl_mc_obj_desc *obj_desc)
500{
501 struct mc_command cmd = { 0 };
502 struct dprc_cmd_get_obj *cmd_params;
503 struct dprc_rsp_get_obj *rsp_params;
504 int err;
505
506
507 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
508 cmd_flags,
509 token);
510 cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
511 cmd_params->obj_index = cpu_to_le32(obj_index);
512
513
514 err = mc_send_command(mc_io, &cmd);
515 if (err)
516 return err;
517
518
519 rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
520 obj_desc->id = le32_to_cpu(rsp_params->id);
521 obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
522 obj_desc->irq_count = rsp_params->irq_count;
523 obj_desc->region_count = rsp_params->region_count;
524 obj_desc->state = le32_to_cpu(rsp_params->state);
525 obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
526 obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
527 obj_desc->flags = le16_to_cpu(rsp_params->flags);
528 strncpy(obj_desc->type, rsp_params->type, 16);
529 obj_desc->type[15] = '\0';
530 strncpy(obj_desc->label, rsp_params->label, 16);
531 obj_desc->label[15] = '\0';
532 return 0;
533}
534EXPORT_SYMBOL(dprc_get_obj);
535
536
537
538
539
540
541
542
543
544
545
546
547
548int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
549 u32 cmd_flags,
550 u16 token,
551 char *obj_type,
552 int obj_id,
553 u8 irq_index,
554 struct dprc_irq_cfg *irq_cfg)
555{
556 struct mc_command cmd = { 0 };
557 struct dprc_cmd_set_obj_irq *cmd_params;
558
559
560 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
561 cmd_flags,
562 token);
563 cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
564 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
565 cmd_params->irq_index = irq_index;
566 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
567 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
568 cmd_params->obj_id = cpu_to_le32(obj_id);
569 strncpy(cmd_params->obj_type, obj_type, 16);
570 cmd_params->obj_type[15] = '\0';
571
572
573 return mc_send_command(mc_io, &cmd);
574}
575EXPORT_SYMBOL(dprc_set_obj_irq);
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
592 u32 cmd_flags,
593 u16 token,
594 char *obj_type,
595 int obj_id,
596 u8 irq_index,
597 int *type,
598 struct dprc_irq_cfg *irq_cfg)
599{
600 struct mc_command cmd = { 0 };
601 struct dprc_cmd_get_obj_irq *cmd_params;
602 struct dprc_rsp_get_obj_irq *rsp_params;
603 int err;
604
605
606 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
607 cmd_flags,
608 token);
609 cmd_params = (struct dprc_cmd_get_obj_irq *)cmd.params;
610 cmd_params->obj_id = cpu_to_le32(obj_id);
611 cmd_params->irq_index = irq_index;
612 strncpy(cmd_params->obj_type, obj_type, 16);
613 cmd_params->obj_type[15] = '\0';
614
615
616 err = mc_send_command(mc_io, &cmd);
617 if (err)
618 return err;
619
620
621 rsp_params = (struct dprc_rsp_get_obj_irq *)cmd.params;
622 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
623 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
624 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
625 *type = le32_to_cpu(rsp_params->type);
626
627 return 0;
628}
629EXPORT_SYMBOL(dprc_get_obj_irq);
630
631
632
633
634
635
636
637
638
639
640
641
642
643int dprc_get_res_count(struct fsl_mc_io *mc_io,
644 u32 cmd_flags,
645 u16 token,
646 char *type,
647 int *res_count)
648{
649 struct mc_command cmd = { 0 };
650 struct dprc_cmd_get_res_count *cmd_params;
651 struct dprc_rsp_get_res_count *rsp_params;
652 int err;
653
654
655 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
656 cmd_flags, token);
657 cmd_params = (struct dprc_cmd_get_res_count *)cmd.params;
658 strncpy(cmd_params->type, type, 16);
659 cmd_params->type[15] = '\0';
660
661
662 err = mc_send_command(mc_io, &cmd);
663 if (err)
664 return err;
665
666
667 rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
668 *res_count = le32_to_cpu(rsp_params->res_count);
669
670 return 0;
671}
672EXPORT_SYMBOL(dprc_get_res_count);
673
674
675
676
677
678
679
680
681
682
683
684
685
686int dprc_get_obj_region(struct fsl_mc_io *mc_io,
687 u32 cmd_flags,
688 u16 token,
689 char *obj_type,
690 int obj_id,
691 u8 region_index,
692 struct dprc_region_desc *region_desc)
693{
694 struct mc_command cmd = { 0 };
695 struct dprc_cmd_get_obj_region *cmd_params;
696 struct dprc_rsp_get_obj_region *rsp_params;
697 int err;
698
699
700 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
701 cmd_flags, token);
702 cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
703 cmd_params->obj_id = cpu_to_le32(obj_id);
704 cmd_params->region_index = region_index;
705 strncpy(cmd_params->obj_type, obj_type, 16);
706 cmd_params->obj_type[15] = '\0';
707
708
709 err = mc_send_command(mc_io, &cmd);
710 if (err)
711 return err;
712
713
714 rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
715 region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
716 region_desc->size = le32_to_cpu(rsp_params->size);
717
718 return 0;
719}
720EXPORT_SYMBOL(dprc_get_obj_region);
721
722
723
724
725
726
727
728
729
730
731int dprc_get_api_version(struct fsl_mc_io *mc_io,
732 u32 cmd_flags,
733 u16 *major_ver,
734 u16 *minor_ver)
735{
736 struct mc_command cmd = { 0 };
737 int err;
738
739
740 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
741 cmd_flags, 0);
742
743
744 err = mc_send_command(mc_io, &cmd);
745 if (err)
746 return err;
747
748
749 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
750
751 return 0;
752}
753
754
755
756
757
758
759
760
761
762int dprc_get_container_id(struct fsl_mc_io *mc_io,
763 u32 cmd_flags,
764 int *container_id)
765{
766 struct mc_command cmd = { 0 };
767 int err;
768
769
770 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
771 cmd_flags,
772 0);
773
774
775 err = mc_send_command(mc_io, &cmd);
776 if (err)
777 return err;
778
779
780 *container_id = (int)mc_cmd_read_object_id(&cmd);
781
782 return 0;
783}
784