sde_hw_ctl.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include <linux/delay.h>
  8. #include "sde_hwio.h"
  9. #include "sde_hw_ctl.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #include "sde_reg_dma.h"
  13. #define CTL_LAYER(lm) \
  14. (((lm) == LM_5) ? (0x024) : (((lm) - LM_0) * 0x004))
  15. #define CTL_LAYER_EXT(lm) \
  16. (0x40 + (((lm) - LM_0) * 0x004))
  17. #define CTL_LAYER_EXT2(lm) \
  18. (0x70 + (((lm) - LM_0) * 0x004))
  19. #define CTL_LAYER_EXT3(lm) \
  20. (0xA0 + (((lm) - LM_0) * 0x004))
  21. #define CTL_LAYER_EXT4(lm) \
  22. (0xB8 + (((lm) - LM_0) * 0x004))
  23. #define CTL_TOP 0x014
  24. #define CTL_FLUSH 0x018
  25. #define CTL_START 0x01C
  26. #define CTL_PREPARE 0x0d0
  27. #define CTL_SW_RESET 0x030
  28. #define CTL_SW_RESET_OVERRIDE 0x060
  29. #define CTL_STATUS 0x064
  30. #define CTL_LAYER_EXTN_OFFSET 0x40
  31. #define CTL_ROT_TOP 0x0C0
  32. #define CTL_ROT_FLUSH 0x0C4
  33. #define CTL_ROT_START 0x0CC
  34. #define CTL_MERGE_3D_ACTIVE 0x0E4
  35. #define CTL_DSC_ACTIVE 0x0E8
  36. #define CTL_WB_ACTIVE 0x0EC
  37. #define CTL_CWB_ACTIVE 0x0F0
  38. #define CTL_INTF_ACTIVE 0x0F4
  39. #define CTL_CDM_ACTIVE 0x0F8
  40. #define CTL_FETCH_PIPE_ACTIVE 0x0FC
  41. #define CTL_MERGE_3D_FLUSH 0x100
  42. #define CTL_DSC_FLUSH 0x104
  43. #define CTL_WB_FLUSH 0x108
  44. #define CTL_CWB_FLUSH 0x10C
  45. #define CTL_INTF_FLUSH 0x110
  46. #define CTL_CDM_FLUSH 0x114
  47. #define CTL_PERIPH_FLUSH 0x128
  48. #define CTL_DSPP_0_FLUSH 0x13c
  49. #define CTL_INTF_MASTER 0x134
  50. #define CTL_UIDLE_ACTIVE 0x138
  51. #define CTL_HW_FENCE_CTRL 0x250
  52. #define CTL_FENCE_READY_SW_OVERRIDE 0x254
  53. #define CTL_INPUT_FENCE_ID 0x258
  54. #define CTL_OUTPUT_FENCE_CTRL 0x25C
  55. #define CTL_OUTPUT_FENCE_ID 0x260
  56. #define CTL_HW_FENCE_STATUS 0x278
  57. #define CTL_OUTPUT_FENCE_SW_OVERRIDE 0x27C
  58. #define CTL_TIMESTAMP_CTRL 0x264
  59. #define CTL_OUTPUT_FENCE_START_TIMESTAMP0 0x268
  60. #define CTL_OUTPUT_FENCE_START_TIMESTAMP1 0x26C
  61. #define CTL_OUTPUT_FENCE_END_TIMESTAMP0 0x270
  62. #define CTL_OUTPUT_FENCE_END_TIMESTAMP1 0x274
  63. #define CTL_MIXER_BORDER_OUT BIT(24)
  64. #define CTL_FLUSH_MASK_ROT BIT(27)
  65. #define CTL_FLUSH_MASK_CTL BIT(17)
  66. #define CTL_NUM_EXT 5
  67. #define CTL_SSPP_MAX_RECTS 2
  68. #define SDE_REG_RESET_TIMEOUT_US 2000
  69. #define SDE_REG_WAIT_RESET_TIMEOUT_US 100000
  70. #define UPDATE_MASK(m, idx, en) \
  71. ((m) = (en) ? ((m) | BIT((idx))) : ((m) & ~BIT((idx))))
  72. #define CTL_INVALID_BIT 0xffff
  73. #define VDC_IDX(i) ((i) + 16)
  74. #define UPDATE_ACTIVE(r, idx, en) UPDATE_MASK((r), (idx), (en))
  75. #define DNSC_BLUR_IDX(i) (i + 16)
  76. /**
  77. * List of SSPP bits in CTL_FLUSH
  78. */
  79. static const u32 sspp_tbl[SSPP_MAX] = { SDE_NONE, 0, 1, 2, 18, 11, 12, 24, 25, 13, 14};
  80. /**
  81. * List of layer mixer bits in CTL_FLUSH
  82. */
  83. static const u32 mixer_tbl[LM_MAX] = {SDE_NONE, 6, 7, 8, 9, 10, 20,
  84. SDE_NONE};
  85. /**
  86. * List of DSPP bits in CTL_FLUSH
  87. */
  88. static const u32 dspp_tbl[DSPP_MAX] = {SDE_NONE, 13, 14, 15, 21};
  89. /**
  90. * List of DSPP PA LUT bits in CTL_FLUSH
  91. */
  92. static const u32 dspp_pav_tbl[DSPP_MAX] = {SDE_NONE, 3, 4, 5, 19};
  93. /**
  94. * List of CDM LUT bits in CTL_FLUSH
  95. */
  96. static const u32 cdm_tbl[CDM_MAX] = {SDE_NONE, 26};
  97. /**
  98. * List of WB bits in CTL_FLUSH
  99. */
  100. static const u32 wb_tbl[WB_MAX] = {SDE_NONE, SDE_NONE, SDE_NONE, 16};
  101. /**
  102. * List of ROT bits in CTL_FLUSH
  103. */
  104. static const u32 rot_tbl[ROT_MAX] = {SDE_NONE, 27};
  105. /**
  106. * List of INTF bits in CTL_FLUSH
  107. */
  108. static const u32 intf_tbl[INTF_MAX] = {SDE_NONE, 31, 30, 29, 28};
  109. /**
  110. * Below definitions are for CTL supporting SDE_CTL_ACTIVE_CFG,
  111. * certain blocks have the individual flush control as well,
  112. * for such blocks flush is done by flushing individual control and
  113. * top level control.
  114. */
  115. /**
  116. * List of SSPP bits in CTL_FETCH_PIPE_ACTIVE
  117. */
  118. static const u32 fetch_tbl[SSPP_MAX] = {CTL_INVALID_BIT, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5};
  119. /**
  120. * list of WB bits in CTL_WB_FLUSH
  121. */
  122. static const u32 wb_flush_tbl[WB_MAX] = {SDE_NONE, SDE_NONE, 1, 2};
  123. /**
  124. * list of INTF bits in CTL_INTF_FLUSH
  125. */
  126. static const u32 intf_flush_tbl[INTF_MAX] = {SDE_NONE, 0, 1, 2, 3, 4, 5};
  127. /**
  128. * list of DSC bits in CTL_DSC_FLUSH
  129. */
  130. static const u32 dsc_flush_tbl[DSC_MAX] = {SDE_NONE, 0, 1, 2, 3, 4, 5};
  131. /**
  132. * list of VDC bits in CTL_DSC_FLUSH
  133. */
  134. static const u32 vdc_flush_tbl[DSC_MAX] = {SDE_NONE, 16, 17};
  135. /**
  136. * list of MERGE_3D bits in CTL_MERGE_3D_FLUSH
  137. */
  138. static const u32 merge_3d_tbl[MERGE_3D_MAX] = {SDE_NONE, 0, 1, 2};
  139. /**
  140. * list of CDM bits in CTL_CDM_FLUSH
  141. */
  142. static const u32 cdm_flush_tbl[CDM_MAX] = {SDE_NONE, 0};
  143. /**
  144. * list of CWB bits in CTL_CWB_FLUSH
  145. */
  146. static const u32 cwb_flush_tbl[CWB_MAX] = {SDE_NONE, SDE_NONE, 1, 2, 3,
  147. 4, 5};
  148. /**
  149. * list of CWB bits in CTL_CWB_FLUSH for dedicated cwb
  150. */
  151. static const u32 dcwb_flush_tbl[CWB_MAX] = {SDE_NONE, SDE_NONE, 0, 1};
  152. /**
  153. * list of DSPP sub-blk flush bits in CTL_DSPP_x_FLUSH
  154. */
  155. static const u32 dspp_sub_blk_flush_tbl[SDE_DSPP_MAX] = {
  156. [SDE_DSPP_IGC] = 2,
  157. [SDE_DSPP_PCC] = 4,
  158. [SDE_DSPP_GC] = 5,
  159. [SDE_DSPP_HSIC] = 0,
  160. [SDE_DSPP_MEMCOLOR] = 0,
  161. [SDE_DSPP_SIXZONE] = 0,
  162. [SDE_DSPP_GAMUT] = 3,
  163. [SDE_DSPP_DITHER] = 0,
  164. [SDE_DSPP_HIST] = 0,
  165. [SDE_DSPP_VLUT] = 1,
  166. [SDE_DSPP_AD] = 0,
  167. [SDE_DSPP_LTM] = 7,
  168. [SDE_DSPP_SPR] = 8,
  169. [SDE_DSPP_DEMURA] = 9,
  170. [SDE_DSPP_RC] = 10,
  171. [SDE_DSPP_SB] = 31,
  172. };
  173. /**
  174. * struct ctl_sspp_stage_reg_map: Describes bit layout for a sspp stage cfg
  175. * @ext: Index to indicate LAYER_x_EXT id for given sspp
  176. * @start: Start position of blend stage bits for given sspp
  177. * @bits: Number of bits from @start assigned for given sspp
  178. * @sec_bit_mask: Bitmask to add to LAYER_x_EXT1 for missing bit of sspp
  179. */
  180. struct ctl_sspp_stage_reg_map {
  181. u32 ext;
  182. u32 start;
  183. u32 bits;
  184. u32 sec_bit_mask;
  185. };
  186. /* list of ctl_sspp_stage_reg_map for all the sppp */
  187. static const struct ctl_sspp_stage_reg_map
  188. sspp_reg_cfg_tbl[SSPP_MAX][CTL_SSPP_MAX_RECTS] = {
  189. /* SSPP_NONE */{ {0, 0, 0, 0}, {0, 0, 0, 0} },
  190. /* SSPP_VIG0 */{ {0, 0, 3, BIT(0)}, {3, 0, 4, 0} },
  191. /* SSPP_VIG1 */{ {0, 3, 3, BIT(2)}, {3, 4, 4, 0} },
  192. /* SSPP_VIG2 */{ {0, 6, 3, BIT(4)}, {3, 8, 4, 0} },
  193. /* SSPP_VIG3 */{ {0, 26, 3, BIT(6)}, {3, 12, 4, 0} },
  194. /* SSPP_DMA0 */{ {0, 18, 3, BIT(16)}, {2, 8, 4, 0} },
  195. /* SSPP_DMA1 */{ {0, 21, 3, BIT(18)}, {2, 12, 4, 0} },
  196. /* SSPP_DMA2 */{ {2, 0, 4, 0}, {2, 16, 4, 0} },
  197. /* SSPP_DMA3 */{ {2, 4, 4, 0}, {2, 20, 4, 0} },
  198. /* SSPP_DMA4 */{ {4, 0, 4, 0}, {4, 8, 4, 0} },
  199. /* SSPP_DMA5 */{ {4, 4, 4, 0}, {4, 12, 4, 0} },
  200. };
  201. /**
  202. * Individual flush bit in CTL_FLUSH
  203. */
  204. #define WB_IDX 16
  205. #define DSC_IDX 22
  206. #define MERGE_3D_IDX 23
  207. #define CDM_IDX 26
  208. #define CWB_IDX 28
  209. #define DSPP_IDX 29
  210. #define PERIPH_IDX 30
  211. #define INTF_IDX 31
  212. /* struct ctl_hw_flush_cfg: Defines the active ctl hw flush config,
  213. * See enum ctl_hw_flush_type for types
  214. * @blk_max: Maximum hw idx
  215. * @flush_reg: Register with corresponding active ctl hw
  216. * @flush_idx: Corresponding index in ctl flush
  217. * @flush_mask_idx: Index of hw flush mask to use
  218. * @flush_tbl: Pointer to flush table
  219. */
  220. struct ctl_hw_flush_cfg {
  221. u32 blk_max;
  222. u32 flush_reg;
  223. u32 flush_idx;
  224. u32 flush_mask_idx;
  225. const u32 *flush_tbl;
  226. };
  227. static const struct ctl_hw_flush_cfg
  228. ctl_hw_flush_cfg_tbl_v1[SDE_HW_FLUSH_MAX] = {
  229. {WB_MAX, CTL_WB_FLUSH, WB_IDX, SDE_HW_FLUSH_WB,
  230. wb_flush_tbl}, /* SDE_HW_FLUSH_WB */
  231. {DSC_MAX, CTL_DSC_FLUSH, DSC_IDX, SDE_HW_FLUSH_DSC,
  232. dsc_flush_tbl}, /* SDE_HW_FLUSH_DSC */
  233. /* VDC is flushed to dsc, flush_reg = 0 so flush is done only once */
  234. {VDC_MAX, 0, DSC_IDX, SDE_HW_FLUSH_DSC,
  235. vdc_flush_tbl}, /* SDE_HW_FLUSH_VDC */
  236. {MERGE_3D_MAX, CTL_MERGE_3D_FLUSH, MERGE_3D_IDX, SDE_HW_FLUSH_MERGE_3D,
  237. merge_3d_tbl}, /* SDE_HW_FLUSH_MERGE_3D */
  238. {CDM_MAX, CTL_CDM_FLUSH, CDM_IDX, SDE_HW_FLUSH_CDM,
  239. cdm_flush_tbl}, /* SDE_HW_FLUSH_CDM */
  240. {CWB_MAX, CTL_CWB_FLUSH, CWB_IDX, SDE_HW_FLUSH_CWB,
  241. cwb_flush_tbl}, /* SDE_HW_FLUSH_CWB */
  242. {INTF_MAX, CTL_PERIPH_FLUSH, PERIPH_IDX, SDE_HW_FLUSH_PERIPH,
  243. intf_flush_tbl }, /* SDE_HW_FLUSH_PERIPH */
  244. {INTF_MAX, CTL_INTF_FLUSH, INTF_IDX, SDE_HW_FLUSH_INTF,
  245. intf_flush_tbl } /* SDE_HW_FLUSH_INTF */
  246. };
  247. static struct sde_ctl_cfg *_ctl_offset(enum sde_ctl ctl,
  248. struct sde_mdss_cfg *m,
  249. void __iomem *addr,
  250. struct sde_hw_blk_reg_map *b)
  251. {
  252. int i;
  253. for (i = 0; i < m->ctl_count; i++) {
  254. if (ctl == m->ctl[i].id) {
  255. b->base_off = addr;
  256. b->blk_off = m->ctl[i].base;
  257. b->length = m->ctl[i].len;
  258. b->hw_rev = m->hw_rev;
  259. b->log_mask = SDE_DBG_MASK_CTL;
  260. return &m->ctl[i];
  261. }
  262. }
  263. return ERR_PTR(-ENOMEM);
  264. }
  265. static int _mixer_stages(const struct sde_lm_cfg *mixer, int count,
  266. enum sde_lm lm)
  267. {
  268. int i;
  269. int stages = -EINVAL;
  270. for (i = 0; i < count; i++) {
  271. if (lm == mixer[i].id) {
  272. stages = mixer[i].sblk->maxblendstages;
  273. break;
  274. }
  275. }
  276. return stages;
  277. }
  278. static inline bool _is_dspp_flush_pending(struct sde_hw_ctl *ctx)
  279. {
  280. int i;
  281. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++) {
  282. if (ctx->flush.pending_dspp_flush_masks[i])
  283. return true;
  284. }
  285. return false;
  286. }
  287. static inline void sde_hw_ctl_update_input_fence(struct sde_hw_ctl *ctx,
  288. u32 client_id, u32 signal_id)
  289. {
  290. u32 val = (client_id << 16) | (0xFFFF & signal_id);
  291. SDE_REG_WRITE(&ctx->hw, CTL_INPUT_FENCE_ID, val);
  292. }
  293. static inline void sde_hw_ctl_update_output_fence(struct sde_hw_ctl *ctx,
  294. u32 client_id, u32 signal_id)
  295. {
  296. u32 val = (client_id << 16) | (0xFFFF & signal_id);
  297. SDE_REG_WRITE(&ctx->hw, CTL_OUTPUT_FENCE_ID, val);
  298. }
  299. static inline int sde_hw_ctl_get_hw_fence_status(struct sde_hw_ctl *ctx)
  300. {
  301. return SDE_REG_READ(&ctx->hw, CTL_HW_FENCE_STATUS);
  302. }
  303. static inline void sde_hw_ctl_trigger_output_fence(struct sde_hw_ctl *ctx, u32 trigger_sel)
  304. {
  305. u32 val = ((trigger_sel & 0xF) << 4) | 0x1;
  306. SDE_REG_WRITE(&ctx->hw, CTL_OUTPUT_FENCE_CTRL, val);
  307. }
  308. static inline void sde_hw_ctl_hw_fence_ctrl(struct sde_hw_ctl *ctx, bool sw_override_set,
  309. bool sw_override_clear, u32 mode)
  310. {
  311. u32 val;
  312. val = SDE_REG_READ(&ctx->hw, CTL_HW_FENCE_CTRL);
  313. val |= (sw_override_set ? BIT(5) : 0) | (sw_override_clear ? BIT(4) : 0);
  314. if (!mode)
  315. val &= ~BIT(0);
  316. else
  317. val |= BIT(0);
  318. SDE_REG_WRITE(&ctx->hw, CTL_HW_FENCE_CTRL, val);
  319. }
  320. static inline void sde_hw_ctl_trigger_sw_override(struct sde_hw_ctl *ctx)
  321. {
  322. /* clear input fence before override */
  323. sde_hw_ctl_update_input_fence(ctx, 0, 0);
  324. SDE_REG_WRITE(&ctx->hw, CTL_FENCE_READY_SW_OVERRIDE, 0x1);
  325. }
  326. static inline void sde_hw_ctl_trigger_output_fence_override(struct sde_hw_ctl *ctx)
  327. {
  328. SDE_REG_WRITE(&ctx->hw, CTL_OUTPUT_FENCE_SW_OVERRIDE, 0x1);
  329. }
  330. static inline void sde_hw_ctl_fence_timestamp_ctrl(struct sde_hw_ctl *ctx, bool enable, bool clear)
  331. {
  332. u32 val;
  333. val = SDE_REG_READ(&ctx->hw, CTL_TIMESTAMP_CTRL);
  334. if (enable)
  335. val |= BIT(0);
  336. else
  337. val &= ~BIT(0);
  338. if (clear)
  339. val |= BIT(1);
  340. else
  341. val &= ~BIT(1);
  342. SDE_REG_WRITE(&ctx->hw, CTL_TIMESTAMP_CTRL, val);
  343. wmb(); /* make sure the ctrl is written */
  344. }
  345. static inline int sde_hw_ctl_output_fence_timestamps(struct sde_hw_ctl *ctx,
  346. u64 *val_start, u64 *val_end)
  347. {
  348. u32 start_l, start_h, end_l, end_h;
  349. if (!ctx || IS_ERR_OR_NULL(val_start) || IS_ERR_OR_NULL(val_end))
  350. return -EINVAL;
  351. start_l = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_START_TIMESTAMP0);
  352. start_h = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_START_TIMESTAMP1);
  353. *val_start = (u64)start_h << 32 | start_l;
  354. end_l = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_END_TIMESTAMP0);
  355. end_h = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_END_TIMESTAMP1);
  356. *val_end = (u64)end_h << 32 | end_l;
  357. /* clear timestamps */
  358. sde_hw_ctl_fence_timestamp_ctrl(ctx, false, true);
  359. return 0;
  360. }
  361. static inline int sde_hw_ctl_trigger_start(struct sde_hw_ctl *ctx)
  362. {
  363. if (!ctx)
  364. return -EINVAL;
  365. SDE_REG_WRITE(&ctx->hw, CTL_START, 0x1);
  366. return 0;
  367. }
  368. static inline int sde_hw_ctl_get_start_state(struct sde_hw_ctl *ctx)
  369. {
  370. if (!ctx)
  371. return -EINVAL;
  372. return SDE_REG_READ(&ctx->hw, CTL_START);
  373. }
  374. static inline int sde_hw_ctl_trigger_pending(struct sde_hw_ctl *ctx)
  375. {
  376. if (!ctx)
  377. return -EINVAL;
  378. SDE_REG_WRITE(&ctx->hw, CTL_PREPARE, 0x1);
  379. return 0;
  380. }
  381. static inline int sde_hw_ctl_clear_pending_flush(struct sde_hw_ctl *ctx)
  382. {
  383. if (!ctx)
  384. return -EINVAL;
  385. memset(&ctx->flush, 0, sizeof(ctx->flush));
  386. return 0;
  387. }
  388. static inline int sde_hw_ctl_update_pending_flush(struct sde_hw_ctl *ctx,
  389. struct sde_ctl_flush_cfg *cfg)
  390. {
  391. if (!ctx || !cfg)
  392. return -EINVAL;
  393. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  394. return 0;
  395. }
  396. static int sde_hw_ctl_get_pending_flush(struct sde_hw_ctl *ctx,
  397. struct sde_ctl_flush_cfg *cfg)
  398. {
  399. if (!ctx || !cfg)
  400. return -EINVAL;
  401. memcpy(cfg, &ctx->flush, sizeof(*cfg));
  402. return 0;
  403. }
  404. static inline int sde_hw_ctl_trigger_flush(struct sde_hw_ctl *ctx)
  405. {
  406. if (!ctx)
  407. return -EINVAL;
  408. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  409. return 0;
  410. }
  411. static inline u32 sde_hw_ctl_get_flush_register(struct sde_hw_ctl *ctx)
  412. {
  413. struct sde_hw_blk_reg_map *c;
  414. u32 rot_op_mode;
  415. if (!ctx)
  416. return 0;
  417. c = &ctx->hw;
  418. rot_op_mode = SDE_REG_READ(c, CTL_ROT_TOP) & 0x3;
  419. /* rotate flush bit is undefined if offline mode, so ignore it */
  420. if (rot_op_mode == SDE_CTL_ROT_OP_MODE_OFFLINE)
  421. return SDE_REG_READ(c, CTL_FLUSH) & ~CTL_FLUSH_MASK_ROT;
  422. return SDE_REG_READ(c, CTL_FLUSH);
  423. }
  424. static inline void sde_hw_ctl_uidle_enable(struct sde_hw_ctl *ctx, bool enable)
  425. {
  426. u32 val;
  427. if (!ctx)
  428. return;
  429. val = SDE_REG_READ(&ctx->hw, CTL_UIDLE_ACTIVE);
  430. val = (val & ~BIT(0)) | (enable ? BIT(0) : 0);
  431. SDE_REG_WRITE(&ctx->hw, CTL_UIDLE_ACTIVE, val);
  432. }
  433. static inline int sde_hw_ctl_update_bitmask_sspp(struct sde_hw_ctl *ctx,
  434. enum sde_sspp sspp,
  435. bool enable)
  436. {
  437. if (!ctx)
  438. return -EINVAL;
  439. if (!(sspp > SSPP_NONE) || !(sspp < SSPP_MAX)) {
  440. SDE_ERROR("Unsupported pipe %d\n", sspp);
  441. return -EINVAL;
  442. }
  443. UPDATE_MASK(ctx->flush.pending_flush_mask, sspp_tbl[sspp], enable);
  444. return 0;
  445. }
  446. static inline int sde_hw_ctl_update_bitmask_mixer(struct sde_hw_ctl *ctx,
  447. enum sde_lm lm,
  448. bool enable)
  449. {
  450. if (!ctx)
  451. return -EINVAL;
  452. if (!(lm > SDE_NONE) || !(lm < LM_MAX)) {
  453. SDE_ERROR("Unsupported mixer %d\n", lm);
  454. return -EINVAL;
  455. }
  456. UPDATE_MASK(ctx->flush.pending_flush_mask, mixer_tbl[lm], enable);
  457. ctx->flush.pending_flush_mask |= CTL_FLUSH_MASK_CTL;
  458. return 0;
  459. }
  460. static inline int sde_hw_ctl_update_bitmask_dspp(struct sde_hw_ctl *ctx,
  461. enum sde_dspp dspp,
  462. bool enable)
  463. {
  464. if (!ctx)
  465. return -EINVAL;
  466. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  467. SDE_ERROR("Unsupported dspp %d\n", dspp);
  468. return -EINVAL;
  469. }
  470. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_tbl[dspp], enable);
  471. return 0;
  472. }
  473. static inline int sde_hw_ctl_update_bitmask_dspp_pavlut(struct sde_hw_ctl *ctx,
  474. enum sde_dspp dspp, bool enable)
  475. {
  476. if (!ctx)
  477. return -EINVAL;
  478. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  479. SDE_ERROR("Unsupported dspp %d\n", dspp);
  480. return -EINVAL;
  481. }
  482. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_pav_tbl[dspp], enable);
  483. return 0;
  484. }
  485. static inline int sde_hw_ctl_update_bitmask_cdm(struct sde_hw_ctl *ctx,
  486. enum sde_cdm cdm,
  487. bool enable)
  488. {
  489. if (!ctx)
  490. return -EINVAL;
  491. if (!(cdm > SDE_NONE) || !(cdm < CDM_MAX) || (cdm == CDM_1)) {
  492. SDE_ERROR("Unsupported cdm %d\n", cdm);
  493. return -EINVAL;
  494. }
  495. UPDATE_MASK(ctx->flush.pending_flush_mask, cdm_tbl[cdm], enable);
  496. return 0;
  497. }
  498. static inline int sde_hw_ctl_update_bitmask_wb(struct sde_hw_ctl *ctx,
  499. enum sde_wb wb, bool enable)
  500. {
  501. if (!ctx)
  502. return -EINVAL;
  503. if (!(wb > SDE_NONE) || !(wb < WB_MAX) ||
  504. (wb == WB_0) || (wb == WB_1)) {
  505. SDE_ERROR("Unsupported wb %d\n", wb);
  506. return -EINVAL;
  507. }
  508. UPDATE_MASK(ctx->flush.pending_flush_mask, wb_tbl[wb], enable);
  509. return 0;
  510. }
  511. static inline int sde_hw_ctl_update_bitmask_intf(struct sde_hw_ctl *ctx,
  512. enum sde_intf intf, bool enable)
  513. {
  514. if (!ctx)
  515. return -EINVAL;
  516. if (!(intf > SDE_NONE) || !(intf < INTF_MAX) || (intf > INTF_4)) {
  517. SDE_ERROR("Unsupported intf %d\n", intf);
  518. return -EINVAL;
  519. }
  520. UPDATE_MASK(ctx->flush.pending_flush_mask, intf_tbl[intf], enable);
  521. return 0;
  522. }
  523. static inline int sde_hw_ctl_update_bitmask(struct sde_hw_ctl *ctx,
  524. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  525. {
  526. int ret = 0;
  527. if (!ctx)
  528. return -EINVAL;
  529. switch (type) {
  530. case SDE_HW_FLUSH_CDM:
  531. ret = sde_hw_ctl_update_bitmask_cdm(ctx, blk_idx, enable);
  532. break;
  533. case SDE_HW_FLUSH_WB:
  534. ret = sde_hw_ctl_update_bitmask_wb(ctx, blk_idx, enable);
  535. break;
  536. case SDE_HW_FLUSH_INTF:
  537. ret = sde_hw_ctl_update_bitmask_intf(ctx, blk_idx, enable);
  538. break;
  539. default:
  540. break;
  541. }
  542. return ret;
  543. }
  544. static inline int sde_hw_ctl_update_bitmask_v1(struct sde_hw_ctl *ctx,
  545. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  546. {
  547. const struct ctl_hw_flush_cfg *cfg;
  548. if (!ctx || !(type < SDE_HW_FLUSH_MAX))
  549. return -EINVAL;
  550. cfg = &ctl_hw_flush_cfg_tbl_v1[type];
  551. if ((blk_idx <= SDE_NONE) || (blk_idx >= cfg->blk_max)) {
  552. SDE_ERROR("Unsupported hw idx, type:%d, blk_idx:%d, blk_max:%d",
  553. type, blk_idx, cfg->blk_max);
  554. return -EINVAL;
  555. }
  556. UPDATE_MASK(ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx],
  557. cfg->flush_tbl[blk_idx], enable);
  558. if (ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx])
  559. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 1);
  560. else
  561. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 0);
  562. return 0;
  563. }
  564. static inline void sde_hw_ctl_update_dnsc_blur_bitmask(struct sde_hw_ctl *ctx,
  565. u32 blk_idx, bool enable)
  566. {
  567. if (enable)
  568. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] |=
  569. BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  570. else
  571. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] &=
  572. ~BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  573. }
  574. static inline int sde_hw_ctl_update_pending_flush_v1(
  575. struct sde_hw_ctl *ctx,
  576. struct sde_ctl_flush_cfg *cfg)
  577. {
  578. int i = 0;
  579. if (!ctx || !cfg)
  580. return -EINVAL;
  581. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  582. ctx->flush.pending_hw_flush_mask[i] |=
  583. cfg->pending_hw_flush_mask[i];
  584. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++)
  585. ctx->flush.pending_dspp_flush_masks[i] |=
  586. cfg->pending_dspp_flush_masks[i];
  587. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  588. return 0;
  589. }
  590. static inline int sde_hw_ctl_update_bitmask_dspp_subblk(struct sde_hw_ctl *ctx,
  591. enum sde_dspp dspp, u32 sub_blk, bool enable)
  592. {
  593. if (!ctx || dspp < DSPP_0 || dspp >= DSPP_MAX ||
  594. sub_blk < SDE_DSPP_IGC || sub_blk >= SDE_DSPP_MAX) {
  595. SDE_ERROR("invalid args - ctx %s, dspp %d sub_block %d\n",
  596. ctx ? "valid" : "invalid", dspp, sub_blk);
  597. return -EINVAL;
  598. }
  599. UPDATE_MASK(ctx->flush.pending_dspp_flush_masks[dspp - DSPP_0],
  600. dspp_sub_blk_flush_tbl[sub_blk], enable);
  601. if (_is_dspp_flush_pending(ctx))
  602. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 1);
  603. else
  604. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 0);
  605. return 0;
  606. }
  607. static void sde_hw_ctl_set_fetch_pipe_active(struct sde_hw_ctl *ctx,
  608. unsigned long *fetch_active)
  609. {
  610. int i;
  611. u32 val = 0;
  612. if (fetch_active) {
  613. for (i = 0; i < SSPP_MAX; i++) {
  614. if (test_bit(i, fetch_active) &&
  615. fetch_tbl[i] != CTL_INVALID_BIT)
  616. val |= BIT(fetch_tbl[i]);
  617. }
  618. }
  619. SDE_REG_WRITE(&ctx->hw, CTL_FETCH_PIPE_ACTIVE, val);
  620. }
  621. static u32 sde_hw_ctl_get_active_fetch_pipes(struct sde_hw_ctl *ctx)
  622. {
  623. int i;
  624. u32 fetch_info, fetch_active = 0;
  625. if (!ctx) {
  626. DRM_ERROR("invalid args - ctx invalid\n");
  627. return 0;
  628. }
  629. fetch_info = SDE_REG_READ(&ctx->hw, CTL_FETCH_PIPE_ACTIVE);
  630. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  631. if (fetch_tbl[i] != CTL_INVALID_BIT &&
  632. fetch_info & BIT(fetch_tbl[i])) {
  633. fetch_active |= BIT(i);
  634. }
  635. }
  636. return fetch_active;
  637. }
  638. static inline void _sde_hw_ctl_write_dspp_flushes(struct sde_hw_ctl *ctx) {
  639. int i;
  640. bool has_dspp_flushes = ctx->caps->features &
  641. BIT(SDE_CTL_UNIFIED_DSPP_FLUSH);
  642. if (!has_dspp_flushes)
  643. return;
  644. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++) {
  645. u32 pending = ctx->flush.pending_dspp_flush_masks[i];
  646. if (pending)
  647. SDE_REG_WRITE(&ctx->hw, CTL_DSPP_0_FLUSH + (i * 4),
  648. pending);
  649. }
  650. }
  651. static inline int sde_hw_ctl_trigger_flush_v1(struct sde_hw_ctl *ctx)
  652. {
  653. int i = 0;
  654. const struct ctl_hw_flush_cfg *cfg = &ctl_hw_flush_cfg_tbl_v1[0];
  655. if (!ctx)
  656. return -EINVAL;
  657. if (ctx->flush.pending_flush_mask & BIT(DSPP_IDX))
  658. _sde_hw_ctl_write_dspp_flushes(ctx);
  659. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  660. if (cfg[i].flush_reg &&
  661. ctx->flush.pending_flush_mask &
  662. BIT(cfg[i].flush_idx))
  663. SDE_REG_WRITE(&ctx->hw,
  664. cfg[i].flush_reg,
  665. ctx->flush.pending_hw_flush_mask[i]);
  666. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  667. return 0;
  668. }
  669. static inline u32 sde_hw_ctl_get_intf_v1(struct sde_hw_ctl *ctx)
  670. {
  671. struct sde_hw_blk_reg_map *c;
  672. u32 intf_active;
  673. if (!ctx) {
  674. pr_err("Invalid input argument\n");
  675. return 0;
  676. }
  677. c = &ctx->hw;
  678. intf_active = SDE_REG_READ(c, CTL_INTF_ACTIVE);
  679. return intf_active;
  680. }
  681. static inline u32 sde_hw_ctl_get_intf(struct sde_hw_ctl *ctx)
  682. {
  683. struct sde_hw_blk_reg_map *c;
  684. u32 ctl_top;
  685. u32 intf_active = 0;
  686. if (!ctx) {
  687. pr_err("Invalid input argument\n");
  688. return 0;
  689. }
  690. c = &ctx->hw;
  691. ctl_top = SDE_REG_READ(c, CTL_TOP);
  692. intf_active = (ctl_top > 0) ?
  693. BIT(ctl_top - 1) : 0;
  694. return intf_active;
  695. }
  696. static u32 sde_hw_ctl_poll_reset_status(struct sde_hw_ctl *ctx, u32 timeout_us)
  697. {
  698. struct sde_hw_blk_reg_map *c;
  699. ktime_t timeout;
  700. u32 status;
  701. if (!ctx)
  702. return 0;
  703. c = &ctx->hw;
  704. timeout = ktime_add_us(ktime_get(), timeout_us);
  705. /*
  706. * it takes around 30us to have mdp finish resetting its ctl path
  707. * poll every 50us so that reset should be completed at 1st poll
  708. */
  709. do {
  710. status = SDE_REG_READ(c, CTL_SW_RESET);
  711. status &= 0x1;
  712. if (status)
  713. usleep_range(20, 50);
  714. } while (status && ktime_compare_safe(ktime_get(), timeout) < 0);
  715. return status;
  716. }
  717. static u32 sde_hw_ctl_get_reset_status(struct sde_hw_ctl *ctx)
  718. {
  719. if (!ctx)
  720. return 0;
  721. return (u32)SDE_REG_READ(&ctx->hw, CTL_SW_RESET);
  722. }
  723. static u32 sde_hw_ctl_get_scheduler_status(struct sde_hw_ctl *ctx)
  724. {
  725. if (!ctx)
  726. return INVALID_CTL_STATUS;
  727. return (u32)SDE_REG_READ(&ctx->hw, CTL_STATUS);
  728. }
  729. static int sde_hw_ctl_reset_control(struct sde_hw_ctl *ctx)
  730. {
  731. struct sde_hw_blk_reg_map *c;
  732. if (!ctx)
  733. return 0;
  734. c = &ctx->hw;
  735. pr_debug("issuing hw ctl reset for ctl:%d\n", ctx->idx);
  736. SDE_REG_WRITE(c, CTL_SW_RESET, 0x1);
  737. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_RESET_TIMEOUT_US))
  738. return -EINVAL;
  739. return 0;
  740. }
  741. static void sde_hw_ctl_hard_reset(struct sde_hw_ctl *ctx, bool enable)
  742. {
  743. struct sde_hw_blk_reg_map *c;
  744. if (!ctx)
  745. return;
  746. c = &ctx->hw;
  747. pr_debug("hw ctl hard reset for ctl:%d, %d\n",
  748. ctx->idx - CTL_0, enable);
  749. SDE_REG_WRITE(c, CTL_SW_RESET_OVERRIDE, enable);
  750. }
  751. static int sde_hw_ctl_wait_reset_status(struct sde_hw_ctl *ctx)
  752. {
  753. struct sde_hw_blk_reg_map *c;
  754. u32 status;
  755. if (!ctx)
  756. return 0;
  757. c = &ctx->hw;
  758. status = SDE_REG_READ(c, CTL_SW_RESET);
  759. status &= 0x01;
  760. if (!status)
  761. return 0;
  762. pr_debug("hw ctl reset is set for ctl:%d\n", ctx->idx);
  763. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_WAIT_RESET_TIMEOUT_US)) {
  764. pr_err("hw recovery is not complete for ctl:%d\n", ctx->idx);
  765. return -EINVAL;
  766. }
  767. return 0;
  768. }
  769. static void sde_hw_ctl_clear_all_blendstages(struct sde_hw_ctl *ctx)
  770. {
  771. struct sde_hw_blk_reg_map *c;
  772. int i;
  773. if (!ctx)
  774. return;
  775. c = &ctx->hw;
  776. for (i = 0; i < ctx->mixer_count; i++) {
  777. int mixer_id = ctx->mixer_hw_caps[i].id;
  778. SDE_REG_WRITE(c, CTL_LAYER(mixer_id), 0);
  779. SDE_REG_WRITE(c, CTL_LAYER_EXT(mixer_id), 0);
  780. SDE_REG_WRITE(c, CTL_LAYER_EXT2(mixer_id), 0);
  781. SDE_REG_WRITE(c, CTL_LAYER_EXT3(mixer_id), 0);
  782. SDE_REG_WRITE(c, CTL_LAYER_EXT4(mixer_id), 0);
  783. }
  784. SDE_REG_WRITE(c, CTL_FETCH_PIPE_ACTIVE, 0);
  785. }
  786. static void _sde_hw_ctl_get_mixer_cfg(struct sde_hw_ctl *ctx,
  787. struct sde_hw_stage_cfg *stage_cfg, int stages, u32 *cfg)
  788. {
  789. int i, j, pipes_per_stage;
  790. const struct ctl_sspp_stage_reg_map *reg_map;
  791. if (test_bit(SDE_MIXER_SOURCESPLIT, &ctx->mixer_hw_caps->features))
  792. pipes_per_stage = PIPES_PER_STAGE;
  793. else
  794. pipes_per_stage = 1;
  795. for (i = 0; i <= stages; i++) {
  796. /* overflow to ext register if 'i + 1 > 7' */
  797. for (j = 0 ; j < pipes_per_stage; j++) {
  798. enum sde_sspp pipe = stage_cfg->stage[i][j];
  799. enum sde_sspp_multirect_index rect_index =
  800. stage_cfg->multirect_index[i][j];
  801. u32 mixer_value;
  802. if (!pipe || pipe >= SSPP_MAX || rect_index >= SDE_SSPP_RECT_MAX)
  803. continue;
  804. /* Handle multi rect enums */
  805. if (rect_index == SDE_SSPP_RECT_SOLO)
  806. rect_index = SDE_SSPP_RECT_0;
  807. reg_map = &sspp_reg_cfg_tbl[pipe][rect_index-1];
  808. if (!reg_map->bits)
  809. continue;
  810. mixer_value = (i + 1) & (BIT(reg_map->bits) - 1);
  811. cfg[reg_map->ext] |= (mixer_value << reg_map->start);
  812. if ((i + 1) > mixer_value)
  813. cfg[1] |= reg_map->sec_bit_mask;
  814. }
  815. }
  816. }
  817. static void sde_hw_ctl_setup_blendstage(struct sde_hw_ctl *ctx,
  818. enum sde_lm lm, struct sde_hw_stage_cfg *stage_cfg,
  819. bool disable_border)
  820. {
  821. struct sde_hw_blk_reg_map *c;
  822. u32 cfg[CTL_NUM_EXT] = { 0 };
  823. int stages;
  824. bool null_commit;
  825. if (!ctx)
  826. return;
  827. stages = _mixer_stages(ctx->mixer_hw_caps, ctx->mixer_count, lm);
  828. if (stages < 0)
  829. return;
  830. c = &ctx->hw;
  831. if (stage_cfg)
  832. _sde_hw_ctl_get_mixer_cfg(ctx, stage_cfg, stages, cfg);
  833. null_commit = (!cfg[0] && !cfg[1] && !cfg[2] && !cfg[3] && !cfg[4]);
  834. if (!disable_border && (null_commit || (stage_cfg && !stage_cfg->stage[0][0])))
  835. cfg[0] |= CTL_MIXER_BORDER_OUT;
  836. SDE_REG_WRITE(c, CTL_LAYER(lm), cfg[0]);
  837. SDE_REG_WRITE(c, CTL_LAYER_EXT(lm), cfg[1]);
  838. SDE_REG_WRITE(c, CTL_LAYER_EXT2(lm), cfg[2]);
  839. SDE_REG_WRITE(c, CTL_LAYER_EXT3(lm), cfg[3]);
  840. SDE_REG_WRITE(c, CTL_LAYER_EXT4(lm), cfg[4]);
  841. }
  842. static u32 sde_hw_ctl_get_staged_sspp(struct sde_hw_ctl *ctx, enum sde_lm lm,
  843. struct sde_sspp_index_info *info)
  844. {
  845. int i, j;
  846. u32 count = 0;
  847. u32 mask = 0;
  848. bool staged;
  849. u32 mixercfg[CTL_NUM_EXT];
  850. struct sde_hw_blk_reg_map *c;
  851. const struct ctl_sspp_stage_reg_map *sspp_cfg;
  852. if (!ctx || (lm >= LM_DCWB_DUMMY_0) || !info)
  853. return 0;
  854. c = &ctx->hw;
  855. mixercfg[0] = SDE_REG_READ(c, CTL_LAYER(lm));
  856. mixercfg[1] = SDE_REG_READ(c, CTL_LAYER_EXT(lm));
  857. mixercfg[2] = SDE_REG_READ(c, CTL_LAYER_EXT2(lm));
  858. mixercfg[3] = SDE_REG_READ(c, CTL_LAYER_EXT3(lm));
  859. mixercfg[4] = SDE_REG_READ(c, CTL_LAYER_EXT4(lm));
  860. if (mixercfg[0] & CTL_MIXER_BORDER_OUT)
  861. info->bordercolor = true;
  862. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  863. for (j = 0; j < CTL_SSPP_MAX_RECTS; j++) {
  864. sspp_cfg = &sspp_reg_cfg_tbl[i][j];
  865. if (!sspp_cfg->bits || sspp_cfg->ext >= CTL_NUM_EXT)
  866. continue;
  867. mask = ((0x1 << sspp_cfg->bits) - 1) << sspp_cfg->start;
  868. staged = mixercfg[sspp_cfg->ext] & mask;
  869. if (!staged)
  870. staged = mixercfg[1] & sspp_cfg->sec_bit_mask;
  871. if (staged) {
  872. if (j)
  873. set_bit(i, info->virt_pipes);
  874. else
  875. set_bit(i, info->pipes);
  876. count++;
  877. }
  878. }
  879. }
  880. return count;
  881. }
  882. static int sde_hw_ctl_intf_cfg_v1(struct sde_hw_ctl *ctx,
  883. struct sde_hw_intf_cfg_v1 *cfg)
  884. {
  885. struct sde_hw_blk_reg_map *c;
  886. u32 intf_active = 0;
  887. u32 wb_active = 0;
  888. u32 merge_3d_active = 0;
  889. u32 cwb_active = 0;
  890. u32 mode_sel = 0xf0000000;
  891. u32 cdm_active = 0;
  892. u32 intf_master = 0;
  893. u32 i;
  894. if (!ctx)
  895. return -EINVAL;
  896. c = &ctx->hw;
  897. for (i = 0; i < cfg->intf_count; i++) {
  898. if (cfg->intf[i])
  899. intf_active |= BIT(cfg->intf[i] - INTF_0);
  900. }
  901. if (cfg->intf_count > 1)
  902. intf_master = BIT(cfg->intf_master - INTF_0);
  903. else if (cfg->intf_count == 1)
  904. intf_master = BIT(cfg->intf[0] - INTF_0);
  905. for (i = 0; i < cfg->wb_count; i++) {
  906. if (cfg->wb[i])
  907. wb_active |= BIT(cfg->wb[i] - WB_0);
  908. }
  909. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  910. if (cfg->dnsc_blur[i])
  911. wb_active |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  912. }
  913. for (i = 0; i < cfg->merge_3d_count; i++) {
  914. if (cfg->merge_3d[i])
  915. merge_3d_active |= BIT(cfg->merge_3d[i] - MERGE_3D_0);
  916. }
  917. for (i = 0; i < cfg->cwb_count; i++) {
  918. if (cfg->cwb[i])
  919. cwb_active |= BIT(cfg->cwb[i] - CWB_0);
  920. }
  921. for (i = 0; i < cfg->cdm_count; i++) {
  922. if (cfg->cdm[i])
  923. cdm_active |= BIT(cfg->cdm[i] - CDM_0);
  924. }
  925. if (cfg->intf_mode_sel == SDE_CTL_MODE_SEL_CMD)
  926. mode_sel |= BIT(17);
  927. SDE_REG_WRITE(c, CTL_TOP, mode_sel);
  928. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  929. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  930. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  931. SDE_REG_WRITE(c, CTL_CDM_ACTIVE, cdm_active);
  932. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  933. SDE_REG_WRITE(c, CTL_INTF_MASTER, intf_master);
  934. return 0;
  935. }
  936. static int sde_hw_ctl_reset_post_disable(struct sde_hw_ctl *ctx,
  937. struct sde_hw_intf_cfg_v1 *cfg, u32 merge_3d_idx)
  938. {
  939. struct sde_hw_blk_reg_map *c;
  940. u32 intf_active = 0, wb_active = 0, merge_3d_active = 0;
  941. u32 intf_flush = 0, wb_flush = 0;
  942. u32 i;
  943. if (!ctx || !cfg) {
  944. SDE_ERROR("invalid hw_ctl or hw_intf blk\n");
  945. return -EINVAL;
  946. }
  947. c = &ctx->hw;
  948. for (i = 0; i < cfg->intf_count; i++) {
  949. if (cfg->intf[i]) {
  950. intf_active &= ~BIT(cfg->intf[i] - INTF_0);
  951. intf_flush |= BIT(cfg->intf[i] - INTF_0);
  952. }
  953. }
  954. for (i = 0; i < cfg->wb_count; i++) {
  955. if (cfg->wb[i]) {
  956. wb_active &= ~BIT(cfg->wb[i] - WB_0);
  957. wb_flush |= BIT(cfg->wb[i] - WB_0);
  958. }
  959. }
  960. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  961. if (cfg->dnsc_blur[i]) {
  962. wb_active &= ~BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  963. wb_flush |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  964. }
  965. }
  966. if (merge_3d_idx) {
  967. /* disable and flush merge3d_blk */
  968. merge_3d_active &= ~BIT(merge_3d_idx - MERGE_3D_0);
  969. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_MERGE_3D] =
  970. BIT(merge_3d_idx - MERGE_3D_0);
  971. UPDATE_MASK(ctx->flush.pending_flush_mask, MERGE_3D_IDX, 1);
  972. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  973. }
  974. sde_hw_ctl_clear_all_blendstages(ctx);
  975. if (cfg->intf_count) {
  976. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_INTF] =
  977. intf_flush;
  978. UPDATE_MASK(ctx->flush.pending_flush_mask, INTF_IDX, 1);
  979. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  980. }
  981. if (cfg->wb_count) {
  982. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] = wb_flush;
  983. UPDATE_MASK(ctx->flush.pending_flush_mask, WB_IDX, 1);
  984. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  985. }
  986. return 0;
  987. }
  988. static int sde_hw_ctl_update_intf_cfg(struct sde_hw_ctl *ctx,
  989. struct sde_hw_intf_cfg_v1 *cfg, bool enable)
  990. {
  991. int i;
  992. u32 cwb_active = 0;
  993. u32 merge_3d_active = 0;
  994. u32 wb_active = 0;
  995. u32 dsc_active = 0;
  996. u32 vdc_active = 0;
  997. struct sde_hw_blk_reg_map *c;
  998. if (!ctx)
  999. return -EINVAL;
  1000. c = &ctx->hw;
  1001. if (cfg->cwb_count) {
  1002. cwb_active = SDE_REG_READ(c, CTL_CWB_ACTIVE);
  1003. for (i = 0; i < cfg->cwb_count; i++) {
  1004. if (cfg->cwb[i])
  1005. UPDATE_ACTIVE(cwb_active,
  1006. (cfg->cwb[i] - CWB_0),
  1007. enable);
  1008. }
  1009. for (i = 0; i < cfg->wb_count; i++) {
  1010. if (cfg->wb[i] && enable)
  1011. wb_active |= BIT(cfg->wb[i] - WB_0);
  1012. }
  1013. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  1014. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  1015. }
  1016. if (cfg->dnsc_blur_count) {
  1017. wb_active = SDE_REG_READ(c, CTL_WB_ACTIVE);
  1018. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  1019. if (cfg->dnsc_blur[i])
  1020. UPDATE_ACTIVE(wb_active,
  1021. DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0),
  1022. enable);
  1023. }
  1024. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  1025. }
  1026. if (cfg->merge_3d_count) {
  1027. merge_3d_active = SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE);
  1028. for (i = 0; i < cfg->merge_3d_count; i++) {
  1029. if (cfg->merge_3d[i])
  1030. UPDATE_ACTIVE(merge_3d_active,
  1031. (cfg->merge_3d[i] - MERGE_3D_0),
  1032. enable);
  1033. }
  1034. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  1035. }
  1036. if (cfg->dsc_count) {
  1037. dsc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  1038. for (i = 0; i < cfg->dsc_count; i++) {
  1039. if (cfg->dsc[i])
  1040. UPDATE_ACTIVE(dsc_active,
  1041. (cfg->dsc[i] - DSC_0), enable);
  1042. }
  1043. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, dsc_active);
  1044. }
  1045. if (cfg->vdc_count) {
  1046. vdc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  1047. for (i = 0; i < cfg->vdc_count; i++) {
  1048. if (cfg->vdc[i])
  1049. UPDATE_ACTIVE(vdc_active,
  1050. VDC_IDX(cfg->vdc[i] - VDC_0), enable);
  1051. }
  1052. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, vdc_active);
  1053. }
  1054. return 0;
  1055. }
  1056. static int sde_hw_ctl_intf_cfg(struct sde_hw_ctl *ctx,
  1057. struct sde_hw_intf_cfg *cfg)
  1058. {
  1059. struct sde_hw_blk_reg_map *c;
  1060. u32 intf_cfg = 0;
  1061. if (!ctx)
  1062. return -EINVAL;
  1063. c = &ctx->hw;
  1064. intf_cfg |= (cfg->intf & 0xF) << 4;
  1065. if (cfg->wb)
  1066. intf_cfg |= (cfg->wb & 0x3) + 2;
  1067. if (cfg->mode_3d) {
  1068. intf_cfg |= BIT(19);
  1069. intf_cfg |= (cfg->mode_3d - 0x1) << 20;
  1070. }
  1071. switch (cfg->intf_mode_sel) {
  1072. case SDE_CTL_MODE_SEL_VID:
  1073. intf_cfg &= ~BIT(17);
  1074. intf_cfg &= ~(0x3 << 15);
  1075. break;
  1076. case SDE_CTL_MODE_SEL_CMD:
  1077. intf_cfg |= BIT(17);
  1078. intf_cfg |= ((cfg->stream_sel & 0x3) << 15);
  1079. break;
  1080. default:
  1081. pr_err("unknown interface type %d\n", cfg->intf_mode_sel);
  1082. return -EINVAL;
  1083. }
  1084. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  1085. return 0;
  1086. }
  1087. static void sde_hw_ctl_update_wb_cfg(struct sde_hw_ctl *ctx,
  1088. struct sde_hw_intf_cfg *cfg, bool enable)
  1089. {
  1090. struct sde_hw_blk_reg_map *c = &ctx->hw;
  1091. u32 intf_cfg = 0;
  1092. if (!cfg->wb)
  1093. return;
  1094. intf_cfg = SDE_REG_READ(c, CTL_TOP);
  1095. if (enable)
  1096. intf_cfg |= (cfg->wb & 0x3) + 2;
  1097. else
  1098. intf_cfg &= ~((cfg->wb & 0x3) + 2);
  1099. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  1100. }
  1101. static inline u32 sde_hw_ctl_read_ctl_layers(struct sde_hw_ctl *ctx, int index)
  1102. {
  1103. struct sde_hw_blk_reg_map *c;
  1104. u32 ctl_top;
  1105. if (!ctx) {
  1106. pr_err("Invalid input argument\n");
  1107. return 0;
  1108. }
  1109. c = &ctx->hw;
  1110. ctl_top = SDE_REG_READ(c, CTL_LAYER(index));
  1111. pr_debug("Ctl_layer value = 0x%x\n", ctl_top);
  1112. return ctl_top;
  1113. }
  1114. static inline bool sde_hw_ctl_read_active_status(struct sde_hw_ctl *ctx,
  1115. enum sde_hw_blk_type blk, int index)
  1116. {
  1117. struct sde_hw_blk_reg_map *c;
  1118. if (!ctx) {
  1119. pr_err("Invalid input argument\n");
  1120. return 0;
  1121. }
  1122. c = &ctx->hw;
  1123. switch (blk) {
  1124. case SDE_HW_BLK_MERGE_3D:
  1125. return (SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE) &
  1126. BIT(index - MERGE_3D_0)) ? true : false;
  1127. case SDE_HW_BLK_DSC:
  1128. return (SDE_REG_READ(c, CTL_DSC_ACTIVE) &
  1129. BIT(index - DSC_0)) ? true : false;
  1130. case SDE_HW_BLK_WB:
  1131. return (SDE_REG_READ(c, CTL_WB_ACTIVE) &
  1132. BIT(index - WB_0)) ? true : false;
  1133. case SDE_HW_BLK_CDM:
  1134. return (SDE_REG_READ(c, CTL_CDM_ACTIVE) &
  1135. BIT(index - CDM_0)) ? true : false;
  1136. case SDE_HW_BLK_INTF:
  1137. return (SDE_REG_READ(c, CTL_INTF_ACTIVE) &
  1138. BIT(index - INTF_0)) ? true : false;
  1139. default:
  1140. pr_err("unsupported blk %d\n", blk);
  1141. return false;
  1142. };
  1143. return false;
  1144. }
  1145. static int sde_hw_reg_dma_flush(struct sde_hw_ctl *ctx, bool blocking)
  1146. {
  1147. struct sde_hw_reg_dma_ops *ops = sde_reg_dma_get_ops();
  1148. if (!ctx)
  1149. return -EINVAL;
  1150. if (ops && ops->last_command)
  1151. return ops->last_command(ctx, DMA_CTL_QUEUE0,
  1152. (blocking ? REG_DMA_WAIT4_COMP : REG_DMA_NOWAIT));
  1153. return 0;
  1154. }
  1155. static void _setup_ctl_ops(struct sde_hw_ctl_ops *ops,
  1156. unsigned long cap)
  1157. {
  1158. if (cap & BIT(SDE_CTL_ACTIVE_CFG)) {
  1159. ops->update_pending_flush =
  1160. sde_hw_ctl_update_pending_flush_v1;
  1161. ops->trigger_flush = sde_hw_ctl_trigger_flush_v1;
  1162. ops->setup_intf_cfg_v1 = sde_hw_ctl_intf_cfg_v1;
  1163. ops->update_intf_cfg = sde_hw_ctl_update_intf_cfg;
  1164. ops->update_bitmask = sde_hw_ctl_update_bitmask_v1;
  1165. ops->update_dnsc_blur_bitmask = sde_hw_ctl_update_dnsc_blur_bitmask;
  1166. ops->get_ctl_intf = sde_hw_ctl_get_intf_v1;
  1167. ops->reset_post_disable = sde_hw_ctl_reset_post_disable;
  1168. ops->get_scheduler_status = sde_hw_ctl_get_scheduler_status;
  1169. ops->read_active_status = sde_hw_ctl_read_active_status;
  1170. ops->set_active_pipes = sde_hw_ctl_set_fetch_pipe_active;
  1171. ops->get_active_pipes = sde_hw_ctl_get_active_fetch_pipes;
  1172. } else {
  1173. ops->update_pending_flush = sde_hw_ctl_update_pending_flush;
  1174. ops->trigger_flush = sde_hw_ctl_trigger_flush;
  1175. ops->setup_intf_cfg = sde_hw_ctl_intf_cfg;
  1176. ops->update_bitmask = sde_hw_ctl_update_bitmask;
  1177. ops->get_ctl_intf = sde_hw_ctl_get_intf;
  1178. }
  1179. ops->clear_pending_flush = sde_hw_ctl_clear_pending_flush;
  1180. ops->get_pending_flush = sde_hw_ctl_get_pending_flush;
  1181. ops->get_flush_register = sde_hw_ctl_get_flush_register;
  1182. ops->trigger_start = sde_hw_ctl_trigger_start;
  1183. ops->trigger_pending = sde_hw_ctl_trigger_pending;
  1184. ops->read_ctl_layers = sde_hw_ctl_read_ctl_layers;
  1185. ops->update_wb_cfg = sde_hw_ctl_update_wb_cfg;
  1186. ops->reset = sde_hw_ctl_reset_control;
  1187. ops->get_reset = sde_hw_ctl_get_reset_status;
  1188. ops->hard_reset = sde_hw_ctl_hard_reset;
  1189. ops->wait_reset_status = sde_hw_ctl_wait_reset_status;
  1190. ops->clear_all_blendstages = sde_hw_ctl_clear_all_blendstages;
  1191. ops->setup_blendstage = sde_hw_ctl_setup_blendstage;
  1192. ops->get_staged_sspp = sde_hw_ctl_get_staged_sspp;
  1193. ops->update_bitmask_sspp = sde_hw_ctl_update_bitmask_sspp;
  1194. ops->update_bitmask_mixer = sde_hw_ctl_update_bitmask_mixer;
  1195. ops->reg_dma_flush = sde_hw_reg_dma_flush;
  1196. ops->get_start_state = sde_hw_ctl_get_start_state;
  1197. if (cap & BIT(SDE_CTL_UNIFIED_DSPP_FLUSH)) {
  1198. ops->update_bitmask_dspp_subblk =
  1199. sde_hw_ctl_update_bitmask_dspp_subblk;
  1200. } else {
  1201. ops->update_bitmask_dspp = sde_hw_ctl_update_bitmask_dspp;
  1202. ops->update_bitmask_dspp_pavlut =
  1203. sde_hw_ctl_update_bitmask_dspp_pavlut;
  1204. }
  1205. if (cap & BIT(SDE_CTL_HW_FENCE)) {
  1206. ops->hw_fence_update_input_fence = sde_hw_ctl_update_input_fence;
  1207. ops->hw_fence_update_output_fence = sde_hw_ctl_update_output_fence;
  1208. ops->hw_fence_trigger_output_fence = sde_hw_ctl_trigger_output_fence;
  1209. ops->hw_fence_ctrl = sde_hw_ctl_hw_fence_ctrl;
  1210. ops->hw_fence_trigger_sw_override = sde_hw_ctl_trigger_sw_override;
  1211. ops->get_hw_fence_status = sde_hw_ctl_get_hw_fence_status;
  1212. ops->trigger_output_fence_override = sde_hw_ctl_trigger_output_fence_override;
  1213. ops->hw_fence_output_status = sde_hw_ctl_output_fence_timestamps;
  1214. ops->hw_fence_output_timestamp_ctrl = sde_hw_ctl_fence_timestamp_ctrl;
  1215. }
  1216. if (cap & BIT(SDE_CTL_UIDLE))
  1217. ops->uidle_enable = sde_hw_ctl_uidle_enable;
  1218. }
  1219. struct sde_hw_blk_reg_map *sde_hw_ctl_init(enum sde_ctl idx,
  1220. void __iomem *addr,
  1221. struct sde_mdss_cfg *m)
  1222. {
  1223. struct sde_hw_ctl *c;
  1224. struct sde_ctl_cfg *cfg;
  1225. c = kzalloc(sizeof(*c), GFP_KERNEL);
  1226. if (!c)
  1227. return ERR_PTR(-ENOMEM);
  1228. cfg = _ctl_offset(idx, m, addr, &c->hw);
  1229. if (IS_ERR_OR_NULL(cfg)) {
  1230. kfree(c);
  1231. pr_err("failed to create sde_hw_ctl %d\n", idx);
  1232. return ERR_PTR(-EINVAL);
  1233. }
  1234. c->caps = cfg;
  1235. _setup_ctl_ops(&c->ops, c->caps->features);
  1236. c->idx = idx;
  1237. c->mixer_count = m->mixer_count;
  1238. c->mixer_hw_caps = m->mixer;
  1239. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  1240. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  1241. return &c->hw;
  1242. }
  1243. void sde_hw_ctl_destroy(struct sde_hw_blk_reg_map *hw)
  1244. {
  1245. if (hw)
  1246. kfree(to_sde_hw_ctl(hw));
  1247. }