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