/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: xiaojun.zhu $
 * $Date: 2015/08/08 $
 * $RCSfile: fbm_pool.h,v $
 * $Revision: #3 $
 *
 *---------------------------------------------------------------------------*/

/** @file sample.h
 *  Brief of file sample.h.
 *  Details of file sample.h (optional).
 */

#ifndef FBM_POOL_H
#define FBM_POOL_H


//---------------------------------------------------------------------------
// Include files
//---------------------------------------------------------------------------

#include "fbm_fb.h"
#include "x_typedef.h"


//---------------------------------------------------------------------------
// Configurations
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Constant definitions
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Type definitions
//---------------------------------------------------------------------------

/** Brief of RESIDUAL_POOL_T
 *  Residual Frame Buffer Pool
 */
typedef struct
{
    UINT32            u4PoolIdx;
    UPTR            u4FbMemoryPool;
    UINT32            u4FbMemoryPoolSize;

    UCHAR            aucFbStatusY[FBM_MAX_FB_NS_PER_GROUP];
    UCHAR            aucFbStatusC[FBM_MAX_FB_NS_PER_GROUP];

    UPTR            au4AddrY[FBM_MAX_FB_NS_PER_GROUP];
    UPTR            au4AddrC[FBM_MAX_FB_NS_PER_GROUP];
} RESIDUAL_POOL_T;

/** Brief of FBP_LIST_T
 *  MPEG Frame Buffer Pool Type List
 */
typedef struct
{
    UCHAR ucType;
    UINT32 u4Size; /* Total size */
    UINT32 u4CTotalSize;/* Total C size ,and total Y+Mv size = total size - total c size */
    UINT32 u4YSize;
    UINT32 u4CSize;
    UINT32 u4Width;
    UINT32 u4Height;
} FBP_LIST_T;


/** Brief of POOL_LIST_T
 *  Frame Buffer Memory Pool Type List
 */
typedef struct
{
    CHAR* szName;
    FBM_POOL_TYPE_T eType;
    UINT32 u4AddrAlign;
    UINT32 u4SizeAlign;
    UINT32 u4Mode;
    UINT32 u4PoolSize;
    UINT32 u4Width;
    UINT32 u4Height;
    UINT32 u4Inherit;
} POOL_LIST_T;

// Frame Buffer Pool arrangement type
typedef enum
{
    FBM_POOL_ARRANGE_AFTER,             // pool arrange after ePool1, need to specify pool size
    FBM_POOL_ARRANGE_BEFORE,            // pool arrange before ePool1, need to specify pool size
    FBM_POOL_ARRANGE_BETWEEN,           // pool arrange after ePool1 & before ePool2, no need to specify pool size
    FBM_POOL_ARRANGE_SHARE,             // pool arrange from ePool1 start address plus offset, need to specify pool size
    FBM_POOL_ARRANGE_ALLIGN_END,         // pool allign with  ePool1  end address no need to specify pool size
    FBM_POOL_ARRANGE_SHARE_ALL          // no need to specify pool size (1) pool arrange form ePool 1 start address plus offset to end of ePool 1, (2) pool arrange form ePool 2 start address to end of ePool 1
} POOL_ARRANGE_TYPE_T;

// Frame Buffer Pool arrangement info
typedef struct
{
    POOL_ARRANGE_TYPE_T eMode;
    FBM_POOL_TYPE_T ePool1;
    FBM_POOL_TYPE_T ePool2;
    UINT8 u1Ready;
    UINT32 u4Offset;
} POOL_ARRANGE_INFO_T;

typedef struct
{
    UINT32  u4FbMemoryPool;
    UINT32  u4FbMemoryPoolC;
    UINT32  u4MpegTotalYSize;
    UINT32  u4MpegTotalCSize;
    BOOL fgUseDynBuf;
} MPEG_POOL_INFO_T;

//---------------------------------------------------------------------------
// Macro definitions
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// Inter-file functions
//---------------------------------------------------------------------------

EXTERN FBM_POOL_T* _FBM_PoolInit(VOID);

EXTERN VOID _FBM_GetPoolList(FBP_LIST_T** pprFbpList, UCHAR* pucFbpNs);

EXTERN UINT32 _FBM_PoolAllocate(MPEG_POOL_INFO_T *prMpegPoolInfo);
EXTERN VOID _FBM_PoolRelease(UPTR u4FbMemoryPool);

EXTERN VOID _FBM_PoolStatus(VOID);

EXTERN VOID FBM_ConfigurePool(POOL_LIST_T* prPoolList, POOL_ARRANGE_INFO_T* prPoolArrangeInfo);

EXTERN FBM_POOL_T* FBM_GetPoolInfoAuto(UCHAR ucPoolType, const FBM_POOL_MODULE_INFO_T* pInfo);
EXTERN UINT32 FBM_GetPanelModel(VOID);
EXTERN VOID FBM_PrintPoolInfo(FBM_POOL_T* prPool, POOL_LIST_T* prPoolList);

//---------------------------------------------------------------------------
// Public functions
//---------------------------------------------------------------------------


#endif  // FBM_POOL_H

