Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 12 | |
| 13 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
| 14 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 15 | #include <linux/debugfs.h> |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 16 | #include <uapi/drm/sde_drm.h> |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 17 | |
| 18 | #include "msm_prop.h" |
| 19 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 20 | #include "sde_kms.h" |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 21 | #include "sde_fence.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 22 | #include "sde_formats.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 23 | #include "sde_hw_sspp.h" |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 24 | #include "sde_trace.h" |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame^] | 25 | #include "sde_crtc.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 26 | |
| 27 | #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci)) |
| 28 | #define PHASE_STEP_SHIFT 21 |
| 29 | #define PHASE_STEP_UNIT_SCALE ((int) (1 << PHASE_STEP_SHIFT)) |
| 30 | #define PHASE_RESIDUAL 15 |
| 31 | |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 32 | #define SHARP_STRENGTH_DEFAULT 32 |
| 33 | #define SHARP_EDGE_THR_DEFAULT 112 |
| 34 | #define SHARP_SMOOTH_THR_DEFAULT 8 |
| 35 | #define SHARP_NOISE_THR_DEFAULT 2 |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 36 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 37 | #define SDE_NAME_SIZE 12 |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 38 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 39 | #define SDE_PLANE_COLOR_FILL_FLAG BIT(31) |
| 40 | |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 41 | /** |
| 42 | * enum sde_plane_qos - Different qos configurations for each pipe |
| 43 | * |
| 44 | * @SDE_PLANE_QOS_VBLANK_CTRL: Setup VBLANK qos for the pipe. |
| 45 | * @SDE_PLANE_QOS_VBLANK_AMORTIZE: Enables Amortization within pipe. |
| 46 | * this configuration is mutually exclusive from VBLANK_CTRL. |
| 47 | * @SDE_PLANE_QOS_PANIC_CTRL: Setup panic for the pipe. |
| 48 | */ |
| 49 | enum sde_plane_qos { |
| 50 | SDE_PLANE_QOS_VBLANK_CTRL = BIT(0), |
| 51 | SDE_PLANE_QOS_VBLANK_AMORTIZE = BIT(1), |
| 52 | SDE_PLANE_QOS_PANIC_CTRL = BIT(2), |
| 53 | }; |
| 54 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 55 | struct sde_plane { |
| 56 | struct drm_plane base; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 57 | |
| 58 | int mmu_id; |
| 59 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 60 | struct mutex lock; |
| 61 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 62 | enum sde_sspp pipe; |
| 63 | uint32_t features; /* capabilities from catalog */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 64 | uint32_t nformats; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 65 | uint32_t formats[64]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 66 | |
| 67 | struct sde_hw_pipe *pipe_hw; |
| 68 | struct sde_hw_pipe_cfg pipe_cfg; |
| 69 | struct sde_hw_pixel_ext pixel_ext; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 70 | struct sde_hw_sharp_cfg sharp_cfg; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 71 | struct sde_hw_scaler3_cfg scaler3_cfg; |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 72 | struct sde_hw_pipe_qos_cfg pipe_qos_cfg; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 73 | uint32_t color_fill; |
| 74 | bool is_error; |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 75 | bool is_rt_pipe; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 76 | |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 77 | struct sde_csc_cfg csc_cfg; |
| 78 | struct sde_csc_cfg *csc_ptr; |
| 79 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 80 | const struct sde_sspp_sub_blks *pipe_sblk; |
| 81 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 82 | char pipe_name[SDE_NAME_SIZE]; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 83 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 84 | struct msm_property_info property_info; |
| 85 | struct msm_property_data property_data[PLANE_PROP_COUNT]; |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 86 | struct drm_property_blob *blob_info; |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 87 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 88 | /* debugfs related stuff */ |
| 89 | struct dentry *debugfs_root; |
| 90 | struct sde_debugfs_regset32 debugfs_src; |
| 91 | struct sde_debugfs_regset32 debugfs_scaler; |
| 92 | struct sde_debugfs_regset32 debugfs_csc; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 93 | }; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 94 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 95 | #define to_sde_plane(x) container_of(x, struct sde_plane, base) |
| 96 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 97 | static bool sde_plane_enabled(struct drm_plane_state *state) |
| 98 | { |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 99 | return state && state->fb && state->crtc; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 102 | /** |
| 103 | * _sde_plane_calc_fill_level - calculate fill level of the given source format |
| 104 | * @plane: Pointer to drm plane |
| 105 | * @fmt: Pointer to source buffer format |
| 106 | * @src_wdith: width of source buffer |
| 107 | * Return: fill level corresponding to the source buffer/format or 0 if error |
| 108 | */ |
| 109 | static inline int _sde_plane_calc_fill_level(struct drm_plane *plane, |
| 110 | const struct sde_format *fmt, u32 src_width) |
| 111 | { |
| 112 | struct sde_plane *psde; |
| 113 | u32 fixed_buff_size; |
| 114 | u32 total_fl; |
| 115 | |
| 116 | if (!plane || !fmt) { |
| 117 | SDE_ERROR("invalid arguments\n"); |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | psde = to_sde_plane(plane); |
| 122 | fixed_buff_size = psde->pipe_sblk->pixel_ram_size; |
| 123 | |
| 124 | if (fmt->fetch_planes == SDE_PLANE_PSEUDO_PLANAR) { |
| 125 | if (fmt->chroma_sample == SDE_CHROMA_420) { |
| 126 | /* NV12 */ |
| 127 | total_fl = (fixed_buff_size / 2) / |
| 128 | ((src_width + 32) * fmt->bpp); |
| 129 | } else { |
| 130 | /* non NV12 */ |
| 131 | total_fl = (fixed_buff_size) / |
| 132 | ((src_width + 32) * fmt->bpp); |
| 133 | } |
| 134 | } else { |
| 135 | total_fl = (fixed_buff_size * 2) / |
| 136 | ((src_width + 32) * fmt->bpp); |
| 137 | } |
| 138 | |
| 139 | SDE_DEBUG("plane%u: pnum:%d fmt:%x w:%u fl:%u\n", |
| 140 | plane->base.id, psde->pipe - SSPP_VIG0, |
| 141 | fmt->base.pixel_format, src_width, total_fl); |
| 142 | |
| 143 | return total_fl; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * _sde_plane_get_qos_lut_linear - get linear LUT mapping |
| 148 | * @total_fl: fill level |
| 149 | * Return: LUT setting corresponding to the fill level |
| 150 | */ |
| 151 | static inline u32 _sde_plane_get_qos_lut_linear(u32 total_fl) |
| 152 | { |
| 153 | u32 qos_lut; |
| 154 | |
| 155 | if (total_fl <= 4) |
| 156 | qos_lut = 0x1B; |
| 157 | else if (total_fl <= 5) |
| 158 | qos_lut = 0x5B; |
| 159 | else if (total_fl <= 6) |
| 160 | qos_lut = 0x15B; |
| 161 | else if (total_fl <= 7) |
| 162 | qos_lut = 0x55B; |
| 163 | else if (total_fl <= 8) |
| 164 | qos_lut = 0x155B; |
| 165 | else if (total_fl <= 9) |
| 166 | qos_lut = 0x555B; |
| 167 | else if (total_fl <= 10) |
| 168 | qos_lut = 0x1555B; |
| 169 | else if (total_fl <= 11) |
| 170 | qos_lut = 0x5555B; |
| 171 | else if (total_fl <= 12) |
| 172 | qos_lut = 0x15555B; |
| 173 | else |
| 174 | qos_lut = 0x55555B; |
| 175 | |
| 176 | return qos_lut; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * _sde_plane_get_qos_lut_macrotile - get macrotile LUT mapping |
| 181 | * @total_fl: fill level |
| 182 | * Return: LUT setting corresponding to the fill level |
| 183 | */ |
| 184 | static inline u32 _sde_plane_get_qos_lut_macrotile(u32 total_fl) |
| 185 | { |
| 186 | u32 qos_lut; |
| 187 | |
| 188 | if (total_fl <= 10) |
| 189 | qos_lut = 0x1AAff; |
| 190 | else if (total_fl <= 11) |
| 191 | qos_lut = 0x5AAFF; |
| 192 | else if (total_fl <= 12) |
| 193 | qos_lut = 0x15AAFF; |
| 194 | else |
| 195 | qos_lut = 0x55AAFF; |
| 196 | |
| 197 | return qos_lut; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * _sde_plane_is_rt_pipe - check if the given plane requires real-time QoS |
| 202 | * @plane: Pointer to drm plane |
| 203 | * @crtc: Pointer to drm crtc associated with the given plane |
| 204 | */ |
| 205 | static bool _sde_plane_is_rt_pipe(struct drm_plane *plane, |
| 206 | struct drm_crtc *crtc) |
| 207 | { |
| 208 | struct sde_plane *psde = to_sde_plane(plane); |
| 209 | struct drm_connector *connector; |
| 210 | bool is_rt = false; |
| 211 | |
| 212 | /* check if this plane has a physical connector interface */ |
| 213 | drm_for_each_connector(connector, plane->dev) |
| 214 | if (connector->state && |
| 215 | (connector->state->crtc == crtc) && |
| 216 | (connector->connector_type |
| 217 | != DRM_MODE_CONNECTOR_VIRTUAL)) { |
| 218 | is_rt = true; |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | SDE_DEBUG("plane%u: pnum:%d rt:%d\n", |
| 223 | plane->base.id, psde->pipe - SSPP_VIG0, is_rt); |
| 224 | |
| 225 | return is_rt; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * _sde_plane_set_qos_lut - set QoS LUT of the given plane |
| 230 | * @plane: Pointer to drm plane |
| 231 | * @fb: Pointer to framebuffer associated with the given plane |
| 232 | */ |
| 233 | static void _sde_plane_set_qos_lut(struct drm_plane *plane, |
| 234 | struct drm_framebuffer *fb) |
| 235 | { |
| 236 | struct sde_plane *psde; |
| 237 | const struct sde_format *fmt = NULL; |
| 238 | u32 qos_lut; |
| 239 | u32 total_fl = 0; |
| 240 | |
| 241 | if (!plane || !fb) { |
| 242 | SDE_ERROR("invalid arguments plane %d fb %d\n", |
| 243 | plane != 0, fb != 0); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | psde = to_sde_plane(plane); |
| 248 | |
| 249 | if (!psde->pipe_hw || !psde->pipe_sblk) { |
| 250 | SDE_ERROR("invalid arguments\n"); |
| 251 | return; |
| 252 | } else if (!psde->pipe_hw->ops.setup_creq_lut) { |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | if (!psde->is_rt_pipe) { |
| 257 | qos_lut = psde->pipe_sblk->creq_lut_nrt; |
| 258 | } else { |
| 259 | fmt = sde_get_sde_format_ext( |
| 260 | fb->pixel_format, |
| 261 | fb->modifier, |
| 262 | drm_format_num_planes(fb->pixel_format)); |
| 263 | total_fl = _sde_plane_calc_fill_level(plane, fmt, |
| 264 | psde->pipe_cfg.src_rect.w); |
| 265 | |
| 266 | if (SDE_FORMAT_IS_LINEAR(fmt)) |
| 267 | qos_lut = _sde_plane_get_qos_lut_linear(total_fl); |
| 268 | else |
| 269 | qos_lut = _sde_plane_get_qos_lut_macrotile(total_fl); |
| 270 | } |
| 271 | |
| 272 | psde->pipe_qos_cfg.creq_lut = qos_lut; |
| 273 | |
| 274 | trace_sde_perf_set_qos_luts(psde->pipe - SSPP_VIG0, |
| 275 | (fmt) ? fmt->base.pixel_format : 0, |
| 276 | psde->is_rt_pipe, total_fl, qos_lut, |
| 277 | (fmt) ? SDE_FORMAT_IS_LINEAR(fmt) : 0); |
| 278 | |
| 279 | SDE_DEBUG("plane%u: pnum:%d fmt:%x rt:%d fl:%u lut:0x%x\n", |
| 280 | plane->base.id, |
| 281 | psde->pipe - SSPP_VIG0, |
| 282 | (fmt) ? fmt->base.pixel_format : 0, |
| 283 | psde->is_rt_pipe, total_fl, qos_lut); |
| 284 | |
| 285 | psde->pipe_hw->ops.setup_creq_lut(psde->pipe_hw, &psde->pipe_qos_cfg); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * _sde_plane_set_panic_lut - set danger/safe LUT of the given plane |
| 290 | * @plane: Pointer to drm plane |
| 291 | * @fb: Pointer to framebuffer associated with the given plane |
| 292 | */ |
| 293 | static void _sde_plane_set_danger_lut(struct drm_plane *plane, |
| 294 | struct drm_framebuffer *fb) |
| 295 | { |
| 296 | struct sde_plane *psde; |
| 297 | const struct sde_format *fmt = NULL; |
| 298 | u32 danger_lut, safe_lut; |
| 299 | |
| 300 | if (!plane || !fb) { |
| 301 | SDE_ERROR("invalid arguments\n"); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | psde = to_sde_plane(plane); |
| 306 | |
| 307 | if (!psde->pipe_hw || !psde->pipe_sblk) { |
| 308 | SDE_ERROR("invalid arguments\n"); |
| 309 | return; |
| 310 | } else if (!psde->pipe_hw->ops.setup_danger_safe_lut) { |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | if (!psde->is_rt_pipe) { |
| 315 | danger_lut = psde->pipe_sblk->danger_lut_nrt; |
| 316 | safe_lut = psde->pipe_sblk->safe_lut_nrt; |
| 317 | } else { |
| 318 | fmt = sde_get_sde_format_ext( |
| 319 | fb->pixel_format, |
| 320 | fb->modifier, |
| 321 | drm_format_num_planes(fb->pixel_format)); |
| 322 | |
| 323 | if (SDE_FORMAT_IS_LINEAR(fmt)) { |
| 324 | danger_lut = psde->pipe_sblk->danger_lut_linear; |
| 325 | safe_lut = psde->pipe_sblk->safe_lut_linear; |
| 326 | } else { |
| 327 | danger_lut = psde->pipe_sblk->danger_lut_tile; |
| 328 | safe_lut = psde->pipe_sblk->safe_lut_tile; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | psde->pipe_qos_cfg.danger_lut = danger_lut; |
| 333 | psde->pipe_qos_cfg.safe_lut = safe_lut; |
| 334 | |
| 335 | trace_sde_perf_set_danger_luts(psde->pipe - SSPP_VIG0, |
| 336 | (fmt) ? fmt->base.pixel_format : 0, |
| 337 | (fmt) ? fmt->fetch_mode : 0, |
| 338 | psde->pipe_qos_cfg.danger_lut, |
| 339 | psde->pipe_qos_cfg.safe_lut); |
| 340 | |
| 341 | SDE_DEBUG("plane%u: pnum:%d fmt:%x mode:%d luts[0x%x, 0x%x]\n", |
| 342 | plane->base.id, |
| 343 | psde->pipe - SSPP_VIG0, |
| 344 | fmt ? fmt->base.pixel_format : 0, |
| 345 | fmt ? fmt->fetch_mode : -1, |
| 346 | psde->pipe_qos_cfg.danger_lut, |
| 347 | psde->pipe_qos_cfg.safe_lut); |
| 348 | |
| 349 | psde->pipe_hw->ops.setup_danger_safe_lut(psde->pipe_hw, |
| 350 | &psde->pipe_qos_cfg); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * _sde_plane_set_qos_ctrl - set QoS control of the given plane |
| 355 | * @plane: Pointer to drm plane |
| 356 | * @enable: true to enable QoS control |
| 357 | * @flags: QoS control mode (enum sde_plane_qos) |
| 358 | */ |
| 359 | static void _sde_plane_set_qos_ctrl(struct drm_plane *plane, |
| 360 | bool enable, u32 flags) |
| 361 | { |
| 362 | struct sde_plane *psde; |
| 363 | |
| 364 | if (!plane) { |
| 365 | SDE_ERROR("invalid arguments\n"); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | psde = to_sde_plane(plane); |
| 370 | |
| 371 | if (!psde->pipe_hw || !psde->pipe_sblk) { |
| 372 | SDE_ERROR("invalid arguments\n"); |
| 373 | return; |
| 374 | } else if (!psde->pipe_hw->ops.setup_qos_ctrl) { |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | if (flags & SDE_PLANE_QOS_VBLANK_CTRL) { |
| 379 | psde->pipe_qos_cfg.creq_vblank = psde->pipe_sblk->creq_vblank; |
| 380 | psde->pipe_qos_cfg.danger_vblank = |
| 381 | psde->pipe_sblk->danger_vblank; |
| 382 | psde->pipe_qos_cfg.vblank_en = enable; |
| 383 | } |
| 384 | |
| 385 | if (flags & SDE_PLANE_QOS_VBLANK_AMORTIZE) { |
| 386 | /* this feature overrules previous VBLANK_CTRL */ |
| 387 | psde->pipe_qos_cfg.vblank_en = false; |
| 388 | psde->pipe_qos_cfg.creq_vblank = 0; /* clear vblank bits */ |
| 389 | } |
| 390 | |
| 391 | if (flags & SDE_PLANE_QOS_PANIC_CTRL) |
| 392 | psde->pipe_qos_cfg.danger_safe_en = enable; |
| 393 | |
| 394 | if (!psde->is_rt_pipe) { |
| 395 | psde->pipe_qos_cfg.vblank_en = false; |
| 396 | psde->pipe_qos_cfg.danger_safe_en = false; |
| 397 | } |
| 398 | |
| 399 | SDE_DEBUG("plane%u: pnum:%d ds:%d vb:%d pri[0x%x, 0x%x]\n", |
| 400 | plane->base.id, |
| 401 | psde->pipe - SSPP_VIG0, |
| 402 | psde->pipe_qos_cfg.danger_safe_en, |
| 403 | psde->pipe_qos_cfg.vblank_en, |
| 404 | psde->pipe_qos_cfg.creq_vblank, |
| 405 | psde->pipe_qos_cfg.danger_vblank); |
| 406 | |
| 407 | psde->pipe_hw->ops.setup_qos_ctrl(psde->pipe_hw, |
| 408 | &psde->pipe_qos_cfg); |
| 409 | } |
| 410 | |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 411 | /** |
| 412 | * _sde_plane_set_ot_limit - set OT limit for the given plane |
| 413 | * @plane: Pointer to drm plane |
| 414 | * @crtc: Pointer to drm crtc |
| 415 | */ |
| 416 | static void _sde_plane_set_ot_limit(struct drm_plane *plane, |
| 417 | struct drm_crtc *crtc) |
| 418 | { |
| 419 | struct sde_plane *psde; |
| 420 | struct sde_vbif_set_ot_params ot_params; |
| 421 | struct msm_drm_private *priv; |
| 422 | struct sde_kms *sde_kms; |
| 423 | |
| 424 | if (!plane || !plane->dev || !crtc) { |
| 425 | SDE_ERROR("invalid arguments plane %d crtc %d\n", |
| 426 | plane != 0, crtc != 0); |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | priv = plane->dev->dev_private; |
| 431 | if (!priv || !priv->kms) { |
| 432 | SDE_ERROR("invalid KMS reference\n"); |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | sde_kms = to_sde_kms(priv->kms); |
| 437 | psde = to_sde_plane(plane); |
| 438 | if (!psde->pipe_hw) { |
| 439 | SDE_ERROR("invalid pipe reference\n"); |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | memset(&ot_params, 0, sizeof(ot_params)); |
| 444 | ot_params.xin_id = psde->pipe_hw->cap->xin_id; |
| 445 | ot_params.num = psde->pipe_hw->idx - SSPP_NONE; |
| 446 | ot_params.width = psde->pipe_cfg.src_rect.w; |
| 447 | ot_params.height = psde->pipe_cfg.src_rect.h; |
| 448 | ot_params.is_wfd = !psde->is_rt_pipe; |
| 449 | ot_params.frame_rate = crtc->mode.vrefresh; |
| 450 | ot_params.vbif_idx = VBIF_RT; |
| 451 | ot_params.clk_ctrl = psde->pipe_hw->cap->clk_ctrl; |
| 452 | ot_params.rd = true; |
| 453 | |
| 454 | sde_vbif_set_ot_limit(sde_kms, &ot_params); |
| 455 | } |
| 456 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 457 | /* helper to update a state's input fence pointer from the property */ |
| 458 | static void _sde_plane_set_input_fence(struct drm_plane *plane, |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 459 | struct sde_plane_state *pstate, uint64_t fd) |
| 460 | { |
| 461 | if (!plane || !pstate) |
| 462 | return; |
| 463 | |
| 464 | /* clear previous reference */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 465 | if (pstate->input_fence) |
| 466 | sde_sync_put(pstate->input_fence); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 467 | |
| 468 | /* get fence pointer for later */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 469 | pstate->input_fence = sde_sync_get(fd); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 470 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 471 | SDE_DEBUG("0x%llX\n", fd); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 472 | } |
| 473 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 474 | int sde_plane_wait_input_fence(struct drm_plane *plane, uint32_t wait_ms) |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 475 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 476 | struct sde_plane *psde; |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 477 | struct sde_plane_state *pstate; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 478 | void *input_fence; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 479 | int ret = -EINVAL; |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 480 | |
| 481 | if (!plane) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 482 | SDE_ERROR("invalid plane\n"); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 483 | } else if (!plane->state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 484 | SDE_ERROR("invalid plane state\n"); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 485 | } else { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 486 | psde = to_sde_plane(plane); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 487 | pstate = to_sde_plane_state(plane->state); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 488 | input_fence = pstate->input_fence; |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 489 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 490 | if (input_fence) { |
| 491 | ret = sde_sync_wait(input_fence, wait_ms); |
| 492 | switch (ret) { |
| 493 | case 0: |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 494 | SDE_DEBUG("%s signaled\n", psde->pipe_name); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 495 | break; |
| 496 | case -ETIME: |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 497 | SDE_ERROR("timeout on %s, %ums\n", |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 498 | psde->pipe_name, wait_ms); |
| 499 | psde->is_error = true; |
| 500 | break; |
| 501 | default: |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 502 | SDE_ERROR("error on %s, %d\n", |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 503 | psde->pipe_name, ret); |
| 504 | psde->is_error = true; |
| 505 | break; |
| 506 | } |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 507 | } else { |
| 508 | ret = 0; |
| 509 | } |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 510 | } |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 511 | return ret; |
| 512 | } |
| 513 | |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 514 | static void _sde_plane_set_scanout(struct drm_plane *plane, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 515 | struct sde_plane_state *pstate, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 516 | struct sde_hw_pipe_cfg *pipe_cfg, |
| 517 | struct drm_framebuffer *fb) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 518 | { |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 519 | struct sde_plane *psde; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 520 | int ret, i; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 521 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 522 | if (!plane || !pstate || !pipe_cfg || !fb) |
| 523 | return; |
| 524 | |
| 525 | psde = to_sde_plane(plane); |
| 526 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 527 | ret = sde_format_populate_layout(psde->mmu_id, fb, &pipe_cfg->layout); |
| 528 | if (ret) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 529 | SDE_ERROR("failed to get format layout, error: %d\n", ret); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 530 | return; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 531 | } |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 532 | |
| 533 | if (sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG) & |
| 534 | BIT(SDE_DRM_DEINTERLACE)) |
| 535 | for (i = 0; i < SDE_MAX_PLANES; ++i) |
| 536 | pipe_cfg->layout.plane_pitch[i] <<= 1; |
| 537 | |
| 538 | if (psde->pipe_hw && psde->pipe_hw->ops.setup_sourceaddress) |
| 539 | psde->pipe_hw->ops.setup_sourceaddress(psde->pipe_hw, pipe_cfg); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 540 | } |
| 541 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 542 | static void _sde_plane_setup_scaler3(struct sde_plane *psde, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 543 | uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h, |
| 544 | struct sde_hw_scaler3_cfg *scale_cfg, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 545 | const struct sde_format *fmt, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 546 | uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v) |
| 547 | { |
| 548 | } |
| 549 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 550 | /** |
| 551 | * _sde_plane_setup_scaler2(): Determine default scaler phase steps/filter type |
| 552 | * @psde: Pointer to SDE plane object |
| 553 | * @src: Source size |
| 554 | * @dst: Destination size |
| 555 | * @phase_steps: Pointer to output array for phase steps |
| 556 | * @filter: Pointer to output array for filter type |
| 557 | * @fmt: Pointer to format definition |
| 558 | * @chroma_subsampling: Subsampling amount for chroma channel |
| 559 | * |
| 560 | * Returns: 0 on success |
| 561 | */ |
| 562 | static int _sde_plane_setup_scaler2(struct sde_plane *psde, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 563 | uint32_t src, uint32_t dst, uint32_t *phase_steps, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 564 | enum sde_hw_filter *filter, const struct sde_format *fmt, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 565 | uint32_t chroma_subsampling) |
| 566 | { |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 567 | if (!psde || !phase_steps || !filter || !fmt) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 568 | SDE_ERROR("invalid arguments\n"); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 569 | return -EINVAL; |
| 570 | } |
| 571 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 572 | /* calculate phase steps, leave init phase as zero */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 573 | phase_steps[SDE_SSPP_COMP_0] = |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 574 | mult_frac(1 << PHASE_STEP_SHIFT, src, dst); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 575 | phase_steps[SDE_SSPP_COMP_1_2] = |
| 576 | phase_steps[SDE_SSPP_COMP_0] / chroma_subsampling; |
| 577 | phase_steps[SDE_SSPP_COMP_2] = phase_steps[SDE_SSPP_COMP_1_2]; |
| 578 | phase_steps[SDE_SSPP_COMP_3] = phase_steps[SDE_SSPP_COMP_0]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 579 | |
| 580 | /* calculate scaler config, if necessary */ |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 581 | if (SDE_FORMAT_IS_YUV(fmt) || src != dst) { |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 582 | filter[SDE_SSPP_COMP_3] = |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 583 | (src <= dst) ? SDE_SCALE_FILTER_BIL : |
| 584 | SDE_SCALE_FILTER_PCMN; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 585 | |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 586 | if (SDE_FORMAT_IS_YUV(fmt)) { |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 587 | filter[SDE_SSPP_COMP_0] = SDE_SCALE_FILTER_CA; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 588 | filter[SDE_SSPP_COMP_1_2] = filter[SDE_SSPP_COMP_3]; |
| 589 | } else { |
| 590 | filter[SDE_SSPP_COMP_0] = filter[SDE_SSPP_COMP_3]; |
| 591 | filter[SDE_SSPP_COMP_1_2] = |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 592 | SDE_SCALE_FILTER_NEAREST; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 593 | } |
| 594 | } else { |
| 595 | /* disable scaler */ |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 596 | SDE_DEBUG("disable scaler\n"); |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 597 | filter[SDE_SSPP_COMP_0] = SDE_SCALE_FILTER_MAX; |
| 598 | filter[SDE_SSPP_COMP_1_2] = SDE_SCALE_FILTER_MAX; |
| 599 | filter[SDE_SSPP_COMP_3] = SDE_SCALE_FILTER_MAX; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 600 | } |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 601 | return 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 604 | /** |
| 605 | * _sde_plane_setup_pixel_ext - determine default pixel extension values |
| 606 | * @psde: Pointer to SDE plane object |
| 607 | * @src: Source size |
| 608 | * @dst: Destination size |
| 609 | * @decimated_src: Source size after decimation, if any |
| 610 | * @phase_steps: Pointer to output array for phase steps |
| 611 | * @out_src: Output array for pixel extension values |
| 612 | * @out_edge1: Output array for pixel extension first edge |
| 613 | * @out_edge2: Output array for pixel extension second edge |
| 614 | * @filter: Pointer to array for filter type |
| 615 | * @fmt: Pointer to format definition |
| 616 | * @chroma_subsampling: Subsampling amount for chroma channel |
| 617 | * @post_compare: Whether to chroma subsampled source size for comparisions |
| 618 | */ |
| 619 | static void _sde_plane_setup_pixel_ext(struct sde_plane *psde, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 620 | uint32_t src, uint32_t dst, uint32_t decimated_src, |
| 621 | uint32_t *phase_steps, uint32_t *out_src, int *out_edge1, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 622 | int *out_edge2, enum sde_hw_filter *filter, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 623 | const struct sde_format *fmt, uint32_t chroma_subsampling, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 624 | bool post_compare) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 625 | { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 626 | int64_t edge1, edge2, caf; |
| 627 | uint32_t src_work; |
| 628 | int i, tmp; |
| 629 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 630 | if (psde && phase_steps && out_src && out_edge1 && |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 631 | out_edge2 && filter && fmt) { |
| 632 | /* handle CAF for YUV formats */ |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 633 | if (SDE_FORMAT_IS_YUV(fmt) && *filter == SDE_SCALE_FILTER_CA) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 634 | caf = PHASE_STEP_UNIT_SCALE; |
| 635 | else |
| 636 | caf = 0; |
| 637 | |
| 638 | for (i = 0; i < SDE_MAX_PLANES; i++) { |
| 639 | src_work = decimated_src; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 640 | if (i == SDE_SSPP_COMP_1_2 || i == SDE_SSPP_COMP_2) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 641 | src_work /= chroma_subsampling; |
| 642 | if (post_compare) |
| 643 | src = src_work; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 644 | if (!SDE_FORMAT_IS_YUV(fmt) && (src == dst)) { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 645 | /* unity */ |
| 646 | edge1 = 0; |
| 647 | edge2 = 0; |
| 648 | } else if (dst >= src) { |
| 649 | /* upscale */ |
| 650 | edge1 = (1 << PHASE_RESIDUAL); |
| 651 | edge1 -= caf; |
| 652 | edge2 = (1 << PHASE_RESIDUAL); |
| 653 | edge2 += (dst - 1) * *(phase_steps + i); |
| 654 | edge2 -= (src_work - 1) * PHASE_STEP_UNIT_SCALE; |
| 655 | edge2 += caf; |
| 656 | edge2 = -(edge2); |
| 657 | } else { |
| 658 | /* downscale */ |
| 659 | edge1 = 0; |
| 660 | edge2 = (dst - 1) * *(phase_steps + i); |
| 661 | edge2 -= (src_work - 1) * PHASE_STEP_UNIT_SCALE; |
| 662 | edge2 += *(phase_steps + i); |
| 663 | edge2 = -(edge2); |
| 664 | } |
| 665 | |
| 666 | /* only enable CAF for luma plane */ |
| 667 | caf = 0; |
| 668 | |
| 669 | /* populate output arrays */ |
| 670 | *(out_src + i) = src_work; |
| 671 | |
| 672 | /* edge updates taken from __pxl_extn_helper */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 673 | if (edge1 >= 0) { |
| 674 | tmp = (uint32_t)edge1; |
| 675 | tmp >>= PHASE_STEP_SHIFT; |
| 676 | *(out_edge1 + i) = -tmp; |
| 677 | } else { |
| 678 | tmp = (uint32_t)(-edge1); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 679 | *(out_edge1 + i) = |
| 680 | (tmp + PHASE_STEP_UNIT_SCALE - 1) >> |
| 681 | PHASE_STEP_SHIFT; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 682 | } |
| 683 | if (edge2 >= 0) { |
| 684 | tmp = (uint32_t)edge2; |
| 685 | tmp >>= PHASE_STEP_SHIFT; |
| 686 | *(out_edge2 + i) = -tmp; |
| 687 | } else { |
| 688 | tmp = (uint32_t)(-edge2); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 689 | *(out_edge2 + i) = |
| 690 | (tmp + PHASE_STEP_UNIT_SCALE - 1) >> |
| 691 | PHASE_STEP_SHIFT; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 697 | /** |
| 698 | * _sde_plane_verify_blob - verify incoming blob is big enough to contain |
| 699 | * sub-structure |
| 700 | * @blob_ptr: Pointer to start of incoming blob data |
| 701 | * @blob_size: Size of incoming blob data, in bytes |
| 702 | * @sub_ptr: Pointer to start of desired sub-structure |
| 703 | * @sub_size: Required size of sub-structure, in bytes |
| 704 | */ |
| 705 | static int _sde_plane_verify_blob(void *blob_ptr, |
| 706 | size_t blob_size, |
| 707 | void *sub_ptr, |
| 708 | size_t sub_size) |
| 709 | { |
| 710 | /* |
| 711 | * Use the blob size provided by drm to check if there are enough |
| 712 | * bytes from the start of versioned sub-structures to the end of |
| 713 | * blob data: |
| 714 | * |
| 715 | * e.g., |
| 716 | * blob_ptr --> struct blob_data { |
| 717 | * uint32_t version; |
| 718 | * sub_ptr --> struct blob_data_v1 v1; |
| 719 | * sub_ptr + sub_size --> struct blob_stuff more_stuff; |
| 720 | * blob_ptr + blob_size --> }; |
| 721 | * |
| 722 | * It's important to check the actual number of bytes from the start |
| 723 | * of the sub-structure to the end of the blob data, and not just rely |
| 724 | * on something like, |
| 725 | * |
| 726 | * sizeof(blob) - sizeof(blob->version) >= sizeof(sub-struct) |
| 727 | * |
| 728 | * This is because the start of the sub-structure can vary based on |
| 729 | * how the compiler pads the overall structure. |
| 730 | */ |
| 731 | if (blob_ptr && sub_ptr) |
| 732 | /* return zero if end of blob >= end of sub-struct */ |
| 733 | return ((unsigned char *)blob_ptr + blob_size) < |
| 734 | ((unsigned char *)sub_ptr + sub_size); |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 738 | static void _sde_plane_setup_csc(struct sde_plane *psde, |
| 739 | struct sde_plane_state *pstate, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 740 | const struct sde_format *fmt) |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 741 | { |
| 742 | static const struct sde_csc_cfg sde_csc_YUV2RGB_601L = { |
| 743 | { |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 744 | /* S15.16 format */ |
| 745 | 0x00012A00, 0x00000000, 0x00019880, |
| 746 | 0x00012A00, 0xFFFF9B80, 0xFFFF3000, |
| 747 | 0x00012A00, 0x00020480, 0x00000000, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 748 | }, |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 749 | /* signed bias */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 750 | { 0xfff0, 0xff80, 0xff80,}, |
| 751 | { 0x0, 0x0, 0x0,}, |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 752 | /* unsigned clamp */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 753 | { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0,}, |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 754 | { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,}, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 755 | }; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 756 | static const struct sde_csc_cfg sde_csc_NOP = { |
| 757 | { |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 758 | /* identity matrix, S15.16 format */ |
| 759 | 0x10000, 0x00000, 0x00000, |
| 760 | 0x00000, 0x10000, 0x00000, |
| 761 | 0x00000, 0x00000, 0x10000, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 762 | }, |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 763 | /* signed bias */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 764 | { 0x0, 0x0, 0x0,}, |
| 765 | { 0x0, 0x0, 0x0,}, |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 766 | /* unsigned clamp */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 767 | { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff,}, |
| 768 | { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff,}, |
| 769 | }; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 770 | struct sde_drm_csc *csc = NULL; |
| 771 | size_t csc_size = 0; |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 772 | int i; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 773 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 774 | if (!psde || !pstate || !fmt) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 775 | SDE_ERROR("invalid arguments\n"); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | if (!psde->pipe_hw || !psde->pipe_hw->ops.setup_csc) |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 779 | return; |
| 780 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 781 | /* check for user space override */ |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 782 | psde->csc_ptr = NULL; |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 783 | csc = msm_property_get_blob(&psde->property_info, |
| 784 | pstate->property_blobs, |
| 785 | &csc_size, |
| 786 | PLANE_PROP_CSC); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 787 | if (csc) { |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 788 | /* user space override */ |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 789 | memcpy(&psde->csc_cfg, |
| 790 | &sde_csc_NOP, |
| 791 | sizeof(struct sde_csc_cfg)); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 792 | switch (csc->version) { |
| 793 | case SDE_DRM_CSC_V1: |
| 794 | if (!_sde_plane_verify_blob(csc, |
| 795 | csc_size, |
| 796 | &csc->v1, |
| 797 | sizeof(struct sde_drm_csc_v1))) { |
| 798 | for (i = 0; i < SDE_CSC_MATRIX_COEFF_SIZE; ++i) |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 799 | psde->csc_cfg.csc_mv[i] = |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 800 | csc->v1.ctm_coeff[i] >> 16; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 801 | for (i = 0; i < SDE_CSC_BIAS_SIZE; ++i) { |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 802 | psde->csc_cfg.csc_pre_bv[i] = |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 803 | csc->v1.pre_bias[i]; |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 804 | psde->csc_cfg.csc_post_bv[i] = |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 805 | csc->v1.post_bias[i]; |
| 806 | } |
| 807 | for (i = 0; i < SDE_CSC_CLAMP_SIZE; ++i) { |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 808 | psde->csc_cfg.csc_pre_lv[i] = |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 809 | csc->v1.pre_clamp[i]; |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 810 | psde->csc_cfg.csc_post_lv[i] = |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 811 | csc->v1.post_clamp[i]; |
| 812 | } |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 813 | psde->csc_ptr = &psde->csc_cfg; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 814 | } |
| 815 | break; |
| 816 | default: |
| 817 | break; |
| 818 | } |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 819 | if (!psde->csc_ptr) |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 820 | SDE_ERROR("invalid csc blob, v%lld\n", csc->version); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 823 | /* revert to kernel default if override not available */ |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 824 | if (psde->csc_ptr) |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 825 | SDE_DEBUG("user blob override for csc\n"); |
Clarence Ip | b493d76 | 2016-07-19 18:49:10 -0400 | [diff] [blame] | 826 | else if (SDE_FORMAT_IS_YUV(fmt)) |
Clarence Ip | 373f859 | 2016-05-26 00:58:42 -0400 | [diff] [blame] | 827 | psde->csc_ptr = (struct sde_csc_cfg *)&sde_csc_YUV2RGB_601L; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 828 | } |
| 829 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 830 | static void _sde_plane_setup_scaler(struct sde_plane *psde, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 831 | const struct sde_format *fmt, |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 832 | struct sde_plane_state *pstate) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 833 | { |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 834 | struct sde_hw_pixel_ext *pe = NULL; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 835 | struct sde_drm_scaler *sc_u = NULL; |
| 836 | struct sde_drm_scaler_v1 *sc_u1 = NULL; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 837 | size_t sc_u_size = 0; |
| 838 | uint32_t chroma_subsmpl_h, chroma_subsmpl_v; |
| 839 | uint32_t tmp; |
| 840 | int i; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 841 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 842 | if (!psde || !fmt) |
| 843 | return; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 844 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 845 | pe = &(psde->pixel_ext); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 846 | memset(pe, 0, sizeof(struct sde_hw_pixel_ext)); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 847 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 848 | /* get scaler config from user space */ |
Clarence Ip | c3ffec1 | 2016-07-18 19:07:24 -0400 | [diff] [blame] | 849 | if (pstate) |
| 850 | sc_u = msm_property_get_blob(&psde->property_info, |
| 851 | pstate->property_blobs, |
| 852 | &sc_u_size, |
| 853 | PLANE_PROP_SCALER); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 854 | if (sc_u) { |
| 855 | switch (sc_u->version) { |
| 856 | case SDE_DRM_SCALER_V1: |
| 857 | if (!_sde_plane_verify_blob(sc_u, |
| 858 | sc_u_size, |
| 859 | &sc_u->v1, |
| 860 | sizeof(*sc_u1))) |
| 861 | sc_u1 = &sc_u->v1; |
| 862 | break; |
| 863 | default: |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 864 | SDE_DEBUG("unrecognized scaler blob v%lld\n", |
| 865 | sc_u->version); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 866 | break; |
| 867 | } |
| 868 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 869 | |
Clarence Ip | 04ec67d | 2016-05-26 01:16:15 -0400 | [diff] [blame] | 870 | /* decimation */ |
| 871 | if (sc_u1 && (sc_u1->enable & SDE_DRM_SCALER_DECIMATE)) { |
| 872 | psde->pipe_cfg.horz_decimation = sc_u1->horz_decimate; |
| 873 | psde->pipe_cfg.vert_decimation = sc_u1->vert_decimate; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 874 | } else { |
| 875 | psde->pipe_cfg.horz_decimation = 0; |
| 876 | psde->pipe_cfg.vert_decimation = 0; |
Clarence Ip | 04ec67d | 2016-05-26 01:16:15 -0400 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* don't chroma subsample if decimating */ |
| 880 | chroma_subsmpl_h = psde->pipe_cfg.horz_decimation ? 1 : |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 881 | drm_format_horz_chroma_subsampling(fmt->base.pixel_format); |
Clarence Ip | 04ec67d | 2016-05-26 01:16:15 -0400 | [diff] [blame] | 882 | chroma_subsmpl_v = psde->pipe_cfg.vert_decimation ? 1 : |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 883 | drm_format_vert_chroma_subsampling(fmt->base.pixel_format); |
Clarence Ip | 04ec67d | 2016-05-26 01:16:15 -0400 | [diff] [blame] | 884 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 885 | /* update scaler */ |
| 886 | if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3)) { |
| 887 | if (sc_u1 && (sc_u1->enable & SDE_DRM_SCALER_SCALER_3)) |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 888 | SDE_DEBUG("SCALER3 blob detected\n"); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 889 | else |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 890 | _sde_plane_setup_scaler3(psde, |
| 891 | psde->pipe_cfg.src_rect.w, |
| 892 | psde->pipe_cfg.src_rect.h, |
| 893 | psde->pipe_cfg.dst_rect.w, |
| 894 | psde->pipe_cfg.dst_rect.h, |
| 895 | &psde->scaler3_cfg, fmt, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 896 | chroma_subsmpl_h, chroma_subsmpl_v); |
| 897 | } else { |
| 898 | /* always calculate basic scaler config */ |
| 899 | if (sc_u1 && (sc_u1->enable & SDE_DRM_SCALER_SCALER_2)) { |
| 900 | /* populate from user space */ |
| 901 | for (i = 0; i < SDE_MAX_PLANES; i++) { |
| 902 | pe->init_phase_x[i] = sc_u1->init_phase_x[i]; |
| 903 | pe->phase_step_x[i] = sc_u1->phase_step_x[i]; |
| 904 | pe->init_phase_y[i] = sc_u1->init_phase_y[i]; |
| 905 | pe->phase_step_y[i] = sc_u1->phase_step_y[i]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 906 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 907 | pe->horz_filter[i] = sc_u1->horz_filter[i]; |
| 908 | pe->vert_filter[i] = sc_u1->vert_filter[i]; |
| 909 | } |
| 910 | } else { |
| 911 | /* calculate phase steps */ |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 912 | _sde_plane_setup_scaler2(psde, |
| 913 | psde->pipe_cfg.src_rect.w, |
| 914 | psde->pipe_cfg.dst_rect.w, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 915 | pe->phase_step_x, |
| 916 | pe->horz_filter, fmt, chroma_subsmpl_h); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 917 | _sde_plane_setup_scaler2(psde, |
| 918 | psde->pipe_cfg.src_rect.h, |
| 919 | psde->pipe_cfg.dst_rect.h, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 920 | pe->phase_step_y, |
| 921 | pe->vert_filter, fmt, chroma_subsmpl_v); |
| 922 | } |
| 923 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 924 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 925 | /* update pixel extensions */ |
| 926 | if (sc_u1 && (sc_u1->enable & SDE_DRM_SCALER_PIX_EXT)) { |
| 927 | /* populate from user space */ |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 928 | SDE_DEBUG("pixel ext blob detected\n"); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 929 | for (i = 0; i < SDE_MAX_PLANES; i++) { |
| 930 | pe->num_ext_pxls_left[i] = sc_u1->lr.num_pxls_start[i]; |
| 931 | pe->num_ext_pxls_right[i] = sc_u1->lr.num_pxls_end[i]; |
| 932 | pe->left_ftch[i] = sc_u1->lr.ftch_start[i]; |
| 933 | pe->right_ftch[i] = sc_u1->lr.ftch_end[i]; |
| 934 | pe->left_rpt[i] = sc_u1->lr.rpt_start[i]; |
| 935 | pe->right_rpt[i] = sc_u1->lr.rpt_end[i]; |
| 936 | pe->roi_w[i] = sc_u1->lr.roi[i]; |
| 937 | |
| 938 | pe->num_ext_pxls_top[i] = sc_u1->tb.num_pxls_start[i]; |
| 939 | pe->num_ext_pxls_btm[i] = sc_u1->tb.num_pxls_end[i]; |
| 940 | pe->top_ftch[i] = sc_u1->tb.ftch_start[i]; |
| 941 | pe->btm_ftch[i] = sc_u1->tb.ftch_end[i]; |
| 942 | pe->top_rpt[i] = sc_u1->tb.rpt_start[i]; |
| 943 | pe->btm_rpt[i] = sc_u1->tb.rpt_end[i]; |
| 944 | pe->roi_h[i] = sc_u1->tb.roi[i]; |
| 945 | } |
| 946 | } else { |
| 947 | /* calculate left/right/top/bottom pixel extensions */ |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 948 | tmp = DECIMATED_DIMENSION(psde->pipe_cfg.src_rect.w, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 949 | psde->pipe_cfg.horz_decimation); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 950 | if (SDE_FORMAT_IS_YUV(fmt)) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 951 | tmp &= ~0x1; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 952 | _sde_plane_setup_pixel_ext(psde, psde->pipe_cfg.src_rect.w, |
| 953 | psde->pipe_cfg.dst_rect.w, tmp, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 954 | pe->phase_step_x, |
| 955 | pe->roi_w, |
| 956 | pe->num_ext_pxls_left, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 957 | pe->num_ext_pxls_right, pe->horz_filter, fmt, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 958 | chroma_subsmpl_h, 0); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 959 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 960 | tmp = DECIMATED_DIMENSION(psde->pipe_cfg.src_rect.h, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 961 | psde->pipe_cfg.vert_decimation); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 962 | _sde_plane_setup_pixel_ext(psde, psde->pipe_cfg.src_rect.h, |
| 963 | psde->pipe_cfg.dst_rect.h, tmp, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 964 | pe->phase_step_y, |
| 965 | pe->roi_h, |
| 966 | pe->num_ext_pxls_top, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 967 | pe->num_ext_pxls_btm, pe->vert_filter, fmt, |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 968 | chroma_subsmpl_v, 1); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 969 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 970 | for (i = 0; i < SDE_MAX_PLANES; i++) { |
| 971 | if (pe->num_ext_pxls_left[i] >= 0) |
| 972 | pe->left_rpt[i] = |
| 973 | pe->num_ext_pxls_left[i]; |
| 974 | else |
| 975 | pe->left_ftch[i] = |
| 976 | pe->num_ext_pxls_left[i]; |
| 977 | |
| 978 | if (pe->num_ext_pxls_right[i] >= 0) |
| 979 | pe->right_rpt[i] = |
| 980 | pe->num_ext_pxls_right[i]; |
| 981 | else |
| 982 | pe->right_ftch[i] = |
| 983 | pe->num_ext_pxls_right[i]; |
| 984 | |
| 985 | if (pe->num_ext_pxls_top[i] >= 0) |
| 986 | pe->top_rpt[i] = |
| 987 | pe->num_ext_pxls_top[i]; |
| 988 | else |
| 989 | pe->top_ftch[i] = |
| 990 | pe->num_ext_pxls_top[i]; |
| 991 | |
| 992 | if (pe->num_ext_pxls_btm[i] >= 0) |
| 993 | pe->btm_rpt[i] = |
| 994 | pe->num_ext_pxls_btm[i]; |
| 995 | else |
| 996 | pe->btm_ftch[i] = |
| 997 | pe->num_ext_pxls_btm[i]; |
| 998 | } |
| 999 | } |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1002 | /** |
| 1003 | * _sde_plane_color_fill - enables color fill on plane |
| 1004 | * @plane: Pointer to DRM plane object |
| 1005 | * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red |
| 1006 | * @alpha: 8-bit fill alpha value, 255 selects 100% alpha |
| 1007 | * Returns: 0 on success |
| 1008 | */ |
| 1009 | static int _sde_plane_color_fill(struct drm_plane *plane, |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1010 | uint32_t color, uint32_t alpha) |
| 1011 | { |
| 1012 | struct sde_plane *psde; |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1013 | const struct sde_format *fmt; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1014 | |
| 1015 | if (!plane) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1016 | SDE_ERROR("invalid plane\n"); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
| 1020 | psde = to_sde_plane(plane); |
| 1021 | if (!psde->pipe_hw) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1022 | SDE_ERROR("invalid plane h/w pointer\n"); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1023 | return -EINVAL; |
| 1024 | } |
| 1025 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1026 | DBG(""); |
| 1027 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1028 | /* |
| 1029 | * select fill format to match user property expectation, |
| 1030 | * h/w only supports RGB variants |
| 1031 | */ |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1032 | fmt = sde_get_sde_format(DRM_FORMAT_ABGR8888); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1033 | |
| 1034 | /* update sspp */ |
| 1035 | if (fmt && psde->pipe_hw->ops.setup_solidfill) { |
| 1036 | psde->pipe_hw->ops.setup_solidfill(psde->pipe_hw, |
| 1037 | (color & 0xFFFFFF) | ((alpha & 0xFF) << 24)); |
| 1038 | |
| 1039 | /* override scaler/decimation if solid fill */ |
| 1040 | psde->pipe_cfg.src_rect.x = 0; |
| 1041 | psde->pipe_cfg.src_rect.y = 0; |
| 1042 | psde->pipe_cfg.src_rect.w = psde->pipe_cfg.dst_rect.w; |
| 1043 | psde->pipe_cfg.src_rect.h = psde->pipe_cfg.dst_rect.h; |
| 1044 | |
| 1045 | _sde_plane_setup_scaler(psde, fmt, 0); |
| 1046 | |
| 1047 | if (psde->pipe_hw->ops.setup_format) |
| 1048 | psde->pipe_hw->ops.setup_format(psde->pipe_hw, |
| 1049 | fmt, SDE_SSPP_SOLID_FILL); |
| 1050 | |
| 1051 | if (psde->pipe_hw->ops.setup_rects) |
| 1052 | psde->pipe_hw->ops.setup_rects(psde->pipe_hw, |
| 1053 | &psde->pipe_cfg, &psde->pixel_ext); |
| 1054 | } |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | static int _sde_plane_mode_set(struct drm_plane *plane, |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1060 | struct drm_plane_state *state) |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1061 | { |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame^] | 1062 | uint32_t nplanes, src_flags, zpos, split_width; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1063 | struct sde_plane *psde; |
| 1064 | struct sde_plane_state *pstate; |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1065 | const struct sde_format *fmt; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1066 | struct drm_crtc *crtc; |
| 1067 | struct drm_framebuffer *fb; |
| 1068 | struct sde_rect src, dst; |
| 1069 | bool q16_data = true; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1070 | |
| 1071 | if (!plane || !plane->state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1072 | SDE_ERROR("invalid plane/state\n"); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1073 | return -EINVAL; |
| 1074 | } |
| 1075 | |
| 1076 | psde = to_sde_plane(plane); |
| 1077 | pstate = to_sde_plane_state(plane->state); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1078 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1079 | crtc = state->crtc; |
| 1080 | fb = state->fb; |
| 1081 | if (!crtc || !fb) { |
| 1082 | SDE_ERROR("invalid crtc/fb\n"); |
| 1083 | return -EINVAL; |
| 1084 | } |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1085 | fmt = to_sde_format(msm_framebuffer_format(fb)); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1086 | nplanes = fmt->num_planes; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1087 | |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 1088 | psde->is_rt_pipe = _sde_plane_is_rt_pipe(plane, crtc); |
| 1089 | |
| 1090 | _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL); |
| 1091 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1092 | POPULATE_RECT(&src, state->src_x, state->src_y, |
| 1093 | state->src_w, state->src_h, q16_data); |
| 1094 | POPULATE_RECT(&dst, state->crtc_x, state->crtc_y, |
| 1095 | state->crtc_w, state->crtc_h, !q16_data); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1096 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1097 | SDE_DEBUG("%s:FB[%u] %u,%u,%u,%u -> CRTC[%u] %d,%d,%u,%u, %s ubwc %d\n", |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1098 | psde->pipe_name, |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1099 | fb->base.id, src.x, src.y, src.w, src.h, |
| 1100 | crtc->base.id, dst.x, dst.y, dst.w, dst.h, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1101 | drm_get_format_name(fmt->base.pixel_format), |
| 1102 | SDE_FORMAT_IS_UBWC(fmt)); |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1103 | |
| 1104 | /* update format configuration */ |
| 1105 | memset(&(psde->pipe_cfg), 0, sizeof(struct sde_hw_pipe_cfg)); |
| 1106 | src_flags = 0; |
| 1107 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1108 | /* flags */ |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1109 | SDE_DEBUG("flags 0x%llX, rotation 0x%llX\n", |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1110 | sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG), |
| 1111 | sde_plane_get_property(pstate, PLANE_PROP_ROTATION)); |
| 1112 | if (sde_plane_get_property(pstate, PLANE_PROP_ROTATION) & |
| 1113 | BIT(DRM_REFLECT_X)) |
| 1114 | src_flags |= SDE_SSPP_FLIP_LR; |
| 1115 | if (sde_plane_get_property(pstate, PLANE_PROP_ROTATION) & |
| 1116 | BIT(DRM_REFLECT_Y)) |
| 1117 | src_flags |= SDE_SSPP_FLIP_UD; |
| 1118 | if (sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG) & |
| 1119 | BIT(SDE_DRM_DEINTERLACE)) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1120 | src.h /= 2; |
| 1121 | src.y = DIV_ROUND_UP(src.y, 2); |
| 1122 | src.y &= ~0x1; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1125 | psde->pipe_cfg.src_rect = src; |
| 1126 | psde->pipe_cfg.dst_rect = dst; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1127 | |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1128 | /* check for color fill */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1129 | psde->color_fill = (uint32_t)sde_plane_get_property(pstate, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1130 | PLANE_PROP_COLOR_FILL); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1131 | if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG) |
| 1132 | /* skip remaining processing on color fill */ |
| 1133 | return 0; |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1134 | |
| 1135 | _sde_plane_set_scanout(plane, pstate, &psde->pipe_cfg, fb); |
| 1136 | |
| 1137 | _sde_plane_setup_scaler(psde, fmt, pstate); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1138 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame^] | 1139 | /* base layer source split needs update */ |
| 1140 | zpos = sde_plane_get_property(pstate, PLANE_PROP_ZPOS); |
| 1141 | if (zpos == SDE_STAGE_BASE) { |
| 1142 | split_width = get_crtc_split_width(crtc); |
| 1143 | if (psde->pipe_cfg.dst_rect.x >= split_width) |
| 1144 | psde->pipe_cfg.dst_rect.x -= split_width; |
| 1145 | } |
| 1146 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1147 | if (psde->pipe_hw->ops.setup_format) |
| 1148 | psde->pipe_hw->ops.setup_format(psde->pipe_hw, |
Clarence Ip | cb410d4 | 2016-06-26 22:52:33 -0400 | [diff] [blame] | 1149 | fmt, src_flags); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1150 | if (psde->pipe_hw->ops.setup_rects) |
| 1151 | psde->pipe_hw->ops.setup_rects(psde->pipe_hw, |
| 1152 | &psde->pipe_cfg, &psde->pixel_ext); |
| 1153 | |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1154 | /* update sharpening */ |
| 1155 | psde->sharp_cfg.strength = SHARP_STRENGTH_DEFAULT; |
| 1156 | psde->sharp_cfg.edge_thr = SHARP_EDGE_THR_DEFAULT; |
| 1157 | psde->sharp_cfg.smooth_thr = SHARP_SMOOTH_THR_DEFAULT; |
| 1158 | psde->sharp_cfg.noise_thr = SHARP_NOISE_THR_DEFAULT; |
| 1159 | |
| 1160 | if (psde->pipe_hw->ops.setup_sharpening) |
| 1161 | psde->pipe_hw->ops.setup_sharpening(psde->pipe_hw, |
| 1162 | &psde->sharp_cfg); |
| 1163 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1164 | /* update csc */ |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1165 | if (SDE_FORMAT_IS_YUV(fmt)) |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1166 | _sde_plane_setup_csc(psde, pstate, fmt); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1167 | else |
| 1168 | psde->csc_ptr = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1169 | |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 1170 | _sde_plane_set_qos_lut(plane, fb); |
| 1171 | _sde_plane_set_danger_lut(plane, fb); |
| 1172 | |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 1173 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 1174 | _sde_plane_set_qos_ctrl(plane, true, SDE_PLANE_QOS_PANIC_CTRL); |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 1175 | _sde_plane_set_ot_limit(plane, crtc); |
| 1176 | } |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 1177 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1178 | return 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | static int sde_plane_prepare_fb(struct drm_plane *plane, |
| 1182 | const struct drm_plane_state *new_state) |
| 1183 | { |
| 1184 | struct drm_framebuffer *fb = new_state->fb; |
| 1185 | struct sde_plane *psde = to_sde_plane(plane); |
| 1186 | |
| 1187 | if (!new_state->fb) |
| 1188 | return 0; |
| 1189 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1190 | SDE_DEBUG("%s: FB[%u]\n", psde->pipe_name, fb->base.id); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1191 | return msm_framebuffer_prepare(fb, psde->mmu_id); |
| 1192 | } |
| 1193 | |
| 1194 | static void sde_plane_cleanup_fb(struct drm_plane *plane, |
| 1195 | const struct drm_plane_state *old_state) |
| 1196 | { |
| 1197 | struct drm_framebuffer *fb = old_state->fb; |
| 1198 | struct sde_plane *psde = to_sde_plane(plane); |
| 1199 | |
| 1200 | if (!fb) |
| 1201 | return; |
| 1202 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1203 | SDE_DEBUG("%s: FB[%u]\n", psde->pipe_name, fb->base.id); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1204 | msm_framebuffer_cleanup(fb, psde->mmu_id); |
| 1205 | } |
| 1206 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1207 | static void _sde_plane_atomic_check_mode_changed(struct sde_plane *psde, |
| 1208 | struct drm_plane_state *state, |
| 1209 | struct drm_plane_state *old_state) |
| 1210 | { |
| 1211 | struct sde_plane_state *pstate = to_sde_plane_state(state); |
| 1212 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1213 | /* no need to check it again */ |
| 1214 | if (pstate->mode_changed) |
| 1215 | return; |
| 1216 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1217 | if (!(sde_plane_enabled(state) && sde_plane_enabled(old_state))) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1218 | SDE_DEBUG("%s: pipe enabling/disabling full modeset required\n", |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1219 | psde->pipe_name); |
| 1220 | pstate->mode_changed = true; |
| 1221 | } else if (to_sde_plane_state(old_state)->pending) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1222 | SDE_DEBUG("%s: still pending\n", psde->pipe_name); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1223 | pstate->mode_changed = true; |
| 1224 | } else if (state->src_w != old_state->src_w || |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1225 | state->src_h != old_state->src_h || |
| 1226 | state->src_x != old_state->src_x || |
| 1227 | state->src_y != old_state->src_y) { |
| 1228 | SDE_DEBUG("%s: src rect updated\n", psde->pipe_name); |
| 1229 | pstate->mode_changed = true; |
| 1230 | } else if (state->crtc_w != old_state->crtc_w || |
| 1231 | state->crtc_h != old_state->crtc_h || |
| 1232 | state->crtc_x != old_state->crtc_x || |
| 1233 | state->crtc_y != old_state->crtc_y) { |
| 1234 | SDE_DEBUG("%s: crtc rect updated\n", psde->pipe_name); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1235 | pstate->mode_changed = true; |
| 1236 | } else if (state->fb->pixel_format != old_state->fb->pixel_format) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1237 | SDE_DEBUG("%s: format change!\n", psde->pipe_name); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1238 | pstate->mode_changed = true; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1239 | } else { |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1240 | uint64_t *new_mods = state->fb->modifier; |
| 1241 | uint64_t *old_mods = old_state->fb->modifier; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1242 | uint32_t *new_pitches = state->fb->pitches; |
| 1243 | uint32_t *old_pitches = old_state->fb->pitches; |
| 1244 | uint32_t *new_offset = state->fb->offsets; |
| 1245 | uint32_t *old_offset = old_state->fb->offsets; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1246 | int i; |
| 1247 | |
| 1248 | for (i = 0; i < ARRAY_SIZE(state->fb->modifier); i++) { |
| 1249 | if (new_mods[i] != old_mods[i]) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1250 | SDE_DEBUG("%s: format modifiers change\"\ |
| 1251 | plane:%d new_mode:%llu old_mode:%llu\n", |
| 1252 | psde->pipe_name, i, new_mods[i], |
| 1253 | old_mods[i]); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1254 | pstate->mode_changed = true; |
| 1255 | break; |
| 1256 | } |
| 1257 | } |
Lloyd Atkinson | 3ab9ef7 | 2016-07-14 17:42:41 -0400 | [diff] [blame] | 1258 | for (i = 0; i < ARRAY_SIZE(state->fb->pitches); i++) { |
| 1259 | if (new_pitches[i] != old_pitches[i]) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1260 | SDE_DEBUG("%s: pitches change plane:%d\"\ |
| 1261 | old_pitches:%u new_pitches:%u\n", |
Lloyd Atkinson | 3ab9ef7 | 2016-07-14 17:42:41 -0400 | [diff] [blame] | 1262 | psde->pipe_name, i, old_pitches[i], |
| 1263 | new_pitches[i]); |
| 1264 | pstate->mode_changed = true; |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1268 | for (i = 0; i < ARRAY_SIZE(state->fb->offsets); i++) { |
| 1269 | if (new_offset[i] != old_offset[i]) { |
| 1270 | SDE_DEBUG("%s: offset change plane:%d\"\ |
| 1271 | old_offset:%u new_offset:%u\n", |
| 1272 | psde->pipe_name, i, old_offset[i], |
| 1273 | new_offset[i]); |
| 1274 | pstate->mode_changed = true; |
| 1275 | break; |
| 1276 | } |
| 1277 | } |
Lloyd Atkinson | 3ab9ef7 | 2016-07-14 17:42:41 -0400 | [diff] [blame] | 1278 | } |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1279 | } |
| 1280 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1281 | static bool __get_scale_data(struct sde_plane *psde, |
| 1282 | struct sde_plane_state *pstate, struct sde_drm_scaler *sc_u, |
| 1283 | size_t *sc_u_size) |
| 1284 | { |
| 1285 | bool valid_flag = false; |
| 1286 | |
| 1287 | sc_u = msm_property_get_blob(&psde->property_info, |
| 1288 | pstate->property_blobs, |
| 1289 | sc_u_size, |
| 1290 | PLANE_PROP_SCALER); |
| 1291 | if (sc_u) { |
| 1292 | switch (sc_u->version) { |
| 1293 | case SDE_DRM_SCALER_V1: |
| 1294 | if (!_sde_plane_verify_blob(sc_u, *sc_u_size, |
| 1295 | &sc_u->v1, sizeof(struct sde_drm_scaler_v1))) |
| 1296 | valid_flag = true; |
| 1297 | break; |
| 1298 | default: |
| 1299 | SDE_DEBUG("unrecognized scaler blob v%lld\n", |
| 1300 | sc_u->version); |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | return valid_flag; |
| 1306 | } |
| 1307 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1308 | static int sde_plane_atomic_check(struct drm_plane *plane, |
| 1309 | struct drm_plane_state *state) |
| 1310 | { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1311 | int ret = 0, valid_scale_data; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1312 | struct sde_plane *psde; |
| 1313 | struct sde_plane_state *pstate; |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1314 | const struct sde_format *fmt; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1315 | size_t sc_u_size = 0; |
| 1316 | struct sde_drm_scaler *sc_u = NULL; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1317 | struct sde_rect src, dst; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1318 | uint32_t deci_w, deci_h, src_deci_w, src_deci_h; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1319 | uint32_t max_upscale, max_downscale, min_src_size, max_linewidth; |
| 1320 | bool q16_data = true; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1321 | |
| 1322 | if (!plane || !state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1323 | SDE_ERROR("invalid plane/state\n"); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1324 | ret = -EINVAL; |
| 1325 | goto exit; |
| 1326 | } |
| 1327 | |
| 1328 | psde = to_sde_plane(plane); |
| 1329 | pstate = to_sde_plane_state(state); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1330 | |
| 1331 | if (!psde->pipe_sblk) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1332 | SDE_ERROR("invalid plane catalog\n"); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1333 | ret = -EINVAL; |
| 1334 | goto exit; |
| 1335 | } |
| 1336 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1337 | valid_scale_data = __get_scale_data(psde, pstate, sc_u, &sc_u_size); |
| 1338 | deci_w = valid_scale_data && sc_u ? sc_u->v1.horz_decimate : 0; |
| 1339 | deci_h = valid_scale_data && sc_u ? sc_u->v1.vert_decimate : 0; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1340 | |
| 1341 | /* src values are in Q16 fixed point, convert to integer */ |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1342 | POPULATE_RECT(&src, state->src_x, state->src_y, state->src_w, |
| 1343 | state->src_h, q16_data); |
| 1344 | POPULATE_RECT(&dst, state->crtc_x, state->crtc_y, state->crtc_w, |
| 1345 | state->crtc_h, !q16_data); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1346 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1347 | src_deci_w = DECIMATED_DIMENSION(src.w, deci_w); |
| 1348 | src_deci_h = DECIMATED_DIMENSION(src.h, deci_h); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1349 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1350 | max_upscale = psde->pipe_sblk->maxupscale; |
| 1351 | max_downscale = psde->pipe_sblk->maxdwnscale; |
| 1352 | max_linewidth = psde->pipe_sblk->maxlinewidth; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1353 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1354 | SDE_DEBUG("%s: check (%d -> %d)\n", psde->pipe_name, |
| 1355 | sde_plane_enabled(plane->state), sde_plane_enabled(state)); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1356 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1357 | if (!sde_plane_enabled(state)) |
| 1358 | goto modeset_update; |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1359 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1360 | fmt = to_sde_format(msm_framebuffer_format(state->fb)); |
| 1361 | |
| 1362 | min_src_size = SDE_FORMAT_IS_YUV(fmt) ? 2 : 1; |
| 1363 | |
| 1364 | if (SDE_FORMAT_IS_YUV(fmt) && |
| 1365 | (!(psde->features & SDE_SSPP_SCALER) || |
| 1366 | !(psde->features & BIT(SDE_SSPP_CSC)))) { |
| 1367 | SDE_ERROR("plane doesn't have scaler/csc capability for yuv\n"); |
| 1368 | ret = -EINVAL; |
| 1369 | |
| 1370 | /* check src bounds */ |
| 1371 | } else if (state->fb->width > MAX_IMG_WIDTH || |
| 1372 | state->fb->height > MAX_IMG_HEIGHT || |
| 1373 | src.w < min_src_size || src.h < min_src_size || |
| 1374 | CHECK_LAYER_BOUNDS(src.x, src.w, state->fb->width) || |
| 1375 | CHECK_LAYER_BOUNDS(src.y, src.h, state->fb->height)) { |
| 1376 | SDE_ERROR("invalid source (%u, %u) -> (%u, %u)\n", |
| 1377 | src.x, src.y, src.w, src.h); |
| 1378 | ret = -E2BIG; |
| 1379 | |
| 1380 | /* valid yuv image */ |
| 1381 | } else if (SDE_FORMAT_IS_YUV(fmt) && ((src.x & 0x1) || (src.y & 0x1) || |
| 1382 | (src.w & 0x1) || (src.h & 0x1))) { |
| 1383 | SDE_ERROR("invalid yuv source (%u, %u) -> (%u, %u)\n", |
| 1384 | src.x, src.y, src.w, src.h); |
| 1385 | ret = -EINVAL; |
| 1386 | |
| 1387 | /* min dst support */ |
| 1388 | } else if (dst.w < 0x1 || dst.h < 0x1) { |
| 1389 | SDE_ERROR("invalid dest rect (%u, %u) -> (%u, %u)\n", |
| 1390 | dst.x, dst.y, dst.w, dst.h); |
| 1391 | ret = -EINVAL; |
| 1392 | |
| 1393 | /* decimation validation */ |
| 1394 | } else if (deci_w || deci_h) { |
| 1395 | if ((deci_w > psde->pipe_sblk->maxhdeciexp) || |
| 1396 | (deci_h > psde->pipe_sblk->maxvdeciexp)) { |
| 1397 | SDE_ERROR("too much decimation requested\n"); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1398 | ret = -EINVAL; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1399 | } else if (fmt->fetch_mode != SDE_FETCH_LINEAR) { |
| 1400 | SDE_ERROR("decimation requires linear fetch\n"); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1401 | ret = -EINVAL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1402 | } |
| 1403 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1404 | } else if (!(psde->features & SDE_SSPP_SCALER) && |
| 1405 | ((src.w != dst.w) || (src.h != dst.h))) { |
| 1406 | SDE_ERROR("pipe doesn't support scaling %ux%u->%ux%u\n", |
| 1407 | src.w, src.h, dst.w, dst.h); |
| 1408 | ret = -EINVAL; |
| 1409 | |
| 1410 | /* check decimated source width */ |
| 1411 | } else if (src_deci_w > max_linewidth) { |
| 1412 | SDE_ERROR("invalid source width:%u, deci wid:%u, line wid:%u\n", |
| 1413 | src.w, src_deci_w, max_linewidth); |
| 1414 | ret = -E2BIG; |
| 1415 | |
| 1416 | /* check max scaler capability */ |
| 1417 | } else if (((src_deci_w * max_upscale) < dst.w) || |
| 1418 | ((src_deci_h * max_upscale) < dst.h) || |
| 1419 | ((dst.w * max_downscale) < src_deci_w) || |
| 1420 | ((dst.h * max_downscale) < src_deci_h)) { |
| 1421 | SDE_ERROR("too much scaling requested %ux%u -> %ux%u\n", |
| 1422 | src_deci_w, src_deci_h, dst.w, dst.h); |
| 1423 | ret = -E2BIG; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1424 | } |
| 1425 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1426 | modeset_update: |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1427 | if (!ret) |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1428 | _sde_plane_atomic_check_mode_changed(psde, state, plane->state); |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1429 | exit: |
| 1430 | return ret; |
| 1431 | } |
| 1432 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1433 | /** |
| 1434 | * sde_plane_flush - final plane operations before commit flush |
| 1435 | * @plane: Pointer to drm plane structure |
| 1436 | */ |
| 1437 | void sde_plane_flush(struct drm_plane *plane) |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1438 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1439 | struct sde_plane *psde; |
| 1440 | |
| 1441 | if (!plane) |
| 1442 | return; |
| 1443 | |
| 1444 | psde = to_sde_plane(plane); |
| 1445 | |
| 1446 | /* |
| 1447 | * These updates have to be done immediately before the plane flush |
| 1448 | * timing, and may not be moved to the atomic_update/mode_set functions. |
| 1449 | */ |
| 1450 | if (psde->is_error) |
| 1451 | /* force white frame with 0% alpha pipe output on error */ |
| 1452 | _sde_plane_color_fill(plane, 0xFFFFFF, 0x0); |
| 1453 | else if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG) |
| 1454 | /* force 100% alpha */ |
| 1455 | _sde_plane_color_fill(plane, psde->color_fill, 0xFF); |
| 1456 | else if (psde->pipe_hw && psde->csc_ptr && psde->pipe_hw->ops.setup_csc) |
| 1457 | psde->pipe_hw->ops.setup_csc(psde->pipe_hw, psde->csc_ptr); |
| 1458 | |
| 1459 | /* flag h/w flush complete */ |
| 1460 | if (plane->state) |
Clarence Ip | dbde983 | 2016-06-26 09:48:36 -0400 | [diff] [blame] | 1461 | to_sde_plane_state(plane->state)->pending = false; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1464 | static void sde_plane_atomic_update(struct drm_plane *plane, |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1465 | struct drm_plane_state *old_state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1466 | { |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1467 | struct sde_plane *sde_plane; |
| 1468 | struct drm_plane_state *state; |
| 1469 | struct sde_plane_state *pstate; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1470 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1471 | if (!plane || !plane->state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1472 | SDE_ERROR("invalid plane/state\n"); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1473 | return; |
| 1474 | } |
| 1475 | |
| 1476 | sde_plane = to_sde_plane(plane); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1477 | sde_plane->is_error = false; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1478 | state = plane->state; |
| 1479 | pstate = to_sde_plane_state(state); |
| 1480 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1481 | SDE_DEBUG("%s: update\n", sde_plane->pipe_name); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1482 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1483 | if (!sde_plane_enabled(state)) { |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1484 | pstate->pending = true; |
| 1485 | } else if (pstate->mode_changed) { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1486 | int ret; |
| 1487 | |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1488 | pstate->pending = true; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1489 | ret = _sde_plane_mode_set(plane, state); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1490 | /* atomic_check should have ensured that this doesn't fail */ |
| 1491 | WARN_ON(ret < 0); |
| 1492 | } else { |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1493 | _sde_plane_set_scanout(plane, pstate, |
| 1494 | &sde_plane->pipe_cfg, state->fb); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1495 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1496 | } |
| 1497 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1498 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1499 | /* helper to install properties which are common to planes and crtcs */ |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1500 | static void _sde_plane_install_properties(struct drm_plane *plane, |
| 1501 | u32 max_blendstages) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1502 | { |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1503 | static const struct drm_prop_enum_list e_blend_op[] = { |
| 1504 | {SDE_DRM_BLEND_OP_NOT_DEFINED, "not_defined"}, |
| 1505 | {SDE_DRM_BLEND_OP_OPAQUE, "opaque"}, |
| 1506 | {SDE_DRM_BLEND_OP_PREMULTIPLIED, "premultiplied"}, |
| 1507 | {SDE_DRM_BLEND_OP_COVERAGE, "coverage"} |
| 1508 | }; |
| 1509 | static const struct drm_prop_enum_list e_src_config[] = { |
| 1510 | {SDE_DRM_DEINTERLACE, "deinterlace"} |
| 1511 | }; |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1512 | const struct sde_format_extended *format_list; |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1513 | struct sde_kms_info *info; |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1514 | struct sde_plane *psde = to_sde_plane(plane); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1515 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1516 | if (!plane || !psde || !psde->pipe_hw || !psde->pipe_sblk) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1517 | SDE_ERROR("Invalid argument(s)\n"); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1518 | return; |
| 1519 | } |
| 1520 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1521 | msm_property_install_range(&psde->property_info, "zpos", 0x0, 0, |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame^] | 1522 | max_blendstages, SDE_STAGE_BASE, PLANE_PROP_ZPOS); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1523 | |
Lloyd Atkinson | 38ad8c9 | 2016-07-06 10:39:32 -0400 | [diff] [blame] | 1524 | msm_property_install_range(&psde->property_info, "alpha", |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1525 | 0x0, 0, 255, 255, PLANE_PROP_ALPHA); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1526 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1527 | /* linux default file descriptor range on each process */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1528 | msm_property_install_range(&psde->property_info, "input_fence", |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1529 | 0x0, 0, INR_OPEN_MAX, 0, PLANE_PROP_INPUT_FENCE); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1530 | |
| 1531 | /* standard properties */ |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1532 | msm_property_install_rotation(&psde->property_info, |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1533 | BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y), PLANE_PROP_ROTATION); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1534 | |
Lloyd Atkinson | 38ad8c9 | 2016-07-06 10:39:32 -0400 | [diff] [blame] | 1535 | msm_property_install_enum(&psde->property_info, "blend_op", 0x0, 0, |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1536 | e_blend_op, ARRAY_SIZE(e_blend_op), PLANE_PROP_BLEND_OP); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1537 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1538 | msm_property_install_enum(&psde->property_info, "src_config", 0x0, 1, |
| 1539 | e_src_config, ARRAY_SIZE(e_src_config), PLANE_PROP_SRC_CONFIG); |
| 1540 | |
| 1541 | if (psde->pipe_hw->ops.setup_solidfill) |
| 1542 | msm_property_install_range(&psde->property_info, "color_fill", |
| 1543 | 0, 0, 0xFFFFFFFF, 0, PLANE_PROP_COLOR_FILL); |
| 1544 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1545 | if (psde->features & SDE_SSPP_SCALER) |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1546 | msm_property_install_blob(&psde->property_info, "scaler", 0, |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1547 | PLANE_PROP_SCALER); |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1548 | |
| 1549 | if (psde->features & BIT(SDE_SSPP_CSC)) |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1550 | msm_property_install_blob(&psde->property_info, "csc", 0, |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1551 | PLANE_PROP_CSC); |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1552 | |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1553 | info = kzalloc(sizeof(struct sde_kms_info), GFP_KERNEL); |
| 1554 | if (!info) |
| 1555 | return; |
| 1556 | |
| 1557 | msm_property_install_blob(&psde->property_info, "capabilities", |
| 1558 | DRM_MODE_PROP_IMMUTABLE, PLANE_PROP_INFO); |
| 1559 | sde_kms_info_reset(info); |
| 1560 | |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1561 | format_list = psde->pipe_sblk->format_list; |
| 1562 | if (format_list) { |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1563 | sde_kms_info_start(info, "pixel_formats"); |
| 1564 | while (format_list->fourcc_format) { |
| 1565 | sde_kms_info_append_format(info, |
| 1566 | format_list->fourcc_format, |
| 1567 | format_list->modifier); |
| 1568 | ++format_list; |
| 1569 | } |
| 1570 | sde_kms_info_stop(info); |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1571 | } |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1572 | |
| 1573 | sde_kms_info_add_keyint(info, "max_linewidth", |
| 1574 | psde->pipe_sblk->maxlinewidth); |
| 1575 | sde_kms_info_add_keyint(info, "max_upscale", |
| 1576 | psde->pipe_sblk->maxupscale); |
| 1577 | sde_kms_info_add_keyint(info, "max_downscale", |
| 1578 | psde->pipe_sblk->maxdwnscale); |
| 1579 | sde_kms_info_add_keyint(info, "max_horizontal_deci", |
| 1580 | psde->pipe_sblk->maxhdeciexp); |
| 1581 | sde_kms_info_add_keyint(info, "max_vertical_deci", |
| 1582 | psde->pipe_sblk->maxvdeciexp); |
| 1583 | msm_property_set_blob(&psde->property_info, &psde->blob_info, |
| 1584 | info->data, info->len, PLANE_PROP_INFO); |
| 1585 | |
| 1586 | kfree(info); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | static int sde_plane_atomic_set_property(struct drm_plane *plane, |
| 1590 | struct drm_plane_state *state, struct drm_property *property, |
| 1591 | uint64_t val) |
| 1592 | { |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1593 | struct sde_plane *psde; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1594 | struct sde_plane_state *pstate; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1595 | int idx, ret = -EINVAL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1596 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1597 | DBG(""); |
| 1598 | |
| 1599 | if (!plane) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1600 | SDE_ERROR("invalid plane\n"); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1601 | } else if (!state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1602 | SDE_ERROR("invalid state\n"); |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1603 | } else { |
| 1604 | psde = to_sde_plane(plane); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1605 | pstate = to_sde_plane_state(state); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1606 | ret = msm_property_atomic_set(&psde->property_info, |
| 1607 | pstate->property_values, pstate->property_blobs, |
| 1608 | property, val); |
| 1609 | if (!ret) { |
| 1610 | idx = msm_property_index(&psde->property_info, |
| 1611 | property); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1612 | if (idx == PLANE_PROP_INPUT_FENCE) |
| 1613 | _sde_plane_set_input_fence(plane, pstate, val); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1617 | return ret; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | static int sde_plane_set_property(struct drm_plane *plane, |
| 1621 | struct drm_property *property, uint64_t val) |
| 1622 | { |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1623 | DBG(""); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1624 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1625 | return sde_plane_atomic_set_property(plane, |
| 1626 | plane->state, property, val); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | static int sde_plane_atomic_get_property(struct drm_plane *plane, |
| 1630 | const struct drm_plane_state *state, |
| 1631 | struct drm_property *property, uint64_t *val) |
| 1632 | { |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1633 | struct sde_plane *psde; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1634 | struct sde_plane_state *pstate; |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1635 | int ret = -EINVAL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1636 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1637 | DBG(""); |
| 1638 | |
| 1639 | if (!plane) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1640 | SDE_ERROR("invalid plane\n"); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1641 | } else if (!state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1642 | SDE_ERROR("invalid state\n"); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1643 | } else { |
| 1644 | psde = to_sde_plane(plane); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1645 | pstate = to_sde_plane_state(state); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1646 | ret = msm_property_atomic_get(&psde->property_info, |
| 1647 | pstate->property_values, pstate->property_blobs, |
| 1648 | property, val); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1649 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1650 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1651 | return ret; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | static void sde_plane_destroy(struct drm_plane *plane) |
| 1655 | { |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1656 | struct sde_plane *psde; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1657 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1658 | DBG(""); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1659 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1660 | if (plane) { |
| 1661 | psde = to_sde_plane(plane); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1662 | |
Alan Kwong | 1a00e4d | 2016-07-18 09:42:30 -0400 | [diff] [blame] | 1663 | _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL); |
| 1664 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1665 | debugfs_remove_recursive(psde->debugfs_root); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1666 | |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1667 | if (psde->blob_info) |
| 1668 | drm_property_unreference_blob(psde->blob_info); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1669 | msm_property_destroy(&psde->property_info); |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1670 | mutex_destroy(&psde->lock); |
| 1671 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1672 | drm_plane_helper_disable(plane); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1673 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1674 | /* this will destroy the states as well */ |
| 1675 | drm_plane_cleanup(plane); |
| 1676 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1677 | if (psde->pipe_hw) |
| 1678 | sde_hw_sspp_destroy(psde->pipe_hw); |
| 1679 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1680 | kfree(psde); |
| 1681 | } |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1684 | static void sde_plane_destroy_state(struct drm_plane *plane, |
| 1685 | struct drm_plane_state *state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1686 | { |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1687 | struct sde_plane *psde; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1688 | struct sde_plane_state *pstate; |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1689 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1690 | if (!plane || !state) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1691 | SDE_ERROR("invalid plane/state\n"); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1692 | return; |
| 1693 | } |
| 1694 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1695 | psde = to_sde_plane(plane); |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1696 | pstate = to_sde_plane_state(state); |
| 1697 | |
| 1698 | DBG(""); |
| 1699 | |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1700 | /* remove ref count for frame buffers */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1701 | if (state->fb) |
| 1702 | drm_framebuffer_unreference(state->fb); |
| 1703 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1704 | /* remove ref count for fence */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1705 | if (pstate->input_fence) |
| 1706 | sde_sync_put(pstate->input_fence); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1707 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1708 | /* destroy value helper */ |
| 1709 | msm_property_destroy_state(&psde->property_info, pstate, |
| 1710 | pstate->property_values, pstate->property_blobs); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1713 | static struct drm_plane_state * |
| 1714 | sde_plane_duplicate_state(struct drm_plane *plane) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1715 | { |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1716 | struct sde_plane *psde; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1717 | struct sde_plane_state *pstate; |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1718 | struct sde_plane_state *old_state; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1719 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1720 | if (!plane || !plane->state) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1721 | return NULL; |
| 1722 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1723 | old_state = to_sde_plane_state(plane->state); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1724 | psde = to_sde_plane(plane); |
| 1725 | pstate = msm_property_alloc_state(&psde->property_info); |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1726 | if (!pstate) |
| 1727 | return NULL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1728 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1729 | DBG(""); |
| 1730 | |
| 1731 | /* duplicate value helper */ |
| 1732 | msm_property_duplicate_state(&psde->property_info, old_state, pstate, |
| 1733 | pstate->property_values, pstate->property_blobs); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1734 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1735 | /* add ref count for frame buffer */ |
| 1736 | if (pstate->base.fb) |
| 1737 | drm_framebuffer_reference(pstate->base.fb); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1738 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1739 | /* add ref count for fence */ |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1740 | if (pstate->input_fence) { |
| 1741 | pstate->input_fence = 0; |
| 1742 | _sde_plane_set_input_fence(plane, pstate, pstate-> |
| 1743 | property_values[PLANE_PROP_INPUT_FENCE]); |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1744 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1745 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1746 | pstate->mode_changed = false; |
| 1747 | pstate->pending = false; |
| 1748 | |
| 1749 | return &pstate->base; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static void sde_plane_reset(struct drm_plane *plane) |
| 1753 | { |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1754 | struct sde_plane *psde; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1755 | struct sde_plane_state *pstate; |
| 1756 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1757 | if (!plane) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1758 | SDE_ERROR("invalid plane\n"); |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1759 | return; |
| 1760 | } |
| 1761 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1762 | psde = to_sde_plane(plane); |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1763 | SDE_DEBUG("%s\n", psde->pipe_name); |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1764 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1765 | /* remove previous state, if present */ |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1766 | if (plane->state) { |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1767 | sde_plane_destroy_state(plane, plane->state); |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1768 | plane->state = 0; |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1769 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1770 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1771 | pstate = msm_property_alloc_state(&psde->property_info); |
| 1772 | if (!pstate) |
| 1773 | return; |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1774 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1775 | /* reset value helper */ |
| 1776 | msm_property_reset_state(&psde->property_info, pstate, |
| 1777 | pstate->property_values, pstate->property_blobs); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1778 | |
| 1779 | pstate->base.plane = plane; |
| 1780 | |
| 1781 | plane->state = &pstate->base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | static const struct drm_plane_funcs sde_plane_funcs = { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1785 | .update_plane = drm_atomic_helper_update_plane, |
| 1786 | .disable_plane = drm_atomic_helper_disable_plane, |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1787 | .destroy = sde_plane_destroy, |
| 1788 | .set_property = sde_plane_set_property, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1789 | .atomic_set_property = sde_plane_atomic_set_property, |
| 1790 | .atomic_get_property = sde_plane_atomic_get_property, |
| 1791 | .reset = sde_plane_reset, |
| 1792 | .atomic_duplicate_state = sde_plane_duplicate_state, |
| 1793 | .atomic_destroy_state = sde_plane_destroy_state, |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1794 | }; |
| 1795 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1796 | static const struct drm_plane_helper_funcs sde_plane_helper_funcs = { |
| 1797 | .prepare_fb = sde_plane_prepare_fb, |
| 1798 | .cleanup_fb = sde_plane_cleanup_fb, |
| 1799 | .atomic_check = sde_plane_atomic_check, |
| 1800 | .atomic_update = sde_plane_atomic_update, |
| 1801 | }; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1802 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1803 | enum sde_sspp sde_plane_pipe(struct drm_plane *plane) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1804 | { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1805 | struct sde_plane *sde_plane = to_sde_plane(plane); |
| 1806 | |
| 1807 | return sde_plane->pipe; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1810 | static void _sde_plane_init_debugfs(struct sde_plane *psde, struct sde_kms *kms) |
| 1811 | { |
| 1812 | const struct sde_sspp_sub_blks *sblk = 0; |
| 1813 | const struct sde_sspp_cfg *cfg = 0; |
| 1814 | |
| 1815 | if (psde && psde->pipe_hw) |
| 1816 | cfg = psde->pipe_hw->cap; |
| 1817 | if (cfg) |
| 1818 | sblk = cfg->sblk; |
| 1819 | |
| 1820 | if (kms && sblk) { |
| 1821 | /* create overall sub-directory for the pipe */ |
| 1822 | psde->debugfs_root = |
| 1823 | debugfs_create_dir(psde->pipe_name, |
| 1824 | sde_debugfs_get_root(kms)); |
| 1825 | if (psde->debugfs_root) { |
| 1826 | /* don't error check these */ |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1827 | debugfs_create_x32("features", 0644, |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1828 | psde->debugfs_root, &psde->features); |
| 1829 | |
| 1830 | /* add register dump support */ |
| 1831 | sde_debugfs_setup_regset32(&psde->debugfs_src, |
| 1832 | sblk->src_blk.base + cfg->base, |
| 1833 | sblk->src_blk.len, |
| 1834 | kms->mmio); |
| 1835 | sde_debugfs_create_regset32("src_blk", 0444, |
| 1836 | psde->debugfs_root, &psde->debugfs_src); |
| 1837 | |
| 1838 | sde_debugfs_setup_regset32(&psde->debugfs_scaler, |
| 1839 | sblk->scaler_blk.base + cfg->base, |
| 1840 | sblk->scaler_blk.len, |
| 1841 | kms->mmio); |
| 1842 | sde_debugfs_create_regset32("scaler_blk", 0444, |
| 1843 | psde->debugfs_root, |
| 1844 | &psde->debugfs_scaler); |
| 1845 | |
| 1846 | sde_debugfs_setup_regset32(&psde->debugfs_csc, |
| 1847 | sblk->csc_blk.base + cfg->base, |
| 1848 | sblk->csc_blk.len, |
| 1849 | kms->mmio); |
| 1850 | sde_debugfs_create_regset32("csc_blk", 0444, |
| 1851 | psde->debugfs_root, &psde->debugfs_csc); |
| 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1856 | /* initialize plane */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame] | 1857 | struct drm_plane *sde_plane_init(struct drm_device *dev, |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1858 | uint32_t pipe, bool primary_plane) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1859 | { |
| 1860 | struct drm_plane *plane = NULL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1861 | struct sde_plane *psde; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1862 | struct msm_drm_private *priv; |
| 1863 | struct sde_kms *kms; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1864 | enum drm_plane_type type; |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1865 | int ret = -EINVAL, max_blendstages = 255; |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1866 | |
| 1867 | if (!dev) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1868 | SDE_ERROR("[%u]device is NULL\n", pipe); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1869 | goto exit; |
| 1870 | } |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1871 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1872 | priv = dev->dev_private; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 1873 | if (!priv) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1874 | SDE_ERROR("[%u]private data is NULL\n", pipe); |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 1875 | goto exit; |
| 1876 | } |
| 1877 | |
| 1878 | if (!priv->kms) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1879 | SDE_ERROR("[%u]invalid KMS reference\n", pipe); |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 1880 | goto exit; |
| 1881 | } |
| 1882 | kms = to_sde_kms(priv->kms); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1883 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1884 | if (!kms->catalog) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1885 | SDE_ERROR("[%u]invalid catalog reference\n", pipe); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1886 | goto exit; |
| 1887 | } |
| 1888 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1889 | /* create and zero local structure */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1890 | psde = kzalloc(sizeof(*psde), GFP_KERNEL); |
| 1891 | if (!psde) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1892 | SDE_ERROR("[%u]failed to allocate local plane struct\n", pipe); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1893 | ret = -ENOMEM; |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1894 | goto exit; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1897 | /* cache local stuff for later */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1898 | plane = &psde->base; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1899 | psde->pipe = pipe; |
Alan Kwong | 112a84f | 2016-05-24 20:49:21 -0400 | [diff] [blame] | 1900 | psde->mmu_id = kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1901 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1902 | /* initialize underlying h/w driver */ |
| 1903 | psde->pipe_hw = sde_hw_sspp_init(pipe, kms->mmio, kms->catalog); |
| 1904 | if (IS_ERR(psde->pipe_hw)) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1905 | SDE_ERROR("[%u]SSPP init failed\n", pipe); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1906 | ret = PTR_ERR(psde->pipe_hw); |
| 1907 | goto clean_plane; |
| 1908 | } else if (!psde->pipe_hw->cap || !psde->pipe_hw->cap->sblk) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1909 | SDE_ERROR("[%u]SSPP init returned invalid cfg\n", pipe); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1910 | goto clean_sspp; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1911 | } |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1912 | |
| 1913 | /* cache features mask for later */ |
| 1914 | psde->features = psde->pipe_hw->cap->features; |
| 1915 | psde->pipe_sblk = psde->pipe_hw->cap->sblk; |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1916 | if (!psde->pipe_sblk) { |
| 1917 | SDE_ERROR("invalid sblk on pipe %d\n", pipe); |
| 1918 | goto clean_sspp; |
| 1919 | } |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1920 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1921 | if (kms->catalog && kms->catalog->mixer_count && kms->catalog->mixer) |
| 1922 | max_blendstages = kms->catalog->mixer[0].sblk->maxblendstages; |
| 1923 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1924 | /* add plane to DRM framework */ |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1925 | psde->nformats = sde_populate_formats(psde->pipe_sblk->format_list, |
| 1926 | psde->formats, |
| 1927 | 0, |
| 1928 | ARRAY_SIZE(psde->formats)); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1929 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1930 | if (!psde->nformats) { |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1931 | SDE_ERROR("[%u]no valid formats for plane\n", pipe); |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1932 | goto clean_sspp; |
| 1933 | } |
| 1934 | |
| 1935 | if (psde->features & BIT(SDE_SSPP_CURSOR)) |
| 1936 | type = DRM_PLANE_TYPE_CURSOR; |
| 1937 | else if (primary_plane) |
| 1938 | type = DRM_PLANE_TYPE_PRIMARY; |
| 1939 | else |
| 1940 | type = DRM_PLANE_TYPE_OVERLAY; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1941 | ret = drm_universal_plane_init(dev, plane, 0xff, &sde_plane_funcs, |
| 1942 | psde->formats, psde->nformats, |
| 1943 | type); |
| 1944 | if (ret) |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1945 | goto clean_sspp; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1946 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1947 | /* success! finalize initialization */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1948 | drm_plane_helper_add(plane, &sde_plane_helper_funcs); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1949 | |
Clarence Ip | aa0faf4 | 2016-05-30 12:07:48 -0400 | [diff] [blame] | 1950 | msm_property_init(&psde->property_info, &plane->base, dev, |
| 1951 | priv->plane_property, psde->property_data, |
| 1952 | PLANE_PROP_COUNT, PLANE_PROP_BLOBCOUNT, |
| 1953 | sizeof(struct sde_plane_state)); |
| 1954 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1955 | _sde_plane_install_properties(plane, max_blendstages); |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1956 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1957 | /* save user friendly pipe name for later */ |
Clarence Ip | 5e2a922 | 2016-06-26 22:38:24 -0400 | [diff] [blame] | 1958 | snprintf(psde->pipe_name, SDE_NAME_SIZE, "plane%u", plane->base.id); |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1959 | |
Clarence Ip | 730e719 | 2016-06-26 22:45:09 -0400 | [diff] [blame] | 1960 | mutex_init(&psde->lock); |
| 1961 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 1962 | _sde_plane_init_debugfs(psde, kms); |
| 1963 | |
Dhaval Patel | 47302cf | 2016-08-18 15:04:28 -0700 | [diff] [blame] | 1964 | DRM_INFO("[%u]successfully created %s\n", pipe, psde->pipe_name); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1965 | return plane; |
| 1966 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 1967 | clean_sspp: |
| 1968 | if (psde && psde->pipe_hw) |
| 1969 | sde_hw_sspp_destroy(psde->pipe_hw); |
| 1970 | clean_plane: |
| 1971 | kfree(psde); |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 1972 | exit: |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1973 | return ERR_PTR(ret); |
| 1974 | } |