blob: 13a8620954b50287248c5d3eeeb440e4806e1f75 [file] [log] [blame]
Saurabh Shah66c941b2016-07-06 17:34:05 -07001/*
2* Copyright (c) 2017, The Linux Foundation. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
13* * Neither the name of The Linux Foundation nor the names of its
14* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef __DRM_INTERFACE_H__
31#define __DRM_INTERFACE_H__
32
33#include <map>
34#include <string>
35#include <utility>
36#include <vector>
37
38#include "xf86drm.h"
39#include "xf86drmMode.h"
40
41namespace sde_drm {
42/*
43 * Drm Atomic Operation Codes
44 */
45enum struct DRMOps {
46 /*
47 * Op: Sets plane source crop
48 * Arg: uint32_t - Plane ID
49 * DRMRect - Source Rectangle
50 */
51 PLANE_SET_SRC_RECT,
52 /*
53 * Op: Sets plane destination rect
54 * Arg: uint32_t - Plane ID
55 * DRMRect - Dst Rectangle
56 */
57 PLANE_SET_DST_RECT,
58 /*
59 * Op: Sets plane zorder
60 * Arg: uint32_t - Plane ID
61 * uint32_t - zorder
62 */
63 PLANE_SET_ZORDER,
64 /*
65 * Op: Sets plane rotation flags
66 * Arg: uint32_t - Plane ID
67 * uint32_t - bit mask of rotation flags (See drm_mode.h for enums)
68 */
69 PLANE_SET_ROTATION,
70 /*
71 * Op: Sets plane alpha
72 * Arg: uint32_t - Plane ID
73 * uint32_t - alpha value
74 */
75 PLANE_SET_ALPHA,
76 /*
77 * Op: Sets the blend type
78 * Arg: uint32_t - Plane ID
79 * uint32_t - blend type (see DRMBlendType)
80 */
81 PLANE_SET_BLEND_TYPE,
82 /*
83 * Op: Sets horizontal decimation
84 * Arg: uint32_t - Plane ID
85 * uint32_t - decimation factor
86 */
87 PLANE_SET_H_DECIMATION,
88 /*
89 * Op: Sets vertical decimation
90 * Arg: uint32_t - Plane ID
91 * uint32_t - decimation factor
92 */
93 PLANE_SET_V_DECIMATION,
94 /*
Prabhanjan Kandula585aa652017-01-26 18:39:11 -080095 * Op: Sets source config flags
96 * Arg: uint32_t - Plane ID
97 * uint32_t - flags to enable or disable a specific op. E.g. deinterlacing
98 */
99 PLANE_SET_SRC_CONFIG,
100 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700101 * Op: Sets frame buffer ID for plane. Set together with CRTC.
102 * Arg: uint32_t - Plane ID
103 * uint32_t - Framebuffer ID
104 */
105 PLANE_SET_FB_ID,
106 /*
107 * Op: Sets the crtc for this plane. Set together with FB_ID.
108 * Arg: uint32_t - Plane ID
109 * uint32_t - CRTC ID
110 */
111 PLANE_SET_CRTC,
112 /*
113 * Op: Sets acquire fence for this plane's buffer. Set together with FB_ID, CRTC.
114 * Arg: uint32_t - Plane ID
115 * uint32_t - Input fence
116 */
117 PLANE_SET_INPUT_FENCE,
118 /*
Saurabh Shah0ffee302016-11-22 10:42:11 -0800119 * Op: Sets scaler config on this plane.
120 * Arg: uint32_t - Plane ID
121 * uint64_t - Address of the scaler config object (version based)
122 */
123 PLANE_SET_SCALER_CONFIG,
124 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700125 * Op: Activate or deactivate a CRTC
126 * Arg: uint32_t - CRTC ID
127 * uint32_t - 1 to enable, 0 to disable
128 */
129 CRTC_SET_ACTIVE,
130 /*
131 * Op: Sets display mode
132 * Arg: uint32_t - CRTC ID
133 * drmModeModeInfo* - Pointer to display mode
134 */
135 CRTC_SET_MODE,
136 /*
137 * Op: Sets an offset indicating when a release fence should be signalled.
138 * Arg: uint32_t - offset
139 * 0: non-speculative, default
140 * 1: speculative
141 */
142 CRTC_SET_OUTPUT_FENCE_OFFSET,
143 /*
144 * Op: Returns release fence for this frame. Should be called after Commit() on
145 * DRMAtomicReqInterface.
146 * Arg: uint32_t - CRTC ID
147 * int * - Pointer to an integer that will hold the returned fence
148 */
149 CRTC_GET_RELEASE_FENCE,
150 /*
Ping Li281f48d2017-01-16 12:45:40 -0800151 * Op: Sets PP feature
152 * Arg: uint32_t - CRTC ID
153 * DRMPPFeatureInfo * - PP feature data pointer
154 */
155 CRTC_SET_POST_PROC,
156 /*
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800157 * Op: Sets CRTC ROIs.
158 * Arg: uint32_t - CRTC ID
159 * uint32_t - number of ROIs
160 * DRMRect * - Array of CRTC ROIs
161 */
162 CRTC_SET_ROI,
163 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700164 * Op: Returns retire fence for this commit. Should be called after Commit() on
165 * DRMAtomicReqInterface.
166 * Arg: uint32_t - Connector ID
167 * int * - Pointer to an integer that will hold the returned fence
168 */
169 CONNECTOR_GET_RETIRE_FENCE,
170 /*
171 * Op: Sets writeback connector destination rect
172 * Arg: uint32_t - Connector ID
173 * DRMRect - Dst Rectangle
174 */
175 CONNECTOR_SET_OUTPUT_RECT,
176 /*
177 * Op: Sets frame buffer ID for writeback connector.
178 * Arg: uint32_t - Connector ID
179 * uint32_t - Framebuffer ID
180 */
181 CONNECTOR_SET_OUTPUT_FB_ID,
Sushil Chauhan3396e202017-04-14 18:34:22 -0700182 /*
183 * Op: Sets power mode for connector.
184 * Arg: uint32_t - Connector ID
185 * uint32_t - Power Mode
186 */
187 CONNECTOR_SET_POWER_MODE,
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800188 /*
189 * Op: Sets panel ROIs.
190 * Arg: uint32_t - Connector ID
191 * uint32_t - number of ROIs
192 * DRMRect * - Array of Connector ROIs
193 */
194 CONNECTOR_SET_ROI,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700195};
196
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700197enum struct DRMRotation {
198 FLIP_H = 0x1,
199 FLIP_V = 0x2,
200 ROT_90 = 0x4,
201};
202
Sushil Chauhan3396e202017-04-14 18:34:22 -0700203enum struct DRMPowerMode {
204 ON,
205 DOZE,
206 DOZE_SUSPEND,
207 OFF,
208};
209
Saurabh Shah66c941b2016-07-06 17:34:05 -0700210enum struct DRMBlendType {
211 UNDEFINED = 0,
212 OPAQUE = 1,
213 PREMULTIPLIED = 2,
214 COVERAGE = 3,
215};
216
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800217enum struct DRMSrcConfig {
218 DEINTERLACE = 0,
219};
220
Saurabh Shah66c941b2016-07-06 17:34:05 -0700221/* Display type to identify a suitable connector */
222enum struct DRMDisplayType {
223 PERIPHERAL,
224 TV,
225 VIRTUAL,
226};
227
228struct DRMRect {
229 uint32_t left; // Left-most pixel coordinate.
230 uint32_t top; // Top-most pixel coordinate.
231 uint32_t right; // Right-most pixel coordinate.
232 uint32_t bottom; // Bottom-most pixel coordinate.
233};
234
235//------------------------------------------------------------------------
236// DRM Info Query Types
237//------------------------------------------------------------------------
238
239enum struct QSEEDVersion {
240 V1,
241 V2,
242 V3,
243};
244
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700245enum struct SmartDMARevision {
246 V1,
247 V2,
248};
249
Saurabh Shah66c941b2016-07-06 17:34:05 -0700250/* Per CRTC Resource Info*/
251struct DRMCrtcInfo {
252 bool has_src_split;
253 uint32_t max_blend_stages;
254 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700255 SmartDMARevision smart_dma_rev;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700256};
257
258enum struct DRMPlaneType {
259 // Has CSC and scaling capability
260 VIG = 0,
261 // Has scaling capability but no CSC
262 RGB,
263 // No scaling support
264 DMA,
265 // Supports a small dimension and doesn't use a CRTC stage
266 CURSOR,
267 MAX,
268};
269
270struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700271 DRMPlaneType type;
272 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700273 // FourCC format enum and modifier
274 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
275 uint32_t max_linewidth;
276 uint32_t max_upscale;
277 uint32_t max_downscale;
278 uint32_t max_horizontal_deci;
279 uint32_t max_vertical_deci;
280};
281
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700282// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
283typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700284
285enum struct DRMTopology {
286 UNKNOWN, // To be compat with driver defs in sde_kms.h
287 SINGLE_LM,
288 DUAL_LM,
289 PPSPLIT,
290 DUAL_LM_MERGE,
291};
292
293enum struct DRMPanelMode {
294 VIDEO,
295 COMMAND,
296};
297
298/* Per Connector Info*/
299struct DRMConnectorInfo {
300 uint32_t mmWidth;
301 uint32_t mmHeight;
302 uint32_t type;
303 uint32_t num_modes;
304 drmModeModeInfo *modes;
305 DRMTopology topology;
306 std::string panel_name;
307 DRMPanelMode panel_mode;
308 bool is_primary;
309 // Valid only if DRMPanelMode is VIDEO
310 bool dynamic_fps;
311 // FourCC format enum and modifier
312 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
313 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
314 uint32_t max_linewidth;
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800315 // Valid only if mode is command
316 int num_roi;
317 int xstart;
318 int ystart;
319 int walign;
320 int halign;
321 int wmin;
322 int hmin;
323 bool roi_merge;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700324};
325
326/* Identifier token for a display */
327struct DRMDisplayToken {
328 uint32_t conn_id;
329 uint32_t crtc_id;
330};
331
Ping Li281f48d2017-01-16 12:45:40 -0800332enum DRMPPFeatureID {
333 kFeaturePcc,
334 kFeatureIgc,
335 kFeaturePgc,
336 kFeatureMixerGc,
337 kFeaturePaV2,
338 kFeatureDither,
339 kFeatureGamut,
340 kFeaturePADither,
341 kPPFeaturesMax,
342};
343
344enum DRMPPPropType {
345 kPropEnum,
346 kPropRange,
347 kPropBlob,
348 kPropTypeMax,
349};
350
351struct DRMPPFeatureInfo {
352 DRMPPFeatureID id;
353 DRMPPPropType type;
354 uint32_t version;
355 uint32_t payload_size;
356 void *payload;
357};
358
Saurabh Shah0ffee302016-11-22 10:42:11 -0800359struct DRMScalerLUTInfo {
360 uint32_t dir_lut_size = 0;
361 uint32_t cir_lut_size = 0;
362 uint32_t sep_lut_size = 0;
363 uint64_t dir_lut = 0;
364 uint64_t cir_lut = 0;
365 uint64_t sep_lut = 0;
366};
367
Saurabh Shah66c941b2016-07-06 17:34:05 -0700368/* DRM Atomic Request Property Set.
369 *
370 * Helper class to create and populate atomic properties of DRM components
371 * when rendered in DRM atomic mode */
372class DRMAtomicReqInterface {
373 public:
374 virtual ~DRMAtomicReqInterface() {}
375 /* Perform request operation.
376 *
377 * [input]: opcode: operation code from DRMOps list.
378 * var_arg: arguments for DRMOps's can differ in number and
379 * data type. Refer above DRMOps to details.
380 * [return]: Error code if the API fails, 0 on success.
381 */
382 virtual int Perform(DRMOps opcode, ...) = 0;
383
384 /*
385 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
386 * called every frame.
387 * [input]: synchronous: Determines if the call should block until a h/w flip
388 * [return]: Error code if the API fails, 0 on success.
389 */
390 virtual int Commit(bool synchronous) = 0;
391 /*
392 * Validate the params set via Perform().
393 * [return]: Error code if the API fails, 0 on success.
394 */
395 virtual int Validate() = 0;
396};
397
398class DRMManagerInterface;
399
400/* Populates a singleton instance of DRMManager */
401typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
402
403/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800404typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700405
406/*
407 * DRM Manager Interface - Any class which plans to implement helper function for vendor
408 * specific DRM driver implementation must implement the below interface routines to work
409 * with SDM.
410 */
411
412class DRMManagerInterface {
413 public:
414 virtual ~DRMManagerInterface() {}
415
416 /*
417 * Since SDM completely manages the planes. GetPlanesInfo will provide all
418 * the plane information.
419 * [output]: DRMPlanesInfo: Resource Info for planes.
420 */
421 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
422
423 /*
424 * Will provide all the information of a selected crtc.
425 * [input]: Use crtc id 0 to obtain system wide info
426 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
427 */
428 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
429
430 /*
431 * Will provide all the information of a selected connector.
432 * [output]: DRMConnectorInfo: Resource Info for the given connector id
433 */
434 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
435
436 /*
Ping Li281f48d2017-01-16 12:45:40 -0800437 * Will query post propcessing feature info of a CRTC.
438 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
439 */
440 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
441 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700442 * Register a logical display to receive a token.
443 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
444 * On display connect(bootup or hotplug), clients should invoke this interface to
445 * establish the pipeline for the display and should get a DisplayToken
446 * populated with crtc and connnector(s) id's. Here onwards, Client should
447 * use this token to represent the display for any Perform operations if
448 * needed.
449 *
450 * [input]: disp_type - Peripheral / TV / Virtual
451 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
452 * [return]: 0 on success, a negative error value otherwise
453 */
454 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
455
456 /* Client should invoke this interface on display disconnect.
457 * [input]: DRMDisplayToken - identifier for the display.
458 */
459 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
460
461 /*
462 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
463 * returned as part of RegisterDisplay API. Needs to be called per display.
464 * [input]: DRMDisplayToken that identifies a display pipeline
465 * [output]: Pointer to an instance of DRMAtomicReqInterface.
466 * [return]: Error code if the API fails, 0 on success.
467 */
468 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
469
470 /*
471 * Destroys the instance of DRMAtomicReqInterface
472 * [input]: Pointer to a DRMAtomicReqInterface
473 * [return]: Error code if the API fails, 0 on success.
474 */
475 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
Saurabh Shah0ffee302016-11-22 10:42:11 -0800476 /*
477 * Sets the global scaler LUT
478 * [input]: LUT Info
479 * [return]: Error code if the API fails, 0 on success.
480 */
481 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700482};
Saurabh Shah0ffee302016-11-22 10:42:11 -0800483
Saurabh Shah66c941b2016-07-06 17:34:05 -0700484} // namespace sde_drm
485#endif // __DRM_INTERFACE_H__