1 /* Copyright 2013-2014 Freescale Semiconductor Inc.
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.
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
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.
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dprc.h"
38 * dprc_open() - Open DPRC object for use
39 * @mc_io: Pointer to MC portal's I/O object
40 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
41 * @container_id: Container ID to open
42 * @token: Returned token of DPRC object
44 * Return: '0' on Success; Error code otherwise.
46 * @warning Required before any operation on the object.
48 int dprc_open(struct fsl_mc_io *mc_io,
53 struct mc_command cmd = { 0 };
57 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
59 cmd.params[0] |= mc_enc(0, 32, container_id);
61 /* send command to mc*/
62 err = mc_send_command(mc_io, &cmd);
66 /* retrieve response parameters */
67 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
71 EXPORT_SYMBOL(dprc_open);
74 * dprc_close() - Close the control session of the object
75 * @mc_io: Pointer to MC portal's I/O object
76 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
77 * @token: Token of DPRC object
79 * After this function is called, no further operations are
80 * allowed on the object without opening a new control session.
82 * Return: '0' on Success; Error code otherwise.
84 int dprc_close(struct fsl_mc_io *mc_io,
88 struct mc_command cmd = { 0 };
91 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
94 /* send command to mc*/
95 return mc_send_command(mc_io, &cmd);
97 EXPORT_SYMBOL(dprc_close);
100 * dprc_create_container() - Create child container
101 * @mc_io: Pointer to MC portal's I/O object
102 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
103 * @token: Token of DPRC object
104 * @cfg: Child container configuration
105 * @child_container_id: Returned child container ID
106 * @child_portal_offset: Returned child portal offset from MC portal base
108 * Return: '0' on Success; Error code otherwise.
110 int dprc_create_container(struct fsl_mc_io *mc_io,
113 struct dprc_cfg *cfg,
114 int *child_container_id,
115 u64 *child_portal_offset)
117 struct mc_command cmd = { 0 };
120 /* prepare command */
121 cmd.params[0] |= mc_enc(32, 16, cfg->icid);
122 cmd.params[0] |= mc_enc(0, 32, cfg->options);
123 cmd.params[1] |= mc_enc(32, 32, cfg->portal_id);
124 cmd.params[2] |= mc_enc(0, 8, cfg->label[0]);
125 cmd.params[2] |= mc_enc(8, 8, cfg->label[1]);
126 cmd.params[2] |= mc_enc(16, 8, cfg->label[2]);
127 cmd.params[2] |= mc_enc(24, 8, cfg->label[3]);
128 cmd.params[2] |= mc_enc(32, 8, cfg->label[4]);
129 cmd.params[2] |= mc_enc(40, 8, cfg->label[5]);
130 cmd.params[2] |= mc_enc(48, 8, cfg->label[6]);
131 cmd.params[2] |= mc_enc(56, 8, cfg->label[7]);
132 cmd.params[3] |= mc_enc(0, 8, cfg->label[8]);
133 cmd.params[3] |= mc_enc(8, 8, cfg->label[9]);
134 cmd.params[3] |= mc_enc(16, 8, cfg->label[10]);
135 cmd.params[3] |= mc_enc(24, 8, cfg->label[11]);
136 cmd.params[3] |= mc_enc(32, 8, cfg->label[12]);
137 cmd.params[3] |= mc_enc(40, 8, cfg->label[13]);
138 cmd.params[3] |= mc_enc(48, 8, cfg->label[14]);
139 cmd.params[3] |= mc_enc(56, 8, cfg->label[15]);
141 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
144 /* send command to mc*/
145 err = mc_send_command(mc_io, &cmd);
149 /* retrieve response parameters */
150 *child_container_id = mc_dec(cmd.params[1], 0, 32);
151 *child_portal_offset = mc_dec(cmd.params[2], 0, 64);
157 * dprc_destroy_container() - Destroy child container.
158 * @mc_io: Pointer to MC portal's I/O object
159 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
160 * @token: Token of DPRC object
161 * @child_container_id: ID of the container to destroy
163 * This function terminates the child container, so following this call the
164 * child container ID becomes invalid.
167 * - All resources and objects of the destroyed container are returned to the
168 * parent container or destroyed if were created be the destroyed container.
169 * - This function destroy all the child containers of the specified
170 * container prior to destroying the container itself.
172 * warning: Only the parent container is allowed to destroy a child policy
173 * Container 0 can't be destroyed
175 * Return: '0' on Success; Error code otherwise.
178 int dprc_destroy_container(struct fsl_mc_io *mc_io,
181 int child_container_id)
183 struct mc_command cmd = { 0 };
185 /* prepare command */
186 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
188 cmd.params[0] |= mc_enc(0, 32, child_container_id);
190 /* send command to mc*/
191 return mc_send_command(mc_io, &cmd);
195 * dprc_reset_container - Reset child container.
196 * @mc_io: Pointer to MC portal's I/O object
197 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
198 * @token: Token of DPRC object
199 * @child_container_id: ID of the container to reset
201 * In case a software context crashes or becomes non-responsive, the parent
202 * may wish to reset its resources container before the software context is
205 * This routine informs all objects assigned to the child container that the
206 * container is being reset, so they may perform any cleanup operations that are
207 * needed. All objects handles that were owned by the child container shall be
210 * Note that such request may be submitted even if the child software context
211 * has not crashed, but the resulting object cleanup operations will not be
214 * Return: '0' on Success; Error code otherwise.
216 int dprc_reset_container(struct fsl_mc_io *mc_io,
219 int child_container_id)
221 struct mc_command cmd = { 0 };
223 /* prepare command */
224 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
226 cmd.params[0] |= mc_enc(0, 32, child_container_id);
228 /* send command to mc*/
229 return mc_send_command(mc_io, &cmd);
233 * dprc_get_irq() - Get IRQ information from the DPRC.
234 * @mc_io: Pointer to MC portal's I/O object
235 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
236 * @token: Token of DPRC object
237 * @irq_index: The interrupt index to configure
238 * @type: Interrupt type: 0 represents message interrupt
239 * type (both irq_addr and irq_val are valid)
240 * @irq_cfg: IRQ attributes
242 * Return: '0' on Success; Error code otherwise.
244 int dprc_get_irq(struct fsl_mc_io *mc_io,
249 struct dprc_irq_cfg *irq_cfg)
251 struct mc_command cmd = { 0 };
254 /* prepare command */
255 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
258 cmd.params[0] |= mc_enc(32, 8, irq_index);
260 /* send command to mc*/
261 err = mc_send_command(mc_io, &cmd);
265 /* retrieve response parameters */
266 irq_cfg->val = mc_dec(cmd.params[0], 0, 32);
267 irq_cfg->paddr = mc_dec(cmd.params[1], 0, 64);
268 irq_cfg->irq_num = mc_dec(cmd.params[2], 0, 32);
269 *type = mc_dec(cmd.params[2], 32, 32);
275 * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
276 * @mc_io: Pointer to MC portal's I/O object
277 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
278 * @token: Token of DPRC object
279 * @irq_index: Identifies the interrupt index to configure
280 * @irq_cfg: IRQ configuration
282 * Return: '0' on Success; Error code otherwise.
284 int dprc_set_irq(struct fsl_mc_io *mc_io,
288 struct dprc_irq_cfg *irq_cfg)
290 struct mc_command cmd = { 0 };
292 /* prepare command */
293 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
296 cmd.params[0] |= mc_enc(32, 8, irq_index);
297 cmd.params[0] |= mc_enc(0, 32, irq_cfg->val);
298 cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
299 cmd.params[2] |= mc_enc(0, 32, irq_cfg->irq_num);
301 /* send command to mc*/
302 return mc_send_command(mc_io, &cmd);
306 * dprc_get_irq_enable() - Get overall interrupt state.
307 * @mc_io: Pointer to MC portal's I/O object
308 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
309 * @token: Token of DPRC object
310 * @irq_index: The interrupt index to configure
311 * @en: Returned interrupt state - enable = 1, disable = 0
313 * Return: '0' on Success; Error code otherwise.
315 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
321 struct mc_command cmd = { 0 };
324 /* prepare command */
325 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
327 cmd.params[0] |= mc_enc(32, 8, irq_index);
329 /* send command to mc*/
330 err = mc_send_command(mc_io, &cmd);
334 /* retrieve response parameters */
335 *en = mc_dec(cmd.params[0], 0, 8);
341 * dprc_set_irq_enable() - Set overall interrupt state.
342 * @mc_io: Pointer to MC portal's I/O object
343 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
344 * @token: Token of DPRC object
345 * @irq_index: The interrupt index to configure
346 * @en: Interrupt state - enable = 1, disable = 0
348 * Allows GPP software to control when interrupts are generated.
349 * Each interrupt can have up to 32 causes. The enable/disable control's the
350 * overall interrupt state. if the interrupt is disabled no causes will cause
353 * Return: '0' on Success; Error code otherwise.
355 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
361 struct mc_command cmd = { 0 };
363 /* prepare command */
364 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
366 cmd.params[0] |= mc_enc(0, 8, en);
367 cmd.params[0] |= mc_enc(32, 8, irq_index);
369 /* send command to mc*/
370 return mc_send_command(mc_io, &cmd);
374 * dprc_get_irq_mask() - Get interrupt mask.
375 * @mc_io: Pointer to MC portal's I/O object
376 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
377 * @token: Token of DPRC object
378 * @irq_index: The interrupt index to configure
379 * @mask: Returned event mask to trigger interrupt
381 * Every interrupt can have up to 32 causes and the interrupt model supports
382 * masking/unmasking each cause independently
384 * Return: '0' on Success; Error code otherwise.
386 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
392 struct mc_command cmd = { 0 };
395 /* prepare command */
396 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
398 cmd.params[0] |= mc_enc(32, 8, irq_index);
400 /* send command to mc*/
401 err = mc_send_command(mc_io, &cmd);
405 /* retrieve response parameters */
406 *mask = mc_dec(cmd.params[0], 0, 32);
412 * dprc_set_irq_mask() - Set interrupt mask.
413 * @mc_io: Pointer to MC portal's I/O object
414 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
415 * @token: Token of DPRC object
416 * @irq_index: The interrupt index to configure
417 * @mask: event mask to trigger interrupt;
420 * 1 = consider event for asserting irq
422 * Every interrupt can have up to 32 causes and the interrupt model supports
423 * masking/unmasking each cause independently
425 * Return: '0' on Success; Error code otherwise.
427 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
433 struct mc_command cmd = { 0 };
435 /* prepare command */
436 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
438 cmd.params[0] |= mc_enc(0, 32, mask);
439 cmd.params[0] |= mc_enc(32, 8, irq_index);
441 /* send command to mc*/
442 return mc_send_command(mc_io, &cmd);
446 * dprc_get_irq_status() - Get the current status of any pending interrupts.
447 * @mc_io: Pointer to MC portal's I/O object
448 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
449 * @token: Token of DPRC object
450 * @irq_index: The interrupt index to configure
451 * @status: Returned interrupts status - one bit per cause:
452 * 0 = no interrupt pending
453 * 1 = interrupt pending
455 * Return: '0' on Success; Error code otherwise.
457 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
463 struct mc_command cmd = { 0 };
466 /* prepare command */
467 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
469 cmd.params[0] |= mc_enc(0, 32, *status);
470 cmd.params[0] |= mc_enc(32, 8, irq_index);
472 /* send command to mc*/
473 err = mc_send_command(mc_io, &cmd);
477 /* retrieve response parameters */
478 *status = mc_dec(cmd.params[0], 0, 32);
484 * dprc_clear_irq_status() - Clear a pending interrupt's status
485 * @mc_io: Pointer to MC portal's I/O object
486 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
487 * @token: Token of DPRC object
488 * @irq_index: The interrupt index to configure
489 * @status: bits to clear (W1C) - one bit per cause:
491 * 1 = clear status bit
493 * Return: '0' on Success; Error code otherwise.
495 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
501 struct mc_command cmd = { 0 };
503 /* prepare command */
504 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
506 cmd.params[0] |= mc_enc(0, 32, status);
507 cmd.params[0] |= mc_enc(32, 8, irq_index);
509 /* send command to mc*/
510 return mc_send_command(mc_io, &cmd);
514 * dprc_get_attributes() - Obtains container attributes
515 * @mc_io: Pointer to MC portal's I/O object
516 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
517 * @token: Token of DPRC object
518 * @attributes Returned container attributes
520 * Return: '0' on Success; Error code otherwise.
522 int dprc_get_attributes(struct fsl_mc_io *mc_io,
525 struct dprc_attributes *attr)
527 struct mc_command cmd = { 0 };
530 /* prepare command */
531 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
535 /* send command to mc*/
536 err = mc_send_command(mc_io, &cmd);
540 /* retrieve response parameters */
541 attr->container_id = mc_dec(cmd.params[0], 0, 32);
542 attr->icid = mc_dec(cmd.params[0], 32, 16);
543 attr->options = mc_dec(cmd.params[1], 0, 32);
544 attr->portal_id = mc_dec(cmd.params[1], 32, 32);
545 attr->version.major = mc_dec(cmd.params[2], 0, 16);
546 attr->version.minor = mc_dec(cmd.params[2], 16, 16);
552 * dprc_set_res_quota() - Set allocation policy for a specific resource/object
553 * type in a child container
554 * @mc_io: Pointer to MC portal's I/O object
555 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
556 * @token: Token of DPRC object
557 * @child_container_id: ID of the child container
558 * @type: Resource/object type
559 * @quota: Sets the maximum number of resources of the selected type
560 * that the child container is allowed to allocate from its parent;
561 * when quota is set to -1, the policy is the same as container's
564 * Allocation policy determines whether or not a container may allocate
565 * resources from its parent. Each container has a 'global' allocation policy
566 * that is set when the container is created.
568 * This function sets allocation policy for a specific resource type.
569 * The default policy for all resource types matches the container's 'global'
572 * Return: '0' on Success; Error code otherwise.
574 * @warning Only the parent container is allowed to change a child policy.
576 int dprc_set_res_quota(struct fsl_mc_io *mc_io,
579 int child_container_id,
583 struct mc_command cmd = { 0 };
585 /* prepare command */
586 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
588 cmd.params[0] |= mc_enc(0, 32, child_container_id);
589 cmd.params[0] |= mc_enc(32, 16, quota);
590 cmd.params[1] |= mc_enc(0, 8, type[0]);
591 cmd.params[1] |= mc_enc(8, 8, type[1]);
592 cmd.params[1] |= mc_enc(16, 8, type[2]);
593 cmd.params[1] |= mc_enc(24, 8, type[3]);
594 cmd.params[1] |= mc_enc(32, 8, type[4]);
595 cmd.params[1] |= mc_enc(40, 8, type[5]);
596 cmd.params[1] |= mc_enc(48, 8, type[6]);
597 cmd.params[1] |= mc_enc(56, 8, type[7]);
598 cmd.params[2] |= mc_enc(0, 8, type[8]);
599 cmd.params[2] |= mc_enc(8, 8, type[9]);
600 cmd.params[2] |= mc_enc(16, 8, type[10]);
601 cmd.params[2] |= mc_enc(24, 8, type[11]);
602 cmd.params[2] |= mc_enc(32, 8, type[12]);
603 cmd.params[2] |= mc_enc(40, 8, type[13]);
604 cmd.params[2] |= mc_enc(48, 8, type[14]);
605 cmd.params[2] |= mc_enc(56, 8, '\0');
607 /* send command to mc*/
608 return mc_send_command(mc_io, &cmd);
612 * dprc_get_res_quota() - Gets the allocation policy of a specific
613 * resource/object type in a child container
614 * @mc_io: Pointer to MC portal's I/O object
615 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
616 * @token: Token of DPRC object
617 * @child_container_id; ID of the child container
618 * @type: resource/object type
619 * @quota: Returnes the maximum number of resources of the selected type
620 * that the child container is allowed to allocate from the parent;
621 * when quota is set to -1, the policy is the same as container's
624 * Return: '0' on Success; Error code otherwise.
626 int dprc_get_res_quota(struct fsl_mc_io *mc_io,
629 int child_container_id,
633 struct mc_command cmd = { 0 };
636 /* prepare command */
637 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
639 cmd.params[0] |= mc_enc(0, 32, child_container_id);
640 cmd.params[1] |= mc_enc(0, 8, type[0]);
641 cmd.params[1] |= mc_enc(8, 8, type[1]);
642 cmd.params[1] |= mc_enc(16, 8, type[2]);
643 cmd.params[1] |= mc_enc(24, 8, type[3]);
644 cmd.params[1] |= mc_enc(32, 8, type[4]);
645 cmd.params[1] |= mc_enc(40, 8, type[5]);
646 cmd.params[1] |= mc_enc(48, 8, type[6]);
647 cmd.params[1] |= mc_enc(56, 8, type[7]);
648 cmd.params[2] |= mc_enc(0, 8, type[8]);
649 cmd.params[2] |= mc_enc(8, 8, type[9]);
650 cmd.params[2] |= mc_enc(16, 8, type[10]);
651 cmd.params[2] |= mc_enc(24, 8, type[11]);
652 cmd.params[2] |= mc_enc(32, 8, type[12]);
653 cmd.params[2] |= mc_enc(40, 8, type[13]);
654 cmd.params[2] |= mc_enc(48, 8, type[14]);
655 cmd.params[2] |= mc_enc(56, 8, '\0');
657 /* send command to mc*/
658 err = mc_send_command(mc_io, &cmd);
662 /* retrieve response parameters */
663 *quota = mc_dec(cmd.params[0], 32, 16);
669 * dprc_assign() - Assigns objects or resource to a child container.
670 * @mc_io: Pointer to MC portal's I/O object
671 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
672 * @token: Token of DPRC object
673 * @container_id: ID of the child container
674 * @res_req: Describes the type and amount of resources to
675 * assign to the given container
677 * Assignment is usually done by a parent (this DPRC) to one of its child
680 * According to the DPRC allocation policy, the assigned resources may be taken
681 * (allocated) from the container's ancestors, if not enough resources are
682 * available in the container itself.
684 * The type of assignment depends on the dprc_res_req options, as follows:
685 * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
686 * the explicit base ID specified at the id_base_align field of res_req.
687 * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
688 * aligned to the value given at id_base_align field of res_req.
689 * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
690 * and indicates that the object must be set to the plugged state.
692 * A container may use this function with its own ID in order to change a
693 * object state to plugged or unplugged.
695 * If IRQ information has been set in the child DPRC, it will signal an
696 * interrupt following every change in its object assignment.
698 * Return: '0' on Success; Error code otherwise.
700 int dprc_assign(struct fsl_mc_io *mc_io,
704 struct dprc_res_req *res_req)
706 struct mc_command cmd = { 0 };
708 /* prepare command */
709 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
711 cmd.params[0] |= mc_enc(0, 32, container_id);
712 cmd.params[0] |= mc_enc(32, 32, res_req->options);
713 cmd.params[1] |= mc_enc(0, 32, res_req->num);
714 cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
715 cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
716 cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
717 cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
718 cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
719 cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
720 cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
721 cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
722 cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
723 cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
724 cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
725 cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
726 cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
727 cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
728 cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
729 cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
730 cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
732 /* send command to mc*/
733 return mc_send_command(mc_io, &cmd);
737 * dprc_unassign() - Un-assigns objects or resources from a child container
738 * and moves them into this (parent) DPRC.
739 * @mc_io: Pointer to MC portal's I/O object
740 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
741 * @token: Token of DPRC object
742 * @child_container_id: ID of the child container
743 * @res_req: Describes the type and amount of resources to un-assign from
744 * the child container
746 * Un-assignment of objects can succeed only if the object is not in the
747 * plugged or opened state.
749 * Return: '0' on Success; Error code otherwise.
751 int dprc_unassign(struct fsl_mc_io *mc_io,
754 int child_container_id,
755 struct dprc_res_req *res_req)
757 struct mc_command cmd = { 0 };
759 /* prepare command */
760 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
763 cmd.params[0] |= mc_enc(0, 32, child_container_id);
764 cmd.params[0] |= mc_enc(32, 32, res_req->options);
765 cmd.params[1] |= mc_enc(0, 32, res_req->num);
766 cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
767 cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
768 cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
769 cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
770 cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
771 cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
772 cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
773 cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
774 cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
775 cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
776 cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
777 cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
778 cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
779 cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
780 cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
781 cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
782 cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
784 /* send command to mc*/
785 return mc_send_command(mc_io, &cmd);
789 * dprc_get_pool_count() - Get the number of dprc's pools
790 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
791 * @mc_io: Pointer to MC portal's I/O object
792 * @token: Token of DPRC object
793 * @pool_count: Returned number of resource pools in the dprc
795 * Return: '0' on Success; Error code otherwise.
797 int dprc_get_pool_count(struct fsl_mc_io *mc_io,
802 struct mc_command cmd = { 0 };
805 /* prepare command */
806 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
809 /* send command to mc*/
810 err = mc_send_command(mc_io, &cmd);
814 /* retrieve response parameters */
815 *pool_count = mc_dec(cmd.params[0], 0, 32);
821 * dprc_get_pool() - Get the type (string) of a certain dprc's pool
822 * @mc_io: Pointer to MC portal's I/O object
823 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
824 * @token: Token of DPRC object
825 * @pool_index; Index of the pool to be queried (< pool_count)
826 * @type: The type of the pool
828 * The pool types retrieved one by one by incrementing
829 * pool_index up to (not including) the value of pool_count returned
830 * from dprc_get_pool_count(). dprc_get_pool_count() must
831 * be called prior to dprc_get_pool().
833 * Return: '0' on Success; Error code otherwise.
835 int dprc_get_pool(struct fsl_mc_io *mc_io,
841 struct mc_command cmd = { 0 };
844 /* prepare command */
845 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
848 cmd.params[0] |= mc_enc(0, 32, pool_index);
850 /* send command to mc*/
851 err = mc_send_command(mc_io, &cmd);
855 /* retrieve response parameters */
856 type[0] = mc_dec(cmd.params[1], 0, 8);
857 type[1] = mc_dec(cmd.params[1], 8, 8);
858 type[2] = mc_dec(cmd.params[1], 16, 8);
859 type[3] = mc_dec(cmd.params[1], 24, 8);
860 type[4] = mc_dec(cmd.params[1], 32, 8);
861 type[5] = mc_dec(cmd.params[1], 40, 8);
862 type[6] = mc_dec(cmd.params[1], 48, 8);
863 type[7] = mc_dec(cmd.params[1], 56, 8);
864 type[8] = mc_dec(cmd.params[2], 0, 8);
865 type[9] = mc_dec(cmd.params[2], 8, 8);
866 type[10] = mc_dec(cmd.params[2], 16, 8);
867 type[11] = mc_dec(cmd.params[2], 24, 8);
868 type[12] = mc_dec(cmd.params[2], 32, 8);
869 type[13] = mc_dec(cmd.params[2], 40, 8);
870 type[14] = mc_dec(cmd.params[2], 48, 8);
877 * dprc_get_obj_count() - Obtains the number of objects in the DPRC
878 * @mc_io: Pointer to MC portal's I/O object
879 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
880 * @token: Token of DPRC object
881 * @obj_count: Number of objects assigned to the DPRC
883 * Return: '0' on Success; Error code otherwise.
885 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
890 struct mc_command cmd = { 0 };
893 /* prepare command */
894 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
897 /* send command to mc*/
898 err = mc_send_command(mc_io, &cmd);
902 /* retrieve response parameters */
903 *obj_count = mc_dec(cmd.params[0], 32, 32);
907 EXPORT_SYMBOL(dprc_get_obj_count);
910 * dprc_get_obj() - Get general information on an object
911 * @mc_io: Pointer to MC portal's I/O object
912 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
913 * @token: Token of DPRC object
914 * @obj_index: Index of the object to be queried (< obj_count)
915 * @obj_desc: Returns the requested object descriptor
917 * The object descriptors are retrieved one by one by incrementing
918 * obj_index up to (not including) the value of obj_count returned
919 * from dprc_get_obj_count(). dprc_get_obj_count() must
920 * be called prior to dprc_get_obj().
922 * Return: '0' on Success; Error code otherwise.
924 int dprc_get_obj(struct fsl_mc_io *mc_io,
928 struct dprc_obj_desc *obj_desc)
930 struct mc_command cmd = { 0 };
933 /* prepare command */
934 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
937 cmd.params[0] |= mc_enc(0, 32, obj_index);
939 /* send command to mc*/
940 err = mc_send_command(mc_io, &cmd);
944 /* retrieve response parameters */
945 obj_desc->id = mc_dec(cmd.params[0], 32, 32);
946 obj_desc->vendor = mc_dec(cmd.params[1], 0, 16);
947 obj_desc->irq_count = mc_dec(cmd.params[1], 16, 8);
948 obj_desc->region_count = mc_dec(cmd.params[1], 24, 8);
949 obj_desc->state = mc_dec(cmd.params[1], 32, 32);
950 obj_desc->ver_major = mc_dec(cmd.params[2], 0, 16);
951 obj_desc->ver_minor = mc_dec(cmd.params[2], 16, 16);
952 obj_desc->flags = mc_dec(cmd.params[2], 32, 16);
953 obj_desc->type[0] = mc_dec(cmd.params[3], 0, 8);
954 obj_desc->type[1] = mc_dec(cmd.params[3], 8, 8);
955 obj_desc->type[2] = mc_dec(cmd.params[3], 16, 8);
956 obj_desc->type[3] = mc_dec(cmd.params[3], 24, 8);
957 obj_desc->type[4] = mc_dec(cmd.params[3], 32, 8);
958 obj_desc->type[5] = mc_dec(cmd.params[3], 40, 8);
959 obj_desc->type[6] = mc_dec(cmd.params[3], 48, 8);
960 obj_desc->type[7] = mc_dec(cmd.params[3], 56, 8);
961 obj_desc->type[8] = mc_dec(cmd.params[4], 0, 8);
962 obj_desc->type[9] = mc_dec(cmd.params[4], 8, 8);
963 obj_desc->type[10] = mc_dec(cmd.params[4], 16, 8);
964 obj_desc->type[11] = mc_dec(cmd.params[4], 24, 8);
965 obj_desc->type[12] = mc_dec(cmd.params[4], 32, 8);
966 obj_desc->type[13] = mc_dec(cmd.params[4], 40, 8);
967 obj_desc->type[14] = mc_dec(cmd.params[4], 48, 8);
968 obj_desc->type[15] = '\0';
969 obj_desc->label[0] = mc_dec(cmd.params[5], 0, 8);
970 obj_desc->label[1] = mc_dec(cmd.params[5], 8, 8);
971 obj_desc->label[2] = mc_dec(cmd.params[5], 16, 8);
972 obj_desc->label[3] = mc_dec(cmd.params[5], 24, 8);
973 obj_desc->label[4] = mc_dec(cmd.params[5], 32, 8);
974 obj_desc->label[5] = mc_dec(cmd.params[5], 40, 8);
975 obj_desc->label[6] = mc_dec(cmd.params[5], 48, 8);
976 obj_desc->label[7] = mc_dec(cmd.params[5], 56, 8);
977 obj_desc->label[8] = mc_dec(cmd.params[6], 0, 8);
978 obj_desc->label[9] = mc_dec(cmd.params[6], 8, 8);
979 obj_desc->label[10] = mc_dec(cmd.params[6], 16, 8);
980 obj_desc->label[11] = mc_dec(cmd.params[6], 24, 8);
981 obj_desc->label[12] = mc_dec(cmd.params[6], 32, 8);
982 obj_desc->label[13] = mc_dec(cmd.params[6], 40, 8);
983 obj_desc->label[14] = mc_dec(cmd.params[6], 48, 8);
984 obj_desc->label[15] = '\0';
987 EXPORT_SYMBOL(dprc_get_obj);
990 * dprc_get_obj_desc() - Get object descriptor.
992 * @mc_io: Pointer to MC portal's I/O object
993 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
994 * @token: Token of DPRC object
995 * @obj_type: The type of the object to get its descriptor.
996 * @obj_id: The id of the object to get its descriptor
997 * @obj_desc: The returned descriptor to fill and return to the user
999 * Return: '0' on Success; Error code otherwise.
1002 int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
1007 struct dprc_obj_desc *obj_desc)
1009 struct mc_command cmd = { 0 };
1012 /* prepare command */
1013 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
1016 cmd.params[0] |= mc_enc(0, 32, obj_id);
1017 cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
1018 cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
1019 cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
1020 cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
1021 cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
1022 cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
1023 cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
1024 cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
1025 cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
1026 cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
1027 cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
1028 cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
1029 cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
1030 cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
1031 cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
1032 cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
1034 /* send command to mc*/
1035 err = mc_send_command(mc_io, &cmd);
1039 /* retrieve response parameters */
1040 obj_desc->id = (int)mc_dec(cmd.params[0], 32, 32);
1041 obj_desc->vendor = (u16)mc_dec(cmd.params[1], 0, 16);
1042 obj_desc->vendor = (u8)mc_dec(cmd.params[1], 16, 8);
1043 obj_desc->region_count = (u8)mc_dec(cmd.params[1], 24, 8);
1044 obj_desc->state = (u32)mc_dec(cmd.params[1], 32, 32);
1045 obj_desc->ver_major = (u16)mc_dec(cmd.params[2], 0, 16);
1046 obj_desc->ver_minor = (u16)mc_dec(cmd.params[2], 16, 16);
1047 obj_desc->flags = mc_dec(cmd.params[2], 32, 16);
1048 obj_desc->type[0] = (char)mc_dec(cmd.params[3], 0, 8);
1049 obj_desc->type[1] = (char)mc_dec(cmd.params[3], 8, 8);
1050 obj_desc->type[2] = (char)mc_dec(cmd.params[3], 16, 8);
1051 obj_desc->type[3] = (char)mc_dec(cmd.params[3], 24, 8);
1052 obj_desc->type[4] = (char)mc_dec(cmd.params[3], 32, 8);
1053 obj_desc->type[5] = (char)mc_dec(cmd.params[3], 40, 8);
1054 obj_desc->type[6] = (char)mc_dec(cmd.params[3], 48, 8);
1055 obj_desc->type[7] = (char)mc_dec(cmd.params[3], 56, 8);
1056 obj_desc->type[8] = (char)mc_dec(cmd.params[4], 0, 8);
1057 obj_desc->type[9] = (char)mc_dec(cmd.params[4], 8, 8);
1058 obj_desc->type[10] = (char)mc_dec(cmd.params[4], 16, 8);
1059 obj_desc->type[11] = (char)mc_dec(cmd.params[4], 24, 8);
1060 obj_desc->type[12] = (char)mc_dec(cmd.params[4], 32, 8);
1061 obj_desc->type[13] = (char)mc_dec(cmd.params[4], 40, 8);
1062 obj_desc->type[14] = (char)mc_dec(cmd.params[4], 48, 8);
1063 obj_desc->type[15] = (char)mc_dec(cmd.params[4], 56, 8);
1064 obj_desc->label[0] = (char)mc_dec(cmd.params[5], 0, 8);
1065 obj_desc->label[1] = (char)mc_dec(cmd.params[5], 8, 8);
1066 obj_desc->label[2] = (char)mc_dec(cmd.params[5], 16, 8);
1067 obj_desc->label[3] = (char)mc_dec(cmd.params[5], 24, 8);
1068 obj_desc->label[4] = (char)mc_dec(cmd.params[5], 32, 8);
1069 obj_desc->label[5] = (char)mc_dec(cmd.params[5], 40, 8);
1070 obj_desc->label[6] = (char)mc_dec(cmd.params[5], 48, 8);
1071 obj_desc->label[7] = (char)mc_dec(cmd.params[5], 56, 8);
1072 obj_desc->label[8] = (char)mc_dec(cmd.params[6], 0, 8);
1073 obj_desc->label[9] = (char)mc_dec(cmd.params[6], 8, 8);
1074 obj_desc->label[10] = (char)mc_dec(cmd.params[6], 16, 8);
1075 obj_desc->label[11] = (char)mc_dec(cmd.params[6], 24, 8);
1076 obj_desc->label[12] = (char)mc_dec(cmd.params[6], 32, 8);
1077 obj_desc->label[13] = (char)mc_dec(cmd.params[6], 40, 8);
1078 obj_desc->label[14] = (char)mc_dec(cmd.params[6], 48, 8);
1079 obj_desc->label[15] = (char)mc_dec(cmd.params[6], 56, 8);
1083 EXPORT_SYMBOL(dprc_get_obj_desc);
1086 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
1087 * @mc_io: Pointer to MC portal's I/O object
1088 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1089 * @token: Token of DPRC object
1090 * @obj_type: Type of the object to set its IRQ
1091 * @obj_id: ID of the object to set its IRQ
1092 * @irq_index: The interrupt index to configure
1093 * @irq_cfg: IRQ configuration
1095 * Return: '0' on Success; Error code otherwise.
1097 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
1103 struct dprc_irq_cfg *irq_cfg)
1105 struct mc_command cmd = { 0 };
1107 /* prepare command */
1108 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
1111 cmd.params[0] |= mc_enc(32, 8, irq_index);
1112 cmd.params[0] |= mc_enc(0, 32, irq_cfg->val);
1113 cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
1114 cmd.params[2] |= mc_enc(0, 32, irq_cfg->irq_num);
1115 cmd.params[2] |= mc_enc(32, 32, obj_id);
1116 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1117 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1118 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1119 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1120 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1121 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1122 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1123 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1124 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1125 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1126 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1127 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1128 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1129 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1130 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1131 cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
1133 /* send command to mc*/
1134 return mc_send_command(mc_io, &cmd);
1136 EXPORT_SYMBOL(dprc_set_obj_irq);
1139 * dprc_get_obj_irq() - Get IRQ information from object.
1140 * @mc_io: Pointer to MC portal's I/O object
1141 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1142 * @token: Token of DPRC object
1143 * @obj_type: Type od the object to get its IRQ
1144 * @obj_id: ID of the object to get its IRQ
1145 * @irq_index: The interrupt index to configure
1146 * @type: Interrupt type: 0 represents message interrupt
1147 * type (both irq_addr and irq_val are valid)
1148 * @irq_cfg: The returned IRQ attributes
1150 * Return: '0' on Success; Error code otherwise.
1152 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
1159 struct dprc_irq_cfg *irq_cfg)
1161 struct mc_command cmd = { 0 };
1164 /* prepare command */
1165 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
1168 cmd.params[0] |= mc_enc(0, 32, obj_id);
1169 cmd.params[0] |= mc_enc(32, 8, irq_index);
1170 cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
1171 cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
1172 cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
1173 cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
1174 cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
1175 cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
1176 cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
1177 cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
1178 cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
1179 cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
1180 cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
1181 cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
1182 cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
1183 cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
1184 cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
1185 cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
1187 /* send command to mc*/
1188 err = mc_send_command(mc_io, &cmd);
1192 /* retrieve response parameters */
1193 irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
1194 irq_cfg->paddr = (u64)mc_dec(cmd.params[1], 0, 64);
1195 irq_cfg->irq_num = (int)mc_dec(cmd.params[2], 0, 32);
1196 *type = (int)mc_dec(cmd.params[2], 32, 32);
1200 EXPORT_SYMBOL(dprc_get_obj_irq);
1203 * dprc_get_res_count() - Obtains the number of free resources that are assigned
1204 * to this container, by pool type
1205 * @mc_io: Pointer to MC portal's I/O object
1206 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1207 * @token: Token of DPRC object
1209 * @res_count: Returned number of free resources of the given
1210 * resource type that are assigned to this DPRC
1212 * Return: '0' on Success; Error code otherwise.
1214 int dprc_get_res_count(struct fsl_mc_io *mc_io,
1220 struct mc_command cmd = { 0 };
1225 /* prepare command */
1226 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
1228 cmd.params[1] |= mc_enc(0, 8, type[0]);
1229 cmd.params[1] |= mc_enc(8, 8, type[1]);
1230 cmd.params[1] |= mc_enc(16, 8, type[2]);
1231 cmd.params[1] |= mc_enc(24, 8, type[3]);
1232 cmd.params[1] |= mc_enc(32, 8, type[4]);
1233 cmd.params[1] |= mc_enc(40, 8, type[5]);
1234 cmd.params[1] |= mc_enc(48, 8, type[6]);
1235 cmd.params[1] |= mc_enc(56, 8, type[7]);
1236 cmd.params[2] |= mc_enc(0, 8, type[8]);
1237 cmd.params[2] |= mc_enc(8, 8, type[9]);
1238 cmd.params[2] |= mc_enc(16, 8, type[10]);
1239 cmd.params[2] |= mc_enc(24, 8, type[11]);
1240 cmd.params[2] |= mc_enc(32, 8, type[12]);
1241 cmd.params[2] |= mc_enc(40, 8, type[13]);
1242 cmd.params[2] |= mc_enc(48, 8, type[14]);
1243 cmd.params[2] |= mc_enc(56, 8, '\0');
1245 /* send command to mc*/
1246 err = mc_send_command(mc_io, &cmd);
1250 /* retrieve response parameters */
1251 *res_count = mc_dec(cmd.params[0], 0, 32);
1255 EXPORT_SYMBOL(dprc_get_res_count);
1258 * dprc_get_res_ids() - Obtains IDs of free resources in the container
1259 * @mc_io: Pointer to MC portal's I/O object
1260 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1261 * @token: Token of DPRC object
1263 * @range_desc: range descriptor
1265 * Return: '0' on Success; Error code otherwise.
1267 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
1271 struct dprc_res_ids_range_desc *range_desc)
1273 struct mc_command cmd = { 0 };
1276 /* prepare command */
1277 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
1279 cmd.params[0] |= mc_enc(42, 7, range_desc->iter_status);
1280 cmd.params[1] |= mc_enc(0, 32, range_desc->base_id);
1281 cmd.params[1] |= mc_enc(32, 32, range_desc->last_id);
1282 cmd.params[2] |= mc_enc(0, 8, type[0]);
1283 cmd.params[2] |= mc_enc(8, 8, type[1]);
1284 cmd.params[2] |= mc_enc(16, 8, type[2]);
1285 cmd.params[2] |= mc_enc(24, 8, type[3]);
1286 cmd.params[2] |= mc_enc(32, 8, type[4]);
1287 cmd.params[2] |= mc_enc(40, 8, type[5]);
1288 cmd.params[2] |= mc_enc(48, 8, type[6]);
1289 cmd.params[2] |= mc_enc(56, 8, type[7]);
1290 cmd.params[3] |= mc_enc(0, 8, type[8]);
1291 cmd.params[3] |= mc_enc(8, 8, type[9]);
1292 cmd.params[3] |= mc_enc(16, 8, type[10]);
1293 cmd.params[3] |= mc_enc(24, 8, type[11]);
1294 cmd.params[3] |= mc_enc(32, 8, type[12]);
1295 cmd.params[3] |= mc_enc(40, 8, type[13]);
1296 cmd.params[3] |= mc_enc(48, 8, type[14]);
1297 cmd.params[3] |= mc_enc(56, 8, '\0');
1299 /* send command to mc*/
1300 err = mc_send_command(mc_io, &cmd);
1304 /* retrieve response parameters */
1305 range_desc->iter_status = mc_dec(cmd.params[0], 42, 7);
1306 range_desc->base_id = mc_dec(cmd.params[1], 0, 32);
1307 range_desc->last_id = mc_dec(cmd.params[1], 32, 32);
1311 EXPORT_SYMBOL(dprc_get_res_ids);
1314 * dprc_get_obj_region() - Get region information for a specified object.
1315 * @mc_io: Pointer to MC portal's I/O object
1316 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1317 * @token: Token of DPRC object
1318 * @obj_type; Object type as returned in dprc_get_obj()
1319 * @obj_id: Unique object instance as returned in dprc_get_obj()
1320 * @region_index: The specific region to query
1321 * @region_desc: Returns the requested region descriptor
1323 * Return: '0' on Success; Error code otherwise.
1325 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
1331 struct dprc_region_desc *region_desc)
1333 struct mc_command cmd = { 0 };
1336 /* prepare command */
1337 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
1339 cmd.params[0] |= mc_enc(0, 32, obj_id);
1340 cmd.params[0] |= mc_enc(48, 8, region_index);
1341 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1342 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1343 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1344 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1345 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1346 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1347 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1348 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1349 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1350 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1351 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1352 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1353 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1354 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1355 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1356 cmd.params[4] |= mc_enc(56, 8, '\0');
1358 /* send command to mc*/
1359 err = mc_send_command(mc_io, &cmd);
1363 /* retrieve response parameters */
1364 region_desc->base_offset = mc_dec(cmd.params[1], 0, 64);
1365 region_desc->size = mc_dec(cmd.params[2], 0, 32);
1369 EXPORT_SYMBOL(dprc_get_obj_region);
1372 * dprc_set_obj_label() - Set object label.
1373 * @mc_io: Pointer to MC portal's I/O object
1374 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1375 * @token: Token of DPRC object
1376 * @obj_type: Object's type
1377 * @obj_id: Object's ID
1378 * @label: The required label. The maximum length is 16 chars.
1380 * Return: '0' on Success; Error code otherwise.
1382 int dprc_set_obj_label(struct fsl_mc_io *mc_io,
1389 struct mc_command cmd = { 0 };
1391 /* prepare command */
1392 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
1396 cmd.params[0] |= mc_enc(0, 32, obj_id);
1397 cmd.params[1] |= mc_enc(0, 8, label[0]);
1398 cmd.params[1] |= mc_enc(8, 8, label[1]);
1399 cmd.params[1] |= mc_enc(16, 8, label[2]);
1400 cmd.params[1] |= mc_enc(24, 8, label[3]);
1401 cmd.params[1] |= mc_enc(32, 8, label[4]);
1402 cmd.params[1] |= mc_enc(40, 8, label[5]);
1403 cmd.params[1] |= mc_enc(48, 8, label[6]);
1404 cmd.params[1] |= mc_enc(56, 8, label[7]);
1405 cmd.params[2] |= mc_enc(0, 8, label[8]);
1406 cmd.params[2] |= mc_enc(8, 8, label[9]);
1407 cmd.params[2] |= mc_enc(16, 8, label[10]);
1408 cmd.params[2] |= mc_enc(24, 8, label[11]);
1409 cmd.params[2] |= mc_enc(32, 8, label[12]);
1410 cmd.params[2] |= mc_enc(40, 8, label[13]);
1411 cmd.params[2] |= mc_enc(48, 8, label[14]);
1412 cmd.params[2] |= mc_enc(56, 8, label[15]);
1413 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1414 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1415 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1416 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1417 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1418 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1419 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1420 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1421 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1422 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1423 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1424 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1425 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1426 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1427 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1428 cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
1430 /* send command to mc*/
1431 return mc_send_command(mc_io, &cmd);
1433 EXPORT_SYMBOL(dprc_set_obj_label);
1436 * dprc_connect() - Connect two endpoints to create a network link between them
1437 * @mc_io: Pointer to MC portal's I/O object
1438 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1439 * @token: Token of DPRC object
1440 * @endpoint1: Endpoint 1 configuration parameters
1441 * @endpoint2: Endpoint 2 configuration parameters
1442 * @cfg: Connection configuration. The connection configuration is ignored for
1443 * connections made to DPMAC objects, where rate is retrieved from the
1444 * MAC configuration.
1446 * Return: '0' on Success; Error code otherwise.
1448 int dprc_connect(struct fsl_mc_io *mc_io,
1451 const struct dprc_endpoint *endpoint1,
1452 const struct dprc_endpoint *endpoint2,
1453 const struct dprc_connection_cfg *cfg)
1455 struct mc_command cmd = { 0 };
1457 /* prepare command */
1458 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
1461 cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
1462 cmd.params[0] |= mc_enc(32, 32, endpoint1->if_id);
1463 cmd.params[1] |= mc_enc(0, 32, endpoint2->id);
1464 cmd.params[1] |= mc_enc(32, 32, endpoint2->if_id);
1465 cmd.params[2] |= mc_enc(0, 8, endpoint1->type[0]);
1466 cmd.params[2] |= mc_enc(8, 8, endpoint1->type[1]);
1467 cmd.params[2] |= mc_enc(16, 8, endpoint1->type[2]);
1468 cmd.params[2] |= mc_enc(24, 8, endpoint1->type[3]);
1469 cmd.params[2] |= mc_enc(32, 8, endpoint1->type[4]);
1470 cmd.params[2] |= mc_enc(40, 8, endpoint1->type[5]);
1471 cmd.params[2] |= mc_enc(48, 8, endpoint1->type[6]);
1472 cmd.params[2] |= mc_enc(56, 8, endpoint1->type[7]);
1473 cmd.params[3] |= mc_enc(0, 8, endpoint1->type[8]);
1474 cmd.params[3] |= mc_enc(8, 8, endpoint1->type[9]);
1475 cmd.params[3] |= mc_enc(16, 8, endpoint1->type[10]);
1476 cmd.params[3] |= mc_enc(24, 8, endpoint1->type[11]);
1477 cmd.params[3] |= mc_enc(32, 8, endpoint1->type[12]);
1478 cmd.params[3] |= mc_enc(40, 8, endpoint1->type[13]);
1479 cmd.params[3] |= mc_enc(48, 8, endpoint1->type[14]);
1480 cmd.params[3] |= mc_enc(56, 8, endpoint1->type[15]);
1481 cmd.params[4] |= mc_enc(0, 32, cfg->max_rate);
1482 cmd.params[4] |= mc_enc(32, 32, cfg->committed_rate);
1483 cmd.params[5] |= mc_enc(0, 8, endpoint2->type[0]);
1484 cmd.params[5] |= mc_enc(8, 8, endpoint2->type[1]);
1485 cmd.params[5] |= mc_enc(16, 8, endpoint2->type[2]);
1486 cmd.params[5] |= mc_enc(24, 8, endpoint2->type[3]);
1487 cmd.params[5] |= mc_enc(32, 8, endpoint2->type[4]);
1488 cmd.params[5] |= mc_enc(40, 8, endpoint2->type[5]);
1489 cmd.params[5] |= mc_enc(48, 8, endpoint2->type[6]);
1490 cmd.params[5] |= mc_enc(56, 8, endpoint2->type[7]);
1491 cmd.params[6] |= mc_enc(0, 8, endpoint2->type[8]);
1492 cmd.params[6] |= mc_enc(8, 8, endpoint2->type[9]);
1493 cmd.params[6] |= mc_enc(16, 8, endpoint2->type[10]);
1494 cmd.params[6] |= mc_enc(24, 8, endpoint2->type[11]);
1495 cmd.params[6] |= mc_enc(32, 8, endpoint2->type[12]);
1496 cmd.params[6] |= mc_enc(40, 8, endpoint2->type[13]);
1497 cmd.params[6] |= mc_enc(48, 8, endpoint2->type[14]);
1498 cmd.params[6] |= mc_enc(56, 8, endpoint2->type[15]);
1500 /* send command to mc*/
1501 return mc_send_command(mc_io, &cmd);
1505 * dprc_disconnect() - Disconnect one endpoint to remove its network connection
1506 * @mc_io: Pointer to MC portal's I/O object
1507 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1508 * @token: Token of DPRC object
1509 * @endpoint: Endpoint configuration parameters
1511 * Return: '0' on Success; Error code otherwise.
1513 int dprc_disconnect(struct fsl_mc_io *mc_io,
1516 const struct dprc_endpoint *endpoint)
1518 struct mc_command cmd = { 0 };
1520 /* prepare command */
1521 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
1524 cmd.params[0] |= mc_enc(0, 32, endpoint->id);
1525 cmd.params[0] |= mc_enc(32, 32, endpoint->if_id);
1526 cmd.params[1] |= mc_enc(0, 8, endpoint->type[0]);
1527 cmd.params[1] |= mc_enc(8, 8, endpoint->type[1]);
1528 cmd.params[1] |= mc_enc(16, 8, endpoint->type[2]);
1529 cmd.params[1] |= mc_enc(24, 8, endpoint->type[3]);
1530 cmd.params[1] |= mc_enc(32, 8, endpoint->type[4]);
1531 cmd.params[1] |= mc_enc(40, 8, endpoint->type[5]);
1532 cmd.params[1] |= mc_enc(48, 8, endpoint->type[6]);
1533 cmd.params[1] |= mc_enc(56, 8, endpoint->type[7]);
1534 cmd.params[2] |= mc_enc(0, 8, endpoint->type[8]);
1535 cmd.params[2] |= mc_enc(8, 8, endpoint->type[9]);
1536 cmd.params[2] |= mc_enc(16, 8, endpoint->type[10]);
1537 cmd.params[2] |= mc_enc(24, 8, endpoint->type[11]);
1538 cmd.params[2] |= mc_enc(32, 8, endpoint->type[12]);
1539 cmd.params[2] |= mc_enc(40, 8, endpoint->type[13]);
1540 cmd.params[2] |= mc_enc(48, 8, endpoint->type[14]);
1541 cmd.params[2] |= mc_enc(56, 8, endpoint->type[15]);
1543 /* send command to mc*/
1544 return mc_send_command(mc_io, &cmd);
1548 * dprc_get_connection() - Get connected endpoint and link status if connection
1550 * @mc_io: Pointer to MC portal's I/O object
1551 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1552 * @token: Token of DPRC object
1553 * @endpoint1: Endpoint 1 configuration parameters
1554 * @endpoint2: Returned endpoint 2 configuration parameters
1555 * @state: Returned link state:
1558 * -1 - no connection (endpoint2 information is irrelevant)
1560 * Return: '0' on Success; -ENAVAIL if connection does not exist.
1562 int dprc_get_connection(struct fsl_mc_io *mc_io,
1565 const struct dprc_endpoint *endpoint1,
1566 struct dprc_endpoint *endpoint2,
1569 struct mc_command cmd = { 0 };
1572 /* prepare command */
1573 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
1576 cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
1577 cmd.params[0] |= mc_enc(32, 32, endpoint1->if_id);
1578 cmd.params[1] |= mc_enc(0, 8, endpoint1->type[0]);
1579 cmd.params[1] |= mc_enc(8, 8, endpoint1->type[1]);
1580 cmd.params[1] |= mc_enc(16, 8, endpoint1->type[2]);
1581 cmd.params[1] |= mc_enc(24, 8, endpoint1->type[3]);
1582 cmd.params[1] |= mc_enc(32, 8, endpoint1->type[4]);
1583 cmd.params[1] |= mc_enc(40, 8, endpoint1->type[5]);
1584 cmd.params[1] |= mc_enc(48, 8, endpoint1->type[6]);
1585 cmd.params[1] |= mc_enc(56, 8, endpoint1->type[7]);
1586 cmd.params[2] |= mc_enc(0, 8, endpoint1->type[8]);
1587 cmd.params[2] |= mc_enc(8, 8, endpoint1->type[9]);
1588 cmd.params[2] |= mc_enc(16, 8, endpoint1->type[10]);
1589 cmd.params[2] |= mc_enc(24, 8, endpoint1->type[11]);
1590 cmd.params[2] |= mc_enc(32, 8, endpoint1->type[12]);
1591 cmd.params[2] |= mc_enc(40, 8, endpoint1->type[13]);
1592 cmd.params[2] |= mc_enc(48, 8, endpoint1->type[14]);
1593 cmd.params[2] |= mc_enc(56, 8, endpoint1->type[15]);
1595 /* send command to mc*/
1596 err = mc_send_command(mc_io, &cmd);
1600 /* retrieve response parameters */
1601 endpoint2->id = mc_dec(cmd.params[3], 0, 32);
1602 endpoint2->if_id = mc_dec(cmd.params[3], 32, 32);
1603 endpoint2->type[0] = mc_dec(cmd.params[4], 0, 8);
1604 endpoint2->type[1] = mc_dec(cmd.params[4], 8, 8);
1605 endpoint2->type[2] = mc_dec(cmd.params[4], 16, 8);
1606 endpoint2->type[3] = mc_dec(cmd.params[4], 24, 8);
1607 endpoint2->type[4] = mc_dec(cmd.params[4], 32, 8);
1608 endpoint2->type[5] = mc_dec(cmd.params[4], 40, 8);
1609 endpoint2->type[6] = mc_dec(cmd.params[4], 48, 8);
1610 endpoint2->type[7] = mc_dec(cmd.params[4], 56, 8);
1611 endpoint2->type[8] = mc_dec(cmd.params[5], 0, 8);
1612 endpoint2->type[9] = mc_dec(cmd.params[5], 8, 8);
1613 endpoint2->type[10] = mc_dec(cmd.params[5], 16, 8);
1614 endpoint2->type[11] = mc_dec(cmd.params[5], 24, 8);
1615 endpoint2->type[12] = mc_dec(cmd.params[5], 32, 8);
1616 endpoint2->type[13] = mc_dec(cmd.params[5], 40, 8);
1617 endpoint2->type[14] = mc_dec(cmd.params[5], 48, 8);
1618 endpoint2->type[15] = mc_dec(cmd.params[5], 56, 8);
1619 *state = mc_dec(cmd.params[6], 0, 32);