blob: 1f56d733ad3241b235ae97f11936b0c6793da30d [file] [log] [blame]
Dhaval Patel14d46ce2017-01-17 16:28:12 -08001/*
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 Muppalla1b0b3352015-09-29 10:16:51 -07005 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -08006 * 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 Muppalla1b0b3352015-09-29 10:16:51 -07009 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -080010 * 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 Muppalla1b0b3352015-09-29 10:16:51 -070017 */
18
19#ifndef __SDE_KMS_H__
20#define __SDE_KMS_H__
21
Alan Kwong54125bb2017-02-26 16:01:36 -080022#include <linux/msm_ion.h>
23
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070024#include "msm_drv.h"
25#include "msm_kms.h"
Alan Kwong112a84f2016-05-24 20:49:21 -040026#include "msm_mmu.h"
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040027#include "sde_dbg.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070028#include "sde_hw_catalog.h"
Clarence Ipc475b082016-06-26 09:27:23 -040029#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040030#include "sde_hw_lm.h"
Ben Chan78647cd2016-06-26 22:02:47 -040031#include "sde_hw_interrupts.h"
Alan Kwongd21960f2016-07-29 03:33:17 -040032#include "sde_hw_wb.h"
33#include "sde_hw_top.h"
Lloyd Atkinson11f34442016-08-11 11:19:52 -040034#include "sde_rm.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070035#include "sde_power_handle.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040036#include "sde_irq.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040037#include "sde_core_perf.h"
Ben Chan78647cd2016-06-26 22:02:47 -040038
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040039#define DRMID(x) ((x) ? (x)->base.id : -1)
40
Clarence Ip31c19b52016-06-10 15:42:08 -040041/**
42 * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
43 * @fmt: Pointer to format string
44 */
45#define SDE_DEBUG(fmt, ...) \
46 do { \
47 if (unlikely(drm_debug & DRM_UT_KMS)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070048 DRM_DEBUG(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040049 else \
50 pr_debug(fmt, ##__VA_ARGS__); \
51 } while (0)
52
53/**
54 * SDE_DEBUG_DRIVER - macro for hardware driver logging
55 * @fmt: Pointer to format string
56 */
57#define SDE_DEBUG_DRIVER(fmt, ...) \
58 do { \
59 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070060 DRM_ERROR(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040061 else \
62 pr_debug(fmt, ##__VA_ARGS__); \
63 } while (0)
64
Dhaval Patelb271b842016-10-19 21:41:22 -070065#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040066
Dhaval Patelec10fad2016-08-22 14:40:48 -070067#define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
68 do { \
69 (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
70 (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
71 (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
72 (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
73 } while (0)
74
75#define CHECK_LAYER_BOUNDS(offset, size, max_size) \
76 (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
77
Clarence Ipfd96ba22016-09-09 16:45:44 -040078/**
79 * ktime_compare_safe - compare two ktime structures
80 * This macro is similar to the standard ktime_compare() function, but
81 * attempts to also handle ktime overflows.
82 * @A: First ktime value
83 * @B: Second ktime value
84 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
85 */
86#define ktime_compare_safe(A, B) \
87 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
88
Dhaval Patel22ef6df2016-10-20 14:42:52 -070089#define SDE_NAME_SIZE 12
90
Ben Chan78647cd2016-06-26 22:02:47 -040091/*
92 * struct sde_irq_callback - IRQ callback handlers
Alan Kwonga172ef52016-09-27 00:29:10 -040093 * @list: list to callback
Ben Chan78647cd2016-06-26 22:02:47 -040094 * @func: intr handler
95 * @arg: argument for the handler
96 */
97struct sde_irq_callback {
Alan Kwonga172ef52016-09-27 00:29:10 -040098 struct list_head list;
Ben Chan78647cd2016-06-26 22:02:47 -040099 void (*func)(void *arg, int irq_idx);
100 void *arg;
101};
102
103/**
104 * struct sde_irq: IRQ structure contains callback registration info
105 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
106 * @irq_cb_tbl: array of IRQ callbacks setting
Alan Kwonga172ef52016-09-27 00:29:10 -0400107 * @enable_counts array of IRQ enable counts
Ben Chan78647cd2016-06-26 22:02:47 -0400108 * @cb_lock: callback lock
Alan Kwonga172ef52016-09-27 00:29:10 -0400109 * @debugfs_file: debugfs file for irq statistics
Ben Chan78647cd2016-06-26 22:02:47 -0400110 */
111struct sde_irq {
112 u32 total_irqs;
Alan Kwonga172ef52016-09-27 00:29:10 -0400113 struct list_head *irq_cb_tbl;
114 atomic_t *enable_counts;
115 atomic_t *irq_counts;
Ben Chan78647cd2016-06-26 22:02:47 -0400116 spinlock_t cb_lock;
Alan Kwonga172ef52016-09-27 00:29:10 -0400117 struct dentry *debugfs_file;
Ben Chan78647cd2016-06-26 22:02:47 -0400118};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700119
Alan Kwong4dd64c82017-02-04 18:41:51 -0800120/**
121 * struct sde_kms_fbo - framebuffer memory object
122 * @refcount: reference/usage count of this object
123 * @dev: Pointer to containing drm device
124 * @width: width of the framebuffer
125 * @height: height of the framebuffer
126 * @flags: drm framebuffer flags
127 * @modifier: pixel format modifier of the framebuffer
128 * @fmt: Pointer to sde format descriptor
129 * @layout: sde format layout descriptor
130 * @ihandle: framebuffer object ion handle
131 * @dma_buf: framebuffer object dma buffer
132 * @bo: per plane buffer object
133 * @fb_list: llist of fb created from this buffer object
134 */
135struct sde_kms_fbo {
136 atomic_t refcount;
137 struct drm_device *dev;
138 u32 width, height;
139 u32 pixel_format;
140 u32 flags;
141 u64 modifier[4];
142 int nplane;
143 const struct sde_format *fmt;
144 struct sde_hw_fmt_layout layout;
Alan Kwong54125bb2017-02-26 16:01:36 -0800145 struct ion_handle *ihandle;
Alan Kwong4dd64c82017-02-04 18:41:51 -0800146 struct dma_buf *dma_buf;
147 struct drm_gem_object *bo[4];
148 struct list_head fb_list;
149};
150
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700151struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400152 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700153 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700154 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700155 struct sde_mdss_cfg *catalog;
156
Alan Kwong112a84f2016-05-24 20:49:21 -0400157 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
158 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700159 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700160
Alan Kwong54125bb2017-02-26 16:01:36 -0800161 struct ion_client *iclient;
162
Clarence Ip4ce59322016-06-26 22:27:51 -0400163 /* directory entry for debugfs */
Alan Kwongf0fd8512016-10-24 21:39:26 -0400164 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400165 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400166
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700167 /* io/register spaces: */
Gopikrishnaiah Anandan7e3e3f52016-12-22 11:13:05 -0800168 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400169 unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700170
171 struct regulator *vdd;
172 struct regulator *mmagic;
173 struct regulator *venus;
174
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400175 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400176
177 struct sde_hw_intr *hw_intr;
178 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400179
Alan Kwong67a3f792016-11-01 23:16:53 -0400180 struct sde_core_perf perf;
181
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400182 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500183 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400184
185 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
186 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400187 int dsi_display_count;
188 void **dsi_displays;
189 int wb_display_count;
190 void **wb_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400191
192 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400193};
194
195struct vsync_info {
196 u32 frame_count;
197 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700198};
199
200#define to_sde_kms(x) container_of(x, struct sde_kms, base)
201
Clarence Ip4c1d9772016-06-26 09:35:38 -0400202/**
Clarence Ipdd395242016-09-09 10:47:17 -0400203 * sde_is_custom_client - whether or not to enable non-standard customizations
204 *
205 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
206 */
207bool sde_is_custom_client(void);
208
209/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400210 * Debugfs functions - extra helper functions for debugfs support
211 *
212 * Main debugfs documentation is located at,
213 *
214 * Documentation/filesystems/debugfs.txt
215 *
216 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
217 * @sde_debugfs_create_regset32: Create 32-bit register dump file
218 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
219 */
220
221/**
222 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
223 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
224 */
225struct sde_debugfs_regset32 {
226 uint32_t offset;
227 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400228 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400229};
230
231/**
232 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
233 * This function is meant to initialize sde_debugfs_regset32 structures for use
234 * with sde_debugfs_create_regset32.
235 * @regset: opaque register definition structure
236 * @offset: sub-block offset
237 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400238 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400239 */
240void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400241 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400242
243/**
244 * sde_debugfs_create_regset32 - Create register read back file for debugfs
245 *
246 * This function is almost identical to the standard debugfs_create_regset32()
247 * function, with the main difference being that a list of register
248 * names/offsets do not need to be provided. The 'read' function simply outputs
249 * sequential register values over a specified range.
250 *
251 * Similar to the related debugfs_create_regset32 API, the structure pointed to
252 * by regset needs to persist for the lifetime of the created file. The calling
253 * code is responsible for initialization/management of this structure.
254 *
255 * The structure pointed to by regset is meant to be opaque. Please use
256 * sde_debugfs_setup_regset32 to initialize it.
257 *
258 * @name: File name within debugfs
259 * @mode: File mode within debugfs
260 * @parent: Parent directory entry within debugfs, can be NULL
261 * @regset: Pointer to persistent register block definition
262 *
263 * Return: dentry pointer for newly created file, use either debugfs_remove()
264 * or debugfs_remove_recursive() (on a parent directory) to remove the
265 * file
266 */
267void *sde_debugfs_create_regset32(const char *name, umode_t mode,
268 void *parent, struct sde_debugfs_regset32 *regset);
269
270/**
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700271 * sde_debugfs_get_root - Return root directory entry for KMS's debugfs
Clarence Ip4ce59322016-06-26 22:27:51 -0400272 *
273 * The return value should be passed as the 'parent' argument to subsequent
274 * debugfs create calls.
275 *
276 * @sde_kms: Pointer to SDE's KMS structure
277 *
278 * Return: dentry pointer for SDE's debugfs location
279 */
280void *sde_debugfs_get_root(struct sde_kms *sde_kms);
281
282/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400283 * SDE info management functions
284 * These functions/definitions allow for building up a 'sde_info' structure
285 * containing one or more "key=value\n" entries.
286 */
287#define SDE_KMS_INFO_MAX_SIZE 4096
288
289/**
290 * struct sde_kms_info - connector information structure container
291 * @data: Array of information character data
292 * @len: Current length of information data
293 * @staged_len: Temporary data buffer length, commit to
294 * len using sde_kms_info_stop
295 * @start: Whether or not a partial data entry was just started
296 */
297struct sde_kms_info {
298 char data[SDE_KMS_INFO_MAX_SIZE];
299 uint32_t len;
300 uint32_t staged_len;
301 bool start;
302};
303
304/**
305 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
306 * @S: Pointer to sde_kms_info structure
307 * Returns: Pointer to byte data
308 */
309#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
310
311/**
312 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
313 * @S: Pointer to sde_kms_info structure
314 * Returns: Size of available byte data
315 */
316#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
317
318/**
319 * sde_kms_info_reset - reset sde_kms_info structure
320 * @info: Pointer to sde_kms_info structure
321 */
322void sde_kms_info_reset(struct sde_kms_info *info);
323
324/**
325 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
326 * @info: Pointer to sde_kms_info structure
327 * @key: Pointer to key string
Alan Kwong6259a382017-04-04 06:18:02 -0700328 * @value: Signed 64-bit integer value
Clarence Ipb218a3c2016-07-15 14:17:42 -0400329 */
330void sde_kms_info_add_keyint(struct sde_kms_info *info,
331 const char *key,
Alan Kwong6259a382017-04-04 06:18:02 -0700332 int64_t value);
Clarence Ipb218a3c2016-07-15 14:17:42 -0400333
334/**
335 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
336 * @info: Pointer to sde_kms_info structure
337 * @key: Pointer to key string
338 * @value: Pointer to string value
339 */
340void sde_kms_info_add_keystr(struct sde_kms_info *info,
341 const char *key,
342 const char *value);
343
344/**
345 * sde_kms_info_start - begin adding key to 'sde_kms_info'
346 * Usage:
347 * sde_kms_info_start(key)
348 * sde_kms_info_append(val_1)
349 * ...
350 * sde_kms_info_append(val_n)
351 * sde_kms_info_stop
352 * @info: Pointer to sde_kms_info structure
353 * @key: Pointer to key string
354 */
355void sde_kms_info_start(struct sde_kms_info *info,
356 const char *key);
357
358/**
359 * sde_kms_info_append - append value string to 'sde_kms_info'
360 * Usage:
361 * sde_kms_info_start(key)
362 * sde_kms_info_append(val_1)
363 * ...
364 * sde_kms_info_append(val_n)
365 * sde_kms_info_stop
366 * @info: Pointer to sde_kms_info structure
367 * @str: Pointer to partial value string
368 */
369void sde_kms_info_append(struct sde_kms_info *info,
370 const char *str);
371
372/**
373 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
374 * Usage:
375 * sde_kms_info_start(key)
376 * sde_kms_info_append_format(fourcc, modifier)
377 * ...
378 * sde_kms_info_stop
379 * @info: Pointer to sde_kms_info structure
380 * @pixel_format: FOURCC format code
381 * @modifier: 64-bit drm format modifier
382 */
383void sde_kms_info_append_format(struct sde_kms_info *info,
384 uint32_t pixel_format,
385 uint64_t modifier);
386
387/**
388 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
389 * Usage:
390 * sde_kms_info_start(key)
391 * sde_kms_info_append(val_1)
392 * ...
393 * sde_kms_info_append(val_n)
394 * sde_kms_info_stop
395 * @info: Pointer to sde_kms_info structure
396 */
397void sde_kms_info_stop(struct sde_kms_info *info);
398
399/**
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500400 * sde_kms_rect_intersect - intersect two rectangles
401 * @r1: first rectangle
402 * @r2: scissor rectangle
403 * @result: result rectangle, all 0's on no intersection found
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800404 */
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500405void sde_kms_rect_intersect(const struct sde_rect *r1,
406 const struct sde_rect *r2,
407 struct sde_rect *result);
408
409/**
Lloyd Atkinsonc2baf412017-04-19 17:53:09 -0400410 * sde_kms_rect_merge_rectangles - merge a rectangle list into one rect
411 * @rois: pointer to the list of rois
412 * @result: output rectangle, all 0 on error
413 */
414void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
415 struct sde_rect *result);
416
417/**
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500418 * sde_kms_rect_is_equal - compares two rects
419 * @r1: rect value to compare
420 * @r2: rect value to compare
421 *
422 * Returns 1 if the rects are same, 0 otherwise.
423 */
424static inline bool sde_kms_rect_is_equal(struct sde_rect *r1,
425 struct sde_rect *r2)
426{
427 if ((!r1 && r2) || (r1 && !r2))
428 return false;
429
430 if (!r1 && !r2)
431 return true;
432
433 return r1->x == r2->x && r1->y == r2->y && r1->w == r2->w &&
434 r1->h == r2->h;
435}
436
437/**
438 * sde_kms_rect_is_null - returns true if the width or height of a rect is 0
439 * @rect: rectangle to check for zero size
440 * @Return: True if width or height of rectangle is 0
441 */
442static inline bool sde_kms_rect_is_null(const struct sde_rect *r)
443{
444 if (!r)
445 return true;
446
447 return (!r->w || !r->h);
448}
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800449
450/**
Ben Chan78647cd2016-06-26 22:02:47 -0400451 * Vblank enable/disable functions
452 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700453int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
454void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
455
Alan Kwong4dd64c82017-02-04 18:41:51 -0800456/**
457 * sde_kms_fbo_create_fb - create framebuffer from given framebuffer object
458 * @dev: Pointer to drm device
459 * @fbo: Pointer to framebuffer object
460 * return: Pointer to drm framebuffer on success; NULL on error
461 */
462struct drm_framebuffer *sde_kms_fbo_create_fb(struct drm_device *dev,
463 struct sde_kms_fbo *fbo);
464
465/**
466 * sde_kms_fbo_alloc - create framebuffer object with given format parameters
467 * @dev: pointer to drm device
468 * @width: width of framebuffer
469 * @height: height of framebuffer
470 * @pixel_format: pixel format of framebuffer
471 * @modifier: pixel format modifier
472 * @flags: DRM_MODE_FB flags
473 * return: Pointer to framebuffer memory object on success; NULL on error
474 */
475struct sde_kms_fbo *sde_kms_fbo_alloc(struct drm_device *dev,
476 u32 width, u32 height, u32 pixel_format,
477 u64 modifiers[4], u32 flags);
478
479/**
480 * sde_kms_fbo_reference - increment reference count of given framebuffer object
481 * @fbo: Pointer to framebuffer memory object
482 * return: 0 on success; error code otherwise
483 */
484int sde_kms_fbo_reference(struct sde_kms_fbo *fbo);
485
486/**
487 * sde_kms_fbo_unreference - decrement reference count of given framebuffer
488 * object
489 * @fbo: Pointer to framebuffer memory object
490 * return: 0 on success; error code otherwise
491 */
492void sde_kms_fbo_unreference(struct sde_kms_fbo *fbo);
493
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700494#endif /* __sde_kms_H__ */