sde_encoder_phys_cmd.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  6. #include "sde_encoder_phys.h"
  7. #include "sde_hw_interrupts.h"
  8. #include "sde_core_irq.h"
  9. #include "sde_formats.h"
  10. #include "sde_trace.h"
  11. #define SDE_DEBUG_CMDENC(e, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt, \
  12. (e) && (e)->base.parent ? \
  13. (e)->base.parent->base.id : -1, \
  14. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  15. #define SDE_ERROR_CMDENC(e, fmt, ...) SDE_ERROR("enc%d intf%d " fmt, \
  16. (e) && (e)->base.parent ? \
  17. (e)->base.parent->base.id : -1, \
  18. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  19. #define to_sde_encoder_phys_cmd(x) \
  20. container_of(x, struct sde_encoder_phys_cmd, base)
  21. /*
  22. * Tearcheck sync start and continue thresholds are empirically found
  23. * based on common panels In the future, may want to allow panels to override
  24. * these default values
  25. */
  26. #define DEFAULT_TEARCHECK_SYNC_THRESH_START 4
  27. #define DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE 4
  28. #define SDE_ENC_WR_PTR_START_TIMEOUT_US 20000
  29. #define AUTOREFRESH_SEQ1_POLL_TIME 2000
  30. #define AUTOREFRESH_SEQ2_POLL_TIME 25000
  31. #define AUTOREFRESH_SEQ2_POLL_TIMEOUT 1000000
  32. static inline int _sde_encoder_phys_cmd_get_idle_timeout(
  33. struct sde_encoder_phys_cmd *cmd_enc)
  34. {
  35. return cmd_enc->autorefresh.cfg.frame_count ?
  36. cmd_enc->autorefresh.cfg.frame_count *
  37. KICKOFF_TIMEOUT_MS : KICKOFF_TIMEOUT_MS;
  38. }
  39. static inline bool sde_encoder_phys_cmd_is_master(
  40. struct sde_encoder_phys *phys_enc)
  41. {
  42. return (phys_enc->split_role != ENC_ROLE_SLAVE) ? true : false;
  43. }
  44. static bool sde_encoder_phys_cmd_mode_fixup(
  45. struct sde_encoder_phys *phys_enc,
  46. const struct drm_display_mode *mode,
  47. struct drm_display_mode *adj_mode)
  48. {
  49. if (phys_enc)
  50. SDE_DEBUG_CMDENC(to_sde_encoder_phys_cmd(phys_enc), "\n");
  51. return true;
  52. }
  53. static uint64_t _sde_encoder_phys_cmd_get_autorefresh_property(
  54. struct sde_encoder_phys *phys_enc)
  55. {
  56. struct drm_connector *conn = phys_enc->connector;
  57. if (!conn || !conn->state)
  58. return 0;
  59. return sde_connector_get_property(conn->state,
  60. CONNECTOR_PROP_AUTOREFRESH);
  61. }
  62. static void _sde_encoder_phys_cmd_config_autorefresh(
  63. struct sde_encoder_phys *phys_enc,
  64. u32 new_frame_count)
  65. {
  66. struct sde_encoder_phys_cmd *cmd_enc =
  67. to_sde_encoder_phys_cmd(phys_enc);
  68. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  69. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  70. struct drm_connector *conn = phys_enc->connector;
  71. struct sde_hw_autorefresh *cfg_cur, cfg_nxt;
  72. if (!conn || !conn->state || !hw_pp || !hw_intf)
  73. return;
  74. cfg_cur = &cmd_enc->autorefresh.cfg;
  75. /* autorefresh property value should be validated already */
  76. memset(&cfg_nxt, 0, sizeof(cfg_nxt));
  77. cfg_nxt.frame_count = new_frame_count;
  78. cfg_nxt.enable = (cfg_nxt.frame_count != 0);
  79. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh state %d->%d framecount %d\n",
  80. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  81. SDE_EVT32(DRMID(phys_enc->parent), hw_pp->idx, hw_intf->idx,
  82. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  83. /* only proceed on state changes */
  84. if (cfg_nxt.enable == cfg_cur->enable)
  85. return;
  86. memcpy(cfg_cur, &cfg_nxt, sizeof(*cfg_cur));
  87. if (phys_enc->has_intf_te && hw_intf->ops.setup_autorefresh)
  88. hw_intf->ops.setup_autorefresh(hw_intf, cfg_cur);
  89. else if (hw_pp->ops.setup_autorefresh)
  90. hw_pp->ops.setup_autorefresh(hw_pp, cfg_cur);
  91. }
  92. static void _sde_encoder_phys_cmd_update_flush_mask(
  93. struct sde_encoder_phys *phys_enc)
  94. {
  95. struct sde_encoder_phys_cmd *cmd_enc;
  96. struct sde_hw_ctl *ctl;
  97. if (!phys_enc || !phys_enc->hw_intf || !phys_enc->hw_pp)
  98. return;
  99. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  100. ctl = phys_enc->hw_ctl;
  101. if (!ctl)
  102. return;
  103. if (!ctl->ops.update_bitmask) {
  104. SDE_ERROR("invalid hw_ctl ops %d\n", ctl->idx);
  105. return;
  106. }
  107. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_INTF, phys_enc->intf_idx, 1);
  108. if (phys_enc->hw_pp->merge_3d)
  109. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_MERGE_3D,
  110. phys_enc->hw_pp->merge_3d->idx, 1);
  111. SDE_DEBUG_CMDENC(cmd_enc, "update pending flush ctl %d intf_idx %x\n",
  112. ctl->idx - CTL_0, phys_enc->intf_idx);
  113. }
  114. static void _sde_encoder_phys_cmd_update_intf_cfg(
  115. struct sde_encoder_phys *phys_enc)
  116. {
  117. struct sde_encoder_phys_cmd *cmd_enc =
  118. to_sde_encoder_phys_cmd(phys_enc);
  119. struct sde_hw_ctl *ctl;
  120. if (!phys_enc)
  121. return;
  122. ctl = phys_enc->hw_ctl;
  123. if (!ctl)
  124. return;
  125. if (ctl->ops.setup_intf_cfg) {
  126. struct sde_hw_intf_cfg intf_cfg = { 0 };
  127. intf_cfg.intf = phys_enc->intf_idx;
  128. intf_cfg.intf_mode_sel = SDE_CTL_MODE_SEL_CMD;
  129. intf_cfg.stream_sel = cmd_enc->stream_sel;
  130. intf_cfg.mode_3d =
  131. sde_encoder_helper_get_3d_blend_mode(phys_enc);
  132. ctl->ops.setup_intf_cfg(ctl, &intf_cfg);
  133. } else if (test_bit(SDE_CTL_ACTIVE_CFG, &ctl->caps->features)) {
  134. sde_encoder_helper_update_intf_cfg(phys_enc);
  135. }
  136. }
  137. static void sde_encoder_phys_cmd_pp_tx_done_irq(void *arg, int irq_idx)
  138. {
  139. struct sde_encoder_phys *phys_enc = arg;
  140. struct sde_encoder_phys_cmd *cmd_enc;
  141. struct sde_hw_ctl *ctl;
  142. u32 scheduler_status = INVALID_CTL_STATUS, event = 0;
  143. if (!phys_enc || !phys_enc->hw_pp)
  144. return;
  145. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  146. ctl = phys_enc->hw_ctl;
  147. SDE_ATRACE_BEGIN("pp_done_irq");
  148. /* notify all synchronous clients first, then asynchronous clients */
  149. if (phys_enc->parent_ops.handle_frame_done &&
  150. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  151. event = SDE_ENCODER_FRAME_EVENT_DONE |
  152. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  153. spin_lock(phys_enc->enc_spinlock);
  154. phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
  155. phys_enc, event);
  156. if (cmd_enc->pp_timeout_report_cnt)
  157. phys_enc->recovered = true;
  158. spin_unlock(phys_enc->enc_spinlock);
  159. }
  160. if (ctl && ctl->ops.get_scheduler_status)
  161. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  162. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  163. phys_enc->hw_pp->idx - PINGPONG_0, event, scheduler_status);
  164. /* Signal any waiting atomic commit thread */
  165. wake_up_all(&phys_enc->pending_kickoff_wq);
  166. SDE_ATRACE_END("pp_done_irq");
  167. }
  168. static void sde_encoder_phys_cmd_autorefresh_done_irq(void *arg, int irq_idx)
  169. {
  170. struct sde_encoder_phys *phys_enc = arg;
  171. struct sde_encoder_phys_cmd *cmd_enc =
  172. to_sde_encoder_phys_cmd(phys_enc);
  173. unsigned long lock_flags;
  174. int new_cnt;
  175. if (!cmd_enc)
  176. return;
  177. phys_enc = &cmd_enc->base;
  178. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  179. new_cnt = atomic_add_unless(&cmd_enc->autorefresh.kickoff_cnt, -1, 0);
  180. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  181. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  182. phys_enc->hw_pp->idx - PINGPONG_0,
  183. phys_enc->hw_intf->idx - INTF_0,
  184. new_cnt);
  185. /* Signal any waiting atomic commit thread */
  186. wake_up_all(&cmd_enc->autorefresh.kickoff_wq);
  187. }
  188. static void sde_encoder_phys_cmd_te_rd_ptr_irq(void *arg, int irq_idx)
  189. {
  190. struct sde_encoder_phys *phys_enc = arg;
  191. struct sde_encoder_phys_cmd *cmd_enc;
  192. u32 scheduler_status = INVALID_CTL_STATUS;
  193. struct sde_hw_ctl *ctl;
  194. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  195. struct sde_encoder_phys_cmd_te_timestamp *te_timestamp;
  196. unsigned long lock_flags;
  197. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  198. return;
  199. SDE_ATRACE_BEGIN("rd_ptr_irq");
  200. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  201. ctl = phys_enc->hw_ctl;
  202. if (ctl && ctl->ops.get_scheduler_status)
  203. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  204. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  205. te_timestamp = list_first_entry_or_null(&cmd_enc->te_timestamp_list,
  206. struct sde_encoder_phys_cmd_te_timestamp, list);
  207. if (te_timestamp) {
  208. list_del_init(&te_timestamp->list);
  209. te_timestamp->timestamp = ktime_get();
  210. list_add_tail(&te_timestamp->list, &cmd_enc->te_timestamp_list);
  211. }
  212. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  213. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  214. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  215. info[0].pp_idx, info[0].intf_idx,
  216. info[0].wr_ptr_line_count, info[0].intf_frame_count,
  217. info[1].pp_idx, info[1].intf_idx,
  218. info[1].wr_ptr_line_count, info[1].intf_frame_count,
  219. scheduler_status);
  220. if (phys_enc->parent_ops.handle_vblank_virt)
  221. phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
  222. phys_enc);
  223. atomic_add_unless(&cmd_enc->pending_vblank_cnt, -1, 0);
  224. wake_up_all(&cmd_enc->pending_vblank_wq);
  225. SDE_ATRACE_END("rd_ptr_irq");
  226. }
  227. static void sde_encoder_phys_cmd_wr_ptr_irq(void *arg, int irq_idx)
  228. {
  229. struct sde_encoder_phys *phys_enc = arg;
  230. struct sde_hw_ctl *ctl;
  231. u32 event = 0;
  232. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  233. if (!phys_enc || !phys_enc->hw_ctl)
  234. return;
  235. SDE_ATRACE_BEGIN("wr_ptr_irq");
  236. ctl = phys_enc->hw_ctl;
  237. if (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0)) {
  238. event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
  239. if (phys_enc->parent_ops.handle_frame_done) {
  240. spin_lock(phys_enc->enc_spinlock);
  241. phys_enc->parent_ops.handle_frame_done(
  242. phys_enc->parent, phys_enc, event);
  243. spin_unlock(phys_enc->enc_spinlock);
  244. }
  245. }
  246. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  247. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  248. ctl->idx - CTL_0, event,
  249. info[0].pp_idx, info[0].intf_idx, info[0].wr_ptr_line_count,
  250. info[1].pp_idx, info[1].intf_idx, info[1].wr_ptr_line_count);
  251. /* Signal any waiting wr_ptr start interrupt */
  252. wake_up_all(&phys_enc->pending_kickoff_wq);
  253. SDE_ATRACE_END("wr_ptr_irq");
  254. }
  255. static void _sde_encoder_phys_cmd_setup_irq_hw_idx(
  256. struct sde_encoder_phys *phys_enc)
  257. {
  258. struct sde_encoder_irq *irq;
  259. struct sde_kms *sde_kms;
  260. if (!phys_enc->sde_kms || !phys_enc->hw_pp || !phys_enc->hw_ctl) {
  261. SDE_ERROR("invalid args %d %d %d\n", !phys_enc->sde_kms,
  262. !phys_enc->hw_pp, !phys_enc->hw_ctl);
  263. return;
  264. }
  265. if (phys_enc->has_intf_te && !phys_enc->hw_intf) {
  266. SDE_ERROR("invalid intf configuration\n");
  267. return;
  268. }
  269. sde_kms = phys_enc->sde_kms;
  270. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  271. irq->hw_idx = phys_enc->hw_ctl->idx;
  272. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  273. irq->hw_idx = phys_enc->hw_pp->idx;
  274. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  275. if (phys_enc->has_intf_te)
  276. irq->hw_idx = phys_enc->hw_intf->idx;
  277. else
  278. irq->hw_idx = phys_enc->hw_pp->idx;
  279. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  280. if (phys_enc->has_intf_te)
  281. irq->hw_idx = phys_enc->hw_intf->idx;
  282. else
  283. irq->hw_idx = phys_enc->hw_pp->idx;
  284. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  285. if (phys_enc->has_intf_te)
  286. irq->hw_idx = phys_enc->hw_intf->idx;
  287. else
  288. irq->hw_idx = phys_enc->hw_pp->idx;
  289. }
  290. static void sde_encoder_phys_cmd_cont_splash_mode_set(
  291. struct sde_encoder_phys *phys_enc,
  292. struct drm_display_mode *adj_mode)
  293. {
  294. struct sde_hw_intf *hw_intf;
  295. struct sde_hw_pingpong *hw_pp;
  296. struct sde_encoder_phys_cmd *cmd_enc;
  297. if (!phys_enc || !adj_mode) {
  298. SDE_ERROR("invalid args\n");
  299. return;
  300. }
  301. phys_enc->cached_mode = *adj_mode;
  302. phys_enc->enable_state = SDE_ENC_ENABLED;
  303. if (!phys_enc->hw_ctl || !phys_enc->hw_pp) {
  304. SDE_DEBUG("invalid ctl:%d pp:%d\n",
  305. (phys_enc->hw_ctl == NULL),
  306. (phys_enc->hw_pp == NULL));
  307. return;
  308. }
  309. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  310. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  311. hw_pp = phys_enc->hw_pp;
  312. hw_intf = phys_enc->hw_intf;
  313. if (phys_enc->has_intf_te && hw_intf &&
  314. hw_intf->ops.get_autorefresh) {
  315. hw_intf->ops.get_autorefresh(hw_intf,
  316. &cmd_enc->autorefresh.cfg);
  317. } else if (hw_pp && hw_pp->ops.get_autorefresh) {
  318. hw_pp->ops.get_autorefresh(hw_pp,
  319. &cmd_enc->autorefresh.cfg);
  320. }
  321. if (hw_intf && hw_intf->ops.reset_counter)
  322. hw_intf->ops.reset_counter(hw_intf);
  323. }
  324. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  325. }
  326. static void sde_encoder_phys_cmd_mode_set(
  327. struct sde_encoder_phys *phys_enc,
  328. struct drm_display_mode *mode,
  329. struct drm_display_mode *adj_mode)
  330. {
  331. struct sde_encoder_phys_cmd *cmd_enc =
  332. to_sde_encoder_phys_cmd(phys_enc);
  333. struct sde_rm *rm = &phys_enc->sde_kms->rm;
  334. struct sde_rm_hw_iter iter;
  335. int i, instance;
  336. if (!phys_enc || !mode || !adj_mode) {
  337. SDE_ERROR("invalid args\n");
  338. return;
  339. }
  340. phys_enc->cached_mode = *adj_mode;
  341. SDE_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
  342. drm_mode_debug_printmodeline(adj_mode);
  343. instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
  344. /* Retrieve previously allocated HW Resources. Shouldn't fail */
  345. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
  346. for (i = 0; i <= instance; i++) {
  347. if (sde_rm_get_hw(rm, &iter))
  348. phys_enc->hw_ctl = (struct sde_hw_ctl *)iter.hw;
  349. }
  350. if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
  351. SDE_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
  352. PTR_ERR(phys_enc->hw_ctl));
  353. phys_enc->hw_ctl = NULL;
  354. return;
  355. }
  356. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_INTF);
  357. for (i = 0; i <= instance; i++) {
  358. if (sde_rm_get_hw(rm, &iter))
  359. phys_enc->hw_intf = (struct sde_hw_intf *)iter.hw;
  360. }
  361. if (IS_ERR_OR_NULL(phys_enc->hw_intf)) {
  362. SDE_ERROR_CMDENC(cmd_enc, "failed to init intf: %ld\n",
  363. PTR_ERR(phys_enc->hw_intf));
  364. phys_enc->hw_intf = NULL;
  365. return;
  366. }
  367. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  368. }
  369. static int _sde_encoder_phys_cmd_handle_ppdone_timeout(
  370. struct sde_encoder_phys *phys_enc)
  371. {
  372. struct sde_encoder_phys_cmd *cmd_enc =
  373. to_sde_encoder_phys_cmd(phys_enc);
  374. bool recovery_events = sde_encoder_recovery_events_enabled(
  375. phys_enc->parent);
  376. u32 frame_event = SDE_ENCODER_FRAME_EVENT_ERROR
  377. | SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  378. struct drm_connector *conn;
  379. u32 pending_kickoff_cnt;
  380. unsigned long lock_flags;
  381. if (!phys_enc->hw_pp || !phys_enc->hw_ctl)
  382. return -EINVAL;
  383. conn = phys_enc->connector;
  384. /* decrement the kickoff_cnt before checking for ESD status */
  385. if (!atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0))
  386. return 0;
  387. cmd_enc->pp_timeout_report_cnt++;
  388. pending_kickoff_cnt = atomic_read(&phys_enc->pending_kickoff_cnt) + 1;
  389. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  390. cmd_enc->pp_timeout_report_cnt,
  391. pending_kickoff_cnt,
  392. frame_event);
  393. /* check if panel is still sending TE signal or not */
  394. if (sde_connector_esd_status(phys_enc->connector))
  395. goto exit;
  396. /* to avoid flooding, only log first time, and "dead" time */
  397. if (cmd_enc->pp_timeout_report_cnt == 1) {
  398. SDE_ERROR_CMDENC(cmd_enc,
  399. "pp:%d kickoff timed out ctl %d koff_cnt %d\n",
  400. phys_enc->hw_pp->idx - PINGPONG_0,
  401. phys_enc->hw_ctl->idx - CTL_0,
  402. pending_kickoff_cnt);
  403. SDE_EVT32(DRMID(phys_enc->parent), SDE_EVTLOG_FATAL);
  404. mutex_lock(phys_enc->vblank_ctl_lock);
  405. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_RDPTR);
  406. if (sde_kms_is_secure_session_inprogress(phys_enc->sde_kms))
  407. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "secure");
  408. else
  409. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL);
  410. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  411. mutex_unlock(phys_enc->vblank_ctl_lock);
  412. }
  413. /*
  414. * if the recovery event is registered by user, don't panic
  415. * trigger panic on first timeout if no listener registered
  416. */
  417. if (recovery_events)
  418. sde_connector_event_notify(conn, DRM_EVENT_SDE_HW_RECOVERY,
  419. sizeof(uint8_t), SDE_RECOVERY_CAPTURE);
  420. else if (cmd_enc->pp_timeout_report_cnt)
  421. SDE_DBG_DUMP(0x0, "panic");
  422. /* request a ctl reset before the next kickoff */
  423. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  424. exit:
  425. if (phys_enc->parent_ops.handle_frame_done) {
  426. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  427. phys_enc->parent_ops.handle_frame_done(
  428. phys_enc->parent, phys_enc, frame_event);
  429. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  430. }
  431. return -ETIMEDOUT;
  432. }
  433. static bool _sde_encoder_phys_is_ppsplit_slave(
  434. struct sde_encoder_phys *phys_enc)
  435. {
  436. if (!phys_enc)
  437. return false;
  438. return _sde_encoder_phys_is_ppsplit(phys_enc) &&
  439. phys_enc->split_role == ENC_ROLE_SLAVE;
  440. }
  441. static bool _sde_encoder_phys_is_disabling_ppsplit_slave(
  442. struct sde_encoder_phys *phys_enc)
  443. {
  444. enum sde_rm_topology_name old_top;
  445. if (!phys_enc || !phys_enc->connector ||
  446. phys_enc->split_role != ENC_ROLE_SLAVE)
  447. return false;
  448. old_top = sde_connector_get_old_topology_name(
  449. phys_enc->connector->state);
  450. return old_top == SDE_RM_TOPOLOGY_PPSPLIT;
  451. }
  452. static int _sde_encoder_phys_cmd_poll_write_pointer_started(
  453. struct sde_encoder_phys *phys_enc)
  454. {
  455. struct sde_encoder_phys_cmd *cmd_enc =
  456. to_sde_encoder_phys_cmd(phys_enc);
  457. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  458. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  459. struct sde_hw_pp_vsync_info info;
  460. u32 timeout_us = SDE_ENC_WR_PTR_START_TIMEOUT_US;
  461. int ret = 0;
  462. if (!hw_pp || !hw_intf)
  463. return 0;
  464. if (phys_enc->has_intf_te) {
  465. if (!hw_intf->ops.get_vsync_info ||
  466. !hw_intf->ops.poll_timeout_wr_ptr)
  467. goto end;
  468. } else {
  469. if (!hw_pp->ops.get_vsync_info ||
  470. !hw_pp->ops.poll_timeout_wr_ptr)
  471. goto end;
  472. }
  473. if (phys_enc->has_intf_te)
  474. ret = hw_intf->ops.get_vsync_info(hw_intf, &info);
  475. else
  476. ret = hw_pp->ops.get_vsync_info(hw_pp, &info);
  477. if (ret)
  478. return ret;
  479. SDE_DEBUG_CMDENC(cmd_enc,
  480. "pp:%d intf:%d rd_ptr %d wr_ptr %d\n",
  481. phys_enc->hw_pp->idx - PINGPONG_0,
  482. phys_enc->hw_intf->idx - INTF_0,
  483. info.rd_ptr_line_count,
  484. info.wr_ptr_line_count);
  485. SDE_EVT32_VERBOSE(DRMID(phys_enc->parent),
  486. phys_enc->hw_pp->idx - PINGPONG_0,
  487. phys_enc->hw_intf->idx - INTF_0,
  488. info.wr_ptr_line_count);
  489. if (phys_enc->has_intf_te)
  490. ret = hw_intf->ops.poll_timeout_wr_ptr(hw_intf, timeout_us);
  491. else
  492. ret = hw_pp->ops.poll_timeout_wr_ptr(hw_pp, timeout_us);
  493. if (ret) {
  494. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  495. phys_enc->hw_intf->idx - INTF_0, timeout_us, ret);
  496. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  497. }
  498. end:
  499. return ret;
  500. }
  501. static bool _sde_encoder_phys_cmd_is_ongoing_pptx(
  502. struct sde_encoder_phys *phys_enc)
  503. {
  504. struct sde_hw_pingpong *hw_pp;
  505. struct sde_hw_pp_vsync_info info;
  506. struct sde_hw_intf *hw_intf;
  507. if (!phys_enc)
  508. return false;
  509. if (phys_enc->has_intf_te) {
  510. hw_intf = phys_enc->hw_intf;
  511. if (!hw_intf || !hw_intf->ops.get_vsync_info)
  512. return false;
  513. hw_intf->ops.get_vsync_info(hw_intf, &info);
  514. } else {
  515. hw_pp = phys_enc->hw_pp;
  516. if (!hw_pp || !hw_pp->ops.get_vsync_info)
  517. return false;
  518. hw_pp->ops.get_vsync_info(hw_pp, &info);
  519. }
  520. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  521. phys_enc->hw_intf->idx - INTF_0, atomic_read(&phys_enc->pending_kickoff_cnt),
  522. info.wr_ptr_line_count, info.intf_frame_count, phys_enc->cached_mode.vdisplay);
  523. if (info.wr_ptr_line_count > 0 && info.wr_ptr_line_count <
  524. phys_enc->cached_mode.vdisplay)
  525. return true;
  526. return false;
  527. }
  528. static bool _sde_encoder_phys_cmd_is_scheduler_idle(
  529. struct sde_encoder_phys *phys_enc)
  530. {
  531. bool wr_ptr_wait_success = true;
  532. unsigned long lock_flags;
  533. bool ret = false;
  534. struct sde_encoder_phys_cmd *cmd_enc =
  535. to_sde_encoder_phys_cmd(phys_enc);
  536. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  537. enum frame_trigger_mode_type frame_trigger_mode =
  538. phys_enc->frame_trigger_mode;
  539. if (sde_encoder_phys_cmd_is_master(phys_enc))
  540. wr_ptr_wait_success = cmd_enc->wr_ptr_wait_success;
  541. /*
  542. * Handle cases where a pp-done interrupt is missed
  543. * due to irq latency with POSTED start
  544. */
  545. if (wr_ptr_wait_success &&
  546. (frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) &&
  547. ctl->ops.get_scheduler_status &&
  548. phys_enc->parent_ops.handle_frame_done &&
  549. atomic_read(&phys_enc->pending_kickoff_cnt) > 0 &&
  550. (ctl->ops.get_scheduler_status(ctl) & BIT(0)) &&
  551. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  552. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  553. phys_enc->parent_ops.handle_frame_done(
  554. phys_enc->parent, phys_enc,
  555. SDE_ENCODER_FRAME_EVENT_DONE |
  556. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE);
  557. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  558. SDE_EVT32(DRMID(phys_enc->parent),
  559. phys_enc->hw_pp->idx - PINGPONG_0,
  560. phys_enc->hw_intf->idx - INTF_0,
  561. atomic_read(&phys_enc->pending_kickoff_cnt));
  562. ret = true;
  563. }
  564. return ret;
  565. }
  566. static int _sde_encoder_phys_cmd_wait_for_idle(
  567. struct sde_encoder_phys *phys_enc)
  568. {
  569. struct sde_encoder_wait_info wait_info = {0};
  570. int ret;
  571. if (!phys_enc) {
  572. SDE_ERROR("invalid encoder\n");
  573. return -EINVAL;
  574. }
  575. if (atomic_read(&phys_enc->pending_kickoff_cnt) > 1)
  576. wait_info.count_check = 1;
  577. wait_info.wq = &phys_enc->pending_kickoff_wq;
  578. wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
  579. wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
  580. /* slave encoder doesn't enable for ppsplit */
  581. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  582. return 0;
  583. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  584. return 0;
  585. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_PINGPONG,
  586. &wait_info);
  587. if (ret == -ETIMEDOUT) {
  588. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  589. return 0;
  590. _sde_encoder_phys_cmd_handle_ppdone_timeout(phys_enc);
  591. }
  592. return ret;
  593. }
  594. static int _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  595. struct sde_encoder_phys *phys_enc)
  596. {
  597. struct sde_encoder_phys_cmd *cmd_enc =
  598. to_sde_encoder_phys_cmd(phys_enc);
  599. struct sde_encoder_wait_info wait_info = {0};
  600. int ret = 0;
  601. if (!phys_enc) {
  602. SDE_ERROR("invalid encoder\n");
  603. return -EINVAL;
  604. }
  605. /* only master deals with autorefresh */
  606. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  607. return 0;
  608. wait_info.wq = &cmd_enc->autorefresh.kickoff_wq;
  609. wait_info.atomic_cnt = &cmd_enc->autorefresh.kickoff_cnt;
  610. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(cmd_enc);
  611. /* wait for autorefresh kickoff to start */
  612. ret = sde_encoder_helper_wait_for_irq(phys_enc,
  613. INTR_IDX_AUTOREFRESH_DONE, &wait_info);
  614. /* double check that kickoff has started by reading write ptr reg */
  615. if (!ret)
  616. ret = _sde_encoder_phys_cmd_poll_write_pointer_started(
  617. phys_enc);
  618. else
  619. sde_encoder_helper_report_irq_timeout(phys_enc,
  620. INTR_IDX_AUTOREFRESH_DONE);
  621. return ret;
  622. }
  623. static int sde_encoder_phys_cmd_control_vblank_irq(
  624. struct sde_encoder_phys *phys_enc,
  625. bool enable)
  626. {
  627. struct sde_encoder_phys_cmd *cmd_enc =
  628. to_sde_encoder_phys_cmd(phys_enc);
  629. int ret = 0;
  630. u32 refcount;
  631. struct sde_kms *sde_kms;
  632. if (!phys_enc || !phys_enc->hw_pp) {
  633. SDE_ERROR("invalid encoder\n");
  634. return -EINVAL;
  635. }
  636. sde_kms = phys_enc->sde_kms;
  637. mutex_lock(phys_enc->vblank_ctl_lock);
  638. /* Slave encoders don't report vblank */
  639. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  640. goto end;
  641. refcount = atomic_read(&phys_enc->vblank_refcount);
  642. /* protect against negative */
  643. if (!enable && refcount == 0) {
  644. ret = -EINVAL;
  645. goto end;
  646. }
  647. SDE_DEBUG_CMDENC(cmd_enc, "[%pS] enable=%d/%d\n",
  648. __builtin_return_address(0), enable, refcount);
  649. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  650. enable, refcount);
  651. if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1) {
  652. ret = sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  653. if (ret)
  654. atomic_dec_return(&phys_enc->vblank_refcount);
  655. } else if (!enable &&
  656. atomic_dec_return(&phys_enc->vblank_refcount) == 0) {
  657. ret = sde_encoder_helper_unregister_irq(phys_enc,
  658. INTR_IDX_RDPTR);
  659. if (ret)
  660. atomic_inc_return(&phys_enc->vblank_refcount);
  661. }
  662. end:
  663. mutex_unlock(phys_enc->vblank_ctl_lock);
  664. if (ret) {
  665. SDE_ERROR_CMDENC(cmd_enc,
  666. "control vblank irq error %d, enable %d, refcount %d\n",
  667. ret, enable, refcount);
  668. SDE_EVT32(DRMID(phys_enc->parent),
  669. phys_enc->hw_pp->idx - PINGPONG_0,
  670. enable, refcount, SDE_EVTLOG_ERROR);
  671. }
  672. return ret;
  673. }
  674. void sde_encoder_phys_cmd_irq_control(struct sde_encoder_phys *phys_enc,
  675. bool enable)
  676. {
  677. struct sde_encoder_phys_cmd *cmd_enc;
  678. if (!phys_enc)
  679. return;
  680. /**
  681. * pingpong split slaves do not register for IRQs
  682. * check old and new topologies
  683. */
  684. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  685. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  686. return;
  687. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  688. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  689. enable, atomic_read(&phys_enc->vblank_refcount));
  690. if (enable) {
  691. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_PINGPONG);
  692. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, true);
  693. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  694. sde_encoder_helper_register_irq(phys_enc,
  695. INTR_IDX_WRPTR);
  696. sde_encoder_helper_register_irq(phys_enc,
  697. INTR_IDX_AUTOREFRESH_DONE);
  698. }
  699. } else {
  700. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  701. sde_encoder_helper_unregister_irq(phys_enc,
  702. INTR_IDX_WRPTR);
  703. sde_encoder_helper_unregister_irq(phys_enc,
  704. INTR_IDX_AUTOREFRESH_DONE);
  705. }
  706. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, false);
  707. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_PINGPONG);
  708. }
  709. }
  710. static int _get_tearcheck_threshold(struct sde_encoder_phys *phys_enc)
  711. {
  712. struct drm_connector *conn = phys_enc->connector;
  713. u32 qsync_mode;
  714. struct drm_display_mode *mode;
  715. u32 threshold_lines = DEFAULT_TEARCHECK_SYNC_THRESH_START;
  716. struct sde_encoder_phys_cmd *cmd_enc =
  717. to_sde_encoder_phys_cmd(phys_enc);
  718. if (!conn || !conn->state)
  719. return 0;
  720. mode = &phys_enc->cached_mode;
  721. qsync_mode = sde_connector_get_qsync_mode(conn);
  722. if (mode && (qsync_mode == SDE_RM_QSYNC_CONTINUOUS_MODE)) {
  723. u32 qsync_min_fps = 0;
  724. u32 default_fps = drm_mode_vrefresh(mode);
  725. u32 yres = mode->vtotal;
  726. u32 slow_time_ns;
  727. u32 default_time_ns;
  728. u32 extra_time_ns;
  729. u32 default_line_time_ns;
  730. if (phys_enc->parent_ops.get_qsync_fps)
  731. phys_enc->parent_ops.get_qsync_fps(
  732. phys_enc->parent, &qsync_min_fps, 0);
  733. if (!qsync_min_fps || !default_fps || !yres) {
  734. SDE_ERROR_CMDENC(cmd_enc,
  735. "wrong qsync params %d %d %d\n",
  736. qsync_min_fps, default_fps, yres);
  737. goto exit;
  738. }
  739. if (qsync_min_fps >= default_fps) {
  740. SDE_ERROR_CMDENC(cmd_enc,
  741. "qsync fps:%d must be less than default:%d\n",
  742. qsync_min_fps, default_fps);
  743. goto exit;
  744. }
  745. /* Calculate the number of extra lines*/
  746. slow_time_ns = DIV_ROUND_UP(1000000000, qsync_min_fps);
  747. default_time_ns = DIV_ROUND_UP(1000000000, default_fps);
  748. extra_time_ns = slow_time_ns - default_time_ns;
  749. default_line_time_ns = DIV_ROUND_UP(default_time_ns, yres);
  750. threshold_lines = extra_time_ns / default_line_time_ns;
  751. /* some DDICs express the timeout value in lines/4, round down to compensate */
  752. threshold_lines = round_down(threshold_lines, 4);
  753. /* remove 2 lines to cover for latency */
  754. if (threshold_lines - 2 > DEFAULT_TEARCHECK_SYNC_THRESH_START)
  755. threshold_lines -= 2;
  756. SDE_DEBUG_CMDENC(cmd_enc, "slow:%d default:%d extra:%d(ns)\n",
  757. slow_time_ns, default_time_ns, extra_time_ns);
  758. SDE_DEBUG_CMDENC(cmd_enc, "min_fps:%d fps:%d yres:%d lines:%d\n",
  759. qsync_min_fps, default_fps, yres, threshold_lines);
  760. SDE_EVT32(qsync_mode, qsync_min_fps, extra_time_ns, default_fps,
  761. yres, threshold_lines);
  762. }
  763. exit:
  764. return threshold_lines;
  765. }
  766. static void sde_encoder_phys_cmd_tearcheck_config(
  767. struct sde_encoder_phys *phys_enc)
  768. {
  769. struct sde_encoder_phys_cmd *cmd_enc =
  770. to_sde_encoder_phys_cmd(phys_enc);
  771. struct sde_hw_tear_check tc_cfg = { 0 };
  772. struct drm_display_mode *mode;
  773. bool tc_enable = true;
  774. u32 vsync_hz;
  775. int vrefresh;
  776. struct msm_drm_private *priv;
  777. struct sde_kms *sde_kms;
  778. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  779. SDE_ERROR("invalid encoder\n");
  780. return;
  781. }
  782. mode = &phys_enc->cached_mode;
  783. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, intf %d\n",
  784. phys_enc->hw_pp->idx - PINGPONG_0,
  785. phys_enc->hw_intf->idx - INTF_0);
  786. if (phys_enc->has_intf_te) {
  787. if (!phys_enc->hw_intf->ops.setup_tearcheck ||
  788. !phys_enc->hw_intf->ops.enable_tearcheck) {
  789. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  790. return;
  791. }
  792. } else {
  793. if (!phys_enc->hw_pp->ops.setup_tearcheck ||
  794. !phys_enc->hw_pp->ops.enable_tearcheck) {
  795. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  796. return;
  797. }
  798. }
  799. sde_kms = phys_enc->sde_kms;
  800. if (!sde_kms || !sde_kms->dev || !sde_kms->dev->dev_private) {
  801. SDE_ERROR("invalid device\n");
  802. return;
  803. }
  804. priv = sde_kms->dev->dev_private;
  805. vrefresh = drm_mode_vrefresh(mode);
  806. /*
  807. * TE default: dsi byte clock calculated base on 70 fps;
  808. * around 14 ms to complete a kickoff cycle if te disabled;
  809. * vclk_line base on 60 fps; write is faster than read;
  810. * init == start == rdptr;
  811. *
  812. * vsync_count is ratio of MDP VSYNC clock frequency to LCD panel
  813. * frequency divided by the no. of rows (lines) in the LCDpanel.
  814. */
  815. vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
  816. if (!vsync_hz || !mode->vtotal || !vrefresh) {
  817. SDE_DEBUG_CMDENC(cmd_enc,
  818. "invalid params - vsync_hz %u vtot %u vrefresh %u\n",
  819. vsync_hz, mode->vtotal, vrefresh);
  820. return;
  821. }
  822. tc_cfg.vsync_count = vsync_hz / (mode->vtotal * vrefresh);
  823. /* enable external TE after kickoff to avoid premature autorefresh */
  824. tc_cfg.hw_vsync_mode = 0;
  825. /*
  826. * By setting sync_cfg_height to near max register value, we essentially
  827. * disable sde hw generated TE signal, since hw TE will arrive first.
  828. * Only caveat is if due to error, we hit wrap-around.
  829. */
  830. tc_cfg.sync_cfg_height = 0xFFF0;
  831. tc_cfg.vsync_init_val = mode->vdisplay;
  832. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc);
  833. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  834. tc_cfg.start_pos = mode->vdisplay;
  835. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  836. tc_cfg.wr_ptr_irq = 1;
  837. SDE_DEBUG_CMDENC(cmd_enc,
  838. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  839. phys_enc->hw_pp->idx - PINGPONG_0,
  840. phys_enc->hw_intf->idx - INTF_0,
  841. vsync_hz, mode->vtotal, vrefresh);
  842. SDE_DEBUG_CMDENC(cmd_enc,
  843. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  844. phys_enc->hw_pp->idx - PINGPONG_0,
  845. phys_enc->hw_intf->idx - INTF_0,
  846. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  847. tc_cfg.wr_ptr_irq);
  848. SDE_DEBUG_CMDENC(cmd_enc,
  849. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  850. phys_enc->hw_pp->idx - PINGPONG_0,
  851. phys_enc->hw_intf->idx - INTF_0,
  852. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  853. tc_cfg.vsync_init_val);
  854. SDE_DEBUG_CMDENC(cmd_enc,
  855. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  856. phys_enc->hw_pp->idx - PINGPONG_0,
  857. phys_enc->hw_intf->idx - INTF_0,
  858. tc_cfg.sync_cfg_height,
  859. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  860. if (phys_enc->has_intf_te) {
  861. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  862. &tc_cfg);
  863. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  864. tc_enable);
  865. } else {
  866. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  867. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  868. tc_enable);
  869. }
  870. }
  871. static void _sde_encoder_phys_cmd_pingpong_config(
  872. struct sde_encoder_phys *phys_enc)
  873. {
  874. struct sde_encoder_phys_cmd *cmd_enc =
  875. to_sde_encoder_phys_cmd(phys_enc);
  876. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  877. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  878. return;
  879. }
  880. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  881. phys_enc->hw_pp->idx - PINGPONG_0);
  882. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  883. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  884. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  885. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  886. }
  887. static void sde_encoder_phys_cmd_enable_helper(
  888. struct sde_encoder_phys *phys_enc)
  889. {
  890. struct sde_hw_intf *hw_intf;
  891. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp ||
  892. !phys_enc->hw_intf) {
  893. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  894. return;
  895. }
  896. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  897. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  898. hw_intf = phys_enc->hw_intf;
  899. if (hw_intf->ops.enable_compressed_input)
  900. hw_intf->ops.enable_compressed_input(phys_enc->hw_intf,
  901. (phys_enc->comp_type !=
  902. MSM_DISPLAY_COMPRESSION_NONE), false);
  903. if (hw_intf->ops.enable_wide_bus)
  904. hw_intf->ops.enable_wide_bus(hw_intf,
  905. sde_encoder_is_widebus_enabled(phys_enc->parent));
  906. /*
  907. * For pp-split, skip setting the flush bit for the slave intf, since
  908. * both intfs use same ctl and HW will only flush the master.
  909. */
  910. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  911. !sde_encoder_phys_cmd_is_master(phys_enc))
  912. goto skip_flush;
  913. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  914. skip_flush:
  915. return;
  916. }
  917. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  918. {
  919. struct sde_encoder_phys_cmd *cmd_enc =
  920. to_sde_encoder_phys_cmd(phys_enc);
  921. if (!phys_enc || !phys_enc->hw_pp) {
  922. SDE_ERROR("invalid phys encoder\n");
  923. return;
  924. }
  925. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  926. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  927. if (!phys_enc->cont_splash_enabled)
  928. SDE_ERROR("already enabled\n");
  929. return;
  930. }
  931. sde_encoder_phys_cmd_enable_helper(phys_enc);
  932. phys_enc->enable_state = SDE_ENC_ENABLED;
  933. }
  934. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  935. struct sde_encoder_phys *phys_enc)
  936. {
  937. struct sde_hw_pingpong *hw_pp;
  938. struct sde_hw_intf *hw_intf;
  939. struct sde_hw_autorefresh cfg;
  940. int ret;
  941. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  942. return false;
  943. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  944. return false;
  945. if (phys_enc->has_intf_te) {
  946. hw_intf = phys_enc->hw_intf;
  947. if (!hw_intf->ops.get_autorefresh)
  948. return false;
  949. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  950. } else {
  951. hw_pp = phys_enc->hw_pp;
  952. if (!hw_pp->ops.get_autorefresh)
  953. return false;
  954. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  955. }
  956. return ret ? false : cfg.enable;
  957. }
  958. static void sde_encoder_phys_cmd_connect_te(
  959. struct sde_encoder_phys *phys_enc, bool enable)
  960. {
  961. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  962. return;
  963. if (phys_enc->has_intf_te &&
  964. phys_enc->hw_intf->ops.connect_external_te)
  965. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  966. enable);
  967. else if (phys_enc->hw_pp->ops.connect_external_te)
  968. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  969. enable);
  970. else
  971. return;
  972. SDE_EVT32(DRMID(phys_enc->parent), enable);
  973. }
  974. static int sde_encoder_phys_cmd_te_get_line_count(
  975. struct sde_encoder_phys *phys_enc)
  976. {
  977. struct sde_hw_pingpong *hw_pp;
  978. struct sde_hw_intf *hw_intf;
  979. u32 line_count;
  980. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  981. return -EINVAL;
  982. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  983. return -EINVAL;
  984. if (phys_enc->has_intf_te) {
  985. hw_intf = phys_enc->hw_intf;
  986. if (!hw_intf->ops.get_line_count)
  987. return -EINVAL;
  988. line_count = hw_intf->ops.get_line_count(hw_intf);
  989. } else {
  990. hw_pp = phys_enc->hw_pp;
  991. if (!hw_pp->ops.get_line_count)
  992. return -EINVAL;
  993. line_count = hw_pp->ops.get_line_count(hw_pp);
  994. }
  995. return line_count;
  996. }
  997. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  998. {
  999. struct sde_encoder_phys_cmd *cmd_enc =
  1000. to_sde_encoder_phys_cmd(phys_enc);
  1001. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1002. SDE_ERROR("invalid encoder\n");
  1003. return;
  1004. }
  1005. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  1006. phys_enc->hw_pp->idx - PINGPONG_0,
  1007. phys_enc->hw_intf->idx - INTF_0,
  1008. phys_enc->enable_state);
  1009. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1010. phys_enc->hw_intf->idx - INTF_0,
  1011. phys_enc->enable_state);
  1012. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1013. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1014. return;
  1015. }
  1016. if (!sde_in_trusted_vm(phys_enc->sde_kms)) {
  1017. if (phys_enc->has_intf_te &&
  1018. phys_enc->hw_intf->ops.enable_tearcheck)
  1019. phys_enc->hw_intf->ops.enable_tearcheck(
  1020. phys_enc->hw_intf,
  1021. false);
  1022. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1023. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1024. false);
  1025. if (sde_encoder_phys_cmd_is_master(phys_enc))
  1026. sde_encoder_helper_phys_disable(phys_enc, NULL);
  1027. if (phys_enc->hw_intf->ops.reset_counter)
  1028. phys_enc->hw_intf->ops.reset_counter(phys_enc->hw_intf);
  1029. }
  1030. memset(&cmd_enc->autorefresh.cfg, 0, sizeof(struct sde_hw_autorefresh));
  1031. phys_enc->enable_state = SDE_ENC_DISABLED;
  1032. }
  1033. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1034. {
  1035. struct sde_encoder_phys_cmd *cmd_enc =
  1036. to_sde_encoder_phys_cmd(phys_enc);
  1037. if (!phys_enc) {
  1038. SDE_ERROR("invalid encoder\n");
  1039. return;
  1040. }
  1041. kfree(cmd_enc);
  1042. }
  1043. static void sde_encoder_phys_cmd_get_hw_resources(
  1044. struct sde_encoder_phys *phys_enc,
  1045. struct sde_encoder_hw_resources *hw_res,
  1046. struct drm_connector_state *conn_state)
  1047. {
  1048. struct sde_encoder_phys_cmd *cmd_enc =
  1049. to_sde_encoder_phys_cmd(phys_enc);
  1050. if (!phys_enc) {
  1051. SDE_ERROR("invalid encoder\n");
  1052. return;
  1053. }
  1054. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1055. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1056. return;
  1057. }
  1058. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1059. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1060. }
  1061. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1062. struct sde_encoder_phys *phys_enc,
  1063. struct sde_encoder_kickoff_params *params)
  1064. {
  1065. struct sde_hw_tear_check tc_cfg = {0};
  1066. struct sde_encoder_phys_cmd *cmd_enc =
  1067. to_sde_encoder_phys_cmd(phys_enc);
  1068. int ret = 0;
  1069. bool recovery_events;
  1070. if (!phys_enc || !phys_enc->hw_pp) {
  1071. SDE_ERROR("invalid encoder\n");
  1072. return -EINVAL;
  1073. }
  1074. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1075. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1076. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1077. atomic_read(&phys_enc->pending_kickoff_cnt),
  1078. atomic_read(&cmd_enc->autorefresh.kickoff_cnt),
  1079. phys_enc->frame_trigger_mode);
  1080. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1081. /*
  1082. * Mark kickoff request as outstanding. If there are more
  1083. * than one outstanding frame, then we have to wait for the
  1084. * previous frame to complete
  1085. */
  1086. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1087. if (ret) {
  1088. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1089. SDE_EVT32(DRMID(phys_enc->parent),
  1090. phys_enc->hw_pp->idx - PINGPONG_0);
  1091. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1092. }
  1093. }
  1094. if (phys_enc->recovered) {
  1095. recovery_events = sde_encoder_recovery_events_enabled(
  1096. phys_enc->parent);
  1097. if (cmd_enc->pp_timeout_report_cnt && recovery_events)
  1098. sde_connector_event_notify(phys_enc->connector,
  1099. DRM_EVENT_SDE_HW_RECOVERY,
  1100. sizeof(uint8_t),
  1101. SDE_RECOVERY_SUCCESS);
  1102. cmd_enc->pp_timeout_report_cnt = 0;
  1103. phys_enc->recovered = false;
  1104. }
  1105. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1106. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(
  1107. phys_enc);
  1108. if (phys_enc->has_intf_te &&
  1109. phys_enc->hw_intf->ops.update_tearcheck)
  1110. phys_enc->hw_intf->ops.update_tearcheck(
  1111. phys_enc->hw_intf, &tc_cfg);
  1112. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1113. phys_enc->hw_pp->ops.update_tearcheck(
  1114. phys_enc->hw_pp, &tc_cfg);
  1115. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1116. }
  1117. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1118. phys_enc->hw_pp->idx - PINGPONG_0,
  1119. atomic_read(&phys_enc->pending_kickoff_cnt));
  1120. return ret;
  1121. }
  1122. static bool _sde_encoder_phys_cmd_needs_vsync_change(
  1123. struct sde_encoder_phys *phys_enc, ktime_t profile_timestamp)
  1124. {
  1125. struct sde_encoder_phys_cmd *cmd_enc;
  1126. struct sde_encoder_phys_cmd_te_timestamp *cur;
  1127. struct sde_encoder_phys_cmd_te_timestamp *prev = NULL;
  1128. ktime_t time_diff;
  1129. u64 l_bound = 0, u_bound = 0;
  1130. bool ret = false;
  1131. unsigned long lock_flags;
  1132. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1133. sde_encoder_helper_get_jitter_bounds_ns(phys_enc->parent,
  1134. &l_bound, &u_bound);
  1135. if (!l_bound || !u_bound) {
  1136. SDE_ERROR_CMDENC(cmd_enc, "invalid vsync jitter bounds\n");
  1137. return false;
  1138. }
  1139. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1140. list_for_each_entry_reverse(cur, &cmd_enc->te_timestamp_list, list) {
  1141. if (prev && ktime_after(cur->timestamp, profile_timestamp)) {
  1142. time_diff = ktime_sub(prev->timestamp, cur->timestamp);
  1143. if ((time_diff < l_bound) || (time_diff > u_bound)) {
  1144. ret = true;
  1145. break;
  1146. }
  1147. }
  1148. prev = cur;
  1149. }
  1150. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  1151. if (ret) {
  1152. SDE_DEBUG_CMDENC(cmd_enc,
  1153. "time_diff:%llu, prev:%llu, cur:%llu, jitter:%llu/%llu\n",
  1154. time_diff, prev->timestamp, cur->timestamp,
  1155. l_bound, u_bound);
  1156. time_diff = div_s64(time_diff, 1000);
  1157. SDE_EVT32(DRMID(phys_enc->parent),
  1158. (u32) (do_div(l_bound, 1000)),
  1159. (u32) (do_div(u_bound, 1000)),
  1160. (u32) (time_diff), SDE_EVTLOG_ERROR);
  1161. }
  1162. return ret;
  1163. }
  1164. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1165. struct sde_encoder_phys *phys_enc)
  1166. {
  1167. struct sde_encoder_phys_cmd *cmd_enc =
  1168. to_sde_encoder_phys_cmd(phys_enc);
  1169. struct sde_encoder_wait_info wait_info = {0};
  1170. int ret;
  1171. bool frame_pending = true;
  1172. struct sde_hw_ctl *ctl;
  1173. unsigned long lock_flags;
  1174. if (!phys_enc || !phys_enc->hw_ctl) {
  1175. SDE_ERROR("invalid argument(s)\n");
  1176. return -EINVAL;
  1177. }
  1178. ctl = phys_enc->hw_ctl;
  1179. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1180. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1181. wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
  1182. /* slave encoder doesn't enable for ppsplit */
  1183. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1184. return 0;
  1185. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1186. &wait_info);
  1187. if (ret == -ETIMEDOUT) {
  1188. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1189. if (ctl && ctl->ops.get_start_state)
  1190. frame_pending = ctl->ops.get_start_state(ctl);
  1191. ret = frame_pending ? ret : 0;
  1192. /*
  1193. * There can be few cases of ESD where CTL_START is cleared but
  1194. * wr_ptr irq doesn't come. Signaling retire fence in these
  1195. * cases to avoid freeze and dangling pending_retire_fence_cnt
  1196. */
  1197. if (!ret) {
  1198. SDE_EVT32(DRMID(phys_enc->parent),
  1199. SDE_EVTLOG_FUNC_CASE1);
  1200. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1201. atomic_add_unless(
  1202. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1203. spin_lock_irqsave(phys_enc->enc_spinlock,
  1204. lock_flags);
  1205. phys_enc->parent_ops.handle_frame_done(
  1206. phys_enc->parent, phys_enc,
  1207. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1208. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1209. lock_flags);
  1210. }
  1211. }
  1212. }
  1213. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1214. return ret;
  1215. }
  1216. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1217. struct sde_encoder_phys *phys_enc)
  1218. {
  1219. int rc;
  1220. struct sde_encoder_phys_cmd *cmd_enc;
  1221. if (!phys_enc)
  1222. return -EINVAL;
  1223. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1224. if (!atomic_read(&phys_enc->pending_kickoff_cnt)) {
  1225. SDE_EVT32(DRMID(phys_enc->parent),
  1226. phys_enc->intf_idx - INTF_0,
  1227. phys_enc->enable_state);
  1228. return 0;
  1229. }
  1230. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1231. if (rc) {
  1232. SDE_EVT32(DRMID(phys_enc->parent),
  1233. phys_enc->intf_idx - INTF_0);
  1234. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1235. }
  1236. return rc;
  1237. }
  1238. static int _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1239. struct sde_encoder_phys *phys_enc,
  1240. ktime_t profile_timestamp)
  1241. {
  1242. struct sde_encoder_phys_cmd *cmd_enc =
  1243. to_sde_encoder_phys_cmd(phys_enc);
  1244. bool switch_te;
  1245. int ret = -ETIMEDOUT;
  1246. unsigned long lock_flags;
  1247. switch_te = _sde_encoder_phys_cmd_needs_vsync_change(
  1248. phys_enc, profile_timestamp);
  1249. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_FUNC_ENTRY);
  1250. if (switch_te) {
  1251. SDE_DEBUG_CMDENC(cmd_enc,
  1252. "wr_ptr_irq wait failed, retry with WD TE\n");
  1253. /* switch to watchdog TE and wait again */
  1254. sde_encoder_helper_switch_vsync(phys_enc->parent, true);
  1255. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1256. /* switch back to default TE */
  1257. sde_encoder_helper_switch_vsync(phys_enc->parent, false);
  1258. }
  1259. /*
  1260. * Signaling the retire fence at wr_ptr timeout
  1261. * to allow the next commit and avoid device freeze.
  1262. */
  1263. if (ret == -ETIMEDOUT) {
  1264. SDE_ERROR_CMDENC(cmd_enc,
  1265. "wr_ptr_irq wait failed, switch_te:%d\n", switch_te);
  1266. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_ERROR);
  1267. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1268. atomic_add_unless(
  1269. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1270. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1271. phys_enc->parent_ops.handle_frame_done(
  1272. phys_enc->parent, phys_enc,
  1273. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1274. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1275. lock_flags);
  1276. }
  1277. }
  1278. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1279. return ret;
  1280. }
  1281. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1282. struct sde_encoder_phys *phys_enc)
  1283. {
  1284. int rc = 0, i, pending_cnt;
  1285. struct sde_encoder_phys_cmd *cmd_enc;
  1286. ktime_t profile_timestamp = ktime_get();
  1287. u32 scheduler_status = INVALID_CTL_STATUS;
  1288. struct sde_hw_ctl *ctl;
  1289. if (!phys_enc)
  1290. return -EINVAL;
  1291. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1292. /* only required for master controller */
  1293. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1294. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1295. if (rc == -ETIMEDOUT) {
  1296. /*
  1297. * Profile all the TE received after profile_timestamp
  1298. * and if the jitter is more, switch to watchdog TE
  1299. * and wait for wr_ptr again. Finally move back to
  1300. * default TE.
  1301. */
  1302. rc = _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1303. phys_enc, profile_timestamp);
  1304. if (rc == -ETIMEDOUT)
  1305. goto wait_for_idle;
  1306. }
  1307. if (cmd_enc->autorefresh.cfg.enable)
  1308. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1309. phys_enc);
  1310. ctl = phys_enc->hw_ctl;
  1311. if (ctl && ctl->ops.get_scheduler_status)
  1312. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  1313. }
  1314. /* wait for posted start or serialize trigger */
  1315. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1316. if ((pending_cnt > 1) ||
  1317. (pending_cnt && (scheduler_status & BIT(0))) ||
  1318. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1319. goto wait_for_idle;
  1320. return rc;
  1321. wait_for_idle:
  1322. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1323. for (i = 0; i < pending_cnt; i++)
  1324. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1325. MSM_ENC_TX_COMPLETE);
  1326. if (rc) {
  1327. SDE_EVT32(DRMID(phys_enc->parent),
  1328. phys_enc->hw_pp->idx - PINGPONG_0,
  1329. phys_enc->frame_trigger_mode,
  1330. atomic_read(&phys_enc->pending_kickoff_cnt),
  1331. phys_enc->enable_state,
  1332. cmd_enc->wr_ptr_wait_success, scheduler_status, rc);
  1333. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1334. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1335. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1336. sde_encoder_needs_hw_reset(phys_enc->parent);
  1337. }
  1338. return rc;
  1339. }
  1340. static int sde_encoder_phys_cmd_wait_for_vblank(
  1341. struct sde_encoder_phys *phys_enc)
  1342. {
  1343. int rc = 0;
  1344. struct sde_encoder_phys_cmd *cmd_enc;
  1345. struct sde_encoder_wait_info wait_info = {0};
  1346. if (!phys_enc)
  1347. return -EINVAL;
  1348. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1349. /* only required for master controller */
  1350. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1351. return rc;
  1352. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1353. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1354. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(cmd_enc);
  1355. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1356. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1357. &wait_info);
  1358. return rc;
  1359. }
  1360. static void sde_encoder_phys_cmd_update_split_role(
  1361. struct sde_encoder_phys *phys_enc,
  1362. enum sde_enc_split_role role)
  1363. {
  1364. struct sde_encoder_phys_cmd *cmd_enc;
  1365. enum sde_enc_split_role old_role;
  1366. bool is_ppsplit;
  1367. if (!phys_enc)
  1368. return;
  1369. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1370. old_role = phys_enc->split_role;
  1371. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1372. phys_enc->split_role = role;
  1373. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1374. old_role, role);
  1375. /*
  1376. * ppsplit solo needs to reprogram because intf may have swapped without
  1377. * role changing on left-only, right-only back-to-back commits
  1378. */
  1379. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1380. (role == old_role || role == ENC_ROLE_SKIP))
  1381. return;
  1382. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1383. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1384. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1385. }
  1386. static void _sde_encoder_autorefresh_disable_seq1(
  1387. struct sde_encoder_phys *phys_enc)
  1388. {
  1389. int trial = 0;
  1390. struct sde_encoder_phys_cmd *cmd_enc =
  1391. to_sde_encoder_phys_cmd(phys_enc);
  1392. /*
  1393. * If autorefresh is enabled, disable it and make sure it is safe to
  1394. * proceed with current frame commit/push. Sequence fallowed is,
  1395. * 1. Disable TE - caller will take care of it
  1396. * 2. Disable autorefresh config
  1397. * 4. Poll for frame transfer ongoing to be false
  1398. * 5. Enable TE back - caller will take care of it
  1399. */
  1400. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1401. do {
  1402. udelay(AUTOREFRESH_SEQ1_POLL_TIME);
  1403. if ((trial * AUTOREFRESH_SEQ1_POLL_TIME)
  1404. > (KICKOFF_TIMEOUT_MS * USEC_PER_MSEC)) {
  1405. SDE_ERROR_CMDENC(cmd_enc,
  1406. "disable autorefresh failed\n");
  1407. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  1408. break;
  1409. }
  1410. trial++;
  1411. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1412. }
  1413. static void _sde_encoder_autorefresh_disable_seq2(
  1414. struct sde_encoder_phys *phys_enc)
  1415. {
  1416. int trial = 0;
  1417. struct sde_hw_mdp *hw_mdp = phys_enc->hw_mdptop;
  1418. u32 autorefresh_status = 0;
  1419. struct sde_encoder_phys_cmd *cmd_enc =
  1420. to_sde_encoder_phys_cmd(phys_enc);
  1421. struct intf_tear_status tear_status;
  1422. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  1423. if (!hw_mdp->ops.get_autorefresh_status ||
  1424. !hw_intf->ops.check_and_reset_tearcheck) {
  1425. SDE_DEBUG_CMDENC(cmd_enc,
  1426. "autofresh disable seq2 not supported\n");
  1427. return;
  1428. }
  1429. /*
  1430. * If autorefresh is still enabled after sequence-1, proceed with
  1431. * below sequence-2.
  1432. * 1. Disable autorefresh config
  1433. * 2. Run in loop:
  1434. * 2.1 Poll for autorefresh to be disabled
  1435. * 2.2 Log read and write count status
  1436. * 2.3 Replace te write count with start_pos to meet trigger window
  1437. */
  1438. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1439. phys_enc->intf_idx);
  1440. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1441. autorefresh_status, SDE_EVTLOG_FUNC_CASE1);
  1442. if (!(autorefresh_status & BIT(7))) {
  1443. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1444. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1445. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1446. phys_enc->intf_idx);
  1447. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1448. autorefresh_status, SDE_EVTLOG_FUNC_CASE2);
  1449. }
  1450. while (autorefresh_status & BIT(7)) {
  1451. if (!trial) {
  1452. SDE_ERROR_CMDENC(cmd_enc,
  1453. "autofresh status:0x%x intf:%d\n", autorefresh_status,
  1454. phys_enc->intf_idx - INTF_0);
  1455. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1456. }
  1457. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1458. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1459. if ((trial * AUTOREFRESH_SEQ2_POLL_TIME)
  1460. > AUTOREFRESH_SEQ2_POLL_TIMEOUT) {
  1461. SDE_ERROR_CMDENC(cmd_enc,
  1462. "disable autorefresh failed\n");
  1463. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  1464. break;
  1465. }
  1466. trial++;
  1467. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1468. phys_enc->intf_idx);
  1469. hw_intf->ops.check_and_reset_tearcheck(hw_intf, &tear_status);
  1470. SDE_ERROR_CMDENC(cmd_enc,
  1471. "autofresh status:0x%x intf:%d tear_read:0x%x tear_write:0x%x\n",
  1472. autorefresh_status, phys_enc->intf_idx - INTF_0,
  1473. tear_status.read_count, tear_status.write_count);
  1474. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1475. autorefresh_status, tear_status.read_count,
  1476. tear_status.write_count);
  1477. }
  1478. }
  1479. static void sde_encoder_phys_cmd_prepare_commit(
  1480. struct sde_encoder_phys *phys_enc)
  1481. {
  1482. struct sde_encoder_phys_cmd *cmd_enc =
  1483. to_sde_encoder_phys_cmd(phys_enc);
  1484. if (!phys_enc)
  1485. return;
  1486. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1487. return;
  1488. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1489. cmd_enc->autorefresh.cfg.enable);
  1490. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1491. return;
  1492. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1493. _sde_encoder_autorefresh_disable_seq1(phys_enc);
  1494. _sde_encoder_autorefresh_disable_seq2(phys_enc);
  1495. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1496. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh disabled successfully\n");
  1497. }
  1498. static void sde_encoder_phys_cmd_trigger_start(
  1499. struct sde_encoder_phys *phys_enc)
  1500. {
  1501. struct sde_encoder_phys_cmd *cmd_enc =
  1502. to_sde_encoder_phys_cmd(phys_enc);
  1503. u32 frame_cnt;
  1504. if (!phys_enc)
  1505. return;
  1506. /* we don't issue CTL_START when using autorefresh */
  1507. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1508. if (frame_cnt) {
  1509. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1510. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1511. } else {
  1512. sde_encoder_helper_trigger_start(phys_enc);
  1513. }
  1514. /* wr_ptr_wait_success is set true when wr_ptr arrives */
  1515. cmd_enc->wr_ptr_wait_success = false;
  1516. }
  1517. static void sde_encoder_phys_cmd_setup_vsync_source(
  1518. struct sde_encoder_phys *phys_enc, u32 vsync_source)
  1519. {
  1520. struct sde_encoder_virt *sde_enc;
  1521. if (!phys_enc || !phys_enc->hw_intf)
  1522. return;
  1523. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1524. if (!sde_enc)
  1525. return;
  1526. if (sde_enc->disp_info.is_te_using_watchdog_timer &&
  1527. phys_enc->hw_intf->ops.setup_vsync_source) {
  1528. vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0;
  1529. phys_enc->hw_intf->ops.setup_vsync_source(phys_enc->hw_intf,
  1530. sde_enc->mode_info.frame_rate);
  1531. } else {
  1532. sde_encoder_helper_vsync_config(phys_enc, vsync_source);
  1533. }
  1534. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1535. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1536. vsync_source);
  1537. }
  1538. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1539. {
  1540. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1541. ops->is_master = sde_encoder_phys_cmd_is_master;
  1542. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1543. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1544. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1545. ops->enable = sde_encoder_phys_cmd_enable;
  1546. ops->disable = sde_encoder_phys_cmd_disable;
  1547. ops->destroy = sde_encoder_phys_cmd_destroy;
  1548. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1549. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1550. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1551. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1552. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1553. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1554. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1555. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1556. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1557. ops->hw_reset = sde_encoder_helper_hw_reset;
  1558. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1559. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1560. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1561. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1562. ops->is_autorefresh_enabled =
  1563. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1564. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1565. ops->wait_for_active = NULL;
  1566. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1567. ops->setup_misr = sde_encoder_helper_setup_misr;
  1568. ops->collect_misr = sde_encoder_helper_collect_misr;
  1569. }
  1570. static inline bool sde_encoder_phys_cmd_intf_te_supported(
  1571. const struct sde_mdss_cfg *sde_cfg, enum sde_intf idx)
  1572. {
  1573. if (sde_cfg && ((idx - INTF_0) < sde_cfg->intf_count))
  1574. return test_bit(SDE_INTF_TE,
  1575. &(sde_cfg->intf[idx - INTF_0].features));
  1576. return false;
  1577. }
  1578. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  1579. struct sde_enc_phys_init_params *p)
  1580. {
  1581. struct sde_encoder_phys *phys_enc = NULL;
  1582. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  1583. struct sde_hw_mdp *hw_mdp;
  1584. struct sde_encoder_irq *irq;
  1585. int i, ret = 0;
  1586. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  1587. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  1588. if (!cmd_enc) {
  1589. ret = -ENOMEM;
  1590. SDE_ERROR("failed to allocate\n");
  1591. goto fail;
  1592. }
  1593. phys_enc = &cmd_enc->base;
  1594. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  1595. if (IS_ERR_OR_NULL(hw_mdp)) {
  1596. ret = PTR_ERR(hw_mdp);
  1597. SDE_ERROR("failed to get mdptop\n");
  1598. goto fail_mdp_init;
  1599. }
  1600. phys_enc->hw_mdptop = hw_mdp;
  1601. phys_enc->intf_idx = p->intf_idx;
  1602. phys_enc->parent = p->parent;
  1603. phys_enc->parent_ops = p->parent_ops;
  1604. phys_enc->sde_kms = p->sde_kms;
  1605. phys_enc->split_role = p->split_role;
  1606. phys_enc->intf_mode = INTF_MODE_CMD;
  1607. phys_enc->enc_spinlock = p->enc_spinlock;
  1608. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  1609. cmd_enc->stream_sel = 0;
  1610. phys_enc->enable_state = SDE_ENC_DISABLED;
  1611. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  1612. phys_enc->comp_type = p->comp_type;
  1613. phys_enc->has_intf_te = sde_encoder_phys_cmd_intf_te_supported(
  1614. phys_enc->sde_kms->catalog, phys_enc->intf_idx);
  1615. for (i = 0; i < INTR_IDX_MAX; i++) {
  1616. irq = &phys_enc->irq[i];
  1617. INIT_LIST_HEAD(&irq->cb.list);
  1618. irq->irq_idx = -EINVAL;
  1619. irq->hw_idx = -EINVAL;
  1620. irq->cb.arg = phys_enc;
  1621. }
  1622. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1623. irq->name = "ctl_start";
  1624. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1625. irq->intr_idx = INTR_IDX_CTL_START;
  1626. irq->cb.func = NULL;
  1627. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1628. irq->name = "pp_done";
  1629. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1630. irq->intr_idx = INTR_IDX_PINGPONG;
  1631. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1632. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1633. irq->intr_idx = INTR_IDX_RDPTR;
  1634. irq->name = "te_rd_ptr";
  1635. if (phys_enc->has_intf_te)
  1636. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1637. else
  1638. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1639. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1640. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1641. irq->name = "autorefresh_done";
  1642. if (phys_enc->has_intf_te)
  1643. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1644. else
  1645. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1646. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1647. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  1648. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  1649. irq->intr_idx = INTR_IDX_WRPTR;
  1650. irq->name = "wr_ptr";
  1651. if (phys_enc->has_intf_te)
  1652. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  1653. else
  1654. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  1655. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  1656. atomic_set(&phys_enc->vblank_refcount, 0);
  1657. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1658. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  1659. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  1660. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  1661. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  1662. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  1663. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  1664. INIT_LIST_HEAD(&cmd_enc->te_timestamp_list);
  1665. for (i = 0; i < MAX_TE_PROFILE_COUNT; i++)
  1666. list_add(&cmd_enc->te_timestamp[i].list,
  1667. &cmd_enc->te_timestamp_list);
  1668. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  1669. return phys_enc;
  1670. fail_mdp_init:
  1671. kfree(cmd_enc);
  1672. fail:
  1673. return ERR_PTR(ret);
  1674. }