ump_kernel_common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2010-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. #ifndef __UMP_KERNEL_COMMON_H__
  11. #define __UMP_KERNEL_COMMON_H__
  12. #include "ump_kernel_types.h"
  13. #include "ump_kernel_interface.h"
  14. #include "ump_kernel_descriptor_mapping.h"
  15. #include "ump_kernel_memory_backend.h"
  16. #ifdef DEBUG
  17. extern int ump_debug_level;
  18. #define UMP_DEBUG_PRINT(args) _mali_osk_dbgmsg args
  19. #define UMP_DEBUG_CODE(args) args
  20. #define DBG_MSG(level,args) do { /* args should be in brackets */ \
  21. ((level) <= ump_debug_level)?\
  22. UMP_DEBUG_PRINT(("UMP<" #level ">: ")), \
  23. UMP_DEBUG_PRINT(args):0; \
  24. } while (0)
  25. #define DBG_MSG_IF(level,condition,args) /* args should be in brackets */ \
  26. if((condition)&&((level) <= ump_debug_level)) {\
  27. UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \
  28. UMP_DEBUG_PRINT(args); \
  29. }
  30. #define DBG_MSG_ELSE(level,args) /* args should be in brackets */ \
  31. else if((level) <= ump_debug_level) { \
  32. UMP_DEBUG_PRINT(("UMP<" #level ">: ")); \
  33. UMP_DEBUG_PRINT(args); \
  34. }
  35. #define DEBUG_ASSERT_POINTER(pointer) do {if( (pointer)== NULL) MSG_ERR(("NULL pointer " #pointer)); } while(0)
  36. #define DEBUG_ASSERT(condition) do {if(!(condition)) MSG_ERR(("ASSERT failed: " #condition)); } while(0)
  37. #else /* DEBUG */
  38. #define UMP_DEBUG_PRINT(args) do {} while(0)
  39. #define UMP_DEBUG_CODE(args)
  40. #define DBG_MSG(level,args) do {} while(0)
  41. #define DBG_MSG_IF(level,condition,args) do {} while(0)
  42. #define DBG_MSG_ELSE(level,args) do {} while(0)
  43. #define DEBUG_ASSERT(condition) do {} while(0)
  44. #define DEBUG_ASSERT_POINTER(pointer) do {} while(0)
  45. #endif /* DEBUG */
  46. #define MSG_ERR(args) do{ /* args should be in brackets */ \
  47. _mali_osk_dbgmsg("UMP: ERR: %s\n" ,__FILE__); \
  48. _mali_osk_dbgmsg( " %s()%4d\n", __FUNCTION__, __LINE__) ; \
  49. _mali_osk_dbgmsg args ; \
  50. _mali_osk_dbgmsg("\n"); \
  51. } while(0)
  52. #define MSG(args) do{ /* args should be in brackets */ \
  53. _mali_osk_dbgmsg("UMP: "); \
  54. _mali_osk_dbgmsg args; \
  55. } while (0)
  56. /*
  57. * This struct is used to store per session data.
  58. * A session is created when someone open() the device, and
  59. * closed when someone close() it or the user space application terminates.
  60. */
  61. typedef struct ump_session_data
  62. {
  63. _mali_osk_list_t list_head_session_memory_list; /**< List of ump allocations made by the process (elements are ump_session_memory_list_element) */
  64. _mali_osk_list_t list_head_session_memory_mappings_list; /**< List of ump_memory_allocations mapped in */
  65. int api_version;
  66. _mali_osk_lock_t * lock;
  67. ump_descriptor_mapping * cookies_map; /**< Secure mapping of cookies from _ump_ukk_map_mem() */
  68. int cache_operations_ongoing;
  69. int has_pending_level1_cache_flush;
  70. } ump_session_data;
  71. /*
  72. * This struct is used to track the UMP memory references a session has.
  73. * We need to track this in order to be able to clean up after user space processes
  74. * which don't do it themself (e.g. due to a crash or premature termination).
  75. */
  76. typedef struct ump_session_memory_list_element
  77. {
  78. struct ump_dd_mem * mem;
  79. _mali_osk_list_t list;
  80. } ump_session_memory_list_element;
  81. /*
  82. * Device specific data, created when device driver is loaded, and then kept as the global variable device.
  83. */
  84. typedef struct ump_dev
  85. {
  86. _mali_osk_lock_t * secure_id_map_lock;
  87. ump_descriptor_mapping * secure_id_map;
  88. ump_memory_backend * backend;
  89. } ump_dev;
  90. extern int ump_debug_level;
  91. extern struct ump_dev device;
  92. _mali_osk_errcode_t ump_kernel_constructor(void);
  93. void ump_kernel_destructor(void);
  94. int map_errcode( _mali_osk_errcode_t err );
  95. /**
  96. * variables from user space cannot be dereferenced from kernel space; tagging them
  97. * with __user allows the GCC compiler to generate a warning. Other compilers may
  98. * not support this so we define it here as an empty macro if the compiler doesn't
  99. * define it.
  100. */
  101. #ifndef __user
  102. #define __user
  103. #endif
  104. #endif /* __UMP_KERNEL_COMMON_H__ */