drmmode_display.h revision 35d5b7c7
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 69 /* Cache for DRM property type IDs for CRTC color management */ 70 uint32_t cm_prop_ids[CM_NUM_PROPS]; 71 /* Lookup table sizes */ 72 uint32_t degamma_lut_size; 73 uint32_t gamma_lut_size; 74} drmmode_rec, *drmmode_ptr; 75 76typedef struct { 77 void *event_data; 78 int flip_count; 79 unsigned int fe_frame; 80 uint64_t fe_usec; 81 xf86CrtcPtr fe_crtc; 82 amdgpu_drm_handler_proc handler; 83 amdgpu_drm_abort_proc abort; 84 struct drmmode_fb *fb[0]; 85} drmmode_flipdata_rec, *drmmode_flipdata_ptr; 86 87struct drmmode_fb { 88 int refcnt; 89 uint32_t handle; 90}; 91 92struct drmmode_scanout { 93 struct amdgpu_buffer *bo; 94 PixmapPtr pixmap; 95 int width, height; 96}; 97 98typedef struct { 99 drmmode_ptr drmmode; 100 drmModeCrtcPtr mode_crtc; 101 int hw_id; 102 struct amdgpu_buffer *cursor_buffer; 103 struct drmmode_scanout rotate; 104 struct drmmode_scanout scanout[2]; 105 DamagePtr scanout_damage; 106 Bool ignore_damage; 107 RegionRec scanout_last_region; 108 unsigned scanout_id; 109 uintptr_t scanout_update_pending; 110 Bool tear_free; 111 112 PixmapPtr prime_scanout_pixmap; 113 114 int dpms_mode; 115 CARD64 dpms_last_ust; 116 uint32_t dpms_last_seq; 117 int dpms_last_fps; 118 uint32_t interpolated_vblanks; 119 120 /* Modeset needed for DPMS on */ 121 Bool need_modeset; 122 /* For keeping track of nested calls to drm_wait_pending_flip / 123 * drm_queue_handle_deferred 124 */ 125 int wait_flip_nesting_level; 126 /* A flip to this FB is pending for this CRTC */ 127 struct drmmode_fb *flip_pending; 128 /* The FB currently being scanned out by this CRTC, if any */ 129 struct drmmode_fb *fb; 130 131 struct drm_color_lut *degamma_lut; 132 struct drm_color_ctm *ctm; 133 struct drm_color_lut *gamma_lut; 134} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; 135 136typedef struct { 137 drmModePropertyPtr mode_prop; 138 uint64_t value; 139 int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ 140 Atom *atoms; 141} drmmode_prop_rec, *drmmode_prop_ptr; 142 143typedef struct { 144 drmmode_ptr drmmode; 145 int output_id; 146 drmModeConnectorPtr mode_output; 147 drmModeEncoderPtr *mode_encoders; 148 drmModePropertyBlobPtr edid_blob; 149 int dpms_enum_id; 150 int num_props; 151 drmmode_prop_ptr props; 152 int enc_mask; 153 int enc_clone_mask; 154 int tear_free; 155} drmmode_output_private_rec, *drmmode_output_private_ptr; 156 157typedef struct { 158 uint32_t lessee_id; 159} drmmode_lease_private_rec, *drmmode_lease_private_ptr; 160 161 162enum drmmode_flip_sync { 163 FLIP_VSYNC, 164 FLIP_ASYNC, 165}; 166 167 168/* Can the page flip ioctl be used for this CRTC? */ 169static inline Bool 170drmmode_crtc_can_flip(xf86CrtcPtr crtc) 171{ 172 drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; 173 174 return crtc->enabled && 175 drmmode_crtc->dpms_mode == DPMSModeOn && 176 !drmmode_crtc->rotate.bo && 177 (drmmode_crtc->tear_free || 178 !drmmode_crtc->scanout[drmmode_crtc->scanout_id].bo); 179} 180 181 182static inline void 183drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new, 184 const char *caller, unsigned line) 185{ 186 if (new) { 187 if (new->refcnt <= 0) { 188 FatalError("New FB's refcnt was %d at %s:%u", 189 new->refcnt, caller, line); 190 } 191 192 new->refcnt++; 193 } 194 195 if (*old) { 196 if ((*old)->refcnt <= 0) { 197 FatalError("Old FB's refcnt was %d at %s:%u", 198 (*old)->refcnt, caller, line); 199 } 200 201 if (--(*old)->refcnt == 0) { 202 drmModeRmFB(drm_fd, (*old)->handle); 203 free(*old); 204 } 205 } 206 207 *old = new; 208} 209 210#define drmmode_fb_reference(fd, old, new) \ 211 drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__) 212 213 214extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt, 215 drmmode_crtc_private_ptr drmmode_crtc, 216 int fb_id, uint32_t flags, 217 uintptr_t drm_queue_seq, 218 uint32_t target_msc); 219extern int drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt, 220 drmmode_crtc_private_ptr drmmode_crtc, 221 int fb_id, uint32_t flags, 222 uintptr_t drm_queue_seq, 223 uint32_t target_msc); 224extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); 225extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 226extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 227extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, 228 struct amdgpu_buffer *bo); 229void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); 230extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, 231 Bool set_hw); 232extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); 233extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); 234 235extern void drmmode_crtc_scanout_destroy(drmmode_ptr drmmode, 236 struct drmmode_scanout *scanout); 237void drmmode_crtc_scanout_free(drmmode_crtc_private_ptr drmmode_crtc); 238PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc, 239 struct drmmode_scanout *scanout, 240 int width, int height); 241 242extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); 243extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); 244 245Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb, 246 DisplayModePtr mode, int x, int y); 247 248extern int drmmode_get_crtc_id(xf86CrtcPtr crtc); 249extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe); 250Bool amdgpu_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, 251 PixmapPtr new_front, uint64_t id, void *data, 252 xf86CrtcPtr ref_crtc, amdgpu_drm_handler_proc handler, 253 amdgpu_drm_abort_proc abort, 254 enum drmmode_flip_sync flip_sync, 255 uint32_t target_msc); 256int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); 257int drmmode_get_current_ust(int drm_fd, CARD64 * ust); 258 259Bool drmmode_wait_vblank(xf86CrtcPtr crtc, drmVBlankSeqType type, 260 uint32_t target_seq, unsigned long signal, 261 uint64_t *ust, uint32_t *result_seq); 262 263 264miPointerSpriteFuncRec drmmode_sprite_funcs; 265 266 267#endif 268