UPSTREAM: DT/arm,gic-v3: Documment PPI partition support
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_osk_types.h
1 /*
2  * Copyright (C) 2010-2014 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
11 /**
12  * @file mali_osk_types.h
13  * Defines types of the OS abstraction layer for the kernel device driver (OSK)
14  */
15
16 #ifndef __MALI_OSK_TYPES_H__
17 #define __MALI_OSK_TYPES_H__
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /**
24  * @addtogroup uddapi Unified Device Driver (UDD) APIs
25  *
26  * @{
27  */
28
29 /**
30  * @addtogroup oskapi UDD OS Abstraction for Kernel-side (OSK) APIs
31  *
32  * @{
33  */
34
35 /** @defgroup _mali_osk_miscellaneous OSK Miscellaneous functions, constants and types
36  * @{ */
37
38 /* Define integer types used by OSK. Note: these currently clash with Linux so we only define them if not defined already */
39 #ifndef __KERNEL__
40 typedef unsigned char      u8;
41 typedef signed char        s8;
42 typedef unsigned short     u16;
43 typedef signed short       s16;
44 typedef unsigned int       u32;
45 typedef signed int         s32;
46 typedef unsigned long long u64;
47 #define BITS_PER_LONG (sizeof(long)*8)
48 #else
49 /* Ensure Linux types u32, etc. are defined */
50 #include <linux/types.h>
51 #endif
52
53 /** @brief Mali Boolean type which uses MALI_TRUE and MALI_FALSE
54   */
55 typedef unsigned long mali_bool;
56
57 #ifndef MALI_TRUE
58 #define MALI_TRUE ((mali_bool)1)
59 #endif
60
61 #ifndef MALI_FALSE
62 #define MALI_FALSE ((mali_bool)0)
63 #endif
64
65 #define MALI_HW_CORE_NO_COUNTER     ((u32)-1)
66
67 /**
68  * @brief OSK Error codes
69  *
70  * Each OS may use its own set of error codes, and may require that the
71  * User/Kernel interface take certain error code. This means that the common
72  * error codes need to be sufficiently rich to pass the correct error code
73  * thorugh from the OSK to U/K layer, across all OSs.
74  *
75  * The result is that some error codes will appear redundant on some OSs.
76  * Under all OSs, the OSK layer must translate native OS error codes to
77  * _mali_osk_errcode_t codes. Similarly, the U/K layer must translate from
78  * _mali_osk_errcode_t codes to native OS error codes.
79  */
80 typedef enum {
81         _MALI_OSK_ERR_OK = 0, /**< Success. */
82         _MALI_OSK_ERR_FAULT = -1, /**< General non-success */
83         _MALI_OSK_ERR_INVALID_FUNC = -2, /**< Invalid function requested through User/Kernel interface (e.g. bad IOCTL number) */
84         _MALI_OSK_ERR_INVALID_ARGS = -3, /**< Invalid arguments passed through User/Kernel interface */
85         _MALI_OSK_ERR_NOMEM = -4, /**< Insufficient memory */
86         _MALI_OSK_ERR_TIMEOUT = -5, /**< Timeout occurred */
87         _MALI_OSK_ERR_RESTARTSYSCALL = -6, /**< Special: On certain OSs, must report when an interruptable mutex is interrupted. Ignore otherwise. */
88         _MALI_OSK_ERR_ITEM_NOT_FOUND = -7, /**< Table Lookup failed */
89         _MALI_OSK_ERR_BUSY = -8, /**< Device/operation is busy. Try again later */
90         _MALI_OSK_ERR_UNSUPPORTED = -9, /**< Optional part of the interface used, and is unsupported */
91 } _mali_osk_errcode_t;
92
93 /** @} */ /* end group _mali_osk_miscellaneous */
94
95 /** @defgroup _mali_osk_wq OSK work queues
96  * @{ */
97
98 /** @brief Private type for work objects */
99 typedef struct _mali_osk_wq_work_s _mali_osk_wq_work_t;
100 typedef struct _mali_osk_wq_delayed_work_s _mali_osk_wq_delayed_work_t;
101
102 /** @brief Work queue handler function
103  *
104  * This function type is called when the work is scheduled by the work queue,
105  * e.g. as an IRQ bottom-half handler.
106  *
107  * Refer to \ref _mali_osk_wq_schedule_work() for more information on the
108  * work-queue and work handlers.
109  *
110  * @param arg resource-specific data
111  */
112 typedef void (*_mali_osk_wq_work_handler_t)(void *arg);
113
114 /* @} */ /* end group _mali_osk_wq */
115
116 /** @defgroup _mali_osk_irq OSK IRQ handling
117  * @{ */
118
119 /** @brief Private type for IRQ handling objects */
120 typedef struct _mali_osk_irq_t_struct _mali_osk_irq_t;
121
122 /** @brief Optional function to trigger an irq from a resource
123  *
124  * This function is implemented by the common layer to allow probing of a resource's IRQ.
125  * @param arg resource-specific data */
126 typedef void (*_mali_osk_irq_trigger_t)(void *arg);
127
128 /** @brief Optional function to acknowledge an irq from a resource
129  *
130  * This function is implemented by the common layer to allow probing of a resource's IRQ.
131  * @param arg resource-specific data
132  * @return _MALI_OSK_ERR_OK if the IRQ was successful, or a suitable _mali_osk_errcode_t on failure. */
133 typedef _mali_osk_errcode_t (*_mali_osk_irq_ack_t)(void *arg);
134
135 /** @brief IRQ 'upper-half' handler callback.
136  *
137  * This function is implemented by the common layer to do the initial handling of a
138  * resource's IRQ. This maps on to the concept of an ISR that does the minimum
139  * work necessary before handing off to an IST.
140  *
141  * The communication of the resource-specific data from the ISR to the IST is
142  * handled by the OSK implementation.
143  *
144  * On most systems, the IRQ upper-half handler executes in IRQ context.
145  * Therefore, the system may have restrictions about what can be done in this
146  * context
147  *
148  * If an IRQ upper-half handler requires more work to be done than can be
149  * acheived in an IRQ context, then it may defer the work with
150  * _mali_osk_wq_schedule_work(). Refer to \ref _mali_osk_wq_create_work() for
151  * more information.
152  *
153  * @param arg resource-specific data
154  * @return _MALI_OSK_ERR_OK if the IRQ was correctly handled, or a suitable
155  * _mali_osk_errcode_t otherwise.
156  */
157 typedef _mali_osk_errcode_t (*_mali_osk_irq_uhandler_t)(void *arg);
158
159
160 /** @} */ /* end group _mali_osk_irq */
161
162
163 /** @defgroup _mali_osk_atomic OSK Atomic counters
164  * @{ */
165
166 /** @brief Public type of atomic counters
167  *
168  * This is public for allocation on stack. On systems that support it, this is just a single 32-bit value.
169  * On others, it could be encapsulating an object stored elsewhere.
170  *
171  * Regardless of implementation, the \ref _mali_osk_atomic functions \b must be used
172  * for all accesses to the variable's value, even if atomicity is not required.
173  * Do not access u.val or u.obj directly.
174  */
175 typedef struct {
176         union {
177                 u32 val;
178                 void *obj;
179         } u;
180 } _mali_osk_atomic_t;
181 /** @} */ /* end group _mali_osk_atomic */
182
183
184 /** @defgroup _mali_osk_lock OSK Mutual Exclusion Locks
185  * @{ */
186
187
188 /** @brief OSK Mutual Exclusion Lock ordered list
189  *
190  * This lists the various types of locks in the system and is used to check
191  * that locks are taken in the correct order.
192  *
193  * - Holding more than one lock of the same order at the same time is not
194  *   allowed.
195  * - Taking a lock of a lower order than the highest-order lock currently held
196  *   is not allowed.
197  *
198  */
199 typedef enum {
200         /*  ||    Locks    ||  */
201         /*  ||   must be   ||  */
202         /* _||_  taken in _||_ */
203         /* \  /    this   \  / */
204         /*  \/    order!   \/  */
205
206         _MALI_OSK_LOCK_ORDER_FIRST = 0,
207
208         _MALI_OSK_LOCK_ORDER_SESSIONS,
209         _MALI_OSK_LOCK_ORDER_MEM_SESSION,
210         _MALI_OSK_LOCK_ORDER_MEM_INFO,
211         _MALI_OSK_LOCK_ORDER_MEM_PT_CACHE,
212         _MALI_OSK_LOCK_ORDER_DESCRIPTOR_MAP,
213         _MALI_OSK_LOCK_ORDER_PM_EXECUTION,
214         _MALI_OSK_LOCK_ORDER_EXECUTOR,
215         _MALI_OSK_LOCK_ORDER_TIMELINE_SYSTEM,
216         _MALI_OSK_LOCK_ORDER_SCHEDULER,
217         _MALI_OSK_LOCK_ORDER_SCHEDULER_DEFERRED,
218         _MALI_OSK_LOCK_ORDER_PROFILING,
219         _MALI_OSK_LOCK_ORDER_L2,
220         _MALI_OSK_LOCK_ORDER_L2_COMMAND,
221         _MALI_OSK_LOCK_ORDER_UTILIZATION,
222         _MALI_OSK_LOCK_ORDER_SESSION_PENDING_JOBS,
223         _MALI_OSK_LOCK_ORDER_PM_STATE,
224
225         _MALI_OSK_LOCK_ORDER_LAST,
226 } _mali_osk_lock_order_t;
227
228
229 /** @brief OSK Mutual Exclusion Lock flags type
230  *
231  * - Any lock can use the order parameter.
232  */
233 typedef enum {
234         _MALI_OSK_LOCKFLAG_UNORDERED        = 0x1, /**< Indicate that the order of this lock should not be checked */
235         _MALI_OSK_LOCKFLAG_ORDERED          = 0x2,
236         /** @enum _mali_osk_lock_flags_t
237          *
238          * Flags from 0x10000--0x80000000 are RESERVED for User-mode */
239
240 } _mali_osk_lock_flags_t;
241
242 /** @brief Mutual Exclusion Lock Mode Optimization hint
243  *
244  * The lock mode is used to implement the read/write locking of locks when we call
245  * functions _mali_osk_mutex_rw_init/wait/signal/term/. In this case, the RO mode can
246  * be used to allow multiple concurrent readers, but no writers. The RW mode is used for
247  * writers, and so will wait for all readers to release the lock (if any present).
248  * Further readers and writers will wait until the writer releases the lock.
249  *
250  * The mode is purely an optimization hint: for example, it is permissible for
251  * all locks to behave in RW mode, regardless of that supplied.
252  *
253  * It is an error to attempt to use locks in anything other that RW mode when
254  * call functions _mali_osk_mutex_rw_wait/signal().
255  *
256  */
257 typedef enum {
258         _MALI_OSK_LOCKMODE_UNDEF = -1,  /**< Undefined lock mode. For internal use only */
259         _MALI_OSK_LOCKMODE_RW    = 0x0, /**< Read-write mode, default. All readers and writers are mutually-exclusive */
260         _MALI_OSK_LOCKMODE_RO,          /**< Read-only mode, to support multiple concurrent readers, but mutual exclusion in the presence of writers. */
261         /** @enum _mali_osk_lock_mode_t
262          *
263          * Lock modes 0x40--0x7F are RESERVED for User-mode */
264 } _mali_osk_lock_mode_t;
265
266 /** @brief Private types for Mutual Exclusion lock objects */
267 typedef struct _mali_osk_lock_debug_s _mali_osk_lock_debug_t;
268 typedef struct _mali_osk_spinlock_s _mali_osk_spinlock_t;
269 typedef struct _mali_osk_spinlock_irq_s _mali_osk_spinlock_irq_t;
270 typedef struct _mali_osk_mutex_s _mali_osk_mutex_t;
271 typedef struct _mali_osk_mutex_rw_s _mali_osk_mutex_rw_t;
272
273 /** @} */ /* end group _mali_osk_lock */
274
275 /** @defgroup _mali_osk_low_level_memory OSK Low-level Memory Operations
276  * @{ */
277
278 /**
279  * @brief Private data type for use in IO accesses to/from devices.
280  *
281  * This represents some range that is accessible from the device. Examples
282  * include:
283  * - Device Registers, which could be readable and/or writeable.
284  * - Memory that the device has access to, for storing configuration structures.
285  *
286  * Access to this range must be made through the _mali_osk_mem_ioread32() and
287  * _mali_osk_mem_iowrite32() functions.
288  */
289 typedef struct _mali_io_address *mali_io_address;
290
291 /** @defgroup _MALI_OSK_CPU_PAGE CPU Physical page size macros.
292  *
293  * The order of the page size is supplied for
294  * ease of use by algorithms that might require it, since it is easier to know
295  * it ahead of time rather than calculating it.
296  *
297  * The Mali Page Mask macro masks off the lower bits of a physical address to
298  * give the start address of the page for that physical address.
299  *
300  * @note The Mali device driver code is designed for systems with 4KB page size.
301  * Changing these macros will not make the entire Mali device driver work with
302  * page sizes other than 4KB.
303  *
304  * @note The CPU Physical Page Size has been assumed to be the same as the Mali
305  * Physical Page Size.
306  *
307  * @{
308  */
309
310 /** CPU Page Order, as log to base 2 of the Page size. @see _MALI_OSK_CPU_PAGE_SIZE */
311 #define _MALI_OSK_CPU_PAGE_ORDER ((u32)12)
312 /** CPU Page Size, in bytes.               */
313 #define _MALI_OSK_CPU_PAGE_SIZE (((u32)1) << (_MALI_OSK_CPU_PAGE_ORDER))
314 /** CPU Page Mask, which masks off the offset within a page */
315 #define _MALI_OSK_CPU_PAGE_MASK (~((((u32)1) << (_MALI_OSK_CPU_PAGE_ORDER)) - ((u32)1)))
316 /** @} */ /* end of group _MALI_OSK_CPU_PAGE */
317
318 /** @defgroup _MALI_OSK_MALI_PAGE Mali Physical Page size macros
319  *
320  * Mali Physical page size macros. The order of the page size is supplied for
321  * ease of use by algorithms that might require it, since it is easier to know
322  * it ahead of time rather than calculating it.
323  *
324  * The Mali Page Mask macro masks off the lower bits of a physical address to
325  * give the start address of the page for that physical address.
326  *
327  * @note The Mali device driver code is designed for systems with 4KB page size.
328  * Changing these macros will not make the entire Mali device driver work with
329  * page sizes other than 4KB.
330  *
331  * @note The Mali Physical Page Size has been assumed to be the same as the CPU
332  * Physical Page Size.
333  *
334  * @{
335  */
336
337 /** Mali Page Order, as log to base 2 of the Page size. @see _MALI_OSK_MALI_PAGE_SIZE */
338 #define _MALI_OSK_MALI_PAGE_ORDER ((u32)12)
339 /** Mali Page Size, in bytes.               */
340 #define _MALI_OSK_MALI_PAGE_SIZE (((u32)1) << (_MALI_OSK_MALI_PAGE_ORDER))
341 /** Mali Page Mask, which masks off the offset within a page */
342 #define _MALI_OSK_MALI_PAGE_MASK (~((((u32)1) << (_MALI_OSK_MALI_PAGE_ORDER)) - ((u32)1)))
343 /** @} */ /* end of group _MALI_OSK_MALI_PAGE*/
344
345 /** @brief flags for mapping a user-accessible memory range
346  *
347  * Where a function with prefix '_mali_osk_mem_mapregion' accepts flags as one
348  * of the function parameters, it will use one of these. These allow per-page
349  * control over mappings. Compare with the mali_memory_allocation_flag type,
350  * which acts over an entire range
351  *
352  * These may be OR'd together with bitwise OR (|), but must be cast back into
353  * the type after OR'ing.
354  */
355 typedef enum {
356         _MALI_OSK_MEM_MAPREGION_FLAG_OS_ALLOCATED_PHYSADDR = 0x1, /**< Physical address is OS Allocated */
357 } _mali_osk_mem_mapregion_flags_t;
358 /** @} */ /* end group _mali_osk_low_level_memory */
359
360 /** @defgroup _mali_osk_notification OSK Notification Queues
361  * @{ */
362
363 /** @brief Private type for notification queue objects */
364 typedef struct _mali_osk_notification_queue_t_struct _mali_osk_notification_queue_t;
365
366 /** @brief Public notification data object type */
367 typedef struct _mali_osk_notification_t_struct {
368         u32 notification_type;   /**< The notification type */
369         u32 result_buffer_size; /**< Size of the result buffer to copy to user space */
370         void *result_buffer;    /**< Buffer containing any type specific data */
371 } _mali_osk_notification_t;
372
373 /** @} */ /* end group _mali_osk_notification */
374
375
376 /** @defgroup _mali_osk_timer OSK Timer Callbacks
377  * @{ */
378
379 /** @brief Function to call when a timer expires
380  *
381  * When a timer expires, this function is called. Note that on many systems,
382  * a timer callback will be executed in IRQ context. Therefore, restrictions
383  * may apply on what can be done inside the timer callback.
384  *
385  * If a timer requires more work to be done than can be acheived in an IRQ
386  * context, then it may defer the work with a work-queue. For example, it may
387  * use \ref _mali_osk_wq_schedule_work() to make use of a bottom-half handler
388  * to carry out the remaining work.
389  *
390  * Stopping the timer with \ref _mali_osk_timer_del() blocks on compeletion of
391  * the callback. Therefore, the callback may not obtain any mutexes also held
392  * by any callers of _mali_osk_timer_del(). Otherwise, a deadlock may occur.
393  *
394  * @param arg Function-specific data */
395 typedef void (*_mali_osk_timer_callback_t)(void *arg);
396
397 /** @brief Private type for Timer Callback Objects */
398 typedef struct _mali_osk_timer_t_struct _mali_osk_timer_t;
399 /** @} */ /* end group _mali_osk_timer */
400
401
402 /** @addtogroup _mali_osk_list OSK Doubly-Linked Circular Lists
403  * @{ */
404
405 /** @brief Public List objects.
406  *
407  * To use, add a _mali_osk_list_t member to the structure that may become part
408  * of a list. When traversing the _mali_osk_list_t objects, use the
409  * _MALI_OSK_CONTAINER_OF() macro to recover the structure from its
410  *_mali_osk_list_t member
411  *
412  * Each structure may have multiple _mali_osk_list_t members, so that the
413  * structure is part of multiple lists. When traversing lists, ensure that the
414  * correct _mali_osk_list_t member is used, because type-checking will be
415  * lost by the compiler.
416  */
417 typedef struct _mali_osk_list_s {
418         struct _mali_osk_list_s *next;
419         struct _mali_osk_list_s *prev;
420 } _mali_osk_list_t;
421 /** @} */ /* end group _mali_osk_list */
422
423 /** @addtogroup _mali_osk_miscellaneous
424  * @{ */
425
426 /** @brief resource description struct
427  *
428  * Platform independent representation of a Mali HW resource
429  */
430 typedef struct _mali_osk_resource {
431         const char *description;        /**< short description of the resource */
432         uintptr_t base;                 /**< Physical base address of the resource, as seen by Mali resources. */
433         const char *irq_name;           /**< Name of irq belong to this resource */
434         u32 irq;                        /**< IRQ number delivered to the CPU, or -1 to tell the driver to probe for it (if possible) */
435 } _mali_osk_resource_t;
436 /** @} */ /* end group _mali_osk_miscellaneous */
437
438 /** @defgroup _mali_osk_wait_queue OSK Wait Queue functionality
439  * @{ */
440 /** @brief Private type for wait queue objects */
441 typedef struct _mali_osk_wait_queue_t_struct _mali_osk_wait_queue_t;
442 /** @} */ /* end group _mali_osk_wait_queue */
443
444 /** @} */ /* end group osuapi */
445
446 /** @} */ /* end group uddapi */
447
448 /** @brief Mali print ctx type which uses seq_file
449   */
450 typedef struct seq_file _mali_osk_print_ctx;
451
452 #ifdef __cplusplus
453 }
454 #endif
455
456 #endif /* __MALI_OSK_TYPES_H__ */