Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __SDE_KMS_H__ |
| 14 | #define __SDE_KMS_H__ |
| 15 | |
| 16 | #include "msm_drv.h" |
| 17 | #include "msm_kms.h" |
Alan Kwong | 112a84f | 2016-05-24 20:49:21 -0400 | [diff] [blame] | 18 | #include "msm_mmu.h" |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 19 | #include "sde_dbg.h" |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 20 | #include "sde_hw_catalog.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 21 | #include "sde_hw_ctl.h" |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 22 | #include "sde_hw_lm.h" |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 23 | #include "sde_hw_interrupts.h" |
Alan Kwong | d21960f | 2016-07-29 03:33:17 -0400 | [diff] [blame] | 24 | #include "sde_hw_wb.h" |
| 25 | #include "sde_hw_top.h" |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 26 | #include "sde_rm.h" |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 27 | #include "sde_power_handle.h" |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 28 | #include "sde_irq.h" |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 29 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 30 | #define DRMID(x) ((x) ? (x)->base.id : -1) |
| 31 | |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 32 | /** |
| 33 | * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs |
| 34 | * @fmt: Pointer to format string |
| 35 | */ |
| 36 | #define SDE_DEBUG(fmt, ...) \ |
| 37 | do { \ |
| 38 | if (unlikely(drm_debug & DRM_UT_KMS)) \ |
| 39 | drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \ |
| 40 | else \ |
| 41 | pr_debug(fmt, ##__VA_ARGS__); \ |
| 42 | } while (0) |
| 43 | |
| 44 | /** |
| 45 | * SDE_DEBUG_DRIVER - macro for hardware driver logging |
| 46 | * @fmt: Pointer to format string |
| 47 | */ |
| 48 | #define SDE_DEBUG_DRIVER(fmt, ...) \ |
| 49 | do { \ |
| 50 | if (unlikely(drm_debug & DRM_UT_DRIVER)) \ |
| 51 | drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \ |
| 52 | else \ |
| 53 | pr_debug(fmt, ##__VA_ARGS__); \ |
| 54 | } while (0) |
| 55 | |
Dhaval Patel | b271b84 | 2016-10-19 21:41:22 -0700 | [diff] [blame] | 56 | #define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__) |
Clarence Ip | 31c19b5 | 2016-06-10 15:42:08 -0400 | [diff] [blame] | 57 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 58 | #define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \ |
| 59 | do { \ |
| 60 | (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \ |
| 61 | (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \ |
| 62 | (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \ |
| 63 | (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \ |
| 64 | } while (0) |
| 65 | |
| 66 | #define CHECK_LAYER_BOUNDS(offset, size, max_size) \ |
| 67 | (((size) > (max_size)) || ((offset) > ((max_size) - (size)))) |
| 68 | |
Clarence Ip | fd96ba2 | 2016-09-09 16:45:44 -0400 | [diff] [blame] | 69 | /** |
| 70 | * ktime_compare_safe - compare two ktime structures |
| 71 | * This macro is similar to the standard ktime_compare() function, but |
| 72 | * attempts to also handle ktime overflows. |
| 73 | * @A: First ktime value |
| 74 | * @B: Second ktime value |
| 75 | * Returns: -1 if A < B, 0 if A == B, 1 if A > B |
| 76 | */ |
| 77 | #define ktime_compare_safe(A, B) \ |
| 78 | ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0)) |
| 79 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 80 | #define SDE_NAME_SIZE 12 |
| 81 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 82 | /* |
| 83 | * struct sde_irq_callback - IRQ callback handlers |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 84 | * @list: list to callback |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 85 | * @func: intr handler |
| 86 | * @arg: argument for the handler |
| 87 | */ |
| 88 | struct sde_irq_callback { |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 89 | struct list_head list; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 90 | void (*func)(void *arg, int irq_idx); |
| 91 | void *arg; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct sde_irq: IRQ structure contains callback registration info |
| 96 | * @total_irq: total number of irq_idx obtained from HW interrupts mapping |
| 97 | * @irq_cb_tbl: array of IRQ callbacks setting |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 98 | * @enable_counts array of IRQ enable counts |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 99 | * @cb_lock: callback lock |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 100 | * @debugfs_file: debugfs file for irq statistics |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 101 | */ |
| 102 | struct sde_irq { |
| 103 | u32 total_irqs; |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 104 | struct list_head *irq_cb_tbl; |
| 105 | atomic_t *enable_counts; |
| 106 | atomic_t *irq_counts; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 107 | spinlock_t cb_lock; |
Alan Kwong | a172ef5 | 2016-09-27 00:29:10 -0400 | [diff] [blame] | 108 | struct dentry *debugfs_file; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 109 | }; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 110 | |
| 111 | struct sde_kms { |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 112 | struct msm_kms base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 113 | struct drm_device *dev; |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 114 | int core_rev; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 115 | struct sde_mdss_cfg *catalog; |
| 116 | |
Alan Kwong | 112a84f | 2016-05-24 20:49:21 -0400 | [diff] [blame] | 117 | struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX]; |
| 118 | int mmu_id[MSM_SMMU_DOMAIN_MAX]; |
Dhaval Patel | 3949f03 | 2016-06-20 16:24:33 -0700 | [diff] [blame] | 119 | struct sde_power_client *core_client; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 120 | |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 121 | /* directory entry for debugfs */ |
| 122 | void *debugfs_root; |
Alan Kwong | cd1c09f | 2016-11-04 20:37:30 -0400 | [diff] [blame] | 123 | struct dentry *debugfs_debug; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 124 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 125 | /* io/register spaces: */ |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 126 | void __iomem *mmio, *vbif[VBIF_MAX]; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 127 | |
| 128 | struct regulator *vdd; |
| 129 | struct regulator *mmagic; |
| 130 | struct regulator *venus; |
| 131 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 132 | struct sde_irq_controller irq_controller; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 133 | |
| 134 | struct sde_hw_intr *hw_intr; |
| 135 | struct sde_irq irq_obj; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 136 | |
| 137 | struct sde_rm rm; |
Clarence Ip | 17162b5 | 2016-11-24 17:06:29 -0500 | [diff] [blame^] | 138 | bool rm_init; |
Alan Kwong | 5d324e4 | 2016-07-28 22:56:18 -0400 | [diff] [blame] | 139 | |
| 140 | struct sde_hw_vbif *hw_vbif[VBIF_MAX]; |
| 141 | struct sde_hw_mdp *hw_mdp; |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 142 | int dsi_display_count; |
| 143 | void **dsi_displays; |
| 144 | int wb_display_count; |
| 145 | void **wb_displays; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | struct vsync_info { |
| 149 | u32 frame_count; |
| 150 | u32 line_count; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | #define to_sde_kms(x) container_of(x, struct sde_kms, base) |
| 154 | |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 155 | /** |
Clarence Ip | dd39524 | 2016-09-09 10:47:17 -0400 | [diff] [blame] | 156 | * sde_is_custom_client - whether or not to enable non-standard customizations |
| 157 | * |
| 158 | * Return: Whether or not the 'sdeclient' module parameter was set on boot up |
| 159 | */ |
| 160 | bool sde_is_custom_client(void); |
| 161 | |
| 162 | /** |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 163 | * Debugfs functions - extra helper functions for debugfs support |
| 164 | * |
| 165 | * Main debugfs documentation is located at, |
| 166 | * |
| 167 | * Documentation/filesystems/debugfs.txt |
| 168 | * |
| 169 | * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32 |
| 170 | * @sde_debugfs_create_regset32: Create 32-bit register dump file |
| 171 | * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node |
| 172 | */ |
| 173 | |
| 174 | /** |
| 175 | * Companion structure for sde_debugfs_create_regset32. Do not initialize the |
| 176 | * members of this structure explicitly; use sde_debugfs_setup_regset32 instead. |
| 177 | */ |
| 178 | struct sde_debugfs_regset32 { |
| 179 | uint32_t offset; |
| 180 | uint32_t blk_len; |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 181 | struct sde_kms *sde_kms; |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /** |
| 185 | * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs |
| 186 | * This function is meant to initialize sde_debugfs_regset32 structures for use |
| 187 | * with sde_debugfs_create_regset32. |
| 188 | * @regset: opaque register definition structure |
| 189 | * @offset: sub-block offset |
| 190 | * @length: sub-block length, in bytes |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 191 | * @sde_kms: pointer to sde kms structure |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 192 | */ |
| 193 | void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset, |
Clarence Ip | aac9f33 | 2016-08-31 15:46:35 -0400 | [diff] [blame] | 194 | uint32_t offset, uint32_t length, struct sde_kms *sde_kms); |
Clarence Ip | 4ce5932 | 2016-06-26 22:27:51 -0400 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * sde_debugfs_create_regset32 - Create register read back file for debugfs |
| 198 | * |
| 199 | * This function is almost identical to the standard debugfs_create_regset32() |
| 200 | * function, with the main difference being that a list of register |
| 201 | * names/offsets do not need to be provided. The 'read' function simply outputs |
| 202 | * sequential register values over a specified range. |
| 203 | * |
| 204 | * Similar to the related debugfs_create_regset32 API, the structure pointed to |
| 205 | * by regset needs to persist for the lifetime of the created file. The calling |
| 206 | * code is responsible for initialization/management of this structure. |
| 207 | * |
| 208 | * The structure pointed to by regset is meant to be opaque. Please use |
| 209 | * sde_debugfs_setup_regset32 to initialize it. |
| 210 | * |
| 211 | * @name: File name within debugfs |
| 212 | * @mode: File mode within debugfs |
| 213 | * @parent: Parent directory entry within debugfs, can be NULL |
| 214 | * @regset: Pointer to persistent register block definition |
| 215 | * |
| 216 | * Return: dentry pointer for newly created file, use either debugfs_remove() |
| 217 | * or debugfs_remove_recursive() (on a parent directory) to remove the |
| 218 | * file |
| 219 | */ |
| 220 | void *sde_debugfs_create_regset32(const char *name, umode_t mode, |
| 221 | void *parent, struct sde_debugfs_regset32 *regset); |
| 222 | |
| 223 | /** |
| 224 | * sde_debugfs_get_root - Return root directory entry for SDE's debugfs |
| 225 | * |
| 226 | * The return value should be passed as the 'parent' argument to subsequent |
| 227 | * debugfs create calls. |
| 228 | * |
| 229 | * @sde_kms: Pointer to SDE's KMS structure |
| 230 | * |
| 231 | * Return: dentry pointer for SDE's debugfs location |
| 232 | */ |
| 233 | void *sde_debugfs_get_root(struct sde_kms *sde_kms); |
| 234 | |
| 235 | /** |
Clarence Ip | b218a3c | 2016-07-15 14:17:42 -0400 | [diff] [blame] | 236 | * SDE info management functions |
| 237 | * These functions/definitions allow for building up a 'sde_info' structure |
| 238 | * containing one or more "key=value\n" entries. |
| 239 | */ |
| 240 | #define SDE_KMS_INFO_MAX_SIZE 4096 |
| 241 | |
| 242 | /** |
| 243 | * struct sde_kms_info - connector information structure container |
| 244 | * @data: Array of information character data |
| 245 | * @len: Current length of information data |
| 246 | * @staged_len: Temporary data buffer length, commit to |
| 247 | * len using sde_kms_info_stop |
| 248 | * @start: Whether or not a partial data entry was just started |
| 249 | */ |
| 250 | struct sde_kms_info { |
| 251 | char data[SDE_KMS_INFO_MAX_SIZE]; |
| 252 | uint32_t len; |
| 253 | uint32_t staged_len; |
| 254 | bool start; |
| 255 | }; |
| 256 | |
| 257 | /** |
| 258 | * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes |
| 259 | * @S: Pointer to sde_kms_info structure |
| 260 | * Returns: Pointer to byte data |
| 261 | */ |
| 262 | #define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0) |
| 263 | |
| 264 | /** |
| 265 | * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length |
| 266 | * @S: Pointer to sde_kms_info structure |
| 267 | * Returns: Size of available byte data |
| 268 | */ |
| 269 | #define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0) |
| 270 | |
| 271 | /** |
| 272 | * sde_kms_info_reset - reset sde_kms_info structure |
| 273 | * @info: Pointer to sde_kms_info structure |
| 274 | */ |
| 275 | void sde_kms_info_reset(struct sde_kms_info *info); |
| 276 | |
| 277 | /** |
| 278 | * sde_kms_info_add_keyint - add integer value to 'sde_kms_info' |
| 279 | * @info: Pointer to sde_kms_info structure |
| 280 | * @key: Pointer to key string |
| 281 | * @value: Signed 32-bit integer value |
| 282 | */ |
| 283 | void sde_kms_info_add_keyint(struct sde_kms_info *info, |
| 284 | const char *key, |
| 285 | int32_t value); |
| 286 | |
| 287 | /** |
| 288 | * sde_kms_info_add_keystr - add string value to 'sde_kms_info' |
| 289 | * @info: Pointer to sde_kms_info structure |
| 290 | * @key: Pointer to key string |
| 291 | * @value: Pointer to string value |
| 292 | */ |
| 293 | void sde_kms_info_add_keystr(struct sde_kms_info *info, |
| 294 | const char *key, |
| 295 | const char *value); |
| 296 | |
| 297 | /** |
| 298 | * sde_kms_info_start - begin adding key to 'sde_kms_info' |
| 299 | * Usage: |
| 300 | * sde_kms_info_start(key) |
| 301 | * sde_kms_info_append(val_1) |
| 302 | * ... |
| 303 | * sde_kms_info_append(val_n) |
| 304 | * sde_kms_info_stop |
| 305 | * @info: Pointer to sde_kms_info structure |
| 306 | * @key: Pointer to key string |
| 307 | */ |
| 308 | void sde_kms_info_start(struct sde_kms_info *info, |
| 309 | const char *key); |
| 310 | |
| 311 | /** |
| 312 | * sde_kms_info_append - append value string to 'sde_kms_info' |
| 313 | * Usage: |
| 314 | * sde_kms_info_start(key) |
| 315 | * sde_kms_info_append(val_1) |
| 316 | * ... |
| 317 | * sde_kms_info_append(val_n) |
| 318 | * sde_kms_info_stop |
| 319 | * @info: Pointer to sde_kms_info structure |
| 320 | * @str: Pointer to partial value string |
| 321 | */ |
| 322 | void sde_kms_info_append(struct sde_kms_info *info, |
| 323 | const char *str); |
| 324 | |
| 325 | /** |
| 326 | * sde_kms_info_append_format - append format code string to 'sde_kms_info' |
| 327 | * Usage: |
| 328 | * sde_kms_info_start(key) |
| 329 | * sde_kms_info_append_format(fourcc, modifier) |
| 330 | * ... |
| 331 | * sde_kms_info_stop |
| 332 | * @info: Pointer to sde_kms_info structure |
| 333 | * @pixel_format: FOURCC format code |
| 334 | * @modifier: 64-bit drm format modifier |
| 335 | */ |
| 336 | void sde_kms_info_append_format(struct sde_kms_info *info, |
| 337 | uint32_t pixel_format, |
| 338 | uint64_t modifier); |
| 339 | |
| 340 | /** |
| 341 | * sde_kms_info_stop - finish adding key to 'sde_kms_info' |
| 342 | * Usage: |
| 343 | * sde_kms_info_start(key) |
| 344 | * sde_kms_info_append(val_1) |
| 345 | * ... |
| 346 | * sde_kms_info_append(val_n) |
| 347 | * sde_kms_info_stop |
| 348 | * @info: Pointer to sde_kms_info structure |
| 349 | */ |
| 350 | void sde_kms_info_stop(struct sde_kms_info *info); |
| 351 | |
| 352 | /** |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 353 | * Vblank enable/disable functions |
| 354 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 355 | int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 356 | void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 357 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 358 | #endif /* __sde_kms_H__ */ |