blob: 1acdf00be2b3e9012e74926d34deff209afbc390 [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
118struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400119 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700120 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700121 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700122 struct sde_mdss_cfg *catalog;
123
Alan Kwong112a84f2016-05-24 20:49:21 -0400124 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
125 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700126 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700127
Clarence Ip4ce59322016-06-26 22:27:51 -0400128 /* directory entry for debugfs */
Alan Kwongf0fd8512016-10-24 21:39:26 -0400129 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400130 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400131
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700132 /* io/register spaces: */
Gopikrishnaiah Anandan7e3e3f52016-12-22 11:13:05 -0800133 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400134 unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700135
136 struct regulator *vdd;
137 struct regulator *mmagic;
138 struct regulator *venus;
139
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400140 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400141
142 struct sde_hw_intr *hw_intr;
143 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400144
Alan Kwong67a3f792016-11-01 23:16:53 -0400145 struct sde_core_perf perf;
146
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400147 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500148 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400149
150 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
151 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400152 int dsi_display_count;
153 void **dsi_displays;
154 int wb_display_count;
155 void **wb_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400156
157 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400158};
159
160struct vsync_info {
161 u32 frame_count;
162 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700163};
164
165#define to_sde_kms(x) container_of(x, struct sde_kms, base)
166
Clarence Ip4c1d9772016-06-26 09:35:38 -0400167/**
Clarence Ipdd395242016-09-09 10:47:17 -0400168 * sde_is_custom_client - whether or not to enable non-standard customizations
169 *
170 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
171 */
172bool sde_is_custom_client(void);
173
174/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400175 * Debugfs functions - extra helper functions for debugfs support
176 *
177 * Main debugfs documentation is located at,
178 *
179 * Documentation/filesystems/debugfs.txt
180 *
181 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
182 * @sde_debugfs_create_regset32: Create 32-bit register dump file
183 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
184 */
185
186/**
187 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
188 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
189 */
190struct sde_debugfs_regset32 {
191 uint32_t offset;
192 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400193 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400194};
195
196/**
197 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
198 * This function is meant to initialize sde_debugfs_regset32 structures for use
199 * with sde_debugfs_create_regset32.
200 * @regset: opaque register definition structure
201 * @offset: sub-block offset
202 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400203 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400204 */
205void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400206 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400207
208/**
209 * sde_debugfs_create_regset32 - Create register read back file for debugfs
210 *
211 * This function is almost identical to the standard debugfs_create_regset32()
212 * function, with the main difference being that a list of register
213 * names/offsets do not need to be provided. The 'read' function simply outputs
214 * sequential register values over a specified range.
215 *
216 * Similar to the related debugfs_create_regset32 API, the structure pointed to
217 * by regset needs to persist for the lifetime of the created file. The calling
218 * code is responsible for initialization/management of this structure.
219 *
220 * The structure pointed to by regset is meant to be opaque. Please use
221 * sde_debugfs_setup_regset32 to initialize it.
222 *
223 * @name: File name within debugfs
224 * @mode: File mode within debugfs
225 * @parent: Parent directory entry within debugfs, can be NULL
226 * @regset: Pointer to persistent register block definition
227 *
228 * Return: dentry pointer for newly created file, use either debugfs_remove()
229 * or debugfs_remove_recursive() (on a parent directory) to remove the
230 * file
231 */
232void *sde_debugfs_create_regset32(const char *name, umode_t mode,
233 void *parent, struct sde_debugfs_regset32 *regset);
234
235/**
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700236 * sde_debugfs_get_root - Return root directory entry for KMS's debugfs
Clarence Ip4ce59322016-06-26 22:27:51 -0400237 *
238 * The return value should be passed as the 'parent' argument to subsequent
239 * debugfs create calls.
240 *
241 * @sde_kms: Pointer to SDE's KMS structure
242 *
243 * Return: dentry pointer for SDE's debugfs location
244 */
245void *sde_debugfs_get_root(struct sde_kms *sde_kms);
246
247/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400248 * SDE info management functions
249 * These functions/definitions allow for building up a 'sde_info' structure
250 * containing one or more "key=value\n" entries.
251 */
252#define SDE_KMS_INFO_MAX_SIZE 4096
253
254/**
255 * struct sde_kms_info - connector information structure container
256 * @data: Array of information character data
257 * @len: Current length of information data
258 * @staged_len: Temporary data buffer length, commit to
259 * len using sde_kms_info_stop
260 * @start: Whether or not a partial data entry was just started
261 */
262struct sde_kms_info {
263 char data[SDE_KMS_INFO_MAX_SIZE];
264 uint32_t len;
265 uint32_t staged_len;
266 bool start;
267};
268
269/**
270 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
271 * @S: Pointer to sde_kms_info structure
272 * Returns: Pointer to byte data
273 */
274#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
275
276/**
277 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
278 * @S: Pointer to sde_kms_info structure
279 * Returns: Size of available byte data
280 */
281#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
282
283/**
284 * sde_kms_info_reset - reset sde_kms_info structure
285 * @info: Pointer to sde_kms_info structure
286 */
287void sde_kms_info_reset(struct sde_kms_info *info);
288
289/**
290 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
291 * @info: Pointer to sde_kms_info structure
292 * @key: Pointer to key string
293 * @value: Signed 32-bit integer value
294 */
295void sde_kms_info_add_keyint(struct sde_kms_info *info,
296 const char *key,
297 int32_t value);
298
299/**
300 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
301 * @info: Pointer to sde_kms_info structure
302 * @key: Pointer to key string
303 * @value: Pointer to string value
304 */
305void sde_kms_info_add_keystr(struct sde_kms_info *info,
306 const char *key,
307 const char *value);
308
309/**
310 * sde_kms_info_start - begin adding key to 'sde_kms_info'
311 * Usage:
312 * sde_kms_info_start(key)
313 * sde_kms_info_append(val_1)
314 * ...
315 * sde_kms_info_append(val_n)
316 * sde_kms_info_stop
317 * @info: Pointer to sde_kms_info structure
318 * @key: Pointer to key string
319 */
320void sde_kms_info_start(struct sde_kms_info *info,
321 const char *key);
322
323/**
324 * sde_kms_info_append - append value string to 'sde_kms_info'
325 * Usage:
326 * sde_kms_info_start(key)
327 * sde_kms_info_append(val_1)
328 * ...
329 * sde_kms_info_append(val_n)
330 * sde_kms_info_stop
331 * @info: Pointer to sde_kms_info structure
332 * @str: Pointer to partial value string
333 */
334void sde_kms_info_append(struct sde_kms_info *info,
335 const char *str);
336
337/**
338 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
339 * Usage:
340 * sde_kms_info_start(key)
341 * sde_kms_info_append_format(fourcc, modifier)
342 * ...
343 * sde_kms_info_stop
344 * @info: Pointer to sde_kms_info structure
345 * @pixel_format: FOURCC format code
346 * @modifier: 64-bit drm format modifier
347 */
348void sde_kms_info_append_format(struct sde_kms_info *info,
349 uint32_t pixel_format,
350 uint64_t modifier);
351
352/**
353 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
354 * Usage:
355 * sde_kms_info_start(key)
356 * sde_kms_info_append(val_1)
357 * ...
358 * sde_kms_info_append(val_n)
359 * sde_kms_info_stop
360 * @info: Pointer to sde_kms_info structure
361 */
362void sde_kms_info_stop(struct sde_kms_info *info);
363
364/**
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800365 * sde_kms_rect_intersect() - find the intersecting region between two rects
366 * @res: Intersecting region between the two rectangles
367 * @rect1: first rectangle coordinates
368 * @rect2: second rectangle coordinates
369 */
370void sde_kms_rect_intersect(struct sde_rect *res,
371 const struct sde_rect *rect1, const struct sde_rect *rect2);
372
373/**
Ben Chan78647cd2016-06-26 22:02:47 -0400374 * Vblank enable/disable functions
375 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700376int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
377void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
378
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700379#endif /* __sde_kms_H__ */