Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-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 | |
| 19 | #ifndef __SDE_KMS_H__ |
| 20 | #define __SDE_KMS_H__ |
| 21 | |
Alan Kwong | 54125bb | 2017-02-26 16:01:36 -0800 | [diff] [blame] | 22 | #include <linux/msm_ion.h> |
Alan Kwong | 23afc2d9 | 2017-09-15 10:59:06 -0400 | [diff] [blame] | 23 | #include <linux/pm_domain.h> |
Lloyd Atkinson | 1fb32ea | 2017-10-10 17:10:28 -0400 | [diff] [blame] | 24 | #include <linux/pm_qos.h> |
Alan Kwong | 54125bb | 2017-02-26 16:01:36 -0800 | [diff] [blame] | 25 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 26 | #include "msm_drv.h" |
| 27 | #include "msm_kms.h" |
Alan Kwong | 112a84f | 2016-05-24 20:49:21 -0400 | [diff] [blame] | 28 | #include "msm_mmu.h" |
Jordan Crouse | 12bf362 | 2017-02-13 10:14:11 -0700 | [diff] [blame] | 29 | #include "msm_gem.h" |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 30 | #include "sde_dbg.h" |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 31 | #include "sde_hw_catalog.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 32 | #include "sde_hw_ctl.h" |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 33 | #include "sde_hw_lm.h" |
Shashank Babu Chinta Venkata | 5d641d4 | 2017-09-29 12:16:28 -0700 | [diff] [blame] | 34 | #include "sde_hw_pingpong.h" |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 35 | #include "sde_hw_interrupts.h" |
Alan Kwong | d21960f | 2016-07-29 03:33:17 -0400 | [diff] [blame] | 36 | #include "sde_hw_wb.h" |
| 37 | #include "sde_hw_top.h" |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 38 | #include "sde_rm.h" |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 39 | #include "sde_power_handle.h" |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 40 | #include "sde_irq.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 41 | #include "sde_core_perf.h" |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 42 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 43 | #define DRMID(x) ((x) ? (x)->base.id : -1) |
| 44 | |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 45 | /** |
| 46 | * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs |
| 47 | * @fmt: Pointer to format string |
| 48 | */ |
| 49 | #define SDE_DEBUG(fmt, ...) \ |
| 50 | do { \ |
| 51 | if (unlikely(drm_debug & DRM_UT_KMS)) \ |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 52 | DRM_DEBUG(fmt, ##__VA_ARGS__); \ |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 53 | else \ |
| 54 | pr_debug(fmt, ##__VA_ARGS__); \ |
| 55 | } while (0) |
| 56 | |
| 57 | /** |
| 58 | * SDE_DEBUG_DRIVER - macro for hardware driver logging |
| 59 | * @fmt: Pointer to format string |
| 60 | */ |
| 61 | #define SDE_DEBUG_DRIVER(fmt, ...) \ |
| 62 | do { \ |
| 63 | if (unlikely(drm_debug & DRM_UT_DRIVER)) \ |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 64 | DRM_ERROR(fmt, ##__VA_ARGS__); \ |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 65 | else \ |
| 66 | pr_debug(fmt, ##__VA_ARGS__); \ |
| 67 | } while (0) |
| 68 | |
Dhaval Patel | b271b84 | 2016-10-19 21:41:22 -0700 | [diff] [blame] | 69 | #define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__) |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 70 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 71 | #define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \ |
| 72 | do { \ |
| 73 | (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \ |
| 74 | (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \ |
| 75 | (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \ |
| 76 | (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \ |
| 77 | } while (0) |
| 78 | |
| 79 | #define CHECK_LAYER_BOUNDS(offset, size, max_size) \ |
| 80 | (((size) > (max_size)) || ((offset) > ((max_size) - (size)))) |
| 81 | |
Clarence Ip | fd96ba2 | 2016-09-09 16:45:44 -0400 | [diff] [blame] | 82 | /** |
| 83 | * ktime_compare_safe - compare two ktime structures |
| 84 | * This macro is similar to the standard ktime_compare() function, but |
| 85 | * attempts to also handle ktime overflows. |
| 86 | * @A: First ktime value |
| 87 | * @B: Second ktime value |
| 88 | * Returns: -1 if A < B, 0 if A == B, 1 if A > B |
| 89 | */ |
| 90 | #define ktime_compare_safe(A, B) \ |
| 91 | ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0)) |
| 92 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 93 | #define SDE_NAME_SIZE 12 |
| 94 | |
Veera Sundaram Sankaran | 7ee9909 | 2017-06-13 11:19:36 -0700 | [diff] [blame] | 95 | /* timeout in frames waiting for frame done */ |
| 96 | #define SDE_FRAME_DONE_TIMEOUT 60 |
| 97 | |
Abhijit Kulkarni | 7444a7d | 2017-06-21 18:53:36 -0700 | [diff] [blame] | 98 | /* max active secure client counts allowed */ |
| 99 | #define MAX_ALLOWED_SECURE_CLIENT_CNT 1 |
| 100 | |
| 101 | /* max active crtc when secure client is active */ |
| 102 | #define MAX_ALLOWED_CRTC_CNT_DURING_SECURE 1 |
| 103 | |
| 104 | /* max virtual encoders per secure crtc */ |
| 105 | #define MAX_ALLOWED_ENCODER_CNT_PER_SECURE_CRTC 1 |
| 106 | |
Abhijit Kulkarni | 1b3340c | 2017-06-22 12:39:37 -0700 | [diff] [blame] | 107 | /* defines the operations required for secure state transition */ |
| 108 | #define SDE_KMS_OPS_CRTC_SECURE_STATE_CHANGE BIT(0) |
| 109 | #define SDE_KMS_OPS_WAIT_FOR_TX_DONE BIT(1) |
| 110 | #define SDE_KMS_OPS_CLEANUP_PLANE_FB BIT(2) |
| 111 | #define SDE_KMS_OPS_PREPARE_PLANE_FB BIT(3) |
| 112 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 113 | /* ESD status check interval in miliseconds */ |
| 114 | #define STATUS_CHECK_INTERVAL_MS 5000 |
| 115 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 116 | /* |
| 117 | * struct sde_irq_callback - IRQ callback handlers |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 118 | * @list: list to callback |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 119 | * @func: intr handler |
| 120 | * @arg: argument for the handler |
| 121 | */ |
| 122 | struct sde_irq_callback { |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 123 | struct list_head list; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 124 | void (*func)(void *arg, int irq_idx); |
| 125 | void *arg; |
| 126 | }; |
| 127 | |
| 128 | /** |
| 129 | * struct sde_irq: IRQ structure contains callback registration info |
| 130 | * @total_irq: total number of irq_idx obtained from HW interrupts mapping |
| 131 | * @irq_cb_tbl: array of IRQ callbacks setting |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 132 | * @enable_counts array of IRQ enable counts |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 133 | * @cb_lock: callback lock |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 134 | * @debugfs_file: debugfs file for irq statistics |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 135 | */ |
| 136 | struct sde_irq { |
| 137 | u32 total_irqs; |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 138 | struct list_head *irq_cb_tbl; |
| 139 | atomic_t *enable_counts; |
| 140 | atomic_t *irq_counts; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 141 | spinlock_t cb_lock; |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 142 | struct dentry *debugfs_file; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 143 | }; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 144 | |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 145 | /** |
| 146 | * struct sde_kms_fbo - framebuffer memory object |
| 147 | * @refcount: reference/usage count of this object |
| 148 | * @dev: Pointer to containing drm device |
| 149 | * @width: width of the framebuffer |
| 150 | * @height: height of the framebuffer |
| 151 | * @flags: drm framebuffer flags |
| 152 | * @modifier: pixel format modifier of the framebuffer |
| 153 | * @fmt: Pointer to sde format descriptor |
| 154 | * @layout: sde format layout descriptor |
| 155 | * @ihandle: framebuffer object ion handle |
| 156 | * @dma_buf: framebuffer object dma buffer |
| 157 | * @bo: per plane buffer object |
| 158 | * @fb_list: llist of fb created from this buffer object |
| 159 | */ |
| 160 | struct sde_kms_fbo { |
| 161 | atomic_t refcount; |
| 162 | struct drm_device *dev; |
| 163 | u32 width, height; |
| 164 | u32 pixel_format; |
| 165 | u32 flags; |
| 166 | u64 modifier[4]; |
| 167 | int nplane; |
| 168 | const struct sde_format *fmt; |
| 169 | struct sde_hw_fmt_layout layout; |
Alan Kwong | 54125bb | 2017-02-26 16:01:36 -0800 | [diff] [blame] | 170 | struct ion_handle *ihandle; |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 171 | struct dma_buf *dma_buf; |
| 172 | struct drm_gem_object *bo[4]; |
| 173 | struct list_head fb_list; |
| 174 | }; |
| 175 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 176 | struct sde_kms { |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 177 | struct msm_kms base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 178 | struct drm_device *dev; |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 179 | int core_rev; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 180 | struct sde_mdss_cfg *catalog; |
| 181 | |
Alan Kwong | 23afc2d9 | 2017-09-15 10:59:06 -0400 | [diff] [blame] | 182 | struct generic_pm_domain genpd; |
| 183 | bool genpd_init; |
| 184 | |
Jordan Crouse | 12bf362 | 2017-02-13 10:14:11 -0700 | [diff] [blame] | 185 | struct msm_gem_address_space *aspace[MSM_SMMU_DOMAIN_MAX]; |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 186 | struct sde_power_client *core_client; |
Lloyd Atkinson | 1fb32ea | 2017-10-10 17:10:28 -0400 | [diff] [blame] | 187 | struct pm_qos_request pm_qos_cpu_req; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 188 | |
Alan Kwong | 54125bb | 2017-02-26 16:01:36 -0800 | [diff] [blame] | 189 | struct ion_client *iclient; |
Clarence Ip | 7f0de63 | 2017-05-31 14:59:14 -0400 | [diff] [blame] | 190 | struct sde_power_event *power_event; |
Alan Kwong | 54125bb | 2017-02-26 16:01:36 -0800 | [diff] [blame] | 191 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 192 | /* directory entry for debugfs */ |
Alan Kwong | f0fd851 | 2016-10-24 21:39:26 -0400 | [diff] [blame] | 193 | struct dentry *debugfs_danger; |
Alan Kwong | 748e833d | 2016-10-26 12:34:48 -0400 | [diff] [blame] | 194 | struct dentry *debugfs_vbif; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 195 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 196 | /* io/register spaces: */ |
Gopikrishnaiah Anandan | 7e3e3f5 | 2016-12-22 11:13:05 -0800 | [diff] [blame] | 197 | void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma; |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 198 | unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 199 | |
| 200 | struct regulator *vdd; |
| 201 | struct regulator *mmagic; |
| 202 | struct regulator *venus; |
| 203 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 204 | struct sde_irq_controller irq_controller; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 205 | |
| 206 | struct sde_hw_intr *hw_intr; |
| 207 | struct sde_irq irq_obj; |
Alan Kwong | 9485ecc | 2017-10-06 18:09:38 -0400 | [diff] [blame] | 208 | int irq_num; /* mdss irq number */ |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 209 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 210 | struct sde_core_perf perf; |
| 211 | |
Clarence Ip | d86f6e4 | 2017-08-08 18:31:00 -0400 | [diff] [blame] | 212 | /* saved atomic state during system suspend */ |
| 213 | struct drm_atomic_state *suspend_state; |
| 214 | bool suspend_block; |
| 215 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 216 | struct sde_rm rm; |
Clarence Ip | 17162b5 | 2016-11-24 17:06:29 -0500 | [diff] [blame] | 217 | bool rm_init; |
Shashank Babu Chinta Venkata | 5d641d4 | 2017-09-29 12:16:28 -0700 | [diff] [blame] | 218 | struct sde_splash_data splash_data; |
| 219 | bool cont_splash_en; |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 220 | struct sde_hw_vbif *hw_vbif[VBIF_MAX]; |
| 221 | struct sde_hw_mdp *hw_mdp; |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 222 | int dsi_display_count; |
| 223 | void **dsi_displays; |
| 224 | int wb_display_count; |
| 225 | void **wb_displays; |
Padmanabhan Komanduru | 6375861 | 2017-05-23 01:47:18 -0700 | [diff] [blame] | 226 | int dp_display_count; |
| 227 | void **dp_displays; |
Alan Kwong | f0fd851 | 2016-10-24 21:39:26 -0400 | [diff] [blame] | 228 | |
| 229 | bool has_danger_ctrl; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | struct vsync_info { |
| 233 | u32 frame_count; |
| 234 | u32 line_count; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | #define to_sde_kms(x) container_of(x, struct sde_kms, base) |
| 238 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 239 | /** |
Clarence Ip | dd39524 | 2016-09-09 10:47:17 -0400 | [diff] [blame] | 240 | * sde_is_custom_client - whether or not to enable non-standard customizations |
| 241 | * |
| 242 | * Return: Whether or not the 'sdeclient' module parameter was set on boot up |
| 243 | */ |
| 244 | bool sde_is_custom_client(void); |
| 245 | |
| 246 | /** |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 247 | * sde_kms_power_resource_is_enabled - whether or not power resource is enabled |
| 248 | * @dev: Pointer to drm device |
| 249 | * Return: true if power resource is enabled; false otherwise |
| 250 | */ |
| 251 | static inline bool sde_kms_power_resource_is_enabled(struct drm_device *dev) |
| 252 | { |
| 253 | struct msm_drm_private *priv; |
| 254 | |
| 255 | if (!dev || !dev->dev_private) |
| 256 | return false; |
| 257 | |
| 258 | priv = dev->dev_private; |
| 259 | |
| 260 | return sde_power_resource_is_enabled(&priv->phandle); |
| 261 | } |
| 262 | |
| 263 | /** |
Clarence Ip | d86f6e4 | 2017-08-08 18:31:00 -0400 | [diff] [blame] | 264 | * sde_kms_is_suspend_state - whether or not the system is pm suspended |
| 265 | * @dev: Pointer to drm device |
| 266 | * Return: Suspend status |
| 267 | */ |
| 268 | static inline bool sde_kms_is_suspend_state(struct drm_device *dev) |
| 269 | { |
| 270 | if (!ddev_to_msm_kms(dev)) |
| 271 | return false; |
| 272 | |
| 273 | return to_sde_kms(ddev_to_msm_kms(dev))->suspend_state != NULL; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * sde_kms_is_suspend_blocked - whether or not commits are blocked due to pm |
| 278 | * suspend status |
| 279 | * @dev: Pointer to drm device |
| 280 | * Return: True if commits should be rejected due to pm suspend |
| 281 | */ |
| 282 | static inline bool sde_kms_is_suspend_blocked(struct drm_device *dev) |
| 283 | { |
| 284 | if (!sde_kms_is_suspend_state(dev)) |
| 285 | return false; |
| 286 | |
| 287 | return to_sde_kms(ddev_to_msm_kms(dev))->suspend_block; |
| 288 | } |
| 289 | |
| 290 | /** |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 291 | * Debugfs functions - extra helper functions for debugfs support |
| 292 | * |
| 293 | * Main debugfs documentation is located at, |
| 294 | * |
| 295 | * Documentation/filesystems/debugfs.txt |
| 296 | * |
| 297 | * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32 |
| 298 | * @sde_debugfs_create_regset32: Create 32-bit register dump file |
| 299 | * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node |
| 300 | */ |
| 301 | |
| 302 | /** |
| 303 | * Companion structure for sde_debugfs_create_regset32. Do not initialize the |
| 304 | * members of this structure explicitly; use sde_debugfs_setup_regset32 instead. |
| 305 | */ |
| 306 | struct sde_debugfs_regset32 { |
| 307 | uint32_t offset; |
| 308 | uint32_t blk_len; |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 309 | struct sde_kms *sde_kms; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | /** |
| 313 | * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs |
| 314 | * This function is meant to initialize sde_debugfs_regset32 structures for use |
| 315 | * with sde_debugfs_create_regset32. |
| 316 | * @regset: opaque register definition structure |
| 317 | * @offset: sub-block offset |
| 318 | * @length: sub-block length, in bytes |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 319 | * @sde_kms: pointer to sde kms structure |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 320 | */ |
| 321 | void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset, |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 322 | uint32_t offset, uint32_t length, struct sde_kms *sde_kms); |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * sde_debugfs_create_regset32 - Create register read back file for debugfs |
| 326 | * |
| 327 | * This function is almost identical to the standard debugfs_create_regset32() |
| 328 | * function, with the main difference being that a list of register |
| 329 | * names/offsets do not need to be provided. The 'read' function simply outputs |
| 330 | * sequential register values over a specified range. |
| 331 | * |
| 332 | * Similar to the related debugfs_create_regset32 API, the structure pointed to |
| 333 | * by regset needs to persist for the lifetime of the created file. The calling |
| 334 | * code is responsible for initialization/management of this structure. |
| 335 | * |
| 336 | * The structure pointed to by regset is meant to be opaque. Please use |
| 337 | * sde_debugfs_setup_regset32 to initialize it. |
| 338 | * |
| 339 | * @name: File name within debugfs |
| 340 | * @mode: File mode within debugfs |
| 341 | * @parent: Parent directory entry within debugfs, can be NULL |
| 342 | * @regset: Pointer to persistent register block definition |
| 343 | * |
| 344 | * Return: dentry pointer for newly created file, use either debugfs_remove() |
| 345 | * or debugfs_remove_recursive() (on a parent directory) to remove the |
| 346 | * file |
| 347 | */ |
| 348 | void *sde_debugfs_create_regset32(const char *name, umode_t mode, |
| 349 | void *parent, struct sde_debugfs_regset32 *regset); |
| 350 | |
| 351 | /** |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 352 | * sde_debugfs_get_root - Return root directory entry for KMS's debugfs |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 353 | * |
| 354 | * The return value should be passed as the 'parent' argument to subsequent |
| 355 | * debugfs create calls. |
| 356 | * |
| 357 | * @sde_kms: Pointer to SDE's KMS structure |
| 358 | * |
| 359 | * Return: dentry pointer for SDE's debugfs location |
| 360 | */ |
| 361 | void *sde_debugfs_get_root(struct sde_kms *sde_kms); |
| 362 | |
| 363 | /** |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 364 | * SDE info management functions |
| 365 | * These functions/definitions allow for building up a 'sde_info' structure |
| 366 | * containing one or more "key=value\n" entries. |
| 367 | */ |
| 368 | #define SDE_KMS_INFO_MAX_SIZE 4096 |
| 369 | |
| 370 | /** |
| 371 | * struct sde_kms_info - connector information structure container |
| 372 | * @data: Array of information character data |
| 373 | * @len: Current length of information data |
| 374 | * @staged_len: Temporary data buffer length, commit to |
| 375 | * len using sde_kms_info_stop |
| 376 | * @start: Whether or not a partial data entry was just started |
| 377 | */ |
| 378 | struct sde_kms_info { |
| 379 | char data[SDE_KMS_INFO_MAX_SIZE]; |
| 380 | uint32_t len; |
| 381 | uint32_t staged_len; |
| 382 | bool start; |
| 383 | }; |
| 384 | |
| 385 | /** |
| 386 | * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes |
| 387 | * @S: Pointer to sde_kms_info structure |
| 388 | * Returns: Pointer to byte data |
| 389 | */ |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 390 | #define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data \ |
| 391 | : NULL) |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 392 | |
| 393 | /** |
| 394 | * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length |
Narendra Muppalla | 22d1725 | 2017-05-31 15:13:39 -0700 | [diff] [blame] | 395 | * it adds an extra character length to count null. |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 396 | * @S: Pointer to sde_kms_info structure |
| 397 | * Returns: Size of available byte data |
| 398 | */ |
Narendra Muppalla | 22d1725 | 2017-05-31 15:13:39 -0700 | [diff] [blame] | 399 | #define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len + 1 \ |
| 400 | : 0) |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 401 | |
| 402 | /** |
| 403 | * sde_kms_info_reset - reset sde_kms_info structure |
| 404 | * @info: Pointer to sde_kms_info structure |
| 405 | */ |
| 406 | void sde_kms_info_reset(struct sde_kms_info *info); |
| 407 | |
| 408 | /** |
| 409 | * sde_kms_info_add_keyint - add integer value to 'sde_kms_info' |
| 410 | * @info: Pointer to sde_kms_info structure |
| 411 | * @key: Pointer to key string |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 412 | * @value: Signed 64-bit integer value |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 413 | */ |
| 414 | void sde_kms_info_add_keyint(struct sde_kms_info *info, |
| 415 | const char *key, |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 416 | int64_t value); |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 417 | |
| 418 | /** |
| 419 | * sde_kms_info_add_keystr - add string value to 'sde_kms_info' |
| 420 | * @info: Pointer to sde_kms_info structure |
| 421 | * @key: Pointer to key string |
| 422 | * @value: Pointer to string value |
| 423 | */ |
| 424 | void sde_kms_info_add_keystr(struct sde_kms_info *info, |
| 425 | const char *key, |
| 426 | const char *value); |
| 427 | |
| 428 | /** |
| 429 | * sde_kms_info_start - begin adding key to 'sde_kms_info' |
| 430 | * Usage: |
| 431 | * sde_kms_info_start(key) |
| 432 | * sde_kms_info_append(val_1) |
| 433 | * ... |
| 434 | * sde_kms_info_append(val_n) |
| 435 | * sde_kms_info_stop |
| 436 | * @info: Pointer to sde_kms_info structure |
| 437 | * @key: Pointer to key string |
| 438 | */ |
| 439 | void sde_kms_info_start(struct sde_kms_info *info, |
| 440 | const char *key); |
| 441 | |
| 442 | /** |
| 443 | * sde_kms_info_append - append value string to 'sde_kms_info' |
| 444 | * Usage: |
| 445 | * sde_kms_info_start(key) |
| 446 | * sde_kms_info_append(val_1) |
| 447 | * ... |
| 448 | * sde_kms_info_append(val_n) |
| 449 | * sde_kms_info_stop |
| 450 | * @info: Pointer to sde_kms_info structure |
| 451 | * @str: Pointer to partial value string |
| 452 | */ |
| 453 | void sde_kms_info_append(struct sde_kms_info *info, |
| 454 | const char *str); |
| 455 | |
| 456 | /** |
| 457 | * sde_kms_info_append_format - append format code string to 'sde_kms_info' |
| 458 | * Usage: |
| 459 | * sde_kms_info_start(key) |
| 460 | * sde_kms_info_append_format(fourcc, modifier) |
| 461 | * ... |
| 462 | * sde_kms_info_stop |
| 463 | * @info: Pointer to sde_kms_info structure |
| 464 | * @pixel_format: FOURCC format code |
| 465 | * @modifier: 64-bit drm format modifier |
| 466 | */ |
| 467 | void sde_kms_info_append_format(struct sde_kms_info *info, |
| 468 | uint32_t pixel_format, |
| 469 | uint64_t modifier); |
| 470 | |
| 471 | /** |
| 472 | * sde_kms_info_stop - finish adding key to 'sde_kms_info' |
| 473 | * Usage: |
| 474 | * sde_kms_info_start(key) |
| 475 | * sde_kms_info_append(val_1) |
| 476 | * ... |
| 477 | * sde_kms_info_append(val_n) |
| 478 | * sde_kms_info_stop |
| 479 | * @info: Pointer to sde_kms_info structure |
| 480 | */ |
| 481 | void sde_kms_info_stop(struct sde_kms_info *info); |
| 482 | |
| 483 | /** |
Lloyd Atkinson | e0e11e2 | 2017-01-17 12:08:48 -0500 | [diff] [blame] | 484 | * sde_kms_rect_intersect - intersect two rectangles |
| 485 | * @r1: first rectangle |
| 486 | * @r2: scissor rectangle |
| 487 | * @result: result rectangle, all 0's on no intersection found |
Veera Sundaram Sankaran | 02dd6ac | 2016-12-22 15:08:29 -0800 | [diff] [blame] | 488 | */ |
Lloyd Atkinson | e0e11e2 | 2017-01-17 12:08:48 -0500 | [diff] [blame] | 489 | void sde_kms_rect_intersect(const struct sde_rect *r1, |
| 490 | const struct sde_rect *r2, |
| 491 | struct sde_rect *result); |
| 492 | |
| 493 | /** |
Lloyd Atkinson | c2baf41 | 2017-04-19 17:53:09 -0400 | [diff] [blame] | 494 | * sde_kms_rect_merge_rectangles - merge a rectangle list into one rect |
| 495 | * @rois: pointer to the list of rois |
| 496 | * @result: output rectangle, all 0 on error |
| 497 | */ |
| 498 | void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois, |
| 499 | struct sde_rect *result); |
| 500 | |
| 501 | /** |
Lloyd Atkinson | e0e11e2 | 2017-01-17 12:08:48 -0500 | [diff] [blame] | 502 | * sde_kms_rect_is_equal - compares two rects |
| 503 | * @r1: rect value to compare |
| 504 | * @r2: rect value to compare |
| 505 | * |
| 506 | * Returns 1 if the rects are same, 0 otherwise. |
| 507 | */ |
| 508 | static inline bool sde_kms_rect_is_equal(struct sde_rect *r1, |
| 509 | struct sde_rect *r2) |
| 510 | { |
| 511 | if ((!r1 && r2) || (r1 && !r2)) |
| 512 | return false; |
| 513 | |
| 514 | if (!r1 && !r2) |
| 515 | return true; |
| 516 | |
| 517 | return r1->x == r2->x && r1->y == r2->y && r1->w == r2->w && |
| 518 | r1->h == r2->h; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * sde_kms_rect_is_null - returns true if the width or height of a rect is 0 |
| 523 | * @rect: rectangle to check for zero size |
| 524 | * @Return: True if width or height of rectangle is 0 |
| 525 | */ |
| 526 | static inline bool sde_kms_rect_is_null(const struct sde_rect *r) |
| 527 | { |
| 528 | if (!r) |
| 529 | return true; |
| 530 | |
| 531 | return (!r->w || !r->h); |
| 532 | } |
Veera Sundaram Sankaran | 02dd6ac | 2016-12-22 15:08:29 -0800 | [diff] [blame] | 533 | |
| 534 | /** |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 535 | * Vblank enable/disable functions |
| 536 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 537 | int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 538 | void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 539 | |
Alan Kwong | 4dd64c8 | 2017-02-04 18:41:51 -0800 | [diff] [blame] | 540 | /** |
| 541 | * sde_kms_fbo_create_fb - create framebuffer from given framebuffer object |
| 542 | * @dev: Pointer to drm device |
| 543 | * @fbo: Pointer to framebuffer object |
| 544 | * return: Pointer to drm framebuffer on success; NULL on error |
| 545 | */ |
| 546 | struct drm_framebuffer *sde_kms_fbo_create_fb(struct drm_device *dev, |
| 547 | struct sde_kms_fbo *fbo); |
| 548 | |
| 549 | /** |
| 550 | * sde_kms_fbo_alloc - create framebuffer object with given format parameters |
| 551 | * @dev: pointer to drm device |
| 552 | * @width: width of framebuffer |
| 553 | * @height: height of framebuffer |
| 554 | * @pixel_format: pixel format of framebuffer |
| 555 | * @modifier: pixel format modifier |
| 556 | * @flags: DRM_MODE_FB flags |
| 557 | * return: Pointer to framebuffer memory object on success; NULL on error |
| 558 | */ |
| 559 | struct sde_kms_fbo *sde_kms_fbo_alloc(struct drm_device *dev, |
| 560 | u32 width, u32 height, u32 pixel_format, |
| 561 | u64 modifiers[4], u32 flags); |
| 562 | |
| 563 | /** |
| 564 | * sde_kms_fbo_reference - increment reference count of given framebuffer object |
| 565 | * @fbo: Pointer to framebuffer memory object |
| 566 | * return: 0 on success; error code otherwise |
| 567 | */ |
| 568 | int sde_kms_fbo_reference(struct sde_kms_fbo *fbo); |
| 569 | |
| 570 | /** |
| 571 | * sde_kms_fbo_unreference - decrement reference count of given framebuffer |
| 572 | * object |
| 573 | * @fbo: Pointer to framebuffer memory object |
| 574 | * return: 0 on success; error code otherwise |
| 575 | */ |
| 576 | void sde_kms_fbo_unreference(struct sde_kms_fbo *fbo); |
| 577 | |
Abhijit Kulkarni | 329a94d | 2017-06-20 17:07:08 -0700 | [diff] [blame] | 578 | /** |
| 579 | * smmu attach/detach functions |
| 580 | * @sde_kms: poiner to sde_kms structure |
| 581 | * @secure_only: if true only secure contexts are attached/detached, else |
| 582 | * all contexts are attached/detached/ |
| 583 | */ |
| 584 | int sde_kms_mmu_attach(struct sde_kms *sde_kms, bool secure_only); |
| 585 | int sde_kms_mmu_detach(struct sde_kms *sde_kms, bool secure_only); |
| 586 | |
Dhaval Patel | 2a3c37a | 2017-10-25 12:30:36 -0700 | [diff] [blame] | 587 | /** |
| 588 | * sde_kms_timeline_status - provides current timeline status |
| 589 | * @dev: Pointer to drm device |
| 590 | */ |
| 591 | void sde_kms_timeline_status(struct drm_device *dev); |
| 592 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 593 | /** |
| 594 | * sde_kms_handle_recovery - handler function for FIFO overflow issue |
| 595 | * @encoder: pointer to drm encoder structure |
| 596 | * return: 0 on success; error code otherwise |
| 597 | */ |
| 598 | int sde_kms_handle_recovery(struct drm_encoder *encoder); |
| 599 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 600 | #endif /* __sde_kms_H__ */ |