1 /* 2 * Copyright (C) 2010-2014, 2016-2017 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_random_mapping.h" 18 #include "ump_kernel_memory_backend.h" 19 20 21 #ifdef DEBUG 22 extern int ump_debug_level; 23 #define UMP_DEBUG_PRINT(args) _mali_osk_dbgmsg args 24 #define UMP_DEBUG_CODE(args) args 25 #define DBG_MSG(level,args) do { /* args should be in brackets */ \ 26 ((level) <= ump_debug_level)?\ 27 UMP_DEBUG_PRINT(("UMP<" #level ">: ")), \ 28 UMP_DEBUG_PRINT(args):0; \ 29 } while (0) 30 31 #define DBG_MSG_IF(level,condition,args) /* args should be in brackets */ \ 32 if((condition)&&((level) <= ump_debug_level)) {\ 33 UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \ 34 UMP_DEBUG_PRINT(args); \ 35 } 36 37 #define DBG_MSG_ELSE(level,args) /* args should be in brackets */ \ 38 else if((level) <= ump_debug_level) { \ 39 UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \ 40 UMP_DEBUG_PRINT(args); \ 41 } 42 43 #define DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) MSG_ERR(("NULL pointer " #pointer)); } while(0) 44 #define DEBUG_ASSERT(condition) do {if(!(condition)) MSG_ERR(("ASSERT failed: " #condition)); } while(0) 45 #else /* DEBUG */ 46 #define UMP_DEBUG_PRINT(args) do {} while(0) 47 #define UMP_DEBUG_CODE(args) 48 #define DBG_MSG(level,args) do {} while(0) 49 #define DBG_MSG_IF(level,condition,args) do {} while(0) 50 #define DBG_MSG_ELSE(level,args) do {} while(0) 51 #define DEBUG_ASSERT(condition) do {} while(0) 52 #define DEBUG_ASSERT_POINTER(pointer) do {} while(0) 53 #endif /* DEBUG */ 54 55 #define MSG_ERR(args) do{ /* args should be in brackets */ \ 56 _mali_osk_dbgmsg("UMP: ERR: %s\n" ,__FILE__); \ 57 _mali_osk_dbgmsg( " %s()%4d\n", __FUNCTION__, __LINE__) ; \ 58 _mali_osk_dbgmsg args ; \ 59 _mali_osk_dbgmsg("\n"); \ 60 } while(0) 61 62 #define MSG(args) do{ /* args should be in brackets */ \ 63 _mali_osk_dbgmsg("UMP: "); \ 64 _mali_osk_dbgmsg args; \ 65 } while (0) 66 67 68 69 /* 70 * This struct is used to store per session data. 71 * A session is created when someone open() the device, and 72 * closed when someone close() it or the user space application terminates. 73 */ 74 typedef struct ump_session_data { 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_mutex_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 struct ump_dd_mem *mem; 93 _mali_osk_list_t list; 94 } ump_session_memory_list_element; 95 96 97 98 /* 99 * Device specific data, created when device driver is loaded, and then kept as the global variable device. 100 */ 101 typedef struct ump_dev { 102 ump_random_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 ump_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__ */ 126