mdp5_ctl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mdp5_kms.h"
  14. #include "mdp5_ctl.h"
  15. /*
  16. * CTL - MDP Control Pool Manager
  17. *
  18. * Controls are shared between all display interfaces.
  19. *
  20. * They are intended to be used for data path configuration.
  21. * The top level register programming describes the complete data path for
  22. * a specific data path ID - REG_MDP5_CTL_*(<id>, ...)
  23. *
  24. * Hardware capabilities determine the number of concurrent data paths
  25. *
  26. * In certain use cases (high-resolution dual pipe), one single CTL can be
  27. * shared across multiple CRTCs.
  28. */
  29. #define CTL_STAT_BUSY 0x1
  30. #define CTL_STAT_BOOKED 0x2
  31. struct op_mode {
  32. struct mdp5_interface intf;
  33. bool encoder_enabled;
  34. uint32_t start_mask;
  35. };
  36. struct mdp5_ctl {
  37. struct mdp5_ctl_manager *ctlm;
  38. u32 id;
  39. int lm;
  40. /* CTL status bitmask */
  41. u32 status;
  42. /* Operation Mode Configuration for the Pipeline */
  43. struct op_mode pipeline;
  44. /* REG_MDP5_CTL_*(<id>) registers access info + lock: */
  45. spinlock_t hw_lock;
  46. u32 reg_offset;
  47. /* when do CTL registers need to be flushed? (mask of trigger bits) */
  48. u32 pending_ctl_trigger;
  49. bool cursor_on;
  50. /* True if the current CTL has FLUSH bits pending for single FLUSH. */
  51. bool flush_pending;
  52. struct mdp5_ctl *pair; /* Paired CTL to be flushed together */
  53. };
  54. struct mdp5_ctl_manager {
  55. struct drm_device *dev;
  56. /* number of CTL / Layer Mixers in this hw config: */
  57. u32 nlm;
  58. u32 nctl;
  59. /* to filter out non-present bits in the current hardware config */
  60. u32 flush_hw_mask;
  61. /* status for single FLUSH */
  62. bool single_flush_supported;
  63. u32 single_flush_pending_mask;
  64. /* pool of CTLs + lock to protect resource allocation (ctls[i].busy) */
  65. spinlock_t pool_lock;
  66. struct mdp5_ctl ctls[MAX_CTL];
  67. };
  68. static inline
  69. struct mdp5_kms *get_kms(struct mdp5_ctl_manager *ctl_mgr)
  70. {
  71. struct msm_drm_private *priv = ctl_mgr->dev->dev_private;
  72. return to_mdp5_kms(to_mdp_kms(priv->kms));
  73. }
  74. static inline
  75. void ctl_write(struct mdp5_ctl *ctl, u32 reg, u32 data)
  76. {
  77. struct mdp5_kms *mdp5_kms = get_kms(ctl->ctlm);
  78. (void)ctl->reg_offset; /* TODO use this instead of mdp5_write */
  79. mdp5_write(mdp5_kms, reg, data);
  80. }
  81. static inline
  82. u32 ctl_read(struct mdp5_ctl *ctl, u32 reg)
  83. {
  84. struct mdp5_kms *mdp5_kms = get_kms(ctl->ctlm);
  85. (void)ctl->reg_offset; /* TODO use this instead of mdp5_write */
  86. return mdp5_read(mdp5_kms, reg);
  87. }
  88. static void set_display_intf(struct mdp5_kms *mdp5_kms,
  89. struct mdp5_interface *intf)
  90. {
  91. unsigned long flags;
  92. u32 intf_sel;
  93. spin_lock_irqsave(&mdp5_kms->resource_lock, flags);
  94. intf_sel = mdp5_read(mdp5_kms, REG_MDP5_MDP_DISP_INTF_SEL(0));
  95. switch (intf->num) {
  96. case 0:
  97. intf_sel &= ~MDP5_MDP_DISP_INTF_SEL_INTF0__MASK;
  98. intf_sel |= MDP5_MDP_DISP_INTF_SEL_INTF0(intf->type);
  99. break;
  100. case 1:
  101. intf_sel &= ~MDP5_MDP_DISP_INTF_SEL_INTF1__MASK;
  102. intf_sel |= MDP5_MDP_DISP_INTF_SEL_INTF1(intf->type);
  103. break;
  104. case 2:
  105. intf_sel &= ~MDP5_MDP_DISP_INTF_SEL_INTF2__MASK;
  106. intf_sel |= MDP5_MDP_DISP_INTF_SEL_INTF2(intf->type);
  107. break;
  108. case 3:
  109. intf_sel &= ~MDP5_MDP_DISP_INTF_SEL_INTF3__MASK;
  110. intf_sel |= MDP5_MDP_DISP_INTF_SEL_INTF3(intf->type);
  111. break;
  112. default:
  113. BUG();
  114. break;
  115. }
  116. mdp5_write(mdp5_kms, REG_MDP5_MDP_DISP_INTF_SEL(0), intf_sel);
  117. spin_unlock_irqrestore(&mdp5_kms->resource_lock, flags);
  118. }
  119. static void set_ctl_op(struct mdp5_ctl *ctl, struct mdp5_interface *intf)
  120. {
  121. unsigned long flags;
  122. u32 ctl_op = 0;
  123. if (!mdp5_cfg_intf_is_virtual(intf->type))
  124. ctl_op |= MDP5_CTL_OP_INTF_NUM(INTF0 + intf->num);
  125. switch (intf->type) {
  126. case INTF_DSI:
  127. if (intf->mode == MDP5_INTF_DSI_MODE_COMMAND)
  128. ctl_op |= MDP5_CTL_OP_CMD_MODE;
  129. break;
  130. case INTF_WB:
  131. if (intf->mode == MDP5_INTF_WB_MODE_LINE)
  132. ctl_op |= MDP5_CTL_OP_MODE(MODE_WB_2_LINE);
  133. break;
  134. default:
  135. break;
  136. }
  137. spin_lock_irqsave(&ctl->hw_lock, flags);
  138. ctl_write(ctl, REG_MDP5_CTL_OP(ctl->id), ctl_op);
  139. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  140. }
  141. int mdp5_ctl_set_pipeline(struct mdp5_ctl *ctl,
  142. struct mdp5_interface *intf, int lm)
  143. {
  144. struct mdp5_ctl_manager *ctl_mgr = ctl->ctlm;
  145. struct mdp5_kms *mdp5_kms = get_kms(ctl_mgr);
  146. if (unlikely(WARN_ON(intf->num != ctl->pipeline.intf.num))) {
  147. dev_err(mdp5_kms->dev->dev,
  148. "CTL %d is allocated by INTF %d, but used by INTF %d\n",
  149. ctl->id, ctl->pipeline.intf.num, intf->num);
  150. return -EINVAL;
  151. }
  152. ctl->lm = lm;
  153. memcpy(&ctl->pipeline.intf, intf, sizeof(*intf));
  154. ctl->pipeline.start_mask = mdp_ctl_flush_mask_lm(ctl->lm) |
  155. mdp_ctl_flush_mask_encoder(intf);
  156. /* Virtual interfaces need not set a display intf (e.g.: Writeback) */
  157. if (!mdp5_cfg_intf_is_virtual(intf->type))
  158. set_display_intf(mdp5_kms, intf);
  159. set_ctl_op(ctl, intf);
  160. return 0;
  161. }
  162. static bool start_signal_needed(struct mdp5_ctl *ctl)
  163. {
  164. struct op_mode *pipeline = &ctl->pipeline;
  165. if (!pipeline->encoder_enabled || pipeline->start_mask != 0)
  166. return false;
  167. switch (pipeline->intf.type) {
  168. case INTF_WB:
  169. return true;
  170. case INTF_DSI:
  171. return pipeline->intf.mode == MDP5_INTF_DSI_MODE_COMMAND;
  172. default:
  173. return false;
  174. }
  175. }
  176. /*
  177. * send_start_signal() - Overlay Processor Start Signal
  178. *
  179. * For a given control operation (display pipeline), a START signal needs to be
  180. * executed in order to kick off operation and activate all layers.
  181. * e.g.: DSI command mode, Writeback
  182. */
  183. static void send_start_signal(struct mdp5_ctl *ctl)
  184. {
  185. unsigned long flags;
  186. spin_lock_irqsave(&ctl->hw_lock, flags);
  187. ctl_write(ctl, REG_MDP5_CTL_START(ctl->id), 1);
  188. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  189. }
  190. static void refill_start_mask(struct mdp5_ctl *ctl)
  191. {
  192. struct op_mode *pipeline = &ctl->pipeline;
  193. struct mdp5_interface *intf = &ctl->pipeline.intf;
  194. pipeline->start_mask = mdp_ctl_flush_mask_lm(ctl->lm);
  195. /*
  196. * Writeback encoder needs to program & flush
  197. * address registers for each page flip..
  198. */
  199. if (intf->type == INTF_WB)
  200. pipeline->start_mask |= mdp_ctl_flush_mask_encoder(intf);
  201. }
  202. /**
  203. * mdp5_ctl_set_encoder_state() - set the encoder state
  204. *
  205. * @enable: true, when encoder is ready for data streaming; false, otherwise.
  206. *
  207. * Note:
  208. * This encoder state is needed to trigger START signal (data path kickoff).
  209. */
  210. int mdp5_ctl_set_encoder_state(struct mdp5_ctl *ctl, bool enabled)
  211. {
  212. if (WARN_ON(!ctl))
  213. return -EINVAL;
  214. ctl->pipeline.encoder_enabled = enabled;
  215. DBG("intf_%d: %s", ctl->pipeline.intf.num, enabled ? "on" : "off");
  216. if (start_signal_needed(ctl)) {
  217. send_start_signal(ctl);
  218. refill_start_mask(ctl);
  219. }
  220. return 0;
  221. }
  222. /*
  223. * Note:
  224. * CTL registers need to be flushed after calling this function
  225. * (call mdp5_ctl_commit() with mdp_ctl_flush_mask_ctl() mask)
  226. */
  227. int mdp5_ctl_set_cursor(struct mdp5_ctl *ctl, int cursor_id, bool enable)
  228. {
  229. struct mdp5_ctl_manager *ctl_mgr = ctl->ctlm;
  230. unsigned long flags;
  231. u32 blend_cfg;
  232. int lm = ctl->lm;
  233. if (unlikely(WARN_ON(lm < 0))) {
  234. dev_err(ctl_mgr->dev->dev, "CTL %d cannot find LM: %d",
  235. ctl->id, lm);
  236. return -EINVAL;
  237. }
  238. spin_lock_irqsave(&ctl->hw_lock, flags);
  239. blend_cfg = ctl_read(ctl, REG_MDP5_CTL_LAYER_REG(ctl->id, lm));
  240. if (enable)
  241. blend_cfg |= MDP5_CTL_LAYER_REG_CURSOR_OUT;
  242. else
  243. blend_cfg &= ~MDP5_CTL_LAYER_REG_CURSOR_OUT;
  244. ctl_write(ctl, REG_MDP5_CTL_LAYER_REG(ctl->id, lm), blend_cfg);
  245. ctl->cursor_on = enable;
  246. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  247. ctl->pending_ctl_trigger = mdp_ctl_flush_mask_cursor(cursor_id);
  248. return 0;
  249. }
  250. static u32 mdp_ctl_blend_mask(enum mdp5_pipe pipe,
  251. enum mdp_mixer_stage_id stage)
  252. {
  253. switch (pipe) {
  254. case SSPP_VIG0: return MDP5_CTL_LAYER_REG_VIG0(stage);
  255. case SSPP_VIG1: return MDP5_CTL_LAYER_REG_VIG1(stage);
  256. case SSPP_VIG2: return MDP5_CTL_LAYER_REG_VIG2(stage);
  257. case SSPP_RGB0: return MDP5_CTL_LAYER_REG_RGB0(stage);
  258. case SSPP_RGB1: return MDP5_CTL_LAYER_REG_RGB1(stage);
  259. case SSPP_RGB2: return MDP5_CTL_LAYER_REG_RGB2(stage);
  260. case SSPP_DMA0: return MDP5_CTL_LAYER_REG_DMA0(stage);
  261. case SSPP_DMA1: return MDP5_CTL_LAYER_REG_DMA1(stage);
  262. case SSPP_VIG3: return MDP5_CTL_LAYER_REG_VIG3(stage);
  263. case SSPP_RGB3: return MDP5_CTL_LAYER_REG_RGB3(stage);
  264. default: return 0;
  265. }
  266. }
  267. static u32 mdp_ctl_blend_ext_mask(enum mdp5_pipe pipe,
  268. enum mdp_mixer_stage_id stage)
  269. {
  270. if (stage < STAGE6)
  271. return 0;
  272. switch (pipe) {
  273. case SSPP_VIG0: return MDP5_CTL_LAYER_EXT_REG_VIG0_BIT3;
  274. case SSPP_VIG1: return MDP5_CTL_LAYER_EXT_REG_VIG1_BIT3;
  275. case SSPP_VIG2: return MDP5_CTL_LAYER_EXT_REG_VIG2_BIT3;
  276. case SSPP_RGB0: return MDP5_CTL_LAYER_EXT_REG_RGB0_BIT3;
  277. case SSPP_RGB1: return MDP5_CTL_LAYER_EXT_REG_RGB1_BIT3;
  278. case SSPP_RGB2: return MDP5_CTL_LAYER_EXT_REG_RGB2_BIT3;
  279. case SSPP_DMA0: return MDP5_CTL_LAYER_EXT_REG_DMA0_BIT3;
  280. case SSPP_DMA1: return MDP5_CTL_LAYER_EXT_REG_DMA1_BIT3;
  281. case SSPP_VIG3: return MDP5_CTL_LAYER_EXT_REG_VIG3_BIT3;
  282. case SSPP_RGB3: return MDP5_CTL_LAYER_EXT_REG_RGB3_BIT3;
  283. default: return 0;
  284. }
  285. }
  286. int mdp5_ctl_blend(struct mdp5_ctl *ctl, u8 *stage, u32 stage_cnt,
  287. u32 ctl_blend_op_flags)
  288. {
  289. unsigned long flags;
  290. u32 blend_cfg = 0, blend_ext_cfg = 0;
  291. int i, start_stage;
  292. if (ctl_blend_op_flags & MDP5_CTL_BLEND_OP_FLAG_BORDER_OUT) {
  293. start_stage = STAGE0;
  294. blend_cfg |= MDP5_CTL_LAYER_REG_BORDER_COLOR;
  295. } else {
  296. start_stage = STAGE_BASE;
  297. }
  298. for (i = start_stage; i < start_stage + stage_cnt; i++) {
  299. blend_cfg |= mdp_ctl_blend_mask(stage[i], i);
  300. blend_ext_cfg |= mdp_ctl_blend_ext_mask(stage[i], i);
  301. }
  302. spin_lock_irqsave(&ctl->hw_lock, flags);
  303. if (ctl->cursor_on)
  304. blend_cfg |= MDP5_CTL_LAYER_REG_CURSOR_OUT;
  305. ctl_write(ctl, REG_MDP5_CTL_LAYER_REG(ctl->id, ctl->lm), blend_cfg);
  306. ctl_write(ctl, REG_MDP5_CTL_LAYER_EXT_REG(ctl->id, ctl->lm), blend_ext_cfg);
  307. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  308. ctl->pending_ctl_trigger = mdp_ctl_flush_mask_lm(ctl->lm);
  309. DBG("lm%d: blend config = 0x%08x. ext_cfg = 0x%08x", ctl->lm,
  310. blend_cfg, blend_ext_cfg);
  311. return 0;
  312. }
  313. u32 mdp_ctl_flush_mask_encoder(struct mdp5_interface *intf)
  314. {
  315. if (intf->type == INTF_WB)
  316. return MDP5_CTL_FLUSH_WB;
  317. switch (intf->num) {
  318. case 0: return MDP5_CTL_FLUSH_TIMING_0;
  319. case 1: return MDP5_CTL_FLUSH_TIMING_1;
  320. case 2: return MDP5_CTL_FLUSH_TIMING_2;
  321. case 3: return MDP5_CTL_FLUSH_TIMING_3;
  322. default: return 0;
  323. }
  324. }
  325. u32 mdp_ctl_flush_mask_cursor(int cursor_id)
  326. {
  327. switch (cursor_id) {
  328. case 0: return MDP5_CTL_FLUSH_CURSOR_0;
  329. case 1: return MDP5_CTL_FLUSH_CURSOR_1;
  330. default: return 0;
  331. }
  332. }
  333. u32 mdp_ctl_flush_mask_pipe(enum mdp5_pipe pipe)
  334. {
  335. switch (pipe) {
  336. case SSPP_VIG0: return MDP5_CTL_FLUSH_VIG0;
  337. case SSPP_VIG1: return MDP5_CTL_FLUSH_VIG1;
  338. case SSPP_VIG2: return MDP5_CTL_FLUSH_VIG2;
  339. case SSPP_RGB0: return MDP5_CTL_FLUSH_RGB0;
  340. case SSPP_RGB1: return MDP5_CTL_FLUSH_RGB1;
  341. case SSPP_RGB2: return MDP5_CTL_FLUSH_RGB2;
  342. case SSPP_DMA0: return MDP5_CTL_FLUSH_DMA0;
  343. case SSPP_DMA1: return MDP5_CTL_FLUSH_DMA1;
  344. case SSPP_VIG3: return MDP5_CTL_FLUSH_VIG3;
  345. case SSPP_RGB3: return MDP5_CTL_FLUSH_RGB3;
  346. default: return 0;
  347. }
  348. }
  349. u32 mdp_ctl_flush_mask_lm(int lm)
  350. {
  351. switch (lm) {
  352. case 0: return MDP5_CTL_FLUSH_LM0;
  353. case 1: return MDP5_CTL_FLUSH_LM1;
  354. case 2: return MDP5_CTL_FLUSH_LM2;
  355. case 5: return MDP5_CTL_FLUSH_LM5;
  356. default: return 0;
  357. }
  358. }
  359. static u32 fix_sw_flush(struct mdp5_ctl *ctl, u32 flush_mask)
  360. {
  361. struct mdp5_ctl_manager *ctl_mgr = ctl->ctlm;
  362. u32 sw_mask = 0;
  363. #define BIT_NEEDS_SW_FIX(bit) \
  364. (!(ctl_mgr->flush_hw_mask & bit) && (flush_mask & bit))
  365. /* for some targets, cursor bit is the same as LM bit */
  366. if (BIT_NEEDS_SW_FIX(MDP5_CTL_FLUSH_CURSOR_0))
  367. sw_mask |= mdp_ctl_flush_mask_lm(ctl->lm);
  368. return sw_mask;
  369. }
  370. static void fix_for_single_flush(struct mdp5_ctl *ctl, u32 *flush_mask,
  371. u32 *flush_id)
  372. {
  373. struct mdp5_ctl_manager *ctl_mgr = ctl->ctlm;
  374. if (ctl->pair) {
  375. DBG("CTL %d FLUSH pending mask %x", ctl->id, *flush_mask);
  376. ctl->flush_pending = true;
  377. ctl_mgr->single_flush_pending_mask |= (*flush_mask);
  378. *flush_mask = 0;
  379. if (ctl->pair->flush_pending) {
  380. *flush_id = min_t(u32, ctl->id, ctl->pair->id);
  381. *flush_mask = ctl_mgr->single_flush_pending_mask;
  382. ctl->flush_pending = false;
  383. ctl->pair->flush_pending = false;
  384. ctl_mgr->single_flush_pending_mask = 0;
  385. DBG("Single FLUSH mask %x,ID %d", *flush_mask,
  386. *flush_id);
  387. }
  388. }
  389. }
  390. /**
  391. * mdp5_ctl_commit() - Register Flush
  392. *
  393. * The flush register is used to indicate several registers are all
  394. * programmed, and are safe to update to the back copy of the double
  395. * buffered registers.
  396. *
  397. * Some registers FLUSH bits are shared when the hardware does not have
  398. * dedicated bits for them; handling these is the job of fix_sw_flush().
  399. *
  400. * CTL registers need to be flushed in some circumstances; if that is the
  401. * case, some trigger bits will be present in both flush mask and
  402. * ctl->pending_ctl_trigger.
  403. *
  404. * Return H/W flushed bit mask.
  405. */
  406. u32 mdp5_ctl_commit(struct mdp5_ctl *ctl, u32 flush_mask)
  407. {
  408. struct mdp5_ctl_manager *ctl_mgr = ctl->ctlm;
  409. struct op_mode *pipeline = &ctl->pipeline;
  410. unsigned long flags;
  411. u32 flush_id = ctl->id;
  412. u32 curr_ctl_flush_mask;
  413. pipeline->start_mask &= ~flush_mask;
  414. VERB("flush_mask=%x, start_mask=%x, trigger=%x", flush_mask,
  415. pipeline->start_mask, ctl->pending_ctl_trigger);
  416. if (ctl->pending_ctl_trigger & flush_mask) {
  417. flush_mask |= MDP5_CTL_FLUSH_CTL;
  418. ctl->pending_ctl_trigger = 0;
  419. }
  420. flush_mask |= fix_sw_flush(ctl, flush_mask);
  421. flush_mask &= ctl_mgr->flush_hw_mask;
  422. curr_ctl_flush_mask = flush_mask;
  423. fix_for_single_flush(ctl, &flush_mask, &flush_id);
  424. if (flush_mask) {
  425. spin_lock_irqsave(&ctl->hw_lock, flags);
  426. ctl_write(ctl, REG_MDP5_CTL_FLUSH(flush_id), flush_mask);
  427. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  428. }
  429. if (start_signal_needed(ctl)) {
  430. send_start_signal(ctl);
  431. refill_start_mask(ctl);
  432. }
  433. return curr_ctl_flush_mask;
  434. }
  435. u32 mdp5_ctl_get_commit_status(struct mdp5_ctl *ctl)
  436. {
  437. return ctl_read(ctl, REG_MDP5_CTL_FLUSH(ctl->id));
  438. }
  439. int mdp5_ctl_get_ctl_id(struct mdp5_ctl *ctl)
  440. {
  441. return WARN_ON(!ctl) ? -EINVAL : ctl->id;
  442. }
  443. /*
  444. * mdp5_ctl_pair() - Associate 2 booked CTLs for single FLUSH
  445. */
  446. int mdp5_ctl_pair(struct mdp5_ctl *ctlx, struct mdp5_ctl *ctly, bool enable)
  447. {
  448. struct mdp5_ctl_manager *ctl_mgr = ctlx->ctlm;
  449. struct mdp5_kms *mdp5_kms = get_kms(ctl_mgr);
  450. /* do nothing silently if hw doesn't support */
  451. if (!ctl_mgr->single_flush_supported)
  452. return 0;
  453. if (!enable) {
  454. ctlx->pair = NULL;
  455. ctly->pair = NULL;
  456. mdp5_write(mdp5_kms, REG_MDP5_MDP_SPARE_0(0), 0);
  457. return 0;
  458. } else if ((ctlx->pair != NULL) || (ctly->pair != NULL)) {
  459. dev_err(ctl_mgr->dev->dev, "CTLs already paired\n");
  460. return -EINVAL;
  461. } else if (!(ctlx->status & ctly->status & CTL_STAT_BOOKED)) {
  462. dev_err(ctl_mgr->dev->dev, "Only pair booked CTLs\n");
  463. return -EINVAL;
  464. }
  465. ctlx->pair = ctly;
  466. ctly->pair = ctlx;
  467. mdp5_write(mdp5_kms, REG_MDP5_MDP_SPARE_0(0),
  468. MDP5_MDP_SPARE_0_SPLIT_DPL_SINGLE_FLUSH_EN);
  469. return 0;
  470. }
  471. /*
  472. * mdp5_ctl_request() - CTL allocation
  473. *
  474. * Try to return booked CTL for @intf_num is 1 or 2, unbooked for other INTFs.
  475. * If no CTL is available in preferred category, allocate from the other one.
  476. *
  477. * @return fail if no CTL is available.
  478. */
  479. struct mdp5_ctl *mdp5_ctlm_request(struct mdp5_ctl_manager *ctl_mgr,
  480. int intf_num)
  481. {
  482. struct mdp5_ctl *ctl = NULL;
  483. const u32 checkm = CTL_STAT_BUSY | CTL_STAT_BOOKED;
  484. u32 match = ((intf_num == 1) || (intf_num == 2)) ? CTL_STAT_BOOKED : 0;
  485. unsigned long flags;
  486. int c;
  487. spin_lock_irqsave(&ctl_mgr->pool_lock, flags);
  488. /* search the preferred */
  489. for (c = 0; c < ctl_mgr->nctl; c++)
  490. if ((ctl_mgr->ctls[c].status & checkm) == match)
  491. goto found;
  492. dev_warn(ctl_mgr->dev->dev,
  493. "fall back to the other CTL category for INTF %d!\n", intf_num);
  494. match ^= CTL_STAT_BOOKED;
  495. for (c = 0; c < ctl_mgr->nctl; c++)
  496. if ((ctl_mgr->ctls[c].status & checkm) == match)
  497. goto found;
  498. dev_err(ctl_mgr->dev->dev, "No more CTL available!");
  499. goto unlock;
  500. found:
  501. ctl = &ctl_mgr->ctls[c];
  502. ctl->pipeline.intf.num = intf_num;
  503. ctl->lm = -1;
  504. ctl->status |= CTL_STAT_BUSY;
  505. ctl->pending_ctl_trigger = 0;
  506. DBG("CTL %d allocated", ctl->id);
  507. unlock:
  508. spin_unlock_irqrestore(&ctl_mgr->pool_lock, flags);
  509. return ctl;
  510. }
  511. void mdp5_ctlm_hw_reset(struct mdp5_ctl_manager *ctl_mgr)
  512. {
  513. unsigned long flags;
  514. int c;
  515. for (c = 0; c < ctl_mgr->nctl; c++) {
  516. struct mdp5_ctl *ctl = &ctl_mgr->ctls[c];
  517. spin_lock_irqsave(&ctl->hw_lock, flags);
  518. ctl_write(ctl, REG_MDP5_CTL_OP(ctl->id), 0);
  519. spin_unlock_irqrestore(&ctl->hw_lock, flags);
  520. }
  521. }
  522. void mdp5_ctlm_destroy(struct mdp5_ctl_manager *ctl_mgr)
  523. {
  524. kfree(ctl_mgr);
  525. }
  526. struct mdp5_ctl_manager *mdp5_ctlm_init(struct drm_device *dev,
  527. void __iomem *mmio_base, struct mdp5_cfg_handler *cfg_hnd)
  528. {
  529. struct mdp5_ctl_manager *ctl_mgr;
  530. const struct mdp5_cfg_hw *hw_cfg = mdp5_cfg_get_hw_config(cfg_hnd);
  531. int rev = mdp5_cfg_get_hw_rev(cfg_hnd);
  532. const struct mdp5_ctl_block *ctl_cfg = &hw_cfg->ctl;
  533. unsigned long flags;
  534. int c, ret;
  535. ctl_mgr = kzalloc(sizeof(*ctl_mgr), GFP_KERNEL);
  536. if (!ctl_mgr) {
  537. dev_err(dev->dev, "failed to allocate CTL manager\n");
  538. ret = -ENOMEM;
  539. goto fail;
  540. }
  541. if (unlikely(WARN_ON(ctl_cfg->count > MAX_CTL))) {
  542. dev_err(dev->dev, "Increase static pool size to at least %d\n",
  543. ctl_cfg->count);
  544. ret = -ENOSPC;
  545. goto fail;
  546. }
  547. /* initialize the CTL manager: */
  548. ctl_mgr->dev = dev;
  549. ctl_mgr->nlm = hw_cfg->lm.count;
  550. ctl_mgr->nctl = ctl_cfg->count;
  551. ctl_mgr->flush_hw_mask = ctl_cfg->flush_hw_mask;
  552. spin_lock_init(&ctl_mgr->pool_lock);
  553. /* initialize each CTL of the pool: */
  554. spin_lock_irqsave(&ctl_mgr->pool_lock, flags);
  555. for (c = 0; c < ctl_mgr->nctl; c++) {
  556. struct mdp5_ctl *ctl = &ctl_mgr->ctls[c];
  557. if (WARN_ON(!ctl_cfg->base[c])) {
  558. dev_err(dev->dev, "CTL_%d: base is null!\n", c);
  559. ret = -EINVAL;
  560. spin_unlock_irqrestore(&ctl_mgr->pool_lock, flags);
  561. goto fail;
  562. }
  563. ctl->ctlm = ctl_mgr;
  564. ctl->id = c;
  565. ctl->reg_offset = ctl_cfg->base[c];
  566. ctl->status = 0;
  567. spin_lock_init(&ctl->hw_lock);
  568. }
  569. /*
  570. * In Dual DSI case, CTL0 and CTL1 are always assigned to two DSI
  571. * interfaces to support single FLUSH feature (Flush CTL0 and CTL1 when
  572. * only write into CTL0's FLUSH register) to keep two DSI pipes in sync.
  573. * Single FLUSH is supported from hw rev v3.0.
  574. */
  575. if (rev >= 3) {
  576. ctl_mgr->single_flush_supported = true;
  577. /* Reserve CTL0/1 for INTF1/2 */
  578. ctl_mgr->ctls[0].status |= CTL_STAT_BOOKED;
  579. ctl_mgr->ctls[1].status |= CTL_STAT_BOOKED;
  580. }
  581. spin_unlock_irqrestore(&ctl_mgr->pool_lock, flags);
  582. DBG("Pool of %d CTLs created.", ctl_mgr->nctl);
  583. return ctl_mgr;
  584. fail:
  585. if (ctl_mgr)
  586. mdp5_ctlm_destroy(ctl_mgr);
  587. return ERR_PTR(ret);
  588. }