/*************************************************************************/ /*!
@File
@Title          HWPerf counter table header

@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description    Utility functions used internally for HWPerf data retrieval
@License        Dual MIT/GPLv2

The contents of this file are subject to the MIT license as set out below.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 ("GPL") in which case the provisions
of GPL are applicable instead of those above.

If you wish to allow use of your version of this file only under the terms of
GPL, and not to allow others to use your version of this file under the terms
of the MIT license, indicate your decision by deleting the provisions above
and replace them with the notice and other provisions required by GPL as set
out in the file called "GPL-COPYING" included in this distribution. If you do
not delete the provisions above, a recipient may use your version of this file
under the terms of either the MIT license or GPL.

This License is also included in this distribution in the file called
"MIT-COPYING".

EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ /**************************************************************************/

#if !defined (__RGX_HWPERF_TABLE_H__)
#define __RGX_HWPERF_TABLE_H__

#include "img_types.h"
#include "rgx_fwif_hwperf.h"


/*****************************************************************************/

/* Forward declaration */
typedef struct _RGXFW_HWPERF_CNTBLK_TYPE_MODEL_ RGXFW_HWPERF_CNTBLK_TYPE_MODEL;

/* Function pointer type for functions to check dynamic power state of
 * counter block instance. Used only in firmware. */
typedef IMG_BOOL (*PFN_RGXFW_HWPERF_CNTBLK_POWERED)(
		RGX_HWPERF_CNTBLK_ID eBlkType,
		IMG_UINT8 ui8UnitId);

/* Counter block run-time info */
typedef struct _RGX_HWPERF_CNTBLK_RT_INFO_
{
	IMG_UINT32 uiNumUnits;              /* Number of instances of this block type in the core */
} RGX_HWPERF_CNTBLK_RT_INFO;

/* Function pointer type for functions to check block is valid and present
 * on that RGX Device at runtime. It may have compile logic or run-time
 * logic depending on where the code executes: server, srvinit or firmware.
 * Values in the psRtInfo output parameter are only valid if true returned. */
typedef IMG_BOOL (*PFN_RGXFW_HWPERF_CNTBLK_PRESENT)(
		const struct _RGXFW_HWPERF_CNTBLK_TYPE_MODEL_* psBlkTypeDesc,
		void *pvDev_km,
		RGX_HWPERF_CNTBLK_RT_INFO *psRtInfo);

/* This structure encodes properties of a type of performance counter block.
 * The structure is sometimes referred to as a block type descriptor. These
 * properties contained in this structure represent the columns in the
 * block type model table variable below. There values vary depending on
 * the build BVNC and core type.
 * Each direct block has a unique type descriptor and each indirect group has
 * a type descriptor. */
struct _RGXFW_HWPERF_CNTBLK_TYPE_MODEL_
{
	/* Could use RGXFW_ALIGN_DCACHEL here but then we would waste 40% of the cache line? */
	IMG_UINT32 uiCntBlkIdBase;         /* The starting block id for this block type */
	IMG_UINT32 uiIndirectReg;          /* 0 if direct type otherwise the indirect control register to select indirect unit */
	IMG_UINT32 uiPerfReg;              /* RGX_CR_*_PERF register for this block type */
	IMG_UINT32 uiSelect0BaseReg;       /* RGX_CR_*_PERF_SELECT0 register for this block type */
	IMG_UINT32 uiCounter0BaseReg;      /* RGX_CR_*_PERF_COUNTER_0 register for this block type */
	IMG_UINT8  uiNumCounters;          /* Number of counters in this block type */
	IMG_UINT8  uiNumUnits;             /* Number of instances of this block type in the core */
	IMG_UINT8  uiSelectRegModeShift;   /* Mode field shift value of select registers */
	IMG_UINT8  uiSelectRegOffsetShift; /* Interval between select registers, either 8 bytes or 16, hence << 3 or << 4 */
	IMG_CHAR   pszBlockNameComment[30];              /* Name of the PERF register. Used while dumping the perf counters to pdumps */
	PFN_RGXFW_HWPERF_CNTBLK_POWERED pfnIsBlkPowered; /* A function to determine dynamic power state for the block type */
	PFN_RGXFW_HWPERF_CNTBLK_PRESENT pfnIsBlkPresent; /* A function to determine presence on RGX Device at run-time */
};

/*****************************************************************************/

IMG_INTERNAL IMG_UINT32 RGXGetHWPerfBlockConfig(const RGXFW_HWPERF_CNTBLK_TYPE_MODEL **ppsModel);


#endif /*  __RGX_HWPERF_TABLE_H__ */

/******************************************************************************
 End of file (rgx_hwperf_table.h)
******************************************************************************/
