blob: 6990d1606d9d9f0821f0c0401bfb44712ed2eb82 [file] [log] [blame]
Clarence Ipaac9f332016-08-31 15:46:35 -04001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07002 *
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 Kwong112a84f2016-05-24 20:49:21 -040018#include "msm_mmu.h"
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040019#include "sde_dbg.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070020#include "sde_hw_catalog.h"
Clarence Ipc475b082016-06-26 09:27:23 -040021#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040022#include "sde_hw_lm.h"
Ben Chan78647cd2016-06-26 22:02:47 -040023#include "sde_hw_interrupts.h"
Alan Kwongd21960f2016-07-29 03:33:17 -040024#include "sde_hw_wb.h"
25#include "sde_hw_top.h"
Lloyd Atkinson11f34442016-08-11 11:19:52 -040026#include "sde_rm.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070027#include "sde_power_handle.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040028#include "sde_irq.h"
Ben Chan78647cd2016-06-26 22:02:47 -040029
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040030#define DRMID(x) ((x) ? (x)->base.id : -1)
31
Clarence Ip31c19b52016-06-10 15:42:08 -040032/**
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)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070039 DRM_DEBUG(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040040 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)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070051 DRM_ERROR(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040052 else \
53 pr_debug(fmt, ##__VA_ARGS__); \
54 } while (0)
55
Dhaval Patelb271b842016-10-19 21:41:22 -070056#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040057
Dhaval Patelec10fad2016-08-22 14:40:48 -070058#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 Ipfd96ba22016-09-09 16:45:44 -040069/**
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 Patel22ef6df2016-10-20 14:42:52 -070080#define SDE_NAME_SIZE 12
81
Ben Chan78647cd2016-06-26 22:02:47 -040082/*
83 * struct sde_irq_callback - IRQ callback handlers
Alan Kwonga172ef52016-09-27 00:29:10 -040084 * @list: list to callback
Ben Chan78647cd2016-06-26 22:02:47 -040085 * @func: intr handler
86 * @arg: argument for the handler
87 */
88struct sde_irq_callback {
Alan Kwonga172ef52016-09-27 00:29:10 -040089 struct list_head list;
Ben Chan78647cd2016-06-26 22:02:47 -040090 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 Kwonga172ef52016-09-27 00:29:10 -040098 * @enable_counts array of IRQ enable counts
Ben Chan78647cd2016-06-26 22:02:47 -040099 * @cb_lock: callback lock
Alan Kwonga172ef52016-09-27 00:29:10 -0400100 * @debugfs_file: debugfs file for irq statistics
Ben Chan78647cd2016-06-26 22:02:47 -0400101 */
102struct sde_irq {
103 u32 total_irqs;
Alan Kwonga172ef52016-09-27 00:29:10 -0400104 struct list_head *irq_cb_tbl;
105 atomic_t *enable_counts;
106 atomic_t *irq_counts;
Ben Chan78647cd2016-06-26 22:02:47 -0400107 spinlock_t cb_lock;
Alan Kwonga172ef52016-09-27 00:29:10 -0400108 struct dentry *debugfs_file;
Ben Chan78647cd2016-06-26 22:02:47 -0400109};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700110
111struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400112 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700113 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700114 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700115 struct sde_mdss_cfg *catalog;
116
Alan Kwong112a84f2016-05-24 20:49:21 -0400117 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
118 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700119 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700120
Clarence Ip4ce59322016-06-26 22:27:51 -0400121 /* directory entry for debugfs */
122 void *debugfs_root;
Alan Kwongcd1c09f2016-11-04 20:37:30 -0400123 struct dentry *debugfs_debug;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400124 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400125 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400126
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700127 /* io/register spaces: */
Alan Kwongdfa8c082016-07-29 04:10:00 -0400128 void __iomem *mmio, *vbif[VBIF_MAX];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700129
130 struct regulator *vdd;
131 struct regulator *mmagic;
132 struct regulator *venus;
133
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400134 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400135
136 struct sde_hw_intr *hw_intr;
137 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400138
139 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500140 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400141
142 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
143 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400144 int dsi_display_count;
145 void **dsi_displays;
146 int wb_display_count;
147 void **wb_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400148
149 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400150};
151
152struct vsync_info {
153 u32 frame_count;
154 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700155};
156
157#define to_sde_kms(x) container_of(x, struct sde_kms, base)
158
Clarence Ip4c1d9772016-06-26 09:35:38 -0400159/**
Clarence Ipdd395242016-09-09 10:47:17 -0400160 * sde_is_custom_client - whether or not to enable non-standard customizations
161 *
162 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
163 */
164bool sde_is_custom_client(void);
165
166/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400167 * Debugfs functions - extra helper functions for debugfs support
168 *
169 * Main debugfs documentation is located at,
170 *
171 * Documentation/filesystems/debugfs.txt
172 *
173 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
174 * @sde_debugfs_create_regset32: Create 32-bit register dump file
175 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
176 */
177
178/**
179 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
180 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
181 */
182struct sde_debugfs_regset32 {
183 uint32_t offset;
184 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400185 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400186};
187
188/**
189 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
190 * This function is meant to initialize sde_debugfs_regset32 structures for use
191 * with sde_debugfs_create_regset32.
192 * @regset: opaque register definition structure
193 * @offset: sub-block offset
194 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400195 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400196 */
197void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400198 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400199
200/**
201 * sde_debugfs_create_regset32 - Create register read back file for debugfs
202 *
203 * This function is almost identical to the standard debugfs_create_regset32()
204 * function, with the main difference being that a list of register
205 * names/offsets do not need to be provided. The 'read' function simply outputs
206 * sequential register values over a specified range.
207 *
208 * Similar to the related debugfs_create_regset32 API, the structure pointed to
209 * by regset needs to persist for the lifetime of the created file. The calling
210 * code is responsible for initialization/management of this structure.
211 *
212 * The structure pointed to by regset is meant to be opaque. Please use
213 * sde_debugfs_setup_regset32 to initialize it.
214 *
215 * @name: File name within debugfs
216 * @mode: File mode within debugfs
217 * @parent: Parent directory entry within debugfs, can be NULL
218 * @regset: Pointer to persistent register block definition
219 *
220 * Return: dentry pointer for newly created file, use either debugfs_remove()
221 * or debugfs_remove_recursive() (on a parent directory) to remove the
222 * file
223 */
224void *sde_debugfs_create_regset32(const char *name, umode_t mode,
225 void *parent, struct sde_debugfs_regset32 *regset);
226
227/**
228 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
229 *
230 * The return value should be passed as the 'parent' argument to subsequent
231 * debugfs create calls.
232 *
233 * @sde_kms: Pointer to SDE's KMS structure
234 *
235 * Return: dentry pointer for SDE's debugfs location
236 */
237void *sde_debugfs_get_root(struct sde_kms *sde_kms);
238
239/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400240 * SDE info management functions
241 * These functions/definitions allow for building up a 'sde_info' structure
242 * containing one or more "key=value\n" entries.
243 */
244#define SDE_KMS_INFO_MAX_SIZE 4096
245
246/**
247 * struct sde_kms_info - connector information structure container
248 * @data: Array of information character data
249 * @len: Current length of information data
250 * @staged_len: Temporary data buffer length, commit to
251 * len using sde_kms_info_stop
252 * @start: Whether or not a partial data entry was just started
253 */
254struct sde_kms_info {
255 char data[SDE_KMS_INFO_MAX_SIZE];
256 uint32_t len;
257 uint32_t staged_len;
258 bool start;
259};
260
261/**
262 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
263 * @S: Pointer to sde_kms_info structure
264 * Returns: Pointer to byte data
265 */
266#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
267
268/**
269 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
270 * @S: Pointer to sde_kms_info structure
271 * Returns: Size of available byte data
272 */
273#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
274
275/**
276 * sde_kms_info_reset - reset sde_kms_info structure
277 * @info: Pointer to sde_kms_info structure
278 */
279void sde_kms_info_reset(struct sde_kms_info *info);
280
281/**
282 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
283 * @info: Pointer to sde_kms_info structure
284 * @key: Pointer to key string
285 * @value: Signed 32-bit integer value
286 */
287void sde_kms_info_add_keyint(struct sde_kms_info *info,
288 const char *key,
289 int32_t value);
290
291/**
292 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
293 * @info: Pointer to sde_kms_info structure
294 * @key: Pointer to key string
295 * @value: Pointer to string value
296 */
297void sde_kms_info_add_keystr(struct sde_kms_info *info,
298 const char *key,
299 const char *value);
300
301/**
302 * sde_kms_info_start - begin adding key to 'sde_kms_info'
303 * Usage:
304 * sde_kms_info_start(key)
305 * sde_kms_info_append(val_1)
306 * ...
307 * sde_kms_info_append(val_n)
308 * sde_kms_info_stop
309 * @info: Pointer to sde_kms_info structure
310 * @key: Pointer to key string
311 */
312void sde_kms_info_start(struct sde_kms_info *info,
313 const char *key);
314
315/**
316 * sde_kms_info_append - append value string to 'sde_kms_info'
317 * Usage:
318 * sde_kms_info_start(key)
319 * sde_kms_info_append(val_1)
320 * ...
321 * sde_kms_info_append(val_n)
322 * sde_kms_info_stop
323 * @info: Pointer to sde_kms_info structure
324 * @str: Pointer to partial value string
325 */
326void sde_kms_info_append(struct sde_kms_info *info,
327 const char *str);
328
329/**
330 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
331 * Usage:
332 * sde_kms_info_start(key)
333 * sde_kms_info_append_format(fourcc, modifier)
334 * ...
335 * sde_kms_info_stop
336 * @info: Pointer to sde_kms_info structure
337 * @pixel_format: FOURCC format code
338 * @modifier: 64-bit drm format modifier
339 */
340void sde_kms_info_append_format(struct sde_kms_info *info,
341 uint32_t pixel_format,
342 uint64_t modifier);
343
344/**
345 * sde_kms_info_stop - finish 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 */
354void sde_kms_info_stop(struct sde_kms_info *info);
355
356/**
Ben Chan78647cd2016-06-26 22:02:47 -0400357 * Vblank enable/disable functions
358 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700359int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
360void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
361
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700362#endif /* __sde_kms_H__ */