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