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