tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / ump / common / ump_kernel_common.h
1 /*
2  * Copyright (C) 2011-2012 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 #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 {
75         _mali_osk_list_t list_head_session_memory_list;  /**< List of ump allocations made by the process (elements are ump_session_memory_list_element) */
76         _mali_osk_list_t list_head_session_memory_mappings_list; /**< List of ump_memory_allocations mapped in */
77         int api_version;
78         _mali_osk_lock_t * lock;
79         ump_descriptor_mapping * cookies_map; /**< Secure mapping of cookies from _ump_ukk_map_mem() */
80         int cache_operations_ongoing;
81         int has_pending_level1_cache_flush;
82 } ump_session_data;
83
84
85
86 /*
87  * This struct is used to track the UMP memory references a session has.
88  * We need to track this in order to be able to clean up after user space processes
89  * which don't do it themself (e.g. due to a crash or premature termination).
90  */
91 typedef struct ump_session_memory_list_element
92 {
93         struct ump_dd_mem * mem;
94         _mali_osk_list_t list;
95 } ump_session_memory_list_element;
96
97
98
99 /*
100  * Device specific data, created when device driver is loaded, and then kept as the global variable device.
101  */
102 typedef struct ump_dev
103 {
104         _mali_osk_lock_t * secure_id_map_lock;
105         ump_descriptor_mapping * secure_id_map;
106         ump_memory_backend * backend;
107 } ump_dev;
108
109
110
111 extern int ump_debug_level;
112 extern struct ump_dev device;
113
114 _mali_osk_errcode_t ump_kernel_constructor(void);
115 void ump_kernel_destructor(void);
116 int map_errcode( _mali_osk_errcode_t err );
117
118 /**
119  * variables from user space cannot be dereferenced from kernel space; tagging them
120  * with __user allows the GCC compiler to generate a warning. Other compilers may
121  * not support this so we define it here as an empty macro if the compiler doesn't
122  * define it.
123  */
124 #ifndef __user
125 #define __user
126 #endif
127
128 #endif /* __UMP_KERNEL_COMMON_H__ */