blob: d1ec5c02b20f4ae8bf19506729d7d486144d2b25 [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"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070019#include "sde_hw_catalog.h"
Clarence Ipc475b082016-06-26 09:27:23 -040020#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040021#include "sde_hw_lm.h"
Ben Chan78647cd2016-06-26 22:02:47 -040022#include "sde_hw_interrupts.h"
Alan Kwongd21960f2016-07-29 03:33:17 -040023#include "sde_hw_wb.h"
24#include "sde_hw_top.h"
Clarence Ipe59fb3f2016-07-26 13:39:59 -040025#include "sde_connector.h"
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -040026#include "sde_crtc.h"
Lloyd Atkinson11f34442016-08-11 11:19:52 -040027#include "sde_rm.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070028#include "sde_power_handle.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040029#include "sde_irq.h"
Ben Chan78647cd2016-06-26 22:02:47 -040030
Clarence Ip31c19b52016-06-10 15:42:08 -040031/**
32 * SDE_DEBUG - macro for kms/plane/crtc/encoder/connector logs
33 * @fmt: Pointer to format string
34 */
35#define SDE_DEBUG(fmt, ...) \
36 do { \
37 if (unlikely(drm_debug & DRM_UT_KMS)) \
38 drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
39 else \
40 pr_debug(fmt, ##__VA_ARGS__); \
41 } while (0)
42
43/**
44 * SDE_DEBUG_DRIVER - macro for hardware driver logging
45 * @fmt: Pointer to format string
46 */
47#define SDE_DEBUG_DRIVER(fmt, ...) \
48 do { \
49 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
50 drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
51 else \
52 pr_debug(fmt, ##__VA_ARGS__); \
53 } while (0)
54
Dhaval Patelb271b842016-10-19 21:41:22 -070055#define SDE_ERROR(fmt, ...) pr_err("[sde error]" fmt, ##__VA_ARGS__)
Clarence Ip31c19b52016-06-10 15:42:08 -040056
Dhaval Patelec10fad2016-08-22 14:40:48 -070057#define POPULATE_RECT(rect, a, b, c, d, Q16_flag) \
58 do { \
59 (rect)->x = (Q16_flag) ? (a) >> 16 : (a); \
60 (rect)->y = (Q16_flag) ? (b) >> 16 : (b); \
61 (rect)->w = (Q16_flag) ? (c) >> 16 : (c); \
62 (rect)->h = (Q16_flag) ? (d) >> 16 : (d); \
63 } while (0)
64
65#define CHECK_LAYER_BOUNDS(offset, size, max_size) \
66 (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
67
Clarence Ipfd96ba22016-09-09 16:45:44 -040068/**
69 * ktime_compare_safe - compare two ktime structures
70 * This macro is similar to the standard ktime_compare() function, but
71 * attempts to also handle ktime overflows.
72 * @A: First ktime value
73 * @B: Second ktime value
74 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
75 */
76#define ktime_compare_safe(A, B) \
77 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
78
Dhaval Patel22ef6df2016-10-20 14:42:52 -070079#define SDE_NAME_SIZE 12
80
Ben Chan78647cd2016-06-26 22:02:47 -040081/*
82 * struct sde_irq_callback - IRQ callback handlers
83 * @func: intr handler
84 * @arg: argument for the handler
85 */
86struct sde_irq_callback {
87 void (*func)(void *arg, int irq_idx);
88 void *arg;
89};
90
91/**
92 * struct sde_irq: IRQ structure contains callback registration info
93 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
94 * @irq_cb_tbl: array of IRQ callbacks setting
95 * @cb_lock: callback lock
96 */
97struct sde_irq {
98 u32 total_irqs;
99 struct sde_irq_callback *irq_cb_tbl;
100 spinlock_t cb_lock;
101};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700102
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400103/**
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400104 * Encoder functions and data types
105 * @intfs: Interfaces this encoder is using, INTF_MODE_NONE if unused
106 * @wbs: Writebacks this encoder is using, INTF_MODE_NONE if unused
107 * @needs_cdm: Encoder requests a CDM based on pixel format conversion needs
108 * @display_num_of_h_tiles:
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400109 */
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400110struct sde_encoder_hw_resources {
111 enum sde_intf_mode intfs[INTF_MAX];
112 enum sde_intf_mode wbs[WB_MAX];
113 bool needs_cdm;
114 u32 display_num_of_h_tiles;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400115};
116
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700117struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -0400118 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700119 struct drm_device *dev;
Dhaval Patel3949f032016-06-20 16:24:33 -0700120 int core_rev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700121 struct sde_mdss_cfg *catalog;
122
Alan Kwong112a84f2016-05-24 20:49:21 -0400123 struct msm_mmu *mmu[MSM_SMMU_DOMAIN_MAX];
124 int mmu_id[MSM_SMMU_DOMAIN_MAX];
Dhaval Patel3949f032016-06-20 16:24:33 -0700125 struct sde_power_client *core_client;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700126
Clarence Ip4ce59322016-06-26 22:27:51 -0400127 /* directory entry for debugfs */
128 void *debugfs_root;
129
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700130 /* io/register spaces: */
Alan Kwongdfa8c082016-07-29 04:10:00 -0400131 void __iomem *mmio, *vbif[VBIF_MAX];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700132
133 struct regulator *vdd;
134 struct regulator *mmagic;
135 struct regulator *venus;
136
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400137 struct sde_irq_controller irq_controller;
Ben Chan78647cd2016-06-26 22:02:47 -0400138
139 struct sde_hw_intr *hw_intr;
140 struct sde_irq irq_obj;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400141
142 struct sde_rm rm;
Alan Kwong5d324e42016-07-28 22:56:18 -0400143
144 struct sde_hw_vbif *hw_vbif[VBIF_MAX];
145 struct sde_hw_mdp *hw_mdp;
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
155struct sde_plane_state {
156 struct drm_plane_state base;
157
158 /* aligned with property */
Clarence Ipe78efb72016-06-24 18:35:21 -0400159 uint64_t property_values[PLANE_PROP_COUNT];
160
161 /* blob properties */
162 struct drm_property_blob *property_blobs[PLANE_PROP_BLOBCOUNT];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700163
Clarence Ipcae1bb62016-07-07 12:07:13 -0400164 /* dereferenced input fence pointer */
165 void *input_fence;
Clarence Ipae4e60c2016-06-26 22:44:04 -0400166
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700167 /* assigned by crtc blender */
168 enum sde_stage stage;
169
Clarence Ip282dad62016-09-27 17:07:35 -0400170 /* bitmask for which pipe h/w config functions need to be updated */
171 uint32_t dirty;
172
173 /* whether the current update is still pending */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700174 bool pending : 1;
175};
176
177#define to_sde_plane_state(x) \
Clarence Ip4c1d9772016-06-26 09:35:38 -0400178 container_of(x, struct sde_plane_state, base)
179
180/**
181 * sde_plane_get_property - Query integer value of plane property
182 *
183 * @S: Pointer to plane state
184 * @X: Property index, from enum msm_mdp_plane_property
185 *
186 * Return: Integer value of requested property
187 */
188#define sde_plane_get_property(S, X) \
189 ((S) && ((X) < PLANE_PROP_COUNT) ? ((S)->property_values[(X)]) : 0)
190
191/**
Clarence Ipdd395242016-09-09 10:47:17 -0400192 * sde_is_custom_client - whether or not to enable non-standard customizations
193 *
194 * Return: Whether or not the 'sdeclient' module parameter was set on boot up
195 */
196bool sde_is_custom_client(void);
197
198/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400199 * Debugfs functions - extra helper functions for debugfs support
200 *
201 * Main debugfs documentation is located at,
202 *
203 * Documentation/filesystems/debugfs.txt
204 *
205 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
206 * @sde_debugfs_create_regset32: Create 32-bit register dump file
207 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
208 */
209
210/**
211 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
212 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
213 */
214struct sde_debugfs_regset32 {
215 uint32_t offset;
216 uint32_t blk_len;
Clarence Ipaac9f332016-08-31 15:46:35 -0400217 struct sde_kms *sde_kms;
Clarence Ip4ce59322016-06-26 22:27:51 -0400218};
219
220/**
221 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
222 * This function is meant to initialize sde_debugfs_regset32 structures for use
223 * with sde_debugfs_create_regset32.
224 * @regset: opaque register definition structure
225 * @offset: sub-block offset
226 * @length: sub-block length, in bytes
Clarence Ipaac9f332016-08-31 15:46:35 -0400227 * @sde_kms: pointer to sde kms structure
Clarence Ip4ce59322016-06-26 22:27:51 -0400228 */
229void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
Clarence Ipaac9f332016-08-31 15:46:35 -0400230 uint32_t offset, uint32_t length, struct sde_kms *sde_kms);
Clarence Ip4ce59322016-06-26 22:27:51 -0400231
232/**
233 * sde_debugfs_create_regset32 - Create register read back file for debugfs
234 *
235 * This function is almost identical to the standard debugfs_create_regset32()
236 * function, with the main difference being that a list of register
237 * names/offsets do not need to be provided. The 'read' function simply outputs
238 * sequential register values over a specified range.
239 *
240 * Similar to the related debugfs_create_regset32 API, the structure pointed to
241 * by regset needs to persist for the lifetime of the created file. The calling
242 * code is responsible for initialization/management of this structure.
243 *
244 * The structure pointed to by regset is meant to be opaque. Please use
245 * sde_debugfs_setup_regset32 to initialize it.
246 *
247 * @name: File name within debugfs
248 * @mode: File mode within debugfs
249 * @parent: Parent directory entry within debugfs, can be NULL
250 * @regset: Pointer to persistent register block definition
251 *
252 * Return: dentry pointer for newly created file, use either debugfs_remove()
253 * or debugfs_remove_recursive() (on a parent directory) to remove the
254 * file
255 */
256void *sde_debugfs_create_regset32(const char *name, umode_t mode,
257 void *parent, struct sde_debugfs_regset32 *regset);
258
259/**
260 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
261 *
262 * The return value should be passed as the 'parent' argument to subsequent
263 * debugfs create calls.
264 *
265 * @sde_kms: Pointer to SDE's KMS structure
266 *
267 * Return: dentry pointer for SDE's debugfs location
268 */
269void *sde_debugfs_get_root(struct sde_kms *sde_kms);
270
271/**
Clarence Ipb218a3c2016-07-15 14:17:42 -0400272 * SDE info management functions
273 * These functions/definitions allow for building up a 'sde_info' structure
274 * containing one or more "key=value\n" entries.
275 */
276#define SDE_KMS_INFO_MAX_SIZE 4096
277
278/**
279 * struct sde_kms_info - connector information structure container
280 * @data: Array of information character data
281 * @len: Current length of information data
282 * @staged_len: Temporary data buffer length, commit to
283 * len using sde_kms_info_stop
284 * @start: Whether or not a partial data entry was just started
285 */
286struct sde_kms_info {
287 char data[SDE_KMS_INFO_MAX_SIZE];
288 uint32_t len;
289 uint32_t staged_len;
290 bool start;
291};
292
293/**
294 * SDE_KMS_INFO_DATA - Macro for accessing sde_kms_info data bytes
295 * @S: Pointer to sde_kms_info structure
296 * Returns: Pointer to byte data
297 */
298#define SDE_KMS_INFO_DATA(S) ((S) ? ((struct sde_kms_info *)(S))->data : 0)
299
300/**
301 * SDE_KMS_INFO_DATALEN - Macro for accessing sde_kms_info data length
302 * @S: Pointer to sde_kms_info structure
303 * Returns: Size of available byte data
304 */
305#define SDE_KMS_INFO_DATALEN(S) ((S) ? ((struct sde_kms_info *)(S))->len : 0)
306
307/**
308 * sde_kms_info_reset - reset sde_kms_info structure
309 * @info: Pointer to sde_kms_info structure
310 */
311void sde_kms_info_reset(struct sde_kms_info *info);
312
313/**
314 * sde_kms_info_add_keyint - add integer value to 'sde_kms_info'
315 * @info: Pointer to sde_kms_info structure
316 * @key: Pointer to key string
317 * @value: Signed 32-bit integer value
318 */
319void sde_kms_info_add_keyint(struct sde_kms_info *info,
320 const char *key,
321 int32_t value);
322
323/**
324 * sde_kms_info_add_keystr - add string value to 'sde_kms_info'
325 * @info: Pointer to sde_kms_info structure
326 * @key: Pointer to key string
327 * @value: Pointer to string value
328 */
329void sde_kms_info_add_keystr(struct sde_kms_info *info,
330 const char *key,
331 const char *value);
332
333/**
334 * sde_kms_info_start - begin adding key to 'sde_kms_info'
335 * Usage:
336 * sde_kms_info_start(key)
337 * sde_kms_info_append(val_1)
338 * ...
339 * sde_kms_info_append(val_n)
340 * sde_kms_info_stop
341 * @info: Pointer to sde_kms_info structure
342 * @key: Pointer to key string
343 */
344void sde_kms_info_start(struct sde_kms_info *info,
345 const char *key);
346
347/**
348 * sde_kms_info_append - append value string to 'sde_kms_info'
349 * Usage:
350 * sde_kms_info_start(key)
351 * sde_kms_info_append(val_1)
352 * ...
353 * sde_kms_info_append(val_n)
354 * sde_kms_info_stop
355 * @info: Pointer to sde_kms_info structure
356 * @str: Pointer to partial value string
357 */
358void sde_kms_info_append(struct sde_kms_info *info,
359 const char *str);
360
361/**
362 * sde_kms_info_append_format - append format code string to 'sde_kms_info'
363 * Usage:
364 * sde_kms_info_start(key)
365 * sde_kms_info_append_format(fourcc, modifier)
366 * ...
367 * sde_kms_info_stop
368 * @info: Pointer to sde_kms_info structure
369 * @pixel_format: FOURCC format code
370 * @modifier: 64-bit drm format modifier
371 */
372void sde_kms_info_append_format(struct sde_kms_info *info,
373 uint32_t pixel_format,
374 uint64_t modifier);
375
376/**
377 * sde_kms_info_stop - finish adding key to 'sde_kms_info'
378 * Usage:
379 * sde_kms_info_start(key)
380 * sde_kms_info_append(val_1)
381 * ...
382 * sde_kms_info_append(val_n)
383 * sde_kms_info_stop
384 * @info: Pointer to sde_kms_info structure
385 */
386void sde_kms_info_stop(struct sde_kms_info *info);
387
388/**
Ben Chan78647cd2016-06-26 22:02:47 -0400389 * Vblank enable/disable functions
390 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700391int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
392void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
393
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400394/**
395 * Plane functions
396 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700397enum sde_sspp sde_plane_pipe(struct drm_plane *plane);
Clarence Ipcae1bb62016-07-07 12:07:13 -0400398void sde_plane_flush(struct drm_plane *plane);
Clarence Ipdbde9832016-06-26 09:48:36 -0400399struct drm_plane *sde_plane_init(struct drm_device *dev,
Clarence Ip2bbf7b32016-09-23 15:07:16 -0400400 uint32_t pipe, bool primary_plane,
401 unsigned long possible_crtcs);
Clarence Ip7a753bb2016-07-07 11:47:44 -0400402
403/**
Clarence Ipcae1bb62016-07-07 12:07:13 -0400404 * sde_plane_wait_input_fence - wait for input fence object
Clarence Ip7a753bb2016-07-07 11:47:44 -0400405 * @plane: Pointer to DRM plane object
406 * @wait_ms: Wait timeout value
407 * Returns: Zero on success
408 */
Clarence Ipcae1bb62016-07-07 12:07:13 -0400409int sde_plane_wait_input_fence(struct drm_plane *plane, uint32_t wait_ms);
Clarence Ipcb410d42016-06-26 22:52:33 -0400410
411/**
Clarence Ipcae1bb62016-07-07 12:07:13 -0400412 * sde_plane_color_fill - Enables color fill on plane
Clarence Ipcb410d42016-06-26 22:52:33 -0400413 * @plane: Pointer to DRM plane object
414 * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
415 * @alpha: 8-bit fill alpha value, 255 selects 100% alpha
416 *
417 * Returns: 0 on success
418 */
419int sde_plane_color_fill(struct drm_plane *plane,
420 uint32_t color, uint32_t alpha);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700421
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400422/**
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400423 * sde_encoder_get_hw_resources - Populate table of required hardware resources
424 * @encoder: encoder pointer
425 * @hw_res: resource table to populate with encoder required resources
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400426 * @conn_state: report hw reqs based on this proposed connector state
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400427 */
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400428void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400429 struct sde_encoder_hw_resources *hw_res,
430 struct drm_connector_state *conn_state);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700431
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400432/**
433 * sde_encoder_register_vblank_callback - provide callback to encoder that
434 * will be called on the next vblank.
435 * @encoder: encoder pointer
436 * @cb: callback pointer, provide NULL to deregister and disable IRQs
437 * @data: user data provided to callback
438 */
439void sde_encoder_register_vblank_callback(struct drm_encoder *encoder,
440 void (*cb)(void *), void *data);
441
442/**
443 * sde_encoder_schedule_kickoff - Register a callback with the encoder to
444 * trigger a double buffer flip of the ctl path (i.e. ctl flush and start)
445 * at the appropriate time.
446 * Immediately: if no previous commit is outstanding.
447 * Delayed: Save the callback, and return. Does not block. Callback will
448 * be triggered later. E.g. cmd encoder will trigger at pp_done irq
449 * irq if it outstanding.
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400450 * @encoder: encoder pointer
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400451 */
Clarence Ip110d15c2016-08-16 14:44:41 -0400452void sde_encoder_schedule_kickoff(struct drm_encoder *encoder);
Lloyd Atkinson5d722782016-05-30 14:09:41 -0400453
454/**
455 * sde_encoder_wait_nxt_committed - Wait for hardware to have flushed the
456 * current pending frames to hardware at a vblank or ctl_start
457 * Encoders will map this differently depending on irqs
458 * vid mode -> vsync_irq
459 * @encoder: encoder pointer
460 *
461 * Return: 0 on success, -EWOULDBLOCK if already signaled, error otherwise
462 */
463int sde_encoder_wait_for_commit_done(struct drm_encoder *drm_encoder);
464
465/**
466 * sde_encoders_init - query platform, create all encoders and bridges,
467 * and register them with the drm_device
468 * @dev: drm device pointer
469 */
470void sde_encoders_init(struct drm_device *dev);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700471
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700472#endif /* __sde_kms_H__ */