drmmode_display.h revision 1b7ce8ce
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 "amdgpu_drm_queue.h" 36#include "amdgpu_probe.h" 37#include "amdgpu.h" 38 39/* 40 * Enum of non-legacy color management properties, according to DRM. Note that 41 * the values should be incremental (with the exception of the INVALID member), 42 * as defined by C99. The ordering also matters. Some logics (such as iterators 43 * and bitmasks) depend on these facts. 44 */ 45enum drmmode_cm_prop { 46 CM_DEGAMMA_LUT, 47 CM_CTM, 48 CM_GAMMA_LUT, 49 CM_DEGAMMA_LUT_SIZE, 50 CM_GAMMA_LUT_SIZE, 51 CM_NUM_PROPS, 52 CM_INVALID_PROP = -1, 53}; 54 55typedef struct { 56 ScrnInfoPtr scrn; 57#ifdef HAVE_LIBUDEV 58 struct udev_monitor *uevent_monitor; 59 InputHandlerProc uevent_handler; 60#endif 61 drmEventContext event_context; 62 int count_crtcs; 63 64 Bool delete_dp_12_displays; 65 66 Bool dri2_flipping; 67 Bool present_flipping; 68 uint32_t vrr_prop_id; 69 70 /* Cache for DRM property type IDs for CRTC color management */ 71 uint32_t cm_prop_ids[CM_NUM_PROPS]; 72 /* Lookup table sizes */ 73 uint32_t degamma_lut_size; 74 uint32_t gamma_lut_size; 75} drmmode_rec, *drmmode_ptr; 76 77typedef struct { 78 void *event_data; 79 int flip_count; 80 unsigned int fe_frame; 81 uint64_t fe_usec; 82 xf86CrtcPtr fe_crtc; 83 amdgpu_drm_handler_proc handler; 84 amdgpu_drm_abort_proc abort; 85 struct drmmode_fb *fb[0]; 86} drmmode_flipdata_rec, *drmmode_flipdata_ptr; 87 88struct drmmode_fb { 89 int refcnt; 90 uint32_t handle; 91}; 92 93enum drmmode_scanout_status { 94 DRMMODE_SCANOUT_OK, 95 DRMMODE_SCANOUT_FLIP_FAILED = 1u << 0, 96 DRMMODE_SCANOUT_VBLANK_FAILED = 1u << 1, 97}; 98 99typedef struct { 100 drmmode_ptr drmmode; 101 drmModeCrtcPtr mode_crtc; 102 int hw_id; 103 104 CursorPtr cursor; 105 int cursor_x; 106 int cursor_y; 107 int cursor_xhot; 108 int cursor_yhot; 109 unsigned cursor_id; 110 struct amdgpu_buffer *cursor_buffer[2]; 111 112 PixmapPtr rotate; 113 PixmapPtr scanout[2]; 114 DamagePtr scanout_damage; 115 Bool ignore_damage; 116 RegionRec scanout_last_region; 117 unsigned scanout_id; 118 uintptr_t scanout_update_pending; 119 Bool tear_free; 120 enum drmmode_scanout_status scanout_status; 121 Bool vrr_enabled; 122 123 PixmapPtr prime_scanout_pixmap; 124 125 int dpms_mode; 126 CARD64 dpms_last_ust; 127 uint32_t dpms_last_seq; 128 int dpms_last_fps; 129 uint32_t interpolated_vblanks; 130 131 /* Modeset needed for DPMS on */ 132 Bool need_modeset; 133 /* For keeping track of nested calls to drm_wait_pending_flip / 134 * drm_queue_handle_deferred 135 */ 136 int wait_flip_nesting_level; 137 /* A flip to this FB is pending for this CRTC */ 138 struct drmmode_fb *flip_pending; 139 /* The FB currently being scanned out by this CRTC, if any */ 140 struct drmmode_fb *fb; 141 142 struct drm_color_lut *degamma_lut; 143 struct drm_color_ctm *ctm; 144 struct drm_color_lut *gamma_lut; 145} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; 146 147typedef struct { 148 drmModePropertyPtr mode_prop; 149 uint64_t value; 150 int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ 151 Atom *atoms; 152} drmmode_prop_rec, *drmmode_prop_ptr; 153 154typedef struct { 155 drmmode_ptr drmmode; 156 int output_id; 157 drmModeConnectorPtr mode_output; 158 drmModeEncoderPtr *mode_encoders; 159 drmModePropertyBlobPtr edid_blob; 160#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1, 17, 99, 901, 0) 161 drmModePropertyBlobPtr tile_blob; 162#endif 163 int dpms_enum_id; 164 int num_props; 165 drmmode_prop_ptr props; 166 int enc_mask; 167 int enc_clone_mask; 168 int tear_free; 169} drmmode_output_private_rec, *drmmode_output_private_ptr; 170 171typedef struct { 172 uint32_t lessee_id; 173} drmmode_lease_private_rec, *drmmode_lease_private_ptr; 174 175 176enum drmmode_flip_sync { 177 FLIP_VSYNC, 178 FLIP_ASYNC, 179}; 180 181 182/** 183 * Return TRUE if kernel supports non-legacy color management. 184 */ 185static inline Bool 186drmmode_cm_enabled(drmmode_ptr drmmode) 187{ 188 return drmmode->cm_prop_ids[CM_GAMMA_LUT_SIZE] != 0; 189} 190 191/* Can the page flip ioctl be used for this CRTC? */ 192static inline Bool 193drmmode_crtc_can_flip(xf86CrtcPtr crtc) 194{ 195 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; 196 197 return crtc->enabled && 198 drmmode_crtc->dpms_mode == DPMSModeOn && 199 !drmmode_crtc->rotate && 200 (drmmode_crtc->tear_free || 201 !drmmode_crtc->scanout[drmmode_crtc->scanout_id]); 202} 203 204 205static inline void 206drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new, 207 const char *caller, unsigned line) 208{ 209 if (new) { 210 if (new->refcnt <= 0) { 211 FatalError("New FB's refcnt was %d at %s:%u", 212 new->refcnt, caller, line); 213 } 214 215 new->refcnt++; 216 } 217 218 if (*old) { 219 if ((*old)->refcnt <= 0) { 220 FatalError("Old FB's refcnt was %d at %s:%u", 221 (*old)->refcnt, caller, line); 222 } 223 224 if (--(*old)->refcnt == 0) { 225 drmModeRmFB(drm_fd, (*old)->handle); 226 free(*old); 227 } 228 } 229 230 *old = new; 231} 232 233#define drmmode_fb_reference(fd, old, new) \ 234 drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) 235 236 237static inline void 238drmmode_crtc_scanout_destroy(PixmapPtr *scanout) 239{ 240 if (!*scanout) 241 return; 242 243 (*scanout)->drawable.pScreen->DestroyPixmap(*scanout); 244 (*scanout) = NULL; 245} 246 247 248extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt, 249 drmmode_crtc_private_ptr drmmode_crtc, 250 int fb_id, uint32_t flags, 251 uintptr_t drm_queue_seq, 252 uint32_t target_msc); 253extern int drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt, 254 drmmode_crtc_private_ptr drmmode_crtc, 255 int fb_id, uint32_t flags, 256 uintptr_t drm_queue_seq, 257 uint32_t target_msc); 258extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 259extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 260extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 261void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 262extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 263 Bool set_hw); 264extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 265extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 266 267void drmmode_crtc_scanout_free(xf86CrtcPtr crtc); 268 269extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); 270extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); 271 272Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb, 273 DisplayModePtr mode, int x, int y); 274 275extern int drmmode_get_crtc_id(xf86CrtcPtr crtc); 276extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe); 277Bool amdgpu_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, 278 PixmapPtr new_front, uint64_t id, void *data, 279 xf86CrtcPtr ref_crtc, amdgpu_drm_handler_proc handler, 280 amdgpu_drm_abort_proc abort, 281 enum drmmode_flip_sync flip_sync, 282 uint32_t target_msc); 283int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); 284int drmmode_get_current_ust(int drm_fd, CARD64 * ust); 285void drmmode_crtc_set_vrr(xf86CrtcPtr crtc, Bool enabled); 286 287Bool drmmode_wait_vblank(xf86CrtcPtr crtc, drmVBlankSeqType type, 288 uint32_t target_seq, unsigned long signal, 289 uint64_t *ust, uint32_t *result_seq); 290 291 292extern miPointerSpriteFuncRec drmmode_sprite_funcs; 293 294 295#endif 296