drmmode_display.h (9968B)
1 /* 2 * Copyright © 2007 Red Hat, Inc. 3 * Copyright © 2019 NVIDIA CORPORATION 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 * Authors: 25 * Dave Airlie <airlied@redhat.com> 26 * Aaron Plattner <aplattner@nvidia.com> 27 * 28 */ 29 #ifndef DRMMODE_DISPLAY_H 30 #define DRMMODE_DISPLAY_H 31 32 #include "xf86drmMode.h" 33 #ifdef CONFIG_UDEV_KMS 34 #include "libudev.h" 35 #endif 36 37 #include "dumb_bo.h" 38 39 struct gbm_device; 40 41 enum drmmode_plane_property { 42 DRMMODE_PLANE_TYPE = 0, 43 DRMMODE_PLANE_FB_ID, 44 DRMMODE_PLANE_IN_FORMATS, 45 DRMMODE_PLANE_CRTC_ID, 46 DRMMODE_PLANE_SRC_X, 47 DRMMODE_PLANE_SRC_Y, 48 DRMMODE_PLANE_SRC_W, 49 DRMMODE_PLANE_SRC_H, 50 DRMMODE_PLANE_CRTC_X, 51 DRMMODE_PLANE_CRTC_Y, 52 DRMMODE_PLANE_CRTC_W, 53 DRMMODE_PLANE_CRTC_H, 54 DRMMODE_PLANE__COUNT 55 }; 56 57 enum drmmode_plane_type { 58 DRMMODE_PLANE_TYPE_PRIMARY = 0, 59 DRMMODE_PLANE_TYPE_CURSOR, 60 DRMMODE_PLANE_TYPE_OVERLAY, 61 DRMMODE_PLANE_TYPE__COUNT 62 }; 63 64 enum drmmode_connector_property { 65 DRMMODE_CONNECTOR_CRTC_ID, 66 DRMMODE_CONNECTOR__COUNT 67 }; 68 69 enum drmmode_crtc_property { 70 DRMMODE_CRTC_ACTIVE, 71 DRMMODE_CRTC_MODE_ID, 72 DRMMODE_CRTC_GAMMA_LUT, 73 DRMMODE_CRTC_GAMMA_LUT_SIZE, 74 DRMMODE_CRTC_CTM, 75 DRMMODE_CRTC__COUNT 76 }; 77 78 typedef struct { 79 uint32_t width; 80 uint32_t height; 81 struct dumb_bo *dumb; 82 #ifdef GLAMOR_HAS_GBM 83 Bool used_modifiers; 84 struct gbm_bo *gbm; 85 #endif 86 } drmmode_bo; 87 88 typedef struct { 89 int fd; 90 unsigned fb_id; 91 drmModeFBPtr mode_fb; 92 int cpp; 93 int kbpp; 94 ScrnInfoPtr scrn; 95 96 struct gbm_device *gbm; 97 98 #ifdef CONFIG_UDEV_KMS 99 struct udev_monitor *uevent_monitor; 100 InputHandlerProc uevent_handler; 101 #endif 102 drmEventContext event_context; 103 drmmode_bo front_bo; 104 Bool sw_cursor; 105 106 /* Broken-out options. */ 107 OptionInfoPtr Options; 108 109 Bool glamor; 110 Bool shadow_enable; 111 Bool shadow_enable2; 112 /** Is Option "PageFlip" enabled? */ 113 Bool pageflip; 114 Bool force_24_32; 115 void *shadow_fb; 116 void *shadow_fb2; 117 118 DevPrivateKeyRec pixmapPrivateKeyRec; 119 DevScreenPrivateKeyRec spritePrivateKeyRec; 120 DevPrivateKeyRec vrrPrivateKeyRec; 121 /* Number of SW cursors currently visible on this screen */ 122 int sprites_visible; 123 124 Bool reverse_prime_offload_mode; 125 126 Bool is_secondary; 127 128 PixmapPtr fbcon_pixmap; 129 130 Bool dri2_flipping; 131 Bool present_flipping; 132 Bool flip_bo_import_failed; 133 134 Bool can_async_flip; 135 Bool async_flip_secondaries; 136 Bool dri2_enable; 137 Bool present_enable; 138 139 uint32_t vrr_prop_id; 140 Bool use_ctm; 141 } drmmode_rec, *drmmode_ptr; 142 143 typedef struct { 144 const char *name; 145 Bool valid; 146 uint64_t value; 147 } drmmode_prop_enum_info_rec, *drmmode_prop_enum_info_ptr; 148 149 typedef struct { 150 const char *name; 151 uint32_t prop_id; 152 uint64_t value; 153 unsigned int num_enum_values; 154 drmmode_prop_enum_info_rec *enum_values; 155 } drmmode_prop_info_rec, *drmmode_prop_info_ptr; 156 157 typedef struct { 158 drmModeModeInfo mode_info; 159 uint32_t blob_id; 160 struct xorg_list entry; 161 } drmmode_mode_rec, *drmmode_mode_ptr; 162 163 typedef struct { 164 uint32_t format; 165 uint32_t num_modifiers; 166 uint64_t *modifiers; 167 } drmmode_format_rec, *drmmode_format_ptr; 168 169 typedef struct { 170 drmmode_ptr drmmode; 171 drmModeCrtcPtr mode_crtc; 172 uint32_t vblank_pipe; 173 int dpms_mode; 174 struct dumb_bo *cursor_bo; 175 Bool cursor_up; 176 uint16_t lut_r[256], lut_g[256], lut_b[256]; 177 178 drmmode_prop_info_rec props[DRMMODE_CRTC__COUNT]; 179 drmmode_prop_info_rec props_plane[DRMMODE_PLANE__COUNT]; 180 uint32_t plane_id; 181 drmmode_mode_ptr current_mode; 182 uint32_t num_formats; 183 drmmode_format_rec *formats; 184 185 drmmode_bo rotate_bo; 186 unsigned rotate_fb_id; 187 188 PixmapPtr prime_pixmap; 189 PixmapPtr prime_pixmap_back; 190 unsigned prime_pixmap_x; 191 192 /** 193 * @{ MSC (vblank count) handling for the PRESENT extension. 194 * 195 * The kernel's vblank counters are 32 bits and apparently full of 196 * lies, and we need to give a reliable 64-bit msc for GL, so we 197 * have to track and convert to a userland-tracked 64-bit msc. 198 */ 199 uint32_t msc_prev; 200 uint64_t msc_high; 201 /** @} */ 202 203 Bool need_modeset; 204 struct xorg_list mode_list; 205 206 Bool enable_flipping; 207 Bool flipping_active; 208 209 Bool vrr_enabled; 210 Bool use_gamma_lut; 211 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; 212 213 typedef struct { 214 drmModePropertyPtr mode_prop; 215 uint64_t value; 216 int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ 217 Atom *atoms; 218 } drmmode_prop_rec, *drmmode_prop_ptr; 219 220 typedef struct { 221 drmmode_ptr drmmode; 222 int output_id; 223 drmModeConnectorPtr mode_output; 224 drmModeEncoderPtr *mode_encoders; 225 drmModePropertyBlobPtr edid_blob; 226 drmModePropertyBlobPtr tile_blob; 227 int dpms_enum_id; 228 int dpms; 229 int num_props; 230 drmmode_prop_ptr props; 231 drmmode_prop_info_rec props_connector[DRMMODE_CONNECTOR__COUNT]; 232 int enc_mask; 233 int enc_clone_mask; 234 xf86CrtcPtr current_crtc; 235 Atom ctm_atom; 236 struct drm_color_ctm ctm; 237 } drmmode_output_private_rec, *drmmode_output_private_ptr; 238 239 typedef struct { 240 uint32_t lessee_id; 241 } drmmode_lease_private_rec, *drmmode_lease_private_ptr; 242 243 typedef struct _msPixmapPriv { 244 uint32_t fb_id; 245 struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */ 246 247 DamagePtr secondary_damage; 248 249 /** Sink fields for flipping shared pixmaps */ 250 int flip_seq; /* seq of current page flip event handler */ 251 Bool wait_for_damage; /* if we have requested damage notification from source */ 252 253 /** Source fields for flipping shared pixmaps */ 254 Bool defer_dirty_update; /* if we want to manually update */ 255 PixmapDirtyUpdatePtr dirty; /* cached dirty ent to avoid searching list */ 256 DrawablePtr secondary_src; /* if we exported shared pixmap, dirty tracking src */ 257 Bool notify_on_damage; /* if sink has requested damage notification */ 258 } msPixmapPrivRec, *msPixmapPrivPtr; 259 260 #define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec)) 261 262 typedef struct _msSpritePriv { 263 CursorPtr cursor; 264 Bool sprite_visible; 265 } msSpritePrivRec, *msSpritePrivPtr; 266 267 #define msGetSpritePriv(dev, ms, screen) dixLookupScreenPrivate(&(dev)->devPrivates, &(ms)->drmmode.spritePrivateKeyRec, screen) 268 269 extern miPointerSpriteFuncRec drmmode_sprite_funcs; 270 271 Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, 272 uint64_t modifier); 273 int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo, 274 uint32_t *fb_id); 275 int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo); 276 uint32_t drmmode_bo_get_pitch(drmmode_bo *bo); 277 uint32_t drmmode_bo_get_handle(drmmode_bo *bo); 278 Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode); 279 void *drmmode_map_secondary_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv); 280 Bool drmmode_SetSlaveBO(PixmapPtr ppix, 281 drmmode_ptr drmmode, 282 int fd_handle, int pitch, int size); 283 284 Bool drmmode_EnableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode, 285 PixmapPtr front, PixmapPtr back); 286 Bool drmmode_SharedPixmapPresentOnVBlank(PixmapPtr frontTarget, xf86CrtcPtr crtc, 287 drmmode_ptr drmmode); 288 Bool drmmode_SharedPixmapFlip(PixmapPtr frontTarget, xf86CrtcPtr crtc, 289 drmmode_ptr drmmode); 290 void drmmode_DisableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode); 291 292 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 293 extern Bool drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 294 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 295 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 296 Bool set_hw, Bool ign_err); 297 extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 298 299 extern void drmmode_update_kms_state(drmmode_ptr drmmode); 300 extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); 301 extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); 302 303 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 304 void *drmmode_map_front_bo(drmmode_ptr drmmode); 305 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 306 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 307 void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, 308 int *depth, int *bpp); 309 310 void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 311 312 int drmmode_crtc_flip(xf86CrtcPtr crtc, uint32_t fb_id, uint32_t flags, void *data); 313 314 void drmmode_set_dpms(ScrnInfoPtr scrn, int PowerManagementMode, int flags); 315 void drmmode_crtc_set_vrr(xf86CrtcPtr crtc, Bool enabled); 316 317 #endif