drmmode_display.h revision 11bf0794
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
39typedef struct {
40	unsigned fb_id;
41	drmModeFBPtr mode_fb;
42	int cpp;
43	ScrnInfoPtr scrn;
44#ifdef HAVE_LIBUDEV
45	struct udev_monitor *uevent_monitor;
46	InputHandlerProc uevent_handler;
47#endif
48	drmEventContext event_context;
49	int count_crtcs;
50
51	Bool delete_dp_12_displays;
52
53	Bool dri2_flipping;
54	Bool present_flipping;
55} drmmode_rec, *drmmode_ptr;
56
57typedef struct {
58	int fd;
59	unsigned old_fb_id;
60	int flip_count;
61	void *event_data;
62	unsigned int fe_frame;
63	uint64_t fe_usec;
64	xf86CrtcPtr fe_crtc;
65	amdgpu_drm_handler_proc handler;
66	amdgpu_drm_abort_proc abort;
67} drmmode_flipdata_rec, *drmmode_flipdata_ptr;
68
69struct drmmode_scanout {
70	struct amdgpu_buffer *bo;
71	PixmapPtr pixmap;
72	unsigned fb_id;
73	int width, height;
74};
75
76typedef struct {
77	drmmode_ptr drmmode;
78	drmModeCrtcPtr mode_crtc;
79	int hw_id;
80	struct amdgpu_buffer *cursor_buffer;
81	struct drmmode_scanout rotate;
82	struct drmmode_scanout scanout[2];
83	struct drmmode_scanout scanout_destroy[2];
84	DamagePtr scanout_damage;
85	RegionRec scanout_last_region;
86	unsigned scanout_id;
87	Bool scanout_update_pending;
88	Bool tear_free;
89	int dpms_mode;
90	/* For when a flip is pending when DPMS off requested */
91	int pending_dpms_mode;
92	CARD64 dpms_last_ust;
93	uint32_t dpms_last_seq;
94	int dpms_last_fps;
95	uint32_t interpolated_vblanks;
96
97	/* Modeset needed for DPMS on */
98	Bool need_modeset;
99	/* A flip is pending for this CRTC */
100	Bool flip_pending;
101} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
102
103typedef struct {
104	drmModePropertyPtr mode_prop;
105	uint64_t value;
106	int num_atoms;		/* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
107	Atom *atoms;
108} drmmode_prop_rec, *drmmode_prop_ptr;
109
110typedef struct {
111	drmmode_ptr drmmode;
112	int output_id;
113	drmModeConnectorPtr mode_output;
114	drmModeEncoderPtr *mode_encoders;
115	drmModePropertyBlobPtr edid_blob;
116	int dpms_enum_id;
117	int num_props;
118	drmmode_prop_ptr props;
119	int enc_mask;
120	int enc_clone_mask;
121	int tear_free;
122} drmmode_output_private_rec, *drmmode_output_private_ptr;
123
124
125enum drmmode_flip_sync {
126    FLIP_VSYNC,
127    FLIP_ASYNC,
128};
129
130
131extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt,
132					     drmmode_crtc_private_ptr drmmode_crtc,
133					     int fb_id, uint32_t flags,
134					     uintptr_t drm_queue_seq,
135					     uint32_t target_msc);
136extern int drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt,
137					     drmmode_crtc_private_ptr drmmode_crtc,
138					     int fb_id, uint32_t flags,
139					     uintptr_t drm_queue_seq,
140					     uint32_t target_msc);
141extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
142extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
143extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
144extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id,
145			       struct amdgpu_buffer *bo);
146void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
147extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode,
148				      Bool set_hw);
149extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
150extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
151
152extern void drmmode_scanout_free(ScrnInfoPtr scrn);
153
154extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
155extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
156
157extern int drmmode_get_crtc_id(xf86CrtcPtr crtc);
158extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe);
159extern void drmmode_clear_pending_flip(xf86CrtcPtr crtc);
160Bool amdgpu_do_pageflip(ScrnInfoPtr scrn, ClientPtr client,
161			PixmapPtr new_front, uint64_t id, void *data,
162			int ref_crtc_hw_id, amdgpu_drm_handler_proc handler,
163			amdgpu_drm_abort_proc abort,
164			enum drmmode_flip_sync flip_sync,
165			uint32_t target_msc);
166int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
167int drmmode_get_current_ust(int drm_fd, CARD64 * ust);
168
169#endif
170