cmdq_def.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #ifndef __CMDQ_DEF_H__
  2. #define __CMDQ_DEF_H__
  3. #ifdef CONFIG_OF
  4. #define CMDQ_OF_SUPPORT /* enable device tree support */
  5. #else
  6. #undef CMDQ_OF_SUPPORT
  7. #endif
  8. /* CMDQ capability*/
  9. #define CMDQ_GPR_SUPPORT
  10. #define CMDQ_DUMP_GIC (0) /* TODO: enable when GIC porting done */
  11. #define CMDQ_PROFILE_MMP (0)
  12. #include <linux/kernel.h>
  13. #include "cmdq_def_idv.h"
  14. #ifdef CMDQ_SECURE_PATH_SUPPORT
  15. #include "cmdq_sec_iwc_common.h"
  16. #endif
  17. #include "cmdq_sec_iwc_common.h"
  18. #ifdef CONFIG_MTK_SMI_EXT
  19. /* #define CMDQ_CONFIG_SMI (1) */
  20. #endif
  21. #define CMDQ_INIT_FREE_TASK_COUNT (8)
  22. #define CMDQ_MAX_THREAD_COUNT (16)
  23. #define CMDQ_MAX_HIGH_PRIORITY_THREAD_COUNT (6) /* Thread that are high-priority (display threads) */
  24. #define CMDQ_MIN_SECURE_THREAD_ID (12)
  25. #define CMDQ_MAX_SECURE_THREAD_COUNT (3)
  26. #define CMDQ_MAX_TRIGGER_LOOP_COUNT (2)
  27. #define CMDQ_MAX_RECORD_COUNT (1024)
  28. #define CMDQ_MAX_ERROR_COUNT (2)
  29. #define CMDQ_MAX_RETRY_COUNT (1)
  30. #define CMDQ_MAX_TASK_IN_THREAD (16)
  31. #define CMDQ_MAX_READ_SLOT_COUNT (4)
  32. #define CMDQ_MAX_PREFETCH_INSTUCTION (240) /* Maximum prefetch buffer size, in instructions. */
  33. #define CMDQ_INITIAL_CMD_BLOCK_SIZE (PAGE_SIZE)
  34. #define CMDQ_EMERGENCY_BLOCK_SIZE (256 * 1024) /* 128KB command buffer */
  35. #define CMDQ_EMERGENCY_BLOCK_COUNT (4)
  36. #define CMDQ_INST_SIZE (2 * sizeof(uint32_t)) /* instruction is 64-bit */
  37. #define CMDQ_MAX_LOOP_COUNT (1000000)
  38. #define CMDQ_MAX_INST_CYCLE (27)
  39. #define CMDQ_MIN_AGE_VALUE (5)
  40. #define CMDQ_MAX_ERROR_SIZE (8 * 1024)
  41. #define CMDQ_MAX_COOKIE_VALUE (0xFFFF) /* max value of CMDQ_THR_EXEC_CMD_CNT (value starts from 0) */
  42. #define CMDQ_ARG_A_SUBSYS_MASK (0x001F0000)
  43. #ifdef CONFIG_MTK_FPGA
  44. #define CMDQ_DEFAULT_TIMEOUT_MS (10000)
  45. #else
  46. #define CMDQ_DEFAULT_TIMEOUT_MS (1000)
  47. #endif
  48. #define CMDQ_ACQUIRE_THREAD_TIMEOUT_MS (2000)
  49. #define CMDQ_PREDUMP_TIMEOUT_MS (200)
  50. #define CMDQ_PREDUMP_RETRY_COUNT (5)
  51. #define CMDQ_INVALID_THREAD (-1)
  52. #define CMDQ_DRIVER_DEVICE_NAME "mtk_cmdq"
  53. #define CMDQ_SEC_SHARED_MEM_THR_CNT_BASE (0)
  54. #ifndef CONFIG_MTK_FPGA
  55. #define CMDQ_PWR_AWARE 1 /* FPGA does not have ClkMgr */
  56. #else
  57. #undef CMDQ_PWR_AWARE
  58. #endif
  59. enum CMDQ_SCENARIO_ENUM {
  60. CMDQ_SCENARIO_JPEG_DEC = 0,
  61. CMDQ_SCENARIO_PRIMARY_DISP = 1,
  62. CMDQ_SCENARIO_PRIMARY_MEMOUT = 2,
  63. CMDQ_SCENARIO_PRIMARY_ALL = 3,
  64. CMDQ_SCENARIO_SUB_DISP = 4,
  65. CMDQ_SCENARIO_SUB_MEMOUT = 5,
  66. CMDQ_SCENARIO_SUB_ALL = 6,
  67. CMDQ_SCENARIO_MHL_DISP = 7,
  68. CMDQ_SCENARIO_RDMA0_DISP = 8,
  69. CMDQ_SCENARIO_RDMA2_DISP = 9,
  70. CMDQ_SCENARIO_TRIGGER_LOOP = 10, /* Trigger loop scenario does not enable HWs */
  71. CMDQ_SCENARIO_DISP_CONFIG_AAL = 11,
  72. CMDQ_SCENARIO_DISP_CONFIG_PRIMARY_GAMMA = 12,
  73. CMDQ_SCENARIO_DISP_CONFIG_SUB_GAMMA = 13,
  74. CMDQ_SCENARIO_DISP_CONFIG_PRIMARY_DITHER = 14,
  75. CMDQ_SCENARIO_DISP_CONFIG_SUB_DITHER = 15,
  76. CMDQ_SCENARIO_DISP_CONFIG_PRIMARY_PWM = 16,
  77. CMDQ_SCENARIO_DISP_CONFIG_SUB_PWM = 17,
  78. CMDQ_SCENARIO_DISP_CONFIG_PRIMARY_PQ = 18,
  79. CMDQ_SCENARIO_DISP_CONFIG_SUB_PQ = 19,
  80. CMDQ_SCENARIO_DISP_CONFIG_OD = 20,
  81. CMDQ_SCENARIO_USER_SPACE = 21, /* client from user space, so the cmd buffer is in user space. */
  82. CMDQ_SCENARIO_DEBUG = 22,
  83. CMDQ_SCENARIO_DEBUG_PREFETCH = 23,
  84. CMDQ_SCENARIO_DISP_ESD_CHECK = 24, /* ESD check */
  85. /* for screen capture to wait for RDMA-done without blocking config thread */
  86. CMDQ_SCENARIO_DISP_SCREEN_CAPTURE = 25,
  87. CMDQ_SCENARIO_USER_MDP = 26, /* client from user space, so the cmd buffer is in user space. */
  88. CMDQ_SCENARIO_SECURE_NOTIFY_LOOP = 27, /* notifiy there are some tasks exec done in secure path */
  89. CMDQ_SCENARIO_DISP_PRIMARY_DISABLE_SECURE_PATH = 28,
  90. CMDQ_SCENARIO_DISP_SUB_DISABLE_SECURE_PATH = 29,
  91. CMDQ_SCENARIO_DISP_COLOR = 30, /* color path request from kernel */
  92. CMDQ_SCENARIO_USER_DISP_COLOR = 31, /* color path request from user sapce */
  93. CMDQ_SCENARIO_DISP_MIRROR_MODE = 32,
  94. CMDQ_MAX_SCENARIO_COUNT /* ALWAYS keep at the end */
  95. };
  96. enum CMDQ_HW_THREAD_PRIORITY_ENUM {
  97. CMDQ_THR_PRIO_NORMAL = 0, /* nomral (lowest) priority */
  98. CMDQ_THR_PRIO_DISPLAY_TRIGGER = 1, /* trigger loop (enables display mutex) */
  99. CMDQ_THR_PRIO_DISPLAY_ESD = 3, /* display ESD check (every 2 secs) */
  100. CMDQ_THR_PRIO_DISPLAY_CONFIG = 3, /* display config (every frame) */
  101. CMDQ_THR_PRIO_MAX = 7, /* maximum possible priority */
  102. };
  103. enum CMDQ_DATA_REGISTER_ENUM {
  104. /* Value Reg, we use 32-bit */
  105. /* Address Reg, we use 64-bit */
  106. /* Note that R0-R15 and P0-P7 actullay share same memory */
  107. /* and R1 cannot be used. */
  108. CMDQ_DATA_REG_JPEG = 0x00, /* R0 */
  109. CMDQ_DATA_REG_JPEG_DST = 0x11, /* P1 */
  110. CMDQ_DATA_REG_PQ_COLOR = 0x04, /* R4 */
  111. CMDQ_DATA_REG_PQ_COLOR_DST = 0x13, /* P3 */
  112. CMDQ_DATA_REG_2D_SHARPNESS_0 = 0x05, /* R5 */
  113. CMDQ_DATA_REG_2D_SHARPNESS_0_DST = 0x14, /* P4 */
  114. CMDQ_DATA_REG_2D_SHARPNESS_1 = 0x0a, /* R10 */
  115. CMDQ_DATA_REG_2D_SHARPNESS_1_DST = 0x16, /* P6 */
  116. CMDQ_DATA_REG_DEBUG = 0x0b, /* R11 */
  117. CMDQ_DATA_REG_DEBUG_DST = 0x17, /* P7 */
  118. /* sentinel value for invalid register ID */
  119. CMDQ_DATA_REG_INVALID = -1,
  120. };
  121. /* CMDQ Events */
  122. #undef DECLARE_CMDQ_EVENT
  123. #define DECLARE_CMDQ_EVENT(name, val) name = val,
  124. enum CMDQ_EVENT_ENUM {
  125. #include "cmdq_event.h"
  126. };
  127. #undef DECLARE_CMDQ_EVENT
  128. /* Custom "wide" pointer type for 64-bit job handle (pointer to VA) */
  129. typedef unsigned long long cmdqJobHandle_t;
  130. /* Custom "wide" pointer type for 64-bit compatibility. Always cast from uint32_t*. */
  131. typedef unsigned long long cmdqU32Ptr_t;
  132. #define CMDQ_U32_PTR(x) ((uint32_t *)(unsigned long)x)
  133. struct cmdqReadRegStruct {
  134. uint32_t count; /* number of entries in regAddresses */
  135. cmdqU32Ptr_t regAddresses; /* an array of 32-bit register addresses (uint32_t) */
  136. };
  137. struct cmdqRegValueStruct {
  138. /* number of entries in result */
  139. uint32_t count;
  140. /* number of entries in result */
  141. /* array of 32-bit register values (uint32_t). */
  142. /* in the same order as cmdqReadRegStruct */
  143. cmdqU32Ptr_t regValues;
  144. };
  145. struct cmdqReadAddressStruct {
  146. uint32_t count; /* [IN] number of entries in result. */
  147. /* [IN] array of physical addresses to read. */
  148. /* these value must allocated by CMDQ_IOCTL_ALLOC_WRITE_ADDRESS ioctl */
  149. /* */
  150. /* indeed param dmaAddresses should be UNSIGNED LONG type for 64 bit kernel. */
  151. /* Considering our plartform supports max 4GB RAM(upper-32bit don't care for SW) */
  152. /* and consistent common code interface, remain uint32_t type. */
  153. cmdqU32Ptr_t dmaAddresses;
  154. cmdqU32Ptr_t values; /* [OUT] uint32_t values that dmaAddresses point into */
  155. };
  156. /*
  157. * Secure address metadata:
  158. * According to handle type, translate handle and replace (_d)th instruciton to
  159. * 1. sec_addr = hadnle_sec_base_addr(baseHandle) + offset(_b)
  160. * 2. sec_mva = mva( hadnle_sec_base_addr(baseHandle) + offset(_b) )
  161. * 3. secure world normal mva = map(baseHandle)
  162. * . pass normal mva to parameter baseHandle
  163. * . use case: OVL reads from secure and normal buffers at the same time)
  164. */
  165. typedef enum CMDQ_SEC_ADDR_METADATA_TYPE {
  166. CMDQ_SAM_H_2_PA = 0, /* sec handle to sec PA */
  167. CMDQ_SAM_H_2_MVA = 1, /* sec handle to sec MVA */
  168. CMDQ_SAM_NMVA_2_MVA = 2, /* map normal MVA to secure world */
  169. CMDQ_SAM_DDP_REG_HDCP = 3, /* DDP register needs to set opposite value when HDCP fail */
  170. } CMDQ_SEC_ADDR_METADATA_TYPE;
  171. typedef struct cmdqSecAddrMetadataStruct {
  172. /* [IN]_d, index of instruction. Update its argB value to real PA/MVA in secure world */
  173. uint32_t instrIndex;
  174. CMDQ_SEC_ADDR_METADATA_TYPE type; /* [IN] addr handle type */
  175. uint32_t baseHandle; /* [IN]_h, secure address handle */
  176. uint32_t offset; /* [IN]_b, buffser offset to secure handle */
  177. uint32_t size; /* buffer size */
  178. uint32_t port; /* hw port id (i.e. M4U port id) */
  179. } cmdqSecAddrMetadataStruct;
  180. typedef struct cmdqSecDataStruct {
  181. bool isSecure; /* [IN]true for secure command */
  182. /* address metadata, used to translate secure buffer PA related instruction in secure world */
  183. uint32_t addrMetadataCount; /* [IN] count of element in addrList */
  184. cmdqU32Ptr_t addrMetadatas; /* [IN] array of cmdqSecAddrMetadataStruct */
  185. uint32_t addrMetadataMaxCount; /*[Reserved] */
  186. uint64_t enginesNeedDAPC;
  187. uint64_t enginesNeedPortSecurity;
  188. /* [Reserved] This is for CMDQ driver usage itself. Not for client. */
  189. int32_t waitCookie; /* task index in thread's tasklist. -1 for not in tasklist. */
  190. bool resetExecCnt; /* reset HW thread in SWd */
  191. /* for MDP to copy HDCP version from srcHandle to dstHandle */
  192. uint32_t srcHandle;
  193. uint32_t dstHandle;
  194. enum CMDQ_DISP_MODE secMode;
  195. } cmdqSecDataStruct;
  196. struct cmdqCommandStruct {
  197. uint32_t scenario; /* [IN] deprecated. will remove in the future. */
  198. uint32_t priority; /* [IN] task schedule priority. this is NOT HW thread priority. */
  199. uint64_t engineFlag; /* [IN] bit flag of engines used. */
  200. /* [IN] pointer to instruction buffer. Use 64-bit for compatibility. */
  201. /* This must point to an 64-bit aligned uint32_t array */
  202. cmdqU32Ptr_t pVABase;
  203. uint32_t blockSize; /* [IN] size of instruction buffer, in bytes. */
  204. struct cmdqReadRegStruct regRequest; /* [IN] request to read register values at the end of command */
  205. struct cmdqRegValueStruct regValue; /* [OUT] register values of regRequest */
  206. struct cmdqReadAddressStruct readAddress; /* [IN/OUT] physical addresses to read value */
  207. cmdqSecDataStruct secData; /*[IN] secure execution data */
  208. uint32_t debugRegDump; /* [IN] set to non-zero to enable register debug dump. */
  209. /* [Reserved] This is for CMDQ driver usage itself. */
  210. /* Not for client. Do not access this field from User Space */
  211. cmdqU32Ptr_t privateData;
  212. };
  213. struct cmdqSyncHandleHdcpStruct {
  214. uint32_t srcHandle;
  215. uint32_t dstHandle;
  216. };
  217. enum CMDQ_CAP_BITS {
  218. CMDQ_CAP_WFE = 0, /* bit 0: TRUE if WFE instruction support is ready. FALSE if we need to POLL instead. */
  219. };
  220. /**
  221. * reply struct for cmdq_sec_cancel_error_task
  222. */
  223. typedef struct {
  224. /* [OUT] */
  225. bool throwAEE;
  226. bool hasReset;
  227. int32_t irqFlag;
  228. uint32_t errInstr[2];
  229. uint32_t pc;
  230. } cmdqSecCancelTaskResultStruct;
  231. #ifdef CMDQ_OF_SUPPORT
  232. typedef enum CMDQ_SUBSYS_ENUM {
  233. CMDQ_SUBSYSCLK_SYS_VDE,
  234. CMDQ_SUBSYSCLK_SYS_ISP,
  235. CMDQ_SUBSYSCLK_SYS_DIS,
  236. CMDQ_SUBSYSCLK_NUM
  237. } CMDQ_SUBSYS_ENUM;
  238. #endif
  239. #endif /* __CMDQ_DEF_H__ */