Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1 | /* |
Lloyd Atkinson | 8c3eca0 | 2016-12-20 17:04:33 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 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 | */ |
| 14 | |
| 15 | #define pr_fmt(fmt) "[drm:%s] " fmt, __func__ |
| 16 | #include "sde_kms.h" |
| 17 | #include "sde_hw_lm.h" |
| 18 | #include "sde_hw_ctl.h" |
| 19 | #include "sde_hw_cdm.h" |
| 20 | #include "sde_hw_dspp.h" |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 21 | #include "sde_hw_ds.h" |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 22 | #include "sde_hw_pingpong.h" |
| 23 | #include "sde_hw_intf.h" |
| 24 | #include "sde_hw_wb.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 25 | #include "sde_encoder.h" |
| 26 | #include "sde_connector.h" |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 27 | #include "sde_hw_dsc.h" |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 28 | #include "sde_hw_rot.h" |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 29 | |
| 30 | #define RESERVED_BY_OTHER(h, r) \ |
| 31 | ((h)->rsvp && ((h)->rsvp->enc_id != (r)->enc_id)) |
| 32 | |
| 33 | #define RM_RQ_LOCK(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) |
| 34 | #define RM_RQ_CLEAR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_CLEAR)) |
| 35 | #define RM_RQ_DSPP(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DSPP)) |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 36 | #define RM_RQ_DS(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DS)) |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 37 | #define RM_IS_TOPOLOGY_MATCH(t, r) ((t).num_lm == (r).num_lm && \ |
| 38 | (t).num_comp_enc == (r).num_enc && \ |
| 39 | (t).num_intf == (r).num_intf) |
| 40 | |
| 41 | struct sde_rm_topology_def { |
| 42 | enum sde_rm_topology_name top_name; |
| 43 | int num_lm; |
| 44 | int num_comp_enc; |
| 45 | int num_intf; |
| 46 | int num_ctl; |
| 47 | int needs_split_display; |
| 48 | }; |
| 49 | |
| 50 | static const struct sde_rm_topology_def g_top_table[] = { |
| 51 | { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false }, |
| 52 | { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false }, |
| 53 | { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false }, |
| 54 | { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 2, true }, |
| 55 | { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 2, true }, |
| 56 | { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false }, |
| 57 | { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false }, |
| 58 | { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false }, |
| 59 | { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, true }, |
| 60 | }; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * struct sde_rm_requirements - Reservation requirements parameter bundle |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 64 | * @top_ctrl: topology control preference from kernel client |
| 65 | * @top: selected topology for the display |
| 66 | * @hw_res: Hardware resources required as reported by the encoders |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 67 | */ |
| 68 | struct sde_rm_requirements { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 69 | uint64_t top_ctrl; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 70 | const struct sde_rm_topology_def *topology; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 71 | struct sde_encoder_hw_resources hw_res; |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * struct sde_rm_rsvp - Use Case Reservation tagging structure |
| 76 | * Used to tag HW blocks as reserved by a CRTC->Encoder->Connector chain |
| 77 | * By using as a tag, rather than lists of pointers to HW blocks used |
| 78 | * we can avoid some list management since we don't know how many blocks |
| 79 | * of each type a given use case may require. |
| 80 | * @list: List head for list of all reservations |
| 81 | * @seq: Global RSVP sequence number for debugging, especially for |
| 82 | * differentiating differenct allocations for same encoder. |
| 83 | * @enc_id: Reservations are tracked by Encoder DRM object ID. |
| 84 | * CRTCs may be connected to multiple Encoders. |
| 85 | * An encoder or connector id identifies the display path. |
| 86 | * @topology DRM<->HW topology use case |
| 87 | */ |
| 88 | struct sde_rm_rsvp { |
| 89 | struct list_head list; |
| 90 | uint32_t seq; |
| 91 | uint32_t enc_id; |
| 92 | enum sde_rm_topology_name topology; |
| 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * struct sde_rm_hw_blk - hardware block tracking list member |
| 97 | * @list: List head for list of all hardware blocks tracking items |
| 98 | * @rsvp: Pointer to use case reservation if reserved by a client |
| 99 | * @rsvp_nxt: Temporary pointer used during reservation to the incoming |
| 100 | * request. Will be swapped into rsvp if proposal is accepted |
| 101 | * @type: Type of hardware block this structure tracks |
| 102 | * @id: Hardware ID number, within it's own space, ie. LM_X |
| 103 | * @catalog: Pointer to the hardware catalog entry for this block |
| 104 | * @hw: Pointer to the hardware register access object for this block |
| 105 | */ |
| 106 | struct sde_rm_hw_blk { |
| 107 | struct list_head list; |
| 108 | struct sde_rm_rsvp *rsvp; |
| 109 | struct sde_rm_rsvp *rsvp_nxt; |
| 110 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 111 | uint32_t id; |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 112 | struct sde_hw_blk *hw; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 115 | /** |
| 116 | * sde_rm_dbg_rsvp_stage - enum of steps in making reservation for event logging |
| 117 | */ |
| 118 | enum sde_rm_dbg_rsvp_stage { |
| 119 | SDE_RM_STAGE_BEGIN, |
| 120 | SDE_RM_STAGE_AFTER_CLEAR, |
| 121 | SDE_RM_STAGE_AFTER_RSVPNEXT, |
| 122 | SDE_RM_STAGE_FINAL |
| 123 | }; |
| 124 | |
| 125 | static void _sde_rm_print_rsvps( |
| 126 | struct sde_rm *rm, |
| 127 | enum sde_rm_dbg_rsvp_stage stage) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 128 | { |
| 129 | struct sde_rm_rsvp *rsvp; |
| 130 | struct sde_rm_hw_blk *blk; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 131 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 132 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 133 | SDE_DEBUG("%d\n", stage); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 134 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 135 | list_for_each_entry(rsvp, &rm->rsvps, list) { |
| 136 | SDE_DEBUG("%d rsvp[s%ue%u] topology %d\n", stage, rsvp->seq, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 137 | rsvp->enc_id, rsvp->topology); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 138 | SDE_EVT32(stage, rsvp->seq, rsvp->enc_id, rsvp->topology); |
| 139 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 140 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 141 | for (type = 0; type < SDE_HW_BLK_MAX; type++) { |
| 142 | list_for_each_entry(blk, &rm->hw_blks[type], list) { |
| 143 | if (!blk->rsvp && !blk->rsvp_nxt) |
| 144 | continue; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 145 | |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 146 | SDE_DEBUG("%d rsvp[s%ue%u->s%ue%u] %d %d\n", stage, |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 147 | (blk->rsvp) ? blk->rsvp->seq : 0, |
| 148 | (blk->rsvp) ? blk->rsvp->enc_id : 0, |
| 149 | (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0, |
| 150 | (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0, |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 151 | blk->type, blk->id); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 152 | |
| 153 | SDE_EVT32(stage, |
| 154 | (blk->rsvp) ? blk->rsvp->seq : 0, |
| 155 | (blk->rsvp) ? blk->rsvp->enc_id : 0, |
| 156 | (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0, |
| 157 | (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0, |
| 158 | blk->type, blk->id); |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 159 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm) |
| 164 | { |
| 165 | return rm->hw_mdp; |
| 166 | } |
| 167 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 168 | void sde_rm_init_hw_iter( |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 169 | struct sde_rm_hw_iter *iter, |
| 170 | uint32_t enc_id, |
| 171 | enum sde_hw_blk_type type) |
| 172 | { |
| 173 | memset(iter, 0, sizeof(*iter)); |
| 174 | iter->enc_id = enc_id; |
| 175 | iter->type = type; |
| 176 | } |
| 177 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 178 | enum sde_rm_topology_name sde_rm_get_topology_name( |
| 179 | struct msm_display_topology topology) |
| 180 | { |
| 181 | int i; |
| 182 | |
| 183 | for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) |
| 184 | if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], topology)) |
| 185 | return g_top_table[i].top_name; |
| 186 | |
| 187 | return SDE_RM_TOPOLOGY_NONE; |
| 188 | } |
| 189 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 190 | static bool _sde_rm_get_hw_locked(struct sde_rm *rm, struct sde_rm_hw_iter *i) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 191 | { |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 192 | struct list_head *blk_list; |
| 193 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 194 | if (!rm || !i || i->type >= SDE_HW_BLK_MAX) { |
| 195 | SDE_ERROR("invalid rm\n"); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | i->hw = NULL; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 200 | blk_list = &rm->hw_blks[i->type]; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 201 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 202 | if (i->blk && (&i->blk->list == blk_list)) { |
Lloyd Atkinson | 75d898c | 2017-01-23 10:10:39 -0500 | [diff] [blame] | 203 | SDE_DEBUG("attempt resume iteration past last\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 207 | i->blk = list_prepare_entry(i->blk, blk_list, list); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 208 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 209 | list_for_each_entry_continue(i->blk, blk_list, list) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 210 | struct sde_rm_rsvp *rsvp = i->blk->rsvp; |
| 211 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 212 | if (i->blk->type != i->type) { |
| 213 | SDE_ERROR("found incorrect block type %d on %d list\n", |
| 214 | i->blk->type, i->type); |
| 215 | return false; |
| 216 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 217 | |
| 218 | if ((i->enc_id == 0) || (rsvp && rsvp->enc_id == i->enc_id)) { |
| 219 | i->hw = i->blk->hw; |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 220 | SDE_DEBUG("found type %d id %d for enc %d\n", |
| 221 | i->type, i->blk->id, i->enc_id); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | SDE_DEBUG("no match, type %d for enc %d\n", i->type, i->enc_id); |
| 227 | |
| 228 | return false; |
| 229 | } |
| 230 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 231 | bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *i) |
| 232 | { |
| 233 | bool ret; |
| 234 | |
| 235 | mutex_lock(&rm->rm_lock); |
| 236 | ret = _sde_rm_get_hw_locked(rm, i); |
| 237 | mutex_unlock(&rm->rm_lock); |
| 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 242 | static void _sde_rm_hw_destroy(enum sde_hw_blk_type type, void *hw) |
| 243 | { |
| 244 | switch (type) { |
| 245 | case SDE_HW_BLK_LM: |
| 246 | sde_hw_lm_destroy(hw); |
| 247 | break; |
| 248 | case SDE_HW_BLK_DSPP: |
| 249 | sde_hw_dspp_destroy(hw); |
| 250 | break; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 251 | case SDE_HW_BLK_DS: |
| 252 | sde_hw_ds_destroy(hw); |
| 253 | break; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 254 | case SDE_HW_BLK_CTL: |
| 255 | sde_hw_ctl_destroy(hw); |
| 256 | break; |
| 257 | case SDE_HW_BLK_CDM: |
| 258 | sde_hw_cdm_destroy(hw); |
| 259 | break; |
| 260 | case SDE_HW_BLK_PINGPONG: |
| 261 | sde_hw_pingpong_destroy(hw); |
| 262 | break; |
| 263 | case SDE_HW_BLK_INTF: |
| 264 | sde_hw_intf_destroy(hw); |
| 265 | break; |
| 266 | case SDE_HW_BLK_WB: |
| 267 | sde_hw_wb_destroy(hw); |
| 268 | break; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 269 | case SDE_HW_BLK_DSC: |
| 270 | sde_hw_dsc_destroy(hw); |
| 271 | break; |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 272 | case SDE_HW_BLK_ROT: |
| 273 | sde_hw_rot_destroy(hw); |
| 274 | break; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 275 | case SDE_HW_BLK_SSPP: |
| 276 | /* SSPPs are not managed by the resource manager */ |
| 277 | case SDE_HW_BLK_TOP: |
| 278 | /* Top is a singleton, not managed in hw_blks list */ |
| 279 | case SDE_HW_BLK_MAX: |
| 280 | default: |
| 281 | SDE_ERROR("unsupported block type %d\n", type); |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | int sde_rm_destroy(struct sde_rm *rm) |
| 287 | { |
| 288 | |
| 289 | struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt; |
| 290 | struct sde_rm_hw_blk *hw_cur, *hw_nxt; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 291 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 292 | |
| 293 | if (!rm) { |
| 294 | SDE_ERROR("invalid rm\n"); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | list_for_each_entry_safe(rsvp_cur, rsvp_nxt, &rm->rsvps, list) { |
| 299 | list_del(&rsvp_cur->list); |
| 300 | kfree(rsvp_cur); |
| 301 | } |
| 302 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 303 | |
| 304 | for (type = 0; type < SDE_HW_BLK_MAX; type++) { |
| 305 | list_for_each_entry_safe(hw_cur, hw_nxt, &rm->hw_blks[type], |
| 306 | list) { |
| 307 | list_del(&hw_cur->list); |
| 308 | _sde_rm_hw_destroy(hw_cur->type, hw_cur->hw); |
| 309 | kfree(hw_cur); |
| 310 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | sde_hw_mdp_destroy(rm->hw_mdp); |
| 314 | rm->hw_mdp = NULL; |
| 315 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 316 | mutex_destroy(&rm->rm_lock); |
| 317 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int _sde_rm_hw_blk_create( |
| 322 | struct sde_rm *rm, |
| 323 | struct sde_mdss_cfg *cat, |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 324 | void __iomem *mmio, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 325 | enum sde_hw_blk_type type, |
| 326 | uint32_t id, |
| 327 | void *hw_catalog_info) |
| 328 | { |
| 329 | struct sde_rm_hw_blk *blk; |
| 330 | struct sde_hw_mdp *hw_mdp; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 331 | void *hw; |
| 332 | |
| 333 | hw_mdp = rm->hw_mdp; |
| 334 | |
| 335 | switch (type) { |
| 336 | case SDE_HW_BLK_LM: |
| 337 | hw = sde_hw_lm_init(id, mmio, cat); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 338 | break; |
| 339 | case SDE_HW_BLK_DSPP: |
| 340 | hw = sde_hw_dspp_init(id, mmio, cat); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 341 | break; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 342 | case SDE_HW_BLK_DS: |
| 343 | hw = sde_hw_ds_init(id, mmio, cat); |
| 344 | break; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 345 | case SDE_HW_BLK_CTL: |
| 346 | hw = sde_hw_ctl_init(id, mmio, cat); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 347 | break; |
| 348 | case SDE_HW_BLK_CDM: |
| 349 | hw = sde_hw_cdm_init(id, mmio, cat, hw_mdp); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 350 | break; |
| 351 | case SDE_HW_BLK_PINGPONG: |
| 352 | hw = sde_hw_pingpong_init(id, mmio, cat); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 353 | break; |
| 354 | case SDE_HW_BLK_INTF: |
| 355 | hw = sde_hw_intf_init(id, mmio, cat); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 356 | break; |
| 357 | case SDE_HW_BLK_WB: |
| 358 | hw = sde_hw_wb_init(id, mmio, cat, hw_mdp); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 359 | break; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 360 | case SDE_HW_BLK_DSC: |
| 361 | hw = sde_hw_dsc_init(id, mmio, cat); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 362 | break; |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 363 | case SDE_HW_BLK_ROT: |
| 364 | hw = sde_hw_rot_init(id, mmio, cat); |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 365 | break; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 366 | case SDE_HW_BLK_SSPP: |
| 367 | /* SSPPs are not managed by the resource manager */ |
| 368 | case SDE_HW_BLK_TOP: |
| 369 | /* Top is a singleton, not managed in hw_blks list */ |
| 370 | case SDE_HW_BLK_MAX: |
| 371 | default: |
| 372 | SDE_ERROR("unsupported block type %d\n", type); |
| 373 | return -EINVAL; |
| 374 | } |
| 375 | |
| 376 | if (IS_ERR_OR_NULL(hw)) { |
| 377 | SDE_ERROR("failed hw object creation: type %d, err %ld\n", |
| 378 | type, PTR_ERR(hw)); |
| 379 | return -EFAULT; |
| 380 | } |
| 381 | |
| 382 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
| 383 | if (!blk) { |
| 384 | _sde_rm_hw_destroy(type, hw); |
| 385 | return -ENOMEM; |
| 386 | } |
| 387 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 388 | blk->type = type; |
| 389 | blk->id = id; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 390 | blk->hw = hw; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 391 | list_add_tail(&blk->list, &rm->hw_blks[type]); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | int sde_rm_init(struct sde_rm *rm, |
| 397 | struct sde_mdss_cfg *cat, |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 398 | void __iomem *mmio, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 399 | struct drm_device *dev) |
| 400 | { |
| 401 | int rc, i; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 402 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 403 | |
| 404 | if (!rm || !cat || !mmio || !dev) { |
| 405 | SDE_ERROR("invalid kms\n"); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | |
| 409 | /* Clear, setup lists */ |
| 410 | memset(rm, 0, sizeof(*rm)); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 411 | |
| 412 | mutex_init(&rm->rm_lock); |
| 413 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 414 | INIT_LIST_HEAD(&rm->rsvps); |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 415 | for (type = 0; type < SDE_HW_BLK_MAX; type++) |
| 416 | INIT_LIST_HEAD(&rm->hw_blks[type]); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 417 | |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 418 | rm->dev = dev; |
| 419 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 420 | /* Some of the sub-blocks require an mdptop to be created */ |
| 421 | rm->hw_mdp = sde_hw_mdptop_init(MDP_TOP, mmio, cat); |
| 422 | if (IS_ERR_OR_NULL(rm->hw_mdp)) { |
| 423 | rc = PTR_ERR(rm->hw_mdp); |
| 424 | rm->hw_mdp = NULL; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 425 | SDE_ERROR("failed: mdp hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 426 | goto fail; |
| 427 | } |
| 428 | |
| 429 | /* Interrogate HW catalog and create tracking items for hw blocks */ |
| 430 | for (i = 0; i < cat->mixer_count; i++) { |
| 431 | struct sde_lm_cfg *lm = &cat->mixer[i]; |
| 432 | |
| 433 | if (lm->pingpong == PINGPONG_MAX) { |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 434 | SDE_ERROR("mixer %d without pingpong\n", lm->id); |
| 435 | goto fail; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_LM, |
| 439 | cat->mixer[i].id, &cat->mixer[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 440 | if (rc) { |
| 441 | SDE_ERROR("failed: lm hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 442 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 443 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 444 | |
| 445 | if (!rm->lm_max_width) { |
| 446 | rm->lm_max_width = lm->sblk->maxwidth; |
| 447 | } else if (rm->lm_max_width != lm->sblk->maxwidth) { |
| 448 | /* |
| 449 | * Don't expect to have hw where lm max widths differ. |
| 450 | * If found, take the min. |
| 451 | */ |
| 452 | SDE_ERROR("unsupported: lm maxwidth differs\n"); |
| 453 | if (rm->lm_max_width > lm->sblk->maxwidth) |
| 454 | rm->lm_max_width = lm->sblk->maxwidth; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | for (i = 0; i < cat->dspp_count; i++) { |
| 459 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSPP, |
| 460 | cat->dspp[i].id, &cat->dspp[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 461 | if (rc) { |
| 462 | SDE_ERROR("failed: dspp hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 463 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 464 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 467 | if (cat->mdp[0].has_dest_scaler) { |
| 468 | for (i = 0; i < cat->ds_count; i++) { |
| 469 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DS, |
| 470 | cat->ds[i].id, &cat->ds[i]); |
| 471 | if (rc) { |
| 472 | SDE_ERROR("failed: ds hw not available\n"); |
| 473 | goto fail; |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 478 | for (i = 0; i < cat->pingpong_count; i++) { |
| 479 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_PINGPONG, |
| 480 | cat->pingpong[i].id, &cat->pingpong[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 481 | if (rc) { |
| 482 | SDE_ERROR("failed: pp hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 483 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 484 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 487 | for (i = 0; i < cat->dsc_count; i++) { |
| 488 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSC, |
| 489 | cat->dsc[i].id, &cat->dsc[i]); |
| 490 | if (rc) { |
| 491 | SDE_ERROR("failed: dsc hw not available\n"); |
| 492 | goto fail; |
| 493 | } |
| 494 | } |
| 495 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 496 | for (i = 0; i < cat->intf_count; i++) { |
| 497 | if (cat->intf[i].type == INTF_NONE) { |
| 498 | SDE_DEBUG("skip intf %d with type none\n", i); |
| 499 | continue; |
| 500 | } |
| 501 | |
| 502 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_INTF, |
| 503 | cat->intf[i].id, &cat->intf[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 504 | if (rc) { |
| 505 | SDE_ERROR("failed: intf hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 506 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 507 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | for (i = 0; i < cat->wb_count; i++) { |
| 511 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_WB, |
| 512 | cat->wb[i].id, &cat->wb[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 513 | if (rc) { |
| 514 | SDE_ERROR("failed: wb hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 515 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 516 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 517 | } |
| 518 | |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 519 | for (i = 0; i < cat->rot_count; i++) { |
| 520 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_ROT, |
| 521 | cat->rot[i].id, &cat->rot[i]); |
| 522 | if (rc) { |
| 523 | SDE_ERROR("failed: rot hw not available\n"); |
| 524 | goto fail; |
| 525 | } |
| 526 | } |
| 527 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 528 | for (i = 0; i < cat->ctl_count; i++) { |
| 529 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CTL, |
| 530 | cat->ctl[i].id, &cat->ctl[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 531 | if (rc) { |
| 532 | SDE_ERROR("failed: ctl hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 533 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 534 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | for (i = 0; i < cat->cdm_count; i++) { |
| 538 | rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CDM, |
| 539 | cat->cdm[i].id, &cat->cdm[i]); |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 540 | if (rc) { |
| 541 | SDE_ERROR("failed: cdm hw not available\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 542 | goto fail; |
Dhaval Patel | 3e8b8c9 | 2016-10-05 18:01:06 -0700 | [diff] [blame] | 543 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return 0; |
| 547 | |
| 548 | fail: |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 549 | sde_rm_destroy(rm); |
| 550 | |
| 551 | return rc; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * _sde_rm_check_lm_and_get_connected_blks - check if proposed layer mixer meets |
| 556 | * proposed use case requirements, incl. hardwired dependent blocks like |
| 557 | * pingpong, and dspp. |
| 558 | * @rm: sde resource manager handle |
| 559 | * @rsvp: reservation currently being created |
| 560 | * @reqs: proposed use case requirements |
| 561 | * @lm: proposed layer mixer, function checks if lm, and all other hardwired |
| 562 | * blocks connected to the lm (pp, dspp) are available and appropriate |
| 563 | * @dspp: output parameter, dspp block attached to the layer mixer. |
| 564 | * NULL if dspp was not available, or not matching requirements. |
| 565 | * @pp: output parameter, pingpong block attached to the layer mixer. |
| 566 | * NULL if dspp was not available, or not matching requirements. |
| 567 | * @primary_lm: if non-null, this function check if lm is compatible primary_lm |
| 568 | * as well as satisfying all other requirements |
| 569 | * @Return: true if lm matches all requirements, false otherwise |
| 570 | */ |
| 571 | static bool _sde_rm_check_lm_and_get_connected_blks( |
| 572 | struct sde_rm *rm, |
| 573 | struct sde_rm_rsvp *rsvp, |
| 574 | struct sde_rm_requirements *reqs, |
| 575 | struct sde_rm_hw_blk *lm, |
| 576 | struct sde_rm_hw_blk **dspp, |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 577 | struct sde_rm_hw_blk **ds, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 578 | struct sde_rm_hw_blk **pp, |
| 579 | struct sde_rm_hw_blk *primary_lm) |
| 580 | { |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 581 | const struct sde_lm_cfg *lm_cfg = to_sde_hw_mixer(lm->hw)->cap; |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 582 | const struct sde_pingpong_cfg *pp_cfg; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 583 | struct sde_rm_hw_iter iter; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 584 | bool is_valid_dspp, is_valid_ds, ret; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 585 | u32 display_pref; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 586 | |
| 587 | *dspp = NULL; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 588 | *ds = NULL; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 589 | *pp = NULL; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 590 | display_pref = lm_cfg->features & BIT(SDE_DISP_PRIMARY_PREF); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 591 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 592 | SDE_DEBUG("check lm %d: dspp %d ds %d pp %d display_pref: %d\n", |
| 593 | lm_cfg->id, lm_cfg->dspp, lm_cfg->ds, |
| 594 | lm_cfg->pingpong, display_pref); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 595 | |
| 596 | /* Check if this layer mixer is a peer of the proposed primary LM */ |
| 597 | if (primary_lm) { |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 598 | const struct sde_lm_cfg *prim_lm_cfg = |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 599 | to_sde_hw_mixer(primary_lm->hw)->cap; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 600 | |
| 601 | if (!test_bit(lm_cfg->id, &prim_lm_cfg->lm_pair_mask)) { |
| 602 | SDE_DEBUG("lm %d not peer of lm %d\n", lm_cfg->id, |
| 603 | prim_lm_cfg->id); |
| 604 | return false; |
| 605 | } |
| 606 | } |
| 607 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 608 | /* bypass rest of the checks if LM for primary display is found */ |
| 609 | if (!display_pref) { |
| 610 | is_valid_dspp = (lm_cfg->dspp != DSPP_MAX) ? true : false; |
| 611 | is_valid_ds = (lm_cfg->ds != DS_MAX) ? true : false; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 612 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 613 | /** |
| 614 | * RM_RQ_X: specification of which LMs to choose |
| 615 | * is_valid_X: indicates whether LM is tied with block X |
| 616 | * ret: true if given LM matches the user requirement, |
| 617 | * false otherwise |
| 618 | */ |
| 619 | if (RM_RQ_DSPP(reqs) && RM_RQ_DS(reqs)) |
| 620 | ret = (is_valid_dspp && is_valid_ds); |
| 621 | else if (RM_RQ_DSPP(reqs)) |
| 622 | ret = is_valid_dspp; |
| 623 | else if (RM_RQ_DS(reqs)) |
| 624 | ret = is_valid_ds; |
| 625 | else |
| 626 | ret = !(is_valid_dspp || is_valid_ds); |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 627 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 628 | if (!ret) { |
| 629 | SDE_DEBUG( |
| 630 | "fail:lm(%d)req_dspp(%d)dspp(%d)req_ds(%d)ds(%d)\n", |
| 631 | lm_cfg->id, (bool)(RM_RQ_DSPP(reqs)), |
| 632 | lm_cfg->dspp, (bool)(RM_RQ_DS(reqs)), |
| 633 | lm_cfg->ds); |
| 634 | return ret; |
| 635 | } |
| 636 | } else if (!(reqs->hw_res.is_primary && display_pref)) { |
| 637 | SDE_DEBUG( |
| 638 | "display preference is not met. is_primary: %d display_pref: %d\n", |
| 639 | (int)reqs->hw_res.is_primary, (int)display_pref); |
| 640 | return false; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* Already reserved? */ |
| 644 | if (RESERVED_BY_OTHER(lm, rsvp)) { |
| 645 | SDE_DEBUG("lm %d already reserved\n", lm_cfg->id); |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | if (lm_cfg->dspp != DSPP_MAX) { |
| 650 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSPP); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 651 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 652 | if (iter.blk->id == lm_cfg->dspp) { |
| 653 | *dspp = iter.blk; |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | if (!*dspp) { |
| 659 | SDE_DEBUG("lm %d failed to retrieve dspp %d\n", lm->id, |
| 660 | lm_cfg->dspp); |
| 661 | return false; |
| 662 | } |
| 663 | |
| 664 | if (RESERVED_BY_OTHER(*dspp, rsvp)) { |
| 665 | SDE_DEBUG("lm %d dspp %d already reserved\n", |
| 666 | lm->id, (*dspp)->id); |
| 667 | return false; |
| 668 | } |
| 669 | } |
| 670 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 671 | if (lm_cfg->ds != DS_MAX) { |
| 672 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DS); |
| 673 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
| 674 | if (iter.blk->id == lm_cfg->ds) { |
| 675 | *ds = iter.blk; |
| 676 | break; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | if (!*ds) { |
| 681 | SDE_DEBUG("lm %d failed to retrieve ds %d\n", lm->id, |
| 682 | lm_cfg->ds); |
| 683 | return false; |
| 684 | } |
| 685 | |
| 686 | if (RESERVED_BY_OTHER(*ds, rsvp)) { |
| 687 | SDE_DEBUG("lm %d ds %d already reserved\n", |
| 688 | lm->id, (*ds)->id); |
| 689 | return false; |
| 690 | } |
| 691 | } |
| 692 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 693 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_PINGPONG); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 694 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 695 | if (iter.blk->id == lm_cfg->pingpong) { |
| 696 | *pp = iter.blk; |
| 697 | break; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | if (!*pp) { |
| 702 | SDE_ERROR("failed to get pp on lm %d\n", lm_cfg->pingpong); |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | if (RESERVED_BY_OTHER(*pp, rsvp)) { |
| 707 | SDE_DEBUG("lm %d pp %d already reserved\n", lm->id, |
| 708 | (*pp)->id); |
| 709 | *dspp = NULL; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 710 | *ds = NULL; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 714 | pp_cfg = to_sde_hw_pingpong((*pp)->hw)->caps; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 715 | if ((reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) && |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 716 | !(test_bit(SDE_PINGPONG_SPLIT, &pp_cfg->features))) { |
| 717 | SDE_DEBUG("pp %d doesn't support ppsplit\n", pp_cfg->id); |
| 718 | *dspp = NULL; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 719 | *ds = NULL; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 720 | return false; |
| 721 | } |
| 722 | |
| 723 | return true; |
| 724 | } |
| 725 | |
| 726 | static int _sde_rm_reserve_lms( |
| 727 | struct sde_rm *rm, |
| 728 | struct sde_rm_rsvp *rsvp, |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 729 | struct sde_rm_requirements *reqs, |
| 730 | u8 *_lm_ids) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 731 | |
| 732 | { |
| 733 | struct sde_rm_hw_blk *lm[MAX_BLOCKS]; |
| 734 | struct sde_rm_hw_blk *dspp[MAX_BLOCKS]; |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 735 | struct sde_rm_hw_blk *ds[MAX_BLOCKS]; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 736 | struct sde_rm_hw_blk *pp[MAX_BLOCKS]; |
| 737 | struct sde_rm_hw_iter iter_i, iter_j; |
| 738 | int lm_count = 0; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 739 | int i, rc = 0; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 740 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 741 | if (!reqs->topology->num_lm) { |
| 742 | SDE_ERROR("invalid number of lm: %d\n", reqs->topology->num_lm); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 743 | return -EINVAL; |
| 744 | } |
| 745 | |
| 746 | /* Find a primary mixer */ |
| 747 | sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_LM); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 748 | while (lm_count != reqs->topology->num_lm && |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 749 | _sde_rm_get_hw_locked(rm, &iter_i)) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 750 | memset(&lm, 0, sizeof(lm)); |
| 751 | memset(&dspp, 0, sizeof(dspp)); |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 752 | memset(&ds, 0, sizeof(ds)); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 753 | memset(&pp, 0, sizeof(pp)); |
| 754 | |
| 755 | lm_count = 0; |
| 756 | lm[lm_count] = iter_i.blk; |
| 757 | |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 758 | SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n", |
| 759 | iter_i.blk->id, |
| 760 | lm_count, |
| 761 | _lm_ids ? _lm_ids[lm_count] : -1); |
| 762 | |
| 763 | if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count]) |
| 764 | continue; |
| 765 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 766 | if (!_sde_rm_check_lm_and_get_connected_blks( |
| 767 | rm, rsvp, reqs, lm[lm_count], |
| 768 | &dspp[lm_count], &ds[lm_count], |
| 769 | &pp[lm_count], NULL)) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 770 | continue; |
| 771 | |
| 772 | ++lm_count; |
| 773 | |
| 774 | /* Valid primary mixer found, find matching peers */ |
| 775 | sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_LM); |
| 776 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 777 | while (lm_count != reqs->topology->num_lm && |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 778 | _sde_rm_get_hw_locked(rm, &iter_j)) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 779 | if (iter_i.blk == iter_j.blk) |
| 780 | continue; |
| 781 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 782 | if (!_sde_rm_check_lm_and_get_connected_blks( |
| 783 | rm, rsvp, reqs, iter_j.blk, |
| 784 | &dspp[lm_count], &ds[lm_count], |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 785 | &pp[lm_count], iter_i.blk)) |
| 786 | continue; |
| 787 | |
| 788 | lm[lm_count] = iter_j.blk; |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 789 | SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n", |
| 790 | iter_i.blk->id, |
| 791 | lm_count, |
| 792 | _lm_ids ? _lm_ids[lm_count] : -1); |
| 793 | |
| 794 | if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count]) |
| 795 | continue; |
| 796 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 797 | ++lm_count; |
| 798 | } |
| 799 | } |
| 800 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 801 | if (lm_count != reqs->topology->num_lm) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 802 | SDE_DEBUG("unable to find appropriate mixers\n"); |
| 803 | return -ENAVAIL; |
| 804 | } |
| 805 | |
| 806 | for (i = 0; i < ARRAY_SIZE(lm); i++) { |
| 807 | if (!lm[i]) |
| 808 | break; |
| 809 | |
| 810 | lm[i]->rsvp_nxt = rsvp; |
| 811 | pp[i]->rsvp_nxt = rsvp; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 812 | if (dspp[i]) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 813 | dspp[i]->rsvp_nxt = rsvp; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 814 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 815 | if (ds[i]) |
| 816 | ds[i]->rsvp_nxt = rsvp; |
| 817 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 818 | SDE_EVT32(lm[i]->type, rsvp->enc_id, lm[i]->id, pp[i]->id, |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 819 | dspp[i] ? dspp[i]->id : 0, |
| 820 | ds[i] ? ds[i]->id : 0); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 823 | if (reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) { |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 824 | /* reserve a free PINGPONG_SLAVE block */ |
| 825 | rc = -ENAVAIL; |
| 826 | sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_PINGPONG); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 827 | while (_sde_rm_get_hw_locked(rm, &iter_i)) { |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 828 | const struct sde_hw_pingpong *pp = |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 829 | to_sde_hw_pingpong(iter_i.blk->hw); |
Lloyd Atkinson | 4a752fc | 2017-05-19 16:09:17 -0400 | [diff] [blame] | 830 | const struct sde_pingpong_cfg *pp_cfg = pp->caps; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 831 | |
| 832 | if (!(test_bit(SDE_PINGPONG_SLAVE, &pp_cfg->features))) |
| 833 | continue; |
| 834 | if (RESERVED_BY_OTHER(iter_i.blk, rsvp)) |
| 835 | continue; |
| 836 | |
| 837 | iter_i.blk->rsvp_nxt = rsvp; |
| 838 | rc = 0; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | return rc; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static int _sde_rm_reserve_ctls( |
| 847 | struct sde_rm *rm, |
| 848 | struct sde_rm_rsvp *rsvp, |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 849 | struct sde_rm_requirements *reqs, |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 850 | const struct sde_rm_topology_def *top, |
| 851 | u8 *_ctl_ids) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 852 | { |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 853 | struct sde_rm_hw_blk *ctls[MAX_BLOCKS]; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 854 | struct sde_rm_hw_iter iter; |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 855 | int i = 0; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 856 | |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 857 | memset(&ctls, 0, sizeof(ctls)); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 858 | |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 859 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 860 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 861 | const struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw); |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 862 | unsigned long features = ctl->caps->features; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 863 | bool has_split_display, has_ppsplit, primary_pref; |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 864 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 865 | if (RESERVED_BY_OTHER(iter.blk, rsvp)) |
| 866 | continue; |
| 867 | |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 868 | has_split_display = BIT(SDE_CTL_SPLIT_DISPLAY) & features; |
| 869 | has_ppsplit = BIT(SDE_CTL_PINGPONG_SPLIT) & features; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 870 | primary_pref = BIT(SDE_CTL_PRIMARY_PREF) & features; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 871 | |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 872 | SDE_DEBUG("ctl %d caps 0x%lX\n", iter.blk->id, features); |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 873 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 874 | /* |
| 875 | * bypass rest feature checks on finding CTL preferred |
| 876 | * for primary displays. |
| 877 | */ |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 878 | if (!primary_pref && !_ctl_ids) { |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 879 | if (top->needs_split_display != has_split_display) |
| 880 | continue; |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 881 | |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 882 | if (top->top_name == SDE_RM_TOPOLOGY_PPSPLIT && |
| 883 | !has_ppsplit) |
| 884 | continue; |
| 885 | } else if (!(reqs->hw_res.is_primary && primary_pref)) { |
| 886 | SDE_DEBUG( |
| 887 | "display pref not met. is_primary: %d primary_pref: %d\n", |
| 888 | reqs->hw_res.is_primary, primary_pref); |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 889 | continue; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 890 | } |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 891 | |
| 892 | ctls[i] = iter.blk; |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 893 | |
| 894 | SDE_DEBUG("blk id = %d, _ctl_ids[%d] = %d\n", |
| 895 | iter.blk->id, i, |
| 896 | _ctl_ids ? _ctl_ids[i] : -1); |
| 897 | |
| 898 | if (_ctl_ids && (ctls[i]->id != _ctl_ids[i])) |
| 899 | continue; |
| 900 | |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 901 | SDE_DEBUG("ctl %d match\n", iter.blk->id); |
| 902 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 903 | if (++i == top->num_ctl) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 904 | break; |
| 905 | } |
| 906 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 907 | if (i != top->num_ctl) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 908 | return -ENAVAIL; |
| 909 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 910 | for (i = 0; i < ARRAY_SIZE(ctls) && i < top->num_ctl; i++) { |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 911 | ctls[i]->rsvp_nxt = rsvp; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 912 | SDE_EVT32(ctls[i]->type, rsvp->enc_id, ctls[i]->id); |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 913 | } |
| 914 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 915 | return 0; |
| 916 | } |
| 917 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 918 | static int _sde_rm_reserve_dsc( |
| 919 | struct sde_rm *rm, |
| 920 | struct sde_rm_rsvp *rsvp, |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 921 | const struct sde_rm_topology_def *top, |
| 922 | u8 *_dsc_ids) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 923 | { |
| 924 | struct sde_rm_hw_iter iter; |
| 925 | int alloc_count = 0; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 926 | int num_dsc_enc = top->num_lm; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 927 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 928 | if (!top->num_comp_enc) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 929 | return 0; |
| 930 | |
| 931 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSC); |
| 932 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 933 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 934 | if (RESERVED_BY_OTHER(iter.blk, rsvp)) |
| 935 | continue; |
| 936 | |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 937 | SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n", |
| 938 | iter.blk->id, |
| 939 | alloc_count, |
| 940 | _dsc_ids ? _dsc_ids[alloc_count] : -1); |
| 941 | |
| 942 | if (_dsc_ids && (iter.blk->id != _dsc_ids[alloc_count])) |
| 943 | continue; |
| 944 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 945 | iter.blk->rsvp_nxt = rsvp; |
| 946 | SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id); |
| 947 | |
| 948 | if (++alloc_count == num_dsc_enc) |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n", |
| 953 | num_dsc_enc, rsvp->enc_id); |
| 954 | |
| 955 | return -ENAVAIL; |
| 956 | } |
| 957 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 958 | static int _sde_rm_reserve_cdm( |
| 959 | struct sde_rm *rm, |
| 960 | struct sde_rm_rsvp *rsvp, |
| 961 | uint32_t id, |
| 962 | enum sde_hw_blk_type type) |
| 963 | { |
| 964 | struct sde_rm_hw_iter iter; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 965 | |
| 966 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 967 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Lloyd Atkinson | f82d7b9 | 2017-05-19 16:23:04 -0400 | [diff] [blame] | 968 | const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw); |
Lloyd Atkinson | 4a752fc | 2017-05-19 16:09:17 -0400 | [diff] [blame] | 969 | const struct sde_cdm_cfg *caps = cdm->caps; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 970 | bool match = false; |
| 971 | |
| 972 | if (RESERVED_BY_OTHER(iter.blk, rsvp)) |
| 973 | continue; |
| 974 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 975 | if (type == SDE_HW_BLK_INTF && id != INTF_MAX) |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 976 | match = test_bit(id, &caps->intf_connect); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 977 | else if (type == SDE_HW_BLK_WB && id != WB_MAX) |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 978 | match = test_bit(id, &caps->wb_connect); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 979 | |
| 980 | SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n", |
Lloyd Atkinson | d13cca2 | 2017-05-03 14:59:04 -0400 | [diff] [blame] | 981 | type, id, caps->intf_connect, caps->wb_connect, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 982 | match); |
| 983 | |
| 984 | if (!match) |
| 985 | continue; |
| 986 | |
| 987 | iter.blk->rsvp_nxt = rsvp; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 988 | SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 989 | break; |
| 990 | } |
| 991 | |
| 992 | if (!iter.hw) { |
| 993 | SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id); |
| 994 | return -ENAVAIL; |
| 995 | } |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | static int _sde_rm_reserve_intf_or_wb( |
| 1001 | struct sde_rm *rm, |
| 1002 | struct sde_rm_rsvp *rsvp, |
| 1003 | uint32_t id, |
| 1004 | enum sde_hw_blk_type type, |
| 1005 | bool needs_cdm) |
| 1006 | { |
| 1007 | struct sde_rm_hw_iter iter; |
Lloyd Atkinson | 04d301c | 2016-08-31 11:39:45 -0400 | [diff] [blame] | 1008 | int ret = 0; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1009 | |
| 1010 | /* Find the block entry in the rm, and note the reservation */ |
| 1011 | sde_rm_init_hw_iter(&iter, 0, type); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1012 | while (_sde_rm_get_hw_locked(rm, &iter)) { |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1013 | if (iter.blk->id != id) |
| 1014 | continue; |
| 1015 | |
| 1016 | if (RESERVED_BY_OTHER(iter.blk, rsvp)) { |
| 1017 | SDE_ERROR("type %d id %d already reserved\n", type, id); |
| 1018 | return -ENAVAIL; |
| 1019 | } |
| 1020 | |
| 1021 | iter.blk->rsvp_nxt = rsvp; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1022 | SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | /* Shouldn't happen since wbs / intfs are fixed at probe */ |
| 1027 | if (!iter.hw) { |
| 1028 | SDE_ERROR("couldn't find type %d id %d\n", type, id); |
| 1029 | return -EINVAL; |
| 1030 | } |
| 1031 | |
| 1032 | /* Expected only one intf or wb will request cdm */ |
| 1033 | if (needs_cdm) |
| 1034 | ret = _sde_rm_reserve_cdm(rm, rsvp, id, type); |
| 1035 | |
| 1036 | return ret; |
| 1037 | } |
| 1038 | |
| 1039 | static int _sde_rm_reserve_intf_related_hw( |
| 1040 | struct sde_rm *rm, |
| 1041 | struct sde_rm_rsvp *rsvp, |
| 1042 | struct sde_encoder_hw_resources *hw_res) |
| 1043 | { |
| 1044 | int i, ret = 0; |
| 1045 | u32 id; |
| 1046 | |
| 1047 | for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) { |
| 1048 | if (hw_res->intfs[i] == INTF_MODE_NONE) |
| 1049 | continue; |
| 1050 | id = i + INTF_0; |
| 1051 | ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, |
| 1052 | SDE_HW_BLK_INTF, hw_res->needs_cdm); |
| 1053 | if (ret) |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) { |
| 1058 | if (hw_res->wbs[i] == INTF_MODE_NONE) |
| 1059 | continue; |
| 1060 | id = i + WB_0; |
| 1061 | ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, |
| 1062 | SDE_HW_BLK_WB, hw_res->needs_cdm); |
| 1063 | if (ret) |
| 1064 | return ret; |
| 1065 | } |
| 1066 | |
| 1067 | return ret; |
| 1068 | } |
| 1069 | |
| 1070 | static int _sde_rm_make_next_rsvp( |
| 1071 | struct sde_rm *rm, |
| 1072 | struct drm_encoder *enc, |
| 1073 | struct drm_crtc_state *crtc_state, |
| 1074 | struct drm_connector_state *conn_state, |
| 1075 | struct sde_rm_rsvp *rsvp, |
| 1076 | struct sde_rm_requirements *reqs) |
| 1077 | { |
| 1078 | int ret; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1079 | struct sde_rm_topology_def topology; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1080 | |
| 1081 | /* Create reservation info, tag reserved blocks with it as we go */ |
| 1082 | rsvp->seq = ++rm->rsvp_next_seq; |
| 1083 | rsvp->enc_id = enc->base.id; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1084 | rsvp->topology = reqs->topology->top_name; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1085 | list_add_tail(&rsvp->list, &rm->rsvps); |
| 1086 | |
| 1087 | /* |
| 1088 | * Assign LMs and blocks whose usage is tied to them: DSPP & Pingpong. |
| 1089 | * Do assignment preferring to give away low-resource mixers first: |
| 1090 | * - Check mixers without DSPPs |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 1091 | * - Only then allow to grab from mixers with DSPP capability |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1092 | */ |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 1093 | ret = _sde_rm_reserve_lms(rm, rsvp, reqs, NULL); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1094 | if (ret && !RM_RQ_DSPP(reqs)) { |
| 1095 | reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP); |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 1096 | ret = _sde_rm_reserve_lms(rm, rsvp, reqs, NULL); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | if (ret) { |
| 1100 | SDE_ERROR("unable to find appropriate mixers\n"); |
| 1101 | return ret; |
| 1102 | } |
| 1103 | |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 1104 | /* |
| 1105 | * Do assignment preferring to give away low-resource CTLs first: |
| 1106 | * - Check mixers without Split Display |
| 1107 | * - Only then allow to grab from CTLs with split display capability |
| 1108 | */ |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 1109 | _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, NULL); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1110 | if (ret && !reqs->topology->needs_split_display) { |
| 1111 | memcpy(&topology, reqs->topology, sizeof(topology)); |
| 1112 | topology.needs_split_display = true; |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 1113 | _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, NULL); |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 1114 | } |
| 1115 | if (ret) { |
| 1116 | SDE_ERROR("unable to find appropriate CTL\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1117 | return ret; |
Lloyd Atkinson | cf8996b | 2016-08-23 09:34:13 -0400 | [diff] [blame] | 1118 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1119 | |
| 1120 | /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */ |
| 1121 | ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, &reqs->hw_res); |
| 1122 | if (ret) |
| 1123 | return ret; |
| 1124 | |
Chandan Uddaraju | 758f28b | 2017-09-04 10:24:10 -0700 | [diff] [blame] | 1125 | ret = _sde_rm_reserve_dsc(rm, rsvp, reqs->topology, NULL); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1126 | if (ret) |
| 1127 | return ret; |
| 1128 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1129 | return ret; |
| 1130 | } |
| 1131 | |
Chandan Uddaraju | 9efbbe3 | 2017-11-09 23:57:05 -0800 | [diff] [blame] | 1132 | /** |
| 1133 | * sde_rm_get_pp_dsc_for_cont_splash - retrieve the current dsc enabled blocks |
| 1134 | * and disable autorefresh if enabled. |
| 1135 | * @mmio: mapped register io address of MDP |
| 1136 | * @max_dsc_cnt: number of DSC blocks supported in the hw |
| 1137 | * @dsc_ids: pointer to store the active DSC block IDs |
| 1138 | * return: number of active DSC blocks |
| 1139 | */ |
| 1140 | static int _sde_rm_get_pp_dsc_for_cont_splash(struct sde_rm *rm, |
| 1141 | int max_dsc_cnt, u8 *dsc_ids) |
| 1142 | { |
| 1143 | int index = 0; |
| 1144 | int value, dsc_cnt = 0; |
| 1145 | struct sde_hw_autorefresh cfg; |
| 1146 | struct sde_rm_hw_iter iter_pp; |
| 1147 | |
| 1148 | if (!rm || !dsc_ids) { |
| 1149 | SDE_ERROR("invalid input parameters\n"); |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
| 1153 | SDE_DEBUG("max_dsc_cnt = %d\n", max_dsc_cnt); |
| 1154 | sde_rm_init_hw_iter(&iter_pp, 0, SDE_HW_BLK_PINGPONG); |
| 1155 | while (_sde_rm_get_hw_locked(rm, &iter_pp)) { |
| 1156 | struct sde_hw_pingpong *pp = |
| 1157 | to_sde_hw_pingpong(iter_pp.blk->hw); |
| 1158 | |
| 1159 | if (!pp->ops.get_dsc_status) { |
| 1160 | SDE_ERROR("get_dsc_status ops not initialized\n"); |
| 1161 | return 0; |
| 1162 | } |
| 1163 | value = pp->ops.get_dsc_status(pp); |
| 1164 | SDE_DEBUG("DSC[%d]=0x%x, dsc_cnt = %d\n", |
| 1165 | index, value, dsc_cnt); |
| 1166 | if (value) { |
| 1167 | dsc_ids[dsc_cnt] = index + DSC_0; |
| 1168 | dsc_cnt++; |
| 1169 | } |
| 1170 | index++; |
| 1171 | |
| 1172 | if (!pp->ops.get_autorefresh) { |
| 1173 | SDE_ERROR("get_autorefresh api not supported\n"); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | memset(&cfg, 0, sizeof(cfg)); |
| 1177 | if (!pp->ops.get_autorefresh(pp, &cfg) |
| 1178 | && (cfg.enable) |
| 1179 | && (pp->ops.setup_autorefresh)) { |
| 1180 | cfg.enable = false; |
| 1181 | SDE_DEBUG("Disabling autoreferesh\n"); |
| 1182 | pp->ops.setup_autorefresh(pp, &cfg); |
| 1183 | /* |
| 1184 | * Wait for one frame update so that |
| 1185 | * auto refresh disable is through |
| 1186 | */ |
| 1187 | usleep_range(16000, 20000); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | return dsc_cnt; |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * _sde_rm_get_ctl_lm_for_cont_splash - retrieve the current LM blocks |
| 1196 | * @ctl: Pointer to CTL hardware block |
| 1197 | * @max_lm_cnt: number of LM blocks supported in the hw |
| 1198 | * @lm_cnt: number of LM blocks already active |
| 1199 | * @lm_ids: pointer to store the active LM block IDs |
| 1200 | * @top: pointer to the current "ctl_top" structure |
| 1201 | * @index: ctl_top index |
| 1202 | * return: number of active LM blocks for this CTL block |
| 1203 | */ |
| 1204 | static int _sde_rm_get_ctl_lm_for_cont_splash(struct sde_hw_ctl *ctl, |
| 1205 | int max_lm_cnt, u8 lm_cnt, |
| 1206 | u8 *lm_ids, struct ctl_top *top, |
| 1207 | int index) |
| 1208 | { |
| 1209 | int j; |
| 1210 | struct sde_splash_lm_hw *lm; |
| 1211 | |
| 1212 | if (!ctl || !top || !lm_ids) { |
| 1213 | SDE_ERROR("invalid input parameters\n"); |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | lm = top->lm; |
| 1218 | for (j = 0; j < max_lm_cnt; j++) { |
| 1219 | lm[top->ctl_lm_cnt].lm_reg_value = |
| 1220 | ctl->ops.read_ctl_layers(ctl, j + LM_0); |
| 1221 | SDE_DEBUG("ctl[%d]_top --> lm[%d]=0x%x, j=%d\n", |
| 1222 | index, top->ctl_lm_cnt, |
| 1223 | lm[top->ctl_lm_cnt].lm_reg_value, j); |
| 1224 | SDE_DEBUG("lm_cnt = %d\n", lm_cnt); |
| 1225 | if (lm[top->ctl_lm_cnt].lm_reg_value) { |
| 1226 | lm[top->ctl_lm_cnt].ctl_id = index; |
| 1227 | lm_ids[lm_cnt++] = j + LM_0; |
| 1228 | lm[top->ctl_lm_cnt].lm_id = j + LM_0; |
| 1229 | SDE_DEBUG("ctl_id=%d, lm[%d].lm_id = %d\n", |
| 1230 | lm[top->ctl_lm_cnt].ctl_id, |
| 1231 | top->ctl_lm_cnt, |
| 1232 | lm[top->ctl_lm_cnt].lm_id); |
| 1233 | top->ctl_lm_cnt++; |
| 1234 | } |
| 1235 | } |
| 1236 | return top->ctl_lm_cnt; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * _sde_rm_get_ctl_top_for_cont_splash - retrieve the current LM blocks |
| 1241 | * @ctl: Pointer to CTL hardware block |
| 1242 | * @top: pointer to the current "ctl_top" structure thats needs update |
| 1243 | * @index: ctl_top index |
| 1244 | */ |
| 1245 | static void _sde_rm_get_ctl_top_for_cont_splash(struct sde_hw_ctl *ctl, |
| 1246 | struct ctl_top *top) |
| 1247 | { |
| 1248 | if (!ctl || !top) { |
| 1249 | SDE_ERROR("invalid input parameters\n"); |
| 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | if (!ctl->ops.read_ctl_top) { |
| 1254 | SDE_ERROR("read_ctl_top not initialized\n"); |
| 1255 | return; |
| 1256 | } |
| 1257 | |
| 1258 | top->value = ctl->ops.read_ctl_top(ctl); |
| 1259 | top->intf_sel = (top->value >> 4) & 0xf; |
| 1260 | top->pp_sel = (top->value >> 8) & 0x7; |
| 1261 | top->dspp_sel = (top->value >> 11) & 0x3; |
| 1262 | top->mode_sel = (top->value >> 17) & 0x1; |
| 1263 | |
| 1264 | SDE_DEBUG("id=%d,top->0x%x,pp_sel=0x%x,dspp_sel=0x%x,intf_sel=%d\n", |
| 1265 | ctl->idx, top->value, top->pp_sel, |
| 1266 | top->dspp_sel, top->intf_sel); |
| 1267 | } |
| 1268 | |
| 1269 | int sde_rm_cont_splash_res_init(struct sde_rm *rm, |
| 1270 | struct sde_splash_data *splash_data, |
| 1271 | struct sde_mdss_cfg *cat) |
| 1272 | { |
| 1273 | struct sde_rm_hw_iter iter_c; |
| 1274 | int index = 0, ctl_top_cnt; |
| 1275 | |
| 1276 | if (!rm || !cat || !splash_data) { |
| 1277 | SDE_ERROR("invalid input parameters\n"); |
| 1278 | return -EINVAL; |
| 1279 | } |
| 1280 | |
| 1281 | SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n", |
| 1282 | cat->mixer_count, |
| 1283 | cat->ctl_count, |
| 1284 | cat->dsc_count); |
| 1285 | |
| 1286 | ctl_top_cnt = cat->ctl_count; |
| 1287 | |
| 1288 | if (ctl_top_cnt > ARRAY_SIZE(splash_data->top)) { |
| 1289 | SDE_ERROR("Mismatch in ctl_top array size\n"); |
| 1290 | return -EINVAL; |
| 1291 | } |
| 1292 | |
| 1293 | sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL); |
| 1294 | while (_sde_rm_get_hw_locked(rm, &iter_c)) { |
| 1295 | struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw); |
| 1296 | |
| 1297 | _sde_rm_get_ctl_top_for_cont_splash(ctl, |
| 1298 | &splash_data->top[index]); |
| 1299 | if (splash_data->top[index].intf_sel) { |
| 1300 | splash_data->lm_cnt += |
| 1301 | _sde_rm_get_ctl_lm_for_cont_splash |
| 1302 | (ctl, |
| 1303 | cat->mixer_count, |
| 1304 | splash_data->lm_cnt, |
| 1305 | splash_data->lm_ids, |
| 1306 | &splash_data->top[index], index); |
| 1307 | splash_data->ctl_ids[splash_data->ctl_top_cnt] |
| 1308 | = index + CTL_0; |
| 1309 | splash_data->ctl_top_cnt++; |
| 1310 | splash_data->cont_splash_en = true; |
| 1311 | } |
| 1312 | index++; |
| 1313 | } |
| 1314 | |
| 1315 | /* Skip DSC blk reads if cont_splash is disabled */ |
| 1316 | if (!splash_data->cont_splash_en) |
| 1317 | return 0; |
| 1318 | |
| 1319 | splash_data->dsc_cnt = |
| 1320 | _sde_rm_get_pp_dsc_for_cont_splash(rm, |
| 1321 | cat->dsc_count, |
| 1322 | splash_data->dsc_ids); |
| 1323 | SDE_DEBUG("splash_data: ctl_top_cnt=%d, lm_cnt=%d, dsc_cnt=%d\n", |
| 1324 | splash_data->ctl_top_cnt, splash_data->lm_cnt, |
| 1325 | splash_data->dsc_cnt); |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1330 | static int _sde_rm_make_next_rsvp_for_cont_splash( |
| 1331 | struct sde_rm *rm, |
| 1332 | struct drm_encoder *enc, |
| 1333 | struct drm_crtc_state *crtc_state, |
| 1334 | struct drm_connector_state *conn_state, |
| 1335 | struct sde_rm_rsvp *rsvp, |
| 1336 | struct sde_rm_requirements *reqs) |
| 1337 | { |
| 1338 | int ret; |
| 1339 | struct sde_rm_topology_def topology; |
| 1340 | struct msm_drm_private *priv; |
| 1341 | struct sde_kms *sde_kms; |
| 1342 | int i; |
| 1343 | |
| 1344 | if (!enc->dev || !enc->dev->dev_private) { |
| 1345 | SDE_ERROR("drm device invalid\n"); |
| 1346 | return -EINVAL; |
| 1347 | } |
| 1348 | priv = enc->dev->dev_private; |
| 1349 | if (!priv->kms) { |
| 1350 | SDE_ERROR("invalid kms\n"); |
| 1351 | return -EINVAL; |
| 1352 | } |
| 1353 | sde_kms = to_sde_kms(priv->kms); |
| 1354 | |
| 1355 | for (i = 0; i < sde_kms->splash_data.lm_cnt; i++) |
| 1356 | SDE_DEBUG("splash_data.lm_ids[%d] = %d\n", |
| 1357 | i, sde_kms->splash_data.lm_ids[i]); |
| 1358 | |
| 1359 | if (sde_kms->splash_data.lm_cnt != |
| 1360 | reqs->topology->num_lm) |
| 1361 | SDE_DEBUG("Configured splash screen LMs != needed LM cnt\n"); |
| 1362 | |
| 1363 | /* Create reservation info, tag reserved blocks with it as we go */ |
| 1364 | rsvp->seq = ++rm->rsvp_next_seq; |
| 1365 | rsvp->enc_id = enc->base.id; |
| 1366 | rsvp->topology = reqs->topology->top_name; |
| 1367 | list_add_tail(&rsvp->list, &rm->rsvps); |
| 1368 | |
| 1369 | /* |
| 1370 | * Assign LMs and blocks whose usage is tied to them: DSPP & Pingpong. |
| 1371 | * Do assignment preferring to give away low-resource mixers first: |
| 1372 | * - Check mixers without DSPPs |
| 1373 | * - Only then allow to grab from mixers with DSPP capability |
| 1374 | */ |
| 1375 | ret = _sde_rm_reserve_lms(rm, rsvp, reqs, |
| 1376 | sde_kms->splash_data.lm_ids); |
| 1377 | if (ret && !RM_RQ_DSPP(reqs)) { |
| 1378 | reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP); |
| 1379 | ret = _sde_rm_reserve_lms(rm, rsvp, reqs, |
| 1380 | sde_kms->splash_data.lm_ids); |
| 1381 | } |
| 1382 | |
| 1383 | if (ret) { |
| 1384 | SDE_ERROR("unable to find appropriate mixers\n"); |
| 1385 | return ret; |
| 1386 | } |
| 1387 | |
| 1388 | /* |
| 1389 | * Do assignment preferring to give away low-resource CTLs first: |
| 1390 | * - Check mixers without Split Display |
| 1391 | * - Only then allow to grab from CTLs with split display capability |
| 1392 | */ |
| 1393 | for (i = 0; i < sde_kms->splash_data.ctl_top_cnt; i++) |
| 1394 | SDE_DEBUG("splash_data.ctl_ids[%d] = %d\n", |
| 1395 | i, sde_kms->splash_data.ctl_ids[i]); |
| 1396 | |
| 1397 | _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, |
| 1398 | sde_kms->splash_data.ctl_ids); |
| 1399 | if (ret && !reqs->topology->needs_split_display) { |
| 1400 | memcpy(&topology, reqs->topology, sizeof(topology)); |
| 1401 | topology.needs_split_display = true; |
| 1402 | _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, |
| 1403 | sde_kms->splash_data.ctl_ids); |
| 1404 | } |
| 1405 | if (ret) { |
| 1406 | SDE_ERROR("unable to find appropriate CTL\n"); |
| 1407 | return ret; |
| 1408 | } |
| 1409 | |
| 1410 | /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */ |
| 1411 | ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, &reqs->hw_res); |
| 1412 | if (ret) |
| 1413 | return ret; |
| 1414 | |
| 1415 | for (i = 0; i < sde_kms->splash_data.dsc_cnt; i++) |
| 1416 | SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n", |
| 1417 | i, sde_kms->splash_data.dsc_ids[i]); |
| 1418 | |
| 1419 | ret = _sde_rm_reserve_dsc(rm, rsvp, reqs->topology, |
| 1420 | sde_kms->splash_data.dsc_ids); |
| 1421 | if (ret) |
| 1422 | return ret; |
| 1423 | |
| 1424 | return ret; |
| 1425 | } |
| 1426 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1427 | static int _sde_rm_populate_requirements( |
| 1428 | struct sde_rm *rm, |
| 1429 | struct drm_encoder *enc, |
| 1430 | struct drm_crtc_state *crtc_state, |
| 1431 | struct drm_connector_state *conn_state, |
| 1432 | struct sde_rm_requirements *reqs) |
| 1433 | { |
| 1434 | const struct drm_display_mode *mode = &crtc_state->mode; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1435 | int i; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1436 | |
| 1437 | memset(reqs, 0, sizeof(*reqs)); |
| 1438 | |
| 1439 | reqs->top_ctrl = sde_connector_get_property(conn_state, |
| 1440 | CONNECTOR_PROP_TOPOLOGY_CONTROL); |
| 1441 | sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state); |
| 1442 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1443 | for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) { |
| 1444 | if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], |
| 1445 | reqs->hw_res.topology)) { |
| 1446 | reqs->topology = &g_top_table[i]; |
| 1447 | break; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1448 | } |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1449 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1450 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1451 | if (!reqs->topology) { |
| 1452 | SDE_ERROR("invalid topology for the display\n"); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1453 | return -EINVAL; |
| 1454 | } |
| 1455 | |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 1456 | /** |
| 1457 | * Set the requirement based on caps if not set from user space |
| 1458 | * This will ensure to select LM tied with DS blocks |
| 1459 | * Currently, DS blocks are tied with LM 0 and LM 1 (primary display) |
| 1460 | */ |
| 1461 | if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler && |
| 1462 | conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) |
| 1463 | reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS); |
| 1464 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1465 | SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1466 | reqs->hw_res.display_num_of_h_tiles); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1467 | SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d\n", |
| 1468 | reqs->topology->num_lm, reqs->topology->num_ctl, |
| 1469 | reqs->topology->top_name, |
| 1470 | reqs->topology->needs_split_display); |
| 1471 | SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm, |
| 1472 | reqs->top_ctrl, reqs->topology->top_name, |
| 1473 | reqs->topology->num_ctl); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1474 | |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | static struct sde_rm_rsvp *_sde_rm_get_rsvp( |
| 1479 | struct sde_rm *rm, |
| 1480 | struct drm_encoder *enc) |
| 1481 | { |
| 1482 | struct sde_rm_rsvp *i; |
| 1483 | |
| 1484 | if (!rm || !enc) { |
| 1485 | SDE_ERROR("invalid params\n"); |
| 1486 | return NULL; |
| 1487 | } |
| 1488 | |
| 1489 | if (list_empty(&rm->rsvps)) |
| 1490 | return NULL; |
| 1491 | |
| 1492 | list_for_each_entry(i, &rm->rsvps, list) |
| 1493 | if (i->enc_id == enc->base.id) |
| 1494 | return i; |
| 1495 | |
| 1496 | return NULL; |
| 1497 | } |
| 1498 | |
| 1499 | static struct drm_connector *_sde_rm_get_connector( |
| 1500 | struct drm_encoder *enc) |
| 1501 | { |
| 1502 | struct drm_connector *conn = NULL; |
| 1503 | struct list_head *connector_list = |
| 1504 | &enc->dev->mode_config.connector_list; |
| 1505 | |
| 1506 | list_for_each_entry(conn, connector_list, head) |
| 1507 | if (conn->encoder == enc) |
| 1508 | return conn; |
| 1509 | |
| 1510 | return NULL; |
| 1511 | } |
| 1512 | |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 1513 | int sde_rm_update_topology(struct drm_connector_state *conn_state, |
| 1514 | struct msm_display_topology *topology) |
| 1515 | { |
| 1516 | int i, ret = 0; |
| 1517 | struct msm_display_topology top; |
| 1518 | enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE; |
| 1519 | |
| 1520 | if (!conn_state) |
| 1521 | return -EINVAL; |
| 1522 | |
| 1523 | if (topology) { |
| 1524 | top = *topology; |
| 1525 | for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) |
| 1526 | if (RM_IS_TOPOLOGY_MATCH(g_top_table[i], top)) { |
| 1527 | top_name = g_top_table[i].top_name; |
| 1528 | break; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | ret = msm_property_set_property( |
| 1533 | sde_connector_get_propinfo(conn_state->connector), |
| 1534 | sde_connector_get_property_state(conn_state), |
| 1535 | CONNECTOR_PROP_TOPOLOGY_NAME, top_name); |
| 1536 | |
| 1537 | return ret; |
| 1538 | } |
| 1539 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1540 | /** |
| 1541 | * _sde_rm_release_rsvp - release resources and release a reservation |
| 1542 | * @rm: KMS handle |
| 1543 | * @rsvp: RSVP pointer to release and release resources for |
| 1544 | */ |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1545 | static void _sde_rm_release_rsvp( |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1546 | struct sde_rm *rm, |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1547 | struct sde_rm_rsvp *rsvp, |
| 1548 | struct drm_connector *conn) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1549 | { |
| 1550 | struct sde_rm_rsvp *rsvp_c, *rsvp_n; |
| 1551 | struct sde_rm_hw_blk *blk; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1552 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1553 | |
| 1554 | if (!rsvp) |
| 1555 | return; |
| 1556 | |
| 1557 | SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id); |
| 1558 | |
| 1559 | list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) { |
| 1560 | if (rsvp == rsvp_c) { |
| 1561 | list_del(&rsvp_c->list); |
| 1562 | break; |
| 1563 | } |
| 1564 | } |
| 1565 | |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1566 | for (type = 0; type < SDE_HW_BLK_MAX; type++) { |
| 1567 | list_for_each_entry(blk, &rm->hw_blks[type], list) { |
| 1568 | if (blk->rsvp == rsvp) { |
| 1569 | blk->rsvp = NULL; |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 1570 | SDE_DEBUG("rel rsvp %d enc %d %d %d\n", |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1571 | rsvp->seq, rsvp->enc_id, |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 1572 | blk->type, blk->id); |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1573 | } |
| 1574 | if (blk->rsvp_nxt == rsvp) { |
| 1575 | blk->rsvp_nxt = NULL; |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 1576 | SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n", |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1577 | rsvp->seq, rsvp->enc_id, |
Lloyd Atkinson | ef50d8f | 2017-05-03 12:06:16 -0400 | [diff] [blame] | 1578 | blk->type, blk->id); |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1579 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | kfree(rsvp); |
| 1584 | } |
| 1585 | |
| 1586 | void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc) |
| 1587 | { |
| 1588 | struct sde_rm_rsvp *rsvp; |
| 1589 | struct drm_connector *conn; |
| 1590 | uint64_t top_ctrl; |
| 1591 | |
| 1592 | if (!rm || !enc) { |
| 1593 | SDE_ERROR("invalid params\n"); |
| 1594 | return; |
| 1595 | } |
| 1596 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1597 | mutex_lock(&rm->rm_lock); |
| 1598 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1599 | rsvp = _sde_rm_get_rsvp(rm, enc); |
| 1600 | if (!rsvp) { |
| 1601 | SDE_ERROR("failed to find rsvp for enc %d\n", enc->base.id); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1602 | goto end; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | conn = _sde_rm_get_connector(enc); |
| 1606 | if (!conn) { |
| 1607 | SDE_ERROR("failed to get connector for enc %d\n", enc->base.id); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1608 | goto end; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | top_ctrl = sde_connector_get_property(conn->state, |
| 1612 | CONNECTOR_PROP_TOPOLOGY_CONTROL); |
| 1613 | |
| 1614 | if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) { |
| 1615 | SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n", |
| 1616 | rsvp->seq, rsvp->enc_id); |
| 1617 | } else { |
| 1618 | SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq, |
| 1619 | rsvp->enc_id); |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1620 | _sde_rm_release_rsvp(rm, rsvp, conn); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1621 | } |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1622 | |
| 1623 | end: |
| 1624 | mutex_unlock(&rm->rm_lock); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | static int _sde_rm_commit_rsvp( |
| 1628 | struct sde_rm *rm, |
| 1629 | struct sde_rm_rsvp *rsvp, |
| 1630 | struct drm_connector_state *conn_state) |
| 1631 | { |
| 1632 | struct sde_rm_hw_blk *blk; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1633 | enum sde_hw_blk_type type; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1634 | int ret = 0; |
| 1635 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1636 | /* Swap next rsvp to be the active */ |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 1637 | for (type = 0; type < SDE_HW_BLK_MAX; type++) { |
| 1638 | list_for_each_entry(blk, &rm->hw_blks[type], list) { |
| 1639 | if (blk->rsvp_nxt) { |
| 1640 | blk->rsvp = blk->rsvp_nxt; |
| 1641 | blk->rsvp_nxt = NULL; |
| 1642 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | if (!ret) { |
| 1647 | SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id, |
| 1648 | rsvp->topology); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1649 | SDE_EVT32(rsvp->enc_id, rsvp->topology); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | return ret; |
| 1653 | } |
| 1654 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1655 | int sde_rm_reserve( |
| 1656 | struct sde_rm *rm, |
| 1657 | struct drm_encoder *enc, |
| 1658 | struct drm_crtc_state *crtc_state, |
| 1659 | struct drm_connector_state *conn_state, |
| 1660 | bool test_only) |
| 1661 | { |
| 1662 | struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt; |
| 1663 | struct sde_rm_requirements reqs; |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1664 | struct msm_drm_private *priv; |
| 1665 | struct sde_kms *sde_kms; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1666 | int ret; |
| 1667 | |
| 1668 | if (!rm || !enc || !crtc_state || !conn_state) { |
| 1669 | SDE_ERROR("invalid arguments\n"); |
| 1670 | return -EINVAL; |
| 1671 | } |
| 1672 | |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1673 | if (!enc->dev || !enc->dev->dev_private) { |
| 1674 | SDE_ERROR("drm device invalid\n"); |
| 1675 | return -EINVAL; |
| 1676 | } |
| 1677 | priv = enc->dev->dev_private; |
| 1678 | if (!priv->kms) { |
| 1679 | SDE_ERROR("invalid kms\n"); |
| 1680 | return -EINVAL; |
| 1681 | } |
| 1682 | sde_kms = to_sde_kms(priv->kms); |
| 1683 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1684 | /* Check if this is just a page-flip */ |
Chandan Uddaraju | 9efbbe3 | 2017-11-09 23:57:05 -0800 | [diff] [blame] | 1685 | if (!sde_kms->splash_data.cont_splash_en && |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1686 | !drm_atomic_crtc_needs_modeset(crtc_state)) |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1687 | return 0; |
| 1688 | |
| 1689 | SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n", |
| 1690 | conn_state->connector->base.id, enc->base.id, |
| 1691 | crtc_state->crtc->base.id, test_only); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1692 | SDE_EVT32(enc->base.id, conn_state->connector->base.id); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1693 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1694 | mutex_lock(&rm->rm_lock); |
| 1695 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1696 | _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1697 | |
| 1698 | ret = _sde_rm_populate_requirements(rm, enc, crtc_state, |
| 1699 | conn_state, &reqs); |
| 1700 | if (ret) { |
| 1701 | SDE_ERROR("failed to populate hw requirements\n"); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1702 | goto end; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /* |
| 1706 | * We only support one active reservation per-hw-block. But to implement |
| 1707 | * transactional semantics for test-only, and for allowing failure while |
| 1708 | * modifying your existing reservation, over the course of this |
| 1709 | * function we can have two reservations: |
| 1710 | * Current: Existing reservation |
| 1711 | * Next: Proposed reservation. The proposed reservation may fail, or may |
| 1712 | * be discarded if in test-only mode. |
| 1713 | * If reservation is successful, and we're not in test-only, then we |
| 1714 | * replace the current with the next. |
| 1715 | */ |
| 1716 | rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL); |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1717 | if (!rsvp_nxt) { |
| 1718 | ret = -ENOMEM; |
| 1719 | goto end; |
| 1720 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1721 | |
| 1722 | rsvp_cur = _sde_rm_get_rsvp(rm, enc); |
| 1723 | |
| 1724 | /* |
| 1725 | * User can request that we clear out any reservation during the |
| 1726 | * atomic_check phase by using this CLEAR bit |
| 1727 | */ |
| 1728 | if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) { |
| 1729 | SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n", |
| 1730 | rsvp_cur->seq, rsvp_cur->enc_id); |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1731 | _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1732 | rsvp_cur = NULL; |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1733 | _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /* Check the proposed reservation, store it in hw's "next" field */ |
Chandan Uddaraju | 9efbbe3 | 2017-11-09 23:57:05 -0800 | [diff] [blame] | 1737 | if (sde_kms->splash_data.cont_splash_en) { |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1738 | SDE_DEBUG("cont_splash feature enabled\n"); |
| 1739 | ret = _sde_rm_make_next_rsvp_for_cont_splash |
| 1740 | (rm, enc, crtc_state, conn_state, rsvp_nxt, &reqs); |
| 1741 | } else { |
| 1742 | ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1743 | rsvp_nxt, &reqs); |
Chandan Uddaraju | bf4927d | 2017-10-05 15:36:32 -0700 | [diff] [blame] | 1744 | } |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1745 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1746 | _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1747 | |
| 1748 | if (ret) { |
| 1749 | SDE_ERROR("failed to reserve hw resources: %d\n", ret); |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1750 | _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1751 | } else if (test_only && !RM_RQ_LOCK(&reqs)) { |
| 1752 | /* |
| 1753 | * Normally, if test_only, test the reservation and then undo |
| 1754 | * However, if the user requests LOCK, then keep the reservation |
| 1755 | * made during the atomic_check phase. |
| 1756 | */ |
| 1757 | SDE_DEBUG("test_only: discard test rsvp[s%de%d]\n", |
| 1758 | rsvp_nxt->seq, rsvp_nxt->enc_id); |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1759 | _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1760 | } else { |
| 1761 | if (test_only && RM_RQ_LOCK(&reqs)) |
| 1762 | SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n", |
| 1763 | rsvp_nxt->seq, rsvp_nxt->enc_id); |
| 1764 | |
Lloyd Atkinson | 9cb3f9e | 2016-09-22 12:55:39 -0400 | [diff] [blame] | 1765 | _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1766 | |
| 1767 | ret = _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state); |
| 1768 | } |
| 1769 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1770 | _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL); |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1771 | |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 1772 | end: |
| 1773 | mutex_unlock(&rm->rm_lock); |
| 1774 | |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1775 | return ret; |
| 1776 | } |