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