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