Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1 | /* |
Lloyd Atkinson | 8772e20 | 2016-09-26 17:52:16 -0400 | [diff] [blame] | 2 | * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved. |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -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. |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 12 | */ |
| 13 | |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 14 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 15 | #include <linux/debugfs.h> |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 16 | #include <uapi/drm/sde_drm.h> |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 17 | |
| 18 | #include "sde_encoder_phys.h" |
| 19 | #include "sde_formats.h" |
| 20 | #include "sde_hw_top.h" |
| 21 | #include "sde_hw_interrupts.h" |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 22 | #include "sde_core_irq.h" |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 23 | #include "sde_wb.h" |
Lloyd Atkinson | 8772e20 | 2016-09-26 17:52:16 -0400 | [diff] [blame] | 24 | #include "sde_vbif.h" |
Alan Kwong | a62eeb8 | 2017-04-19 08:57:55 -0700 | [diff] [blame] | 25 | #include "sde_crtc.h" |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 26 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 27 | #define to_sde_encoder_phys_wb(x) \ |
| 28 | container_of(x, struct sde_encoder_phys_wb, base) |
| 29 | |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 30 | #define WBID(wb_enc) \ |
| 31 | ((wb_enc && wb_enc->wb_dev) ? wb_enc->wb_dev->wb_idx - WB_0 : -1) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 32 | |
Alan Kwong | d6a3860 | 2017-03-11 22:26:25 -0800 | [diff] [blame] | 33 | #define TO_S15D16(_x_) ((_x_) << 7) |
| 34 | |
| 35 | /** |
| 36 | * sde_rgb2yuv_601l - rgb to yuv color space conversion matrix |
| 37 | * |
| 38 | */ |
| 39 | static struct sde_csc_cfg sde_encoder_phys_wb_rgb2yuv_601l = { |
| 40 | { |
| 41 | TO_S15D16(0x0083), TO_S15D16(0x0102), TO_S15D16(0x0032), |
| 42 | TO_S15D16(0x1fb5), TO_S15D16(0x1f6c), TO_S15D16(0x00e1), |
| 43 | TO_S15D16(0x00e1), TO_S15D16(0x1f45), TO_S15D16(0x1fdc) |
| 44 | }, |
| 45 | { 0x00, 0x00, 0x00 }, |
| 46 | { 0x0040, 0x0200, 0x0200 }, |
| 47 | { 0x000, 0x3ff, 0x000, 0x3ff, 0x000, 0x3ff }, |
| 48 | { 0x040, 0x3ac, 0x040, 0x3c0, 0x040, 0x3c0 }, |
| 49 | }; |
| 50 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 51 | /** |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 52 | * sde_encoder_phys_wb_is_master - report wb always as master encoder |
| 53 | */ |
| 54 | static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc) |
| 55 | { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 60 | * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode |
| 61 | * @hw_wb: Pointer to h/w writeback driver |
| 62 | */ |
| 63 | static enum sde_intr_type sde_encoder_phys_wb_get_intr_type( |
| 64 | struct sde_hw_wb *hw_wb) |
| 65 | { |
| 66 | return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ? |
| 67 | SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP; |
| 68 | } |
| 69 | |
| 70 | /** |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 71 | * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface |
| 72 | * @phys_enc: Pointer to physical encoder |
| 73 | */ |
| 74 | static void sde_encoder_phys_wb_set_ot_limit( |
| 75 | struct sde_encoder_phys *phys_enc) |
| 76 | { |
| 77 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 78 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 79 | struct sde_vbif_set_ot_params ot_params; |
| 80 | |
| 81 | memset(&ot_params, 0, sizeof(ot_params)); |
| 82 | ot_params.xin_id = hw_wb->caps->xin_id; |
| 83 | ot_params.num = hw_wb->idx - WB_0; |
| 84 | ot_params.width = wb_enc->wb_roi.w; |
| 85 | ot_params.height = wb_enc->wb_roi.h; |
| 86 | ot_params.is_wfd = true; |
| 87 | ot_params.frame_rate = phys_enc->cached_mode.vrefresh; |
| 88 | ot_params.vbif_idx = hw_wb->caps->vbif_idx; |
| 89 | ot_params.clk_ctrl = hw_wb->caps->clk_ctrl; |
| 90 | ot_params.rd = false; |
| 91 | |
| 92 | sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params); |
| 93 | } |
| 94 | |
| 95 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 96 | * sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback |
| 97 | * @phys_enc: Pointer to physical encoder |
| 98 | */ |
| 99 | static void sde_encoder_phys_wb_set_traffic_shaper( |
| 100 | struct sde_encoder_phys *phys_enc) |
| 101 | { |
| 102 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 103 | struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg; |
| 104 | |
| 105 | /* traffic shaper is only enabled for rotator */ |
| 106 | wb_cfg->ts_cfg.en = false; |
| 107 | } |
| 108 | |
| 109 | /** |
Alan Kwong | a62eeb8 | 2017-04-19 08:57:55 -0700 | [diff] [blame] | 110 | * sde_encoder_phys_wb_set_qos_remap - set QoS remapper for writeback |
| 111 | * @phys_enc: Pointer to physical encoder |
| 112 | */ |
| 113 | static void sde_encoder_phys_wb_set_qos_remap( |
| 114 | struct sde_encoder_phys *phys_enc) |
| 115 | { |
| 116 | struct sde_encoder_phys_wb *wb_enc; |
| 117 | struct sde_hw_wb *hw_wb; |
| 118 | struct drm_crtc *crtc; |
| 119 | struct sde_vbif_set_qos_params qos_params; |
| 120 | |
| 121 | if (!phys_enc || !phys_enc->parent || !phys_enc->parent->crtc) { |
| 122 | SDE_ERROR("invalid arguments\n"); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Harsh Sahu | fae4d81 | 2017-11-29 15:08:59 -0800 | [diff] [blame] | 127 | if (!wb_enc->crtc) { |
| 128 | SDE_ERROR("invalid crtc"); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | crtc = wb_enc->crtc; |
Alan Kwong | a62eeb8 | 2017-04-19 08:57:55 -0700 | [diff] [blame] | 133 | |
| 134 | if (!wb_enc->hw_wb || !wb_enc->hw_wb->caps) { |
| 135 | SDE_ERROR("invalid writeback hardware\n"); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | hw_wb = wb_enc->hw_wb; |
| 140 | |
| 141 | memset(&qos_params, 0, sizeof(qos_params)); |
| 142 | qos_params.vbif_idx = hw_wb->caps->vbif_idx; |
| 143 | qos_params.xin_id = hw_wb->caps->xin_id; |
| 144 | qos_params.clk_ctrl = hw_wb->caps->clk_ctrl; |
| 145 | qos_params.num = hw_wb->idx - WB_0; |
| 146 | qos_params.is_rt = sde_crtc_get_client_type(crtc) != NRT_CLIENT; |
| 147 | |
| 148 | SDE_DEBUG("[qos_remap] wb:%d vbif:%d xin:%d rt:%d\n", |
| 149 | qos_params.num, |
| 150 | qos_params.vbif_idx, |
| 151 | qos_params.xin_id, qos_params.is_rt); |
| 152 | |
| 153 | sde_vbif_set_qos_remap(phys_enc->sde_kms, &qos_params); |
| 154 | } |
| 155 | |
| 156 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 157 | * sde_encoder_phys_setup_cdm - setup chroma down block |
| 158 | * @phys_enc: Pointer to physical encoder |
| 159 | * @fb: Pointer to output framebuffer |
| 160 | * @format: Output format |
| 161 | */ |
| 162 | void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc, |
| 163 | struct drm_framebuffer *fb, const struct sde_format *format, |
| 164 | struct sde_rect *wb_roi) |
| 165 | { |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 166 | struct sde_hw_cdm *hw_cdm; |
| 167 | struct sde_hw_cdm_cfg *cdm_cfg; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 168 | int ret; |
| 169 | |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 170 | if (!phys_enc || !format) |
| 171 | return; |
| 172 | |
| 173 | cdm_cfg = &phys_enc->cdm_cfg; |
| 174 | hw_cdm = phys_enc->hw_cdm; |
| 175 | if (!hw_cdm) |
| 176 | return; |
| 177 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 178 | if (!SDE_FORMAT_IS_YUV(format)) { |
| 179 | SDE_DEBUG("[cdm_disable fmt:%x]\n", |
| 180 | format->base.pixel_format); |
| 181 | |
| 182 | if (hw_cdm && hw_cdm->ops.disable) |
| 183 | hw_cdm->ops.disable(hw_cdm); |
| 184 | |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg)); |
| 189 | |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 190 | if (!wb_roi) |
| 191 | return; |
| 192 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 193 | cdm_cfg->output_width = wb_roi->w; |
| 194 | cdm_cfg->output_height = wb_roi->h; |
| 195 | cdm_cfg->output_fmt = format; |
| 196 | cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB; |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 197 | cdm_cfg->output_bit_depth = SDE_FORMAT_IS_DX(format) ? |
| 198 | CDM_CDWN_OUTPUT_10BIT : CDM_CDWN_OUTPUT_8BIT; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 199 | |
| 200 | /* enable 10 bit logic */ |
| 201 | switch (cdm_cfg->output_fmt->chroma_sample) { |
| 202 | case SDE_CHROMA_RGB: |
| 203 | cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE; |
| 204 | cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE; |
| 205 | break; |
| 206 | case SDE_CHROMA_H2V1: |
| 207 | cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE; |
| 208 | cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE; |
| 209 | break; |
| 210 | case SDE_CHROMA_420: |
| 211 | cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE; |
| 212 | cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE; |
| 213 | break; |
| 214 | case SDE_CHROMA_H1V2: |
| 215 | default: |
| 216 | SDE_ERROR("unsupported chroma sampling type\n"); |
| 217 | cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE; |
| 218 | cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE; |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n", |
| 223 | cdm_cfg->output_width, |
| 224 | cdm_cfg->output_height, |
| 225 | cdm_cfg->output_fmt->base.pixel_format, |
| 226 | cdm_cfg->output_type, |
| 227 | cdm_cfg->output_bit_depth, |
| 228 | cdm_cfg->h_cdwn_type, |
| 229 | cdm_cfg->v_cdwn_type); |
| 230 | |
Alan Kwong | d6a3860 | 2017-03-11 22:26:25 -0800 | [diff] [blame] | 231 | if (hw_cdm && hw_cdm->ops.setup_csc_data) { |
| 232 | ret = hw_cdm->ops.setup_csc_data(hw_cdm, |
| 233 | &sde_encoder_phys_wb_rgb2yuv_601l); |
| 234 | if (ret < 0) { |
| 235 | SDE_ERROR("failed to setup CSC %d\n", ret); |
| 236 | return; |
| 237 | } |
| 238 | } |
| 239 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 240 | if (hw_cdm && hw_cdm->ops.setup_cdwn) { |
| 241 | ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg); |
| 242 | if (ret < 0) { |
| 243 | SDE_ERROR("failed to setup CDM %d\n", ret); |
| 244 | return; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (hw_cdm && hw_cdm->ops.enable) { |
| 249 | ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg); |
| 250 | if (ret < 0) { |
| 251 | SDE_ERROR("failed to enable CDM %d\n", ret); |
| 252 | return; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * sde_encoder_phys_wb_setup_fb - setup output framebuffer |
| 259 | * @phys_enc: Pointer to physical encoder |
| 260 | * @fb: Pointer to output framebuffer |
| 261 | * @wb_roi: Pointer to output region of interest |
| 262 | */ |
| 263 | static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc, |
| 264 | struct drm_framebuffer *fb, struct sde_rect *wb_roi) |
| 265 | { |
| 266 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 267 | struct sde_hw_wb *hw_wb; |
| 268 | struct sde_hw_wb_cfg *wb_cfg; |
Alan Kwong | 143f50c | 2017-04-28 07:34:28 -0700 | [diff] [blame] | 269 | struct sde_hw_wb_cdp_cfg *cdp_cfg; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 270 | const struct msm_format *format; |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 271 | int ret; |
| 272 | struct msm_gem_address_space *aspace; |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 273 | u32 fb_mode; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 274 | |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 275 | if (!phys_enc || !phys_enc->sde_kms || !phys_enc->sde_kms->catalog || |
| 276 | !phys_enc->connector) { |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 277 | SDE_ERROR("invalid encoder\n"); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | hw_wb = wb_enc->hw_wb; |
| 282 | wb_cfg = &wb_enc->wb_cfg; |
Alan Kwong | 143f50c | 2017-04-28 07:34:28 -0700 | [diff] [blame] | 283 | cdp_cfg = &wb_enc->cdp_cfg; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 284 | memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg)); |
| 285 | |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 286 | wb_cfg->intf_mode = phys_enc->intf_mode; |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 287 | |
| 288 | fb_mode = sde_connector_get_property(phys_enc->connector->state, |
| 289 | CONNECTOR_PROP_FB_TRANSLATION_MODE); |
| 290 | if (phys_enc->enable_state == SDE_ENC_DISABLING) |
| 291 | wb_cfg->is_secure = false; |
| 292 | else if (fb_mode == SDE_DRM_FB_SEC) |
| 293 | wb_cfg->is_secure = true; |
| 294 | else |
| 295 | wb_cfg->is_secure = false; |
| 296 | |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 297 | aspace = (wb_cfg->is_secure) ? |
| 298 | wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] : |
| 299 | wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE]; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 300 | |
| 301 | SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure); |
| 302 | |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 303 | ret = msm_framebuffer_prepare(fb, aspace); |
| 304 | if (ret) { |
| 305 | SDE_ERROR("prep fb failed, %d\n", ret); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* cache framebuffer for cleanup in writeback done */ |
| 310 | wb_enc->wb_fb = fb; |
| 311 | wb_enc->wb_aspace = aspace; |
| 312 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 313 | format = msm_framebuffer_format(fb); |
Dhaval Patel | ccbcb3d | 2016-08-22 11:58:14 -0700 | [diff] [blame] | 314 | if (!format) { |
| 315 | SDE_DEBUG("invalid format for fb\n"); |
| 316 | return; |
| 317 | } |
| 318 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 319 | wb_cfg->dest.format = sde_get_sde_format_ext( |
| 320 | format->pixel_format, |
| 321 | fb->modifier, |
| 322 | drm_format_num_planes(fb->pixel_format)); |
| 323 | if (!wb_cfg->dest.format) { |
| 324 | /* this error should be detected during atomic_check */ |
| 325 | SDE_ERROR("failed to get format %x\n", format->pixel_format); |
| 326 | return; |
| 327 | } |
abeykun | f1539f7 | 2016-08-24 16:08:03 -0400 | [diff] [blame] | 328 | wb_cfg->roi = *wb_roi; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 329 | |
abeykun | f1539f7 | 2016-08-24 16:08:03 -0400 | [diff] [blame] | 330 | if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 331 | ret = sde_format_populate_layout(aspace, fb, &wb_cfg->dest); |
abeykun | f1539f7 | 2016-08-24 16:08:03 -0400 | [diff] [blame] | 332 | if (ret) { |
| 333 | SDE_DEBUG("failed to populate layout %d\n", ret); |
| 334 | return; |
| 335 | } |
| 336 | wb_cfg->dest.width = fb->width; |
| 337 | wb_cfg->dest.height = fb->height; |
| 338 | wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes; |
| 339 | } else { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 340 | ret = sde_format_populate_layout_with_roi(aspace, fb, wb_roi, |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 341 | &wb_cfg->dest); |
abeykun | f1539f7 | 2016-08-24 16:08:03 -0400 | [diff] [blame] | 342 | if (ret) { |
| 343 | /* this error should be detected during atomic_check */ |
| 344 | SDE_DEBUG("failed to populate layout %d\n", ret); |
| 345 | return; |
| 346 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) && |
| 350 | (wb_cfg->dest.format->element[0] == C1_B_Cb)) |
| 351 | swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]); |
| 352 | |
| 353 | SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n", |
| 354 | wb_cfg->dest.plane_addr[0], |
| 355 | wb_cfg->dest.plane_addr[1], |
| 356 | wb_cfg->dest.plane_addr[2], |
| 357 | wb_cfg->dest.plane_addr[3]); |
| 358 | SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n", |
| 359 | wb_cfg->dest.plane_pitch[0], |
| 360 | wb_cfg->dest.plane_pitch[1], |
| 361 | wb_cfg->dest.plane_pitch[2], |
| 362 | wb_cfg->dest.plane_pitch[3]); |
| 363 | |
abeykun | f1539f7 | 2016-08-24 16:08:03 -0400 | [diff] [blame] | 364 | if (hw_wb->ops.setup_roi) |
| 365 | hw_wb->ops.setup_roi(hw_wb, wb_cfg); |
| 366 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 367 | if (hw_wb->ops.setup_outformat) |
| 368 | hw_wb->ops.setup_outformat(hw_wb, wb_cfg); |
| 369 | |
Alan Kwong | 143f50c | 2017-04-28 07:34:28 -0700 | [diff] [blame] | 370 | if (hw_wb->ops.setup_cdp) { |
| 371 | memset(cdp_cfg, 0, sizeof(struct sde_hw_wb_cdp_cfg)); |
| 372 | |
| 373 | cdp_cfg->enable = phys_enc->sde_kms->catalog->perf.cdp_cfg |
| 374 | [SDE_PERF_CDP_USAGE_NRT].wr_enable; |
| 375 | cdp_cfg->ubwc_meta_enable = |
| 376 | SDE_FORMAT_IS_UBWC(wb_cfg->dest.format); |
| 377 | cdp_cfg->tile_amortize_enable = |
| 378 | SDE_FORMAT_IS_UBWC(wb_cfg->dest.format) || |
| 379 | SDE_FORMAT_IS_TILE(wb_cfg->dest.format); |
| 380 | cdp_cfg->preload_ahead = SDE_WB_CDP_PRELOAD_AHEAD_64; |
| 381 | |
| 382 | hw_wb->ops.setup_cdp(hw_wb, cdp_cfg); |
| 383 | } |
| 384 | |
Alan Kwong | c16e092 | 2017-05-11 14:50:46 -0700 | [diff] [blame] | 385 | if (hw_wb->ops.setup_outaddress) { |
| 386 | SDE_EVT32(hw_wb->idx, |
| 387 | wb_cfg->dest.width, |
| 388 | wb_cfg->dest.height, |
| 389 | wb_cfg->dest.plane_addr[0], |
| 390 | wb_cfg->dest.plane_size[0], |
| 391 | wb_cfg->dest.plane_addr[1], |
| 392 | wb_cfg->dest.plane_size[1], |
| 393 | wb_cfg->dest.plane_addr[2], |
| 394 | wb_cfg->dest.plane_size[2], |
| 395 | wb_cfg->dest.plane_addr[3], |
| 396 | wb_cfg->dest.plane_size[3]); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 397 | hw_wb->ops.setup_outaddress(hw_wb, wb_cfg); |
Alan Kwong | c16e092 | 2017-05-11 14:50:46 -0700 | [diff] [blame] | 398 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
| 402 | * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block |
| 403 | * @phys_enc: Pointer to physical encoder |
| 404 | */ |
| 405 | static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc) |
| 406 | { |
| 407 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 408 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 409 | struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg; |
| 410 | |
| 411 | memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg)); |
| 412 | |
| 413 | intf_cfg->intf = SDE_NONE; |
| 414 | intf_cfg->wb = hw_wb->idx; |
Lloyd Atkinson | 55987b0 | 2016-08-16 16:57:46 -0400 | [diff] [blame] | 415 | intf_cfg->mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 416 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 417 | if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 418 | phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl, |
| 419 | intf_cfg); |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states |
| 424 | * @phys_enc: Pointer to physical encoder |
| 425 | * @crtc_state: Pointer to CRTC atomic state |
| 426 | * @conn_state: Pointer to connector atomic state |
| 427 | */ |
| 428 | static int sde_encoder_phys_wb_atomic_check( |
| 429 | struct sde_encoder_phys *phys_enc, |
| 430 | struct drm_crtc_state *crtc_state, |
| 431 | struct drm_connector_state *conn_state) |
| 432 | { |
| 433 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 434 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 435 | const struct sde_wb_cfg *wb_cfg = hw_wb->caps; |
| 436 | struct drm_framebuffer *fb; |
| 437 | const struct sde_format *fmt; |
| 438 | struct sde_rect wb_roi; |
| 439 | const struct drm_display_mode *mode = &crtc_state->mode; |
| 440 | int rc; |
| 441 | |
| 442 | SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n", |
| 443 | hw_wb->idx - WB_0, mode->base.id, mode->name, |
| 444 | mode->hdisplay, mode->vdisplay); |
| 445 | |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 446 | if (!conn_state || !conn_state->connector) { |
| 447 | SDE_ERROR("invalid connector state\n"); |
| 448 | return -EINVAL; |
| 449 | } else if (conn_state->connector->status != |
| 450 | connector_status_connected) { |
| 451 | SDE_ERROR("connector not connected %d\n", |
| 452 | conn_state->connector->status); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 456 | memset(&wb_roi, 0, sizeof(struct sde_rect)); |
| 457 | |
| 458 | rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi); |
| 459 | if (rc) { |
| 460 | SDE_ERROR("failed to get roi %d\n", rc); |
| 461 | return rc; |
| 462 | } |
| 463 | |
| 464 | SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y, |
| 465 | wb_roi.w, wb_roi.h); |
| 466 | |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 467 | /* bypass check if commit with no framebuffer */ |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 468 | fb = sde_wb_connector_state_get_output_fb(conn_state); |
| 469 | if (!fb) { |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 470 | SDE_DEBUG("no output framebuffer\n"); |
| 471 | return 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id, |
| 475 | fb->width, fb->height); |
| 476 | |
| 477 | fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier, |
| 478 | drm_format_num_planes(fb->pixel_format)); |
| 479 | if (!fmt) { |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 480 | SDE_ERROR("unsupported output pixel format:%x\n", |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 481 | fb->pixel_format); |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
| 485 | SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format, |
| 486 | fb->modifier[0]); |
| 487 | |
| 488 | if (SDE_FORMAT_IS_YUV(fmt) && |
| 489 | !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) { |
| 490 | SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format); |
| 491 | return -EINVAL; |
| 492 | } |
| 493 | |
| 494 | if (SDE_FORMAT_IS_UBWC(fmt) && |
Clarence Ip | 32bcb00 | 2017-03-13 12:26:44 -0700 | [diff] [blame] | 495 | !(wb_cfg->features & BIT(SDE_WB_UBWC))) { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 496 | SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 500 | if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm) |
| 501 | crtc_state->mode_changed = true; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 502 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 503 | if (wb_roi.w && wb_roi.h) { |
| 504 | if (wb_roi.w != mode->hdisplay) { |
| 505 | SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w, |
| 506 | mode->hdisplay); |
| 507 | return -EINVAL; |
| 508 | } else if (wb_roi.h != mode->vdisplay) { |
| 509 | SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h, |
| 510 | mode->vdisplay); |
| 511 | return -EINVAL; |
| 512 | } else if (wb_roi.x + wb_roi.w > fb->width) { |
| 513 | SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n", |
| 514 | wb_roi.x, wb_roi.w, fb->width); |
| 515 | return -EINVAL; |
| 516 | } else if (wb_roi.y + wb_roi.h > fb->height) { |
| 517 | SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n", |
| 518 | wb_roi.y, wb_roi.h, fb->height); |
| 519 | return -EINVAL; |
| 520 | } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) { |
| 521 | SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n", |
| 522 | wb_roi.w, wb_cfg->sblk->maxlinewidth); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | } else { |
| 526 | if (wb_roi.x || wb_roi.y) { |
| 527 | SDE_ERROR("invalid roi x=%d, y=%d\n", |
| 528 | wb_roi.x, wb_roi.y); |
| 529 | return -EINVAL; |
| 530 | } else if (fb->width != mode->hdisplay) { |
| 531 | SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width, |
| 532 | mode->hdisplay); |
| 533 | return -EINVAL; |
| 534 | } else if (fb->height != mode->vdisplay) { |
| 535 | SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height, |
| 536 | mode->vdisplay); |
| 537 | return -EINVAL; |
| 538 | } else if (fb->width > wb_cfg->sblk->maxlinewidth) { |
| 539 | SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n", |
| 540 | fb->width, wb_cfg->sblk->maxlinewidth); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /** |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 549 | * _sde_encoder_phys_wb_update_flush - flush hardware update |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 550 | * @phys_enc: Pointer to physical encoder |
| 551 | */ |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 552 | static void _sde_encoder_phys_wb_update_flush(struct sde_encoder_phys *phys_enc) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 553 | { |
| 554 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 555 | struct sde_hw_wb *hw_wb; |
| 556 | struct sde_hw_ctl *hw_ctl; |
| 557 | struct sde_hw_cdm *hw_cdm; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 558 | u32 flush_mask = 0; |
| 559 | |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 560 | if (!phys_enc) |
| 561 | return; |
| 562 | |
| 563 | hw_wb = wb_enc->hw_wb; |
| 564 | hw_ctl = phys_enc->hw_ctl; |
| 565 | hw_cdm = phys_enc->hw_cdm; |
| 566 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 567 | SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0); |
| 568 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 569 | if (!hw_ctl) { |
| 570 | SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0); |
| 571 | return; |
| 572 | } |
| 573 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 574 | if (hw_ctl->ops.get_bitmask_wb) |
| 575 | hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx); |
| 576 | |
| 577 | if (hw_ctl->ops.get_bitmask_cdm && hw_cdm) |
| 578 | hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx); |
| 579 | |
| 580 | if (hw_ctl->ops.update_pending_flush) |
| 581 | hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask); |
| 582 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 583 | if (hw_ctl->ops.get_pending_flush) |
| 584 | flush_mask = hw_ctl->ops.get_pending_flush(hw_ctl); |
| 585 | |
| 586 | SDE_DEBUG("Pending flush mask for CTL_%d is 0x%x, WB %d\n", |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 587 | hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * sde_encoder_phys_wb_setup - setup writeback encoder |
| 592 | * @phys_enc: Pointer to physical encoder |
| 593 | */ |
| 594 | static void sde_encoder_phys_wb_setup( |
| 595 | struct sde_encoder_phys *phys_enc) |
| 596 | { |
| 597 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 598 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 599 | struct drm_display_mode mode = phys_enc->cached_mode; |
| 600 | struct drm_framebuffer *fb; |
| 601 | struct sde_rect *wb_roi = &wb_enc->wb_roi; |
| 602 | |
| 603 | SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n", |
| 604 | hw_wb->idx - WB_0, mode.base.id, mode.name, |
| 605 | mode.hdisplay, mode.vdisplay); |
| 606 | |
| 607 | memset(wb_roi, 0, sizeof(struct sde_rect)); |
| 608 | |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 609 | /* clear writeback framebuffer - will be updated in setup_fb */ |
| 610 | wb_enc->wb_fb = NULL; |
| 611 | wb_enc->wb_aspace = NULL; |
| 612 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 613 | if (phys_enc->enable_state == SDE_ENC_DISABLING) { |
| 614 | fb = wb_enc->fb_disable; |
| 615 | wb_roi->w = 0; |
| 616 | wb_roi->h = 0; |
| 617 | } else { |
| 618 | fb = sde_wb_get_output_fb(wb_enc->wb_dev); |
| 619 | sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi); |
| 620 | } |
| 621 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 622 | if (!fb) { |
| 623 | SDE_DEBUG("no output framebuffer\n"); |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id, |
| 628 | fb->width, fb->height); |
| 629 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 630 | if (wb_roi->w == 0 || wb_roi->h == 0) { |
| 631 | wb_roi->x = 0; |
| 632 | wb_roi->y = 0; |
| 633 | wb_roi->w = fb->width; |
| 634 | wb_roi->h = fb->height; |
| 635 | } |
| 636 | |
| 637 | SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y, |
| 638 | wb_roi->w, wb_roi->h); |
| 639 | |
| 640 | wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier, |
| 641 | drm_format_num_planes(fb->pixel_format)); |
| 642 | if (!wb_enc->wb_fmt) { |
| 643 | SDE_ERROR("unsupported output pixel format: %d\n", |
| 644 | fb->pixel_format); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format, |
| 649 | fb->modifier[0]); |
| 650 | |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 651 | sde_encoder_phys_wb_set_ot_limit(phys_enc); |
| 652 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 653 | sde_encoder_phys_wb_set_traffic_shaper(phys_enc); |
| 654 | |
Alan Kwong | a62eeb8 | 2017-04-19 08:57:55 -0700 | [diff] [blame] | 655 | sde_encoder_phys_wb_set_qos_remap(phys_enc); |
| 656 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 657 | sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi); |
| 658 | |
| 659 | sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi); |
| 660 | |
| 661 | sde_encoder_phys_wb_setup_cdp(phys_enc); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler |
| 666 | * @phys_enc: Pointer to physical encoder |
| 667 | */ |
| 668 | static int sde_encoder_phys_wb_unregister_irq( |
| 669 | struct sde_encoder_phys *phys_enc) |
| 670 | { |
| 671 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 672 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 673 | |
| 674 | if (wb_enc->bypass_irqreg) |
| 675 | return 0; |
| 676 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 677 | sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1); |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 678 | sde_core_irq_unregister_callback(phys_enc->sde_kms, wb_enc->irq_idx, |
| 679 | &wb_enc->irq_cb); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 680 | |
| 681 | SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n", |
| 682 | hw_wb->idx - WB_0, |
| 683 | wb_enc->irq_idx); |
| 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * sde_encoder_phys_wb_done_irq - writeback interrupt handler |
| 690 | * @arg: Pointer to writeback encoder |
| 691 | * @irq_idx: interrupt index |
| 692 | */ |
| 693 | static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx) |
| 694 | { |
| 695 | struct sde_encoder_phys_wb *wb_enc = arg; |
| 696 | struct sde_encoder_phys *phys_enc = &wb_enc->base; |
| 697 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 698 | u32 event = 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 699 | |
| 700 | SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0, |
| 701 | wb_enc->frame_count); |
| 702 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 703 | /* don't notify upper layer for internal commit */ |
| 704 | if (phys_enc->enable_state == SDE_ENC_DISABLING) |
| 705 | goto complete; |
| 706 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 707 | event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE |
| 708 | | SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE |
| 709 | | SDE_ENCODER_FRAME_EVENT_DONE; |
| 710 | |
| 711 | atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 712 | if (phys_enc->parent_ops.handle_frame_done) |
| 713 | phys_enc->parent_ops.handle_frame_done(phys_enc->parent, |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 714 | phys_enc, event); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 715 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 716 | if (phys_enc->parent_ops.handle_vblank_virt) |
| 717 | phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent, |
| 718 | phys_enc); |
| 719 | |
| 720 | SDE_EVT32_IRQ(DRMID(phys_enc->parent), hw_wb->idx - WB_0, event); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 721 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 722 | complete: |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 723 | complete_all(&wb_enc->wbdone_complete); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * sde_encoder_phys_wb_register_irq - register writeback interrupt handler |
| 728 | * @phys_enc: Pointer to physical encoder |
| 729 | */ |
| 730 | static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc) |
| 731 | { |
| 732 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 733 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 734 | struct sde_irq_callback *irq_cb = &wb_enc->irq_cb; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 735 | enum sde_intr_type intr_type; |
| 736 | int ret = 0; |
| 737 | |
| 738 | if (wb_enc->bypass_irqreg) |
| 739 | return 0; |
| 740 | |
| 741 | intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb); |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 742 | wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms, |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 743 | intr_type, hw_wb->idx); |
| 744 | if (wb_enc->irq_idx < 0) { |
| 745 | SDE_ERROR( |
| 746 | "failed to lookup IRQ index for WB_DONE with wb=%d\n", |
| 747 | hw_wb->idx - WB_0); |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 751 | irq_cb->func = sde_encoder_phys_wb_done_irq; |
| 752 | irq_cb->arg = wb_enc; |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 753 | ret = sde_core_irq_register_callback(phys_enc->sde_kms, |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 754 | wb_enc->irq_idx, irq_cb); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 755 | if (ret) { |
| 756 | SDE_ERROR("failed to register IRQ callback WB_DONE\n"); |
| 757 | return ret; |
| 758 | } |
| 759 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 760 | ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 761 | if (ret) { |
| 762 | SDE_ERROR( |
| 763 | "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n", |
| 764 | hw_wb->idx - WB_0, |
| 765 | wb_enc->irq_idx); |
| 766 | wb_enc->irq_idx = -EINVAL; |
| 767 | |
| 768 | /* Unregister callback on IRQ enable failure */ |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 769 | sde_core_irq_unregister_callback(phys_enc->sde_kms, |
| 770 | wb_enc->irq_idx, irq_cb); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n", |
| 775 | hw_wb->idx - WB_0, |
| 776 | wb_enc->irq_idx); |
| 777 | |
| 778 | return ret; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * sde_encoder_phys_wb_mode_set - set display mode |
| 783 | * @phys_enc: Pointer to physical encoder |
| 784 | * @mode: Pointer to requested display mode |
| 785 | * @adj_mode: Pointer to adjusted display mode |
| 786 | */ |
| 787 | static void sde_encoder_phys_wb_mode_set( |
| 788 | struct sde_encoder_phys *phys_enc, |
| 789 | struct drm_display_mode *mode, |
| 790 | struct drm_display_mode *adj_mode) |
| 791 | { |
| 792 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 793 | struct sde_rm *rm = &phys_enc->sde_kms->rm; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 794 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 795 | struct sde_rm_hw_iter iter; |
| 796 | int i, instance; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 797 | |
| 798 | phys_enc->cached_mode = *adj_mode; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 799 | instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 800 | |
| 801 | SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n", |
| 802 | hw_wb->idx - WB_0, mode->base.id, |
| 803 | mode->name, mode->hdisplay, mode->vdisplay); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 804 | |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 805 | phys_enc->hw_ctl = NULL; |
| 806 | phys_enc->hw_cdm = NULL; |
| 807 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 808 | /* Retrieve previously allocated HW Resources. CTL shouldn't fail */ |
| 809 | sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL); |
| 810 | for (i = 0; i <= instance; i++) { |
| 811 | sde_rm_get_hw(rm, &iter); |
| 812 | if (i == instance) |
| 813 | phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw; |
| 814 | } |
| 815 | |
| 816 | if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) { |
| 817 | SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl)); |
| 818 | phys_enc->hw_ctl = NULL; |
| 819 | return; |
| 820 | } |
| 821 | |
| 822 | /* CDM is optional */ |
| 823 | sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM); |
| 824 | for (i = 0; i <= instance; i++) { |
| 825 | sde_rm_get_hw(rm, &iter); |
| 826 | if (i == instance) |
| 827 | phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw; |
| 828 | } |
| 829 | |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 830 | if (IS_ERR(phys_enc->hw_cdm)) { |
| 831 | SDE_ERROR("CDM required but not allocated: %ld\n", |
| 832 | PTR_ERR(phys_enc->hw_cdm)); |
| 833 | phys_enc->hw_ctl = NULL; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 834 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 838 | * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed |
| 839 | * @phys_enc: Pointer to physical encoder |
| 840 | */ |
| 841 | static int sde_encoder_phys_wb_wait_for_commit_done( |
| 842 | struct sde_encoder_phys *phys_enc) |
| 843 | { |
| 844 | unsigned long ret; |
| 845 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 846 | u32 irq_status, event = 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 847 | u64 wb_time = 0; |
| 848 | int rc = 0; |
Alan Kwong | 5a50a4a | 2017-01-24 19:12:51 -0800 | [diff] [blame] | 849 | u32 timeout = max_t(u32, wb_enc->wbdone_timeout, KICKOFF_TIMEOUT_MS); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 850 | |
| 851 | /* Return EWOULDBLOCK since we know the wait isn't necessary */ |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 852 | if (phys_enc->enable_state == SDE_ENC_DISABLED) { |
| 853 | SDE_ERROR("encoder already disabled\n"); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 854 | return -EWOULDBLOCK; |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 855 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 856 | |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 857 | SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count, |
| 858 | !!wb_enc->wb_fb); |
| 859 | |
| 860 | /* signal completion if commit with no framebuffer */ |
| 861 | if (!wb_enc->wb_fb) { |
| 862 | SDE_DEBUG("no output framebuffer\n"); |
| 863 | sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx); |
| 864 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 865 | |
| 866 | ret = wait_for_completion_timeout(&wb_enc->wbdone_complete, |
Alan Kwong | 5a50a4a | 2017-01-24 19:12:51 -0800 | [diff] [blame] | 867 | msecs_to_jiffies(timeout)); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 868 | |
| 869 | if (!ret) { |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 870 | SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), |
| 871 | wb_enc->frame_count); |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 872 | irq_status = sde_core_irq_read(phys_enc->sde_kms, |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 873 | wb_enc->irq_idx, true); |
| 874 | if (irq_status) { |
| 875 | SDE_DEBUG("wb:%d done but irq not triggered\n", |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 876 | WBID(wb_enc)); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 877 | sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx); |
| 878 | } else { |
| 879 | SDE_ERROR("wb:%d kickoff timed out\n", |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 880 | WBID(wb_enc)); |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 881 | atomic_add_unless( |
| 882 | &phys_enc->pending_retire_fence_cnt, -1, 0); |
| 883 | |
| 884 | event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE |
| 885 | | SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE |
| 886 | | SDE_ENCODER_FRAME_EVENT_ERROR; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 887 | if (phys_enc->parent_ops.handle_frame_done) |
| 888 | phys_enc->parent_ops.handle_frame_done( |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 889 | phys_enc->parent, phys_enc, event); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 890 | rc = -ETIMEDOUT; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | sde_encoder_phys_wb_unregister_irq(phys_enc); |
| 895 | |
| 896 | if (!rc) |
| 897 | wb_enc->end_time = ktime_get(); |
| 898 | |
| 899 | /* once operation is done, disable traffic shaper */ |
| 900 | if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb && |
| 901 | wb_enc->hw_wb->ops.setup_trafficshaper) { |
| 902 | wb_enc->wb_cfg.ts_cfg.en = false; |
| 903 | wb_enc->hw_wb->ops.setup_trafficshaper( |
| 904 | wb_enc->hw_wb, &wb_enc->wb_cfg); |
| 905 | } |
| 906 | |
| 907 | /* remove vote for iommu/clk/bus */ |
| 908 | wb_enc->frame_count++; |
| 909 | |
| 910 | if (!rc) { |
| 911 | wb_time = (u64)ktime_to_us(wb_enc->end_time) - |
| 912 | (u64)ktime_to_us(wb_enc->start_time); |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 913 | SDE_DEBUG("wb:%d took %llu us\n", WBID(wb_enc), wb_time); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 914 | } |
| 915 | |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 916 | /* cleanup writeback framebuffer */ |
| 917 | if (wb_enc->wb_fb && wb_enc->wb_aspace) { |
| 918 | msm_framebuffer_cleanup(wb_enc->wb_fb, wb_enc->wb_aspace); |
| 919 | wb_enc->wb_fb = NULL; |
| 920 | wb_enc->wb_aspace = NULL; |
| 921 | } |
| 922 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 923 | SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count, |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 924 | wb_time, event, rc); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 925 | |
| 926 | return rc; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing |
| 931 | * @phys_enc: Pointer to physical encoder |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 932 | * @params: kickoff parameters |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 933 | * Returns: Zero on success |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 934 | */ |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 935 | static int sde_encoder_phys_wb_prepare_for_kickoff( |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 936 | struct sde_encoder_phys *phys_enc, |
| 937 | struct sde_encoder_kickoff_params *params) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 938 | { |
| 939 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 940 | int ret; |
| 941 | |
| 942 | SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0, |
| 943 | wb_enc->kickoff_count); |
| 944 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 945 | reinit_completion(&wb_enc->wbdone_complete); |
| 946 | |
| 947 | ret = sde_encoder_phys_wb_register_irq(phys_enc); |
| 948 | if (ret) { |
| 949 | SDE_ERROR("failed to register irq %d\n", ret); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 950 | return ret; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | wb_enc->kickoff_count++; |
| 954 | |
| 955 | /* set OT limit & enable traffic shaper */ |
| 956 | sde_encoder_phys_wb_setup(phys_enc); |
| 957 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 958 | _sde_encoder_phys_wb_update_flush(phys_enc); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 959 | |
| 960 | /* vote for iommu/clk/bus */ |
| 961 | wb_enc->start_time = ktime_get(); |
| 962 | |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 963 | SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->kickoff_count); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 964 | return 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /** |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 968 | * sde_encoder_phys_wb_trigger_flush - trigger flush processing |
| 969 | * @phys_enc: Pointer to physical encoder |
| 970 | */ |
| 971 | static void sde_encoder_phys_wb_trigger_flush(struct sde_encoder_phys *phys_enc) |
| 972 | { |
| 973 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 974 | |
| 975 | if (!phys_enc || !wb_enc->hw_wb) { |
| 976 | SDE_ERROR("invalid encoder\n"); |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0); |
| 981 | |
| 982 | /* clear pending flush if commit with no framebuffer */ |
| 983 | if (!wb_enc->wb_fb) { |
| 984 | SDE_DEBUG("no output framebuffer\n"); |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | sde_encoder_helper_trigger_flush(phys_enc); |
| 989 | } |
| 990 | |
| 991 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 992 | * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing |
| 993 | * @phys_enc: Pointer to physical encoder |
| 994 | */ |
| 995 | static void sde_encoder_phys_wb_handle_post_kickoff( |
| 996 | struct sde_encoder_phys *phys_enc) |
| 997 | { |
| 998 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 999 | |
| 1000 | SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0); |
| 1001 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1002 | SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc)); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /** |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1006 | * _sde_encoder_phys_wb_init_internal_fb - create fb for internal commit |
| 1007 | * @wb_enc: Pointer to writeback encoder |
| 1008 | * @pixel_format: DRM pixel format |
| 1009 | * @width: Desired fb width |
| 1010 | * @height: Desired fb height |
Narendra Muppalla | 58a64e2 | 2017-07-24 10:54:47 -0700 | [diff] [blame] | 1011 | * @pitch: Desired fb pitch |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1012 | */ |
| 1013 | static int _sde_encoder_phys_wb_init_internal_fb( |
| 1014 | struct sde_encoder_phys_wb *wb_enc, |
Narendra Muppalla | 58a64e2 | 2017-07-24 10:54:47 -0700 | [diff] [blame] | 1015 | uint32_t pixel_format, uint32_t width, |
| 1016 | uint32_t height, uint32_t pitch) |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1017 | { |
| 1018 | struct drm_device *dev; |
| 1019 | struct drm_framebuffer *fb; |
| 1020 | struct drm_mode_fb_cmd2 mode_cmd; |
| 1021 | uint32_t size; |
| 1022 | int nplanes, i, ret; |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1023 | struct msm_gem_address_space *aspace; |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1024 | |
| 1025 | if (!wb_enc || !wb_enc->base.parent || !wb_enc->base.sde_kms) { |
| 1026 | SDE_ERROR("invalid params\n"); |
| 1027 | return -EINVAL; |
| 1028 | } |
| 1029 | |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1030 | aspace = wb_enc->base.sde_kms->aspace[SDE_IOMMU_DOMAIN_UNSECURE]; |
| 1031 | if (!aspace) { |
| 1032 | SDE_ERROR("invalid address space\n"); |
| 1033 | return -EINVAL; |
| 1034 | } |
| 1035 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1036 | dev = wb_enc->base.sde_kms->dev; |
| 1037 | if (!dev) { |
| 1038 | SDE_ERROR("invalid dev\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | |
| 1042 | memset(&mode_cmd, 0, sizeof(mode_cmd)); |
| 1043 | mode_cmd.pixel_format = pixel_format; |
| 1044 | mode_cmd.width = width; |
| 1045 | mode_cmd.height = height; |
Narendra Muppalla | 58a64e2 | 2017-07-24 10:54:47 -0700 | [diff] [blame] | 1046 | mode_cmd.pitches[0] = pitch; |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1047 | |
| 1048 | size = sde_format_get_framebuffer_size(pixel_format, |
Narendra Muppalla | 58a64e2 | 2017-07-24 10:54:47 -0700 | [diff] [blame] | 1049 | mode_cmd.width, mode_cmd.height, |
| 1050 | mode_cmd.pitches, NULL, 0); |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1051 | if (!size) { |
| 1052 | SDE_DEBUG("not creating zero size buffer\n"); |
| 1053 | return -EINVAL; |
| 1054 | } |
| 1055 | |
| 1056 | /* allocate gem tracking object */ |
| 1057 | nplanes = drm_format_num_planes(pixel_format); |
| 1058 | if (nplanes > SDE_MAX_PLANES) { |
| 1059 | SDE_ERROR("requested format has too many planes\n"); |
| 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | mutex_lock(&dev->struct_mutex); |
| 1063 | wb_enc->bo_disable[0] = msm_gem_new(dev, size, |
| 1064 | MSM_BO_SCANOUT | MSM_BO_WC); |
| 1065 | mutex_unlock(&dev->struct_mutex); |
| 1066 | |
| 1067 | if (IS_ERR_OR_NULL(wb_enc->bo_disable[0])) { |
| 1068 | ret = PTR_ERR(wb_enc->bo_disable[0]); |
| 1069 | wb_enc->bo_disable[0] = NULL; |
| 1070 | |
| 1071 | SDE_ERROR("failed to create bo, %d\n", ret); |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
| 1075 | for (i = 0; i < nplanes; ++i) { |
| 1076 | wb_enc->bo_disable[i] = wb_enc->bo_disable[0]; |
| 1077 | mode_cmd.pitches[i] = width * |
| 1078 | drm_format_plane_cpp(pixel_format, i); |
| 1079 | } |
| 1080 | |
| 1081 | fb = msm_framebuffer_init(dev, &mode_cmd, wb_enc->bo_disable); |
| 1082 | if (IS_ERR_OR_NULL(fb)) { |
| 1083 | ret = PTR_ERR(fb); |
| 1084 | drm_gem_object_unreference(wb_enc->bo_disable[0]); |
| 1085 | wb_enc->bo_disable[0] = NULL; |
| 1086 | |
| 1087 | SDE_ERROR("failed to init fb, %d\n", ret); |
| 1088 | return ret; |
| 1089 | } |
| 1090 | |
| 1091 | /* prepare the backing buffer now so that it's available later */ |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1092 | ret = msm_framebuffer_prepare(fb, aspace); |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1093 | if (!ret) |
| 1094 | wb_enc->fb_disable = fb; |
| 1095 | return ret; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * _sde_encoder_phys_wb_destroy_internal_fb - deconstruct internal fb |
| 1100 | * @wb_enc: Pointer to writeback encoder |
| 1101 | */ |
| 1102 | static void _sde_encoder_phys_wb_destroy_internal_fb( |
| 1103 | struct sde_encoder_phys_wb *wb_enc) |
| 1104 | { |
| 1105 | if (!wb_enc) |
| 1106 | return; |
| 1107 | |
| 1108 | if (wb_enc->fb_disable) { |
| 1109 | drm_framebuffer_unregister_private(wb_enc->fb_disable); |
| 1110 | drm_framebuffer_remove(wb_enc->fb_disable); |
| 1111 | wb_enc->fb_disable = NULL; |
| 1112 | } |
| 1113 | |
| 1114 | if (wb_enc->bo_disable[0]) { |
| 1115 | drm_gem_object_unreference(wb_enc->bo_disable[0]); |
| 1116 | wb_enc->bo_disable[0] = NULL; |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1121 | * sde_encoder_phys_wb_enable - enable writeback encoder |
| 1122 | * @phys_enc: Pointer to physical encoder |
| 1123 | */ |
| 1124 | static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc) |
| 1125 | { |
| 1126 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 1127 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
Alan Kwong | 74e8ba3 | 2016-09-30 14:25:16 -0400 | [diff] [blame] | 1128 | struct drm_device *dev; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1129 | struct drm_connector *connector; |
| 1130 | |
| 1131 | SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0); |
| 1132 | |
Alan Kwong | 74e8ba3 | 2016-09-30 14:25:16 -0400 | [diff] [blame] | 1133 | if (!wb_enc->base.parent || !wb_enc->base.parent->dev) { |
| 1134 | SDE_ERROR("invalid drm device\n"); |
| 1135 | return; |
| 1136 | } |
| 1137 | dev = wb_enc->base.parent->dev; |
| 1138 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1139 | /* find associated writeback connector */ |
Clarence Ip | 05431f3 | 2016-11-25 16:39:38 -0500 | [diff] [blame] | 1140 | connector = phys_enc->connector; |
Alan Kwong | 74e8ba3 | 2016-09-30 14:25:16 -0400 | [diff] [blame] | 1141 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1142 | if (!connector || connector->encoder != phys_enc->parent) { |
| 1143 | SDE_ERROR("failed to find writeback connector\n"); |
| 1144 | return; |
| 1145 | } |
| 1146 | wb_enc->wb_dev = sde_wb_connector_get_wb(connector); |
| 1147 | |
| 1148 | phys_enc->enable_state = SDE_ENC_ENABLED; |
Harsh Sahu | fae4d81 | 2017-11-29 15:08:59 -0800 | [diff] [blame] | 1149 | |
| 1150 | /* |
| 1151 | * cache the crtc in wb_enc on enable for duration of use case |
| 1152 | * for correctly servicing asynchronous irq events and timers |
| 1153 | */ |
| 1154 | wb_enc->crtc = phys_enc->parent->crtc; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * sde_encoder_phys_wb_disable - disable writeback encoder |
| 1159 | * @phys_enc: Pointer to physical encoder |
| 1160 | */ |
| 1161 | static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc) |
| 1162 | { |
| 1163 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 1164 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 1165 | |
| 1166 | SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0); |
| 1167 | |
| 1168 | if (phys_enc->enable_state == SDE_ENC_DISABLED) { |
| 1169 | SDE_ERROR("encoder is already disabled\n"); |
| 1170 | return; |
| 1171 | } |
| 1172 | |
| 1173 | if (wb_enc->frame_count != wb_enc->kickoff_count) { |
| 1174 | SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n", |
| 1175 | hw_wb->idx - WB_0, wb_enc->frame_count, |
| 1176 | wb_enc->kickoff_count); |
| 1177 | sde_encoder_phys_wb_wait_for_commit_done(phys_enc); |
| 1178 | } |
| 1179 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1180 | if (!phys_enc->hw_ctl || !phys_enc->parent || |
| 1181 | !phys_enc->sde_kms || !wb_enc->fb_disable) { |
| 1182 | SDE_DEBUG("invalid enc, skipping extra commit\n"); |
| 1183 | goto exit; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1186 | /* reset h/w before final flush */ |
Clarence Ip | 662698e | 2017-09-12 18:34:16 -0400 | [diff] [blame] | 1187 | if (phys_enc->hw_ctl->ops.clear_pending_flush) |
| 1188 | phys_enc->hw_ctl->ops.clear_pending_flush(phys_enc->hw_ctl); |
| 1189 | if (sde_encoder_helper_reset_mixers(phys_enc, wb_enc->fb_disable)) |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1190 | goto exit; |
| 1191 | |
| 1192 | phys_enc->enable_state = SDE_ENC_DISABLING; |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 1193 | sde_encoder_phys_wb_prepare_for_kickoff(phys_enc, NULL); |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1194 | if (phys_enc->hw_ctl->ops.trigger_flush) |
| 1195 | phys_enc->hw_ctl->ops.trigger_flush(phys_enc->hw_ctl); |
| 1196 | sde_encoder_helper_trigger_start(phys_enc); |
| 1197 | sde_encoder_phys_wb_wait_for_commit_done(phys_enc); |
| 1198 | exit: |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1199 | phys_enc->enable_state = SDE_ENC_DISABLED; |
Harsh Sahu | fae4d81 | 2017-11-29 15:08:59 -0800 | [diff] [blame] | 1200 | wb_enc->crtc = NULL; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * sde_encoder_phys_wb_get_hw_resources - get hardware resources |
| 1205 | * @phys_enc: Pointer to physical encoder |
| 1206 | * @hw_res: Pointer to encoder resources |
| 1207 | */ |
| 1208 | static void sde_encoder_phys_wb_get_hw_resources( |
| 1209 | struct sde_encoder_phys *phys_enc, |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1210 | struct sde_encoder_hw_resources *hw_res, |
| 1211 | struct drm_connector_state *conn_state) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1212 | { |
| 1213 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 1214 | struct sde_hw_wb *hw_wb; |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 1215 | struct drm_framebuffer *fb; |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 1216 | const struct sde_format *fmt = NULL; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1217 | |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 1218 | if (!phys_enc) { |
| 1219 | SDE_ERROR("invalid encoder\n"); |
| 1220 | return; |
| 1221 | } |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 1222 | |
| 1223 | fb = sde_wb_connector_state_get_output_fb(conn_state); |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 1224 | if (fb) { |
| 1225 | fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier, |
| 1226 | drm_format_num_planes(fb->pixel_format)); |
| 1227 | if (!fmt) { |
| 1228 | SDE_ERROR("unsupported output pixel format:%d\n", |
| 1229 | fb->pixel_format); |
| 1230 | return; |
| 1231 | } |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 1234 | hw_wb = wb_enc->hw_wb; |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 1235 | hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode; |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 1236 | hw_res->needs_cdm = fmt ? SDE_FORMAT_IS_YUV(fmt) : false; |
Alan Kwong | 4c3cf4c | 2016-09-25 20:08:09 -0400 | [diff] [blame] | 1237 | SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0, |
| 1238 | hw_res->wbs[hw_wb->idx - WB_0], |
| 1239 | hw_res->needs_cdm); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1240 | } |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1241 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1242 | #ifdef CONFIG_DEBUG_FS |
| 1243 | /** |
| 1244 | * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1245 | * @phys_enc: Pointer to physical encoder |
| 1246 | * @debugfs_root: Pointer to virtual encoder's debugfs_root dir |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1247 | */ |
| 1248 | static int sde_encoder_phys_wb_init_debugfs( |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1249 | struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1250 | { |
| 1251 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 1252 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1253 | if (!phys_enc || !wb_enc->hw_wb || !debugfs_root) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1254 | return -EINVAL; |
| 1255 | |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 1256 | if (!debugfs_create_u32("wbdone_timeout", 0600, |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1257 | debugfs_root, &wb_enc->wbdone_timeout)) { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1258 | SDE_ERROR("failed to create debugfs/wbdone_timeout\n"); |
| 1259 | return -ENOMEM; |
| 1260 | } |
| 1261 | |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 1262 | if (!debugfs_create_u32("bypass_irqreg", 0600, |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1263 | debugfs_root, &wb_enc->bypass_irqreg)) { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1264 | SDE_ERROR("failed to create debugfs/bypass_irqreg\n"); |
| 1265 | return -ENOMEM; |
| 1266 | } |
| 1267 | |
| 1268 | return 0; |
| 1269 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1270 | #else |
Dhaval Patel | 48f2d0f | 2016-09-27 16:39:12 -0700 | [diff] [blame] | 1271 | static int sde_encoder_phys_wb_init_debugfs( |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1272 | struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1273 | { |
Dhaval Patel | 48f2d0f | 2016-09-27 16:39:12 -0700 | [diff] [blame] | 1274 | return 0; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1275 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1276 | #endif |
| 1277 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1278 | static int sde_encoder_phys_wb_late_register(struct sde_encoder_phys *phys_enc, |
| 1279 | struct dentry *debugfs_root) |
| 1280 | { |
| 1281 | return sde_encoder_phys_wb_init_debugfs(phys_enc, debugfs_root); |
| 1282 | } |
| 1283 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1284 | /** |
| 1285 | * sde_encoder_phys_wb_destroy - destroy writeback encoder |
| 1286 | * @phys_enc: Pointer to physical encoder |
| 1287 | */ |
| 1288 | static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc) |
| 1289 | { |
| 1290 | struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc); |
| 1291 | struct sde_hw_wb *hw_wb = wb_enc->hw_wb; |
| 1292 | |
| 1293 | SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0); |
| 1294 | |
| 1295 | if (!phys_enc) |
| 1296 | return; |
| 1297 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1298 | _sde_encoder_phys_wb_destroy_internal_fb(wb_enc); |
| 1299 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1300 | kfree(wb_enc); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * sde_encoder_phys_wb_init_ops - initialize writeback operations |
| 1305 | * @ops: Pointer to encoder operation table |
| 1306 | */ |
| 1307 | static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops) |
| 1308 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1309 | ops->late_register = sde_encoder_phys_wb_late_register; |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1310 | ops->is_master = sde_encoder_phys_wb_is_master; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1311 | ops->mode_set = sde_encoder_phys_wb_mode_set; |
| 1312 | ops->enable = sde_encoder_phys_wb_enable; |
| 1313 | ops->disable = sde_encoder_phys_wb_disable; |
| 1314 | ops->destroy = sde_encoder_phys_wb_destroy; |
| 1315 | ops->atomic_check = sde_encoder_phys_wb_atomic_check; |
| 1316 | ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1317 | ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done; |
| 1318 | ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff; |
| 1319 | ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff; |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 1320 | ops->trigger_flush = sde_encoder_phys_wb_trigger_flush; |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 1321 | ops->trigger_start = sde_encoder_helper_trigger_start; |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 1322 | ops->hw_reset = sde_encoder_helper_hw_reset; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * sde_encoder_phys_wb_init - initialize writeback encoder |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 1327 | * @init: Pointer to init info structure with initialization params |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1328 | */ |
| 1329 | struct sde_encoder_phys *sde_encoder_phys_wb_init( |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 1330 | struct sde_enc_phys_init_params *p) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1331 | { |
| 1332 | struct sde_encoder_phys *phys_enc; |
| 1333 | struct sde_encoder_phys_wb *wb_enc; |
| 1334 | struct sde_hw_mdp *hw_mdp; |
| 1335 | int ret = 0; |
| 1336 | |
| 1337 | SDE_DEBUG("\n"); |
| 1338 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1339 | if (!p || !p->parent) { |
| 1340 | SDE_ERROR("invalid params\n"); |
| 1341 | ret = -EINVAL; |
| 1342 | goto fail_alloc; |
| 1343 | } |
| 1344 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1345 | wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL); |
| 1346 | if (!wb_enc) { |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1347 | SDE_ERROR("failed to allocate wb enc\n"); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1348 | ret = -ENOMEM; |
| 1349 | goto fail_alloc; |
| 1350 | } |
| 1351 | wb_enc->irq_idx = -EINVAL; |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 1352 | wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1353 | init_completion(&wb_enc->wbdone_complete); |
| 1354 | |
| 1355 | phys_enc = &wb_enc->base; |
| 1356 | |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 1357 | if (p->sde_kms->vbif[VBIF_NRT]) { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1358 | wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 1359 | p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_UNSECURE]; |
| 1360 | wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] = |
| 1361 | p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_SECURE]; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1362 | } else { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1363 | wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 1364 | p->sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE]; |
| 1365 | wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] = |
| 1366 | p->sde_kms->aspace[MSM_SMMU_DOMAIN_SECURE]; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1369 | hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1370 | if (IS_ERR_OR_NULL(hw_mdp)) { |
| 1371 | ret = PTR_ERR(hw_mdp); |
| 1372 | SDE_ERROR("failed to init hw_top: %d\n", ret); |
| 1373 | goto fail_mdp_init; |
| 1374 | } |
| 1375 | phys_enc->hw_mdptop = hw_mdp; |
| 1376 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1377 | /** |
| 1378 | * hw_wb resource permanently assigned to this encoder |
| 1379 | * Other resources allocated at atomic commit time by use case |
| 1380 | */ |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 1381 | if (p->wb_idx != SDE_NONE) { |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1382 | struct sde_rm_hw_iter iter; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1383 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1384 | sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB); |
| 1385 | while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) { |
| 1386 | struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw; |
| 1387 | |
| 1388 | if (hw_wb->idx == p->wb_idx) { |
| 1389 | wb_enc->hw_wb = hw_wb; |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | if (!wb_enc->hw_wb) { |
| 1395 | ret = -EINVAL; |
| 1396 | SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1397 | goto fail_wb_init; |
| 1398 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1399 | } else { |
| 1400 | ret = -EINVAL; |
| 1401 | SDE_ERROR("invalid wb_idx\n"); |
| 1402 | goto fail_wb_check; |
| 1403 | } |
| 1404 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1405 | sde_encoder_phys_wb_init_ops(&phys_enc->ops); |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 1406 | phys_enc->parent = p->parent; |
| 1407 | phys_enc->parent_ops = p->parent_ops; |
| 1408 | phys_enc->sde_kms = p->sde_kms; |
| 1409 | phys_enc->split_role = p->split_role; |
Clarence Ip | 0352198 | 2016-08-26 10:49:47 -0400 | [diff] [blame] | 1410 | phys_enc->intf_mode = INTF_MODE_WB_LINE; |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 1411 | phys_enc->intf_idx = p->intf_idx; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 1412 | phys_enc->enc_spinlock = p->enc_spinlock; |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 1413 | atomic_set(&phys_enc->pending_retire_fence_cnt, 0); |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 1414 | INIT_LIST_HEAD(&wb_enc->irq_cb.list); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1415 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1416 | /* create internal buffer for disable logic */ |
| 1417 | if (_sde_encoder_phys_wb_init_internal_fb(wb_enc, |
Narendra Muppalla | 58a64e2 | 2017-07-24 10:54:47 -0700 | [diff] [blame] | 1418 | DRM_FORMAT_RGB888, 2, 1, 6)) { |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 1419 | SDE_ERROR("failed to init internal fb\n"); |
| 1420 | goto fail_wb_init; |
| 1421 | } |
| 1422 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1423 | SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n", |
| 1424 | wb_enc->hw_wb->idx - WB_0); |
| 1425 | |
| 1426 | return phys_enc; |
| 1427 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1428 | fail_wb_init: |
| 1429 | fail_wb_check: |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 1430 | fail_mdp_init: |
| 1431 | kfree(wb_enc); |
| 1432 | fail_alloc: |
| 1433 | return ERR_PTR(ret); |
| 1434 | } |
| 1435 | |