ump_ukk_wrappers.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. /**
  11. * @file ump_ukk_wrappers.c
  12. * Defines the wrapper functions which turn Linux IOCTL calls into _ukk_ calls
  13. */
  14. #include <asm/uaccess.h> /* user space access */
  15. #include "ump_osk.h"
  16. #include "ump_uk_types.h"
  17. #include "ump_ukk.h"
  18. #include "ump_kernel_common.h"
  19. /*
  20. * IOCTL operation; Negotiate version of IOCTL API
  21. */
  22. int ump_get_api_version_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  23. {
  24. _ump_uk_api_version_s version_info;
  25. _mali_osk_errcode_t err;
  26. /* Sanity check input parameters */
  27. if (NULL == argument || NULL == session_data)
  28. {
  29. MSG_ERR(("NULL parameter in ump_ioctl_get_api_version()\n"));
  30. return -ENOTTY;
  31. }
  32. /* Copy the user space memory to kernel space (so we safely can read it) */
  33. if (0 != copy_from_user(&version_info, argument, sizeof(version_info)))
  34. {
  35. MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
  36. return -EFAULT;
  37. }
  38. version_info.ctx = (void*) session_data;
  39. err = _ump_uku_get_api_version( &version_info );
  40. if( _MALI_OSK_ERR_OK != err )
  41. {
  42. MSG_ERR(("_ump_uku_get_api_version() failed in ump_ioctl_get_api_version()\n"));
  43. return map_errcode(err);
  44. }
  45. version_info.ctx = NULL;
  46. /* Copy ouput data back to user space */
  47. if (0 != copy_to_user(argument, &version_info, sizeof(version_info)))
  48. {
  49. MSG_ERR(("copy_to_user() failed in ump_ioctl_get_api_version()\n"));
  50. return -EFAULT;
  51. }
  52. return 0; /* success */
  53. }
  54. /*
  55. * IOCTL operation; Release reference to specified UMP memory.
  56. */
  57. int ump_release_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  58. {
  59. _ump_uk_release_s release_args;
  60. _mali_osk_errcode_t err;
  61. /* Sanity check input parameters */
  62. if (NULL == session_data)
  63. {
  64. MSG_ERR(("NULL parameter in ump_ioctl_release()\n"));
  65. return -ENOTTY;
  66. }
  67. /* Copy the user space memory to kernel space (so we safely can read it) */
  68. if (0 != copy_from_user(&release_args, argument, sizeof(release_args)))
  69. {
  70. MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
  71. return -EFAULT;
  72. }
  73. release_args.ctx = (void*) session_data;
  74. err = _ump_ukk_release( &release_args );
  75. if( _MALI_OSK_ERR_OK != err )
  76. {
  77. MSG_ERR(("_ump_ukk_release() failed in ump_ioctl_release()\n"));
  78. return map_errcode(err);
  79. }
  80. return 0; /* success */
  81. }
  82. /*
  83. * IOCTL operation; Return size for specified UMP memory.
  84. */
  85. int ump_size_get_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  86. {
  87. _ump_uk_size_get_s user_interaction;
  88. _mali_osk_errcode_t err;
  89. /* Sanity check input parameters */
  90. if (NULL == argument || NULL == session_data)
  91. {
  92. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  93. return -ENOTTY;
  94. }
  95. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  96. {
  97. MSG_ERR(("copy_from_user() in ump_ioctl_size_get()\n"));
  98. return -EFAULT;
  99. }
  100. user_interaction.ctx = (void *) session_data;
  101. err = _ump_ukk_size_get( &user_interaction );
  102. if( _MALI_OSK_ERR_OK != err )
  103. {
  104. MSG_ERR(("_ump_ukk_size_get() failed in ump_ioctl_size_get()\n"));
  105. return map_errcode(err);
  106. }
  107. user_interaction.ctx = NULL;
  108. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  109. {
  110. MSG_ERR(("copy_to_user() failed in ump_ioctl_size_get()\n"));
  111. return -EFAULT;
  112. }
  113. return 0; /* success */
  114. }
  115. /*
  116. * IOCTL operation; Do cache maintenance on specified UMP memory.
  117. */
  118. int ump_msync_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  119. {
  120. _ump_uk_msync_s user_interaction;
  121. /* Sanity check input parameters */
  122. if (NULL == argument || NULL == session_data)
  123. {
  124. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  125. return -ENOTTY;
  126. }
  127. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  128. {
  129. MSG_ERR(("copy_from_user() in ump_ioctl_msync()\n"));
  130. return -EFAULT;
  131. }
  132. user_interaction.ctx = (void *) session_data;
  133. _ump_ukk_msync( &user_interaction );
  134. user_interaction.ctx = NULL;
  135. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  136. {
  137. MSG_ERR(("copy_to_user() failed in ump_ioctl_msync()\n"));
  138. return -EFAULT;
  139. }
  140. return 0; /* success */
  141. }
  142. int ump_cache_operations_control_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  143. {
  144. _ump_uk_cache_operations_control_s user_interaction;
  145. /* Sanity check input parameters */
  146. if (NULL == argument || NULL == session_data)
  147. {
  148. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  149. return -ENOTTY;
  150. }
  151. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  152. {
  153. MSG_ERR(("copy_from_user() in ump_ioctl_cache_operations_control()\n"));
  154. return -EFAULT;
  155. }
  156. user_interaction.ctx = (void *) session_data;
  157. _ump_ukk_cache_operations_control((_ump_uk_cache_operations_control_s*) &user_interaction );
  158. user_interaction.ctx = NULL;
  159. #if 0 /* No data to copy back */
  160. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  161. {
  162. MSG_ERR(("copy_to_user() failed in ump_ioctl_cache_operations_control()\n"));
  163. return -EFAULT;
  164. }
  165. #endif
  166. return 0; /* success */
  167. }
  168. int ump_switch_hw_usage_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  169. {
  170. _ump_uk_switch_hw_usage_s user_interaction;
  171. /* Sanity check input parameters */
  172. if (NULL == argument || NULL == session_data)
  173. {
  174. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  175. return -ENOTTY;
  176. }
  177. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  178. {
  179. MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
  180. return -EFAULT;
  181. }
  182. user_interaction.ctx = (void *) session_data;
  183. _ump_ukk_switch_hw_usage( &user_interaction );
  184. user_interaction.ctx = NULL;
  185. #if 0 /* No data to copy back */
  186. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  187. {
  188. MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
  189. return -EFAULT;
  190. }
  191. #endif
  192. return 0; /* success */
  193. }
  194. int ump_lock_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  195. {
  196. _ump_uk_lock_s user_interaction;
  197. /* Sanity check input parameters */
  198. if (NULL == argument || NULL == session_data)
  199. {
  200. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  201. return -ENOTTY;
  202. }
  203. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  204. {
  205. MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
  206. return -EFAULT;
  207. }
  208. user_interaction.ctx = (void *) session_data;
  209. _ump_ukk_lock( &user_interaction );
  210. user_interaction.ctx = NULL;
  211. #if 0 /* No data to copy back */
  212. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  213. {
  214. MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
  215. return -EFAULT;
  216. }
  217. #endif
  218. return 0; /* success */
  219. }
  220. int ump_unlock_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  221. {
  222. _ump_uk_unlock_s user_interaction;
  223. /* Sanity check input parameters */
  224. if (NULL == argument || NULL == session_data)
  225. {
  226. MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
  227. return -ENOTTY;
  228. }
  229. if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
  230. {
  231. MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
  232. return -EFAULT;
  233. }
  234. user_interaction.ctx = (void *) session_data;
  235. _ump_ukk_unlock( &user_interaction );
  236. user_interaction.ctx = NULL;
  237. #if 0 /* No data to copy back */
  238. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  239. {
  240. MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
  241. return -EFAULT;
  242. }
  243. #endif
  244. return 0; /* success */
  245. }