msm_vidc_iris2.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/interrupt.h>
  6. #include "msm_vidc_iris2.h"
  7. #include "msm_vidc_buffer_iris2.h"
  8. #include "msm_vidc_power_iris2.h"
  9. #include "venus_hfi.h"
  10. #include "msm_vidc_inst.h"
  11. #include "msm_vidc_core.h"
  12. #include "msm_vidc_driver.h"
  13. #include "msm_vidc_dt.h"
  14. #include "msm_vidc_internal.h"
  15. #include "msm_vidc_buffer.h"
  16. #include "msm_vidc_debug.h"
  17. #define VBIF_BASE_OFFS_IRIS2 0x00080000
  18. #define CPU_BASE_OFFS_IRIS2 0x000A0000
  19. #define AON_BASE_OFFS 0x000E0000
  20. #define CPU_CS_BASE_OFFS_IRIS2 (CPU_BASE_OFFS_IRIS2)
  21. #define CPU_IC_BASE_OFFS_IRIS2 (CPU_BASE_OFFS_IRIS2)
  22. #define CPU_CS_A2HSOFTINTCLR_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x1C)
  23. #define CPU_CS_VCICMD_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x20)
  24. #define CPU_CS_VCICMDARG0_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x24)
  25. #define CPU_CS_VCICMDARG1_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x28)
  26. #define CPU_CS_VCICMDARG2_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x2C)
  27. #define CPU_CS_VCICMDARG3_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x30)
  28. #define CPU_CS_VMIMSG_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x34)
  29. #define CPU_CS_VMIMSGAG0_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x38)
  30. #define CPU_CS_VMIMSGAG1_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x3C)
  31. #define CPU_CS_SCIACMD_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x48)
  32. #define CPU_CS_H2XSOFTINTEN_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x148)
  33. /* HFI_CTRL_STATUS */
  34. #define CPU_CS_SCIACMDARG0_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x4C)
  35. #define CPU_CS_SCIACMDARG0_HFI_CTRL_ERROR_STATUS_BMSK_IRIS2 0xfe
  36. #define CPU_CS_SCIACMDARG0_HFI_CTRL_PC_READY_IRIS2 0x100
  37. #define CPU_CS_SCIACMDARG0_HFI_CTRL_INIT_IDLE_MSG_BMSK_IRIS2 0x40000000
  38. /* HFI_QTBL_INFO */
  39. #define CPU_CS_SCIACMDARG1_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x50)
  40. /* HFI_QTBL_ADDR */
  41. #define CPU_CS_SCIACMDARG2_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x54)
  42. /* HFI_VERSION_INFO */
  43. #define CPU_CS_SCIACMDARG3_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x58)
  44. /* SFR_ADDR */
  45. #define CPU_CS_SCIBCMD_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x5C)
  46. /* MMAP_ADDR */
  47. #define CPU_CS_SCIBCMDARG0_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x60)
  48. /* UC_REGION_ADDR */
  49. #define CPU_CS_SCIBARG1_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x64)
  50. /* UC_REGION_ADDR */
  51. #define CPU_CS_SCIBARG2_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x68)
  52. /* FAL10 Feature Control */
  53. #define CPU_CS_X2RPMh_IRIS2 (CPU_CS_BASE_OFFS_IRIS2 + 0x168)
  54. #define CPU_CS_X2RPMh_MASK0_BMSK_IRIS2 0x1
  55. #define CPU_CS_X2RPMh_MASK0_SHFT_IRIS2 0x0
  56. #define CPU_CS_X2RPMh_MASK1_BMSK_IRIS2 0x2
  57. #define CPU_CS_X2RPMh_MASK1_SHFT_IRIS2 0x1
  58. #define CPU_CS_X2RPMh_SWOVERRIDE_BMSK_IRIS2 0x4
  59. #define CPU_CS_X2RPMh_SWOVERRIDE_SHFT_IRIS2 0x3
  60. #define CPU_IC_SOFTINT_IRIS2 (CPU_IC_BASE_OFFS_IRIS2 + 0x150)
  61. #define CPU_IC_SOFTINT_H2A_SHFT_IRIS2 0x0
  62. /*
  63. * --------------------------------------------------------------------------
  64. * MODULE: wrapper
  65. * --------------------------------------------------------------------------
  66. */
  67. #define WRAPPER_BASE_OFFS_IRIS2 0x000B0000
  68. #define WRAPPER_INTR_STATUS_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x0C)
  69. #define WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS2 0x8
  70. #define WRAPPER_INTR_STATUS_A2H_BMSK_IRIS2 0x4
  71. #define WRAPPER_INTR_MASK_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x10)
  72. #define WRAPPER_INTR_MASK_A2HWD_BMSK_IRIS2 0x8
  73. #define WRAPPER_INTR_MASK_A2HCPU_BMSK_IRIS2 0x4
  74. #define WRAPPER_CPU_CLOCK_CONFIG_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x2000)
  75. #define WRAPPER_CPU_CGC_DIS_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x2010)
  76. #define WRAPPER_CPU_STATUS_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x2014)
  77. #define WRAPPER_DEBUG_BRIDGE_LPI_CONTROL_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x54)
  78. #define WRAPPER_DEBUG_BRIDGE_LPI_STATUS_IRIS2 (WRAPPER_BASE_OFFS_IRIS2 + 0x58)
  79. /*
  80. * --------------------------------------------------------------------------
  81. * MODULE: tz_wrapper
  82. * --------------------------------------------------------------------------
  83. */
  84. #define WRAPPER_TZ_BASE_OFFS 0x000C0000
  85. #define WRAPPER_TZ_CPU_CLOCK_CONFIG (WRAPPER_TZ_BASE_OFFS)
  86. #define WRAPPER_TZ_CPU_STATUS (WRAPPER_TZ_BASE_OFFS + 0x10)
  87. #define CTRL_INIT_IRIS2 CPU_CS_SCIACMD_IRIS2
  88. #define CTRL_STATUS_IRIS2 CPU_CS_SCIACMDARG0_IRIS2
  89. #define CTRL_ERROR_STATUS__M_IRIS2 \
  90. CPU_CS_SCIACMDARG0_HFI_CTRL_ERROR_STATUS_BMSK_IRIS2
  91. #define CTRL_INIT_IDLE_MSG_BMSK_IRIS2 \
  92. CPU_CS_SCIACMDARG0_HFI_CTRL_INIT_IDLE_MSG_BMSK_IRIS2
  93. #define CTRL_STATUS_PC_READY_IRIS2 \
  94. CPU_CS_SCIACMDARG0_HFI_CTRL_PC_READY_IRIS2
  95. #define QTBL_INFO_IRIS2 CPU_CS_SCIACMDARG1_IRIS2
  96. #define QTBL_ADDR_IRIS2 CPU_CS_SCIACMDARG2_IRIS2
  97. #define VERSION_INFO_IRIS2 CPU_CS_SCIACMDARG3_IRIS2
  98. #define SFR_ADDR_IRIS2 CPU_CS_SCIBCMD_IRIS2
  99. #define MMAP_ADDR_IRIS2 CPU_CS_SCIBCMDARG0_IRIS2
  100. #define UC_REGION_ADDR_IRIS2 CPU_CS_SCIBARG1_IRIS2
  101. #define UC_REGION_SIZE_IRIS2 CPU_CS_SCIBARG2_IRIS2
  102. #define AON_WRAPPER_MVP_NOC_LPI_CONTROL (AON_BASE_OFFS)
  103. #define AON_WRAPPER_MVP_NOC_LPI_STATUS (AON_BASE_OFFS + 0x4)
  104. /*
  105. * --------------------------------------------------------------------------
  106. * MODULE: vcodec noc error log registers (iris2)
  107. * --------------------------------------------------------------------------
  108. */
  109. #define VCODEC_NOC_VIDEO_A_NOC_BASE_OFFS 0x00010000
  110. #define VCODEC_NOC_ERL_MAIN_SWID_LOW 0x00011200
  111. #define VCODEC_NOC_ERL_MAIN_SWID_HIGH 0x00011204
  112. #define VCODEC_NOC_ERL_MAIN_MAINCTL_LOW 0x00011208
  113. #define VCODEC_NOC_ERL_MAIN_ERRVLD_LOW 0x00011210
  114. #define VCODEC_NOC_ERL_MAIN_ERRCLR_LOW 0x00011218
  115. #define VCODEC_NOC_ERL_MAIN_ERRLOG0_LOW 0x00011220
  116. #define VCODEC_NOC_ERL_MAIN_ERRLOG0_HIGH 0x00011224
  117. #define VCODEC_NOC_ERL_MAIN_ERRLOG1_LOW 0x00011228
  118. #define VCODEC_NOC_ERL_MAIN_ERRLOG1_HIGH 0x0001122C
  119. #define VCODEC_NOC_ERL_MAIN_ERRLOG2_LOW 0x00011230
  120. #define VCODEC_NOC_ERL_MAIN_ERRLOG2_HIGH 0x00011234
  121. #define VCODEC_NOC_ERL_MAIN_ERRLOG3_LOW 0x00011238
  122. #define VCODEC_NOC_ERL_MAIN_ERRLOG3_HIGH 0x0001123C
  123. static int __interrupt_init_iris2(struct msm_vidc_core *vidc_core)
  124. {
  125. u32 mask_val = 0;
  126. struct msm_vidc_core *core = vidc_core;
  127. if (!core) {
  128. d_vpr_e("%s: invalid params\n", __func__);
  129. return -EINVAL;
  130. }
  131. /* All interrupts should be disabled initially 0x1F6 : Reset value */
  132. mask_val = __read_register(core, WRAPPER_INTR_MASK_IRIS2);
  133. /* Write 0 to unmask CPU and WD interrupts */
  134. mask_val &= ~(WRAPPER_INTR_MASK_A2HWD_BMSK_IRIS2|
  135. WRAPPER_INTR_MASK_A2HCPU_BMSK_IRIS2);
  136. __write_register(core, WRAPPER_INTR_MASK_IRIS2, mask_val);
  137. return 0;
  138. }
  139. static int __setup_ucregion_memory_map_iris2(struct msm_vidc_core *vidc_core)
  140. {
  141. struct msm_vidc_core *core = vidc_core;
  142. if (!core) {
  143. d_vpr_e("%s: invalid params\n", __func__);
  144. return -EINVAL;
  145. }
  146. __write_register(core, UC_REGION_ADDR_IRIS2,
  147. (u32)core->iface_q_table.align_device_addr);
  148. __write_register(core, UC_REGION_SIZE_IRIS2, SHARED_QSIZE);
  149. __write_register(core, QTBL_ADDR_IRIS2,
  150. (u32)core->iface_q_table.align_device_addr);
  151. __write_register(core, QTBL_INFO_IRIS2, 0x01);
  152. /* update queues vaddr for debug purpose */
  153. __write_register(core, CPU_CS_VCICMDARG0_IRIS2,
  154. (u32)((u64)core->iface_q_table.align_virtual_addr));
  155. __write_register(core, CPU_CS_VCICMDARG1_IRIS2,
  156. (u32)((u64)core->iface_q_table.align_virtual_addr >> 32));
  157. return 0;
  158. }
  159. static int __power_off_iris2(struct msm_vidc_core *vidc_core)
  160. {
  161. u32 lpi_status, reg_status = 0, count = 0, max_count = 10;
  162. struct msm_vidc_core *core = vidc_core;
  163. if (!core) {
  164. d_vpr_e("%s: invalid params\n", __func__);
  165. return -EINVAL;
  166. }
  167. if (!core->power_enabled)
  168. return 0;
  169. if (!(core->intr_status & WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS2))
  170. disable_irq_nosync(core->dt->irq);
  171. core->intr_status = 0;
  172. /* HPG 6.1.2 Step 1 */
  173. __write_register(core, CPU_CS_X2RPMh_IRIS2, 0x3);
  174. /* HPG 6.1.2 Step 2, noc to low power */
  175. //if (core->res->vpu_ver == VPU_VERSION_IRIS2_1)
  176. // goto skip_aon_mvp_noc;
  177. __write_register(core, AON_WRAPPER_MVP_NOC_LPI_CONTROL, 0x1);
  178. while (!reg_status && count < max_count) {
  179. lpi_status =
  180. __read_register(core,
  181. AON_WRAPPER_MVP_NOC_LPI_STATUS);
  182. reg_status = lpi_status & BIT(0);
  183. d_vpr_h("Noc: lpi_status %d noc_status %d (count %d)\n",
  184. lpi_status, reg_status, count);
  185. usleep_range(50, 100);
  186. count++;
  187. }
  188. if (count == max_count)
  189. d_vpr_e("NOC not in qaccept status %d\n", reg_status);
  190. //skip_aon_mvp_noc:
  191. /* HPG 6.1.2 Step 3, debug bridge to low power */
  192. __write_register(core,
  193. WRAPPER_DEBUG_BRIDGE_LPI_CONTROL_IRIS2, 0x7);
  194. reg_status = 0;
  195. count = 0;
  196. while ((reg_status != 0x7) && count < max_count) {
  197. lpi_status = __read_register(core,
  198. WRAPPER_DEBUG_BRIDGE_LPI_STATUS_IRIS2);
  199. reg_status = lpi_status & 0x7;
  200. d_vpr_h("DBLP Set : lpi_status %d reg_status %d (count %d)\n",
  201. lpi_status, reg_status, count);
  202. usleep_range(50, 100);
  203. count++;
  204. }
  205. if (count == max_count)
  206. d_vpr_e("DBLP Set: status %d\n", reg_status);
  207. /* HPG 6.1.2 Step 4, debug bridge to lpi release */
  208. __write_register(core,
  209. WRAPPER_DEBUG_BRIDGE_LPI_CONTROL_IRIS2, 0x0);
  210. lpi_status = 0x1;
  211. count = 0;
  212. while (lpi_status && count < max_count) {
  213. lpi_status = __read_register(core,
  214. WRAPPER_DEBUG_BRIDGE_LPI_STATUS_IRIS2);
  215. d_vpr_h("DBLP Release: lpi_status %d(count %d)\n",
  216. lpi_status, count);
  217. usleep_range(50, 100);
  218. count++;
  219. }
  220. if (count == max_count)
  221. d_vpr_e("DBLP Release: lpi_status %d\n", lpi_status);
  222. /* HPG 6.1.2 Step 6 */
  223. __disable_unprepare_clks(core);
  224. /* HPG 6.1.2 Step 5 */
  225. if (__disable_regulators(core))
  226. d_vpr_e("%s: Failed to disable regulators\n", __func__);
  227. if (__unvote_buses(core))
  228. d_vpr_e("%s: Failed to unvote for buses\n", __func__);
  229. core->power_enabled = false;
  230. return 0;
  231. }
  232. static int __prepare_pc_iris2(struct msm_vidc_core *vidc_core)
  233. {
  234. int rc = 0;
  235. u32 wfi_status = 0, idle_status = 0, pc_ready = 0;
  236. u32 ctrl_status = 0;
  237. int count = 0;
  238. const int max_tries = 10;
  239. struct msm_vidc_core *core = vidc_core;
  240. if (!core) {
  241. d_vpr_e("%s: invalid params\n", __func__);
  242. return -EINVAL;
  243. }
  244. ctrl_status = __read_register(core, CTRL_STATUS_IRIS2);
  245. pc_ready = ctrl_status & CTRL_STATUS_PC_READY_IRIS2;
  246. idle_status = ctrl_status & BIT(30);
  247. if (pc_ready) {
  248. d_vpr_h("Already in pc_ready state\n");
  249. return 0;
  250. }
  251. wfi_status = BIT(0) & __read_register(core, WRAPPER_TZ_CPU_STATUS);
  252. if (!wfi_status || !idle_status) {
  253. d_vpr_e("Skipping PC, wfi status not set\n");
  254. goto skip_power_off;
  255. }
  256. rc = __prepare_pc(core);
  257. if (rc) {
  258. d_vpr_e("Failed __prepare_pc %d\n", rc);
  259. goto skip_power_off;
  260. }
  261. while (count < max_tries) {
  262. wfi_status = BIT(0) & __read_register(core,
  263. WRAPPER_TZ_CPU_STATUS);
  264. ctrl_status = __read_register(core,
  265. CTRL_STATUS_IRIS2);
  266. if (wfi_status && (ctrl_status & CTRL_STATUS_PC_READY_IRIS2))
  267. break;
  268. usleep_range(150, 250);
  269. count++;
  270. }
  271. if (count == max_tries) {
  272. d_vpr_e("Skip PC. Core is not in right state\n");
  273. goto skip_power_off;
  274. }
  275. return rc;
  276. skip_power_off:
  277. d_vpr_e("Skip PC, wfi=%#x, idle=%#x, pcr=%#x, ctrl=%#x)\n",
  278. wfi_status, idle_status, pc_ready, ctrl_status);
  279. return -EAGAIN;
  280. }
  281. static int __raise_interrupt_iris2(struct msm_vidc_core *vidc_core)
  282. {
  283. struct msm_vidc_core *core = vidc_core;
  284. if (!core) {
  285. d_vpr_e("%s: invalid params\n", __func__);
  286. return -EINVAL;
  287. }
  288. __write_register(core, CPU_IC_SOFTINT_IRIS2,
  289. 1 << CPU_IC_SOFTINT_H2A_SHFT_IRIS2);
  290. return 0;
  291. }
  292. static int __watchdog_iris2(struct msm_vidc_core *vidc_core, u32 intr_status)
  293. {
  294. int rc = 0;
  295. struct msm_vidc_core *core = vidc_core;
  296. if (!core) {
  297. d_vpr_e("%s: invalid params\n", __func__);
  298. return -EINVAL;
  299. }
  300. if (intr_status & WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS2) {
  301. d_vpr_e("%s: received watchdog interrupt\n", __func__);
  302. rc = 1;
  303. }
  304. return rc;
  305. }
  306. static int __noc_error_info_iris2(struct msm_vidc_core *vidc_core)
  307. {
  308. u32 val = 0;
  309. struct msm_vidc_core *core = vidc_core;
  310. if (!core) {
  311. d_vpr_e("%s: invalid params\n", __func__);
  312. return -EINVAL;
  313. }
  314. //if (core->res->vpu_ver == VPU_VERSION_IRIS2_1)
  315. // return;
  316. val = __read_register(core, VCODEC_NOC_ERL_MAIN_SWID_LOW);
  317. d_vpr_e("VCODEC_NOC_ERL_MAIN_SWID_LOW: %#x\n", val);
  318. val = __read_register(core, VCODEC_NOC_ERL_MAIN_SWID_HIGH);
  319. d_vpr_e("VCODEC_NOC_ERL_MAIN_SWID_HIGH: %#x\n", val);
  320. val = __read_register(core, VCODEC_NOC_ERL_MAIN_MAINCTL_LOW);
  321. d_vpr_e("VCODEC_NOC_ERL_MAIN_MAINCTL_LOW: %#x\n", val);
  322. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRVLD_LOW);
  323. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRVLD_LOW: %#x\n", val);
  324. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRCLR_LOW);
  325. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRCLR_LOW: %#x\n", val);
  326. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG0_LOW);
  327. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG0_LOW: %#x\n", val);
  328. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG0_HIGH);
  329. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG0_HIGH: %#x\n", val);
  330. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG1_LOW);
  331. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG1_LOW: %#x\n", val);
  332. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG1_HIGH);
  333. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG1_HIGH: %#x\n", val);
  334. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG2_LOW);
  335. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG2_LOW: %#x\n", val);
  336. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG2_HIGH);
  337. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG2_HIGH: %#x\n", val);
  338. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG3_LOW);
  339. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG3_LOW: %#x\n", val);
  340. val = __read_register(core, VCODEC_NOC_ERL_MAIN_ERRLOG3_HIGH);
  341. d_vpr_e("VCODEC_NOC_ERL_MAIN_ERRLOG3_HIGH: %#x\n", val);
  342. return 0;
  343. }
  344. static int __clear_interrupt_iris2(struct msm_vidc_core *vidc_core)
  345. {
  346. u32 intr_status = 0, mask = 0;
  347. struct msm_vidc_core *core = vidc_core;
  348. if (!core) {
  349. d_vpr_e("%s: NULL core\n", __func__);
  350. return 0;
  351. }
  352. intr_status = __read_register(core, WRAPPER_INTR_STATUS_IRIS2);
  353. mask = (WRAPPER_INTR_STATUS_A2H_BMSK_IRIS2|
  354. WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS2|
  355. CTRL_INIT_IDLE_MSG_BMSK_IRIS2);
  356. if (intr_status & mask) {
  357. core->intr_status |= intr_status;
  358. core->reg_count++;
  359. d_vpr_l("INTERRUPT: times: %d interrupt_status: %d\n",
  360. core->reg_count, intr_status);
  361. } else {
  362. core->spur_count++;
  363. }
  364. __write_register(core, CPU_CS_A2HSOFTINTCLR_IRIS2, 1);
  365. return 0;
  366. }
  367. static int __boot_firmware_iris2(struct msm_vidc_core *vidc_core)
  368. {
  369. int rc = 0;
  370. u32 ctrl_init_val = 0, ctrl_status = 0, count = 0, max_tries = 1000;
  371. struct msm_vidc_core *core = vidc_core;
  372. if (!core) {
  373. d_vpr_e("%s: NULL core\n", __func__);
  374. return 0;
  375. }
  376. ctrl_init_val = BIT(0);
  377. __write_register(core, CTRL_INIT_IRIS2, ctrl_init_val);
  378. while (!ctrl_status && count < max_tries) {
  379. ctrl_status = __read_register(core, CTRL_STATUS_IRIS2);
  380. if ((ctrl_status & CTRL_ERROR_STATUS__M_IRIS2) == 0x4) {
  381. d_vpr_e("invalid setting for UC_REGION\n");
  382. break;
  383. }
  384. usleep_range(50, 100);
  385. count++;
  386. }
  387. if (count >= max_tries) {
  388. d_vpr_e("Error booting up vidc firmware\n");
  389. rc = -ETIME;
  390. }
  391. /* Enable interrupt before sending commands to venus */
  392. __write_register(core, CPU_CS_H2XSOFTINTEN_IRIS2, 0x1);
  393. __write_register(core, CPU_CS_X2RPMh_IRIS2, 0x0);
  394. return rc;
  395. }
  396. bool res_is_greater_than(u32 width, u32 height,
  397. u32 ref_width, u32 ref_height)
  398. {
  399. u32 num_mbs = NUM_MBS_PER_FRAME(height, width);
  400. u32 max_side = max(ref_width, ref_height);
  401. if (num_mbs > NUM_MBS_PER_FRAME(ref_height, ref_width) ||
  402. width > max_side ||
  403. height > max_side)
  404. return true;
  405. else
  406. return false;
  407. }
  408. bool res_is_less_than_or_equal_to(u32 width, u32 height,
  409. u32 ref_width, u32 ref_height)
  410. {
  411. u32 num_mbs = NUM_MBS_PER_FRAME(height, width);
  412. u32 max_side = max(ref_width, ref_height);
  413. if (num_mbs <= NUM_MBS_PER_FRAME(ref_height, ref_width) &&
  414. width <= max_side &&
  415. height <= max_side)
  416. return true;
  417. else
  418. return false;
  419. }
  420. int msm_vidc_decide_work_mode_iris2(struct msm_vidc_inst* inst)
  421. {
  422. u32 work_mode;
  423. struct v4l2_format* out_f;
  424. struct v4l2_format* inp_f;
  425. u32 width, height;
  426. bool res_ok = false;
  427. bool lowlatency = false;
  428. if (!inst || !inst->capabilities) {
  429. d_vpr_e("%s: invalid params\n", __func__);
  430. return -EINVAL;
  431. }
  432. work_mode = MSM_VIDC_STAGE_2;
  433. out_f = &inst->fmts[OUTPUT_PORT];
  434. inp_f = &inst->fmts[INPUT_PORT];
  435. if (is_decode_session(inst)) {
  436. height = out_f->fmt.pix_mp.height;
  437. width = out_f->fmt.pix_mp.width;
  438. res_ok = res_is_less_than_or_equal_to(width, height, 1280, 720);
  439. if (inst->capabilities->cap[CODED_FRAMES].value ==
  440. CODED_FRAMES_ADAPTIVE_FIELDS ||
  441. inst->capabilities->cap[LOWLATENCY_MODE].value ||
  442. res_ok) {
  443. work_mode = MSM_VIDC_STAGE_1;
  444. }
  445. } else if (is_encode_session(inst)) {
  446. height = inp_f->fmt.pix_mp.height;
  447. width = inp_f->fmt.pix_mp.width;
  448. res_ok = !res_is_greater_than(width, height, 4096, 2160);
  449. if (res_ok &&
  450. (inst->capabilities->cap[LOWLATENCY_MODE].value)) {
  451. work_mode = MSM_VIDC_STAGE_1;
  452. /* For WORK_MODE_1, set Low Latency mode by default */
  453. lowlatency = true;
  454. }
  455. if (inst->capabilities->cap[LOSSLESS].value) {
  456. /*TODO Set 2 stage in case of ALL INTRA */
  457. work_mode = MSM_VIDC_STAGE_2;
  458. lowlatency = false;
  459. }
  460. }
  461. else {
  462. d_vpr_e("%s: invalid session type\n", __func__);
  463. return -EINVAL;
  464. }
  465. s_vpr_h(inst->sid, "Configuring work mode = %u low latency = %u",
  466. work_mode, lowlatency);
  467. inst->capabilities->cap[STAGE].value = work_mode;
  468. /* TODO If Encode then Set Low Latency (Enable/Disable)
  469. * and Update internal cap struct
  470. */
  471. return 0;
  472. }
  473. int msm_vidc_decide_work_route_iris2(struct msm_vidc_inst* inst)
  474. {
  475. u32 work_route;
  476. struct msm_vidc_core* core;
  477. if (!inst || !inst->core) {
  478. d_vpr_e("%s: invalid params\n", __func__);
  479. return -EINVAL;
  480. }
  481. core = inst->core;
  482. work_route = core->capabilities[NUM_VPP_PIPE].value;
  483. if (is_decode_session(inst)) {
  484. if (inst->capabilities->cap[CODED_FRAMES].value ==
  485. CODED_FRAMES_ADAPTIVE_FIELDS)
  486. work_route = MSM_VIDC_PIPE_1;
  487. } else if (is_encode_session(inst)) {
  488. u32 slice_mode, width, height;
  489. struct v4l2_format* f;
  490. f = &inst->fmts[INPUT_PORT];
  491. height = f->fmt.pix_mp.height;
  492. width = f->fmt.pix_mp.width;
  493. slice_mode = inst->capabilities->cap[SLICE_MODE].value;
  494. /*TODO Pipe=1 for legacy CBR*/
  495. if (slice_mode == V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES)
  496. work_route = MSM_VIDC_PIPE_1;
  497. } else {
  498. d_vpr_e("%s: invalid session type\n", __func__);
  499. return -EINVAL;
  500. }
  501. s_vpr_h(inst->sid, "Configuring work route = %u", work_route);
  502. inst->capabilities->cap[PIPE].value = work_route;
  503. return 0;
  504. }
  505. int msm_vidc_decide_quality_mode_iris2(struct msm_vidc_inst* inst)
  506. {
  507. struct msm_vidc_inst_capability* capability = inst->capabilities;
  508. struct msm_vidc_core *core;
  509. u32 mbpf, mbps, max_hq_mbpf, max_hq_mbps;
  510. u32 mode;
  511. if (!inst || !inst->capabilities) {
  512. d_vpr_e("%s: invalid params\n", __func__);
  513. return -EINVAL;
  514. }
  515. if (!is_encode_session(inst))
  516. return 0;
  517. mode = MSM_VIDC_POWER_SAVE_MODE;
  518. mbpf = msm_vidc_get_mbs_per_frame(inst);
  519. mbps = mbpf * msm_vidc_get_fps(inst);
  520. core = inst->core;
  521. max_hq_mbpf = core->capabilities[MAX_MBPF_HQ].value;;
  522. max_hq_mbps = core->capabilities[MAX_MBPS_HQ].value;;
  523. /* Power saving always disabled for CQ and LOSSLESS RC modes. */
  524. if (inst->capabilities->cap[LOSSLESS].value ||
  525. (mbpf <= max_hq_mbpf && mbps <= max_hq_mbps))
  526. mode = MSM_VIDC_MAX_QUALITY_MODE;
  527. inst->flags = mode == MSM_VIDC_POWER_SAVE_MODE ?
  528. inst->flags | VIDC_LOW_POWER :
  529. inst->flags & ~VIDC_LOW_POWER;
  530. capability->cap[QUALITY_MODE].value = mode;
  531. return 0;
  532. }
  533. static struct msm_vidc_venus_ops iris2_ops = {
  534. .boot_firmware = __boot_firmware_iris2,
  535. .interrupt_init = __interrupt_init_iris2,
  536. .raise_interrupt = __raise_interrupt_iris2,
  537. .clear_interrupt = __clear_interrupt_iris2,
  538. .setup_ucregion_memmap = __setup_ucregion_memory_map_iris2,
  539. .clock_config_on_enable = NULL,
  540. .reset_ahb2axi_bridge = __reset_ahb2axi_bridge,
  541. .power_off = __power_off_iris2,
  542. .prepare_pc = __prepare_pc_iris2,
  543. .watchdog = __watchdog_iris2,
  544. .noc_error_info = __noc_error_info_iris2,
  545. };
  546. static struct msm_vidc_session_ops msm_session_ops = {
  547. .buffer_size = msm_buffer_size_iris2,
  548. .min_count = msm_buffer_min_count_iris2,
  549. .extra_count = msm_buffer_extra_count_iris2,
  550. .calc_freq = msm_vidc_calc_freq_iris2,
  551. .calc_bw = msm_vidc_calc_bw_iris2,
  552. .decide_work_route = msm_vidc_decide_work_route_iris2,
  553. .decide_work_mode = msm_vidc_decide_work_mode_iris2,
  554. .decide_quality_mode = msm_vidc_decide_quality_mode_iris2,
  555. };
  556. int msm_vidc_init_iris2(struct msm_vidc_core *core)
  557. {
  558. if (!core) {
  559. d_vpr_e("%s: invalid params\n", __func__);
  560. return -EINVAL;
  561. }
  562. d_vpr_h("%s()\n", __func__);
  563. core->venus_ops = &iris2_ops;
  564. core->session_ops = &msm_session_ops;
  565. return 0;
  566. }
  567. int msm_vidc_deinit_iris2(struct msm_vidc_core *core)
  568. {
  569. /* do nothing */
  570. return 0;
  571. }