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