drmmode_display.h revision ad01e365
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 99struct drmmode_scanout { 100 struct amdgpu_buffer *bo; 101 PixmapPtr pixmap; 102 int width, height; 103}; 104 105typedef struct { 106 drmmode_ptr drmmode; 107 drmModeCrtcPtr mode_crtc; 108 int hw_id; 109 110 CursorPtr cursor; 111 int cursor_x; 112 int cursor_y; 113 int cursor_xhot; 114 int cursor_yhot; 115 unsigned cursor_id; 116 struct amdgpu_buffer *cursor_buffer[2]; 117 118 struct drmmode_scanout rotate; 119 struct drmmode_scanout scanout[2]; 120 DamagePtr scanout_damage; 121 Bool ignore_damage; 122 RegionRec scanout_last_region; 123 unsigned scanout_id; 124 uintptr_t scanout_update_pending; 125 Bool tear_free; 126 enum drmmode_scanout_status scanout_status; 127 Bool vrr_enabled; 128 129 PixmapPtr prime_scanout_pixmap; 130 131 int dpms_mode; 132 CARD64 dpms_last_ust; 133 uint32_t dpms_last_seq; 134 int dpms_last_fps; 135 uint32_t interpolated_vblanks; 136 137 /* Modeset needed for DPMS on */ 138 Bool need_modeset; 139 /* For keeping track of nested calls to drm_wait_pending_flip / 140 * drm_queue_handle_deferred 141 */ 142 int wait_flip_nesting_level; 143 /* A flip to this FB is pending for this CRTC */ 144 struct drmmode_fb *flip_pending; 145 /* The FB currently being scanned out by this CRTC, if any */ 146 struct drmmode_fb *fb; 147 148 struct drm_color_lut *degamma_lut; 149 struct drm_color_ctm *ctm; 150 struct drm_color_lut *gamma_lut; 151} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; 152 153typedef struct { 154 drmModePropertyPtr mode_prop; 155 uint64_t value; 156 int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ 157 Atom *atoms; 158} drmmode_prop_rec, *drmmode_prop_ptr; 159 160typedef struct { 161 drmmode_ptr drmmode; 162 int output_id; 163 drmModeConnectorPtr mode_output; 164 drmModeEncoderPtr *mode_encoders; 165 drmModePropertyBlobPtr edid_blob; 166#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1, 17, 99, 901, 0) 167 drmModePropertyBlobPtr tile_blob; 168#endif 169 int dpms_enum_id; 170 int num_props; 171 drmmode_prop_ptr props; 172 int enc_mask; 173 int enc_clone_mask; 174 int tear_free; 175} drmmode_output_private_rec, *drmmode_output_private_ptr; 176 177typedef struct { 178 uint32_t lessee_id; 179} drmmode_lease_private_rec, *drmmode_lease_private_ptr; 180 181 182enum drmmode_flip_sync { 183 FLIP_VSYNC, 184 FLIP_ASYNC, 185}; 186 187 188/** 189 * Return TRUE if kernel supports non-legacy color management. 190 */ 191static inline Bool 192drmmode_cm_enabled(drmmode_ptr drmmode) 193{ 194 return drmmode->cm_prop_ids[CM_GAMMA_LUT_SIZE] != 0; 195} 196 197/* Can the page flip ioctl be used for this CRTC? */ 198static inline Bool 199drmmode_crtc_can_flip(xf86CrtcPtr crtc) 200{ 201 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; 202 203 return crtc->enabled && 204 drmmode_crtc->dpms_mode == DPMSModeOn && 205 !drmmode_crtc->rotate.bo && 206 (drmmode_crtc->tear_free || 207 !drmmode_crtc->scanout[drmmode_crtc->scanout_id].bo); 208} 209 210 211static inline void 212drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new, 213 const char *caller, unsigned line) 214{ 215 if (new) { 216 if (new->refcnt <= 0) { 217 FatalError("New FB's refcnt was %d at %s:%u", 218 new->refcnt, caller, line); 219 } 220 221 new->refcnt++; 222 } 223 224 if (*old) { 225 if ((*old)->refcnt <= 0) { 226 FatalError("Old FB's refcnt was %d at %s:%u", 227 (*old)->refcnt, caller, line); 228 } 229 230 if (--(*old)->refcnt == 0) { 231 drmModeRmFB(drm_fd, (*old)->handle); 232 free(*old); 233 } 234 } 235 236 *old = new; 237} 238 239#define drmmode_fb_reference(fd, old, new) \ 240 drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) 241 242 243extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt, 244 drmmode_crtc_private_ptr drmmode_crtc, 245 int fb_id, uint32_t flags, 246 uintptr_t drm_queue_seq, 247 uint32_t target_msc); 248extern int drmmode_page_flip_target_relative(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 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 254extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 255extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 256void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 257extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 258 Bool set_hw); 259extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 260extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 261 262extern void drmmode_crtc_scanout_destroy(drmmode_ptr drmmode, 263 struct drmmode_scanout *scanout); 264void drmmode_crtc_scanout_free(xf86CrtcPtr crtc); 265PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc, 266 struct drmmode_scanout *scanout, 267 int width, int height); 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