/* 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: brianpc.huang $
 * $Date: 2015/05/29 $
 * $RCSfile: osd_debug.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file osd_debug.h
 *  This header file declares debug macro
 */

#ifndef OSD_DEBUG_H
#define OSD_DEBUG_H

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

#ifdef CC_MTK_LOADER
#define DEFINE_IS_LOG(level, fmt...) Printf(fmt)
#else /* CC_MTK_LOADER */
#define DEFINE_IS_LOG OSD_IsLog
#endif /* CC_MTK_LOADER */
#include "x_debug.h"

EXTERN UINT32 osd_log_level;
#define OSD_LOG(level, format...) \
    do \
    { \
        if (level <= osd_log_level) { \
            LOG(0, "[OSD]%s: ",__FUNCTION__); \
            LOG(0, format); \
        }\
    } while (0)

#define OSD_LOG_E(format...) OSD_LOG(OSD_LL_ERROR, format)
#define OSD_LOG_W(format...) OSD_LOG(OSD_LL_WARNING, format)
#define OSD_LOG_I(format...) OSD_LOG(OSD_LL_INFO, format)
#define OSD_LOG_D(format...) OSD_LOG(OSD_LL_DEBUG, format)
#define OSD_LOG_V(format...) OSD_LOG(OSD_LL_VERBOSE, format)

//#define OSD_CLI_LOG(format...) DEFINE_IS_LOG(0, format)

#if !defined(CC_MTK_LOADER) && defined(LINUX_TURNKEY_SOLUTION) && !defined(__USERDRV__)
#include <linux/sched.h>
#define OSD_DUMP_LOG(format...) \
    do \
    { \
        LOG(0, "[OSD pid:%d comm:%s]%s: ", current->pid, current->comm, __FUNCTION__); \
        LOG(0, format); \
    } while(0)
#define OSD_Dump_Stack() \
    do \
    { \
        if (OSD_LL_VERBOSE <= osd_log_level) { \
            LOG(0, "[OSD]"); \
            dump_stack(); \
        }\
    } while (0)
#else
#define OSD_DUMP_LOG(format...)
#define OSD_Dump_Stack()
#endif

#endif //OSD_DEBUG_H
