Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved. |
| 3 | * Copyright (C) 2013 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 5 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 9 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program. If not, see <http://www.gnu.org/licenses/>. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 19 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 20 | #include <linux/sort.h> |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 22 | #include <linux/ktime.h> |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 23 | #include <uapi/drm/sde_drm.h> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 24 | #include <drm/drm_mode.h> |
| 25 | #include <drm/drm_crtc.h> |
| 26 | #include <drm/drm_crtc_helper.h> |
| 27 | #include <drm/drm_flip_work.h> |
| 28 | |
| 29 | #include "sde_kms.h" |
| 30 | #include "sde_hw_lm.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 31 | #include "sde_hw_ctl.h" |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 32 | #include "sde_crtc.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 33 | #include "sde_plane.h" |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 34 | #include "sde_color_processing.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 35 | #include "sde_encoder.h" |
| 36 | #include "sde_connector.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 37 | #include "sde_power_handle.h" |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 38 | #include "sde_core_perf.h" |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 39 | #include "sde_trace.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 40 | |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 41 | struct sde_crtc_irq_info { |
| 42 | struct sde_irq_callback irq; |
| 43 | u32 event; |
| 44 | int (*func)(struct drm_crtc *crtc, bool en, |
| 45 | struct sde_irq_callback *irq); |
| 46 | struct list_head list; |
| 47 | }; |
| 48 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 49 | struct sde_crtc_custom_events { |
| 50 | u32 event; |
| 51 | int (*func)(struct drm_crtc *crtc, bool en, |
| 52 | struct sde_irq_callback *irq); |
| 53 | }; |
| 54 | |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 55 | static int sde_crtc_power_interrupt_handler(struct drm_crtc *crtc_drm, |
| 56 | bool en, struct sde_irq_callback *ad_irq); |
| 57 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 58 | static struct sde_crtc_custom_events custom_events[] = { |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 59 | {DRM_EVENT_AD_BACKLIGHT, sde_cp_ad_interrupt}, |
| 60 | {DRM_EVENT_CRTC_POWER, sde_crtc_power_interrupt_handler} |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 63 | /* default input fence timeout, in ms */ |
| 64 | #define SDE_CRTC_INPUT_FENCE_TIMEOUT 2000 |
| 65 | |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 66 | /* |
| 67 | * The default input fence timeout is 2 seconds while max allowed |
| 68 | * range is 10 seconds. Any value above 10 seconds adds glitches beyond |
| 69 | * tolerance limit. |
| 70 | */ |
| 71 | #define SDE_CRTC_MAX_INPUT_FENCE_TIMEOUT 10000 |
| 72 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 73 | /* layer mixer index on sde_crtc */ |
| 74 | #define LEFT_MIXER 0 |
| 75 | #define RIGHT_MIXER 1 |
| 76 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 77 | #define MISR_BUFF_SIZE 256 |
| 78 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 79 | static inline struct sde_kms *_sde_crtc_get_kms(struct drm_crtc *crtc) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 80 | { |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 81 | struct msm_drm_private *priv; |
| 82 | |
| 83 | if (!crtc || !crtc->dev || !crtc->dev->dev_private) { |
| 84 | SDE_ERROR("invalid crtc\n"); |
| 85 | return NULL; |
| 86 | } |
| 87 | priv = crtc->dev->dev_private; |
| 88 | if (!priv || !priv->kms) { |
| 89 | SDE_ERROR("invalid kms\n"); |
| 90 | return NULL; |
| 91 | } |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 92 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 93 | return to_sde_kms(priv->kms); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 96 | static inline int _sde_crtc_power_enable(struct sde_crtc *sde_crtc, bool enable) |
| 97 | { |
| 98 | struct drm_crtc *crtc; |
| 99 | struct msm_drm_private *priv; |
| 100 | struct sde_kms *sde_kms; |
| 101 | |
| 102 | if (!sde_crtc) { |
| 103 | SDE_ERROR("invalid sde crtc\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | crtc = &sde_crtc->base; |
| 108 | if (!crtc->dev || !crtc->dev->dev_private) { |
| 109 | SDE_ERROR("invalid drm device\n"); |
| 110 | return -EINVAL; |
| 111 | } |
| 112 | |
| 113 | priv = crtc->dev->dev_private; |
| 114 | if (!priv->kms) { |
| 115 | SDE_ERROR("invalid kms\n"); |
| 116 | return -EINVAL; |
| 117 | } |
| 118 | |
| 119 | sde_kms = to_sde_kms(priv->kms); |
| 120 | |
| 121 | return sde_power_resource_enable(&priv->phandle, sde_kms->core_client, |
| 122 | enable); |
| 123 | } |
| 124 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 125 | /** |
| 126 | * _sde_crtc_rp_to_crtc - get crtc from resource pool object |
| 127 | * @rp: Pointer to resource pool |
| 128 | * return: Pointer to drm crtc if success; null otherwise |
| 129 | */ |
| 130 | static struct drm_crtc *_sde_crtc_rp_to_crtc(struct sde_crtc_respool *rp) |
| 131 | { |
| 132 | if (!rp) |
| 133 | return NULL; |
| 134 | |
| 135 | return container_of(rp, struct sde_crtc_state, rp)->base.crtc; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * _sde_crtc_rp_reclaim - reclaim unused, or all if forced, resources in pool |
| 140 | * @rp: Pointer to resource pool |
| 141 | * @force: True to reclaim all resources; otherwise, reclaim only unused ones |
| 142 | * return: None |
| 143 | */ |
| 144 | static void _sde_crtc_rp_reclaim(struct sde_crtc_respool *rp, bool force) |
| 145 | { |
| 146 | struct sde_crtc_res *res, *next; |
| 147 | struct drm_crtc *crtc; |
| 148 | |
| 149 | crtc = _sde_crtc_rp_to_crtc(rp); |
| 150 | if (!crtc) { |
| 151 | SDE_ERROR("invalid crtc\n"); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | SDE_DEBUG("crtc%d.%u %s\n", crtc->base.id, rp->sequence_id, |
| 156 | force ? "destroy" : "free_unused"); |
| 157 | |
| 158 | list_for_each_entry_safe(res, next, &rp->res_list, list) { |
| 159 | if (!force && !(res->flags & SDE_CRTC_RES_FLAG_FREE)) |
| 160 | continue; |
| 161 | SDE_DEBUG("crtc%d.%u reclaim res:0x%x/0x%llx/%pK/%d\n", |
| 162 | crtc->base.id, rp->sequence_id, |
| 163 | res->type, res->tag, res->val, |
| 164 | atomic_read(&res->refcount)); |
| 165 | list_del(&res->list); |
| 166 | if (res->ops.put) |
| 167 | res->ops.put(res->val); |
| 168 | kfree(res); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * _sde_crtc_rp_free_unused - free unused resource in pool |
| 174 | * @rp: Pointer to resource pool |
| 175 | * return: none |
| 176 | */ |
| 177 | static void _sde_crtc_rp_free_unused(struct sde_crtc_respool *rp) |
| 178 | { |
| 179 | _sde_crtc_rp_reclaim(rp, false); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * _sde_crtc_rp_destroy - destroy resource pool |
| 184 | * @rp: Pointer to resource pool |
| 185 | * return: None |
| 186 | */ |
| 187 | static void _sde_crtc_rp_destroy(struct sde_crtc_respool *rp) |
| 188 | { |
| 189 | _sde_crtc_rp_reclaim(rp, true); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * _sde_crtc_hw_blk_get - get callback for hardware block |
| 194 | * @val: Resource handle |
| 195 | * @type: Resource type |
| 196 | * @tag: Search tag for given resource |
| 197 | * return: Resource handle |
| 198 | */ |
| 199 | static void *_sde_crtc_hw_blk_get(void *val, u32 type, u64 tag) |
| 200 | { |
| 201 | SDE_DEBUG("res:%d/0x%llx/%pK\n", type, tag, val); |
| 202 | return sde_hw_blk_get(val, type, tag); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * _sde_crtc_hw_blk_put - put callback for hardware block |
| 207 | * @val: Resource handle |
| 208 | * return: None |
| 209 | */ |
| 210 | static void _sde_crtc_hw_blk_put(void *val) |
| 211 | { |
| 212 | SDE_DEBUG("res://%pK\n", val); |
| 213 | sde_hw_blk_put(val); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * _sde_crtc_rp_duplicate - duplicate resource pool and reset reference count |
| 218 | * @rp: Pointer to original resource pool |
| 219 | * @dup_rp: Pointer to duplicated resource pool |
| 220 | * return: None |
| 221 | */ |
| 222 | static void _sde_crtc_rp_duplicate(struct sde_crtc_respool *rp, |
| 223 | struct sde_crtc_respool *dup_rp) |
| 224 | { |
| 225 | struct sde_crtc_res *res, *dup_res; |
| 226 | struct drm_crtc *crtc; |
| 227 | |
| 228 | if (!rp || !dup_rp) { |
| 229 | SDE_ERROR("invalid resource pool\n"); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | crtc = _sde_crtc_rp_to_crtc(rp); |
| 234 | if (!crtc) { |
| 235 | SDE_ERROR("invalid crtc\n"); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | SDE_DEBUG("crtc%d.%u duplicate\n", crtc->base.id, rp->sequence_id); |
| 240 | |
| 241 | dup_rp->sequence_id = rp->sequence_id + 1; |
| 242 | INIT_LIST_HEAD(&dup_rp->res_list); |
| 243 | dup_rp->ops = rp->ops; |
| 244 | list_for_each_entry(res, &rp->res_list, list) { |
| 245 | dup_res = kzalloc(sizeof(struct sde_crtc_res), GFP_KERNEL); |
| 246 | if (!dup_res) |
| 247 | return; |
| 248 | INIT_LIST_HEAD(&dup_res->list); |
| 249 | atomic_set(&dup_res->refcount, 0); |
| 250 | dup_res->type = res->type; |
| 251 | dup_res->tag = res->tag; |
| 252 | dup_res->val = res->val; |
| 253 | dup_res->ops = res->ops; |
| 254 | dup_res->flags = SDE_CRTC_RES_FLAG_FREE; |
| 255 | SDE_DEBUG("crtc%d.%u dup res:0x%x/0x%llx/%pK/%d\n", |
| 256 | crtc->base.id, dup_rp->sequence_id, |
| 257 | dup_res->type, dup_res->tag, dup_res->val, |
| 258 | atomic_read(&dup_res->refcount)); |
| 259 | list_add_tail(&dup_res->list, &dup_rp->res_list); |
| 260 | if (dup_res->ops.get) |
| 261 | dup_res->ops.get(dup_res->val, 0, -1); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * _sde_crtc_rp_reset - reset resource pool after allocation |
| 267 | * @rp: Pointer to original resource pool |
| 268 | * return: None |
| 269 | */ |
| 270 | static void _sde_crtc_rp_reset(struct sde_crtc_respool *rp) |
| 271 | { |
| 272 | if (!rp) { |
| 273 | SDE_ERROR("invalid resource pool\n"); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | rp->sequence_id = 0; |
| 278 | INIT_LIST_HEAD(&rp->res_list); |
| 279 | rp->ops.get = _sde_crtc_hw_blk_get; |
| 280 | rp->ops.put = _sde_crtc_hw_blk_put; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * _sde_crtc_rp_add - add given resource to resource pool |
| 285 | * @rp: Pointer to original resource pool |
| 286 | * @type: Resource type |
| 287 | * @tag: Search tag for given resource |
| 288 | * @val: Resource handle |
| 289 | * @ops: Resource callback operations |
| 290 | * return: 0 if success; error code otherwise |
| 291 | */ |
| 292 | static int _sde_crtc_rp_add(struct sde_crtc_respool *rp, u32 type, u64 tag, |
| 293 | void *val, struct sde_crtc_res_ops *ops) |
| 294 | { |
| 295 | struct sde_crtc_res *res; |
| 296 | struct drm_crtc *crtc; |
| 297 | |
| 298 | if (!rp || !ops) { |
| 299 | SDE_ERROR("invalid resource pool/ops\n"); |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
| 303 | crtc = _sde_crtc_rp_to_crtc(rp); |
| 304 | if (!crtc) { |
| 305 | SDE_ERROR("invalid crtc\n"); |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | list_for_each_entry(res, &rp->res_list, list) { |
| 310 | if (res->type != type || res->tag != tag) |
| 311 | continue; |
| 312 | SDE_ERROR("crtc%d.%u already exist res:0x%x/0x%llx/%pK/%d\n", |
| 313 | crtc->base.id, rp->sequence_id, |
| 314 | res->type, res->tag, res->val, |
| 315 | atomic_read(&res->refcount)); |
| 316 | return -EEXIST; |
| 317 | } |
| 318 | res = kzalloc(sizeof(struct sde_crtc_res), GFP_KERNEL); |
| 319 | if (!res) |
| 320 | return -ENOMEM; |
| 321 | INIT_LIST_HEAD(&res->list); |
| 322 | atomic_set(&res->refcount, 1); |
| 323 | res->type = type; |
| 324 | res->tag = tag; |
| 325 | res->val = val; |
| 326 | res->ops = *ops; |
| 327 | list_add_tail(&res->list, &rp->res_list); |
| 328 | SDE_DEBUG("crtc%d.%u added res:0x%x/0x%llx\n", |
| 329 | crtc->base.id, rp->sequence_id, type, tag); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * _sde_crtc_rp_get - lookup the resource from given resource pool and obtain |
| 335 | * if available; otherwise, obtain resource from global pool |
| 336 | * @rp: Pointer to original resource pool |
| 337 | * @type: Resource type |
| 338 | * @tag: Search tag for given resource |
| 339 | * return: Resource handle if success; pointer error or null otherwise |
| 340 | */ |
| 341 | static void *_sde_crtc_rp_get(struct sde_crtc_respool *rp, u32 type, u64 tag) |
| 342 | { |
| 343 | struct sde_crtc_res *res; |
| 344 | void *val = NULL; |
| 345 | int rc; |
| 346 | struct drm_crtc *crtc; |
| 347 | |
| 348 | if (!rp) { |
| 349 | SDE_ERROR("invalid resource pool\n"); |
| 350 | return NULL; |
| 351 | } |
| 352 | |
| 353 | crtc = _sde_crtc_rp_to_crtc(rp); |
| 354 | if (!crtc) { |
| 355 | SDE_ERROR("invalid crtc\n"); |
| 356 | return NULL; |
| 357 | } |
| 358 | |
| 359 | list_for_each_entry(res, &rp->res_list, list) { |
| 360 | if (res->type != type || res->tag != tag) |
| 361 | continue; |
| 362 | SDE_DEBUG("crtc%d.%u found res:0x%x/0x%llx/%pK/%d\n", |
| 363 | crtc->base.id, rp->sequence_id, |
| 364 | res->type, res->tag, res->val, |
| 365 | atomic_read(&res->refcount)); |
| 366 | atomic_inc(&res->refcount); |
| 367 | res->flags &= ~SDE_CRTC_RES_FLAG_FREE; |
| 368 | return res->val; |
| 369 | } |
| 370 | list_for_each_entry(res, &rp->res_list, list) { |
| 371 | if (res->type != type || !(res->flags & SDE_CRTC_RES_FLAG_FREE)) |
| 372 | continue; |
| 373 | SDE_DEBUG("crtc%d.%u retag res:0x%x/0x%llx/%pK/%d\n", |
| 374 | crtc->base.id, rp->sequence_id, |
| 375 | res->type, res->tag, res->val, |
| 376 | atomic_read(&res->refcount)); |
| 377 | atomic_inc(&res->refcount); |
| 378 | res->tag = tag; |
| 379 | res->flags &= ~SDE_CRTC_RES_FLAG_FREE; |
| 380 | return res->val; |
| 381 | } |
| 382 | if (rp->ops.get) |
| 383 | val = rp->ops.get(NULL, type, -1); |
| 384 | if (IS_ERR_OR_NULL(val)) { |
Alan Kwong | 42e3505 | 2017-05-05 06:52:51 -0700 | [diff] [blame] | 385 | SDE_DEBUG("crtc%d.%u failed to get res:0x%x//\n", |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 386 | crtc->base.id, rp->sequence_id, type); |
| 387 | return NULL; |
| 388 | } |
| 389 | rc = _sde_crtc_rp_add(rp, type, tag, val, &rp->ops); |
| 390 | if (rc) { |
| 391 | SDE_ERROR("crtc%d.%u failed to add res:0x%x/0x%llx\n", |
| 392 | crtc->base.id, rp->sequence_id, type, tag); |
| 393 | if (rp->ops.put) |
| 394 | rp->ops.put(val); |
| 395 | val = NULL; |
| 396 | } |
| 397 | return val; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * _sde_crtc_rp_put - return given resource to resource pool |
| 402 | * @rp: Pointer to original resource pool |
| 403 | * @type: Resource type |
| 404 | * @tag: Search tag for given resource |
| 405 | * return: None |
| 406 | */ |
| 407 | static void _sde_crtc_rp_put(struct sde_crtc_respool *rp, u32 type, u64 tag) |
| 408 | { |
| 409 | struct sde_crtc_res *res, *next; |
| 410 | struct drm_crtc *crtc; |
| 411 | |
| 412 | if (!rp) { |
| 413 | SDE_ERROR("invalid resource pool\n"); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | crtc = _sde_crtc_rp_to_crtc(rp); |
| 418 | if (!crtc) { |
| 419 | SDE_ERROR("invalid crtc\n"); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | list_for_each_entry_safe(res, next, &rp->res_list, list) { |
| 424 | if (res->type != type || res->tag != tag) |
| 425 | continue; |
| 426 | SDE_DEBUG("crtc%d.%u found res:0x%x/0x%llx/%pK/%d\n", |
| 427 | crtc->base.id, rp->sequence_id, |
| 428 | res->type, res->tag, res->val, |
| 429 | atomic_read(&res->refcount)); |
| 430 | if (res->flags & SDE_CRTC_RES_FLAG_FREE) |
| 431 | SDE_ERROR( |
| 432 | "crtc%d.%u already free res:0x%x/0x%llx/%pK/%d\n", |
| 433 | crtc->base.id, rp->sequence_id, |
| 434 | res->type, res->tag, res->val, |
| 435 | atomic_read(&res->refcount)); |
| 436 | else if (atomic_dec_return(&res->refcount) == 0) |
| 437 | res->flags |= SDE_CRTC_RES_FLAG_FREE; |
| 438 | |
| 439 | return; |
| 440 | } |
| 441 | SDE_ERROR("crtc%d.%u not found res:0x%x/0x%llx\n", |
| 442 | crtc->base.id, rp->sequence_id, type, tag); |
| 443 | } |
| 444 | |
| 445 | int sde_crtc_res_add(struct drm_crtc_state *state, u32 type, u64 tag, |
| 446 | void *val, struct sde_crtc_res_ops *ops) |
| 447 | { |
| 448 | struct sde_crtc_respool *rp; |
| 449 | |
| 450 | if (!state) { |
| 451 | SDE_ERROR("invalid parameters\n"); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | |
| 455 | rp = &to_sde_crtc_state(state)->rp; |
| 456 | return _sde_crtc_rp_add(rp, type, tag, val, ops); |
| 457 | } |
| 458 | |
| 459 | void *sde_crtc_res_get(struct drm_crtc_state *state, u32 type, u64 tag) |
| 460 | { |
| 461 | struct sde_crtc_respool *rp; |
| 462 | void *val; |
| 463 | |
| 464 | if (!state) { |
| 465 | SDE_ERROR("invalid parameters\n"); |
| 466 | return NULL; |
| 467 | } |
| 468 | |
| 469 | rp = &to_sde_crtc_state(state)->rp; |
| 470 | val = _sde_crtc_rp_get(rp, type, tag); |
| 471 | if (IS_ERR(val)) { |
| 472 | SDE_ERROR("failed to get res type:0x%x:0x%llx\n", |
| 473 | type, tag); |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | return val; |
| 478 | } |
| 479 | |
| 480 | void sde_crtc_res_put(struct drm_crtc_state *state, u32 type, u64 tag) |
| 481 | { |
| 482 | struct sde_crtc_respool *rp; |
| 483 | |
| 484 | if (!state) { |
| 485 | SDE_ERROR("invalid parameters\n"); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | rp = &to_sde_crtc_state(state)->rp; |
| 490 | _sde_crtc_rp_put(rp, type, tag); |
| 491 | } |
| 492 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 493 | static void _sde_crtc_deinit_events(struct sde_crtc *sde_crtc) |
| 494 | { |
| 495 | if (!sde_crtc) |
| 496 | return; |
| 497 | |
| 498 | if (sde_crtc->event_thread) { |
| 499 | kthread_flush_worker(&sde_crtc->event_worker); |
| 500 | kthread_stop(sde_crtc->event_thread); |
| 501 | sde_crtc->event_thread = NULL; |
| 502 | } |
| 503 | } |
| 504 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 505 | static void sde_crtc_destroy(struct drm_crtc *crtc) |
| 506 | { |
| 507 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 508 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 509 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 510 | |
| 511 | if (!crtc) |
| 512 | return; |
| 513 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 514 | if (sde_crtc->blob_info) |
| 515 | drm_property_unreference_blob(sde_crtc->blob_info); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 516 | msm_property_destroy(&sde_crtc->property_info); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 517 | sde_cp_crtc_destroy_properties(crtc); |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 518 | |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 519 | sde_fence_deinit(&sde_crtc->output_fence); |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 520 | _sde_crtc_deinit_events(sde_crtc); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 521 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 522 | drm_crtc_cleanup(crtc); |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 523 | mutex_destroy(&sde_crtc->crtc_lock); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 524 | kfree(sde_crtc); |
| 525 | } |
| 526 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 527 | static bool sde_crtc_mode_fixup(struct drm_crtc *crtc, |
| 528 | const struct drm_display_mode *mode, |
| 529 | struct drm_display_mode *adjusted_mode) |
| 530 | { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 531 | SDE_DEBUG("\n"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 532 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 533 | if (msm_is_mode_seamless(adjusted_mode) && |
| 534 | (!crtc->enabled || crtc->state->active_changed)) { |
| 535 | SDE_ERROR("crtc state prevents seamless transition\n"); |
| 536 | return false; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 539 | return true; |
| 540 | } |
| 541 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 542 | static void _sde_crtc_setup_blend_cfg(struct sde_crtc_mixer *mixer, |
| 543 | struct sde_plane_state *pstate, struct sde_format *format) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 544 | { |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 545 | uint32_t blend_op, fg_alpha, bg_alpha; |
| 546 | uint32_t blend_type; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 547 | struct sde_hw_mixer *lm = mixer->hw_lm; |
| 548 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 549 | /* default to opaque blending */ |
| 550 | fg_alpha = sde_plane_get_property(pstate, PLANE_PROP_ALPHA); |
| 551 | bg_alpha = 0xFF - fg_alpha; |
| 552 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | SDE_BLEND_BG_ALPHA_BG_CONST; |
| 553 | blend_type = sde_plane_get_property(pstate, PLANE_PROP_BLEND_OP); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 554 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 555 | SDE_DEBUG("blend type:0x%x blend alpha:0x%x\n", blend_type, fg_alpha); |
| 556 | |
| 557 | switch (blend_type) { |
| 558 | |
| 559 | case SDE_DRM_BLEND_OP_OPAQUE: |
| 560 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | |
| 561 | SDE_BLEND_BG_ALPHA_BG_CONST; |
| 562 | break; |
| 563 | |
| 564 | case SDE_DRM_BLEND_OP_PREMULTIPLIED: |
| 565 | if (format->alpha_enable) { |
| 566 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | |
| 567 | SDE_BLEND_BG_ALPHA_FG_PIXEL; |
| 568 | if (fg_alpha != 0xff) { |
| 569 | bg_alpha = fg_alpha; |
| 570 | blend_op |= SDE_BLEND_BG_MOD_ALPHA | |
| 571 | SDE_BLEND_BG_INV_MOD_ALPHA; |
| 572 | } else { |
| 573 | blend_op |= SDE_BLEND_BG_INV_ALPHA; |
| 574 | } |
| 575 | } |
| 576 | break; |
| 577 | |
| 578 | case SDE_DRM_BLEND_OP_COVERAGE: |
| 579 | if (format->alpha_enable) { |
| 580 | blend_op = SDE_BLEND_FG_ALPHA_FG_PIXEL | |
| 581 | SDE_BLEND_BG_ALPHA_FG_PIXEL; |
| 582 | if (fg_alpha != 0xff) { |
| 583 | bg_alpha = fg_alpha; |
| 584 | blend_op |= SDE_BLEND_FG_MOD_ALPHA | |
| 585 | SDE_BLEND_FG_INV_MOD_ALPHA | |
| 586 | SDE_BLEND_BG_MOD_ALPHA | |
| 587 | SDE_BLEND_BG_INV_MOD_ALPHA; |
| 588 | } else { |
| 589 | blend_op |= SDE_BLEND_BG_INV_ALPHA; |
| 590 | } |
| 591 | } |
| 592 | break; |
| 593 | default: |
| 594 | /* do nothing */ |
| 595 | break; |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 596 | } |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 597 | |
| 598 | lm->ops.setup_blend_config(lm, pstate->stage, fg_alpha, |
| 599 | bg_alpha, blend_op); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 600 | SDE_DEBUG( |
| 601 | "format: %4.4s, alpha_enable %u fg alpha:0x%x bg alpha:0x%x blend_op:0x%x\n", |
| 602 | (char *) &format->base.pixel_format, |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 603 | format->alpha_enable, fg_alpha, bg_alpha, blend_op); |
| 604 | } |
| 605 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 606 | static void _sde_crtc_setup_dim_layer_cfg(struct drm_crtc *crtc, |
| 607 | struct sde_crtc *sde_crtc, struct sde_crtc_mixer *mixer, |
| 608 | struct sde_hw_dim_layer *dim_layer) |
| 609 | { |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 610 | struct sde_crtc_state *cstate; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 611 | struct sde_hw_mixer *lm; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 612 | struct sde_hw_dim_layer split_dim_layer; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 613 | int i; |
| 614 | |
| 615 | if (!dim_layer->rect.w || !dim_layer->rect.h) { |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 616 | SDE_DEBUG("empty dim_layer\n"); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 617 | return; |
| 618 | } |
| 619 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 620 | cstate = to_sde_crtc_state(crtc->state); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 621 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 622 | SDE_DEBUG("dim_layer - flags:%d, stage:%d\n", |
| 623 | dim_layer->flags, dim_layer->stage); |
| 624 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 625 | split_dim_layer.stage = dim_layer->stage; |
| 626 | split_dim_layer.color_fill = dim_layer->color_fill; |
| 627 | |
| 628 | /* |
| 629 | * traverse through the layer mixers attached to crtc and find the |
| 630 | * intersecting dim layer rect in each LM and program accordingly. |
| 631 | */ |
| 632 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 633 | split_dim_layer.flags = dim_layer->flags; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 634 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 635 | sde_kms_rect_intersect(&cstate->lm_bounds[i], &dim_layer->rect, |
Lloyd Atkinson | e0e11e2 | 2017-01-17 12:08:48 -0500 | [diff] [blame] | 636 | &split_dim_layer.rect); |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 637 | if (sde_kms_rect_is_null(&split_dim_layer.rect)) { |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 638 | /* |
| 639 | * no extra programming required for non-intersecting |
| 640 | * layer mixers with INCLUSIVE dim layer |
| 641 | */ |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 642 | if (split_dim_layer.flags & SDE_DRM_DIM_LAYER_INCLUSIVE) |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 643 | continue; |
| 644 | |
| 645 | /* |
| 646 | * program the other non-intersecting layer mixers with |
| 647 | * INCLUSIVE dim layer of full size for uniformity |
| 648 | * with EXCLUSIVE dim layer config. |
| 649 | */ |
| 650 | split_dim_layer.flags &= ~SDE_DRM_DIM_LAYER_EXCLUSIVE; |
| 651 | split_dim_layer.flags |= SDE_DRM_DIM_LAYER_INCLUSIVE; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 652 | memcpy(&split_dim_layer.rect, &cstate->lm_bounds[i], |
| 653 | sizeof(split_dim_layer.rect)); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 654 | |
| 655 | } else { |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 656 | split_dim_layer.rect.x = |
| 657 | split_dim_layer.rect.x - |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 658 | cstate->lm_bounds[i].x; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 661 | SDE_DEBUG("split_dim_layer - LM:%d, rect:{%d,%d,%d,%d}}\n", |
| 662 | i, split_dim_layer.rect.x, split_dim_layer.rect.y, |
| 663 | split_dim_layer.rect.w, split_dim_layer.rect.h); |
| 664 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 665 | lm = mixer[i].hw_lm; |
| 666 | mixer[i].mixer_op_mode |= 1 << split_dim_layer.stage; |
| 667 | lm->ops.setup_dim_layer(lm, &split_dim_layer); |
| 668 | } |
| 669 | } |
| 670 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 671 | void sde_crtc_get_crtc_roi(struct drm_crtc_state *state, |
| 672 | const struct sde_rect **crtc_roi) |
| 673 | { |
| 674 | struct sde_crtc_state *crtc_state; |
| 675 | |
| 676 | if (!state || !crtc_roi) |
| 677 | return; |
| 678 | |
| 679 | crtc_state = to_sde_crtc_state(state); |
| 680 | *crtc_roi = &crtc_state->crtc_roi; |
| 681 | } |
| 682 | |
| 683 | static int _sde_crtc_set_roi_v1(struct drm_crtc_state *state, |
| 684 | void *usr_ptr) |
| 685 | { |
| 686 | struct drm_crtc *crtc; |
| 687 | struct sde_crtc_state *cstate; |
| 688 | struct sde_drm_roi_v1 roi_v1; |
| 689 | int i; |
| 690 | |
| 691 | if (!state) { |
| 692 | SDE_ERROR("invalid args\n"); |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | |
| 696 | cstate = to_sde_crtc_state(state); |
| 697 | crtc = cstate->base.crtc; |
| 698 | |
| 699 | memset(&cstate->user_roi_list, 0, sizeof(cstate->user_roi_list)); |
| 700 | |
| 701 | if (!usr_ptr) { |
| 702 | SDE_DEBUG("crtc%d: rois cleared\n", DRMID(crtc)); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | if (copy_from_user(&roi_v1, usr_ptr, sizeof(roi_v1))) { |
| 707 | SDE_ERROR("crtc%d: failed to copy roi_v1 data\n", DRMID(crtc)); |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | SDE_DEBUG("crtc%d: num_rects %d\n", DRMID(crtc), roi_v1.num_rects); |
| 712 | |
| 713 | if (roi_v1.num_rects == 0) { |
| 714 | SDE_DEBUG("crtc%d: rois cleared\n", DRMID(crtc)); |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | if (roi_v1.num_rects > SDE_MAX_ROI_V1) { |
| 719 | SDE_ERROR("crtc%d: too many rects specified: %d\n", DRMID(crtc), |
| 720 | roi_v1.num_rects); |
| 721 | return -EINVAL; |
| 722 | } |
| 723 | |
| 724 | cstate->user_roi_list.num_rects = roi_v1.num_rects; |
| 725 | for (i = 0; i < roi_v1.num_rects; ++i) { |
| 726 | cstate->user_roi_list.roi[i] = roi_v1.roi[i]; |
| 727 | SDE_DEBUG("crtc%d: roi%d: roi (%d,%d) (%d,%d)\n", |
| 728 | DRMID(crtc), i, |
| 729 | cstate->user_roi_list.roi[i].x1, |
| 730 | cstate->user_roi_list.roi[i].y1, |
| 731 | cstate->user_roi_list.roi[i].x2, |
| 732 | cstate->user_roi_list.roi[i].y2); |
| 733 | } |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int _sde_crtc_set_crtc_roi(struct drm_crtc *crtc, |
| 739 | struct drm_crtc_state *state) |
| 740 | { |
| 741 | struct drm_connector *conn; |
| 742 | struct drm_connector_state *conn_state; |
| 743 | struct sde_crtc *sde_crtc; |
| 744 | struct sde_crtc_state *crtc_state; |
| 745 | struct sde_rect *crtc_roi; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 746 | int i, num_attached_conns = 0; |
| 747 | |
| 748 | if (!crtc || !state) |
| 749 | return -EINVAL; |
| 750 | |
| 751 | sde_crtc = to_sde_crtc(crtc); |
| 752 | crtc_state = to_sde_crtc_state(state); |
| 753 | crtc_roi = &crtc_state->crtc_roi; |
| 754 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 755 | for_each_connector_in_state(state->state, conn, conn_state, i) { |
| 756 | struct sde_connector_state *sde_conn_state; |
| 757 | |
| 758 | if (!conn_state || conn_state->crtc != crtc) |
| 759 | continue; |
| 760 | |
| 761 | if (num_attached_conns) { |
| 762 | SDE_ERROR( |
| 763 | "crtc%d: unsupported: roi on crtc w/ >1 connectors\n", |
| 764 | DRMID(crtc)); |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | ++num_attached_conns; |
| 768 | |
| 769 | sde_conn_state = to_sde_connector_state(conn_state); |
| 770 | |
| 771 | if (memcmp(&sde_conn_state->rois, &crtc_state->user_roi_list, |
| 772 | sizeof(crtc_state->user_roi_list))) { |
| 773 | SDE_ERROR("%s: crtc -> conn roi scaling unsupported\n", |
| 774 | sde_crtc->name); |
| 775 | return -EINVAL; |
| 776 | } |
| 777 | } |
| 778 | |
Lloyd Atkinson | c2baf41 | 2017-04-19 17:53:09 -0400 | [diff] [blame] | 779 | sde_kms_rect_merge_rectangles(&crtc_state->user_roi_list, crtc_roi); |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 780 | |
| 781 | SDE_DEBUG("%s: crtc roi (%d,%d,%d,%d)\n", sde_crtc->name, |
| 782 | crtc_roi->x, crtc_roi->y, crtc_roi->w, crtc_roi->h); |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
Lloyd Atkinson | 7738220 | 2017-02-01 14:59:43 -0500 | [diff] [blame] | 787 | static int _sde_crtc_check_autorefresh(struct drm_crtc *crtc, |
| 788 | struct drm_crtc_state *state) |
| 789 | { |
| 790 | struct sde_crtc *sde_crtc; |
| 791 | struct sde_crtc_state *crtc_state; |
| 792 | struct drm_connector *conn; |
| 793 | struct drm_connector_state *conn_state; |
| 794 | int i; |
| 795 | |
| 796 | if (!crtc || !state) |
| 797 | return -EINVAL; |
| 798 | |
| 799 | sde_crtc = to_sde_crtc(crtc); |
| 800 | crtc_state = to_sde_crtc_state(state); |
| 801 | |
| 802 | if (sde_kms_rect_is_null(&crtc_state->crtc_roi)) |
| 803 | return 0; |
| 804 | |
| 805 | /* partial update active, check if autorefresh is also requested */ |
| 806 | for_each_connector_in_state(state->state, conn, conn_state, i) { |
| 807 | uint64_t autorefresh; |
| 808 | |
| 809 | if (!conn_state || conn_state->crtc != crtc) |
| 810 | continue; |
| 811 | |
| 812 | autorefresh = sde_connector_get_property(conn_state, |
| 813 | CONNECTOR_PROP_AUTOREFRESH); |
| 814 | if (autorefresh) { |
| 815 | SDE_ERROR( |
| 816 | "%s: autorefresh & partial crtc roi incompatible %llu\n", |
| 817 | sde_crtc->name, autorefresh); |
| 818 | return -EINVAL; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 825 | static int _sde_crtc_set_lm_roi(struct drm_crtc *crtc, |
| 826 | struct drm_crtc_state *state, int lm_idx) |
| 827 | { |
| 828 | struct sde_crtc *sde_crtc; |
| 829 | struct sde_crtc_state *crtc_state; |
| 830 | const struct sde_rect *crtc_roi; |
| 831 | const struct sde_rect *lm_bounds; |
| 832 | struct sde_rect *lm_roi; |
| 833 | |
| 834 | if (!crtc || !state || lm_idx >= ARRAY_SIZE(crtc_state->lm_bounds)) |
| 835 | return -EINVAL; |
| 836 | |
| 837 | sde_crtc = to_sde_crtc(crtc); |
| 838 | crtc_state = to_sde_crtc_state(state); |
| 839 | crtc_roi = &crtc_state->crtc_roi; |
| 840 | lm_bounds = &crtc_state->lm_bounds[lm_idx]; |
| 841 | lm_roi = &crtc_state->lm_roi[lm_idx]; |
| 842 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 843 | if (sde_kms_rect_is_null(crtc_roi)) |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 844 | memcpy(lm_roi, lm_bounds, sizeof(*lm_roi)); |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 845 | else |
| 846 | sde_kms_rect_intersect(crtc_roi, lm_bounds, lm_roi); |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 847 | |
| 848 | SDE_DEBUG("%s: lm%d roi (%d,%d,%d,%d)\n", sde_crtc->name, lm_idx, |
| 849 | lm_roi->x, lm_roi->y, lm_roi->w, lm_roi->h); |
| 850 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 851 | /* if any dimension is zero, clear all dimensions for clarity */ |
| 852 | if (sde_kms_rect_is_null(lm_roi)) |
| 853 | memset(lm_roi, 0, sizeof(*lm_roi)); |
| 854 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 855 | return 0; |
| 856 | } |
| 857 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 858 | static u32 _sde_crtc_get_displays_affected(struct drm_crtc *crtc, |
| 859 | struct drm_crtc_state *state) |
| 860 | { |
| 861 | struct sde_crtc *sde_crtc; |
| 862 | struct sde_crtc_state *crtc_state; |
| 863 | u32 disp_bitmask = 0; |
| 864 | int i; |
| 865 | |
| 866 | sde_crtc = to_sde_crtc(crtc); |
| 867 | crtc_state = to_sde_crtc_state(state); |
| 868 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 869 | /* pingpong split: one ROI, one LM, two physical displays */ |
| 870 | if (crtc_state->is_ppsplit) { |
| 871 | u32 lm_split_width = crtc_state->lm_bounds[0].w / 2; |
| 872 | struct sde_rect *roi = &crtc_state->lm_roi[0]; |
| 873 | |
| 874 | if (sde_kms_rect_is_null(roi)) |
| 875 | disp_bitmask = 0; |
| 876 | else if ((u32)roi->x + (u32)roi->w <= lm_split_width) |
| 877 | disp_bitmask = BIT(0); /* left only */ |
| 878 | else if (roi->x >= lm_split_width) |
| 879 | disp_bitmask = BIT(1); /* right only */ |
| 880 | else |
| 881 | disp_bitmask = BIT(0) | BIT(1); /* left and right */ |
| 882 | } else { |
| 883 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 884 | if (!sde_kms_rect_is_null(&crtc_state->lm_roi[i])) |
| 885 | disp_bitmask |= BIT(i); |
| 886 | } |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | SDE_DEBUG("affected displays 0x%x\n", disp_bitmask); |
| 890 | |
| 891 | return disp_bitmask; |
| 892 | } |
| 893 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 894 | static int _sde_crtc_check_rois_centered_and_symmetric(struct drm_crtc *crtc, |
| 895 | struct drm_crtc_state *state) |
| 896 | { |
| 897 | struct sde_crtc *sde_crtc; |
| 898 | struct sde_crtc_state *crtc_state; |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 899 | const struct sde_rect *roi[CRTC_DUAL_MIXERS]; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 900 | |
| 901 | if (!crtc || !state) |
| 902 | return -EINVAL; |
| 903 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 904 | sde_crtc = to_sde_crtc(crtc); |
| 905 | crtc_state = to_sde_crtc_state(state); |
| 906 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 907 | if (sde_crtc->num_mixers > CRTC_DUAL_MIXERS) { |
| 908 | SDE_ERROR("%s: unsupported number of mixers: %d\n", |
| 909 | sde_crtc->name, sde_crtc->num_mixers); |
| 910 | return -EINVAL; |
| 911 | } |
| 912 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 913 | /* |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 914 | * If using pingpong split: one ROI, one LM, two physical displays |
| 915 | * then the ROI must be centered on the panel split boundary and |
| 916 | * be of equal width across the split. |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 917 | */ |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 918 | if (crtc_state->is_ppsplit) { |
| 919 | u16 panel_split_width; |
| 920 | u32 display_mask; |
| 921 | |
| 922 | roi[0] = &crtc_state->lm_roi[0]; |
| 923 | |
| 924 | if (sde_kms_rect_is_null(roi[0])) |
| 925 | return 0; |
| 926 | |
| 927 | display_mask = _sde_crtc_get_displays_affected(crtc, state); |
| 928 | if (display_mask != (BIT(0) | BIT(1))) |
| 929 | return 0; |
| 930 | |
| 931 | panel_split_width = crtc_state->lm_bounds[0].w / 2; |
| 932 | if (roi[0]->x + roi[0]->w / 2 != panel_split_width) { |
| 933 | SDE_ERROR("%s: roi x %d w %d split %d\n", |
| 934 | sde_crtc->name, roi[0]->x, roi[0]->w, |
| 935 | panel_split_width); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * On certain HW, if using 2 LM, ROIs must be split evenly between the |
| 944 | * LMs and be of equal width. |
| 945 | */ |
| 946 | if (sde_crtc->num_mixers == 1) |
| 947 | return 0; |
| 948 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 949 | roi[0] = &crtc_state->lm_roi[0]; |
| 950 | roi[1] = &crtc_state->lm_roi[1]; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 951 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 952 | /* if one of the roi is null it's a left/right-only update */ |
| 953 | if (sde_kms_rect_is_null(roi[0]) || sde_kms_rect_is_null(roi[1])) |
| 954 | return 0; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 955 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 956 | /* check lm rois are equal width & first roi ends at 2nd roi */ |
| 957 | if (roi[0]->x + roi[0]->w != roi[1]->x || roi[0]->w != roi[1]->w) { |
| 958 | SDE_ERROR( |
| 959 | "%s: rois not centered and symmetric: roi0 x %d w %d roi1 x %d w %d\n", |
| 960 | sde_crtc->name, roi[0]->x, roi[0]->w, |
| 961 | roi[1]->x, roi[1]->w); |
| 962 | return -EINVAL; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | static int _sde_crtc_check_planes_within_crtc_roi(struct drm_crtc *crtc, |
| 969 | struct drm_crtc_state *state) |
| 970 | { |
| 971 | struct sde_crtc *sde_crtc; |
| 972 | struct sde_crtc_state *crtc_state; |
| 973 | const struct sde_rect *crtc_roi; |
| 974 | struct drm_plane_state *pstate; |
| 975 | struct drm_plane *plane; |
| 976 | |
| 977 | if (!crtc || !state) |
| 978 | return -EINVAL; |
| 979 | |
| 980 | /* |
| 981 | * Reject commit if a Plane CRTC destination coordinates fall outside |
| 982 | * the partial CRTC ROI. LM output is determined via connector ROIs, |
| 983 | * if they are specified, not Plane CRTC ROIs. |
| 984 | */ |
| 985 | |
| 986 | sde_crtc = to_sde_crtc(crtc); |
| 987 | crtc_state = to_sde_crtc_state(state); |
| 988 | crtc_roi = &crtc_state->crtc_roi; |
| 989 | |
| 990 | if (sde_kms_rect_is_null(crtc_roi)) |
| 991 | return 0; |
| 992 | |
| 993 | drm_atomic_crtc_state_for_each_plane(plane, state) { |
| 994 | struct sde_rect plane_roi, intersection; |
| 995 | |
| 996 | pstate = drm_atomic_get_plane_state(state->state, plane); |
| 997 | if (IS_ERR_OR_NULL(pstate)) { |
| 998 | int rc = PTR_ERR(pstate); |
| 999 | |
| 1000 | SDE_ERROR("%s: failed to get plane%d state, %d\n", |
| 1001 | sde_crtc->name, plane->base.id, rc); |
| 1002 | return rc; |
| 1003 | } |
| 1004 | |
| 1005 | plane_roi.x = pstate->crtc_x; |
| 1006 | plane_roi.y = pstate->crtc_y; |
| 1007 | plane_roi.w = pstate->crtc_w; |
| 1008 | plane_roi.h = pstate->crtc_h; |
| 1009 | sde_kms_rect_intersect(crtc_roi, &plane_roi, &intersection); |
| 1010 | if (!sde_kms_rect_is_equal(&plane_roi, &intersection)) { |
| 1011 | SDE_ERROR( |
| 1012 | "%s: plane%d crtc roi (%d,%d,%d,%d) outside crtc roi (%d,%d,%d,%d)\n", |
| 1013 | sde_crtc->name, plane->base.id, |
| 1014 | plane_roi.x, plane_roi.y, |
| 1015 | plane_roi.w, plane_roi.h, |
| 1016 | crtc_roi->x, crtc_roi->y, |
| 1017 | crtc_roi->w, crtc_roi->h); |
| 1018 | return -E2BIG; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int _sde_crtc_check_rois(struct drm_crtc *crtc, |
| 1026 | struct drm_crtc_state *state) |
| 1027 | { |
| 1028 | struct sde_crtc *sde_crtc; |
| 1029 | int lm_idx; |
| 1030 | int rc; |
| 1031 | |
| 1032 | if (!crtc || !state) |
| 1033 | return -EINVAL; |
| 1034 | |
| 1035 | sde_crtc = to_sde_crtc(crtc); |
| 1036 | |
| 1037 | rc = _sde_crtc_set_crtc_roi(crtc, state); |
| 1038 | if (rc) |
| 1039 | return rc; |
| 1040 | |
Lloyd Atkinson | 7738220 | 2017-02-01 14:59:43 -0500 | [diff] [blame] | 1041 | rc = _sde_crtc_check_autorefresh(crtc, state); |
| 1042 | if (rc) |
| 1043 | return rc; |
| 1044 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1045 | for (lm_idx = 0; lm_idx < sde_crtc->num_mixers; lm_idx++) { |
| 1046 | rc = _sde_crtc_set_lm_roi(crtc, state, lm_idx); |
| 1047 | if (rc) |
| 1048 | return rc; |
| 1049 | } |
| 1050 | |
| 1051 | rc = _sde_crtc_check_rois_centered_and_symmetric(crtc, state); |
| 1052 | if (rc) |
| 1053 | return rc; |
| 1054 | |
| 1055 | rc = _sde_crtc_check_planes_within_crtc_roi(crtc, state); |
| 1056 | if (rc) |
| 1057 | return rc; |
| 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1062 | static void _sde_crtc_program_lm_output_roi(struct drm_crtc *crtc) |
| 1063 | { |
| 1064 | struct sde_crtc *sde_crtc; |
| 1065 | struct sde_crtc_state *crtc_state; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1066 | const struct sde_rect *lm_roi; |
| 1067 | struct sde_hw_mixer *hw_lm; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1068 | int lm_idx, lm_horiz_position; |
| 1069 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1070 | if (!crtc) |
| 1071 | return; |
| 1072 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1073 | sde_crtc = to_sde_crtc(crtc); |
| 1074 | crtc_state = to_sde_crtc_state(crtc->state); |
| 1075 | |
| 1076 | lm_horiz_position = 0; |
| 1077 | for (lm_idx = 0; lm_idx < sde_crtc->num_mixers; lm_idx++) { |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1078 | struct sde_hw_mixer_cfg cfg; |
| 1079 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1080 | lm_roi = &crtc_state->lm_roi[lm_idx]; |
| 1081 | hw_lm = sde_crtc->mixers[lm_idx].hw_lm; |
| 1082 | |
| 1083 | SDE_EVT32(DRMID(crtc_state->base.crtc), lm_idx, |
| 1084 | lm_roi->x, lm_roi->y, lm_roi->w, lm_roi->h); |
| 1085 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1086 | if (sde_kms_rect_is_null(lm_roi)) |
| 1087 | continue; |
| 1088 | |
Ping Li | f41c2ef | 2017-05-04 14:40:45 -0700 | [diff] [blame] | 1089 | hw_lm->cfg.out_width = lm_roi->w; |
| 1090 | hw_lm->cfg.out_height = lm_roi->h; |
| 1091 | hw_lm->cfg.right_mixer = lm_horiz_position; |
| 1092 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1093 | cfg.out_width = lm_roi->w; |
| 1094 | cfg.out_height = lm_roi->h; |
| 1095 | cfg.right_mixer = lm_horiz_position++; |
| 1096 | cfg.flags = 0; |
| 1097 | hw_lm->ops.setup_mixer_out(hw_lm, &cfg); |
| 1098 | } |
| 1099 | } |
| 1100 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1101 | static void _sde_crtc_blend_setup_mixer(struct drm_crtc *crtc, |
| 1102 | struct sde_crtc *sde_crtc, struct sde_crtc_mixer *mixer) |
| 1103 | { |
| 1104 | struct drm_plane *plane; |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1105 | struct drm_framebuffer *fb; |
| 1106 | struct drm_plane_state *state; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1107 | struct sde_crtc_state *cstate; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1108 | struct sde_plane_state *pstate = NULL; |
| 1109 | struct sde_format *format; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1110 | struct sde_hw_ctl *ctl; |
| 1111 | struct sde_hw_mixer *lm; |
| 1112 | struct sde_hw_stage_cfg *stage_cfg; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1113 | struct sde_rect plane_crtc_roi; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1114 | |
Clarence Ip | 7e5f000 | 2017-05-29 18:46:56 -0400 | [diff] [blame] | 1115 | u32 flush_mask, flush_sbuf, flush_tmp; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1116 | uint32_t lm_idx = LEFT_MIXER, stage_idx; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1117 | bool bg_alpha_enable[CRTC_DUAL_MIXERS] = {false}; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1118 | int zpos_cnt[CRTC_DUAL_MIXERS][SDE_STAGE_MAX + 1] = { {0} }; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1119 | int i; |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 1120 | u32 prefill = 0; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1121 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1122 | if (!sde_crtc || !mixer) { |
| 1123 | SDE_ERROR("invalid sde_crtc or mixer\n"); |
| 1124 | return; |
| 1125 | } |
| 1126 | |
| 1127 | ctl = mixer->hw_ctl; |
| 1128 | lm = mixer->hw_lm; |
| 1129 | stage_cfg = &sde_crtc->stage_cfg; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1130 | cstate = to_sde_crtc_state(crtc->state); |
Clarence Ip | 7e5f000 | 2017-05-29 18:46:56 -0400 | [diff] [blame] | 1131 | flush_sbuf = 0x0; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1132 | |
Clarence Ip | 7eb9045 | 2017-05-23 11:41:19 -0400 | [diff] [blame] | 1133 | cstate->sbuf_cfg.rot_op_mode = SDE_CTL_ROT_OP_MODE_OFFLINE; |
| 1134 | cstate->sbuf_prefill_line = 0; |
| 1135 | |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1136 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1137 | state = plane->state; |
| 1138 | if (!state) |
| 1139 | continue; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1140 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1141 | plane_crtc_roi.x = state->crtc_x; |
| 1142 | plane_crtc_roi.y = state->crtc_y; |
| 1143 | plane_crtc_roi.w = state->crtc_w; |
| 1144 | plane_crtc_roi.h = state->crtc_h; |
| 1145 | |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1146 | pstate = to_sde_plane_state(state); |
| 1147 | fb = state->fb; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1148 | |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 1149 | if (sde_plane_is_sbuf_mode(plane, &prefill)) |
Clarence Ip | 7eb9045 | 2017-05-23 11:41:19 -0400 | [diff] [blame] | 1150 | cstate->sbuf_cfg.rot_op_mode = |
| 1151 | SDE_CTL_ROT_OP_MODE_INLINE_SYNC; |
| 1152 | if (prefill > cstate->sbuf_prefill_line) |
| 1153 | cstate->sbuf_prefill_line = prefill; |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 1154 | |
Clarence Ip | 7e5f000 | 2017-05-29 18:46:56 -0400 | [diff] [blame] | 1155 | sde_plane_get_ctl_flush(plane, ctl, &flush_mask, &flush_tmp); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1156 | |
Clarence Ip | 7e5f000 | 2017-05-29 18:46:56 -0400 | [diff] [blame] | 1157 | /* persist rotator flush bit(s) for one more commit */ |
| 1158 | flush_mask |= cstate->sbuf_flush_mask | flush_tmp; |
| 1159 | flush_sbuf |= flush_tmp; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1160 | |
| 1161 | SDE_DEBUG("crtc %d stage:%d - plane %d sspp %d fb %d\n", |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 1162 | crtc->base.id, |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 1163 | pstate->stage, |
| 1164 | plane->base.id, |
| 1165 | sde_plane_pipe(plane) - SSPP_VIG0, |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1166 | state->fb ? state->fb->base.id : -1); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1167 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1168 | format = to_sde_format(msm_framebuffer_format(pstate->base.fb)); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1169 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1170 | SDE_EVT32(DRMID(crtc), DRMID(plane), |
| 1171 | state->fb ? state->fb->base.id : -1, |
| 1172 | state->src_x >> 16, state->src_y >> 16, |
| 1173 | state->src_w >> 16, state->src_h >> 16, |
| 1174 | state->crtc_x, state->crtc_y, |
Clarence Ip | 7eb9045 | 2017-05-23 11:41:19 -0400 | [diff] [blame] | 1175 | state->crtc_w, state->crtc_h, |
| 1176 | cstate->sbuf_cfg.rot_op_mode); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1177 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1178 | for (lm_idx = 0; lm_idx < sde_crtc->num_mixers; lm_idx++) { |
| 1179 | struct sde_rect intersect; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1180 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1181 | /* skip if the roi doesn't fall within LM's bounds */ |
| 1182 | sde_kms_rect_intersect(&plane_crtc_roi, |
| 1183 | &cstate->lm_bounds[lm_idx], |
| 1184 | &intersect); |
| 1185 | if (sde_kms_rect_is_null(&intersect)) |
| 1186 | continue; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1187 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1188 | stage_idx = zpos_cnt[lm_idx][pstate->stage]++; |
| 1189 | stage_cfg->stage[lm_idx][pstate->stage][stage_idx] = |
| 1190 | sde_plane_pipe(plane); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1191 | stage_cfg->multirect_index |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1192 | [lm_idx][pstate->stage][stage_idx] = |
| 1193 | pstate->multirect_index; |
| 1194 | |
| 1195 | mixer[lm_idx].flush_mask |= flush_mask; |
| 1196 | |
| 1197 | |
| 1198 | SDE_EVT32(DRMID(plane), DRMID(crtc), lm_idx, stage_idx, |
| 1199 | pstate->stage, pstate->multirect_index, |
| 1200 | pstate->multirect_mode, |
| 1201 | format->base.pixel_format, |
| 1202 | fb ? fb->modifier[0] : 0); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1203 | |
| 1204 | /* blend config update */ |
| 1205 | if (pstate->stage != SDE_STAGE_BASE) { |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1206 | _sde_crtc_setup_blend_cfg(mixer + lm_idx, |
| 1207 | pstate, format); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1208 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1209 | if (bg_alpha_enable[lm_idx] && |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1210 | !format->alpha_enable) |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1211 | mixer[lm_idx].mixer_op_mode = 0; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1212 | else |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1213 | mixer[lm_idx].mixer_op_mode |= |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1214 | 1 << pstate->stage; |
| 1215 | } else if (format->alpha_enable) { |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1216 | bg_alpha_enable[lm_idx] = true; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1219 | } |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1220 | |
Clarence Ip | 7e5f000 | 2017-05-29 18:46:56 -0400 | [diff] [blame] | 1221 | cstate->sbuf_flush_mask = flush_sbuf; |
| 1222 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1223 | if (lm && lm->ops.setup_dim_layer) { |
| 1224 | cstate = to_sde_crtc_state(crtc->state); |
| 1225 | for (i = 0; i < cstate->num_dim_layers; i++) |
| 1226 | _sde_crtc_setup_dim_layer_cfg(crtc, sde_crtc, |
| 1227 | mixer, &cstate->dim_layer[i]); |
| 1228 | } |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 1229 | |
Clarence Ip | 7eb9045 | 2017-05-23 11:41:19 -0400 | [diff] [blame] | 1230 | if (ctl->ops.setup_sbuf_cfg) |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 1231 | ctl->ops.setup_sbuf_cfg(ctl, &cstate->sbuf_cfg); |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1232 | |
| 1233 | _sde_crtc_program_lm_output_roi(crtc); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1236 | static void _sde_crtc_swap_mixers_for_right_partial_update( |
| 1237 | struct drm_crtc *crtc) |
| 1238 | { |
| 1239 | struct sde_crtc *sde_crtc; |
| 1240 | struct sde_crtc_state *cstate; |
| 1241 | struct drm_encoder *drm_enc; |
| 1242 | bool is_right_only; |
| 1243 | bool encoder_in_dsc_merge = false; |
| 1244 | |
| 1245 | if (!crtc || !crtc->state) |
| 1246 | return; |
| 1247 | |
| 1248 | sde_crtc = to_sde_crtc(crtc); |
| 1249 | cstate = to_sde_crtc_state(crtc->state); |
| 1250 | |
| 1251 | if (sde_crtc->num_mixers != CRTC_DUAL_MIXERS) |
| 1252 | return; |
| 1253 | |
| 1254 | drm_for_each_encoder(drm_enc, crtc->dev) { |
| 1255 | if (drm_enc->crtc == crtc && |
| 1256 | sde_encoder_is_dsc_merge(drm_enc)) { |
| 1257 | encoder_in_dsc_merge = true; |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * For right-only partial update with DSC merge, we swap LM0 & LM1. |
| 1264 | * This is due to two reasons: |
| 1265 | * - On 8996, there is a DSC HW requirement that in DSC Merge Mode, |
| 1266 | * the left DSC must be used, right DSC cannot be used alone. |
| 1267 | * For right-only partial update, this means swap layer mixers to map |
| 1268 | * Left LM to Right INTF. On later HW this was relaxed. |
| 1269 | * - In DSC Merge mode, the physical encoder has already registered |
| 1270 | * PP0 as the master, to switch to right-only we would have to |
| 1271 | * reprogram to be driven by PP1 instead. |
| 1272 | * To support both cases, we prefer to support the mixer swap solution. |
| 1273 | */ |
| 1274 | if (!encoder_in_dsc_merge) |
| 1275 | return; |
| 1276 | |
| 1277 | is_right_only = sde_kms_rect_is_null(&cstate->lm_roi[0]) && |
| 1278 | !sde_kms_rect_is_null(&cstate->lm_roi[1]); |
| 1279 | |
| 1280 | if (is_right_only && !sde_crtc->mixers_swapped) { |
| 1281 | /* right-only update swap mixers */ |
| 1282 | swap(sde_crtc->mixers[0], sde_crtc->mixers[1]); |
| 1283 | sde_crtc->mixers_swapped = true; |
| 1284 | } else if (!is_right_only && sde_crtc->mixers_swapped) { |
| 1285 | /* left-only or full update, swap back */ |
| 1286 | swap(sde_crtc->mixers[0], sde_crtc->mixers[1]); |
| 1287 | sde_crtc->mixers_swapped = false; |
| 1288 | } |
| 1289 | |
| 1290 | SDE_DEBUG("%s: right_only %d swapped %d, mix0->lm%d, mix1->lm%d\n", |
| 1291 | sde_crtc->name, is_right_only, sde_crtc->mixers_swapped, |
| 1292 | sde_crtc->mixers[0].hw_lm->idx - LM_0, |
| 1293 | sde_crtc->mixers[1].hw_lm->idx - LM_0); |
| 1294 | SDE_EVT32(DRMID(crtc), is_right_only, sde_crtc->mixers_swapped, |
| 1295 | sde_crtc->mixers[0].hw_lm->idx - LM_0, |
| 1296 | sde_crtc->mixers[1].hw_lm->idx - LM_0); |
| 1297 | } |
| 1298 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 1299 | /** |
| 1300 | * _sde_crtc_blend_setup - configure crtc mixers |
| 1301 | * @crtc: Pointer to drm crtc structure |
| 1302 | */ |
| 1303 | static void _sde_crtc_blend_setup(struct drm_crtc *crtc) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1304 | { |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 1305 | struct sde_crtc *sde_crtc; |
| 1306 | struct sde_crtc_state *sde_crtc_state; |
| 1307 | struct sde_crtc_mixer *mixer; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1308 | struct sde_hw_ctl *ctl; |
| 1309 | struct sde_hw_mixer *lm; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1310 | |
| 1311 | int i; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1312 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 1313 | if (!crtc) |
| 1314 | return; |
| 1315 | |
| 1316 | sde_crtc = to_sde_crtc(crtc); |
| 1317 | sde_crtc_state = to_sde_crtc_state(crtc->state); |
| 1318 | mixer = sde_crtc->mixers; |
| 1319 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1320 | SDE_DEBUG("%s\n", sde_crtc->name); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1321 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1322 | if (sde_crtc->num_mixers > CRTC_DUAL_MIXERS) { |
| 1323 | SDE_ERROR("invalid number mixers: %d\n", sde_crtc->num_mixers); |
| 1324 | return; |
| 1325 | } |
| 1326 | |
| 1327 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 1328 | if (!mixer[i].hw_lm || !mixer[i].hw_ctl) { |
| 1329 | SDE_ERROR("invalid lm or ctl assigned to mixer\n"); |
| 1330 | return; |
| 1331 | } |
| 1332 | mixer[i].mixer_op_mode = 0; |
| 1333 | mixer[i].flush_mask = 0; |
Lloyd Atkinson | e5ec30d | 2016-08-23 14:32:32 -0400 | [diff] [blame] | 1334 | if (mixer[i].hw_ctl->ops.clear_all_blendstages) |
| 1335 | mixer[i].hw_ctl->ops.clear_all_blendstages( |
| 1336 | mixer[i].hw_ctl); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1337 | |
| 1338 | /* clear dim_layer settings */ |
| 1339 | lm = mixer[i].hw_lm; |
| 1340 | if (lm->ops.clear_dim_layer) |
| 1341 | lm->ops.clear_dim_layer(lm); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1344 | _sde_crtc_swap_mixers_for_right_partial_update(crtc); |
| 1345 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1346 | /* initialize stage cfg */ |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1347 | memset(&sde_crtc->stage_cfg, 0, sizeof(struct sde_hw_stage_cfg)); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1348 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1349 | _sde_crtc_blend_setup_mixer(crtc, sde_crtc, mixer); |
| 1350 | |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 1351 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 1352 | const struct sde_rect *lm_roi = &sde_crtc_state->lm_roi[i]; |
| 1353 | |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 1354 | ctl = mixer[i].hw_ctl; |
| 1355 | lm = mixer[i].hw_lm; |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 1356 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 1357 | if (sde_kms_rect_is_null(lm_roi)) { |
| 1358 | SDE_DEBUG( |
| 1359 | "%s: lm%d leave ctl%d mask 0 since null roi\n", |
| 1360 | sde_crtc->name, lm->idx - LM_0, |
| 1361 | ctl->idx - CTL_0); |
| 1362 | continue; |
| 1363 | } |
| 1364 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1365 | lm->ops.setup_alpha_out(lm, mixer[i].mixer_op_mode); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1366 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1367 | mixer[i].flush_mask |= ctl->ops.get_bitmask_mixer(ctl, |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 1368 | mixer[i].hw_lm->idx); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1369 | |
| 1370 | /* stage config flush mask */ |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1371 | ctl->ops.update_pending_flush(ctl, mixer[i].flush_mask); |
| 1372 | |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 1373 | SDE_DEBUG("lm %d, op_mode 0x%X, ctl %d, flush mask 0x%x\n", |
| 1374 | mixer[i].hw_lm->idx - LM_0, |
| 1375 | mixer[i].mixer_op_mode, |
| 1376 | ctl->idx - CTL_0, |
| 1377 | mixer[i].flush_mask); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1378 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1379 | ctl->ops.setup_blendstage(ctl, mixer[i].hw_lm->idx, |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1380 | &sde_crtc->stage_cfg, i); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1381 | } |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1382 | |
| 1383 | _sde_crtc_program_lm_output_roi(crtc); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1386 | void sde_crtc_prepare_commit(struct drm_crtc *crtc, |
| 1387 | struct drm_crtc_state *old_state) |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1388 | { |
| 1389 | struct sde_crtc *sde_crtc; |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1390 | struct sde_crtc_state *cstate; |
| 1391 | struct drm_connector *conn; |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1392 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1393 | if (!crtc || !crtc->state) { |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1394 | SDE_ERROR("invalid crtc\n"); |
| 1395 | return; |
| 1396 | } |
| 1397 | |
| 1398 | sde_crtc = to_sde_crtc(crtc); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1399 | cstate = to_sde_crtc_state(crtc->state); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1400 | SDE_EVT32_VERBOSE(DRMID(crtc)); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1401 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1402 | /* identify connectors attached to this crtc */ |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1403 | cstate->num_connectors = 0; |
| 1404 | |
| 1405 | drm_for_each_connector(conn, crtc->dev) |
| 1406 | if (conn->state && conn->state->crtc == crtc && |
| 1407 | cstate->num_connectors < MAX_CONNECTORS) { |
| 1408 | cstate->connectors[cstate->num_connectors++] = conn; |
| 1409 | sde_connector_prepare_fence(conn); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* prepare main output fence */ |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1413 | sde_fence_prepare(&sde_crtc->output_fence); |
| 1414 | } |
| 1415 | |
Abhinav Kumar | f2e94b5 | 2017-02-09 20:27:24 -0800 | [diff] [blame] | 1416 | /** |
| 1417 | * _sde_crtc_complete_flip - signal pending page_flip events |
| 1418 | * Any pending vblank events are added to the vblank_event_list |
| 1419 | * so that the next vblank interrupt shall signal them. |
| 1420 | * However PAGE_FLIP events are not handled through the vblank_event_list. |
| 1421 | * This API signals any pending PAGE_FLIP events requested through |
| 1422 | * DRM_IOCTL_MODE_PAGE_FLIP and are cached in the sde_crtc->event. |
| 1423 | * if file!=NULL, this is preclose potential cancel-flip path |
| 1424 | * @crtc: Pointer to drm crtc structure |
| 1425 | * @file: Pointer to drm file |
| 1426 | */ |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1427 | static void _sde_crtc_complete_flip(struct drm_crtc *crtc, |
| 1428 | struct drm_file *file) |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 1429 | { |
| 1430 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 1431 | struct drm_device *dev = crtc->dev; |
| 1432 | struct drm_pending_vblank_event *event; |
| 1433 | unsigned long flags; |
| 1434 | |
| 1435 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1436 | event = sde_crtc->event; |
| 1437 | if (event) { |
| 1438 | /* if regular vblank case (!file) or if cancel-flip from |
| 1439 | * preclose on file that requested flip, then send the |
| 1440 | * event: |
| 1441 | */ |
| 1442 | if (!file || (event->base.file_priv == file)) { |
| 1443 | sde_crtc->event = NULL; |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1444 | DRM_DEBUG_VBL("%s: send event: %pK\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1445 | sde_crtc->name, event); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1446 | SDE_EVT32(DRMID(crtc)); |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 1447 | drm_crtc_send_vblank_event(crtc, event); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1451 | } |
| 1452 | |
Alan Kwong | 3e985f0 | 2017-02-12 15:08:44 -0800 | [diff] [blame] | 1453 | enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc) |
| 1454 | { |
| 1455 | struct drm_encoder *encoder; |
| 1456 | |
| 1457 | if (!crtc || !crtc->dev) { |
| 1458 | SDE_ERROR("invalid crtc\n"); |
| 1459 | return INTF_MODE_NONE; |
| 1460 | } |
| 1461 | |
| 1462 | drm_for_each_encoder(encoder, crtc->dev) |
| 1463 | if (encoder->crtc == crtc) |
| 1464 | return sde_encoder_get_intf_mode(encoder); |
| 1465 | |
| 1466 | return INTF_MODE_NONE; |
| 1467 | } |
| 1468 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 1469 | static void sde_crtc_vblank_cb(void *data) |
| 1470 | { |
| 1471 | struct drm_crtc *crtc = (struct drm_crtc *)data; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1472 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 1473 | |
| 1474 | /* keep statistics on vblank callback - with auto reset via debugfs */ |
| 1475 | if (ktime_equal(sde_crtc->vblank_cb_time, ktime_set(0, 0))) |
| 1476 | sde_crtc->vblank_cb_time = ktime_get(); |
| 1477 | else |
| 1478 | sde_crtc->vblank_cb_count++; |
Abhinav Kumar | f2e94b5 | 2017-02-09 20:27:24 -0800 | [diff] [blame] | 1479 | _sde_crtc_complete_flip(crtc, NULL); |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 1480 | drm_crtc_handle_vblank(crtc); |
Lloyd Atkinson | 9eabe7a | 2016-09-14 13:39:15 -0400 | [diff] [blame] | 1481 | DRM_DEBUG_VBL("crtc%d\n", crtc->base.id); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1482 | SDE_EVT32_VERBOSE(DRMID(crtc)); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 1483 | } |
| 1484 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1485 | static void sde_crtc_frame_event_work(struct kthread_work *work) |
| 1486 | { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1487 | struct msm_drm_private *priv; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1488 | struct sde_crtc_frame_event *fevent; |
| 1489 | struct drm_crtc *crtc; |
| 1490 | struct sde_crtc *sde_crtc; |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 1491 | struct sde_crtc_state *cstate; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1492 | struct sde_kms *sde_kms; |
| 1493 | unsigned long flags; |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1494 | bool disable_inprogress = false; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1495 | |
| 1496 | if (!work) { |
| 1497 | SDE_ERROR("invalid work handle\n"); |
| 1498 | return; |
| 1499 | } |
| 1500 | |
| 1501 | fevent = container_of(work, struct sde_crtc_frame_event, work); |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 1502 | if (!fevent->crtc || !fevent->crtc->state) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1503 | SDE_ERROR("invalid crtc\n"); |
| 1504 | return; |
| 1505 | } |
| 1506 | |
| 1507 | crtc = fevent->crtc; |
| 1508 | sde_crtc = to_sde_crtc(crtc); |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 1509 | cstate = to_sde_crtc_state(crtc->state); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1510 | |
| 1511 | sde_kms = _sde_crtc_get_kms(crtc); |
| 1512 | if (!sde_kms) { |
| 1513 | SDE_ERROR("invalid kms handle\n"); |
| 1514 | return; |
| 1515 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1516 | priv = sde_kms->dev->dev_private; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1517 | |
| 1518 | SDE_DEBUG("crtc%d event:%u ts:%lld\n", crtc->base.id, fevent->event, |
| 1519 | ktime_to_ns(fevent->ts)); |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1520 | disable_inprogress = fevent->event & |
| 1521 | SDE_ENCODER_FRAME_EVENT_DURING_DISABLE; |
| 1522 | fevent->event &= ~SDE_ENCODER_FRAME_EVENT_DURING_DISABLE; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1523 | |
| 1524 | if (fevent->event == SDE_ENCODER_FRAME_EVENT_DONE || |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 1525 | (fevent->event & SDE_ENCODER_FRAME_EVENT_ERROR) || |
| 1526 | (fevent->event & SDE_ENCODER_FRAME_EVENT_PANEL_DEAD)) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1527 | |
| 1528 | if (atomic_read(&sde_crtc->frame_pending) < 1) { |
| 1529 | /* this should not happen */ |
| 1530 | SDE_ERROR("crtc%d ts:%lld invalid frame_pending:%d\n", |
| 1531 | crtc->base.id, |
| 1532 | ktime_to_ns(fevent->ts), |
| 1533 | atomic_read(&sde_crtc->frame_pending)); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1534 | SDE_EVT32(DRMID(crtc), fevent->event, |
| 1535 | SDE_EVTLOG_FUNC_CASE1); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1536 | } else if (atomic_dec_return(&sde_crtc->frame_pending) == 0) { |
| 1537 | /* release bandwidth and other resources */ |
| 1538 | SDE_DEBUG("crtc%d ts:%lld last pending\n", |
| 1539 | crtc->base.id, |
| 1540 | ktime_to_ns(fevent->ts)); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1541 | SDE_EVT32(DRMID(crtc), fevent->event, |
| 1542 | SDE_EVTLOG_FUNC_CASE2); |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1543 | if (!disable_inprogress) |
| 1544 | sde_core_perf_crtc_release_bw(crtc); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1545 | } else { |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1546 | SDE_EVT32_VERBOSE(DRMID(crtc), fevent->event, |
| 1547 | SDE_EVTLOG_FUNC_CASE3); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1548 | } |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 1549 | |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1550 | if (fevent->event == SDE_ENCODER_FRAME_EVENT_DONE && |
| 1551 | !disable_inprogress) |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 1552 | sde_core_perf_crtc_update(crtc, 0, false); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1553 | } else { |
| 1554 | SDE_ERROR("crtc%d ts:%lld unknown event %u\n", crtc->base.id, |
| 1555 | ktime_to_ns(fevent->ts), |
| 1556 | fevent->event); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1557 | SDE_EVT32(DRMID(crtc), fevent->event, SDE_EVTLOG_FUNC_CASE4); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 1560 | if (fevent->event & SDE_ENCODER_FRAME_EVENT_PANEL_DEAD) |
| 1561 | SDE_ERROR("crtc%d ts:%lld received panel dead event\n", |
| 1562 | crtc->base.id, ktime_to_ns(fevent->ts)); |
| 1563 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1564 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
| 1565 | list_add_tail(&fevent->list, &sde_crtc->frame_event_list); |
| 1566 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
| 1567 | } |
| 1568 | |
| 1569 | static void sde_crtc_frame_event_cb(void *data, u32 event) |
| 1570 | { |
| 1571 | struct drm_crtc *crtc = (struct drm_crtc *)data; |
| 1572 | struct sde_crtc *sde_crtc; |
| 1573 | struct msm_drm_private *priv; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1574 | struct sde_crtc_frame_event *fevent; |
| 1575 | unsigned long flags; |
| 1576 | int pipe_id; |
| 1577 | |
| 1578 | if (!crtc || !crtc->dev || !crtc->dev->dev_private) { |
| 1579 | SDE_ERROR("invalid parameters\n"); |
| 1580 | return; |
| 1581 | } |
| 1582 | sde_crtc = to_sde_crtc(crtc); |
| 1583 | priv = crtc->dev->dev_private; |
| 1584 | pipe_id = drm_crtc_index(crtc); |
| 1585 | |
| 1586 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1587 | SDE_EVT32_VERBOSE(DRMID(crtc), event); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1588 | |
| 1589 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
Lloyd Atkinson | 78831f8 | 2016-12-09 11:24:56 -0500 | [diff] [blame] | 1590 | fevent = list_first_entry_or_null(&sde_crtc->frame_event_list, |
| 1591 | struct sde_crtc_frame_event, list); |
| 1592 | if (fevent) |
| 1593 | list_del_init(&fevent->list); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1594 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
| 1595 | |
Lloyd Atkinson | 78831f8 | 2016-12-09 11:24:56 -0500 | [diff] [blame] | 1596 | if (!fevent) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1597 | SDE_ERROR("crtc%d event %d overflow\n", |
| 1598 | crtc->base.id, event); |
| 1599 | SDE_EVT32(DRMID(crtc), event); |
| 1600 | return; |
| 1601 | } |
| 1602 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1603 | fevent->event = event; |
| 1604 | fevent->crtc = crtc; |
| 1605 | fevent->ts = ktime_get(); |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 1606 | if (event & SDE_ENCODER_FRAME_EVENT_DURING_DISABLE) |
| 1607 | sde_crtc_frame_event_work(&fevent->work); |
| 1608 | else |
| 1609 | kthread_queue_work(&priv->disp_thread[pipe_id].worker, |
| 1610 | &fevent->work); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1611 | } |
| 1612 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1613 | void sde_crtc_complete_commit(struct drm_crtc *crtc, |
| 1614 | struct drm_crtc_state *old_state) |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1615 | { |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1616 | struct sde_crtc *sde_crtc; |
| 1617 | struct sde_crtc_state *cstate; |
| 1618 | int i; |
| 1619 | |
| 1620 | if (!crtc || !crtc->state) { |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1621 | SDE_ERROR("invalid crtc\n"); |
| 1622 | return; |
| 1623 | } |
| 1624 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1625 | sde_crtc = to_sde_crtc(crtc); |
| 1626 | cstate = to_sde_crtc_state(crtc->state); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 1627 | SDE_EVT32_VERBOSE(DRMID(crtc)); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1628 | |
| 1629 | /* signal output fence(s) at end of commit */ |
| 1630 | sde_fence_signal(&sde_crtc->output_fence, 0); |
| 1631 | |
| 1632 | for (i = 0; i < cstate->num_connectors; ++i) |
| 1633 | sde_connector_complete_commit(cstate->connectors[i]); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1634 | } |
| 1635 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 1636 | /** |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1637 | * _sde_crtc_set_input_fence_timeout - update ns version of in fence timeout |
| 1638 | * @cstate: Pointer to sde crtc state |
| 1639 | */ |
| 1640 | static void _sde_crtc_set_input_fence_timeout(struct sde_crtc_state *cstate) |
| 1641 | { |
| 1642 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1643 | SDE_ERROR("invalid cstate\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1644 | return; |
| 1645 | } |
| 1646 | cstate->input_fence_timeout_ns = |
| 1647 | sde_crtc_get_property(cstate, CRTC_PROP_INPUT_FENCE_TIMEOUT); |
| 1648 | cstate->input_fence_timeout_ns *= NSEC_PER_MSEC; |
| 1649 | } |
| 1650 | |
| 1651 | /** |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1652 | * _sde_crtc_set_dim_layer_v1 - copy dim layer settings from userspace |
| 1653 | * @cstate: Pointer to sde crtc state |
| 1654 | * @user_ptr: User ptr for sde_drm_dim_layer_v1 struct |
| 1655 | */ |
| 1656 | static void _sde_crtc_set_dim_layer_v1(struct sde_crtc_state *cstate, |
| 1657 | void *usr_ptr) |
| 1658 | { |
| 1659 | struct sde_drm_dim_layer_v1 dim_layer_v1; |
| 1660 | struct sde_drm_dim_layer_cfg *user_cfg; |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1661 | struct sde_hw_dim_layer *dim_layer; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1662 | u32 count, i; |
| 1663 | |
| 1664 | if (!cstate) { |
| 1665 | SDE_ERROR("invalid cstate\n"); |
| 1666 | return; |
| 1667 | } |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1668 | dim_layer = cstate->dim_layer; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1669 | |
| 1670 | if (!usr_ptr) { |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1671 | SDE_DEBUG("dim_layer data removed\n"); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | if (copy_from_user(&dim_layer_v1, usr_ptr, sizeof(dim_layer_v1))) { |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1676 | SDE_ERROR("failed to copy dim_layer data\n"); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1677 | return; |
| 1678 | } |
| 1679 | |
| 1680 | count = dim_layer_v1.num_layers; |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1681 | if (count > SDE_MAX_DIM_LAYERS) { |
| 1682 | SDE_ERROR("invalid number of dim_layers:%d", count); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1683 | return; |
| 1684 | } |
| 1685 | |
| 1686 | /* populate from user space */ |
| 1687 | cstate->num_dim_layers = count; |
| 1688 | for (i = 0; i < count; i++) { |
| 1689 | user_cfg = &dim_layer_v1.layer_cfg[i]; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1690 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1691 | dim_layer[i].flags = user_cfg->flags; |
| 1692 | dim_layer[i].stage = user_cfg->stage + SDE_STAGE_0; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1693 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1694 | dim_layer[i].rect.x = user_cfg->rect.x1; |
| 1695 | dim_layer[i].rect.y = user_cfg->rect.y1; |
| 1696 | dim_layer[i].rect.w = user_cfg->rect.x2 - user_cfg->rect.x1; |
| 1697 | dim_layer[i].rect.h = user_cfg->rect.y2 - user_cfg->rect.y1; |
| 1698 | |
| 1699 | dim_layer[i].color_fill = (struct sde_mdss_color) { |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1700 | user_cfg->color_fill.color_0, |
| 1701 | user_cfg->color_fill.color_1, |
| 1702 | user_cfg->color_fill.color_2, |
| 1703 | user_cfg->color_fill.color_3, |
| 1704 | }; |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 1705 | |
| 1706 | SDE_DEBUG("dim_layer[%d] - flags:%d, stage:%d\n", |
| 1707 | i, dim_layer[i].flags, dim_layer[i].stage); |
| 1708 | SDE_DEBUG(" rect:{%d,%d,%d,%d}, color:{%d,%d,%d,%d}\n", |
| 1709 | dim_layer[i].rect.x, dim_layer[i].rect.y, |
| 1710 | dim_layer[i].rect.w, dim_layer[i].rect.h, |
| 1711 | dim_layer[i].color_fill.color_0, |
| 1712 | dim_layer[i].color_fill.color_1, |
| 1713 | dim_layer[i].color_fill.color_2, |
| 1714 | dim_layer[i].color_fill.color_3); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | /** |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1719 | * _sde_crtc_wait_for_fences - wait for incoming framebuffer sync fences |
| 1720 | * @crtc: Pointer to CRTC object |
| 1721 | */ |
| 1722 | static void _sde_crtc_wait_for_fences(struct drm_crtc *crtc) |
| 1723 | { |
| 1724 | struct drm_plane *plane = NULL; |
| 1725 | uint32_t wait_ms = 1; |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 1726 | ktime_t kt_end, kt_wait; |
Dhaval Patel | 39323d4 | 2017-03-01 23:48:24 -0800 | [diff] [blame] | 1727 | int rc = 0; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1728 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1729 | SDE_DEBUG("\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1730 | |
| 1731 | if (!crtc || !crtc->state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1732 | SDE_ERROR("invalid crtc/state %pK\n", crtc); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | /* use monotonic timer to limit total fence wait time */ |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 1737 | kt_end = ktime_add_ns(ktime_get(), |
| 1738 | to_sde_crtc_state(crtc->state)->input_fence_timeout_ns); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1739 | |
| 1740 | /* |
| 1741 | * Wait for fences sequentially, as all of them need to be signalled |
| 1742 | * before we can proceed. |
| 1743 | * |
| 1744 | * Limit total wait time to INPUT_FENCE_TIMEOUT, but still call |
| 1745 | * sde_plane_wait_input_fence with wait_ms == 0 after the timeout so |
| 1746 | * that each plane can check its fence status and react appropriately |
Dhaval Patel | 39323d4 | 2017-03-01 23:48:24 -0800 | [diff] [blame] | 1747 | * if its fence has timed out. Call input fence wait multiple times if |
| 1748 | * fence wait is interrupted due to interrupt call. |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1749 | */ |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 1750 | SDE_ATRACE_BEGIN("plane_wait_input_fence"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1751 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
Dhaval Patel | 39323d4 | 2017-03-01 23:48:24 -0800 | [diff] [blame] | 1752 | do { |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 1753 | kt_wait = ktime_sub(kt_end, ktime_get()); |
| 1754 | if (ktime_compare(kt_wait, ktime_set(0, 0)) >= 0) |
| 1755 | wait_ms = ktime_to_ms(kt_wait); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1756 | else |
| 1757 | wait_ms = 0; |
Dhaval Patel | 39323d4 | 2017-03-01 23:48:24 -0800 | [diff] [blame] | 1758 | |
| 1759 | rc = sde_plane_wait_input_fence(plane, wait_ms); |
| 1760 | } while (wait_ms && rc == -ERESTARTSYS); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1761 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 1762 | SDE_ATRACE_END("plane_wait_input_fence"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1763 | } |
| 1764 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1765 | static void _sde_crtc_setup_mixer_for_encoder( |
| 1766 | struct drm_crtc *crtc, |
| 1767 | struct drm_encoder *enc) |
| 1768 | { |
| 1769 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1770 | struct sde_kms *sde_kms = _sde_crtc_get_kms(crtc); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1771 | struct sde_rm *rm = &sde_kms->rm; |
| 1772 | struct sde_crtc_mixer *mixer; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1773 | struct sde_hw_ctl *last_valid_ctl = NULL; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1774 | int i; |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1775 | struct sde_rm_hw_iter lm_iter, ctl_iter, dspp_iter; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1776 | |
| 1777 | sde_rm_init_hw_iter(&lm_iter, enc->base.id, SDE_HW_BLK_LM); |
| 1778 | sde_rm_init_hw_iter(&ctl_iter, enc->base.id, SDE_HW_BLK_CTL); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1779 | sde_rm_init_hw_iter(&dspp_iter, enc->base.id, SDE_HW_BLK_DSPP); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1780 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1781 | /* Set up all the mixers and ctls reserved by this encoder */ |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1782 | for (i = sde_crtc->num_mixers; i < ARRAY_SIZE(sde_crtc->mixers); i++) { |
| 1783 | mixer = &sde_crtc->mixers[i]; |
| 1784 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1785 | if (!sde_rm_get_hw(rm, &lm_iter)) |
| 1786 | break; |
| 1787 | mixer->hw_lm = (struct sde_hw_mixer *)lm_iter.hw; |
| 1788 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1789 | /* CTL may be <= LMs, if <, multiple LMs controlled by 1 CTL */ |
| 1790 | if (!sde_rm_get_hw(rm, &ctl_iter)) { |
| 1791 | SDE_DEBUG("no ctl assigned to lm %d, using previous\n", |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 1792 | mixer->hw_lm->idx - LM_0); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1793 | mixer->hw_ctl = last_valid_ctl; |
| 1794 | } else { |
| 1795 | mixer->hw_ctl = (struct sde_hw_ctl *)ctl_iter.hw; |
| 1796 | last_valid_ctl = mixer->hw_ctl; |
| 1797 | } |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1798 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1799 | /* Shouldn't happen, mixers are always >= ctls */ |
| 1800 | if (!mixer->hw_ctl) { |
| 1801 | SDE_ERROR("no valid ctls found for lm %d\n", |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 1802 | mixer->hw_lm->idx - LM_0); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1803 | return; |
| 1804 | } |
| 1805 | |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1806 | /* Dspp may be null */ |
| 1807 | (void) sde_rm_get_hw(rm, &dspp_iter); |
| 1808 | mixer->hw_dspp = (struct sde_hw_dspp *)dspp_iter.hw; |
| 1809 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1810 | mixer->encoder = enc; |
| 1811 | |
| 1812 | sde_crtc->num_mixers++; |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 1813 | SDE_DEBUG("setup mixer %d: lm %d\n", |
| 1814 | i, mixer->hw_lm->idx - LM_0); |
| 1815 | SDE_DEBUG("setup mixer %d: ctl %d\n", |
| 1816 | i, mixer->hw_ctl->idx - CTL_0); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | static void _sde_crtc_setup_mixers(struct drm_crtc *crtc) |
| 1821 | { |
| 1822 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 1823 | struct drm_encoder *enc; |
| 1824 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1825 | sde_crtc->num_mixers = 0; |
| 1826 | memset(sde_crtc->mixers, 0, sizeof(sde_crtc->mixers)); |
| 1827 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1828 | mutex_lock(&sde_crtc->crtc_lock); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1829 | /* Check for mixers on all encoders attached to this crtc */ |
| 1830 | list_for_each_entry(enc, &crtc->dev->mode_config.encoder_list, head) { |
| 1831 | if (enc->crtc != crtc) |
| 1832 | continue; |
| 1833 | |
| 1834 | _sde_crtc_setup_mixer_for_encoder(crtc, enc); |
| 1835 | } |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1836 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1837 | mutex_unlock(&sde_crtc->crtc_lock); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 1840 | static void _sde_crtc_setup_is_ppsplit(struct drm_crtc_state *state) |
| 1841 | { |
| 1842 | int i; |
| 1843 | struct sde_crtc_state *cstate; |
| 1844 | |
| 1845 | cstate = to_sde_crtc_state(state); |
| 1846 | |
| 1847 | cstate->is_ppsplit = false; |
| 1848 | for (i = 0; i < cstate->num_connectors; i++) { |
| 1849 | struct drm_connector *conn = cstate->connectors[i]; |
| 1850 | |
| 1851 | if (sde_connector_get_topology_name(conn) == |
| 1852 | SDE_RM_TOPOLOGY_PPSPLIT) |
| 1853 | cstate->is_ppsplit = true; |
| 1854 | } |
| 1855 | } |
| 1856 | |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1857 | static void _sde_crtc_setup_lm_bounds(struct drm_crtc *crtc, |
| 1858 | struct drm_crtc_state *state) |
| 1859 | { |
| 1860 | struct sde_crtc *sde_crtc; |
| 1861 | struct sde_crtc_state *cstate; |
| 1862 | struct drm_display_mode *adj_mode; |
| 1863 | u32 crtc_split_width; |
| 1864 | int i; |
| 1865 | |
| 1866 | if (!crtc || !state) { |
| 1867 | SDE_ERROR("invalid args\n"); |
| 1868 | return; |
| 1869 | } |
| 1870 | |
| 1871 | sde_crtc = to_sde_crtc(crtc); |
| 1872 | cstate = to_sde_crtc_state(state); |
| 1873 | |
| 1874 | adj_mode = &state->adjusted_mode; |
| 1875 | crtc_split_width = sde_crtc_mixer_width(sde_crtc, adj_mode); |
| 1876 | |
| 1877 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1878 | cstate->lm_bounds[i].x = crtc_split_width * i; |
| 1879 | cstate->lm_bounds[i].y = 0; |
| 1880 | cstate->lm_bounds[i].w = crtc_split_width; |
| 1881 | cstate->lm_bounds[i].h = adj_mode->vdisplay; |
| 1882 | memcpy(&cstate->lm_roi[i], &cstate->lm_bounds[i], |
| 1883 | sizeof(cstate->lm_roi[i])); |
| 1884 | SDE_EVT32(DRMID(crtc), i, |
| 1885 | cstate->lm_bounds[i].x, cstate->lm_bounds[i].y, |
| 1886 | cstate->lm_bounds[i].w, cstate->lm_bounds[i].h); |
| 1887 | SDE_DEBUG("%s: lm%d bnd&roi (%d,%d,%d,%d)\n", sde_crtc->name, i, |
| 1888 | cstate->lm_roi[i].x, cstate->lm_roi[i].y, |
| 1889 | cstate->lm_roi[i].w, cstate->lm_roi[i].h); |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | drm_mode_debug_printmodeline(adj_mode); |
| 1893 | } |
| 1894 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1895 | static void sde_crtc_atomic_begin(struct drm_crtc *crtc, |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 1896 | struct drm_crtc_state *old_state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1897 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1898 | struct sde_crtc *sde_crtc; |
Dhaval Patel | 0e558f4 | 2017-04-30 00:51:40 -0700 | [diff] [blame] | 1899 | struct drm_encoder *encoder; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1900 | struct drm_device *dev; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1901 | unsigned long flags; |
| 1902 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1903 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1904 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1905 | return; |
| 1906 | } |
| 1907 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 1908 | if (!crtc->state->enable) { |
| 1909 | SDE_DEBUG("crtc%d -> enable %d, skip atomic_begin\n", |
| 1910 | crtc->base.id, crtc->state->enable); |
| 1911 | return; |
| 1912 | } |
| 1913 | |
| 1914 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
| 1915 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1916 | sde_crtc = to_sde_crtc(crtc); |
| 1917 | dev = crtc->dev; |
| 1918 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1919 | if (!sde_crtc->num_mixers) { |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1920 | _sde_crtc_setup_mixers(crtc); |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 1921 | _sde_crtc_setup_is_ppsplit(crtc->state); |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1922 | _sde_crtc_setup_lm_bounds(crtc, crtc->state); |
| 1923 | } |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 1924 | |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 1925 | if (sde_crtc->event) { |
| 1926 | WARN_ON(sde_crtc->event); |
| 1927 | } else { |
| 1928 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1929 | sde_crtc->event = crtc->state->event; |
| 1930 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1931 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1932 | |
Dhaval Patel | 0e558f4 | 2017-04-30 00:51:40 -0700 | [diff] [blame] | 1933 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1934 | if (encoder->crtc != crtc) |
| 1935 | continue; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 1936 | |
Dhaval Patel | 0e558f4 | 2017-04-30 00:51:40 -0700 | [diff] [blame] | 1937 | /* encoder will trigger pending mask now */ |
| 1938 | sde_encoder_trigger_kickoff_pending(encoder); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1941 | /* |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1942 | * If no mixers have been allocated in sde_crtc_atomic_check(), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1943 | * it means we are trying to flush a CRTC whose state is disabled: |
| 1944 | * nothing else needs to be done. |
| 1945 | */ |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1946 | if (unlikely(!sde_crtc->num_mixers)) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1947 | return; |
| 1948 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 1949 | _sde_crtc_blend_setup(crtc); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1950 | sde_cp_crtc_apply_properties(crtc); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1951 | |
| 1952 | /* |
| 1953 | * PP_DONE irq is only used by command mode for now. |
| 1954 | * It is better to request pending before FLUSH and START trigger |
| 1955 | * to make sure no pp_done irq missed. |
| 1956 | * This is safe because no pp_done will happen before SW trigger |
| 1957 | * in command mode. |
| 1958 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1961 | static void sde_crtc_atomic_flush(struct drm_crtc *crtc, |
| 1962 | struct drm_crtc_state *old_crtc_state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1963 | { |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1964 | struct drm_encoder *encoder; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1965 | struct sde_crtc *sde_crtc; |
| 1966 | struct drm_device *dev; |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 1967 | struct drm_plane *plane; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1968 | unsigned long flags; |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1969 | struct sde_crtc_state *cstate; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1970 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1971 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1972 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1973 | return; |
| 1974 | } |
| 1975 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 1976 | if (!crtc->state->enable) { |
| 1977 | SDE_DEBUG("crtc%d -> enable %d, skip atomic_flush\n", |
| 1978 | crtc->base.id, crtc->state->enable); |
| 1979 | return; |
| 1980 | } |
| 1981 | |
| 1982 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1983 | |
| 1984 | sde_crtc = to_sde_crtc(crtc); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1985 | cstate = to_sde_crtc_state(crtc->state); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1986 | dev = crtc->dev; |
| 1987 | |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 1988 | if (sde_crtc->event) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1989 | SDE_DEBUG("already received sde_crtc->event\n"); |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 1990 | } else { |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 1991 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1992 | sde_crtc->event = crtc->state->event; |
| 1993 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1994 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1995 | |
| 1996 | /* |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1997 | * If no mixers has been allocated in sde_crtc_atomic_check(), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1998 | * it means we are trying to flush a CRTC whose state is disabled: |
| 1999 | * nothing else needs to be done. |
| 2000 | */ |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2001 | if (unlikely(!sde_crtc->num_mixers)) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2002 | return; |
| 2003 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2004 | /* wait for acquire fences before anything else is done */ |
| 2005 | _sde_crtc_wait_for_fences(crtc); |
| 2006 | |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 2007 | if (!cstate->rsc_update) { |
| 2008 | drm_for_each_encoder(encoder, dev) { |
| 2009 | if (encoder->crtc != crtc) |
| 2010 | continue; |
| 2011 | |
| 2012 | cstate->rsc_client = |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 2013 | sde_encoder_get_rsc_client(encoder); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 2014 | } |
| 2015 | cstate->rsc_update = true; |
| 2016 | } |
| 2017 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2018 | /* update performance setting before crtc kickoff */ |
| 2019 | sde_core_perf_crtc_update(crtc, 1, false); |
| 2020 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2021 | /* |
| 2022 | * Final plane updates: Give each plane a chance to complete all |
| 2023 | * required writes/flushing before crtc's "flush |
| 2024 | * everything" call below. |
| 2025 | */ |
| 2026 | drm_atomic_crtc_for_each_plane(plane, crtc) |
| 2027 | sde_plane_flush(plane); |
| 2028 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2029 | /* Kickoff will be scheduled by outer layer */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2032 | /** |
| 2033 | * sde_crtc_destroy_state - state destroy hook |
| 2034 | * @crtc: drm CRTC |
| 2035 | * @state: CRTC state object to release |
| 2036 | */ |
| 2037 | static void sde_crtc_destroy_state(struct drm_crtc *crtc, |
| 2038 | struct drm_crtc_state *state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2039 | { |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2040 | struct sde_crtc *sde_crtc; |
| 2041 | struct sde_crtc_state *cstate; |
| 2042 | |
| 2043 | if (!crtc || !state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2044 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2045 | return; |
| 2046 | } |
| 2047 | |
| 2048 | sde_crtc = to_sde_crtc(crtc); |
| 2049 | cstate = to_sde_crtc_state(state); |
| 2050 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 2051 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2052 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2053 | _sde_crtc_rp_destroy(&cstate->rp); |
| 2054 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 2055 | __drm_atomic_helper_crtc_destroy_state(state); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2056 | |
| 2057 | /* destroy value helper */ |
| 2058 | msm_property_destroy_state(&sde_crtc->property_info, cstate, |
| 2059 | cstate->property_values, cstate->property_blobs); |
| 2060 | } |
| 2061 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2062 | void sde_crtc_commit_kickoff(struct drm_crtc *crtc) |
| 2063 | { |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 2064 | struct drm_encoder *encoder; |
| 2065 | struct drm_device *dev; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2066 | struct sde_crtc *sde_crtc; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 2067 | struct msm_drm_private *priv; |
| 2068 | struct sde_kms *sde_kms; |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2069 | struct sde_crtc_state *cstate; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2070 | |
| 2071 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2072 | SDE_ERROR("invalid argument\n"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2073 | return; |
| 2074 | } |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 2075 | dev = crtc->dev; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2076 | sde_crtc = to_sde_crtc(crtc); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 2077 | sde_kms = _sde_crtc_get_kms(crtc); |
| 2078 | priv = sde_kms->dev->dev_private; |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2079 | cstate = to_sde_crtc_state(crtc->state); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2080 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 2081 | /* |
| 2082 | * If no mixers has been allocated in sde_crtc_atomic_check(), |
| 2083 | * it means we are trying to start a CRTC whose state is disabled: |
| 2084 | * nothing else needs to be done. |
| 2085 | */ |
| 2086 | if (unlikely(!sde_crtc->num_mixers)) |
| 2087 | return; |
| 2088 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2089 | SDE_ATRACE_BEGIN("crtc_commit"); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 2090 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2091 | struct sde_encoder_kickoff_params params = { 0 }; |
| 2092 | |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 2093 | if (encoder->crtc != crtc) |
| 2094 | continue; |
| 2095 | |
| 2096 | /* |
| 2097 | * Encoder will flush/start now, unless it has a tx pending. |
| 2098 | * If so, it may delay and flush at an irq event (e.g. ppdone) |
| 2099 | */ |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2100 | params.inline_rotate_prefill = cstate->sbuf_prefill_line; |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2101 | params.affected_displays = _sde_crtc_get_displays_affected(crtc, |
| 2102 | crtc->state); |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2103 | sde_encoder_prepare_for_kickoff(encoder, ¶ms); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | if (atomic_read(&sde_crtc->frame_pending) > 2) { |
| 2107 | /* framework allows only 1 outstanding + current */ |
| 2108 | SDE_ERROR("crtc%d invalid frame pending\n", |
| 2109 | crtc->base.id); |
| 2110 | SDE_EVT32(DRMID(crtc), 0); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2111 | goto end; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2112 | } else if (atomic_inc_return(&sde_crtc->frame_pending) == 1) { |
| 2113 | /* acquire bandwidth and other resources */ |
| 2114 | SDE_DEBUG("crtc%d first commit\n", crtc->base.id); |
| 2115 | SDE_EVT32(DRMID(crtc), 1); |
| 2116 | } else { |
| 2117 | SDE_DEBUG("crtc%d commit\n", crtc->base.id); |
| 2118 | SDE_EVT32(DRMID(crtc), 2); |
| 2119 | } |
| 2120 | |
| 2121 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 2122 | if (encoder->crtc != crtc) |
| 2123 | continue; |
| 2124 | |
| 2125 | sde_encoder_kickoff(encoder); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 2126 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2127 | end: |
| 2128 | SDE_ATRACE_END("crtc_commit"); |
| 2129 | return; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2130 | } |
| 2131 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2132 | /** |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2133 | * _sde_crtc_vblank_enable_nolock - update power resource and vblank request |
| 2134 | * @sde_crtc: Pointer to sde crtc structure |
| 2135 | * @enable: Whether to enable/disable vblanks |
| 2136 | */ |
| 2137 | static void _sde_crtc_vblank_enable_nolock( |
| 2138 | struct sde_crtc *sde_crtc, bool enable) |
| 2139 | { |
| 2140 | struct drm_device *dev; |
| 2141 | struct drm_crtc *crtc; |
| 2142 | struct drm_encoder *enc; |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2143 | |
| 2144 | if (!sde_crtc) { |
| 2145 | SDE_ERROR("invalid crtc\n"); |
| 2146 | return; |
| 2147 | } |
| 2148 | |
| 2149 | crtc = &sde_crtc->base; |
| 2150 | dev = crtc->dev; |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2151 | |
| 2152 | if (enable) { |
Lloyd Atkinson | 2c554eb | 2017-05-24 16:22:39 -0400 | [diff] [blame] | 2153 | int ret; |
| 2154 | |
| 2155 | /* drop lock since power crtc cb may try to re-acquire lock */ |
| 2156 | mutex_unlock(&sde_crtc->crtc_lock); |
| 2157 | ret = _sde_crtc_power_enable(sde_crtc, true); |
| 2158 | mutex_lock(&sde_crtc->crtc_lock); |
| 2159 | if (ret) |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 2160 | return; |
| 2161 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2162 | list_for_each_entry(enc, &dev->mode_config.encoder_list, head) { |
| 2163 | if (enc->crtc != crtc) |
| 2164 | continue; |
| 2165 | |
| 2166 | SDE_EVT32(DRMID(crtc), DRMID(enc), enable); |
| 2167 | |
| 2168 | sde_encoder_register_vblank_callback(enc, |
| 2169 | sde_crtc_vblank_cb, (void *)crtc); |
| 2170 | } |
| 2171 | } else { |
| 2172 | list_for_each_entry(enc, &dev->mode_config.encoder_list, head) { |
| 2173 | if (enc->crtc != crtc) |
| 2174 | continue; |
| 2175 | |
| 2176 | SDE_EVT32(DRMID(crtc), DRMID(enc), enable); |
| 2177 | |
| 2178 | sde_encoder_register_vblank_callback(enc, NULL, NULL); |
| 2179 | } |
Lloyd Atkinson | 2c554eb | 2017-05-24 16:22:39 -0400 | [diff] [blame] | 2180 | |
| 2181 | /* drop lock since power crtc cb may try to re-acquire lock */ |
| 2182 | mutex_unlock(&sde_crtc->crtc_lock); |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 2183 | _sde_crtc_power_enable(sde_crtc, false); |
Lloyd Atkinson | 2c554eb | 2017-05-24 16:22:39 -0400 | [diff] [blame] | 2184 | mutex_lock(&sde_crtc->crtc_lock); |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | /** |
| 2189 | * _sde_crtc_set_suspend - notify crtc of suspend enable/disable |
| 2190 | * @crtc: Pointer to drm crtc object |
| 2191 | * @enable: true to enable suspend, false to indicate resume |
| 2192 | */ |
| 2193 | static void _sde_crtc_set_suspend(struct drm_crtc *crtc, bool enable) |
| 2194 | { |
| 2195 | struct sde_crtc *sde_crtc; |
| 2196 | struct msm_drm_private *priv; |
| 2197 | struct sde_kms *sde_kms; |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2198 | struct drm_event event; |
| 2199 | u32 power_on; |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2200 | |
| 2201 | if (!crtc || !crtc->dev || !crtc->dev->dev_private) { |
| 2202 | SDE_ERROR("invalid crtc\n"); |
| 2203 | return; |
| 2204 | } |
| 2205 | sde_crtc = to_sde_crtc(crtc); |
| 2206 | priv = crtc->dev->dev_private; |
| 2207 | |
| 2208 | if (!priv->kms) { |
| 2209 | SDE_ERROR("invalid crtc kms\n"); |
| 2210 | return; |
| 2211 | } |
| 2212 | sde_kms = to_sde_kms(priv->kms); |
| 2213 | |
| 2214 | SDE_DEBUG("crtc%d suspend = %d\n", crtc->base.id, enable); |
| 2215 | |
| 2216 | mutex_lock(&sde_crtc->crtc_lock); |
| 2217 | |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2218 | event.type = DRM_EVENT_CRTC_POWER; |
| 2219 | event.length = sizeof(u32); |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2220 | /* |
Clarence Ip | 2f9beeb | 2017-03-16 11:04:53 -0400 | [diff] [blame] | 2221 | * Update CP on suspend/resume transitions |
| 2222 | */ |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2223 | if (enable && !sde_crtc->suspend) { |
Clarence Ip | 2f9beeb | 2017-03-16 11:04:53 -0400 | [diff] [blame] | 2224 | sde_cp_crtc_suspend(crtc); |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2225 | power_on = 0; |
| 2226 | } else if (!enable && sde_crtc->suspend) { |
Clarence Ip | 2f9beeb | 2017-03-16 11:04:53 -0400 | [diff] [blame] | 2227 | sde_cp_crtc_resume(crtc); |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2228 | power_on = 1; |
| 2229 | } |
Clarence Ip | 2f9beeb | 2017-03-16 11:04:53 -0400 | [diff] [blame] | 2230 | |
| 2231 | /* |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2232 | * If the vblank refcount != 0, release a power reference on suspend |
| 2233 | * and take it back during resume (if it is still != 0). |
| 2234 | */ |
| 2235 | if (sde_crtc->suspend == enable) |
| 2236 | SDE_DEBUG("crtc%d suspend already set to %d, ignoring update\n", |
| 2237 | crtc->base.id, enable); |
| 2238 | else if (atomic_read(&sde_crtc->vblank_refcount) != 0) |
| 2239 | _sde_crtc_vblank_enable_nolock(sde_crtc, !enable); |
| 2240 | |
| 2241 | sde_crtc->suspend = enable; |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 2242 | msm_mode_object_event_nofity(&crtc->base, crtc->dev, &event, |
| 2243 | (u8 *)&power_on); |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2244 | mutex_unlock(&sde_crtc->crtc_lock); |
| 2245 | } |
| 2246 | |
| 2247 | /** |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2248 | * sde_crtc_duplicate_state - state duplicate hook |
| 2249 | * @crtc: Pointer to drm crtc structure |
| 2250 | * @Returns: Pointer to new drm_crtc_state structure |
| 2251 | */ |
| 2252 | static struct drm_crtc_state *sde_crtc_duplicate_state(struct drm_crtc *crtc) |
| 2253 | { |
| 2254 | struct sde_crtc *sde_crtc; |
| 2255 | struct sde_crtc_state *cstate, *old_cstate; |
| 2256 | |
| 2257 | if (!crtc || !crtc->state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2258 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2259 | return NULL; |
| 2260 | } |
| 2261 | |
| 2262 | sde_crtc = to_sde_crtc(crtc); |
| 2263 | old_cstate = to_sde_crtc_state(crtc->state); |
| 2264 | cstate = msm_property_alloc_state(&sde_crtc->property_info); |
| 2265 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2266 | SDE_ERROR("failed to allocate state\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2267 | return NULL; |
| 2268 | } |
| 2269 | |
| 2270 | /* duplicate value helper */ |
| 2271 | msm_property_duplicate_state(&sde_crtc->property_info, |
| 2272 | old_cstate, cstate, |
| 2273 | cstate->property_values, cstate->property_blobs); |
| 2274 | |
| 2275 | /* duplicate base helper */ |
| 2276 | __drm_atomic_helper_crtc_duplicate_state(crtc, &cstate->base); |
| 2277 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2278 | _sde_crtc_rp_duplicate(&old_cstate->rp, &cstate->rp); |
| 2279 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2280 | return &cstate->base; |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * sde_crtc_reset - reset hook for CRTCs |
| 2285 | * Resets the atomic state for @crtc by freeing the state pointer (which might |
| 2286 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2287 | * @crtc: Pointer to drm crtc structure |
| 2288 | */ |
| 2289 | static void sde_crtc_reset(struct drm_crtc *crtc) |
| 2290 | { |
| 2291 | struct sde_crtc *sde_crtc; |
| 2292 | struct sde_crtc_state *cstate; |
| 2293 | |
| 2294 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2295 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2296 | return; |
| 2297 | } |
| 2298 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2299 | /* revert suspend actions, if necessary */ |
| 2300 | if (msm_is_suspend_state(crtc->dev)) |
| 2301 | _sde_crtc_set_suspend(crtc, false); |
| 2302 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2303 | /* remove previous state, if present */ |
| 2304 | if (crtc->state) { |
| 2305 | sde_crtc_destroy_state(crtc, crtc->state); |
| 2306 | crtc->state = 0; |
| 2307 | } |
| 2308 | |
| 2309 | sde_crtc = to_sde_crtc(crtc); |
| 2310 | cstate = msm_property_alloc_state(&sde_crtc->property_info); |
| 2311 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2312 | SDE_ERROR("failed to allocate state\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | /* reset value helper */ |
| 2317 | msm_property_reset_state(&sde_crtc->property_info, cstate, |
| 2318 | cstate->property_values, cstate->property_blobs); |
| 2319 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2320 | _sde_crtc_set_input_fence_timeout(cstate); |
| 2321 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2322 | _sde_crtc_rp_reset(&cstate->rp); |
| 2323 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2324 | cstate->base.crtc = crtc; |
| 2325 | crtc->state = &cstate->base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
Clarence Ip | 9728a1d | 2017-04-18 22:22:13 -0400 | [diff] [blame] | 2328 | static int _sde_crtc_vblank_no_lock(struct sde_crtc *sde_crtc, bool en) |
| 2329 | { |
| 2330 | if (!sde_crtc) { |
| 2331 | SDE_ERROR("invalid crtc\n"); |
| 2332 | return -EINVAL; |
| 2333 | } else if (en && atomic_inc_return(&sde_crtc->vblank_refcount) == 1) { |
| 2334 | SDE_DEBUG("crtc%d vblank enable\n", sde_crtc->base.base.id); |
| 2335 | if (!sde_crtc->suspend) |
| 2336 | _sde_crtc_vblank_enable_nolock(sde_crtc, true); |
| 2337 | } else if (!en && atomic_read(&sde_crtc->vblank_refcount) < 1) { |
| 2338 | SDE_ERROR("crtc%d invalid vblank disable\n", |
| 2339 | sde_crtc->base.base.id); |
| 2340 | return -EINVAL; |
| 2341 | } else if (!en && atomic_dec_return(&sde_crtc->vblank_refcount) == 0) { |
| 2342 | SDE_DEBUG("crtc%d vblank disable\n", sde_crtc->base.base.id); |
| 2343 | if (!sde_crtc->suspend) |
| 2344 | _sde_crtc_vblank_enable_nolock(sde_crtc, false); |
| 2345 | } else { |
| 2346 | SDE_DEBUG("crtc%d vblank %s refcount:%d\n", |
| 2347 | sde_crtc->base.base.id, |
| 2348 | en ? "enable" : "disable", |
| 2349 | atomic_read(&sde_crtc->vblank_refcount)); |
| 2350 | } |
| 2351 | |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2355 | static void sde_crtc_handle_power_event(u32 event_type, void *arg) |
| 2356 | { |
| 2357 | struct drm_crtc *crtc = arg; |
| 2358 | struct sde_crtc *sde_crtc; |
| 2359 | struct drm_encoder *encoder; |
| 2360 | |
| 2361 | if (!crtc) { |
| 2362 | SDE_ERROR("invalid crtc\n"); |
| 2363 | return; |
| 2364 | } |
| 2365 | sde_crtc = to_sde_crtc(crtc); |
| 2366 | |
| 2367 | mutex_lock(&sde_crtc->crtc_lock); |
| 2368 | |
| 2369 | SDE_EVT32(DRMID(crtc), event_type); |
| 2370 | |
| 2371 | if (event_type == SDE_POWER_EVENT_POST_ENABLE) { |
| 2372 | /* restore encoder; crtc will be programmed during commit */ |
| 2373 | drm_for_each_encoder(encoder, crtc->dev) { |
| 2374 | if (encoder->crtc != crtc) |
| 2375 | continue; |
| 2376 | |
| 2377 | sde_encoder_virt_restore(encoder); |
| 2378 | } |
| 2379 | |
| 2380 | } else if (event_type == SDE_POWER_EVENT_POST_DISABLE) { |
| 2381 | struct drm_plane *plane; |
| 2382 | |
| 2383 | /* |
| 2384 | * set revalidate flag in planes, so it will be re-programmed |
| 2385 | * in the next frame update |
| 2386 | */ |
| 2387 | drm_atomic_crtc_for_each_plane(plane, crtc) |
| 2388 | sde_plane_set_revalidate(plane, true); |
| 2389 | } |
| 2390 | |
| 2391 | mutex_unlock(&sde_crtc->crtc_lock); |
| 2392 | } |
| 2393 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2394 | static void sde_crtc_disable(struct drm_crtc *crtc) |
| 2395 | { |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2396 | struct sde_crtc *sde_crtc; |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 2397 | struct sde_crtc_state *cstate; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 2398 | struct drm_encoder *encoder; |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2399 | struct msm_drm_private *priv; |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 2400 | unsigned long flags; |
| 2401 | struct sde_crtc_irq_info *node = NULL; |
| 2402 | int ret; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2403 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2404 | if (!crtc || !crtc->dev || !crtc->dev->dev_private || !crtc->state) { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 2405 | SDE_ERROR("invalid crtc\n"); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2406 | return; |
| 2407 | } |
| 2408 | sde_crtc = to_sde_crtc(crtc); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 2409 | cstate = to_sde_crtc_state(crtc->state); |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2410 | priv = crtc->dev->dev_private; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2411 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 2412 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2413 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2414 | if (msm_is_suspend_state(crtc->dev)) |
| 2415 | _sde_crtc_set_suspend(crtc, true); |
| 2416 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 2417 | mutex_lock(&sde_crtc->crtc_lock); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2418 | SDE_EVT32(DRMID(crtc)); |
| 2419 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2420 | if (atomic_read(&sde_crtc->vblank_refcount) && !sde_crtc->suspend) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2421 | SDE_ERROR("crtc%d invalid vblank refcount\n", |
| 2422 | crtc->base.id); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 2423 | SDE_EVT32(DRMID(crtc), atomic_read(&sde_crtc->vblank_refcount), |
| 2424 | SDE_EVTLOG_FUNC_CASE1); |
Clarence Ip | 9728a1d | 2017-04-18 22:22:13 -0400 | [diff] [blame] | 2425 | while (atomic_read(&sde_crtc->vblank_refcount)) |
| 2426 | if (_sde_crtc_vblank_no_lock(sde_crtc, false)) |
| 2427 | break; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 2428 | } |
| 2429 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2430 | if (atomic_read(&sde_crtc->frame_pending)) { |
| 2431 | /* release bandwidth and other resources */ |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 2432 | SDE_ERROR("crtc%d invalid frame pending\n", crtc->base.id); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 2433 | SDE_EVT32(DRMID(crtc), atomic_read(&sde_crtc->frame_pending), |
| 2434 | SDE_EVTLOG_FUNC_CASE2); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2435 | sde_core_perf_crtc_release_bw(crtc); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2436 | atomic_set(&sde_crtc->frame_pending, 0); |
| 2437 | } |
| 2438 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2439 | sde_core_perf_crtc_update(crtc, 0, true); |
| 2440 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2441 | drm_for_each_encoder(encoder, crtc->dev) { |
| 2442 | if (encoder->crtc != crtc) |
| 2443 | continue; |
| 2444 | sde_encoder_register_frame_event_callback(encoder, NULL, NULL); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 2445 | cstate->rsc_client = NULL; |
| 2446 | cstate->rsc_update = false; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2449 | if (sde_crtc->power_event) |
| 2450 | sde_power_handle_unregister_event(&priv->phandle, |
| 2451 | sde_crtc->power_event); |
| 2452 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 2453 | memset(sde_crtc->mixers, 0, sizeof(sde_crtc->mixers)); |
| 2454 | sde_crtc->num_mixers = 0; |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 2455 | |
| 2456 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
| 2457 | list_for_each_entry(node, &sde_crtc->user_event_list, list) { |
| 2458 | ret = 0; |
| 2459 | if (node->func) |
| 2460 | ret = node->func(crtc, false, &node->irq); |
| 2461 | if (ret) |
| 2462 | SDE_ERROR("%s failed to disable event %x\n", |
| 2463 | sde_crtc->name, node->event); |
| 2464 | } |
| 2465 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
| 2466 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 2467 | mutex_unlock(&sde_crtc->crtc_lock); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | static void sde_crtc_enable(struct drm_crtc *crtc) |
| 2471 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2472 | struct sde_crtc *sde_crtc; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2473 | struct drm_encoder *encoder; |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2474 | struct msm_drm_private *priv; |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 2475 | unsigned long flags; |
| 2476 | struct sde_crtc_irq_info *node = NULL; |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 2477 | int ret; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 2478 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2479 | if (!crtc || !crtc->dev || !crtc->dev->dev_private) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2480 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2481 | return; |
| 2482 | } |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2483 | priv = crtc->dev->dev_private; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2484 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 2485 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2486 | SDE_EVT32(DRMID(crtc)); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2487 | sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 2488 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2489 | drm_for_each_encoder(encoder, crtc->dev) { |
| 2490 | if (encoder->crtc != crtc) |
| 2491 | continue; |
| 2492 | sde_encoder_register_frame_event_callback(encoder, |
| 2493 | sde_crtc_frame_event_cb, (void *)crtc); |
| 2494 | } |
| 2495 | |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 2496 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
| 2497 | list_for_each_entry(node, &sde_crtc->user_event_list, list) { |
| 2498 | ret = 0; |
| 2499 | if (node->func) |
| 2500 | ret = node->func(crtc, true, &node->irq); |
| 2501 | if (ret) |
| 2502 | SDE_ERROR("%s failed to enable event %x\n", |
| 2503 | sde_crtc->name, node->event); |
| 2504 | } |
| 2505 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2506 | |
| 2507 | sde_crtc->power_event = sde_power_handle_register_event( |
| 2508 | &priv->phandle, |
| 2509 | SDE_POWER_EVENT_POST_ENABLE | SDE_POWER_EVENT_POST_DISABLE, |
| 2510 | sde_crtc_handle_power_event, crtc, sde_crtc->name); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | struct plane_state { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2514 | struct sde_plane_state *sde_pstate; |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 2515 | const struct drm_plane_state *drm_pstate; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2516 | int stage; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2517 | u32 pipe_id; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2518 | }; |
| 2519 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2520 | static int pstate_cmp(const void *a, const void *b) |
| 2521 | { |
| 2522 | struct plane_state *pa = (struct plane_state *)a; |
| 2523 | struct plane_state *pb = (struct plane_state *)b; |
| 2524 | int rc = 0; |
| 2525 | int pa_zpos, pb_zpos; |
| 2526 | |
| 2527 | pa_zpos = sde_plane_get_property(pa->sde_pstate, PLANE_PROP_ZPOS); |
| 2528 | pb_zpos = sde_plane_get_property(pb->sde_pstate, PLANE_PROP_ZPOS); |
| 2529 | |
| 2530 | if (pa_zpos != pb_zpos) |
| 2531 | rc = pa_zpos - pb_zpos; |
| 2532 | else |
| 2533 | rc = pa->drm_pstate->crtc_x - pb->drm_pstate->crtc_x; |
| 2534 | |
| 2535 | return rc; |
| 2536 | } |
| 2537 | |
Dhaval Patel | a8d6bc6 | 2017-05-10 17:40:18 -0700 | [diff] [blame] | 2538 | static int _sde_crtc_excl_rect_overlap_check(struct plane_state pstates[], |
| 2539 | int cnt, int curr_cnt, struct sde_rect *excl_rect, int z_pos) |
| 2540 | { |
| 2541 | struct sde_rect dst_rect, intersect; |
| 2542 | int i, rc = -EINVAL; |
| 2543 | const struct drm_plane_state *pstate; |
| 2544 | |
| 2545 | /* start checking from next plane */ |
| 2546 | for (i = curr_cnt; i < cnt; i++) { |
| 2547 | pstate = pstates[i].drm_pstate; |
| 2548 | POPULATE_RECT(&dst_rect, pstate->crtc_x, pstate->crtc_y, |
| 2549 | pstate->crtc_w, pstate->crtc_h, true); |
| 2550 | sde_kms_rect_intersect(&dst_rect, excl_rect, &intersect); |
| 2551 | |
| 2552 | if (intersect.w == excl_rect->w && intersect.h == excl_rect->h |
| 2553 | /* next plane may be on same z-order */ |
| 2554 | && z_pos != pstates[i].stage) { |
| 2555 | rc = 0; |
| 2556 | goto end; |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | SDE_ERROR("excl rect does not find top overlapping rect\n"); |
| 2561 | end: |
| 2562 | return rc; |
| 2563 | } |
| 2564 | |
| 2565 | /* no input validation - caller API has all the checks */ |
| 2566 | static int _sde_crtc_excl_dim_layer_check(struct drm_crtc_state *state, |
| 2567 | struct plane_state pstates[], int cnt) |
| 2568 | { |
| 2569 | struct sde_crtc_state *cstate = to_sde_crtc_state(state); |
| 2570 | struct drm_display_mode *mode = &state->adjusted_mode; |
| 2571 | const struct drm_plane_state *pstate; |
| 2572 | struct sde_plane_state *sde_pstate; |
| 2573 | int rc = 0, i; |
| 2574 | |
| 2575 | /* Check dim layer rect bounds and stage */ |
| 2576 | for (i = 0; i < cstate->num_dim_layers; i++) { |
| 2577 | if ((CHECK_LAYER_BOUNDS(cstate->dim_layer[i].rect.y, |
| 2578 | cstate->dim_layer[i].rect.h, mode->vdisplay)) || |
| 2579 | (CHECK_LAYER_BOUNDS(cstate->dim_layer[i].rect.x, |
| 2580 | cstate->dim_layer[i].rect.w, mode->hdisplay)) || |
| 2581 | (cstate->dim_layer[i].stage >= SDE_STAGE_MAX) || |
| 2582 | (!cstate->dim_layer[i].rect.w) || |
| 2583 | (!cstate->dim_layer[i].rect.h)) { |
| 2584 | SDE_ERROR("invalid dim_layer:{%d,%d,%d,%d}, stage:%d\n", |
| 2585 | cstate->dim_layer[i].rect.x, |
| 2586 | cstate->dim_layer[i].rect.y, |
| 2587 | cstate->dim_layer[i].rect.w, |
| 2588 | cstate->dim_layer[i].rect.h, |
| 2589 | cstate->dim_layer[i].stage); |
| 2590 | SDE_ERROR("display: %dx%d\n", mode->hdisplay, |
| 2591 | mode->vdisplay); |
| 2592 | rc = -E2BIG; |
| 2593 | goto end; |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /* this is traversing on sorted z-order pstates */ |
| 2598 | for (i = 0; i < cnt; i++) { |
| 2599 | pstate = pstates[i].drm_pstate; |
| 2600 | sde_pstate = to_sde_plane_state(pstate); |
| 2601 | if (sde_pstate->excl_rect.w && sde_pstate->excl_rect.h) { |
| 2602 | /* check overlap on all top z-order */ |
| 2603 | rc = _sde_crtc_excl_rect_overlap_check(pstates, cnt, |
| 2604 | i + 1, &sde_pstate->excl_rect, pstates[i].stage); |
| 2605 | if (rc) |
| 2606 | goto end; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | end: |
| 2611 | return rc; |
| 2612 | } |
| 2613 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2614 | static int sde_crtc_atomic_check(struct drm_crtc *crtc, |
| 2615 | struct drm_crtc_state *state) |
| 2616 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2617 | struct sde_crtc *sde_crtc; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2618 | struct plane_state pstates[SDE_STAGE_MAX * 4]; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 2619 | struct sde_crtc_state *cstate; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2620 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 2621 | const struct drm_plane_state *pstate; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2622 | struct drm_plane *plane; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2623 | struct drm_display_mode *mode; |
| 2624 | |
| 2625 | int cnt = 0, rc = 0, mixer_width, i, z_pos; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2626 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2627 | struct sde_multirect_plane_states multirect_plane[SDE_STAGE_MAX * 2]; |
| 2628 | int multirect_count = 0; |
| 2629 | const struct drm_plane_state *pipe_staged[SSPP_MAX]; |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2630 | int left_zpos_cnt = 0, right_zpos_cnt = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2631 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2632 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2633 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2634 | return -EINVAL; |
| 2635 | } |
| 2636 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2637 | sde_crtc = to_sde_crtc(crtc); |
| 2638 | cstate = to_sde_crtc_state(state); |
| 2639 | |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2640 | if (!state->enable || !state->active) { |
| 2641 | SDE_DEBUG("crtc%d -> enable %d, active %d, skip atomic_check\n", |
| 2642 | crtc->base.id, state->enable, state->active); |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2643 | goto end; |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2644 | } |
| 2645 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2646 | mode = &state->adjusted_mode; |
| 2647 | SDE_DEBUG("%s: check", sde_crtc->name); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 2648 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 2649 | /* force a full mode set if active state changed */ |
| 2650 | if (state->active_changed) |
| 2651 | state->mode_changed = true; |
| 2652 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2653 | memset(pipe_staged, 0, sizeof(pipe_staged)); |
| 2654 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2655 | mixer_width = sde_crtc_mixer_width(sde_crtc, mode); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2656 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 2657 | _sde_crtc_setup_is_ppsplit(state); |
Lloyd Atkinson | a9d7e75 | 2017-01-17 16:31:43 -0500 | [diff] [blame] | 2658 | _sde_crtc_setup_lm_bounds(crtc, state); |
| 2659 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2660 | /* get plane state for all drm planes associated with crtc state */ |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 2661 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2662 | if (IS_ERR_OR_NULL(pstate)) { |
| 2663 | rc = PTR_ERR(pstate); |
| 2664 | SDE_ERROR("%s: failed to get plane%d state, %d\n", |
| 2665 | sde_crtc->name, plane->base.id, rc); |
Alan Kwong | 8576728 | 2016-10-03 18:03:37 -0400 | [diff] [blame] | 2666 | goto end; |
| 2667 | } |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2668 | if (cnt >= ARRAY_SIZE(pstates)) |
| 2669 | continue; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2670 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2671 | pstates[cnt].sde_pstate = to_sde_plane_state(pstate); |
| 2672 | pstates[cnt].drm_pstate = pstate; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2673 | pstates[cnt].stage = sde_plane_get_property( |
| 2674 | pstates[cnt].sde_pstate, PLANE_PROP_ZPOS); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2675 | pstates[cnt].pipe_id = sde_plane_pipe(plane); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 2676 | |
| 2677 | /* check dim layer stage with every plane */ |
| 2678 | for (i = 0; i < cstate->num_dim_layers; i++) { |
| 2679 | if (pstates[cnt].stage == cstate->dim_layer[i].stage) { |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 2680 | SDE_ERROR( |
| 2681 | "plane:%d/dim_layer:%i-same stage:%d\n", |
| 2682 | plane->base.id, i, |
| 2683 | cstate->dim_layer[i].stage); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 2684 | rc = -EINVAL; |
| 2685 | goto end; |
| 2686 | } |
| 2687 | } |
| 2688 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2689 | if (pipe_staged[pstates[cnt].pipe_id]) { |
| 2690 | multirect_plane[multirect_count].r0 = |
| 2691 | pipe_staged[pstates[cnt].pipe_id]; |
| 2692 | multirect_plane[multirect_count].r1 = pstate; |
| 2693 | multirect_count++; |
| 2694 | |
| 2695 | pipe_staged[pstates[cnt].pipe_id] = NULL; |
| 2696 | } else { |
| 2697 | pipe_staged[pstates[cnt].pipe_id] = pstate; |
| 2698 | } |
| 2699 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2700 | cnt++; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2701 | |
| 2702 | if (CHECK_LAYER_BOUNDS(pstate->crtc_y, pstate->crtc_h, |
| 2703 | mode->vdisplay) || |
| 2704 | CHECK_LAYER_BOUNDS(pstate->crtc_x, pstate->crtc_w, |
| 2705 | mode->hdisplay)) { |
| 2706 | SDE_ERROR("invalid vertical/horizontal destination\n"); |
| 2707 | SDE_ERROR("y:%d h:%d vdisp:%d x:%d w:%d hdisp:%d\n", |
| 2708 | pstate->crtc_y, pstate->crtc_h, mode->vdisplay, |
| 2709 | pstate->crtc_x, pstate->crtc_w, mode->hdisplay); |
| 2710 | rc = -E2BIG; |
| 2711 | goto end; |
| 2712 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2713 | } |
| 2714 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2715 | for (i = 1; i < SSPP_MAX; i++) { |
Jeykumar Sankaran | e964dc7 | 2017-05-10 19:26:43 -0700 | [diff] [blame] | 2716 | if (pipe_staged[i]) { |
| 2717 | sde_plane_clear_multirect(pipe_staged[i]); |
| 2718 | |
| 2719 | if (is_sde_plane_virtual(pipe_staged[i]->plane)) { |
| 2720 | SDE_ERROR("invalid use of virtual plane: %d\n", |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2721 | pipe_staged[i]->plane->base.id); |
Jeykumar Sankaran | e964dc7 | 2017-05-10 19:26:43 -0700 | [diff] [blame] | 2722 | goto end; |
| 2723 | } |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2727 | /* assign mixer stages based on sorted zpos property */ |
| 2728 | sort(pstates, cnt, sizeof(pstates[0]), pstate_cmp, NULL); |
| 2729 | |
Dhaval Patel | a8d6bc6 | 2017-05-10 17:40:18 -0700 | [diff] [blame] | 2730 | rc = _sde_crtc_excl_dim_layer_check(state, pstates, cnt); |
| 2731 | if (rc) |
| 2732 | goto end; |
| 2733 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2734 | if (!sde_is_custom_client()) { |
| 2735 | int stage_old = pstates[0].stage; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2736 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2737 | z_pos = 0; |
| 2738 | for (i = 0; i < cnt; i++) { |
| 2739 | if (stage_old != pstates[i].stage) |
| 2740 | ++z_pos; |
| 2741 | stage_old = pstates[i].stage; |
| 2742 | pstates[i].stage = z_pos; |
| 2743 | } |
| 2744 | } |
| 2745 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2746 | z_pos = -1; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2747 | for (i = 0; i < cnt; i++) { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2748 | /* reset counts at every new blend stage */ |
| 2749 | if (pstates[i].stage != z_pos) { |
| 2750 | left_zpos_cnt = 0; |
| 2751 | right_zpos_cnt = 0; |
| 2752 | z_pos = pstates[i].stage; |
| 2753 | } |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2754 | |
| 2755 | /* verify z_pos setting before using it */ |
Clarence Ip | 649989a | 2016-10-21 14:28:34 -0400 | [diff] [blame] | 2756 | if (z_pos >= SDE_STAGE_MAX - SDE_STAGE_0) { |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2757 | SDE_ERROR("> %d plane stages assigned\n", |
| 2758 | SDE_STAGE_MAX - SDE_STAGE_0); |
| 2759 | rc = -EINVAL; |
| 2760 | goto end; |
| 2761 | } else if (pstates[i].drm_pstate->crtc_x < mixer_width) { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2762 | if (left_zpos_cnt == 2) { |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2763 | SDE_ERROR("> 2 planes @ stage %d on left\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2764 | z_pos); |
| 2765 | rc = -EINVAL; |
| 2766 | goto end; |
| 2767 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2768 | left_zpos_cnt++; |
| 2769 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2770 | } else { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2771 | if (right_zpos_cnt == 2) { |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2772 | SDE_ERROR("> 2 planes @ stage %d on right\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2773 | z_pos); |
| 2774 | rc = -EINVAL; |
| 2775 | goto end; |
| 2776 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2777 | right_zpos_cnt++; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2778 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2779 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 2780 | pstates[i].sde_pstate->stage = z_pos + SDE_STAGE_0; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2781 | SDE_DEBUG("%s: zpos %d", sde_crtc->name, z_pos); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2782 | } |
| 2783 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2784 | for (i = 0; i < multirect_count; i++) { |
| 2785 | if (sde_plane_validate_multirect_v2(&multirect_plane[i])) { |
| 2786 | SDE_ERROR( |
| 2787 | "multirect validation failed for planes (%d - %d)\n", |
| 2788 | multirect_plane[i].r0->plane->base.id, |
| 2789 | multirect_plane[i].r1->plane->base.id); |
| 2790 | rc = -EINVAL; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2791 | goto end; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2795 | rc = sde_core_perf_crtc_check(crtc, state); |
| 2796 | if (rc) { |
| 2797 | SDE_ERROR("crtc%d failed performance check %d\n", |
| 2798 | crtc->base.id, rc); |
| 2799 | goto end; |
| 2800 | } |
| 2801 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2802 | /* |
| 2803 | * enforce pipe priority restrictions |
| 2804 | * use pstates sorted by stage to check planes on same stage |
| 2805 | * we assume that all pipes are in source split so its valid to compare |
| 2806 | * without taking into account left/right mixer placement |
| 2807 | */ |
| 2808 | for (i = 1; i < cnt; i++) { |
| 2809 | struct plane_state *prv_pstate, *cur_pstate; |
| 2810 | int32_t prv_x, cur_x, prv_id, cur_id; |
| 2811 | |
| 2812 | prv_pstate = &pstates[i - 1]; |
| 2813 | cur_pstate = &pstates[i]; |
| 2814 | if (prv_pstate->stage != cur_pstate->stage) |
| 2815 | continue; |
| 2816 | |
| 2817 | prv_x = prv_pstate->drm_pstate->crtc_x; |
| 2818 | cur_x = cur_pstate->drm_pstate->crtc_x; |
| 2819 | prv_id = prv_pstate->sde_pstate->base.plane->base.id; |
| 2820 | cur_id = cur_pstate->sde_pstate->base.plane->base.id; |
| 2821 | |
| 2822 | /* |
| 2823 | * Planes are enumerated in pipe-priority order such that planes |
| 2824 | * with lower drm_id must be left-most in a shared blend-stage |
| 2825 | * when using source split. |
| 2826 | */ |
| 2827 | if (cur_x > prv_x && cur_id < prv_id) { |
| 2828 | SDE_ERROR( |
| 2829 | "shared z_pos %d lower id plane%d @ x%d should be left of plane%d @ x %d\n", |
| 2830 | cur_pstate->stage, cur_id, cur_x, |
| 2831 | prv_id, prv_x); |
| 2832 | rc = -EINVAL; |
| 2833 | goto end; |
| 2834 | } else if (cur_x < prv_x && cur_id > prv_id) { |
| 2835 | SDE_ERROR( |
| 2836 | "shared z_pos %d lower id plane%d @ x%d should be left of plane%d @ x %d\n", |
| 2837 | cur_pstate->stage, prv_id, prv_x, |
| 2838 | cur_id, cur_x); |
| 2839 | rc = -EINVAL; |
| 2840 | goto end; |
| 2841 | } |
| 2842 | } |
| 2843 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 2844 | rc = _sde_crtc_check_rois(crtc, state); |
| 2845 | if (rc) { |
| 2846 | SDE_ERROR("crtc%d failed roi check %d\n", crtc->base.id, rc); |
| 2847 | goto end; |
| 2848 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 2849 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2850 | end: |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 2851 | _sde_crtc_rp_free_unused(&cstate->rp); |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 2852 | return rc; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2853 | } |
| 2854 | |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 2855 | int sde_crtc_vblank(struct drm_crtc *crtc, bool en) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2856 | { |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2857 | struct sde_crtc *sde_crtc; |
Clarence Ip | 9728a1d | 2017-04-18 22:22:13 -0400 | [diff] [blame] | 2858 | int rc; |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 2859 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2860 | if (!crtc) { |
| 2861 | SDE_ERROR("invalid crtc\n"); |
| 2862 | return -EINVAL; |
| 2863 | } |
| 2864 | sde_crtc = to_sde_crtc(crtc); |
| 2865 | |
| 2866 | mutex_lock(&sde_crtc->crtc_lock); |
Clarence Ip | 9728a1d | 2017-04-18 22:22:13 -0400 | [diff] [blame] | 2867 | rc = _sde_crtc_vblank_no_lock(sde_crtc, en); |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2868 | mutex_unlock(&sde_crtc->crtc_lock); |
Clarence Ip | 9728a1d | 2017-04-18 22:22:13 -0400 | [diff] [blame] | 2869 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 2870 | return rc; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2873 | void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file) |
| 2874 | { |
| 2875 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 2876 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 2877 | SDE_DEBUG("%s: cancel: %p\n", sde_crtc->name, file); |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 2878 | _sde_crtc_complete_flip(crtc, file); |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2879 | } |
| 2880 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2881 | /** |
| 2882 | * sde_crtc_install_properties - install all drm properties for crtc |
| 2883 | * @crtc: Pointer to drm crtc structure |
| 2884 | */ |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2885 | static void sde_crtc_install_properties(struct drm_crtc *crtc, |
| 2886 | struct sde_mdss_cfg *catalog) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2887 | { |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2888 | struct sde_crtc *sde_crtc; |
| 2889 | struct drm_device *dev; |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2890 | struct sde_kms_info *info; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2891 | struct sde_kms *sde_kms; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2892 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 2893 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2894 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2895 | if (!crtc || !catalog) { |
| 2896 | SDE_ERROR("invalid crtc or catalog\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2897 | return; |
| 2898 | } |
| 2899 | |
| 2900 | sde_crtc = to_sde_crtc(crtc); |
| 2901 | dev = crtc->dev; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2902 | sde_kms = _sde_crtc_get_kms(crtc); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2903 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2904 | info = kzalloc(sizeof(struct sde_kms_info), GFP_KERNEL); |
| 2905 | if (!info) { |
| 2906 | SDE_ERROR("failed to allocate info memory\n"); |
| 2907 | return; |
| 2908 | } |
| 2909 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 2910 | /* range properties */ |
| 2911 | msm_property_install_range(&sde_crtc->property_info, |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 2912 | "input_fence_timeout", 0x0, 0, SDE_CRTC_MAX_INPUT_FENCE_TIMEOUT, |
| 2913 | SDE_CRTC_INPUT_FENCE_TIMEOUT, CRTC_PROP_INPUT_FENCE_TIMEOUT); |
| 2914 | |
| 2915 | msm_property_install_range(&sde_crtc->property_info, "output_fence", |
| 2916 | 0x0, 0, INR_OPEN_MAX, 0x0, CRTC_PROP_OUTPUT_FENCE); |
Clarence Ip | 1d9728b | 2016-09-01 11:10:54 -0400 | [diff] [blame] | 2917 | |
| 2918 | msm_property_install_range(&sde_crtc->property_info, |
| 2919 | "output_fence_offset", 0x0, 0, 1, 0, |
| 2920 | CRTC_PROP_OUTPUT_FENCE_OFFSET); |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2921 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2922 | msm_property_install_range(&sde_crtc->property_info, |
| 2923 | "core_clk", 0x0, 0, U64_MAX, |
| 2924 | sde_kms->perf.max_core_clk_rate, |
| 2925 | CRTC_PROP_CORE_CLK); |
| 2926 | msm_property_install_range(&sde_crtc->property_info, |
| 2927 | "core_ab", 0x0, 0, U64_MAX, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 2928 | catalog->perf.max_bw_high * 1000ULL, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2929 | CRTC_PROP_CORE_AB); |
| 2930 | msm_property_install_range(&sde_crtc->property_info, |
| 2931 | "core_ib", 0x0, 0, U64_MAX, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 2932 | catalog->perf.max_bw_high * 1000ULL, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2933 | CRTC_PROP_CORE_IB); |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2934 | msm_property_install_range(&sde_crtc->property_info, |
Alan Kwong | 8c176bf | 2017-02-09 19:34:32 -0800 | [diff] [blame] | 2935 | "mem_ab", 0x0, 0, U64_MAX, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 2936 | catalog->perf.max_bw_high * 1000ULL, |
Alan Kwong | 8c176bf | 2017-02-09 19:34:32 -0800 | [diff] [blame] | 2937 | CRTC_PROP_MEM_AB); |
| 2938 | msm_property_install_range(&sde_crtc->property_info, |
| 2939 | "mem_ib", 0x0, 0, U64_MAX, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 2940 | catalog->perf.max_bw_high * 1000ULL, |
Alan Kwong | 8c176bf | 2017-02-09 19:34:32 -0800 | [diff] [blame] | 2941 | CRTC_PROP_MEM_IB); |
| 2942 | msm_property_install_range(&sde_crtc->property_info, |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 2943 | "rot_prefill_bw", 0, 0, U64_MAX, |
| 2944 | catalog->perf.max_bw_high * 1000ULL, |
| 2945 | CRTC_PROP_ROT_PREFILL_BW); |
Alan Kwong | 8c176bf | 2017-02-09 19:34:32 -0800 | [diff] [blame] | 2946 | msm_property_install_range(&sde_crtc->property_info, |
| 2947 | "rot_clk", 0, 0, U64_MAX, |
| 2948 | sde_kms->perf.max_core_clk_rate, |
| 2949 | CRTC_PROP_ROT_CLK); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 2950 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2951 | msm_property_install_blob(&sde_crtc->property_info, "capabilities", |
| 2952 | DRM_MODE_PROP_IMMUTABLE, CRTC_PROP_INFO); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 2953 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 2954 | msm_property_install_volatile_range(&sde_crtc->property_info, |
| 2955 | "sde_drm_roi_v1", 0x0, 0, ~0, 0, CRTC_PROP_ROI_V1); |
| 2956 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2957 | sde_kms_info_reset(info); |
| 2958 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 2959 | if (catalog->has_dim_layer) { |
| 2960 | msm_property_install_volatile_range(&sde_crtc->property_info, |
| 2961 | "dim_layer_v1", 0x0, 0, ~0, 0, CRTC_PROP_DIM_LAYER_V1); |
| 2962 | sde_kms_info_add_keyint(info, "dim_layer_v1_max_layers", |
| 2963 | SDE_MAX_DIM_LAYERS); |
| 2964 | } |
| 2965 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2966 | sde_kms_info_add_keyint(info, "hw_version", catalog->hwversion); |
| 2967 | sde_kms_info_add_keyint(info, "max_linewidth", |
| 2968 | catalog->max_mixer_width); |
| 2969 | sde_kms_info_add_keyint(info, "max_blendstages", |
| 2970 | catalog->max_mixer_blendstages); |
| 2971 | if (catalog->qseed_type == SDE_SSPP_SCALER_QSEED2) |
| 2972 | sde_kms_info_add_keystr(info, "qseed_type", "qseed2"); |
| 2973 | if (catalog->qseed_type == SDE_SSPP_SCALER_QSEED3) |
| 2974 | sde_kms_info_add_keystr(info, "qseed_type", "qseed3"); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 2975 | |
| 2976 | if (sde_is_custom_client()) { |
| 2977 | if (catalog->smart_dma_rev == SDE_SSPP_SMART_DMA_V1) |
| 2978 | sde_kms_info_add_keystr(info, |
| 2979 | "smart_dma_rev", "smart_dma_v1"); |
| 2980 | if (catalog->smart_dma_rev == SDE_SSPP_SMART_DMA_V2) |
| 2981 | sde_kms_info_add_keystr(info, |
| 2982 | "smart_dma_rev", "smart_dma_v2"); |
| 2983 | } |
| 2984 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 2985 | sde_kms_info_add_keyint(info, "has_src_split", catalog->has_src_split); |
Alan Kwong | 2f84f8a | 2016-12-29 13:07:47 -0500 | [diff] [blame] | 2986 | if (catalog->perf.max_bw_low) |
| 2987 | sde_kms_info_add_keyint(info, "max_bandwidth_low", |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 2988 | catalog->perf.max_bw_low * 1000LL); |
Alan Kwong | 2f84f8a | 2016-12-29 13:07:47 -0500 | [diff] [blame] | 2989 | if (catalog->perf.max_bw_high) |
| 2990 | sde_kms_info_add_keyint(info, "max_bandwidth_high", |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 2991 | catalog->perf.max_bw_high * 1000LL); |
Alan Kwong | 2f84f8a | 2016-12-29 13:07:47 -0500 | [diff] [blame] | 2992 | if (sde_kms->perf.max_core_clk_rate) |
| 2993 | sde_kms_info_add_keyint(info, "max_mdp_clk", |
| 2994 | sde_kms->perf.max_core_clk_rate); |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 2995 | sde_kms_info_add_keystr(info, "core_ib_ff", |
| 2996 | catalog->perf.core_ib_ff); |
| 2997 | sde_kms_info_add_keystr(info, "core_clk_ff", |
| 2998 | catalog->perf.core_clk_ff); |
| 2999 | sde_kms_info_add_keystr(info, "comp_ratio_rt", |
| 3000 | catalog->perf.comp_ratio_rt); |
| 3001 | sde_kms_info_add_keystr(info, "comp_ratio_nrt", |
| 3002 | catalog->perf.comp_ratio_nrt); |
| 3003 | sde_kms_info_add_keyint(info, "dest_scale_prefill_lines", |
| 3004 | catalog->perf.dest_scale_prefill_lines); |
| 3005 | sde_kms_info_add_keyint(info, "undersized_prefill_lines", |
| 3006 | catalog->perf.undersized_prefill_lines); |
| 3007 | sde_kms_info_add_keyint(info, "macrotile_prefill_lines", |
| 3008 | catalog->perf.macrotile_prefill_lines); |
| 3009 | sde_kms_info_add_keyint(info, "yuv_nv12_prefill_lines", |
| 3010 | catalog->perf.yuv_nv12_prefill_lines); |
| 3011 | sde_kms_info_add_keyint(info, "linear_prefill_lines", |
| 3012 | catalog->perf.linear_prefill_lines); |
| 3013 | sde_kms_info_add_keyint(info, "downscaling_prefill_lines", |
| 3014 | catalog->perf.downscaling_prefill_lines); |
| 3015 | sde_kms_info_add_keyint(info, "xtra_prefill_lines", |
| 3016 | catalog->perf.xtra_prefill_lines); |
| 3017 | sde_kms_info_add_keyint(info, "amortizable_threshold", |
| 3018 | catalog->perf.amortizable_threshold); |
| 3019 | sde_kms_info_add_keyint(info, "min_prefill_lines", |
| 3020 | catalog->perf.min_prefill_lines); |
| 3021 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 3022 | msm_property_set_blob(&sde_crtc->property_info, &sde_crtc->blob_info, |
| 3023 | info->data, info->len, CRTC_PROP_INFO); |
| 3024 | |
| 3025 | kfree(info); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | /** |
| 3029 | * sde_crtc_atomic_set_property - atomically set a crtc drm property |
| 3030 | * @crtc: Pointer to drm crtc structure |
| 3031 | * @state: Pointer to drm crtc state structure |
| 3032 | * @property: Pointer to targeted drm property |
| 3033 | * @val: Updated property value |
| 3034 | * @Returns: Zero on success |
| 3035 | */ |
| 3036 | static int sde_crtc_atomic_set_property(struct drm_crtc *crtc, |
| 3037 | struct drm_crtc_state *state, |
| 3038 | struct drm_property *property, |
| 3039 | uint64_t val) |
| 3040 | { |
| 3041 | struct sde_crtc *sde_crtc; |
| 3042 | struct sde_crtc_state *cstate; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 3043 | int idx, ret = -EINVAL; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3044 | |
| 3045 | if (!crtc || !state || !property) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 3046 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3047 | } else { |
| 3048 | sde_crtc = to_sde_crtc(crtc); |
| 3049 | cstate = to_sde_crtc_state(state); |
| 3050 | ret = msm_property_atomic_set(&sde_crtc->property_info, |
| 3051 | cstate->property_values, cstate->property_blobs, |
| 3052 | property, val); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 3053 | if (!ret) { |
| 3054 | idx = msm_property_index(&sde_crtc->property_info, |
| 3055 | property); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 3056 | switch (idx) { |
| 3057 | case CRTC_PROP_INPUT_FENCE_TIMEOUT: |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 3058 | _sde_crtc_set_input_fence_timeout(cstate); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 3059 | break; |
| 3060 | case CRTC_PROP_DIM_LAYER_V1: |
| 3061 | _sde_crtc_set_dim_layer_v1(cstate, (void *)val); |
| 3062 | break; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 3063 | case CRTC_PROP_ROI_V1: |
| 3064 | ret = _sde_crtc_set_roi_v1(state, (void *)val); |
| 3065 | break; |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 3066 | case CRTC_PROP_CORE_AB: |
| 3067 | case CRTC_PROP_CORE_IB: |
| 3068 | case CRTC_PROP_MEM_AB: |
| 3069 | case CRTC_PROP_MEM_IB: |
| 3070 | cstate->bw_control = true; |
| 3071 | break; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 3072 | default: |
| 3073 | /* nothing to do */ |
| 3074 | break; |
| 3075 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3076 | } else { |
| 3077 | ret = sde_cp_crtc_set_property(crtc, |
| 3078 | property, val); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 3079 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3080 | if (ret) |
| 3081 | DRM_ERROR("failed to set the property\n"); |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 3082 | |
| 3083 | SDE_DEBUG("crtc%d %s[%d] <= 0x%llx ret=%d\n", crtc->base.id, |
| 3084 | property->name, property->base.id, val, ret); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | return ret; |
| 3088 | } |
| 3089 | |
| 3090 | /** |
| 3091 | * sde_crtc_set_property - set a crtc drm property |
| 3092 | * @crtc: Pointer to drm crtc structure |
| 3093 | * @property: Pointer to targeted drm property |
| 3094 | * @val: Updated property value |
| 3095 | * @Returns: Zero on success |
| 3096 | */ |
| 3097 | static int sde_crtc_set_property(struct drm_crtc *crtc, |
| 3098 | struct drm_property *property, uint64_t val) |
| 3099 | { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 3100 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3101 | |
| 3102 | return sde_crtc_atomic_set_property(crtc, crtc->state, property, val); |
| 3103 | } |
| 3104 | |
| 3105 | /** |
| 3106 | * sde_crtc_atomic_get_property - retrieve a crtc drm property |
| 3107 | * @crtc: Pointer to drm crtc structure |
| 3108 | * @state: Pointer to drm crtc state structure |
| 3109 | * @property: Pointer to targeted drm property |
| 3110 | * @val: Pointer to variable for receiving property value |
| 3111 | * @Returns: Zero on success |
| 3112 | */ |
| 3113 | static int sde_crtc_atomic_get_property(struct drm_crtc *crtc, |
| 3114 | const struct drm_crtc_state *state, |
| 3115 | struct drm_property *property, |
| 3116 | uint64_t *val) |
| 3117 | { |
| 3118 | struct sde_crtc *sde_crtc; |
| 3119 | struct sde_crtc_state *cstate; |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 3120 | int i, ret = -EINVAL; |
Dhaval Patel | 5cb59be | 2017-04-20 20:00:56 -0700 | [diff] [blame] | 3121 | bool conn_offset = 0; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3122 | |
| 3123 | if (!crtc || !state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 3124 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3125 | } else { |
| 3126 | sde_crtc = to_sde_crtc(crtc); |
| 3127 | cstate = to_sde_crtc_state(state); |
Dhaval Patel | 5cb59be | 2017-04-20 20:00:56 -0700 | [diff] [blame] | 3128 | |
| 3129 | for (i = 0; i < cstate->num_connectors; ++i) { |
| 3130 | conn_offset = sde_connector_needs_offset( |
| 3131 | cstate->connectors[i]); |
| 3132 | if (conn_offset) |
| 3133 | break; |
| 3134 | } |
| 3135 | |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 3136 | i = msm_property_index(&sde_crtc->property_info, property); |
| 3137 | if (i == CRTC_PROP_OUTPUT_FENCE) { |
Dhaval Patel | 39323d4 | 2017-03-01 23:48:24 -0800 | [diff] [blame] | 3138 | uint32_t offset = sde_crtc_get_property(cstate, |
Clarence Ip | 1d9728b | 2016-09-01 11:10:54 -0400 | [diff] [blame] | 3139 | CRTC_PROP_OUTPUT_FENCE_OFFSET); |
| 3140 | |
Dhaval Patel | 5cb59be | 2017-04-20 20:00:56 -0700 | [diff] [blame] | 3141 | ret = sde_fence_create(&sde_crtc->output_fence, val, |
| 3142 | offset + conn_offset); |
Clarence Ip | 1d9728b | 2016-09-01 11:10:54 -0400 | [diff] [blame] | 3143 | if (ret) |
| 3144 | SDE_ERROR("fence create failed\n"); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 3145 | } else { |
| 3146 | ret = msm_property_atomic_get(&sde_crtc->property_info, |
| 3147 | cstate->property_values, |
| 3148 | cstate->property_blobs, property, val); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3149 | if (ret) |
| 3150 | ret = sde_cp_crtc_get_property(crtc, |
| 3151 | property, val); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 3152 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3153 | if (ret) |
| 3154 | DRM_ERROR("get property failed\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3155 | } |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3156 | return ret; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3159 | #ifdef CONFIG_DEBUG_FS |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3160 | static int _sde_debugfs_status_show(struct seq_file *s, void *data) |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3161 | { |
| 3162 | struct sde_crtc *sde_crtc; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3163 | struct sde_plane_state *pstate = NULL; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3164 | struct sde_crtc_mixer *m; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3165 | |
| 3166 | struct drm_crtc *crtc; |
| 3167 | struct drm_plane *plane; |
| 3168 | struct drm_display_mode *mode; |
| 3169 | struct drm_framebuffer *fb; |
| 3170 | struct drm_plane_state *state; |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 3171 | struct sde_crtc_state *cstate; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3172 | |
| 3173 | int i, out_width; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3174 | |
| 3175 | if (!s || !s->private) |
| 3176 | return -EINVAL; |
| 3177 | |
| 3178 | sde_crtc = s->private; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3179 | crtc = &sde_crtc->base; |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 3180 | cstate = to_sde_crtc_state(crtc->state); |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3181 | |
| 3182 | mutex_lock(&sde_crtc->crtc_lock); |
| 3183 | mode = &crtc->state->adjusted_mode; |
| 3184 | out_width = sde_crtc_mixer_width(sde_crtc, mode); |
| 3185 | |
| 3186 | seq_printf(s, "crtc:%d width:%d height:%d\n", crtc->base.id, |
| 3187 | mode->hdisplay, mode->vdisplay); |
| 3188 | |
| 3189 | seq_puts(s, "\n"); |
| 3190 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3191 | for (i = 0; i < sde_crtc->num_mixers; ++i) { |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 3192 | m = &sde_crtc->mixers[i]; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3193 | if (!m->hw_lm) |
| 3194 | seq_printf(s, "\tmixer[%d] has no lm\n", i); |
| 3195 | else if (!m->hw_ctl) |
| 3196 | seq_printf(s, "\tmixer[%d] has no ctl\n", i); |
| 3197 | else |
| 3198 | seq_printf(s, "\tmixer:%d ctl:%d width:%d height:%d\n", |
| 3199 | m->hw_lm->idx - LM_0, m->hw_ctl->idx - CTL_0, |
| 3200 | out_width, mode->vdisplay); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3201 | } |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 3202 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3203 | seq_puts(s, "\n"); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 3204 | |
Veera Sundaram Sankaran | 2cb064f | 2017-05-05 14:12:17 -0700 | [diff] [blame] | 3205 | for (i = 0; i < cstate->num_dim_layers; i++) { |
| 3206 | struct sde_hw_dim_layer *dim_layer = &cstate->dim_layer[i]; |
| 3207 | |
| 3208 | seq_printf(s, "\tdim_layer:%d] stage:%d flags:%d\n", |
| 3209 | i, dim_layer->stage, dim_layer->flags); |
| 3210 | seq_printf(s, "\tdst_x:%d dst_y:%d dst_w:%d dst_h:%d\n", |
| 3211 | dim_layer->rect.x, dim_layer->rect.y, |
| 3212 | dim_layer->rect.w, dim_layer->rect.h); |
| 3213 | seq_printf(s, |
| 3214 | "\tcolor_0:%d color_1:%d color_2:%d color_3:%d\n", |
| 3215 | dim_layer->color_fill.color_0, |
| 3216 | dim_layer->color_fill.color_1, |
| 3217 | dim_layer->color_fill.color_2, |
| 3218 | dim_layer->color_fill.color_3); |
| 3219 | seq_puts(s, "\n"); |
| 3220 | } |
| 3221 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3222 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
| 3223 | pstate = to_sde_plane_state(plane->state); |
| 3224 | state = plane->state; |
| 3225 | |
| 3226 | if (!pstate || !state) |
| 3227 | continue; |
| 3228 | |
| 3229 | seq_printf(s, "\tplane:%u stage:%d\n", plane->base.id, |
| 3230 | pstate->stage); |
| 3231 | |
| 3232 | if (plane->state->fb) { |
| 3233 | fb = plane->state->fb; |
| 3234 | |
| 3235 | seq_printf(s, "\tfb:%d image format:%4.4s wxh:%ux%u bpp:%d\n", |
| 3236 | fb->base.id, (char *) &fb->pixel_format, |
| 3237 | fb->width, fb->height, fb->bits_per_pixel); |
| 3238 | |
| 3239 | seq_puts(s, "\t"); |
| 3240 | for (i = 0; i < ARRAY_SIZE(fb->modifier); i++) |
| 3241 | seq_printf(s, "modifier[%d]:%8llu ", i, |
| 3242 | fb->modifier[i]); |
| 3243 | seq_puts(s, "\n"); |
| 3244 | |
| 3245 | seq_puts(s, "\t"); |
| 3246 | for (i = 0; i < ARRAY_SIZE(fb->pitches); i++) |
| 3247 | seq_printf(s, "pitches[%d]:%8u ", i, |
| 3248 | fb->pitches[i]); |
| 3249 | seq_puts(s, "\n"); |
| 3250 | |
| 3251 | seq_puts(s, "\t"); |
| 3252 | for (i = 0; i < ARRAY_SIZE(fb->offsets); i++) |
| 3253 | seq_printf(s, "offsets[%d]:%8u ", i, |
| 3254 | fb->offsets[i]); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 3255 | seq_puts(s, "\n"); |
| 3256 | } |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3257 | |
| 3258 | seq_printf(s, "\tsrc_x:%4d src_y:%4d src_w:%4d src_h:%4d\n", |
| 3259 | state->src_x, state->src_y, state->src_w, state->src_h); |
| 3260 | |
| 3261 | seq_printf(s, "\tdst x:%4d dst_y:%4d dst_w:%4d dst_h:%4d\n", |
| 3262 | state->crtc_x, state->crtc_y, state->crtc_w, |
| 3263 | state->crtc_h); |
Jeykumar Sankaran | e964dc7 | 2017-05-10 19:26:43 -0700 | [diff] [blame] | 3264 | seq_printf(s, "\tmultirect: mode: %d index: %d\n", |
| 3265 | pstate->multirect_mode, pstate->multirect_index); |
Veera Sundaram Sankaran | 58e1281 | 2017-05-05 11:51:09 -0700 | [diff] [blame] | 3266 | |
| 3267 | seq_printf(s, "\texcl_rect: x:%4d y:%4d w:%4d h:%4d\n", |
| 3268 | pstate->excl_rect.x, pstate->excl_rect.y, |
| 3269 | pstate->excl_rect.w, pstate->excl_rect.h); |
| 3270 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3271 | seq_puts(s, "\n"); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3272 | } |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 3273 | |
| 3274 | if (sde_crtc->vblank_cb_count) { |
| 3275 | ktime_t diff = ktime_sub(ktime_get(), sde_crtc->vblank_cb_time); |
| 3276 | s64 diff_ms = ktime_to_ms(diff); |
| 3277 | s64 fps = diff_ms ? DIV_ROUND_CLOSEST( |
| 3278 | sde_crtc->vblank_cb_count * 1000, diff_ms) : 0; |
| 3279 | |
| 3280 | seq_printf(s, |
| 3281 | "vblank fps:%lld count:%u total:%llums\n", |
| 3282 | fps, |
| 3283 | sde_crtc->vblank_cb_count, |
| 3284 | ktime_to_ms(diff)); |
| 3285 | |
| 3286 | /* reset time & count for next measurement */ |
| 3287 | sde_crtc->vblank_cb_count = 0; |
| 3288 | sde_crtc->vblank_cb_time = ktime_set(0, 0); |
| 3289 | } |
| 3290 | |
| 3291 | seq_printf(s, "vblank_refcount:%d\n", |
| 3292 | atomic_read(&sde_crtc->vblank_refcount)); |
| 3293 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3294 | mutex_unlock(&sde_crtc->crtc_lock); |
| 3295 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3296 | return 0; |
| 3297 | } |
| 3298 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3299 | static int _sde_debugfs_status_open(struct inode *inode, struct file *file) |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3300 | { |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3301 | return single_open(file, _sde_debugfs_status_show, inode->i_private); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3302 | } |
| 3303 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3304 | static ssize_t _sde_crtc_misr_setup(struct file *file, |
| 3305 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 3306 | { |
| 3307 | struct sde_crtc *sde_crtc; |
| 3308 | struct sde_crtc_mixer *m; |
| 3309 | int i = 0, rc; |
| 3310 | char buf[MISR_BUFF_SIZE + 1]; |
| 3311 | u32 frame_count, enable; |
| 3312 | size_t buff_copy; |
| 3313 | |
| 3314 | if (!file || !file->private_data) |
| 3315 | return -EINVAL; |
| 3316 | |
| 3317 | sde_crtc = file->private_data; |
| 3318 | buff_copy = min_t(size_t, count, MISR_BUFF_SIZE); |
| 3319 | if (copy_from_user(buf, user_buf, buff_copy)) { |
| 3320 | SDE_ERROR("buffer copy failed\n"); |
| 3321 | return -EINVAL; |
| 3322 | } |
| 3323 | |
| 3324 | buf[buff_copy] = 0; /* end of string */ |
| 3325 | |
| 3326 | if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) |
| 3327 | return -EINVAL; |
| 3328 | |
| 3329 | rc = _sde_crtc_power_enable(sde_crtc, true); |
| 3330 | if (rc) |
| 3331 | return rc; |
| 3332 | |
| 3333 | mutex_lock(&sde_crtc->crtc_lock); |
| 3334 | sde_crtc->misr_enable = enable; |
| 3335 | for (i = 0; i < sde_crtc->num_mixers; ++i) { |
| 3336 | m = &sde_crtc->mixers[i]; |
| 3337 | if (!m->hw_lm) |
| 3338 | continue; |
| 3339 | |
| 3340 | m->hw_lm->ops.setup_misr(m->hw_lm, enable, frame_count); |
| 3341 | } |
| 3342 | mutex_unlock(&sde_crtc->crtc_lock); |
| 3343 | _sde_crtc_power_enable(sde_crtc, false); |
| 3344 | |
| 3345 | return count; |
| 3346 | } |
| 3347 | |
| 3348 | static ssize_t _sde_crtc_misr_read(struct file *file, |
| 3349 | char __user *user_buff, size_t count, loff_t *ppos) |
| 3350 | { |
| 3351 | struct sde_crtc *sde_crtc; |
| 3352 | struct sde_crtc_mixer *m; |
| 3353 | int i = 0, rc; |
| 3354 | ssize_t len = 0; |
| 3355 | char buf[MISR_BUFF_SIZE + 1] = {'\0'}; |
| 3356 | |
| 3357 | if (*ppos) |
| 3358 | return 0; |
| 3359 | |
| 3360 | if (!file || !file->private_data) |
| 3361 | return -EINVAL; |
| 3362 | |
| 3363 | sde_crtc = file->private_data; |
| 3364 | rc = _sde_crtc_power_enable(sde_crtc, true); |
| 3365 | if (rc) |
| 3366 | return rc; |
| 3367 | |
| 3368 | mutex_lock(&sde_crtc->crtc_lock); |
| 3369 | if (!sde_crtc->misr_enable) { |
| 3370 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, |
| 3371 | "disabled\n"); |
| 3372 | goto buff_check; |
| 3373 | } |
| 3374 | |
| 3375 | for (i = 0; i < sde_crtc->num_mixers; ++i) { |
| 3376 | m = &sde_crtc->mixers[i]; |
| 3377 | if (!m->hw_lm) |
| 3378 | continue; |
| 3379 | |
| 3380 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, "lm idx:%d\n", |
| 3381 | m->hw_lm->idx - LM_0); |
| 3382 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, "0x%x\n", |
| 3383 | m->hw_lm->ops.collect_misr(m->hw_lm)); |
| 3384 | } |
| 3385 | |
| 3386 | buff_check: |
| 3387 | if (count <= len) { |
| 3388 | len = 0; |
| 3389 | goto end; |
| 3390 | } |
| 3391 | |
| 3392 | if (copy_to_user(user_buff, buf, len)) { |
| 3393 | len = -EFAULT; |
| 3394 | goto end; |
| 3395 | } |
| 3396 | |
| 3397 | *ppos += len; /* increase offset */ |
| 3398 | |
| 3399 | end: |
| 3400 | mutex_unlock(&sde_crtc->crtc_lock); |
| 3401 | _sde_crtc_power_enable(sde_crtc, false); |
| 3402 | return len; |
| 3403 | } |
| 3404 | |
| 3405 | #define DEFINE_SDE_DEBUGFS_SEQ_FOPS(__prefix) \ |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3406 | static int __prefix ## _open(struct inode *inode, struct file *file) \ |
| 3407 | { \ |
| 3408 | return single_open(file, __prefix ## _show, inode->i_private); \ |
| 3409 | } \ |
| 3410 | static const struct file_operations __prefix ## _fops = { \ |
| 3411 | .owner = THIS_MODULE, \ |
| 3412 | .open = __prefix ## _open, \ |
| 3413 | .release = single_release, \ |
| 3414 | .read = seq_read, \ |
| 3415 | .llseek = seq_lseek, \ |
| 3416 | } |
| 3417 | |
| 3418 | static int sde_crtc_debugfs_state_show(struct seq_file *s, void *v) |
| 3419 | { |
| 3420 | struct drm_crtc *crtc = (struct drm_crtc *) s->private; |
| 3421 | struct sde_crtc_state *cstate = to_sde_crtc_state(crtc->state); |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 3422 | struct sde_crtc_res *res; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3423 | |
| 3424 | seq_printf(s, "num_connectors: %d\n", cstate->num_connectors); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 3425 | seq_printf(s, "client type: %d\n", sde_crtc_get_client_type(crtc)); |
Alan Kwong | 3e985f0 | 2017-02-12 15:08:44 -0800 | [diff] [blame] | 3426 | seq_printf(s, "intf_mode: %d\n", sde_crtc_get_intf_mode(crtc)); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 3427 | seq_printf(s, "bw_ctl: %llu\n", cstate->cur_perf.bw_ctl); |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 3428 | seq_printf(s, "core_clk_rate: %llu\n", cstate->cur_perf.core_clk_rate); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 3429 | seq_printf(s, "max_per_pipe_ib: %llu\n", |
| 3430 | cstate->cur_perf.max_per_pipe_ib); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3431 | |
Alan Kwong | cdb2f28 | 2017-03-18 13:42:06 -0700 | [diff] [blame] | 3432 | seq_printf(s, "rp.%d: ", cstate->rp.sequence_id); |
| 3433 | list_for_each_entry(res, &cstate->rp.res_list, list) |
| 3434 | seq_printf(s, "0x%x/0x%llx/%pK/%d ", |
| 3435 | res->type, res->tag, res->val, |
| 3436 | atomic_read(&res->refcount)); |
| 3437 | seq_puts(s, "\n"); |
| 3438 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3439 | return 0; |
| 3440 | } |
| 3441 | DEFINE_SDE_DEBUGFS_SEQ_FOPS(sde_crtc_debugfs_state); |
| 3442 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3443 | static int _sde_crtc_init_debugfs(struct drm_crtc *crtc) |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3444 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3445 | struct sde_crtc *sde_crtc; |
| 3446 | struct sde_kms *sde_kms; |
| 3447 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 3448 | static const struct file_operations debugfs_status_fops = { |
| 3449 | .open = _sde_debugfs_status_open, |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3450 | .read = seq_read, |
| 3451 | .llseek = seq_lseek, |
| 3452 | .release = single_release, |
| 3453 | }; |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3454 | static const struct file_operations debugfs_misr_fops = { |
| 3455 | .open = simple_open, |
| 3456 | .read = _sde_crtc_misr_read, |
| 3457 | .write = _sde_crtc_misr_setup, |
| 3458 | }; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3459 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3460 | if (!crtc) |
| 3461 | return -EINVAL; |
| 3462 | sde_crtc = to_sde_crtc(crtc); |
| 3463 | |
| 3464 | sde_kms = _sde_crtc_get_kms(crtc); |
| 3465 | if (!sde_kms) |
| 3466 | return -EINVAL; |
| 3467 | |
| 3468 | sde_crtc->debugfs_root = debugfs_create_dir(sde_crtc->name, |
Lloyd Atkinson | 09e64bf | 2017-04-13 14:09:59 -0700 | [diff] [blame] | 3469 | crtc->dev->primary->debugfs_root); |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3470 | if (!sde_crtc->debugfs_root) |
| 3471 | return -ENOMEM; |
| 3472 | |
| 3473 | /* don't error check these */ |
| 3474 | debugfs_create_file("status", 0444, |
| 3475 | sde_crtc->debugfs_root, |
| 3476 | sde_crtc, &debugfs_status_fops); |
| 3477 | debugfs_create_file("state", 0644, |
| 3478 | sde_crtc->debugfs_root, |
| 3479 | &sde_crtc->base, |
| 3480 | &sde_crtc_debugfs_state_fops); |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3481 | debugfs_create_file("misr_data", 0644, sde_crtc->debugfs_root, |
| 3482 | sde_crtc, &debugfs_misr_fops); |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3483 | |
| 3484 | return 0; |
| 3485 | } |
| 3486 | |
| 3487 | static void _sde_crtc_destroy_debugfs(struct drm_crtc *crtc) |
| 3488 | { |
| 3489 | struct sde_crtc *sde_crtc; |
| 3490 | |
| 3491 | if (!crtc) |
| 3492 | return; |
| 3493 | sde_crtc = to_sde_crtc(crtc); |
| 3494 | debugfs_remove_recursive(sde_crtc->debugfs_root); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3495 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3496 | #else |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3497 | static int _sde_crtc_init_debugfs(struct drm_crtc *crtc) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3498 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3499 | return 0; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 3500 | } |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3501 | |
| 3502 | static void _sde_crtc_destroy_debugfs(struct drm_crtc *crtc) |
| 3503 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3504 | } |
| 3505 | #endif /* CONFIG_DEBUG_FS */ |
| 3506 | |
| 3507 | static int sde_crtc_late_register(struct drm_crtc *crtc) |
| 3508 | { |
| 3509 | return _sde_crtc_init_debugfs(crtc); |
| 3510 | } |
| 3511 | |
| 3512 | static void sde_crtc_early_unregister(struct drm_crtc *crtc) |
| 3513 | { |
| 3514 | _sde_crtc_destroy_debugfs(crtc); |
| 3515 | } |
| 3516 | |
| 3517 | static const struct drm_crtc_funcs sde_crtc_funcs = { |
| 3518 | .set_config = drm_atomic_helper_set_config, |
| 3519 | .destroy = sde_crtc_destroy, |
| 3520 | .page_flip = drm_atomic_helper_page_flip, |
| 3521 | .set_property = sde_crtc_set_property, |
| 3522 | .atomic_set_property = sde_crtc_atomic_set_property, |
| 3523 | .atomic_get_property = sde_crtc_atomic_get_property, |
| 3524 | .reset = sde_crtc_reset, |
| 3525 | .atomic_duplicate_state = sde_crtc_duplicate_state, |
| 3526 | .atomic_destroy_state = sde_crtc_destroy_state, |
| 3527 | .late_register = sde_crtc_late_register, |
| 3528 | .early_unregister = sde_crtc_early_unregister, |
| 3529 | }; |
| 3530 | |
| 3531 | static const struct drm_crtc_helper_funcs sde_crtc_helper_funcs = { |
| 3532 | .mode_fixup = sde_crtc_mode_fixup, |
| 3533 | .disable = sde_crtc_disable, |
| 3534 | .enable = sde_crtc_enable, |
| 3535 | .atomic_check = sde_crtc_atomic_check, |
| 3536 | .atomic_begin = sde_crtc_atomic_begin, |
| 3537 | .atomic_flush = sde_crtc_atomic_flush, |
| 3538 | }; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3539 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3540 | static void _sde_crtc_event_cb(struct kthread_work *work) |
| 3541 | { |
| 3542 | struct sde_crtc_event *event; |
| 3543 | struct sde_crtc *sde_crtc; |
| 3544 | unsigned long irq_flags; |
| 3545 | |
| 3546 | if (!work) { |
| 3547 | SDE_ERROR("invalid work item\n"); |
| 3548 | return; |
| 3549 | } |
| 3550 | |
| 3551 | event = container_of(work, struct sde_crtc_event, kt_work); |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3552 | |
| 3553 | /* set sde_crtc to NULL for static work structures */ |
| 3554 | sde_crtc = event->sde_crtc; |
| 3555 | if (!sde_crtc) |
| 3556 | return; |
| 3557 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3558 | if (event->cb_func) |
| 3559 | event->cb_func(&sde_crtc->base, event->usr); |
| 3560 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3561 | spin_lock_irqsave(&sde_crtc->event_lock, irq_flags); |
| 3562 | list_add_tail(&event->list, &sde_crtc->event_free_list); |
| 3563 | spin_unlock_irqrestore(&sde_crtc->event_lock, irq_flags); |
| 3564 | } |
| 3565 | |
| 3566 | int sde_crtc_event_queue(struct drm_crtc *crtc, |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3567 | void (*func)(struct drm_crtc *crtc, void *usr), void *usr) |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3568 | { |
| 3569 | unsigned long irq_flags; |
| 3570 | struct sde_crtc *sde_crtc; |
| 3571 | struct sde_crtc_event *event = NULL; |
| 3572 | |
| 3573 | if (!crtc || !func) |
| 3574 | return -EINVAL; |
| 3575 | sde_crtc = to_sde_crtc(crtc); |
| 3576 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3577 | if (!sde_crtc->event_thread) |
| 3578 | return -EINVAL; |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3579 | /* |
| 3580 | * Obtain an event struct from the private cache. This event |
| 3581 | * queue may be called from ISR contexts, so use a private |
| 3582 | * cache to avoid calling any memory allocation functions. |
| 3583 | */ |
| 3584 | spin_lock_irqsave(&sde_crtc->event_lock, irq_flags); |
| 3585 | if (!list_empty(&sde_crtc->event_free_list)) { |
| 3586 | event = list_first_entry(&sde_crtc->event_free_list, |
| 3587 | struct sde_crtc_event, list); |
| 3588 | list_del_init(&event->list); |
| 3589 | } |
| 3590 | spin_unlock_irqrestore(&sde_crtc->event_lock, irq_flags); |
| 3591 | |
| 3592 | if (!event) |
| 3593 | return -ENOMEM; |
| 3594 | |
| 3595 | /* populate event node */ |
| 3596 | event->sde_crtc = sde_crtc; |
| 3597 | event->cb_func = func; |
| 3598 | event->usr = usr; |
| 3599 | |
| 3600 | /* queue new event request */ |
| 3601 | kthread_init_work(&event->kt_work, _sde_crtc_event_cb); |
| 3602 | kthread_queue_work(&sde_crtc->event_worker, &event->kt_work); |
| 3603 | |
| 3604 | return 0; |
| 3605 | } |
| 3606 | |
| 3607 | static int _sde_crtc_init_events(struct sde_crtc *sde_crtc) |
| 3608 | { |
| 3609 | int i, rc = 0; |
| 3610 | |
| 3611 | if (!sde_crtc) { |
| 3612 | SDE_ERROR("invalid crtc\n"); |
| 3613 | return -EINVAL; |
| 3614 | } |
| 3615 | |
| 3616 | spin_lock_init(&sde_crtc->event_lock); |
| 3617 | |
| 3618 | INIT_LIST_HEAD(&sde_crtc->event_free_list); |
| 3619 | for (i = 0; i < SDE_CRTC_MAX_EVENT_COUNT; ++i) |
| 3620 | list_add_tail(&sde_crtc->event_cache[i].list, |
| 3621 | &sde_crtc->event_free_list); |
| 3622 | |
| 3623 | kthread_init_worker(&sde_crtc->event_worker); |
| 3624 | sde_crtc->event_thread = kthread_run(kthread_worker_fn, |
| 3625 | &sde_crtc->event_worker, "crtc_event:%d", |
| 3626 | sde_crtc->base.base.id); |
| 3627 | |
| 3628 | if (IS_ERR_OR_NULL(sde_crtc->event_thread)) { |
| 3629 | SDE_ERROR("failed to create event thread\n"); |
| 3630 | rc = PTR_ERR(sde_crtc->event_thread); |
| 3631 | sde_crtc->event_thread = NULL; |
| 3632 | } |
| 3633 | |
| 3634 | return rc; |
| 3635 | } |
| 3636 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3637 | /* initialize crtc */ |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 3638 | struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3639 | { |
| 3640 | struct drm_crtc *crtc = NULL; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3641 | struct sde_crtc *sde_crtc = NULL; |
| 3642 | struct msm_drm_private *priv = NULL; |
| 3643 | struct sde_kms *kms = NULL; |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3644 | int i, rc; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3645 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3646 | priv = dev->dev_private; |
| 3647 | kms = to_sde_kms(priv->kms); |
| 3648 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3649 | sde_crtc = kzalloc(sizeof(*sde_crtc), GFP_KERNEL); |
| 3650 | if (!sde_crtc) |
| 3651 | return ERR_PTR(-ENOMEM); |
| 3652 | |
| 3653 | crtc = &sde_crtc->base; |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3654 | crtc->dev = dev; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 3655 | atomic_set(&sde_crtc->vblank_refcount, 0); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3656 | |
Clarence Ip | 7f70ce4 | 2017-03-20 06:53:46 -0700 | [diff] [blame] | 3657 | mutex_init(&sde_crtc->crtc_lock); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3658 | spin_lock_init(&sde_crtc->spin_lock); |
| 3659 | atomic_set(&sde_crtc->frame_pending, 0); |
| 3660 | |
| 3661 | INIT_LIST_HEAD(&sde_crtc->frame_event_list); |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 3662 | INIT_LIST_HEAD(&sde_crtc->user_event_list); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3663 | for (i = 0; i < ARRAY_SIZE(sde_crtc->frame_events); i++) { |
| 3664 | INIT_LIST_HEAD(&sde_crtc->frame_events[i].list); |
| 3665 | list_add(&sde_crtc->frame_events[i].list, |
| 3666 | &sde_crtc->frame_event_list); |
| 3667 | kthread_init_work(&sde_crtc->frame_events[i].work, |
| 3668 | sde_crtc_frame_event_work); |
| 3669 | } |
| 3670 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 3671 | drm_crtc_init_with_planes(dev, crtc, plane, NULL, &sde_crtc_funcs, |
| 3672 | NULL); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3673 | |
| 3674 | drm_crtc_helper_add(crtc, &sde_crtc_helper_funcs); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3675 | plane->crtc = crtc; |
| 3676 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 3677 | /* save user friendly CRTC name for later */ |
| 3678 | snprintf(sde_crtc->name, SDE_CRTC_NAME_SIZE, "crtc%u", crtc->base.id); |
| 3679 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 3680 | /* initialize event handling */ |
| 3681 | rc = _sde_crtc_init_events(sde_crtc); |
| 3682 | if (rc) { |
| 3683 | drm_crtc_cleanup(crtc); |
| 3684 | kfree(sde_crtc); |
| 3685 | return ERR_PTR(rc); |
| 3686 | } |
| 3687 | |
Clarence Ip | 9a74a44 | 2016-08-25 18:29:03 -0400 | [diff] [blame] | 3688 | /* initialize output fence support */ |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 3689 | sde_fence_init(&sde_crtc->output_fence, sde_crtc->name, crtc->base.id); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 3690 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3691 | /* create CRTC properties */ |
| 3692 | msm_property_init(&sde_crtc->property_info, &crtc->base, dev, |
| 3693 | priv->crtc_property, sde_crtc->property_data, |
| 3694 | CRTC_PROP_COUNT, CRTC_PROP_BLOBCOUNT, |
| 3695 | sizeof(struct sde_crtc_state)); |
| 3696 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 3697 | sde_crtc_install_properties(crtc, kms->catalog); |
Gopikrishnaiah Anandan | 703eb90 | 2016-10-06 18:43:57 -0700 | [diff] [blame] | 3698 | |
| 3699 | /* Install color processing properties */ |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 3700 | sde_cp_crtc_init(crtc); |
Gopikrishnaiah Anandan | 703eb90 | 2016-10-06 18:43:57 -0700 | [diff] [blame] | 3701 | sde_cp_crtc_install_properties(crtc); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 3702 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 3703 | SDE_DEBUG("%s: successfully initialized crtc\n", sde_crtc->name); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3704 | return crtc; |
| 3705 | } |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 3706 | |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3707 | static int _sde_crtc_event_enable(struct sde_kms *kms, |
| 3708 | struct drm_crtc *crtc_drm, u32 event) |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 3709 | { |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3710 | struct sde_crtc *crtc = NULL; |
| 3711 | struct sde_crtc_irq_info *node; |
| 3712 | struct msm_drm_private *priv; |
| 3713 | unsigned long flags; |
| 3714 | bool found = false; |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3715 | int ret, i = 0; |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3716 | |
| 3717 | crtc = to_sde_crtc(crtc_drm); |
| 3718 | spin_lock_irqsave(&crtc->spin_lock, flags); |
| 3719 | list_for_each_entry(node, &crtc->user_event_list, list) { |
| 3720 | if (node->event == event) { |
| 3721 | found = true; |
| 3722 | break; |
| 3723 | } |
| 3724 | } |
| 3725 | spin_unlock_irqrestore(&crtc->spin_lock, flags); |
| 3726 | |
| 3727 | /* event already enabled */ |
| 3728 | if (found) |
| 3729 | return 0; |
| 3730 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3731 | node = NULL; |
| 3732 | for (i = 0; i < ARRAY_SIZE(custom_events); i++) { |
| 3733 | if (custom_events[i].event == event && |
| 3734 | custom_events[i].func) { |
| 3735 | node = kzalloc(sizeof(*node), GFP_KERNEL); |
| 3736 | if (!node) |
| 3737 | return -ENOMEM; |
| 3738 | node->event = event; |
| 3739 | INIT_LIST_HEAD(&node->list); |
| 3740 | node->func = custom_events[i].func; |
| 3741 | node->event = event; |
| 3742 | break; |
| 3743 | } |
| 3744 | } |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3745 | |
Gopikrishnaiah Anandan | b6b401f | 2017-03-14 16:39:49 -0700 | [diff] [blame] | 3746 | if (!node) { |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3747 | SDE_ERROR("unsupported event %x\n", event); |
Gopikrishnaiah Anandan | 5154c71 | 2017-02-27 17:48:24 -0800 | [diff] [blame] | 3748 | return -EINVAL; |
| 3749 | } |
| 3750 | |
| 3751 | priv = kms->dev->dev_private; |
| 3752 | ret = 0; |
| 3753 | if (crtc_drm->enabled) { |
| 3754 | sde_power_resource_enable(&priv->phandle, kms->core_client, |
| 3755 | true); |
| 3756 | ret = node->func(crtc_drm, true, &node->irq); |
| 3757 | sde_power_resource_enable(&priv->phandle, kms->core_client, |
| 3758 | false); |
| 3759 | } |
| 3760 | |
| 3761 | if (!ret) { |
| 3762 | spin_lock_irqsave(&crtc->spin_lock, flags); |
| 3763 | list_add_tail(&node->list, &crtc->user_event_list); |
| 3764 | spin_unlock_irqrestore(&crtc->spin_lock, flags); |
| 3765 | } else { |
| 3766 | kfree(node); |
| 3767 | } |
| 3768 | |
| 3769 | return ret; |
| 3770 | } |
| 3771 | |
| 3772 | static int _sde_crtc_event_disable(struct sde_kms *kms, |
| 3773 | struct drm_crtc *crtc_drm, u32 event) |
| 3774 | { |
| 3775 | struct sde_crtc *crtc = NULL; |
| 3776 | struct sde_crtc_irq_info *node = NULL; |
| 3777 | struct msm_drm_private *priv; |
| 3778 | unsigned long flags; |
| 3779 | bool found = false; |
| 3780 | int ret; |
| 3781 | |
| 3782 | crtc = to_sde_crtc(crtc_drm); |
| 3783 | spin_lock_irqsave(&crtc->spin_lock, flags); |
| 3784 | list_for_each_entry(node, &crtc->user_event_list, list) { |
| 3785 | if (node->event == event) { |
| 3786 | list_del(&node->list); |
| 3787 | found = true; |
| 3788 | break; |
| 3789 | } |
| 3790 | } |
| 3791 | spin_unlock_irqrestore(&crtc->spin_lock, flags); |
| 3792 | |
| 3793 | /* event already disabled */ |
| 3794 | if (!found) |
| 3795 | return 0; |
| 3796 | |
| 3797 | /** |
| 3798 | * crtc is disabled interrupts are cleared remove from the list, |
| 3799 | * no need to disable/de-register. |
| 3800 | */ |
| 3801 | if (!crtc_drm->enabled) { |
| 3802 | kfree(node); |
| 3803 | return 0; |
| 3804 | } |
| 3805 | priv = kms->dev->dev_private; |
| 3806 | sde_power_resource_enable(&priv->phandle, kms->core_client, true); |
| 3807 | ret = node->func(crtc_drm, false, &node->irq); |
| 3808 | sde_power_resource_enable(&priv->phandle, kms->core_client, false); |
| 3809 | return ret; |
| 3810 | } |
| 3811 | |
| 3812 | int sde_crtc_register_custom_event(struct sde_kms *kms, |
| 3813 | struct drm_crtc *crtc_drm, u32 event, bool en) |
| 3814 | { |
| 3815 | struct sde_crtc *crtc = NULL; |
| 3816 | int ret; |
| 3817 | |
| 3818 | crtc = to_sde_crtc(crtc_drm); |
| 3819 | if (!crtc || !kms || !kms->dev) { |
| 3820 | DRM_ERROR("invalid sde_crtc %pK kms %pK dev %pK\n", crtc, |
| 3821 | kms, ((kms) ? (kms->dev) : NULL)); |
| 3822 | return -EINVAL; |
| 3823 | } |
| 3824 | |
| 3825 | if (en) |
| 3826 | ret = _sde_crtc_event_enable(kms, crtc_drm, event); |
| 3827 | else |
| 3828 | ret = _sde_crtc_event_disable(kms, crtc_drm, event); |
| 3829 | |
| 3830 | return ret; |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 3831 | } |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 3832 | |
| 3833 | static int sde_crtc_power_interrupt_handler(struct drm_crtc *crtc_drm, |
| 3834 | bool en, struct sde_irq_callback *irq) |
| 3835 | { |
| 3836 | return 0; |
| 3837 | } |