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 * Drm Atomic Operation Codes 44 */ 45 enum 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 /* 95 * Op: Sets frame buffer ID for plane. Set together with CRTC. 96 * Arg: uint32_t - Plane ID 97 * uint32_t - Framebuffer ID 98 */ 99 PLANE_SET_FB_ID, 100 /* 101 * Op: Sets the crtc for this plane. Set together with FB_ID. 102 * Arg: uint32_t - Plane ID 103 * uint32_t - CRTC ID 104 */ 105 PLANE_SET_CRTC, 106 /* 107 * Op: Sets acquire fence for this plane's buffer. Set together with FB_ID, CRTC. 108 * Arg: uint32_t - Plane ID 109 * uint32_t - Input fence 110 */ 111 PLANE_SET_INPUT_FENCE, 112 /* 113 * Op: Activate or deactivate a CRTC 114 * Arg: uint32_t - CRTC ID 115 * uint32_t - 1 to enable, 0 to disable 116 */ 117 CRTC_SET_ACTIVE, 118 /* 119 * Op: Sets display mode 120 * Arg: uint32_t - CRTC ID 121 * drmModeModeInfo* - Pointer to display mode 122 */ 123 CRTC_SET_MODE, 124 /* 125 * Op: Sets an offset indicating when a release fence should be signalled. 126 * Arg: uint32_t - offset 127 * 0: non-speculative, default 128 * 1: speculative 129 */ 130 CRTC_SET_OUTPUT_FENCE_OFFSET, 131 /* 132 * Op: Returns release fence for this frame. Should be called after Commit() on 133 * DRMAtomicReqInterface. 134 * Arg: uint32_t - CRTC ID 135 * int * - Pointer to an integer that will hold the returned fence 136 */ 137 CRTC_GET_RELEASE_FENCE, 138 /* 139 * Op: Returns retire fence for this commit. Should be called after Commit() on 140 * DRMAtomicReqInterface. 141 * Arg: uint32_t - Connector ID 142 * int * - Pointer to an integer that will hold the returned fence 143 */ 144 CONNECTOR_GET_RETIRE_FENCE, 145 /* 146 * Op: Sets writeback connector destination rect 147 * Arg: uint32_t - Connector ID 148 * DRMRect - Dst Rectangle 149 */ 150 CONNECTOR_SET_OUTPUT_RECT, 151 /* 152 * Op: Sets frame buffer ID for writeback connector. 153 * Arg: uint32_t - Connector ID 154 * uint32_t - Framebuffer ID 155 */ 156 CONNECTOR_SET_OUTPUT_FB_ID, 157 }; 158 159 enum struct DRMBlendType { 160 UNDEFINED = 0, 161 OPAQUE = 1, 162 PREMULTIPLIED = 2, 163 COVERAGE = 3, 164 }; 165 166 /* Display type to identify a suitable connector */ 167 enum struct DRMDisplayType { 168 PERIPHERAL, 169 TV, 170 VIRTUAL, 171 }; 172 173 struct DRMRect { 174 uint32_t left; // Left-most pixel coordinate. 175 uint32_t top; // Top-most pixel coordinate. 176 uint32_t right; // Right-most pixel coordinate. 177 uint32_t bottom; // Bottom-most pixel coordinate. 178 }; 179 180 //------------------------------------------------------------------------ 181 // DRM Info Query Types 182 //------------------------------------------------------------------------ 183 184 enum struct QSEEDVersion { 185 V1, 186 V2, 187 V3, 188 }; 189 190 /* Per CRTC Resource Info*/ 191 struct DRMCrtcInfo { 192 bool has_src_split; 193 uint32_t max_blend_stages; 194 QSEEDVersion qseed_version; 195 }; 196 197 enum struct DRMPlaneType { 198 // Has CSC and scaling capability 199 VIG = 0, 200 // Has scaling capability but no CSC 201 RGB, 202 // No scaling support 203 DMA, 204 // Supports a small dimension and doesn't use a CRTC stage 205 CURSOR, 206 MAX, 207 }; 208 209 struct DRMPlaneTypeInfo { 210 // FourCC format enum and modifier 211 std::vector<std::pair<uint32_t, uint64_t>> formats_supported; 212 uint32_t max_linewidth; 213 uint32_t max_upscale; 214 uint32_t max_downscale; 215 uint32_t max_horizontal_deci; 216 uint32_t max_vertical_deci; 217 }; 218 219 /* All DRM Planes Info*/ 220 struct DRMPlanesInfo { 221 // Plane id and plane type sorted by highest to lowest priority 222 std::vector<std::pair<uint32_t, DRMPlaneType>> planes; 223 // Plane type and type info 224 std::map<DRMPlaneType, DRMPlaneTypeInfo> types; 225 }; 226 227 enum struct DRMTopology { 228 UNKNOWN, // To be compat with driver defs in sde_kms.h 229 SINGLE_LM, 230 DUAL_LM, 231 PPSPLIT, 232 DUAL_LM_MERGE, 233 }; 234 235 enum struct DRMPanelMode { 236 VIDEO, 237 COMMAND, 238 }; 239 240 /* Per Connector Info*/ 241 struct DRMConnectorInfo { 242 uint32_t mmWidth; 243 uint32_t mmHeight; 244 uint32_t type; 245 uint32_t num_modes; 246 drmModeModeInfo *modes; 247 DRMTopology topology; 248 std::string panel_name; 249 DRMPanelMode panel_mode; 250 bool is_primary; 251 // Valid only if DRMPanelMode is VIDEO 252 bool dynamic_fps; 253 // FourCC format enum and modifier 254 std::vector<std::pair<uint32_t, uint64_t>> formats_supported; 255 // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL 256 uint32_t max_linewidth; 257 }; 258 259 /* Identifier token for a display */ 260 struct DRMDisplayToken { 261 uint32_t conn_id; 262 uint32_t crtc_id; 263 }; 264 265 /* DRM Atomic Request Property Set. 266 * 267 * Helper class to create and populate atomic properties of DRM components 268 * when rendered in DRM atomic mode */ 269 class DRMAtomicReqInterface { 270 public: 271 virtual ~DRMAtomicReqInterface() {} 272 /* Perform request operation. 273 * 274 * [input]: opcode: operation code from DRMOps list. 275 * var_arg: arguments for DRMOps's can differ in number and 276 * data type. Refer above DRMOps to details. 277 * [return]: Error code if the API fails, 0 on success. 278 */ 279 virtual int Perform(DRMOps opcode, ...) = 0; 280 281 /* 282 * Commit the params set via Perform(). Also resets the properties after commit. Needs to be 283 * called every frame. 284 * [input]: synchronous: Determines if the call should block until a h/w flip 285 * [return]: Error code if the API fails, 0 on success. 286 */ 287 virtual int Commit(bool synchronous) = 0; 288 /* 289 * Validate the params set via Perform(). 290 * [return]: Error code if the API fails, 0 on success. 291 */ 292 virtual int Validate() = 0; 293 }; 294 295 class DRMManagerInterface; 296 297 /* Populates a singleton instance of DRMManager */ 298 typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf); 299 300 /* Destroy DRMManager instance */ 301 typedef int (*DestroyDRMManager)(); 302 303 /* 304 * DRM Manager Interface - Any class which plans to implement helper function for vendor 305 * specific DRM driver implementation must implement the below interface routines to work 306 * with SDM. 307 */ 308 309 class DRMManagerInterface { 310 public: 311 virtual ~DRMManagerInterface() {} 312 313 /* 314 * Since SDM completely manages the planes. GetPlanesInfo will provide all 315 * the plane information. 316 * [output]: DRMPlanesInfo: Resource Info for planes. 317 */ 318 virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0; 319 320 /* 321 * Will provide all the information of a selected crtc. 322 * [input]: Use crtc id 0 to obtain system wide info 323 * [output]: DRMCrtcInfo: Resource Info for the given CRTC id. 324 */ 325 virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0; 326 327 /* 328 * Will provide all the information of a selected connector. 329 * [output]: DRMConnectorInfo: Resource Info for the given connector id 330 */ 331 virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0; 332 333 /* 334 * Register a logical display to receive a token. 335 * Each display pipeline in DRM is identified by its CRTC and Connector(s). 336 * On display connect(bootup or hotplug), clients should invoke this interface to 337 * establish the pipeline for the display and should get a DisplayToken 338 * populated with crtc and connnector(s) id's. Here onwards, Client should 339 * use this token to represent the display for any Perform operations if 340 * needed. 341 * 342 * [input]: disp_type - Peripheral / TV / Virtual 343 * [output]: DRMDisplayToken - CRTC and Connector id's for the display 344 * [return]: 0 on success, a negative error value otherwise 345 */ 346 virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0; 347 348 /* Client should invoke this interface on display disconnect. 349 * [input]: DRMDisplayToken - identifier for the display. 350 */ 351 virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0; 352 353 /* 354 * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token 355 * returned as part of RegisterDisplay API. Needs to be called per display. 356 * [input]: DRMDisplayToken that identifies a display pipeline 357 * [output]: Pointer to an instance of DRMAtomicReqInterface. 358 * [return]: Error code if the API fails, 0 on success. 359 */ 360 virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0; 361 362 /* 363 * Destroys the instance of DRMAtomicReqInterface 364 * [input]: Pointer to a DRMAtomicReqInterface 365 * [return]: Error code if the API fails, 0 on success. 366 */ 367 virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0; 368 }; 369 } // namespace sde_drm 370 #endif // __DRM_INTERFACE_H__ 371