blob: 501797bcc4659fa2b568515ed2b06a06904a2a8b [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
Alan Kwong54125bb2017-02-26 16:01:36 -080022#include <linux/msm_ion.h>
Alan Kwong23afc2d92017-09-15 10:59:06 -040023#include <linux/pm_domain.h>
Lloyd Atkinson1fb32ea2017-10-10 17:10:28 -040024#include <linux/pm_qos.h>
Alan Kwong54125bb2017-02-26 16:01:36 -080025
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070026#include "msm_drv.h"
27#include "msm_kms.h"
Alan Kwong112a84f2016-05-24 20:49:21 -040028#include "msm_mmu.h"
Jordan Crouse12bf3622017-02-13 10:14:11 -070029#include "msm_gem.h"
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040030#include "sde_dbg.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070031#include "sde_hw_catalog.h"
Clarence Ipc475b082016-06-26 09:27:23 -040032#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040033#include "sde_hw_lm.h"
Shashank Babu Chinta Venkata5d641d42017-09-29 12:16:28 -070034#include "sde_hw_pingpong.h"
Ben Chan78647cd2016-06-26 22:02:47 -040035#include "sde_hw_interrupts.h"
Alan Kwongd21960f2016-07-29 03:33:17 -040036#include "sde_hw_wb.h"
37#include "sde_hw_top.h"
Lloyd Atkinson11f34442016-08-11 11:19:52 -040038#include "sde_rm.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070039#include "sde_power_handle.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040040#include "sde_irq.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040041#include "sde_core_perf.h"
Ben Chan78647cd2016-06-26 22:02:47 -040042
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040043#define DRMID(x) ((x) ? (x)->base.id : -1)
44
Clarence Ip31c19b52016-06-10 15:42:08 -040045/**
46 * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
47 * @fmt: Pointer to format string
48 */
49#define SDE_DEBUG(fmt, ...) \
50 do { \
51 if (unlikely(drm_debug & DRM_UT_KMS)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070052 DRM_DEBUG(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040053 else \
54 pr_debug(fmt, ##__VA_ARGS__); \
55 } while (0)
56
57/**
58 * SDE_DEBUG_DRIVER - macro for hardware driver logging
59 * @fmt: Pointer to format string
60 */
61#define SDE_DEBUG_DRIVER(fmt, ...) \
62 do { \
63 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
Dhaval Patel04c7e8e2016-09-26 20:14:31 -070064 DRM_ERROR(fmt, ##__VA_ARGS__); \
Clarence Ip31c19b52016-06-10 15:42:08 -040065 else \
66 pr_debug(fmt, ##__VA_ARGS__); \
67 } while (0)
68
Dhaval Patelb271b842016-10-19 21:41:22 -070069#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040070
Dhaval Patelec10fad2016-08-22 14:40:48 -070071#define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
72 do { \
73 (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
74 (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
75 (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
76 (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
77 } while (0)
78
79#define CHECK_LAYER_BOUNDS(offset, size, max_size) \
80 (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
81
Clarence Ipfd96ba22016-09-09 16:45:44 -040082/**
83 * ktime_compare_safe - compare two ktime structures
84 * This macro is similar to the standard ktime_compare() function, but
85 * attempts to also handle ktime overflows.
86 * @A: First ktime value
87 * @B: Second ktime value
88 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
89 */
90#define ktime_compare_safe(A, B) \
91 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
92
Dhaval Patel22ef6df2016-10-20 14:42:52 -070093#define SDE_NAME_SIZE 12
94
Veera Sundaram Sankaran7ee99092017-06-13 11:19:36 -070095/* timeout in frames waiting for frame done */
96#define SDE_FRAME_DONE_TIMEOUT 60
97
Abhijit Kulkarni7444a7d2017-06-21 18:53:36 -070098/* max active secure client counts allowed */
99#define MAX_ALLOWED_SECURE_CLIENT_CNT 1
100
101/* max active crtc when secure client is active */
102#define MAX_ALLOWED_CRTC_CNT_DURING_SECURE 1
103
104/* max virtual encoders per secure crtc */
105#define MAX_ALLOWED_ENCODER_CNT_PER_SECURE_CRTC 1
106
Abhijit Kulkarni1b3340c2017-06-22 12:39:37 -0700107/* defines the operations required for secure state transition */
108#define SDE_KMS_OPS_CRTC_SECURE_STATE_CHANGE BIT(0)
109#define SDE_KMS_OPS_WAIT_FOR_TX_DONE BIT(1)
110#define SDE_KMS_OPS_CLEANUP_PLANE_FB BIT(2)
111#define SDE_KMS_OPS_PREPARE_PLANE_FB BIT(3)
112
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530113/* ESD status check interval in miliseconds */
114#define STATUS_CHECK_INTERVAL_MS 5000
115
Ben Chan78647cd2016-06-26 22:02:47 -0400116/*
117 * struct sde_irq_callback - IRQ callback handlers
Alan Kwonga172ef52016-09-27 00:29:10 -0400118 * @list: list to callback
Ben Chan78647cd2016-06-26 22:02:47 -0400119 * @func: intr handler
120 * @arg: argument for the handler
121 */
122struct sde_irq_callback {
Alan Kwonga172ef52016-09-27 00:29:10 -0400123 struct list_head list;
Ben Chan78647cd2016-06-26 22:02:47 -0400124 void (*func)(void *arg, int irq_idx);
125 void *arg;
126};
127
128/**
129 * struct sde_irq: IRQ structure contains callback registration info
130 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
131 * @irq_cb_tbl: array of IRQ callbacks setting
Alan Kwonga172ef52016-09-27 00:29:10 -0400132 * @enable_counts array of IRQ enable counts
Ben Chan78647cd2016-06-26 22:02:47 -0400133 * @cb_lock: callback lock
Alan Kwonga172ef52016-09-27 00:29:10 -0400134 * @debugfs_file: debugfs file for irq statistics
Ben Chan78647cd2016-06-26 22:02:47 -0400135 */
136struct sde_irq {
137 u32 total_irqs;
Alan Kwonga172ef52016-09-27 00:29:10 -0400138 struct list_head *irq_cb_tbl;
139 atomic_t *enable_counts;
140 atomic_t *irq_counts;
Ben Chan78647cd2016-06-26 22:02:47 -0400141 spinlock_t cb_lock;
Alan Kwonga172ef52016-09-27 00:29:10 -0400142 struct dentry *debugfs_file;
Ben Chan78647cd2016-06-26 22:02:47 -0400143};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700144
Alan Kwong4dd64c82017-02-04 18:41:51 -0800145/**
146 * struct sde_kms_fbo - framebuffer memory object
147 * @refcount: reference/usage count of this object
148 * @dev: Pointer to containing drm device
149 * @width: width of the framebuffer
150 * @height: height of the framebuffer
151 * @flags: drm framebuffer flags
152 * @modifier: pixel format modifier of the framebuffer
153 * @fmt: Pointer to sde format descriptor
154 * @layout: sde format layout descriptor
155 * @ihandle: framebuffer object ion handle
156 * @dma_buf: framebuffer object dma buffer
157 * @bo: per plane buffer object
158 * @fb_list: llist of fb created from this buffer object
159 */
160struct sde_kms_fbo {
161 atomic_t refcount;
162 struct drm_device *dev;
163 u32 width, height;
164 u32 pixel_format;
165 u32 flags;
166 u64 modifier[4];
167 int nplane;
168 const struct sde_format *fmt;
169 struct sde_hw_fmt_layout layout;
Alan Kwong54125bb2017-02-26 16:01:36 -0800170 struct ion_handle *ihandle;
Alan Kwong4dd64c82017-02-04 18:41:51 -0800171 struct dma_buf *dma_buf;
172 struct drm_gem_object *bo[4];
173 struct list_head fb_list;
174};
175
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700176struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400177 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700178 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700179 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700180 struct sde_mdss_cfg *catalog;
181
Alan Kwong23afc2d92017-09-15 10:59:06 -0400182 struct generic_pm_domain genpd;
183 bool genpd_init;
184
Jordan Crouse12bf3622017-02-13 10:14:11 -0700185 struct msm_gem_address_space *aspace[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700186 struct sde_power_client *core_client;
Lloyd Atkinson1fb32ea2017-10-10 17:10:28 -0400187 struct pm_qos_request pm_qos_cpu_req;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700188
Alan Kwong54125bb2017-02-26 16:01:36 -0800189 struct ion_client *iclient;
Clarence Ip7f0de632017-05-31 14:59:14 -0400190 struct sde_power_event *power_event;
Alan Kwong54125bb2017-02-26 16:01:36 -0800191
Clarence Ip4ce59322016-06-26 22:27:51 -0400192 /* directory entry for debugfs */
Alan Kwongf0fd8512016-10-24 21:39:26 -0400193 struct dentry *debugfs_danger;
Alan Kwong748e833d2016-10-26 12:34:48 -0400194 struct dentry *debugfs_vbif;
Clarence Ip4ce59322016-06-26 22:27:51 -0400195
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700196 /* io/register spaces: */
Gopikrishnaiah Anandan7e3e3f52016-12-22 11:13:05 -0800197 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400198 unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700199
200 struct regulator *vdd;
201 struct regulator *mmagic;
202 struct regulator *venus;
203
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400204 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400205
206 struct sde_hw_intr *hw_intr;
207 struct sde_irq irq_obj;
Alan Kwong9485ecc2017-10-06 18:09:38 -0400208 int irq_num; /* mdss irq number */
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400209
Alan Kwong67a3f792016-11-01 23:16:53 -0400210 struct sde_core_perf perf;
211
Clarence Ipd86f6e42017-08-08 18:31:00 -0400212 /* saved atomic state during system suspend */
213 struct drm_atomic_state *suspend_state;
214 bool suspend_block;
215
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400216 struct sde_rm rm;
Clarence Ip17162b52016-11-24 17:06:29 -0500217 bool rm_init;
Shashank Babu Chinta Venkata5d641d42017-09-29 12:16:28 -0700218 struct sde_splash_data splash_data;
219 bool cont_splash_en;
Alan Kwong5d324e42016-07-28 22:56:18 -0400220 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
221 struct sde_hw_mdp *hw_mdp;
Clarence Ip3649f8b2016-10-31 09:59:44 -0400222 int dsi_display_count;
223 void **dsi_displays;
224 int wb_display_count;
225 void **wb_displays;
Padmanabhan Komanduru63758612017-05-23 01:47:18 -0700226 int dp_display_count;
227 void **dp_displays;
Alan Kwongf0fd8512016-10-24 21:39:26 -0400228
229 bool has_danger_ctrl;
Ben Chan78647cd2016-06-26 22:02:47 -0400230};
231
232struct vsync_info {
233 u32 frame_count;
234 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700235};
236
237#define to_sde_kms(x) container_of(x, struct sde_kms, base)
238
Clarence Ip4c1d9772016-06-26 09:35:38 -0400239/**
Clarence Ipdd395242016-09-09 10:47:17 -0400240 * sde_is_custom_client - whether or not to enable non-standard customizations
241 *
242 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
243 */
244bool sde_is_custom_client(void);
245
246/**
Alan Kwong1124f1f2017-11-10 18:14:39 -0500247 * sde_kms_power_resource_is_enabled - whether or not power resource is enabled
248 * @dev: Pointer to drm device
249 * Return: true if power resource is enabled; false otherwise
250 */
251static inline bool sde_kms_power_resource_is_enabled(struct drm_device *dev)
252{
253 struct msm_drm_private *priv;
254
255 if (!dev || !dev->dev_private)
256 return false;
257
258 priv = dev->dev_private;
259
260 return sde_power_resource_is_enabled(&priv->phandle);
261}
262
263/**
Clarence Ipd86f6e42017-08-08 18:31:00 -0400264 * sde_kms_is_suspend_state - whether or not the system is pm suspended
265 * @dev: Pointer to drm device
266 * Return: Suspend status
267 */
268static inline bool sde_kms_is_suspend_state(struct drm_device *dev)
269{
270 if (!ddev_to_msm_kms(dev))
271 return false;
272
273 return to_sde_kms(ddev_to_msm_kms(dev))->suspend_state != NULL;
274}
275
276/**
277 * sde_kms_is_suspend_blocked - whether or not commits are blocked due to pm
278 * suspend status
279 * @dev: Pointer to drm device
280 * Return: True if commits should be rejected due to pm suspend
281 */
282static inline bool sde_kms_is_suspend_blocked(struct drm_device *dev)
283{
284 if (!sde_kms_is_suspend_state(dev))
285 return false;
286
287 return to_sde_kms(ddev_to_msm_kms(dev))->suspend_block;
288}
289
290/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400291 * Debugfs functions - extra helper functions for debugfs support
292 *
293 * Main debugfs documentation is located at,
294 *
295 * Documentation/filesystems/debugfs.txt
296 *
297 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
298 * @sde_debugfs_create_regset32: Create 32-bit register dump file
299 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
300 */
301
302/**
303 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
304 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
305 */
306struct sde_debugfs_regset32 {
307 uint32_t offset;
308 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400309 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400310};
311
312/**
313 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
314 * This function is meant to initialize sde_debugfs_regset32 structures for use
315 * with sde_debugfs_create_regset32.
316 * @regset: opaque register definition structure
317 * @offset: sub-block offset
318 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400319 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400320 */
321void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400322 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400323
324/**
325 * sde_debugfs_create_regset32 - Create register read back file for debugfs
326 *
327 * This function is almost identical to the standard debugfs_create_regset32()
328 * function, with the main difference being that a list of register
329 * names/offsets do not need to be provided. The 'read' function simply outputs
330 * sequential register values over a specified range.
331 *
332 * Similar to the related debugfs_create_regset32 API, the structure pointed to
333 * by regset needs to persist for the lifetime of the created file. The calling
334 * code is responsible for initialization/management of this structure.
335 *
336 * The structure pointed to by regset is meant to be opaque. Please use
337 * sde_debugfs_setup_regset32 to initialize it.
338 *
339 * @name: File name within debugfs
340 * @mode: File mode within debugfs
341 * @parent: Parent directory entry within debugfs, can be NULL
342 * @regset: Pointer to persistent register block definition
343 *
344 * Return: dentry pointer for newly created file, use either debugfs_remove()
345 * or debugfs_remove_recursive() (on a parent directory) to remove the
346 * file
347 */
348void *sde_debugfs_create_regset32(const char *name, umode_t mode,
349 void *parent, struct sde_debugfs_regset32 *regset);
350
351/**
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700352 * sde_debugfs_get_root - Return root directory entry for KMS's debugfs
Clarence Ip4ce59322016-06-26 22:27:51 -0400353 *
354 * The return value should be passed as the 'parent' argument to subsequent
355 * debugfs create calls.
356 *
357 * @sde_kms: Pointer to SDE's KMS structure
358 *
359 * Return: dentry pointer for SDE's debugfs location
360 */
361void *sde_debugfs_get_root(struct sde_kms *sde_kms);
362
363/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400364 * SDE info management functions
365 * These functions/definitions allow for building up a 'sde_info' structure
366 * containing one or more "key=value\n" entries.
367 */
368#define SDE_KMS_INFO_MAX_SIZE 4096
369
370/**
371 * struct sde_kms_info - connector information structure container
372 * @data: Array of information character data
373 * @len: Current length of information data
374 * @staged_len: Temporary data buffer length, commit to
375 * len using sde_kms_info_stop
376 * @start: Whether or not a partial data entry was just started
377 */
378struct sde_kms_info {
379 char data[SDE_KMS_INFO_MAX_SIZE];
380 uint32_t len;
381 uint32_t staged_len;
382 bool start;
383};
384
385/**
386 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
387 * @S: Pointer to sde_kms_info structure
388 * Returns: Pointer to byte data
389 */
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -0700390#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data \
391 : NULL)
Clarence Ipb218a3c2016-07-15 14:17:42 -0400392
393/**
394 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
Narendra Muppalla22d17252017-05-31 15:13:39 -0700395 * it adds an extra character length to count null.
Clarence Ipb218a3c2016-07-15 14:17:42 -0400396 * @S: Pointer to sde_kms_info structure
397 * Returns: Size of available byte data
398 */
Narendra Muppalla22d17252017-05-31 15:13:39 -0700399#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len + 1 \
400 : 0)
Clarence Ipb218a3c2016-07-15 14:17:42 -0400401
402/**
403 * sde_kms_info_reset - reset sde_kms_info structure
404 * @info: Pointer to sde_kms_info structure
405 */
406void sde_kms_info_reset(struct sde_kms_info *info);
407
408/**
409 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
410 * @info: Pointer to sde_kms_info structure
411 * @key: Pointer to key string
Alan Kwong6259a382017-04-04 06:18:02 -0700412 * @value: Signed 64-bit integer value
Clarence Ipb218a3c2016-07-15 14:17:42 -0400413 */
414void sde_kms_info_add_keyint(struct sde_kms_info *info,
415 const char *key,
Alan Kwong6259a382017-04-04 06:18:02 -0700416 int64_t value);
Clarence Ipb218a3c2016-07-15 14:17:42 -0400417
418/**
419 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
420 * @info: Pointer to sde_kms_info structure
421 * @key: Pointer to key string
422 * @value: Pointer to string value
423 */
424void sde_kms_info_add_keystr(struct sde_kms_info *info,
425 const char *key,
426 const char *value);
427
428/**
429 * sde_kms_info_start - begin adding key to 'sde_kms_info'
430 * Usage:
431 * sde_kms_info_start(key)
432 * sde_kms_info_append(val_1)
433 * ...
434 * sde_kms_info_append(val_n)
435 * sde_kms_info_stop
436 * @info: Pointer to sde_kms_info structure
437 * @key: Pointer to key string
438 */
439void sde_kms_info_start(struct sde_kms_info *info,
440 const char *key);
441
442/**
443 * sde_kms_info_append - append value string to 'sde_kms_info'
444 * Usage:
445 * sde_kms_info_start(key)
446 * sde_kms_info_append(val_1)
447 * ...
448 * sde_kms_info_append(val_n)
449 * sde_kms_info_stop
450 * @info: Pointer to sde_kms_info structure
451 * @str: Pointer to partial value string
452 */
453void sde_kms_info_append(struct sde_kms_info *info,
454 const char *str);
455
456/**
457 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
458 * Usage:
459 * sde_kms_info_start(key)
460 * sde_kms_info_append_format(fourcc, modifier)
461 * ...
462 * sde_kms_info_stop
463 * @info: Pointer to sde_kms_info structure
464 * @pixel_format: FOURCC format code
465 * @modifier: 64-bit drm format modifier
466 */
467void sde_kms_info_append_format(struct sde_kms_info *info,
468 uint32_t pixel_format,
469 uint64_t modifier);
470
471/**
472 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
473 * Usage:
474 * sde_kms_info_start(key)
475 * sde_kms_info_append(val_1)
476 * ...
477 * sde_kms_info_append(val_n)
478 * sde_kms_info_stop
479 * @info: Pointer to sde_kms_info structure
480 */
481void sde_kms_info_stop(struct sde_kms_info *info);
482
483/**
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500484 * sde_kms_rect_intersect - intersect two rectangles
485 * @r1: first rectangle
486 * @r2: scissor rectangle
487 * @result: result rectangle, all 0's on no intersection found
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800488 */
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500489void sde_kms_rect_intersect(const struct sde_rect *r1,
490 const struct sde_rect *r2,
491 struct sde_rect *result);
492
493/**
Lloyd Atkinsonc2baf412017-04-19 17:53:09 -0400494 * sde_kms_rect_merge_rectangles - merge a rectangle list into one rect
495 * @rois: pointer to the list of rois
496 * @result: output rectangle, all 0 on error
497 */
498void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
499 struct sde_rect *result);
500
501/**
Lloyd Atkinsone0e11e22017-01-17 12:08:48 -0500502 * sde_kms_rect_is_equal - compares two rects
503 * @r1: rect value to compare
504 * @r2: rect value to compare
505 *
506 * Returns 1 if the rects are same, 0 otherwise.
507 */
508static inline bool sde_kms_rect_is_equal(struct sde_rect *r1,
509 struct sde_rect *r2)
510{
511 if ((!r1 && r2) || (r1 && !r2))
512 return false;
513
514 if (!r1 && !r2)
515 return true;
516
517 return r1->x == r2->x && r1->y == r2->y && r1->w == r2->w &&
518 r1->h == r2->h;
519}
520
521/**
522 * sde_kms_rect_is_null - returns true if the width or height of a rect is 0
523 * @rect: rectangle to check for zero size
524 * @Return: True if width or height of rectangle is 0
525 */
526static inline bool sde_kms_rect_is_null(const struct sde_rect *r)
527{
528 if (!r)
529 return true;
530
531 return (!r->w || !r->h);
532}
Veera Sundaram Sankaran02dd6ac2016-12-22 15:08:29 -0800533
534/**
Ben Chan78647cd2016-06-26 22:02:47 -0400535 * Vblank enable/disable functions
536 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700537int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
538void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
539
Alan Kwong4dd64c82017-02-04 18:41:51 -0800540/**
541 * sde_kms_fbo_create_fb - create framebuffer from given framebuffer object
542 * @dev: Pointer to drm device
543 * @fbo: Pointer to framebuffer object
544 * return: Pointer to drm framebuffer on success; NULL on error
545 */
546struct drm_framebuffer *sde_kms_fbo_create_fb(struct drm_device *dev,
547 struct sde_kms_fbo *fbo);
548
549/**
550 * sde_kms_fbo_alloc - create framebuffer object with given format parameters
551 * @dev: pointer to drm device
552 * @width: width of framebuffer
553 * @height: height of framebuffer
554 * @pixel_format: pixel format of framebuffer
555 * @modifier: pixel format modifier
556 * @flags: DRM_MODE_FB flags
557 * return: Pointer to framebuffer memory object on success; NULL on error
558 */
559struct sde_kms_fbo *sde_kms_fbo_alloc(struct drm_device *dev,
560 u32 width, u32 height, u32 pixel_format,
561 u64 modifiers[4], u32 flags);
562
563/**
564 * sde_kms_fbo_reference - increment reference count of given framebuffer object
565 * @fbo: Pointer to framebuffer memory object
566 * return: 0 on success; error code otherwise
567 */
568int sde_kms_fbo_reference(struct sde_kms_fbo *fbo);
569
570/**
571 * sde_kms_fbo_unreference - decrement reference count of given framebuffer
572 * object
573 * @fbo: Pointer to framebuffer memory object
574 * return: 0 on success; error code otherwise
575 */
576void sde_kms_fbo_unreference(struct sde_kms_fbo *fbo);
577
Abhijit Kulkarni329a94d2017-06-20 17:07:08 -0700578/**
579 * smmu attach/detach functions
580 * @sde_kms: poiner to sde_kms structure
581 * @secure_only: if true only secure contexts are attached/detached, else
582 * all contexts are attached/detached/
583 */
584int sde_kms_mmu_attach(struct sde_kms *sde_kms, bool secure_only);
585int sde_kms_mmu_detach(struct sde_kms *sde_kms, bool secure_only);
586
Dhaval Patel2a3c37a2017-10-25 12:30:36 -0700587/**
588 * sde_kms_timeline_status - provides current timeline status
589 * @dev: Pointer to drm device
590 */
591void sde_kms_timeline_status(struct drm_device *dev);
592
Sandeep Panda11b20d82017-06-19 12:57:27 +0530593/**
594 * sde_kms_handle_recovery - handler function for FIFO overflow issue
595 * @encoder: pointer to drm encoder structure
596 * return: 0 on success; error code otherwise
597 */
598int sde_kms_handle_recovery(struct drm_encoder *encoder);
599
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700600#endif /* __sde_kms_H__ */