blob: 83edde36405bdc7941e5ed57d8a6aee8f9958bc1 [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
22#include "msm_drv.h"
23#include "msm_kms.h"
Alan Kwong112a84f2016-05-24 20:49:21 -040024#include "msm_mmu.h"
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040025#include "sde_dbg.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070026#include "sde_hw_catalog.h"
Clarence Ipc475b082016-06-26 09:27:23 -040027#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040028#include "sde_hw_lm.h"
Ben Chan78647cd2016-06-26 22:02:47 -040029#include "sde_hw_interrupts.h"
Alan Kwongd21960f2016-07-29 03:33:17 -040030#include "sde_hw_wb.h"
31#include "sde_hw_top.h"
Lloyd Atkinson11f34442016-08-11 11:19:52 -040032#include "sde_rm.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070033#include "sde_power_handle.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040034#include "sde_irq.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040035#include "sde_core_perf.h"
Ben Chan78647cd2016-06-26 22:02:47 -040036
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040037#define DRMID(x) ((x) ? (x)->base.id : -1)
38
Clarence Ip31c19b52016-06-10 15:42:08 -040039/**
40 * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
41 * @fmt: Pointer to format string
42 */
43#define SDE_DEBUG(fmt, ...) \
44 do { \
45 if (unlikely(drm_debug & DRM_UT_KMS)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070046 DRM_DEBUG(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040047 else \
48 pr_debug(fmt, ##__VA_ARGS__); \
49 } while (0)
50
51/**
52 * SDE_DEBUG_DRIVER - macro for hardware driver logging
53 * @fmt: Pointer to format string
54 */
55#define SDE_DEBUG_DRIVER(fmt, ...) \
56 do { \
57 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070058 DRM_ERROR(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040059 else \
60 pr_debug(fmt, ##__VA_ARGS__); \
61 } while (0)
62
Dhaval Patelb271b842016-10-19 21:41:22 -070063#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040064
Dhaval Patelec10fad2016-08-22 14:40:48 -070065#define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
66 do { \
67 (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
68 (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
69 (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
70 (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
71 } while (0)
72
73#define CHECK_LAYER_BOUNDS(offset, size, max_size) \
74 (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
75
Clarence Ipfd96ba22016-09-09 16:45:44 -040076/**
77 * ktime_compare_safe - compare two ktime structures
78 * This macro is similar to the standard ktime_compare() function, but
79 * attempts to also handle ktime overflows.
80 * @A: First ktime value
81 * @B: Second ktime value
82 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
83 */
84#define ktime_compare_safe(A, B) \
85 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
86
Dhaval Patel22ef6df2016-10-20 14:42:52 -070087#define SDE_NAME_SIZE 12
88
Ben Chan78647cd2016-06-26 22:02:47 -040089/*
90 * struct sde_irq_callback - IRQ callback handlers
Alan Kwonga172ef52016-09-27 00:29:10 -040091 * @list: list to callback
Ben Chan78647cd2016-06-26 22:02:47 -040092 * @func: intr handler
93 * @arg: argument for the handler
94 */
95struct sde_irq_callback {
Alan Kwonga172ef52016-09-27 00:29:10 -040096 struct list_head list;
Ben Chan78647cd2016-06-26 22:02:47 -040097 void (*func)(void *arg, int irq_idx);
98 void *arg;
99};
100
101/**
102 * struct sde_irq: IRQ structure contains callback registration info
103 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
104 * @irq_cb_tbl: array of IRQ callbacks setting
Alan Kwonga172ef52016-09-27 00:29:10 -0400105 * @enable_counts array of IRQ enable counts
Ben Chan78647cd2016-06-26 22:02:47 -0400106 * @cb_lock: callback lock
Alan Kwonga172ef52016-09-27 00:29:10 -0400107 * @debugfs_file: debugfs file for irq statistics
Ben Chan78647cd2016-06-26 22:02:47 -0400108 */
109struct sde_irq {
110 u32 total_irqs;
Alan Kwonga172ef52016-09-27 00:29:10 -0400111 struct list_head *irq_cb_tbl;
112 atomic_t *enable_counts;
113 atomic_t *irq_counts;
Ben Chan78647cd2016-06-26 22:02:47 -0400114 spinlock_t cb_lock;
Alan Kwonga172ef52016-09-27 00:29:10 -0400115 struct dentry *debugfs_file;
Ben Chan78647cd2016-06-26 22:02:47 -0400116};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700117
Alan Kwong4dd64c82017-02-04 18:41:51 -0800118/**
119 * struct sde_kms_fbo - framebuffer memory object
120 * @refcount: reference/usage count of this object
121 * @dev: Pointer to containing drm device
122 * @width: width of the framebuffer
123 * @height: height of the framebuffer
124 * @flags: drm framebuffer flags
125 * @modifier: pixel format modifier of the framebuffer
126 * @fmt: Pointer to sde format descriptor
127 * @layout: sde format layout descriptor
128 * @ihandle: framebuffer object ion handle
129 * @dma_buf: framebuffer object dma buffer
130 * @bo: per plane buffer object
131 * @fb_list: llist of fb created from this buffer object
132 */
133struct sde_kms_fbo {
134 atomic_t refcount;
135 struct drm_device *dev;
136 u32 width, height;
137 u32 pixel_format;
138 u32 flags;
139 u64 modifier[4];
140 int nplane;
141 const struct sde_format *fmt;
142 struct sde_hw_fmt_layout layout;
143 struct dma_buf *dma_buf;
144 struct drm_gem_object *bo[4];
145 struct list_head fb_list;
146};
147
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700148struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400149 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700150 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700151 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700152 struct sde_mdss_cfg *catalog;
153
Alan Kwong112a84f2016-05-24 20:49:21 -0400154 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
155 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700156 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700157
Clarence Ip4ce59322016-06-26 22:27:51 -0400158 /* directory entry for debugfs */
Alan Kwongf0fd8512016-10-24 21:39:26 -0400159 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400160 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400161
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700162 /* io/register spaces: */
Gopikrishnaiah Anandan7e3e3f52016-12-22 11:13:05 -0800163 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400164 unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700165
166 struct regulator *vdd;
167 struct regulator *mmagic;
168 struct regulator *venus;
169
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400170 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400171
172 struct sde_hw_intr *hw_intr;
173 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400174
Alan Kwong67a3f792016-11-01 23:16:53 -0400175 struct sde_core_perf perf;
176
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400177 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500178 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400179
180 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
181 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400182 int dsi_display_count;
183 void **dsi_displays;
184 int wb_display_count;
185 void **wb_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400186
187 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400188};
189
190struct vsync_info {
191 u32 frame_count;
192 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700193};
194
195#define to_sde_kms(x) container_of(x, struct sde_kms, base)
196
Clarence Ip4c1d9772016-06-26 09:35:38 -0400197/**
Clarence Ipdd395242016-09-09 10:47:17 -0400198 * sde_is_custom_client - whether or not to enable non-standard customizations
199 *
200 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
201 */
202bool sde_is_custom_client(void);
203
204/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400205 * Debugfs functions - extra helper functions for debugfs support
206 *
207 * Main debugfs documentation is located at,
208 *
209 * Documentation/filesystems/debugfs.txt
210 *
211 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
212 * @sde_debugfs_create_regset32: Create 32-bit register dump file
213 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
214 */
215
216/**
217 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
218 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
219 */
220struct sde_debugfs_regset32 {
221 uint32_t offset;
222 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400223 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400224};
225
226/**
227 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
228 * This function is meant to initialize sde_debugfs_regset32 structures for use
229 * with sde_debugfs_create_regset32.
230 * @regset: opaque register definition structure
231 * @offset: sub-block offset
232 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400233 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400234 */
235void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400236 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400237
238/**
239 * sde_debugfs_create_regset32 - Create register read back file for debugfs
240 *
241 * This function is almost identical to the standard debugfs_create_regset32()
242 * function, with the main difference being that a list of register
243 * names/offsets do not need to be provided. The 'read' function simply outputs
244 * sequential register values over a specified range.
245 *
246 * Similar to the related debugfs_create_regset32 API, the structure pointed to
247 * by regset needs to persist for the lifetime of the created file. The calling
248 * code is responsible for initialization/management of this structure.
249 *
250 * The structure pointed to by regset is meant to be opaque. Please use
251 * sde_debugfs_setup_regset32 to initialize it.
252 *
253 * @name: File name within debugfs
254 * @mode: File mode within debugfs
255 * @parent: Parent directory entry within debugfs, can be NULL
256 * @regset: Pointer to persistent register block definition
257 *
258 * Return: dentry pointer for newly created file, use either debugfs_remove()
259 * or debugfs_remove_recursive() (on a parent directory) to remove the
260 * file
261 */
262void *sde_debugfs_create_regset32(const char *name, umode_t mode,
263 void *parent, struct sde_debugfs_regset32 *regset);
264
265/**
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700266 * sde_debugfs_get_root - Return root directory entry for KMS's debugfs
Clarence Ip4ce59322016-06-26 22:27:51 -0400267 *
268 * The return value should be passed as the 'parent' argument to subsequent
269 * debugfs create calls.
270 *
271 * @sde_kms: Pointer to SDE's KMS structure
272 *
273 * Return: dentry pointer for SDE's debugfs location
274 */
275void *sde_debugfs_get_root(struct sde_kms *sde_kms);
276
277/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400278 * SDE info management functions
279 * These functions/definitions allow for building up a 'sde_info' structure
280 * containing one or more "key=value\n" entries.
281 */
282#define SDE_KMS_INFO_MAX_SIZE 4096
283
284/**
285 * struct sde_kms_info - connector information structure container
286 * @data: Array of information character data
287 * @len: Current length of information data
288 * @staged_len: Temporary data buffer length, commit to
289 * len using sde_kms_info_stop
290 * @start: Whether or not a partial data entry was just started
291 */
292struct sde_kms_info {
293 char data[SDE_KMS_INFO_MAX_SIZE];
294 uint32_t len;
295 uint32_t staged_len;
296 bool start;
297};
298
299/**
300 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
301 * @S: Pointer to sde_kms_info structure
302 * Returns: Pointer to byte data
303 */
304#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
305
306/**
307 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
308 * @S: Pointer to sde_kms_info structure
309 * Returns: Size of available byte data
310 */
311#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
312
313/**
314 * sde_kms_info_reset - reset sde_kms_info structure
315 * @info: Pointer to sde_kms_info structure
316 */
317void sde_kms_info_reset(struct sde_kms_info *info);
318
319/**
320 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
321 * @info: Pointer to sde_kms_info structure
322 * @key: Pointer to key string
323 * @value: Signed 32-bit integer value
324 */
325void sde_kms_info_add_keyint(struct sde_kms_info *info,
326 const char *key,
327 int32_t value);
328
329/**
330 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
331 * @info: Pointer to sde_kms_info structure
332 * @key: Pointer to key string
333 * @value: Pointer to string value
334 */
335void sde_kms_info_add_keystr(struct sde_kms_info *info,
336 const char *key,
337 const char *value);
338
339/**
340 * sde_kms_info_start - begin adding key to 'sde_kms_info'
341 * Usage:
342 * sde_kms_info_start(key)
343 * sde_kms_info_append(val_1)
344 * ...
345 * sde_kms_info_append(val_n)
346 * sde_kms_info_stop
347 * @info: Pointer to sde_kms_info structure
348 * @key: Pointer to key string
349 */
350void sde_kms_info_start(struct sde_kms_info *info,
351 const char *key);
352
353/**
354 * sde_kms_info_append - append value string to 'sde_kms_info'
355 * Usage:
356 * sde_kms_info_start(key)
357 * sde_kms_info_append(val_1)
358 * ...
359 * sde_kms_info_append(val_n)
360 * sde_kms_info_stop
361 * @info: Pointer to sde_kms_info structure
362 * @str: Pointer to partial value string
363 */
364void sde_kms_info_append(struct sde_kms_info *info,
365 const char *str);
366
367/**
368 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
369 * Usage:
370 * sde_kms_info_start(key)
371 * sde_kms_info_append_format(fourcc, modifier)
372 * ...
373 * sde_kms_info_stop
374 * @info: Pointer to sde_kms_info structure
375 * @pixel_format: FOURCC format code
376 * @modifier: 64-bit drm format modifier
377 */
378void sde_kms_info_append_format(struct sde_kms_info *info,
379 uint32_t pixel_format,
380 uint64_t modifier);
381
382/**
383 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
384 * Usage:
385 * sde_kms_info_start(key)
386 * sde_kms_info_append(val_1)
387 * ...
388 * sde_kms_info_append(val_n)
389 * sde_kms_info_stop
390 * @info: Pointer to sde_kms_info structure
391 */
392void sde_kms_info_stop(struct sde_kms_info *info);
393
394/**
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800395 * sde_kms_rect_intersect() - find the intersecting region between two rects
396 * @res: Intersecting region between the two rectangles
397 * @rect1: first rectangle coordinates
398 * @rect2: second rectangle coordinates
399 */
400void sde_kms_rect_intersect(struct sde_rect *res,
401 const struct sde_rect *rect1, const struct sde_rect *rect2);
402
403/**
Ben Chan78647cd2016-06-26 22:02:47 -0400404 * Vblank enable/disable functions
405 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700406int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
407void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
408
Alan Kwong4dd64c82017-02-04 18:41:51 -0800409/**
410 * sde_kms_fbo_create_fb - create framebuffer from given framebuffer object
411 * @dev: Pointer to drm device
412 * @fbo: Pointer to framebuffer object
413 * return: Pointer to drm framebuffer on success; NULL on error
414 */
415struct drm_framebuffer *sde_kms_fbo_create_fb(struct drm_device *dev,
416 struct sde_kms_fbo *fbo);
417
418/**
419 * sde_kms_fbo_alloc - create framebuffer object with given format parameters
420 * @dev: pointer to drm device
421 * @width: width of framebuffer
422 * @height: height of framebuffer
423 * @pixel_format: pixel format of framebuffer
424 * @modifier: pixel format modifier
425 * @flags: DRM_MODE_FB flags
426 * return: Pointer to framebuffer memory object on success; NULL on error
427 */
428struct sde_kms_fbo *sde_kms_fbo_alloc(struct drm_device *dev,
429 u32 width, u32 height, u32 pixel_format,
430 u64 modifiers[4], u32 flags);
431
432/**
433 * sde_kms_fbo_reference - increment reference count of given framebuffer object
434 * @fbo: Pointer to framebuffer memory object
435 * return: 0 on success; error code otherwise
436 */
437int sde_kms_fbo_reference(struct sde_kms_fbo *fbo);
438
439/**
440 * sde_kms_fbo_unreference - decrement reference count of given framebuffer
441 * object
442 * @fbo: Pointer to framebuffer memory object
443 * return: 0 on success; error code otherwise
444 */
445void sde_kms_fbo_unreference(struct sde_kms_fbo *fbo);
446
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700447#endif /* __sde_kms_H__ */