ump_ukk_ref_wrappers.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2010 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 for the reference implementation
  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; Allocate UMP memory
  21. */
  22. int ump_allocate_wrapper(u32 __user * argument, struct ump_session_data * session_data)
  23. {
  24. _ump_uk_allocate_s user_interaction;
  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_allocate()\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(&user_interaction, argument, sizeof(user_interaction)))
  34. {
  35. MSG_ERR(("copy_from_user() in ump_ioctl_allocate()\n"));
  36. return -EFAULT;
  37. }
  38. user_interaction.ctx = (void *) session_data;
  39. err = _ump_ukk_allocate( &user_interaction );
  40. if( _MALI_OSK_ERR_OK != err )
  41. {
  42. DBG_MSG(1, ("_ump_ukk_allocate() failed in ump_ioctl_allocate()\n"));
  43. return map_errcode(err);
  44. }
  45. user_interaction.ctx = NULL;
  46. if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
  47. {
  48. /* If the copy fails then we should release the memory. We can use the IOCTL release to accomplish this */
  49. _ump_uk_release_s release_args;
  50. MSG_ERR(("copy_to_user() failed in ump_ioctl_allocate()\n"));
  51. release_args.ctx = (void *) session_data;
  52. release_args.secure_id = user_interaction.secure_id;
  53. err = _ump_ukk_release( &release_args );
  54. if(_MALI_OSK_ERR_OK != err)
  55. {
  56. MSG_ERR(("_ump_ukk_release() also failed when trying to release newly allocated memory in ump_ioctl_allocate()\n"));
  57. }
  58. return -EFAULT;
  59. }
  60. return 0; /* success */
  61. }