blob: 2a17ccb115f756bff04a878f7f15a6841f24294a [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)) \
39 drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
40 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)) \
51 drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
52 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;
Clarence Ip4ce59322016-06-26 22:27:51 -0400124
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700125 /* io/register spaces: */
Alan Kwongdfa8c082016-07-29 04:10:00 -0400126 void __iomem *mmio, *vbif[VBIF_MAX];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700127
128 struct regulator *vdd;
129 struct regulator *mmagic;
130 struct regulator *venus;
131
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400132 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400133
134 struct sde_hw_intr *hw_intr;
135 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400136
137 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500138 bool rm_init;
Alan Kwong5d324e42016-07-28 22:56:18 -0400139
140 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
141 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400142 int dsi_display_count;
143 void **dsi_displays;
144 int wb_display_count;
145 void **wb_displays;
Ben Chan78647cd2016-06-26 22:02:47 -0400146};
147
148struct vsync_info {
149 u32 frame_count;
150 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700151};
152
153#define to_sde_kms(x) container_of(x, struct sde_kms, base)
154
Clarence Ip4c1d9772016-06-26 09:35:38 -0400155/**
Clarence Ipdd395242016-09-09 10:47:17 -0400156 * sde_is_custom_client - whether or not to enable non-standard customizations
157 *
158 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
159 */
160bool sde_is_custom_client(void);
161
162/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400163 * Debugfs functions - extra helper functions for debugfs support
164 *
165 * Main debugfs documentation is located at,
166 *
167 * Documentation/filesystems/debugfs.txt
168 *
169 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
170 * @sde_debugfs_create_regset32: Create 32-bit register dump file
171 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
172 */
173
174/**
175 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
176 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
177 */
178struct sde_debugfs_regset32 {
179 uint32_t offset;
180 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400181 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400182};
183
184/**
185 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
186 * This function is meant to initialize sde_debugfs_regset32 structures for use
187 * with sde_debugfs_create_regset32.
188 * @regset: opaque register definition structure
189 * @offset: sub-block offset
190 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400191 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400192 */
193void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400194 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400195
196/**
197 * sde_debugfs_create_regset32 - Create register read back file for debugfs
198 *
199 * This function is almost identical to the standard debugfs_create_regset32()
200 * function, with the main difference being that a list of register
201 * names/offsets do not need to be provided. The 'read' function simply outputs
202 * sequential register values over a specified range.
203 *
204 * Similar to the related debugfs_create_regset32 API, the structure pointed to
205 * by regset needs to persist for the lifetime of the created file. The calling
206 * code is responsible for initialization/management of this structure.
207 *
208 * The structure pointed to by regset is meant to be opaque. Please use
209 * sde_debugfs_setup_regset32 to initialize it.
210 *
211 * @name: File name within debugfs
212 * @mode: File mode within debugfs
213 * @parent: Parent directory entry within debugfs, can be NULL
214 * @regset: Pointer to persistent register block definition
215 *
216 * Return: dentry pointer for newly created file, use either debugfs_remove()
217 * or debugfs_remove_recursive() (on a parent directory) to remove the
218 * file
219 */
220void *sde_debugfs_create_regset32(const char *name, umode_t mode,
221 void *parent, struct sde_debugfs_regset32 *regset);
222
223/**
224 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
225 *
226 * The return value should be passed as the 'parent' argument to subsequent
227 * debugfs create calls.
228 *
229 * @sde_kms: Pointer to SDE's KMS structure
230 *
231 * Return: dentry pointer for SDE's debugfs location
232 */
233void *sde_debugfs_get_root(struct sde_kms *sde_kms);
234
235/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400236 * SDE info management functions
237 * These functions/definitions allow for building up a 'sde_info' structure
238 * containing one or more "key=value\n" entries.
239 */
240#define SDE_KMS_INFO_MAX_SIZE 4096
241
242/**
243 * struct sde_kms_info - connector information structure container
244 * @data: Array of information character data
245 * @len: Current length of information data
246 * @staged_len: Temporary data buffer length, commit to
247 * len using sde_kms_info_stop
248 * @start: Whether or not a partial data entry was just started
249 */
250struct sde_kms_info {
251 char data[SDE_KMS_INFO_MAX_SIZE];
252 uint32_t len;
253 uint32_t staged_len;
254 bool start;
255};
256
257/**
258 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
259 * @S: Pointer to sde_kms_info structure
260 * Returns: Pointer to byte data
261 */
262#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
263
264/**
265 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
266 * @S: Pointer to sde_kms_info structure
267 * Returns: Size of available byte data
268 */
269#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
270
271/**
272 * sde_kms_info_reset - reset sde_kms_info structure
273 * @info: Pointer to sde_kms_info structure
274 */
275void sde_kms_info_reset(struct sde_kms_info *info);
276
277/**
278 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
279 * @info: Pointer to sde_kms_info structure
280 * @key: Pointer to key string
281 * @value: Signed 32-bit integer value
282 */
283void sde_kms_info_add_keyint(struct sde_kms_info *info,
284 const char *key,
285 int32_t value);
286
287/**
288 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
289 * @info: Pointer to sde_kms_info structure
290 * @key: Pointer to key string
291 * @value: Pointer to string value
292 */
293void sde_kms_info_add_keystr(struct sde_kms_info *info,
294 const char *key,
295 const char *value);
296
297/**
298 * sde_kms_info_start - begin adding key to 'sde_kms_info'
299 * Usage:
300 * sde_kms_info_start(key)
301 * sde_kms_info_append(val_1)
302 * ...
303 * sde_kms_info_append(val_n)
304 * sde_kms_info_stop
305 * @info: Pointer to sde_kms_info structure
306 * @key: Pointer to key string
307 */
308void sde_kms_info_start(struct sde_kms_info *info,
309 const char *key);
310
311/**
312 * sde_kms_info_append - append value string 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 * @str: Pointer to partial value string
321 */
322void sde_kms_info_append(struct sde_kms_info *info,
323 const char *str);
324
325/**
326 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
327 * Usage:
328 * sde_kms_info_start(key)
329 * sde_kms_info_append_format(fourcc, modifier)
330 * ...
331 * sde_kms_info_stop
332 * @info: Pointer to sde_kms_info structure
333 * @pixel_format: FOURCC format code
334 * @modifier: 64-bit drm format modifier
335 */
336void sde_kms_info_append_format(struct sde_kms_info *info,
337 uint32_t pixel_format,
338 uint64_t modifier);
339
340/**
341 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
342 * Usage:
343 * sde_kms_info_start(key)
344 * sde_kms_info_append(val_1)
345 * ...
346 * sde_kms_info_append(val_n)
347 * sde_kms_info_stop
348 * @info: Pointer to sde_kms_info structure
349 */
350void sde_kms_info_stop(struct sde_kms_info *info);
351
352/**
Ben Chan78647cd2016-06-26 22:02:47 -0400353 * Vblank enable/disable functions
354 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700355int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
356void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
357
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700358#endif /* __sde_kms_H__ */