xref: /freebsd/sys/dev/drm2/drmP.h (revision 918988576c57ef3ee72ff36273e37b919c4c93d5)
1592ffb21SWarner Losh /**
2592ffb21SWarner Losh  * \file drmP.h
3592ffb21SWarner Losh  * Private header for Direct Rendering Manager
4592ffb21SWarner Losh  *
5592ffb21SWarner Losh  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6592ffb21SWarner Losh  * \author Gareth Hughes <gareth@valinux.com>
7592ffb21SWarner Losh  */
8592ffb21SWarner Losh 
9592ffb21SWarner Losh /*
10592ffb21SWarner Losh  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11592ffb21SWarner Losh  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12592ffb21SWarner Losh  * Copyright (c) 2009-2010, Code Aurora Forum.
13592ffb21SWarner Losh  * All rights reserved.
14592ffb21SWarner Losh  *
15592ffb21SWarner Losh  * Permission is hereby granted, free of charge, to any person obtaining a
16592ffb21SWarner Losh  * copy of this software and associated documentation files (the "Software"),
17592ffb21SWarner Losh  * to deal in the Software without restriction, including without limitation
18592ffb21SWarner Losh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19592ffb21SWarner Losh  * and/or sell copies of the Software, and to permit persons to whom the
20592ffb21SWarner Losh  * Software is furnished to do so, subject to the following conditions:
21592ffb21SWarner Losh  *
22592ffb21SWarner Losh  * The above copyright notice and this permission notice (including the next
23592ffb21SWarner Losh  * paragraph) shall be included in all copies or substantial portions of the
24592ffb21SWarner Losh  * Software.
25592ffb21SWarner Losh  *
26592ffb21SWarner Losh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27592ffb21SWarner Losh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28592ffb21SWarner Losh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
29592ffb21SWarner Losh  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30592ffb21SWarner Losh  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31592ffb21SWarner Losh  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32592ffb21SWarner Losh  * OTHER DEALINGS IN THE SOFTWARE.
33592ffb21SWarner Losh  */
34592ffb21SWarner Losh 
35592ffb21SWarner Losh #include <sys/cdefs.h>
36592ffb21SWarner Losh __FBSDID("$FreeBSD$");
37592ffb21SWarner Losh 
38592ffb21SWarner Losh #ifndef _DRM_P_H_
39592ffb21SWarner Losh #define _DRM_P_H_
40592ffb21SWarner Losh 
41592ffb21SWarner Losh #if defined(_KERNEL) || defined(__KERNEL__)
42592ffb21SWarner Losh 
43592ffb21SWarner Losh #include <sys/param.h>
44592ffb21SWarner Losh #include <sys/queue.h>
45592ffb21SWarner Losh #include <sys/malloc.h>
46592ffb21SWarner Losh #include <sys/kernel.h>
47592ffb21SWarner Losh #include <sys/ktr.h>
48592ffb21SWarner Losh #include <sys/module.h>
49592ffb21SWarner Losh #include <sys/systm.h>
50592ffb21SWarner Losh #include <sys/conf.h>
51592ffb21SWarner Losh #include <sys/sglist.h>
52592ffb21SWarner Losh #include <sys/stat.h>
53592ffb21SWarner Losh #include <sys/priv.h>
54592ffb21SWarner Losh #include <sys/proc.h>
55*91898857SMark Johnston #include <sys/limits.h>
56592ffb21SWarner Losh #include <sys/lock.h>
57592ffb21SWarner Losh #include <sys/fcntl.h>
58592ffb21SWarner Losh #include <sys/uio.h>
59592ffb21SWarner Losh #include <sys/filio.h>
60592ffb21SWarner Losh #include <sys/rwlock.h>
61592ffb21SWarner Losh #include <sys/selinfo.h>
62592ffb21SWarner Losh #include <sys/sysctl.h>
63592ffb21SWarner Losh #include <sys/bus.h>
64592ffb21SWarner Losh #include <sys/queue.h>
65592ffb21SWarner Losh #include <sys/signalvar.h>
66592ffb21SWarner Losh #include <sys/poll.h>
67592ffb21SWarner Losh #include <sys/sbuf.h>
68592ffb21SWarner Losh #include <sys/taskqueue.h>
69592ffb21SWarner Losh #include <sys/tree.h>
70592ffb21SWarner Losh #include <sys/vmmeter.h>
71592ffb21SWarner Losh #include <vm/vm.h>
72592ffb21SWarner Losh #include <vm/pmap.h>
73592ffb21SWarner Losh #include <vm/vm_extern.h>
74592ffb21SWarner Losh #include <vm/vm_kern.h>
75592ffb21SWarner Losh #include <vm/vm_map.h>
76592ffb21SWarner Losh #include <vm/vm_object.h>
77592ffb21SWarner Losh #include <vm/vm_page.h>
78592ffb21SWarner Losh #include <vm/vm_pager.h>
79592ffb21SWarner Losh #include <vm/vm_param.h>
80592ffb21SWarner Losh #include <vm/vm_phys.h>
81592ffb21SWarner Losh #include <machine/bus.h>
82592ffb21SWarner Losh #include <machine/resource.h>
83592ffb21SWarner Losh #if defined(__i386__) || defined(__amd64__)
84592ffb21SWarner Losh #include <machine/specialreg.h>
85592ffb21SWarner Losh #endif
86592ffb21SWarner Losh #include <machine/sysarch.h>
87592ffb21SWarner Losh #include <sys/endian.h>
88592ffb21SWarner Losh #include <sys/mman.h>
89592ffb21SWarner Losh #include <sys/rman.h>
90592ffb21SWarner Losh #include <sys/memrange.h>
91592ffb21SWarner Losh #include <dev/agp/agpvar.h>
92592ffb21SWarner Losh #include <sys/agpio.h>
93592ffb21SWarner Losh #include <sys/mutex.h>
94592ffb21SWarner Losh #include <dev/pci/pcivar.h>
95592ffb21SWarner Losh #include <dev/pci/pcireg.h>
96592ffb21SWarner Losh #include <sys/selinfo.h>
97592ffb21SWarner Losh #include <sys/bus.h>
98592ffb21SWarner Losh 
99592ffb21SWarner Losh #include <dev/drm2/drm.h>
100592ffb21SWarner Losh #include <dev/drm2/drm_sarea.h>
101592ffb21SWarner Losh 
102592ffb21SWarner Losh #include <dev/drm2/drm_atomic.h>
103592ffb21SWarner Losh #include <dev/drm2/drm_linux_list.h>
104592ffb21SWarner Losh #include <dev/drm2/drm_gem_names.h>
105592ffb21SWarner Losh 
106592ffb21SWarner Losh #include <dev/drm2/drm_os_freebsd.h>
107592ffb21SWarner Losh 
108592ffb21SWarner Losh #if defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))
109592ffb21SWarner Losh #define __OS_HAS_AGP 1
110592ffb21SWarner Losh #else
111592ffb21SWarner Losh #define __OS_HAS_AGP 0
112592ffb21SWarner Losh #endif
113592ffb21SWarner Losh #if defined(CONFIG_MTRR)
114592ffb21SWarner Losh #define __OS_HAS_MTRR 1
115592ffb21SWarner Losh #else
116592ffb21SWarner Losh #define __OS_HAS_MTRR 0
117592ffb21SWarner Losh #endif
118592ffb21SWarner Losh 
119592ffb21SWarner Losh struct drm_file;
120592ffb21SWarner Losh struct drm_device;
121592ffb21SWarner Losh 
122592ffb21SWarner Losh #include <dev/drm2/drm_hashtab.h>
123592ffb21SWarner Losh #include <dev/drm2/drm_mm.h>
124592ffb21SWarner Losh 
125592ffb21SWarner Losh #include "opt_drm.h"
126592ffb21SWarner Losh #include "opt_syscons.h"
127592ffb21SWarner Losh #ifdef DRM_DEBUG
128592ffb21SWarner Losh #undef DRM_DEBUG
129592ffb21SWarner Losh #define DRM_DEBUG_DEFAULT_ON 1
130592ffb21SWarner Losh #endif /* DRM_DEBUG */
131592ffb21SWarner Losh 
132592ffb21SWarner Losh #define	DRM_DEBUGBITS_DEBUG		0x1
133592ffb21SWarner Losh #define	DRM_DEBUGBITS_KMS		0x2
134592ffb21SWarner Losh #define	DRM_DEBUGBITS_FAILED_IOCTL	0x4
135592ffb21SWarner Losh 
136592ffb21SWarner Losh #undef DRM_LINUX
137592ffb21SWarner Losh #define DRM_LINUX 0
138592ffb21SWarner Losh 
139592ffb21SWarner Losh /***********************************************************************/
140592ffb21SWarner Losh /** \name DRM template customization defaults */
141592ffb21SWarner Losh /*@{*/
142592ffb21SWarner Losh 
143592ffb21SWarner Losh /* driver capabilities and requirements mask */
144592ffb21SWarner Losh #define DRIVER_USE_AGP     0x1
145592ffb21SWarner Losh #define DRIVER_REQUIRE_AGP 0x2
146592ffb21SWarner Losh #define DRIVER_USE_MTRR    0x4
147592ffb21SWarner Losh #define DRIVER_PCI_DMA     0x8
148592ffb21SWarner Losh #define DRIVER_SG          0x10
149592ffb21SWarner Losh #define DRIVER_HAVE_DMA    0x20
150592ffb21SWarner Losh #define DRIVER_HAVE_IRQ    0x40
151592ffb21SWarner Losh #define DRIVER_IRQ_SHARED  0x80
152592ffb21SWarner Losh #define DRIVER_IRQ_VBL     0x100
153592ffb21SWarner Losh #define DRIVER_DMA_QUEUE   0x200
154592ffb21SWarner Losh #define DRIVER_FB_DMA      0x400
155592ffb21SWarner Losh #define DRIVER_IRQ_VBL2    0x800
156592ffb21SWarner Losh #define DRIVER_GEM         0x1000
157592ffb21SWarner Losh #define DRIVER_MODESET     0x2000
158592ffb21SWarner Losh #define DRIVER_PRIME       0x4000
159592ffb21SWarner Losh 
160592ffb21SWarner Losh #define DRIVER_BUS_PCI 0x1
161592ffb21SWarner Losh #define DRIVER_BUS_PLATFORM 0x2
162592ffb21SWarner Losh #define DRIVER_BUS_USB 0x3
163592ffb21SWarner Losh 
164592ffb21SWarner Losh /***********************************************************************/
165592ffb21SWarner Losh /** \name Begin the DRM... */
166592ffb21SWarner Losh /*@{*/
167592ffb21SWarner Losh 
168592ffb21SWarner Losh #define DRM_DEBUG_CODE 2	  /**< Include debugging code if > 1, then
169592ffb21SWarner Losh 				     also include looping detection. */
170592ffb21SWarner Losh 
171592ffb21SWarner Losh #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
172592ffb21SWarner Losh #define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
173592ffb21SWarner Losh #define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
174592ffb21SWarner Losh #define DRM_LOOPING_LIMIT     5000000
175592ffb21SWarner Losh #define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
176592ffb21SWarner Losh #define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
177592ffb21SWarner Losh 
178592ffb21SWarner Losh #define DRM_FLAG_DEBUG	  0x01
179592ffb21SWarner Losh 
180592ffb21SWarner Losh #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
181592ffb21SWarner Losh #define DRM_MAP_HASH_OFFSET 0x10000000
182592ffb21SWarner Losh 
183592ffb21SWarner Losh /*@}*/
184592ffb21SWarner Losh 
185592ffb21SWarner Losh /***********************************************************************/
186592ffb21SWarner Losh /** \name Macros to make printk easier */
187592ffb21SWarner Losh /*@{*/
188592ffb21SWarner Losh 
189592ffb21SWarner Losh /**
190592ffb21SWarner Losh  * Error output.
191592ffb21SWarner Losh  *
192592ffb21SWarner Losh  * \param fmt printf() like format string.
193592ffb21SWarner Losh  * \param arg arguments
194592ffb21SWarner Losh  */
195592ffb21SWarner Losh #define DRM_ERROR(fmt, ...) \
196592ffb21SWarner Losh 	printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt,		\
197592ffb21SWarner Losh 	    DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
198592ffb21SWarner Losh 
199592ffb21SWarner Losh #define DRM_WARNING(fmt, ...)  printf("warning: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
200592ffb21SWarner Losh #define DRM_INFO(fmt, ...)  printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
201592ffb21SWarner Losh 
202592ffb21SWarner Losh /**
203592ffb21SWarner Losh  * Debug output.
204592ffb21SWarner Losh  *
205592ffb21SWarner Losh  * \param fmt printf() like format string.
206592ffb21SWarner Losh  * \param arg arguments
207592ffb21SWarner Losh  */
208592ffb21SWarner Losh #define DRM_DEBUG(fmt, ...) do {					\
209592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0)			\
210592ffb21SWarner Losh 		printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID,	\
211592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
212592ffb21SWarner Losh } while (0)
213592ffb21SWarner Losh 
214592ffb21SWarner Losh #define DRM_DEBUG_DRIVER(fmt, ...) do {					\
215592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
216592ffb21SWarner Losh 		printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
217592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
218592ffb21SWarner Losh } while (0)
219592ffb21SWarner Losh 
220592ffb21SWarner Losh #define DRM_DEBUG_KMS(fmt, ...) do {					\
221592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
222592ffb21SWarner Losh 		printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
223592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
224592ffb21SWarner Losh } while (0)
225592ffb21SWarner Losh 
226592ffb21SWarner Losh #define DRM_LOG(fmt, ...) do {						\
227592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
228592ffb21SWarner Losh 		printf("[" DRM_NAME "]:pid%d:%s]" fmt, DRM_CURRENTPID,	\
229592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
230592ffb21SWarner Losh } while (0)
231592ffb21SWarner Losh 
232592ffb21SWarner Losh #define DRM_LOG_KMS(fmt, ...) do {					\
233592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
234592ffb21SWarner Losh 		printf("[" DRM_NAME "]:KMS:pid%d:%s]" fmt, DRM_CURRENTPID,\
235592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
236592ffb21SWarner Losh } while (0)
237592ffb21SWarner Losh 
238592ffb21SWarner Losh #define DRM_LOG_MODE(fmt, ...) do {					\
239592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
240592ffb21SWarner Losh 		printf("[" DRM_NAME "]:pid%d:%s]" fmt, DRM_CURRENTPID,	\
241592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
242592ffb21SWarner Losh } while (0)
243592ffb21SWarner Losh 
244592ffb21SWarner Losh #define DRM_LOG_DRIVER(fmt, ...) do {					\
245592ffb21SWarner Losh 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
246592ffb21SWarner Losh 		printf("[" DRM_NAME "]:KMS:pid%d:%s]" fmt, DRM_CURRENTPID,\
247592ffb21SWarner Losh 			__func__ , ##__VA_ARGS__);			\
248592ffb21SWarner Losh } while (0)
249592ffb21SWarner Losh 
250592ffb21SWarner Losh /*@}*/
251592ffb21SWarner Losh 
252592ffb21SWarner Losh /***********************************************************************/
253592ffb21SWarner Losh /** \name Internal types and structures */
254592ffb21SWarner Losh /*@{*/
255592ffb21SWarner Losh 
256592ffb21SWarner Losh #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
257592ffb21SWarner Losh 
258592ffb21SWarner Losh #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
259592ffb21SWarner Losh #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
260592ffb21SWarner Losh 
261592ffb21SWarner Losh #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
262592ffb21SWarner Losh 
263592ffb21SWarner Losh /**
264592ffb21SWarner Losh  * Test that the hardware lock is held by the caller, returning otherwise.
265592ffb21SWarner Losh  *
266592ffb21SWarner Losh  * \param dev DRM device.
267592ffb21SWarner Losh  * \param filp file pointer of the caller.
268592ffb21SWarner Losh  */
269592ffb21SWarner Losh #define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
270592ffb21SWarner Losh do {										\
271592ffb21SWarner Losh 	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
272592ffb21SWarner Losh 	    _file_priv->master->lock.file_priv != _file_priv)	{		\
273592ffb21SWarner Losh 		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
274592ffb21SWarner Losh 			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
275592ffb21SWarner Losh 			   _file_priv->master->lock.file_priv, _file_priv);	\
276592ffb21SWarner Losh 		return -EINVAL;							\
277592ffb21SWarner Losh 	}									\
278592ffb21SWarner Losh } while (0)
279592ffb21SWarner Losh 
280592ffb21SWarner Losh /**
281592ffb21SWarner Losh  * Ioctl function type.
282592ffb21SWarner Losh  *
283592ffb21SWarner Losh  * \param inode device inode.
284592ffb21SWarner Losh  * \param file_priv DRM file private pointer.
285592ffb21SWarner Losh  * \param cmd command.
286592ffb21SWarner Losh  * \param arg argument.
287592ffb21SWarner Losh  */
288592ffb21SWarner Losh typedef int drm_ioctl_t(struct drm_device *dev, void *data,
289592ffb21SWarner Losh 			struct drm_file *file_priv);
290592ffb21SWarner Losh 
291592ffb21SWarner Losh #define DRM_IOCTL_NR(n)                ((n) & 0xff)
292592ffb21SWarner Losh #define DRM_MAJOR       226
293592ffb21SWarner Losh 
294592ffb21SWarner Losh #define DRM_AUTH	0x1
295592ffb21SWarner Losh #define	DRM_MASTER	0x2
296592ffb21SWarner Losh #define DRM_ROOT_ONLY	0x4
297592ffb21SWarner Losh #define DRM_CONTROL_ALLOW 0x8
298592ffb21SWarner Losh #define DRM_UNLOCKED	0x10
299592ffb21SWarner Losh 
300592ffb21SWarner Losh struct drm_ioctl_desc {
301592ffb21SWarner Losh 	unsigned long cmd;
302592ffb21SWarner Losh 	int flags;
303592ffb21SWarner Losh 	drm_ioctl_t *func;
304592ffb21SWarner Losh 	unsigned int cmd_drv;
305592ffb21SWarner Losh };
306592ffb21SWarner Losh 
307592ffb21SWarner Losh /**
308592ffb21SWarner Losh  * Creates a driver or general drm_ioctl_desc array entry for the given
309592ffb21SWarner Losh  * ioctl, for use by drm_ioctl().
310592ffb21SWarner Losh  */
311592ffb21SWarner Losh 
312592ffb21SWarner Losh #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
313592ffb21SWarner Losh 	[DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, .cmd_drv = 0}
314592ffb21SWarner Losh 
315592ffb21SWarner Losh #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)			\
316592ffb21SWarner Losh 	[DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
317592ffb21SWarner Losh 
318592ffb21SWarner Losh struct drm_magic_entry {
319592ffb21SWarner Losh 	struct list_head head;
320592ffb21SWarner Losh 	struct drm_hash_item hash_item;
321592ffb21SWarner Losh 	struct drm_file *priv;
322592ffb21SWarner Losh };
323592ffb21SWarner Losh 
324592ffb21SWarner Losh /**
325592ffb21SWarner Losh  * DMA buffer.
326592ffb21SWarner Losh  */
327592ffb21SWarner Losh struct drm_buf {
328592ffb21SWarner Losh 	int idx;		       /**< Index into master buflist */
329592ffb21SWarner Losh 	int total;		       /**< Buffer size */
330592ffb21SWarner Losh 	int order;		       /**< log-base-2(total) */
331592ffb21SWarner Losh 	int used;		       /**< Amount of buffer in use (for DMA) */
332592ffb21SWarner Losh 	unsigned long offset;	       /**< Byte offset (used internally) */
333592ffb21SWarner Losh 	void *address;		       /**< Address of buffer */
334592ffb21SWarner Losh 	unsigned long bus_address;     /**< Bus address of buffer */
335592ffb21SWarner Losh 	struct drm_buf *next;	       /**< Kernel-only: used for free list */
336592ffb21SWarner Losh 	__volatile__ int waiting;      /**< On kernel DMA queue */
337592ffb21SWarner Losh 	__volatile__ int pending;      /**< On hardware DMA queue */
338592ffb21SWarner Losh 	struct drm_file *file_priv;    /**< Private of holding file descr */
339592ffb21SWarner Losh 	int context;		       /**< Kernel queue for this buffer */
340592ffb21SWarner Losh 	int while_locked;	       /**< Dispatch this buffer while locked */
341592ffb21SWarner Losh 	enum {
342592ffb21SWarner Losh 		DRM_LIST_NONE = 0,
343592ffb21SWarner Losh 		DRM_LIST_FREE = 1,
344592ffb21SWarner Losh 		DRM_LIST_WAIT = 2,
345592ffb21SWarner Losh 		DRM_LIST_PEND = 3,
346592ffb21SWarner Losh 		DRM_LIST_PRIO = 4,
347592ffb21SWarner Losh 		DRM_LIST_RECLAIM = 5
348592ffb21SWarner Losh 	} list;			       /**< Which list we're on */
349592ffb21SWarner Losh 
350592ffb21SWarner Losh 	int dev_priv_size;		 /**< Size of buffer private storage */
351592ffb21SWarner Losh 	void *dev_private;		 /**< Per-buffer private storage */
352592ffb21SWarner Losh };
353592ffb21SWarner Losh 
354592ffb21SWarner Losh struct drm_freelist {
355592ffb21SWarner Losh 	int initialized;	       /**< Freelist in use */
356592ffb21SWarner Losh 	atomic_t count;		       /**< Number of free buffers */
357592ffb21SWarner Losh 	struct drm_buf *next;	       /**< End pointer */
358592ffb21SWarner Losh 
359592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
360592ffb21SWarner Losh 	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
361592ffb21SWarner Losh #endif /* defined(FREEBSD_NOTYET) */
362592ffb21SWarner Losh 	int low_mark;		       /**< Low water mark */
363592ffb21SWarner Losh 	int high_mark;		       /**< High water mark */
364592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
365592ffb21SWarner Losh 	atomic_t wfh;		       /**< If waiting for high mark */
366592ffb21SWarner Losh 	spinlock_t lock;
367592ffb21SWarner Losh #endif /* defined(FREEBSD_NOTYET) */
368592ffb21SWarner Losh };
369592ffb21SWarner Losh 
370592ffb21SWarner Losh typedef struct drm_dma_handle {
371592ffb21SWarner Losh 	void *vaddr;
372592ffb21SWarner Losh 	bus_addr_t busaddr;
373592ffb21SWarner Losh 	bus_dma_tag_t tag;
374592ffb21SWarner Losh 	bus_dmamap_t map;
375592ffb21SWarner Losh } drm_dma_handle_t;
376592ffb21SWarner Losh 
377592ffb21SWarner Losh /**
378592ffb21SWarner Losh  * Buffer entry.  There is one of this for each buffer size order.
379592ffb21SWarner Losh  */
380592ffb21SWarner Losh struct drm_buf_entry {
381592ffb21SWarner Losh 	int buf_size;			/**< size */
382592ffb21SWarner Losh 	int buf_count;			/**< number of buffers */
383592ffb21SWarner Losh 	struct drm_buf *buflist;		/**< buffer list */
384592ffb21SWarner Losh 	int seg_count;
385592ffb21SWarner Losh 	int page_order;
386592ffb21SWarner Losh 	struct drm_dma_handle **seglist;
387592ffb21SWarner Losh 
388592ffb21SWarner Losh 	struct drm_freelist freelist;
389592ffb21SWarner Losh };
390592ffb21SWarner Losh 
391592ffb21SWarner Losh /* Event queued up for userspace to read */
392592ffb21SWarner Losh struct drm_pending_event {
393592ffb21SWarner Losh 	struct drm_event *event;
394592ffb21SWarner Losh 	struct list_head link;
395592ffb21SWarner Losh 	struct drm_file *file_priv;
396592ffb21SWarner Losh 	pid_t pid; /* pid of requester, no guarantee it's valid by the time
397592ffb21SWarner Losh 		      we deliver the event, for tracing only */
398592ffb21SWarner Losh 	void (*destroy)(struct drm_pending_event *event);
399592ffb21SWarner Losh };
400592ffb21SWarner Losh 
401592ffb21SWarner Losh /* initial implementaton using a linked list - todo hashtab */
402592ffb21SWarner Losh struct drm_prime_file_private {
403592ffb21SWarner Losh 	struct list_head head;
404592ffb21SWarner Losh 	struct mtx lock;
405592ffb21SWarner Losh };
406592ffb21SWarner Losh 
407592ffb21SWarner Losh struct drm_file {
408592ffb21SWarner Losh 	int authenticated;
409592ffb21SWarner Losh 	pid_t pid;
410592ffb21SWarner Losh 	uid_t uid;
411592ffb21SWarner Losh 	drm_magic_t magic;
412592ffb21SWarner Losh 	unsigned long ioctl_count;
413592ffb21SWarner Losh 	struct list_head lhead;
414592ffb21SWarner Losh 	struct drm_minor *minor;
415592ffb21SWarner Losh 	unsigned long lock_count;
416592ffb21SWarner Losh 
417592ffb21SWarner Losh 	void *driver_priv;
418592ffb21SWarner Losh 	struct drm_gem_names object_names;
419592ffb21SWarner Losh 
420592ffb21SWarner Losh 	int is_master; /* this file private is a master for a minor */
421592ffb21SWarner Losh 	struct drm_master *master; /* master this node is currently associated with
422592ffb21SWarner Losh 				      N.B. not always minor->master */
423592ffb21SWarner Losh 	struct list_head fbs;
424592ffb21SWarner Losh 
425592ffb21SWarner Losh 	struct selinfo event_poll;
426592ffb21SWarner Losh 	struct list_head event_list;
427592ffb21SWarner Losh 	int event_space;
428592ffb21SWarner Losh 
429592ffb21SWarner Losh 	struct drm_prime_file_private prime;
430592ffb21SWarner Losh };
431592ffb21SWarner Losh 
432592ffb21SWarner Losh /**
433592ffb21SWarner Losh  * Lock data.
434592ffb21SWarner Losh  */
435592ffb21SWarner Losh struct drm_lock_data {
436592ffb21SWarner Losh 	struct drm_hw_lock *hw_lock;	/**< Hardware lock */
437592ffb21SWarner Losh 	/** Private of lock holder's file (NULL=kernel) */
438592ffb21SWarner Losh 	struct drm_file *file_priv;
439592ffb21SWarner Losh 	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
440592ffb21SWarner Losh 	unsigned long lock_time;	/**< Time of last lock in jiffies */
441592ffb21SWarner Losh 	struct mtx spinlock;
442592ffb21SWarner Losh 	uint32_t kernel_waiters;
443592ffb21SWarner Losh 	uint32_t user_waiters;
444592ffb21SWarner Losh 	int idle_has_lock;
445592ffb21SWarner Losh };
446592ffb21SWarner Losh 
447592ffb21SWarner Losh /**
448592ffb21SWarner Losh  * DMA data.
449592ffb21SWarner Losh  */
450592ffb21SWarner Losh struct drm_device_dma {
451592ffb21SWarner Losh 
452592ffb21SWarner Losh 	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
453592ffb21SWarner Losh 	int buf_count;			/**< total number of buffers */
454592ffb21SWarner Losh 	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
455592ffb21SWarner Losh 	int seg_count;
456592ffb21SWarner Losh 	int page_count;			/**< number of pages */
457592ffb21SWarner Losh 	unsigned long *pagelist;	/**< page list */
458592ffb21SWarner Losh 	unsigned long byte_count;
459592ffb21SWarner Losh 	enum {
460592ffb21SWarner Losh 		_DRM_DMA_USE_AGP = 0x01,
461592ffb21SWarner Losh 		_DRM_DMA_USE_SG = 0x02,
462592ffb21SWarner Losh 		_DRM_DMA_USE_FB = 0x04,
463592ffb21SWarner Losh 		_DRM_DMA_USE_PCI_RO = 0x08
464592ffb21SWarner Losh 	} flags;
465592ffb21SWarner Losh 
466592ffb21SWarner Losh };
467592ffb21SWarner Losh 
468592ffb21SWarner Losh /**
469592ffb21SWarner Losh  * AGP memory entry.  Stored as a doubly linked list.
470592ffb21SWarner Losh  */
471592ffb21SWarner Losh struct drm_agp_mem {
472592ffb21SWarner Losh 	unsigned long handle;		/**< handle */
473592ffb21SWarner Losh 	DRM_AGP_MEM *memory;
474592ffb21SWarner Losh 	unsigned long bound;		/**< address */
475592ffb21SWarner Losh 	int pages;
476592ffb21SWarner Losh 	struct list_head head;
477592ffb21SWarner Losh };
478592ffb21SWarner Losh 
479592ffb21SWarner Losh /**
480592ffb21SWarner Losh  * AGP data.
481592ffb21SWarner Losh  *
482592ffb21SWarner Losh  * \sa drm_agp_init() and drm_device::agp.
483592ffb21SWarner Losh  */
484592ffb21SWarner Losh struct drm_agp_head {
485592ffb21SWarner Losh 	DRM_AGP_KERN agp_info;		/**< AGP device information */
486592ffb21SWarner Losh 	struct list_head memory;
487592ffb21SWarner Losh 	unsigned long mode;		/**< AGP mode */
488592ffb21SWarner Losh 	device_t bridge;
489592ffb21SWarner Losh 	int enabled;			/**< whether the AGP bus as been enabled */
490592ffb21SWarner Losh 	int acquired;			/**< whether the AGP device has been acquired */
491592ffb21SWarner Losh 	unsigned long base;
492592ffb21SWarner Losh 	int agp_mtrr;
493592ffb21SWarner Losh 	int cant_use_aperture;
494592ffb21SWarner Losh };
495592ffb21SWarner Losh 
496592ffb21SWarner Losh /**
497592ffb21SWarner Losh  * Scatter-gather memory.
498592ffb21SWarner Losh  */
499592ffb21SWarner Losh struct drm_sg_mem {
500592ffb21SWarner Losh 	vm_offset_t vaddr;
501592ffb21SWarner Losh 	vm_paddr_t *busaddr;
502592ffb21SWarner Losh 	vm_pindex_t pages;
503592ffb21SWarner Losh };
504592ffb21SWarner Losh 
505592ffb21SWarner Losh struct drm_sigdata {
506592ffb21SWarner Losh 	int context;
507592ffb21SWarner Losh 	struct drm_hw_lock *lock;
508592ffb21SWarner Losh };
509592ffb21SWarner Losh 
510592ffb21SWarner Losh /**
511592ffb21SWarner Losh  * Kernel side of a mapping
512592ffb21SWarner Losh  */
513592ffb21SWarner Losh #define DRM_MAP_HANDLE_BITS	(sizeof(void *) == 4 ? 4 : 24)
514592ffb21SWarner Losh #define DRM_MAP_HANDLE_SHIFT	(sizeof(void *) * 8 - DRM_MAP_HANDLE_BITS)
515592ffb21SWarner Losh 
516592ffb21SWarner Losh struct drm_local_map {
517592ffb21SWarner Losh 	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
518592ffb21SWarner Losh 	unsigned long size;	 /**< Requested physical size (bytes) */
519592ffb21SWarner Losh 	enum drm_map_type type;	 /**< Type of memory to map */
520592ffb21SWarner Losh 	enum drm_map_flags flags;	 /**< Flags */
521592ffb21SWarner Losh 	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
522592ffb21SWarner Losh 				 /**< Kernel-space: kernel-virtual address */
523592ffb21SWarner Losh 	int mtrr;		 /**< MTRR slot used */
524592ffb21SWarner Losh 
525592ffb21SWarner Losh 				  /* Private data                         */
526592ffb21SWarner Losh 	drm_dma_handle_t *dmah;
527592ffb21SWarner Losh };
528592ffb21SWarner Losh 
529592ffb21SWarner Losh typedef struct drm_local_map drm_local_map_t;
530592ffb21SWarner Losh 
531592ffb21SWarner Losh /**
532592ffb21SWarner Losh  * Mappings list
533592ffb21SWarner Losh  */
534592ffb21SWarner Losh struct drm_map_list {
535592ffb21SWarner Losh 	struct list_head head;		/**< list head */
536592ffb21SWarner Losh 	struct drm_hash_item hash;
537592ffb21SWarner Losh 	struct drm_local_map *map;	/**< mapping */
538592ffb21SWarner Losh 	uint64_t user_token;
539592ffb21SWarner Losh 	struct drm_master *master;
540592ffb21SWarner Losh 	struct drm_mm_node *file_offset_node;	/**< fake offset */
541592ffb21SWarner Losh };
542592ffb21SWarner Losh 
543592ffb21SWarner Losh /**
544592ffb21SWarner Losh  * Context handle list
545592ffb21SWarner Losh  */
546592ffb21SWarner Losh struct drm_ctx_list {
547592ffb21SWarner Losh 	struct list_head head;		/**< list head */
548592ffb21SWarner Losh 	drm_context_t handle;		/**< context handle */
549592ffb21SWarner Losh 	struct drm_file *tag;		/**< associated fd private data */
550592ffb21SWarner Losh };
551592ffb21SWarner Losh 
552592ffb21SWarner Losh /* location of GART table */
553592ffb21SWarner Losh #define DRM_ATI_GART_MAIN 1
554592ffb21SWarner Losh #define DRM_ATI_GART_FB   2
555592ffb21SWarner Losh 
556592ffb21SWarner Losh #define DRM_ATI_GART_PCI 1
557592ffb21SWarner Losh #define DRM_ATI_GART_PCIE 2
558592ffb21SWarner Losh #define DRM_ATI_GART_IGP 3
559592ffb21SWarner Losh 
560592ffb21SWarner Losh struct drm_ati_pcigart_info {
561592ffb21SWarner Losh 	int gart_table_location;
562592ffb21SWarner Losh 	int gart_reg_if;
563592ffb21SWarner Losh 	void *addr;
564592ffb21SWarner Losh 	dma_addr_t bus_addr;
565592ffb21SWarner Losh 	dma_addr_t table_mask;
566592ffb21SWarner Losh 	struct drm_dma_handle *table_handle;
567592ffb21SWarner Losh 	struct drm_local_map mapping;
568592ffb21SWarner Losh 	int table_size;
569592ffb21SWarner Losh 	struct drm_dma_handle *dmah; /* handle for ATI PCIGART table FIXME */
570592ffb21SWarner Losh };
571592ffb21SWarner Losh 
572592ffb21SWarner Losh /**
573592ffb21SWarner Losh  * GEM specific mm private for tracking GEM objects
574592ffb21SWarner Losh  */
575592ffb21SWarner Losh struct drm_gem_mm {
576592ffb21SWarner Losh 	struct unrhdr *idxunr;
577592ffb21SWarner Losh 	struct drm_open_hash offset_hash; /**< User token hash table for maps */
578592ffb21SWarner Losh };
579592ffb21SWarner Losh 
580592ffb21SWarner Losh /**
581592ffb21SWarner Losh  * This structure defines the drm_mm memory object, which will be used by the
582592ffb21SWarner Losh  * DRM for its buffer objects.
583592ffb21SWarner Losh  */
584592ffb21SWarner Losh struct drm_gem_object {
585592ffb21SWarner Losh 	/** Reference count of this object */
586592ffb21SWarner Losh 	u_int refcount;
587592ffb21SWarner Losh 
588592ffb21SWarner Losh 	/** Handle count of this object. Each handle also holds a reference */
589592ffb21SWarner Losh 	atomic_t handle_count; /* number of handles on this object */
590592ffb21SWarner Losh 
591592ffb21SWarner Losh 	/** Related drm device */
592592ffb21SWarner Losh 	struct drm_device *dev;
593592ffb21SWarner Losh 
594592ffb21SWarner Losh 	/** File representing the shmem storage: filp in Linux parlance */
595592ffb21SWarner Losh 	vm_object_t vm_obj;
596592ffb21SWarner Losh 
597592ffb21SWarner Losh 	/* Mapping info for this object */
598592ffb21SWarner Losh 	bool on_map;
599592ffb21SWarner Losh 	struct drm_hash_item map_list;
600592ffb21SWarner Losh 
601592ffb21SWarner Losh 	/**
602592ffb21SWarner Losh 	 * Size of the object, in bytes.  Immutable over the object's
603592ffb21SWarner Losh 	 * lifetime.
604592ffb21SWarner Losh 	 */
605592ffb21SWarner Losh 	size_t size;
606592ffb21SWarner Losh 
607592ffb21SWarner Losh 	/**
608592ffb21SWarner Losh 	 * Global name for this object, starts at 1. 0 means unnamed.
609592ffb21SWarner Losh 	 * Access is covered by the object_name_lock in the related drm_device
610592ffb21SWarner Losh 	 */
611592ffb21SWarner Losh 	int name;
612592ffb21SWarner Losh 
613592ffb21SWarner Losh 	/**
614592ffb21SWarner Losh 	 * Memory domains. These monitor which caches contain read/write data
615592ffb21SWarner Losh 	 * related to the object. When transitioning from one set of domains
616592ffb21SWarner Losh 	 * to another, the driver is called to ensure that caches are suitably
617592ffb21SWarner Losh 	 * flushed and invalidated
618592ffb21SWarner Losh 	 */
619592ffb21SWarner Losh 	uint32_t read_domains;
620592ffb21SWarner Losh 	uint32_t write_domain;
621592ffb21SWarner Losh 
622592ffb21SWarner Losh 	/**
623592ffb21SWarner Losh 	 * While validating an exec operation, the
624592ffb21SWarner Losh 	 * new read/write domain values are computed here.
625592ffb21SWarner Losh 	 * They will be transferred to the above values
626592ffb21SWarner Losh 	 * at the point that any cache flushing occurs
627592ffb21SWarner Losh 	 */
628592ffb21SWarner Losh 	uint32_t pending_read_domains;
629592ffb21SWarner Losh 	uint32_t pending_write_domain;
630592ffb21SWarner Losh 
631592ffb21SWarner Losh 	void *driver_private;
632592ffb21SWarner Losh 
633592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
634592ffb21SWarner Losh 	/* dma buf exported from this GEM object */
635592ffb21SWarner Losh 	struct dma_buf *export_dma_buf;
636592ffb21SWarner Losh 
637592ffb21SWarner Losh 	/* dma buf attachment backing this object */
638592ffb21SWarner Losh 	struct dma_buf_attachment *import_attach;
639592ffb21SWarner Losh #endif /* FREEBSD_NOTYET */
640592ffb21SWarner Losh };
641592ffb21SWarner Losh 
642592ffb21SWarner Losh #include <dev/drm2/drm_crtc.h>
643592ffb21SWarner Losh 
644592ffb21SWarner Losh /* per-master structure */
645592ffb21SWarner Losh struct drm_master {
646592ffb21SWarner Losh 
647592ffb21SWarner Losh 	u_int refcount; /* refcount for this master */
648592ffb21SWarner Losh 
649592ffb21SWarner Losh 	struct list_head head; /**< each minor contains a list of masters */
650592ffb21SWarner Losh 	struct drm_minor *minor; /**< link back to minor we are a master for */
651592ffb21SWarner Losh 
652592ffb21SWarner Losh 	char *unique;			/**< Unique identifier: e.g., busid */
653592ffb21SWarner Losh 	int unique_len;			/**< Length of unique field */
654592ffb21SWarner Losh 	int unique_size;		/**< amount allocated */
655592ffb21SWarner Losh 
656592ffb21SWarner Losh 	int blocked;			/**< Blocked due to VC switch? */
657592ffb21SWarner Losh 
658592ffb21SWarner Losh 	/** \name Authentication */
659592ffb21SWarner Losh 	/*@{ */
660592ffb21SWarner Losh 	struct drm_open_hash magiclist;
661592ffb21SWarner Losh 	struct list_head magicfree;
662592ffb21SWarner Losh 	/*@} */
663592ffb21SWarner Losh 
664592ffb21SWarner Losh 	struct drm_lock_data lock;	/**< Information on hardware lock */
665592ffb21SWarner Losh 
666592ffb21SWarner Losh 	void *driver_priv; /**< Private structure for driver to use */
667592ffb21SWarner Losh };
668592ffb21SWarner Losh 
669592ffb21SWarner Losh /* Size of ringbuffer for vblank timestamps. Just double-buffer
670592ffb21SWarner Losh  * in initial implementation.
671592ffb21SWarner Losh  */
672592ffb21SWarner Losh #define DRM_VBLANKTIME_RBSIZE 2
673592ffb21SWarner Losh 
674592ffb21SWarner Losh /* Flags and return codes for get_vblank_timestamp() driver function. */
675592ffb21SWarner Losh #define DRM_CALLED_FROM_VBLIRQ 1
676592ffb21SWarner Losh #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
677592ffb21SWarner Losh #define DRM_VBLANKTIME_INVBL             (1 << 1)
678592ffb21SWarner Losh 
679592ffb21SWarner Losh /* get_scanout_position() return flags */
680592ffb21SWarner Losh #define DRM_SCANOUTPOS_VALID        (1 << 0)
681592ffb21SWarner Losh #define DRM_SCANOUTPOS_INVBL        (1 << 1)
682592ffb21SWarner Losh #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
683592ffb21SWarner Losh 
684592ffb21SWarner Losh struct drm_bus {
685592ffb21SWarner Losh 	int bus_type;
686592ffb21SWarner Losh 	int (*get_irq)(struct drm_device *dev);
687592ffb21SWarner Losh 	void (*free_irq)(struct drm_device *dev);
688592ffb21SWarner Losh 	const char *(*get_name)(struct drm_device *dev);
689592ffb21SWarner Losh 	int (*set_busid)(struct drm_device *dev, struct drm_master *master);
690592ffb21SWarner Losh 	int (*set_unique)(struct drm_device *dev, struct drm_master *master,
691592ffb21SWarner Losh 			  struct drm_unique *unique);
692592ffb21SWarner Losh 	int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
693592ffb21SWarner Losh 	/* hooks that are for PCI */
694592ffb21SWarner Losh 	int (*agp_init)(struct drm_device *dev);
695592ffb21SWarner Losh 
696592ffb21SWarner Losh };
697592ffb21SWarner Losh 
698592ffb21SWarner Losh /**
699592ffb21SWarner Losh  * DRM driver structure. This structure represent the common code for
700592ffb21SWarner Losh  * a family of cards. There will one drm_device for each card present
701592ffb21SWarner Losh  * in this family
702592ffb21SWarner Losh  */
703592ffb21SWarner Losh struct drm_driver {
704592ffb21SWarner Losh 	int (*load) (struct drm_device *, unsigned long flags);
705592ffb21SWarner Losh 	int (*firstopen) (struct drm_device *);
706592ffb21SWarner Losh 	int (*open) (struct drm_device *, struct drm_file *);
707592ffb21SWarner Losh 	void (*preclose) (struct drm_device *, struct drm_file *file_priv);
708592ffb21SWarner Losh 	void (*postclose) (struct drm_device *, struct drm_file *);
709592ffb21SWarner Losh 	void (*lastclose) (struct drm_device *);
710592ffb21SWarner Losh 	int (*unload) (struct drm_device *);
711592ffb21SWarner Losh 	int (*suspend) (struct drm_device *, pm_message_t state);
712592ffb21SWarner Losh 	int (*resume) (struct drm_device *);
713592ffb21SWarner Losh 	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
714592ffb21SWarner Losh 	int (*dma_quiescent) (struct drm_device *);
715592ffb21SWarner Losh 	int (*context_dtor) (struct drm_device *dev, int context);
716592ffb21SWarner Losh 
717592ffb21SWarner Losh 	/**
718592ffb21SWarner Losh 	 * get_vblank_counter - get raw hardware vblank counter
719592ffb21SWarner Losh 	 * @dev: DRM device
720592ffb21SWarner Losh 	 * @crtc: counter to fetch
721592ffb21SWarner Losh 	 *
722592ffb21SWarner Losh 	 * Driver callback for fetching a raw hardware vblank counter for @crtc.
723592ffb21SWarner Losh 	 * If a device doesn't have a hardware counter, the driver can simply
724592ffb21SWarner Losh 	 * return the value of drm_vblank_count. The DRM core will account for
725592ffb21SWarner Losh 	 * missed vblank events while interrupts where disabled based on system
726592ffb21SWarner Losh 	 * timestamps.
727592ffb21SWarner Losh 	 *
728592ffb21SWarner Losh 	 * Wraparound handling and loss of events due to modesetting is dealt
729592ffb21SWarner Losh 	 * with in the DRM core code.
730592ffb21SWarner Losh 	 *
731592ffb21SWarner Losh 	 * RETURNS
732592ffb21SWarner Losh 	 * Raw vblank counter value.
733592ffb21SWarner Losh 	 */
734592ffb21SWarner Losh 	u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
735592ffb21SWarner Losh 
736592ffb21SWarner Losh 	/**
737592ffb21SWarner Losh 	 * enable_vblank - enable vblank interrupt events
738592ffb21SWarner Losh 	 * @dev: DRM device
739592ffb21SWarner Losh 	 * @crtc: which irq to enable
740592ffb21SWarner Losh 	 *
741592ffb21SWarner Losh 	 * Enable vblank interrupts for @crtc.  If the device doesn't have
742592ffb21SWarner Losh 	 * a hardware vblank counter, this routine should be a no-op, since
743592ffb21SWarner Losh 	 * interrupts will have to stay on to keep the count accurate.
744592ffb21SWarner Losh 	 *
745592ffb21SWarner Losh 	 * RETURNS
746592ffb21SWarner Losh 	 * Zero on success, appropriate errno if the given @crtc's vblank
747592ffb21SWarner Losh 	 * interrupt cannot be enabled.
748592ffb21SWarner Losh 	 */
749592ffb21SWarner Losh 	int (*enable_vblank) (struct drm_device *dev, int crtc);
750592ffb21SWarner Losh 
751592ffb21SWarner Losh 	/**
752592ffb21SWarner Losh 	 * disable_vblank - disable vblank interrupt events
753592ffb21SWarner Losh 	 * @dev: DRM device
754592ffb21SWarner Losh 	 * @crtc: which irq to enable
755592ffb21SWarner Losh 	 *
756592ffb21SWarner Losh 	 * Disable vblank interrupts for @crtc.  If the device doesn't have
757592ffb21SWarner Losh 	 * a hardware vblank counter, this routine should be a no-op, since
758592ffb21SWarner Losh 	 * interrupts will have to stay on to keep the count accurate.
759592ffb21SWarner Losh 	 */
760592ffb21SWarner Losh 	void (*disable_vblank) (struct drm_device *dev, int crtc);
761592ffb21SWarner Losh 
762592ffb21SWarner Losh 	/**
763592ffb21SWarner Losh 	 * Called by \c drm_device_is_agp.  Typically used to determine if a
764592ffb21SWarner Losh 	 * card is really attached to AGP or not.
765592ffb21SWarner Losh 	 *
766592ffb21SWarner Losh 	 * \param dev  DRM device handle
767592ffb21SWarner Losh 	 *
768592ffb21SWarner Losh 	 * \returns
769592ffb21SWarner Losh 	 * One of three values is returned depending on whether or not the
770592ffb21SWarner Losh 	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
771592ffb21SWarner Losh 	 * (return of 1), or may or may not be AGP (return of 2).
772592ffb21SWarner Losh 	 */
773592ffb21SWarner Losh 	int (*device_is_agp) (struct drm_device *dev);
774592ffb21SWarner Losh 
775592ffb21SWarner Losh 	/**
776592ffb21SWarner Losh 	 * Called by vblank timestamping code.
777592ffb21SWarner Losh 	 *
778592ffb21SWarner Losh 	 * Return the current display scanout position from a crtc.
779592ffb21SWarner Losh 	 *
780592ffb21SWarner Losh 	 * \param dev  DRM device.
781592ffb21SWarner Losh 	 * \param crtc Id of the crtc to query.
782592ffb21SWarner Losh 	 * \param *vpos Target location for current vertical scanout position.
783592ffb21SWarner Losh 	 * \param *hpos Target location for current horizontal scanout position.
784592ffb21SWarner Losh 	 *
785592ffb21SWarner Losh 	 * Returns vpos as a positive number while in active scanout area.
786592ffb21SWarner Losh 	 * Returns vpos as a negative number inside vblank, counting the number
787592ffb21SWarner Losh 	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
788592ffb21SWarner Losh 	 * until start of active scanout / end of vblank."
789592ffb21SWarner Losh 	 *
790592ffb21SWarner Losh 	 * \return Flags, or'ed together as follows:
791592ffb21SWarner Losh 	 *
792592ffb21SWarner Losh 	 * DRM_SCANOUTPOS_VALID = Query successful.
793592ffb21SWarner Losh 	 * DRM_SCANOUTPOS_INVBL = Inside vblank.
794592ffb21SWarner Losh 	 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
795592ffb21SWarner Losh 	 * this flag means that returned position may be offset by a constant
796592ffb21SWarner Losh 	 * but unknown small number of scanlines wrt. real scanout position.
797592ffb21SWarner Losh 	 *
798592ffb21SWarner Losh 	 */
799592ffb21SWarner Losh 	int (*get_scanout_position) (struct drm_device *dev, int crtc,
800592ffb21SWarner Losh 				     int *vpos, int *hpos);
801592ffb21SWarner Losh 
802592ffb21SWarner Losh 	/**
803592ffb21SWarner Losh 	 * Called by \c drm_get_last_vbltimestamp. Should return a precise
804592ffb21SWarner Losh 	 * timestamp when the most recent VBLANK interval ended or will end.
805592ffb21SWarner Losh 	 *
806592ffb21SWarner Losh 	 * Specifically, the timestamp in @vblank_time should correspond as
807592ffb21SWarner Losh 	 * closely as possible to the time when the first video scanline of
808592ffb21SWarner Losh 	 * the video frame after the end of VBLANK will start scanning out,
809592ffb21SWarner Losh 	 * the time immediately after end of the VBLANK interval. If the
810592ffb21SWarner Losh 	 * @crtc is currently inside VBLANK, this will be a time in the future.
811592ffb21SWarner Losh 	 * If the @crtc is currently scanning out a frame, this will be the
812592ffb21SWarner Losh 	 * past start time of the current scanout. This is meant to adhere
813592ffb21SWarner Losh 	 * to the OpenML OML_sync_control extension specification.
814592ffb21SWarner Losh 	 *
815592ffb21SWarner Losh 	 * \param dev dev DRM device handle.
816592ffb21SWarner Losh 	 * \param crtc crtc for which timestamp should be returned.
817592ffb21SWarner Losh 	 * \param *max_error Maximum allowable timestamp error in nanoseconds.
818592ffb21SWarner Losh 	 *                   Implementation should strive to provide timestamp
819592ffb21SWarner Losh 	 *                   with an error of at most *max_error nanoseconds.
820592ffb21SWarner Losh 	 *                   Returns true upper bound on error for timestamp.
821592ffb21SWarner Losh 	 * \param *vblank_time Target location for returned vblank timestamp.
822592ffb21SWarner Losh 	 * \param flags 0 = Defaults, no special treatment needed.
823592ffb21SWarner Losh 	 * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
824592ffb21SWarner Losh 	 *	        irq handler. Some drivers need to apply some workarounds
825592ffb21SWarner Losh 	 *              for gpu-specific vblank irq quirks if flag is set.
826592ffb21SWarner Losh 	 *
827592ffb21SWarner Losh 	 * \returns
828592ffb21SWarner Losh 	 * Zero if timestamping isn't supported in current display mode or a
829592ffb21SWarner Losh 	 * negative number on failure. A positive status code on success,
830592ffb21SWarner Losh 	 * which describes how the vblank_time timestamp was computed.
831592ffb21SWarner Losh 	 */
832592ffb21SWarner Losh 	int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
833592ffb21SWarner Losh 				     int *max_error,
834592ffb21SWarner Losh 				     struct timeval *vblank_time,
835592ffb21SWarner Losh 				     unsigned flags);
836592ffb21SWarner Losh 
837592ffb21SWarner Losh 	/* these have to be filled in */
838592ffb21SWarner Losh 
839592ffb21SWarner Losh 	irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
840592ffb21SWarner Losh 	void (*irq_preinstall) (struct drm_device *dev);
841592ffb21SWarner Losh 	int (*irq_postinstall) (struct drm_device *dev);
842592ffb21SWarner Losh 	void (*irq_uninstall) (struct drm_device *dev);
843592ffb21SWarner Losh 	void (*set_version) (struct drm_device *dev,
844592ffb21SWarner Losh 			     struct drm_set_version *sv);
845592ffb21SWarner Losh 
846592ffb21SWarner Losh 	/* Master routines */
847592ffb21SWarner Losh 	int (*master_create)(struct drm_device *dev, struct drm_master *master);
848592ffb21SWarner Losh 	void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
849592ffb21SWarner Losh 	/**
850592ffb21SWarner Losh 	 * master_set is called whenever the minor master is set.
851592ffb21SWarner Losh 	 * master_drop is called whenever the minor master is dropped.
852592ffb21SWarner Losh 	 */
853592ffb21SWarner Losh 
854592ffb21SWarner Losh 	int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
855592ffb21SWarner Losh 			  bool from_open);
856592ffb21SWarner Losh 	void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
857592ffb21SWarner Losh 			    bool from_release);
858592ffb21SWarner Losh 
859592ffb21SWarner Losh 	/**
860592ffb21SWarner Losh 	 * Driver-specific constructor for drm_gem_objects, to set up
861592ffb21SWarner Losh 	 * obj->driver_private.
862592ffb21SWarner Losh 	 *
863592ffb21SWarner Losh 	 * Returns 0 on success.
864592ffb21SWarner Losh 	 */
865592ffb21SWarner Losh 	int (*gem_init_object) (struct drm_gem_object *obj);
866592ffb21SWarner Losh 	void (*gem_free_object) (struct drm_gem_object *obj);
867592ffb21SWarner Losh 	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
868592ffb21SWarner Losh 	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
869592ffb21SWarner Losh 
870592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
871592ffb21SWarner Losh 	/* prime: */
872592ffb21SWarner Losh 	/* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
873592ffb21SWarner Losh 	int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
874592ffb21SWarner Losh 				uint32_t handle, uint32_t flags, int *prime_fd);
875592ffb21SWarner Losh 	/* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
876592ffb21SWarner Losh 	int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
877592ffb21SWarner Losh 				int prime_fd, uint32_t *handle);
878592ffb21SWarner Losh 	/* export GEM -> dmabuf */
879592ffb21SWarner Losh 	struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
880592ffb21SWarner Losh 				struct drm_gem_object *obj, int flags);
881592ffb21SWarner Losh 	/* import dmabuf -> GEM */
882592ffb21SWarner Losh 	struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
883592ffb21SWarner Losh 				struct dma_buf *dma_buf);
884592ffb21SWarner Losh #endif /* defined(FREEBSD_NOTYET) */
885592ffb21SWarner Losh 
886592ffb21SWarner Losh 	/* dumb alloc support */
887592ffb21SWarner Losh 	int (*dumb_create)(struct drm_file *file_priv,
888592ffb21SWarner Losh 			   struct drm_device *dev,
889592ffb21SWarner Losh 			   struct drm_mode_create_dumb *args);
890592ffb21SWarner Losh 	int (*dumb_map_offset)(struct drm_file *file_priv,
891592ffb21SWarner Losh 			       struct drm_device *dev, uint32_t handle,
892592ffb21SWarner Losh 			       uint64_t *offset);
893592ffb21SWarner Losh 	int (*dumb_destroy)(struct drm_file *file_priv,
894592ffb21SWarner Losh 			    struct drm_device *dev,
895592ffb21SWarner Losh 			    uint32_t handle);
896592ffb21SWarner Losh 
897592ffb21SWarner Losh 	/* Driver private ops for this object */
898592ffb21SWarner Losh 	struct cdev_pager_ops *gem_pager_ops;
899592ffb21SWarner Losh 
900592ffb21SWarner Losh 	int	(*sysctl_init)(struct drm_device *dev,
901592ffb21SWarner Losh 		    struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
902592ffb21SWarner Losh 	void	(*sysctl_cleanup)(struct drm_device *dev);
903592ffb21SWarner Losh 
904592ffb21SWarner Losh 	int major;
905592ffb21SWarner Losh 	int minor;
906592ffb21SWarner Losh 	int patchlevel;
907592ffb21SWarner Losh 	char *name;
908592ffb21SWarner Losh 	char *desc;
909592ffb21SWarner Losh 	char *date;
910592ffb21SWarner Losh 
911592ffb21SWarner Losh 	u32 driver_features;
912592ffb21SWarner Losh 	int dev_priv_size;
913592ffb21SWarner Losh 	struct drm_ioctl_desc *ioctls;
914592ffb21SWarner Losh 	int num_ioctls;
915592ffb21SWarner Losh 	struct drm_bus *bus;
916592ffb21SWarner Losh #ifdef COMPAT_FREEBSD32
917592ffb21SWarner Losh 	struct drm_ioctl_desc *compat_ioctls;
918592ffb21SWarner Losh 	int *num_compat_ioctls;
919592ffb21SWarner Losh #endif
920592ffb21SWarner Losh 
921592ffb21SWarner Losh 	int	buf_priv_size;
922592ffb21SWarner Losh };
923592ffb21SWarner Losh 
924592ffb21SWarner Losh #define DRM_MINOR_UNASSIGNED 0
925592ffb21SWarner Losh #define DRM_MINOR_LEGACY 1
926592ffb21SWarner Losh #define DRM_MINOR_CONTROL 2
927592ffb21SWarner Losh #define DRM_MINOR_RENDER 3
928592ffb21SWarner Losh 
929592ffb21SWarner Losh /**
930592ffb21SWarner Losh  * DRM minor structure. This structure represents a drm minor number.
931592ffb21SWarner Losh  */
932592ffb21SWarner Losh struct drm_minor {
933592ffb21SWarner Losh 	int index;			/**< Minor device number */
934592ffb21SWarner Losh 	int type;                       /**< Control or render */
935592ffb21SWarner Losh 	struct cdev *device;		/**< Device number for mknod */
936592ffb21SWarner Losh 	device_t kdev;			/**< OS device */
937592ffb21SWarner Losh 	struct drm_device *dev;
938592ffb21SWarner Losh 
939592ffb21SWarner Losh 	struct drm_master *master; /* currently active master for this node */
940592ffb21SWarner Losh 	struct list_head master_list;
941592ffb21SWarner Losh 	struct drm_mode_group mode_group;
942592ffb21SWarner Losh 
943592ffb21SWarner Losh 	struct sigio *buf_sigio;	/* Processes waiting for SIGIO     */
944592ffb21SWarner Losh };
945592ffb21SWarner Losh 
946592ffb21SWarner Losh /* mode specified on the command line */
947592ffb21SWarner Losh struct drm_cmdline_mode {
948592ffb21SWarner Losh 	bool specified;
949592ffb21SWarner Losh 	bool refresh_specified;
950592ffb21SWarner Losh 	bool bpp_specified;
951592ffb21SWarner Losh 	int xres, yres;
952592ffb21SWarner Losh 	int bpp;
953592ffb21SWarner Losh 	int refresh;
954592ffb21SWarner Losh 	bool rb;
955592ffb21SWarner Losh 	bool interlace;
956592ffb21SWarner Losh 	bool cvt;
957592ffb21SWarner Losh 	bool margins;
958592ffb21SWarner Losh 	enum drm_connector_force force;
959592ffb21SWarner Losh };
960592ffb21SWarner Losh 
961592ffb21SWarner Losh 
962592ffb21SWarner Losh struct drm_pending_vblank_event {
963592ffb21SWarner Losh 	struct drm_pending_event base;
964592ffb21SWarner Losh 	int pipe;
965592ffb21SWarner Losh 	struct drm_event_vblank event;
966592ffb21SWarner Losh };
967592ffb21SWarner Losh 
968592ffb21SWarner Losh /**
969592ffb21SWarner Losh  * DRM device structure. This structure represent a complete card that
970592ffb21SWarner Losh  * may contain multiple heads.
971592ffb21SWarner Losh  */
972592ffb21SWarner Losh struct drm_device {
973592ffb21SWarner Losh 	int if_version;			/**< Highest interface version set */
974592ffb21SWarner Losh 
975592ffb21SWarner Losh 	/** \name Locks */
976592ffb21SWarner Losh 	/*@{ */
977592ffb21SWarner Losh 	struct mtx count_lock;		/**< For inuse, drm_device::open_count, drm_device::buf_use */
978592ffb21SWarner Losh 	struct sx dev_struct_lock;	/**< For others */
979592ffb21SWarner Losh 	/*@} */
980592ffb21SWarner Losh 
981592ffb21SWarner Losh 	/** \name Usage Counters */
982592ffb21SWarner Losh 	/*@{ */
983592ffb21SWarner Losh 	int open_count;			/**< Outstanding files open */
984592ffb21SWarner Losh 	atomic_t ioctl_count;		/**< Outstanding IOCTLs pending */
985592ffb21SWarner Losh 	atomic_t vma_count;		/**< Outstanding vma areas open */
986592ffb21SWarner Losh 	int buf_use;			/**< Buffers in use -- cannot alloc */
987592ffb21SWarner Losh 	atomic_t buf_alloc;		/**< Buffer allocation in progress */
988592ffb21SWarner Losh 	/*@} */
989592ffb21SWarner Losh 
990592ffb21SWarner Losh 	/** \name Performance counters */
991592ffb21SWarner Losh 	/*@{ */
992592ffb21SWarner Losh 	unsigned long counters;
993592ffb21SWarner Losh 	enum drm_stat_type types[15];
994592ffb21SWarner Losh 	atomic_t counts[15];
995592ffb21SWarner Losh 	/*@} */
996592ffb21SWarner Losh 
997592ffb21SWarner Losh 	struct list_head filelist;
998592ffb21SWarner Losh 
999592ffb21SWarner Losh 	/** \name Memory management */
1000592ffb21SWarner Losh 	/*@{ */
1001592ffb21SWarner Losh 	struct list_head maplist;	/**< Linked list of regions */
1002592ffb21SWarner Losh 	int map_count;			/**< Number of mappable regions */
1003592ffb21SWarner Losh 	struct drm_open_hash map_hash;	/**< User token hash table for maps */
1004592ffb21SWarner Losh 
1005592ffb21SWarner Losh 	/** \name Context handle management */
1006592ffb21SWarner Losh 	/*@{ */
1007592ffb21SWarner Losh 	struct list_head ctxlist;	/**< Linked list of context handles */
1008592ffb21SWarner Losh 	int ctx_count;			/**< Number of context handles */
1009592ffb21SWarner Losh 	struct mtx ctxlist_mutex;	/**< For ctxlist */
1010592ffb21SWarner Losh 	drm_local_map_t **context_sareas;
1011592ffb21SWarner Losh 	int max_context;
1012592ffb21SWarner Losh 	unsigned long *ctx_bitmap;
1013592ffb21SWarner Losh 
1014592ffb21SWarner Losh 	/*@} */
1015592ffb21SWarner Losh 
1016592ffb21SWarner Losh 	/** \name DMA support */
1017592ffb21SWarner Losh 	/*@{ */
1018592ffb21SWarner Losh 	struct drm_device_dma *dma;		/**< Optional pointer for DMA support */
1019592ffb21SWarner Losh 	/*@} */
1020592ffb21SWarner Losh 
1021592ffb21SWarner Losh 	/** \name Context support */
1022592ffb21SWarner Losh 	/*@{ */
1023592ffb21SWarner Losh 	int irq_enabled;		/**< True if irq handler is enabled */
1024592ffb21SWarner Losh 	atomic_t context_flag;		/**< Context swapping flag */
1025592ffb21SWarner Losh 	atomic_t interrupt_flag;	/**< Interruption handler flag */
1026592ffb21SWarner Losh 	atomic_t dma_flag;		/**< DMA dispatch flag */
1027592ffb21SWarner Losh 	wait_queue_head_t context_wait;	/**< Processes waiting on ctx switch */
1028592ffb21SWarner Losh 	int last_checked;		/**< Last context checked for DMA */
1029592ffb21SWarner Losh 	int last_context;		/**< Last current context */
1030592ffb21SWarner Losh 	unsigned long last_switch;	/**< jiffies at last context switch */
1031592ffb21SWarner Losh 	/*@} */
1032592ffb21SWarner Losh 
1033592ffb21SWarner Losh 	/** \name VBLANK IRQ support */
1034592ffb21SWarner Losh 	/*@{ */
1035592ffb21SWarner Losh 
1036592ffb21SWarner Losh 	/*
1037592ffb21SWarner Losh 	 * At load time, disabling the vblank interrupt won't be allowed since
1038592ffb21SWarner Losh 	 * old clients may not call the modeset ioctl and therefore misbehave.
1039592ffb21SWarner Losh 	 * Once the modeset ioctl *has* been called though, we can safely
1040592ffb21SWarner Losh 	 * disable them when unused.
1041592ffb21SWarner Losh 	 */
1042592ffb21SWarner Losh 	int vblank_disable_allowed;
1043592ffb21SWarner Losh 
1044592ffb21SWarner Losh 	atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
1045592ffb21SWarner Losh 	struct timeval *_vblank_time;   /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
1046592ffb21SWarner Losh 	struct mtx vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
1047592ffb21SWarner Losh 	struct mtx vbl_lock;
1048592ffb21SWarner Losh 	atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
1049592ffb21SWarner Losh 	u32 *last_vblank;               /* protected by dev->vbl_lock, used */
1050592ffb21SWarner Losh 					/* for wraparound handling */
1051592ffb21SWarner Losh 	int *vblank_enabled;            /* so we don't call enable more than
1052592ffb21SWarner Losh 					   once per disable */
1053592ffb21SWarner Losh 	int *vblank_inmodeset;          /* Display driver is setting mode */
1054592ffb21SWarner Losh 	u32 *last_vblank_wait;		/* Last vblank seqno waited per CRTC */
1055592ffb21SWarner Losh 	struct callout vblank_disable_callout;
1056592ffb21SWarner Losh 
1057592ffb21SWarner Losh 	u32 max_vblank_count;           /**< size of vblank counter register */
1058592ffb21SWarner Losh 
1059592ffb21SWarner Losh 	/**
1060592ffb21SWarner Losh 	 * List of events
1061592ffb21SWarner Losh 	 */
1062592ffb21SWarner Losh 	struct list_head vblank_event_list;
1063592ffb21SWarner Losh 	struct mtx event_lock;
1064592ffb21SWarner Losh 
1065592ffb21SWarner Losh 	/*@} */
1066592ffb21SWarner Losh 
1067592ffb21SWarner Losh 	struct drm_agp_head *agp;	/**< AGP data */
1068592ffb21SWarner Losh 
1069592ffb21SWarner Losh 	device_t dev;			/* Device instance from newbus */
1070592ffb21SWarner Losh 	uint16_t pci_device;		/* PCI device id */
1071592ffb21SWarner Losh 	uint16_t pci_vendor;		/* PCI vendor id */
1072592ffb21SWarner Losh 	uint16_t pci_subdevice;		/* PCI subsystem device id */
1073592ffb21SWarner Losh 	uint16_t pci_subvendor;		/* PCI subsystem vendor id */
1074592ffb21SWarner Losh 
1075592ffb21SWarner Losh 	struct drm_sg_mem *sg;	/**< Scatter gather memory */
1076592ffb21SWarner Losh 	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1077592ffb21SWarner Losh 	void *dev_private;		/**< device private data */
1078592ffb21SWarner Losh 	void *mm_private;
1079592ffb21SWarner Losh 	struct drm_sigdata sigdata;	   /**< For block_all_signals */
1080592ffb21SWarner Losh 	sigset_t sigmask;
1081592ffb21SWarner Losh 
1082592ffb21SWarner Losh 	struct drm_driver *driver;
1083592ffb21SWarner Losh 	struct drm_local_map *agp_buffer_map;
1084592ffb21SWarner Losh 	unsigned int agp_buffer_token;
1085592ffb21SWarner Losh 	struct drm_minor *control;		/**< Control node for card */
1086592ffb21SWarner Losh 	struct drm_minor *primary;		/**< render type primary screen head */
1087592ffb21SWarner Losh 
1088592ffb21SWarner Losh         struct drm_mode_config mode_config;	/**< Current mode config */
1089592ffb21SWarner Losh 
1090592ffb21SWarner Losh 	/** \name GEM information */
1091592ffb21SWarner Losh 	/*@{ */
1092592ffb21SWarner Losh 	struct sx object_name_lock;
1093592ffb21SWarner Losh 	struct drm_gem_names object_names;
1094592ffb21SWarner Losh 	/*@} */
1095592ffb21SWarner Losh 	int switch_power_state;
1096592ffb21SWarner Losh 
1097592ffb21SWarner Losh 	atomic_t unplugged; /* device has been unplugged or gone away */
1098592ffb21SWarner Losh 
1099592ffb21SWarner Losh 				/* Locks */
1100592ffb21SWarner Losh 	struct mtx	  dma_lock;	/* protects dev->dma */
1101592ffb21SWarner Losh 	struct mtx	  irq_lock;	/* protects irq condition checks */
1102592ffb21SWarner Losh 
1103592ffb21SWarner Losh 				/* Context support */
1104592ffb21SWarner Losh 	int		  irq;		/* Interrupt used by board	   */
1105592ffb21SWarner Losh 	int		  msi_enabled;	/* MSI enabled */
1106592ffb21SWarner Losh 	int		  irqrid;	/* Interrupt used by board */
1107592ffb21SWarner Losh 	struct resource   *irqr;	/* Resource for interrupt used by board	   */
1108592ffb21SWarner Losh 	void		  *irqh;	/* Handle from bus_setup_intr      */
1109592ffb21SWarner Losh 
1110592ffb21SWarner Losh 	/* Storage of resource pointers for drm_get_resource_* */
1111592ffb21SWarner Losh #define	DRM_MAX_PCI_RESOURCE	6
1112592ffb21SWarner Losh 	struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
1113592ffb21SWarner Losh 	int		  pcirid[DRM_MAX_PCI_RESOURCE];
1114592ffb21SWarner Losh 	struct mtx	  pcir_lock;
1115592ffb21SWarner Losh 
1116592ffb21SWarner Losh 	int		  pci_domain;
1117592ffb21SWarner Losh 	int		  pci_bus;
1118592ffb21SWarner Losh 	int		  pci_slot;
1119592ffb21SWarner Losh 	int		  pci_func;
1120592ffb21SWarner Losh 
1121592ffb21SWarner Losh 				/* Sysctl support */
1122592ffb21SWarner Losh 	struct drm_sysctl_info *sysctl;
1123592ffb21SWarner Losh 	int		  sysctl_node_idx;
1124592ffb21SWarner Losh 
1125592ffb21SWarner Losh 	void		  *drm_ttm_bdev;
1126592ffb21SWarner Losh 
1127592ffb21SWarner Losh 	void *sysctl_private;
1128592ffb21SWarner Losh 	char busid_str[128];
1129592ffb21SWarner Losh 	int modesetting;
1130592ffb21SWarner Losh 
1131592ffb21SWarner Losh 	const drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
1132592ffb21SWarner Losh };
1133592ffb21SWarner Losh 
1134592ffb21SWarner Losh #define DRM_SWITCH_POWER_ON 0
1135592ffb21SWarner Losh #define DRM_SWITCH_POWER_OFF 1
1136592ffb21SWarner Losh #define DRM_SWITCH_POWER_CHANGING 2
1137592ffb21SWarner Losh 
1138592ffb21SWarner Losh static __inline__ int drm_core_check_feature(struct drm_device *dev,
1139592ffb21SWarner Losh 					     int feature)
1140592ffb21SWarner Losh {
1141592ffb21SWarner Losh 	return ((dev->driver->driver_features & feature) ? 1 : 0);
1142592ffb21SWarner Losh }
1143592ffb21SWarner Losh 
1144592ffb21SWarner Losh static inline int drm_dev_to_irq(struct drm_device *dev)
1145592ffb21SWarner Losh {
1146592ffb21SWarner Losh 	return dev->driver->bus->get_irq(dev);
1147592ffb21SWarner Losh }
1148592ffb21SWarner Losh 
1149592ffb21SWarner Losh 
1150592ffb21SWarner Losh #if __OS_HAS_AGP
1151592ffb21SWarner Losh static inline int drm_core_has_AGP(struct drm_device *dev)
1152592ffb21SWarner Losh {
1153592ffb21SWarner Losh 	return drm_core_check_feature(dev, DRIVER_USE_AGP);
1154592ffb21SWarner Losh }
1155592ffb21SWarner Losh #else
1156592ffb21SWarner Losh #define drm_core_has_AGP(dev) (0)
1157592ffb21SWarner Losh #endif
1158592ffb21SWarner Losh 
1159592ffb21SWarner Losh #if __OS_HAS_MTRR
1160592ffb21SWarner Losh static inline int drm_core_has_MTRR(struct drm_device *dev)
1161592ffb21SWarner Losh {
1162592ffb21SWarner Losh 	return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1163592ffb21SWarner Losh }
1164592ffb21SWarner Losh 
1165592ffb21SWarner Losh #define DRM_MTRR_WC		MDF_WRITECOMBINE
1166592ffb21SWarner Losh 
1167592ffb21SWarner Losh int drm_mtrr_add(unsigned long offset, unsigned long size, unsigned int flags);
1168592ffb21SWarner Losh int drm_mtrr_del(int handle, unsigned long offset, unsigned long size, unsigned int flags);
1169592ffb21SWarner Losh 
1170592ffb21SWarner Losh #else
1171592ffb21SWarner Losh #define drm_core_has_MTRR(dev) (0)
1172592ffb21SWarner Losh 
1173592ffb21SWarner Losh #define DRM_MTRR_WC		0
1174592ffb21SWarner Losh 
1175592ffb21SWarner Losh static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1176592ffb21SWarner Losh 			       unsigned int flags)
1177592ffb21SWarner Losh {
1178592ffb21SWarner Losh 	return 0;
1179592ffb21SWarner Losh }
1180592ffb21SWarner Losh 
1181592ffb21SWarner Losh static inline int drm_mtrr_del(int handle, unsigned long offset,
1182592ffb21SWarner Losh 			       unsigned long size, unsigned int flags)
1183592ffb21SWarner Losh {
1184592ffb21SWarner Losh 	return 0;
1185592ffb21SWarner Losh }
1186592ffb21SWarner Losh #endif
1187592ffb21SWarner Losh 
1188592ffb21SWarner Losh /******************************************************************/
1189592ffb21SWarner Losh /** \name Internal function definitions */
1190592ffb21SWarner Losh /*@{*/
1191592ffb21SWarner Losh 
1192592ffb21SWarner Losh 				/* Driver support (drm_drv.h) */
1193592ffb21SWarner Losh d_ioctl_t drm_ioctl;
1194592ffb21SWarner Losh extern int drm_lastclose(struct drm_device *dev);
1195592ffb21SWarner Losh 
1196592ffb21SWarner Losh 				/* Device support (drm_fops.h) */
1197592ffb21SWarner Losh extern struct sx drm_global_mutex;
1198592ffb21SWarner Losh d_open_t drm_open;
1199592ffb21SWarner Losh d_read_t drm_read;
1200592ffb21SWarner Losh extern void drm_release(void *data);
1201592ffb21SWarner Losh 
1202592ffb21SWarner Losh 				/* Mapping support (drm_vm.h) */
1203592ffb21SWarner Losh d_mmap_t drm_mmap;
1204592ffb21SWarner Losh int	drm_mmap_single(struct cdev *kdev, vm_ooffset_t *offset,
1205592ffb21SWarner Losh 	    vm_size_t size, struct vm_object **obj_res, int nprot);
1206592ffb21SWarner Losh d_poll_t drm_poll;
1207592ffb21SWarner Losh 
1208592ffb21SWarner Losh 
1209592ffb21SWarner Losh 				/* Misc. IOCTL support (drm_ioctl.h) */
1210592ffb21SWarner Losh extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1211592ffb21SWarner Losh 			    struct drm_file *file_priv);
1212592ffb21SWarner Losh extern int drm_getunique(struct drm_device *dev, void *data,
1213592ffb21SWarner Losh 			 struct drm_file *file_priv);
1214592ffb21SWarner Losh extern int drm_setunique(struct drm_device *dev, void *data,
1215592ffb21SWarner Losh 			 struct drm_file *file_priv);
1216592ffb21SWarner Losh extern int drm_getmap(struct drm_device *dev, void *data,
1217592ffb21SWarner Losh 		      struct drm_file *file_priv);
1218592ffb21SWarner Losh extern int drm_getclient(struct drm_device *dev, void *data,
1219592ffb21SWarner Losh 			 struct drm_file *file_priv);
1220592ffb21SWarner Losh extern int drm_getstats(struct drm_device *dev, void *data,
1221592ffb21SWarner Losh 			struct drm_file *file_priv);
1222592ffb21SWarner Losh extern int drm_getcap(struct drm_device *dev, void *data,
1223592ffb21SWarner Losh 		      struct drm_file *file_priv);
1224592ffb21SWarner Losh extern int drm_setversion(struct drm_device *dev, void *data,
1225592ffb21SWarner Losh 			  struct drm_file *file_priv);
1226592ffb21SWarner Losh extern int drm_noop(struct drm_device *dev, void *data,
1227592ffb21SWarner Losh 		    struct drm_file *file_priv);
1228592ffb21SWarner Losh 
1229592ffb21SWarner Losh 				/* Context IOCTL support (drm_context.h) */
1230592ffb21SWarner Losh extern int drm_resctx(struct drm_device *dev, void *data,
1231592ffb21SWarner Losh 		      struct drm_file *file_priv);
1232592ffb21SWarner Losh extern int drm_addctx(struct drm_device *dev, void *data,
1233592ffb21SWarner Losh 		      struct drm_file *file_priv);
1234592ffb21SWarner Losh extern int drm_modctx(struct drm_device *dev, void *data,
1235592ffb21SWarner Losh 		      struct drm_file *file_priv);
1236592ffb21SWarner Losh extern int drm_getctx(struct drm_device *dev, void *data,
1237592ffb21SWarner Losh 		      struct drm_file *file_priv);
1238592ffb21SWarner Losh extern int drm_switchctx(struct drm_device *dev, void *data,
1239592ffb21SWarner Losh 			 struct drm_file *file_priv);
1240592ffb21SWarner Losh extern int drm_newctx(struct drm_device *dev, void *data,
1241592ffb21SWarner Losh 		      struct drm_file *file_priv);
1242592ffb21SWarner Losh extern int drm_rmctx(struct drm_device *dev, void *data,
1243592ffb21SWarner Losh 		     struct drm_file *file_priv);
1244592ffb21SWarner Losh 
1245592ffb21SWarner Losh extern int drm_ctxbitmap_init(struct drm_device *dev);
1246592ffb21SWarner Losh extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1247592ffb21SWarner Losh extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1248592ffb21SWarner Losh 
1249592ffb21SWarner Losh extern int drm_setsareactx(struct drm_device *dev, void *data,
1250592ffb21SWarner Losh 			   struct drm_file *file_priv);
1251592ffb21SWarner Losh extern int drm_getsareactx(struct drm_device *dev, void *data,
1252592ffb21SWarner Losh 			   struct drm_file *file_priv);
1253592ffb21SWarner Losh 
1254592ffb21SWarner Losh 				/* Authentication IOCTL support (drm_auth.h) */
1255592ffb21SWarner Losh extern int drm_getmagic(struct drm_device *dev, void *data,
1256592ffb21SWarner Losh 			struct drm_file *file_priv);
1257592ffb21SWarner Losh extern int drm_authmagic(struct drm_device *dev, void *data,
1258592ffb21SWarner Losh 			 struct drm_file *file_priv);
1259592ffb21SWarner Losh extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1260592ffb21SWarner Losh 
1261592ffb21SWarner Losh /* Cache management (drm_cache.c) */
1262592ffb21SWarner Losh void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1263592ffb21SWarner Losh void drm_clflush_virt_range(char *addr, unsigned long length);
1264592ffb21SWarner Losh 
1265592ffb21SWarner Losh 				/* Locking IOCTL support (drm_lock.h) */
1266592ffb21SWarner Losh extern int drm_lock(struct drm_device *dev, void *data,
1267592ffb21SWarner Losh 		    struct drm_file *file_priv);
1268592ffb21SWarner Losh extern int drm_unlock(struct drm_device *dev, void *data,
1269592ffb21SWarner Losh 		      struct drm_file *file_priv);
1270592ffb21SWarner Losh extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1271592ffb21SWarner Losh extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1272592ffb21SWarner Losh extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1273592ffb21SWarner Losh 
1274592ffb21SWarner Losh /*
1275592ffb21SWarner Losh  * These are exported to drivers so that they can implement fencing using
1276592ffb21SWarner Losh  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1277592ffb21SWarner Losh  */
1278592ffb21SWarner Losh 
1279592ffb21SWarner Losh extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1280592ffb21SWarner Losh 
1281592ffb21SWarner Losh 				/* Buffer management support (drm_bufs.h) */
1282592ffb21SWarner Losh extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1283592ffb21SWarner Losh extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1284592ffb21SWarner Losh extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1285592ffb21SWarner Losh 		      unsigned int size, enum drm_map_type type,
1286592ffb21SWarner Losh 		      enum drm_map_flags flags, struct drm_local_map **map_ptr);
1287592ffb21SWarner Losh extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1288592ffb21SWarner Losh 			    struct drm_file *file_priv);
1289592ffb21SWarner Losh extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1290592ffb21SWarner Losh extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1291592ffb21SWarner Losh extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1292592ffb21SWarner Losh 			   struct drm_file *file_priv);
1293592ffb21SWarner Losh extern int drm_addbufs(struct drm_device *dev, void *data,
1294592ffb21SWarner Losh 		       struct drm_file *file_priv);
1295592ffb21SWarner Losh extern int drm_infobufs(struct drm_device *dev, void *data,
1296592ffb21SWarner Losh 			struct drm_file *file_priv);
1297592ffb21SWarner Losh extern int drm_markbufs(struct drm_device *dev, void *data,
1298592ffb21SWarner Losh 			struct drm_file *file_priv);
1299592ffb21SWarner Losh extern int drm_freebufs(struct drm_device *dev, void *data,
1300592ffb21SWarner Losh 			struct drm_file *file_priv);
1301592ffb21SWarner Losh extern int drm_mapbufs(struct drm_device *dev, void *data,
1302592ffb21SWarner Losh 		       struct drm_file *file_priv);
1303592ffb21SWarner Losh extern int drm_order(unsigned long size);
1304592ffb21SWarner Losh 
1305592ffb21SWarner Losh 				/* DMA support (drm_dma.h) */
1306592ffb21SWarner Losh extern int drm_dma_setup(struct drm_device *dev);
1307592ffb21SWarner Losh extern void drm_dma_takedown(struct drm_device *dev);
1308592ffb21SWarner Losh extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1309592ffb21SWarner Losh extern void drm_core_reclaim_buffers(struct drm_device *dev,
1310592ffb21SWarner Losh 				     struct drm_file *filp);
1311592ffb21SWarner Losh 
1312592ffb21SWarner Losh 				/* IRQ support (drm_irq.h) */
1313592ffb21SWarner Losh extern int drm_control(struct drm_device *dev, void *data,
1314592ffb21SWarner Losh 		       struct drm_file *file_priv);
1315592ffb21SWarner Losh extern int drm_irq_install(struct drm_device *dev);
1316592ffb21SWarner Losh extern int drm_irq_uninstall(struct drm_device *dev);
1317592ffb21SWarner Losh 
1318592ffb21SWarner Losh extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1319592ffb21SWarner Losh extern int drm_wait_vblank(struct drm_device *dev, void *data,
1320592ffb21SWarner Losh 			   struct drm_file *filp);
1321592ffb21SWarner Losh extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1322592ffb21SWarner Losh extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1323592ffb21SWarner Losh extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1324592ffb21SWarner Losh 				     struct timeval *vblanktime);
1325592ffb21SWarner Losh extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1326592ffb21SWarner Losh 				     struct drm_pending_vblank_event *e);
1327592ffb21SWarner Losh extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1328592ffb21SWarner Losh extern int drm_vblank_get(struct drm_device *dev, int crtc);
1329592ffb21SWarner Losh extern void drm_vblank_put(struct drm_device *dev, int crtc);
1330592ffb21SWarner Losh extern void drm_vblank_off(struct drm_device *dev, int crtc);
1331592ffb21SWarner Losh extern void drm_vblank_cleanup(struct drm_device *dev);
1332592ffb21SWarner Losh extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1333592ffb21SWarner Losh 				     struct timeval *tvblank, unsigned flags);
1334592ffb21SWarner Losh extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1335592ffb21SWarner Losh 						 int crtc, int *max_error,
1336592ffb21SWarner Losh 						 struct timeval *vblank_time,
1337592ffb21SWarner Losh 						 unsigned flags,
1338592ffb21SWarner Losh 						 struct drm_crtc *refcrtc);
1339592ffb21SWarner Losh extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1340592ffb21SWarner Losh 
1341592ffb21SWarner Losh extern bool
1342592ffb21SWarner Losh drm_mode_parse_command_line_for_connector(const char *mode_option,
1343592ffb21SWarner Losh 					  struct drm_connector *connector,
1344592ffb21SWarner Losh 					  struct drm_cmdline_mode *mode);
1345592ffb21SWarner Losh 
1346592ffb21SWarner Losh extern struct drm_display_mode *
1347592ffb21SWarner Losh drm_mode_create_from_cmdline_mode(struct drm_device *dev,
1348592ffb21SWarner Losh 				  struct drm_cmdline_mode *cmd);
1349592ffb21SWarner Losh 
1350592ffb21SWarner Losh /* Modesetting support */
1351592ffb21SWarner Losh extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1352592ffb21SWarner Losh extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1353592ffb21SWarner Losh extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1354592ffb21SWarner Losh 			   struct drm_file *file_priv);
1355592ffb21SWarner Losh 
1356592ffb21SWarner Losh 
1357592ffb21SWarner Losh 				/* Stub support (drm_stub.h) */
1358592ffb21SWarner Losh extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1359592ffb21SWarner Losh 			       struct drm_file *file_priv);
1360592ffb21SWarner Losh extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1361592ffb21SWarner Losh 				struct drm_file *file_priv);
1362592ffb21SWarner Losh struct drm_master *drm_master_create(struct drm_minor *minor);
1363592ffb21SWarner Losh extern struct drm_master *drm_master_get(struct drm_master *master);
1364592ffb21SWarner Losh extern void drm_master_put(struct drm_master **master);
1365592ffb21SWarner Losh 
1366592ffb21SWarner Losh extern void drm_put_dev(struct drm_device *dev);
1367592ffb21SWarner Losh extern int drm_put_minor(struct drm_minor **minor);
1368592ffb21SWarner Losh extern void drm_unplug_dev(struct drm_device *dev);
1369592ffb21SWarner Losh extern unsigned int drm_debug;
1370592ffb21SWarner Losh extern unsigned int drm_notyet;
1371592ffb21SWarner Losh 
1372592ffb21SWarner Losh extern unsigned int drm_vblank_offdelay;
1373592ffb21SWarner Losh extern unsigned int drm_timestamp_precision;
1374592ffb21SWarner Losh extern unsigned int drm_timestamp_monotonic;
1375592ffb21SWarner Losh 
1376592ffb21SWarner Losh extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
1377592ffb21SWarner Losh 
1378592ffb21SWarner Losh 
1379592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
1380592ffb21SWarner Losh extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1381592ffb21SWarner Losh 		struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1382592ffb21SWarner Losh 		int *prime_fd);
1383592ffb21SWarner Losh extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1384592ffb21SWarner Losh 		struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1385592ffb21SWarner Losh 
1386592ffb21SWarner Losh extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1387592ffb21SWarner Losh 					struct drm_file *file_priv);
1388592ffb21SWarner Losh extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1389592ffb21SWarner Losh 					struct drm_file *file_priv);
1390592ffb21SWarner Losh 
1391592ffb21SWarner Losh extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages,
1392592ffb21SWarner Losh 					    dma_addr_t *addrs, int max_pages);
1393592ffb21SWarner Losh extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
1394592ffb21SWarner Losh extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1395592ffb21SWarner Losh 
1396592ffb21SWarner Losh 
1397592ffb21SWarner Losh void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1398592ffb21SWarner Losh void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1399592ffb21SWarner Losh int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1400592ffb21SWarner Losh int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1401592ffb21SWarner Losh void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1402592ffb21SWarner Losh 
1403592ffb21SWarner Losh int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1404592ffb21SWarner Losh int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1405592ffb21SWarner Losh 			 struct drm_gem_object **obj);
1406592ffb21SWarner Losh #endif /* FREEBSD_NOTYET */
1407592ffb21SWarner Losh 
1408592ffb21SWarner Losh 				/* Scatter Gather Support (drm_scatter.h) */
1409592ffb21SWarner Losh extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1410592ffb21SWarner Losh extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1411592ffb21SWarner Losh 			struct drm_file *file_priv);
1412592ffb21SWarner Losh extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1413592ffb21SWarner Losh extern int drm_sg_free(struct drm_device *dev, void *data,
1414592ffb21SWarner Losh 		       struct drm_file *file_priv);
1415592ffb21SWarner Losh 
1416592ffb21SWarner Losh 			       /* ATI PCIGART support (ati_pcigart.h) */
1417592ffb21SWarner Losh extern int drm_ati_pcigart_init(struct drm_device *dev,
1418592ffb21SWarner Losh 				struct drm_ati_pcigart_info * gart_info);
1419592ffb21SWarner Losh extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1420592ffb21SWarner Losh 				   struct drm_ati_pcigart_info * gart_info);
1421592ffb21SWarner Losh 
1422592ffb21SWarner Losh extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1423592ffb21SWarner Losh 				       size_t align, dma_addr_t maxaddr);
1424592ffb21SWarner Losh extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1425592ffb21SWarner Losh extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1426592ffb21SWarner Losh 
1427592ffb21SWarner Losh /* Graphics Execution Manager library functions (drm_gem.c) */
1428592ffb21SWarner Losh int drm_gem_init(struct drm_device *dev);
1429592ffb21SWarner Losh void drm_gem_destroy(struct drm_device *dev);
1430592ffb21SWarner Losh void drm_gem_object_release(struct drm_gem_object *obj);
1431592ffb21SWarner Losh void drm_gem_object_free(struct drm_gem_object *obj);
1432592ffb21SWarner Losh struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1433592ffb21SWarner Losh 					    size_t size);
1434592ffb21SWarner Losh int drm_gem_object_init(struct drm_device *dev,
1435592ffb21SWarner Losh 			struct drm_gem_object *obj, size_t size);
1436592ffb21SWarner Losh int drm_gem_private_object_init(struct drm_device *dev,
1437592ffb21SWarner Losh 			struct drm_gem_object *obj, size_t size);
1438592ffb21SWarner Losh void drm_gem_object_handle_free(struct drm_gem_object *obj);
1439592ffb21SWarner Losh int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1440592ffb21SWarner Losh     vm_size_t size, struct vm_object **obj_res, int nprot);
1441592ffb21SWarner Losh void drm_gem_pager_dtr(void *obj);
1442592ffb21SWarner Losh 
1443592ffb21SWarner Losh #include <dev/drm2/drm_global.h>
1444592ffb21SWarner Losh 
1445592ffb21SWarner Losh static inline void
1446592ffb21SWarner Losh drm_gem_object_reference(struct drm_gem_object *obj)
1447592ffb21SWarner Losh {
1448592ffb21SWarner Losh 
1449592ffb21SWarner Losh 	KASSERT(obj->refcount > 0, ("Dangling obj %p", obj));
1450592ffb21SWarner Losh 	refcount_acquire(&obj->refcount);
1451592ffb21SWarner Losh }
1452592ffb21SWarner Losh 
1453592ffb21SWarner Losh static inline void
1454592ffb21SWarner Losh drm_gem_object_unreference(struct drm_gem_object *obj)
1455592ffb21SWarner Losh {
1456592ffb21SWarner Losh 
1457592ffb21SWarner Losh 	if (obj == NULL)
1458592ffb21SWarner Losh 		return;
1459592ffb21SWarner Losh 	if (refcount_release(&obj->refcount))
1460592ffb21SWarner Losh 		drm_gem_object_free(obj);
1461592ffb21SWarner Losh }
1462592ffb21SWarner Losh 
1463592ffb21SWarner Losh static inline void
1464592ffb21SWarner Losh drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1465592ffb21SWarner Losh {
1466592ffb21SWarner Losh 	if (obj != NULL) {
1467592ffb21SWarner Losh 		struct drm_device *dev = obj->dev;
1468592ffb21SWarner Losh 		DRM_LOCK(dev);
1469592ffb21SWarner Losh 		drm_gem_object_unreference(obj);
1470592ffb21SWarner Losh 		DRM_UNLOCK(dev);
1471592ffb21SWarner Losh 	}
1472592ffb21SWarner Losh }
1473592ffb21SWarner Losh 
1474592ffb21SWarner Losh int drm_gem_handle_create(struct drm_file *file_priv,
1475592ffb21SWarner Losh 			  struct drm_gem_object *obj,
1476592ffb21SWarner Losh 			  u32 *handlep);
1477592ffb21SWarner Losh int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1478592ffb21SWarner Losh 
1479592ffb21SWarner Losh static inline void
1480592ffb21SWarner Losh drm_gem_object_handle_reference(struct drm_gem_object *obj)
1481592ffb21SWarner Losh {
1482592ffb21SWarner Losh 	drm_gem_object_reference(obj);
1483592ffb21SWarner Losh 	atomic_inc(&obj->handle_count);
1484592ffb21SWarner Losh }
1485592ffb21SWarner Losh 
1486592ffb21SWarner Losh static inline void
1487592ffb21SWarner Losh drm_gem_object_handle_unreference(struct drm_gem_object *obj)
1488592ffb21SWarner Losh {
1489592ffb21SWarner Losh 	if (obj == NULL)
1490592ffb21SWarner Losh 		return;
1491592ffb21SWarner Losh 
1492592ffb21SWarner Losh 	if (atomic_read(&obj->handle_count) == 0)
1493592ffb21SWarner Losh 		return;
1494592ffb21SWarner Losh 	/*
1495592ffb21SWarner Losh 	 * Must bump handle count first as this may be the last
1496592ffb21SWarner Losh 	 * ref, in which case the object would disappear before we
1497592ffb21SWarner Losh 	 * checked for a name
1498592ffb21SWarner Losh 	 */
1499592ffb21SWarner Losh 	if (atomic_dec_and_test(&obj->handle_count))
1500592ffb21SWarner Losh 		drm_gem_object_handle_free(obj);
1501592ffb21SWarner Losh 	drm_gem_object_unreference(obj);
1502592ffb21SWarner Losh }
1503592ffb21SWarner Losh 
1504592ffb21SWarner Losh static inline void
1505592ffb21SWarner Losh drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
1506592ffb21SWarner Losh {
1507592ffb21SWarner Losh 	if (obj == NULL)
1508592ffb21SWarner Losh 		return;
1509592ffb21SWarner Losh 
1510592ffb21SWarner Losh 	if (atomic_read(&obj->handle_count) == 0)
1511592ffb21SWarner Losh 		return;
1512592ffb21SWarner Losh 
1513592ffb21SWarner Losh 	/*
1514592ffb21SWarner Losh 	* Must bump handle count first as this may be the last
1515592ffb21SWarner Losh 	* ref, in which case the object would disappear before we
1516592ffb21SWarner Losh 	* checked for a name
1517592ffb21SWarner Losh 	*/
1518592ffb21SWarner Losh 
1519592ffb21SWarner Losh 	if (atomic_dec_and_test(&obj->handle_count))
1520592ffb21SWarner Losh 		drm_gem_object_handle_free(obj);
1521592ffb21SWarner Losh 	drm_gem_object_unreference_unlocked(obj);
1522592ffb21SWarner Losh }
1523592ffb21SWarner Losh 
1524592ffb21SWarner Losh void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1525592ffb21SWarner Losh int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1526592ffb21SWarner Losh 
1527592ffb21SWarner Losh struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1528592ffb21SWarner Losh 					     struct drm_file *filp,
1529592ffb21SWarner Losh 					     u32 handle);
1530592ffb21SWarner Losh int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1531592ffb21SWarner Losh 			struct drm_file *file_priv);
1532592ffb21SWarner Losh int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1533592ffb21SWarner Losh 			struct drm_file *file_priv);
1534592ffb21SWarner Losh int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1535592ffb21SWarner Losh 		       struct drm_file *file_priv);
1536592ffb21SWarner Losh void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1537592ffb21SWarner Losh void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1538592ffb21SWarner Losh 
1539592ffb21SWarner Losh extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1540592ffb21SWarner Losh extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1541592ffb21SWarner Losh extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1542592ffb21SWarner Losh 
1543592ffb21SWarner Losh static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1544592ffb21SWarner Losh 							 unsigned int token)
1545592ffb21SWarner Losh {
1546592ffb21SWarner Losh 	struct drm_map_list *_entry;
1547592ffb21SWarner Losh 	list_for_each_entry(_entry, &dev->maplist, head)
1548592ffb21SWarner Losh 	    if (_entry->user_token == token)
1549592ffb21SWarner Losh 		return _entry->map;
1550592ffb21SWarner Losh 	return NULL;
1551592ffb21SWarner Losh }
1552592ffb21SWarner Losh 
1553592ffb21SWarner Losh static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1554592ffb21SWarner Losh {
1555592ffb21SWarner Losh }
1556592ffb21SWarner Losh 
1557592ffb21SWarner Losh #include <dev/drm2/drm_mem_util.h>
1558592ffb21SWarner Losh 
1559592ffb21SWarner Losh extern int drm_fill_in_dev(struct drm_device *dev,
1560592ffb21SWarner Losh 			   struct drm_driver *driver);
1561592ffb21SWarner Losh extern void drm_cancel_fill_in_dev(struct drm_device *dev);
1562592ffb21SWarner Losh int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
1563592ffb21SWarner Losh /*@}*/
1564592ffb21SWarner Losh 
1565592ffb21SWarner Losh /* PCI section */
1566592ffb21SWarner Losh int drm_pci_device_is_agp(struct drm_device *dev);
1567592ffb21SWarner Losh int drm_pci_device_is_pcie(struct drm_device *dev);
1568592ffb21SWarner Losh 
1569592ffb21SWarner Losh extern int drm_get_pci_dev(device_t kdev, struct drm_device *dev,
1570592ffb21SWarner Losh 			   struct drm_driver *driver);
1571592ffb21SWarner Losh 
1572592ffb21SWarner Losh #define DRM_PCIE_SPEED_25 1
1573592ffb21SWarner Losh #define DRM_PCIE_SPEED_50 2
1574592ffb21SWarner Losh #define DRM_PCIE_SPEED_80 4
1575592ffb21SWarner Losh 
1576592ffb21SWarner Losh extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1577592ffb21SWarner Losh 
1578592ffb21SWarner Losh #define	drm_can_sleep()	(DRM_HZ & 1)
1579592ffb21SWarner Losh 
1580592ffb21SWarner Losh /* Platform section */
1581592ffb21SWarner Losh int drm_get_platform_dev(device_t kdev, struct drm_device *dev,
1582592ffb21SWarner Losh 			 struct drm_driver *driver);
1583592ffb21SWarner Losh 
1584592ffb21SWarner Losh /* FreeBSD specific -- should be moved to drm_os_freebsd.h */
1585592ffb21SWarner Losh 
1586592ffb21SWarner Losh #define	DRM_GEM_MAPPING_MASK	(3ULL << 62)
1587592ffb21SWarner Losh #define	DRM_GEM_MAPPING_KEY	(2ULL << 62) /* Non-canonical address form */
1588592ffb21SWarner Losh #define	DRM_GEM_MAX_IDX		0x3fffff
1589592ffb21SWarner Losh #define	DRM_GEM_MAPPING_IDX(o)	(((o) >> 40) & DRM_GEM_MAX_IDX)
1590592ffb21SWarner Losh #define	DRM_GEM_MAPPING_OFF(i)	(((uint64_t)(i)) << 40)
1591592ffb21SWarner Losh #define	DRM_GEM_MAPPING_MAPOFF(o) \
1592592ffb21SWarner Losh     ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
1593592ffb21SWarner Losh 
1594592ffb21SWarner Losh SYSCTL_DECL(_hw_drm);
1595592ffb21SWarner Losh 
1596592ffb21SWarner Losh #define DRM_DEV_MODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
1597592ffb21SWarner Losh #define DRM_DEV_UID	UID_ROOT
1598592ffb21SWarner Losh #define DRM_DEV_GID	GID_VIDEO
1599592ffb21SWarner Losh 
1600592ffb21SWarner Losh #define DRM_WAKEUP(w)		wakeup((void *)w)
1601592ffb21SWarner Losh #define DRM_WAKEUP_INT(w)	wakeup(w)
1602592ffb21SWarner Losh #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
1603592ffb21SWarner Losh 
1604592ffb21SWarner Losh #define DRM_CURPROC		curthread
1605592ffb21SWarner Losh #define DRM_STRUCTPROC		struct thread
1606592ffb21SWarner Losh #define DRM_SPINTYPE		struct mtx
1607592ffb21SWarner Losh #define DRM_SPININIT(l,name)	mtx_init(l, name, NULL, MTX_DEF)
1608592ffb21SWarner Losh #define DRM_SPINUNINIT(l)	mtx_destroy(l)
1609592ffb21SWarner Losh #define DRM_SPINLOCK(l)		mtx_lock(l)
1610592ffb21SWarner Losh #define DRM_SPINUNLOCK(u)	mtx_unlock(u)
1611592ffb21SWarner Losh #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do {		\
1612592ffb21SWarner Losh 	mtx_lock(l);					\
1613592ffb21SWarner Losh 	(void)irqflags;					\
1614592ffb21SWarner Losh } while (0)
1615592ffb21SWarner Losh #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
1616592ffb21SWarner Losh #define DRM_SPINLOCK_ASSERT(l)	mtx_assert(l, MA_OWNED)
1617592ffb21SWarner Losh #define	DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout)			\
1618592ffb21SWarner Losh     (sx_sleep((chan), &(dev)->dev_struct_lock, (flags), (msg), (timeout)))
1619592ffb21SWarner Losh #if defined(INVARIANTS)
1620592ffb21SWarner Losh #define	DRM_LOCK_ASSERT(dev)	sx_assert(&(dev)->dev_struct_lock, SA_XLOCKED)
1621592ffb21SWarner Losh #define	DRM_UNLOCK_ASSERT(dev)	sx_assert(&(dev)->dev_struct_lock, SA_UNLOCKED)
1622592ffb21SWarner Losh #else
1623592ffb21SWarner Losh #define	DRM_LOCK_ASSERT(d)
1624592ffb21SWarner Losh #define	DRM_UNLOCK_ASSERT(d)
1625592ffb21SWarner Losh #endif
1626592ffb21SWarner Losh 
1627592ffb21SWarner Losh #define DRM_SYSCTL_HANDLER_ARGS	(SYSCTL_HANDLER_ARGS)
1628592ffb21SWarner Losh 
1629592ffb21SWarner Losh enum {
1630592ffb21SWarner Losh 	DRM_IS_NOT_AGP,
1631592ffb21SWarner Losh 	DRM_IS_AGP,
1632592ffb21SWarner Losh 	DRM_MIGHT_BE_AGP
1633592ffb21SWarner Losh };
1634592ffb21SWarner Losh 
1635592ffb21SWarner Losh #define DRM_VERIFYAREA_READ( uaddr, size )		\
1636592ffb21SWarner Losh 	(!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
1637592ffb21SWarner Losh 
1638592ffb21SWarner Losh #define DRM_COPY_TO_USER(user, kern, size) \
1639592ffb21SWarner Losh 	copyout(kern, user, size)
1640592ffb21SWarner Losh #define DRM_COPY_FROM_USER(kern, user, size) \
1641592ffb21SWarner Losh 	copyin(user, kern, size)
1642592ffb21SWarner Losh #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) 	\
1643592ffb21SWarner Losh 	copyin(arg2, arg1, arg3)
1644592ffb21SWarner Losh #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)	\
1645592ffb21SWarner Losh 	copyout(arg2, arg1, arg3)
1646592ffb21SWarner Losh #define DRM_GET_USER_UNCHECKED(val, uaddr)		\
1647592ffb21SWarner Losh 	((val) = fuword32(uaddr), 0)
1648592ffb21SWarner Losh 
1649592ffb21SWarner Losh #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {	\
1650592ffb21SWarner Losh 	(_map) = (_dev)->context_sareas[_ctx];		\
1651592ffb21SWarner Losh } while(0)
1652592ffb21SWarner Losh 
1653592ffb21SWarner Losh /* Returns -errno to shared code */
1654592ffb21SWarner Losh #define DRM_WAIT_ON( ret, queue, timeout, condition )		\
1655592ffb21SWarner Losh for ( ret = 0 ; !ret && !(condition) ; ) {			\
1656592ffb21SWarner Losh 	DRM_UNLOCK(dev);					\
1657592ffb21SWarner Losh 	mtx_lock(&dev->irq_lock);				\
1658592ffb21SWarner Losh 	if (!(condition))					\
1659592ffb21SWarner Losh 	    ret = -mtx_sleep(&(queue), &dev->irq_lock, 		\
1660592ffb21SWarner Losh 		PCATCH, "drmwtq", (timeout));			\
1661592ffb21SWarner Losh 	    if (ret == -ERESTART)				\
1662592ffb21SWarner Losh 	        ret = -ERESTARTSYS;				\
1663592ffb21SWarner Losh 	mtx_unlock(&dev->irq_lock);				\
1664592ffb21SWarner Losh 	DRM_LOCK(dev);						\
1665592ffb21SWarner Losh }
1666592ffb21SWarner Losh 
1667592ffb21SWarner Losh #define	dev_err(dev, fmt, ...)						\
1668592ffb21SWarner Losh 	device_printf((dev), "error: " fmt, ## __VA_ARGS__)
1669592ffb21SWarner Losh #define	dev_warn(dev, fmt, ...)						\
1670592ffb21SWarner Losh 	device_printf((dev), "warning: " fmt, ## __VA_ARGS__)
1671592ffb21SWarner Losh #define	dev_info(dev, fmt, ...)						\
1672592ffb21SWarner Losh 	device_printf((dev), "info: " fmt, ## __VA_ARGS__)
1673592ffb21SWarner Losh #define	dev_dbg(dev, fmt, ...) do {					\
1674592ffb21SWarner Losh 	if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) {			\
1675592ffb21SWarner Losh 		device_printf((dev), "debug: " fmt, ## __VA_ARGS__);	\
1676592ffb21SWarner Losh 	}								\
1677592ffb21SWarner Losh } while (0)
1678592ffb21SWarner Losh 
1679592ffb21SWarner Losh struct drm_msi_blacklist_entry
1680592ffb21SWarner Losh {
1681592ffb21SWarner Losh 	int vendor;
1682592ffb21SWarner Losh 	int device;
1683592ffb21SWarner Losh };
1684592ffb21SWarner Losh 
1685592ffb21SWarner Losh struct drm_vblank_info {
1686592ffb21SWarner Losh 	wait_queue_head_t queue;	/* vblank wait queue */
1687592ffb21SWarner Losh 	atomic_t count;			/* number of VBLANK interrupts */
1688592ffb21SWarner Losh 					/* (driver must alloc the right number of counters) */
1689592ffb21SWarner Losh 	atomic_t refcount;		/* number of users of vblank interrupts */
1690592ffb21SWarner Losh 	u32 last;			/* protected by dev->vbl_lock, used */
1691592ffb21SWarner Losh 					/* for wraparound handling */
1692592ffb21SWarner Losh 	int enabled;			/* so we don't call enable more than */
1693592ffb21SWarner Losh 					/* once per disable */
1694592ffb21SWarner Losh 	int inmodeset;			/* Display driver is setting mode */
1695592ffb21SWarner Losh };
1696592ffb21SWarner Losh 
1697592ffb21SWarner Losh #ifndef DMA_BIT_MASK
1698592ffb21SWarner Losh #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
1699592ffb21SWarner Losh #endif
1700592ffb21SWarner Losh 
1701592ffb21SWarner Losh #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
1702592ffb21SWarner Losh 
1703592ffb21SWarner Losh enum dmi_field {
1704592ffb21SWarner Losh         DMI_NONE,
1705592ffb21SWarner Losh         DMI_BIOS_VENDOR,
1706592ffb21SWarner Losh         DMI_BIOS_VERSION,
1707592ffb21SWarner Losh         DMI_BIOS_DATE,
1708592ffb21SWarner Losh         DMI_SYS_VENDOR,
1709592ffb21SWarner Losh         DMI_PRODUCT_NAME,
1710592ffb21SWarner Losh         DMI_PRODUCT_VERSION,
1711592ffb21SWarner Losh         DMI_PRODUCT_SERIAL,
1712592ffb21SWarner Losh         DMI_PRODUCT_UUID,
1713592ffb21SWarner Losh         DMI_BOARD_VENDOR,
1714592ffb21SWarner Losh         DMI_BOARD_NAME,
1715592ffb21SWarner Losh         DMI_BOARD_VERSION,
1716592ffb21SWarner Losh         DMI_BOARD_SERIAL,
1717592ffb21SWarner Losh         DMI_BOARD_ASSET_TAG,
1718592ffb21SWarner Losh         DMI_CHASSIS_VENDOR,
1719592ffb21SWarner Losh         DMI_CHASSIS_TYPE,
1720592ffb21SWarner Losh         DMI_CHASSIS_VERSION,
1721592ffb21SWarner Losh         DMI_CHASSIS_SERIAL,
1722592ffb21SWarner Losh         DMI_CHASSIS_ASSET_TAG,
1723592ffb21SWarner Losh         DMI_STRING_MAX,
1724592ffb21SWarner Losh };
1725592ffb21SWarner Losh 
1726592ffb21SWarner Losh struct dmi_strmatch {
1727592ffb21SWarner Losh 	unsigned char slot;
1728592ffb21SWarner Losh 	char substr[79];
1729592ffb21SWarner Losh };
1730592ffb21SWarner Losh 
1731592ffb21SWarner Losh struct dmi_system_id {
1732592ffb21SWarner Losh         int (*callback)(const struct dmi_system_id *);
1733592ffb21SWarner Losh         const char *ident;
1734592ffb21SWarner Losh         struct dmi_strmatch matches[4];
1735592ffb21SWarner Losh };
1736592ffb21SWarner Losh #define	DMI_MATCH(a, b) {(a), (b)}
1737592ffb21SWarner Losh bool dmi_check_system(const struct dmi_system_id *);
1738592ffb21SWarner Losh 
1739592ffb21SWarner Losh /* Device setup support (drm_drv.c) */
1740592ffb21SWarner Losh int	drm_probe_helper(device_t kdev, const drm_pci_id_list_t *idlist);
1741592ffb21SWarner Losh int	drm_attach_helper(device_t kdev, const drm_pci_id_list_t *idlist,
1742592ffb21SWarner Losh 	    struct drm_driver *driver);
1743592ffb21SWarner Losh int	drm_generic_suspend(device_t kdev);
1744592ffb21SWarner Losh int	drm_generic_resume(device_t kdev);
1745592ffb21SWarner Losh int	drm_generic_detach(device_t kdev);
1746592ffb21SWarner Losh 
1747592ffb21SWarner Losh void drm_event_wakeup(struct drm_pending_event *e);
1748592ffb21SWarner Losh 
1749592ffb21SWarner Losh int drm_add_busid_modesetting(struct drm_device *dev,
1750592ffb21SWarner Losh     struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1751592ffb21SWarner Losh 
1752592ffb21SWarner Losh /* Buffer management support (drm_bufs.c) */
1753592ffb21SWarner Losh unsigned long drm_get_resource_start(struct drm_device *dev,
1754592ffb21SWarner Losh 				     unsigned int resource);
1755592ffb21SWarner Losh unsigned long drm_get_resource_len(struct drm_device *dev,
1756592ffb21SWarner Losh 				   unsigned int resource);
1757592ffb21SWarner Losh 
1758592ffb21SWarner Losh /* IRQ support (drm_irq.c) */
1759592ffb21SWarner Losh irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1760592ffb21SWarner Losh void	drm_driver_irq_preinstall(struct drm_device *dev);
1761592ffb21SWarner Losh void	drm_driver_irq_postinstall(struct drm_device *dev);
1762592ffb21SWarner Losh void	drm_driver_irq_uninstall(struct drm_device *dev);
1763592ffb21SWarner Losh 
1764592ffb21SWarner Losh /* sysctl support (drm_sysctl.h) */
1765592ffb21SWarner Losh extern int		drm_sysctl_init(struct drm_device *dev);
1766592ffb21SWarner Losh extern int		drm_sysctl_cleanup(struct drm_device *dev);
1767592ffb21SWarner Losh 
1768592ffb21SWarner Losh int	drm_version(struct drm_device *dev, void *data,
1769592ffb21SWarner Losh 		    struct drm_file *file_priv);
1770592ffb21SWarner Losh 
1771592ffb21SWarner Losh /* consistent PCI memory functions (drm_pci.c) */
1772592ffb21SWarner Losh int	drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
1773592ffb21SWarner Losh int	drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
1774592ffb21SWarner Losh 	    struct drm_unique *u);
1775592ffb21SWarner Losh int	drm_pci_agp_init(struct drm_device *dev);
1776592ffb21SWarner Losh int	drm_pci_enable_msi(struct drm_device *dev);
1777592ffb21SWarner Losh void	drm_pci_disable_msi(struct drm_device *dev);
1778592ffb21SWarner Losh 
1779592ffb21SWarner Losh struct ttm_bo_device;
1780592ffb21SWarner Losh int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1781592ffb21SWarner Losh     vm_size_t size, struct vm_object **obj_res, int nprot);
1782592ffb21SWarner Losh struct ttm_buffer_object;
1783592ffb21SWarner Losh void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1784592ffb21SWarner Losh 
1785592ffb21SWarner Losh #if  __OS_HAS_AGP
1786592ffb21SWarner Losh 				/* Memory management support (drm_memory.h) */
1787592ffb21SWarner Losh extern void drm_free_agp(DRM_AGP_MEM * handle, int pages);
1788592ffb21SWarner Losh extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1789592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
1790592ffb21SWarner Losh extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1791592ffb21SWarner Losh 				       struct page **pages,
1792592ffb21SWarner Losh 				       unsigned long num_pages,
1793592ffb21SWarner Losh 				       uint32_t gtt_offset,
1794592ffb21SWarner Losh 				       uint32_t type);
1795592ffb21SWarner Losh #endif /* FREEBSD_NOTYET */
1796592ffb21SWarner Losh extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1797592ffb21SWarner Losh 
1798592ffb21SWarner Losh 				/* AGP/GART support (drm_agpsupport.h) */
1799592ffb21SWarner Losh extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1800592ffb21SWarner Losh extern int drm_agp_acquire(struct drm_device *dev);
1801592ffb21SWarner Losh extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1802592ffb21SWarner Losh 				 struct drm_file *file_priv);
1803592ffb21SWarner Losh extern int drm_agp_release(struct drm_device *dev);
1804592ffb21SWarner Losh extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1805592ffb21SWarner Losh 				 struct drm_file *file_priv);
1806592ffb21SWarner Losh extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1807592ffb21SWarner Losh extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1808592ffb21SWarner Losh 				struct drm_file *file_priv);
1809592ffb21SWarner Losh extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1810592ffb21SWarner Losh extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1811592ffb21SWarner Losh 			struct drm_file *file_priv);
1812592ffb21SWarner Losh extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1813592ffb21SWarner Losh extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1814592ffb21SWarner Losh 			 struct drm_file *file_priv);
1815592ffb21SWarner Losh extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1816592ffb21SWarner Losh extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1817592ffb21SWarner Losh 			struct drm_file *file_priv);
1818592ffb21SWarner Losh extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1819592ffb21SWarner Losh extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1820592ffb21SWarner Losh 			  struct drm_file *file_priv);
1821592ffb21SWarner Losh extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1822592ffb21SWarner Losh extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1823592ffb21SWarner Losh 			struct drm_file *file_priv);
1824592ffb21SWarner Losh 
1825592ffb21SWarner Losh #else
1826592ffb21SWarner Losh 
1827592ffb21SWarner Losh static inline void drm_free_agp(DRM_AGP_MEM * handle, int pages)
1828592ffb21SWarner Losh {
1829592ffb21SWarner Losh }
1830592ffb21SWarner Losh 
1831592ffb21SWarner Losh static inline int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
1832592ffb21SWarner Losh {
1833592ffb21SWarner Losh 	return -ENODEV;
1834592ffb21SWarner Losh }
1835592ffb21SWarner Losh 
1836592ffb21SWarner Losh static inline int drm_unbind_agp(DRM_AGP_MEM * handle)
1837592ffb21SWarner Losh {
1838592ffb21SWarner Losh 	return -ENODEV;
1839592ffb21SWarner Losh }
1840592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
1841592ffb21SWarner Losh static inline struct agp_memory *drm_agp_bind_pages(struct drm_device *dev,
1842592ffb21SWarner Losh 					      struct page **pages,
1843592ffb21SWarner Losh 					      unsigned long num_pages,
1844592ffb21SWarner Losh 					      uint32_t gtt_offset,
1845592ffb21SWarner Losh 					      uint32_t type)
1846592ffb21SWarner Losh {
1847592ffb21SWarner Losh 	return NULL;
1848592ffb21SWarner Losh }
1849592ffb21SWarner Losh #endif
1850592ffb21SWarner Losh static inline struct drm_agp_head *drm_agp_init(struct drm_device *dev)
1851592ffb21SWarner Losh {
1852592ffb21SWarner Losh 	return NULL;
1853592ffb21SWarner Losh }
1854592ffb21SWarner Losh 
1855592ffb21SWarner Losh static inline void drm_agp_clear(struct drm_device *dev)
1856592ffb21SWarner Losh {
1857592ffb21SWarner Losh }
1858592ffb21SWarner Losh 
1859592ffb21SWarner Losh static inline int drm_agp_acquire(struct drm_device *dev)
1860592ffb21SWarner Losh {
1861592ffb21SWarner Losh 	return -ENODEV;
1862592ffb21SWarner Losh }
1863592ffb21SWarner Losh 
1864592ffb21SWarner Losh static inline int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1865592ffb21SWarner Losh 					struct drm_file *file_priv)
1866592ffb21SWarner Losh {
1867592ffb21SWarner Losh 	return -ENODEV;
1868592ffb21SWarner Losh }
1869592ffb21SWarner Losh 
1870592ffb21SWarner Losh static inline int drm_agp_release(struct drm_device *dev)
1871592ffb21SWarner Losh {
1872592ffb21SWarner Losh 	return -ENODEV;
1873592ffb21SWarner Losh }
1874592ffb21SWarner Losh 
1875592ffb21SWarner Losh static inline int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1876592ffb21SWarner Losh 					struct drm_file *file_priv)
1877592ffb21SWarner Losh {
1878592ffb21SWarner Losh 	return -ENODEV;
1879592ffb21SWarner Losh }
1880592ffb21SWarner Losh 
1881592ffb21SWarner Losh static inline int drm_agp_enable(struct drm_device *dev,
1882592ffb21SWarner Losh 				 struct drm_agp_mode mode)
1883592ffb21SWarner Losh {
1884592ffb21SWarner Losh 	return -ENODEV;
1885592ffb21SWarner Losh }
1886592ffb21SWarner Losh 
1887592ffb21SWarner Losh static inline int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1888592ffb21SWarner Losh 				       struct drm_file *file_priv)
1889592ffb21SWarner Losh {
1890592ffb21SWarner Losh 	return -ENODEV;
1891592ffb21SWarner Losh }
1892592ffb21SWarner Losh 
1893592ffb21SWarner Losh static inline int drm_agp_info(struct drm_device *dev,
1894592ffb21SWarner Losh 			       struct drm_agp_info *info)
1895592ffb21SWarner Losh {
1896592ffb21SWarner Losh 	return -ENODEV;
1897592ffb21SWarner Losh }
1898592ffb21SWarner Losh 
1899592ffb21SWarner Losh static inline int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1900592ffb21SWarner Losh 				     struct drm_file *file_priv)
1901592ffb21SWarner Losh {
1902592ffb21SWarner Losh 	return -ENODEV;
1903592ffb21SWarner Losh }
1904592ffb21SWarner Losh 
1905592ffb21SWarner Losh static inline int drm_agp_alloc(struct drm_device *dev,
1906592ffb21SWarner Losh 				struct drm_agp_buffer *request)
1907592ffb21SWarner Losh {
1908592ffb21SWarner Losh 	return -ENODEV;
1909592ffb21SWarner Losh }
1910592ffb21SWarner Losh 
1911592ffb21SWarner Losh static inline int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1912592ffb21SWarner Losh 				      struct drm_file *file_priv)
1913592ffb21SWarner Losh {
1914592ffb21SWarner Losh 	return -ENODEV;
1915592ffb21SWarner Losh }
1916592ffb21SWarner Losh 
1917592ffb21SWarner Losh static inline int drm_agp_free(struct drm_device *dev,
1918592ffb21SWarner Losh 			       struct drm_agp_buffer *request)
1919592ffb21SWarner Losh {
1920592ffb21SWarner Losh 	return -ENODEV;
1921592ffb21SWarner Losh }
1922592ffb21SWarner Losh 
1923592ffb21SWarner Losh static inline int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1924592ffb21SWarner Losh 				     struct drm_file *file_priv)
1925592ffb21SWarner Losh {
1926592ffb21SWarner Losh 	return -ENODEV;
1927592ffb21SWarner Losh }
1928592ffb21SWarner Losh 
1929592ffb21SWarner Losh static inline int drm_agp_unbind(struct drm_device *dev,
1930592ffb21SWarner Losh 				 struct drm_agp_binding *request)
1931592ffb21SWarner Losh {
1932592ffb21SWarner Losh 	return -ENODEV;
1933592ffb21SWarner Losh }
1934592ffb21SWarner Losh 
1935592ffb21SWarner Losh static inline int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1936592ffb21SWarner Losh 				       struct drm_file *file_priv)
1937592ffb21SWarner Losh {
1938592ffb21SWarner Losh 	return -ENODEV;
1939592ffb21SWarner Losh }
1940592ffb21SWarner Losh 
1941592ffb21SWarner Losh static inline int drm_agp_bind(struct drm_device *dev,
1942592ffb21SWarner Losh 			       struct drm_agp_binding *request)
1943592ffb21SWarner Losh {
1944592ffb21SWarner Losh 	return -ENODEV;
1945592ffb21SWarner Losh }
1946592ffb21SWarner Losh 
1947592ffb21SWarner Losh static inline int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1948592ffb21SWarner Losh 				     struct drm_file *file_priv)
1949592ffb21SWarner Losh {
1950592ffb21SWarner Losh 	return -ENODEV;
1951592ffb21SWarner Losh }
1952592ffb21SWarner Losh 
1953592ffb21SWarner Losh #endif /* __OS_HAS_AGP */
1954592ffb21SWarner Losh 
1955592ffb21SWarner Losh #endif				/* __KERNEL__ */
1956592ffb21SWarner Losh #endif
1957