blob: 6e87b716fb35b6b7d049b9cd6cefb6595b058b72 [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 /*
119 * Op: Activate or deactivate a CRTC
120 * Arg: uint32_t - CRTC ID
121 * uint32_t - 1 to enable, 0 to disable
122 */
123 CRTC_SET_ACTIVE,
124 /*
125 * Op: Sets display mode
126 * Arg: uint32_t - CRTC ID
127 * drmModeModeInfo* - Pointer to display mode
128 */
129 CRTC_SET_MODE,
130 /*
131 * Op: Sets an offset indicating when a release fence should be signalled.
132 * Arg: uint32_t - offset
133 * 0: non-speculative, default
134 * 1: speculative
135 */
136 CRTC_SET_OUTPUT_FENCE_OFFSET,
137 /*
138 * Op: Returns release fence for this frame. Should be called after Commit() on
139 * DRMAtomicReqInterface.
140 * Arg: uint32_t - CRTC ID
141 * int * - Pointer to an integer that will hold the returned fence
142 */
143 CRTC_GET_RELEASE_FENCE,
144 /*
Ping Li281f48d2017-01-16 12:45:40 -0800145 * Op: Sets PP feature
146 * Arg: uint32_t - CRTC ID
147 * DRMPPFeatureInfo * - PP feature data pointer
148 */
149 CRTC_SET_POST_PROC,
150 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700151 * Op: Returns retire fence for this commit. Should be called after Commit() on
152 * DRMAtomicReqInterface.
153 * Arg: uint32_t - Connector ID
154 * int * - Pointer to an integer that will hold the returned fence
155 */
156 CONNECTOR_GET_RETIRE_FENCE,
157 /*
158 * Op: Sets writeback connector destination rect
159 * Arg: uint32_t - Connector ID
160 * DRMRect - Dst Rectangle
161 */
162 CONNECTOR_SET_OUTPUT_RECT,
163 /*
164 * Op: Sets frame buffer ID for writeback connector.
165 * Arg: uint32_t - Connector ID
166 * uint32_t - Framebuffer ID
167 */
168 CONNECTOR_SET_OUTPUT_FB_ID,
169};
170
171enum struct DRMBlendType {
172 UNDEFINED = 0,
173 OPAQUE = 1,
174 PREMULTIPLIED = 2,
175 COVERAGE = 3,
176};
177
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800178enum struct DRMSrcConfig {
179 DEINTERLACE = 0,
180};
181
Saurabh Shah66c941b2016-07-06 17:34:05 -0700182/* Display type to identify a suitable connector */
183enum struct DRMDisplayType {
184 PERIPHERAL,
185 TV,
186 VIRTUAL,
187};
188
189struct DRMRect {
190 uint32_t left; // Left-most pixel coordinate.
191 uint32_t top; // Top-most pixel coordinate.
192 uint32_t right; // Right-most pixel coordinate.
193 uint32_t bottom; // Bottom-most pixel coordinate.
194};
195
196//------------------------------------------------------------------------
197// DRM Info Query Types
198//------------------------------------------------------------------------
199
200enum struct QSEEDVersion {
201 V1,
202 V2,
203 V3,
204};
205
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700206enum struct SmartDMARevision {
207 V1,
208 V2,
209};
210
Saurabh Shah66c941b2016-07-06 17:34:05 -0700211/* Per CRTC Resource Info*/
212struct DRMCrtcInfo {
213 bool has_src_split;
214 uint32_t max_blend_stages;
215 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700216 SmartDMARevision smart_dma_rev;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700217};
218
219enum struct DRMPlaneType {
220 // Has CSC and scaling capability
221 VIG = 0,
222 // Has scaling capability but no CSC
223 RGB,
224 // No scaling support
225 DMA,
226 // Supports a small dimension and doesn't use a CRTC stage
227 CURSOR,
228 MAX,
229};
230
231struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700232 DRMPlaneType type;
233 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700234 // FourCC format enum and modifier
235 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
236 uint32_t max_linewidth;
237 uint32_t max_upscale;
238 uint32_t max_downscale;
239 uint32_t max_horizontal_deci;
240 uint32_t max_vertical_deci;
241};
242
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700243// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
244typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700245
246enum struct DRMTopology {
247 UNKNOWN, // To be compat with driver defs in sde_kms.h
248 SINGLE_LM,
249 DUAL_LM,
250 PPSPLIT,
251 DUAL_LM_MERGE,
252};
253
254enum struct DRMPanelMode {
255 VIDEO,
256 COMMAND,
257};
258
259/* Per Connector Info*/
260struct DRMConnectorInfo {
261 uint32_t mmWidth;
262 uint32_t mmHeight;
263 uint32_t type;
264 uint32_t num_modes;
265 drmModeModeInfo *modes;
266 DRMTopology topology;
267 std::string panel_name;
268 DRMPanelMode panel_mode;
269 bool is_primary;
270 // Valid only if DRMPanelMode is VIDEO
271 bool dynamic_fps;
272 // FourCC format enum and modifier
273 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
274 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
275 uint32_t max_linewidth;
276};
277
278/* Identifier token for a display */
279struct DRMDisplayToken {
280 uint32_t conn_id;
281 uint32_t crtc_id;
282};
283
Ping Li281f48d2017-01-16 12:45:40 -0800284enum DRMPPFeatureID {
285 kFeaturePcc,
286 kFeatureIgc,
287 kFeaturePgc,
288 kFeatureMixerGc,
289 kFeaturePaV2,
290 kFeatureDither,
291 kFeatureGamut,
292 kFeaturePADither,
293 kPPFeaturesMax,
294};
295
296enum DRMPPPropType {
297 kPropEnum,
298 kPropRange,
299 kPropBlob,
300 kPropTypeMax,
301};
302
303struct DRMPPFeatureInfo {
304 DRMPPFeatureID id;
305 DRMPPPropType type;
306 uint32_t version;
307 uint32_t payload_size;
308 void *payload;
309};
310
Saurabh Shah66c941b2016-07-06 17:34:05 -0700311/* DRM Atomic Request Property Set.
312 *
313 * Helper class to create and populate atomic properties of DRM components
314 * when rendered in DRM atomic mode */
315class DRMAtomicReqInterface {
316 public:
317 virtual ~DRMAtomicReqInterface() {}
318 /* Perform request operation.
319 *
320 * [input]: opcode: operation code from DRMOps list.
321 * var_arg: arguments for DRMOps's can differ in number and
322 * data type. Refer above DRMOps to details.
323 * [return]: Error code if the API fails, 0 on success.
324 */
325 virtual int Perform(DRMOps opcode, ...) = 0;
326
327 /*
328 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
329 * called every frame.
330 * [input]: synchronous: Determines if the call should block until a h/w flip
331 * [return]: Error code if the API fails, 0 on success.
332 */
333 virtual int Commit(bool synchronous) = 0;
334 /*
335 * Validate the params set via Perform().
336 * [return]: Error code if the API fails, 0 on success.
337 */
338 virtual int Validate() = 0;
339};
340
341class DRMManagerInterface;
342
343/* Populates a singleton instance of DRMManager */
344typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
345
346/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800347typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700348
349/*
350 * DRM Manager Interface - Any class which plans to implement helper function for vendor
351 * specific DRM driver implementation must implement the below interface routines to work
352 * with SDM.
353 */
354
355class DRMManagerInterface {
356 public:
357 virtual ~DRMManagerInterface() {}
358
359 /*
360 * Since SDM completely manages the planes. GetPlanesInfo will provide all
361 * the plane information.
362 * [output]: DRMPlanesInfo: Resource Info for planes.
363 */
364 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
365
366 /*
367 * Will provide all the information of a selected crtc.
368 * [input]: Use crtc id 0 to obtain system wide info
369 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
370 */
371 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
372
373 /*
374 * Will provide all the information of a selected connector.
375 * [output]: DRMConnectorInfo: Resource Info for the given connector id
376 */
377 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
378
379 /*
Ping Li281f48d2017-01-16 12:45:40 -0800380 * Will query post propcessing feature info of a CRTC.
381 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
382 */
383 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
384 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700385 * Register a logical display to receive a token.
386 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
387 * On display connect(bootup or hotplug), clients should invoke this interface to
388 * establish the pipeline for the display and should get a DisplayToken
389 * populated with crtc and connnector(s) id's. Here onwards, Client should
390 * use this token to represent the display for any Perform operations if
391 * needed.
392 *
393 * [input]: disp_type - Peripheral / TV / Virtual
394 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
395 * [return]: 0 on success, a negative error value otherwise
396 */
397 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
398
399 /* Client should invoke this interface on display disconnect.
400 * [input]: DRMDisplayToken - identifier for the display.
401 */
402 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
403
404 /*
405 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
406 * returned as part of RegisterDisplay API. Needs to be called per display.
407 * [input]: DRMDisplayToken that identifies a display pipeline
408 * [output]: Pointer to an instance of DRMAtomicReqInterface.
409 * [return]: Error code if the API fails, 0 on success.
410 */
411 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
412
413 /*
414 * Destroys the instance of DRMAtomicReqInterface
415 * [input]: Pointer to a DRMAtomicReqInterface
416 * [return]: Error code if the API fails, 0 on success.
417 */
418 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
419};
420} // namespace sde_drm
421#endif // __DRM_INTERFACE_H__