]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-mc/bus/dprc.c
Revert "staging: fsl-mc: move mc-cmd.h contents in the public header"
[karo-tx-linux.git] / drivers / staging / fsl-mc / bus / dprc.c
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the above-listed copyright holders nor the
12  * names of any contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
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 <linux/kernel.h>
33 #include "../include/mc.h"
34 #include "../include/mc-cmd.h"
35 #include "../include/dprc.h"
36
37 #include "dprc-cmd.h"
38
39 /**
40  * dprc_open() - Open DPRC object for use
41  * @mc_io:      Pointer to MC portal's I/O object
42  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
43  * @container_id: Container ID to open
44  * @token:      Returned token of DPRC object
45  *
46  * Return:      '0' on Success; Error code otherwise.
47  *
48  * @warning     Required before any operation on the object.
49  */
50 int dprc_open(struct fsl_mc_io *mc_io,
51               u32 cmd_flags,
52               int container_id,
53               u16 *token)
54 {
55         struct mc_command cmd = { 0 };
56         struct dprc_cmd_open *cmd_params;
57         int err;
58
59         /* prepare command */
60         cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
61                                           0);
62         cmd_params = (struct dprc_cmd_open *)cmd.params;
63         cmd_params->container_id = cpu_to_le32(container_id);
64
65         /* send command to mc*/
66         err = mc_send_command(mc_io, &cmd);
67         if (err)
68                 return err;
69
70         /* retrieve response parameters */
71         *token = mc_cmd_hdr_read_token(&cmd);
72
73         return 0;
74 }
75 EXPORT_SYMBOL(dprc_open);
76
77 /**
78  * dprc_close() - Close the control session of the object
79  * @mc_io:      Pointer to MC portal's I/O object
80  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
81  * @token:      Token of DPRC object
82  *
83  * After this function is called, no further operations are
84  * allowed on the object without opening a new control session.
85  *
86  * Return:      '0' on Success; Error code otherwise.
87  */
88 int dprc_close(struct fsl_mc_io *mc_io,
89                u32 cmd_flags,
90                u16 token)
91 {
92         struct mc_command cmd = { 0 };
93
94         /* prepare command */
95         cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
96                                           token);
97
98         /* send command to mc*/
99         return mc_send_command(mc_io, &cmd);
100 }
101 EXPORT_SYMBOL(dprc_close);
102
103 /**
104  * dprc_get_irq() - Get IRQ information from the DPRC.
105  * @mc_io:      Pointer to MC portal's I/O object
106  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
107  * @token:      Token of DPRC object
108  * @irq_index:  The interrupt index to configure
109  * @type:       Interrupt type: 0 represents message interrupt
110  *              type (both irq_addr and irq_val are valid)
111  * @irq_cfg:    IRQ attributes
112  *
113  * Return:      '0' on Success; Error code otherwise.
114  */
115 int dprc_get_irq(struct fsl_mc_io *mc_io,
116                  u32 cmd_flags,
117                  u16 token,
118                  u8 irq_index,
119                  int *type,
120                  struct dprc_irq_cfg *irq_cfg)
121 {
122         struct mc_command cmd = { 0 };
123         struct dprc_cmd_get_irq *cmd_params;
124         struct dprc_rsp_get_irq *rsp_params;
125         int err;
126
127         /* prepare command */
128         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
129                                           cmd_flags,
130                                           token);
131         cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
132         cmd_params->irq_index = irq_index;
133
134         /* send command to mc*/
135         err = mc_send_command(mc_io, &cmd);
136         if (err)
137                 return err;
138
139         /* retrieve response parameters */
140         rsp_params = (struct dprc_rsp_get_irq *)cmd.params;
141         irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
142         irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
143         irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
144         *type = le32_to_cpu(rsp_params->type);
145
146         return 0;
147 }
148
149 /**
150  * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
151  * @mc_io:      Pointer to MC portal's I/O object
152  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
153  * @token:      Token of DPRC object
154  * @irq_index:  Identifies the interrupt index to configure
155  * @irq_cfg:    IRQ configuration
156  *
157  * Return:      '0' on Success; Error code otherwise.
158  */
159 int dprc_set_irq(struct fsl_mc_io *mc_io,
160                  u32 cmd_flags,
161                  u16 token,
162                  u8 irq_index,
163                  struct dprc_irq_cfg *irq_cfg)
164 {
165         struct mc_command cmd = { 0 };
166         struct dprc_cmd_set_irq *cmd_params;
167
168         /* prepare command */
169         cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
170                                           cmd_flags,
171                                           token);
172         cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
173         cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
174         cmd_params->irq_index = irq_index;
175         cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
176         cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
177
178         /* send command to mc*/
179         return mc_send_command(mc_io, &cmd);
180 }
181
182 /**
183  * dprc_get_irq_enable() - Get overall interrupt state.
184  * @mc_io:      Pointer to MC portal's I/O object
185  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
186  * @token:      Token of DPRC object
187  * @irq_index:  The interrupt index to configure
188  * @en:         Returned interrupt state - enable = 1, disable = 0
189  *
190  * Return:      '0' on Success; Error code otherwise.
191  */
192 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
193                         u32 cmd_flags,
194                         u16 token,
195                         u8 irq_index,
196                         u8 *en)
197 {
198         struct mc_command cmd = { 0 };
199         struct dprc_cmd_get_irq_enable *cmd_params;
200         struct dprc_rsp_get_irq_enable *rsp_params;
201         int err;
202
203         /* prepare command */
204         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
205                                           cmd_flags, token);
206         cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
207         cmd_params->irq_index = irq_index;
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         rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
216         *en = rsp_params->enabled & DPRC_ENABLE;
217
218         return 0;
219 }
220
221 /**
222  * dprc_set_irq_enable() - Set overall interrupt state.
223  * @mc_io:      Pointer to MC portal's I/O object
224  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
225  * @token:      Token of DPRC object
226  * @irq_index:  The interrupt index to configure
227  * @en:         Interrupt state - enable = 1, disable = 0
228  *
229  * Allows GPP software to control when interrupts are generated.
230  * Each interrupt can have up to 32 causes.  The enable/disable control's the
231  * overall interrupt state. if the interrupt is disabled no causes will cause
232  * an interrupt.
233  *
234  * Return:      '0' on Success; Error code otherwise.
235  */
236 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
237                         u32 cmd_flags,
238                         u16 token,
239                         u8 irq_index,
240                         u8 en)
241 {
242         struct mc_command cmd = { 0 };
243         struct dprc_cmd_set_irq_enable *cmd_params;
244
245         /* prepare command */
246         cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
247                                           cmd_flags, token);
248         cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
249         cmd_params->enable = en & DPRC_ENABLE;
250         cmd_params->irq_index = irq_index;
251
252         /* send command to mc*/
253         return mc_send_command(mc_io, &cmd);
254 }
255
256 /**
257  * dprc_get_irq_mask() - Get interrupt mask.
258  * @mc_io:      Pointer to MC portal's I/O object
259  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
260  * @token:      Token of DPRC object
261  * @irq_index:  The interrupt index to configure
262  * @mask:       Returned event mask to trigger interrupt
263  *
264  * Every interrupt can have up to 32 causes and the interrupt model supports
265  * masking/unmasking each cause independently
266  *
267  * Return:      '0' on Success; Error code otherwise.
268  */
269 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
270                       u32 cmd_flags,
271                       u16 token,
272                       u8 irq_index,
273                       u32 *mask)
274 {
275         struct mc_command cmd = { 0 };
276         struct dprc_cmd_get_irq_mask *cmd_params;
277         struct dprc_rsp_get_irq_mask *rsp_params;
278         int err;
279
280         /* prepare command */
281         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
282                                           cmd_flags, token);
283         cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
284         cmd_params->irq_index = irq_index;
285
286         /* send command to mc*/
287         err = mc_send_command(mc_io, &cmd);
288         if (err)
289                 return err;
290
291         /* retrieve response parameters */
292         rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
293         *mask = le32_to_cpu(rsp_params->mask);
294
295         return 0;
296 }
297
298 /**
299  * dprc_set_irq_mask() - Set interrupt mask.
300  * @mc_io:      Pointer to MC portal's I/O object
301  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
302  * @token:      Token of DPRC object
303  * @irq_index:  The interrupt index to configure
304  * @mask:       event mask to trigger interrupt;
305  *                      each bit:
306  *                              0 = ignore event
307  *                              1 = consider event for asserting irq
308  *
309  * Every interrupt can have up to 32 causes and the interrupt model supports
310  * masking/unmasking each cause independently
311  *
312  * Return:      '0' on Success; Error code otherwise.
313  */
314 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
315                       u32 cmd_flags,
316                       u16 token,
317                       u8 irq_index,
318                       u32 mask)
319 {
320         struct mc_command cmd = { 0 };
321         struct dprc_cmd_set_irq_mask *cmd_params;
322
323         /* prepare command */
324         cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
325                                           cmd_flags, token);
326         cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
327         cmd_params->mask = cpu_to_le32(mask);
328         cmd_params->irq_index = irq_index;
329
330         /* send command to mc*/
331         return mc_send_command(mc_io, &cmd);
332 }
333
334 /**
335  * dprc_get_irq_status() - Get the current status of any pending interrupts.
336  * @mc_io:      Pointer to MC portal's I/O object
337  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
338  * @token:      Token of DPRC object
339  * @irq_index:  The interrupt index to configure
340  * @status:     Returned interrupts status - one bit per cause:
341  *                      0 = no interrupt pending
342  *                      1 = interrupt pending
343  *
344  * Return:      '0' on Success; Error code otherwise.
345  */
346 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
347                         u32 cmd_flags,
348                         u16 token,
349                         u8 irq_index,
350                         u32 *status)
351 {
352         struct mc_command cmd = { 0 };
353         struct dprc_cmd_get_irq_status *cmd_params;
354         struct dprc_rsp_get_irq_status *rsp_params;
355         int err;
356
357         /* prepare command */
358         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
359                                           cmd_flags, token);
360         cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
361         cmd_params->status = cpu_to_le32(*status);
362         cmd_params->irq_index = irq_index;
363
364         /* send command to mc*/
365         err = mc_send_command(mc_io, &cmd);
366         if (err)
367                 return err;
368
369         /* retrieve response parameters */
370         rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
371         *status = le32_to_cpu(rsp_params->status);
372
373         return 0;
374 }
375
376 /**
377  * dprc_clear_irq_status() - Clear a pending interrupt's status
378  * @mc_io:      Pointer to MC portal's I/O object
379  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
380  * @token:      Token of DPRC object
381  * @irq_index:  The interrupt index to configure
382  * @status:     bits to clear (W1C) - one bit per cause:
383  *                                      0 = don't change
384  *                                      1 = clear status bit
385  *
386  * Return:      '0' on Success; Error code otherwise.
387  */
388 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
389                           u32 cmd_flags,
390                           u16 token,
391                           u8 irq_index,
392                           u32 status)
393 {
394         struct mc_command cmd = { 0 };
395         struct dprc_cmd_clear_irq_status *cmd_params;
396
397         /* prepare command */
398         cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
399                                           cmd_flags, token);
400         cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
401         cmd_params->status = cpu_to_le32(status);
402         cmd_params->irq_index = irq_index;
403
404         /* send command to mc*/
405         return mc_send_command(mc_io, &cmd);
406 }
407
408 /**
409  * dprc_get_attributes() - Obtains container attributes
410  * @mc_io:      Pointer to MC portal's I/O object
411  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
412  * @token:      Token of DPRC object
413  * @attributes  Returned container attributes
414  *
415  * Return:     '0' on Success; Error code otherwise.
416  */
417 int dprc_get_attributes(struct fsl_mc_io *mc_io,
418                         u32 cmd_flags,
419                         u16 token,
420                         struct dprc_attributes *attr)
421 {
422         struct mc_command cmd = { 0 };
423         struct dprc_rsp_get_attributes *rsp_params;
424         int err;
425
426         /* prepare command */
427         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
428                                           cmd_flags,
429                                           token);
430
431         /* send command to mc*/
432         err = mc_send_command(mc_io, &cmd);
433         if (err)
434                 return err;
435
436         /* retrieve response parameters */
437         rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
438         attr->container_id = le32_to_cpu(rsp_params->container_id);
439         attr->icid = le16_to_cpu(rsp_params->icid);
440         attr->options = le32_to_cpu(rsp_params->options);
441         attr->portal_id = le32_to_cpu(rsp_params->portal_id);
442
443         return 0;
444 }
445
446 /**
447  * dprc_get_obj_count() - Obtains the number of objects in the DPRC
448  * @mc_io:      Pointer to MC portal's I/O object
449  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
450  * @token:      Token of DPRC object
451  * @obj_count:  Number of objects assigned to the DPRC
452  *
453  * Return:      '0' on Success; Error code otherwise.
454  */
455 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
456                        u32 cmd_flags,
457                        u16 token,
458                        int *obj_count)
459 {
460         struct mc_command cmd = { 0 };
461         struct dprc_rsp_get_obj_count *rsp_params;
462         int err;
463
464         /* prepare command */
465         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
466                                           cmd_flags, token);
467
468         /* send command to mc*/
469         err = mc_send_command(mc_io, &cmd);
470         if (err)
471                 return err;
472
473         /* retrieve response parameters */
474         rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
475         *obj_count = le32_to_cpu(rsp_params->obj_count);
476
477         return 0;
478 }
479 EXPORT_SYMBOL(dprc_get_obj_count);
480
481 /**
482  * dprc_get_obj() - Get general information on an object
483  * @mc_io:      Pointer to MC portal's I/O object
484  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
485  * @token:      Token of DPRC object
486  * @obj_index:  Index of the object to be queried (< obj_count)
487  * @obj_desc:   Returns the requested object descriptor
488  *
489  * The object descriptors are retrieved one by one by incrementing
490  * obj_index up to (not including) the value of obj_count returned
491  * from dprc_get_obj_count(). dprc_get_obj_count() must
492  * be called prior to dprc_get_obj().
493  *
494  * Return:      '0' on Success; Error code otherwise.
495  */
496 int dprc_get_obj(struct fsl_mc_io *mc_io,
497                  u32 cmd_flags,
498                  u16 token,
499                  int obj_index,
500                  struct fsl_mc_obj_desc *obj_desc)
501 {
502         struct mc_command cmd = { 0 };
503         struct dprc_cmd_get_obj *cmd_params;
504         struct dprc_rsp_get_obj *rsp_params;
505         int err;
506
507         /* prepare command */
508         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
509                                           cmd_flags,
510                                           token);
511         cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
512         cmd_params->obj_index = cpu_to_le32(obj_index);
513
514         /* send command to mc*/
515         err = mc_send_command(mc_io, &cmd);
516         if (err)
517                 return err;
518
519         /* retrieve response parameters */
520         rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
521         obj_desc->id = le32_to_cpu(rsp_params->id);
522         obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
523         obj_desc->irq_count = rsp_params->irq_count;
524         obj_desc->region_count = rsp_params->region_count;
525         obj_desc->state = le32_to_cpu(rsp_params->state);
526         obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
527         obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
528         obj_desc->flags = le16_to_cpu(rsp_params->flags);
529         strncpy(obj_desc->type, rsp_params->type, 16);
530         obj_desc->type[15] = '\0';
531         strncpy(obj_desc->label, rsp_params->label, 16);
532         obj_desc->label[15] = '\0';
533         return 0;
534 }
535 EXPORT_SYMBOL(dprc_get_obj);
536
537 /**
538  * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
539  * @mc_io:      Pointer to MC portal's I/O object
540  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
541  * @token:      Token of DPRC object
542  * @obj_type:   Type of the object to set its IRQ
543  * @obj_id:     ID of the object to set its IRQ
544  * @irq_index:  The interrupt index to configure
545  * @irq_cfg:    IRQ configuration
546  *
547  * Return:      '0' on Success; Error code otherwise.
548  */
549 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
550                      u32 cmd_flags,
551                      u16 token,
552                      char *obj_type,
553                      int obj_id,
554                      u8 irq_index,
555                      struct dprc_irq_cfg *irq_cfg)
556 {
557         struct mc_command cmd = { 0 };
558         struct dprc_cmd_set_obj_irq *cmd_params;
559
560         /* prepare command */
561         cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
562                                           cmd_flags,
563                                           token);
564         cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
565         cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
566         cmd_params->irq_index = irq_index;
567         cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
568         cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
569         cmd_params->obj_id = cpu_to_le32(obj_id);
570         strncpy(cmd_params->obj_type, obj_type, 16);
571         cmd_params->obj_type[15] = '\0';
572
573         /* send command to mc*/
574         return mc_send_command(mc_io, &cmd);
575 }
576 EXPORT_SYMBOL(dprc_set_obj_irq);
577
578 /**
579  * dprc_get_obj_irq() - Get IRQ information from object.
580  * @mc_io:      Pointer to MC portal's I/O object
581  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
582  * @token:      Token of DPRC object
583  * @obj_type:   Type od the object to get its IRQ
584  * @obj_id:     ID of the object to get its IRQ
585  * @irq_index:  The interrupt index to configure
586  * @type:       Interrupt type: 0 represents message interrupt
587  *              type (both irq_addr and irq_val are valid)
588  * @irq_cfg:    The returned IRQ attributes
589  *
590  * Return:      '0' on Success; Error code otherwise.
591  */
592 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
593                      u32 cmd_flags,
594                      u16 token,
595                      char *obj_type,
596                      int obj_id,
597                      u8 irq_index,
598                      int *type,
599                      struct dprc_irq_cfg *irq_cfg)
600 {
601         struct mc_command cmd = { 0 };
602         struct dprc_cmd_get_obj_irq *cmd_params;
603         struct dprc_rsp_get_obj_irq *rsp_params;
604         int err;
605
606         /* prepare command */
607         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
608                                           cmd_flags,
609                                           token);
610         cmd_params = (struct dprc_cmd_get_obj_irq *)cmd.params;
611         cmd_params->obj_id = cpu_to_le32(obj_id);
612         cmd_params->irq_index = irq_index;
613         strncpy(cmd_params->obj_type, obj_type, 16);
614         cmd_params->obj_type[15] = '\0';
615
616         /* send command to mc*/
617         err = mc_send_command(mc_io, &cmd);
618         if (err)
619                 return err;
620
621         /* retrieve response parameters */
622         rsp_params = (struct dprc_rsp_get_obj_irq *)cmd.params;
623         irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
624         irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
625         irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
626         *type = le32_to_cpu(rsp_params->type);
627
628         return 0;
629 }
630 EXPORT_SYMBOL(dprc_get_obj_irq);
631
632 /**
633  * dprc_get_res_count() - Obtains the number of free resources that are assigned
634  *              to this container, by pool type
635  * @mc_io:      Pointer to MC portal's I/O object
636  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
637  * @token:      Token of DPRC object
638  * @type:       pool type
639  * @res_count:  Returned number of free resources of the given
640  *                      resource type that are assigned to this DPRC
641  *
642  * Return:      '0' on Success; Error code otherwise.
643  */
644 int dprc_get_res_count(struct fsl_mc_io *mc_io,
645                        u32 cmd_flags,
646                        u16 token,
647                        char *type,
648                        int *res_count)
649 {
650         struct mc_command cmd = { 0 };
651         struct dprc_cmd_get_res_count *cmd_params;
652         struct dprc_rsp_get_res_count *rsp_params;
653         int err;
654
655         /* prepare command */
656         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
657                                           cmd_flags, token);
658         cmd_params = (struct dprc_cmd_get_res_count *)cmd.params;
659         strncpy(cmd_params->type, type, 16);
660         cmd_params->type[15] = '\0';
661
662         /* send command to mc*/
663         err = mc_send_command(mc_io, &cmd);
664         if (err)
665                 return err;
666
667         /* retrieve response parameters */
668         rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
669         *res_count = le32_to_cpu(rsp_params->res_count);
670
671         return 0;
672 }
673 EXPORT_SYMBOL(dprc_get_res_count);
674
675 /**
676  * dprc_get_obj_region() - Get region information for a specified object.
677  * @mc_io:      Pointer to MC portal's I/O object
678  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
679  * @token:      Token of DPRC object
680  * @obj_type;   Object type as returned in dprc_get_obj()
681  * @obj_id:     Unique object instance as returned in dprc_get_obj()
682  * @region_index: The specific region to query
683  * @region_desc:  Returns the requested region descriptor
684  *
685  * Return:      '0' on Success; Error code otherwise.
686  */
687 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
688                         u32 cmd_flags,
689                         u16 token,
690                         char *obj_type,
691                         int obj_id,
692                         u8 region_index,
693                         struct dprc_region_desc *region_desc)
694 {
695         struct mc_command cmd = { 0 };
696         struct dprc_cmd_get_obj_region *cmd_params;
697         struct dprc_rsp_get_obj_region *rsp_params;
698         int err;
699
700         /* prepare command */
701         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
702                                           cmd_flags, token);
703         cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
704         cmd_params->obj_id = cpu_to_le32(obj_id);
705         cmd_params->region_index = region_index;
706         strncpy(cmd_params->obj_type, obj_type, 16);
707         cmd_params->obj_type[15] = '\0';
708
709         /* send command to mc*/
710         err = mc_send_command(mc_io, &cmd);
711         if (err)
712                 return err;
713
714         /* retrieve response parameters */
715         rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
716         region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
717         region_desc->size = le32_to_cpu(rsp_params->size);
718
719         return 0;
720 }
721 EXPORT_SYMBOL(dprc_get_obj_region);
722
723 /**
724  * dprc_get_api_version - Get Data Path Resource Container API version
725  * @mc_io:      Pointer to Mc portal's I/O object
726  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
727  * @major_ver:  Major version of Data Path Resource Container API
728  * @minor_ver:  Minor version of Data Path Resource Container API
729  *
730  * Return:      '0' on Success; Error code otherwise.
731  */
732 int dprc_get_api_version(struct fsl_mc_io *mc_io,
733                          u32 cmd_flags,
734                          u16 *major_ver,
735                          u16 *minor_ver)
736 {
737         struct mc_command cmd = { 0 };
738         int err;
739
740         /* prepare command */
741         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
742                                           cmd_flags, 0);
743
744         /* send command to mc */
745         err = mc_send_command(mc_io, &cmd);
746         if (err)
747                 return err;
748
749         /* retrieve response parameters */
750         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
751
752         return 0;
753 }
754
755 /**
756  * dprc_get_container_id - Get container ID associated with a given portal.
757  * @mc_io:              Pointer to Mc portal's I/O object
758  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
759  * @container_id:       Requested container id
760  *
761  * Return:      '0' on Success; Error code otherwise.
762  */
763 int dprc_get_container_id(struct fsl_mc_io *mc_io,
764                           u32 cmd_flags,
765                           int *container_id)
766 {
767         struct mc_command cmd = { 0 };
768         int err;
769
770         /* prepare command */
771         cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
772                                           cmd_flags,
773                                           0);
774
775         /* send command to mc*/
776         err = mc_send_command(mc_io, &cmd);
777         if (err)
778                 return err;
779
780         /* retrieve response parameters */
781         *container_id = (int)mc_cmd_read_object_id(&cmd);
782
783         return 0;
784 }