blob: 6e3b0053c87998f3b6b7f1b9515e60d4e1cd5e1e [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 /*
Rohit Kulkarni8622e362017-01-30 18:14:10 -0800128 * Op: Sets plane rotation destination rect
129 * Arg: uint32_t - Plane ID
130 * DRMRect - rotator dst Rectangle
131 */
132 PLANE_SET_ROTATION_DST_RECT,
133 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700134 * Op: Activate or deactivate a CRTC
135 * Arg: uint32_t - CRTC ID
136 * uint32_t - 1 to enable, 0 to disable
137 */
138 CRTC_SET_ACTIVE,
139 /*
140 * Op: Sets display mode
141 * Arg: uint32_t - CRTC ID
142 * drmModeModeInfo* - Pointer to display mode
143 */
144 CRTC_SET_MODE,
145 /*
146 * Op: Sets an offset indicating when a release fence should be signalled.
147 * Arg: uint32_t - offset
148 * 0: non-speculative, default
149 * 1: speculative
150 */
151 CRTC_SET_OUTPUT_FENCE_OFFSET,
152 /*
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800153 * Op: Sets overall SDE core clock
154 * Arg: uint32_t - CRTC ID
155 * uint32_t - core_clk
156 */
157 CRTC_SET_CORE_CLK,
158 /*
159 * Op: Sets overall SDE core average bandwidth
160 * Arg: uint32_t - CRTC ID
161 * uint32_t - core_ab
162 */
163 CRTC_SET_CORE_AB,
164 /*
165 * Op: Sets overall SDE core instantaneous bandwidth
166 * Arg: uint32_t - CRTC ID
167 * uint32_t - core_ib
168 */
169 CRTC_SET_CORE_IB,
170 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700171 * Op: Returns release fence for this frame. Should be called after Commit() on
172 * DRMAtomicReqInterface.
173 * Arg: uint32_t - CRTC ID
174 * int * - Pointer to an integer that will hold the returned fence
175 */
176 CRTC_GET_RELEASE_FENCE,
177 /*
Ping Li281f48d2017-01-16 12:45:40 -0800178 * Op: Sets PP feature
179 * Arg: uint32_t - CRTC ID
180 * DRMPPFeatureInfo * - PP feature data pointer
181 */
182 CRTC_SET_POST_PROC,
183 /*
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800184 * Op: Sets CRTC ROIs.
185 * Arg: uint32_t - CRTC ID
186 * uint32_t - number of ROIs
187 * DRMRect * - Array of CRTC ROIs
188 */
189 CRTC_SET_ROI,
190 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700191 * Op: Returns retire fence for this commit. Should be called after Commit() on
192 * DRMAtomicReqInterface.
193 * Arg: uint32_t - Connector ID
194 * int * - Pointer to an integer that will hold the returned fence
195 */
196 CONNECTOR_GET_RETIRE_FENCE,
197 /*
198 * Op: Sets writeback connector destination rect
199 * Arg: uint32_t - Connector ID
200 * DRMRect - Dst Rectangle
201 */
202 CONNECTOR_SET_OUTPUT_RECT,
203 /*
204 * Op: Sets frame buffer ID for writeback connector.
205 * Arg: uint32_t - Connector ID
206 * uint32_t - Framebuffer ID
207 */
208 CONNECTOR_SET_OUTPUT_FB_ID,
Sushil Chauhan3396e202017-04-14 18:34:22 -0700209 /*
210 * Op: Sets power mode for connector.
211 * Arg: uint32_t - Connector ID
212 * uint32_t - Power Mode
213 */
214 CONNECTOR_SET_POWER_MODE,
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800215 /*
216 * Op: Sets panel ROIs.
217 * Arg: uint32_t - Connector ID
218 * uint32_t - number of ROIs
219 * DRMRect * - Array of Connector ROIs
220 */
221 CONNECTOR_SET_ROI,
Saurabh Shah66c941b2016-07-06 17:34:05 -0700222};
223
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700224enum struct DRMRotation {
225 FLIP_H = 0x1,
226 FLIP_V = 0x2,
Prabhanjan Kandula5bc7f8b2017-05-23 12:24:57 -0700227 ROT_180 = FLIP_H | FLIP_V,
Saurabh Shahf9266ee2017-04-19 15:25:46 -0700228 ROT_90 = 0x4,
229};
230
Sushil Chauhan3396e202017-04-14 18:34:22 -0700231enum struct DRMPowerMode {
232 ON,
233 DOZE,
234 DOZE_SUSPEND,
235 OFF,
236};
237
Saurabh Shah66c941b2016-07-06 17:34:05 -0700238enum struct DRMBlendType {
239 UNDEFINED = 0,
240 OPAQUE = 1,
241 PREMULTIPLIED = 2,
242 COVERAGE = 3,
243};
244
Prabhanjan Kandula585aa652017-01-26 18:39:11 -0800245enum struct DRMSrcConfig {
246 DEINTERLACE = 0,
247};
248
Saurabh Shah66c941b2016-07-06 17:34:05 -0700249/* Display type to identify a suitable connector */
250enum struct DRMDisplayType {
251 PERIPHERAL,
252 TV,
253 VIRTUAL,
254};
255
256struct DRMRect {
257 uint32_t left; // Left-most pixel coordinate.
258 uint32_t top; // Top-most pixel coordinate.
259 uint32_t right; // Right-most pixel coordinate.
260 uint32_t bottom; // Bottom-most pixel coordinate.
261};
262
263//------------------------------------------------------------------------
264// DRM Info Query Types
265//------------------------------------------------------------------------
266
267enum struct QSEEDVersion {
268 V1,
269 V2,
270 V3,
271};
272
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700273enum struct SmartDMARevision {
274 V1,
275 V2,
276};
277
Saurabh Shah66c941b2016-07-06 17:34:05 -0700278/* Per CRTC Resource Info*/
279struct DRMCrtcInfo {
280 bool has_src_split;
281 uint32_t max_blend_stages;
282 QSEEDVersion qseed_version;
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700283 SmartDMARevision smart_dma_rev;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800284 float ib_fudge_factor;
285 float clk_fudge_factor;
286 uint32_t dest_scale_prefill_lines;
287 uint32_t undersized_prefill_lines;
288 uint32_t macrotile_prefill_lines;
289 uint32_t nv12_prefill_lines;
290 uint32_t linear_prefill_lines;
291 uint32_t downscale_prefill_lines;
292 uint32_t extra_prefill_lines;
293 uint32_t amortized_threshold;
294 uint64_t max_bandwidth_low;
295 uint64_t max_bandwidth_high;
296 uint32_t max_sde_clk;
297 CompRatioMap comp_ratio_rt_map;
298 CompRatioMap comp_ratio_nrt_map;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700299};
300
301enum struct DRMPlaneType {
302 // Has CSC and scaling capability
303 VIG = 0,
304 // Has scaling capability but no CSC
305 RGB,
306 // No scaling support
307 DMA,
308 // Supports a small dimension and doesn't use a CRTC stage
309 CURSOR,
310 MAX,
311};
312
313struct DRMPlaneTypeInfo {
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700314 DRMPlaneType type;
315 uint32_t master_plane_id;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700316 // FourCC format enum and modifier
317 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
318 uint32_t max_linewidth;
319 uint32_t max_upscale;
320 uint32_t max_downscale;
321 uint32_t max_horizontal_deci;
322 uint32_t max_vertical_deci;
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800323 uint64_t max_pipe_bandwidth;
Rohit Kulkarni8622e362017-01-30 18:14:10 -0800324 uint32_t cache_size; // cache size in bytes for inline rotation support.
Saurabh Shah66c941b2016-07-06 17:34:05 -0700325};
326
Prabhanjan Kandulae6dfab92017-03-14 11:02:49 -0700327// All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority
328typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700329
330enum struct DRMTopology {
331 UNKNOWN, // To be compat with driver defs in sde_kms.h
332 SINGLE_LM,
333 DUAL_LM,
334 PPSPLIT,
335 DUAL_LM_MERGE,
336};
337
338enum struct DRMPanelMode {
339 VIDEO,
340 COMMAND,
341};
342
343/* Per Connector Info*/
344struct DRMConnectorInfo {
345 uint32_t mmWidth;
346 uint32_t mmHeight;
347 uint32_t type;
348 uint32_t num_modes;
349 drmModeModeInfo *modes;
350 DRMTopology topology;
351 std::string panel_name;
352 DRMPanelMode panel_mode;
353 bool is_primary;
354 // Valid only if DRMPanelMode is VIDEO
355 bool dynamic_fps;
356 // FourCC format enum and modifier
357 std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
358 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
359 uint32_t max_linewidth;
Saurabh Shahe9f55d72017-03-03 15:14:13 -0800360 // Valid only if mode is command
361 int num_roi;
362 int xstart;
363 int ystart;
364 int walign;
365 int halign;
366 int wmin;
367 int hmin;
368 bool roi_merge;
Prabhanjan Kandula5bc7f8b2017-05-23 12:24:57 -0700369 DRMRotation panel_orientation;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700370};
371
372/* Identifier token for a display */
373struct DRMDisplayToken {
374 uint32_t conn_id;
375 uint32_t crtc_id;
376};
377
Ping Li281f48d2017-01-16 12:45:40 -0800378enum DRMPPFeatureID {
379 kFeaturePcc,
380 kFeatureIgc,
381 kFeaturePgc,
382 kFeatureMixerGc,
383 kFeaturePaV2,
384 kFeatureDither,
385 kFeatureGamut,
386 kFeaturePADither,
387 kPPFeaturesMax,
388};
389
390enum DRMPPPropType {
391 kPropEnum,
392 kPropRange,
393 kPropBlob,
394 kPropTypeMax,
395};
396
397struct DRMPPFeatureInfo {
398 DRMPPFeatureID id;
399 DRMPPPropType type;
400 uint32_t version;
401 uint32_t payload_size;
402 void *payload;
403};
404
Saurabh Shah0ffee302016-11-22 10:42:11 -0800405struct DRMScalerLUTInfo {
406 uint32_t dir_lut_size = 0;
407 uint32_t cir_lut_size = 0;
408 uint32_t sep_lut_size = 0;
409 uint64_t dir_lut = 0;
410 uint64_t cir_lut = 0;
411 uint64_t sep_lut = 0;
412};
413
Saurabh Shah66c941b2016-07-06 17:34:05 -0700414/* DRM Atomic Request Property Set.
415 *
416 * Helper class to create and populate atomic properties of DRM components
417 * when rendered in DRM atomic mode */
418class DRMAtomicReqInterface {
419 public:
420 virtual ~DRMAtomicReqInterface() {}
421 /* Perform request operation.
422 *
423 * [input]: opcode: operation code from DRMOps list.
424 * var_arg: arguments for DRMOps's can differ in number and
425 * data type. Refer above DRMOps to details.
426 * [return]: Error code if the API fails, 0 on success.
427 */
428 virtual int Perform(DRMOps opcode, ...) = 0;
429
430 /*
431 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
432 * called every frame.
433 * [input]: synchronous: Determines if the call should block until a h/w flip
434 * [return]: Error code if the API fails, 0 on success.
435 */
436 virtual int Commit(bool synchronous) = 0;
437 /*
438 * Validate the params set via Perform().
439 * [return]: Error code if the API fails, 0 on success.
440 */
441 virtual int Validate() = 0;
442};
443
444class DRMManagerInterface;
445
446/* Populates a singleton instance of DRMManager */
447typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
448
449/* Destroy DRMManager instance */
Saurabh Shahab7807c2017-02-08 15:41:08 -0800450typedef int (*DestroyDRMManager)();
Saurabh Shah66c941b2016-07-06 17:34:05 -0700451
452/*
453 * DRM Manager Interface - Any class which plans to implement helper function for vendor
454 * specific DRM driver implementation must implement the below interface routines to work
455 * with SDM.
456 */
457
458class DRMManagerInterface {
459 public:
460 virtual ~DRMManagerInterface() {}
461
462 /*
463 * Since SDM completely manages the planes. GetPlanesInfo will provide all
464 * the plane information.
465 * [output]: DRMPlanesInfo: Resource Info for planes.
466 */
467 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
468
469 /*
470 * Will provide all the information of a selected crtc.
471 * [input]: Use crtc id 0 to obtain system wide info
472 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
473 */
474 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
475
476 /*
477 * Will provide all the information of a selected connector.
478 * [output]: DRMConnectorInfo: Resource Info for the given connector id
479 */
480 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
481
482 /*
Ping Li281f48d2017-01-16 12:45:40 -0800483 * Will query post propcessing feature info of a CRTC.
484 * [output]: DRMPPFeatureInfo: CRTC post processing feature info
485 */
Ramkumar Radhakrishnan9ed1fd82017-03-09 18:46:41 -0800486 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0;
Ping Li281f48d2017-01-16 12:45:40 -0800487 /*
Saurabh Shah66c941b2016-07-06 17:34:05 -0700488 * Register a logical display to receive a token.
489 * Each display pipeline in DRM is identified by its CRTC and Connector(s).
490 * On display connect(bootup or hotplug), clients should invoke this interface to
491 * establish the pipeline for the display and should get a DisplayToken
492 * populated with crtc and connnector(s) id's. Here onwards, Client should
493 * use this token to represent the display for any Perform operations if
494 * needed.
495 *
496 * [input]: disp_type - Peripheral / TV / Virtual
497 * [output]: DRMDisplayToken - CRTC and Connector id's for the display
498 * [return]: 0 on success, a negative error value otherwise
499 */
500 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
501
502 /* Client should invoke this interface on display disconnect.
503 * [input]: DRMDisplayToken - identifier for the display.
504 */
505 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
506
507 /*
508 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
509 * returned as part of RegisterDisplay API. Needs to be called per display.
510 * [input]: DRMDisplayToken that identifies a display pipeline
511 * [output]: Pointer to an instance of DRMAtomicReqInterface.
512 * [return]: Error code if the API fails, 0 on success.
513 */
514 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
515
516 /*
517 * Destroys the instance of DRMAtomicReqInterface
518 * [input]: Pointer to a DRMAtomicReqInterface
519 * [return]: Error code if the API fails, 0 on success.
520 */
521 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
Saurabh Shah0ffee302016-11-22 10:42:11 -0800522 /*
523 * Sets the global scaler LUT
524 * [input]: LUT Info
525 * [return]: Error code if the API fails, 0 on success.
526 */
527 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0;
Saurabh Shah66c941b2016-07-06 17:34:05 -0700528};
Saurabh Shah0ffee302016-11-22 10:42:11 -0800529
Saurabh Shah66c941b2016-07-06 17:34:05 -0700530} // namespace sde_drm
531#endif // __DRM_INTERFACE_H__