cmdq_record.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. #ifndef __CMDQ_RECORD_H__
  2. #define __CMDQ_RECORD_H__
  3. #include <linux/types.h>
  4. #include "cmdq_def.h"
  5. #include "cmdq_core.h"
  6. struct TaskStruct;
  7. struct cmdqRecStruct {
  8. uint64_t engineFlag;
  9. int32_t scenario;
  10. uint32_t blockSize; /* command size */
  11. void *pBuffer;
  12. uint32_t bufferSize; /* allocated buffer size */
  13. struct TaskStruct *pRunningTask; /* running task after flush() or startLoop() */
  14. enum CMDQ_HW_THREAD_PRIORITY_ENUM priority; /* setting high priority. This implies Prefetch ENABLE. */
  15. bool finalized; /* set to true after flush() or startLoop() */
  16. uint32_t prefetchCount; /* maintenance prefetch instruction */
  17. cmdqSecDataStruct secData; /* secure execution data */
  18. };
  19. typedef struct cmdqRecStruct *cmdqRecHandle;
  20. typedef dma_addr_t cmdqBackupSlotHandle;
  21. typedef void *CmdqRecLoopHandle;
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26. * Create command queue recorder handle
  27. * Parameter:
  28. * pHandle: pointer to retrieve the handle
  29. * Return:
  30. * 0 for success; else the error code is returned
  31. */
  32. int32_t cmdqRecCreate(enum CMDQ_SCENARIO_ENUM scenario, cmdqRecHandle *pHandle);
  33. /**
  34. * Reset command queue recorder commands
  35. * Parameter:
  36. * handle: the command queue recorder handle
  37. * Return:
  38. * 0 for success; else the error code is returned
  39. */
  40. int32_t cmdqRecReset(cmdqRecHandle handle);
  41. /**
  42. * Configure as secure task
  43. * Parameter:
  44. * handle: the command queue recorder handle
  45. * isSecure: true, execute the command in secure world
  46. * Return:
  47. * 0 for success; else the error code is returned
  48. *
  49. * Note:
  50. * a. Secure CMDQ support when t-base enabled only
  51. * b. By default cmdqRecHandle records a normal command,
  52. * please call cmdqRecSetSecure to set command as SECURE after cmdqRecReset
  53. */
  54. int32_t cmdqRecSetSecure(cmdqRecHandle handle, const bool isSecure);
  55. /**
  56. * Add DPAC protection flag
  57. * Parameter:
  58. * Note:
  59. * a. Secure CMDQ support when t-base enabled only
  60. * b. after reset handle, user have to specify protection flag again
  61. */
  62. int32_t cmdqRecSecureEnableDAPC(cmdqRecHandle handle, const uint64_t engineFlag);
  63. /**
  64. * Add flag for M4U security ports
  65. * Parameter:
  66. * Note:
  67. * a. Secure CMDQ support when t-base enabled only
  68. * b. after reset handle, user have to specify protection flag again
  69. */
  70. int32_t cmdqRecSecureEnablePortSecurity(cmdqRecHandle handle, const uint64_t engineFlag);
  71. /**
  72. * Append mark command to the recorder
  73. * Parameter:
  74. * handle: the command queue recorder handle
  75. * Return:
  76. * 0 for success; else the error code is returned
  77. */
  78. int32_t cmdqRecMark(cmdqRecHandle handle);
  79. /**
  80. * Append mark command to enable prefetch
  81. * Parameter:
  82. * handle: the command queue recorder handle
  83. * Return:
  84. * 0 for success; else the error code is returned
  85. */
  86. int32_t cmdqRecEnablePrefetch(cmdqRecHandle handle);
  87. /**
  88. * Append mark command to disable prefetch
  89. * Parameter:
  90. * handle: the command queue recorder handle
  91. * Return:
  92. * 0 for success; else the error code is returned
  93. */
  94. int32_t cmdqRecDisablePrefetch(cmdqRecHandle handle);
  95. /**
  96. * Append write command to the recorder
  97. * Parameter:
  98. * handle: the command queue recorder handle
  99. * addr: the specified target register physical address
  100. * value: the specified target register value
  101. * mask: the specified target register mask
  102. * Return:
  103. * 0 for success; else the error code is returned
  104. */
  105. int32_t cmdqRecWrite(cmdqRecHandle handle, uint32_t addr, uint32_t value, uint32_t mask);
  106. /**
  107. * Append write command to the update secure buffer address in secure path
  108. * Parameter:
  109. * handle: the command queue recorder handle
  110. * addr: the specified register physical address about module src/dst buffer address
  111. * type: base handle type
  112. * base handle: secure handle of a secure mememory
  113. * offset: offset related to base handle (secure buffer = addr(base_handle) + offset)
  114. * size: secure buffer size
  115. * mask: 0xFFFF_FFFF
  116. * Return:
  117. * 0 for success; else the error code is returned
  118. * Note:
  119. * support only when secure OS enabled
  120. */
  121. int32_t cmdqRecWriteSecure(cmdqRecHandle handle,
  122. uint32_t addr,
  123. CMDQ_SEC_ADDR_METADATA_TYPE type,
  124. uint32_t baseHandle,
  125. uint32_t offset, uint32_t size, uint32_t port);
  126. /**
  127. * Record and memorize the index of write command to trust zone in secure path
  128. * Parameter:
  129. * handle: the command queue recorder handle
  130. * addr: the specified target register physical address
  131. * type: base handle type
  132. * value: the specified target register value
  133. * mask: the specified target register mask
  134. * Return:
  135. * 0 for success; else the error code is returned
  136. * Note:
  137. * support only when secure OS enabled
  138. */
  139. int32_t cmdqRecWriteSecureMask(cmdqRecHandle handle, uint32_t addr,
  140. CMDQ_SEC_ADDR_METADATA_TYPE type,
  141. uint32_t value, uint32_t mask);
  142. /**
  143. * Append poll command to the recorder
  144. * Parameter:
  145. * handle: the command queue recorder handle
  146. * addr: the specified register physical address
  147. * value: the required register value
  148. * mask: the required register mask
  149. * Return:
  150. * 0 for success; else the error code is returned
  151. */
  152. int32_t cmdqRecPoll(cmdqRecHandle handle, uint32_t addr, uint32_t value, uint32_t mask);
  153. /**
  154. * Append wait command to the recorder
  155. * Parameter:
  156. * handle: the command queue recorder handle
  157. * event: the desired event type to "wait and CLEAR"
  158. * Return:
  159. * 0 for success; else the error code is returned
  160. */
  161. int32_t cmdqRecWait(cmdqRecHandle handle, enum CMDQ_EVENT_ENUM event);
  162. /**
  163. * like cmdqRecWait, but won't clear the event after
  164. * leaving wait state.
  165. *
  166. * Parameter:
  167. * handle: the command queue recorder handle
  168. * event: the desired event type wait for
  169. * Return:
  170. * 0 for success; else the error code is returned
  171. */
  172. int32_t cmdqRecWaitNoClear(cmdqRecHandle handle, enum CMDQ_EVENT_ENUM event);
  173. /**
  174. * Unconditionally set to given event to 0.
  175. * Parameter:
  176. * handle: the command queue recorder handle
  177. * event: the desired event type to set
  178. * Return:
  179. * 0 for success; else the error code is returned
  180. */
  181. int32_t cmdqRecClearEventToken(cmdqRecHandle handle, enum CMDQ_EVENT_ENUM event);
  182. /**
  183. * Unconditionally set to given event to 1.
  184. * Parameter:
  185. * handle: the command queue recorder handle
  186. * event: the desired event type to set
  187. * Return:
  188. * 0 for success; else the error code is returned
  189. */
  190. int32_t cmdqRecSetEventToken(cmdqRecHandle handle, enum CMDQ_EVENT_ENUM event);
  191. /**
  192. * Read a register value to a CMDQ general purpose register(GPR)
  193. * Parameter:
  194. * handle: the command queue recorder handle
  195. * hwRegAddr: register address to read from
  196. * dstDataReg: CMDQ GPR to write to
  197. * Return:
  198. * 0 for success; else the error code is returned
  199. */
  200. int32_t cmdqRecReadToDataRegister(cmdqRecHandle handle, uint32_t hwRegAddr,
  201. enum CMDQ_DATA_REGISTER_ENUM dstDataReg);
  202. /**
  203. * Write a register value from a CMDQ general purpose register(GPR)
  204. * Parameter:
  205. * handle: the command queue recorder handle
  206. * srcDataReg: CMDQ GPR to read from
  207. * hwRegAddr: register address to write to
  208. * Return:
  209. * 0 for success; else the error code is returned
  210. */
  211. int32_t cmdqRecWriteFromDataRegister(cmdqRecHandle handle,
  212. enum CMDQ_DATA_REGISTER_ENUM srcDataReg,
  213. uint32_t hwRegAddr);
  214. /**
  215. * Allocate 32-bit register backup slot
  216. *
  217. */
  218. int32_t cmdqBackupAllocateSlot(cmdqBackupSlotHandle *phBackupSlot, uint32_t slotCount);
  219. /**
  220. * Read 32-bit register backup slot by index
  221. *
  222. */
  223. int32_t cmdqBackupReadSlot(cmdqBackupSlotHandle hBackupSlot, uint32_t slotIndex,
  224. uint32_t *value);
  225. /**
  226. * Use CPU to write value into 32-bit register backup slot by index directly.
  227. *
  228. */
  229. int32_t cmdqBackupWriteSlot(cmdqBackupSlotHandle hBackupSlot, uint32_t slotIndex,
  230. uint32_t value);
  231. /**
  232. * Free allocated backup slot. DO NOT free them before corresponding
  233. * task finishes. Becareful on AsyncFlush use cases.
  234. *
  235. */
  236. int32_t cmdqBackupFreeSlot(cmdqBackupSlotHandle hBackupSlot);
  237. /**
  238. * Insert instructions to backup given 32-bit HW register
  239. * to a backup slot.
  240. * You can use cmdqBackupReadSlot() to retrieve the result
  241. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  242. *
  243. */
  244. int32_t cmdqRecBackupRegisterToSlot(cmdqRecHandle handle,
  245. cmdqBackupSlotHandle hBackupSlot,
  246. uint32_t slotIndex, uint32_t addr);
  247. /**
  248. * Insert instructions to write 32-bit HW register
  249. * from a backup slot.
  250. * You can use cmdqBackupReadSlot() to retrieve the result
  251. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  252. *
  253. */
  254. int32_t cmdqRecBackupWriteRegisterFromSlot(cmdqRecHandle handle,
  255. cmdqBackupSlotHandle hBackupSlot,
  256. uint32_t slotIndex, uint32_t addr);
  257. /**
  258. * Insert instructions to update slot with given 32-bit value
  259. * You can use cmdqBackupReadSlot() to retrieve the result
  260. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  261. *
  262. */
  263. int32_t cmdqRecBackupUpdateSlot(cmdqRecHandle handle,
  264. cmdqBackupSlotHandle hBackupSlot,
  265. uint32_t slotIndex, uint32_t value);
  266. /**
  267. * Trigger CMDQ to execute the recorded commands
  268. * Parameter:
  269. * handle: the command queue recorder handle
  270. * Return:
  271. * 0 for success; else the error code is returned
  272. * Note:
  273. * This is a synchronous function. When the function
  274. * returned, the recorded commands have been done.
  275. */
  276. int32_t cmdqRecFlush(cmdqRecHandle handle);
  277. /**
  278. * Flush the command; Also at the end of the command, backup registers
  279. * appointed by addrArray.
  280. *
  281. */
  282. int32_t cmdqRecFlushAndReadRegister(cmdqRecHandle handle, uint32_t regCount,
  283. uint32_t *addrArray, uint32_t *valueArray);
  284. /**
  285. * Trigger CMDQ to asynchronously execute the recorded commands
  286. * Parameter:
  287. * handle: the command queue recorder handle
  288. * Return:
  289. * 0 for successfully start execution; else the error code is returned
  290. * Note:
  291. * This is an ASYNC function. When the function
  292. * returned, it may or may not be finished. There is no way to retrieve the result.
  293. */
  294. int32_t cmdqRecFlushAsync(cmdqRecHandle handle);
  295. int32_t cmdqRecFlushAsyncCallback(cmdqRecHandle handle, CmdqAsyncFlushCB callback,
  296. uint32_t userData);
  297. /**
  298. * Trigger CMDQ to execute the recorded commands in loop.
  299. * each loop completion generates callback in interrupt context.
  300. *
  301. * Parameter:
  302. * handle: the command queue recorder handle
  303. * irqCallback: this CmdqInterruptCB callback is called after each loop completion.
  304. * data: user data, this will pass back to irqCallback
  305. * hLoop: output, a handle used to stop this loop.
  306. *
  307. * Return:
  308. * 0 for success; else the error code is returned
  309. *
  310. * Note:
  311. * This is an asynchronous function. When the function
  312. * returned, the thread has started. Return -1 in irqCallback to stop it.
  313. */
  314. int32_t cmdqRecStartLoop(cmdqRecHandle handle);
  315. /**
  316. * Unconditionally stops the loop thread.
  317. * Must call after cmdqRecStartLoop().
  318. */
  319. int32_t cmdqRecStopLoop(cmdqRecHandle handle);
  320. /**
  321. * returns current count of instructions in given handle
  322. */
  323. int32_t cmdqRecGetInstructionCount(cmdqRecHandle handle);
  324. /**
  325. * Dump command buffer to kernel log
  326. * This is for debugging purpose.
  327. */
  328. int32_t cmdqRecDumpCommand(cmdqRecHandle handle);
  329. /**
  330. * Destroy command queue recorder handle
  331. * Parameter:
  332. * handle: the command queue recorder handle
  333. */
  334. void cmdqRecDestroy(cmdqRecHandle handle);
  335. int32_t cmdqRecSetSecureMode(cmdqRecHandle handle, enum CMDQ_DISP_MODE mode);
  336. int32_t cmdqRecWaitThreadIdleWithTimeout(int threadID, unsigned int retryCount);
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340. #endif /* __CMDQ_RECORD_H__ */