blob: 46ab7829ea3c8a84c7c303438befa8651a4995e0 [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 {
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -080042
43typedef std::map<std::pair<uint32_t, uint64_t>, float> CompRatioMap;
44
Saurabh Shah66c941b2016-07-06 17:34:05 -070045/*
46 * Drm Atomic Operation Codes
47 */
48enum struct DRMOps {
49 /*
50 * Op: Sets plane source crop
51 * Arg: uint32_t - Plane ID
52 * DRMRect - Source Rectangle
53 */
54 PLANE_SET_SRC_RECT,
55 /*
56 * Op: Sets plane destination rect
57 * Arg: uint32_t - Plane ID
58 * DRMRect - Dst Rectangle
59 */
60 PLANE_SET_DST_RECT,
61 /*
62 * Op: Sets plane zorder
63 * Arg: uint32_t - Plane ID
64 * uint32_t - zorder
65 */
66 PLANE_SET_ZORDER,
67 /*
68 * Op: Sets plane rotation flags
69 * Arg: uint32_t - Plane ID
70 * uint32_t - bit mask of rotation flags (See drm_mode.h for enums)
71 */
72 PLANE_SET_ROTATION,
73 /*
74 * Op: Sets plane alpha
75 * Arg: uint32_t - Plane ID
76 * uint32_t - alpha value
77 */
78 PLANE_SET_ALPHA,
79 /*
80 * Op: Sets the blend type
81 * Arg: uint32_t - Plane ID
82 * uint32_t - blend type (see DRMBlendType)
83 */
84 PLANE_SET_BLEND_TYPE,
85 /*
86 * Op: Sets horizontal decimation
87 * Arg: uint32_t - Plane ID
88 * uint32_t - decimation factor
89 */
90 PLANE_SET_H_DECIMATION,
91 /*
92 * Op: Sets vertical decimation
93 * Arg: uint32_t - Plane ID
94 * uint32_t - decimation factor
95 */
96 PLANE_SET_V_DECIMATION,
97 /*
Prabhanjan Kandula585aa652017-01-26 18:39:11 -080098 * Op: Sets source config flags
99 * Arg: uint32_t - Plane ID
100 * uint32_t - flags to enable or disable a specific op. E.g. deinterlacing
101 */
102 PLANE_SET_SRC_CONFIG,
103 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700104 * Op: Sets frame buffer ID for plane. Set together with CRTC.
105 * Arg: uint32_t - Plane ID
106 * uint32_t - Framebuffer ID
107 */
108 PLANE_SET_FB_ID,
109 /*
110 * Op: Sets the crtc for this plane. Set together with FB_ID.
111 * Arg: uint32_t - Plane ID
112 * uint32_t - CRTC ID
113 */
114 PLANE_SET_CRTC,
115 /*
116 * Op: Sets acquire fence for this plane's buffer. Set together with FB_ID, CRTC.
117 * Arg: uint32_t - Plane ID
118 * uint32_t - Input fence
119 */
120 PLANE_SET_INPUT_FENCE,
121 /*
Saurabh Shah0ffee302016-11-22 10:42:11 -0800122 * Op: Sets scaler config on this plane.
123 * Arg: uint32_t - Plane ID
124 * uint64_t - Address of the scaler config object (version based)
125 */
126 PLANE_SET_SCALER_CONFIG,
127 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700128 * Op: Activate or deactivate a CRTC
129 * Arg: uint32_t - CRTC ID
130 * uint32_t - 1 to enable, 0 to disable
131 */
132 CRTC_SET_ACTIVE,
133 /*
134 * Op: Sets display mode
135 * Arg: uint32_t - CRTC ID
136 * drmModeModeInfo* - Pointer to display mode
137 */
138 CRTC_SET_MODE,
139 /*
140 * Op: Sets an offset indicating when a release fence should be signalled.
141 * Arg: uint32_t - offset
142 * 0: non-speculative, default
143 * 1: speculative
144 */
145 CRTC_SET_OUTPUT_FENCE_OFFSET,
146 /*
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800147 * Op: Sets overall SDE core clock
148 * Arg: uint32_t - CRTC ID
149 * uint32_t - core_clk
150 */
151 CRTC_SET_CORE_CLK,
152 /*
153 * Op: Sets overall SDE core average bandwidth
154 * Arg: uint32_t - CRTC ID
155 * uint32_t - core_ab
156 */
157 CRTC_SET_CORE_AB,
158 /*
159 * Op: Sets overall SDE core instantaneous bandwidth
160 * Arg: uint32_t - CRTC ID
161 * uint32_t - core_ib
162 */
163 CRTC_SET_CORE_IB,
164 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700165 * Op: Returns release fence for this frame. Should be called after Commit() on
166 * DRMAtomicReqInterface.
167 * Arg: uint32_t - CRTC ID
168 * int * - Pointer to an integer that will hold the returned fence
169 */
170 CRTC_GET_RELEASE_FENCE,
171 /*
Ping Li281f48d2017-01-16 12:45:40 -0800172 * Op: Sets PP feature
173 * Arg: uint32_t - CRTC ID
174 * DRMPPFeatureInfo * - PP feature data pointer
175 */
176 CRTC_SET_POST_PROC,
177 /*
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800178 * Op: Sets CRTC ROIs.
179 * Arg: uint32_t - CRTC ID
180 * uint32_t - number of ROIs
181 * DRMRect * - Array of CRTC ROIs
182 */
183 CRTC_SET_ROI,
184 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700185 * Op: Returns retire fence for this commit. Should be called after Commit() on
186 * DRMAtomicReqInterface.
187 * Arg: uint32_t - Connector ID
188 * int * - Pointer to an integer that will hold the returned fence
189 */
190 CONNECTOR_GET_RETIRE_FENCE,
191 /*
192 * Op: Sets writeback connector destination rect
193 * Arg: uint32_t - Connector ID
194 * DRMRect - Dst Rectangle
195 */
196 CONNECTOR_SET_OUTPUT_RECT,
197 /*
198 * Op: Sets frame buffer ID for writeback connector.
199 * Arg: uint32_t - Connector ID
200 * uint32_t - Framebuffer ID
201 */
202 CONNECTOR_SET_OUTPUT_FB_ID,
Sushil Chauhan3396e202017-04-14 18:34:22 -0700203 /*
204 * Op: Sets power mode for connector.
205 * Arg: uint32_t - Connector ID
206 * uint32_t - Power Mode
207 */
208 CONNECTOR_SET_POWER_MODE,
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800209 /*
210 * Op: Sets panel ROIs.
211 * Arg: uint32_t - Connector ID
212 * uint32_t - number of ROIs
213 * DRMRect * - Array of Connector ROIs
214 */
215 CONNECTOR_SET_ROI,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700216};
217
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700218enum struct DRMRotation {
219 FLIP_H = 0x1,
220 FLIP_V = 0x2,
221 ROT_90 = 0x4,
222};
223
Sushil Chauhan3396e202017-04-14 18:34:22 -0700224enum struct DRMPowerMode {
225 ON,
226 DOZE,
227 DOZE_SUSPEND,
228 OFF,
229};
230
Saurabh Shah66c941b2016-07-06 17:34:05 -0700231enum struct DRMBlendType {
232 UNDEFINED = 0,
233 OPAQUE = 1,
234 PREMULTIPLIED = 2,
235 COVERAGE = 3,
236};
237
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800238enum struct DRMSrcConfig {
239 DEINTERLACE = 0,
240};
241
Saurabh Shah66c941b2016-07-06 17:34:05 -0700242/* Display type to identify a suitable connector */
243enum struct DRMDisplayType {
244 PERIPHERAL,
245 TV,
246 VIRTUAL,
247};
248
249struct DRMRect {
250 uint32_t left; // Left-most pixel coordinate.
251 uint32_t top; // Top-most pixel coordinate.
252 uint32_t right; // Right-most pixel coordinate.
253 uint32_t bottom; // Bottom-most pixel coordinate.
254};
255
256//------------------------------------------------------------------------
257// DRM Info Query Types
258//------------------------------------------------------------------------
259
260enum struct QSEEDVersion {
261 V1,
262 V2,
263 V3,
264};
265
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700266enum struct SmartDMARevision {
267 V1,
268 V2,
269};
270
Saurabh Shah66c941b2016-07-06 17:34:05 -0700271/* Per CRTC Resource Info*/
272struct DRMCrtcInfo {
273 bool has_src_split;
274 uint32_t max_blend_stages;
275 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700276 SmartDMARevision smart_dma_rev;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800277 float ib_fudge_factor;
278 float clk_fudge_factor;
279 uint32_t dest_scale_prefill_lines;
280 uint32_t undersized_prefill_lines;
281 uint32_t macrotile_prefill_lines;
282 uint32_t nv12_prefill_lines;
283 uint32_t linear_prefill_lines;
284 uint32_t downscale_prefill_lines;
285 uint32_t extra_prefill_lines;
286 uint32_t amortized_threshold;
287 uint64_t max_bandwidth_low;
288 uint64_t max_bandwidth_high;
289 uint32_t max_sde_clk;
290 CompRatioMap comp_ratio_rt_map;
291 CompRatioMap comp_ratio_nrt_map;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700292};
293
294enum struct DRMPlaneType {
295 // Has CSC and scaling capability
296 VIG = 0,
297 // Has scaling capability but no CSC
298 RGB,
299 // No scaling support
300 DMA,
301 // Supports a small dimension and doesn't use a CRTC stage
302 CURSOR,
303 MAX,
304};
305
306struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700307 DRMPlaneType type;
308 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700309 // FourCC format enum and modifier
310 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
311 uint32_t max_linewidth;
312 uint32_t max_upscale;
313 uint32_t max_downscale;
314 uint32_t max_horizontal_deci;
315 uint32_t max_vertical_deci;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800316 uint64_t max_pipe_bandwidth;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700317};
318
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700319// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
320typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700321
322enum struct DRMTopology {
323 UNKNOWN, // To be compat with driver defs in sde_kms.h
324 SINGLE_LM,
325 DUAL_LM,
326 PPSPLIT,
327 DUAL_LM_MERGE,
328};
329
330enum struct DRMPanelMode {
331 VIDEO,
332 COMMAND,
333};
334
335/* Per Connector Info*/
336struct DRMConnectorInfo {
337 uint32_t mmWidth;
338 uint32_t mmHeight;
339 uint32_t type;
340 uint32_t num_modes;
341 drmModeModeInfo *modes;
342 DRMTopology topology;
343 std::string panel_name;
344 DRMPanelMode panel_mode;
345 bool is_primary;
346 // Valid only if DRMPanelMode is VIDEO
347 bool dynamic_fps;
348 // FourCC format enum and modifier
349 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
350 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
351 uint32_t max_linewidth;
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800352 // Valid only if mode is command
353 int num_roi;
354 int xstart;
355 int ystart;
356 int walign;
357 int halign;
358 int wmin;
359 int hmin;
360 bool roi_merge;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700361};
362
363/* Identifier token for a display */
364struct DRMDisplayToken {
365 uint32_t conn_id;
366 uint32_t crtc_id;
367};
368
Ping Li281f48d2017-01-16 12:45:40 -0800369enum DRMPPFeatureID {
370 kFeaturePcc,
371 kFeatureIgc,
372 kFeaturePgc,
373 kFeatureMixerGc,
374 kFeaturePaV2,
375 kFeatureDither,
376 kFeatureGamut,
377 kFeaturePADither,
378 kPPFeaturesMax,
379};
380
381enum DRMPPPropType {
382 kPropEnum,
383 kPropRange,
384 kPropBlob,
385 kPropTypeMax,
386};
387
388struct DRMPPFeatureInfo {
389 DRMPPFeatureID id;
390 DRMPPPropType type;
391 uint32_t version;
392 uint32_t payload_size;
393 void *payload;
394};
395
Saurabh Shah0ffee302016-11-22 10:42:11 -0800396struct DRMScalerLUTInfo {
397 uint32_t dir_lut_size = 0;
398 uint32_t cir_lut_size = 0;
399 uint32_t sep_lut_size = 0;
400 uint64_t dir_lut = 0;
401 uint64_t cir_lut = 0;
402 uint64_t sep_lut = 0;
403};
404
Saurabh Shah66c941b2016-07-06 17:34:05 -0700405/* DRM Atomic Request Property Set.
406 *
407 * Helper class to create and populate atomic properties of DRM components
408 * when rendered in DRM atomic mode */
409class DRMAtomicReqInterface {
410 public:
411 virtual ~DRMAtomicReqInterface() {}
412 /* Perform request operation.
413 *
414 * [input]: opcode: operation code from DRMOps list.
415 * var_arg: arguments for DRMOps's can differ in number and
416 * data type. Refer above DRMOps to details.
417 * [return]: Error code if the API fails, 0 on success.
418 */
419 virtual int Perform(DRMOps opcode, ...) = 0;
420
421 /*
422 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
423 * called every frame.
424 * [input]: synchronous: Determines if the call should block until a h/w flip
425 * [return]: Error code if the API fails, 0 on success.
426 */
427 virtual int Commit(bool synchronous) = 0;
428 /*
429 * Validate the params set via Perform().
430 * [return]: Error code if the API fails, 0 on success.
431 */
432 virtual int Validate() = 0;
433};
434
435class DRMManagerInterface;
436
437/* Populates a singleton instance of DRMManager */
438typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
439
440/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800441typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700442
443/*
444 * DRM Manager Interface - Any class which plans to implement helper function for vendor
445 * specific DRM driver implementation must implement the below interface routines to work
446 * with SDM.
447 */
448
449class DRMManagerInterface {
450 public:
451 virtual ~DRMManagerInterface() {}
452
453 /*
454 * Since SDM completely manages the planes. GetPlanesInfo will provide all
455 * the plane information.
456 * [output]: DRMPlanesInfo: Resource Info for planes.
457 */
458 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
459
460 /*
461 * Will provide all the information of a selected crtc.
462 * [input]: Use crtc id 0 to obtain system wide info
463 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
464 */
465 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
466
467 /*
468 * Will provide all the information of a selected connector.
469 * [output]: DRMConnectorInfo: Resource Info for the given connector id
470 */
471 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
472
473 /*
Ping Li281f48d2017-01-16 12:45:40 -0800474 * Will query post propcessing feature info of a CRTC.
475 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
476 */
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800477 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
Ping Li281f48d2017-01-16 12:45:40 -0800478 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700479 * Register a logical display to receive a token.
480 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
481 * On display connect(bootup or hotplug), clients should invoke this interface to
482 * establish the pipeline for the display and should get a DisplayToken
483 * populated with crtc and connnector(s) id's. Here onwards, Client should
484 * use this token to represent the display for any Perform operations if
485 * needed.
486 *
487 * [input]: disp_type - Peripheral / TV / Virtual
488 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
489 * [return]: 0 on success, a negative error value otherwise
490 */
491 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
492
493 /* Client should invoke this interface on display disconnect.
494 * [input]: DRMDisplayToken - identifier for the display.
495 */
496 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
497
498 /*
499 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
500 * returned as part of RegisterDisplay API. Needs to be called per display.
501 * [input]: DRMDisplayToken that identifies a display pipeline
502 * [output]: Pointer to an instance of DRMAtomicReqInterface.
503 * [return]: Error code if the API fails, 0 on success.
504 */
505 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
506
507 /*
508 * Destroys the instance of DRMAtomicReqInterface
509 * [input]: Pointer to a DRMAtomicReqInterface
510 * [return]: Error code if the API fails, 0 on success.
511 */
512 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
Saurabh Shah0ffee302016-11-22 10:42:11 -0800513 /*
514 * Sets the global scaler LUT
515 * [input]: LUT Info
516 * [return]: Error code if the API fails, 0 on success.
517 */
518 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700519};
Saurabh Shah0ffee302016-11-22 10:42:11 -0800520
Saurabh Shah66c941b2016-07-06 17:34:05 -0700521} // namespace sde_drm
522#endif // __DRM_INTERFACE_H__