blob: bf46200f624ee1133ac043d81ba2d151fa2c09f3 [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
206/* Per CRTC Resource Info*/
207struct DRMCrtcInfo {
208 bool has_src_split;
209 uint32_t max_blend_stages;
210 QSEEDVersion qseed_version;
211};
212
213enum struct DRMPlaneType {
214 // Has CSC and scaling capability
215 VIG = 0,
216 // Has scaling capability but no CSC
217 RGB,
218 // No scaling support
219 DMA,
220 // Supports a small dimension and doesn't use a CRTC stage
221 CURSOR,
222 MAX,
223};
224
225struct DRMPlaneTypeInfo {
226 // FourCC format enum and modifier
227 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
228 uint32_t max_linewidth;
229 uint32_t max_upscale;
230 uint32_t max_downscale;
231 uint32_t max_horizontal_deci;
232 uint32_t max_vertical_deci;
233};
234
235/* All DRM Planes Info*/
236struct DRMPlanesInfo {
237 // Plane id and plane type sorted by highest to lowest priority
238 std::vector<std::pair<uint32_t, DRMPlaneType>> planes;
239 // Plane type and type info
240 std::map<DRMPlaneType, DRMPlaneTypeInfo> types;
241};
242
243enum struct DRMTopology {
244 UNKNOWN, // To be compat with driver defs in sde_kms.h
245 SINGLE_LM,
246 DUAL_LM,
247 PPSPLIT,
248 DUAL_LM_MERGE,
249};
250
251enum struct DRMPanelMode {
252 VIDEO,
253 COMMAND,
254};
255
256/* Per Connector Info*/
257struct DRMConnectorInfo {
258 uint32_t mmWidth;
259 uint32_t mmHeight;
260 uint32_t type;
261 uint32_t num_modes;
262 drmModeModeInfo *modes;
263 DRMTopology topology;
264 std::string panel_name;
265 DRMPanelMode panel_mode;
266 bool is_primary;
267 // Valid only if DRMPanelMode is VIDEO
268 bool dynamic_fps;
269 // FourCC format enum and modifier
270 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
271 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
272 uint32_t max_linewidth;
273};
274
275/* Identifier token for a display */
276struct DRMDisplayToken {
277 uint32_t conn_id;
278 uint32_t crtc_id;
279};
280
Ping Li281f48d2017-01-16 12:45:40 -0800281enum DRMPPFeatureID {
282 kFeaturePcc,
283 kFeatureIgc,
284 kFeaturePgc,
285 kFeatureMixerGc,
286 kFeaturePaV2,
287 kFeatureDither,
288 kFeatureGamut,
289 kFeaturePADither,
290 kPPFeaturesMax,
291};
292
293enum DRMPPPropType {
294 kPropEnum,
295 kPropRange,
296 kPropBlob,
297 kPropTypeMax,
298};
299
300struct DRMPPFeatureInfo {
301 DRMPPFeatureID id;
302 DRMPPPropType type;
303 uint32_t version;
304 uint32_t payload_size;
305 void *payload;
306};
307
Saurabh Shah66c941b2016-07-06 17:34:05 -0700308/* DRM Atomic Request Property Set.
309 *
310 * Helper class to create and populate atomic properties of DRM components
311 * when rendered in DRM atomic mode */
312class DRMAtomicReqInterface {
313 public:
314 virtual ~DRMAtomicReqInterface() {}
315 /* Perform request operation.
316 *
317 * [input]: opcode: operation code from DRMOps list.
318 * var_arg: arguments for DRMOps's can differ in number and
319 * data type. Refer above DRMOps to details.
320 * [return]: Error code if the API fails, 0 on success.
321 */
322 virtual int Perform(DRMOps opcode, ...) = 0;
323
324 /*
325 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
326 * called every frame.
327 * [input]: synchronous: Determines if the call should block until a h/w flip
328 * [return]: Error code if the API fails, 0 on success.
329 */
330 virtual int Commit(bool synchronous) = 0;
331 /*
332 * Validate the params set via Perform().
333 * [return]: Error code if the API fails, 0 on success.
334 */
335 virtual int Validate() = 0;
336};
337
338class DRMManagerInterface;
339
340/* Populates a singleton instance of DRMManager */
341typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
342
343/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800344typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700345
346/*
347 * DRM Manager Interface - Any class which plans to implement helper function for vendor
348 * specific DRM driver implementation must implement the below interface routines to work
349 * with SDM.
350 */
351
352class DRMManagerInterface {
353 public:
354 virtual ~DRMManagerInterface() {}
355
356 /*
357 * Since SDM completely manages the planes. GetPlanesInfo will provide all
358 * the plane information.
359 * [output]: DRMPlanesInfo: Resource Info for planes.
360 */
361 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
362
363 /*
364 * Will provide all the information of a selected crtc.
365 * [input]: Use crtc id 0 to obtain system wide info
366 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
367 */
368 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
369
370 /*
371 * Will provide all the information of a selected connector.
372 * [output]: DRMConnectorInfo: Resource Info for the given connector id
373 */
374 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
375
376 /*
Ping Li281f48d2017-01-16 12:45:40 -0800377 * Will query post propcessing feature info of a CRTC.
378 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
379 */
380 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
381 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700382 * Register a logical display to receive a token.
383 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
384 * On display connect(bootup or hotplug), clients should invoke this interface to
385 * establish the pipeline for the display and should get a DisplayToken
386 * populated with crtc and connnector(s) id's. Here onwards, Client should
387 * use this token to represent the display for any Perform operations if
388 * needed.
389 *
390 * [input]: disp_type - Peripheral / TV / Virtual
391 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
392 * [return]: 0 on success, a negative error value otherwise
393 */
394 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
395
396 /* Client should invoke this interface on display disconnect.
397 * [input]: DRMDisplayToken - identifier for the display.
398 */
399 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
400
401 /*
402 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
403 * returned as part of RegisterDisplay API. Needs to be called per display.
404 * [input]: DRMDisplayToken that identifies a display pipeline
405 * [output]: Pointer to an instance of DRMAtomicReqInterface.
406 * [return]: Error code if the API fails, 0 on success.
407 */
408 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
409
410 /*
411 * Destroys the instance of DRMAtomicReqInterface
412 * [input]: Pointer to a DRMAtomicReqInterface
413 * [return]: Error code if the API fails, 0 on success.
414 */
415 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
416};
417} // namespace sde_drm
418#endif // __DRM_INTERFACE_H__