drmmode_display.h revision 39413783
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 HAVE_LIBUDEV 32#include "libudev.h" 33#endif 34 35#include "radeon_drm_queue.h" 36#include "radeon_probe.h" 37 38#ifndef DRM_CAP_TIMESTAMP_MONOTONIC 39#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6 40#endif 41 42typedef struct { 43 struct radeon_bo_manager *bufmgr; 44 ScrnInfoPtr scrn; 45#ifdef HAVE_LIBUDEV 46 struct udev_monitor *uevent_monitor; 47 InputHandlerProc uevent_handler; 48#endif 49 drmEventContext event_context; 50 int count_crtcs; 51 52 Bool delete_dp_12_displays; 53 54 Bool dri2_flipping; 55 Bool present_flipping; 56} drmmode_rec, *drmmode_ptr; 57 58typedef struct { 59 void *event_data; 60 int flip_count; 61 unsigned int fe_frame; 62 uint64_t fe_usec; 63 xf86CrtcPtr fe_crtc; 64 radeon_drm_handler_proc handler; 65 radeon_drm_abort_proc abort; 66 struct drmmode_fb *fb[0]; 67} drmmode_flipdata_rec, *drmmode_flipdata_ptr; 68 69struct drmmode_fb { 70 int refcnt; 71 uint32_t handle; 72}; 73 74struct drmmode_scanout { 75 struct radeon_buffer *bo; 76 PixmapPtr pixmap; 77 int width, height; 78}; 79 80typedef struct { 81 drmmode_ptr drmmode; 82 drmModeCrtcPtr mode_crtc; 83 int hw_id; 84 struct radeon_bo *cursor_bo; 85 struct drmmode_scanout rotate; 86 struct drmmode_scanout scanout[2]; 87 DamagePtr scanout_damage; 88 Bool ignore_damage; 89 RegionRec scanout_last_region; 90 unsigned scanout_id; 91 uintptr_t scanout_update_pending; 92 Bool tear_free; 93 94 PixmapPtr prime_scanout_pixmap; 95 96 int dpms_mode; 97 CARD64 dpms_last_ust; 98 uint32_t dpms_last_seq; 99 int dpms_last_fps; 100 uint32_t interpolated_vblanks; 101 102 /* Modeset needed (for DPMS on or after a page flip crossing with a 103 * modeset) 104 */ 105 Bool need_modeset; 106 /* For keeping track of nested calls to drm_wait_pending_flip / 107 * drm_queue_handle_deferred 108 */ 109 int wait_flip_nesting_level; 110 /* A flip to this FB is pending for this CRTC */ 111 struct drmmode_fb *flip_pending; 112 /* The FB currently being scanned out by this CRTC, if any */ 113 struct drmmode_fb *fb; 114} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; 115 116typedef struct { 117 drmModePropertyPtr mode_prop; 118 uint64_t value; 119 int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ 120 Atom *atoms; 121} drmmode_prop_rec, *drmmode_prop_ptr; 122 123 124typedef struct { 125 drmmode_ptr drmmode; 126 int output_id; 127 drmModeConnectorPtr mode_output; 128 drmModeEncoderPtr *mode_encoders; 129 drmModePropertyBlobPtr edid_blob; 130 int dpms_enum_id; 131 int num_props; 132 drmmode_prop_ptr props; 133 int enc_mask; 134 int enc_clone_mask; 135 int tear_free; 136} drmmode_output_private_rec, *drmmode_output_private_ptr; 137 138typedef struct { 139 uint32_t lessee_id; 140} drmmode_lease_private_rec, *drmmode_lease_private_ptr; 141 142 143enum drmmode_flip_sync { 144 FLIP_VSYNC, 145 FLIP_ASYNC, 146}; 147 148 149/* Can the page flip ioctl be used for this CRTC? */ 150static inline Bool 151drmmode_crtc_can_flip(xf86CrtcPtr crtc) 152{ 153 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; 154 155 return crtc->enabled && 156 drmmode_crtc->dpms_mode == DPMSModeOn && 157 !drmmode_crtc->rotate.bo && 158 (drmmode_crtc->tear_free || 159 !drmmode_crtc->scanout[drmmode_crtc->scanout_id].bo); 160} 161 162 163static inline void 164drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new, 165 const char *caller, unsigned line) 166{ 167 if (new) { 168 if (new->refcnt <= 0) { 169 FatalError("New FB's refcnt was %d at %s:%u", 170 new->refcnt, caller, line); 171 } 172 173 new->refcnt++; 174 } 175 176 if (*old) { 177 if ((*old)->refcnt <= 0) { 178 FatalError("Old FB's refcnt was %d at %s:%u", 179 (*old)->refcnt, caller, line); 180 } 181 182 if (--(*old)->refcnt == 0) { 183 drmModeRmFB(drm_fd, (*old)->handle); 184 free(*old); 185 } 186 } 187 188 *old = new; 189} 190 191#define drmmode_fb_reference(fd, old, new) \ 192 drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) 193 194 195extern int drmmode_page_flip_target_absolute(RADEONEntPtr pRADEONEnt, 196 drmmode_crtc_private_ptr drmmode_crtc, 197 int fb_id, uint32_t flags, 198 uintptr_t drm_queue_seq, 199 uint32_t target_msc); 200extern int drmmode_page_flip_target_relative(RADEONEntPtr pRADEONEnt, 201 drmmode_crtc_private_ptr drmmode_crtc, 202 int fb_id, uint32_t flags, 203 uintptr_t drm_queue_seq, 204 uint32_t target_msc); 205extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 206extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 207extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 208extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr); 209extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo); 210void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 211extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 212 Bool set_hw); 213extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 214extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 215 216extern void drmmode_crtc_scanout_destroy(drmmode_ptr drmmode, 217 struct drmmode_scanout *scanout); 218void drmmode_crtc_scanout_free(drmmode_crtc_private_ptr drmmode_crtc); 219PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc, 220 struct drmmode_scanout *scanout, 221 int width, int height); 222 223extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); 224extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); 225 226Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb, 227 DisplayModePtr mode, int x, int y); 228 229extern int drmmode_get_crtc_id(xf86CrtcPtr crtc); 230extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling); 231extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); 232extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); 233 234Bool radeon_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, 235 PixmapPtr new_front, uint64_t id, void *data, 236 xf86CrtcPtr ref_crtc, radeon_drm_handler_proc handler, 237 radeon_drm_abort_proc abort, 238 enum drmmode_flip_sync flip_sync, 239 uint32_t target_msc); 240int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); 241int drmmode_get_current_ust(int drm_fd, CARD64 *ust); 242 243Bool drmmode_wait_vblank(xf86CrtcPtr crtc, drmVBlankSeqType type, 244 uint32_t target_seq, unsigned long signal, 245 uint64_t *ust, uint32_t *result_seq); 246 247 248miPointerSpriteFuncRec drmmode_sprite_funcs; 249 250 251#endif 252 253