cmdq_record.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. typedef 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. 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. /* profile marker */
  19. #ifdef CMDQ_PROFILE_MARKER_SUPPORT
  20. cmdqProfileMarkerStruct profileMarker;
  21. #endif
  22. } cmdqRecStruct, *cmdqRecHandle;
  23. typedef dma_addr_t cmdqBackupSlotHandle;
  24. typedef void *CmdqRecLoopHandle;
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. * Create command queue recorder handle
  30. * Parameter:
  31. * pHandle: pointer to retrieve the handle
  32. * Return:
  33. * 0 for success; else the error code is returned
  34. */
  35. int32_t cmdqRecCreate(CMDQ_SCENARIO_ENUM scenario, cmdqRecHandle *pHandle);
  36. /**
  37. * Set engine flag for command queue picking HW thread
  38. * Parameter:
  39. * pHandle: pointer to retrieve the handle
  40. * engineFlag: Flag use to identify which HW module can be accessed
  41. * Return:
  42. * 0 for success; else the error code is returned
  43. */
  44. int32_t cmdqRecSetEngine(cmdqRecHandle handle, uint64_t engineFlag);
  45. /**
  46. * Reset command queue recorder commands
  47. * Parameter:
  48. * handle: the command queue recorder handle
  49. * Return:
  50. * 0 for success; else the error code is returned
  51. */
  52. int32_t cmdqRecReset(cmdqRecHandle handle);
  53. /**
  54. * Configure as secure task
  55. * Parameter:
  56. * handle: the command queue recorder handle
  57. * isSecure: true, execute the command in secure world
  58. * Return:
  59. * 0 for success; else the error code is returned
  60. *
  61. * Note:
  62. * a. Secure CMDQ support when t-base enabled only
  63. * b. By default cmdqRecHandle records a normal command,
  64. * please call cmdqRecSetSecure to set command as SECURE after cmdqRecReset
  65. */
  66. int32_t cmdqRecSetSecure(cmdqRecHandle handle, const bool isSecure);
  67. /**
  68. * query handle is secure task or not
  69. * Parameter:
  70. * handle: the command queue recorder handle
  71. * Return:
  72. * 0 for false (not secure) and 1 for true (is secure)
  73. */
  74. int32_t cmdqRecIsSecure(cmdqRecHandle handle);
  75. /**
  76. * Add DPAC protection flag
  77. * Parameter:
  78. * Note:
  79. * a. Secure CMDQ support when t-base enabled only
  80. * b. after reset handle, user have to specify protection flag again
  81. */
  82. int32_t cmdqRecSecureEnableDAPC(cmdqRecHandle handle, const uint64_t engineFlag);
  83. /**
  84. * Add flag for M4U security ports
  85. * Parameter:
  86. * Note:
  87. * a. Secure CMDQ support when t-base enabled only
  88. * b. after reset handle, user have to specify protection flag again
  89. */
  90. int32_t cmdqRecSecureEnablePortSecurity(cmdqRecHandle handle, const uint64_t engineFlag);
  91. /**
  92. * Append mark command to the recorder
  93. * Parameter:
  94. * handle: the command queue recorder handle
  95. * Return:
  96. * 0 for success; else the error code is returned
  97. */
  98. int32_t cmdqRecMark(cmdqRecHandle handle);
  99. /**
  100. * Append mark command to enable prefetch
  101. * Parameter:
  102. * handle: the command queue recorder handle
  103. * Return:
  104. * 0 for success; else the error code is returned
  105. */
  106. int32_t cmdqRecEnablePrefetch(cmdqRecHandle handle);
  107. /**
  108. * Append mark command to disable prefetch
  109. * Parameter:
  110. * handle: the command queue recorder handle
  111. * Return:
  112. * 0 for success; else the error code is returned
  113. */
  114. int32_t cmdqRecDisablePrefetch(cmdqRecHandle handle);
  115. /**
  116. * Append write command to the recorder
  117. * Parameter:
  118. * handle: the command queue recorder handle
  119. * addr: the specified target register physical address
  120. * value: the specified target register value
  121. * mask: the specified target register mask
  122. * Return:
  123. * 0 for success; else the error code is returned
  124. */
  125. int32_t cmdqRecWrite(cmdqRecHandle handle, uint32_t addr, uint32_t value, uint32_t mask);
  126. /**
  127. * Append write command to the update secure buffer address in secure path
  128. * Parameter:
  129. * handle: the command queue recorder handle
  130. * addr: the specified register physical address about module src/dst buffer address
  131. * type: base handle type
  132. * base handle: secure handle of a secure mememory
  133. * offset: offset related to base handle (secure buffer = addr(base_handle) + offset)
  134. * size: secure buffer size
  135. * mask: 0xFFFF_FFFF
  136. * Return:
  137. * 0 for success; else the error code is returned
  138. * Note:
  139. * support only when secure OS enabled
  140. */
  141. int32_t cmdqRecWriteSecure(cmdqRecHandle handle,
  142. uint32_t addr,
  143. CMDQ_SEC_ADDR_METADATA_TYPE type,
  144. uint32_t baseHandle,
  145. uint32_t offset, uint32_t size, uint32_t port);
  146. /**
  147. * Append poll command to the recorder
  148. * Parameter:
  149. * handle: the command queue recorder handle
  150. * addr: the specified register physical address
  151. * value: the required register value
  152. * mask: the required register mask
  153. * Return:
  154. * 0 for success; else the error code is returned
  155. */
  156. int32_t cmdqRecPoll(cmdqRecHandle handle, uint32_t addr, uint32_t value, uint32_t mask);
  157. /**
  158. * Append wait command to the recorder
  159. * Parameter:
  160. * handle: the command queue recorder handle
  161. * event: the desired event type to "wait and CLEAR"
  162. * Return:
  163. * 0 for success; else the error code is returned
  164. */
  165. int32_t cmdqRecWait(cmdqRecHandle handle, CMDQ_EVENT_ENUM event);
  166. /**
  167. * like cmdqRecWait, but won't clear the event after
  168. * leaving wait state.
  169. *
  170. * Parameter:
  171. * handle: the command queue recorder handle
  172. * event: the desired event type wait for
  173. * Return:
  174. * 0 for success; else the error code is returned
  175. */
  176. int32_t cmdqRecWaitNoClear(cmdqRecHandle handle, CMDQ_EVENT_ENUM event);
  177. /**
  178. * Unconditionally set to given event to 0.
  179. * Parameter:
  180. * handle: the command queue recorder handle
  181. * event: the desired event type to set
  182. * Return:
  183. * 0 for success; else the error code is returned
  184. */
  185. int32_t cmdqRecClearEventToken(cmdqRecHandle handle, CMDQ_EVENT_ENUM event);
  186. /**
  187. * Unconditionally set to given event to 1.
  188. * Parameter:
  189. * handle: the command queue recorder handle
  190. * event: the desired event type to set
  191. * Return:
  192. * 0 for success; else the error code is returned
  193. */
  194. int32_t cmdqRecSetEventToken(cmdqRecHandle handle, CMDQ_EVENT_ENUM event);
  195. /**
  196. * Read a register value to a CMDQ general purpose register(GPR)
  197. * Parameter:
  198. * handle: the command queue recorder handle
  199. * hwRegAddr: register address to read from
  200. * dstDataReg: CMDQ GPR to write to
  201. * Return:
  202. * 0 for success; else the error code is returned
  203. */
  204. int32_t cmdqRecReadToDataRegister(cmdqRecHandle handle, uint32_t hwRegAddr,
  205. CMDQ_DATA_REGISTER_ENUM dstDataReg);
  206. /**
  207. * Write a register value from a CMDQ general purpose register(GPR)
  208. * Parameter:
  209. * handle: the command queue recorder handle
  210. * srcDataReg: CMDQ GPR to read from
  211. * hwRegAddr: register address to write to
  212. * Return:
  213. * 0 for success; else the error code is returned
  214. */
  215. int32_t cmdqRecWriteFromDataRegister(cmdqRecHandle handle,
  216. CMDQ_DATA_REGISTER_ENUM srcDataReg,
  217. uint32_t hwRegAddr);
  218. /**
  219. * Allocate 32-bit register backup slot
  220. *
  221. */
  222. int32_t cmdqBackupAllocateSlot(cmdqBackupSlotHandle *phBackupSlot, uint32_t slotCount);
  223. /**
  224. * Read 32-bit register backup slot by index
  225. *
  226. */
  227. int32_t cmdqBackupReadSlot(cmdqBackupSlotHandle hBackupSlot, uint32_t slotIndex,
  228. uint32_t *value);
  229. /**
  230. * Use CPU to write value into 32-bit register backup slot by index directly.
  231. *
  232. */
  233. int32_t cmdqBackupWriteSlot(cmdqBackupSlotHandle hBackupSlot, uint32_t slotIndex,
  234. uint32_t value);
  235. /**
  236. * Free allocated backup slot. DO NOT free them before corresponding
  237. * task finishes. Becareful on AsyncFlush use cases.
  238. *
  239. */
  240. int32_t cmdqBackupFreeSlot(cmdqBackupSlotHandle hBackupSlot);
  241. /**
  242. * Insert instructions to backup given 32-bit HW register
  243. * to a backup slot.
  244. * You can use cmdqBackupReadSlot() to retrieve the result
  245. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  246. *
  247. */
  248. int32_t cmdqRecBackupRegisterToSlot(cmdqRecHandle handle,
  249. cmdqBackupSlotHandle hBackupSlot,
  250. uint32_t slotIndex, uint32_t addr);
  251. /**
  252. * Insert instructions to write 32-bit HW register
  253. * from a backup slot.
  254. * You can use cmdqBackupReadSlot() to retrieve the result
  255. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  256. *
  257. */
  258. int32_t cmdqRecBackupWriteRegisterFromSlot(cmdqRecHandle handle,
  259. cmdqBackupSlotHandle hBackupSlot,
  260. uint32_t slotIndex, uint32_t addr);
  261. /**
  262. * Insert instructions to update slot with given 32-bit value
  263. * You can use cmdqBackupReadSlot() to retrieve the result
  264. * AFTER cmdqRecFlush() returns, or INSIDE the callback of cmdqRecFlushAsyncCallback().
  265. *
  266. */
  267. int32_t cmdqRecBackupUpdateSlot(cmdqRecHandle handle,
  268. cmdqBackupSlotHandle hBackupSlot,
  269. uint32_t slotIndex, uint32_t value);
  270. /**
  271. * Trigger CMDQ to execute the recorded commands
  272. * Parameter:
  273. * handle: the command queue recorder handle
  274. * Return:
  275. * 0 for success; else the error code is returned
  276. * Note:
  277. * This is a synchronous function. When the function
  278. * returned, the recorded commands have been done.
  279. */
  280. int32_t cmdqRecFlush(cmdqRecHandle handle);
  281. /**
  282. * Flush the command; Also at the end of the command, backup registers
  283. * appointed by addrArray.
  284. *
  285. */
  286. int32_t cmdqRecFlushAndReadRegister(cmdqRecHandle handle, uint32_t regCount,
  287. uint32_t *addrArray, uint32_t *valueArray);
  288. /**
  289. * Trigger CMDQ to asynchronously execute the recorded commands
  290. * Parameter:
  291. * handle: the command queue recorder handle
  292. * Return:
  293. * 0 for successfully start execution; else the error code is returned
  294. * Note:
  295. * This is an ASYNC function. When the function
  296. * returned, it may or may not be finished. There is no way to retrieve the result.
  297. */
  298. int32_t cmdqRecFlushAsync(cmdqRecHandle handle);
  299. int32_t cmdqRecFlushAsyncCallback(cmdqRecHandle handle, CmdqAsyncFlushCB callback,
  300. uint32_t userData);
  301. /**
  302. * Trigger CMDQ to execute the recorded commands in loop.
  303. * each loop completion generates callback in interrupt context.
  304. *
  305. * Parameter:
  306. * handle: the command queue recorder handle
  307. * irqCallback: this CmdqInterruptCB callback is called after each loop completion.
  308. * data: user data, this will pass back to irqCallback
  309. * hLoop: output, a handle used to stop this loop.
  310. *
  311. * Return:
  312. * 0 for success; else the error code is returned
  313. *
  314. * Note:
  315. * This is an asynchronous function. When the function
  316. * returned, the thread has started. Return -1 in irqCallback to stop it.
  317. */
  318. int32_t cmdqRecStartLoop(cmdqRecHandle handle);
  319. int32_t cmdqRecStartLoopWithCallback(cmdqRecHandle handle, CmdqInterruptCB loopCB, unsigned long loopData);
  320. /**
  321. * Unconditionally stops the loop thread.
  322. * Must call after cmdqRecStartLoop().
  323. */
  324. int32_t cmdqRecStopLoop(cmdqRecHandle handle);
  325. /**
  326. * returns current count of instructions in given handle
  327. */
  328. int32_t cmdqRecGetInstructionCount(cmdqRecHandle handle);
  329. /**
  330. * Record timestamp while CMDQ HW executes here
  331. * This is for prfiling purpose.
  332. *
  333. * Return:
  334. * 0 for success; else the error code is returned
  335. *
  336. * Note:
  337. * Please define CMDQ_PROFILE_MARKER_SUPPORT in cmdq_def.h
  338. * to enable profile marker.
  339. */
  340. int32_t cmdqRecProfileMarker(cmdqRecHandle handle, const char *tag);
  341. /**
  342. * Dump command buffer to kernel log
  343. * This is for debugging purpose.
  344. */
  345. int32_t cmdqRecDumpCommand(cmdqRecHandle handle);
  346. /**
  347. * Estimate command execu time.
  348. * This is for debugging purpose.
  349. *
  350. * Note this estimation supposes all POLL/WAIT condition pass immediately
  351. */
  352. int32_t cmdqRecEstimateCommandExecTime(const cmdqRecHandle handle);
  353. /**
  354. * Destroy command queue recorder handle
  355. * Parameter:
  356. * handle: the command queue recorder handle
  357. */
  358. void cmdqRecDestroy(cmdqRecHandle handle);
  359. /**
  360. * Change instruction of index to NOP instruction
  361. * Current NOP is [JUMP + 8]
  362. *
  363. * Parameter:
  364. * handle: the command queue recorder handle
  365. * index: the index of replaced instruction (start from 0)
  366. * Return:
  367. * > 0 (index) for success; else the error code is returned
  368. */
  369. int32_t cmdqRecSetNOP(cmdqRecHandle handle, uint32_t index);
  370. /**
  371. * Query offset of instruction by instruction name
  372. *
  373. * Parameter:
  374. * handle: the command queue recorder handle
  375. * startIndex: Query offset from "startIndex" of instruction (start from 0)
  376. * opCode: instruction name, you can use the following 6 instruction names:
  377. * CMDQ_CODE_WFE : create via cmdqRecWait()
  378. * CMDQ_CODE_SET_TOKEN : create via cmdqRecSetEventToken()
  379. * CMDQ_CODE_WAIT_NO_CLEAR : create via cmdqRecWaitNoClear()
  380. * CMDQ_CODE_CLEAR_TOKEN : create via cmdqRecClearEventToken()
  381. * CMDQ_CODE_PREFETCH_ENABLE : create via cmdqRecEnablePrefetch()
  382. * CMDQ_CODE_PREFETCH_DISABLE : create via cmdqRecDisablePrefetch()
  383. * event: the desired event type to set, clear, or wait
  384. * Return:
  385. * > 0 (index) for offset of instruction; else the error code is returned
  386. */
  387. int32_t cmdqRecQueryOffset(cmdqRecHandle handle, uint32_t startIndex,
  388. const CMDQ_CODE_ENUM opCode, CMDQ_EVENT_ENUM event);
  389. /**
  390. * acquire resource by resourceEvent
  391. * Parameter:
  392. * handle: the command queue recorder handle
  393. * resourceEvent: the event of resource to control in GCE thread
  394. * Return:
  395. * 0 for success; else the error code is returned
  396. * Note:
  397. * mutex protected, be careful
  398. */
  399. int32_t cmdqRecAcquireResource(cmdqRecHandle handle, CMDQ_EVENT_ENUM resourceEvent);
  400. /**
  401. * acquire resource by resourceEvent and ALSO ADD write instruction to use resource
  402. * Parameter:
  403. * handle: the command queue recorder handle
  404. * resourceEvent: the event of resource to control in GCE thread
  405. * addr, value, mask: same as cmdqRecWrite
  406. * Return:
  407. * 0 for success; else the error code is returned
  408. * Note:
  409. * mutex protected, be careful
  410. * Order: CPU clear resourceEvent at first, then add write instruction
  411. */
  412. int32_t cmdqRecWriteForResource(cmdqRecHandle handle, CMDQ_EVENT_ENUM resourceEvent,
  413. uint32_t addr, uint32_t value, uint32_t mask);
  414. /**
  415. * Release resource by ADD INSTRUCTION to set event
  416. * Parameter:
  417. * handle: the command queue recorder handle
  418. * resourceEvent: the event of resource to control in GCE thread
  419. * Return:
  420. * 0 for success; else the error code is returned
  421. * Note:
  422. * mutex protected, be careful
  423. * Remember to flush handle after this API to release resource via GCE
  424. */
  425. int32_t cmdqRecReleaseResource(cmdqRecHandle handle, CMDQ_EVENT_ENUM resourceEvent);
  426. /**
  427. * Release resource by ADD INSTRUCTION to set event
  428. * Parameter:
  429. * handle: the command queue recorder handle
  430. * resourceEvent: the event of resource to control in GCE thread
  431. * addr, value, mask: same as cmdqRecWrite
  432. * Return:
  433. * 0 for success; else the error code is returned
  434. * Note:
  435. * mutex protected, be careful
  436. * Order: Add add write instruction at first, then set resourceEvent instruction
  437. * Remember to flush handle after this API to release resource via GCE
  438. */
  439. int32_t cmdqRecWriteAndReleaseResource(cmdqRecHandle handle, CMDQ_EVENT_ENUM resourceEvent,
  440. uint32_t addr, uint32_t value, uint32_t mask);
  441. #ifdef __cplusplus
  442. }
  443. #endif
  444. #endif /* __CMDQ_RECORD_H__ */