/* 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.
 *
 *****************************************************************************/
#ifndef __X_UTIL_H__
#define __X_UTIL_H__

#include "x_typedef.h"

typedef enum {
    eNO_TYPE,
    eRD_ONLY,
    eWR_ONLY,
    eRD_WR
} REGTYPE;

typedef struct strucRegTest {
    UINT32     u4Addr;		// the register offset
    REGTYPE    eRegType;
    INT32      iRegLen;		// 1, 2, or 4; number of byte
	UINT32     u4Mask;		// the valid bit mask
	INT32      fgWDfV;		// set 0 if without reset value.
	UINT32     u4DfVal;		// the reset value.
} REG_TEST_T;


/* Log export function. */
extern INT32 UTIL_LogThreadInit(void);
extern INT32 UTIL_Log(const CHAR *szFmt, ...);
extern void UTIL_LogFlush(void);

/* Cli util functions. */
extern INT32 UTIL_MemOrder(UINT32 u4Addr, UINT32 u4ByteUnit, UINT32 u4Len, UINT32 u4Step);
extern INT32 UTIL_MemCmp(UINT32 u4Addr1, UINT32 u4Addr2, UINT32 u4Len);

/* Reg test functions. */
INT32 UTIL_AllSpaceRWTest(UINT32 u4BaseAddr, UINT32 u4Length);
INT32 UTIL_RegDefChk(UINT32 u4BaseAddr, REG_TEST_T *psrgtRegList);
INT32 UTIL_RegRWTest(UINT32 u4BaseAddr, REG_TEST_T *psrgtRegList);

/*
 * Do u8Dividend / u8Divider.
 * u8Divider value should be < max 32 bit integer number.
 * If pu8Remainder is not NULL, remainder will be returned.
 * The function returns quotient.
 */
extern UINT64 u8Div6432(UINT64 u8Dividend, UINT64 u8Divider, UINT64 *pu8Remainder);

#endif /* __X_UTIL_H__ */
