cmdq_sec_iwc_common.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #ifndef __CMDQ_SEC_IWC_COMMON_H__
  2. #define __CMDQ_SEC_IWC_COMMON_H__
  3. #include "cmdqSecTl_Api.h"
  4. /* shared DRAM */
  5. #define CMDQ_SEC_SHARED_IRQ_RAISED_OFFSET (0x100) /* bit x = 1 means thread x raise IRQ */
  6. /* #define CMDQ_SEC_SHARED_THR_CNT_OFFSET (0x100) */
  7. #define CMDQ_SEC_SHARED_THR_CNT_OFFSET (0x0)
  8. /* commanad buffer & metadata */
  9. #define CMDQ_TZ_CMD_BLOCK_SIZE (32 * 1024)
  10. #define CMDQ_IWC_MAX_CMD_LENGTH (32 * 1024 / 4)
  11. #define CMDQ_IWC_MAX_ADDR_LIST_LENGTH (12)
  12. #define CMDQ_IWC_CLIENT_NAME (16)
  13. typedef enum CMDQ_IWC_ADDR_METADATA_TYPE {
  14. CMDQ_IWC_H_2_PA = 0, /* sec handle to sec PA */
  15. CMDQ_IWC_H_2_MVA = 1, /* sec handle to sec MVA */
  16. CMDQ_IWC_NMVA_2_MVA = 2, /* map normal MVA to secure world */
  17. CMDQ_IWC_DDP_REG_HDCP = 3, /* DDP register needs to set opposite value when HDCP fail */
  18. } CMDQ_IWC_ADDR_METADATA_TYPE;
  19. /* */
  20. /* profile setting enum */
  21. /* .default is 0, not enable profile, otherwise we enalbe it depends on profile bit */
  22. /* */
  23. typedef enum CMDQ_IWC_PROF_ENUM {
  24. CMDQ_IWC_PROF_LOG,
  25. CMDQ_IWC_PROF_SYSTRACE,
  26. } CMDQ_IWC_PROF_ENUM;
  27. /* IWC systrace tag enum */
  28. typedef enum CMDQ_IWC_SYSTRACE_TAG_ENUM {
  29. /* profile cmdqSecDR */
  30. CMDQ_IST_CMDQ_IPC = 0,
  31. CMDQ_IST_CMDQ_TASK_ACQ,
  32. CMDQ_IST_CMDQ_TASK_REL,
  33. CMDQ_IST_CMDQ_HW,
  34. CMDQ_IST_CMDQ_SIG_WAIT,
  35. CMDQ_IST_CMDQ_LAST_TAG, /* dummy tag, just mark end of CMDQ driver profiling tag */
  36. /* profile cmdqSecTL */
  37. CMDQ_IST_CMD_ALLOC,
  38. CMDQ_IST_H2PAS,
  39. CMDQ_IST_PORT_ON,
  40. CMDQ_IST_PORT_OFF,
  41. CMDQ_IST_DAPC_ON,
  42. CMDQ_IST_DAPC_OFF,
  43. CMDQ_IST_SUBMIT,
  44. /* always at the end */
  45. CMDQ_IST_MAX_COUNT,
  46. } CMDQ_IWC_SYSTRACE_TAG_ENUM;
  47. /* */
  48. /* IWC message */
  49. /* */
  50. typedef struct {
  51. /* [IN]_d, index of instruction. Update its argB value to real PA/MVA in secure world */
  52. uint32_t instrIndex;
  53. uint32_t type; /* [IN] addr handle type */
  54. uint32_t baseHandle; /* [IN]_h, secure address handle */
  55. uint32_t offset; /* [IN]_b, buffser offset to secure handle */
  56. uint32_t size; /* buffer size */
  57. uint32_t port; /* hw port id (i.e. M4U port id) */
  58. } iwcCmdqAddrMetadata_t;
  59. enum CMDQ_DISP_MODE {
  60. CMDQ_DISP_NON_SUPPORTED_MODE = 0,
  61. CMDQ_DISP_SINGLE_MODE = 1,
  62. CMDQ_DISP_VIDEO_MODE = 2,
  63. CMDQ_MDP_USER_MODE = 3,
  64. };
  65. typedef struct {
  66. enum LOG_LEVEL logLevel;
  67. int32_t enableProfile;
  68. } iwcCmdqDebugConfig_t;
  69. typedef struct {
  70. uint64_t startTime; /* start timestamp */
  71. uint64_t endTime; /* end timestamp */
  72. } iwcCmdqSystraceLog_t;
  73. typedef struct {
  74. uint32_t addrListLength;
  75. iwcCmdqAddrMetadata_t addrList[CMDQ_IWC_MAX_ADDR_LIST_LENGTH];
  76. uint64_t enginesNeedDAPC;
  77. uint64_t enginesNeedPortSecurity;
  78. enum CMDQ_DISP_MODE secMode;
  79. /* for MDP to copy HDCP version from srcHandle to dstHandle */
  80. uint32_t srcHandle;
  81. uint32_t dstHandle;
  82. } iwcCmdqMetadata_t;
  83. typedef struct {
  84. long shareMemoryPA;
  85. unsigned long shareMemoryVA;
  86. uint32_t size;
  87. } iwcCmdqPathResource_t;
  88. typedef struct {
  89. /* [IN] */
  90. int32_t thread;
  91. uint32_t waitCookie;
  92. /* [OUT] */
  93. bool throwAEE;
  94. bool hasReset;
  95. int32_t irqStatus; /* global secure IRQ flag */
  96. int32_t irqFlag; /* thread IRQ flag */
  97. uint32_t errInstr[2]; /*errInstr[0] = instB, errInstr[1] = instA */
  98. uint32_t pc;
  99. } iwcCmdqCancelTask_t;
  100. typedef struct {
  101. /* share memory with NWd */
  102. /* startPA and size must be 4K aligned for drApiMapPhys */
  103. /* uint32_t sharedThrExecCntPA; // [IN]PA start address of THR cookie */
  104. /* uint32_t sharedThrExecCntSize; */
  105. /* basic execution data */
  106. uint32_t thread;
  107. uint32_t scenario;
  108. uint32_t priority;
  109. uint32_t commandSize;
  110. uint64_t engineFlag;
  111. uint32_t pVABase[CMDQ_IWC_MAX_CMD_LENGTH];
  112. /* exec order data */
  113. uint32_t waitCookie; /* [IN] index in thread's task list, it should be (nextCookie - 1) */
  114. bool resetExecCnt; /* [IN] reset HW thread */
  115. /* client info */
  116. int32_t callerPid;
  117. char callerName[CMDQ_IWC_CLIENT_NAME];
  118. /* metadata */
  119. iwcCmdqMetadata_t metadata;
  120. /* debug */
  121. uint64_t hNormalTask; /* handle to reference task in normal world */
  122. } iwcCmdqCommand_t;
  123. /* */
  124. /* linex kernel and mobicore has their own MMU tables, */
  125. /* the latter's is used to map world shared memory and physical address */
  126. /* so mobicore dose not understand linux virtual address mapping. */
  127. /* */
  128. /* if we want to transact a large buffer in TCI/DCI, there are 2 method (both need 1 copy): */
  129. /* 1. use mc_map, to map normal world buffer to WSM, and pass secure_virt_addr in TCI/DCI buffer */
  130. /* note mc_map implies a memcopy to copy content from normal world to WSM */
  131. /* 2. declare a fixed length array in TCI/DCI struct, and its size must be < 1M */
  132. /* */
  133. typedef struct {
  134. union {
  135. uint32_t cmd; /* [IN] command id */
  136. int32_t rsp; /* [OUT] 0 for success, < 0 for error */
  137. };
  138. union {
  139. iwcCmdqCommand_t command;
  140. iwcCmdqCancelTask_t cancelTask;
  141. iwcCmdqPathResource_t pathResource;
  142. };
  143. iwcCmdqDebugConfig_t debug;
  144. } iwcCmdqMessage_t, *iwcCmdqMessage_ptr;
  145. /* */
  146. /* ERROR code number (ERRNO) */
  147. /* note the error result returns negative value, i.e, -(ERRNO) */
  148. /* */
  149. #define CMDQ_ERR_NOMEM (12) /* out of memory */
  150. #define CMDQ_ERR_FAULT (14) /* bad address */
  151. #define CMDQ_ERR_ADDR_CONVERT_HANDLE_2_PA (1000)
  152. #define CMDQ_ERR_ADDR_CONVERT_ALLOC_MVA (1100)
  153. #define CMDQ_ERR_ADDR_CONVERT_FREE_MVA (1200)
  154. #define CMDQ_ERR_PORT_CONFIG (1300)
  155. /* param check */
  156. #define CMDQ_ERR_UNKNOWN_ADDR_METADATA_TYPE (1400)
  157. #define CMDQ_ERR_TOO_MANY_SEC_HANDLE (1401)
  158. /* security check */
  159. #define CMDQ_ERR_SECURITY_INVALID_INSTR (1500)
  160. #define CMDQ_ERR_SECURITY_INVALID_SEC_HANDLE (1501)
  161. #define CMDQ_ERR_SECURITY_INVALID_DAPC_FALG (1502)
  162. #define CMDQ_ERR_INSERT_DAPC_INSTR_FAILED (1503)
  163. #define CMDQ_ERR_INSERT_PORT_SECURITY_INSTR_FAILED (1504)
  164. #define CMDQ_ERR_NON_SUPPORT_DISP_MODE (1505)
  165. #define CMDQ_TL_ERR_UNKNOWN_IWC_CMD (5000)
  166. #define CMDQ_ERR_DR_IPC_EXECUTE_SESSION (5001)
  167. #define CMDQ_ERR_DR_IPC_CLOSE_SESSION (5002)
  168. #define CMDQ_ERR_DR_EXEC_FAILED (5003)
  169. #endif /* __CMDQ_SEC_TLAPI_H__ */