mali_kbase_smc.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. *
  3. * (C) COPYRIGHT 2015 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. #ifdef CONFIG_ARM64
  16. #include <mali_kbase.h>
  17. #include <mali_kbase_smc.h>
  18. #include <linux/compiler.h>
  19. static noinline u64 invoke_smc_fid(u64 function_id,
  20. u64 arg0, u64 arg1, u64 arg2)
  21. {
  22. register u64 x0 asm("x0") = function_id;
  23. register u64 x1 asm("x1") = arg0;
  24. register u64 x2 asm("x2") = arg1;
  25. register u64 x3 asm("x3") = arg2;
  26. asm volatile(
  27. __asmeq("%0", "x0")
  28. __asmeq("%1", "x1")
  29. __asmeq("%2", "x2")
  30. __asmeq("%3", "x3")
  31. "smc #0\n"
  32. : "+r" (x0)
  33. : "r" (x1), "r" (x2), "r" (x3));
  34. return x0;
  35. }
  36. u64 kbase_invoke_smc_fid(u32 fid, u64 arg0, u64 arg1, u64 arg2)
  37. {
  38. /* Is fast call (bit 31 set) */
  39. KBASE_DEBUG_ASSERT(fid & ~SMC_FAST_CALL);
  40. /* bits 16-23 must be zero for fast calls */
  41. KBASE_DEBUG_ASSERT((fid & (0xFF << 16)) == 0);
  42. return invoke_smc_fid(fid, arg0, arg1, arg2);
  43. }
  44. u64 kbase_invoke_smc(u32 oen, u16 function_number, bool smc64,
  45. u64 arg0, u64 arg1, u64 arg2)
  46. {
  47. u32 fid = 0;
  48. /* Only the six bits allowed should be used. */
  49. KBASE_DEBUG_ASSERT((oen & ~SMC_OEN_MASK) == 0);
  50. fid |= SMC_FAST_CALL; /* Bit 31: Fast call */
  51. if (smc64)
  52. fid |= SMC_64; /* Bit 30: 1=SMC64, 0=SMC32 */
  53. fid |= oen; /* Bit 29:24: OEN */
  54. /* Bit 23:16: Must be zero for fast calls */
  55. fid |= (function_number); /* Bit 15:0: function number */
  56. return kbase_invoke_smc_fid(fid, arg0, arg1, arg2);
  57. }
  58. #endif // ifdef CONFIG_ARM64