2 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
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.
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.
15 #define pr_fmt(fmt) "[drm:%s] " fmt, __func__
17 #include "dpu_hw_lm.h"
18 #include "dpu_hw_ctl.h"
19 #include "dpu_hw_cdm.h"
20 #include "dpu_hw_pingpong.h"
21 #include "dpu_hw_intf.h"
22 #include "dpu_encoder.h"
23 #include "dpu_trace.h"
25 #define RESERVED_BY_OTHER(h, r) \
26 ((h)->rsvp && ((h)->rsvp->enc_id != (r)->enc_id))
28 #define RM_RQ_LOCK(r) ((r)->top_ctrl & BIT(DPU_RM_TOPCTL_RESERVE_LOCK))
29 #define RM_RQ_CLEAR(r) ((r)->top_ctrl & BIT(DPU_RM_TOPCTL_RESERVE_CLEAR))
30 #define RM_RQ_DS(r) ((r)->top_ctrl & BIT(DPU_RM_TOPCTL_DS))
31 #define RM_IS_TOPOLOGY_MATCH(t, r) ((t).num_lm == (r).num_lm && \
32 (t).num_comp_enc == (r).num_enc && \
33 (t).num_intf == (r).num_intf)
35 struct dpu_rm_topology_def {
36 enum dpu_rm_topology_name top_name;
41 int needs_split_display;
44 static const struct dpu_rm_topology_def g_top_table[] = {
45 { DPU_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false },
46 { DPU_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false },
47 { DPU_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 2, true },
48 { DPU_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false },
52 * struct dpu_rm_requirements - Reservation requirements parameter bundle
53 * @top_ctrl: topology control preference from kernel client
54 * @top: selected topology for the display
55 * @hw_res: Hardware resources required as reported by the encoders
57 struct dpu_rm_requirements {
59 const struct dpu_rm_topology_def *topology;
60 struct dpu_encoder_hw_resources hw_res;
64 * struct dpu_rm_rsvp - Use Case Reservation tagging structure
65 * Used to tag HW blocks as reserved by a CRTC->Encoder->Connector chain
66 * By using as a tag, rather than lists of pointers to HW blocks used
67 * we can avoid some list management since we don't know how many blocks
68 * of each type a given use case may require.
69 * @list: List head for list of all reservations
70 * @seq: Global RSVP sequence number for debugging, especially for
71 * differentiating differenct allocations for same encoder.
72 * @enc_id: Reservations are tracked by Encoder DRM object ID.
73 * CRTCs may be connected to multiple Encoders.
74 * An encoder or connector id identifies the display path.
75 * @topology DRM<->HW topology use case
78 struct list_head list;
81 enum dpu_rm_topology_name topology;
85 * struct dpu_rm_hw_blk - hardware block tracking list member
86 * @list: List head for list of all hardware blocks tracking items
87 * @rsvp: Pointer to use case reservation if reserved by a client
88 * @rsvp_nxt: Temporary pointer used during reservation to the incoming
89 * request. Will be swapped into rsvp if proposal is accepted
90 * @type: Type of hardware block this structure tracks
91 * @id: Hardware ID number, within it's own space, ie. LM_X
92 * @catalog: Pointer to the hardware catalog entry for this block
93 * @hw: Pointer to the hardware register access object for this block
95 struct dpu_rm_hw_blk {
96 struct list_head list;
97 struct dpu_rm_rsvp *rsvp;
98 struct dpu_rm_rsvp *rsvp_nxt;
99 enum dpu_hw_blk_type type;
101 struct dpu_hw_blk *hw;
105 * dpu_rm_dbg_rsvp_stage - enum of steps in making reservation for event logging
107 enum dpu_rm_dbg_rsvp_stage {
109 DPU_RM_STAGE_AFTER_CLEAR,
110 DPU_RM_STAGE_AFTER_RSVPNEXT,
114 static void _dpu_rm_print_rsvps(
116 enum dpu_rm_dbg_rsvp_stage stage)
118 struct dpu_rm_rsvp *rsvp;
119 struct dpu_rm_hw_blk *blk;
120 enum dpu_hw_blk_type type;
122 DPU_DEBUG("%d\n", stage);
124 list_for_each_entry(rsvp, &rm->rsvps, list) {
125 DRM_DEBUG_KMS("%d rsvp[s%ue%u] topology %d\n", stage, rsvp->seq,
126 rsvp->enc_id, rsvp->topology);
129 for (type = 0; type < DPU_HW_BLK_MAX; type++) {
130 list_for_each_entry(blk, &rm->hw_blks[type], list) {
131 if (!blk->rsvp && !blk->rsvp_nxt)
134 DRM_DEBUG_KMS("%d rsvp[s%ue%u->s%ue%u] %d %d\n", stage,
135 (blk->rsvp) ? blk->rsvp->seq : 0,
136 (blk->rsvp) ? blk->rsvp->enc_id : 0,
137 (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
138 (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
144 struct dpu_hw_mdp *dpu_rm_get_mdp(struct dpu_rm *rm)
149 enum dpu_rm_topology_name
150 dpu_rm_get_topology_name(struct msm_display_topology topology)
154 for (i = 0; i < DPU_RM_TOPOLOGY_MAX; i++)
155 if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], topology))
156 return g_top_table[i].top_name;
158 return DPU_RM_TOPOLOGY_NONE;
161 void dpu_rm_init_hw_iter(
162 struct dpu_rm_hw_iter *iter,
164 enum dpu_hw_blk_type type)
166 memset(iter, 0, sizeof(*iter));
167 iter->enc_id = enc_id;
171 static bool _dpu_rm_get_hw_locked(struct dpu_rm *rm, struct dpu_rm_hw_iter *i)
173 struct list_head *blk_list;
175 if (!rm || !i || i->type >= DPU_HW_BLK_MAX) {
176 DPU_ERROR("invalid rm\n");
181 blk_list = &rm->hw_blks[i->type];
183 if (i->blk && (&i->blk->list == blk_list)) {
184 DPU_DEBUG("attempt resume iteration past last\n");
188 i->blk = list_prepare_entry(i->blk, blk_list, list);
190 list_for_each_entry_continue(i->blk, blk_list, list) {
191 struct dpu_rm_rsvp *rsvp = i->blk->rsvp;
193 if (i->blk->type != i->type) {
194 DPU_ERROR("found incorrect block type %d on %d list\n",
195 i->blk->type, i->type);
199 if ((i->enc_id == 0) || (rsvp && rsvp->enc_id == i->enc_id)) {
201 DPU_DEBUG("found type %d id %d for enc %d\n",
202 i->type, i->blk->id, i->enc_id);
207 DPU_DEBUG("no match, type %d for enc %d\n", i->type, i->enc_id);
212 bool dpu_rm_get_hw(struct dpu_rm *rm, struct dpu_rm_hw_iter *i)
216 mutex_lock(&rm->rm_lock);
217 ret = _dpu_rm_get_hw_locked(rm, i);
218 mutex_unlock(&rm->rm_lock);
223 static void _dpu_rm_hw_destroy(enum dpu_hw_blk_type type, void *hw)
227 dpu_hw_lm_destroy(hw);
230 dpu_hw_ctl_destroy(hw);
233 dpu_hw_cdm_destroy(hw);
235 case DPU_HW_BLK_PINGPONG:
236 dpu_hw_pingpong_destroy(hw);
238 case DPU_HW_BLK_INTF:
239 dpu_hw_intf_destroy(hw);
241 case DPU_HW_BLK_SSPP:
242 /* SSPPs are not managed by the resource manager */
244 /* Top is a singleton, not managed in hw_blks list */
247 DPU_ERROR("unsupported block type %d\n", type);
252 int dpu_rm_destroy(struct dpu_rm *rm)
255 struct dpu_rm_rsvp *rsvp_cur, *rsvp_nxt;
256 struct dpu_rm_hw_blk *hw_cur, *hw_nxt;
257 enum dpu_hw_blk_type type;
260 DPU_ERROR("invalid rm\n");
264 list_for_each_entry_safe(rsvp_cur, rsvp_nxt, &rm->rsvps, list) {
265 list_del(&rsvp_cur->list);
270 for (type = 0; type < DPU_HW_BLK_MAX; type++) {
271 list_for_each_entry_safe(hw_cur, hw_nxt, &rm->hw_blks[type],
273 list_del(&hw_cur->list);
274 _dpu_rm_hw_destroy(hw_cur->type, hw_cur->hw);
279 dpu_hw_mdp_destroy(rm->hw_mdp);
282 mutex_destroy(&rm->rm_lock);
287 static int _dpu_rm_hw_blk_create(
289 struct dpu_mdss_cfg *cat,
291 enum dpu_hw_blk_type type,
293 void *hw_catalog_info)
295 struct dpu_rm_hw_blk *blk;
296 struct dpu_hw_mdp *hw_mdp;
303 hw = dpu_hw_lm_init(id, mmio, cat);
306 hw = dpu_hw_ctl_init(id, mmio, cat);
309 hw = dpu_hw_cdm_init(id, mmio, cat, hw_mdp);
311 case DPU_HW_BLK_PINGPONG:
312 hw = dpu_hw_pingpong_init(id, mmio, cat);
314 case DPU_HW_BLK_INTF:
315 hw = dpu_hw_intf_init(id, mmio, cat);
317 case DPU_HW_BLK_SSPP:
318 /* SSPPs are not managed by the resource manager */
320 /* Top is a singleton, not managed in hw_blks list */
323 DPU_ERROR("unsupported block type %d\n", type);
327 if (IS_ERR_OR_NULL(hw)) {
328 DPU_ERROR("failed hw object creation: type %d, err %ld\n",
333 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
335 _dpu_rm_hw_destroy(type, hw);
342 list_add_tail(&blk->list, &rm->hw_blks[type]);
347 int dpu_rm_init(struct dpu_rm *rm,
348 struct dpu_mdss_cfg *cat,
350 struct drm_device *dev)
353 enum dpu_hw_blk_type type;
355 if (!rm || !cat || !mmio || !dev) {
356 DPU_ERROR("invalid kms\n");
360 /* Clear, setup lists */
361 memset(rm, 0, sizeof(*rm));
363 mutex_init(&rm->rm_lock);
365 INIT_LIST_HEAD(&rm->rsvps);
366 for (type = 0; type < DPU_HW_BLK_MAX; type++)
367 INIT_LIST_HEAD(&rm->hw_blks[type]);
371 /* Some of the sub-blocks require an mdptop to be created */
372 rm->hw_mdp = dpu_hw_mdptop_init(MDP_TOP, mmio, cat);
373 if (IS_ERR_OR_NULL(rm->hw_mdp)) {
374 rc = PTR_ERR(rm->hw_mdp);
376 DPU_ERROR("failed: mdp hw not available\n");
380 /* Interrogate HW catalog and create tracking items for hw blocks */
381 for (i = 0; i < cat->mixer_count; i++) {
382 struct dpu_lm_cfg *lm = &cat->mixer[i];
384 if (lm->pingpong == PINGPONG_MAX) {
385 DPU_DEBUG("skip mixer %d without pingpong\n", lm->id);
389 rc = _dpu_rm_hw_blk_create(rm, cat, mmio, DPU_HW_BLK_LM,
390 cat->mixer[i].id, &cat->mixer[i]);
392 DPU_ERROR("failed: lm hw not available\n");
396 if (!rm->lm_max_width) {
397 rm->lm_max_width = lm->sblk->maxwidth;
398 } else if (rm->lm_max_width != lm->sblk->maxwidth) {
400 * Don't expect to have hw where lm max widths differ.
401 * If found, take the min.
403 DPU_ERROR("unsupported: lm maxwidth differs\n");
404 if (rm->lm_max_width > lm->sblk->maxwidth)
405 rm->lm_max_width = lm->sblk->maxwidth;
409 for (i = 0; i < cat->pingpong_count; i++) {
410 rc = _dpu_rm_hw_blk_create(rm, cat, mmio, DPU_HW_BLK_PINGPONG,
411 cat->pingpong[i].id, &cat->pingpong[i]);
413 DPU_ERROR("failed: pp hw not available\n");
418 for (i = 0; i < cat->intf_count; i++) {
419 if (cat->intf[i].type == INTF_NONE) {
420 DPU_DEBUG("skip intf %d with type none\n", i);
424 rc = _dpu_rm_hw_blk_create(rm, cat, mmio, DPU_HW_BLK_INTF,
425 cat->intf[i].id, &cat->intf[i]);
427 DPU_ERROR("failed: intf hw not available\n");
432 for (i = 0; i < cat->ctl_count; i++) {
433 rc = _dpu_rm_hw_blk_create(rm, cat, mmio, DPU_HW_BLK_CTL,
434 cat->ctl[i].id, &cat->ctl[i]);
436 DPU_ERROR("failed: ctl hw not available\n");
441 for (i = 0; i < cat->cdm_count; i++) {
442 rc = _dpu_rm_hw_blk_create(rm, cat, mmio, DPU_HW_BLK_CDM,
443 cat->cdm[i].id, &cat->cdm[i]);
445 DPU_ERROR("failed: cdm hw not available\n");
459 * _dpu_rm_check_lm_and_get_connected_blks - check if proposed layer mixer meets
460 * proposed use case requirements, incl. hardwired dependent blocks like
462 * @rm: dpu resource manager handle
463 * @rsvp: reservation currently being created
464 * @reqs: proposed use case requirements
465 * @lm: proposed layer mixer, function checks if lm, and all other hardwired
466 * blocks connected to the lm (pp) is available and appropriate
467 * @pp: output parameter, pingpong block attached to the layer mixer.
468 * NULL if pp was not available, or not matching requirements.
469 * @primary_lm: if non-null, this function check if lm is compatible primary_lm
470 * as well as satisfying all other requirements
471 * @Return: true if lm matches all requirements, false otherwise
473 static bool _dpu_rm_check_lm_and_get_connected_blks(
475 struct dpu_rm_rsvp *rsvp,
476 struct dpu_rm_requirements *reqs,
477 struct dpu_rm_hw_blk *lm,
478 struct dpu_rm_hw_blk **pp,
479 struct dpu_rm_hw_blk *primary_lm)
481 const struct dpu_lm_cfg *lm_cfg = to_dpu_hw_mixer(lm->hw)->cap;
482 struct dpu_rm_hw_iter iter;
486 DPU_DEBUG("check lm %d pp %d\n",
487 lm_cfg->id, lm_cfg->pingpong);
489 /* Check if this layer mixer is a peer of the proposed primary LM */
491 const struct dpu_lm_cfg *prim_lm_cfg =
492 to_dpu_hw_mixer(primary_lm->hw)->cap;
494 if (!test_bit(lm_cfg->id, &prim_lm_cfg->lm_pair_mask)) {
495 DPU_DEBUG("lm %d not peer of lm %d\n", lm_cfg->id,
501 /* Already reserved? */
502 if (RESERVED_BY_OTHER(lm, rsvp)) {
503 DPU_DEBUG("lm %d already reserved\n", lm_cfg->id);
507 dpu_rm_init_hw_iter(&iter, 0, DPU_HW_BLK_PINGPONG);
508 while (_dpu_rm_get_hw_locked(rm, &iter)) {
509 if (iter.blk->id == lm_cfg->pingpong) {
516 DPU_ERROR("failed to get pp on lm %d\n", lm_cfg->pingpong);
520 if (RESERVED_BY_OTHER(*pp, rsvp)) {
521 DPU_DEBUG("lm %d pp %d already reserved\n", lm->id,
529 static int _dpu_rm_reserve_lms(
531 struct dpu_rm_rsvp *rsvp,
532 struct dpu_rm_requirements *reqs)
535 struct dpu_rm_hw_blk *lm[MAX_BLOCKS];
536 struct dpu_rm_hw_blk *pp[MAX_BLOCKS];
537 struct dpu_rm_hw_iter iter_i, iter_j;
541 if (!reqs->topology->num_lm) {
542 DPU_ERROR("invalid number of lm: %d\n", reqs->topology->num_lm);
546 /* Find a primary mixer */
547 dpu_rm_init_hw_iter(&iter_i, 0, DPU_HW_BLK_LM);
548 while (lm_count != reqs->topology->num_lm &&
549 _dpu_rm_get_hw_locked(rm, &iter_i)) {
550 memset(&lm, 0, sizeof(lm));
551 memset(&pp, 0, sizeof(pp));
554 lm[lm_count] = iter_i.blk;
556 if (!_dpu_rm_check_lm_and_get_connected_blks(
557 rm, rsvp, reqs, lm[lm_count],
558 &pp[lm_count], NULL))
563 /* Valid primary mixer found, find matching peers */
564 dpu_rm_init_hw_iter(&iter_j, 0, DPU_HW_BLK_LM);
566 while (lm_count != reqs->topology->num_lm &&
567 _dpu_rm_get_hw_locked(rm, &iter_j)) {
568 if (iter_i.blk == iter_j.blk)
571 if (!_dpu_rm_check_lm_and_get_connected_blks(
572 rm, rsvp, reqs, iter_j.blk,
573 &pp[lm_count], iter_i.blk))
576 lm[lm_count] = iter_j.blk;
581 if (lm_count != reqs->topology->num_lm) {
582 DPU_DEBUG("unable to find appropriate mixers\n");
586 for (i = 0; i < ARRAY_SIZE(lm); i++) {
590 lm[i]->rsvp_nxt = rsvp;
591 pp[i]->rsvp_nxt = rsvp;
593 trace_dpu_rm_reserve_lms(lm[i]->id, lm[i]->type, rsvp->enc_id,
600 static int _dpu_rm_reserve_ctls(
602 struct dpu_rm_rsvp *rsvp,
603 const struct dpu_rm_topology_def *top)
605 struct dpu_rm_hw_blk *ctls[MAX_BLOCKS];
606 struct dpu_rm_hw_iter iter;
609 memset(&ctls, 0, sizeof(ctls));
611 dpu_rm_init_hw_iter(&iter, 0, DPU_HW_BLK_CTL);
612 while (_dpu_rm_get_hw_locked(rm, &iter)) {
613 const struct dpu_hw_ctl *ctl = to_dpu_hw_ctl(iter.blk->hw);
614 unsigned long features = ctl->caps->features;
615 bool has_split_display;
617 if (RESERVED_BY_OTHER(iter.blk, rsvp))
620 has_split_display = BIT(DPU_CTL_SPLIT_DISPLAY) & features;
622 DPU_DEBUG("ctl %d caps 0x%lX\n", iter.blk->id, features);
624 if (top->needs_split_display != has_split_display)
628 DPU_DEBUG("ctl %d match\n", iter.blk->id);
630 if (++i == top->num_ctl)
634 if (i != top->num_ctl)
637 for (i = 0; i < ARRAY_SIZE(ctls) && i < top->num_ctl; i++) {
638 ctls[i]->rsvp_nxt = rsvp;
639 trace_dpu_rm_reserve_ctls(ctls[i]->id, ctls[i]->type,
646 static int _dpu_rm_reserve_cdm(
648 struct dpu_rm_rsvp *rsvp,
650 enum dpu_hw_blk_type type)
652 struct dpu_rm_hw_iter iter;
654 DRM_DEBUG_KMS("type %d id %d\n", type, id);
656 dpu_rm_init_hw_iter(&iter, 0, DPU_HW_BLK_CDM);
657 while (_dpu_rm_get_hw_locked(rm, &iter)) {
658 const struct dpu_hw_cdm *cdm = to_dpu_hw_cdm(iter.blk->hw);
659 const struct dpu_cdm_cfg *caps = cdm->caps;
662 if (RESERVED_BY_OTHER(iter.blk, rsvp))
665 if (type == DPU_HW_BLK_INTF && id != INTF_MAX)
666 match = test_bit(id, &caps->intf_connect);
668 DRM_DEBUG_KMS("iter: type:%d id:%d enc:%d cdm:%lu match:%d\n",
669 iter.blk->type, iter.blk->id, rsvp->enc_id,
670 caps->intf_connect, match);
675 trace_dpu_rm_reserve_cdm(iter.blk->id, iter.blk->type,
677 iter.blk->rsvp_nxt = rsvp;
682 DPU_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
689 static int _dpu_rm_reserve_intf(
691 struct dpu_rm_rsvp *rsvp,
693 enum dpu_hw_blk_type type,
696 struct dpu_rm_hw_iter iter;
699 /* Find the block entry in the rm, and note the reservation */
700 dpu_rm_init_hw_iter(&iter, 0, type);
701 while (_dpu_rm_get_hw_locked(rm, &iter)) {
702 if (iter.blk->id != id)
705 if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
706 DPU_ERROR("type %d id %d already reserved\n", type, id);
710 iter.blk->rsvp_nxt = rsvp;
711 trace_dpu_rm_reserve_intf(iter.blk->id, iter.blk->type,
716 /* Shouldn't happen since intfs are fixed at probe */
718 DPU_ERROR("couldn't find type %d id %d\n", type, id);
723 ret = _dpu_rm_reserve_cdm(rm, rsvp, id, type);
728 static int _dpu_rm_reserve_intf_related_hw(
730 struct dpu_rm_rsvp *rsvp,
731 struct dpu_encoder_hw_resources *hw_res)
736 for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
737 if (hw_res->intfs[i] == INTF_MODE_NONE)
740 ret = _dpu_rm_reserve_intf(rm, rsvp, id,
741 DPU_HW_BLK_INTF, hw_res->needs_cdm);
749 static int _dpu_rm_make_next_rsvp(
751 struct drm_encoder *enc,
752 struct drm_crtc_state *crtc_state,
753 struct drm_connector_state *conn_state,
754 struct dpu_rm_rsvp *rsvp,
755 struct dpu_rm_requirements *reqs)
758 struct dpu_rm_topology_def topology;
760 /* Create reservation info, tag reserved blocks with it as we go */
761 rsvp->seq = ++rm->rsvp_next_seq;
762 rsvp->enc_id = enc->base.id;
763 rsvp->topology = reqs->topology->top_name;
764 list_add_tail(&rsvp->list, &rm->rsvps);
766 ret = _dpu_rm_reserve_lms(rm, rsvp, reqs);
768 DPU_ERROR("unable to find appropriate mixers\n");
773 * Do assignment preferring to give away low-resource CTLs first:
774 * - Check mixers without Split Display
775 * - Only then allow to grab from CTLs with split display capability
777 _dpu_rm_reserve_ctls(rm, rsvp, reqs->topology);
778 if (ret && !reqs->topology->needs_split_display) {
779 memcpy(&topology, reqs->topology, sizeof(topology));
780 topology.needs_split_display = true;
781 _dpu_rm_reserve_ctls(rm, rsvp, &topology);
784 DPU_ERROR("unable to find appropriate CTL\n");
788 /* Assign INTFs and blks whose usage is tied to them: CTL & CDM */
789 ret = _dpu_rm_reserve_intf_related_hw(rm, rsvp, &reqs->hw_res);
796 static int _dpu_rm_populate_requirements(
798 struct drm_encoder *enc,
799 struct drm_crtc_state *crtc_state,
800 struct drm_connector_state *conn_state,
801 struct dpu_rm_requirements *reqs,
802 struct msm_display_topology req_topology)
806 memset(reqs, 0, sizeof(*reqs));
808 dpu_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
810 for (i = 0; i < DPU_RM_TOPOLOGY_MAX; i++) {
811 if (RM_IS_TOPOLOGY_MATCH(g_top_table[i],
813 reqs->topology = &g_top_table[i];
818 if (!reqs->topology) {
819 DPU_ERROR("invalid topology for the display\n");
824 * Set the requirement based on caps if not set from user space
825 * This will ensure to select LM tied with DS blocks
826 * Currently, DS blocks are tied with LM 0 and LM 1 (primary display)
828 if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
829 conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI)
830 reqs->top_ctrl |= BIT(DPU_RM_TOPCTL_DS);
832 DRM_DEBUG_KMS("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
833 reqs->hw_res.display_num_of_h_tiles);
834 DRM_DEBUG_KMS("num_lm: %d num_ctl: %d topology: %d split_display: %d\n",
835 reqs->topology->num_lm, reqs->topology->num_ctl,
836 reqs->topology->top_name,
837 reqs->topology->needs_split_display);
842 static struct dpu_rm_rsvp *_dpu_rm_get_rsvp(
844 struct drm_encoder *enc)
846 struct dpu_rm_rsvp *i;
849 DPU_ERROR("invalid params\n");
853 if (list_empty(&rm->rsvps))
856 list_for_each_entry(i, &rm->rsvps, list)
857 if (i->enc_id == enc->base.id)
863 static struct drm_connector *_dpu_rm_get_connector(
864 struct drm_encoder *enc)
866 struct drm_connector *conn = NULL;
867 struct list_head *connector_list =
868 &enc->dev->mode_config.connector_list;
870 list_for_each_entry(conn, connector_list, head)
871 if (conn->encoder == enc)
878 * _dpu_rm_release_rsvp - release resources and release a reservation
880 * @rsvp: RSVP pointer to release and release resources for
882 static void _dpu_rm_release_rsvp(
884 struct dpu_rm_rsvp *rsvp,
885 struct drm_connector *conn)
887 struct dpu_rm_rsvp *rsvp_c, *rsvp_n;
888 struct dpu_rm_hw_blk *blk;
889 enum dpu_hw_blk_type type;
894 DPU_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
896 list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
897 if (rsvp == rsvp_c) {
898 list_del(&rsvp_c->list);
903 for (type = 0; type < DPU_HW_BLK_MAX; type++) {
904 list_for_each_entry(blk, &rm->hw_blks[type], list) {
905 if (blk->rsvp == rsvp) {
907 DPU_DEBUG("rel rsvp %d enc %d %d %d\n",
908 rsvp->seq, rsvp->enc_id,
911 if (blk->rsvp_nxt == rsvp) {
912 blk->rsvp_nxt = NULL;
913 DPU_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
914 rsvp->seq, rsvp->enc_id,
923 void dpu_rm_release(struct dpu_rm *rm, struct drm_encoder *enc)
925 struct dpu_rm_rsvp *rsvp;
926 struct drm_connector *conn;
929 DPU_ERROR("invalid params\n");
933 mutex_lock(&rm->rm_lock);
935 rsvp = _dpu_rm_get_rsvp(rm, enc);
937 DPU_ERROR("failed to find rsvp for enc %d\n", enc->base.id);
941 conn = _dpu_rm_get_connector(enc);
943 DPU_ERROR("failed to get connector for enc %d\n", enc->base.id);
947 _dpu_rm_release_rsvp(rm, rsvp, conn);
949 mutex_unlock(&rm->rm_lock);
952 static int _dpu_rm_commit_rsvp(
954 struct dpu_rm_rsvp *rsvp,
955 struct drm_connector_state *conn_state)
957 struct dpu_rm_hw_blk *blk;
958 enum dpu_hw_blk_type type;
961 /* Swap next rsvp to be the active */
962 for (type = 0; type < DPU_HW_BLK_MAX; type++) {
963 list_for_each_entry(blk, &rm->hw_blks[type], list) {
965 blk->rsvp = blk->rsvp_nxt;
966 blk->rsvp_nxt = NULL;
972 DRM_DEBUG_KMS("rsrv enc %d topology %d\n", rsvp->enc_id,
980 struct drm_encoder *enc,
981 struct drm_crtc_state *crtc_state,
982 struct drm_connector_state *conn_state,
983 struct msm_display_topology topology,
986 struct dpu_rm_rsvp *rsvp_cur, *rsvp_nxt;
987 struct dpu_rm_requirements reqs;
990 if (!rm || !enc || !crtc_state || !conn_state) {
991 DPU_ERROR("invalid arguments\n");
995 /* Check if this is just a page-flip */
996 if (!drm_atomic_crtc_needs_modeset(crtc_state))
999 DRM_DEBUG_KMS("reserving hw for conn %d enc %d crtc %d test_only %d\n",
1000 conn_state->connector->base.id, enc->base.id,
1001 crtc_state->crtc->base.id, test_only);
1003 mutex_lock(&rm->rm_lock);
1005 _dpu_rm_print_rsvps(rm, DPU_RM_STAGE_BEGIN);
1007 ret = _dpu_rm_populate_requirements(rm, enc, crtc_state,
1008 conn_state, &reqs, topology);
1010 DPU_ERROR("failed to populate hw requirements\n");
1015 * We only support one active reservation per-hw-block. But to implement
1016 * transactional semantics for test-only, and for allowing failure while
1017 * modifying your existing reservation, over the course of this
1018 * function we can have two reservations:
1019 * Current: Existing reservation
1020 * Next: Proposed reservation. The proposed reservation may fail, or may
1021 * be discarded if in test-only mode.
1022 * If reservation is successful, and we're not in test-only, then we
1023 * replace the current with the next.
1025 rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
1031 rsvp_cur = _dpu_rm_get_rsvp(rm, enc);
1034 * User can request that we clear out any reservation during the
1035 * atomic_check phase by using this CLEAR bit
1037 if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
1038 DPU_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
1039 rsvp_cur->seq, rsvp_cur->enc_id);
1040 _dpu_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
1042 _dpu_rm_print_rsvps(rm, DPU_RM_STAGE_AFTER_CLEAR);
1045 /* Check the proposed reservation, store it in hw's "next" field */
1046 ret = _dpu_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
1049 _dpu_rm_print_rsvps(rm, DPU_RM_STAGE_AFTER_RSVPNEXT);
1052 DPU_ERROR("failed to reserve hw resources: %d\n", ret);
1053 _dpu_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
1054 } else if (test_only && !RM_RQ_LOCK(&reqs)) {
1056 * Normally, if test_only, test the reservation and then undo
1057 * However, if the user requests LOCK, then keep the reservation
1058 * made during the atomic_check phase.
1060 DPU_DEBUG("test_only: discard test rsvp[s%de%d]\n",
1061 rsvp_nxt->seq, rsvp_nxt->enc_id);
1062 _dpu_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
1064 if (test_only && RM_RQ_LOCK(&reqs))
1065 DPU_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
1066 rsvp_nxt->seq, rsvp_nxt->enc_id);
1068 _dpu_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
1070 ret = _dpu_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
1073 _dpu_rm_print_rsvps(rm, DPU_RM_STAGE_FINAL);
1076 mutex_unlock(&rm->rm_lock);