drmmode_display.h revision 90f2b693
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 int dpms_enum_id; 167 int num_props; 168 drmmode_prop_ptr props; 169 int enc_mask; 170 int enc_clone_mask; 171 int tear_free; 172} drmmode_output_private_rec, *drmmode_output_private_ptr; 173 174typedef struct { 175 uint32_t lessee_id; 176} drmmode_lease_private_rec, *drmmode_lease_private_ptr; 177 178 179enum drmmode_flip_sync { 180 FLIP_VSYNC, 181 FLIP_ASYNC, 182}; 183 184 185/** 186 * Return TRUE if kernel supports non-legacy color management. 187 */ 188static inline Bool 189drmmode_cm_enabled(drmmode_ptr drmmode) 190{ 191 return drmmode->cm_prop_ids[CM_GAMMA_LUT_SIZE] != 0; 192} 193 194/* Can the page flip ioctl be used for this CRTC? */ 195static inline Bool 196drmmode_crtc_can_flip(xf86CrtcPtr crtc) 197{ 198 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; 199 200 return crtc->enabled && 201 drmmode_crtc->dpms_mode == DPMSModeOn && 202 !drmmode_crtc->rotate.bo && 203 (drmmode_crtc->tear_free || 204 !drmmode_crtc->scanout[drmmode_crtc->scanout_id].bo); 205} 206 207 208static inline void 209drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new, 210 const char *caller, unsigned line) 211{ 212 if (new) { 213 if (new->refcnt <= 0) { 214 FatalError("New FB's refcnt was %d at %s:%u", 215 new->refcnt, caller, line); 216 } 217 218 new->refcnt++; 219 } 220 221 if (*old) { 222 if ((*old)->refcnt <= 0) { 223 FatalError("Old FB's refcnt was %d at %s:%u", 224 (*old)->refcnt, caller, line); 225 } 226 227 if (--(*old)->refcnt == 0) { 228 drmModeRmFB(drm_fd, (*old)->handle); 229 free(*old); 230 } 231 } 232 233 *old = new; 234} 235 236#define drmmode_fb_reference(fd, old, new) \ 237 drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) 238 239 240extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt, 241 drmmode_crtc_private_ptr drmmode_crtc, 242 int fb_id, uint32_t flags, 243 uintptr_t drm_queue_seq, 244 uint32_t target_msc); 245extern int drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt, 246 drmmode_crtc_private_ptr drmmode_crtc, 247 int fb_id, uint32_t flags, 248 uintptr_t drm_queue_seq, 249 uint32_t target_msc); 250extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 251extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 252extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 253void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 254extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 255 Bool set_hw); 256extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 257extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 258 259extern void drmmode_crtc_scanout_destroy(drmmode_ptr drmmode, 260 struct drmmode_scanout *scanout); 261void drmmode_crtc_scanout_free(xf86CrtcPtr crtc); 262PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc, 263 struct drmmode_scanout *scanout, 264 int width, int height); 265 266extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); 267extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); 268 269Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb, 270 DisplayModePtr mode, int x, int y); 271 272extern int drmmode_get_crtc_id(xf86CrtcPtr crtc); 273extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe); 274Bool amdgpu_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, 275 PixmapPtr new_front, uint64_t id, void *data, 276 xf86CrtcPtr ref_crtc, amdgpu_drm_handler_proc handler, 277 amdgpu_drm_abort_proc abort, 278 enum drmmode_flip_sync flip_sync, 279 uint32_t target_msc); 280int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); 281int drmmode_get_current_ust(int drm_fd, CARD64 * ust); 282void drmmode_crtc_set_vrr(xf86CrtcPtr crtc, Bool enabled); 283 284Bool drmmode_wait_vblank(xf86CrtcPtr crtc, drmVBlankSeqType type, 285 uint32_t target_seq, unsigned long signal, 286 uint64_t *ust, uint32_t *result_seq); 287 288 289miPointerSpriteFuncRec drmmode_sprite_funcs; 290 291 292#endif 293