59aee9ee1e102a4d3542d3315bc9e0f407213ac5
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / ump / common / ump_kernel_common.h
1 /*
2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2008-2013 ARM Limited
5 * ALL RIGHTS RESERVED
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
9 */
10
11 #ifndef __UMP_KERNEL_COMMON_H__
12 #define __UMP_KERNEL_COMMON_H__
13
14 #include "ump_kernel_types.h"
15 #include "ump_kernel_interface.h"
16 #include "ump_kernel_descriptor_mapping.h"
17 #include "ump_kernel_memory_backend.h"
18
19
20 #ifdef DEBUG
21 extern int ump_debug_level;
22 #define UMP_DEBUG_PRINT(args) _mali_osk_dbgmsg args
23 #define UMP_DEBUG_CODE(args) args
24 #define DBG_MSG(level,args) do { /* args should be in brackets */ \
25 ((level) <= ump_debug_level)?\
26 UMP_DEBUG_PRINT(("UMP<" #level ">: ")), \
27 UMP_DEBUG_PRINT(args):0; \
28 } while (0)
29
30 #define DBG_MSG_IF(level,condition,args) /* args should be in brackets */ \
31 if((condition)&&((level) <= ump_debug_level)) {\
32 UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \
33 UMP_DEBUG_PRINT(args); \
34 }
35
36 #define DBG_MSG_ELSE(level,args) /* args should be in brackets */ \
37 else if((level) <= ump_debug_level) { \
38 UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \
39 UMP_DEBUG_PRINT(args); \
40 }
41
42 #define DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) MSG_ERR(("NULL pointer " #pointer)); } while(0)
43 #define DEBUG_ASSERT(condition) do {if(!(condition)) MSG_ERR(("ASSERT failed: " #condition)); } while(0)
44 #else /* DEBUG */
45 #define UMP_DEBUG_PRINT(args) do {} while(0)
46 #define UMP_DEBUG_CODE(args)
47 #define DBG_MSG(level,args) do {} while(0)
48 #define DBG_MSG_IF(level,condition,args) do {} while(0)
49 #define DBG_MSG_ELSE(level,args) do {} while(0)
50 #define DEBUG_ASSERT(condition) do {} while(0)
51 #define DEBUG_ASSERT_POINTER(pointer) do {} while(0)
52 #endif /* DEBUG */
53
54 #define MSG_ERR(args) do{ /* args should be in brackets */ \
55 _mali_osk_dbgmsg("UMP: ERR: %s\n" ,__FILE__); \
56 _mali_osk_dbgmsg( " %s()%4d\n", __FUNCTION__, __LINE__) ; \
57 _mali_osk_dbgmsg args ; \
58 _mali_osk_dbgmsg("\n"); \
59 } while(0)
60
61 #define MSG(args) do{ /* args should be in brackets */ \
62 _mali_osk_dbgmsg("UMP: "); \
63 _mali_osk_dbgmsg args; \
64 } while (0)
65
66
67
68 /*
69 * This struct is used to store per session data.
70 * A session is created when someone open() the device, and
71 * closed when someone close() it or the user space application terminates.
72 */
73 typedef struct ump_session_data {
74 _mali_osk_list_t list_head_session_memory_list; /**< List of ump allocations made by the process (elements are ump_session_memory_list_element) */
75 _mali_osk_list_t list_head_session_memory_mappings_list; /**< List of ump_memory_allocations mapped in */
76 int api_version;
77 _mali_osk_mutex_t *lock;
78 ump_descriptor_mapping * cookies_map; /**< Secure mapping of cookies from _ump_ukk_map_mem() */
79 int cache_operations_ongoing;
80 int has_pending_level1_cache_flush;
81 } ump_session_data;
82
83
84
85 /*
86 * This struct is used to track the UMP memory references a session has.
87 * We need to track this in order to be able to clean up after user space processes
88 * which don't do it themself (e.g. due to a crash or premature termination).
89 */
90 typedef struct ump_session_memory_list_element {
91 struct ump_dd_mem * mem;
92 _mali_osk_list_t list;
93 } ump_session_memory_list_element;
94
95
96
97 /*
98 * Device specific data, created when device driver is loaded, and then kept as the global variable device.
99 */
100 typedef struct ump_dev {
101 _mali_osk_mutex_t *secure_id_map_lock;
102 ump_descriptor_mapping * secure_id_map;
103 ump_memory_backend * backend;
104 } ump_dev;
105
106
107
108 extern int ump_debug_level;
109 extern struct ump_dev device;
110
111 _mali_osk_errcode_t ump_kernel_constructor(void);
112 void ump_kernel_destructor(void);
113 int map_errcode( _mali_osk_errcode_t err );
114
115 /**
116 * variables from user space cannot be dereferenced from kernel space; tagging them
117 * with __user allows the GCC compiler to generate a warning. Other compilers may
118 * not support this so we define it here as an empty macro if the compiler doesn't
119 * define it.
120 */
121 #ifndef __user
122 #define __user
123 #endif
124
125 #endif /* __UMP_KERNEL_COMMON_H__ */