amdgpu_drv.h revision 11bf0794
1/*
2 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3 *                VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation on the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial
17 * portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NON-INFRINGEMENT.  IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
23 * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * Authors:
31 *   Kevin E. Martin <martin@xfree86.org>
32 *   Rickard E. Faith <faith@valinux.com>
33 *   Alan Hourihane <alanh@fairlite.demon.co.uk>
34 *
35 */
36
37#ifndef _AMDGPU_DRV_H_
38#define _AMDGPU_DRV_H_
39
40#include <stdlib.h>		/* For abs() */
41#include <unistd.h>		/* For usleep() */
42#include <sys/time.h>		/* For gettimeofday() */
43
44#include "config.h"
45
46#include "xf86str.h"
47#include "compiler.h"
48
49/* PCI support */
50#include "xf86Pci.h"
51
52#include "fb.h"
53
54/* Cursor Support */
55#include "xf86Cursor.h"
56
57/* DDC support */
58#include "xf86DDC.h"
59
60/* Xv support */
61#include "xf86xv.h"
62
63#include "amdgpu_probe.h"
64
65/* DRI support */
66#include "xf86drm.h"
67#include "amdgpu_drm.h"
68
69#ifdef DAMAGE
70#include "damage.h"
71#include "globals.h"
72#endif
73
74#include "xf86Crtc.h"
75#include "X11/Xatom.h"
76
77#include "amdgpu_dri2.h"
78#include "drmmode_display.h"
79#include "amdgpu_bo_helper.h"
80
81/* Render support */
82#ifdef RENDER
83#include "picturestr.h"
84#endif
85
86#include "compat-api.h"
87
88#include "simple_list.h"
89
90struct _SyncFence;
91
92#ifndef HAVE_REGIONDUPLICATE
93
94static inline RegionPtr
95RegionDuplicate(RegionPtr pOld)
96{
97	RegionPtr pNew;
98
99	pNew = RegionCreate(&pOld->extents, 0);
100	if (!pNew)
101		return NULL;
102	if (!RegionCopy(pNew, pOld)) {
103		RegionDestroy(pNew);
104		return NULL;
105	}
106	return pNew;
107}
108
109#endif
110
111#ifndef MAX
112#define MAX(a,b) ((a)>(b)?(a):(b))
113#endif
114#ifndef MIN
115#define MIN(a,b) ((a)>(b)?(b):(a))
116#endif
117
118#if HAVE_BYTESWAP_H
119#include <byteswap.h>
120#elif defined(USE_SYS_ENDIAN_H)
121#include <sys/endian.h>
122#else
123#define bswap_16(value)  \
124        ((((value) & 0xff) << 8) | ((value) >> 8))
125
126#define bswap_32(value) \
127        (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
128        (uint32_t)bswap_16((uint16_t)((value) >> 16)))
129
130#define bswap_64(value) \
131        (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
132            << 32) | \
133        (uint64_t)bswap_32((uint32_t)((value) >> 32)))
134#endif
135
136#if X_BYTE_ORDER == X_BIG_ENDIAN
137#define le32_to_cpu(x) bswap_32(x)
138#define le16_to_cpu(x) bswap_16(x)
139#define cpu_to_le32(x) bswap_32(x)
140#define cpu_to_le16(x) bswap_16(x)
141#else
142#define le32_to_cpu(x) (x)
143#define le16_to_cpu(x) (x)
144#define cpu_to_le32(x) (x)
145#define cpu_to_le16(x) (x)
146#endif
147
148/* Provide substitutes for gcc's __FUNCTION__ on other compilers */
149#if !defined(__GNUC__) && !defined(__FUNCTION__)
150#define __FUNCTION__ __func__	/* C99 */
151#endif
152
153typedef enum {
154	OPTION_ACCEL,
155	OPTION_SW_CURSOR,
156	OPTION_PAGE_FLIP,
157#ifdef RENDER
158	OPTION_SUBPIXEL_ORDER,
159#endif
160	OPTION_ZAPHOD_HEADS,
161	OPTION_ACCEL_METHOD,
162	OPTION_DRI3,
163	OPTION_DRI,
164	OPTION_SHADOW_PRIMARY,
165	OPTION_TEAR_FREE,
166	OPTION_DELETE_DP12,
167} AMDGPUOpts;
168
169#if XF86_CRTC_VERSION >= 5
170#define AMDGPU_PIXMAP_SHARING 1
171#define amdgpu_is_gpu_screen(screen) (screen)->isGPU
172#define amdgpu_is_gpu_scrn(scrn) (scrn)->is_gpu
173#else
174#define amdgpu_is_gpu_screen(screen) 0
175#define amdgpu_is_gpu_scrn(scrn) 0
176#endif
177
178#define AMDGPU_VSYNC_TIMEOUT	20000	/* Maximum wait for VSYNC (in usecs) */
179
180/* Buffer are aligned on 4096 byte boundaries */
181#define AMDGPU_GPU_PAGE_SIZE 4096
182#define AMDGPU_BUFFER_ALIGN (AMDGPU_GPU_PAGE_SIZE - 1)
183
184#define xFixedToFloat(f) (((float) (f)) / 65536)
185
186#define AMDGPU_LOGLEVEL_DEBUG 4
187
188/* Other macros */
189#define AMDGPU_ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
190#define AMDGPU_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
191#define AMDGPUPTR(pScrn)      ((AMDGPUInfoPtr)(pScrn)->driverPrivate)
192
193#define CURSOR_WIDTH	64
194#define CURSOR_HEIGHT	64
195
196#define CURSOR_WIDTH_CIK	128
197#define CURSOR_HEIGHT_CIK	128
198
199#define AMDGPU_BO_FLAGS_GBM	0x1
200
201struct amdgpu_buffer {
202	union {
203		struct gbm_bo *gbm;
204		amdgpu_bo_handle amdgpu;
205	} bo;
206	void *cpu_ptr;
207	uint32_t ref_count;
208	uint32_t flags;
209};
210
211struct amdgpu_client_priv {
212	uint_fast32_t needs_flush;
213};
214
215typedef struct {
216	EntityInfoPtr pEnt;
217	struct pci_device *PciInfo;
218	int Chipset;
219	uint32_t family;
220	struct gbm_device *gbm;
221
222	 Bool(*CloseScreen) (CLOSE_SCREEN_ARGS_DECL);
223
224	void (*BlockHandler) (BLOCKHANDLER_ARGS_DECL);
225
226	void (*CreateFence) (ScreenPtr pScreen, struct _SyncFence *pFence,
227			     Bool initially_triggered);
228
229	int pix24bpp;		/* Depth of pixmap for 24bpp fb      */
230	Bool dac6bits;		/* Use 6 bit DAC?                    */
231
232	int pixel_bytes;
233
234	Bool directRenderingEnabled;
235	struct amdgpu_dri2 dri2;
236
237	/* accel */
238	PixmapPtr fbcon_pixmap;
239	int callback_event_type;
240	uint_fast32_t gpu_flushed;
241	uint_fast32_t gpu_synced;
242	Bool use_glamor;
243	Bool force_accel;
244	Bool shadow_primary;
245	int tear_free;
246
247	/* general */
248	OptionInfoPtr Options;
249
250	DisplayModePtr currentMode;
251
252	CreateScreenResourcesProcPtr CreateScreenResources;
253	CreateWindowProcPtr CreateWindow;
254	WindowExposuresProcPtr WindowExposures;
255
256	Bool IsSecondary;
257
258	Bool shadow_fb;
259	void *fb_shadow;
260	struct amdgpu_buffer *front_buffer;
261	struct amdgpu_buffer *cursor_buffer[32];
262
263	uint64_t vram_size;
264	uint64_t gart_size;
265	drmmode_rec drmmode;
266	Bool drmmode_inited;
267	/* r6xx+ tile config */
268	Bool have_tiling_info;
269	int group_bytes;
270
271	/* kms pageflipping */
272	Bool allowPageFlip;
273
274	/* cursor size */
275	int cursor_w;
276	int cursor_h;
277
278	/* If bit n of this field is set, xf86_config->crtc[n] currently can't
279	 * use the HW cursor
280	 */
281	unsigned hwcursor_disabled;
282
283	struct {
284		CreateGCProcPtr SavedCreateGC;
285		RegionPtr (*SavedCopyArea)(DrawablePtr, DrawablePtr, GCPtr,
286					   int, int, int, int, int, int);
287		void (*SavedPolyFillRect)(DrawablePtr, GCPtr, int, xRectangle*);
288		CloseScreenProcPtr SavedCloseScreen;
289		GetImageProcPtr SavedGetImage;
290		GetSpansProcPtr SavedGetSpans;
291		CreatePixmapProcPtr SavedCreatePixmap;
292		DestroyPixmapProcPtr SavedDestroyPixmap;
293		CopyWindowProcPtr SavedCopyWindow;
294		ChangeWindowAttributesProcPtr SavedChangeWindowAttributes;
295		BitmapToRegionProcPtr SavedBitmapToRegion;
296#ifdef RENDER
297		CompositeProcPtr SavedComposite;
298		TrianglesProcPtr SavedTriangles;
299		GlyphsProcPtr SavedGlyphs;
300		TrapezoidsProcPtr SavedTrapezoids;
301		AddTrapsProcPtr SavedAddTraps;
302		UnrealizeGlyphProcPtr SavedUnrealizeGlyph;
303#endif
304#ifdef AMDGPU_PIXMAP_SHARING
305		SharePixmapBackingProcPtr SavedSharePixmapBacking;
306		SetSharedPixmapBackingProcPtr SavedSetSharedPixmapBacking;
307#endif
308	} glamor;
309
310} AMDGPUInfoRec, *AMDGPUInfoPtr;
311
312
313/* amdgpu_dri3.c */
314Bool amdgpu_dri3_screen_init(ScreenPtr screen);
315
316/* amdgpu_kms.c */
317Bool amdgpu_scanout_do_update(xf86CrtcPtr xf86_crtc, int scanout_id);
318
319/* amdgpu_present.c */
320Bool amdgpu_present_screen_init(ScreenPtr screen);
321
322/* amdgpu_sync.c */
323extern Bool amdgpu_sync_init(ScreenPtr screen);
324extern void amdgpu_sync_close(ScreenPtr screen);
325
326/* amdgpu_video.c */
327extern void AMDGPUInitVideo(ScreenPtr pScreen);
328extern void AMDGPUResetVideo(ScrnInfoPtr pScrn);
329extern xf86CrtcPtr amdgpu_pick_best_crtc(ScrnInfoPtr pScrn,
330					 Bool consider_disabled,
331					 int x1, int x2, int y1, int y2);
332
333extern AMDGPUEntPtr AMDGPUEntPriv(ScrnInfoPtr pScrn);
334
335drmVBlankSeqType amdgpu_populate_vbl_request_type(xf86CrtcPtr crtc);
336
337#endif /* _AMDGPU_DRV_H_ */
338