sde_hw_ctl.c 39 KB

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