1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved. 4 * Copyright (C) 2013 Red Hat 5 * Author: Rob Clark <robdclark@gmail.com> 6 */ 7 8 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ 9 #include <linux/sort.h> 10 #include <linux/debugfs.h> 11 #include <linux/ktime.h> 12 #include <drm/drm_crtc.h> 13 #include <drm/drm_flip_work.h> 14 #include <drm/drm_mode.h> 15 #include <drm/drm_probe_helper.h> 16 #include <drm/drm_rect.h> 17 18 #include "dpu_kms.h" 19 #include "dpu_hw_lm.h" 20 #include "dpu_hw_ctl.h" 21 #include "dpu_crtc.h" 22 #include "dpu_plane.h" 23 #include "dpu_encoder.h" 24 #include "dpu_vbif.h" 25 #include "dpu_core_perf.h" 26 #include "dpu_trace.h" 27 28 #define DPU_DRM_BLEND_OP_NOT_DEFINED 0 29 #define DPU_DRM_BLEND_OP_OPAQUE 1 30 #define DPU_DRM_BLEND_OP_PREMULTIPLIED 2 31 #define DPU_DRM_BLEND_OP_COVERAGE 3 32 #define DPU_DRM_BLEND_OP_MAX 4 33 34 /* layer mixer index on dpu_crtc */ 35 #define LEFT_MIXER 0 36 #define RIGHT_MIXER 1 37 38 /* timeout in ms waiting for frame done */ 39 #define DPU_CRTC_FRAME_DONE_TIMEOUT_MS 60 40 41 static struct dpu_kms *_dpu_crtc_get_kms(struct drm_crtc *crtc) 42 { 43 struct msm_drm_private *priv = crtc->dev->dev_private; 44 45 return to_dpu_kms(priv->kms); 46 } 47 48 static void dpu_crtc_destroy(struct drm_crtc *crtc) 49 { 50 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 51 52 DPU_DEBUG("\n"); 53 54 if (!crtc) 55 return; 56 57 drm_crtc_cleanup(crtc); 58 kfree(dpu_crtc); 59 } 60 61 static void _dpu_crtc_setup_blend_cfg(struct dpu_crtc_mixer *mixer, 62 struct dpu_plane_state *pstate, struct dpu_format *format) 63 { 64 struct dpu_hw_mixer *lm = mixer->hw_lm; 65 uint32_t blend_op; 66 struct drm_format_name_buf format_name; 67 68 /* default to opaque blending */ 69 blend_op = DPU_BLEND_FG_ALPHA_FG_CONST | 70 DPU_BLEND_BG_ALPHA_BG_CONST; 71 72 if (format->alpha_enable) { 73 /* coverage blending */ 74 blend_op = DPU_BLEND_FG_ALPHA_FG_PIXEL | 75 DPU_BLEND_BG_ALPHA_FG_PIXEL | 76 DPU_BLEND_BG_INV_ALPHA; 77 } 78 79 lm->ops.setup_blend_config(lm, pstate->stage, 80 0xFF, 0, blend_op); 81 82 DPU_DEBUG("format:%s, alpha_en:%u blend_op:0x%x\n", 83 drm_get_format_name(format->base.pixel_format, &format_name), 84 format->alpha_enable, blend_op); 85 } 86 87 static void _dpu_crtc_program_lm_output_roi(struct drm_crtc *crtc) 88 { 89 struct dpu_crtc *dpu_crtc; 90 struct dpu_crtc_state *crtc_state; 91 int lm_idx, lm_horiz_position; 92 93 dpu_crtc = to_dpu_crtc(crtc); 94 crtc_state = to_dpu_crtc_state(crtc->state); 95 96 lm_horiz_position = 0; 97 for (lm_idx = 0; lm_idx < crtc_state->num_mixers; lm_idx++) { 98 const struct drm_rect *lm_roi = &crtc_state->lm_bounds[lm_idx]; 99 struct dpu_hw_mixer *hw_lm = crtc_state->mixers[lm_idx].hw_lm; 100 struct dpu_hw_mixer_cfg cfg; 101 102 if (!lm_roi || !drm_rect_visible(lm_roi)) 103 continue; 104 105 cfg.out_width = drm_rect_width(lm_roi); 106 cfg.out_height = drm_rect_height(lm_roi); 107 cfg.right_mixer = lm_horiz_position++; 108 cfg.flags = 0; 109 hw_lm->ops.setup_mixer_out(hw_lm, &cfg); 110 } 111 } 112 113 static void _dpu_crtc_blend_setup_mixer(struct drm_crtc *crtc, 114 struct dpu_crtc *dpu_crtc, struct dpu_crtc_mixer *mixer) 115 { 116 struct drm_plane *plane; 117 struct drm_framebuffer *fb; 118 struct drm_plane_state *state; 119 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state); 120 struct dpu_plane_state *pstate = NULL; 121 struct dpu_format *format; 122 struct dpu_hw_ctl *ctl = mixer->lm_ctl; 123 struct dpu_hw_stage_cfg *stage_cfg = &dpu_crtc->stage_cfg; 124 125 u32 flush_mask; 126 uint32_t stage_idx, lm_idx; 127 int zpos_cnt[DPU_STAGE_MAX + 1] = { 0 }; 128 bool bg_alpha_enable = false; 129 130 drm_atomic_crtc_for_each_plane(plane, crtc) { 131 state = plane->state; 132 if (!state) 133 continue; 134 135 pstate = to_dpu_plane_state(state); 136 fb = state->fb; 137 138 dpu_plane_get_ctl_flush(plane, ctl, &flush_mask); 139 140 DPU_DEBUG("crtc %d stage:%d - plane %d sspp %d fb %d\n", 141 crtc->base.id, 142 pstate->stage, 143 plane->base.id, 144 dpu_plane_pipe(plane) - SSPP_VIG0, 145 state->fb ? state->fb->base.id : -1); 146 147 format = to_dpu_format(msm_framebuffer_format(pstate->base.fb)); 148 149 if (pstate->stage == DPU_STAGE_BASE && format->alpha_enable) 150 bg_alpha_enable = true; 151 152 stage_idx = zpos_cnt[pstate->stage]++; 153 stage_cfg->stage[pstate->stage][stage_idx] = 154 dpu_plane_pipe(plane); 155 stage_cfg->multirect_index[pstate->stage][stage_idx] = 156 pstate->multirect_index; 157 158 trace_dpu_crtc_setup_mixer(DRMID(crtc), DRMID(plane), 159 state, pstate, stage_idx, 160 dpu_plane_pipe(plane) - SSPP_VIG0, 161 format->base.pixel_format, 162 fb ? fb->modifier : 0); 163 164 /* blend config update */ 165 for (lm_idx = 0; lm_idx < cstate->num_mixers; lm_idx++) { 166 _dpu_crtc_setup_blend_cfg(mixer + lm_idx, 167 pstate, format); 168 169 mixer[lm_idx].flush_mask |= flush_mask; 170 171 if (bg_alpha_enable && !format->alpha_enable) 172 mixer[lm_idx].mixer_op_mode = 0; 173 else 174 mixer[lm_idx].mixer_op_mode |= 175 1 << pstate->stage; 176 } 177 } 178 179 _dpu_crtc_program_lm_output_roi(crtc); 180 } 181 182 /** 183 * _dpu_crtc_blend_setup - configure crtc mixers 184 * @crtc: Pointer to drm crtc structure 185 */ 186 static void _dpu_crtc_blend_setup(struct drm_crtc *crtc) 187 { 188 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 189 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state); 190 struct dpu_crtc_mixer *mixer = cstate->mixers; 191 struct dpu_hw_ctl *ctl; 192 struct dpu_hw_mixer *lm; 193 int i; 194 195 DPU_DEBUG("%s\n", dpu_crtc->name); 196 197 for (i = 0; i < cstate->num_mixers; i++) { 198 if (!mixer[i].hw_lm || !mixer[i].lm_ctl) { 199 DPU_ERROR("invalid lm or ctl assigned to mixer\n"); 200 return; 201 } 202 mixer[i].mixer_op_mode = 0; 203 mixer[i].flush_mask = 0; 204 if (mixer[i].lm_ctl->ops.clear_all_blendstages) 205 mixer[i].lm_ctl->ops.clear_all_blendstages( 206 mixer[i].lm_ctl); 207 } 208 209 /* initialize stage cfg */ 210 memset(&dpu_crtc->stage_cfg, 0, sizeof(struct dpu_hw_stage_cfg)); 211 212 _dpu_crtc_blend_setup_mixer(crtc, dpu_crtc, mixer); 213 214 for (i = 0; i < cstate->num_mixers; i++) { 215 ctl = mixer[i].lm_ctl; 216 lm = mixer[i].hw_lm; 217 218 lm->ops.setup_alpha_out(lm, mixer[i].mixer_op_mode); 219 220 mixer[i].flush_mask |= ctl->ops.get_bitmask_mixer(ctl, 221 mixer[i].hw_lm->idx); 222 223 /* stage config flush mask */ 224 ctl->ops.update_pending_flush(ctl, mixer[i].flush_mask); 225 226 DPU_DEBUG("lm %d, op_mode 0x%X, ctl %d, flush mask 0x%x\n", 227 mixer[i].hw_lm->idx - LM_0, 228 mixer[i].mixer_op_mode, 229 ctl->idx - CTL_0, 230 mixer[i].flush_mask); 231 232 ctl->ops.setup_blendstage(ctl, mixer[i].hw_lm->idx, 233 &dpu_crtc->stage_cfg); 234 } 235 } 236 237 /** 238 * _dpu_crtc_complete_flip - signal pending page_flip events 239 * Any pending vblank events are added to the vblank_event_list 240 * so that the next vblank interrupt shall signal them. 241 * However PAGE_FLIP events are not handled through the vblank_event_list. 242 * This API signals any pending PAGE_FLIP events requested through 243 * DRM_IOCTL_MODE_PAGE_FLIP and are cached in the dpu_crtc->event. 244 * @crtc: Pointer to drm crtc structure 245 */ 246 static void _dpu_crtc_complete_flip(struct drm_crtc *crtc) 247 { 248 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 249 struct drm_device *dev = crtc->dev; 250 unsigned long flags; 251 252 spin_lock_irqsave(&dev->event_lock, flags); 253 if (dpu_crtc->event) { 254 DRM_DEBUG_VBL("%s: send event: %pK\n", dpu_crtc->name, 255 dpu_crtc->event); 256 trace_dpu_crtc_complete_flip(DRMID(crtc)); 257 drm_crtc_send_vblank_event(crtc, dpu_crtc->event); 258 dpu_crtc->event = NULL; 259 } 260 spin_unlock_irqrestore(&dev->event_lock, flags); 261 } 262 263 enum dpu_intf_mode dpu_crtc_get_intf_mode(struct drm_crtc *crtc) 264 { 265 struct drm_encoder *encoder; 266 267 if (!crtc || !crtc->dev) { 268 DPU_ERROR("invalid crtc\n"); 269 return INTF_MODE_NONE; 270 } 271 272 WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); 273 274 /* TODO: Returns the first INTF_MODE, could there be multiple values? */ 275 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 276 return dpu_encoder_get_intf_mode(encoder); 277 278 return INTF_MODE_NONE; 279 } 280 281 void dpu_crtc_vblank_callback(struct drm_crtc *crtc) 282 { 283 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 284 285 /* keep statistics on vblank callback - with auto reset via debugfs */ 286 if (ktime_compare(dpu_crtc->vblank_cb_time, ktime_set(0, 0)) == 0) 287 dpu_crtc->vblank_cb_time = ktime_get(); 288 else 289 dpu_crtc->vblank_cb_count++; 290 _dpu_crtc_complete_flip(crtc); 291 drm_crtc_handle_vblank(crtc); 292 trace_dpu_crtc_vblank_cb(DRMID(crtc)); 293 } 294 295 static void dpu_crtc_release_bw_unlocked(struct drm_crtc *crtc) 296 { 297 int ret = 0; 298 struct drm_modeset_acquire_ctx ctx; 299 300 DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, ret); 301 dpu_core_perf_crtc_release_bw(crtc); 302 DRM_MODESET_LOCK_ALL_END(ctx, ret); 303 if (ret) 304 DRM_ERROR("Failed to acquire modeset locks to release bw, %d\n", 305 ret); 306 } 307 308 static void dpu_crtc_frame_event_work(struct kthread_work *work) 309 { 310 struct dpu_crtc_frame_event *fevent = container_of(work, 311 struct dpu_crtc_frame_event, work); 312 struct drm_crtc *crtc = fevent->crtc; 313 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 314 unsigned long flags; 315 bool frame_done = false; 316 317 DPU_ATRACE_BEGIN("crtc_frame_event"); 318 319 DRM_DEBUG_KMS("crtc%d event:%u ts:%lld\n", crtc->base.id, fevent->event, 320 ktime_to_ns(fevent->ts)); 321 322 if (fevent->event & (DPU_ENCODER_FRAME_EVENT_DONE 323 | DPU_ENCODER_FRAME_EVENT_ERROR 324 | DPU_ENCODER_FRAME_EVENT_PANEL_DEAD)) { 325 326 if (atomic_read(&dpu_crtc->frame_pending) < 1) { 327 /* this should not happen */ 328 DRM_ERROR("crtc%d ev:%u ts:%lld frame_pending:%d\n", 329 crtc->base.id, 330 fevent->event, 331 ktime_to_ns(fevent->ts), 332 atomic_read(&dpu_crtc->frame_pending)); 333 } else if (atomic_dec_return(&dpu_crtc->frame_pending) == 0) { 334 /* release bandwidth and other resources */ 335 trace_dpu_crtc_frame_event_done(DRMID(crtc), 336 fevent->event); 337 dpu_crtc_release_bw_unlocked(crtc); 338 } else { 339 trace_dpu_crtc_frame_event_more_pending(DRMID(crtc), 340 fevent->event); 341 } 342 343 if (fevent->event & DPU_ENCODER_FRAME_EVENT_DONE) 344 dpu_core_perf_crtc_update(crtc, 0, false); 345 346 if (fevent->event & (DPU_ENCODER_FRAME_EVENT_DONE 347 | DPU_ENCODER_FRAME_EVENT_ERROR)) 348 frame_done = true; 349 } 350 351 if (fevent->event & DPU_ENCODER_FRAME_EVENT_PANEL_DEAD) 352 DPU_ERROR("crtc%d ts:%lld received panel dead event\n", 353 crtc->base.id, ktime_to_ns(fevent->ts)); 354 355 if (frame_done) 356 complete_all(&dpu_crtc->frame_done_comp); 357 358 spin_lock_irqsave(&dpu_crtc->spin_lock, flags); 359 list_add_tail(&fevent->list, &dpu_crtc->frame_event_list); 360 spin_unlock_irqrestore(&dpu_crtc->spin_lock, flags); 361 DPU_ATRACE_END("crtc_frame_event"); 362 } 363 364 /* 365 * dpu_crtc_frame_event_cb - crtc frame event callback API. CRTC module 366 * registers this API to encoder for all frame event callbacks like 367 * frame_error, frame_done, idle_timeout, etc. Encoder may call different events 368 * from different context - IRQ, user thread, commit_thread, etc. Each event 369 * should be carefully reviewed and should be processed in proper task context 370 * to avoid schedulin delay or properly manage the irq context's bottom half 371 * processing. 372 */ 373 static void dpu_crtc_frame_event_cb(void *data, u32 event) 374 { 375 struct drm_crtc *crtc = (struct drm_crtc *)data; 376 struct dpu_crtc *dpu_crtc; 377 struct msm_drm_private *priv; 378 struct dpu_crtc_frame_event *fevent; 379 unsigned long flags; 380 u32 crtc_id; 381 382 /* Nothing to do on idle event */ 383 if (event & DPU_ENCODER_FRAME_EVENT_IDLE) 384 return; 385 386 dpu_crtc = to_dpu_crtc(crtc); 387 priv = crtc->dev->dev_private; 388 crtc_id = drm_crtc_index(crtc); 389 390 trace_dpu_crtc_frame_event_cb(DRMID(crtc), event); 391 392 spin_lock_irqsave(&dpu_crtc->spin_lock, flags); 393 fevent = list_first_entry_or_null(&dpu_crtc->frame_event_list, 394 struct dpu_crtc_frame_event, list); 395 if (fevent) 396 list_del_init(&fevent->list); 397 spin_unlock_irqrestore(&dpu_crtc->spin_lock, flags); 398 399 if (!fevent) { 400 DRM_ERROR("crtc%d event %d overflow\n", crtc->base.id, event); 401 return; 402 } 403 404 fevent->event = event; 405 fevent->crtc = crtc; 406 fevent->ts = ktime_get(); 407 kthread_queue_work(&priv->event_thread[crtc_id].worker, &fevent->work); 408 } 409 410 void dpu_crtc_complete_commit(struct drm_crtc *crtc, 411 struct drm_crtc_state *old_state) 412 { 413 if (!crtc || !crtc->state) { 414 DPU_ERROR("invalid crtc\n"); 415 return; 416 } 417 trace_dpu_crtc_complete_commit(DRMID(crtc)); 418 } 419 420 static void _dpu_crtc_setup_lm_bounds(struct drm_crtc *crtc, 421 struct drm_crtc_state *state) 422 { 423 struct dpu_crtc_state *cstate = to_dpu_crtc_state(state); 424 struct drm_display_mode *adj_mode = &state->adjusted_mode; 425 u32 crtc_split_width = adj_mode->hdisplay / cstate->num_mixers; 426 int i; 427 428 for (i = 0; i < cstate->num_mixers; i++) { 429 struct drm_rect *r = &cstate->lm_bounds[i]; 430 r->x1 = crtc_split_width * i; 431 r->y1 = 0; 432 r->x2 = r->x1 + crtc_split_width; 433 r->y2 = adj_mode->vdisplay; 434 435 trace_dpu_crtc_setup_lm_bounds(DRMID(crtc), i, r); 436 } 437 438 drm_mode_debug_printmodeline(adj_mode); 439 } 440 441 static void dpu_crtc_atomic_begin(struct drm_crtc *crtc, 442 struct drm_crtc_state *old_state) 443 { 444 struct dpu_crtc *dpu_crtc; 445 struct dpu_crtc_state *cstate; 446 struct drm_encoder *encoder; 447 struct drm_device *dev; 448 unsigned long flags; 449 struct dpu_crtc_smmu_state_data *smmu_state; 450 451 if (!crtc) { 452 DPU_ERROR("invalid crtc\n"); 453 return; 454 } 455 456 if (!crtc->state->enable) { 457 DPU_DEBUG("crtc%d -> enable %d, skip atomic_begin\n", 458 crtc->base.id, crtc->state->enable); 459 return; 460 } 461 462 DPU_DEBUG("crtc%d\n", crtc->base.id); 463 464 dpu_crtc = to_dpu_crtc(crtc); 465 cstate = to_dpu_crtc_state(crtc->state); 466 dev = crtc->dev; 467 smmu_state = &dpu_crtc->smmu_state; 468 469 _dpu_crtc_setup_lm_bounds(crtc, crtc->state); 470 471 if (dpu_crtc->event) { 472 WARN_ON(dpu_crtc->event); 473 } else { 474 spin_lock_irqsave(&dev->event_lock, flags); 475 dpu_crtc->event = crtc->state->event; 476 crtc->state->event = NULL; 477 spin_unlock_irqrestore(&dev->event_lock, flags); 478 } 479 480 /* encoder will trigger pending mask now */ 481 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 482 dpu_encoder_trigger_kickoff_pending(encoder); 483 484 /* 485 * If no mixers have been allocated in dpu_crtc_atomic_check(), 486 * it means we are trying to flush a CRTC whose state is disabled: 487 * nothing else needs to be done. 488 */ 489 if (unlikely(!cstate->num_mixers)) 490 return; 491 492 _dpu_crtc_blend_setup(crtc); 493 494 /* 495 * PP_DONE irq is only used by command mode for now. 496 * It is better to request pending before FLUSH and START trigger 497 * to make sure no pp_done irq missed. 498 * This is safe because no pp_done will happen before SW trigger 499 * in command mode. 500 */ 501 } 502 503 static void dpu_crtc_atomic_flush(struct drm_crtc *crtc, 504 struct drm_crtc_state *old_crtc_state) 505 { 506 struct dpu_crtc *dpu_crtc; 507 struct drm_device *dev; 508 struct drm_plane *plane; 509 struct msm_drm_private *priv; 510 struct msm_drm_thread *event_thread; 511 unsigned long flags; 512 struct dpu_crtc_state *cstate; 513 514 if (!crtc->state->enable) { 515 DPU_DEBUG("crtc%d -> enable %d, skip atomic_flush\n", 516 crtc->base.id, crtc->state->enable); 517 return; 518 } 519 520 DPU_DEBUG("crtc%d\n", crtc->base.id); 521 522 dpu_crtc = to_dpu_crtc(crtc); 523 cstate = to_dpu_crtc_state(crtc->state); 524 dev = crtc->dev; 525 priv = dev->dev_private; 526 527 if (crtc->index >= ARRAY_SIZE(priv->event_thread)) { 528 DPU_ERROR("invalid crtc index[%d]\n", crtc->index); 529 return; 530 } 531 532 event_thread = &priv->event_thread[crtc->index]; 533 534 if (dpu_crtc->event) { 535 DPU_DEBUG("already received dpu_crtc->event\n"); 536 } else { 537 spin_lock_irqsave(&dev->event_lock, flags); 538 dpu_crtc->event = crtc->state->event; 539 crtc->state->event = NULL; 540 spin_unlock_irqrestore(&dev->event_lock, flags); 541 } 542 543 /* 544 * If no mixers has been allocated in dpu_crtc_atomic_check(), 545 * it means we are trying to flush a CRTC whose state is disabled: 546 * nothing else needs to be done. 547 */ 548 if (unlikely(!cstate->num_mixers)) 549 return; 550 551 /* 552 * For planes without commit update, drm framework will not add 553 * those planes to current state since hardware update is not 554 * required. However, if those planes were power collapsed since 555 * last commit cycle, driver has to restore the hardware state 556 * of those planes explicitly here prior to plane flush. 557 */ 558 drm_atomic_crtc_for_each_plane(plane, crtc) 559 dpu_plane_restore(plane); 560 561 /* update performance setting before crtc kickoff */ 562 dpu_core_perf_crtc_update(crtc, 1, false); 563 564 /* 565 * Final plane updates: Give each plane a chance to complete all 566 * required writes/flushing before crtc's "flush 567 * everything" call below. 568 */ 569 drm_atomic_crtc_for_each_plane(plane, crtc) { 570 if (dpu_crtc->smmu_state.transition_error) 571 dpu_plane_set_error(plane, true); 572 dpu_plane_flush(plane); 573 } 574 575 /* Kickoff will be scheduled by outer layer */ 576 } 577 578 /** 579 * dpu_crtc_destroy_state - state destroy hook 580 * @crtc: drm CRTC 581 * @state: CRTC state object to release 582 */ 583 static void dpu_crtc_destroy_state(struct drm_crtc *crtc, 584 struct drm_crtc_state *state) 585 { 586 struct dpu_crtc *dpu_crtc; 587 struct dpu_crtc_state *cstate; 588 589 if (!crtc || !state) { 590 DPU_ERROR("invalid argument(s)\n"); 591 return; 592 } 593 594 dpu_crtc = to_dpu_crtc(crtc); 595 cstate = to_dpu_crtc_state(state); 596 597 DPU_DEBUG("crtc%d\n", crtc->base.id); 598 599 __drm_atomic_helper_crtc_destroy_state(state); 600 601 kfree(cstate); 602 } 603 604 static int _dpu_crtc_wait_for_frame_done(struct drm_crtc *crtc) 605 { 606 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 607 int ret, rc = 0; 608 609 if (!atomic_read(&dpu_crtc->frame_pending)) { 610 DPU_DEBUG("no frames pending\n"); 611 return 0; 612 } 613 614 DPU_ATRACE_BEGIN("frame done completion wait"); 615 ret = wait_for_completion_timeout(&dpu_crtc->frame_done_comp, 616 msecs_to_jiffies(DPU_CRTC_FRAME_DONE_TIMEOUT_MS)); 617 if (!ret) { 618 DRM_ERROR("frame done wait timed out, ret:%d\n", ret); 619 rc = -ETIMEDOUT; 620 } 621 DPU_ATRACE_END("frame done completion wait"); 622 623 return rc; 624 } 625 626 void dpu_crtc_commit_kickoff(struct drm_crtc *crtc, bool async) 627 { 628 struct drm_encoder *encoder; 629 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 630 struct dpu_kms *dpu_kms = _dpu_crtc_get_kms(crtc); 631 struct dpu_crtc_state *cstate = to_dpu_crtc_state(crtc->state); 632 int ret; 633 634 /* 635 * If no mixers has been allocated in dpu_crtc_atomic_check(), 636 * it means we are trying to start a CRTC whose state is disabled: 637 * nothing else needs to be done. 638 */ 639 if (unlikely(!cstate->num_mixers)) 640 return; 641 642 DPU_ATRACE_BEGIN("crtc_commit"); 643 644 /* 645 * Encoder will flush/start now, unless it has a tx pending. If so, it 646 * may delay and flush at an irq event (e.g. ppdone) 647 */ 648 drm_for_each_encoder_mask(encoder, crtc->dev, 649 crtc->state->encoder_mask) 650 dpu_encoder_prepare_for_kickoff(encoder, async); 651 652 if (!async) { 653 /* wait for frame_event_done completion */ 654 DPU_ATRACE_BEGIN("wait_for_frame_done_event"); 655 ret = _dpu_crtc_wait_for_frame_done(crtc); 656 DPU_ATRACE_END("wait_for_frame_done_event"); 657 if (ret) { 658 DPU_ERROR("crtc%d wait for frame done failed;frame_pending%d\n", 659 crtc->base.id, 660 atomic_read(&dpu_crtc->frame_pending)); 661 goto end; 662 } 663 664 if (atomic_inc_return(&dpu_crtc->frame_pending) == 1) { 665 /* acquire bandwidth and other resources */ 666 DPU_DEBUG("crtc%d first commit\n", crtc->base.id); 667 } else 668 DPU_DEBUG("crtc%d commit\n", crtc->base.id); 669 670 dpu_crtc->play_count++; 671 } 672 673 dpu_vbif_clear_errors(dpu_kms); 674 675 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 676 dpu_encoder_kickoff(encoder, async); 677 678 end: 679 if (!async) 680 reinit_completion(&dpu_crtc->frame_done_comp); 681 DPU_ATRACE_END("crtc_commit"); 682 } 683 684 static void dpu_crtc_reset(struct drm_crtc *crtc) 685 { 686 struct dpu_crtc_state *cstate; 687 688 if (crtc->state) 689 dpu_crtc_destroy_state(crtc, crtc->state); 690 691 crtc->state = kzalloc(sizeof(*cstate), GFP_KERNEL); 692 if (crtc->state) 693 crtc->state->crtc = crtc; 694 } 695 696 /** 697 * dpu_crtc_duplicate_state - state duplicate hook 698 * @crtc: Pointer to drm crtc structure 699 * @Returns: Pointer to new drm_crtc_state structure 700 */ 701 static struct drm_crtc_state *dpu_crtc_duplicate_state(struct drm_crtc *crtc) 702 { 703 struct dpu_crtc *dpu_crtc; 704 struct dpu_crtc_state *cstate, *old_cstate; 705 706 if (!crtc || !crtc->state) { 707 DPU_ERROR("invalid argument(s)\n"); 708 return NULL; 709 } 710 711 dpu_crtc = to_dpu_crtc(crtc); 712 old_cstate = to_dpu_crtc_state(crtc->state); 713 cstate = kmemdup(old_cstate, sizeof(*old_cstate), GFP_KERNEL); 714 if (!cstate) { 715 DPU_ERROR("failed to allocate state\n"); 716 return NULL; 717 } 718 719 /* duplicate base helper */ 720 __drm_atomic_helper_crtc_duplicate_state(crtc, &cstate->base); 721 722 return &cstate->base; 723 } 724 725 static void dpu_crtc_disable(struct drm_crtc *crtc, 726 struct drm_crtc_state *old_crtc_state) 727 { 728 struct dpu_crtc *dpu_crtc; 729 struct dpu_crtc_state *cstate; 730 struct drm_display_mode *mode; 731 struct drm_encoder *encoder; 732 struct msm_drm_private *priv; 733 unsigned long flags; 734 735 if (!crtc || !crtc->dev || !crtc->dev->dev_private || !crtc->state) { 736 DPU_ERROR("invalid crtc\n"); 737 return; 738 } 739 dpu_crtc = to_dpu_crtc(crtc); 740 cstate = to_dpu_crtc_state(crtc->state); 741 mode = &cstate->base.adjusted_mode; 742 priv = crtc->dev->dev_private; 743 744 DRM_DEBUG_KMS("crtc%d\n", crtc->base.id); 745 746 /* Disable/save vblank irq handling */ 747 drm_crtc_vblank_off(crtc); 748 749 drm_for_each_encoder_mask(encoder, crtc->dev, 750 old_crtc_state->encoder_mask) 751 dpu_encoder_assign_crtc(encoder, NULL); 752 753 /* wait for frame_event_done completion */ 754 if (_dpu_crtc_wait_for_frame_done(crtc)) 755 DPU_ERROR("crtc%d wait for frame done failed;frame_pending%d\n", 756 crtc->base.id, 757 atomic_read(&dpu_crtc->frame_pending)); 758 759 trace_dpu_crtc_disable(DRMID(crtc), false, dpu_crtc); 760 dpu_crtc->enabled = false; 761 762 if (atomic_read(&dpu_crtc->frame_pending)) { 763 trace_dpu_crtc_disable_frame_pending(DRMID(crtc), 764 atomic_read(&dpu_crtc->frame_pending)); 765 dpu_core_perf_crtc_release_bw(crtc); 766 atomic_set(&dpu_crtc->frame_pending, 0); 767 } 768 769 dpu_core_perf_crtc_update(crtc, 0, true); 770 771 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 772 dpu_encoder_register_frame_event_callback(encoder, NULL, NULL); 773 774 memset(cstate->mixers, 0, sizeof(cstate->mixers)); 775 cstate->num_mixers = 0; 776 777 /* disable clk & bw control until clk & bw properties are set */ 778 cstate->bw_control = false; 779 cstate->bw_split_vote = false; 780 781 if (crtc->state->event && !crtc->state->active) { 782 spin_lock_irqsave(&crtc->dev->event_lock, flags); 783 drm_crtc_send_vblank_event(crtc, crtc->state->event); 784 crtc->state->event = NULL; 785 spin_unlock_irqrestore(&crtc->dev->event_lock, flags); 786 } 787 788 pm_runtime_put_sync(crtc->dev->dev); 789 } 790 791 static void dpu_crtc_enable(struct drm_crtc *crtc, 792 struct drm_crtc_state *old_crtc_state) 793 { 794 struct dpu_crtc *dpu_crtc; 795 struct drm_encoder *encoder; 796 struct msm_drm_private *priv; 797 798 if (!crtc || !crtc->dev || !crtc->dev->dev_private) { 799 DPU_ERROR("invalid crtc\n"); 800 return; 801 } 802 priv = crtc->dev->dev_private; 803 804 pm_runtime_get_sync(crtc->dev->dev); 805 806 DRM_DEBUG_KMS("crtc%d\n", crtc->base.id); 807 dpu_crtc = to_dpu_crtc(crtc); 808 809 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 810 dpu_encoder_register_frame_event_callback(encoder, 811 dpu_crtc_frame_event_cb, (void *)crtc); 812 813 trace_dpu_crtc_enable(DRMID(crtc), true, dpu_crtc); 814 dpu_crtc->enabled = true; 815 816 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) 817 dpu_encoder_assign_crtc(encoder, crtc); 818 819 /* Enable/restore vblank irq handling */ 820 drm_crtc_vblank_on(crtc); 821 } 822 823 struct plane_state { 824 struct dpu_plane_state *dpu_pstate; 825 const struct drm_plane_state *drm_pstate; 826 int stage; 827 u32 pipe_id; 828 }; 829 830 static int dpu_crtc_atomic_check(struct drm_crtc *crtc, 831 struct drm_crtc_state *state) 832 { 833 struct dpu_crtc *dpu_crtc; 834 struct plane_state *pstates; 835 struct dpu_crtc_state *cstate; 836 837 const struct drm_plane_state *pstate; 838 struct drm_plane *plane; 839 struct drm_display_mode *mode; 840 841 int cnt = 0, rc = 0, mixer_width, i, z_pos; 842 843 struct dpu_multirect_plane_states multirect_plane[DPU_STAGE_MAX * 2]; 844 int multirect_count = 0; 845 const struct drm_plane_state *pipe_staged[SSPP_MAX]; 846 int left_zpos_cnt = 0, right_zpos_cnt = 0; 847 struct drm_rect crtc_rect = { 0 }; 848 849 if (!crtc) { 850 DPU_ERROR("invalid crtc\n"); 851 return -EINVAL; 852 } 853 854 pstates = kzalloc(sizeof(*pstates) * DPU_STAGE_MAX * 4, GFP_KERNEL); 855 856 dpu_crtc = to_dpu_crtc(crtc); 857 cstate = to_dpu_crtc_state(state); 858 859 if (!state->enable || !state->active) { 860 DPU_DEBUG("crtc%d -> enable %d, active %d, skip atomic_check\n", 861 crtc->base.id, state->enable, state->active); 862 goto end; 863 } 864 865 mode = &state->adjusted_mode; 866 DPU_DEBUG("%s: check", dpu_crtc->name); 867 868 /* force a full mode set if active state changed */ 869 if (state->active_changed) 870 state->mode_changed = true; 871 872 memset(pipe_staged, 0, sizeof(pipe_staged)); 873 874 mixer_width = mode->hdisplay / cstate->num_mixers; 875 876 _dpu_crtc_setup_lm_bounds(crtc, state); 877 878 crtc_rect.x2 = mode->hdisplay; 879 crtc_rect.y2 = mode->vdisplay; 880 881 /* get plane state for all drm planes associated with crtc state */ 882 drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { 883 struct drm_rect dst, clip = crtc_rect; 884 885 if (IS_ERR_OR_NULL(pstate)) { 886 rc = PTR_ERR(pstate); 887 DPU_ERROR("%s: failed to get plane%d state, %d\n", 888 dpu_crtc->name, plane->base.id, rc); 889 goto end; 890 } 891 if (cnt >= DPU_STAGE_MAX * 4) 892 continue; 893 894 pstates[cnt].dpu_pstate = to_dpu_plane_state(pstate); 895 pstates[cnt].drm_pstate = pstate; 896 pstates[cnt].stage = pstate->normalized_zpos; 897 pstates[cnt].pipe_id = dpu_plane_pipe(plane); 898 899 if (pipe_staged[pstates[cnt].pipe_id]) { 900 multirect_plane[multirect_count].r0 = 901 pipe_staged[pstates[cnt].pipe_id]; 902 multirect_plane[multirect_count].r1 = pstate; 903 multirect_count++; 904 905 pipe_staged[pstates[cnt].pipe_id] = NULL; 906 } else { 907 pipe_staged[pstates[cnt].pipe_id] = pstate; 908 } 909 910 cnt++; 911 912 dst = drm_plane_state_dest(pstate); 913 if (!drm_rect_intersect(&clip, &dst)) { 914 DPU_ERROR("invalid vertical/horizontal destination\n"); 915 DPU_ERROR("display: " DRM_RECT_FMT " plane: " 916 DRM_RECT_FMT "\n", DRM_RECT_ARG(&crtc_rect), 917 DRM_RECT_ARG(&dst)); 918 rc = -E2BIG; 919 goto end; 920 } 921 } 922 923 for (i = 1; i < SSPP_MAX; i++) { 924 if (pipe_staged[i]) { 925 dpu_plane_clear_multirect(pipe_staged[i]); 926 927 if (is_dpu_plane_virtual(pipe_staged[i]->plane)) { 928 DPU_ERROR( 929 "r1 only virt plane:%d not supported\n", 930 pipe_staged[i]->plane->base.id); 931 rc = -EINVAL; 932 goto end; 933 } 934 } 935 } 936 937 z_pos = -1; 938 for (i = 0; i < cnt; i++) { 939 /* reset counts at every new blend stage */ 940 if (pstates[i].stage != z_pos) { 941 left_zpos_cnt = 0; 942 right_zpos_cnt = 0; 943 z_pos = pstates[i].stage; 944 } 945 946 /* verify z_pos setting before using it */ 947 if (z_pos >= DPU_STAGE_MAX - DPU_STAGE_0) { 948 DPU_ERROR("> %d plane stages assigned\n", 949 DPU_STAGE_MAX - DPU_STAGE_0); 950 rc = -EINVAL; 951 goto end; 952 } else if (pstates[i].drm_pstate->crtc_x < mixer_width) { 953 if (left_zpos_cnt == 2) { 954 DPU_ERROR("> 2 planes @ stage %d on left\n", 955 z_pos); 956 rc = -EINVAL; 957 goto end; 958 } 959 left_zpos_cnt++; 960 961 } else { 962 if (right_zpos_cnt == 2) { 963 DPU_ERROR("> 2 planes @ stage %d on right\n", 964 z_pos); 965 rc = -EINVAL; 966 goto end; 967 } 968 right_zpos_cnt++; 969 } 970 971 pstates[i].dpu_pstate->stage = z_pos + DPU_STAGE_0; 972 DPU_DEBUG("%s: zpos %d", dpu_crtc->name, z_pos); 973 } 974 975 for (i = 0; i < multirect_count; i++) { 976 if (dpu_plane_validate_multirect_v2(&multirect_plane[i])) { 977 DPU_ERROR( 978 "multirect validation failed for planes (%d - %d)\n", 979 multirect_plane[i].r0->plane->base.id, 980 multirect_plane[i].r1->plane->base.id); 981 rc = -EINVAL; 982 goto end; 983 } 984 } 985 986 rc = dpu_core_perf_crtc_check(crtc, state); 987 if (rc) { 988 DPU_ERROR("crtc%d failed performance check %d\n", 989 crtc->base.id, rc); 990 goto end; 991 } 992 993 /* validate source split: 994 * use pstates sorted by stage to check planes on same stage 995 * we assume that all pipes are in source split so its valid to compare 996 * without taking into account left/right mixer placement 997 */ 998 for (i = 1; i < cnt; i++) { 999 struct plane_state *prv_pstate, *cur_pstate; 1000 struct drm_rect left_rect, right_rect; 1001 int32_t left_pid, right_pid; 1002 int32_t stage; 1003 1004 prv_pstate = &pstates[i - 1]; 1005 cur_pstate = &pstates[i]; 1006 if (prv_pstate->stage != cur_pstate->stage) 1007 continue; 1008 1009 stage = cur_pstate->stage; 1010 1011 left_pid = prv_pstate->dpu_pstate->base.plane->base.id; 1012 left_rect = drm_plane_state_dest(prv_pstate->drm_pstate); 1013 1014 right_pid = cur_pstate->dpu_pstate->base.plane->base.id; 1015 right_rect = drm_plane_state_dest(cur_pstate->drm_pstate); 1016 1017 if (right_rect.x1 < left_rect.x1) { 1018 swap(left_pid, right_pid); 1019 swap(left_rect, right_rect); 1020 } 1021 1022 /** 1023 * - planes are enumerated in pipe-priority order such that 1024 * planes with lower drm_id must be left-most in a shared 1025 * blend-stage when using source split. 1026 * - planes in source split must be contiguous in width 1027 * - planes in source split must have same dest yoff and height 1028 */ 1029 if (right_pid < left_pid) { 1030 DPU_ERROR( 1031 "invalid src split cfg. priority mismatch. stage: %d left: %d right: %d\n", 1032 stage, left_pid, right_pid); 1033 rc = -EINVAL; 1034 goto end; 1035 } else if (right_rect.x1 != drm_rect_width(&left_rect)) { 1036 DPU_ERROR("non-contiguous coordinates for src split. " 1037 "stage: %d left: " DRM_RECT_FMT " right: " 1038 DRM_RECT_FMT "\n", stage, 1039 DRM_RECT_ARG(&left_rect), 1040 DRM_RECT_ARG(&right_rect)); 1041 rc = -EINVAL; 1042 goto end; 1043 } else if (left_rect.y1 != right_rect.y1 || 1044 drm_rect_height(&left_rect) != drm_rect_height(&right_rect)) { 1045 DPU_ERROR("source split at stage: %d. invalid " 1046 "yoff/height: left: " DRM_RECT_FMT " right: " 1047 DRM_RECT_FMT "\n", stage, 1048 DRM_RECT_ARG(&left_rect), 1049 DRM_RECT_ARG(&right_rect)); 1050 rc = -EINVAL; 1051 goto end; 1052 } 1053 } 1054 1055 end: 1056 kfree(pstates); 1057 return rc; 1058 } 1059 1060 int dpu_crtc_vblank(struct drm_crtc *crtc, bool en) 1061 { 1062 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 1063 struct drm_encoder *enc; 1064 1065 trace_dpu_crtc_vblank(DRMID(&dpu_crtc->base), en, dpu_crtc); 1066 1067 /* 1068 * Normally we would iterate through encoder_mask in crtc state to find 1069 * attached encoders. In this case, we might be disabling vblank _after_ 1070 * encoder_mask has been cleared. 1071 * 1072 * Instead, we "assign" a crtc to the encoder in enable and clear it in 1073 * disable (which is also after encoder_mask is cleared). So instead of 1074 * using encoder mask, we'll ask the encoder to toggle itself iff it's 1075 * currently assigned to our crtc. 1076 * 1077 * Note also that this function cannot be called while crtc is disabled 1078 * since we use drm_crtc_vblank_on/off. So we don't need to worry 1079 * about the assigned crtcs being inconsistent with the current state 1080 * (which means no need to worry about modeset locks). 1081 */ 1082 list_for_each_entry(enc, &crtc->dev->mode_config.encoder_list, head) { 1083 trace_dpu_crtc_vblank_enable(DRMID(crtc), DRMID(enc), en, 1084 dpu_crtc); 1085 1086 dpu_encoder_toggle_vblank_for_crtc(enc, crtc, en); 1087 } 1088 1089 return 0; 1090 } 1091 1092 #ifdef CONFIG_DEBUG_FS 1093 static int _dpu_debugfs_status_show(struct seq_file *s, void *data) 1094 { 1095 struct dpu_crtc *dpu_crtc; 1096 struct dpu_plane_state *pstate = NULL; 1097 struct dpu_crtc_mixer *m; 1098 1099 struct drm_crtc *crtc; 1100 struct drm_plane *plane; 1101 struct drm_display_mode *mode; 1102 struct drm_framebuffer *fb; 1103 struct drm_plane_state *state; 1104 struct dpu_crtc_state *cstate; 1105 1106 int i, out_width; 1107 1108 dpu_crtc = s->private; 1109 crtc = &dpu_crtc->base; 1110 1111 drm_modeset_lock_all(crtc->dev); 1112 cstate = to_dpu_crtc_state(crtc->state); 1113 1114 mode = &crtc->state->adjusted_mode; 1115 out_width = mode->hdisplay / cstate->num_mixers; 1116 1117 seq_printf(s, "crtc:%d width:%d height:%d\n", crtc->base.id, 1118 mode->hdisplay, mode->vdisplay); 1119 1120 seq_puts(s, "\n"); 1121 1122 for (i = 0; i < cstate->num_mixers; ++i) { 1123 m = &cstate->mixers[i]; 1124 if (!m->hw_lm) 1125 seq_printf(s, "\tmixer[%d] has no lm\n", i); 1126 else if (!m->lm_ctl) 1127 seq_printf(s, "\tmixer[%d] has no ctl\n", i); 1128 else 1129 seq_printf(s, "\tmixer:%d ctl:%d width:%d height:%d\n", 1130 m->hw_lm->idx - LM_0, m->lm_ctl->idx - CTL_0, 1131 out_width, mode->vdisplay); 1132 } 1133 1134 seq_puts(s, "\n"); 1135 1136 drm_atomic_crtc_for_each_plane(plane, crtc) { 1137 pstate = to_dpu_plane_state(plane->state); 1138 state = plane->state; 1139 1140 if (!pstate || !state) 1141 continue; 1142 1143 seq_printf(s, "\tplane:%u stage:%d\n", plane->base.id, 1144 pstate->stage); 1145 1146 if (plane->state->fb) { 1147 fb = plane->state->fb; 1148 1149 seq_printf(s, "\tfb:%d image format:%4.4s wxh:%ux%u ", 1150 fb->base.id, (char *) &fb->format->format, 1151 fb->width, fb->height); 1152 for (i = 0; i < ARRAY_SIZE(fb->format->cpp); ++i) 1153 seq_printf(s, "cpp[%d]:%u ", 1154 i, fb->format->cpp[i]); 1155 seq_puts(s, "\n\t"); 1156 1157 seq_printf(s, "modifier:%8llu ", fb->modifier); 1158 seq_puts(s, "\n"); 1159 1160 seq_puts(s, "\t"); 1161 for (i = 0; i < ARRAY_SIZE(fb->pitches); i++) 1162 seq_printf(s, "pitches[%d]:%8u ", i, 1163 fb->pitches[i]); 1164 seq_puts(s, "\n"); 1165 1166 seq_puts(s, "\t"); 1167 for (i = 0; i < ARRAY_SIZE(fb->offsets); i++) 1168 seq_printf(s, "offsets[%d]:%8u ", i, 1169 fb->offsets[i]); 1170 seq_puts(s, "\n"); 1171 } 1172 1173 seq_printf(s, "\tsrc_x:%4d src_y:%4d src_w:%4d src_h:%4d\n", 1174 state->src_x, state->src_y, state->src_w, state->src_h); 1175 1176 seq_printf(s, "\tdst x:%4d dst_y:%4d dst_w:%4d dst_h:%4d\n", 1177 state->crtc_x, state->crtc_y, state->crtc_w, 1178 state->crtc_h); 1179 seq_printf(s, "\tmultirect: mode: %d index: %d\n", 1180 pstate->multirect_mode, pstate->multirect_index); 1181 1182 seq_puts(s, "\n"); 1183 } 1184 if (dpu_crtc->vblank_cb_count) { 1185 ktime_t diff = ktime_sub(ktime_get(), dpu_crtc->vblank_cb_time); 1186 s64 diff_ms = ktime_to_ms(diff); 1187 s64 fps = diff_ms ? div_s64( 1188 dpu_crtc->vblank_cb_count * 1000, diff_ms) : 0; 1189 1190 seq_printf(s, 1191 "vblank fps:%lld count:%u total:%llums total_framecount:%llu\n", 1192 fps, dpu_crtc->vblank_cb_count, 1193 ktime_to_ms(diff), dpu_crtc->play_count); 1194 1195 /* reset time & count for next measurement */ 1196 dpu_crtc->vblank_cb_count = 0; 1197 dpu_crtc->vblank_cb_time = ktime_set(0, 0); 1198 } 1199 1200 drm_modeset_unlock_all(crtc->dev); 1201 1202 return 0; 1203 } 1204 1205 static int _dpu_debugfs_status_open(struct inode *inode, struct file *file) 1206 { 1207 return single_open(file, _dpu_debugfs_status_show, inode->i_private); 1208 } 1209 1210 #define DEFINE_DPU_DEBUGFS_SEQ_FOPS(__prefix) \ 1211 static int __prefix ## _open(struct inode *inode, struct file *file) \ 1212 { \ 1213 return single_open(file, __prefix ## _show, inode->i_private); \ 1214 } \ 1215 static const struct file_operations __prefix ## _fops = { \ 1216 .owner = THIS_MODULE, \ 1217 .open = __prefix ## _open, \ 1218 .release = single_release, \ 1219 .read = seq_read, \ 1220 .llseek = seq_lseek, \ 1221 } 1222 1223 static int dpu_crtc_debugfs_state_show(struct seq_file *s, void *v) 1224 { 1225 struct drm_crtc *crtc = (struct drm_crtc *) s->private; 1226 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 1227 int i; 1228 1229 seq_printf(s, "client type: %d\n", dpu_crtc_get_client_type(crtc)); 1230 seq_printf(s, "intf_mode: %d\n", dpu_crtc_get_intf_mode(crtc)); 1231 seq_printf(s, "core_clk_rate: %llu\n", 1232 dpu_crtc->cur_perf.core_clk_rate); 1233 for (i = DPU_CORE_PERF_DATA_BUS_ID_MNOC; 1234 i < DPU_CORE_PERF_DATA_BUS_ID_MAX; i++) { 1235 seq_printf(s, "bw_ctl[%d]: %llu\n", i, 1236 dpu_crtc->cur_perf.bw_ctl[i]); 1237 seq_printf(s, "max_per_pipe_ib[%d]: %llu\n", i, 1238 dpu_crtc->cur_perf.max_per_pipe_ib[i]); 1239 } 1240 1241 return 0; 1242 } 1243 DEFINE_DPU_DEBUGFS_SEQ_FOPS(dpu_crtc_debugfs_state); 1244 1245 static int _dpu_crtc_init_debugfs(struct drm_crtc *crtc) 1246 { 1247 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 1248 1249 static const struct file_operations debugfs_status_fops = { 1250 .open = _dpu_debugfs_status_open, 1251 .read = seq_read, 1252 .llseek = seq_lseek, 1253 .release = single_release, 1254 }; 1255 1256 dpu_crtc->debugfs_root = debugfs_create_dir(dpu_crtc->name, 1257 crtc->dev->primary->debugfs_root); 1258 if (!dpu_crtc->debugfs_root) 1259 return -ENOMEM; 1260 1261 /* don't error check these */ 1262 debugfs_create_file("status", 0400, 1263 dpu_crtc->debugfs_root, 1264 dpu_crtc, &debugfs_status_fops); 1265 debugfs_create_file("state", 0600, 1266 dpu_crtc->debugfs_root, 1267 &dpu_crtc->base, 1268 &dpu_crtc_debugfs_state_fops); 1269 1270 return 0; 1271 } 1272 #else 1273 static int _dpu_crtc_init_debugfs(struct drm_crtc *crtc) 1274 { 1275 return 0; 1276 } 1277 #endif /* CONFIG_DEBUG_FS */ 1278 1279 static int dpu_crtc_late_register(struct drm_crtc *crtc) 1280 { 1281 return _dpu_crtc_init_debugfs(crtc); 1282 } 1283 1284 static void dpu_crtc_early_unregister(struct drm_crtc *crtc) 1285 { 1286 struct dpu_crtc *dpu_crtc = to_dpu_crtc(crtc); 1287 1288 debugfs_remove_recursive(dpu_crtc->debugfs_root); 1289 } 1290 1291 static const struct drm_crtc_funcs dpu_crtc_funcs = { 1292 .set_config = drm_atomic_helper_set_config, 1293 .destroy = dpu_crtc_destroy, 1294 .page_flip = drm_atomic_helper_page_flip, 1295 .reset = dpu_crtc_reset, 1296 .atomic_duplicate_state = dpu_crtc_duplicate_state, 1297 .atomic_destroy_state = dpu_crtc_destroy_state, 1298 .late_register = dpu_crtc_late_register, 1299 .early_unregister = dpu_crtc_early_unregister, 1300 }; 1301 1302 static const struct drm_crtc_helper_funcs dpu_crtc_helper_funcs = { 1303 .atomic_disable = dpu_crtc_disable, 1304 .atomic_enable = dpu_crtc_enable, 1305 .atomic_check = dpu_crtc_atomic_check, 1306 .atomic_begin = dpu_crtc_atomic_begin, 1307 .atomic_flush = dpu_crtc_atomic_flush, 1308 }; 1309 1310 /* initialize crtc */ 1311 struct drm_crtc *dpu_crtc_init(struct drm_device *dev, struct drm_plane *plane, 1312 struct drm_plane *cursor) 1313 { 1314 struct drm_crtc *crtc = NULL; 1315 struct dpu_crtc *dpu_crtc = NULL; 1316 struct msm_drm_private *priv = NULL; 1317 struct dpu_kms *kms = NULL; 1318 int i; 1319 1320 priv = dev->dev_private; 1321 kms = to_dpu_kms(priv->kms); 1322 1323 dpu_crtc = kzalloc(sizeof(*dpu_crtc), GFP_KERNEL); 1324 if (!dpu_crtc) 1325 return ERR_PTR(-ENOMEM); 1326 1327 crtc = &dpu_crtc->base; 1328 crtc->dev = dev; 1329 1330 spin_lock_init(&dpu_crtc->spin_lock); 1331 atomic_set(&dpu_crtc->frame_pending, 0); 1332 1333 init_completion(&dpu_crtc->frame_done_comp); 1334 1335 INIT_LIST_HEAD(&dpu_crtc->frame_event_list); 1336 1337 for (i = 0; i < ARRAY_SIZE(dpu_crtc->frame_events); i++) { 1338 INIT_LIST_HEAD(&dpu_crtc->frame_events[i].list); 1339 list_add(&dpu_crtc->frame_events[i].list, 1340 &dpu_crtc->frame_event_list); 1341 kthread_init_work(&dpu_crtc->frame_events[i].work, 1342 dpu_crtc_frame_event_work); 1343 } 1344 1345 drm_crtc_init_with_planes(dev, crtc, plane, cursor, &dpu_crtc_funcs, 1346 NULL); 1347 1348 drm_crtc_helper_add(crtc, &dpu_crtc_helper_funcs); 1349 1350 /* save user friendly CRTC name for later */ 1351 snprintf(dpu_crtc->name, DPU_CRTC_NAME_SIZE, "crtc%u", crtc->base.id); 1352 1353 /* initialize event handling */ 1354 spin_lock_init(&dpu_crtc->event_lock); 1355 1356 DPU_DEBUG("%s: successfully initialized crtc\n", dpu_crtc->name); 1357 return crtc; 1358 } 1359