MALI: utgard: upgrade DDK to r7p0-00rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / include / linux / mali / mali_utgard_uk_types.h
1 /*
2  * Copyright (C) 2010-2016 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9
10  * Class Path Exception
11  * Linking this library statically or dynamically with other modules is making a combined work based on this library. 
12  * Thus, the terms and conditions of the GNU General Public License cover the whole combination.
13  * As a special exception, the copyright holders of this library give you permission to link this library with independent modules 
14  * to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting 
15  * executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions 
16  * of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify 
17  * this library, you may extend this exception to your version of the library, but you are not obligated to do so. 
18  * If you do not wish to do so, delete this exception statement from your version.
19  */
20
21 /**
22  * @file mali_uk_types.h
23  * Defines the types and constants used in the user-kernel interface
24  */
25
26 #ifndef __MALI_UTGARD_UK_TYPES_H__
27 #define __MALI_UTGARD_UK_TYPES_H__
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* Iteration functions depend on these values being consecutive. */
34 #define MALI_UK_TIMELINE_GP   0
35 #define MALI_UK_TIMELINE_PP   1
36 #define MALI_UK_TIMELINE_SOFT 2
37 #define MALI_UK_TIMELINE_MAX  3
38
39 #define MALI_UK_BIG_VARYING_SIZE  (1024*1024*2)
40
41 typedef struct {
42         u32 points[MALI_UK_TIMELINE_MAX];
43         s32 sync_fd;
44 } _mali_uk_fence_t;
45
46 /**
47  * @addtogroup uddapi Unified Device Driver (UDD) APIs
48  *
49  * @{
50  */
51
52 /**
53  * @addtogroup u_k_api UDD User/Kernel Interface (U/K) APIs
54  *
55  * @{
56  */
57
58 /** @defgroup _mali_uk_core U/K Core
59  * @{ */
60
61 /** Definition of subsystem numbers, to assist in creating a unique identifier
62  * for each U/K call.
63  *
64  * @see _mali_uk_functions */
65 typedef enum {
66         _MALI_UK_CORE_SUBSYSTEM,      /**< Core Group of U/K calls */
67         _MALI_UK_MEMORY_SUBSYSTEM,    /**< Memory Group of U/K calls */
68         _MALI_UK_PP_SUBSYSTEM,        /**< Fragment Processor Group of U/K calls */
69         _MALI_UK_GP_SUBSYSTEM,        /**< Vertex Processor Group of U/K calls */
70         _MALI_UK_PROFILING_SUBSYSTEM, /**< Profiling Group of U/K calls */
71         _MALI_UK_VSYNC_SUBSYSTEM,     /**< VSYNC Group of U/K calls */
72 } _mali_uk_subsystem_t;
73
74 /** Within a function group each function has its unique sequence number
75  * to assist in creating a unique identifier for each U/K call.
76  *
77  * An ordered pair of numbers selected from
78  * ( \ref _mali_uk_subsystem_t,\ref  _mali_uk_functions) will uniquely identify the
79  * U/K call across all groups of functions, and all functions. */
80 typedef enum {
81         /** Core functions */
82
83         _MALI_UK_OPEN                    = 0, /**< _mali_ukk_open() */
84         _MALI_UK_CLOSE,                       /**< _mali_ukk_close() */
85         _MALI_UK_WAIT_FOR_NOTIFICATION,       /**< _mali_ukk_wait_for_notification() */
86         _MALI_UK_GET_API_VERSION,             /**< _mali_ukk_get_api_version() */
87         _MALI_UK_POST_NOTIFICATION,           /**< _mali_ukk_post_notification() */
88         _MALI_UK_GET_USER_SETTING,            /**< _mali_ukk_get_user_setting() *//**< [out] */
89         _MALI_UK_GET_USER_SETTINGS,           /**< _mali_ukk_get_user_settings() *//**< [out] */
90         _MALI_UK_REQUEST_HIGH_PRIORITY,       /**< _mali_ukk_request_high_priority() */
91         _MALI_UK_TIMELINE_GET_LATEST_POINT,   /**< _mali_ukk_timeline_get_latest_point() */
92         _MALI_UK_TIMELINE_WAIT,               /**< _mali_ukk_timeline_wait() */
93         _MALI_UK_TIMELINE_CREATE_SYNC_FENCE,  /**< _mali_ukk_timeline_create_sync_fence() */
94         _MALI_UK_SOFT_JOB_START,              /**< _mali_ukk_soft_job_start() */
95         _MALI_UK_SOFT_JOB_SIGNAL,             /**< _mali_ukk_soft_job_signal() */
96         _MALI_UK_PENDING_SUBMIT,             /**< _mali_ukk_pending_submit() */
97
98         _MALI_GET_RK_KO_VERSION,                /* rk_ext */
99         _MALI_UK_GET_MALI_VERSION_IN_RK30,
100
101         /** Memory functions */
102
103         _MALI_UK_ALLOC_MEM                = 0,   /**< _mali_ukk_alloc_mem() */
104         _MALI_UK_FREE_MEM,                       /**< _mali_ukk_free_mem() */
105         _MALI_UK_BIND_MEM,                       /**< _mali_ukk_mem_bind() */
106         _MALI_UK_UNBIND_MEM,                     /**< _mali_ukk_mem_unbind() */
107         _MALI_UK_COW_MEM,                        /**< _mali_ukk_mem_cow() */
108         _MALI_UK_COW_MODIFY_RANGE,               /**< _mali_ukk_mem_cow_modify_range() */
109         _MALI_UK_RESIZE_MEM,                     /**<._mali_ukk_mem_resize() */
110         _MALI_UK_QUERY_MMU_PAGE_TABLE_DUMP_SIZE, /**< _mali_ukk_mem_get_mmu_page_table_dump_size() */
111         _MALI_UK_DUMP_MMU_PAGE_TABLE,            /**< _mali_ukk_mem_dump_mmu_page_table() */
112         _MALI_UK_DMA_BUF_GET_SIZE,               /**< _mali_ukk_dma_buf_get_size() */
113         _MALI_UK_MEM_WRITE_SAFE,                 /**< _mali_uku_mem_write_safe() */
114
115         /** Common functions for each core */
116
117         _MALI_UK_START_JOB           = 0,     /**< Start a Fragment/Vertex Processor Job on a core */
118         _MALI_UK_GET_NUMBER_OF_CORES,         /**< Get the number of Fragment/Vertex Processor cores */
119         _MALI_UK_GET_CORE_VERSION,            /**< Get the Fragment/Vertex Processor version compatible with all cores */
120
121         /** Fragment Processor Functions  */
122
123         _MALI_UK_PP_START_JOB            = _MALI_UK_START_JOB,            /**< _mali_ukk_pp_start_job() */
124         _MALI_UK_GET_PP_NUMBER_OF_CORES  = _MALI_UK_GET_NUMBER_OF_CORES,  /**< _mali_ukk_get_pp_number_of_cores() */
125         _MALI_UK_GET_PP_CORE_VERSION     = _MALI_UK_GET_CORE_VERSION,     /**< _mali_ukk_get_pp_core_version() */
126         _MALI_UK_PP_DISABLE_WB,                                           /**< _mali_ukk_pp_job_disable_wb() */
127         _MALI_UK_PP_AND_GP_START_JOB,                                     /**< _mali_ukk_pp_and_gp_start_job() */
128
129         /** Vertex Processor Functions  */
130
131         _MALI_UK_GP_START_JOB            = _MALI_UK_START_JOB,            /**< _mali_ukk_gp_start_job() */
132         _MALI_UK_GET_GP_NUMBER_OF_CORES  = _MALI_UK_GET_NUMBER_OF_CORES,  /**< _mali_ukk_get_gp_number_of_cores() */
133         _MALI_UK_GET_GP_CORE_VERSION     = _MALI_UK_GET_CORE_VERSION,     /**< _mali_ukk_get_gp_core_version() */
134         _MALI_UK_GP_SUSPEND_RESPONSE,                                     /**< _mali_ukk_gp_suspend_response() */
135
136         /** Profiling functions */
137
138         _MALI_UK_PROFILING_ADD_EVENT     = 0, /**< __mali_uku_profiling_add_event() */
139         _MALI_UK_PROFILING_REPORT_SW_COUNTERS,/**< __mali_uku_profiling_report_sw_counters() */
140         _MALI_UK_PROFILING_MEMORY_USAGE_GET,  /**< __mali_uku_profiling_memory_usage_get() */
141         _MALI_UK_PROFILING_STREAM_FD_GET, /** < __mali_uku_profiling_stream_fd_get() */
142         _MALI_UK_PROFILING_CONTROL_SET, /** < __mali_uku_profiling_control_set() */
143
144         /** VSYNC reporting fuctions */
145         _MALI_UK_VSYNC_EVENT_REPORT      = 0, /**< _mali_ukk_vsync_event_report() */
146 } _mali_uk_functions;
147
148 /** @defgroup _mali_uk_getsysteminfo U/K Get System Info
149  * @{ */
150
151 /**
152  * Type definition for the core version number.
153  * Used when returning the version number read from a core
154  *
155  * Its format is that of the 32-bit Version register for a particular core.
156  * Refer to the "Mali200 and MaliGP2 3D Graphics Processor Technical Reference
157  * Manual", ARM DDI 0415C, for more information.
158  */
159 typedef u32 _mali_core_version;
160
161 /** @} */ /* end group _mali_uk_core */
162
163
164 /** @defgroup _mali_uk_gp U/K Vertex Processor
165  * @{ */
166
167 /** @defgroup _mali_uk_gp_suspend_response_s Vertex Processor Suspend Response
168  * @{ */
169
170 /** @brief Arguments for _mali_ukk_gp_suspend_response()
171  *
172  * When _mali_wait_for_notification() receives notification that a
173  * Vertex Processor job was suspended, you need to send a response to indicate
174  * what needs to happen with this job. You can either abort or resume the job.
175  *
176  * - set @c code to indicate response code. This is either @c _MALIGP_JOB_ABORT or
177  * @c _MALIGP_JOB_RESUME_WITH_NEW_HEAP to indicate you will provide a new heap
178  * for the job that will resolve the out of memory condition for the job.
179  * - copy the @c cookie value from the @c _mali_uk_gp_job_suspended_s notification;
180  * this is an identifier for the suspended job
181  * - set @c arguments[0] and @c arguments[1] to zero if you abort the job. If
182  * you resume it, @c argument[0] should specify the Mali start address for the new
183  * heap and @c argument[1] the Mali end address of the heap.
184  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
185  *
186  */
187 typedef enum _maligp_job_suspended_response_code {
188         _MALIGP_JOB_ABORT,                  /**< Abort the Vertex Processor job */
189         _MALIGP_JOB_RESUME_WITH_NEW_HEAP    /**< Resume the Vertex Processor job with a new heap */
190 } _maligp_job_suspended_response_code;
191
192 typedef struct {
193         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
194         u32 cookie;                     /**< [in] cookie from the _mali_uk_gp_job_suspended_s notification */
195         _maligp_job_suspended_response_code code; /**< [in] abort or resume response code, see \ref _maligp_job_suspended_response_code */
196         u32 arguments[2];               /**< [in] 0 when aborting a job. When resuming a job, the Mali start and end address for a new heap to resume the job with */
197 } _mali_uk_gp_suspend_response_s;
198
199 /** @} */ /* end group _mali_uk_gp_suspend_response_s */
200
201 /** @defgroup _mali_uk_gpstartjob_s Vertex Processor Start Job
202  * @{ */
203
204 /** @brief Status indicating the result of the execution of a Vertex or Fragment processor job  */
205 typedef enum {
206         _MALI_UK_JOB_STATUS_END_SUCCESS         = 1 << (16 + 0),
207         _MALI_UK_JOB_STATUS_END_OOM             = 1 << (16 + 1),
208         _MALI_UK_JOB_STATUS_END_ABORT           = 1 << (16 + 2),
209         _MALI_UK_JOB_STATUS_END_TIMEOUT_SW      = 1 << (16 + 3),
210         _MALI_UK_JOB_STATUS_END_HANG            = 1 << (16 + 4),
211         _MALI_UK_JOB_STATUS_END_SEG_FAULT       = 1 << (16 + 5),
212         _MALI_UK_JOB_STATUS_END_ILLEGAL_JOB     = 1 << (16 + 6),
213         _MALI_UK_JOB_STATUS_END_UNKNOWN_ERR     = 1 << (16 + 7),
214         _MALI_UK_JOB_STATUS_END_SHUTDOWN        = 1 << (16 + 8),
215         _MALI_UK_JOB_STATUS_END_SYSTEM_UNUSABLE = 1 << (16 + 9)
216 } _mali_uk_job_status;
217
218 #define MALIGP2_NUM_REGS_FRAME (6)
219
220 /** @brief Arguments for _mali_ukk_gp_start_job()
221  *
222  * To start a Vertex Processor job
223  * - associate the request with a reference to a @c mali_gp_job_info by setting
224  * user_job_ptr to the address of the @c mali_gp_job_info of the job.
225  * - set @c priority to the priority of the @c mali_gp_job_info
226  * - specify a timeout for the job by setting @c watchdog_msecs to the number of
227  * milliseconds the job is allowed to run. Specifying a value of 0 selects the
228  * default timeout in use by the device driver.
229  * - copy the frame registers from the @c mali_gp_job_info into @c frame_registers.
230  * - set the @c perf_counter_flag, @c perf_counter_src0 and @c perf_counter_src1 to zero
231  * for a non-instrumented build. For an instrumented build you can use up
232  * to two performance counters. Set the corresponding bit in @c perf_counter_flag
233  * to enable them. @c perf_counter_src0 and @c perf_counter_src1 specify
234  * the source of what needs to get counted (e.g. number of vertex loader
235  * cache hits). For source id values, see ARM DDI0415A, Table 3-60.
236  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
237  *
238  * When @c _mali_ukk_gp_start_job() returns @c _MALI_OSK_ERR_OK, status contains the
239  * result of the request (see \ref _mali_uk_start_job_status). If the job could
240  * not get started (@c _MALI_UK_START_JOB_NOT_STARTED_DO_REQUEUE) it should be
241  * tried again.
242  *
243  * After the job has started, @c _mali_wait_for_notification() will be notified
244  * that the job finished or got suspended. It may get suspended due to
245  * resource shortage. If it finished (see _mali_ukk_wait_for_notification())
246  * the notification will contain a @c _mali_uk_gp_job_finished_s result. If
247  * it got suspended the notification will contain a @c _mali_uk_gp_job_suspended_s
248  * result.
249  *
250  * The @c _mali_uk_gp_job_finished_s contains the job status (see \ref _mali_uk_job_status),
251  * the number of milliseconds the job took to render, and values of core registers
252  * when the job finished (irq status, performance counters, renderer list
253  * address). A job has finished succesfully when its status is
254  * @c _MALI_UK_JOB_STATUS_FINISHED. If the hardware detected a timeout while rendering
255  * the job, or software detected the job is taking more than watchdog_msecs to
256  * complete, the status will indicate @c _MALI_UK_JOB_STATUS_HANG.
257  * If the hardware detected a bus error while accessing memory associated with the
258  * job, status will indicate @c _MALI_UK_JOB_STATUS_SEG_FAULT.
259  * status will indicate @c _MALI_UK_JOB_STATUS_NOT_STARTED if the driver had to
260  * stop the job but the job didn't start on the hardware yet, e.g. when the
261  * driver shutdown.
262  *
263  * In case the job got suspended, @c _mali_uk_gp_job_suspended_s contains
264  * the @c user_job_ptr identifier used to start the job with, the @c reason
265  * why the job stalled (see \ref _maligp_job_suspended_reason) and a @c cookie
266  * to identify the core on which the job stalled.  This @c cookie will be needed
267  * when responding to this nofication by means of _mali_ukk_gp_suspend_response().
268  * (see _mali_ukk_gp_suspend_response()). The response is either to abort or
269  * resume the job. If the job got suspended due to an out of memory condition
270  * you may be able to resolve this by providing more memory and resuming the job.
271  *
272  */
273 typedef struct {
274         u64 ctx;                          /**< [in,out] user-kernel context (trashed on output) */
275         u64 user_job_ptr;                   /**< [in] identifier for the job in user space, a @c mali_gp_job_info* */
276         u32 priority;                       /**< [in] job priority. A lower number means higher priority */
277         u32 frame_registers[MALIGP2_NUM_REGS_FRAME]; /**< [in] core specific registers associated with this job */
278         u32 perf_counter_flag;              /**< [in] bitmask indicating which performance counters to enable, see \ref _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE and related macro definitions */
279         u32 perf_counter_src0;              /**< [in] source id for performance counter 0 (see ARM DDI0415A, Table 3-60) */
280         u32 perf_counter_src1;              /**< [in] source id for performance counter 1 (see ARM DDI0415A, Table 3-60) */
281         u32 frame_builder_id;               /**< [in] id of the originating frame builder */
282         u32 flush_id;                       /**< [in] flush id within the originating frame builder */
283         _mali_uk_fence_t fence;             /**< [in] fence this job must wait on */
284         u64 timeline_point_ptr;            /**< [in,out] pointer to u32: location where point on gp timeline for this job will be written */
285         u32 varying_memsize;            /** < [in] size of varying memory to use deffer bind*/
286         u32 deferred_mem_num;
287         u64 deferred_mem_list;         /** < [in] memory hanlde list of varying buffer to use deffer bind */
288 } _mali_uk_gp_start_job_s;
289
290 #define _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE (1<<0) /**< Enable performance counter SRC0 for a job */
291 #define _MALI_PERFORMANCE_COUNTER_FLAG_SRC1_ENABLE (1<<1) /**< Enable performance counter SRC1 for a job */
292 #define _MALI_PERFORMANCE_COUNTER_FLAG_HEATMAP_ENABLE (1<<2) /**< Enable per tile (aka heatmap) generation with for a job (using the enabled counter sources) */
293
294 /** @} */ /* end group _mali_uk_gpstartjob_s */
295
296 typedef struct {
297         u64 user_job_ptr;               /**< [out] identifier for the job in user space */
298         _mali_uk_job_status status;     /**< [out] status of finished job */
299         u32 heap_current_addr;          /**< [out] value of the GP PLB PL heap start address register */
300         u32 perf_counter0;              /**< [out] value of performance counter 0 (see ARM DDI0415A) */
301         u32 perf_counter1;              /**< [out] value of performance counter 1 (see ARM DDI0415A) */
302         u32 pending_big_job_num;
303 } _mali_uk_gp_job_finished_s;
304
305 typedef struct {
306         u64 user_job_ptr;                    /**< [out] identifier for the job in user space */
307         u32 cookie;                          /**< [out] identifier for the core in kernel space on which the job stalled */
308 } _mali_uk_gp_job_suspended_s;
309
310 /** @} */ /* end group _mali_uk_gp */
311
312
313 /** @defgroup _mali_uk_pp U/K Fragment Processor
314  * @{ */
315
316 #define _MALI_PP_MAX_SUB_JOBS 8
317
318 #define _MALI_PP_MAX_FRAME_REGISTERS ((0x058/4)+1)
319
320 #define _MALI_PP_MAX_WB_REGISTERS ((0x02C/4)+1)
321
322 #define _MALI_DLBU_MAX_REGISTERS 4
323
324 /** Flag for _mali_uk_pp_start_job_s */
325 #define _MALI_PP_JOB_FLAG_NO_NOTIFICATION (1<<0)
326 #define _MALI_PP_JOB_FLAG_IS_WINDOW_SURFACE (1<<1)
327 #define _MALI_PP_JOB_FLAG_PROTECTED (1<<2)
328
329 /** @defgroup _mali_uk_ppstartjob_s Fragment Processor Start Job
330  * @{ */
331
332 /** @brief Arguments for _mali_ukk_pp_start_job()
333  *
334  * To start a Fragment Processor job
335  * - associate the request with a reference to a mali_pp_job by setting
336  * @c user_job_ptr to the address of the @c mali_pp_job of the job.
337  * - set @c priority to the priority of the mali_pp_job
338  * - specify a timeout for the job by setting @c watchdog_msecs to the number of
339  * milliseconds the job is allowed to run. Specifying a value of 0 selects the
340  * default timeout in use by the device driver.
341  * - copy the frame registers from the @c mali_pp_job into @c frame_registers.
342  * For MALI200 you also need to copy the write back 0,1 and 2 registers.
343  * - set the @c perf_counter_flag, @c perf_counter_src0 and @c perf_counter_src1 to zero
344  * for a non-instrumented build. For an instrumented build you can use up
345  * to two performance counters. Set the corresponding bit in @c perf_counter_flag
346  * to enable them. @c perf_counter_src0 and @c perf_counter_src1 specify
347  * the source of what needs to get counted (e.g. number of vertex loader
348  * cache hits). For source id values, see ARM DDI0415A, Table 3-60.
349  * - pass in the user-kernel context in @c ctx that was returned from _mali_ukk_open()
350  *
351  * When _mali_ukk_pp_start_job() returns @c _MALI_OSK_ERR_OK, @c status contains the
352  * result of the request (see \ref _mali_uk_start_job_status). If the job could
353  * not get started (@c _MALI_UK_START_JOB_NOT_STARTED_DO_REQUEUE) it should be
354  * tried again.
355  *
356  * After the job has started, _mali_wait_for_notification() will be notified
357  * when the job finished. The notification will contain a
358  * @c _mali_uk_pp_job_finished_s result. It contains the @c user_job_ptr
359  * identifier used to start the job with, the job @c status (see \ref _mali_uk_job_status),
360  * the number of milliseconds the job took to render, and values of core registers
361  * when the job finished (irq status, performance counters, renderer list
362  * address). A job has finished succesfully when its status is
363  * @c _MALI_UK_JOB_STATUS_FINISHED. If the hardware detected a timeout while rendering
364  * the job, or software detected the job is taking more than @c watchdog_msecs to
365  * complete, the status will indicate @c _MALI_UK_JOB_STATUS_HANG.
366  * If the hardware detected a bus error while accessing memory associated with the
367  * job, status will indicate @c _MALI_UK_JOB_STATUS_SEG_FAULT.
368  * status will indicate @c _MALI_UK_JOB_STATUS_NOT_STARTED if the driver had to
369  * stop the job but the job didn't start on the hardware yet, e.g. when the
370  * driver shutdown.
371  *
372  */
373 typedef struct {
374         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
375         u64 user_job_ptr;               /**< [in] identifier for the job in user space */
376         u32 priority;                   /**< [in] job priority. A lower number means higher priority */
377         u32 frame_registers[_MALI_PP_MAX_FRAME_REGISTERS];         /**< [in] core specific registers associated with first sub job, see ARM DDI0415A */
378         u32 frame_registers_addr_frame[_MALI_PP_MAX_SUB_JOBS - 1]; /**< [in] ADDR_FRAME registers for sub job 1-7 */
379         u32 frame_registers_addr_stack[_MALI_PP_MAX_SUB_JOBS - 1]; /**< [in] ADDR_STACK registers for sub job 1-7 */
380         u32 wb0_registers[_MALI_PP_MAX_WB_REGISTERS];
381         u32 wb1_registers[_MALI_PP_MAX_WB_REGISTERS];
382         u32 wb2_registers[_MALI_PP_MAX_WB_REGISTERS];
383         u32 dlbu_registers[_MALI_DLBU_MAX_REGISTERS]; /**< [in] Dynamic load balancing unit registers */
384         u32 num_cores;                      /**< [in] Number of cores to set up (valid range: 1-8(M450) or 4(M400)) */
385         u32 perf_counter_flag;              /**< [in] bitmask indicating which performance counters to enable, see \ref _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE and related macro definitions */
386         u32 perf_counter_src0;              /**< [in] source id for performance counter 0 (see ARM DDI0415A, Table 3-60) */
387         u32 perf_counter_src1;              /**< [in] source id for performance counter 1 (see ARM DDI0415A, Table 3-60) */
388         u32 frame_builder_id;               /**< [in] id of the originating frame builder */
389         u32 flush_id;                       /**< [in] flush id within the originating frame builder */
390         u32 flags;                          /**< [in] See _MALI_PP_JOB_FLAG_* for a list of avaiable flags */
391         u32 tilesx;                         /**< [in] number of tiles in the x direction (needed for heatmap generation */
392         u32 tilesy;                         /**< [in] number of tiles in y direction (needed for reading the heatmap memory) */
393         u32 heatmap_mem;                    /**< [in] memory address to store counter values per tile (aka heatmap) */
394         u32 num_memory_cookies;             /**< [in] number of memory cookies attached to job */
395         u64 memory_cookies;               /**< [in] pointer to array of u32 memory cookies attached to job */
396         _mali_uk_fence_t fence;             /**< [in] fence this job must wait on */
397         u64 timeline_point_ptr;           /**< [in,out] pointer to location of u32 where point on pp timeline for this job will be written */
398 } _mali_uk_pp_start_job_s;
399
400 typedef struct {
401         u64 ctx;       /**< [in,out] user-kernel context (trashed on output) */
402         u64 gp_args;   /**< [in,out] GP uk arguments (see _mali_uk_gp_start_job_s) */
403         u64 pp_args;   /**< [in,out] PP uk arguments (see _mali_uk_pp_start_job_s) */
404 } _mali_uk_pp_and_gp_start_job_s;
405
406 /** @} */ /* end group _mali_uk_ppstartjob_s */
407
408 typedef struct {
409         u64 user_job_ptr;                          /**< [out] identifier for the job in user space */
410         _mali_uk_job_status status;                /**< [out] status of finished job */
411         u32 perf_counter0[_MALI_PP_MAX_SUB_JOBS];  /**< [out] value of perfomance counter 0 (see ARM DDI0415A), one for each sub job */
412         u32 perf_counter1[_MALI_PP_MAX_SUB_JOBS];  /**< [out] value of perfomance counter 1 (see ARM DDI0415A), one for each sub job */
413         u32 perf_counter_src0;
414         u32 perf_counter_src1;
415 } _mali_uk_pp_job_finished_s;
416
417 typedef struct {
418         u32 number_of_enabled_cores;               /**< [out] the new number of enabled cores */
419 } _mali_uk_pp_num_cores_changed_s;
420
421
422
423 /**
424  * Flags to indicate write-back units
425  */
426 typedef enum {
427         _MALI_UK_PP_JOB_WB0 = 1,
428         _MALI_UK_PP_JOB_WB1 = 2,
429         _MALI_UK_PP_JOB_WB2 = 4,
430 } _mali_uk_pp_job_wbx_flag;
431
432 typedef struct {
433         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
434         u32 fb_id;                      /**< [in] Frame builder ID of job to disable WB units for */
435         u32 wb0_memory;
436         u32 wb1_memory;
437         u32 wb2_memory;
438 } _mali_uk_pp_disable_wb_s;
439
440
441 /** @} */ /* end group _mali_uk_pp */
442
443 /** @defgroup _mali_uk_soft_job U/K Soft Job
444  * @{ */
445
446 typedef struct {
447         u64 ctx;                            /**< [in,out] user-kernel context (trashed on output) */
448         u64 user_job;                       /**< [in] identifier for the job in user space */
449         u64 job_id_ptr;                     /**< [in,out] pointer to location of u32 where job id will be written */
450         _mali_uk_fence_t fence;             /**< [in] fence this job must wait on */
451         u32 point;                          /**< [out] point on soft timeline for this job */
452         u32 type;                           /**< [in] type of soft job */
453 } _mali_uk_soft_job_start_s;
454
455 typedef struct {
456         u64 user_job;                       /**< [out] identifier for the job in user space */
457 } _mali_uk_soft_job_activated_s;
458
459 typedef struct {
460         u64 ctx;                          /**< [in,out] user-kernel context (trashed on output) */
461         u32 job_id;                         /**< [in] id for soft job */
462 } _mali_uk_soft_job_signal_s;
463
464 /** @} */ /* end group _mali_uk_soft_job */
465
466 typedef struct {
467         u32 counter_id;
468         u32 key;
469         int enable;
470 } _mali_uk_annotate_profiling_mem_counter_s;
471
472 typedef struct {
473         u32 sampling_rate;
474         int enable;
475 } _mali_uk_annotate_profiling_enable_s;
476
477
478 /** @addtogroup _mali_uk_core U/K Core
479  * @{ */
480
481 /** @defgroup _mali_uk_waitfornotification_s Wait For Notification
482  * @{ */
483
484 /** @brief Notification type encodings
485  *
486  * Each Notification type is an ordered pair of (subsystem,id), and is unique.
487  *
488  * The encoding of subsystem,id into a 32-bit word is:
489  * encoding = (( subsystem << _MALI_NOTIFICATION_SUBSYSTEM_SHIFT ) & _MALI_NOTIFICATION_SUBSYSTEM_MASK)
490  *            | (( id <<  _MALI_NOTIFICATION_ID_SHIFT ) & _MALI_NOTIFICATION_ID_MASK)
491  *
492  * @see _mali_uk_wait_for_notification_s
493  */
494 typedef enum {
495         /** core notifications */
496
497         _MALI_NOTIFICATION_CORE_SHUTDOWN_IN_PROGRESS = (_MALI_UK_CORE_SUBSYSTEM << 16) | 0x20,
498         _MALI_NOTIFICATION_APPLICATION_QUIT = (_MALI_UK_CORE_SUBSYSTEM << 16) | 0x40,
499         _MALI_NOTIFICATION_SETTINGS_CHANGED = (_MALI_UK_CORE_SUBSYSTEM << 16) | 0x80,
500         _MALI_NOTIFICATION_SOFT_ACTIVATED = (_MALI_UK_CORE_SUBSYSTEM << 16) | 0x100,
501
502         /** Fragment Processor notifications */
503
504         _MALI_NOTIFICATION_PP_FINISHED = (_MALI_UK_PP_SUBSYSTEM << 16) | 0x10,
505         _MALI_NOTIFICATION_PP_NUM_CORE_CHANGE = (_MALI_UK_PP_SUBSYSTEM << 16) | 0x20,
506
507         /** Vertex Processor notifications */
508
509         _MALI_NOTIFICATION_GP_FINISHED = (_MALI_UK_GP_SUBSYSTEM << 16) | 0x10,
510         _MALI_NOTIFICATION_GP_STALLED = (_MALI_UK_GP_SUBSYSTEM << 16) | 0x20,
511
512         /** Profiling notifications */
513         _MALI_NOTIFICATION_ANNOTATE_PROFILING_MEM_COUNTER = (_MALI_UK_PROFILING_SUBSYSTEM << 16) | 0x10,
514         _MALI_NOTIFICATION_ANNOTATE_PROFILING_ENABLE = (_MALI_UK_PROFILING_SUBSYSTEM << 16) | 0x20,
515 } _mali_uk_notification_type;
516
517 /** to assist in splitting up 32-bit notification value in subsystem and id value */
518 #define _MALI_NOTIFICATION_SUBSYSTEM_MASK 0xFFFF0000
519 #define _MALI_NOTIFICATION_SUBSYSTEM_SHIFT 16
520 #define _MALI_NOTIFICATION_ID_MASK 0x0000FFFF
521 #define _MALI_NOTIFICATION_ID_SHIFT 0
522
523
524 /** @brief Enumeration of possible settings which match mali_setting_t in user space
525  *
526  *
527  */
528 typedef enum {
529         _MALI_UK_USER_SETTING_SW_EVENTS_ENABLE = 0,
530         _MALI_UK_USER_SETTING_COLORBUFFER_CAPTURE_ENABLED,
531         _MALI_UK_USER_SETTING_DEPTHBUFFER_CAPTURE_ENABLED,
532         _MALI_UK_USER_SETTING_STENCILBUFFER_CAPTURE_ENABLED,
533         _MALI_UK_USER_SETTING_PER_TILE_COUNTERS_CAPTURE_ENABLED,
534         _MALI_UK_USER_SETTING_BUFFER_CAPTURE_COMPOSITOR,
535         _MALI_UK_USER_SETTING_BUFFER_CAPTURE_WINDOW,
536         _MALI_UK_USER_SETTING_BUFFER_CAPTURE_OTHER,
537         _MALI_UK_USER_SETTING_BUFFER_CAPTURE_N_FRAMES,
538         _MALI_UK_USER_SETTING_BUFFER_CAPTURE_RESIZE_FACTOR,
539         _MALI_UK_USER_SETTING_SW_COUNTER_ENABLED,
540         _MALI_UK_USER_SETTING_MAX,
541 } _mali_uk_user_setting_t;
542
543 /* See mali_user_settings_db.c */
544 extern const char *_mali_uk_user_setting_descriptions[];
545 #define _MALI_UK_USER_SETTING_DESCRIPTIONS \
546         {                                           \
547                 "sw_events_enable",                 \
548                 "colorbuffer_capture_enable",       \
549                 "depthbuffer_capture_enable",       \
550                 "stencilbuffer_capture_enable",     \
551                 "per_tile_counters_enable",         \
552                 "buffer_capture_compositor",        \
553                 "buffer_capture_window",            \
554                 "buffer_capture_other",             \
555                 "buffer_capture_n_frames",          \
556                 "buffer_capture_resize_factor",     \
557                 "sw_counters_enable",               \
558         };
559
560 /** @brief struct to hold the value to a particular setting as seen in the kernel space
561  */
562 typedef struct {
563         _mali_uk_user_setting_t setting;
564         u32 value;
565 } _mali_uk_settings_changed_s;
566
567 /** @brief Arguments for _mali_ukk_wait_for_notification()
568  *
569  * On successful return from _mali_ukk_wait_for_notification(), the members of
570  * this structure will indicate the reason for notification.
571  *
572  * Specifically, the source of the notification can be identified by the
573  * subsystem and id fields of the mali_uk_notification_type in the code.type
574  * member. The type member is encoded in a way to divide up the types into a
575  * subsystem field, and a per-subsystem ID field. See
576  * _mali_uk_notification_type for more information.
577  *
578  * Interpreting the data union member depends on the notification type:
579  *
580  * - type == _MALI_NOTIFICATION_CORE_SHUTDOWN_IN_PROGRESS
581  *     - The kernel side is shutting down. No further
582  * _mali_uk_wait_for_notification() calls should be made.
583  *     - In this case, the value of the data union member is undefined.
584  *     - This is used to indicate to the user space client that it should close
585  * the connection to the Mali Device Driver.
586  * - type == _MALI_NOTIFICATION_PP_FINISHED
587  *    - The notification data is of type _mali_uk_pp_job_finished_s. It contains the user_job_ptr
588  * identifier used to start the job with, the job status, the number of milliseconds the job took to render,
589  * and values of core registers when the job finished (irq status, performance counters, renderer list
590  * address).
591  *    - A job has finished succesfully when its status member is _MALI_UK_JOB_STATUS_FINISHED.
592  *    - If the hardware detected a timeout while rendering the job, or software detected the job is
593  * taking more than watchdog_msecs (see _mali_ukk_pp_start_job()) to complete, the status member will
594  * indicate _MALI_UK_JOB_STATUS_HANG.
595  *    - If the hardware detected a bus error while accessing memory associated with the job, status will
596  * indicate _MALI_UK_JOB_STATUS_SEG_FAULT.
597  *    - Status will indicate MALI_UK_JOB_STATUS_NOT_STARTED if the driver had to stop the job but the job
598  * didn't start the hardware yet, e.g. when the driver closes.
599  * - type == _MALI_NOTIFICATION_GP_FINISHED
600  *     - The notification data is of type _mali_uk_gp_job_finished_s. The notification is similar to that of
601  * type == _MALI_NOTIFICATION_PP_FINISHED, except that several other GP core register values are returned.
602  * The status values have the same meaning for type == _MALI_NOTIFICATION_PP_FINISHED.
603  * - type == _MALI_NOTIFICATION_GP_STALLED
604  *     - The nofication data is of type _mali_uk_gp_job_suspended_s. It contains the user_job_ptr
605  * identifier used to start the job with, the reason why the job stalled and a cookie to identify the core on
606  * which the job stalled.
607  *     - The reason member of gp_job_suspended is set to _MALIGP_JOB_SUSPENDED_OUT_OF_MEMORY
608  * when the polygon list builder unit has run out of memory.
609  */
610 typedef struct {
611         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
612         _mali_uk_notification_type type; /**< [out] Type of notification available */
613         union {
614                 _mali_uk_gp_job_suspended_s gp_job_suspended;/**< [out] Notification data for _MALI_NOTIFICATION_GP_STALLED notification type */
615                 _mali_uk_gp_job_finished_s  gp_job_finished; /**< [out] Notification data for _MALI_NOTIFICATION_GP_FINISHED notification type */
616                 _mali_uk_pp_job_finished_s  pp_job_finished; /**< [out] Notification data for _MALI_NOTIFICATION_PP_FINISHED notification type */
617                 _mali_uk_settings_changed_s setting_changed;/**< [out] Notification data for _MALI_NOTIFICAATION_SETTINGS_CHANGED notification type */
618                 _mali_uk_soft_job_activated_s soft_job_activated; /**< [out] Notification data for _MALI_NOTIFICATION_SOFT_ACTIVATED notification type */
619                 _mali_uk_annotate_profiling_mem_counter_s profiling_mem_counter;
620                 _mali_uk_annotate_profiling_enable_s profiling_enable;
621         } data;
622 } _mali_uk_wait_for_notification_s;
623
624 /** @brief Arguments for _mali_ukk_post_notification()
625  *
626  * Posts the specified notification to the notification queue for this application.
627  * This is used to send a quit message to the callback thread.
628  */
629 typedef struct {
630         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
631         _mali_uk_notification_type type; /**< [in] Type of notification to post */
632 } _mali_uk_post_notification_s;
633
634 /** @} */ /* end group _mali_uk_waitfornotification_s */
635
636 /** @defgroup _mali_uk_getapiversion_s Get API Version
637  * @{ */
638
639 /** helpers for Device Driver API version handling */
640
641 /** @brief Encode a version ID from a 16-bit input
642  *
643  * @note the input is assumed to be 16 bits. It must not exceed 16 bits. */
644 #define _MAKE_VERSION_ID(x) (((x) << 16UL) | (x))
645
646 /** @brief Check whether a 32-bit value is likely to be Device Driver API
647  * version ID. */
648 #define _IS_VERSION_ID(x) (((x) & 0xFFFF) == (((x) >> 16UL) & 0xFFFF))
649
650 /** @brief Decode a 16-bit version number from a 32-bit Device Driver API version
651  * ID */
652 #define _GET_VERSION(x) (((x) >> 16UL) & 0xFFFF)
653
654 /** @brief Determine whether two 32-bit encoded version IDs match */
655 #define _IS_API_MATCH(x, y) (IS_VERSION_ID((x)) && IS_VERSION_ID((y)) && (GET_VERSION((x)) == GET_VERSION((y))))
656  /**
657   * RK MALI version code
658   */
659 #define _MALI_RK_LIBS_VERSION 1
660
661 /**
662  * API version define.
663  * Indicates the version of the kernel API
664  * The version is a 16bit integer incremented on each API change.
665  * The 16bit integer is stored twice in a 32bit integer
666  * For example, for version 1 the value would be 0x00010001
667  */
668 #define _MALI_API_VERSION 900
669 #define _MALI_UK_API_VERSION _MAKE_VERSION_ID(_MALI_API_VERSION)
670
671 /**
672  * The API version is a 16-bit integer stored in both the lower and upper 16-bits
673  * of a 32-bit value. The 16-bit API version value is incremented on each API
674  * change. Version 1 would be 0x00010001. Used in _mali_uk_get_api_version_s.
675  */
676 typedef u32 _mali_uk_api_version;
677
678 /** @brief Arguments for _mali_uk_get_api_version()
679  *
680  * The user-side interface version must be written into the version member,
681  * encoded using _MAKE_VERSION_ID(). It will be compared to the API version of
682  * the kernel-side interface.
683  *
684  * On successful return, the version member will be the API version of the
685  * kernel-side interface. _MALI_UK_API_VERSION macro defines the current version
686  * of the API.
687  *
688  * The compatible member must be checked to see if the version of the user-side
689  * interface is compatible with the kernel-side interface, since future versions
690  * of the interface may be backwards compatible.
691  */
692 typedef struct {
693         u32 ctx;                        /**< [in,out] user-kernel context (trashed on output) */
694         _mali_uk_api_version version;   /**< [in,out] API version of user-side interface. */
695         int compatible;                 /**< [out] @c 1 when @version is compatible, @c 0 otherwise */
696 } _mali_uk_get_api_version_s;
697
698 /** @brief Arguments for _mali_uk_get_api_version_v2()
699  *
700  * The user-side interface version must be written into the version member,
701  * encoded using _MAKE_VERSION_ID(). It will be compared to the API version of
702  * the kernel-side interface.
703  *
704  * On successful return, the version member will be the API version of the
705  * kernel-side interface. _MALI_UK_API_VERSION macro defines the current version
706  * of the API.
707  *
708  * The compatible member must be checked to see if the version of the user-side
709  * interface is compatible with the kernel-side interface, since future versions
710  * of the interface may be backwards compatible.
711  */
712 typedef struct {
713         u64 ctx;                        /**< [in,out] user-kernel context (trashed on output) */
714         _mali_uk_api_version version;   /**< [in,out] API version of user-side interface. */
715         int compatible;                 /**< [out] @c 1 when @version is compatible, @c 0 otherwise */
716 } _mali_uk_get_api_version_v2_s;
717
718 typedef struct
719 {
720     u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
721     _mali_uk_api_version version;                   /**< [in,out] API version of user-side interface. */
722 } _mali_uk_get_mali_version_in_rk30_s;
723
724 /* rk_ext : rk_ko_ver_t. */
725 typedef struct {
726         u64 ctx;                        /**< [in,out] user-kernel context (trashed on output) */
727         _mali_uk_api_version version;   /**< [in,out] API version of user-side interface. */
728 } _mali_rk_ko_version_s;
729 /** @} */ /* end group _mali_uk_getapiversion_s */
730
731 /** @defgroup _mali_uk_get_user_settings_s Get user space settings */
732
733 /** @brief struct to keep the matching values of the user space settings within certain context
734  *
735  * Each member of the settings array corresponds to a matching setting in the user space and its value is the value
736  * of that particular setting.
737  *
738  * All settings are given reference to the context pointed to by the ctx pointer.
739  *
740  */
741 typedef struct {
742         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
743         u32 settings[_MALI_UK_USER_SETTING_MAX]; /**< [out] The values for all settings */
744 } _mali_uk_get_user_settings_s;
745
746 /** @brief struct to hold the value of a particular setting from the user space within a given context
747  */
748 typedef struct {
749         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
750         _mali_uk_user_setting_t setting; /**< [in] setting to get */
751         u32 value;                       /**< [out] value of setting */
752 } _mali_uk_get_user_setting_s;
753
754 /** @brief Arguments for _mali_ukk_request_high_priority() */
755 typedef struct {
756         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
757 } _mali_uk_request_high_priority_s;
758
759 /** @brief Arguments for _mali_ukk_pending_submit() */
760 typedef struct {
761         u64 ctx;                       /**< [in,out] user-kernel context (trashed on output) */
762 } _mali_uk_pending_submit_s;
763
764 /** @} */ /* end group _mali_uk_core */
765
766
767 /** @defgroup _mali_uk_memory U/K Memory
768  * @{ */
769
770 #define _MALI_MEMORY_ALLOCATE_RESIZEABLE  (1<<4) /* BUFFER can trim dow/grow*/
771 #define _MALI_MEMORY_ALLOCATE_NO_BIND_GPU (1<<5) /*Not map to GPU when allocate, must call bind later*/
772 #define _MALI_MEMORY_ALLOCATE_SWAPPABLE   (1<<6) /* Allocate swappale memory. */
773 #define _MALI_MEMORY_ALLOCATE_DEFER_BIND (1<<7) /*Not map to GPU when allocate, must call bind later*/
774 #define _MALI_MEMORY_ALLOCATE_SECURE (1<<8) /* Allocate secure memory. */
775
776
777 typedef struct {
778         u64 ctx;                                          /**< [in,out] user-kernel context (trashed on output) */
779         u32 gpu_vaddr;                                    /**< [in] GPU virtual address */
780         u32 vsize;                                        /**< [in] vitrual size of the allocation */
781         u32 psize;                                        /**< [in] physical size of the allocation */
782         u32 flags;
783         u64 backend_handle;                               /**< [out] backend handle */
784         s32 secure_shared_fd;                           /** < [in] the mem handle for secure mem */
785 } _mali_uk_alloc_mem_s;
786
787
788 typedef struct {
789         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
790         u32 gpu_vaddr;                /**< [in] use as handle to free allocation */
791         u32 free_pages_nr;      /** < [out] record the number of free pages */
792 } _mali_uk_free_mem_s;
793
794
795 #define _MALI_MEMORY_BIND_BACKEND_UMP             (1<<8)
796 #define _MALI_MEMORY_BIND_BACKEND_DMA_BUF         (1<<9)
797 #define _MALI_MEMORY_BIND_BACKEND_MALI_MEMORY     (1<<10)
798 #define _MALI_MEMORY_BIND_BACKEND_EXTERNAL_MEMORY (1<<11)
799 #define _MALI_MEMORY_BIND_BACKEND_EXT_COW         (1<<12)
800 #define _MALI_MEMORY_BIND_BACKEND_HAVE_ALLOCATION (1<<13)
801
802
803 #define _MALI_MEMORY_BIND_BACKEND_MASK (_MALI_MEMORY_BIND_BACKEND_UMP| \
804                                         _MALI_MEMORY_BIND_BACKEND_DMA_BUF |\
805                                         _MALI_MEMORY_BIND_BACKEND_MALI_MEMORY |\
806                                         _MALI_MEMORY_BIND_BACKEND_EXTERNAL_MEMORY |\
807                                         _MALI_MEMORY_BIND_BACKEND_EXT_COW |\
808                                         _MALI_MEMORY_BIND_BACKEND_HAVE_ALLOCATION)
809
810
811 #define _MALI_MEMORY_GPU_READ_ALLOCATE            (1<<16)
812
813
814 typedef struct {
815         u64 ctx;                                        /**< [in,out] user-kernel context (trashed on output) */
816         u32 vaddr;                                      /**< [in] mali address to map the physical memory to */
817         u32 size;                                       /**< [in] size */
818         u32 flags;                                      /**< [in] see_MALI_MEMORY_BIND_BACKEND_* */
819         u32 padding;                                    /** padding for 32/64 struct alignment */
820         union {
821                 struct {
822                         u32 secure_id;                  /**< [in] secure id */
823                         u32 rights;                     /**< [in] rights necessary for accessing memory */
824                         u32 flags;                      /**< [in] flags, see \ref _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE */
825                 } bind_ump;
826                 struct {
827                         u32 mem_fd;                     /**< [in] Memory descriptor */
828                         u32 rights;                     /**< [in] rights necessary for accessing memory */
829                         u32 flags;                      /**< [in] flags, see \ref _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE */
830                 } bind_dma_buf;
831                 struct {
832                         u32 phys_addr;                  /**< [in] physical address */
833                         u32 rights;                     /**< [in] rights necessary for accessing memory */
834                         u32 flags;                      /**< [in] flags, see \ref _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE */
835                 } bind_ext_memory;
836         } mem_union;
837 } _mali_uk_bind_mem_s;
838
839 typedef struct {
840         u64 ctx;                                        /**< [in,out] user-kernel context (trashed on output) */
841         u32 flags;                                      /**< [in] see_MALI_MEMORY_BIND_BACKEND_* */
842         u32 vaddr;                                      /**<  [in] identifier for mapped memory object in kernel space  */
843 } _mali_uk_unbind_mem_s;
844
845 typedef struct {
846         u64 ctx;                                        /**< [in,out] user-kernel context (trashed on output) */
847         u32 target_handle;                              /**< [in] handle of allocation need to do COW */
848         u32 target_offset;                              /**< [in] offset in target allocation to do COW(for support COW  a memory allocated from memory_bank, PAGE_SIZE align)*/
849         u32 target_size;                                /**< [in] size of target allocation to do COW (for support memory bank, PAGE_SIZE align)(in byte) */
850         u32 range_start;                                /**< [in] re allocate range start offset, offset from the start of allocation (PAGE_SIZE align)*/
851         u32 range_size;                                 /**< [in] re allocate size (PAGE_SIZE align)*/
852         u32 vaddr;                                      /**< [in] mali address for the new allocaiton */
853         u32 backend_handle;                             /**< [out] backend handle */
854         u32 flags;
855 } _mali_uk_cow_mem_s;
856
857 typedef struct {
858         u64 ctx;                                        /**< [in,out] user-kernel context (trashed on output) */
859         u32 range_start;                                /**< [in] re allocate range start offset, offset from the start of allocation */
860         u32 size;                                       /**< [in] re allocate size*/
861         u32 vaddr;                                      /**< [in] mali address for the new allocaiton */
862         s32 change_pages_nr;                            /**< [out] record the page number change for cow operation */
863 } _mali_uk_cow_modify_range_s;
864
865
866 typedef struct {
867         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
868         u32 mem_fd;                     /**< [in] Memory descriptor */
869         u32 size;                       /**< [out] size */
870 } _mali_uk_dma_buf_get_size_s;
871
872 /** Flag for _mali_uk_map_external_mem_s, _mali_uk_attach_ump_mem_s and _mali_uk_attach_dma_buf_s */
873 #define _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE (1<<0)
874
875
876 typedef struct {
877         u64 ctx;                                /**< [in,out] user-kernel context (trashed on output) */
878         u64 vaddr;                              /* the buffer to do resize*/
879         u32 psize;                              /* wanted physical size of this memory */
880 } _mali_uk_mem_resize_s;
881
882 /**
883  * @brief Arguments for _mali_uk[uk]_mem_write_safe()
884  */
885 typedef struct {
886         u64 ctx;  /**< [in,out] user-kernel context (trashed on output) */
887         u64 src;  /**< [in] Pointer to source data */
888         u64 dest; /**< [in] Destination Mali buffer */
889         u32 size;   /**< [in,out] Number of bytes to write/copy on input, number of bytes actually written/copied on output */
890 } _mali_uk_mem_write_safe_s;
891
892 typedef struct {
893         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
894         u32 size;                       /**< [out] size of MMU page table information (registers + page tables) */
895 } _mali_uk_query_mmu_page_table_dump_size_s;
896
897 typedef struct {
898         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
899         u32 size;                       /**< [in] size of buffer to receive mmu page table information */
900         u64 buffer;                   /**< [in,out] buffer to receive mmu page table information */
901         u32 register_writes_size;       /**< [out] size of MMU register dump */
902         u64 register_writes;           /**< [out] pointer within buffer where MMU register dump is stored */
903         u32 page_table_dump_size;       /**< [out] size of MMU page table dump */
904         u64 page_table_dump;           /**< [out] pointer within buffer where MMU page table dump is stored */
905 } _mali_uk_dump_mmu_page_table_s;
906
907 /** @} */ /* end group _mali_uk_memory */
908
909
910 /** @addtogroup _mali_uk_pp U/K Fragment Processor
911  * @{ */
912
913 /** @brief Arguments for _mali_ukk_get_pp_number_of_cores()
914  *
915  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
916  * - Upon successful return from _mali_ukk_get_pp_number_of_cores(), @c number_of_cores
917  * will contain the number of Fragment Processor cores in the system.
918  */
919 typedef struct {
920         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
921         u32 number_of_total_cores;      /**< [out] Total number of Fragment Processor cores in the system */
922         u32 number_of_enabled_cores;    /**< [out] Number of enabled Fragment Processor cores */
923 } _mali_uk_get_pp_number_of_cores_s;
924
925 /** @brief Arguments for _mali_ukk_get_pp_core_version()
926  *
927  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
928  * - Upon successful return from _mali_ukk_get_pp_core_version(), @c version contains
929  * the version that all Fragment Processor cores are compatible with.
930  */
931 typedef struct {
932         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
933         _mali_core_version version;     /**< [out] version returned from core, see \ref _mali_core_version  */
934         u32 padding;
935 } _mali_uk_get_pp_core_version_s;
936
937 /** @} */ /* end group _mali_uk_pp */
938
939
940 /** @addtogroup _mali_uk_gp U/K Vertex Processor
941  * @{ */
942
943 /** @brief Arguments for _mali_ukk_get_gp_number_of_cores()
944  *
945  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
946  * - Upon successful return from _mali_ukk_get_gp_number_of_cores(), @c number_of_cores
947  * will contain the number of Vertex Processor cores in the system.
948  */
949 typedef struct {
950         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
951         u32 number_of_cores;            /**< [out] number of Vertex Processor cores in the system */
952 } _mali_uk_get_gp_number_of_cores_s;
953
954 /** @brief Arguments for _mali_ukk_get_gp_core_version()
955  *
956  * - pass in the user-kernel context @c ctx that was returned from _mali_ukk_open()
957  * - Upon successful return from _mali_ukk_get_gp_core_version(), @c version contains
958  * the version that all Vertex Processor cores are compatible with.
959  */
960 typedef struct {
961         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
962         _mali_core_version version;     /**< [out] version returned from core, see \ref _mali_core_version */
963 } _mali_uk_get_gp_core_version_s;
964
965 /** @} */ /* end group _mali_uk_gp */
966
967 typedef struct {
968         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
969         u32 event_id;                   /**< [in] event id to register (see  enum mali_profiling_events for values) */
970         u32 data[5];                    /**< [in] event specific data */
971 } _mali_uk_profiling_add_event_s;
972
973 typedef struct {
974         u64 ctx;                     /**< [in,out] user-kernel context (trashed on output) */
975         u32 memory_usage;              /**< [out] total memory usage */
976         u32 vaddr;                                      /**< [in] mali address for the cow allocaiton */
977         s32 change_pages_nr;            /**< [out] record the page number change for cow operation */
978 } _mali_uk_profiling_memory_usage_get_s;
979
980
981 /** @addtogroup _mali_uk_memory U/K Memory
982  * @{ */
983
984 /** @brief Arguments to _mali_ukk_mem_mmap()
985  *
986  * Use of the phys_addr member depends on whether the driver is compiled for
987  * Mali-MMU or nonMMU:
988  * - in the nonMMU case, this is the physical address of the memory as seen by
989  * the CPU (which may be a constant offset from that used by Mali)
990  * - in the MMU case, this is the Mali Virtual base address of the memory to
991  * allocate, and the particular physical pages used to back the memory are
992  * entirely determined by _mali_ukk_mem_mmap(). The details of the physical pages
993  * are not reported to user-space for security reasons.
994  *
995  * The cookie member must be stored for use later when freeing the memory by
996  * calling _mali_ukk_mem_munmap(). In the Mali-MMU case, the cookie is secure.
997  *
998  * The ukk_private word must be set to zero when calling from user-space. On
999  * Kernel-side, the  OS implementation of the U/K interface can use it to
1000  * communicate data to the OS implementation of the OSK layer. In particular,
1001  * _mali_ukk_get_big_block() directly calls _mali_ukk_mem_mmap directly, and
1002  * will communicate its own ukk_private word through the ukk_private member
1003  * here. The common code itself will not inspect or modify the ukk_private
1004  * word, and so it may be safely used for whatever purposes necessary to
1005  * integrate Mali Memory handling into the OS.
1006  *
1007  * The uku_private member is currently reserved for use by the user-side
1008  * implementation of the U/K interface. Its value must be zero.
1009  */
1010 typedef struct {
1011         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1012         void *mapping;                  /**< [out] Returns user-space virtual address for the mapping */
1013         u32 size;                       /**< [in] Size of the requested mapping */
1014         u32 phys_addr;                  /**< [in] Physical address - could be offset, depending on caller+callee convention */
1015         mali_bool writeable;
1016 } _mali_uk_mem_mmap_s;
1017
1018 /** @brief Arguments to _mali_ukk_mem_munmap()
1019  *
1020  * The cookie and mapping members must be that returned from the same previous
1021  * call to _mali_ukk_mem_mmap(). The size member must correspond to cookie
1022  * and mapping - that is, it must be the value originally supplied to a call to
1023  * _mali_ukk_mem_mmap that returned the values of mapping and cookie.
1024  *
1025  * An error will be returned if an attempt is made to unmap only part of the
1026  * originally obtained range, or to unmap more than was originally obtained.
1027  */
1028 typedef struct {
1029         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1030         void *mapping;                  /**< [in] The mapping returned from mmap call */
1031         u32 size;                       /**< [in] The size passed to mmap call */
1032 } _mali_uk_mem_munmap_s;
1033 /** @} */ /* end group _mali_uk_memory */
1034
1035 /** @defgroup _mali_uk_vsync U/K VSYNC Wait Reporting Module
1036  * @{ */
1037
1038 /** @brief VSYNC events
1039  *
1040  * These events are reported when DDK starts to wait for vsync and when the
1041  * vsync has occured and the DDK can continue on the next frame.
1042  */
1043 typedef enum _mali_uk_vsync_event {
1044         _MALI_UK_VSYNC_EVENT_BEGIN_WAIT = 0,
1045         _MALI_UK_VSYNC_EVENT_END_WAIT
1046 } _mali_uk_vsync_event;
1047
1048 /** @brief Arguments to _mali_ukk_vsync_event()
1049  *
1050  */
1051 typedef struct {
1052         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1053         _mali_uk_vsync_event event;     /**< [in] VSYNCH event type */
1054 } _mali_uk_vsync_event_report_s;
1055
1056 /** @} */ /* end group _mali_uk_vsync */
1057
1058 /** @defgroup _mali_uk_sw_counters_report U/K Software Counter Reporting
1059  * @{ */
1060
1061 /** @brief Software counter values
1062  *
1063  * Values recorded for each of the software counters during a single renderpass.
1064  */
1065 typedef struct {
1066         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1067         u64 counters;                  /**< [in] The array of u32 counter values */
1068         u32 num_counters;              /**< [in] The number of elements in counters array */
1069 } _mali_uk_sw_counters_report_s;
1070
1071 /** @} */ /* end group _mali_uk_sw_counters_report */
1072
1073 /** @defgroup _mali_uk_timeline U/K Mali Timeline
1074  * @{ */
1075
1076 typedef struct {
1077         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1078         u32 timeline;                   /**< [in] timeline id */
1079         u32 point;                      /**< [out] latest point on timeline */
1080 } _mali_uk_timeline_get_latest_point_s;
1081
1082 typedef struct {
1083         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1084         _mali_uk_fence_t fence;         /**< [in] fence */
1085         u32 timeout;                    /**< [in] timeout (0 for no wait, -1 for blocking) */
1086         u32 status;                     /**< [out] status of fence (1 if signaled, 0 if timeout) */
1087 } _mali_uk_timeline_wait_s;
1088
1089 typedef struct {
1090         u64 ctx;                      /**< [in,out] user-kernel context (trashed on output) */
1091         _mali_uk_fence_t fence;         /**< [in] mali fence to create linux sync fence from */
1092         s32 sync_fd;                    /**< [out] file descriptor for new linux sync fence */
1093 } _mali_uk_timeline_create_sync_fence_s;
1094
1095 /** @} */ /* end group _mali_uk_timeline */
1096
1097 /** @} */ /* end group u_k_api */
1098
1099 /** @} */ /* end group uddapi */
1100
1101 typedef struct {
1102         u64 ctx;                 /**< [in,out] user-kernel context (trashed on output) */
1103         s32 stream_fd;   /**< [in] The profiling kernel base stream fd handle */
1104 } _mali_uk_profiling_stream_fd_get_s;
1105
1106 typedef struct {
1107         u64 ctx;        /**< [in,out] user-kernel context (trashed on output) */
1108         u64 control_packet_data; /**< [in] the control packet data for control settings */
1109         u32 control_packet_size;  /**< [in] The control packet size */
1110         u64 response_packet_data; /** < [out] The response packet data */
1111         u32 response_packet_size; /** < [in,out] The response packet data */
1112 } _mali_uk_profiling_control_set_s;
1113
1114 #ifdef __cplusplus
1115 }
1116 #endif
1117
1118 #endif /* __MALI_UTGARD_UK_TYPES_H__ */