blob: 0550b1904fc81632d1ed42fd904fab0f384e9198 [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"
Ben Chan78647cd2016-06-26 22:02:47 -040035
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040036#define DRMID(x) ((x) ? (x)->base.id : -1)
37
Clarence Ip31c19b52016-06-10 15:42:08 -040038/**
39 * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
40 * @fmt: Pointer to format string
41 */
42#define SDE_DEBUG(fmt, ...) \
43 do { \
44 if (unlikely(drm_debug & DRM_UT_KMS)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070045 DRM_DEBUG(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040046 else \
47 pr_debug(fmt, ##__VA_ARGS__); \
48 } while (0)
49
50/**
51 * SDE_DEBUG_DRIVER - macro for hardware driver logging
52 * @fmt: Pointer to format string
53 */
54#define SDE_DEBUG_DRIVER(fmt, ...) \
55 do { \
56 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070057 DRM_ERROR(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040058 else \
59 pr_debug(fmt, ##__VA_ARGS__); \
60 } while (0)
61
Dhaval Patelb271b842016-10-19 21:41:22 -070062#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040063
Dhaval Patelec10fad2016-08-22 14:40:48 -070064#define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
65 do { \
66 (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
67 (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
68 (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
69 (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
70 } while (0)
71
72#define CHECK_LAYER_BOUNDS(offset, size, max_size) \
73 (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
74
Clarence Ipfd96ba22016-09-09 16:45:44 -040075/**
76 * ktime_compare_safe - compare two ktime structures
77 * This macro is similar to the standard ktime_compare() function, but
78 * attempts to also handle ktime overflows.
79 * @A: First ktime value
80 * @B: Second ktime value
81 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
82 */
83#define ktime_compare_safe(A, B) \
84 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
85
Dhaval Patel22ef6df2016-10-20 14:42:52 -070086#define SDE_NAME_SIZE 12
87
Ben Chan78647cd2016-06-26 22:02:47 -040088/*
89 * struct sde_irq_callback - IRQ callback handlers
Alan Kwonga172ef52016-09-27 00:29:10 -040090 * @list: list to callback
Ben Chan78647cd2016-06-26 22:02:47 -040091 * @func: intr handler
92 * @arg: argument for the handler
93 */
94struct sde_irq_callback {
Alan Kwonga172ef52016-09-27 00:29:10 -040095 struct list_head list;
Ben Chan78647cd2016-06-26 22:02:47 -040096 void (*func)(void *arg, int irq_idx);
97 void *arg;
98};
99
100/**
101 * struct sde_irq: IRQ structure contains callback registration info
102 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
103 * @irq_cb_tbl: array of IRQ callbacks setting
Alan Kwonga172ef52016-09-27 00:29:10 -0400104 * @enable_counts array of IRQ enable counts
Ben Chan78647cd2016-06-26 22:02:47 -0400105 * @cb_lock: callback lock
Alan Kwonga172ef52016-09-27 00:29:10 -0400106 * @debugfs_file: debugfs file for irq statistics
Ben Chan78647cd2016-06-26 22:02:47 -0400107 */
108struct sde_irq {
109 u32 total_irqs;
Alan Kwonga172ef52016-09-27 00:29:10 -0400110 struct list_head *irq_cb_tbl;
111 atomic_t *enable_counts;
112 atomic_t *irq_counts;
Ben Chan78647cd2016-06-26 22:02:47 -0400113 spinlock_t cb_lock;
Alan Kwonga172ef52016-09-27 00:29:10 -0400114 struct dentry *debugfs_file;
Ben Chan78647cd2016-06-26 22:02:47 -0400115};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700116
117struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400118 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700119 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700120 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700121 struct sde_mdss_cfg *catalog;
122
Alan Kwong112a84f2016-05-24 20:49:21 -0400123 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
124 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700125 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700126
Clarence Ip4ce59322016-06-26 22:27:51 -0400127 /* directory entry for debugfs */
128 void *debugfs_root;
Alan Kwongcd1c09f2016-11-04 20:37:30 -0400129 struct dentry *debugfs_debug;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400130 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400131 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400132
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700133 /* io/register spaces: */
Gopikrishnaiah Anandan7e3e3f52016-12-22 11:13:05 -0800134 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
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
145 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500146 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400147
148 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
149 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400150 int dsi_display_count;
151 void **dsi_displays;
152 int wb_display_count;
153 void **wb_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400154
155 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400156};
157
158struct vsync_info {
159 u32 frame_count;
160 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700161};
162
163#define to_sde_kms(x) container_of(x, struct sde_kms, base)
164
Clarence Ip4c1d9772016-06-26 09:35:38 -0400165/**
Clarence Ipdd395242016-09-09 10:47:17 -0400166 * sde_is_custom_client - whether or not to enable non-standard customizations
167 *
168 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
169 */
170bool sde_is_custom_client(void);
171
172/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400173 * Debugfs functions - extra helper functions for debugfs support
174 *
175 * Main debugfs documentation is located at,
176 *
177 * Documentation/filesystems/debugfs.txt
178 *
179 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
180 * @sde_debugfs_create_regset32: Create 32-bit register dump file
181 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
182 */
183
184/**
185 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
186 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
187 */
188struct sde_debugfs_regset32 {
189 uint32_t offset;
190 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400191 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400192};
193
194/**
195 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
196 * This function is meant to initialize sde_debugfs_regset32 structures for use
197 * with sde_debugfs_create_regset32.
198 * @regset: opaque register definition structure
199 * @offset: sub-block offset
200 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400201 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400202 */
203void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400204 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400205
206/**
207 * sde_debugfs_create_regset32 - Create register read back file for debugfs
208 *
209 * This function is almost identical to the standard debugfs_create_regset32()
210 * function, with the main difference being that a list of register
211 * names/offsets do not need to be provided. The 'read' function simply outputs
212 * sequential register values over a specified range.
213 *
214 * Similar to the related debugfs_create_regset32 API, the structure pointed to
215 * by regset needs to persist for the lifetime of the created file. The calling
216 * code is responsible for initialization/management of this structure.
217 *
218 * The structure pointed to by regset is meant to be opaque. Please use
219 * sde_debugfs_setup_regset32 to initialize it.
220 *
221 * @name: File name within debugfs
222 * @mode: File mode within debugfs
223 * @parent: Parent directory entry within debugfs, can be NULL
224 * @regset: Pointer to persistent register block definition
225 *
226 * Return: dentry pointer for newly created file, use either debugfs_remove()
227 * or debugfs_remove_recursive() (on a parent directory) to remove the
228 * file
229 */
230void *sde_debugfs_create_regset32(const char *name, umode_t mode,
231 void *parent, struct sde_debugfs_regset32 *regset);
232
233/**
234 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
235 *
236 * The return value should be passed as the 'parent' argument to subsequent
237 * debugfs create calls.
238 *
239 * @sde_kms: Pointer to SDE's KMS structure
240 *
241 * Return: dentry pointer for SDE's debugfs location
242 */
243void *sde_debugfs_get_root(struct sde_kms *sde_kms);
244
245/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400246 * SDE info management functions
247 * These functions/definitions allow for building up a 'sde_info' structure
248 * containing one or more "key=value\n" entries.
249 */
250#define SDE_KMS_INFO_MAX_SIZE 4096
251
252/**
253 * struct sde_kms_info - connector information structure container
254 * @data: Array of information character data
255 * @len: Current length of information data
256 * @staged_len: Temporary data buffer length, commit to
257 * len using sde_kms_info_stop
258 * @start: Whether or not a partial data entry was just started
259 */
260struct sde_kms_info {
261 char data[SDE_KMS_INFO_MAX_SIZE];
262 uint32_t len;
263 uint32_t staged_len;
264 bool start;
265};
266
267/**
268 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
269 * @S: Pointer to sde_kms_info structure
270 * Returns: Pointer to byte data
271 */
272#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
273
274/**
275 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
276 * @S: Pointer to sde_kms_info structure
277 * Returns: Size of available byte data
278 */
279#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
280
281/**
282 * sde_kms_info_reset - reset sde_kms_info structure
283 * @info: Pointer to sde_kms_info structure
284 */
285void sde_kms_info_reset(struct sde_kms_info *info);
286
287/**
288 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
289 * @info: Pointer to sde_kms_info structure
290 * @key: Pointer to key string
291 * @value: Signed 32-bit integer value
292 */
293void sde_kms_info_add_keyint(struct sde_kms_info *info,
294 const char *key,
295 int32_t value);
296
297/**
298 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
299 * @info: Pointer to sde_kms_info structure
300 * @key: Pointer to key string
301 * @value: Pointer to string value
302 */
303void sde_kms_info_add_keystr(struct sde_kms_info *info,
304 const char *key,
305 const char *value);
306
307/**
308 * sde_kms_info_start - begin adding key to 'sde_kms_info'
309 * Usage:
310 * sde_kms_info_start(key)
311 * sde_kms_info_append(val_1)
312 * ...
313 * sde_kms_info_append(val_n)
314 * sde_kms_info_stop
315 * @info: Pointer to sde_kms_info structure
316 * @key: Pointer to key string
317 */
318void sde_kms_info_start(struct sde_kms_info *info,
319 const char *key);
320
321/**
322 * sde_kms_info_append - append value string to 'sde_kms_info'
323 * Usage:
324 * sde_kms_info_start(key)
325 * sde_kms_info_append(val_1)
326 * ...
327 * sde_kms_info_append(val_n)
328 * sde_kms_info_stop
329 * @info: Pointer to sde_kms_info structure
330 * @str: Pointer to partial value string
331 */
332void sde_kms_info_append(struct sde_kms_info *info,
333 const char *str);
334
335/**
336 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
337 * Usage:
338 * sde_kms_info_start(key)
339 * sde_kms_info_append_format(fourcc, modifier)
340 * ...
341 * sde_kms_info_stop
342 * @info: Pointer to sde_kms_info structure
343 * @pixel_format: FOURCC format code
344 * @modifier: 64-bit drm format modifier
345 */
346void sde_kms_info_append_format(struct sde_kms_info *info,
347 uint32_t pixel_format,
348 uint64_t modifier);
349
350/**
351 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
352 * Usage:
353 * sde_kms_info_start(key)
354 * sde_kms_info_append(val_1)
355 * ...
356 * sde_kms_info_append(val_n)
357 * sde_kms_info_stop
358 * @info: Pointer to sde_kms_info structure
359 */
360void sde_kms_info_stop(struct sde_kms_info *info);
361
362/**
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800363 * sde_kms_rect_intersect() - find the intersecting region between two rects
364 * @res: Intersecting region between the two rectangles
365 * @rect1: first rectangle coordinates
366 * @rect2: second rectangle coordinates
367 */
368void sde_kms_rect_intersect(struct sde_rect *res,
369 const struct sde_rect *rect1, const struct sde_rect *rect2);
370
371/**
Ben Chan78647cd2016-06-26 22:02:47 -0400372 * Vblank enable/disable functions
373 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700374int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
375void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
376
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700377#endif /* __sde_kms_H__ */