PageRenderTime 25ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/component-sources/syslink_2_20_02_20/packages/ti/syslink/utils/hlos/knl/Linux/CacheDrv.c

https://gitlab.com/yesjyo/J5_A8_Code
C | 245 lines | 155 code | 19 blank | 71 comment | 18 complexity | 76b9a1b3d844591f97250e2becef23cf MD5 | raw file
  1. /*
  2. * @file CacheDrv.c
  3. *
  4. * @brief Driver for Cache on HLOS side
  5. *
  6. *
  7. * ============================================================================
  8. *
  9. * Copyright (c) 2008-2012, Texas Instruments Incorporated
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. *
  22. * * Neither the name of Texas Instruments Incorporated nor the names of
  23. * its contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  33. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  34. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  35. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  36. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. * Contact information for paper mail:
  38. * Texas Instruments
  39. * Post Office Box 655303
  40. * Dallas, Texas 75265
  41. * Contact information:
  42. * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
  43. * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
  44. * ============================================================================
  45. *
  46. */
  47. /* Defined to include MACROS EXPORT_SYMBOL. This must be done before including
  48. * module.h
  49. */
  50. #if !defined (EXPORT_SYMTAB)
  51. #define EXPORT_SYMTAB
  52. #endif
  53. /* Standard headers */
  54. #include <ti/syslink/Std.h>
  55. /* OSAL & Utils headers */
  56. #include <ti/syslink/utils/Cache.h>
  57. #include <ti/syslink/utils/Trace.h>
  58. /* Module specific header files */
  59. #include <ti/syslink/inc/CacheDrv.h>
  60. #include <ti/syslink/inc/CacheDrvDefs.h>
  61. /* Linux specific header files */
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/cdev.h>
  65. #include <linux/device.h>
  66. #include <asm/uaccess.h>
  67. /** ============================================================================
  68. * Functions
  69. * ============================================================================
  70. */
  71. /*
  72. * @brief Function to invoke the APIs through ioctl.
  73. *
  74. * @param cmd Command for driver ioctl
  75. * @param args Arguments for the ioctl command
  76. *
  77. * @sa
  78. */
  79. Int
  80. CacheDrv_ioctl (UInt32 cmd, Ptr args) {
  81. CacheDrv_CmdArgs * cargs = (CacheDrv_CmdArgs *) args;
  82. CacheDrv_CmdArgs cmdArgs;
  83. Int32 osStatus = 0;
  84. Int32 ret;
  85. GT_2trace (curTrace, GT_ENTER, "CacheDrv_ioctl",
  86. cmd, args);
  87. /* set API return status as zero of void API calls*/
  88. cargs->apiStatus = 0;
  89. switch (cmd) {
  90. case CMD_CACHE_INV:
  91. {
  92. ret = copy_from_user (&cmdArgs.args.inv,
  93. &cargs->args.inv,
  94. sizeof (cmdArgs.args.inv));
  95. GT_assert (curTrace, (ret == 0));
  96. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  97. if (ret != 0) {
  98. GT_setFailureReason (curTrace,
  99. GT_4CLASS,
  100. " CacheDrv_ioctl",
  101. ret,
  102. "copy_from_user call failed");
  103. osStatus = -EFAULT;
  104. }
  105. else {
  106. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  107. Cache_inv (cmdArgs.args.inv.blockPtr,
  108. cmdArgs.args.inv.byteCnt,
  109. cmdArgs.args.inv.type,
  110. cmdArgs.args.inv.wait);
  111. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  112. }
  113. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  114. }
  115. break;
  116. case CMD_CACHE_WB:
  117. {
  118. ret = copy_from_user (&cmdArgs.args.wb,
  119. &cargs->args.wb,
  120. sizeof (cmdArgs.args.wb));
  121. GT_assert (curTrace, (ret == 0));
  122. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  123. if (ret != 0) {
  124. GT_setFailureReason (curTrace,
  125. GT_4CLASS,
  126. " CacheDrv_ioctl",
  127. ret,
  128. "copy_from_user call failed");
  129. osStatus = -EFAULT;
  130. }
  131. else {
  132. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  133. Cache_wb (cmdArgs.args.wb.blockPtr,
  134. cmdArgs.args.wb.byteCnt,
  135. cmdArgs.args.wb.type,
  136. cmdArgs.args.wb.wait);
  137. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  138. }
  139. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  140. }
  141. break;
  142. case CMD_CACHE_WBINV:
  143. {
  144. ret = copy_from_user (&cmdArgs.args.wbinv,
  145. &cargs->args.wbinv,
  146. sizeof (cmdArgs.args.wbinv));
  147. GT_assert (curTrace, (ret == 0));
  148. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  149. if (ret != 0) {
  150. GT_setFailureReason (curTrace,
  151. GT_4CLASS,
  152. " CacheDrv_ioctl",
  153. ret,
  154. "copy_from_user call failed");
  155. osStatus = -EFAULT;
  156. }
  157. else {
  158. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  159. Cache_wbInv (cmdArgs.args.wbinv.blockPtr,
  160. cmdArgs.args.wbinv.byteCnt,
  161. cmdArgs.args.wbinv.type,
  162. cmdArgs.args.wbinv.wait);
  163. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  164. }
  165. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  166. }
  167. break;
  168. case CMD_CACHE_WAIT:
  169. {
  170. Cache_wait ();
  171. }
  172. break;
  173. case CMD_CACHE_SETMODE:
  174. {
  175. ret = copy_from_user (&cmdArgs.args.setmode,
  176. &cargs->args.setmode,
  177. sizeof (cmdArgs.args.setmode));
  178. GT_assert (curTrace, (ret == 0));
  179. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  180. if (ret != 0) {
  181. GT_setFailureReason (curTrace,
  182. GT_4CLASS,
  183. " CacheDrv_ioctl",
  184. ret,
  185. "copy_from_user call failed");
  186. osStatus = -EFAULT;
  187. }
  188. else {
  189. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  190. cmdArgs.args.setmode.mode = Cache_setMode (
  191. cmdArgs.args.setmode.type,
  192. cmdArgs.args.setmode.mode);
  193. cmdArgs.apiStatus = Cache_S_SUCCESS;
  194. /* Copy the full args to the user-side. */
  195. ret = copy_to_user (cargs,
  196. &cmdArgs,
  197. sizeof (CacheDrv_CmdArgs));
  198. GT_assert (curTrace, (ret == 0));
  199. #if !defined(SYSLINK_BUILD_OPTIMIZE)
  200. }
  201. #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) */
  202. }
  203. break;
  204. default:
  205. {
  206. /* This does not impact return status of this function, so retVal
  207. * comment is not used.
  208. */
  209. osStatus = Cache_E_FAIL;
  210. GT_setFailureReason (curTrace,
  211. GT_4CLASS,
  212. "CacheDrv_ioctl",
  213. osStatus,
  214. "Unsupported ioctl command specified");
  215. }
  216. break;
  217. }
  218. GT_1trace (curTrace, GT_LEAVE, "CacheDrv_ioctl", osStatus);
  219. /*! @return status Operation successfully completed. */
  220. return osStatus;
  221. }
  222. EXPORT_SYMBOL (Cache_inv);
  223. EXPORT_SYMBOL (Cache_wb);
  224. EXPORT_SYMBOL (Cache_wbInv);
  225. EXPORT_SYMBOL (Cache_wait);
  226. EXPORT_SYMBOL (Cache_setMode);