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