1 /* 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 41 namespace sde_drm { 42 43 typedef std::map<std::pair<uint32_t, uint64_t>, float> CompRatioMap; 44 45 /* 46 * Drm Atomic Operation Codes 47 */ 48 enum 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 /* 98 * 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 /* 104 * 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 /* 122 * 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 /* 128 * 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 /* 147 * 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 /* 165 * 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 /* 172 * Op: Sets PP feature 173 * Arg: uint32_t - CRTC ID 174 * DRMPPFeatureInfo * - PP feature data pointer 175 */ 176 CRTC_SET_POST_PROC, 177 /* 178 * 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 /* 185 * 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, 203 /* 204 * Op: Sets power mode for connector. 205 * Arg: uint32_t - Connector ID 206 * uint32_t - Power Mode 207 */ 208 CONNECTOR_SET_POWER_MODE, 209 /* 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, 216 }; 217 218 enum struct DRMRotation { 219 FLIP_H = 0x1, 220 FLIP_V = 0x2, 221 ROT_180 = FLIP_H | FLIP_V, 222 ROT_90 = 0x4, 223 }; 224 225 enum struct DRMPowerMode { 226 ON, 227 DOZE, 228 DOZE_SUSPEND, 229 OFF, 230 }; 231 232 enum struct DRMBlendType { 233 UNDEFINED = 0, 234 OPAQUE = 1, 235 PREMULTIPLIED = 2, 236 COVERAGE = 3, 237 }; 238 239 enum struct DRMSrcConfig { 240 DEINTERLACE = 0, 241 }; 242 243 /* Display type to identify a suitable connector */ 244 enum struct DRMDisplayType { 245 PERIPHERAL, 246 TV, 247 VIRTUAL, 248 }; 249 250 struct 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 261 enum struct QSEEDVersion { 262 V1, 263 V2, 264 V3, 265 }; 266 267 enum struct SmartDMARevision { 268 V1, 269 V2, 270 }; 271 272 /* Per CRTC Resource Info*/ 273 struct DRMCrtcInfo { 274 bool has_src_split; 275 uint32_t max_blend_stages; 276 QSEEDVersion qseed_version; 277 SmartDMARevision smart_dma_rev; 278 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; 293 }; 294 295 enum 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 307 struct DRMPlaneTypeInfo { 308 DRMPlaneType type; 309 uint32_t master_plane_id; 310 // 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; 317 uint64_t max_pipe_bandwidth; 318 }; 319 320 // All DRM Planes as map<Plane_id , plane_type_info> listed from highest to lowest priority 321 typedef std::vector<std::pair<uint32_t, DRMPlaneTypeInfo>> DRMPlanesInfo; 322 323 enum struct DRMTopology { 324 UNKNOWN, // To be compat with driver defs in sde_kms.h 325 SINGLE_LM, 326 DUAL_LM, 327 PPSPLIT, 328 DUAL_LM_MERGE, 329 }; 330 331 enum struct DRMPanelMode { 332 VIDEO, 333 COMMAND, 334 }; 335 336 /* Per Connector Info*/ 337 struct DRMConnectorInfo { 338 uint32_t mmWidth; 339 uint32_t mmHeight; 340 uint32_t type; 341 uint32_t num_modes; 342 drmModeModeInfo *modes; 343 DRMTopology topology; 344 std::string panel_name; 345 DRMPanelMode panel_mode; 346 bool is_primary; 347 // Valid only if DRMPanelMode is VIDEO 348 bool dynamic_fps; 349 // FourCC format enum and modifier 350 std::vector<std::pair<uint32_t, uint64_t>> formats_supported; 351 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL 352 uint32_t max_linewidth; 353 // Valid only if mode is command 354 int num_roi; 355 int xstart; 356 int ystart; 357 int walign; 358 int halign; 359 int wmin; 360 int hmin; 361 bool roi_merge; 362 DRMRotation panel_orientation; 363 }; 364 365 /* Identifier token for a display */ 366 struct DRMDisplayToken { 367 uint32_t conn_id; 368 uint32_t crtc_id; 369 }; 370 371 enum DRMPPFeatureID { 372 kFeaturePcc, 373 kFeatureIgc, 374 kFeaturePgc, 375 kFeatureMixerGc, 376 kFeaturePaV2, 377 kFeatureDither, 378 kFeatureGamut, 379 kFeaturePADither, 380 kPPFeaturesMax, 381 }; 382 383 enum DRMPPPropType { 384 kPropEnum, 385 kPropRange, 386 kPropBlob, 387 kPropTypeMax, 388 }; 389 390 struct DRMPPFeatureInfo { 391 DRMPPFeatureID id; 392 DRMPPPropType type; 393 uint32_t version; 394 uint32_t payload_size; 395 void *payload; 396 }; 397 398 struct DRMScalerLUTInfo { 399 uint32_t dir_lut_size = 0; 400 uint32_t cir_lut_size = 0; 401 uint32_t sep_lut_size = 0; 402 uint64_t dir_lut = 0; 403 uint64_t cir_lut = 0; 404 uint64_t sep_lut = 0; 405 }; 406 407 /* DRM Atomic Request Property Set. 408 * 409 * Helper class to create and populate atomic properties of DRM components 410 * when rendered in DRM atomic mode */ 411 class DRMAtomicReqInterface { 412 public: 413 virtual ~DRMAtomicReqInterface() {} 414 /* Perform request operation. 415 * 416 * [input]: opcode: operation code from DRMOps list. 417 * var_arg: arguments for DRMOps's can differ in number and 418 * data type. Refer above DRMOps to details. 419 * [return]: Error code if the API fails, 0 on success. 420 */ 421 virtual int Perform(DRMOps opcode, ...) = 0; 422 423 /* 424 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be 425 * called every frame. 426 * [input]: synchronous: Determines if the call should block until a h/w flip 427 * [return]: Error code if the API fails, 0 on success. 428 */ 429 virtual int Commit(bool synchronous) = 0; 430 /* 431 * Validate the params set via Perform(). 432 * [return]: Error code if the API fails, 0 on success. 433 */ 434 virtual int Validate() = 0; 435 }; 436 437 class DRMManagerInterface; 438 439 /* Populates a singleton instance of DRMManager */ 440 typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf); 441 442 /* Destroy DRMManager instance */ 443 typedef int (*DestroyDRMManager)(); 444 445 /* 446 * DRM Manager Interface - Any class which plans to implement helper function for vendor 447 * specific DRM driver implementation must implement the below interface routines to work 448 * with SDM. 449 */ 450 451 class DRMManagerInterface { 452 public: 453 virtual ~DRMManagerInterface() {} 454 455 /* 456 * Since SDM completely manages the planes. GetPlanesInfo will provide all 457 * the plane information. 458 * [output]: DRMPlanesInfo: Resource Info for planes. 459 */ 460 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0; 461 462 /* 463 * Will provide all the information of a selected crtc. 464 * [input]: Use crtc id 0 to obtain system wide info 465 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id. 466 */ 467 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0; 468 469 /* 470 * Will provide all the information of a selected connector. 471 * [output]: DRMConnectorInfo: Resource Info for the given connector id 472 */ 473 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0; 474 475 /* 476 * Will query post propcessing feature info of a CRTC. 477 * [output]: DRMPPFeatureInfo: CRTC post processing feature info 478 */ 479 virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &info) = 0; 480 /* 481 * Register a logical display to receive a token. 482 * Each display pipeline in DRM is identified by its CRTC and Connector(s). 483 * On display connect(bootup or hotplug), clients should invoke this interface to 484 * establish the pipeline for the display and should get a DisplayToken 485 * populated with crtc and connnector(s) id's. Here onwards, Client should 486 * use this token to represent the display for any Perform operations if 487 * needed. 488 * 489 * [input]: disp_type - Peripheral / TV / Virtual 490 * [output]: DRMDisplayToken - CRTC and Connector id's for the display 491 * [return]: 0 on success, a negative error value otherwise 492 */ 493 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0; 494 495 /* Client should invoke this interface on display disconnect. 496 * [input]: DRMDisplayToken - identifier for the display. 497 */ 498 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0; 499 500 /* 501 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token 502 * returned as part of RegisterDisplay API. Needs to be called per display. 503 * [input]: DRMDisplayToken that identifies a display pipeline 504 * [output]: Pointer to an instance of DRMAtomicReqInterface. 505 * [return]: Error code if the API fails, 0 on success. 506 */ 507 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0; 508 509 /* 510 * Destroys the instance of DRMAtomicReqInterface 511 * [input]: Pointer to a DRMAtomicReqInterface 512 * [return]: Error code if the API fails, 0 on success. 513 */ 514 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0; 515 /* 516 * Sets the global scaler LUT 517 * [input]: LUT Info 518 * [return]: Error code if the API fails, 0 on success. 519 */ 520 virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0; 521 }; 522 523 } // namespace sde_drm 524 #endif // __DRM_INTERFACE_H__ 525