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