blob: d41181f0601544117c1ee14208f2a3f7b3349007 [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 Shah66c941b2016-07-06 17:34:05 -0700157 * Op: Returns retire fence for this commit. Should be called after Commit() on
158 * DRMAtomicReqInterface.
159 * Arg: uint32_t - Connector ID
160 * int * - Pointer to an integer that will hold the returned fence
161 */
162 CONNECTOR_GET_RETIRE_FENCE,
163 /*
164 * Op: Sets writeback connector destination rect
165 * Arg: uint32_t - Connector ID
166 * DRMRect - Dst Rectangle
167 */
168 CONNECTOR_SET_OUTPUT_RECT,
169 /*
170 * Op: Sets frame buffer ID for writeback connector.
171 * Arg: uint32_t - Connector ID
172 * uint32_t - Framebuffer ID
173 */
174 CONNECTOR_SET_OUTPUT_FB_ID,
Sushil Chauhan3396e202017-04-14 18:34:22 -0700175 /*
176 * Op: Sets power mode for connector.
177 * Arg: uint32_t - Connector ID
178 * uint32_t - Power Mode
179 */
180 CONNECTOR_SET_POWER_MODE,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700181};
182
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700183enum struct DRMRotation {
184 FLIP_H = 0x1,
185 FLIP_V = 0x2,
186 ROT_90 = 0x4,
187};
188
Sushil Chauhan3396e202017-04-14 18:34:22 -0700189enum struct DRMPowerMode {
190 ON,
191 DOZE,
192 DOZE_SUSPEND,
193 OFF,
194};
195
Saurabh Shah66c941b2016-07-06 17:34:05 -0700196enum struct DRMBlendType {
197 UNDEFINED = 0,
198 OPAQUE = 1,
199 PREMULTIPLIED = 2,
200 COVERAGE = 3,
201};
202
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800203enum struct DRMSrcConfig {
204 DEINTERLACE = 0,
205};
206
Saurabh Shah66c941b2016-07-06 17:34:05 -0700207/* Display type to identify a suitable connector */
208enum struct DRMDisplayType {
209 PERIPHERAL,
210 TV,
211 VIRTUAL,
212};
213
214struct DRMRect {
215 uint32_t left; // Left-most pixel coordinate.
216 uint32_t top; // Top-most pixel coordinate.
217 uint32_t right; // Right-most pixel coordinate.
218 uint32_t bottom; // Bottom-most pixel coordinate.
219};
220
221//------------------------------------------------------------------------
222// DRM Info Query Types
223//------------------------------------------------------------------------
224
225enum struct QSEEDVersion {
226 V1,
227 V2,
228 V3,
229};
230
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700231enum struct SmartDMARevision {
232 V1,
233 V2,
234};
235
Saurabh Shah66c941b2016-07-06 17:34:05 -0700236/* Per CRTC Resource Info*/
237struct DRMCrtcInfo {
238 bool has_src_split;
239 uint32_t max_blend_stages;
240 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700241 SmartDMARevision smart_dma_rev;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700242};
243
244enum struct DRMPlaneType {
245 // Has CSC and scaling capability
246 VIG = 0,
247 // Has scaling capability but no CSC
248 RGB,
249 // No scaling support
250 DMA,
251 // Supports a small dimension and doesn't use a CRTC stage
252 CURSOR,
253 MAX,
254};
255
256struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700257 DRMPlaneType type;
258 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700259 // FourCC format enum and modifier
260 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
261 uint32_t max_linewidth;
262 uint32_t max_upscale;
263 uint32_t max_downscale;
264 uint32_t max_horizontal_deci;
265 uint32_t max_vertical_deci;
266};
267
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700268// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
269typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700270
271enum struct DRMTopology {
272 UNKNOWN, // To be compat with driver defs in sde_kms.h
273 SINGLE_LM,
274 DUAL_LM,
275 PPSPLIT,
276 DUAL_LM_MERGE,
277};
278
279enum struct DRMPanelMode {
280 VIDEO,
281 COMMAND,
282};
283
284/* Per Connector Info*/
285struct DRMConnectorInfo {
286 uint32_t mmWidth;
287 uint32_t mmHeight;
288 uint32_t type;
289 uint32_t num_modes;
290 drmModeModeInfo *modes;
291 DRMTopology topology;
292 std::string panel_name;
293 DRMPanelMode panel_mode;
294 bool is_primary;
295 // Valid only if DRMPanelMode is VIDEO
296 bool dynamic_fps;
297 // FourCC format enum and modifier
298 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
299 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
300 uint32_t max_linewidth;
301};
302
303/* Identifier token for a display */
304struct DRMDisplayToken {
305 uint32_t conn_id;
306 uint32_t crtc_id;
307};
308
Ping Li281f48d2017-01-16 12:45:40 -0800309enum DRMPPFeatureID {
310 kFeaturePcc,
311 kFeatureIgc,
312 kFeaturePgc,
313 kFeatureMixerGc,
314 kFeaturePaV2,
315 kFeatureDither,
316 kFeatureGamut,
317 kFeaturePADither,
318 kPPFeaturesMax,
319};
320
321enum DRMPPPropType {
322 kPropEnum,
323 kPropRange,
324 kPropBlob,
325 kPropTypeMax,
326};
327
328struct DRMPPFeatureInfo {
329 DRMPPFeatureID id;
330 DRMPPPropType type;
331 uint32_t version;
332 uint32_t payload_size;
333 void *payload;
334};
335
Saurabh Shah0ffee302016-11-22 10:42:11 -0800336struct DRMScalerLUTInfo {
337 uint32_t dir_lut_size = 0;
338 uint32_t cir_lut_size = 0;
339 uint32_t sep_lut_size = 0;
340 uint64_t dir_lut = 0;
341 uint64_t cir_lut = 0;
342 uint64_t sep_lut = 0;
343};
344
Saurabh Shah66c941b2016-07-06 17:34:05 -0700345/* DRM Atomic Request Property Set.
346 *
347 * Helper class to create and populate atomic properties of DRM components
348 * when rendered in DRM atomic mode */
349class DRMAtomicReqInterface {
350 public:
351 virtual ~DRMAtomicReqInterface() {}
352 /* Perform request operation.
353 *
354 * [input]: opcode: operation code from DRMOps list.
355 * var_arg: arguments for DRMOps's can differ in number and
356 * data type. Refer above DRMOps to details.
357 * [return]: Error code if the API fails, 0 on success.
358 */
359 virtual int Perform(DRMOps opcode, ...) = 0;
360
361 /*
362 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
363 * called every frame.
364 * [input]: synchronous: Determines if the call should block until a h/w flip
365 * [return]: Error code if the API fails, 0 on success.
366 */
367 virtual int Commit(bool synchronous) = 0;
368 /*
369 * Validate the params set via Perform().
370 * [return]: Error code if the API fails, 0 on success.
371 */
372 virtual int Validate() = 0;
373};
374
375class DRMManagerInterface;
376
377/* Populates a singleton instance of DRMManager */
378typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
379
380/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800381typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700382
383/*
384 * DRM Manager Interface - Any class which plans to implement helper function for vendor
385 * specific DRM driver implementation must implement the below interface routines to work
386 * with SDM.
387 */
388
389class DRMManagerInterface {
390 public:
391 virtual ~DRMManagerInterface() {}
392
393 /*
394 * Since SDM completely manages the planes. GetPlanesInfo will provide all
395 * the plane information.
396 * [output]: DRMPlanesInfo: Resource Info for planes.
397 */
398 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
399
400 /*
401 * Will provide all the information of a selected crtc.
402 * [input]: Use crtc id 0 to obtain system wide info
403 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
404 */
405 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
406
407 /*
408 * Will provide all the information of a selected connector.
409 * [output]: DRMConnectorInfo: Resource Info for the given connector id
410 */
411 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
412
413 /*
Ping Li281f48d2017-01-16 12:45:40 -0800414 * Will query post propcessing feature info of a CRTC.
415 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
416 */
417 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
418 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700419 * Register a logical display to receive a token.
420 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
421 * On display connect(bootup or hotplug), clients should invoke this interface to
422 * establish the pipeline for the display and should get a DisplayToken
423 * populated with crtc and connnector(s) id's. Here onwards, Client should
424 * use this token to represent the display for any Perform operations if
425 * needed.
426 *
427 * [input]: disp_type - Peripheral / TV / Virtual
428 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
429 * [return]: 0 on success, a negative error value otherwise
430 */
431 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
432
433 /* Client should invoke this interface on display disconnect.
434 * [input]: DRMDisplayToken - identifier for the display.
435 */
436 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
437
438 /*
439 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
440 * returned as part of RegisterDisplay API. Needs to be called per display.
441 * [input]: DRMDisplayToken that identifies a display pipeline
442 * [output]: Pointer to an instance of DRMAtomicReqInterface.
443 * [return]: Error code if the API fails, 0 on success.
444 */
445 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
446
447 /*
448 * Destroys the instance of DRMAtomicReqInterface
449 * [input]: Pointer to a DRMAtomicReqInterface
450 * [return]: Error code if the API fails, 0 on success.
451 */
452 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
Saurabh Shah0ffee302016-11-22 10:42:11 -0800453 /*
454 * Sets the global scaler LUT
455 * [input]: LUT Info
456 * [return]: Error code if the API fails, 0 on success.
457 */
458 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700459};
Saurabh Shah0ffee302016-11-22 10:42:11 -0800460
Saurabh Shah66c941b2016-07-06 17:34:05 -0700461} // namespace sde_drm
462#endif // __DRM_INTERFACE_H__