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