linux/drivers/staging/fsl-mc/include/dprc.h
<<
>>
Prefs
   1/* Copyright 2013-2015 Freescale Semiconductor Inc.
   2 *
   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.
  13 *
  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#ifndef _FSL_DPRC_H
  33#define _FSL_DPRC_H
  34
  35#include "mc-cmd.h"
  36
  37/* Data Path Resource Container API
  38 * Contains DPRC API for managing and querying DPAA resources
  39 */
  40
  41struct fsl_mc_io;
  42
  43/**
  44 * Set this value as the icid value in dprc_cfg structure when creating a
  45 * container, in case the ICID is not selected by the user and should be
  46 * allocated by the DPRC from the pool of ICIDs.
  47 */
  48#define DPRC_GET_ICID_FROM_POOL                 (u16)(~(0))
  49
  50/**
  51 * Set this value as the portal_id value in dprc_cfg structure when creating a
  52 * container, in case the portal ID is not specifically selected by the
  53 * user and should be allocated by the DPRC from the pool of portal ids.
  54 */
  55#define DPRC_GET_PORTAL_ID_FROM_POOL    (int)(~(0))
  56
  57int dprc_open(struct fsl_mc_io *mc_io,
  58              u32 cmd_flags,
  59              int container_id,
  60              u16 *token);
  61
  62int dprc_close(struct fsl_mc_io *mc_io,
  63               u32 cmd_flags,
  64               u16 token);
  65
  66/**
  67 * Container general options
  68 *
  69 * These options may be selected at container creation by the container creator
  70 * and can be retrieved using dprc_get_attributes()
  71 */
  72
  73/* Spawn Policy Option allowed - Indicates that the new container is allowed
  74 * to spawn and have its own child containers.
  75 */
  76#define DPRC_CFG_OPT_SPAWN_ALLOWED              0x00000001
  77
  78/* General Container allocation policy - Indicates that the new container is
  79 * allowed to allocate requested resources from its parent container; if not
  80 * set, the container is only allowed to use resources in its own pools; Note
  81 * that this is a container's global policy, but the parent container may
  82 * override it and set specific quota per resource type.
  83 */
  84#define DPRC_CFG_OPT_ALLOC_ALLOWED              0x00000002
  85
  86/* Object initialization allowed - software context associated with this
  87 * container is allowed to invoke object initialization operations.
  88 */
  89#define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
  90
  91/* Topology change allowed - software context associated with this
  92 * container is allowed to invoke topology operations, such as attach/detach
  93 * of network objects.
  94 */
  95#define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED   0x00000008
  96
  97/* IOMMU bypass - indicates whether objects of this container are permitted
  98 * to bypass the IOMMU.
  99 */
 100#define DPRC_CFG_OPT_IOMMU_BYPASS               0x00000010
 101
 102/* AIOP - Indicates that container belongs to AIOP.  */
 103#define DPRC_CFG_OPT_AIOP                       0x00000020
 104
 105/* IRQ Config - Indicates that the container allowed to configure its IRQs.  */
 106#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED            0x00000040
 107
 108/**
 109 * struct dprc_cfg - Container configuration options
 110 * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
 111 *              ICID value is allocated by the DPRC
 112 * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
 113 *              portal ID is allocated by the DPRC
 114 * @options: Combination of 'DPRC_CFG_OPT_<X>' options
 115 * @label: Object's label
 116 */
 117struct dprc_cfg {
 118        u16 icid;
 119        int portal_id;
 120        u64 options;
 121        char label[16];
 122};
 123
 124int dprc_create_container(struct fsl_mc_io      *mc_io,
 125                          u32           cmd_flags,
 126                          u16           token,
 127                          struct dprc_cfg       *cfg,
 128                          int                   *child_container_id,
 129                          u64           *child_portal_offset);
 130
 131int dprc_destroy_container(struct fsl_mc_io     *mc_io,
 132                           u32          cmd_flags,
 133                           u16          token,
 134                           int                  child_container_id);
 135
 136int dprc_reset_container(struct fsl_mc_io *mc_io,
 137                         u32 cmd_flags,
 138                         u16 token,
 139                         int child_container_id);
 140
 141/* IRQ */
 142
 143/* IRQ index */
 144#define DPRC_IRQ_INDEX          0
 145
 146/* Number of dprc's IRQs */
 147#define DPRC_NUM_OF_IRQS                1
 148
 149/* DPRC IRQ events */
 150
 151/* IRQ event - Indicates that a new object added to the container */
 152#define DPRC_IRQ_EVENT_OBJ_ADDED                0x00000001
 153/* IRQ event - Indicates that an object was removed from the container */
 154#define DPRC_IRQ_EVENT_OBJ_REMOVED              0x00000002
 155/* IRQ event - Indicates that resources added to the container */
 156#define DPRC_IRQ_EVENT_RES_ADDED                0x00000004
 157/* IRQ event - Indicates that resources removed from the container */
 158#define DPRC_IRQ_EVENT_RES_REMOVED              0x00000008
 159/* IRQ event - Indicates that one of the descendant containers that opened by
 160 * this container is destroyed
 161 */
 162#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED      0x00000010
 163
 164/* IRQ event - Indicates that on one of the container's opened object is
 165 * destroyed
 166 */
 167#define DPRC_IRQ_EVENT_OBJ_DESTROYED            0x00000020
 168
 169/* Irq event - Indicates that object is created at the container */
 170#define DPRC_IRQ_EVENT_OBJ_CREATED              0x00000040
 171
 172/**
 173 * struct dprc_irq_cfg - IRQ configuration
 174 * @paddr:      Address that must be written to signal a message-based interrupt
 175 * @val:        Value to write into irq_addr address
 176 * @user_irq_id: A user defined number associated with this IRQ
 177 */
 178struct dprc_irq_cfg {
 179             phys_addr_t        paddr;
 180             u32                val;
 181             int                user_irq_id;
 182};
 183
 184int dprc_set_irq(struct fsl_mc_io       *mc_io,
 185                 u32            cmd_flags,
 186                 u16            token,
 187                 u8             irq_index,
 188                 struct dprc_irq_cfg    *irq_cfg);
 189
 190int dprc_get_irq(struct fsl_mc_io       *mc_io,
 191                 u32            cmd_flags,
 192                 u16            token,
 193                 u8             irq_index,
 194                 int                    *type,
 195                 struct dprc_irq_cfg    *irq_cfg);
 196
 197int dprc_set_irq_enable(struct fsl_mc_io        *mc_io,
 198                        u32             cmd_flags,
 199                        u16             token,
 200                        u8                      irq_index,
 201                        u8                      en);
 202
 203int dprc_get_irq_enable(struct fsl_mc_io        *mc_io,
 204                        u32             cmd_flags,
 205                        u16             token,
 206                        u8                      irq_index,
 207                        u8                      *en);
 208
 209int dprc_set_irq_mask(struct fsl_mc_io  *mc_io,
 210                      u32               cmd_flags,
 211                      u16               token,
 212                      u8                irq_index,
 213                      u32               mask);
 214
 215int dprc_get_irq_mask(struct fsl_mc_io  *mc_io,
 216                      u32               cmd_flags,
 217                      u16               token,
 218                      u8                irq_index,
 219                      u32               *mask);
 220
 221int dprc_get_irq_status(struct fsl_mc_io        *mc_io,
 222                        u32             cmd_flags,
 223                        u16             token,
 224                        u8                      irq_index,
 225                        u32             *status);
 226
 227int dprc_clear_irq_status(struct fsl_mc_io      *mc_io,
 228                          u32           cmd_flags,
 229                          u16           token,
 230                          u8            irq_index,
 231                          u32           status);
 232
 233/**
 234 * struct dprc_attributes - Container attributes
 235 * @container_id: Container's ID
 236 * @icid: Container's ICID
 237 * @portal_id: Container's portal ID
 238 * @options: Container's options as set at container's creation
 239 * @version: DPRC version
 240 */
 241struct dprc_attributes {
 242        int container_id;
 243        u16 icid;
 244        int portal_id;
 245        u64 options;
 246        /**
 247         * struct version - DPRC version
 248         * @major: DPRC major version
 249         * @minor: DPRC minor version
 250         */
 251        struct {
 252                u16 major;
 253                u16 minor;
 254        } version;
 255};
 256
 257int dprc_get_attributes(struct fsl_mc_io        *mc_io,
 258                        u32             cmd_flags,
 259                        u16             token,
 260                        struct dprc_attributes  *attributes);
 261
 262int dprc_set_res_quota(struct fsl_mc_io *mc_io,
 263                       u32              cmd_flags,
 264                       u16              token,
 265                       int              child_container_id,
 266                       char             *type,
 267                       u16              quota);
 268
 269int dprc_get_res_quota(struct fsl_mc_io *mc_io,
 270                       u32              cmd_flags,
 271                       u16              token,
 272                       int              child_container_id,
 273                       char             *type,
 274                       u16              *quota);
 275
 276/* Resource request options */
 277
 278/* Explicit resource ID request - The requested objects/resources
 279 * are explicit and sequential (in case of resources).
 280 * The base ID is given at res_req at base_align field
 281 */
 282#define DPRC_RES_REQ_OPT_EXPLICIT               0x00000001
 283
 284/* Aligned resources request - Relevant only for resources
 285 * request (and not objects). Indicates that resources base ID should be
 286 * sequential and aligned to the value given at dprc_res_req base_align field
 287 */
 288#define DPRC_RES_REQ_OPT_ALIGNED                0x00000002
 289
 290/* Plugged Flag - Relevant only for object assignment request.
 291 * Indicates that after all objects assigned. An interrupt will be invoked at
 292 * the relevant GPP. The assigned object will be marked as plugged.
 293 * plugged objects can't be assigned from their container
 294 */
 295#define DPRC_RES_REQ_OPT_PLUGGED                0x00000004
 296
 297/**
 298 * struct dprc_res_req - Resource request descriptor, to be used in assignment
 299 *                      or un-assignment of resources and objects.
 300 * @type: Resource/object type: Represent as a NULL terminated string.
 301 *      This string may received by using dprc_get_pool() to get resource
 302 *      type and dprc_get_obj() to get object type;
 303 *      Note: it is not possible to assign/un-assign DPRC objects
 304 * @num: Number of resources
 305 * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
 306 * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
 307 *              is set at option), this field represents the required base ID
 308 *              for resource allocation; In case of aligned assignment
 309 *              (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
 310 *              indicates the required alignment for the resource ID(s) -
 311 *              use 0 if there is no alignment or explicit ID requirements
 312 */
 313struct dprc_res_req {
 314        char type[16];
 315        u32 num;
 316        u32 options;
 317        int id_base_align;
 318};
 319
 320int dprc_assign(struct fsl_mc_io        *mc_io,
 321                u32             cmd_flags,
 322                u16             token,
 323                int                     container_id,
 324                struct dprc_res_req     *res_req);
 325
 326int dprc_unassign(struct fsl_mc_io      *mc_io,
 327                  u32           cmd_flags,
 328                  u16           token,
 329                  int                   child_container_id,
 330                  struct dprc_res_req   *res_req);
 331
 332int dprc_get_pool_count(struct fsl_mc_io        *mc_io,
 333                        u32             cmd_flags,
 334                        u16             token,
 335                        int                     *pool_count);
 336
 337int dprc_get_pool(struct fsl_mc_io      *mc_io,
 338                  u32           cmd_flags,
 339                  u16           token,
 340                  int                   pool_index,
 341                  char                  *type);
 342
 343int dprc_get_obj_count(struct fsl_mc_io *mc_io,
 344                       u32              cmd_flags,
 345                       u16              token,
 346                       int              *obj_count);
 347
 348/* Objects Attributes Flags */
 349
 350/* Opened state - Indicates that an object is open by at least one owner */
 351#define DPRC_OBJ_STATE_OPEN             0x00000001
 352/* Plugged state - Indicates that the object is plugged */
 353#define DPRC_OBJ_STATE_PLUGGED          0x00000002
 354
 355/**
 356 * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
 357 * @type: Type of object: NULL terminated string
 358 * @id: ID of logical object resource
 359 * @vendor: Object vendor identifier
 360 * @ver_major: Major version number
 361 * @ver_minor:  Minor version number
 362 * @irq_count: Number of interrupts supported by the object
 363 * @region_count: Number of mappable regions supported by the object
 364 * @state: Object state: combination of DPRC_OBJ_STATE_ states
 365 * @label: Object label
 366 */
 367struct dprc_obj_desc {
 368        char type[16];
 369        int id;
 370        u16 vendor;
 371        u16 ver_major;
 372        u16 ver_minor;
 373        u8 irq_count;
 374        u8 region_count;
 375        u32 state;
 376        char label[16];
 377};
 378
 379int dprc_get_obj(struct fsl_mc_io       *mc_io,
 380                 u32            cmd_flags,
 381                 u16            token,
 382                 int                    obj_index,
 383                 struct dprc_obj_desc   *obj_desc);
 384
 385int dprc_get_obj_desc(struct fsl_mc_io          *mc_io,
 386                      u32               cmd_flags,
 387                        u16             token,
 388                        char                    *obj_type,
 389                        int                     obj_id,
 390                        struct dprc_obj_desc    *obj_desc);
 391
 392int dprc_set_obj_irq(struct fsl_mc_io           *mc_io,
 393                     u32                        cmd_flags,
 394                     u16                        token,
 395                     char                       *obj_type,
 396                     int                        obj_id,
 397                     u8                 irq_index,
 398                     struct dprc_irq_cfg        *irq_cfg);
 399
 400int dprc_get_obj_irq(struct fsl_mc_io           *mc_io,
 401                     u32                        cmd_flags,
 402                     u16                        token,
 403                     char                       *obj_type,
 404                     int                        obj_id,
 405                     u8                 irq_index,
 406                     int                        *type,
 407                     struct dprc_irq_cfg        *irq_cfg);
 408
 409int dprc_get_res_count(struct fsl_mc_io *mc_io,
 410                       u32              cmd_flags,
 411                       u16              token,
 412                       char             *type,
 413                       int              *res_count);
 414
 415/**
 416 * enum dprc_iter_status - Iteration status
 417 * @DPRC_ITER_STATUS_FIRST: Perform first iteration
 418 * @DPRC_ITER_STATUS_MORE: Indicates more/next iteration is needed
 419 * @DPRC_ITER_STATUS_LAST: Indicates last iteration
 420 */
 421enum dprc_iter_status {
 422        DPRC_ITER_STATUS_FIRST = 0,
 423        DPRC_ITER_STATUS_MORE = 1,
 424        DPRC_ITER_STATUS_LAST = 2
 425};
 426
 427/**
 428 * struct dprc_res_ids_range_desc - Resource ID range descriptor
 429 * @base_id: Base resource ID of this range
 430 * @last_id: Last resource ID of this range
 431 * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
 432 *      first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
 433 *      additional iterations are needed, until the returned marker is
 434 *      DPRC_ITER_STATUS_LAST
 435 */
 436struct dprc_res_ids_range_desc {
 437        int base_id;
 438        int last_id;
 439        enum dprc_iter_status iter_status;
 440};
 441
 442int dprc_get_res_ids(struct fsl_mc_io                   *mc_io,
 443                     u32                                cmd_flags,
 444                     u16                                token,
 445                     char                               *type,
 446                     struct dprc_res_ids_range_desc     *range_desc);
 447
 448/* Region flags */
 449/* Cacheable - Indicates that region should be mapped as cacheable */
 450#define DPRC_REGION_CACHEABLE   0x00000001
 451
 452/**
 453 * enum dprc_region_type - Region type
 454 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
 455 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
 456 */
 457enum dprc_region_type {
 458        DPRC_REGION_TYPE_MC_PORTAL,
 459        DPRC_REGION_TYPE_QBMAN_PORTAL
 460};
 461
 462/**
 463 * struct dprc_region_desc - Mappable region descriptor
 464 * @base_offset: Region offset from region's base address.
 465 *      For DPMCP and DPRC objects, region base is offset from SoC MC portals
 466 *      base address; For DPIO, region base is offset from SoC QMan portals
 467 *      base address
 468 * @size: Region size (in bytes)
 469 * @flags: Region attributes
 470 * @type: Portal region type
 471 */
 472struct dprc_region_desc {
 473        u32 base_offset;
 474        u32 size;
 475        u32 flags;
 476        enum dprc_region_type type;
 477};
 478
 479int dprc_get_obj_region(struct fsl_mc_io        *mc_io,
 480                        u32             cmd_flags,
 481                        u16             token,
 482                        char                    *obj_type,
 483                        int                     obj_id,
 484                        u8                      region_index,
 485                        struct dprc_region_desc *region_desc);
 486
 487int dprc_set_obj_label(struct fsl_mc_io *mc_io,
 488                       u32              cmd_flags,
 489                       u16              token,
 490                       char             *obj_type,
 491                       int              obj_id,
 492                       char             *label);
 493
 494/**
 495 * struct dprc_endpoint - Endpoint description for link connect/disconnect
 496 *                      operations
 497 * @type: Endpoint object type: NULL terminated string
 498 * @id: Endpoint object ID
 499 * @if_id: Interface ID; should be set for endpoints with multiple
 500 *              interfaces ("dpsw", "dpdmux"); for others, always set to 0
 501 */
 502struct dprc_endpoint {
 503        char type[16];
 504        int id;
 505        int if_id;
 506};
 507
 508/**
 509 * struct dprc_connection_cfg - Connection configuration.
 510 *                              Used for virtual connections only
 511 * @committed_rate: Committed rate (Mbits/s)
 512 * @max_rate: Maximum rate (Mbits/s)
 513 */
 514struct dprc_connection_cfg {
 515        u32 committed_rate;
 516        u32 max_rate;
 517};
 518
 519int dprc_connect(struct fsl_mc_io               *mc_io,
 520                 u32                    cmd_flags,
 521                 u16                    token,
 522                 const struct dprc_endpoint     *endpoint1,
 523                 const struct dprc_endpoint     *endpoint2,
 524                 const struct dprc_connection_cfg *cfg);
 525
 526int dprc_disconnect(struct fsl_mc_io            *mc_io,
 527                    u32                 cmd_flags,
 528                    u16                 token,
 529                    const struct dprc_endpoint  *endpoint);
 530
 531int dprc_get_connection(struct fsl_mc_io                *mc_io,
 532                        u32                     cmd_flags,
 533                        u16                     token,
 534                        const struct dprc_endpoint      *endpoint1,
 535                        struct dprc_endpoint            *endpoint2,
 536                        int                             *state);
 537
 538#endif /* _FSL_DPRC_H */
 539
 540