drmmode_display.h revision 8bf5c682
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  struct drmmode_fb *fb;
60  void *event_data;
61  int flip_count;
62  unsigned int fe_frame;
63  uint64_t fe_usec;
64  xf86CrtcPtr fe_crtc;
65  radeon_drm_handler_proc handler;
66  radeon_drm_abort_proc abort;
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_bo *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    Bool 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    /* A flip to this FB is pending for this CRTC */
107    struct drmmode_fb *flip_pending;
108    /* The FB currently being scanned out by this CRTC, if any */
109    struct drmmode_fb *fb;
110
111#ifdef HAVE_PRESENT_H
112    /* Deferred processing of Present vblank event */
113    uint64_t present_vblank_event_id;
114    uint64_t present_vblank_usec;
115    unsigned present_vblank_msc;
116    Bool present_flip_expected;
117#endif
118} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
119
120typedef struct {
121    drmModePropertyPtr mode_prop;
122    uint64_t value;
123    int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
124    Atom *atoms;
125} drmmode_prop_rec, *drmmode_prop_ptr;
126
127
128typedef struct {
129    drmmode_ptr drmmode;
130    int output_id;
131    drmModeConnectorPtr mode_output;
132    drmModeEncoderPtr *mode_encoders;
133    drmModePropertyBlobPtr edid_blob;
134    int dpms_enum_id;
135    int num_props;
136    drmmode_prop_ptr props;
137    int enc_mask;
138    int enc_clone_mask;
139    int tear_free;
140} drmmode_output_private_rec, *drmmode_output_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_sprite_set_cursor(DeviceIntPtr pDev, ScreenPtr pScreen,
210				      CursorPtr pCursor, int x, int y);
211extern void drmmode_sprite_move_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x,
212				       int y);
213extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
214void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
215extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode,
216				      Bool set_hw);
217extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
218extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
219
220extern void drmmode_crtc_scanout_destroy(drmmode_ptr drmmode,
221					 struct drmmode_scanout *scanout);
222void drmmode_crtc_scanout_free(drmmode_crtc_private_ptr drmmode_crtc);
223PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc,
224				      struct drmmode_scanout *scanout,
225				      int width, int height);
226
227extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
228extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
229
230Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb,
231		      DisplayModePtr mode, int x, int y);
232
233extern int drmmode_get_crtc_id(xf86CrtcPtr crtc);
234extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling);
235extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
236extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
237
238Bool radeon_do_pageflip(ScrnInfoPtr scrn, ClientPtr client,
239			PixmapPtr new_front, uint64_t id, void *data,
240			xf86CrtcPtr ref_crtc, radeon_drm_handler_proc handler,
241			radeon_drm_abort_proc abort,
242			enum drmmode_flip_sync flip_sync,
243			uint32_t target_msc);
244int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
245int drmmode_get_current_ust(int drm_fd, CARD64 *ust);
246
247Bool drmmode_wait_vblank(xf86CrtcPtr crtc, drmVBlankSeqType type,
248			 uint32_t target_seq, unsigned long signal,
249			 uint64_t *ust, uint32_t *result_seq);
250
251
252#endif
253
254