gcpu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include <linux/uaccess.h>
  2. #include <linux/module.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/cdev.h>
  5. #include <linux/mm.h>
  6. #include <linux/vmalloc.h>
  7. #include <linux/slab.h>
  8. #include <mt-plat/aee.h>
  9. #include <linux/printk.h>
  10. #if defined(CONFIG_MTK_IN_HOUSE_TEE_SUPPORT)
  11. #include "trustzone/kree/system.h"
  12. #include "trustzone/tz_cross/ta_gcpu.h"
  13. #define GCPU_TEE_ENABLE 1
  14. #else
  15. #define GCPU_TEE_ENABLE 0
  16. #endif
  17. #define GCPU_DEV_NAME "MTK_GCPU"
  18. #define GCPU_TAG "GCPU Kernel"
  19. #define GCPU_USE_XLOG 0
  20. #if GCPU_USE_XLOG
  21. #define GCPU_LOG_ERR(log, args...) \
  22. xlog_printk(ANDROID_LOG_ERROR, GCPU_TAG, "[%s] [%d] *** ERROR: "log, __func__, __LINE__, ##args)
  23. #define GCPU_LOG_INFO(log, args...) \
  24. xlog_printk(ANDROID_LOG_INFO, GCPU_TAG, "[%s] [%d] "log, __func__, __LINE__, ##args)
  25. #else
  26. #define GCPU_LOG_ERR(log, args...) \
  27. pr_err("[GCPU Kernel] [%s] [%d] *** ERROR: "log, __func__, __LINE__, ##args)
  28. #define GCPU_LOG_INFO(log, args...) \
  29. pr_info("[GCPU Kernel] [%s] [%d] "log, __func__, __LINE__, ##args)
  30. #endif
  31. #if 0
  32. int gcpu_enableClk(void)
  33. {
  34. int ret = 0;
  35. GCPU_LOG_INFO("Enable GCPU clock\n");
  36. ret = enable_clock(MT_CG_PERI_GCPU, "GCPU");
  37. return ret;
  38. }
  39. EXPORT_SYMBOL(gcpu_enableClk);
  40. int gcpu_disableClk(void)
  41. {
  42. int ret = 0;
  43. GCPU_LOG_INFO("Disable GCPU clock\n");
  44. ret = disable_clock(MT_CG_PERI_GCPU, "GCPU");
  45. return ret;
  46. }
  47. EXPORT_SYMBOL(gcpu_disableClk);
  48. #endif
  49. #if GCPU_TEE_ENABLE
  50. static int gcpu_tee_call(uint32_t cmd)
  51. {
  52. TZ_RESULT l_ret = TZ_RESULT_SUCCESS;
  53. int ret = 0;
  54. KREE_SESSION_HANDLE test_session;
  55. /* MTEEC_PARAM param[4]; */
  56. struct timespec start, end;
  57. long long ns;
  58. l_ret = KREE_CreateSession(TZ_TA_GCPU_UUID, &test_session);
  59. if (l_ret != TZ_RESULT_SUCCESS) {
  60. GCPU_LOG_ERR("KREE_CreateSession error, ret = %x\n", l_ret);
  61. return 1;
  62. }
  63. getnstimeofday(&start);
  64. l_ret = KREE_TeeServiceCall(test_session, cmd, 0, NULL);
  65. if (l_ret != TZ_RESULT_SUCCESS) {
  66. GCPU_LOG_ERR("KREE_TeeServiceCall error, ret = %x\n", l_ret);
  67. ret = 1;
  68. }
  69. getnstimeofday(&end);
  70. ns = ((long long)end.tv_sec - start.tv_sec) * 1000000000 + (end.tv_nsec - start.tv_nsec);
  71. GCPU_LOG_INFO("gcpu_tee_call, cmd: %d, time: %lld ns\n", cmd, ns);
  72. l_ret = KREE_CloseSession(test_session);
  73. if (l_ret != TZ_RESULT_SUCCESS) {
  74. GCPU_LOG_ERR("KREE_CloseSession error, ret = %x\n", l_ret);
  75. ret = 1;
  76. }
  77. return ret;
  78. }
  79. static int gcpu_probe(struct platform_device *pdev)
  80. {
  81. GCPU_LOG_INFO("gcpu_probe\n");
  82. /* gcpu_tee_call(TZCMD_GCPU_SELFTEST); */
  83. return 0;
  84. }
  85. static int gcpu_remove(struct platform_device *pdev)
  86. {
  87. GCPU_LOG_INFO("gcpu_remove\n");
  88. return 0;
  89. }
  90. static int gcpu_suspend(struct platform_device *pdev, pm_message_t mesg)
  91. {
  92. int ret = 0;
  93. GCPU_LOG_INFO("gcpu_suspend\n");
  94. if (gcpu_tee_call(TZCMD_GCPU_SUSPEND)) {
  95. GCPU_LOG_ERR("Suspend fail\n");
  96. ret = 1;
  97. } else {
  98. GCPU_LOG_INFO("Suspend ok\n");
  99. ret = 0;
  100. }
  101. return ret;
  102. }
  103. static int gcpu_resume(struct platform_device *pdev)
  104. {
  105. GCPU_LOG_INFO("gcpu_resume\n");
  106. /* gcpu_tee_call(TZCMD_GCPU_SELFTEST); */
  107. return 0;
  108. }
  109. struct platform_device gcpu_device = {
  110. .name = GCPU_DEV_NAME,
  111. .id = -1,
  112. };
  113. static struct platform_driver gcpu_driver = {
  114. .probe = gcpu_probe,
  115. .remove = gcpu_remove,
  116. .suspend = gcpu_suspend,
  117. .resume = gcpu_resume,
  118. .driver = {
  119. .name = GCPU_DEV_NAME,
  120. .owner = THIS_MODULE,
  121. }
  122. };
  123. #endif
  124. static int __init gcpu_init(void)
  125. {
  126. #if GCPU_TEE_ENABLE
  127. int ret = 0;
  128. GCPU_LOG_INFO("module init\n");
  129. ret = platform_device_register(&gcpu_device);
  130. if (ret) {
  131. GCPU_LOG_ERR("Unable to register device , ret = %d\n", ret);
  132. return ret;
  133. }
  134. ret = platform_driver_register(&gcpu_driver);
  135. if (ret) {
  136. GCPU_LOG_ERR("Unable to register driver, ret = %d\n", ret);
  137. return ret;
  138. }
  139. gcpu_tee_call(TZCMD_GCPU_KERNEL_INIT_DONE);
  140. #endif
  141. return 0;
  142. }
  143. static void __exit gcpu_exit(void)
  144. {
  145. #if GCPU_TEE_ENABLE
  146. GCPU_LOG_INFO("module exit\n");
  147. #endif
  148. }
  149. module_init(gcpu_init);
  150. module_exit(gcpu_exit);
  151. MODULE_DESCRIPTION("MTK GCPU driver");
  152. MODULE_AUTHOR("Yi Zheng <yi.zheng@mediatek.com>");
  153. MODULE_LICENSE("GPL");