sde_hw_ctl.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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 |= (0x1 & mode) | (sw_override_set ? BIT(5) : 0) | (sw_override_clear ? BIT(4) : 0);
  314. SDE_REG_WRITE(&ctx->hw, CTL_HW_FENCE_CTRL, val);
  315. }
  316. static inline void sde_hw_ctl_trigger_sw_override(struct sde_hw_ctl *ctx)
  317. {
  318. /* clear input fence before override */
  319. sde_hw_ctl_update_input_fence(ctx, 0, 0);
  320. SDE_REG_WRITE(&ctx->hw, CTL_FENCE_READY_SW_OVERRIDE, 0x1);
  321. }
  322. static inline void sde_hw_ctl_trigger_output_fence_override(struct sde_hw_ctl *ctx)
  323. {
  324. SDE_REG_WRITE(&ctx->hw, CTL_OUTPUT_FENCE_SW_OVERRIDE, 0x1);
  325. }
  326. static inline void sde_hw_ctl_fence_timestamp_ctrl(struct sde_hw_ctl *ctx, bool enable, bool clear)
  327. {
  328. u32 val;
  329. val = SDE_REG_READ(&ctx->hw, CTL_TIMESTAMP_CTRL);
  330. if (enable)
  331. val |= BIT(0);
  332. else
  333. val &= ~BIT(0);
  334. if (clear)
  335. val |= BIT(1);
  336. else
  337. val &= ~BIT(1);
  338. SDE_REG_WRITE(&ctx->hw, CTL_TIMESTAMP_CTRL, val);
  339. wmb(); /* make sure the ctrl is written */
  340. }
  341. static inline int sde_hw_ctl_output_fence_timestamps(struct sde_hw_ctl *ctx,
  342. u64 *val_start, u64 *val_end)
  343. {
  344. u32 start_l, start_h, end_l, end_h;
  345. if (!ctx || IS_ERR_OR_NULL(val_start) || IS_ERR_OR_NULL(val_end))
  346. return -EINVAL;
  347. start_l = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_START_TIMESTAMP0);
  348. start_h = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_START_TIMESTAMP1);
  349. *val_start = (u64)start_h << 32 | start_l;
  350. end_l = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_END_TIMESTAMP0);
  351. end_h = SDE_REG_READ(&ctx->hw, CTL_OUTPUT_FENCE_END_TIMESTAMP1);
  352. *val_end = (u64)end_h << 32 | end_l;
  353. /* clear timestamps */
  354. sde_hw_ctl_fence_timestamp_ctrl(ctx, false, true);
  355. return 0;
  356. }
  357. static inline int sde_hw_ctl_trigger_start(struct sde_hw_ctl *ctx)
  358. {
  359. if (!ctx)
  360. return -EINVAL;
  361. SDE_REG_WRITE(&ctx->hw, CTL_START, 0x1);
  362. return 0;
  363. }
  364. static inline int sde_hw_ctl_get_start_state(struct sde_hw_ctl *ctx)
  365. {
  366. if (!ctx)
  367. return -EINVAL;
  368. return SDE_REG_READ(&ctx->hw, CTL_START);
  369. }
  370. static inline int sde_hw_ctl_trigger_pending(struct sde_hw_ctl *ctx)
  371. {
  372. if (!ctx)
  373. return -EINVAL;
  374. SDE_REG_WRITE(&ctx->hw, CTL_PREPARE, 0x1);
  375. return 0;
  376. }
  377. static inline int sde_hw_ctl_clear_pending_flush(struct sde_hw_ctl *ctx)
  378. {
  379. if (!ctx)
  380. return -EINVAL;
  381. memset(&ctx->flush, 0, sizeof(ctx->flush));
  382. return 0;
  383. }
  384. static inline int sde_hw_ctl_update_pending_flush(struct sde_hw_ctl *ctx,
  385. struct sde_ctl_flush_cfg *cfg)
  386. {
  387. if (!ctx || !cfg)
  388. return -EINVAL;
  389. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  390. return 0;
  391. }
  392. static int sde_hw_ctl_get_pending_flush(struct sde_hw_ctl *ctx,
  393. struct sde_ctl_flush_cfg *cfg)
  394. {
  395. if (!ctx || !cfg)
  396. return -EINVAL;
  397. memcpy(cfg, &ctx->flush, sizeof(*cfg));
  398. return 0;
  399. }
  400. static inline int sde_hw_ctl_trigger_flush(struct sde_hw_ctl *ctx)
  401. {
  402. if (!ctx)
  403. return -EINVAL;
  404. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  405. return 0;
  406. }
  407. static inline u32 sde_hw_ctl_get_flush_register(struct sde_hw_ctl *ctx)
  408. {
  409. struct sde_hw_blk_reg_map *c;
  410. u32 rot_op_mode;
  411. if (!ctx)
  412. return 0;
  413. c = &ctx->hw;
  414. rot_op_mode = SDE_REG_READ(c, CTL_ROT_TOP) & 0x3;
  415. /* rotate flush bit is undefined if offline mode, so ignore it */
  416. if (rot_op_mode == SDE_CTL_ROT_OP_MODE_OFFLINE)
  417. return SDE_REG_READ(c, CTL_FLUSH) & ~CTL_FLUSH_MASK_ROT;
  418. return SDE_REG_READ(c, CTL_FLUSH);
  419. }
  420. static inline void sde_hw_ctl_uidle_enable(struct sde_hw_ctl *ctx, bool enable)
  421. {
  422. u32 val;
  423. if (!ctx)
  424. return;
  425. val = SDE_REG_READ(&ctx->hw, CTL_UIDLE_ACTIVE);
  426. val = (val & ~BIT(0)) | (enable ? BIT(0) : 0);
  427. SDE_REG_WRITE(&ctx->hw, CTL_UIDLE_ACTIVE, val);
  428. }
  429. static inline int sde_hw_ctl_update_bitmask_sspp(struct sde_hw_ctl *ctx,
  430. enum sde_sspp sspp,
  431. bool enable)
  432. {
  433. if (!ctx)
  434. return -EINVAL;
  435. if (!(sspp > SSPP_NONE) || !(sspp < SSPP_MAX)) {
  436. SDE_ERROR("Unsupported pipe %d\n", sspp);
  437. return -EINVAL;
  438. }
  439. UPDATE_MASK(ctx->flush.pending_flush_mask, sspp_tbl[sspp], enable);
  440. return 0;
  441. }
  442. static inline int sde_hw_ctl_update_bitmask_mixer(struct sde_hw_ctl *ctx,
  443. enum sde_lm lm,
  444. bool enable)
  445. {
  446. if (!ctx)
  447. return -EINVAL;
  448. if (!(lm > SDE_NONE) || !(lm < LM_MAX)) {
  449. SDE_ERROR("Unsupported mixer %d\n", lm);
  450. return -EINVAL;
  451. }
  452. UPDATE_MASK(ctx->flush.pending_flush_mask, mixer_tbl[lm], enable);
  453. ctx->flush.pending_flush_mask |= CTL_FLUSH_MASK_CTL;
  454. return 0;
  455. }
  456. static inline int sde_hw_ctl_update_bitmask_dspp(struct sde_hw_ctl *ctx,
  457. enum sde_dspp dspp,
  458. bool enable)
  459. {
  460. if (!ctx)
  461. return -EINVAL;
  462. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  463. SDE_ERROR("Unsupported dspp %d\n", dspp);
  464. return -EINVAL;
  465. }
  466. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_tbl[dspp], enable);
  467. return 0;
  468. }
  469. static inline int sde_hw_ctl_update_bitmask_dspp_pavlut(struct sde_hw_ctl *ctx,
  470. enum sde_dspp dspp, bool enable)
  471. {
  472. if (!ctx)
  473. return -EINVAL;
  474. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  475. SDE_ERROR("Unsupported dspp %d\n", dspp);
  476. return -EINVAL;
  477. }
  478. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_pav_tbl[dspp], enable);
  479. return 0;
  480. }
  481. static inline int sde_hw_ctl_update_bitmask_cdm(struct sde_hw_ctl *ctx,
  482. enum sde_cdm cdm,
  483. bool enable)
  484. {
  485. if (!ctx)
  486. return -EINVAL;
  487. if (!(cdm > SDE_NONE) || !(cdm < CDM_MAX) || (cdm == CDM_1)) {
  488. SDE_ERROR("Unsupported cdm %d\n", cdm);
  489. return -EINVAL;
  490. }
  491. UPDATE_MASK(ctx->flush.pending_flush_mask, cdm_tbl[cdm], enable);
  492. return 0;
  493. }
  494. static inline int sde_hw_ctl_update_bitmask_wb(struct sde_hw_ctl *ctx,
  495. enum sde_wb wb, bool enable)
  496. {
  497. if (!ctx)
  498. return -EINVAL;
  499. if (!(wb > SDE_NONE) || !(wb < WB_MAX) ||
  500. (wb == WB_0) || (wb == WB_1)) {
  501. SDE_ERROR("Unsupported wb %d\n", wb);
  502. return -EINVAL;
  503. }
  504. UPDATE_MASK(ctx->flush.pending_flush_mask, wb_tbl[wb], enable);
  505. return 0;
  506. }
  507. static inline int sde_hw_ctl_update_bitmask_intf(struct sde_hw_ctl *ctx,
  508. enum sde_intf intf, bool enable)
  509. {
  510. if (!ctx)
  511. return -EINVAL;
  512. if (!(intf > SDE_NONE) || !(intf < INTF_MAX) || (intf > INTF_4)) {
  513. SDE_ERROR("Unsupported intf %d\n", intf);
  514. return -EINVAL;
  515. }
  516. UPDATE_MASK(ctx->flush.pending_flush_mask, intf_tbl[intf], enable);
  517. return 0;
  518. }
  519. static inline int sde_hw_ctl_update_bitmask(struct sde_hw_ctl *ctx,
  520. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  521. {
  522. int ret = 0;
  523. if (!ctx)
  524. return -EINVAL;
  525. switch (type) {
  526. case SDE_HW_FLUSH_CDM:
  527. ret = sde_hw_ctl_update_bitmask_cdm(ctx, blk_idx, enable);
  528. break;
  529. case SDE_HW_FLUSH_WB:
  530. ret = sde_hw_ctl_update_bitmask_wb(ctx, blk_idx, enable);
  531. break;
  532. case SDE_HW_FLUSH_INTF:
  533. ret = sde_hw_ctl_update_bitmask_intf(ctx, blk_idx, enable);
  534. break;
  535. default:
  536. break;
  537. }
  538. return ret;
  539. }
  540. static inline int sde_hw_ctl_update_bitmask_v1(struct sde_hw_ctl *ctx,
  541. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  542. {
  543. const struct ctl_hw_flush_cfg *cfg;
  544. if (!ctx || !(type < SDE_HW_FLUSH_MAX))
  545. return -EINVAL;
  546. cfg = &ctl_hw_flush_cfg_tbl_v1[type];
  547. if ((blk_idx <= SDE_NONE) || (blk_idx >= cfg->blk_max)) {
  548. SDE_ERROR("Unsupported hw idx, type:%d, blk_idx:%d, blk_max:%d",
  549. type, blk_idx, cfg->blk_max);
  550. return -EINVAL;
  551. }
  552. UPDATE_MASK(ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx],
  553. cfg->flush_tbl[blk_idx], enable);
  554. if (ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx])
  555. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 1);
  556. else
  557. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 0);
  558. return 0;
  559. }
  560. static inline void sde_hw_ctl_update_dnsc_blur_bitmask(struct sde_hw_ctl *ctx,
  561. u32 blk_idx, bool enable)
  562. {
  563. if (enable)
  564. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] |=
  565. BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  566. else
  567. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] &=
  568. ~BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  569. }
  570. static inline int sde_hw_ctl_update_pending_flush_v1(
  571. struct sde_hw_ctl *ctx,
  572. struct sde_ctl_flush_cfg *cfg)
  573. {
  574. int i = 0;
  575. if (!ctx || !cfg)
  576. return -EINVAL;
  577. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  578. ctx->flush.pending_hw_flush_mask[i] |=
  579. cfg->pending_hw_flush_mask[i];
  580. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++)
  581. ctx->flush.pending_dspp_flush_masks[i] |=
  582. cfg->pending_dspp_flush_masks[i];
  583. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  584. return 0;
  585. }
  586. static inline int sde_hw_ctl_update_bitmask_dspp_subblk(struct sde_hw_ctl *ctx,
  587. enum sde_dspp dspp, u32 sub_blk, bool enable)
  588. {
  589. if (!ctx || dspp < DSPP_0 || dspp >= DSPP_MAX ||
  590. sub_blk < SDE_DSPP_IGC || sub_blk >= SDE_DSPP_MAX) {
  591. SDE_ERROR("invalid args - ctx %s, dspp %d sub_block %d\n",
  592. ctx ? "valid" : "invalid", dspp, sub_blk);
  593. return -EINVAL;
  594. }
  595. UPDATE_MASK(ctx->flush.pending_dspp_flush_masks[dspp - DSPP_0],
  596. dspp_sub_blk_flush_tbl[sub_blk], enable);
  597. if (_is_dspp_flush_pending(ctx))
  598. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 1);
  599. else
  600. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 0);
  601. return 0;
  602. }
  603. static void sde_hw_ctl_set_fetch_pipe_active(struct sde_hw_ctl *ctx,
  604. unsigned long *fetch_active)
  605. {
  606. int i;
  607. u32 val = 0;
  608. if (fetch_active) {
  609. for (i = 0; i < SSPP_MAX; i++) {
  610. if (test_bit(i, fetch_active) &&
  611. fetch_tbl[i] != CTL_INVALID_BIT)
  612. val |= BIT(fetch_tbl[i]);
  613. }
  614. }
  615. SDE_REG_WRITE(&ctx->hw, CTL_FETCH_PIPE_ACTIVE, val);
  616. }
  617. static u32 sde_hw_ctl_get_active_fetch_pipes(struct sde_hw_ctl *ctx)
  618. {
  619. int i;
  620. u32 fetch_info, fetch_active = 0;
  621. if (!ctx) {
  622. DRM_ERROR("invalid args - ctx invalid\n");
  623. return 0;
  624. }
  625. fetch_info = SDE_REG_READ(&ctx->hw, CTL_FETCH_PIPE_ACTIVE);
  626. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  627. if (fetch_tbl[i] != CTL_INVALID_BIT &&
  628. fetch_info & BIT(fetch_tbl[i])) {
  629. fetch_active |= BIT(i);
  630. }
  631. }
  632. return fetch_active;
  633. }
  634. static inline void _sde_hw_ctl_write_dspp_flushes(struct sde_hw_ctl *ctx) {
  635. int i;
  636. bool has_dspp_flushes = ctx->caps->features &
  637. BIT(SDE_CTL_UNIFIED_DSPP_FLUSH);
  638. if (!has_dspp_flushes)
  639. return;
  640. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++) {
  641. u32 pending = ctx->flush.pending_dspp_flush_masks[i];
  642. if (pending)
  643. SDE_REG_WRITE(&ctx->hw, CTL_DSPP_0_FLUSH + (i * 4),
  644. pending);
  645. }
  646. }
  647. static inline int sde_hw_ctl_trigger_flush_v1(struct sde_hw_ctl *ctx)
  648. {
  649. int i = 0;
  650. const struct ctl_hw_flush_cfg *cfg = &ctl_hw_flush_cfg_tbl_v1[0];
  651. if (!ctx)
  652. return -EINVAL;
  653. if (ctx->flush.pending_flush_mask & BIT(DSPP_IDX))
  654. _sde_hw_ctl_write_dspp_flushes(ctx);
  655. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  656. if (cfg[i].flush_reg &&
  657. ctx->flush.pending_flush_mask &
  658. BIT(cfg[i].flush_idx))
  659. SDE_REG_WRITE(&ctx->hw,
  660. cfg[i].flush_reg,
  661. ctx->flush.pending_hw_flush_mask[i]);
  662. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  663. return 0;
  664. }
  665. static inline u32 sde_hw_ctl_get_intf_v1(struct sde_hw_ctl *ctx)
  666. {
  667. struct sde_hw_blk_reg_map *c;
  668. u32 intf_active;
  669. if (!ctx) {
  670. pr_err("Invalid input argument\n");
  671. return 0;
  672. }
  673. c = &ctx->hw;
  674. intf_active = SDE_REG_READ(c, CTL_INTF_ACTIVE);
  675. return intf_active;
  676. }
  677. static inline u32 sde_hw_ctl_get_intf(struct sde_hw_ctl *ctx)
  678. {
  679. struct sde_hw_blk_reg_map *c;
  680. u32 ctl_top;
  681. u32 intf_active = 0;
  682. if (!ctx) {
  683. pr_err("Invalid input argument\n");
  684. return 0;
  685. }
  686. c = &ctx->hw;
  687. ctl_top = SDE_REG_READ(c, CTL_TOP);
  688. intf_active = (ctl_top > 0) ?
  689. BIT(ctl_top - 1) : 0;
  690. return intf_active;
  691. }
  692. static u32 sde_hw_ctl_poll_reset_status(struct sde_hw_ctl *ctx, u32 timeout_us)
  693. {
  694. struct sde_hw_blk_reg_map *c;
  695. ktime_t timeout;
  696. u32 status;
  697. if (!ctx)
  698. return 0;
  699. c = &ctx->hw;
  700. timeout = ktime_add_us(ktime_get(), timeout_us);
  701. /*
  702. * it takes around 30us to have mdp finish resetting its ctl path
  703. * poll every 50us so that reset should be completed at 1st poll
  704. */
  705. do {
  706. status = SDE_REG_READ(c, CTL_SW_RESET);
  707. status &= 0x1;
  708. if (status)
  709. usleep_range(20, 50);
  710. } while (status && ktime_compare_safe(ktime_get(), timeout) < 0);
  711. return status;
  712. }
  713. static u32 sde_hw_ctl_get_reset_status(struct sde_hw_ctl *ctx)
  714. {
  715. if (!ctx)
  716. return 0;
  717. return (u32)SDE_REG_READ(&ctx->hw, CTL_SW_RESET);
  718. }
  719. static u32 sde_hw_ctl_get_scheduler_status(struct sde_hw_ctl *ctx)
  720. {
  721. if (!ctx)
  722. return INVALID_CTL_STATUS;
  723. return (u32)SDE_REG_READ(&ctx->hw, CTL_STATUS);
  724. }
  725. static int sde_hw_ctl_reset_control(struct sde_hw_ctl *ctx)
  726. {
  727. struct sde_hw_blk_reg_map *c;
  728. if (!ctx)
  729. return 0;
  730. c = &ctx->hw;
  731. pr_debug("issuing hw ctl reset for ctl:%d\n", ctx->idx);
  732. SDE_REG_WRITE(c, CTL_SW_RESET, 0x1);
  733. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_RESET_TIMEOUT_US))
  734. return -EINVAL;
  735. return 0;
  736. }
  737. static void sde_hw_ctl_hard_reset(struct sde_hw_ctl *ctx, bool enable)
  738. {
  739. struct sde_hw_blk_reg_map *c;
  740. if (!ctx)
  741. return;
  742. c = &ctx->hw;
  743. pr_debug("hw ctl hard reset for ctl:%d, %d\n",
  744. ctx->idx - CTL_0, enable);
  745. SDE_REG_WRITE(c, CTL_SW_RESET_OVERRIDE, enable);
  746. }
  747. static int sde_hw_ctl_wait_reset_status(struct sde_hw_ctl *ctx)
  748. {
  749. struct sde_hw_blk_reg_map *c;
  750. u32 status;
  751. if (!ctx)
  752. return 0;
  753. c = &ctx->hw;
  754. status = SDE_REG_READ(c, CTL_SW_RESET);
  755. status &= 0x01;
  756. if (!status)
  757. return 0;
  758. pr_debug("hw ctl reset is set for ctl:%d\n", ctx->idx);
  759. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_WAIT_RESET_TIMEOUT_US)) {
  760. pr_err("hw recovery is not complete for ctl:%d\n", ctx->idx);
  761. return -EINVAL;
  762. }
  763. return 0;
  764. }
  765. static void sde_hw_ctl_clear_all_blendstages(struct sde_hw_ctl *ctx)
  766. {
  767. struct sde_hw_blk_reg_map *c;
  768. int i;
  769. if (!ctx)
  770. return;
  771. c = &ctx->hw;
  772. for (i = 0; i < ctx->mixer_count; i++) {
  773. int mixer_id = ctx->mixer_hw_caps[i].id;
  774. SDE_REG_WRITE(c, CTL_LAYER(mixer_id), 0);
  775. SDE_REG_WRITE(c, CTL_LAYER_EXT(mixer_id), 0);
  776. SDE_REG_WRITE(c, CTL_LAYER_EXT2(mixer_id), 0);
  777. SDE_REG_WRITE(c, CTL_LAYER_EXT3(mixer_id), 0);
  778. SDE_REG_WRITE(c, CTL_LAYER_EXT4(mixer_id), 0);
  779. }
  780. SDE_REG_WRITE(c, CTL_FETCH_PIPE_ACTIVE, 0);
  781. }
  782. static void _sde_hw_ctl_get_mixer_cfg(struct sde_hw_ctl *ctx,
  783. struct sde_hw_stage_cfg *stage_cfg, int stages, u32 *cfg)
  784. {
  785. int i, j, pipes_per_stage;
  786. const struct ctl_sspp_stage_reg_map *reg_map;
  787. if (test_bit(SDE_MIXER_SOURCESPLIT, &ctx->mixer_hw_caps->features))
  788. pipes_per_stage = PIPES_PER_STAGE;
  789. else
  790. pipes_per_stage = 1;
  791. for (i = 0; i <= stages; i++) {
  792. /* overflow to ext register if 'i + 1 > 7' */
  793. for (j = 0 ; j < pipes_per_stage; j++) {
  794. enum sde_sspp pipe = stage_cfg->stage[i][j];
  795. enum sde_sspp_multirect_index rect_index =
  796. stage_cfg->multirect_index[i][j];
  797. u32 mixer_value;
  798. if (!pipe || pipe >= SSPP_MAX || rect_index >= SDE_SSPP_RECT_MAX)
  799. continue;
  800. /* Handle multi rect enums */
  801. if (rect_index == SDE_SSPP_RECT_SOLO)
  802. rect_index = SDE_SSPP_RECT_0;
  803. reg_map = &sspp_reg_cfg_tbl[pipe][rect_index-1];
  804. if (!reg_map->bits)
  805. continue;
  806. mixer_value = (i + 1) & (BIT(reg_map->bits) - 1);
  807. cfg[reg_map->ext] |= (mixer_value << reg_map->start);
  808. if ((i + 1) > mixer_value)
  809. cfg[1] |= reg_map->sec_bit_mask;
  810. }
  811. }
  812. }
  813. static void sde_hw_ctl_setup_blendstage(struct sde_hw_ctl *ctx,
  814. enum sde_lm lm, struct sde_hw_stage_cfg *stage_cfg,
  815. bool disable_border)
  816. {
  817. struct sde_hw_blk_reg_map *c;
  818. u32 cfg[CTL_NUM_EXT] = { 0 };
  819. int stages;
  820. bool null_commit;
  821. if (!ctx)
  822. return;
  823. stages = _mixer_stages(ctx->mixer_hw_caps, ctx->mixer_count, lm);
  824. if (stages < 0)
  825. return;
  826. c = &ctx->hw;
  827. if (stage_cfg)
  828. _sde_hw_ctl_get_mixer_cfg(ctx, stage_cfg, stages, cfg);
  829. null_commit = (!cfg[0] && !cfg[1] && !cfg[2] && !cfg[3] && !cfg[4]);
  830. if (!disable_border && (null_commit || (stage_cfg && !stage_cfg->stage[0][0])))
  831. cfg[0] |= CTL_MIXER_BORDER_OUT;
  832. SDE_REG_WRITE(c, CTL_LAYER(lm), cfg[0]);
  833. SDE_REG_WRITE(c, CTL_LAYER_EXT(lm), cfg[1]);
  834. SDE_REG_WRITE(c, CTL_LAYER_EXT2(lm), cfg[2]);
  835. SDE_REG_WRITE(c, CTL_LAYER_EXT3(lm), cfg[3]);
  836. SDE_REG_WRITE(c, CTL_LAYER_EXT4(lm), cfg[4]);
  837. }
  838. static u32 sde_hw_ctl_get_staged_sspp(struct sde_hw_ctl *ctx, enum sde_lm lm,
  839. struct sde_sspp_index_info *info)
  840. {
  841. int i, j;
  842. u32 count = 0;
  843. u32 mask = 0;
  844. bool staged;
  845. u32 mixercfg[CTL_NUM_EXT];
  846. struct sde_hw_blk_reg_map *c;
  847. const struct ctl_sspp_stage_reg_map *sspp_cfg;
  848. if (!ctx || (lm >= LM_DCWB_DUMMY_0) || !info)
  849. return 0;
  850. c = &ctx->hw;
  851. mixercfg[0] = SDE_REG_READ(c, CTL_LAYER(lm));
  852. mixercfg[1] = SDE_REG_READ(c, CTL_LAYER_EXT(lm));
  853. mixercfg[2] = SDE_REG_READ(c, CTL_LAYER_EXT2(lm));
  854. mixercfg[3] = SDE_REG_READ(c, CTL_LAYER_EXT3(lm));
  855. mixercfg[4] = SDE_REG_READ(c, CTL_LAYER_EXT4(lm));
  856. if (mixercfg[0] & CTL_MIXER_BORDER_OUT)
  857. info->bordercolor = true;
  858. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  859. for (j = 0; j < CTL_SSPP_MAX_RECTS; j++) {
  860. sspp_cfg = &sspp_reg_cfg_tbl[i][j];
  861. if (!sspp_cfg->bits || sspp_cfg->ext >= CTL_NUM_EXT)
  862. continue;
  863. mask = ((0x1 << sspp_cfg->bits) - 1) << sspp_cfg->start;
  864. staged = mixercfg[sspp_cfg->ext] & mask;
  865. if (!staged)
  866. staged = mixercfg[1] & sspp_cfg->sec_bit_mask;
  867. if (staged) {
  868. if (j)
  869. set_bit(i, info->virt_pipes);
  870. else
  871. set_bit(i, info->pipes);
  872. count++;
  873. }
  874. }
  875. }
  876. return count;
  877. }
  878. static int sde_hw_ctl_intf_cfg_v1(struct sde_hw_ctl *ctx,
  879. struct sde_hw_intf_cfg_v1 *cfg)
  880. {
  881. struct sde_hw_blk_reg_map *c;
  882. u32 intf_active = 0;
  883. u32 wb_active = 0;
  884. u32 merge_3d_active = 0;
  885. u32 cwb_active = 0;
  886. u32 mode_sel = 0xf0000000;
  887. u32 cdm_active = 0;
  888. u32 intf_master = 0;
  889. u32 i;
  890. if (!ctx)
  891. return -EINVAL;
  892. c = &ctx->hw;
  893. for (i = 0; i < cfg->intf_count; i++) {
  894. if (cfg->intf[i])
  895. intf_active |= BIT(cfg->intf[i] - INTF_0);
  896. }
  897. if (cfg->intf_count > 1)
  898. intf_master = BIT(cfg->intf_master - INTF_0);
  899. else if (cfg->intf_count == 1)
  900. intf_master = BIT(cfg->intf[0] - INTF_0);
  901. for (i = 0; i < cfg->wb_count; i++) {
  902. if (cfg->wb[i])
  903. wb_active |= BIT(cfg->wb[i] - WB_0);
  904. }
  905. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  906. if (cfg->dnsc_blur[i])
  907. wb_active |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  908. }
  909. for (i = 0; i < cfg->merge_3d_count; i++) {
  910. if (cfg->merge_3d[i])
  911. merge_3d_active |= BIT(cfg->merge_3d[i] - MERGE_3D_0);
  912. }
  913. for (i = 0; i < cfg->cwb_count; i++) {
  914. if (cfg->cwb[i])
  915. cwb_active |= BIT(cfg->cwb[i] - CWB_0);
  916. }
  917. for (i = 0; i < cfg->cdm_count; i++) {
  918. if (cfg->cdm[i])
  919. cdm_active |= BIT(cfg->cdm[i] - CDM_0);
  920. }
  921. if (cfg->intf_mode_sel == SDE_CTL_MODE_SEL_CMD)
  922. mode_sel |= BIT(17);
  923. SDE_REG_WRITE(c, CTL_TOP, mode_sel);
  924. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  925. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  926. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  927. SDE_REG_WRITE(c, CTL_CDM_ACTIVE, cdm_active);
  928. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  929. SDE_REG_WRITE(c, CTL_INTF_MASTER, intf_master);
  930. return 0;
  931. }
  932. static int sde_hw_ctl_reset_post_disable(struct sde_hw_ctl *ctx,
  933. struct sde_hw_intf_cfg_v1 *cfg, u32 merge_3d_idx)
  934. {
  935. struct sde_hw_blk_reg_map *c;
  936. u32 intf_active = 0, wb_active = 0, merge_3d_active = 0;
  937. u32 intf_flush = 0, wb_flush = 0;
  938. u32 i;
  939. if (!ctx || !cfg) {
  940. SDE_ERROR("invalid hw_ctl or hw_intf blk\n");
  941. return -EINVAL;
  942. }
  943. c = &ctx->hw;
  944. for (i = 0; i < cfg->intf_count; i++) {
  945. if (cfg->intf[i]) {
  946. intf_active &= ~BIT(cfg->intf[i] - INTF_0);
  947. intf_flush |= BIT(cfg->intf[i] - INTF_0);
  948. }
  949. }
  950. for (i = 0; i < cfg->wb_count; i++) {
  951. if (cfg->wb[i]) {
  952. wb_active &= ~BIT(cfg->wb[i] - WB_0);
  953. wb_flush |= BIT(cfg->wb[i] - WB_0);
  954. }
  955. }
  956. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  957. if (cfg->dnsc_blur[i]) {
  958. wb_active &= ~BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  959. wb_flush |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  960. }
  961. }
  962. if (merge_3d_idx) {
  963. /* disable and flush merge3d_blk */
  964. merge_3d_active &= ~BIT(merge_3d_idx - MERGE_3D_0);
  965. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_MERGE_3D] =
  966. BIT(merge_3d_idx - MERGE_3D_0);
  967. UPDATE_MASK(ctx->flush.pending_flush_mask, MERGE_3D_IDX, 1);
  968. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  969. }
  970. sde_hw_ctl_clear_all_blendstages(ctx);
  971. if (cfg->intf_count) {
  972. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_INTF] =
  973. intf_flush;
  974. UPDATE_MASK(ctx->flush.pending_flush_mask, INTF_IDX, 1);
  975. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  976. }
  977. if (cfg->wb_count) {
  978. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] = wb_flush;
  979. UPDATE_MASK(ctx->flush.pending_flush_mask, WB_IDX, 1);
  980. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  981. }
  982. return 0;
  983. }
  984. static int sde_hw_ctl_update_intf_cfg(struct sde_hw_ctl *ctx,
  985. struct sde_hw_intf_cfg_v1 *cfg, bool enable)
  986. {
  987. int i;
  988. u32 cwb_active = 0;
  989. u32 merge_3d_active = 0;
  990. u32 wb_active = 0;
  991. u32 dsc_active = 0;
  992. u32 vdc_active = 0;
  993. struct sde_hw_blk_reg_map *c;
  994. if (!ctx)
  995. return -EINVAL;
  996. c = &ctx->hw;
  997. if (cfg->cwb_count) {
  998. cwb_active = SDE_REG_READ(c, CTL_CWB_ACTIVE);
  999. for (i = 0; i < cfg->cwb_count; i++) {
  1000. if (cfg->cwb[i])
  1001. UPDATE_ACTIVE(cwb_active,
  1002. (cfg->cwb[i] - CWB_0),
  1003. enable);
  1004. }
  1005. for (i = 0; i < cfg->wb_count; i++) {
  1006. if (cfg->wb[i] && enable)
  1007. wb_active |= BIT(cfg->wb[i] - WB_0);
  1008. }
  1009. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  1010. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  1011. }
  1012. if (cfg->dnsc_blur_count) {
  1013. wb_active = SDE_REG_READ(c, CTL_WB_ACTIVE);
  1014. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  1015. if (cfg->dnsc_blur[i])
  1016. UPDATE_ACTIVE(wb_active,
  1017. DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0),
  1018. enable);
  1019. }
  1020. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  1021. }
  1022. if (cfg->merge_3d_count) {
  1023. merge_3d_active = SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE);
  1024. for (i = 0; i < cfg->merge_3d_count; i++) {
  1025. if (cfg->merge_3d[i])
  1026. UPDATE_ACTIVE(merge_3d_active,
  1027. (cfg->merge_3d[i] - MERGE_3D_0),
  1028. enable);
  1029. }
  1030. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  1031. }
  1032. if (cfg->dsc_count) {
  1033. dsc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  1034. for (i = 0; i < cfg->dsc_count; i++) {
  1035. if (cfg->dsc[i])
  1036. UPDATE_ACTIVE(dsc_active,
  1037. (cfg->dsc[i] - DSC_0), enable);
  1038. }
  1039. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, dsc_active);
  1040. }
  1041. if (cfg->vdc_count) {
  1042. vdc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  1043. for (i = 0; i < cfg->vdc_count; i++) {
  1044. if (cfg->vdc[i])
  1045. UPDATE_ACTIVE(vdc_active,
  1046. VDC_IDX(cfg->vdc[i] - VDC_0), enable);
  1047. }
  1048. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, vdc_active);
  1049. }
  1050. return 0;
  1051. }
  1052. static int sde_hw_ctl_intf_cfg(struct sde_hw_ctl *ctx,
  1053. struct sde_hw_intf_cfg *cfg)
  1054. {
  1055. struct sde_hw_blk_reg_map *c;
  1056. u32 intf_cfg = 0;
  1057. if (!ctx)
  1058. return -EINVAL;
  1059. c = &ctx->hw;
  1060. intf_cfg |= (cfg->intf & 0xF) << 4;
  1061. if (cfg->wb)
  1062. intf_cfg |= (cfg->wb & 0x3) + 2;
  1063. if (cfg->mode_3d) {
  1064. intf_cfg |= BIT(19);
  1065. intf_cfg |= (cfg->mode_3d - 0x1) << 20;
  1066. }
  1067. switch (cfg->intf_mode_sel) {
  1068. case SDE_CTL_MODE_SEL_VID:
  1069. intf_cfg &= ~BIT(17);
  1070. intf_cfg &= ~(0x3 << 15);
  1071. break;
  1072. case SDE_CTL_MODE_SEL_CMD:
  1073. intf_cfg |= BIT(17);
  1074. intf_cfg |= ((cfg->stream_sel & 0x3) << 15);
  1075. break;
  1076. default:
  1077. pr_err("unknown interface type %d\n", cfg->intf_mode_sel);
  1078. return -EINVAL;
  1079. }
  1080. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  1081. return 0;
  1082. }
  1083. static void sde_hw_ctl_update_wb_cfg(struct sde_hw_ctl *ctx,
  1084. struct sde_hw_intf_cfg *cfg, bool enable)
  1085. {
  1086. struct sde_hw_blk_reg_map *c = &ctx->hw;
  1087. u32 intf_cfg = 0;
  1088. if (!cfg->wb)
  1089. return;
  1090. intf_cfg = SDE_REG_READ(c, CTL_TOP);
  1091. if (enable)
  1092. intf_cfg |= (cfg->wb & 0x3) + 2;
  1093. else
  1094. intf_cfg &= ~((cfg->wb & 0x3) + 2);
  1095. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  1096. }
  1097. static inline u32 sde_hw_ctl_read_ctl_layers(struct sde_hw_ctl *ctx, int index)
  1098. {
  1099. struct sde_hw_blk_reg_map *c;
  1100. u32 ctl_top;
  1101. if (!ctx) {
  1102. pr_err("Invalid input argument\n");
  1103. return 0;
  1104. }
  1105. c = &ctx->hw;
  1106. ctl_top = SDE_REG_READ(c, CTL_LAYER(index));
  1107. pr_debug("Ctl_layer value = 0x%x\n", ctl_top);
  1108. return ctl_top;
  1109. }
  1110. static inline bool sde_hw_ctl_read_active_status(struct sde_hw_ctl *ctx,
  1111. enum sde_hw_blk_type blk, int index)
  1112. {
  1113. struct sde_hw_blk_reg_map *c;
  1114. if (!ctx) {
  1115. pr_err("Invalid input argument\n");
  1116. return 0;
  1117. }
  1118. c = &ctx->hw;
  1119. switch (blk) {
  1120. case SDE_HW_BLK_MERGE_3D:
  1121. return (SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE) &
  1122. BIT(index - MERGE_3D_0)) ? true : false;
  1123. case SDE_HW_BLK_DSC:
  1124. return (SDE_REG_READ(c, CTL_DSC_ACTIVE) &
  1125. BIT(index - DSC_0)) ? true : false;
  1126. case SDE_HW_BLK_WB:
  1127. return (SDE_REG_READ(c, CTL_WB_ACTIVE) &
  1128. BIT(index - WB_0)) ? true : false;
  1129. case SDE_HW_BLK_CDM:
  1130. return (SDE_REG_READ(c, CTL_CDM_ACTIVE) &
  1131. BIT(index - CDM_0)) ? true : false;
  1132. case SDE_HW_BLK_INTF:
  1133. return (SDE_REG_READ(c, CTL_INTF_ACTIVE) &
  1134. BIT(index - INTF_0)) ? true : false;
  1135. default:
  1136. pr_err("unsupported blk %d\n", blk);
  1137. return false;
  1138. };
  1139. return false;
  1140. }
  1141. static int sde_hw_reg_dma_flush(struct sde_hw_ctl *ctx, bool blocking)
  1142. {
  1143. struct sde_hw_reg_dma_ops *ops = sde_reg_dma_get_ops();
  1144. if (!ctx)
  1145. return -EINVAL;
  1146. if (ops && ops->last_command)
  1147. return ops->last_command(ctx, DMA_CTL_QUEUE0,
  1148. (blocking ? REG_DMA_WAIT4_COMP : REG_DMA_NOWAIT));
  1149. return 0;
  1150. }
  1151. static void _setup_ctl_ops(struct sde_hw_ctl_ops *ops,
  1152. unsigned long cap)
  1153. {
  1154. if (cap & BIT(SDE_CTL_ACTIVE_CFG)) {
  1155. ops->update_pending_flush =
  1156. sde_hw_ctl_update_pending_flush_v1;
  1157. ops->trigger_flush = sde_hw_ctl_trigger_flush_v1;
  1158. ops->setup_intf_cfg_v1 = sde_hw_ctl_intf_cfg_v1;
  1159. ops->update_intf_cfg = sde_hw_ctl_update_intf_cfg;
  1160. ops->update_bitmask = sde_hw_ctl_update_bitmask_v1;
  1161. ops->update_dnsc_blur_bitmask = sde_hw_ctl_update_dnsc_blur_bitmask;
  1162. ops->get_ctl_intf = sde_hw_ctl_get_intf_v1;
  1163. ops->reset_post_disable = sde_hw_ctl_reset_post_disable;
  1164. ops->get_scheduler_status = sde_hw_ctl_get_scheduler_status;
  1165. ops->read_active_status = sde_hw_ctl_read_active_status;
  1166. ops->set_active_pipes = sde_hw_ctl_set_fetch_pipe_active;
  1167. ops->get_active_pipes = sde_hw_ctl_get_active_fetch_pipes;
  1168. } else {
  1169. ops->update_pending_flush = sde_hw_ctl_update_pending_flush;
  1170. ops->trigger_flush = sde_hw_ctl_trigger_flush;
  1171. ops->setup_intf_cfg = sde_hw_ctl_intf_cfg;
  1172. ops->update_bitmask = sde_hw_ctl_update_bitmask;
  1173. ops->get_ctl_intf = sde_hw_ctl_get_intf;
  1174. }
  1175. ops->clear_pending_flush = sde_hw_ctl_clear_pending_flush;
  1176. ops->get_pending_flush = sde_hw_ctl_get_pending_flush;
  1177. ops->get_flush_register = sde_hw_ctl_get_flush_register;
  1178. ops->trigger_start = sde_hw_ctl_trigger_start;
  1179. ops->trigger_pending = sde_hw_ctl_trigger_pending;
  1180. ops->read_ctl_layers = sde_hw_ctl_read_ctl_layers;
  1181. ops->update_wb_cfg = sde_hw_ctl_update_wb_cfg;
  1182. ops->reset = sde_hw_ctl_reset_control;
  1183. ops->get_reset = sde_hw_ctl_get_reset_status;
  1184. ops->hard_reset = sde_hw_ctl_hard_reset;
  1185. ops->wait_reset_status = sde_hw_ctl_wait_reset_status;
  1186. ops->clear_all_blendstages = sde_hw_ctl_clear_all_blendstages;
  1187. ops->setup_blendstage = sde_hw_ctl_setup_blendstage;
  1188. ops->get_staged_sspp = sde_hw_ctl_get_staged_sspp;
  1189. ops->update_bitmask_sspp = sde_hw_ctl_update_bitmask_sspp;
  1190. ops->update_bitmask_mixer = sde_hw_ctl_update_bitmask_mixer;
  1191. ops->reg_dma_flush = sde_hw_reg_dma_flush;
  1192. ops->get_start_state = sde_hw_ctl_get_start_state;
  1193. if (cap & BIT(SDE_CTL_UNIFIED_DSPP_FLUSH)) {
  1194. ops->update_bitmask_dspp_subblk =
  1195. sde_hw_ctl_update_bitmask_dspp_subblk;
  1196. } else {
  1197. ops->update_bitmask_dspp = sde_hw_ctl_update_bitmask_dspp;
  1198. ops->update_bitmask_dspp_pavlut =
  1199. sde_hw_ctl_update_bitmask_dspp_pavlut;
  1200. }
  1201. if (cap & BIT(SDE_CTL_HW_FENCE)) {
  1202. ops->hw_fence_update_input_fence = sde_hw_ctl_update_input_fence;
  1203. ops->hw_fence_update_output_fence = sde_hw_ctl_update_output_fence;
  1204. ops->hw_fence_trigger_output_fence = sde_hw_ctl_trigger_output_fence;
  1205. ops->hw_fence_ctrl = sde_hw_ctl_hw_fence_ctrl;
  1206. ops->hw_fence_trigger_sw_override = sde_hw_ctl_trigger_sw_override;
  1207. ops->get_hw_fence_status = sde_hw_ctl_get_hw_fence_status;
  1208. ops->trigger_output_fence_override = sde_hw_ctl_trigger_output_fence_override;
  1209. ops->hw_fence_output_status = sde_hw_ctl_output_fence_timestamps;
  1210. ops->hw_fence_output_timestamp_ctrl = sde_hw_ctl_fence_timestamp_ctrl;
  1211. }
  1212. if (cap & BIT(SDE_CTL_UIDLE))
  1213. ops->uidle_enable = sde_hw_ctl_uidle_enable;
  1214. }
  1215. struct sde_hw_blk_reg_map *sde_hw_ctl_init(enum sde_ctl idx,
  1216. void __iomem *addr,
  1217. struct sde_mdss_cfg *m)
  1218. {
  1219. struct sde_hw_ctl *c;
  1220. struct sde_ctl_cfg *cfg;
  1221. c = kzalloc(sizeof(*c), GFP_KERNEL);
  1222. if (!c)
  1223. return ERR_PTR(-ENOMEM);
  1224. cfg = _ctl_offset(idx, m, addr, &c->hw);
  1225. if (IS_ERR_OR_NULL(cfg)) {
  1226. kfree(c);
  1227. pr_err("failed to create sde_hw_ctl %d\n", idx);
  1228. return ERR_PTR(-EINVAL);
  1229. }
  1230. c->caps = cfg;
  1231. _setup_ctl_ops(&c->ops, c->caps->features);
  1232. c->idx = idx;
  1233. c->mixer_count = m->mixer_count;
  1234. c->mixer_hw_caps = m->mixer;
  1235. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  1236. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  1237. return &c->hw;
  1238. }
  1239. void sde_hw_ctl_destroy(struct sde_hw_blk_reg_map *hw)
  1240. {
  1241. if (hw)
  1242. kfree(to_sde_hw_ctl(hw));
  1243. }