blob: b16c15b336d4b6a01f6b52beea2605660767886c [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,
Prabhanjan Kandula5bc7f8b2017-05-23 12:24:57 -0700221 ROT_180 = FLIP_H | FLIP_V,
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700222 ROT_90 = 0x4,
223};
224
Sushil Chauhan3396e202017-04-14 18:34:22 -0700225enum struct DRMPowerMode {
226 ON,
227 DOZE,
228 DOZE_SUSPEND,
229 OFF,
230};
231
Saurabh Shah66c941b2016-07-06 17:34:05 -0700232enum struct DRMBlendType {
233 UNDEFINED = 0,
234 OPAQUE = 1,
235 PREMULTIPLIED = 2,
236 COVERAGE = 3,
237};
238
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800239enum struct DRMSrcConfig {
240 DEINTERLACE = 0,
241};
242
Saurabh Shah66c941b2016-07-06 17:34:05 -0700243/* Display type to identify a suitable connector */
244enum struct DRMDisplayType {
245 PERIPHERAL,
246 TV,
247 VIRTUAL,
248};
249
250struct DRMRect {
251 uint32_t left; // Left-most pixel coordinate.
252 uint32_t top; // Top-most pixel coordinate.
253 uint32_t right; // Right-most pixel coordinate.
254 uint32_t bottom; // Bottom-most pixel coordinate.
255};
256
257//------------------------------------------------------------------------
258// DRM Info Query Types
259//------------------------------------------------------------------------
260
261enum struct QSEEDVersion {
262 V1,
263 V2,
264 V3,
265};
266
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700267enum struct SmartDMARevision {
268 V1,
269 V2,
270};
271
Saurabh Shah66c941b2016-07-06 17:34:05 -0700272/* Per CRTC Resource Info*/
273struct DRMCrtcInfo {
274 bool has_src_split;
275 uint32_t max_blend_stages;
276 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700277 SmartDMARevision smart_dma_rev;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800278 float ib_fudge_factor;
279 float clk_fudge_factor;
280 uint32_t dest_scale_prefill_lines;
281 uint32_t undersized_prefill_lines;
282 uint32_t macrotile_prefill_lines;
283 uint32_t nv12_prefill_lines;
284 uint32_t linear_prefill_lines;
285 uint32_t downscale_prefill_lines;
286 uint32_t extra_prefill_lines;
287 uint32_t amortized_threshold;
288 uint64_t max_bandwidth_low;
289 uint64_t max_bandwidth_high;
290 uint32_t max_sde_clk;
291 CompRatioMap comp_ratio_rt_map;
292 CompRatioMap comp_ratio_nrt_map;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700293};
294
295enum struct DRMPlaneType {
296 // Has CSC and scaling capability
297 VIG = 0,
298 // Has scaling capability but no CSC
299 RGB,
300 // No scaling support
301 DMA,
302 // Supports a small dimension and doesn't use a CRTC stage
303 CURSOR,
304 MAX,
305};
306
307struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700308 DRMPlaneType type;
309 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700310 // FourCC format enum and modifier
311 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
312 uint32_t max_linewidth;
313 uint32_t max_upscale;
314 uint32_t max_downscale;
315 uint32_t max_horizontal_deci;
316 uint32_t max_vertical_deci;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800317 uint64_t max_pipe_bandwidth;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700318};
319
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700320// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
321typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700322
323enum struct DRMTopology {
Rohit Kulkarni2faa91c2017-06-05 15:43:48 -0700324 UNKNOWN, // To be compat with driver defs in sde_rm.h
Saurabh Shah66c941b2016-07-06 17:34:05 -0700325 SINGLE_LM,
Rohit Kulkarni2faa91c2017-06-05 15:43:48 -0700326 SINGLE_LM_DSC,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700327 DUAL_LM,
Rohit Kulkarni2faa91c2017-06-05 15:43:48 -0700328 DUAL_LM_DSC,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700329 DUAL_LM_MERGE,
Rohit Kulkarni2faa91c2017-06-05 15:43:48 -0700330 DUAL_LM_MERGE_DSC,
331 DUAL_LM_DSCMERGE,
332 PPSPLIT,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700333};
334
335enum struct DRMPanelMode {
336 VIDEO,
337 COMMAND,
338};
339
340/* Per Connector Info*/
341struct DRMConnectorInfo {
342 uint32_t mmWidth;
343 uint32_t mmHeight;
344 uint32_t type;
345 uint32_t num_modes;
346 drmModeModeInfo *modes;
347 DRMTopology topology;
348 std::string panel_name;
349 DRMPanelMode panel_mode;
350 bool is_primary;
351 // Valid only if DRMPanelMode is VIDEO
352 bool dynamic_fps;
353 // FourCC format enum and modifier
354 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
355 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
356 uint32_t max_linewidth;
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800357 // Valid only if mode is command
358 int num_roi;
359 int xstart;
360 int ystart;
361 int walign;
362 int halign;
363 int wmin;
364 int hmin;
365 bool roi_merge;
Prabhanjan Kandula5bc7f8b2017-05-23 12:24:57 -0700366 DRMRotation panel_orientation;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700367};
368
369/* Identifier token for a display */
370struct DRMDisplayToken {
371 uint32_t conn_id;
372 uint32_t crtc_id;
373};
374
Ping Li281f48d2017-01-16 12:45:40 -0800375enum DRMPPFeatureID {
376 kFeaturePcc,
377 kFeatureIgc,
378 kFeaturePgc,
379 kFeatureMixerGc,
380 kFeaturePaV2,
381 kFeatureDither,
382 kFeatureGamut,
383 kFeaturePADither,
384 kPPFeaturesMax,
385};
386
387enum DRMPPPropType {
388 kPropEnum,
389 kPropRange,
390 kPropBlob,
391 kPropTypeMax,
392};
393
394struct DRMPPFeatureInfo {
395 DRMPPFeatureID id;
396 DRMPPPropType type;
397 uint32_t version;
398 uint32_t payload_size;
399 void *payload;
400};
401
Saurabh Shah0ffee302016-11-22 10:42:11 -0800402struct DRMScalerLUTInfo {
403 uint32_t dir_lut_size = 0;
404 uint32_t cir_lut_size = 0;
405 uint32_t sep_lut_size = 0;
406 uint64_t dir_lut = 0;
407 uint64_t cir_lut = 0;
408 uint64_t sep_lut = 0;
409};
410
Saurabh Shah66c941b2016-07-06 17:34:05 -0700411/* DRM Atomic Request Property Set.
412 *
413 * Helper class to create and populate atomic properties of DRM components
414 * when rendered in DRM atomic mode */
415class DRMAtomicReqInterface {
416 public:
417 virtual ~DRMAtomicReqInterface() {}
418 /* Perform request operation.
419 *
420 * [input]: opcode: operation code from DRMOps list.
421 * var_arg: arguments for DRMOps's can differ in number and
422 * data type. Refer above DRMOps to details.
423 * [return]: Error code if the API fails, 0 on success.
424 */
425 virtual int Perform(DRMOps opcode, ...) = 0;
426
427 /*
428 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
429 * called every frame.
430 * [input]: synchronous: Determines if the call should block until a h/w flip
431 * [return]: Error code if the API fails, 0 on success.
432 */
433 virtual int Commit(bool synchronous) = 0;
434 /*
435 * Validate the params set via Perform().
436 * [return]: Error code if the API fails, 0 on success.
437 */
438 virtual int Validate() = 0;
439};
440
441class DRMManagerInterface;
442
443/* Populates a singleton instance of DRMManager */
444typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
445
446/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800447typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700448
449/*
450 * DRM Manager Interface - Any class which plans to implement helper function for vendor
451 * specific DRM driver implementation must implement the below interface routines to work
452 * with SDM.
453 */
454
455class DRMManagerInterface {
456 public:
457 virtual ~DRMManagerInterface() {}
458
459 /*
460 * Since SDM completely manages the planes. GetPlanesInfo will provide all
461 * the plane information.
462 * [output]: DRMPlanesInfo: Resource Info for planes.
463 */
464 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
465
466 /*
467 * Will provide all the information of a selected crtc.
468 * [input]: Use crtc id 0 to obtain system wide info
469 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
470 */
471 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
472
473 /*
474 * Will provide all the information of a selected connector.
475 * [output]: DRMConnectorInfo: Resource Info for the given connector id
476 */
477 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
478
479 /*
Ping Li281f48d2017-01-16 12:45:40 -0800480 * Will query post propcessing feature info of a CRTC.
481 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
482 */
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800483 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
Ping Li281f48d2017-01-16 12:45:40 -0800484 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700485 * Register a logical display to receive a token.
486 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
487 * On display connect(bootup or hotplug), clients should invoke this interface to
488 * establish the pipeline for the display and should get a DisplayToken
489 * populated with crtc and connnector(s) id's. Here onwards, Client should
490 * use this token to represent the display for any Perform operations if
491 * needed.
492 *
493 * [input]: disp_type - Peripheral / TV / Virtual
494 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
495 * [return]: 0 on success, a negative error value otherwise
496 */
497 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
498
499 /* Client should invoke this interface on display disconnect.
500 * [input]: DRMDisplayToken - identifier for the display.
501 */
502 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
503
504 /*
505 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
506 * returned as part of RegisterDisplay API. Needs to be called per display.
507 * [input]: DRMDisplayToken that identifies a display pipeline
508 * [output]: Pointer to an instance of DRMAtomicReqInterface.
509 * [return]: Error code if the API fails, 0 on success.
510 */
511 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
512
513 /*
514 * Destroys the instance of DRMAtomicReqInterface
515 * [input]: Pointer to a DRMAtomicReqInterface
516 * [return]: Error code if the API fails, 0 on success.
517 */
518 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
Saurabh Shah0ffee302016-11-22 10:42:11 -0800519 /*
520 * Sets the global scaler LUT
521 * [input]: LUT Info
522 * [return]: Error code if the API fails, 0 on success.
523 */
524 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700525};
Saurabh Shah0ffee302016-11-22 10:42:11 -0800526
Saurabh Shah66c941b2016-07-06 17:34:05 -0700527} // namespace sde_drm
528#endif // __DRM_INTERFACE_H__