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->user_irq_id = 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->user_irq_id);
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(32, 8, irq_index);
471 /* send command to mc*/
472 err = mc_send_command(mc_io, &cmd);
476 /* retrieve response parameters */
477 *status = mc_dec(cmd.params[0], 0, 32);
483 * dprc_clear_irq_status() - Clear a pending interrupt's status
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 * @irq_index: The interrupt index to configure
488 * @status: bits to clear (W1C) - one bit per cause:
490 * 1 = clear status bit
492 * Return: '0' on Success; Error code otherwise.
494 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
500 struct mc_command cmd = { 0 };
502 /* prepare command */
503 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
505 cmd.params[0] |= mc_enc(0, 32, status);
506 cmd.params[0] |= mc_enc(32, 8, irq_index);
508 /* send command to mc*/
509 return mc_send_command(mc_io, &cmd);
513 * dprc_get_attributes() - Obtains container attributes
514 * @mc_io: Pointer to MC portal's I/O object
515 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
516 * @token: Token of DPRC object
517 * @attributes Returned container attributes
519 * Return: '0' on Success; Error code otherwise.
521 int dprc_get_attributes(struct fsl_mc_io *mc_io,
524 struct dprc_attributes *attr)
526 struct mc_command cmd = { 0 };
529 /* prepare command */
530 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
534 /* send command to mc*/
535 err = mc_send_command(mc_io, &cmd);
539 /* retrieve response parameters */
540 attr->container_id = mc_dec(cmd.params[0], 0, 32);
541 attr->icid = mc_dec(cmd.params[0], 32, 16);
542 attr->options = mc_dec(cmd.params[1], 0, 32);
543 attr->portal_id = mc_dec(cmd.params[1], 32, 32);
544 attr->version.major = mc_dec(cmd.params[2], 0, 16);
545 attr->version.minor = mc_dec(cmd.params[2], 16, 16);
551 * dprc_set_res_quota() - Set allocation policy for a specific resource/object
552 * type in a child container
553 * @mc_io: Pointer to MC portal's I/O object
554 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
555 * @token: Token of DPRC object
556 * @child_container_id: ID of the child container
557 * @type: Resource/object type
558 * @quota: Sets the maximum number of resources of the selected type
559 * that the child container is allowed to allocate from its parent;
560 * when quota is set to -1, the policy is the same as container's
563 * Allocation policy determines whether or not a container may allocate
564 * resources from its parent. Each container has a 'global' allocation policy
565 * that is set when the container is created.
567 * This function sets allocation policy for a specific resource type.
568 * The default policy for all resource types matches the container's 'global'
571 * Return: '0' on Success; Error code otherwise.
573 * @warning Only the parent container is allowed to change a child policy.
575 int dprc_set_res_quota(struct fsl_mc_io *mc_io,
578 int child_container_id,
582 struct mc_command cmd = { 0 };
584 /* prepare command */
585 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
587 cmd.params[0] |= mc_enc(0, 32, child_container_id);
588 cmd.params[0] |= mc_enc(32, 16, quota);
589 cmd.params[1] |= mc_enc(0, 8, type[0]);
590 cmd.params[1] |= mc_enc(8, 8, type[1]);
591 cmd.params[1] |= mc_enc(16, 8, type[2]);
592 cmd.params[1] |= mc_enc(24, 8, type[3]);
593 cmd.params[1] |= mc_enc(32, 8, type[4]);
594 cmd.params[1] |= mc_enc(40, 8, type[5]);
595 cmd.params[1] |= mc_enc(48, 8, type[6]);
596 cmd.params[1] |= mc_enc(56, 8, type[7]);
597 cmd.params[2] |= mc_enc(0, 8, type[8]);
598 cmd.params[2] |= mc_enc(8, 8, type[9]);
599 cmd.params[2] |= mc_enc(16, 8, type[10]);
600 cmd.params[2] |= mc_enc(24, 8, type[11]);
601 cmd.params[2] |= mc_enc(32, 8, type[12]);
602 cmd.params[2] |= mc_enc(40, 8, type[13]);
603 cmd.params[2] |= mc_enc(48, 8, type[14]);
604 cmd.params[2] |= mc_enc(56, 8, '\0');
606 /* send command to mc*/
607 return mc_send_command(mc_io, &cmd);
611 * dprc_get_res_quota() - Gets the allocation policy of a specific
612 * resource/object type in a child container
613 * @mc_io: Pointer to MC portal's I/O object
614 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
615 * @token: Token of DPRC object
616 * @child_container_id; ID of the child container
617 * @type: resource/object type
618 * @quota: Returnes the maximum number of resources of the selected type
619 * that the child container is allowed to allocate from the parent;
620 * when quota is set to -1, the policy is the same as container's
623 * Return: '0' on Success; Error code otherwise.
625 int dprc_get_res_quota(struct fsl_mc_io *mc_io,
628 int child_container_id,
632 struct mc_command cmd = { 0 };
635 /* prepare command */
636 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
638 cmd.params[0] |= mc_enc(0, 32, child_container_id);
639 cmd.params[1] |= mc_enc(0, 8, type[0]);
640 cmd.params[1] |= mc_enc(8, 8, type[1]);
641 cmd.params[1] |= mc_enc(16, 8, type[2]);
642 cmd.params[1] |= mc_enc(24, 8, type[3]);
643 cmd.params[1] |= mc_enc(32, 8, type[4]);
644 cmd.params[1] |= mc_enc(40, 8, type[5]);
645 cmd.params[1] |= mc_enc(48, 8, type[6]);
646 cmd.params[1] |= mc_enc(56, 8, type[7]);
647 cmd.params[2] |= mc_enc(0, 8, type[8]);
648 cmd.params[2] |= mc_enc(8, 8, type[9]);
649 cmd.params[2] |= mc_enc(16, 8, type[10]);
650 cmd.params[2] |= mc_enc(24, 8, type[11]);
651 cmd.params[2] |= mc_enc(32, 8, type[12]);
652 cmd.params[2] |= mc_enc(40, 8, type[13]);
653 cmd.params[2] |= mc_enc(48, 8, type[14]);
654 cmd.params[2] |= mc_enc(56, 8, '\0');
656 /* send command to mc*/
657 err = mc_send_command(mc_io, &cmd);
661 /* retrieve response parameters */
662 *quota = mc_dec(cmd.params[0], 32, 16);
668 * dprc_assign() - Assigns objects or resource to a child container.
669 * @mc_io: Pointer to MC portal's I/O object
670 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
671 * @token: Token of DPRC object
672 * @container_id: ID of the child container
673 * @res_req: Describes the type and amount of resources to
674 * assign to the given container
676 * Assignment is usually done by a parent (this DPRC) to one of its child
679 * According to the DPRC allocation policy, the assigned resources may be taken
680 * (allocated) from the container's ancestors, if not enough resources are
681 * available in the container itself.
683 * The type of assignment depends on the dprc_res_req options, as follows:
684 * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
685 * the explicit base ID specified at the id_base_align field of res_req.
686 * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
687 * aligned to the value given at id_base_align field of res_req.
688 * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
689 * and indicates that the object must be set to the plugged state.
691 * A container may use this function with its own ID in order to change a
692 * object state to plugged or unplugged.
694 * If IRQ information has been set in the child DPRC, it will signal an
695 * interrupt following every change in its object assignment.
697 * Return: '0' on Success; Error code otherwise.
699 int dprc_assign(struct fsl_mc_io *mc_io,
703 struct dprc_res_req *res_req)
705 struct mc_command cmd = { 0 };
707 /* prepare command */
708 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
710 cmd.params[0] |= mc_enc(0, 32, container_id);
711 cmd.params[0] |= mc_enc(32, 32, res_req->options);
712 cmd.params[1] |= mc_enc(0, 32, res_req->num);
713 cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
714 cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
715 cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
716 cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
717 cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
718 cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
719 cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
720 cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
721 cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
722 cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
723 cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
724 cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
725 cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
726 cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
727 cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
728 cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
729 cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
731 /* send command to mc*/
732 return mc_send_command(mc_io, &cmd);
736 * dprc_unassign() - Un-assigns objects or resources from a child container
737 * and moves them into this (parent) DPRC.
738 * @mc_io: Pointer to MC portal's I/O object
739 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
740 * @token: Token of DPRC object
741 * @child_container_id: ID of the child container
742 * @res_req: Describes the type and amount of resources to un-assign from
743 * the child container
745 * Un-assignment of objects can succeed only if the object is not in the
746 * plugged or opened state.
748 * Return: '0' on Success; Error code otherwise.
750 int dprc_unassign(struct fsl_mc_io *mc_io,
753 int child_container_id,
754 struct dprc_res_req *res_req)
756 struct mc_command cmd = { 0 };
758 /* prepare command */
759 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
762 cmd.params[0] |= mc_enc(0, 32, child_container_id);
763 cmd.params[0] |= mc_enc(32, 32, res_req->options);
764 cmd.params[1] |= mc_enc(0, 32, res_req->num);
765 cmd.params[1] |= mc_enc(32, 32, res_req->id_base_align);
766 cmd.params[2] |= mc_enc(0, 8, res_req->type[0]);
767 cmd.params[2] |= mc_enc(8, 8, res_req->type[1]);
768 cmd.params[2] |= mc_enc(16, 8, res_req->type[2]);
769 cmd.params[2] |= mc_enc(24, 8, res_req->type[3]);
770 cmd.params[2] |= mc_enc(32, 8, res_req->type[4]);
771 cmd.params[2] |= mc_enc(40, 8, res_req->type[5]);
772 cmd.params[2] |= mc_enc(48, 8, res_req->type[6]);
773 cmd.params[2] |= mc_enc(56, 8, res_req->type[7]);
774 cmd.params[3] |= mc_enc(0, 8, res_req->type[8]);
775 cmd.params[3] |= mc_enc(8, 8, res_req->type[9]);
776 cmd.params[3] |= mc_enc(16, 8, res_req->type[10]);
777 cmd.params[3] |= mc_enc(24, 8, res_req->type[11]);
778 cmd.params[3] |= mc_enc(32, 8, res_req->type[12]);
779 cmd.params[3] |= mc_enc(40, 8, res_req->type[13]);
780 cmd.params[3] |= mc_enc(48, 8, res_req->type[14]);
781 cmd.params[3] |= mc_enc(56, 8, res_req->type[15]);
783 /* send command to mc*/
784 return mc_send_command(mc_io, &cmd);
788 * dprc_get_pool_count() - Get the number of dprc's pools
789 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
790 * @mc_io: Pointer to MC portal's I/O object
791 * @token: Token of DPRC object
792 * @pool_count: Returned number of resource pools in the dprc
794 * Return: '0' on Success; Error code otherwise.
796 int dprc_get_pool_count(struct fsl_mc_io *mc_io,
801 struct mc_command cmd = { 0 };
804 /* prepare command */
805 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
808 /* send command to mc*/
809 err = mc_send_command(mc_io, &cmd);
813 /* retrieve response parameters */
814 *pool_count = mc_dec(cmd.params[0], 0, 32);
820 * dprc_get_pool() - Get the type (string) of a certain dprc's pool
821 * @mc_io: Pointer to MC portal's I/O object
822 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
823 * @token: Token of DPRC object
824 * @pool_index; Index of the pool to be queried (< pool_count)
825 * @type: The type of the pool
827 * The pool types retrieved one by one by incrementing
828 * pool_index up to (not including) the value of pool_count returned
829 * from dprc_get_pool_count(). dprc_get_pool_count() must
830 * be called prior to dprc_get_pool().
832 * Return: '0' on Success; Error code otherwise.
834 int dprc_get_pool(struct fsl_mc_io *mc_io,
840 struct mc_command cmd = { 0 };
843 /* prepare command */
844 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
847 cmd.params[0] |= mc_enc(0, 32, pool_index);
849 /* send command to mc*/
850 err = mc_send_command(mc_io, &cmd);
854 /* retrieve response parameters */
855 type[0] = mc_dec(cmd.params[1], 0, 8);
856 type[1] = mc_dec(cmd.params[1], 8, 8);
857 type[2] = mc_dec(cmd.params[1], 16, 8);
858 type[3] = mc_dec(cmd.params[1], 24, 8);
859 type[4] = mc_dec(cmd.params[1], 32, 8);
860 type[5] = mc_dec(cmd.params[1], 40, 8);
861 type[6] = mc_dec(cmd.params[1], 48, 8);
862 type[7] = mc_dec(cmd.params[1], 56, 8);
863 type[8] = mc_dec(cmd.params[2], 0, 8);
864 type[9] = mc_dec(cmd.params[2], 8, 8);
865 type[10] = mc_dec(cmd.params[2], 16, 8);
866 type[11] = mc_dec(cmd.params[2], 24, 8);
867 type[12] = mc_dec(cmd.params[2], 32, 8);
868 type[13] = mc_dec(cmd.params[2], 40, 8);
869 type[14] = mc_dec(cmd.params[2], 48, 8);
876 * dprc_get_obj_count() - Obtains the number of objects in the DPRC
877 * @mc_io: Pointer to MC portal's I/O object
878 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
879 * @token: Token of DPRC object
880 * @obj_count: Number of objects assigned to the DPRC
882 * Return: '0' on Success; Error code otherwise.
884 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
889 struct mc_command cmd = { 0 };
892 /* prepare command */
893 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
896 /* send command to mc*/
897 err = mc_send_command(mc_io, &cmd);
901 /* retrieve response parameters */
902 *obj_count = mc_dec(cmd.params[0], 32, 32);
906 EXPORT_SYMBOL(dprc_get_obj_count);
909 * dprc_get_obj() - Get general information on an object
910 * @mc_io: Pointer to MC portal's I/O object
911 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
912 * @token: Token of DPRC object
913 * @obj_index: Index of the object to be queried (< obj_count)
914 * @obj_desc: Returns the requested object descriptor
916 * The object descriptors are retrieved one by one by incrementing
917 * obj_index up to (not including) the value of obj_count returned
918 * from dprc_get_obj_count(). dprc_get_obj_count() must
919 * be called prior to dprc_get_obj().
921 * Return: '0' on Success; Error code otherwise.
923 int dprc_get_obj(struct fsl_mc_io *mc_io,
927 struct dprc_obj_desc *obj_desc)
929 struct mc_command cmd = { 0 };
932 /* prepare command */
933 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
936 cmd.params[0] |= mc_enc(0, 32, obj_index);
938 /* send command to mc*/
939 err = mc_send_command(mc_io, &cmd);
943 /* retrieve response parameters */
944 obj_desc->id = mc_dec(cmd.params[0], 32, 32);
945 obj_desc->vendor = mc_dec(cmd.params[1], 0, 16);
946 obj_desc->irq_count = mc_dec(cmd.params[1], 16, 8);
947 obj_desc->region_count = mc_dec(cmd.params[1], 24, 8);
948 obj_desc->state = mc_dec(cmd.params[1], 32, 32);
949 obj_desc->ver_major = mc_dec(cmd.params[2], 0, 16);
950 obj_desc->ver_minor = mc_dec(cmd.params[2], 16, 16);
951 obj_desc->type[0] = mc_dec(cmd.params[3], 0, 8);
952 obj_desc->type[1] = mc_dec(cmd.params[3], 8, 8);
953 obj_desc->type[2] = mc_dec(cmd.params[3], 16, 8);
954 obj_desc->type[3] = mc_dec(cmd.params[3], 24, 8);
955 obj_desc->type[4] = mc_dec(cmd.params[3], 32, 8);
956 obj_desc->type[5] = mc_dec(cmd.params[3], 40, 8);
957 obj_desc->type[6] = mc_dec(cmd.params[3], 48, 8);
958 obj_desc->type[7] = mc_dec(cmd.params[3], 56, 8);
959 obj_desc->type[8] = mc_dec(cmd.params[4], 0, 8);
960 obj_desc->type[9] = mc_dec(cmd.params[4], 8, 8);
961 obj_desc->type[10] = mc_dec(cmd.params[4], 16, 8);
962 obj_desc->type[11] = mc_dec(cmd.params[4], 24, 8);
963 obj_desc->type[12] = mc_dec(cmd.params[4], 32, 8);
964 obj_desc->type[13] = mc_dec(cmd.params[4], 40, 8);
965 obj_desc->type[14] = mc_dec(cmd.params[4], 48, 8);
966 obj_desc->type[15] = '\0';
967 obj_desc->label[0] = mc_dec(cmd.params[5], 0, 8);
968 obj_desc->label[1] = mc_dec(cmd.params[5], 8, 8);
969 obj_desc->label[2] = mc_dec(cmd.params[5], 16, 8);
970 obj_desc->label[3] = mc_dec(cmd.params[5], 24, 8);
971 obj_desc->label[4] = mc_dec(cmd.params[5], 32, 8);
972 obj_desc->label[5] = mc_dec(cmd.params[5], 40, 8);
973 obj_desc->label[6] = mc_dec(cmd.params[5], 48, 8);
974 obj_desc->label[7] = mc_dec(cmd.params[5], 56, 8);
975 obj_desc->label[8] = mc_dec(cmd.params[6], 0, 8);
976 obj_desc->label[9] = mc_dec(cmd.params[6], 8, 8);
977 obj_desc->label[10] = mc_dec(cmd.params[6], 16, 8);
978 obj_desc->label[11] = mc_dec(cmd.params[6], 24, 8);
979 obj_desc->label[12] = mc_dec(cmd.params[6], 32, 8);
980 obj_desc->label[13] = mc_dec(cmd.params[6], 40, 8);
981 obj_desc->label[14] = mc_dec(cmd.params[6], 48, 8);
982 obj_desc->label[15] = '\0';
985 EXPORT_SYMBOL(dprc_get_obj);
988 * dprc_get_obj_desc() - Get object descriptor.
990 * @mc_io: Pointer to MC portal's I/O object
991 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
992 * @token: Token of DPRC object
993 * @obj_type: The type of the object to get its descriptor.
994 * @obj_id: The id of the object to get its descriptor
995 * @obj_desc: The returned descriptor to fill and return to the user
997 * Return: '0' on Success; Error code otherwise.
1000 int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
1005 struct dprc_obj_desc *obj_desc)
1007 struct mc_command cmd = { 0 };
1010 /* prepare command */
1011 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
1014 cmd.params[0] |= mc_enc(0, 32, obj_id);
1015 cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
1016 cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
1017 cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
1018 cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
1019 cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
1020 cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
1021 cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
1022 cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
1023 cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
1024 cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
1025 cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
1026 cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
1027 cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
1028 cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
1029 cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
1030 cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
1032 /* send command to mc*/
1033 err = mc_send_command(mc_io, &cmd);
1037 /* retrieve response parameters */
1038 obj_desc->id = (int)mc_dec(cmd.params[0], 32, 32);
1039 obj_desc->vendor = (u16)mc_dec(cmd.params[1], 0, 16);
1040 obj_desc->vendor = (u8)mc_dec(cmd.params[1], 16, 8);
1041 obj_desc->region_count = (u8)mc_dec(cmd.params[1], 24, 8);
1042 obj_desc->state = (u32)mc_dec(cmd.params[1], 32, 32);
1043 obj_desc->ver_major = (u16)mc_dec(cmd.params[2], 0, 16);
1044 obj_desc->ver_minor = (u16)mc_dec(cmd.params[2], 16, 16);
1045 obj_desc->type[0] = (char)mc_dec(cmd.params[3], 0, 8);
1046 obj_desc->type[1] = (char)mc_dec(cmd.params[3], 8, 8);
1047 obj_desc->type[2] = (char)mc_dec(cmd.params[3], 16, 8);
1048 obj_desc->type[3] = (char)mc_dec(cmd.params[3], 24, 8);
1049 obj_desc->type[4] = (char)mc_dec(cmd.params[3], 32, 8);
1050 obj_desc->type[5] = (char)mc_dec(cmd.params[3], 40, 8);
1051 obj_desc->type[6] = (char)mc_dec(cmd.params[3], 48, 8);
1052 obj_desc->type[7] = (char)mc_dec(cmd.params[3], 56, 8);
1053 obj_desc->type[8] = (char)mc_dec(cmd.params[4], 0, 8);
1054 obj_desc->type[9] = (char)mc_dec(cmd.params[4], 8, 8);
1055 obj_desc->type[10] = (char)mc_dec(cmd.params[4], 16, 8);
1056 obj_desc->type[11] = (char)mc_dec(cmd.params[4], 24, 8);
1057 obj_desc->type[12] = (char)mc_dec(cmd.params[4], 32, 8);
1058 obj_desc->type[13] = (char)mc_dec(cmd.params[4], 40, 8);
1059 obj_desc->type[14] = (char)mc_dec(cmd.params[4], 48, 8);
1060 obj_desc->type[15] = (char)mc_dec(cmd.params[4], 56, 8);
1061 obj_desc->label[0] = (char)mc_dec(cmd.params[5], 0, 8);
1062 obj_desc->label[1] = (char)mc_dec(cmd.params[5], 8, 8);
1063 obj_desc->label[2] = (char)mc_dec(cmd.params[5], 16, 8);
1064 obj_desc->label[3] = (char)mc_dec(cmd.params[5], 24, 8);
1065 obj_desc->label[4] = (char)mc_dec(cmd.params[5], 32, 8);
1066 obj_desc->label[5] = (char)mc_dec(cmd.params[5], 40, 8);
1067 obj_desc->label[6] = (char)mc_dec(cmd.params[5], 48, 8);
1068 obj_desc->label[7] = (char)mc_dec(cmd.params[5], 56, 8);
1069 obj_desc->label[8] = (char)mc_dec(cmd.params[6], 0, 8);
1070 obj_desc->label[9] = (char)mc_dec(cmd.params[6], 8, 8);
1071 obj_desc->label[10] = (char)mc_dec(cmd.params[6], 16, 8);
1072 obj_desc->label[11] = (char)mc_dec(cmd.params[6], 24, 8);
1073 obj_desc->label[12] = (char)mc_dec(cmd.params[6], 32, 8);
1074 obj_desc->label[13] = (char)mc_dec(cmd.params[6], 40, 8);
1075 obj_desc->label[14] = (char)mc_dec(cmd.params[6], 48, 8);
1076 obj_desc->label[15] = (char)mc_dec(cmd.params[6], 56, 8);
1080 EXPORT_SYMBOL(dprc_get_obj_desc);
1083 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
1084 * @mc_io: Pointer to MC portal's I/O object
1085 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1086 * @token: Token of DPRC object
1087 * @obj_type: Type of the object to set its IRQ
1088 * @obj_id: ID of the object to set its IRQ
1089 * @irq_index: The interrupt index to configure
1090 * @irq_cfg: IRQ configuration
1092 * Return: '0' on Success; Error code otherwise.
1094 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
1100 struct dprc_irq_cfg *irq_cfg)
1102 struct mc_command cmd = { 0 };
1104 /* prepare command */
1105 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
1108 cmd.params[0] |= mc_enc(32, 8, irq_index);
1109 cmd.params[0] |= mc_enc(0, 32, irq_cfg->val);
1110 cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
1111 cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
1112 cmd.params[2] |= mc_enc(32, 32, obj_id);
1113 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1114 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1115 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1116 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1117 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1118 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1119 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1120 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1121 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1122 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1123 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1124 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1125 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1126 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1127 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1128 cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
1130 /* send command to mc*/
1131 return mc_send_command(mc_io, &cmd);
1133 EXPORT_SYMBOL(dprc_set_obj_irq);
1136 * dprc_get_obj_irq() - Get IRQ information from object.
1137 * @mc_io: Pointer to MC portal's I/O object
1138 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1139 * @token: Token of DPRC object
1140 * @obj_type: Type od the object to get its IRQ
1141 * @obj_id: ID of the object to get its IRQ
1142 * @irq_index: The interrupt index to configure
1143 * @type: Interrupt type: 0 represents message interrupt
1144 * type (both irq_addr and irq_val are valid)
1145 * @irq_cfg: The returned IRQ attributes
1147 * Return: '0' on Success; Error code otherwise.
1149 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
1156 struct dprc_irq_cfg *irq_cfg)
1158 struct mc_command cmd = { 0 };
1161 /* prepare command */
1162 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
1165 cmd.params[0] |= mc_enc(0, 32, obj_id);
1166 cmd.params[0] |= mc_enc(32, 8, irq_index);
1167 cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
1168 cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
1169 cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
1170 cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
1171 cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
1172 cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
1173 cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
1174 cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
1175 cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
1176 cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
1177 cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
1178 cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
1179 cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
1180 cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
1181 cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
1182 cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
1184 /* send command to mc*/
1185 err = mc_send_command(mc_io, &cmd);
1189 /* retrieve response parameters */
1190 irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
1191 irq_cfg->paddr = (u64)mc_dec(cmd.params[1], 0, 64);
1192 irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
1193 *type = (int)mc_dec(cmd.params[2], 32, 32);
1197 EXPORT_SYMBOL(dprc_get_obj_irq);
1200 * dprc_get_res_count() - Obtains the number of free resources that are assigned
1201 * to this container, by pool type
1202 * @mc_io: Pointer to MC portal's I/O object
1203 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1204 * @token: Token of DPRC object
1206 * @res_count: Returned number of free resources of the given
1207 * resource type that are assigned to this DPRC
1209 * Return: '0' on Success; Error code otherwise.
1211 int dprc_get_res_count(struct fsl_mc_io *mc_io,
1217 struct mc_command cmd = { 0 };
1222 /* prepare command */
1223 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
1225 cmd.params[1] |= mc_enc(0, 8, type[0]);
1226 cmd.params[1] |= mc_enc(8, 8, type[1]);
1227 cmd.params[1] |= mc_enc(16, 8, type[2]);
1228 cmd.params[1] |= mc_enc(24, 8, type[3]);
1229 cmd.params[1] |= mc_enc(32, 8, type[4]);
1230 cmd.params[1] |= mc_enc(40, 8, type[5]);
1231 cmd.params[1] |= mc_enc(48, 8, type[6]);
1232 cmd.params[1] |= mc_enc(56, 8, type[7]);
1233 cmd.params[2] |= mc_enc(0, 8, type[8]);
1234 cmd.params[2] |= mc_enc(8, 8, type[9]);
1235 cmd.params[2] |= mc_enc(16, 8, type[10]);
1236 cmd.params[2] |= mc_enc(24, 8, type[11]);
1237 cmd.params[2] |= mc_enc(32, 8, type[12]);
1238 cmd.params[2] |= mc_enc(40, 8, type[13]);
1239 cmd.params[2] |= mc_enc(48, 8, type[14]);
1240 cmd.params[2] |= mc_enc(56, 8, '\0');
1242 /* send command to mc*/
1243 err = mc_send_command(mc_io, &cmd);
1247 /* retrieve response parameters */
1248 *res_count = mc_dec(cmd.params[0], 0, 32);
1252 EXPORT_SYMBOL(dprc_get_res_count);
1255 * dprc_get_res_ids() - Obtains IDs of free resources in the container
1256 * @mc_io: Pointer to MC portal's I/O object
1257 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1258 * @token: Token of DPRC object
1260 * @range_desc: range descriptor
1262 * Return: '0' on Success; Error code otherwise.
1264 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
1268 struct dprc_res_ids_range_desc *range_desc)
1270 struct mc_command cmd = { 0 };
1273 /* prepare command */
1274 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
1276 cmd.params[0] |= mc_enc(42, 7, range_desc->iter_status);
1277 cmd.params[1] |= mc_enc(0, 32, range_desc->base_id);
1278 cmd.params[1] |= mc_enc(32, 32, range_desc->last_id);
1279 cmd.params[2] |= mc_enc(0, 8, type[0]);
1280 cmd.params[2] |= mc_enc(8, 8, type[1]);
1281 cmd.params[2] |= mc_enc(16, 8, type[2]);
1282 cmd.params[2] |= mc_enc(24, 8, type[3]);
1283 cmd.params[2] |= mc_enc(32, 8, type[4]);
1284 cmd.params[2] |= mc_enc(40, 8, type[5]);
1285 cmd.params[2] |= mc_enc(48, 8, type[6]);
1286 cmd.params[2] |= mc_enc(56, 8, type[7]);
1287 cmd.params[3] |= mc_enc(0, 8, type[8]);
1288 cmd.params[3] |= mc_enc(8, 8, type[9]);
1289 cmd.params[3] |= mc_enc(16, 8, type[10]);
1290 cmd.params[3] |= mc_enc(24, 8, type[11]);
1291 cmd.params[3] |= mc_enc(32, 8, type[12]);
1292 cmd.params[3] |= mc_enc(40, 8, type[13]);
1293 cmd.params[3] |= mc_enc(48, 8, type[14]);
1294 cmd.params[3] |= mc_enc(56, 8, '\0');
1296 /* send command to mc*/
1297 err = mc_send_command(mc_io, &cmd);
1301 /* retrieve response parameters */
1302 range_desc->iter_status = mc_dec(cmd.params[0], 42, 7);
1303 range_desc->base_id = mc_dec(cmd.params[1], 0, 32);
1304 range_desc->last_id = mc_dec(cmd.params[1], 32, 32);
1308 EXPORT_SYMBOL(dprc_get_res_ids);
1311 * dprc_get_obj_region() - Get region information for a specified object.
1312 * @mc_io: Pointer to MC portal's I/O object
1313 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1314 * @token: Token of DPRC object
1315 * @obj_type; Object type as returned in dprc_get_obj()
1316 * @obj_id: Unique object instance as returned in dprc_get_obj()
1317 * @region_index: The specific region to query
1318 * @region_desc: Returns the requested region descriptor
1320 * Return: '0' on Success; Error code otherwise.
1322 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
1328 struct dprc_region_desc *region_desc)
1330 struct mc_command cmd = { 0 };
1333 /* prepare command */
1334 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
1336 cmd.params[0] |= mc_enc(0, 32, obj_id);
1337 cmd.params[0] |= mc_enc(48, 8, region_index);
1338 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1339 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1340 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1341 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1342 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1343 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1344 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1345 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1346 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1347 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1348 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1349 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1350 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1351 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1352 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1353 cmd.params[4] |= mc_enc(56, 8, '\0');
1355 /* send command to mc*/
1356 err = mc_send_command(mc_io, &cmd);
1360 /* retrieve response parameters */
1361 region_desc->base_offset = mc_dec(cmd.params[1], 0, 64);
1362 region_desc->size = mc_dec(cmd.params[2], 0, 32);
1366 EXPORT_SYMBOL(dprc_get_obj_region);
1369 * dprc_set_obj_label() - Set object label.
1370 * @mc_io: Pointer to MC portal's I/O object
1371 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1372 * @token: Token of DPRC object
1373 * @obj_type: Object's type
1374 * @obj_id: Object's ID
1375 * @label: The required label. The maximum length is 16 chars.
1377 * Return: '0' on Success; Error code otherwise.
1379 int dprc_set_obj_label(struct fsl_mc_io *mc_io,
1386 struct mc_command cmd = { 0 };
1388 /* prepare command */
1389 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
1393 cmd.params[0] |= mc_enc(0, 32, obj_id);
1394 cmd.params[1] |= mc_enc(0, 8, label[0]);
1395 cmd.params[1] |= mc_enc(8, 8, label[1]);
1396 cmd.params[1] |= mc_enc(16, 8, label[2]);
1397 cmd.params[1] |= mc_enc(24, 8, label[3]);
1398 cmd.params[1] |= mc_enc(32, 8, label[4]);
1399 cmd.params[1] |= mc_enc(40, 8, label[5]);
1400 cmd.params[1] |= mc_enc(48, 8, label[6]);
1401 cmd.params[1] |= mc_enc(56, 8, label[7]);
1402 cmd.params[2] |= mc_enc(0, 8, label[8]);
1403 cmd.params[2] |= mc_enc(8, 8, label[9]);
1404 cmd.params[2] |= mc_enc(16, 8, label[10]);
1405 cmd.params[2] |= mc_enc(24, 8, label[11]);
1406 cmd.params[2] |= mc_enc(32, 8, label[12]);
1407 cmd.params[2] |= mc_enc(40, 8, label[13]);
1408 cmd.params[2] |= mc_enc(48, 8, label[14]);
1409 cmd.params[2] |= mc_enc(56, 8, label[15]);
1410 cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
1411 cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
1412 cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
1413 cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
1414 cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
1415 cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
1416 cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
1417 cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
1418 cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
1419 cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
1420 cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
1421 cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
1422 cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
1423 cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
1424 cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
1425 cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
1427 /* send command to mc*/
1428 return mc_send_command(mc_io, &cmd);
1430 EXPORT_SYMBOL(dprc_set_obj_label);
1433 * dprc_connect() - Connect two endpoints to create a network link between them
1434 * @mc_io: Pointer to MC portal's I/O object
1435 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1436 * @token: Token of DPRC object
1437 * @endpoint1: Endpoint 1 configuration parameters
1438 * @endpoint2: Endpoint 2 configuration parameters
1439 * @cfg: Connection configuration. The connection configuration is ignored for
1440 * connections made to DPMAC objects, where rate is set according to
1441 * MAC configuration.
1442 * The committed rate is the guaranteed rate for the connection.
1443 * The maximum rate is an upper limit allowed for the connection; it is
1444 * expected to be equal or higher than the committed rate.
1445 * When committed and maximum rates are both zero, the connection is set
1446 * to "best effort" mode, having lower priority compared to connections
1447 * with committed or maximum rates.
1449 * Return: '0' on Success; Error code otherwise.
1451 int dprc_connect(struct fsl_mc_io *mc_io,
1454 const struct dprc_endpoint *endpoint1,
1455 const struct dprc_endpoint *endpoint2,
1456 const struct dprc_connection_cfg *cfg)
1458 struct mc_command cmd = { 0 };
1460 /* prepare command */
1461 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
1464 cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
1465 cmd.params[0] |= mc_enc(32, 32, endpoint1->if_id);
1466 cmd.params[1] |= mc_enc(0, 32, endpoint2->id);
1467 cmd.params[1] |= mc_enc(32, 32, endpoint2->if_id);
1468 cmd.params[2] |= mc_enc(0, 8, endpoint1->type[0]);
1469 cmd.params[2] |= mc_enc(8, 8, endpoint1->type[1]);
1470 cmd.params[2] |= mc_enc(16, 8, endpoint1->type[2]);
1471 cmd.params[2] |= mc_enc(24, 8, endpoint1->type[3]);
1472 cmd.params[2] |= mc_enc(32, 8, endpoint1->type[4]);
1473 cmd.params[2] |= mc_enc(40, 8, endpoint1->type[5]);
1474 cmd.params[2] |= mc_enc(48, 8, endpoint1->type[6]);
1475 cmd.params[2] |= mc_enc(56, 8, endpoint1->type[7]);
1476 cmd.params[3] |= mc_enc(0, 8, endpoint1->type[8]);
1477 cmd.params[3] |= mc_enc(8, 8, endpoint1->type[9]);
1478 cmd.params[3] |= mc_enc(16, 8, endpoint1->type[10]);
1479 cmd.params[3] |= mc_enc(24, 8, endpoint1->type[11]);
1480 cmd.params[3] |= mc_enc(32, 8, endpoint1->type[12]);
1481 cmd.params[3] |= mc_enc(40, 8, endpoint1->type[13]);
1482 cmd.params[3] |= mc_enc(48, 8, endpoint1->type[14]);
1483 cmd.params[3] |= mc_enc(56, 8, endpoint1->type[15]);
1484 cmd.params[4] |= mc_enc(0, 32, cfg->max_rate);
1485 cmd.params[4] |= mc_enc(32, 32, cfg->committed_rate);
1486 cmd.params[5] |= mc_enc(0, 8, endpoint2->type[0]);
1487 cmd.params[5] |= mc_enc(8, 8, endpoint2->type[1]);
1488 cmd.params[5] |= mc_enc(16, 8, endpoint2->type[2]);
1489 cmd.params[5] |= mc_enc(24, 8, endpoint2->type[3]);
1490 cmd.params[5] |= mc_enc(32, 8, endpoint2->type[4]);
1491 cmd.params[5] |= mc_enc(40, 8, endpoint2->type[5]);
1492 cmd.params[5] |= mc_enc(48, 8, endpoint2->type[6]);
1493 cmd.params[5] |= mc_enc(56, 8, endpoint2->type[7]);
1494 cmd.params[6] |= mc_enc(0, 8, endpoint2->type[8]);
1495 cmd.params[6] |= mc_enc(8, 8, endpoint2->type[9]);
1496 cmd.params[6] |= mc_enc(16, 8, endpoint2->type[10]);
1497 cmd.params[6] |= mc_enc(24, 8, endpoint2->type[11]);
1498 cmd.params[6] |= mc_enc(32, 8, endpoint2->type[12]);
1499 cmd.params[6] |= mc_enc(40, 8, endpoint2->type[13]);
1500 cmd.params[6] |= mc_enc(48, 8, endpoint2->type[14]);
1501 cmd.params[6] |= mc_enc(56, 8, endpoint2->type[15]);
1503 /* send command to mc*/
1504 return mc_send_command(mc_io, &cmd);
1508 * dprc_disconnect() - Disconnect one endpoint to remove its network connection
1509 * @mc_io: Pointer to MC portal's I/O object
1510 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1511 * @token: Token of DPRC object
1512 * @endpoint: Endpoint configuration parameters
1514 * Return: '0' on Success; Error code otherwise.
1516 int dprc_disconnect(struct fsl_mc_io *mc_io,
1519 const struct dprc_endpoint *endpoint)
1521 struct mc_command cmd = { 0 };
1523 /* prepare command */
1524 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
1527 cmd.params[0] |= mc_enc(0, 32, endpoint->id);
1528 cmd.params[0] |= mc_enc(32, 32, endpoint->if_id);
1529 cmd.params[1] |= mc_enc(0, 8, endpoint->type[0]);
1530 cmd.params[1] |= mc_enc(8, 8, endpoint->type[1]);
1531 cmd.params[1] |= mc_enc(16, 8, endpoint->type[2]);
1532 cmd.params[1] |= mc_enc(24, 8, endpoint->type[3]);
1533 cmd.params[1] |= mc_enc(32, 8, endpoint->type[4]);
1534 cmd.params[1] |= mc_enc(40, 8, endpoint->type[5]);
1535 cmd.params[1] |= mc_enc(48, 8, endpoint->type[6]);
1536 cmd.params[1] |= mc_enc(56, 8, endpoint->type[7]);
1537 cmd.params[2] |= mc_enc(0, 8, endpoint->type[8]);
1538 cmd.params[2] |= mc_enc(8, 8, endpoint->type[9]);
1539 cmd.params[2] |= mc_enc(16, 8, endpoint->type[10]);
1540 cmd.params[2] |= mc_enc(24, 8, endpoint->type[11]);
1541 cmd.params[2] |= mc_enc(32, 8, endpoint->type[12]);
1542 cmd.params[2] |= mc_enc(40, 8, endpoint->type[13]);
1543 cmd.params[2] |= mc_enc(48, 8, endpoint->type[14]);
1544 cmd.params[2] |= mc_enc(56, 8, endpoint->type[15]);
1546 /* send command to mc*/
1547 return mc_send_command(mc_io, &cmd);
1551 * dprc_get_connection() - Get connected endpoint and link status if connection
1553 * @mc_io: Pointer to MC portal's I/O object
1554 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1555 * @token: Token of DPRC object
1556 * @endpoint1: Endpoint 1 configuration parameters
1557 * @endpoint2: Returned endpoint 2 configuration parameters
1558 * @state: Returned link state: 1 - link is up, 0 - link is down
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);