// SPDX-License-Identifier: GPL-2.0
/* Copyright Statement:
*
* This software/firmware and related documentation ("MediaTek Software") are
* protected under relevant copyright laws. The information contained herein
* is confidential and proprietary to MediaTek Inc. and/or its licensors.
* Without the prior written permission of MediaTek inc. and/or its licensors,
* any reproduction, modification, use or disclosure of MediaTek Software,
* and information contained herein, in whole or in part, shall be strictly prohibited.
*/
/* MediaTek Inc. (C) 2016. All rights reserved.
*
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
* THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
* CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
* SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
* CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*/

#ifndef _SYSTRACKER_H_
#define _SYSTRACKER_H_

#define BUS_DBG_NUM_TRACKER         (8)

#define BUS_DBG_BASE                 (0x10208000)
#define BUS_DBG_CON                 (BUS_DBG_BASE + 0x0000)
#define BUS_DBG_AR_TRACK_L(__n)     (BUS_DBG_BASE + 0x0100 + 8 * (__n))
#define BUS_DBG_AR_TRACK_H(__n)     (BUS_DBG_BASE + 0x0104 + 8 * (__n))
#define BUS_DBG_AW_TRACK_L(__n)     (BUS_DBG_BASE + 0x0200 + 8 * (__n))
#define BUS_DBG_AW_TRACK_H(__n)     (BUS_DBG_BASE + 0x0204 + 8 * (__n))


#define BUS_DBG_CON_IRQ_AR_STA0     (0x00000100)
#define BUS_DBG_CON_IRQ_AW_STA0     (0x00000200)
#define BUS_DBG_CON_IRQ_AR_STA1     (0x00100000)
#define BUS_DBG_CON_IRQ_AW_STA1     (0x00200000)
#define BUS_DBG_CON_TIMEOUT         (BUS_DBG_CON_IRQ_AR_STA0|BUS_DBG_CON_IRQ_AW_STA0| \
                                    BUS_DBG_CON_IRQ_AR_STA1|BUS_DBG_CON_IRQ_AW_STA1)

/* a 2KB buffer is sufficient for systracker */
#define SYSTRACKER_BUF_LENGTH   2000
/*
///FIXME: found function body in C header. Please move to the source file.
static inline unsigned int extract_n2mbits(unsigned int input, unsigned int n, unsigned int m)
{
*/
    /*
    * 1. ~0 = 1111 1111 1111 1111 1111 1111 1111 1111
    * 2. ~0 << (m - n + 1) = 1111 1111 1111 1111 1100 0000 0000 0000
    * // assuming we are extracting 14 bits, the +1 is added for inclusive selection
    * 3. ~(~0 << (m - n + 1)) = 0000 0000 0000 0000 0011 1111 1111 1111
    */
/*
    int mask;

    if (n > m) {
        n = n + m;
        m = n - m;
        n = n - m;
    }
    mask = ~(~0 << (m - n + 1));
    return (input >> n) & mask;
}
*/
int systracker_get(void **data, int *len, unsigned int entry_num);
void systracker_put(void **data);

#endif
