RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / rgx_hwperf_km.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          RGX HWPerf Types and Defines Header
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Common data types definitions for hardware performance API
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43 #ifndef RGX_HWPERF_KM_H_
44 #define RGX_HWPERF_KM_H_
45
46 /* 
47  * This header file holds the HWPerf related macros and types needed by the
48  * code in the Kernel Mode (KM) server/driver module and its content is
49  * intended to be suitable for distribution under a public software license.
50  * The definitions within are common and may be used in user-mode, kernel-mode
51  * and firmware compilation units.
52  */
53
54 #if defined (__cplusplus)
55 extern "C" {
56 #endif
57
58 #define RGX_HWPERF_V2_FORMAT 2
59
60 #include "rgx_common.h"
61 #include "pvrsrv_tlcommon.h"
62 #include <powervr/sync_external.h>
63
64 /* HWPerf host buffer size constraints in KBs */
65 #define HWPERF_HOST_TL_STREAM_SIZE_DEFAULT (128U)
66 #define HWPERF_HOST_TL_STREAM_SIZE_MIN     (32U)
67 #define HWPERF_HOST_TL_STREAM_SIZE_MAX     (1024U)
68
69 /*! The number of indirectly addressable TPU_MSC blocks in the GPU */
70 #define RGX_HWPERF_PHANTOM_INDIRECT_BY_DUST MAX((RGX_FEATURE_NUM_CLUSTERS>>1),1)
71
72 /*! The number of indirectly addressable USC blocks in the GPU */
73 #define RGX_HWPERF_PHANTOM_INDIRECT_BY_CLUSTER (RGX_FEATURE_NUM_CLUSTERS)
74
75 #if defined(RGX_FEATURE_S7_TOP_INFRASTRUCTURE)
76
77  /*! Defines the number of performance counter blocks that are directly
78   * addressable in the RGX register map. */
79  #define RGX_HWPERF_MAX_DIRECT_ADDR_BLKS 1 /* JONES */
80  #define RGX_HWPERF_INDIRECT_BY_PHANTOM (RGX_NUM_PHANTOMS)
81  #define RGX_HWPERF_PHANTOM_NONDUST_BLKS 1 /* BLACKPEARL */
82  #define RGX_HWPERF_PHANTOM_DUST_BLKS 2 /* TPU, TEXAS */
83  #define RGX_HWPERF_PHANTOM_DUST_CLUSTER_BLKS 2 /* USC, PBE */
84  #define RGX_HWPERF_DOPPLER_BX_TU_BLKS  0 /* No doppler unit */
85  #define RGX_HWPERF_MAX_OTHER_INDIRECT_BLKS 0 /* some indirect blocks have fixed instances in a core */
86
87 #elif defined(RGX_FEATURE_XT_TOP_INFRASTRUCTURE)
88
89  #if defined(RGX_FEATURE_RAY_TRACING)
90   /*! Defines the number of performance counter blocks that are directly
91    * addressable in the RGX register map. */
92   #define RGX_HWPERF_MAX_DIRECT_ADDR_BLKS 6 /* TORNADO, TA, BF, BT, RT, SH */
93   #define RGX_HWPERF_DOPPLER_BX_TU_BLKS 4 /* Doppler unit unconditionally has 4 instances of BX_TU */
94   #define RGX_HWPERF_MAX_OTHER_INDIRECT_BLKS RGX_HWPERF_DOPPLER_BX_TU_BLKS
95  #else /*#if defined(RAY_TRACING) */
96   /*! Defines the number of performance counter blocks that are directly
97    * addressable in the RGX register map. */
98   #define RGX_HWPERF_MAX_DIRECT_ADDR_BLKS 2 /* TORNADO, TA */
99   #define RGX_HWPERF_DOPPLER_BX_TU_BLKS 0 /* No doppler unit */
100   #define RGX_HWPERF_MAX_OTHER_INDIRECT_BLKS 0
101  #endif /*#if defined(RAY_TRACING) */
102
103  #define RGX_HWPERF_INDIRECT_BY_PHANTOM (RGX_NUM_PHANTOMS)
104  #define RGX_HWPERF_PHANTOM_NONDUST_BLKS 2 /* RASTER, TEXAS */
105  #define RGX_HWPERF_PHANTOM_DUST_BLKS 1 /* TPU */
106  #define RGX_HWPERF_PHANTOM_DUST_CLUSTER_BLKS 1 /* USC */
107
108 #else   /* if defined(RGX_FEATURE_S7_TOP_INFRASTRUCTURE) */
109
110  /*! Defines the number of performance counter blocks that are directly
111   * addressable in the RGX register map. */
112  #define RGX_HWPERF_MAX_DIRECT_ADDR_BLKS 3 /* TA, RASTER, HUB */
113  #define RGX_HWPERF_INDIRECT_BY_PHANTOM 0  /* PHANTOM is not there is Rogue1. Just using it to keep naming same as later series (RogueXT n Rogue XT+) */
114  #define RGX_HWPERF_PHANTOM_NONDUST_BLKS 0
115  #define RGX_HWPERF_PHANTOM_DUST_BLKS 1 /* TPU */
116  #define RGX_HWPERF_PHANTOM_DUST_CLUSTER_BLKS 1 /* USC */
117 #define RGX_HWPERF_DOPPLER_BX_TU_BLKS   0 /* No doppler unit */
118  #define RGX_HWPERF_MAX_OTHER_INDIRECT_BLKS 0
119
120 #endif
121
122 /*! The number of indirect addressable layout blocks in the GPU with performance counters */
123 #define RGX_HWPERF_MAX_INDIRECT_ADDR_BLKS       (RGX_HWPERF_PHANTOM_DUST_BLKS * RGX_HWPERF_PHANTOM_INDIRECT_BY_DUST +\
124                                                                                         RGX_HWPERF_PHANTOM_DUST_CLUSTER_BLKS * RGX_HWPERF_PHANTOM_INDIRECT_BY_CLUSTER +\
125                                                                                         RGX_HWPERF_PHANTOM_NONDUST_BLKS      * RGX_HWPERF_INDIRECT_BY_PHANTOM +\
126                                                                                         RGX_HWPERF_MAX_OTHER_INDIRECT_BLKS)
127
128 /*! The number of custom non-mux counter blocks supported */
129 #define RGX_HWPERF_MAX_CUSTOM_BLKS 5
130
131 /*! The number of counters supported in each non-mux counter block */
132 #define RGX_HWPERF_MAX_CUSTOM_CNTRS 8
133
134 /******************************************************************************
135  *      Data Stream Common Types
136  *****************************************************************************/
137
138 /* These structures are used on both GPU and CPU and must be a size that is a
139  * multiple of 64 bits, 8 bytes to allow the FW to write 8 byte quantities
140  * at 8 byte aligned addresses.  RGX_FW_STRUCT_*_ASSERT() is used to check this.
141  */
142  
143 /*! Type used to encode the event that generated the HW performance packet.
144  * NOTE: When this type is updated the corresponding hwperfbin2json tool source
145  * needs to be updated as well. The RGX_HWPERF_EVENT_MASK_* macros will also need
146  * updating when adding new types.
147  */
148 typedef enum
149 {
150         RGX_HWPERF_INVALID                              = 0x00,
151
152         /* FW types 0x01..0x06 */
153         RGX_HWPERF_FW_EVENT_RANGE_FIRST_TYPE    = 0x01,
154
155         RGX_HWPERF_FW_BGSTART                   = 0x01,
156         RGX_HWPERF_FW_BGEND                             = 0x02,
157         RGX_HWPERF_FW_IRQSTART                  = 0x03,
158
159         RGX_HWPERF_FW_IRQEND                    = 0x04,
160         RGX_HWPERF_FW_DBGSTART                  = 0x05,
161         RGX_HWPERF_FW_DBGEND                    = 0x06,
162
163         RGX_HWPERF_FW_EVENT_RANGE_LAST_TYPE             = 0x06,
164
165         /* HW types 0x07..0x19 */
166         RGX_HWPERF_HW_EVENT_RANGE0_FIRST_TYPE   = 0x07,
167
168         RGX_HWPERF_HW_PMOOM_TAPAUSE             = 0x07,
169         RGX_HWPERF_HW_TAKICK                    = 0x08,
170 /*      RGX_HWPERF_HW_PMOOM_TAPAUSE             = 0x07, */
171 /*      RGX_HWPERF_HW_PMOOM_TARESUME    = 0x19, */
172         RGX_HWPERF_HW_TAFINISHED                = 0x09,
173         RGX_HWPERF_HW_3DTQKICK                  = 0x0A,
174 /*      RGX_HWPERF_HW_3DTQFINISHED              = 0x17, */
175 /*      RGX_HWPERF_HW_3DSPMKICK                 = 0x11, */
176 /*      RGX_HWPERF_HW_3DSPMFINISHED             = 0x18, */
177         RGX_HWPERF_HW_3DKICK                    = 0x0B,
178         RGX_HWPERF_HW_3DFINISHED                = 0x0C,
179         RGX_HWPERF_HW_CDMKICK                   = 0x0D,
180         RGX_HWPERF_HW_CDMFINISHED               = 0x0E,
181         RGX_HWPERF_HW_TLAKICK                   = 0x0F,
182         RGX_HWPERF_HW_TLAFINISHED               = 0x10,
183         RGX_HWPERF_HW_3DSPMKICK                 = 0x11,
184         RGX_HWPERF_HW_PERIODIC                  = 0x12,
185         RGX_HWPERF_HW_RTUKICK                   = 0x13,
186         RGX_HWPERF_HW_RTUFINISHED               = 0x14,
187         RGX_HWPERF_HW_SHGKICK                   = 0x15,
188         RGX_HWPERF_HW_SHGFINISHED               = 0x16,
189         RGX_HWPERF_HW_3DTQFINISHED              = 0x17,
190         RGX_HWPERF_HW_3DSPMFINISHED             = 0x18,
191         RGX_HWPERF_HW_PMOOM_TARESUME    = 0x19,
192
193         /* HW_EVENT_RANGE0 used up. Use next empty range below to add new hardware events */
194         RGX_HWPERF_HW_EVENT_RANGE0_LAST_TYPE    = 0x19,
195
196         /* other types 0x1A..0x1F */
197         RGX_HWPERF_CLKS_CHG                             = 0x1A,
198         RGX_HWPERF_GPU_STATE_CHG                = 0x1B,
199
200         /* power types 0x20..0x27 */
201         RGX_HWPERF_PWR_EST_RANGE_FIRST_TYPE     = 0x20,
202         RGX_HWPERF_PWR_EST_REQUEST              = 0x20,
203         RGX_HWPERF_PWR_EST_READY                = 0x21,
204         RGX_HWPERF_PWR_EST_RESULT               = 0x22,
205         RGX_HWPERF_PWR_EST_RANGE_LAST_TYPE      = 0x22,
206
207         RGX_HWPERF_PWR_CHG                              = 0x23,
208
209         /* HW_EVENT_RANGE1 0x28..0x2F, for accommodating new hardware events */
210         RGX_HWPERF_HW_EVENT_RANGE1_FIRST_TYPE   = 0x28,
211
212         RGX_HWPERF_HW_TDMKICK                   = 0x28,
213         RGX_HWPERF_HW_TDMFINISHED               = 0x29,
214
215         RGX_HWPERF_HW_EVENT_RANGE1_LAST_TYPE = 0x29,
216
217         /* context switch types 0x30..0x31 */
218         RGX_HWPERF_CSW_START                    = 0x30,
219         RGX_HWPERF_CSW_FINISHED                 = 0x31,
220
221         /* firmware misc 0x38..0x39 */
222         RGX_HWPERF_UFO                                  = 0x38,
223         RGX_HWPERF_FWACT                                = 0x39,
224
225         /* last */
226         RGX_HWPERF_LAST_TYPE,
227
228         /* This enumeration must have a value that is a power of two as it is
229          * used in masks and a filter bit field (currently 64 bits long).
230          */
231         RGX_HWPERF_MAX_TYPE                             = 0x40
232 } RGX_HWPERF_EVENT_TYPE;
233
234 /* Macro used to check if an event type ID is present in the known set of hardware type events */
235 #define HWPERF_PACKET_IS_HW_TYPE(_etype)        (((_etype) >= RGX_HWPERF_HW_EVENT_RANGE0_FIRST_TYPE && (_etype) <= RGX_HWPERF_HW_EVENT_RANGE0_LAST_TYPE) || \
236                                                                                          ((_etype) >= RGX_HWPERF_HW_EVENT_RANGE1_FIRST_TYPE && (_etype) <= RGX_HWPERF_HW_EVENT_RANGE1_LAST_TYPE))
237
238 #define HWPERF_PACKET_IS_FW_TYPE(_etype)                                        \
239         ((_etype) >= RGX_HWPERF_FW_EVENT_RANGE_FIRST_TYPE &&    \
240          (_etype) <= RGX_HWPERF_FW_EVENT_RANGE_LAST_TYPE)
241
242 typedef enum {
243         RGX_HWPERF_HOST_INVALID        = 0x00,
244         RGX_HWPERF_HOST_ENQ            = 0x01,
245         RGX_HWPERF_HOST_UFO            = 0x02,
246         RGX_HWPERF_HOST_ALLOC          = 0x03,
247         RGX_HWPERF_HOST_CLK_SYNC       = 0x04,
248         RGX_HWPERF_HOST_FREE           = 0x05,
249
250         /* last */
251         RGX_HWPERF_HOST_LAST_TYPE,
252
253         /* event used as a control layer for HWPerf */
254         RGX_HWPERF_HOST_CTRL           = 0x1f,
255
256         /* This enumeration must have a value that is a power of two as it is
257          * used in masks and a filter bit field (currently 32 bits long).
258          */
259         RGX_HWPERF_HOST_MAX_TYPE       = 0x20
260 } RGX_HWPERF_HOST_EVENT_TYPE;
261
262 /* The event type values are incrementing integers for use as a shift ordinal
263  * in the event filtering process at the point events are generated.
264  * This scheme thus implies a limit of 63 event types.
265  */
266 static_assert(RGX_HWPERF_LAST_TYPE < RGX_HWPERF_MAX_TYPE, "Too many HWPerf event types");
267
268 /******************************************************************************
269  *      Packet Format Version 2 Types
270  *****************************************************************************/
271
272 /*! Signature ASCII pattern 'HWP2' found in the first word of a HWPerfV2 packet
273  */
274 #define HWPERF_PACKET_V2_SIG            0x48575032
275 /*! Signature ASCII pattern 'HWPA' found in the first word of a HWPerfV2a packet
276  */
277 #define HWPERF_PACKET_V2A_SIG           0x48575041
278
279 /*! Signature ASCII pattern 'HWPB' found in the first word of a HWPerfV2b packet
280  */
281 #define HWPERF_PACKET_V2B_SIG           0x48575042
282
283 #define HWPERF_PACKET_ISVALID(_ptr) (((_ptr) == HWPERF_PACKET_V2_SIG) || ((_ptr) == HWPERF_PACKET_V2A_SIG)|| ((_ptr) == HWPERF_PACKET_V2B_SIG))
284
285 /*! This structure defines version 2 of the packet format which is
286  * based around a header and a variable length data payload structure.
287  * The address of the next packet can be found by adding the ui16Size field
288  * in the header to the current packet address.
289  * Producers of packets must always ensure the size field is a multiple of 8
290  * as packets must start on an 8-byte granular address.
291  */
292 typedef struct
293 {
294         /* HEADER - packet header fields common to all packet types */
295         IMG_UINT32  ui32Sig;        /*!< Always the value HWPERF_PACKET_SIG */
296
297         IMG_UINT32  ui32Size;       /*!< Overall packet size in bytes, includes
298                                      * header and payload. Size is a 16-bit field
299                                      * stored in the 16 LSb. 16 MSb reserved.
300                                      * Use RGX_HWPERF_MAKE_SIZE_* and RGX_HWPERF_GET_SIZE
301                                      * macros to set/get, never write directly. */
302
303         IMG_UINT32  eTypeId;        /*!< Fields layout as shown: 
304                                                                  * |<--------------------------32-bits----------------------------->|
305                                                                  * |<---8---->|<----5----->|<----3----->|<---1---->|<------15------>|
306                                                                  * |   OSID   |  RESERVED  |  STREAM-ID | META TID |    EventType   |
307                                                                  *
308                                                                  * NOTE- It seems 3-bits (total 8 OSIDs) are enough for OSID field above?
309                                                                  * In case some bits are in future, perhaps 5 MS bits can be borrowed.
310                                                                  *
311                                      * Use RGX_HWPERF_MAKE_TYPEID and RGX_HWPERF_GET_*
312                                      * macros to set/get, never write directly. */
313
314         IMG_UINT32  ui32Ordinal;    /*!< Sequential number of the packet */
315         IMG_UINT64  ui64Timestamp;   /*!< Depending on the side that packet originated
316                                       * may be either CPU timestamp or value of RGX_CR_TIMER
317                                       * at event. */
318
319         /* PAYLOAD - bytes from this point on in the buffer are from the
320          * RGX_PHWPERF_V2_PACKET_DATA union which encodes the payload data specific
321          * to the event type set in the header. When the structure in the union
322          * has a variable length member e.g. HW packets, the payload length
323          * varies and ui32Size in the header defines the end of the payload data.
324          */
325 } RGX_HWPERF_V2_PACKET_HDR, *RGX_PHWPERF_V2_PACKET_HDR;
326
327 RGX_FW_STRUCT_OFFSET_ASSERT(RGX_HWPERF_V2_PACKET_HDR, ui64Timestamp);
328
329 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_V2_PACKET_HDR);
330
331
332 /*! Mask for use with the IMG_UINT32 ui32Size header field */
333 #define RGX_HWPERF_SIZE_MASK         0xFFFFU
334
335 /*! This macro defines an upper limit to which the size of the largest variable
336  * length HWPerf packet must fall within, currently 3KB. This constant may be
337  * used to allocate a buffer to hold one packet.
338  * This upper limit is policed by packet producing code.
339  */
340 #define RGX_HWPERF_MAX_PACKET_SIZE   0xC00U
341
342 /*! Defines an upper limit to the size of a variable length packet payload.
343  */
344 #define RGX_HWPERF_MAX_PAYLOAD_SIZE      ((IMG_UINT32)(RGX_HWPERF_MAX_PACKET_SIZE-\
345         sizeof(RGX_HWPERF_V2_PACKET_HDR)))
346
347
348 /*! Macro which takes a structure name and provides the packet size for
349  * a fixed size payload packet, rounded up to 8 bytes to align packets
350  * for 64 bit architectures. */
351 #define RGX_HWPERF_MAKE_SIZE_FIXED(_struct)       ((IMG_UINT32)(RGX_HWPERF_SIZE_MASK&(sizeof(RGX_HWPERF_V2_PACKET_HDR)+PVR_ALIGN(sizeof(_struct), PVRSRVTL_PACKET_ALIGNMENT))))
352
353 /*! Macro which takes the number of bytes written in the data payload of a
354  * packet for a variable size payload packet, rounded up to 8 bytes to 
355  * align packets for 64 bit architectures. */
356 #define RGX_HWPERF_MAKE_SIZE_VARIABLE(_size)      ((IMG_UINT32)(RGX_HWPERF_SIZE_MASK&(sizeof(RGX_HWPERF_V2_PACKET_HDR)+PVR_ALIGN(_size, PVRSRVTL_PACKET_ALIGNMENT))))
357
358 /*! Macro to obtain the size of the packet */
359 #define RGX_HWPERF_GET_SIZE(_packet_addr)         ((IMG_UINT16)(((_packet_addr)->ui32Size) & RGX_HWPERF_SIZE_MASK))
360
361 /*! Macro to obtain the size of the packet data */
362 #define RGX_HWPERF_GET_DATA_SIZE(_packet_addr)    (RGX_HWPERF_GET_SIZE(_packet_addr) - sizeof(RGX_HWPERF_V2_PACKET_HDR))
363
364
365
366 /*! Masks for use with the IMG_UINT32 eTypeId header field */
367 #define RGX_HWPERF_TYPEID_MASK                  0x7FFFFU
368 #define RGX_HWPERF_TYPEID_EVENT_MASK    0x07FFFU
369 #define RGX_HWPERF_TYPEID_THREAD_MASK   0x08000U
370 #define RGX_HWPERF_TYPEID_STREAM_MASK   0x70000U
371 #define RGX_HWPERF_TYPEID_OSID_MASK             0xFF000000U
372
373 /*! Meta thread macros for encoding the ID into the type field of a packet */
374 #define RGX_HWPERF_META_THREAD_SHIFT    15U
375 #define RGX_HWPERF_META_THREAD_ID0              0x0U
376 #define RGX_HWPERF_META_THREAD_ID1              0x1U
377 /*! Obsolete, kept for source compatibility */
378 #define RGX_HWPERF_META_THREAD_MASK             0x1U
379 /*! Stream ID macros for encoding the ID into the type field of a packet */
380 #define RGX_HWPERF_STREAM_SHIFT                 16U
381 /*! OSID bit-shift macro used for encoding OSID into type field of a packet */
382 #define RGX_HWPERF_OSID_SHIFT                   24U
383 typedef enum {
384         RGX_HWPERF_STREAM_ID0_FW,     /*!< Events from the Firmware/GPU */
385         RGX_HWPERF_STREAM_ID1_HOST,   /*!< Events from the Server host driver component */
386         RGX_HWPERF_STREAM_ID2_CLIENT, /*!< Events from the Client host driver component */
387         RGX_HWPERF_STREAM_ID_LAST,
388 } RGX_HWPERF_STREAM_ID;
389
390 /* Checks if all stream IDs can fit under RGX_HWPERF_TYPEID_STREAM_MASK. */
391 static_assert((RGX_HWPERF_STREAM_ID_LAST - 1) < (RGX_HWPERF_TYPEID_STREAM_MASK >> RGX_HWPERF_STREAM_SHIFT),
392                 "To many HWPerf stream IDs.");
393
394 /*! Macros used to set the packet type and encode meta thread ID (0|1), hwperf stream ID, and OSID within */
395 #define RGX_HWPERF_MAKE_TYPEID(_stream,_type,_thread,_osid)\
396                 ((IMG_UINT32) ((RGX_HWPERF_TYPEID_STREAM_MASK&((_stream)<<RGX_HWPERF_STREAM_SHIFT)) | \
397                 (RGX_HWPERF_TYPEID_THREAD_MASK&((_thread)<<RGX_HWPERF_META_THREAD_SHIFT)) | \
398                 (RGX_HWPERF_TYPEID_EVENT_MASK&(_type)) | \
399                 (RGX_HWPERF_TYPEID_OSID_MASK & ((_osid) << RGX_HWPERF_OSID_SHIFT))))
400
401 /*! Obtains the event type that generated the packet */
402 #define RGX_HWPERF_GET_TYPE(_packet_addr)            (((_packet_addr)->eTypeId) & RGX_HWPERF_TYPEID_EVENT_MASK)
403
404 /*! Obtains the META Thread number that generated the packet */
405 #define RGX_HWPERF_GET_THREAD_ID(_packet_addr)       (((((_packet_addr)->eTypeId)&RGX_HWPERF_TYPEID_THREAD_MASK) >> RGX_HWPERF_META_THREAD_SHIFT))
406
407 /*! Obtains the guest OSID which resulted in packet generation */
408 #define RGX_HWPERF_GET_OSID(_packet_addr)            (((_packet_addr)->eTypeId & RGX_HWPERF_TYPEID_OSID_MASK) >> RGX_HWPERF_OSID_SHIFT)
409
410 /*! Obtain stream id */
411 #define RGX_HWPERF_GET_STREAM_ID(_packet_addr)       (((((_packet_addr)->eTypeId)&RGX_HWPERF_TYPEID_STREAM_MASK) >> RGX_HWPERF_STREAM_SHIFT))
412
413 /*! Macros to obtain a typed pointer to a packet or data structure given a packet address */
414 #define RGX_HWPERF_GET_PACKET(_buffer_addr)            ((RGX_HWPERF_V2_PACKET_HDR*)  (_buffer_addr))
415 #define RGX_HWPERF_GET_PACKET_DATA_BYTES(_packet_addr) ((IMG_BYTE*) ( ((IMG_BYTE*)(_packet_addr)) +sizeof(RGX_HWPERF_V2_PACKET_HDR) ) )
416 #define RGX_HWPERF_GET_NEXT_PACKET(_packet_addr)       ((RGX_HWPERF_V2_PACKET_HDR*)  ( ((IMG_BYTE*)(_packet_addr))+(RGX_HWPERF_SIZE_MASK&(_packet_addr)->ui32Size)) )
417
418 /*! Obtains a typed pointer to a packet header given the packed data address */
419 #define RGX_HWPERF_GET_PACKET_HEADER(_packet_addr)     ((RGX_HWPERF_V2_PACKET_HDR*)  ( ((IMG_BYTE*)(_packet_addr)) - sizeof(RGX_HWPERF_V2_PACKET_HDR) ))
420
421 /* This macro is not a real array size, but indicates the array has a
422  * variable length only known at run-time but always contains at least 1 element.
423  * The final size of the array is deduced from the size field of a packet
424  * header. */
425 #define RGX_HWPERF_ONE_OR_MORE_ELEMENTS  1U
426
427 /* This macro is not a real array size, but indicates the array is optional
428  * and if present has a variable length only known at run-time. The final 
429  * size of the array is deduced from the size field of a packet header. */
430 #define RGX_HWPERF_ZERO_OR_MORE_ELEMENTS 1U
431
432
433 /*! Masks for use with the IMG_UINT32 ui32BlkInfo field */
434 #define RGX_HWPERF_BLKINFO_BLKCOUNT_MASK        0xFFFF0000U
435 #define RGX_HWPERF_BLKINFO_BLKOFFSET_MASK       0x0000FFFFU
436
437 /*! Shift for the NumBlocks and counter block offset field in ui32BlkInfo */
438 #define RGX_HWPERF_BLKINFO_BLKCOUNT_SHIFT       16U
439 #define RGX_HWPERF_BLKINFO_BLKOFFSET_SHIFT 0U
440
441 /*! Macro used to set the block info word as a combination of two 16-bit integers */
442 #define RGX_HWPERF_MAKE_BLKINFO(_numblks,_blkoffset) ((IMG_UINT32) ((RGX_HWPERF_BLKINFO_BLKCOUNT_MASK&((_numblks) << RGX_HWPERF_BLKINFO_BLKCOUNT_SHIFT)) | (RGX_HWPERF_BLKINFO_BLKOFFSET_MASK&((_blkoffset) << RGX_HWPERF_BLKINFO_BLKOFFSET_SHIFT))))
443
444 /*! Macro used to obtain get the number of counter blocks present in the packet */
445 #define RGX_HWPERF_GET_BLKCOUNT(_blkinfo)            ((_blkinfo & RGX_HWPERF_BLKINFO_BLKCOUNT_MASK) >> RGX_HWPERF_BLKINFO_BLKCOUNT_SHIFT)
446
447 /*! Obtains the offset of the counter block stream in the packet */
448 #define RGX_HWPERF_GET_BLKOFFSET(_blkinfo)           ((_blkinfo & RGX_HWPERF_BLKINFO_BLKOFFSET_MASK) >> RGX_HWPERF_BLKINFO_BLKOFFSET_SHIFT)
449
450 /* This is the maximum frame contexts that are supported in the driver at the moment */
451 #define RGX_HWPERF_HW_MAX_WORK_CONTEXT               2
452
453 /*! Masks for use with the RGX_HWPERF_UFO_EV eEvType field */
454 #define RGX_HWPERF_UFO_STREAMSIZE_MASK 0xFFFF0000U
455 #define RGX_HWPERF_UFO_STREAMOFFSET_MASK 0x0000FFFFU
456
457 /*! Shift for the UFO count and data stream fields */
458 #define RGX_HWPERF_UFO_STREAMSIZE_SHIFT 16U
459 #define RGX_HWPERF_UFO_STREAMOFFSET_SHIFT 0U
460
461 /*! Macro used to set ufo stream info word as a combination of two 16-bit integers */
462 #define RGX_HWPERF_MAKE_UFOPKTINFO(_ssize,_soff)\
463         ((IMG_UINT32) ((RGX_HWPERF_UFO_STREAMSIZE_MASK&((_ssize) << RGX_HWPERF_UFO_STREAMSIZE_SHIFT)) |\
464         (RGX_HWPERF_UFO_STREAMOFFSET_MASK&((_soff) << RGX_HWPERF_UFO_STREAMOFFSET_SHIFT))))
465
466 /*! Macro used to obtain ufo count*/
467 #define RGX_HWPERF_GET_UFO_STREAMSIZE(_streaminfo)\
468         ((_streaminfo & RGX_HWPERF_UFO_STREAMSIZE_MASK) >> RGX_HWPERF_UFO_STREAMSIZE_SHIFT)
469
470 /*! Obtains the offset of the ufo stream in the packet */
471 #define RGX_HWPERF_GET_UFO_STREAMOFFSET(_streaminfo)\
472         ((_streaminfo & RGX_HWPERF_UFO_STREAMOFFSET_MASK) >> RGX_HWPERF_UFO_STREAMOFFSET_SHIFT)
473
474 /******************************************************************************
475  *      API Types
476  *****************************************************************************/
477
478 /*! Counter block IDs for all the hardware blocks with a performance
479  * counting module. Directly addressable blocks must have a value between 0..15.
480  * First hex digit represents a group number and the second hex digit represents
481  * the unit within the group. Group 0 is the direct group, all others are
482  * indirect groups.
483  */
484 typedef enum
485 {
486         /* Directly addressable counter blocks */
487         RGX_CNTBLK_ID_TA                        = 0x0000,
488         RGX_CNTBLK_ID_RASTER            = 0x0001, /* Non-cluster grouping cores */
489         RGX_CNTBLK_ID_HUB                       = 0x0002, /* Non-cluster grouping cores */
490         RGX_CNTBLK_ID_TORNADO           = 0x0003, /* XT cores */
491         RGX_CNTBLK_ID_JONES                     = 0x0004, /* S7 cores */
492         RGX_CNTBLK_ID_BF                        = 0x0005, /* Doppler unit */
493         RGX_CNTBLK_ID_BT                        = 0x0006, /* Doppler unit */
494         RGX_CNTBLK_ID_RT                        = 0x0007, /* Doppler unit */
495         RGX_CNTBLK_ID_SH                        = 0x0008, /* Ray tracing unit */
496
497         RGX_CNTBLK_ID_DIRECT_LAST,
498
499         /* Indirectly addressable counter blocks */
500         RGX_CNTBLK_ID_TPU_MCU0          = 0x0010, /* Addressable by Dust */
501         RGX_CNTBLK_ID_TPU_MCU1          = 0x0011,
502         RGX_CNTBLK_ID_TPU_MCU2          = 0x0012,
503         RGX_CNTBLK_ID_TPU_MCU3          = 0x0013,
504         RGX_CNTBLK_ID_TPU_MCU4          = 0x0014,
505         RGX_CNTBLK_ID_TPU_MCU5          = 0x0015,
506         RGX_CNTBLK_ID_TPU_MCU6          = 0x0016,
507         RGX_CNTBLK_ID_TPU_MCU7          = 0x0017,
508         RGX_CNTBLK_ID_TPU_MCU_ALL       = 0x4010,
509
510         RGX_CNTBLK_ID_USC0                      = 0x0020, /* Addressable by Cluster */
511         RGX_CNTBLK_ID_USC1                      = 0x0021,
512         RGX_CNTBLK_ID_USC2                      = 0x0022,
513         RGX_CNTBLK_ID_USC3                      = 0x0023,
514         RGX_CNTBLK_ID_USC4                      = 0x0024,
515         RGX_CNTBLK_ID_USC5                      = 0x0025,
516         RGX_CNTBLK_ID_USC6                      = 0x0026,
517         RGX_CNTBLK_ID_USC7                      = 0x0027,
518         RGX_CNTBLK_ID_USC8                      = 0x0028,
519         RGX_CNTBLK_ID_USC9                      = 0x0029,
520         RGX_CNTBLK_ID_USC10                     = 0x002A,
521         RGX_CNTBLK_ID_USC11                     = 0x002B,
522         RGX_CNTBLK_ID_USC12                     = 0x002C,
523         RGX_CNTBLK_ID_USC13                     = 0x002D,
524         RGX_CNTBLK_ID_USC14                     = 0x002E,
525         RGX_CNTBLK_ID_USC15                     = 0x002F,
526         RGX_CNTBLK_ID_USC_ALL           = 0x4020,
527
528         RGX_CNTBLK_ID_TEXAS0            = 0x0030, /* Addressable by Phantom in XT, Dust in S7 */
529         RGX_CNTBLK_ID_TEXAS1            = 0x0031,
530         RGX_CNTBLK_ID_TEXAS2            = 0x0032,
531         RGX_CNTBLK_ID_TEXAS3            = 0x0033,
532         RGX_CNTBLK_ID_TEXAS4            = 0x0034,
533         RGX_CNTBLK_ID_TEXAS5            = 0x0035,
534         RGX_CNTBLK_ID_TEXAS6            = 0x0036,
535         RGX_CNTBLK_ID_TEXAS7            = 0x0037,
536         RGX_CNTBLK_ID_TEXAS_ALL         = 0x4030,
537
538         RGX_CNTBLK_ID_RASTER0           = 0x0040, /* Addressable by Phantom, XT only */
539         RGX_CNTBLK_ID_RASTER1           = 0x0041,
540         RGX_CNTBLK_ID_RASTER2           = 0x0042,
541         RGX_CNTBLK_ID_RASTER3           = 0x0043,
542         RGX_CNTBLK_ID_RASTER_ALL        = 0x4040,
543
544         RGX_CNTBLK_ID_BLACKPEARL0       = 0x0050, /* Addressable by Phantom, S7 only */
545         RGX_CNTBLK_ID_BLACKPEARL1       = 0x0051,
546         RGX_CNTBLK_ID_BLACKPEARL2       = 0x0052,
547         RGX_CNTBLK_ID_BLACKPEARL3       = 0x0053,
548         RGX_CNTBLK_ID_BLACKPEARL_ALL= 0x4050,
549
550         RGX_CNTBLK_ID_PBE0                      = 0x0060, /* Addressable by Cluster, S7 only */
551         RGX_CNTBLK_ID_PBE1                      = 0x0061,
552         RGX_CNTBLK_ID_PBE2                      = 0x0062,
553         RGX_CNTBLK_ID_PBE3                      = 0x0063,
554         RGX_CNTBLK_ID_PBE4                      = 0x0064,
555         RGX_CNTBLK_ID_PBE5                      = 0x0065,
556         RGX_CNTBLK_ID_PBE6                      = 0x0066,
557         RGX_CNTBLK_ID_PBE7                      = 0x0067,
558         RGX_CNTBLK_ID_PBE8                      = 0x0068,
559         RGX_CNTBLK_ID_PBE9                      = 0x0069,
560         RGX_CNTBLK_ID_PBE10                     = 0x006A,
561         RGX_CNTBLK_ID_PBE11                     = 0x006B,
562         RGX_CNTBLK_ID_PBE12                     = 0x006C,
563         RGX_CNTBLK_ID_PBE13                     = 0x006D,
564         RGX_CNTBLK_ID_PBE14                     = 0x006E,
565         RGX_CNTBLK_ID_PBE15                     = 0x006F,
566         RGX_CNTBLK_ID_PBE_ALL           = 0x4060,
567
568         RGX_CNTBLK_ID_BX_TU0            = 0x0070, /* Doppler unit, XT only */
569         RGX_CNTBLK_ID_BX_TU1            = 0x0071,
570         RGX_CNTBLK_ID_BX_TU2            = 0x0072,
571         RGX_CNTBLK_ID_BX_TU3            = 0x0073,
572         RGX_CNTBLK_ID_BX_TU_ALL         = 0x4070,
573
574         RGX_CNTBLK_ID_LAST                      = 0x0074,
575
576         RGX_CNTBLK_ID_CUSTOM0           = 0x7FF0,
577         RGX_CNTBLK_ID_CUSTOM1           = 0x7FF1,
578         RGX_CNTBLK_ID_CUSTOM2           = 0x7FF2,
579         RGX_CNTBLK_ID_CUSTOM3           = 0x7FF3,
580         RGX_CNTBLK_ID_CUSTOM4_FW        = 0x7FF4        /* Custom block used for getting statistics held in the FW */
581
582 } RGX_HWPERF_CNTBLK_ID;
583
584 /* Masks for the counter block ID*/
585 #define RGX_CNTBLK_ID_GROUP_MASK     (0x00F0U)
586 #define RGX_CNTBLK_ID_GROUP_SHIFT    (4)
587 #define RGX_CNTBLK_ID_UNIT_ALL_MASK  (0x4000U)
588 #define RGX_CNTBLK_ID_UNIT_MASK          (0xf)
589
590 #define RGX_CNTBLK_INDIRECT_COUNT(_class, _n) ((RGX_CNTBLK_ID_ ## _class ## _n) - (RGX_CNTBLK_ID_ ## _class ## 0) +1)
591
592 /*! The number of layout blocks defined with configurable multiplexed
593  * performance counters, hence excludes custom counter blocks.
594  */
595 #define RGX_HWPERF_MAX_DEFINED_BLKS  (\
596         RGX_CNTBLK_ID_DIRECT_LAST               +\
597         RGX_CNTBLK_INDIRECT_COUNT(TPU_MCU,     7)+\
598         RGX_CNTBLK_INDIRECT_COUNT(USC,        15)+\
599         RGX_CNTBLK_INDIRECT_COUNT(TEXAS,       7)+\
600         RGX_CNTBLK_INDIRECT_COUNT(RASTER,      3)+\
601         RGX_CNTBLK_INDIRECT_COUNT(BLACKPEARL,  3)+\
602         RGX_CNTBLK_INDIRECT_COUNT(PBE,        15)+\
603         RGX_CNTBLK_INDIRECT_COUNT(BX_TU,       3) )
604
605 #define RGX_HWPERF_EVENT_MASK_VALUE(e)      (((IMG_UINT64)1)<<(e))
606
607 #define RGX_CUSTOM_FW_CNTRS     \
608                 X(TA_LOCAL_FL_SIZE,             0x0,    RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_TAKICK) | \
609                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_PMOOM_TAPAUSE) | \
610                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_PMOOM_TARESUME) | \
611                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_TAFINISHED))  \
612                 X(TA_GLOBAL_FL_SIZE,    0x1,    RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_TAKICK) | \
613                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_PMOOM_TAPAUSE) | \
614                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_PMOOM_TARESUME) | \
615                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_TAFINISHED))  \
616                 X(3D_LOCAL_FL_SIZE,             0x2,    RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_3DKICK) | \
617                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_3DFINISHED))  \
618                 X(3D_GLOBAL_FL_SIZE,    0x3,    RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_3DKICK) | \
619                                                                                 RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_3DFINISHED))
620
621 /*! Counter IDs for the firmware held stats */
622 typedef enum
623 {
624 #define X(ctr, id, allow_mask)  RGX_CUSTOM_FW_CNTR_##ctr = id,
625         RGX_CUSTOM_FW_CNTRS
626 #undef X
627
628         /* always the last entry in the list */
629         RGX_CUSTOM_FW_CNTR_LAST
630 } RGX_HWPERF_CUSTOM_FW_CNTR_ID;
631
632 /*! Identifier for each counter in a performance counting module */
633 typedef enum
634 {
635         RGX_CNTBLK_COUNTER0_ID    = 0,
636         RGX_CNTBLK_COUNTER1_ID    = 1,
637         RGX_CNTBLK_COUNTER2_ID    = 2,
638         RGX_CNTBLK_COUNTER3_ID    = 3,
639         RGX_CNTBLK_COUNTER4_ID    = 4,
640         RGX_CNTBLK_COUNTER5_ID    = 5,
641         /* MAX value used in server handling of counter config arrays */
642         RGX_CNTBLK_COUNTERS_MAX 
643 } RGX_HWPERF_CNTBLK_COUNTER_ID;
644
645 /* sets all the bits from bit _b1 to _b2, in a IMG_UINT64 type */
646 #define _MASK_RANGE(_b1, _b2)   (((IMG_UINT64_C(1) << ((_b2)-(_b1)+1)) - 1) << _b1)
647 #define MASK_RANGE(R)                   _MASK_RANGE(R##_FIRST_TYPE, R##_LAST_TYPE)
648 #define RGX_HWPERF_HOST_EVENT_MASK_VALUE(e) ((IMG_UINT32)(1<<(e)))
649
650 /*! Mask macros for use with RGXCtrlHWPerf() API.
651  */
652 #define RGX_HWPERF_EVENT_MASK_NONE          (IMG_UINT64_C(0x0000000000000000))
653 #define RGX_HWPERF_EVENT_MASK_ALL           (IMG_UINT64_C(0xFFFFFFFFFFFFFFFF))
654
655 /*! HWPerf Firmware event masks
656  * Next macro covers all FW Start/End/Debug (SED) events.
657  */
658 #define RGX_HWPERF_EVENT_MASK_FW_SED    (MASK_RANGE(RGX_HWPERF_FW_EVENT_RANGE))
659
660 #define RGX_HWPERF_EVENT_MASK_FW_UFO    (RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_UFO))
661 #define RGX_HWPERF_EVENT_MASK_FW_CSW    (RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_CSW_START) |\
662                                           RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_CSW_FINISHED))
663 #define RGX_HWPERF_EVENT_MASK_ALL_FW    (RGX_HWPERF_EVENT_MASK_FW_SED |\
664                                           RGX_HWPERF_EVENT_MASK_FW_UFO |\
665                                           RGX_HWPERF_EVENT_MASK_FW_CSW)
666
667 #define RGX_HWPERF_EVENT_MASK_HW_PERIODIC   (RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_HW_PERIODIC))
668 #define RGX_HWPERF_EVENT_MASK_HW_KICKFINISH ((MASK_RANGE(RGX_HWPERF_HW_EVENT_RANGE0) |\
669                                                MASK_RANGE(RGX_HWPERF_HW_EVENT_RANGE1)) &\
670                                               ~(RGX_HWPERF_EVENT_MASK_HW_PERIODIC))
671
672 #define RGX_HWPERF_EVENT_MASK_ALL_HW        (RGX_HWPERF_EVENT_MASK_HW_KICKFINISH |\
673                                               RGX_HWPERF_EVENT_MASK_HW_PERIODIC)
674
675 #define RGX_HWPERF_EVENT_MASK_ALL_PWR_EST   (MASK_RANGE(RGX_HWPERF_PWR_EST_RANGE))
676
677 #define RGX_HWPERF_EVENT_MASK_ALL_PWR       (RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_CLKS_CHG) |\
678                                               RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_GPU_STATE_CHG) |\
679                                               RGX_HWPERF_EVENT_MASK_VALUE(RGX_HWPERF_PWR_CHG))
680
681 /*! HWPerf Host event masks
682  */
683 #define RGX_HWPERF_EVENT_MASK_HOST_WORK_ENQ  (RGX_HWPERF_HOST_EVENT_MASK_VALUE(RGX_HWPERF_HOST_ENQ))
684 #define RGX_HWPERF_EVENT_MASK_HOST_ALL_UFO   (RGX_HWPERF_HOST_EVENT_MASK_VALUE(RGX_HWPERF_HOST_UFO))
685 #define RGX_HWPERF_EVENT_MASK_HOST_ALL_PWR   (RGX_HWPERF_HOST_EVENT_MASK_VALUE(RGX_HWPERF_HOST_CLK_SYNC))
686
687
688
689 /*! Type used in the RGX API RGXConfigureAndEnableHWPerfCounters()
690  * It is used to configure the performance counter module in a layout
691  * block and allows one or more counters in the block to be 
692  * configured in one operation based on the counter select mask. The bit
693  * shifts for this are the values in RGX_HWPERF_CNTBLK_COUNTER_ID. This mask
694  * also encodes which values in the arrays are valid, for example, if bit 1 set
695  * then aui8Mode[1], aui16GroupSelect[1], aui16BitSelect[1], aui32BatchMax[1],
696  * and aui32BatchMin[1] must be set. If these array elements are all set to 
697  * 0 then the counter will not count and will not be in the HW event,
698  * effectively disabling the counter from the callers point of view.
699  * If any are non zero then the counter will be included in the HW event.
700  *
701  * Each layout block has 4 or 6 counters that can be programmed independently to
702  * profile the performance of a HW block. Each counter can be configured to
703  * accumulate statistics from 1 of 32 counter groups defined for that block.
704  * Each counter group can have up to 16 signals/bits defined that can be
705  * selected. Each counter may accumulate in one of two modes.
706  * See hwdefs/regapiperf.h for block/group/signal definitions.
707  */
708  typedef struct _RGX_HWPERF_CONFIG_CNTBLK_
709 {
710         /*! Counter block ID, see RGX_HWPERF_CNTBLK_ID */
711         IMG_UINT16 ui16BlockID;
712
713         /*! 4 or 6 LSBs are a mask of which counters to configure. Bit 0 is counter 0,
714          * bit 1 is counter 1 on so on. */
715         IMG_UINT8   ui8CounterSelect;
716
717         /*! 4 or 6 LSBs 0 for counting 1's in the group, 1 for treating the group
718          * signals as a number for unsigned addition. Bit 0 is counter 0, bit 1 is
719          * counter 1 on so on. This member relates to the MODE field
720          * in the RGX_CR_<N>_PERF_SELECTm register for each counter */
721         IMG_UINT8       ui8Mode;
722
723         /*! 5 or 6 LSBs used as the GROUP_SELECT field in the RGX_CR_<N>_PERF_SELECTm
724          * register. Array index 0 is counter 0, index 1 is counter 1 and so on. */
725         IMG_UINT8       aui8GroupSelect[RGX_CNTBLK_COUNTERS_MAX];
726
727         /*! 16 LSBs used as the BIT_SELECT field in the RGX_CR_<N>_PERF_SELECTm
728          * register. Array indexes relate to counters as above. */
729         IMG_UINT16  aui16BitSelect[RGX_CNTBLK_COUNTERS_MAX];
730
731         /*! 14 LSBs used as the BATCH_MAX field in the RGX_CR_<N>_PERF_SELECTm
732          * register. Array indexes relate to counters as above. */
733         IMG_UINT32  aui32BatchMax[RGX_CNTBLK_COUNTERS_MAX];
734
735         /*! 14 LSBs used as the BATCH_MIN field in the RGX_CR_<N>_PERF_SELECTm
736          * register. Array indexes relate to counters as above. */
737         IMG_UINT32  aui32BatchMin[RGX_CNTBLK_COUNTERS_MAX];
738 } UNCACHED_ALIGN RGX_HWPERF_CONFIG_CNTBLK;
739
740 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_CONFIG_CNTBLK);
741
742 /******************************************************************************
743  *      Data Stream Common Types
744  *****************************************************************************/
745
746 /* All the Data Masters HWPerf is aware of. When a new DM is added to this list,
747  * it should be appended at the end to maintain backward compatibility of HWPerf data */
748 typedef enum _RGX_HWPERF_DM {
749
750         RGX_HWPERF_DM_GP,
751         RGX_HWPERF_DM_2D,
752         RGX_HWPERF_DM_TA,
753         RGX_HWPERF_DM_3D,
754         RGX_HWPERF_DM_CDM,
755         RGX_HWPERF_DM_RTU,
756         RGX_HWPERF_DM_SHG,
757         RGX_HWPERF_DM_TDM,
758
759         RGX_HWPERF_DM_LAST,
760
761         RGX_HWPERF_DM_INVALID = 0x1FFFFFFF
762 } RGX_HWPERF_DM;
763
764 /* These structures are used on both GPU and CPU and must be a size that is a
765  * multiple of 64 bits, 8 bytes to allow the FW to write 8 byte quantities
766  * at 8 byte aligned addresses.  RGX_FW_STRUCT_*_ASSERT() is used to check this.
767  */
768
769
770 /*! This structure holds the field data of a Hardware packet.
771  */
772 #define RGX_HWPERF_HW_DATA_FIELDS_LIST \
773 IMG_UINT32 ui32DMCyc;         /*!< DataMaster cycle count register, 0 if none */\
774 IMG_UINT32 ui32FrameNum;      /*!< Frame number, undefined on some DataMasters */\
775 IMG_UINT32 ui32PID;           /*!< Process identifier */\
776 IMG_UINT32 ui32DMContext;     /*!< GPU Data Master (FW) Context */\
777 IMG_UINT32 ui32WorkTarget;    /*!< RenderTarget for a TA,3D; Frame context for RTU, 0x0 otherwise */\
778 IMG_UINT32 ui32ExtJobRef;     /*!< Externally provided job reference used to track work for debugging purposes */\
779 IMG_UINT32 ui32IntJobRef;     /*!< Internally provided job reference used to track work for debugging purposes */\
780 IMG_UINT32 ui32TimeCorrIndex; /*!< Index to the time correlation at the time the packet was generated */\
781 IMG_UINT32 ui32BlkInfo;       /*!< <31..16> NumBlocks <15..0> Counterblock stream offset */\
782 IMG_UINT32 ui32WorkCtx;       /*!< Work context: Render Context for TA/3D; RayTracing Context for RTU/SHG; 0x0 otherwise */\
783 IMG_UINT32 ui32CtxPriority;   /*!< Context priority */\
784 IMG_UINT32 ui32Padding1;      /* To ensure correct alignment */
785
786 typedef struct
787 {
788         RGX_HWPERF_HW_DATA_FIELDS_LIST
789 } RGX_HWPERF_HW_DATA_FIELDS;
790
791 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_HW_DATA_FIELDS);
792
793 typedef enum {
794         RGX_HWPERF_UFO_EV_UPDATE,
795         RGX_HWPERF_UFO_EV_CHECK_SUCCESS,
796         RGX_HWPERF_UFO_EV_PRCHECK_SUCCESS,
797         RGX_HWPERF_UFO_EV_CHECK_FAIL,
798         RGX_HWPERF_UFO_EV_PRCHECK_FAIL,
799
800         RGX_HWPERF_UFO_EV_LAST
801 } RGX_HWPERF_UFO_EV;
802
803 /*! Data stream tuple. */
804 typedef union
805 {
806         struct
807         {
808                 IMG_UINT32 ui32FWAddr;
809                 IMG_UINT32 ui32Value;
810         } sCheckSuccess;
811         struct
812         {
813                 IMG_UINT32 ui32FWAddr;
814                 IMG_UINT32 ui32Value;
815                 IMG_UINT32 ui32Required;
816         } sCheckFail;
817         struct
818         {
819                 IMG_UINT32 ui32FWAddr;
820                 IMG_UINT32 ui32OldValue;
821                 IMG_UINT32 ui32NewValue;
822         } sUpdate;
823 } RGX_HWPERF_UFO_DATA_ELEMENT;
824
825 /*! This structure holds data for ufo packet. */
826 typedef struct
827 {
828         RGX_HWPERF_UFO_EV eEvType;
829         IMG_UINT32 ui32TimeCorrIndex;
830         IMG_UINT32 ui32PID;
831         IMG_UINT32 ui32ExtJobRef;
832         IMG_UINT32 ui32IntJobRef;
833         IMG_UINT32 ui32DMContext;      /*!< GPU Data Master (FW) Context */
834         IMG_UINT32 ui32StreamInfo;
835         RGX_HWPERF_DM eDM;
836         IMG_UINT32 ui32Padding;
837
838         IMG_UINT32 aui32StreamData[RGX_HWPERF_ONE_OR_MORE_ELEMENTS];
839         /*!< Data stream contains UFO objects for specific command.
840          *
841          * Data stream consists of tuples containing UFO related data. Depending
842          * on the UFO event type there are three tuple formats:
843          *      For UPDATE packet tuple consist of two 32bit values:
844          *          <32bit> :        UFO's firmware address
845          *          <32bit> :        old UFO's value
846          *          <32bit> :        update value
847          *      For PRCHECK/CHECK SUCCESS packets tuple consists of two 32bit
848          *      values:
849          *          <32bit> :        UFO's firmware address
850          *          <32bit> :        UFO's/fence value
851          *      For PRCHECK/CHECK FAIL packets tuple consists of three 32bit values:
852          *          <32bit> :        UFO's firmware address
853          *          <32bit> :        UFO's value
854          *          <32bit> :        fence value
855          *
856          * An example of data stream:
857          *          <UFO0addr>, <UFO0val>, <Fnc0Val>, <UFO1addr>, <UFO1val>, <Fnc1Val> ...
858          *
859          * The array size is at least large enough to fit in one tuple. Real
860          * size is however dynamic and reflects number of all tuples that are fit
861          * into the array.
862          */
863 } RGX_HWPERF_UFO_DATA;
864
865 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_UFO_DATA);
866
867 /*! This structure holds the data of a firmware packet. */
868 typedef struct
869 {
870         RGX_HWPERF_DM eDM;                              /*!< DataMaster identifier, see RGX_HWPERF_DM */
871         IMG_UINT32 ui32TxtActCyc;               /*!< Meta TXTACTCYC register value */
872         IMG_UINT32 ui32FWPerfCount0;    /*!< Meta/MIPS PERF_COUNT0 register */
873         IMG_UINT32 ui32FWPerfCount1;    /*!< Meta/MIPS PERF_COUNT1 register */
874         IMG_UINT32 ui32TimeCorrIndex;
875         IMG_UINT32 ui32Padding;
876 } RGX_HWPERF_FW_DATA;
877
878 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_FW_DATA);
879
880 typedef enum
881 {
882         RGX_HWPERF_CTRL_TYPE_INVALID,
883         RGX_HWPERF_CTRL_TYPE_CLIENT_STREAM_OPEN,
884         RGX_HWPERF_CTRL_TYPE_CLIENT_STREAM_CLOSE,
885         RGX_HWPERF_CTRL_TYPE_LAST
886 } RGX_HWPERF_HOST_CTRL_TYPE;
887
888 typedef struct
889 {
890         RGX_HWPERF_HOST_CTRL_TYPE eEvType;
891         union
892         {
893                 IMG_UINT32 ui32Pid;
894         } uData;
895 } RGX_HWPERF_HOST_CTRL_DATA;
896
897 typedef enum
898 {
899         RGX_HWPERF_KICK_TYPE_TA3D,
900         RGX_HWPERF_KICK_TYPE_TQ2D,
901         RGX_HWPERF_KICK_TYPE_TQ3D,
902         RGX_HWPERF_KICK_TYPE_CDM,
903         RGX_HWPERF_KICK_TYPE_RS,
904         RGX_HWPERF_KICK_TYPE_VRDM,
905         RGX_HWPERF_KICK_TYPE_TQTDM,
906         RGX_HWPERF_KICK_TYPE_SYNC,
907         RGX_HWPERF_KICK_TYPE_LAST
908 } RGX_HWPERF_KICK_TYPE;
909
910 typedef struct
911 {
912         RGX_HWPERF_KICK_TYPE ui32EnqType;
913         IMG_UINT32 ui32PID;
914         IMG_UINT32 ui32ExtJobRef;
915         IMG_UINT32 ui32IntJobRef;
916         IMG_UINT32 ui32DMContext;      /*!< GPU Data Master (FW) Context */
917         IMG_UINT32 ui32Padding;        /* Align structure size to 8 bytes */
918 } RGX_HWPERF_HOST_ENQ_DATA;
919
920 /* Payload size must be multiple of 8 bytes to align start of next packet. */
921 static_assert((sizeof(RGX_HWPERF_HOST_ENQ_DATA) & (PVRSRVTL_PACKET_ALIGNMENT-1)) == 0,
922                           "sizeof(RGX_HWPERF_HOST_ENQ_DATA) must be a multiple PVRSRVTL_PACKET_ALIGNMENT");
923
924 typedef struct
925 {
926         RGX_HWPERF_UFO_EV eEvType;
927         IMG_UINT32 ui32StreamInfo;
928         IMG_UINT32 aui32StreamData[RGX_HWPERF_ONE_OR_MORE_ELEMENTS];
929         IMG_UINT32 ui32Padding;      /* Align structure size to 8 bytes */
930 } RGX_HWPERF_HOST_UFO_DATA;
931
932 /* Payload size must be multiple of 8 bytes to align start of next packet. */
933 static_assert((sizeof(RGX_HWPERF_HOST_UFO_DATA) & (PVRSRVTL_PACKET_ALIGNMENT-1)) == 0,
934                           "sizeof(RGX_HWPERF_HOST_UFO_DATA) must be a multiple PVRSRVTL_PACKET_ALIGNMENT");
935
936 typedef enum
937 {
938         RGX_HWPERF_HOST_RESOURCE_TYPE_INVALID,
939         RGX_HWPERF_HOST_RESOURCE_TYPE_SYNC,
940         RGX_HWPERF_HOST_RESOURCE_TYPE_LAST
941 } RGX_HWPERF_HOST_RESOURCE_TYPE;
942
943 typedef union
944 {
945         struct
946         {
947                 IMG_UINT32 ui32FWAddr;
948                 IMG_CHAR acName[SYNC_MAX_CLASS_NAME_LEN];
949         } sSyncAlloc;
950 } RGX_HWPERF_HOST_ALLOC_DETAIL;
951
952 typedef struct
953 {
954         RGX_HWPERF_HOST_RESOURCE_TYPE ui32AllocType;
955         RGX_HWPERF_HOST_ALLOC_DETAIL uAllocDetail;
956 } RGX_HWPERF_HOST_ALLOC_DATA;
957
958 /* Payload size must be multiple of 8 bytes to align start of next packet. */
959 static_assert((sizeof(RGX_HWPERF_HOST_ALLOC_DATA) & (PVRSRVTL_PACKET_ALIGNMENT-1)) == 0,
960                           "sizeof(RGX_HWPERF_HOST_ALLOC_DATA) must be a multiple PVRSRVTL_PACKET_ALIGNMENT");
961
962 typedef union
963 {
964         struct
965         {
966                 IMG_UINT32 ui32FWAddr;
967         } sSyncFree;
968 } RGX_HWPERF_HOST_FREE_DETAIL;
969
970 typedef struct
971 {
972         RGX_HWPERF_HOST_RESOURCE_TYPE ui32FreeType;
973         RGX_HWPERF_HOST_FREE_DETAIL uFreeDetail;
974 } RGX_HWPERF_HOST_FREE_DATA;
975
976 /* Payload size must be multiple of 8 bytes to align start of next packet. */
977 static_assert((sizeof(RGX_HWPERF_HOST_FREE_DATA) & (PVRSRVTL_PACKET_ALIGNMENT-1)) == 0,
978                           "sizeof(RGX_HWPERF_HOST_FREE_DATA) must be a multiple PVRSRVTL_PACKET_ALIGNMENT");
979
980 typedef struct
981 {
982         IMG_UINT64 ui64CRTimestamp;
983         IMG_UINT64 ui64OSTimestamp;
984         IMG_UINT32 ui32ClockSpeed;
985         IMG_UINT32 ui32Padding;       /* Align structure size to 8 bytes */
986 } RGX_HWPERF_HOST_CLK_SYNC_DATA;
987
988 /* Payload size must be multiple of 8 bytes to align start of next packet. */
989 static_assert((sizeof(RGX_HWPERF_HOST_CLK_SYNC_DATA) & (PVRSRVTL_PACKET_ALIGNMENT-1)) == 0,
990                           "sizeof(RGX_HWPERF_HOST_CLK_SYNC_DATA) must be a multiple PVRSRVTL_PACKET_ALIGNMENT");
991
992 #if defined (__cplusplus)
993 }
994 #endif
995
996 #endif /* RGX_HWPERF_KM_H_ */
997
998 /******************************************************************************
999  End of file
1000 ******************************************************************************/
1001