////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2019-2022 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxcslopedefs.h
/// @brief OPE Hardware Interface Definition
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXCSLOPEDEFS_H
#define CAMXCSLOPEDEFS_H
#include "camxutils.h"
#include "camxcslresourcedefs.h"

CAMX_BEGIN_PACKED

static const UINT OPEInputFull = 1;
static const UINT OPEInputMax  = 1;

static const UINT OPEOutputVideo     = 1;
static const UINT OPEOutputDisp      = 2;
static const UINT OPEOutputARGB      = 3;
static const UINT OPEOutputStatRS    = 4;
static const UINT OPEOutputStatIHIST = 5;
static const UINT OPEOutputStatLTM   = 6;
static const UINT OPEOutputMax       = 6;

// OPE Command Buffer Scope
static const UINT CSLOPECMDBufferScopeBatch  = 1;
static const UINT CSLOPECMDBufferScopeFrame  = 2;
static const UINT CSLOPECMDBufferScopePass   = 3;
static const UINT CSLOPECMDBufferScopeStripe = 4;

// OPE Command Buffer Type
static const UINT CSLOPECMDBufferTypeDirect   = 1;
static const UINT CSLOPECMDBufferTypeInDirect = 2;

// OPE Command Buffer Usage
static const UINT CSLOPECMDBufferUsageUMD   = 1;
static const UINT CSLOPECMDBufferUsageKMD   = 2;
static const UINT CSLOPECMDBufferUsageDebug = 3;

// OPE Single/Double Buffered
static const UINT CSLOPECMDSingleBuffered   = 1;
static const UINT CSLOPECMDDoubleBuffered   = 2;

static const UINT CSLOPEGenericBlobCmdBufferClk = 1;

// OPE Stipe Location
static const UINT CSLOPEStripeFULL          = 0;
static const UINT CSLOPEStripeLEFT          = 1;
static const UINT CSLOPEStripeRIGHT         = 2;
static const UINT CSLOPEStripeMIDDLE        = 3;

static const UINT CSLOPEMaxCDMBLs           = 32;
static const UINT CSLOPEMaxCMDBuffers       = 64;
static const UINT CSLOPEMaxIOBuffers        = OPEInputMax + OPEOutputMax;
static const UINT CSLOPEMaxPass             = 1;
static const UINT CSLOPEMaxPlanes           = 2;
static const UINT CSLOPEMaxStripes          = 64;
static const UINT CSLOPEMaxBatchSize        = 16;

struct CSLOPEStripeInfo
{
    UINT32 offset;           ///< Offset of Stripe
    UINT32 xInit;            ///< Init on x-axis
    UINT32 stripeLocation;   ///< stripe Location
    UINT32 width;            ///< width of Stripe
    UINT32 height;           ///< height of Stripe
    UINT32 disableBus;       ///< disable Bus flag
    UINT32 reserved;         ///< Reserved
} CAMX_PACKED;

struct CSLOPEIOBufferInfo
{
    UINT32            direction;                                         ///< Direction of buffer of a port (Input/Output)
    UINT32            resourceType;                                      ///< Resource Type
    UINT32            numberOfPlanes;                                    ///< Number of Planes
    UINT32            reserved;                                          ///< Reserved
    UINT32            numberOfStripes[CSLOPEMaxPlanes];                  ///< Number of Stripes
    UINT32            hMemHandle[CSLOPEMaxPlanes];                       ///< Memory Handles of Input/Output Ports
    UINT32            planeOffset[CSLOPEMaxPlanes];                      ///< Plane Offset
    UINT32            length[CSLOPEMaxPlanes];                           ///< size of Planes
    UINT32            planeStride[CSLOPEMaxPlanes];                      ///< stride in bytes
    UINT32            height[CSLOPEMaxPlanes];                           ///< height in lines
    UINT32            format;                                            ///< Format of the image
    CSLFence          hFence;                                            ///< Fence of the buffer
    CSLOPEStripeInfo  stripesInfo[CSLOPEMaxPlanes][CSLOPEMaxStripes];    ///< Info related to Stripes
} CAMX_PACKED;

struct CSLOPEFrameSet
{
    UINT32             numberOfIOBuffers;                           ///< Number of IO Buffers
    UINT32             reserved;                                    ///< Reserved
    CSLOPEIOBufferInfo ioBuffers[CSLOPEMaxIOBuffers];               ///< Info related to IO Buffers
} CAMX_PACKED;

struct CSLOPECMDBufferInfo
{
    UINT32 hMemHandle;                                ///< Handle to buffer memory
    UINT32 offset;                                    ///< Offset of buffer
    UINT32 size;                                      ///< Size of buffer
    UINT32 length;                                    ///< Length of buffer
    UINT32 cmdBufferScope;                            ///< Scope of buffer
    UINT32 cmdBufferType;                             ///< Buffer Type
    UINT32 cmdBufferUsage;                            ///< Buffer Usage
    UINT32 cmdBufferTypeBuffered;                     ///< Indicates how buffer is buffered
    UINT32 cmdBufferStripeIdx;                        ///< Stripe Idx
    UINT32 cmdBufferPassIdx;                          ///< Pass Idx
    UINT32 prefetchDisable;                           ///< Prefetch Disable flag
} CAMX_PACKED;

struct CSLOPEFrameProcess
{
    UINT32               numberOfCMDBuffers[CSLOPEMaxBatchSize];                 ///< Number of CMD buffers
    UINT32               batchSize;                                              ///< Size of batch
    CSLOPECMDBufferInfo  cmdBuffers[CSLOPEMaxBatchSize][CSLOPEMaxCMDBuffers];    ///< Info related to CMD buffers
    CSLOPEFrameSet       frameSets[CSLOPEMaxBatchSize];                          ///< Infor related to frame Sets
} CAMX_PACKED;

/// @brief OPE hardware version information
struct CSLOPEDeviceVersion
{
    UINT32      deviceType; ///< Device type for the cap info(CSLOPEDeviceType)
    UINT32      reserved;   ///< Reserved field to force size as a multiple of 64bits
    CSLVersion  version;    ///< Device version
} CAMX_PACKED;

/// @brief OPE Output resource characteristics information
struct CSLOPEOutResourceInfo
{
    UINT32      portId;             ///< Port ID
    UINT32      format;             ///< Image format
    UINT32      width;              ///< Image width
    UINT32      height;             ///< Image height
    UINT32      alignment;          ///< Image alignment base
    UINT32      packerFormat;       ///< Format of Packer
    UINT32      subSamplePeriod;    ///< based on nstripes/batch this will be programmed by KMD
    UINT32      subSamplePattern;   ///< based on nstripes/batch this will be programmed by KMD
    UINT32      pixelPattern;       ///< Pixel Pattern
    UINT32      reserved;           ///< Reserved
} CAMX_PACKED;

/// @brief ICP Input resource characteristics information
struct CSLOPEInResourceInfo
{
    UINT32      portId;           ///< Port ID
    UINT32      format;           ///< Image format
    UINT32      width;            ///< Image width
    UINT32      height;           ///< Image height
    UINT32      pixelPattern;     ///< Pixel Pattern
    UINT32      alignment;        ///< Image Alignment base
    UINT32      unpackerFormat;   ///< Format of Unpacker
    UINT32      maxStripeSize;    ///< Maximum Stripe Size
    UINT32      FPS;              ///< FPS
    UINT32      reserved;         ///< Reserved
} CAMX_PACKED;

/// @brief OPE acquire device information
struct CSLOPEAcquireDeviceInfo
{
    UINT32                hwType;                          ///< Type of Hardware
    UINT32                devType;                         ///< Type of Device
    CHAR                  deviceName[128];                 ///< Name of Device
    UINT32                nrtStripesInCDM;                 ///< NRT stripes in CDM
    UINT32                secureMode;                      ///< Secure Mode
    UINT32                batchSize;                       ///< Size of Batch
    UINT32                numberOfInputResources;          ///< Count of Input Resources
    CSLOPEInResourceInfo  inputResources[OPEInputMax];     ///< Information of Input Resources
    UINT32                numberOfOutputResources;         ///< Count of Output Resources
    UINT32                reserved;                        ///< Reserved Bits
    CSLOPEOutResourceInfo outputResources[OPEOutputMax];   ///< Information of Output Resources
} CAMX_PACKED;

/// @brief OPE clock and bandwidth request
struct CSLOPEClockBandwidthRequest
{
    UINT64               budgetNS;               ///< Maximum duration to process a frame in Nano Seconds
    UINT32               frameCycles;            ///< FrameCycles Info
    UINT32               realtimeFlag;           ///< Flag for Realtime stream
    UINT32               reserved;               ///< Reserved
    UINT32               numPaths;               ///< Number of paths
    CSLAXIperPathBWVote  axiPath[1];             ///< Per path axi vote info
} CAMX_PACKED;

CAMX_END_PACKED
#endif // CAMXCSLOPEDEFS_H
