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