sde_hw_ctl.c 39 KB

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