Merge tag 'lsk-v3.10-15.04-android'
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue / include / 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
62
63 /******************************************************************************
64  *      Data Stream Common Types
65  *****************************************************************************/
66
67 /* These structures are used on both GPU and CPU and must be a size that is a
68  * multiple of 64 bits, 8 bytes to allow the FW to write 8 byte quantities
69  * at 8 byte aligned addresses.  BLD_ASSERT() is used to check this.
70  */
71  
72 /*! Type used to encode the event that generated the HW performance packet.
73  * NOTE: When this type is updated the corresponding hwperfbin2json tool source
74  * needs to be updated as well. Also need to update the table in rgxhwperf.c.
75  * The RGX_HWPERF_EVENT_MASK_* macros will also need updating when adding new
76  * types.
77  */
78 typedef enum
79 {
80         RGX_HWPERF_INVALID                              = 0x00,
81         /* FW types 0x01..0x07 */
82         RGX_HWPERF_FW_BGSTART                   = 0x01,
83         RGX_HWPERF_FW_BGEND                             = 0x02,
84         RGX_HWPERF_FW_IRQSTART                  = 0x03,
85
86         RGX_HWPERF_FW_IRQEND                    = 0x04,
87         RGX_HWPERF_FW_DBGSTART                  = 0x05,
88         RGX_HWPERF_FW_DBGEND                    = 0x06,
89
90         /* HW types 0x08..0x18 */
91         RGX_HWPERF_HW_TAKICK                    = 0x08,
92         RGX_HWPERF_HW_TAFINISHED                = 0x09,
93         RGX_HWPERF_HW_3DTQKICK                  = 0x0A,
94 /*      RGX_HWPERF_HW_3DTQFINISHED              = 0x17, */
95 /*      RGX_HWPERF_HW_3DSPMKICK                 = 0x11, */
96 /*      RGX_HWPERF_HW_3DSPMFINISHED             = 0x18, */
97         RGX_HWPERF_HW_3DKICK                    = 0x0B,
98
99         RGX_HWPERF_HW_3DFINISHED                = 0x0C,
100         RGX_HWPERF_HW_CDMKICK                   = 0x0D,
101         RGX_HWPERF_HW_CDMFINISHED               = 0x0E,
102         RGX_HWPERF_HW_TLAKICK                   = 0x0F,
103
104         RGX_HWPERF_HW_TLAFINISHED               = 0x10,
105         RGX_HWPERF_HW_3DSPMKICK                 = 0x11,
106         RGX_HWPERF_HW_PERIODIC                  = 0x12,
107         RGX_HWPERF_HW_RTUKICK                   = 0x13,
108         
109         RGX_HWPERF_HW_RTUFINISHED               = 0x14,
110         RGX_HWPERF_HW_SHGKICK                   = 0x15,
111         RGX_HWPERF_HW_SHGFINISHED               = 0x16,
112         RGX_HWPERF_HW_3DTQFINISHED              = 0x17,
113
114         RGX_HWPERF_HW_3DSPMFINISHED             = 0x18,
115
116         /* other types 0x1A..0x1F */
117         RGX_HWPERF_CLKS_CHG                             = 0x1A,
118         RGX_HWPERF_GPU_STATE_CHG                = 0x1B,
119
120         /* power types 0x20..0x27 */
121         RGX_HWPERF_PWR_EST_REQUEST              = 0x20,
122         RGX_HWPERF_PWR_EST_READY                = 0x21,
123         RGX_HWPERF_PWR_EST_RESULT               = 0x22,
124         RGX_HWPERF_PWR_CHG                              = 0x23,
125
126         /* context switch types 0x30..0x31 */
127         RGX_HWPERF_CSW_START                    = 0x30,
128         RGX_HWPERF_CSW_FINISHED                 = 0x31,
129         
130         /* last */
131         RGX_HWPERF_LAST_TYPE,
132
133         /* This enumeration must have a value that is a power of two as it is
134          * used in masks and a filter bit field (currently 64 bits long).
135          */
136         RGX_HWPERF_MAX_TYPE                             = 0x40
137 } RGX_HWPERF_EVENT_TYPE;
138
139 /* The event type values are incrementing integers for use as a shift ordinal
140  * in the event filtering process at the point events are generated.
141  * This scheme thus implies a limit of 63 event types.
142  */
143 BLD_ASSERT((RGX_HWPERF_LAST_TYPE<RGX_HWPERF_MAX_TYPE), rgx_hwperf_h)
144
145 /*! Type obsolete and will be removed in a later release, use RGXFWIF_DM */
146 typedef RGXFWIF_DM RGX_HWPERF_DM;
147 #define RGX_HWPERF_DM_GP        RGXFWIF_DM_GP
148 #define RGX_HWPERF_DM_2D        RGXFWIF_DM_2D
149 #define RGX_HWPERF_DM_TA        RGXFWIF_DM_TA
150 #define RGX_HWPERF_DM_3D        RGXFWIF_DM_3D
151 #define RGX_HWPERF_DM_CDM       RGXFWIF_DM_CDM
152 #define RGX_HWPERF_DM_RTU       RGXFWIF_DM_RTU
153 #define RGX_HWPERF_DM_SHG   RGXFWIF_DM_SHG
154 #define RGX_HWPERF_DM_LAST      RGXFWIF_DM_LAST
155
156
157 /******************************************************************************
158  *      Packet Format Version 2 Types
159  *****************************************************************************/
160
161 /*! Signature ASCII pattern 'HWP2' found in the first word of a HWPerfV2 packet
162  */
163 #define HWPERF_PACKET_V2_SIG            0x48575032
164 /*! Signature ASCII pattern 'HWPA' found in the first word of a HWPerfV2a packet
165  */
166 #define HWPERF_PACKET_V2A_SIG           0x48575041
167
168 /*! This structure defines version 2 of the packet format which is
169  * based around a header and a variable length data payload structure.
170  * The address of the next packet can be found by adding the ui16Size field
171  * in the header to the current packet address.
172  * Producers of packets must always ensure the size field is a multiple of 8
173  * as packets must start on an 8-byte granular address.
174  */
175 typedef struct
176 {
177         /* HEADER - packet header fields common to all packet types */
178         IMG_UINT32  ui32Sig;        /*!< Always the value HWPERF_PACKET_SIG */
179
180         IMG_UINT32  ui32Size;       /*!< Overall packet size in bytes, includes
181                                      * header and payload. Size is a 16-bit field
182                                      * stored in the 16 LSb. 16 MSb reserved.
183                                      * Use RGX_HWPERF_MAKE_SIZE_* and RGX_HWPERF_GET_SIZE
184                                      * macros to set/get, never write directly. */
185
186         IMG_UINT32  eTypeId;        /*!< Includes event type and META thread ID in
187                                      * the 16 LSb. 16 MSb reserved.
188                                      * Use RGX_HWPERF_MAKE_TYPEID and RGX_HWPERF_GET_*
189                                      * macros to set/get, never write directly. */
190
191         IMG_UINT32  ui32Ordinal;    /*!< Sequential number of the packet */
192         IMG_UINT64  ui64RGXTimer;   /*!< Value of RGX_CR_TIMER at event */
193
194         /* PAYLOAD - bytes from this point on in the buffer are from the
195          * RGX_HWPERF_V2_PACKET_DATA union which encodes the payload data specific
196          * to the event type set in the header. When the structure in the union
197          * has a variable length member e.g. HW packets the payload length
198          * varies.
199          */
200 } RGX_HWPERF_V2_PACKET_HDR, *RGX_PHWPERF_V2_PACKET_HDR;
201
202 RGX_FW_STRUCT_OFFSET_ASSERT(RGX_HWPERF_V2_PACKET_HDR, ui64RGXTimer)
203
204 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_V2_PACKET_HDR)
205
206
207 /*! Mask for use with the IMG_UINT32 ui32Size header field */
208 #define RGX_HWPERF_SIZE_MASK                    0xFFFFU
209
210 /*! Macro which takes a structure name and provides the packet size for
211  * a fixed size payload packet for assignment to the ui16Size field. */
212 #define RGX_HWPERF_MAKE_SIZE_FIXED(_struct)       ((IMG_UINT32)(RGX_HWPERF_SIZE_MASK&(sizeof(RGX_HWPERF_V2_PACKET_HDR)+sizeof(_struct))))
213
214 /*! Macro which takes the number of bytes written in the data payload of a
215  * packet for a variable size payload packet, rounds it up to 8 bytes where
216  * it may be assigned to the ui16Size field. */
217 #define RGX_HWPERF_MAKE_SIZE_VARIABLE(_size)       ((IMG_UINT32)(RGX_HWPERF_SIZE_MASK&(sizeof(RGX_HWPERF_V2_PACKET_HDR)+PVR_ALIGN(_size, 8))))
218
219 /*! Macro to obtain the size of the packet */
220 #define RGX_HWPERF_GET_SIZE(_packet_addr)    ((IMG_UINT16)(((_packet_addr)->ui32Size) & RGX_HWPERF_SIZE_MASK))
221
222 /*! Macro to obtain the size of the packet data */
223 #define RGX_HWPERF_GET_DATA_SIZE(_packet_addr)   (RGX_HWPERF_GET_SIZE(_packet_addr) - sizeof(RGX_HWPERF_V2_PACKET_HDR))
224
225
226 /*! Masks for use with the IMG_UINT32 eTypeId header field */
227 #define RGX_HWPERF_TYPEID_MASK                  0xFFFFU
228 #define RGX_HWPERF_TYPEID_THREAD_MASK   0x8000U
229 #define RGX_HWPERF_TYPEID_EVENT_MASK    (RGX_HWPERF_MAX_TYPE-1)
230
231 /*! Meta thread macros for encoding the ID into the type field of a packet */
232 #define RGX_HWPERF_META_THREAD_SHIFT    15U
233 #define RGX_HWPERF_META_THREAD_ID0              0x0U
234 #define RGX_HWPERF_META_THREAD_ID1              0x1U
235 /*! Obsolete, kept for source compatibility */
236 #define RGX_HWPERF_META_THREAD_MASK             0x1U
237
238 /*! Macros used to set the packet type and encode meta thread ID (0|1) within */
239 #define RGX_HWPERF_MAKE_TYPEID(_type,_thread) ((IMG_UINT32) ((RGX_HWPERF_TYPEID_THREAD_MASK&((_thread)<<RGX_HWPERF_META_THREAD_SHIFT)) | (RGX_HWPERF_TYPEID_EVENT_MASK&(_type))))
240
241 /*! Obtains the event type that generated the packet */
242 #define RGX_HWPERF_GET_TYPE(_packet_addr)            (((_packet_addr)->eTypeId) & RGX_HWPERF_TYPEID_EVENT_MASK)
243
244 /*! Obtains the META Thread number that generated the packet */
245 #define RGX_HWPERF_GET_THREAD_ID(_packet_addr)       (((((_packet_addr)->eTypeId)&RGX_HWPERF_TYPEID_THREAD_MASK) >> RGX_HWPERF_META_THREAD_SHIFT))
246
247 /*! Macros to obtain a typed pointer to a packet or data structure given a packet address */
248 #define RGX_HWPERF_GET_PACKET(_buffer_addr)            ((RGX_HWPERF_V2_PACKET_HDR*)  (_buffer_addr))
249 #define RGX_HWPERF_GET_PACKET_DATA_BYTES(_packet_addr) ((IMG_BYTE*) ( ((IMG_BYTE*)(_packet_addr)) +sizeof(RGX_HWPERF_V2_PACKET_HDR) ) )
250 #define RGX_HWPERF_GET_NEXT_PACKET(_packet_addr)       ((RGX_HWPERF_V2_PACKET_HDR*)  ( ((IMG_BYTE*)(_packet_addr))+(RGX_HWPERF_SIZE_MASK&(_packet_addr)->ui32Size)) )
251
252 /*! Obtains a typed pointer to a packet header given the packed data address */
253 #define RGX_HWPERF_GET_PACKET_HEADER(_packet_addr)     ((RGX_HWPERF_V2_PACKET_HDR*)  ( ((IMG_BYTE*)(_packet_addr)) - sizeof(RGX_HWPERF_V2_PACKET_HDR) ))
254
255
256 /*! This structure holds the field data of a Hardware packet.
257  */
258 #define RGX_HWPERF_HW_DATA_FIELDS_LIST \
259 IMG_UINT32 ui32DMCyc;        /*!< DataMaster cycle count register, 0 if none */\
260 IMG_UINT32 ui32FrameNum;     /*!< Frame number */\
261 IMG_UINT32 ui32PID;          /*!< Process identifier */\
262 IMG_UINT32 ui32DMContext;    /*!< RenderContext for a TA,3D, Compute context for CDM, etc. */\
263 IMG_UINT32 ui32RenderTarget; /*!< RenderTarget for a TA,3D, 0x0 otherwise */\
264 IMG_UINT32 ui32ExtJobRef; /*!< Externally provided job reference used to track work for debugging purposes */\
265 IMG_UINT32 ui32IntJobRef; /*!< Internally provided job reference used to track work for debugging purposes */\
266 IMG_UINT32 ui32TimeCorrIndex; /*!< Index to the time correlation at the time the packet was generated */
267
268 typedef struct
269 {
270         RGX_HWPERF_HW_DATA_FIELDS_LIST
271 } RGX_HWPERF_HW_DATA_FIELDS;
272
273 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_HW_DATA_FIELDS)
274
275
276 /******************************************************************************
277  *      API Types
278  *****************************************************************************/
279
280
281 /*! Mask macros for use with RGXCtrlHWPerf() API.
282  * RGX_HWPERF_EVENT_ALL is obsolete, use RGX_HWPERF_EVENT_MASK_ALL
283  */
284 #define RGX_HWPERF_EVENT_MASK_NONE          (IMG_UINT64_C(0x0000000000000000))
285 #define RGX_HWPERF_EVENT_MASK_ALL           (IMG_UINT64_C(0xFFFFFFFFFFFFFFFF))
286 #define RGX_HWPERF_EVENT_MASK_ALL_FW        (IMG_UINT64_C(0x000000000000007E))
287 #define RGX_HWPERF_EVENT_MASK_HW_KICKFINISH (IMG_UINT64_C(0x0000000001FBFF00))
288 #define RGX_HWPERF_EVENT_MASK_HW_PERIODIC   (IMG_UINT64_C(0x0000000000040000))
289 #define RGX_HWPERF_EVENT_MASK_ALL_HW        (RGX_HWPERF_EVENT_MASK_HW_KICKFINISH \
290                                             | RGX_HWPERF_EVENT_MASK_HW_PERIODIC)
291 #define RGX_HWPERF_EVENT_MASK_ALL_PWR_EST   (IMG_UINT64_C(0X0000000700000000))
292 #define RGX_HWPERF_EVENT_MASK_ALL_PWR       (IMG_UINT64_C(0X0000000800000000))
293 #define RGX_HWPERF_EVENT_MASK_VALUE(e)      (((IMG_UINT64)1)<<(e))
294
295 /*! Type used in the RGX API RGXConfigureAndEnableHWPerfCounters()
296  * It is used to configure the performance counter module in a layout
297  * block and allows one or more counters in the block to be 
298  * configured in one operation based on the counter select mask. The bit
299  * shifts for this are the values in RGX_HWPERF_CNTBLK_COUNTER_ID. This mask
300  * also encodes which values in the arrays are valid, for example, if bit 1 set
301  * then aui8Mode[1], aui16GroupSelect[1], aui16BitSelect[1], aui32BatchMax[1],
302  * and aui32BatchMin[1] must be set. If these array elements are all set to 
303  * 0 then the counter will not count and will not be in the HW event, 
304  * effectively disabling the counter from the callers point of view. 
305  * If any are non zero then the counter will be included in the HW event.
306  *
307  * Each layout block has 4 or 6 counters that can be programmed independently to
308  * profile the performance of a HW block. Each counter can be configured to
309  * accumulate statistics from 1 of 32 counter groups defined for that block.
310  * Each counter group can have up to 16 signals/bits defined that can be
311  * selected. Each counter may accumulate in one of two modes.
312  * See hwdefs/regapiperf.h for block/group/signal definitions.
313  */
314  typedef struct _RGX_HWPERF_CONFIG_CNTBLK_
315 {
316         /*! Counter block ID, see RGX_HWPERF_CNTBLK_ID */
317         IMG_UINT8       ui8BlockID;
318
319         /*! 4 or 6 LSBs are a mask of which counters to configure. Bit 0 is counter 0,
320          * bit 1 is counter 1 on so on. */
321         IMG_UINT8   ui8CounterSelect;
322
323         /*! 4 or 6 LSBs 0 for counting 1's in the group, 1 for treating the group
324          * signals as a number for unsigned addition. Bit 0 is counter 0, bit 1 is
325          * counter 1 on so on. This member relates to the MODE field
326          * in the RGX_CR_<N>_PERF_SELECTm register for each counter */
327         IMG_UINT8       ui8Mode;
328
329         /*! 5 or 6 LSBs used as the GROUP_SELECT field in the RGX_CR_<N>_PERF_SELECTm
330          * register. Array index 0 is counter 0, index 1 is counter 1 and so on. */
331         IMG_UINT8       aui8GroupSelect[RGX_HWPERF_CNTRS_IN_BLK];
332
333         /*! 16 LSBs used as the BIT_SELECT field in the RGX_CR_<N>_PERF_SELECTm
334          * register. Array indexes relate to counters as above. */
335         IMG_UINT16  aui16BitSelect[RGX_HWPERF_CNTRS_IN_BLK];
336
337         /*! 14 LSBs used as the BATCH_MAX field in the RGX_CR_<N>_PERF_SELECTm
338          * register. Array indexes relate to counters as above. */
339         IMG_UINT32  aui32BatchMax[RGX_HWPERF_CNTRS_IN_BLK];
340
341         /*! 14 LSBs used as the BATCH_MIN field in the RGX_CR_<N>_PERF_SELECTm
342          * register. Array indexes relate to counters as above. */
343         IMG_UINT32  aui32BatchMin[RGX_HWPERF_CNTRS_IN_BLK];
344 } RGX_HWPERF_CONFIG_CNTBLK;
345
346 RGX_FW_STRUCT_SIZE_ASSERT(RGX_HWPERF_CONFIG_CNTBLK)
347
348
349 #if defined (__cplusplus)
350 }
351 #endif
352
353 #endif /* RGX_HWPERF_KM_H_ */
354
355 /******************************************************************************
356  End of file
357 ******************************************************************************/
358