Deleted Added
full compact
drmP.h (247832) drmP.h (247835)
1/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
3 */
4/*-
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 *
28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
31 *
32 */
33
34#include <sys/cdefs.h>
1/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
3 */
4/*-
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 *
28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
31 *
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/drm2/drmP.h 247832 2013-03-05 09:07:01Z kib $");
35__FBSDID("$FreeBSD: head/sys/dev/drm2/drmP.h 247835 2013-03-05 09:49:34Z kib $");
36
37#ifndef _DRM_P_H_
38#define _DRM_P_H_
39
40#if defined(_KERNEL) || defined(__KERNEL__)
41
42struct drm_device;
43struct drm_file;
44
45#include <sys/param.h>
46#include <sys/queue.h>
47#include <sys/malloc.h>
48#include <sys/kernel.h>
49#include <sys/ktr.h>
50#include <sys/module.h>
51#include <sys/systm.h>
52#include <sys/conf.h>
53#include <sys/sglist.h>
54#include <sys/stat.h>
55#include <sys/priv.h>
56#include <sys/proc.h>
57#include <sys/lock.h>
58#include <sys/fcntl.h>
59#include <sys/uio.h>
60#include <sys/filio.h>
61#include <sys/selinfo.h>
62#include <sys/sysctl.h>
63#include <sys/bus.h>
64#include <sys/queue.h>
65#include <sys/signalvar.h>
66#include <sys/poll.h>
67#include <sys/sbuf.h>
68#include <sys/taskqueue.h>
69#include <sys/tree.h>
70#include <vm/vm.h>
71#include <vm/pmap.h>
72#include <vm/vm_extern.h>
73#include <vm/vm_kern.h>
74#include <vm/vm_map.h>
75#include <vm/vm_object.h>
76#include <vm/vm_page.h>
77#include <vm/vm_pager.h>
78#include <vm/vm_param.h>
79#include <vm/vm_phys.h>
80#include <machine/param.h>
81#include <machine/pmap.h>
82#include <machine/bus.h>
83#include <machine/resource.h>
84#if defined(__i386__) || defined(__amd64__)
85#include <machine/specialreg.h>
86#endif
87#include <machine/sysarch.h>
88#include <sys/endian.h>
89#include <sys/mman.h>
90#include <sys/rman.h>
91#include <sys/memrange.h>
92#include <dev/agp/agpvar.h>
93#include <sys/agpio.h>
94#include <sys/mutex.h>
95#include <dev/pci/pcivar.h>
96#include <dev/pci/pcireg.h>
97#include <sys/selinfo.h>
98#include <sys/bus.h>
99
100#include <dev/drm2/drm.h>
101#include <dev/drm2/drm_atomic.h>
102#include <dev/drm2/drm_internal.h>
103#include <dev/drm2/drm_linux_list.h>
104#include <dev/drm2/drm_gem_names.h>
105#include <dev/drm2/drm_mm.h>
106#include <dev/drm2/drm_hashtab.h>
107
108#include "opt_compat.h"
109#include "opt_drm.h"
110#ifdef DRM_DEBUG
111#undef DRM_DEBUG
112#define DRM_DEBUG_DEFAULT_ON 1
113#endif /* DRM_DEBUG */
114
115#define DRM_DEBUGBITS_DEBUG 0x1
116#define DRM_DEBUGBITS_KMS 0x2
117#define DRM_DEBUGBITS_FAILED_IOCTL 0x4
118
119#undef DRM_LINUX
120#define DRM_LINUX 0
121
122/* driver capabilities and requirements mask */
123#define DRIVER_USE_AGP 0x1
124#define DRIVER_REQUIRE_AGP 0x2
125#define DRIVER_USE_MTRR 0x4
126#define DRIVER_PCI_DMA 0x8
127#define DRIVER_SG 0x10
128#define DRIVER_HAVE_DMA 0x20
129#define DRIVER_HAVE_IRQ 0x40
130#define DRIVER_IRQ_SHARED 0x80
131#define DRIVER_IRQ_VBL 0x100
132#define DRIVER_DMA_QUEUE 0x200
133#define DRIVER_FB_DMA 0x400
134#define DRIVER_IRQ_VBL2 0x800
135#define DRIVER_GEM 0x1000
136#define DRIVER_MODESET 0x2000
137#define DRIVER_USE_PLATFORM_DEVICE 0x4000
138#define DRIVER_LOCKLESS_IRQ 0x8000
139
140
141#define DRM_HASH_SIZE 16 /* Size of key hash table */
142#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
143#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
144
145#define DRM_GEM_MAPPING_MASK (3ULL << 62)
146#define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */
147#define DRM_GEM_MAX_IDX 0x3fffff
148#define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX)
149#define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40)
150#define DRM_GEM_MAPPING_MAPOFF(o) \
151 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
152
153MALLOC_DECLARE(DRM_MEM_DMA);
154MALLOC_DECLARE(DRM_MEM_SAREA);
155MALLOC_DECLARE(DRM_MEM_DRIVER);
156MALLOC_DECLARE(DRM_MEM_MAGIC);
157MALLOC_DECLARE(DRM_MEM_IOCTLS);
158MALLOC_DECLARE(DRM_MEM_MAPS);
159MALLOC_DECLARE(DRM_MEM_BUFS);
160MALLOC_DECLARE(DRM_MEM_SEGS);
161MALLOC_DECLARE(DRM_MEM_PAGES);
162MALLOC_DECLARE(DRM_MEM_FILES);
163MALLOC_DECLARE(DRM_MEM_QUEUES);
164MALLOC_DECLARE(DRM_MEM_CMDS);
165MALLOC_DECLARE(DRM_MEM_MAPPINGS);
166MALLOC_DECLARE(DRM_MEM_BUFLISTS);
167MALLOC_DECLARE(DRM_MEM_AGPLISTS);
168MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
169MALLOC_DECLARE(DRM_MEM_SGLISTS);
170MALLOC_DECLARE(DRM_MEM_DRAWABLE);
171MALLOC_DECLARE(DRM_MEM_MM);
172MALLOC_DECLARE(DRM_MEM_HASHTAB);
173MALLOC_DECLARE(DRM_MEM_KMS);
174
175SYSCTL_DECL(_hw_drm);
176
177#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
178
179 /* Internal types and structures */
180#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
181#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
182#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
183
184#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
185
186#define __OS_HAS_AGP 1
187
188#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
189#define DRM_DEV_UID 0
190#define DRM_DEV_GID 0
191
192#define wait_queue_head_t atomic_t
193#define DRM_WAKEUP(w) wakeup((void *)w)
194#define DRM_WAKEUP_INT(w) wakeup(w)
195#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
196
197#define DRM_CURPROC curthread
198#define DRM_STRUCTPROC struct thread
199#define DRM_SPINTYPE struct mtx
200#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
201#define DRM_SPINUNINIT(l) mtx_destroy(l)
202#define DRM_SPINLOCK(l) mtx_lock(l)
203#define DRM_SPINUNLOCK(u) mtx_unlock(u)
204#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
205 mtx_lock(l); \
206 (void)irqflags; \
207} while (0)
208#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
209#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
210#define DRM_CURRENTPID curthread->td_proc->p_pid
211#define DRM_LOCK(dev) sx_xlock(&(dev)->dev_struct_lock)
212#define DRM_UNLOCK(dev) sx_xunlock(&(dev)->dev_struct_lock)
213#define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
214 (sx_sleep((chan), &(dev)->dev_struct_lock, (flags), (msg), (timeout)))
215#if defined(INVARIANTS)
216#define DRM_LOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_XLOCKED)
217#define DRM_UNLOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_UNLOCKED)
218#else
219#define DRM_LOCK_ASSERT(d)
220#define DRM_UNLOCK_ASSERT(d)
221#endif
222
223#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
224
225#define DRM_IRQ_ARGS void *arg
226typedef void irqreturn_t;
227#define IRQ_HANDLED /* nothing */
228#define IRQ_NONE /* nothing */
229
230#define unlikely(x) __builtin_expect(!!(x), 0)
231#define likely(x) __builtin_expect((x), 0)
232#define container_of(ptr, type, member) ({ \
233 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
234 (type *)( (char *)__mptr - offsetof(type,member) );})
235
236enum {
237 DRM_IS_NOT_AGP,
238 DRM_IS_AGP,
239 DRM_MIGHT_BE_AGP
240};
241#define DRM_AGP_MEM struct agp_memory_info
242
243#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
244
245#define PAGE_ALIGN(addr) round_page(addr)
246/* DRM_SUSER returns true if the user is superuser */
247#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
248#define DRM_AGP_FIND_DEVICE() agp_find_device()
249#define DRM_MTRR_WC MDF_WRITECOMBINE
250#define jiffies ticks
251#define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz)
252#define msecs_to_jiffies(x) (((int64_t)(x)) * hz / 1000)
253#define time_after(a,b) ((long)(b) - (long)(a) < 0)
254#define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0)
255#define drm_msleep(x, msg) pause((msg), ((int64_t)(x)) * hz / 1000)
256
257typedef vm_paddr_t dma_addr_t;
258typedef uint64_t u64;
259typedef uint32_t u32;
260typedef uint16_t u16;
261typedef uint8_t u8;
262typedef int64_t s64;
263typedef int32_t s32;
264typedef int16_t s16;
265typedef int8_t s8;
266
267/* DRM_READMEMORYBARRIER() prevents reordering of reads.
268 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
269 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
270 */
271#define DRM_READMEMORYBARRIER() rmb()
272#define DRM_WRITEMEMORYBARRIER() wmb()
273#define DRM_MEMORYBARRIER() mb()
274
275#define DRM_READ8(map, offset) \
276 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \
277 (vm_offset_t)(offset))
278#define DRM_READ16(map, offset) \
279 le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \
280 (vm_offset_t)(offset)))
281#define DRM_READ32(map, offset) \
282 le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \
283 (vm_offset_t)(offset)))
284#define DRM_READ64(map, offset) \
285 le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \
286 (vm_offset_t)(offset)))
287#define DRM_WRITE8(map, offset, val) \
288 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \
289 (vm_offset_t)(offset)) = val
290#define DRM_WRITE16(map, offset, val) \
291 *(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \
292 (vm_offset_t)(offset)) = htole16(val)
293#define DRM_WRITE32(map, offset, val) \
294 *(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \
295 (vm_offset_t)(offset)) = htole32(val)
296#define DRM_WRITE64(map, offset, val) \
297 *(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \
298 (vm_offset_t)(offset)) = htole64(val)
299
300#define DRM_VERIFYAREA_READ( uaddr, size ) \
301 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
302
303#define DRM_COPY_TO_USER(user, kern, size) \
304 copyout(kern, user, size)
305#define DRM_COPY_FROM_USER(kern, user, size) \
306 copyin(user, kern, size)
307#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
308 copyin(arg2, arg1, arg3)
309#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
310 copyout(arg2, arg1, arg3)
311#define DRM_GET_USER_UNCHECKED(val, uaddr) \
312 ((val) = fuword32(uaddr), 0)
313
314#define cpu_to_le32(x) htole32(x)
315#define le32_to_cpu(x) le32toh(x)
316
317#define DRM_HZ hz
318#define DRM_UDELAY(udelay) DELAY(udelay)
319#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
320
321#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
322 (_map) = (_dev)->context_sareas[_ctx]; \
323} while(0)
324
325#define LOCK_TEST_WITH_RETURN(dev, file_priv) \
326do { \
327 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
328 dev->lock.file_priv != file_priv) { \
329 DRM_ERROR("%s called without lock held\n", \
330 __FUNCTION__); \
331 return EINVAL; \
332 } \
333} while (0)
334
335/* Returns -errno to shared code */
336#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
337for ( ret = 0 ; !ret && !(condition) ; ) { \
338 DRM_UNLOCK(dev); \
339 mtx_lock(&dev->irq_lock); \
340 if (!(condition)) \
341 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
342 PCATCH, "drmwtq", (timeout)); \
343 mtx_unlock(&dev->irq_lock); \
344 DRM_LOCK(dev); \
345}
346
347#define DRM_ERROR(fmt, ...) \
348 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
349 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
350
351#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
352
353#define DRM_DEBUG(fmt, ...) do { \
354 if ((drm_debug_flag & DRM_DEBUGBITS_DEBUG) != 0) \
355 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
356 __func__ , ##__VA_ARGS__); \
357} while (0)
358
359#define DRM_DEBUG_KMS(fmt, ...) do { \
360 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \
361 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
362 __func__ , ##__VA_ARGS__); \
363} while (0)
364
365#define DRM_DEBUG_DRIVER(fmt, ...) do { \
366 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \
367 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
368 __func__ , ##__VA_ARGS__); \
369} while (0)
370
371typedef struct drm_pci_id_list
372{
373 int vendor;
374 int device;
375 long driver_private;
376 char *name;
377} drm_pci_id_list_t;
378
379struct drm_msi_blacklist_entry
380{
381 int vendor;
382 int device;
383};
384
385#define DRM_AUTH 0x1
386#define DRM_MASTER 0x2
387#define DRM_ROOT_ONLY 0x4
388#define DRM_CONTROL_ALLOW 0x8
389#define DRM_UNLOCKED 0x10
390
391typedef struct drm_ioctl_desc {
392 unsigned long cmd;
393 int (*func)(struct drm_device *dev, void *data,
394 struct drm_file *file_priv);
395 int flags;
396} drm_ioctl_desc_t;
397/**
398 * Creates a driver or general drm_ioctl_desc array entry for the given
399 * ioctl, for use by drm_ioctl().
400 */
401#define DRM_IOCTL_DEF(ioctl, func, flags) \
402 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
403
404typedef struct drm_magic_entry {
405 drm_magic_t magic;
406 struct drm_file *priv;
407 struct drm_magic_entry *next;
408} drm_magic_entry_t;
409
410typedef struct drm_magic_head {
411 struct drm_magic_entry *head;
412 struct drm_magic_entry *tail;
413} drm_magic_head_t;
414
415typedef struct drm_buf {
416 int idx; /* Index into master buflist */
417 int total; /* Buffer size */
418 int order; /* log-base-2(total) */
419 int used; /* Amount of buffer in use (for DMA) */
420 unsigned long offset; /* Byte offset (used internally) */
421 void *address; /* Address of buffer */
422 unsigned long bus_address; /* Bus address of buffer */
423 struct drm_buf *next; /* Kernel-only: used for free list */
424 __volatile__ int pending; /* On hardware DMA queue */
425 struct drm_file *file_priv; /* Unique identifier of holding process */
426 int context; /* Kernel queue for this buffer */
427 enum {
428 DRM_LIST_NONE = 0,
429 DRM_LIST_FREE = 1,
430 DRM_LIST_WAIT = 2,
431 DRM_LIST_PEND = 3,
432 DRM_LIST_PRIO = 4,
433 DRM_LIST_RECLAIM = 5
434 } list; /* Which list we're on */
435
436 int dev_priv_size; /* Size of buffer private stoarge */
437 void *dev_private; /* Per-buffer private storage */
438} drm_buf_t;
439
440typedef struct drm_freelist {
441 int initialized; /* Freelist in use */
442 atomic_t count; /* Number of free buffers */
443 drm_buf_t *next; /* End pointer */
444
445 int low_mark; /* Low water mark */
446 int high_mark; /* High water mark */
447} drm_freelist_t;
448
449typedef struct drm_dma_handle {
450 void *vaddr;
451 bus_addr_t busaddr;
452 bus_dma_tag_t tag;
453 bus_dmamap_t map;
454} drm_dma_handle_t;
455
456typedef struct drm_buf_entry {
457 int buf_size;
458 int buf_count;
459 drm_buf_t *buflist;
460 int seg_count;
461 drm_dma_handle_t **seglist;
462 int page_order;
463
464 drm_freelist_t freelist;
465} drm_buf_entry_t;
466
467/* Event queued up for userspace to read */
468struct drm_pending_event {
469 struct drm_event *event;
470 struct list_head link;
471 struct drm_file *file_priv;
472 pid_t pid; /* pid of requester, no guarantee it's valid by the time
473 we deliver the event, for tracing only */
474 void (*destroy)(struct drm_pending_event *event);
475};
476
477typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
478struct drm_file {
479 TAILQ_ENTRY(drm_file) link;
480 struct drm_device *dev;
481 int authenticated;
482 int master;
483 pid_t pid;
484 uid_t uid;
485 drm_magic_t magic;
486 unsigned long ioctl_count;
487
488 void *driver_priv;
489 struct drm_gem_names object_names;
490
491 int is_master;
492 struct drm_master *masterp;
493
494 struct list_head fbs;
495
496 struct list_head event_list;
497 int event_space;
498 struct selinfo event_poll;
499};
500
501typedef struct drm_lock_data {
502 struct drm_hw_lock *hw_lock; /* Hardware lock */
503 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
504 int lock_queue; /* Queue of blocked processes */
505 unsigned long lock_time; /* Time of last lock in jiffies */
506} drm_lock_data_t;
507
508/* This structure, in the struct drm_device, is always initialized while the
509 * device
510 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
511 * when set marks that no further bufs may be allocated until device teardown
512 * occurs (when the last open of the device has closed). The high/low
513 * watermarks of bufs are only touched by the X Server, and thus not
514 * concurrently accessed, so no locking is needed.
515 */
516typedef struct drm_device_dma {
517 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
518 int buf_count;
519 drm_buf_t **buflist; /* Vector of pointers info bufs */
520 int seg_count;
521 int page_count;
522 unsigned long *pagelist;
523 unsigned long byte_count;
524 enum {
525 _DRM_DMA_USE_AGP = 0x01,
526 _DRM_DMA_USE_SG = 0x02
527 } flags;
528} drm_device_dma_t;
529
530typedef struct drm_agp_mem {
531 void *handle;
532 unsigned long bound; /* address */
533 int pages;
534 struct drm_agp_mem *prev;
535 struct drm_agp_mem *next;
536} drm_agp_mem_t;
537
538typedef struct drm_agp_head {
539 device_t agpdev;
540 struct agp_info info;
541 const char *chipset;
542 drm_agp_mem_t *memory;
543 unsigned long mode;
544 int enabled;
545 int acquired;
546 unsigned long base;
547 int mtrr;
548 int cant_use_aperture;
549 unsigned long page_mask;
550} drm_agp_head_t;
551
552typedef struct drm_sg_mem {
553 vm_offset_t vaddr;
554 vm_paddr_t *busaddr;
555 vm_pindex_t pages;
556} drm_sg_mem_t;
557
558#define DRM_MAP_HANDLE_BITS (sizeof(void *) == 4 ? 4 : 24)
559#define DRM_MAP_HANDLE_SHIFT (sizeof(void *) * 8 - DRM_MAP_HANDLE_BITS)
560typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
561
562typedef struct drm_local_map {
563 unsigned long offset; /* Physical address (0 for SAREA) */
564 unsigned long size; /* Physical size (bytes) */
565 enum drm_map_type type; /* Type of memory mapped */
566 enum drm_map_flags flags; /* Flags */
567 void *handle; /* User-space: "Handle" to pass to mmap */
568 /* Kernel-space: kernel-virtual address */
569 int mtrr; /* Boolean: MTRR used */
570 /* Private data */
571 int rid; /* PCI resource ID for bus_space */
572 void *virtual; /* Kernel-space: kernel-virtual address */
573 struct resource *bsr;
574 bus_space_tag_t bst;
575 bus_space_handle_t bsh;
576 drm_dma_handle_t *dmah;
577 TAILQ_ENTRY(drm_local_map) link;
578} drm_local_map_t;
579
580struct drm_vblank_info {
581 wait_queue_head_t queue; /* vblank wait queue */
582 atomic_t count; /* number of VBLANK interrupts */
583 /* (driver must alloc the right number of counters) */
584 atomic_t refcount; /* number of users of vblank interrupts */
585 u32 last; /* protected by dev->vbl_lock, used */
586 /* for wraparound handling */
587 int enabled; /* so we don't call enable more than */
588 /* once per disable */
589 int inmodeset; /* Display driver is setting mode */
590};
591
592/* Size of ringbuffer for vblank timestamps. Just double-buffer
593 * in initial implementation.
594 */
595#define DRM_VBLANKTIME_RBSIZE 2
596
597/* Flags and return codes for get_vblank_timestamp() driver function. */
598#define DRM_CALLED_FROM_VBLIRQ 1
599#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
600#define DRM_VBLANKTIME_INVBL (1 << 1)
601
602/* get_scanout_position() return flags */
603#define DRM_SCANOUTPOS_VALID (1 << 0)
604#define DRM_SCANOUTPOS_INVBL (1 << 1)
605#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
606
607/* location of GART table */
608#define DRM_ATI_GART_MAIN 1
609#define DRM_ATI_GART_FB 2
610
611#define DRM_ATI_GART_PCI 1
612#define DRM_ATI_GART_PCIE 2
613#define DRM_ATI_GART_IGP 3
614
615struct drm_ati_pcigart_info {
616 int gart_table_location;
617 int gart_reg_if;
618 void *addr;
619 dma_addr_t bus_addr;
620 dma_addr_t table_mask;
621 dma_addr_t member_mask;
622 struct drm_dma_handle *table_handle;
623 drm_local_map_t mapping;
624 int table_size;
625 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
626};
627
628typedef vm_paddr_t resource_size_t;
629
630/**
631 * GEM specific mm private for tracking GEM objects
632 */
633struct drm_gem_mm {
634 struct drm_open_hash offset_hash; /**< User token hash table for maps */
635 struct unrhdr *idxunr;
636};
637
638struct drm_gem_object {
639 /** Reference count of this object */
640 u_int refcount;
641
642 /** Handle count of this object. Each handle also holds a reference */
643 u_int handle_count; /* number of handles on this object */
644
645 /** Related drm device */
646 struct drm_device *dev;
647
648 /** File representing the shmem storage: filp in Linux parlance */
649 vm_object_t vm_obj;
650
651 bool on_map;
652 struct drm_hash_item map_list;
653
654 /**
655 * Size of the object, in bytes. Immutable over the object's
656 * lifetime.
657 */
658 size_t size;
659
660 /**
661 * Global name for this object, starts at 1. 0 means unnamed.
662 * Access is covered by the object_name_lock in the related drm_device
663 */
664 int name;
665
666 /**
667 * Memory domains. These monitor which caches contain read/write data
668 * related to the object. When transitioning from one set of domains
669 * to another, the driver is called to ensure that caches are suitably
670 * flushed and invalidated
671 */
672 uint32_t read_domains;
673 uint32_t write_domain;
674
675 /**
676 * While validating an exec operation, the
677 * new read/write domain values are computed here.
678 * They will be transferred to the above values
679 * at the point that any cache flushing occurs
680 */
681 uint32_t pending_read_domains;
682 uint32_t pending_write_domain;
683
684 void *driver_private;
685};
686
687#include "drm_crtc.h"
688
689#ifndef DMA_BIT_MASK
690#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
691#endif
692
693#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
694
695struct drm_driver_info {
696 int (*load)(struct drm_device *, unsigned long flags);
697 int (*firstopen)(struct drm_device *);
698 int (*open)(struct drm_device *, struct drm_file *);
699 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
700 void (*postclose)(struct drm_device *, struct drm_file *);
701 void (*lastclose)(struct drm_device *);
702 int (*unload)(struct drm_device *);
703 void (*reclaim_buffers_locked)(struct drm_device *,
704 struct drm_file *file_priv);
705 int (*dma_ioctl)(struct drm_device *dev, void *data,
706 struct drm_file *file_priv);
707 void (*dma_ready)(struct drm_device *);
708 int (*dma_quiescent)(struct drm_device *);
709 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
710 enum drm_lock_flags flags);
711 int (*dma_flush_unblock)(struct drm_device *, int context,
712 enum drm_lock_flags flags);
713 int (*context_ctor)(struct drm_device *dev, int context);
714 int (*context_dtor)(struct drm_device *dev, int context);
715 int (*kernel_context_switch)(struct drm_device *dev, int old,
716 int new);
717 int (*kernel_context_switch_unlock)(struct drm_device *dev);
718 void (*irq_preinstall)(struct drm_device *dev);
719 int (*irq_postinstall)(struct drm_device *dev);
720 void (*irq_uninstall)(struct drm_device *dev);
721 void (*irq_handler)(DRM_IRQ_ARGS);
722
723 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
724 int (*enable_vblank)(struct drm_device *dev, int crtc);
725 void (*disable_vblank)(struct drm_device *dev, int crtc);
726 int (*get_scanout_position)(struct drm_device *dev, int crtc,
727 int *vpos, int *hpos);
728
729 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc,
730 int *max_error, struct timeval *vblank_time,
731 unsigned flags);
732
733 int (*gem_init_object)(struct drm_gem_object *obj);
734 void (*gem_free_object)(struct drm_gem_object *obj);
735
736 struct cdev_pager_ops *gem_pager_ops;
737
738 int (*dumb_create)(struct drm_file *file_priv,
739 struct drm_device *dev, struct drm_mode_create_dumb *args);
740 int (*dumb_map_offset)(struct drm_file *file_priv,
741 struct drm_device *dev, uint32_t handle, uint64_t *offset);
742 int (*dumb_destroy)(struct drm_file *file_priv,
743 struct drm_device *dev, uint32_t handle);
744
745 int (*sysctl_init)(struct drm_device *dev,
746 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
747 void (*sysctl_cleanup)(struct drm_device *dev);
748
749 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
750
751 /**
752 * Called by \c drm_device_is_agp. Typically used to determine if a
753 * card is really attached to AGP or not.
754 *
755 * \param dev DRM device handle
756 *
757 * \returns
758 * One of three values is returned depending on whether or not the
759 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
760 * (return of 1), or may or may not be AGP (return of 2).
761 */
762 int (*device_is_agp) (struct drm_device * dev);
763
764 drm_ioctl_desc_t *ioctls;
765#ifdef COMPAT_FREEBSD32
766 drm_ioctl_desc_t *compat_ioctls;
767 int *compat_ioctls_nr;
768#endif
769 int max_ioctl;
770
771 int buf_priv_size;
772
773 int major;
774 int minor;
775 int patchlevel;
776 const char *name; /* Simple driver name */
777 const char *desc; /* Longer driver name */
778 const char *date; /* Date of last major changes. */
779
780 u32 driver_features;
781};
782
783/**
784 * DRM minor structure. This structure represents a drm minor number.
785 */
786struct drm_minor {
787 int index; /**< Minor device number */
788 int type; /**< Control or render */
789 device_t kdev; /**< OS device */
790 struct drm_device *dev;
791
792 struct drm_master *master; /* currently active master for this node */
793 struct list_head master_list;
794 struct drm_mode_group mode_group;
795};
796
797/* mode specified on the command line */
798struct drm_cmdline_mode {
799 bool specified;
800 bool refresh_specified;
801 bool bpp_specified;
802 int xres, yres;
803 int bpp;
804 int refresh;
805 bool rb;
806 bool interlace;
807 bool cvt;
808 bool margins;
809 enum drm_connector_force force;
810};
811
812struct drm_pending_vblank_event {
813 struct drm_pending_event base;
814 int pipe;
815 struct drm_event_vblank event;
816};
817
818/* Length for the array of resource pointers for drm_get_resource_*. */
819#define DRM_MAX_PCI_RESOURCE 6
820
821/**
822 * DRM device functions structure
823 */
824struct drm_device {
825 struct drm_driver_info *driver;
826 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
827
828 u_int16_t pci_device; /* PCI device id */
829 u_int16_t pci_vendor; /* PCI vendor id */
830
831 char *unique; /* Unique identifier: e.g., busid */
832 int unique_len; /* Length of unique field */
833 device_t device; /* Device instance from newbus */
834 struct cdev *devnode; /* Device number for mknod */
835 int if_version; /* Highest interface version set */
836
837 int flags; /* Flags to open(2) */
838
839 /* Locks */
840 struct mtx dma_lock; /* protects dev->dma */
841 struct mtx irq_lock; /* protects irq condition checks */
842 struct mtx dev_lock; /* protects everything else */
843 struct sx dev_struct_lock;
844 DRM_SPINTYPE drw_lock;
845
846 /* Usage Counters */
847 int open_count; /* Outstanding files open */
848 int buf_use; /* Buffers in use -- cannot alloc */
849
850 /* Performance counters */
851 unsigned long counters;
852 enum drm_stat_type types[15];
853 atomic_t counts[15];
854
855 /* Authentication */
856 drm_file_list_t files;
857 drm_magic_head_t magiclist[DRM_HASH_SIZE];
858
859 /* Linked list of mappable regions. Protected by dev_lock */
860 drm_map_list_t maplist;
861 struct unrhdr *map_unrhdr;
862
863 drm_local_map_t **context_sareas;
864 int max_context;
865
866 drm_lock_data_t lock; /* Information on hardware lock */
867
868 /* DMA queues (contexts) */
869 drm_device_dma_t *dma; /* Optional pointer for DMA support */
870
871 /* Context support */
872 int irq; /* Interrupt used by board */
873 int irq_enabled; /* True if the irq handler is enabled */
874 int msi_enabled; /* MSI enabled */
875 int irqrid; /* Interrupt used by board */
876 struct resource *irqr; /* Resource for interrupt used by board */
877 void *irqh; /* Handle from bus_setup_intr */
878
879 /* Storage of resource pointers for drm_get_resource_* */
880 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
881 int pcirid[DRM_MAX_PCI_RESOURCE];
882
883 int pci_domain;
884 int pci_bus;
885 int pci_slot;
886 int pci_func;
887
888 atomic_t context_flag; /* Context swapping flag */
889 int last_context; /* Last current context */
890
891 int num_crtcs;
892
893 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
894
895 /* Sysctl support */
896 struct drm_sysctl_info *sysctl;
897 int sysctl_node_idx;
898
899 drm_agp_head_t *agp;
900 drm_sg_mem_t *sg; /* Scatter gather memory */
901 atomic_t *ctx_bitmap;
902 void *dev_private;
903 unsigned int agp_buffer_token;
904 drm_local_map_t *agp_buffer_map;
905
906 struct drm_minor *control; /**< Control node for card */
907 struct drm_minor *primary; /**< render type primary screen head */
908
36
37#ifndef _DRM_P_H_
38#define _DRM_P_H_
39
40#if defined(_KERNEL) || defined(__KERNEL__)
41
42struct drm_device;
43struct drm_file;
44
45#include <sys/param.h>
46#include <sys/queue.h>
47#include <sys/malloc.h>
48#include <sys/kernel.h>
49#include <sys/ktr.h>
50#include <sys/module.h>
51#include <sys/systm.h>
52#include <sys/conf.h>
53#include <sys/sglist.h>
54#include <sys/stat.h>
55#include <sys/priv.h>
56#include <sys/proc.h>
57#include <sys/lock.h>
58#include <sys/fcntl.h>
59#include <sys/uio.h>
60#include <sys/filio.h>
61#include <sys/selinfo.h>
62#include <sys/sysctl.h>
63#include <sys/bus.h>
64#include <sys/queue.h>
65#include <sys/signalvar.h>
66#include <sys/poll.h>
67#include <sys/sbuf.h>
68#include <sys/taskqueue.h>
69#include <sys/tree.h>
70#include <vm/vm.h>
71#include <vm/pmap.h>
72#include <vm/vm_extern.h>
73#include <vm/vm_kern.h>
74#include <vm/vm_map.h>
75#include <vm/vm_object.h>
76#include <vm/vm_page.h>
77#include <vm/vm_pager.h>
78#include <vm/vm_param.h>
79#include <vm/vm_phys.h>
80#include <machine/param.h>
81#include <machine/pmap.h>
82#include <machine/bus.h>
83#include <machine/resource.h>
84#if defined(__i386__) || defined(__amd64__)
85#include <machine/specialreg.h>
86#endif
87#include <machine/sysarch.h>
88#include <sys/endian.h>
89#include <sys/mman.h>
90#include <sys/rman.h>
91#include <sys/memrange.h>
92#include <dev/agp/agpvar.h>
93#include <sys/agpio.h>
94#include <sys/mutex.h>
95#include <dev/pci/pcivar.h>
96#include <dev/pci/pcireg.h>
97#include <sys/selinfo.h>
98#include <sys/bus.h>
99
100#include <dev/drm2/drm.h>
101#include <dev/drm2/drm_atomic.h>
102#include <dev/drm2/drm_internal.h>
103#include <dev/drm2/drm_linux_list.h>
104#include <dev/drm2/drm_gem_names.h>
105#include <dev/drm2/drm_mm.h>
106#include <dev/drm2/drm_hashtab.h>
107
108#include "opt_compat.h"
109#include "opt_drm.h"
110#ifdef DRM_DEBUG
111#undef DRM_DEBUG
112#define DRM_DEBUG_DEFAULT_ON 1
113#endif /* DRM_DEBUG */
114
115#define DRM_DEBUGBITS_DEBUG 0x1
116#define DRM_DEBUGBITS_KMS 0x2
117#define DRM_DEBUGBITS_FAILED_IOCTL 0x4
118
119#undef DRM_LINUX
120#define DRM_LINUX 0
121
122/* driver capabilities and requirements mask */
123#define DRIVER_USE_AGP 0x1
124#define DRIVER_REQUIRE_AGP 0x2
125#define DRIVER_USE_MTRR 0x4
126#define DRIVER_PCI_DMA 0x8
127#define DRIVER_SG 0x10
128#define DRIVER_HAVE_DMA 0x20
129#define DRIVER_HAVE_IRQ 0x40
130#define DRIVER_IRQ_SHARED 0x80
131#define DRIVER_IRQ_VBL 0x100
132#define DRIVER_DMA_QUEUE 0x200
133#define DRIVER_FB_DMA 0x400
134#define DRIVER_IRQ_VBL2 0x800
135#define DRIVER_GEM 0x1000
136#define DRIVER_MODESET 0x2000
137#define DRIVER_USE_PLATFORM_DEVICE 0x4000
138#define DRIVER_LOCKLESS_IRQ 0x8000
139
140
141#define DRM_HASH_SIZE 16 /* Size of key hash table */
142#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
143#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
144
145#define DRM_GEM_MAPPING_MASK (3ULL << 62)
146#define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */
147#define DRM_GEM_MAX_IDX 0x3fffff
148#define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX)
149#define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40)
150#define DRM_GEM_MAPPING_MAPOFF(o) \
151 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
152
153MALLOC_DECLARE(DRM_MEM_DMA);
154MALLOC_DECLARE(DRM_MEM_SAREA);
155MALLOC_DECLARE(DRM_MEM_DRIVER);
156MALLOC_DECLARE(DRM_MEM_MAGIC);
157MALLOC_DECLARE(DRM_MEM_IOCTLS);
158MALLOC_DECLARE(DRM_MEM_MAPS);
159MALLOC_DECLARE(DRM_MEM_BUFS);
160MALLOC_DECLARE(DRM_MEM_SEGS);
161MALLOC_DECLARE(DRM_MEM_PAGES);
162MALLOC_DECLARE(DRM_MEM_FILES);
163MALLOC_DECLARE(DRM_MEM_QUEUES);
164MALLOC_DECLARE(DRM_MEM_CMDS);
165MALLOC_DECLARE(DRM_MEM_MAPPINGS);
166MALLOC_DECLARE(DRM_MEM_BUFLISTS);
167MALLOC_DECLARE(DRM_MEM_AGPLISTS);
168MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
169MALLOC_DECLARE(DRM_MEM_SGLISTS);
170MALLOC_DECLARE(DRM_MEM_DRAWABLE);
171MALLOC_DECLARE(DRM_MEM_MM);
172MALLOC_DECLARE(DRM_MEM_HASHTAB);
173MALLOC_DECLARE(DRM_MEM_KMS);
174
175SYSCTL_DECL(_hw_drm);
176
177#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
178
179 /* Internal types and structures */
180#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
181#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
182#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
183
184#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
185
186#define __OS_HAS_AGP 1
187
188#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
189#define DRM_DEV_UID 0
190#define DRM_DEV_GID 0
191
192#define wait_queue_head_t atomic_t
193#define DRM_WAKEUP(w) wakeup((void *)w)
194#define DRM_WAKEUP_INT(w) wakeup(w)
195#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
196
197#define DRM_CURPROC curthread
198#define DRM_STRUCTPROC struct thread
199#define DRM_SPINTYPE struct mtx
200#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
201#define DRM_SPINUNINIT(l) mtx_destroy(l)
202#define DRM_SPINLOCK(l) mtx_lock(l)
203#define DRM_SPINUNLOCK(u) mtx_unlock(u)
204#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
205 mtx_lock(l); \
206 (void)irqflags; \
207} while (0)
208#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
209#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
210#define DRM_CURRENTPID curthread->td_proc->p_pid
211#define DRM_LOCK(dev) sx_xlock(&(dev)->dev_struct_lock)
212#define DRM_UNLOCK(dev) sx_xunlock(&(dev)->dev_struct_lock)
213#define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
214 (sx_sleep((chan), &(dev)->dev_struct_lock, (flags), (msg), (timeout)))
215#if defined(INVARIANTS)
216#define DRM_LOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_XLOCKED)
217#define DRM_UNLOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_UNLOCKED)
218#else
219#define DRM_LOCK_ASSERT(d)
220#define DRM_UNLOCK_ASSERT(d)
221#endif
222
223#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
224
225#define DRM_IRQ_ARGS void *arg
226typedef void irqreturn_t;
227#define IRQ_HANDLED /* nothing */
228#define IRQ_NONE /* nothing */
229
230#define unlikely(x) __builtin_expect(!!(x), 0)
231#define likely(x) __builtin_expect((x), 0)
232#define container_of(ptr, type, member) ({ \
233 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
234 (type *)( (char *)__mptr - offsetof(type,member) );})
235
236enum {
237 DRM_IS_NOT_AGP,
238 DRM_IS_AGP,
239 DRM_MIGHT_BE_AGP
240};
241#define DRM_AGP_MEM struct agp_memory_info
242
243#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
244
245#define PAGE_ALIGN(addr) round_page(addr)
246/* DRM_SUSER returns true if the user is superuser */
247#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
248#define DRM_AGP_FIND_DEVICE() agp_find_device()
249#define DRM_MTRR_WC MDF_WRITECOMBINE
250#define jiffies ticks
251#define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz)
252#define msecs_to_jiffies(x) (((int64_t)(x)) * hz / 1000)
253#define time_after(a,b) ((long)(b) - (long)(a) < 0)
254#define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0)
255#define drm_msleep(x, msg) pause((msg), ((int64_t)(x)) * hz / 1000)
256
257typedef vm_paddr_t dma_addr_t;
258typedef uint64_t u64;
259typedef uint32_t u32;
260typedef uint16_t u16;
261typedef uint8_t u8;
262typedef int64_t s64;
263typedef int32_t s32;
264typedef int16_t s16;
265typedef int8_t s8;
266
267/* DRM_READMEMORYBARRIER() prevents reordering of reads.
268 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
269 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
270 */
271#define DRM_READMEMORYBARRIER() rmb()
272#define DRM_WRITEMEMORYBARRIER() wmb()
273#define DRM_MEMORYBARRIER() mb()
274
275#define DRM_READ8(map, offset) \
276 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \
277 (vm_offset_t)(offset))
278#define DRM_READ16(map, offset) \
279 le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \
280 (vm_offset_t)(offset)))
281#define DRM_READ32(map, offset) \
282 le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \
283 (vm_offset_t)(offset)))
284#define DRM_READ64(map, offset) \
285 le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \
286 (vm_offset_t)(offset)))
287#define DRM_WRITE8(map, offset, val) \
288 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \
289 (vm_offset_t)(offset)) = val
290#define DRM_WRITE16(map, offset, val) \
291 *(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \
292 (vm_offset_t)(offset)) = htole16(val)
293#define DRM_WRITE32(map, offset, val) \
294 *(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \
295 (vm_offset_t)(offset)) = htole32(val)
296#define DRM_WRITE64(map, offset, val) \
297 *(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \
298 (vm_offset_t)(offset)) = htole64(val)
299
300#define DRM_VERIFYAREA_READ( uaddr, size ) \
301 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
302
303#define DRM_COPY_TO_USER(user, kern, size) \
304 copyout(kern, user, size)
305#define DRM_COPY_FROM_USER(kern, user, size) \
306 copyin(user, kern, size)
307#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
308 copyin(arg2, arg1, arg3)
309#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
310 copyout(arg2, arg1, arg3)
311#define DRM_GET_USER_UNCHECKED(val, uaddr) \
312 ((val) = fuword32(uaddr), 0)
313
314#define cpu_to_le32(x) htole32(x)
315#define le32_to_cpu(x) le32toh(x)
316
317#define DRM_HZ hz
318#define DRM_UDELAY(udelay) DELAY(udelay)
319#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
320
321#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
322 (_map) = (_dev)->context_sareas[_ctx]; \
323} while(0)
324
325#define LOCK_TEST_WITH_RETURN(dev, file_priv) \
326do { \
327 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
328 dev->lock.file_priv != file_priv) { \
329 DRM_ERROR("%s called without lock held\n", \
330 __FUNCTION__); \
331 return EINVAL; \
332 } \
333} while (0)
334
335/* Returns -errno to shared code */
336#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
337for ( ret = 0 ; !ret && !(condition) ; ) { \
338 DRM_UNLOCK(dev); \
339 mtx_lock(&dev->irq_lock); \
340 if (!(condition)) \
341 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
342 PCATCH, "drmwtq", (timeout)); \
343 mtx_unlock(&dev->irq_lock); \
344 DRM_LOCK(dev); \
345}
346
347#define DRM_ERROR(fmt, ...) \
348 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
349 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
350
351#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
352
353#define DRM_DEBUG(fmt, ...) do { \
354 if ((drm_debug_flag & DRM_DEBUGBITS_DEBUG) != 0) \
355 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
356 __func__ , ##__VA_ARGS__); \
357} while (0)
358
359#define DRM_DEBUG_KMS(fmt, ...) do { \
360 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \
361 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
362 __func__ , ##__VA_ARGS__); \
363} while (0)
364
365#define DRM_DEBUG_DRIVER(fmt, ...) do { \
366 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \
367 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
368 __func__ , ##__VA_ARGS__); \
369} while (0)
370
371typedef struct drm_pci_id_list
372{
373 int vendor;
374 int device;
375 long driver_private;
376 char *name;
377} drm_pci_id_list_t;
378
379struct drm_msi_blacklist_entry
380{
381 int vendor;
382 int device;
383};
384
385#define DRM_AUTH 0x1
386#define DRM_MASTER 0x2
387#define DRM_ROOT_ONLY 0x4
388#define DRM_CONTROL_ALLOW 0x8
389#define DRM_UNLOCKED 0x10
390
391typedef struct drm_ioctl_desc {
392 unsigned long cmd;
393 int (*func)(struct drm_device *dev, void *data,
394 struct drm_file *file_priv);
395 int flags;
396} drm_ioctl_desc_t;
397/**
398 * Creates a driver or general drm_ioctl_desc array entry for the given
399 * ioctl, for use by drm_ioctl().
400 */
401#define DRM_IOCTL_DEF(ioctl, func, flags) \
402 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
403
404typedef struct drm_magic_entry {
405 drm_magic_t magic;
406 struct drm_file *priv;
407 struct drm_magic_entry *next;
408} drm_magic_entry_t;
409
410typedef struct drm_magic_head {
411 struct drm_magic_entry *head;
412 struct drm_magic_entry *tail;
413} drm_magic_head_t;
414
415typedef struct drm_buf {
416 int idx; /* Index into master buflist */
417 int total; /* Buffer size */
418 int order; /* log-base-2(total) */
419 int used; /* Amount of buffer in use (for DMA) */
420 unsigned long offset; /* Byte offset (used internally) */
421 void *address; /* Address of buffer */
422 unsigned long bus_address; /* Bus address of buffer */
423 struct drm_buf *next; /* Kernel-only: used for free list */
424 __volatile__ int pending; /* On hardware DMA queue */
425 struct drm_file *file_priv; /* Unique identifier of holding process */
426 int context; /* Kernel queue for this buffer */
427 enum {
428 DRM_LIST_NONE = 0,
429 DRM_LIST_FREE = 1,
430 DRM_LIST_WAIT = 2,
431 DRM_LIST_PEND = 3,
432 DRM_LIST_PRIO = 4,
433 DRM_LIST_RECLAIM = 5
434 } list; /* Which list we're on */
435
436 int dev_priv_size; /* Size of buffer private stoarge */
437 void *dev_private; /* Per-buffer private storage */
438} drm_buf_t;
439
440typedef struct drm_freelist {
441 int initialized; /* Freelist in use */
442 atomic_t count; /* Number of free buffers */
443 drm_buf_t *next; /* End pointer */
444
445 int low_mark; /* Low water mark */
446 int high_mark; /* High water mark */
447} drm_freelist_t;
448
449typedef struct drm_dma_handle {
450 void *vaddr;
451 bus_addr_t busaddr;
452 bus_dma_tag_t tag;
453 bus_dmamap_t map;
454} drm_dma_handle_t;
455
456typedef struct drm_buf_entry {
457 int buf_size;
458 int buf_count;
459 drm_buf_t *buflist;
460 int seg_count;
461 drm_dma_handle_t **seglist;
462 int page_order;
463
464 drm_freelist_t freelist;
465} drm_buf_entry_t;
466
467/* Event queued up for userspace to read */
468struct drm_pending_event {
469 struct drm_event *event;
470 struct list_head link;
471 struct drm_file *file_priv;
472 pid_t pid; /* pid of requester, no guarantee it's valid by the time
473 we deliver the event, for tracing only */
474 void (*destroy)(struct drm_pending_event *event);
475};
476
477typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
478struct drm_file {
479 TAILQ_ENTRY(drm_file) link;
480 struct drm_device *dev;
481 int authenticated;
482 int master;
483 pid_t pid;
484 uid_t uid;
485 drm_magic_t magic;
486 unsigned long ioctl_count;
487
488 void *driver_priv;
489 struct drm_gem_names object_names;
490
491 int is_master;
492 struct drm_master *masterp;
493
494 struct list_head fbs;
495
496 struct list_head event_list;
497 int event_space;
498 struct selinfo event_poll;
499};
500
501typedef struct drm_lock_data {
502 struct drm_hw_lock *hw_lock; /* Hardware lock */
503 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
504 int lock_queue; /* Queue of blocked processes */
505 unsigned long lock_time; /* Time of last lock in jiffies */
506} drm_lock_data_t;
507
508/* This structure, in the struct drm_device, is always initialized while the
509 * device
510 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
511 * when set marks that no further bufs may be allocated until device teardown
512 * occurs (when the last open of the device has closed). The high/low
513 * watermarks of bufs are only touched by the X Server, and thus not
514 * concurrently accessed, so no locking is needed.
515 */
516typedef struct drm_device_dma {
517 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
518 int buf_count;
519 drm_buf_t **buflist; /* Vector of pointers info bufs */
520 int seg_count;
521 int page_count;
522 unsigned long *pagelist;
523 unsigned long byte_count;
524 enum {
525 _DRM_DMA_USE_AGP = 0x01,
526 _DRM_DMA_USE_SG = 0x02
527 } flags;
528} drm_device_dma_t;
529
530typedef struct drm_agp_mem {
531 void *handle;
532 unsigned long bound; /* address */
533 int pages;
534 struct drm_agp_mem *prev;
535 struct drm_agp_mem *next;
536} drm_agp_mem_t;
537
538typedef struct drm_agp_head {
539 device_t agpdev;
540 struct agp_info info;
541 const char *chipset;
542 drm_agp_mem_t *memory;
543 unsigned long mode;
544 int enabled;
545 int acquired;
546 unsigned long base;
547 int mtrr;
548 int cant_use_aperture;
549 unsigned long page_mask;
550} drm_agp_head_t;
551
552typedef struct drm_sg_mem {
553 vm_offset_t vaddr;
554 vm_paddr_t *busaddr;
555 vm_pindex_t pages;
556} drm_sg_mem_t;
557
558#define DRM_MAP_HANDLE_BITS (sizeof(void *) == 4 ? 4 : 24)
559#define DRM_MAP_HANDLE_SHIFT (sizeof(void *) * 8 - DRM_MAP_HANDLE_BITS)
560typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
561
562typedef struct drm_local_map {
563 unsigned long offset; /* Physical address (0 for SAREA) */
564 unsigned long size; /* Physical size (bytes) */
565 enum drm_map_type type; /* Type of memory mapped */
566 enum drm_map_flags flags; /* Flags */
567 void *handle; /* User-space: "Handle" to pass to mmap */
568 /* Kernel-space: kernel-virtual address */
569 int mtrr; /* Boolean: MTRR used */
570 /* Private data */
571 int rid; /* PCI resource ID for bus_space */
572 void *virtual; /* Kernel-space: kernel-virtual address */
573 struct resource *bsr;
574 bus_space_tag_t bst;
575 bus_space_handle_t bsh;
576 drm_dma_handle_t *dmah;
577 TAILQ_ENTRY(drm_local_map) link;
578} drm_local_map_t;
579
580struct drm_vblank_info {
581 wait_queue_head_t queue; /* vblank wait queue */
582 atomic_t count; /* number of VBLANK interrupts */
583 /* (driver must alloc the right number of counters) */
584 atomic_t refcount; /* number of users of vblank interrupts */
585 u32 last; /* protected by dev->vbl_lock, used */
586 /* for wraparound handling */
587 int enabled; /* so we don't call enable more than */
588 /* once per disable */
589 int inmodeset; /* Display driver is setting mode */
590};
591
592/* Size of ringbuffer for vblank timestamps. Just double-buffer
593 * in initial implementation.
594 */
595#define DRM_VBLANKTIME_RBSIZE 2
596
597/* Flags and return codes for get_vblank_timestamp() driver function. */
598#define DRM_CALLED_FROM_VBLIRQ 1
599#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
600#define DRM_VBLANKTIME_INVBL (1 << 1)
601
602/* get_scanout_position() return flags */
603#define DRM_SCANOUTPOS_VALID (1 << 0)
604#define DRM_SCANOUTPOS_INVBL (1 << 1)
605#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
606
607/* location of GART table */
608#define DRM_ATI_GART_MAIN 1
609#define DRM_ATI_GART_FB 2
610
611#define DRM_ATI_GART_PCI 1
612#define DRM_ATI_GART_PCIE 2
613#define DRM_ATI_GART_IGP 3
614
615struct drm_ati_pcigart_info {
616 int gart_table_location;
617 int gart_reg_if;
618 void *addr;
619 dma_addr_t bus_addr;
620 dma_addr_t table_mask;
621 dma_addr_t member_mask;
622 struct drm_dma_handle *table_handle;
623 drm_local_map_t mapping;
624 int table_size;
625 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
626};
627
628typedef vm_paddr_t resource_size_t;
629
630/**
631 * GEM specific mm private for tracking GEM objects
632 */
633struct drm_gem_mm {
634 struct drm_open_hash offset_hash; /**< User token hash table for maps */
635 struct unrhdr *idxunr;
636};
637
638struct drm_gem_object {
639 /** Reference count of this object */
640 u_int refcount;
641
642 /** Handle count of this object. Each handle also holds a reference */
643 u_int handle_count; /* number of handles on this object */
644
645 /** Related drm device */
646 struct drm_device *dev;
647
648 /** File representing the shmem storage: filp in Linux parlance */
649 vm_object_t vm_obj;
650
651 bool on_map;
652 struct drm_hash_item map_list;
653
654 /**
655 * Size of the object, in bytes. Immutable over the object's
656 * lifetime.
657 */
658 size_t size;
659
660 /**
661 * Global name for this object, starts at 1. 0 means unnamed.
662 * Access is covered by the object_name_lock in the related drm_device
663 */
664 int name;
665
666 /**
667 * Memory domains. These monitor which caches contain read/write data
668 * related to the object. When transitioning from one set of domains
669 * to another, the driver is called to ensure that caches are suitably
670 * flushed and invalidated
671 */
672 uint32_t read_domains;
673 uint32_t write_domain;
674
675 /**
676 * While validating an exec operation, the
677 * new read/write domain values are computed here.
678 * They will be transferred to the above values
679 * at the point that any cache flushing occurs
680 */
681 uint32_t pending_read_domains;
682 uint32_t pending_write_domain;
683
684 void *driver_private;
685};
686
687#include "drm_crtc.h"
688
689#ifndef DMA_BIT_MASK
690#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
691#endif
692
693#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
694
695struct drm_driver_info {
696 int (*load)(struct drm_device *, unsigned long flags);
697 int (*firstopen)(struct drm_device *);
698 int (*open)(struct drm_device *, struct drm_file *);
699 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
700 void (*postclose)(struct drm_device *, struct drm_file *);
701 void (*lastclose)(struct drm_device *);
702 int (*unload)(struct drm_device *);
703 void (*reclaim_buffers_locked)(struct drm_device *,
704 struct drm_file *file_priv);
705 int (*dma_ioctl)(struct drm_device *dev, void *data,
706 struct drm_file *file_priv);
707 void (*dma_ready)(struct drm_device *);
708 int (*dma_quiescent)(struct drm_device *);
709 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
710 enum drm_lock_flags flags);
711 int (*dma_flush_unblock)(struct drm_device *, int context,
712 enum drm_lock_flags flags);
713 int (*context_ctor)(struct drm_device *dev, int context);
714 int (*context_dtor)(struct drm_device *dev, int context);
715 int (*kernel_context_switch)(struct drm_device *dev, int old,
716 int new);
717 int (*kernel_context_switch_unlock)(struct drm_device *dev);
718 void (*irq_preinstall)(struct drm_device *dev);
719 int (*irq_postinstall)(struct drm_device *dev);
720 void (*irq_uninstall)(struct drm_device *dev);
721 void (*irq_handler)(DRM_IRQ_ARGS);
722
723 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
724 int (*enable_vblank)(struct drm_device *dev, int crtc);
725 void (*disable_vblank)(struct drm_device *dev, int crtc);
726 int (*get_scanout_position)(struct drm_device *dev, int crtc,
727 int *vpos, int *hpos);
728
729 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc,
730 int *max_error, struct timeval *vblank_time,
731 unsigned flags);
732
733 int (*gem_init_object)(struct drm_gem_object *obj);
734 void (*gem_free_object)(struct drm_gem_object *obj);
735
736 struct cdev_pager_ops *gem_pager_ops;
737
738 int (*dumb_create)(struct drm_file *file_priv,
739 struct drm_device *dev, struct drm_mode_create_dumb *args);
740 int (*dumb_map_offset)(struct drm_file *file_priv,
741 struct drm_device *dev, uint32_t handle, uint64_t *offset);
742 int (*dumb_destroy)(struct drm_file *file_priv,
743 struct drm_device *dev, uint32_t handle);
744
745 int (*sysctl_init)(struct drm_device *dev,
746 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
747 void (*sysctl_cleanup)(struct drm_device *dev);
748
749 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
750
751 /**
752 * Called by \c drm_device_is_agp. Typically used to determine if a
753 * card is really attached to AGP or not.
754 *
755 * \param dev DRM device handle
756 *
757 * \returns
758 * One of three values is returned depending on whether or not the
759 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
760 * (return of 1), or may or may not be AGP (return of 2).
761 */
762 int (*device_is_agp) (struct drm_device * dev);
763
764 drm_ioctl_desc_t *ioctls;
765#ifdef COMPAT_FREEBSD32
766 drm_ioctl_desc_t *compat_ioctls;
767 int *compat_ioctls_nr;
768#endif
769 int max_ioctl;
770
771 int buf_priv_size;
772
773 int major;
774 int minor;
775 int patchlevel;
776 const char *name; /* Simple driver name */
777 const char *desc; /* Longer driver name */
778 const char *date; /* Date of last major changes. */
779
780 u32 driver_features;
781};
782
783/**
784 * DRM minor structure. This structure represents a drm minor number.
785 */
786struct drm_minor {
787 int index; /**< Minor device number */
788 int type; /**< Control or render */
789 device_t kdev; /**< OS device */
790 struct drm_device *dev;
791
792 struct drm_master *master; /* currently active master for this node */
793 struct list_head master_list;
794 struct drm_mode_group mode_group;
795};
796
797/* mode specified on the command line */
798struct drm_cmdline_mode {
799 bool specified;
800 bool refresh_specified;
801 bool bpp_specified;
802 int xres, yres;
803 int bpp;
804 int refresh;
805 bool rb;
806 bool interlace;
807 bool cvt;
808 bool margins;
809 enum drm_connector_force force;
810};
811
812struct drm_pending_vblank_event {
813 struct drm_pending_event base;
814 int pipe;
815 struct drm_event_vblank event;
816};
817
818/* Length for the array of resource pointers for drm_get_resource_*. */
819#define DRM_MAX_PCI_RESOURCE 6
820
821/**
822 * DRM device functions structure
823 */
824struct drm_device {
825 struct drm_driver_info *driver;
826 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
827
828 u_int16_t pci_device; /* PCI device id */
829 u_int16_t pci_vendor; /* PCI vendor id */
830
831 char *unique; /* Unique identifier: e.g., busid */
832 int unique_len; /* Length of unique field */
833 device_t device; /* Device instance from newbus */
834 struct cdev *devnode; /* Device number for mknod */
835 int if_version; /* Highest interface version set */
836
837 int flags; /* Flags to open(2) */
838
839 /* Locks */
840 struct mtx dma_lock; /* protects dev->dma */
841 struct mtx irq_lock; /* protects irq condition checks */
842 struct mtx dev_lock; /* protects everything else */
843 struct sx dev_struct_lock;
844 DRM_SPINTYPE drw_lock;
845
846 /* Usage Counters */
847 int open_count; /* Outstanding files open */
848 int buf_use; /* Buffers in use -- cannot alloc */
849
850 /* Performance counters */
851 unsigned long counters;
852 enum drm_stat_type types[15];
853 atomic_t counts[15];
854
855 /* Authentication */
856 drm_file_list_t files;
857 drm_magic_head_t magiclist[DRM_HASH_SIZE];
858
859 /* Linked list of mappable regions. Protected by dev_lock */
860 drm_map_list_t maplist;
861 struct unrhdr *map_unrhdr;
862
863 drm_local_map_t **context_sareas;
864 int max_context;
865
866 drm_lock_data_t lock; /* Information on hardware lock */
867
868 /* DMA queues (contexts) */
869 drm_device_dma_t *dma; /* Optional pointer for DMA support */
870
871 /* Context support */
872 int irq; /* Interrupt used by board */
873 int irq_enabled; /* True if the irq handler is enabled */
874 int msi_enabled; /* MSI enabled */
875 int irqrid; /* Interrupt used by board */
876 struct resource *irqr; /* Resource for interrupt used by board */
877 void *irqh; /* Handle from bus_setup_intr */
878
879 /* Storage of resource pointers for drm_get_resource_* */
880 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
881 int pcirid[DRM_MAX_PCI_RESOURCE];
882
883 int pci_domain;
884 int pci_bus;
885 int pci_slot;
886 int pci_func;
887
888 atomic_t context_flag; /* Context swapping flag */
889 int last_context; /* Last current context */
890
891 int num_crtcs;
892
893 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
894
895 /* Sysctl support */
896 struct drm_sysctl_info *sysctl;
897 int sysctl_node_idx;
898
899 drm_agp_head_t *agp;
900 drm_sg_mem_t *sg; /* Scatter gather memory */
901 atomic_t *ctx_bitmap;
902 void *dev_private;
903 unsigned int agp_buffer_token;
904 drm_local_map_t *agp_buffer_map;
905
906 struct drm_minor *control; /**< Control node for card */
907 struct drm_minor *primary; /**< render type primary screen head */
908
909 void *drm_ttm_bo;
909 struct unrhdr *drw_unrhdr;
910 /* RB tree of drawable infos */
911 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
912
913 int vblank_disable_allowed;
914
915 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
916 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
917 struct mtx vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
918 struct mtx vbl_lock;
919 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
920 u32 *last_vblank; /* protected by dev->vbl_lock, used */
921 /* for wraparound handling */
922 int *vblank_enabled; /* so we don't call enable more than
923 once per disable */
924 int *vblank_inmodeset; /* Display driver is setting mode */
925 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
926 struct callout vblank_disable_callout;
927
928 u32 max_vblank_count; /**< size of vblank counter register */
929
930 struct list_head vblank_event_list;
931 struct mtx event_lock;
932
933 struct drm_mode_config mode_config; /**< Current mode config */
934
935 /* GEM part */
936 struct sx object_name_lock;
937 struct drm_gem_names object_names;
938 void *mm_private;
939
940 void *sysctl_private;
941 char busid_str[128];
942 int modesetting;
943};
944
945static __inline__ int drm_core_check_feature(struct drm_device *dev,
946 int feature)
947{
948 return ((dev->driver->driver_features & feature) ? 1 : 0);
949}
950
951#if __OS_HAS_AGP
952static inline int drm_core_has_AGP(struct drm_device *dev)
953{
954 return drm_core_check_feature(dev, DRIVER_USE_AGP);
955}
956#else
957#define drm_core_has_AGP(dev) (0)
958#endif
959
960enum dmi_field {
961 DMI_NONE,
962 DMI_BIOS_VENDOR,
963 DMI_BIOS_VERSION,
964 DMI_BIOS_DATE,
965 DMI_SYS_VENDOR,
966 DMI_PRODUCT_NAME,
967 DMI_PRODUCT_VERSION,
968 DMI_PRODUCT_SERIAL,
969 DMI_PRODUCT_UUID,
970 DMI_BOARD_VENDOR,
971 DMI_BOARD_NAME,
972 DMI_BOARD_VERSION,
973 DMI_BOARD_SERIAL,
974 DMI_BOARD_ASSET_TAG,
975 DMI_CHASSIS_VENDOR,
976 DMI_CHASSIS_TYPE,
977 DMI_CHASSIS_VERSION,
978 DMI_CHASSIS_SERIAL,
979 DMI_CHASSIS_ASSET_TAG,
980 DMI_STRING_MAX,
981};
982
983struct dmi_strmatch {
984 unsigned char slot;
985 char substr[79];
986};
987
988struct dmi_system_id {
989 int (*callback)(const struct dmi_system_id *);
990 const char *ident;
991 struct dmi_strmatch matches[4];
992};
993#define DMI_MATCH(a, b) {(a), (b)}
994bool dmi_check_system(const struct dmi_system_id *);
995
996extern int drm_debug_flag;
997extern int drm_notyet_flag;
998extern unsigned int drm_vblank_offdelay;
999extern unsigned int drm_timestamp_precision;
1000
1001/* Device setup support (drm_drv.c) */
1002int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1003int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1004int drm_create_cdevs(device_t kdev);
1005void drm_close(void *data);
1006int drm_detach(device_t kdev);
1007d_ioctl_t drm_ioctl;
1008d_open_t drm_open;
1009d_read_t drm_read;
1010d_poll_t drm_poll;
1011d_mmap_t drm_mmap;
1012extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1013
1014void drm_event_wakeup(struct drm_pending_event *e);
1015
1016int drm_add_busid_modesetting(struct drm_device *dev,
1017 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1018
1019/* File operations helpers (drm_fops.c) */
1020extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
1021 DRM_STRUCTPROC *p,
1022 struct drm_device *dev);
1023
1024/* Memory management support (drm_memory.c) */
1025void drm_mem_init(void);
1026void drm_mem_uninit(void);
1027void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1028void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1029void drm_ioremapfree(drm_local_map_t *map);
1030int drm_mtrr_add(unsigned long offset, size_t size, int flags);
1031int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1032
1033int drm_context_switch(struct drm_device *dev, int old, int new);
1034int drm_context_switch_complete(struct drm_device *dev, int new);
1035
1036int drm_ctxbitmap_init(struct drm_device *dev);
1037void drm_ctxbitmap_cleanup(struct drm_device *dev);
1038void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1039int drm_ctxbitmap_next(struct drm_device *dev);
1040
1041/* Locking IOCTL support (drm_lock.c) */
1042int drm_lock_take(struct drm_lock_data *lock_data,
1043 unsigned int context);
1044int drm_lock_transfer(struct drm_lock_data *lock_data,
1045 unsigned int context);
1046int drm_lock_free(struct drm_lock_data *lock_data,
1047 unsigned int context);
1048
1049/* Buffer management support (drm_bufs.c) */
1050unsigned long drm_get_resource_start(struct drm_device *dev,
1051 unsigned int resource);
1052unsigned long drm_get_resource_len(struct drm_device *dev,
1053 unsigned int resource);
1054void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1055int drm_order(unsigned long size);
1056int drm_addmap(struct drm_device *dev, unsigned long offset,
1057 unsigned long size,
1058 enum drm_map_type type, enum drm_map_flags flags,
1059 drm_local_map_t **map_ptr);
1060int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1061int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
1062int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1063
1064/* DMA support (drm_dma.c) */
1065int drm_dma_setup(struct drm_device *dev);
1066void drm_dma_takedown(struct drm_device *dev);
1067void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1068void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1069#define drm_core_reclaim_buffers drm_reclaim_buffers
1070
1071/* IRQ support (drm_irq.c) */
1072int drm_irq_install(struct drm_device *dev);
1073int drm_irq_uninstall(struct drm_device *dev);
1074irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1075void drm_driver_irq_preinstall(struct drm_device *dev);
1076void drm_driver_irq_postinstall(struct drm_device *dev);
1077void drm_driver_irq_uninstall(struct drm_device *dev);
1078
1079void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1080void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1081int drm_modeset_ctl(struct drm_device *dev, void *data,
1082 struct drm_file *file_priv);
1083
1084extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1085extern int drm_wait_vblank(struct drm_device *dev, void *data,
1086 struct drm_file *filp);
1087extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1088extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1089extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1090 struct timeval *vblanktime);
1091extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1092void drm_handle_vblank_events(struct drm_device *dev, int crtc);
1093extern int drm_vblank_get(struct drm_device *dev, int crtc);
1094extern void drm_vblank_put(struct drm_device *dev, int crtc);
1095extern void drm_vblank_off(struct drm_device *dev, int crtc);
1096extern void drm_vblank_cleanup(struct drm_device *dev);
1097extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1098 struct timeval *tvblank, unsigned flags);
1099extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1100 int crtc, int *max_error,
1101 struct timeval *vblank_time,
1102 unsigned flags,
1103 struct drm_crtc *refcrtc);
1104extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1105
1106struct timeval ns_to_timeval(const int64_t nsec);
1107int64_t timeval_to_ns(const struct timeval *tv);
1108
1109/* AGP/PCI Express/GART support (drm_agpsupport.c) */
1110int drm_device_is_agp(struct drm_device *dev);
1111int drm_device_is_pcie(struct drm_device *dev);
1112drm_agp_head_t *drm_agp_init(void);
1113int drm_agp_acquire(struct drm_device *dev);
1114int drm_agp_release(struct drm_device *dev);
1115int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1116int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1117void *drm_agp_allocate_memory(size_t pages, u32 type);
1118int drm_agp_free_memory(void *handle);
1119int drm_agp_bind_memory(void *handle, off_t start);
1120int drm_agp_unbind_memory(void *handle);
1121int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1122int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1123int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1124int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1125
1126/* Scatter Gather Support (drm_scatter.c) */
1127void drm_sg_cleanup(drm_sg_mem_t *entry);
1128int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1129
1130/* sysctl support (drm_sysctl.h) */
1131extern int drm_sysctl_init(struct drm_device *dev);
1132extern int drm_sysctl_cleanup(struct drm_device *dev);
1133
1134/* ATI PCIGART support (ati_pcigart.c) */
1135int drm_ati_pcigart_init(struct drm_device *dev,
1136 struct drm_ati_pcigart_info *gart_info);
1137int drm_ati_pcigart_cleanup(struct drm_device *dev,
1138 struct drm_ati_pcigart_info *gart_info);
1139
1140/* Cache management (drm_memory.c) */
1141void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1142
1143/* Locking IOCTL support (drm_drv.c) */
1144int drm_lock(struct drm_device *dev, void *data,
1145 struct drm_file *file_priv);
1146int drm_unlock(struct drm_device *dev, void *data,
1147 struct drm_file *file_priv);
1148int drm_version(struct drm_device *dev, void *data,
1149 struct drm_file *file_priv);
1150int drm_setversion(struct drm_device *dev, void *data,
1151 struct drm_file *file_priv);
1152
1153/* Misc. IOCTL support (drm_ioctl.c) */
1154int drm_irq_by_busid(struct drm_device *dev, void *data,
1155 struct drm_file *file_priv);
1156int drm_getunique(struct drm_device *dev, void *data,
1157 struct drm_file *file_priv);
1158int drm_setunique(struct drm_device *dev, void *data,
1159 struct drm_file *file_priv);
1160int drm_getmap(struct drm_device *dev, void *data,
1161 struct drm_file *file_priv);
1162int drm_getclient(struct drm_device *dev, void *data,
1163 struct drm_file *file_priv);
1164int drm_getstats(struct drm_device *dev, void *data,
1165 struct drm_file *file_priv);
1166int drm_getcap(struct drm_device *dev, void *data,
1167 struct drm_file *file_priv);
1168int drm_noop(struct drm_device *dev, void *data,
1169 struct drm_file *file_priv);
1170
1171/* Context IOCTL support (drm_context.c) */
1172int drm_resctx(struct drm_device *dev, void *data,
1173 struct drm_file *file_priv);
1174int drm_addctx(struct drm_device *dev, void *data,
1175 struct drm_file *file_priv);
1176int drm_modctx(struct drm_device *dev, void *data,
1177 struct drm_file *file_priv);
1178int drm_getctx(struct drm_device *dev, void *data,
1179 struct drm_file *file_priv);
1180int drm_switchctx(struct drm_device *dev, void *data,
1181 struct drm_file *file_priv);
1182int drm_newctx(struct drm_device *dev, void *data,
1183 struct drm_file *file_priv);
1184int drm_rmctx(struct drm_device *dev, void *data,
1185 struct drm_file *file_priv);
1186int drm_setsareactx(struct drm_device *dev, void *data,
1187 struct drm_file *file_priv);
1188int drm_getsareactx(struct drm_device *dev, void *data,
1189 struct drm_file *file_priv);
1190
1191/* Drawable IOCTL support (drm_drawable.c) */
1192int drm_adddraw(struct drm_device *dev, void *data,
1193 struct drm_file *file_priv);
1194int drm_rmdraw(struct drm_device *dev, void *data,
1195 struct drm_file *file_priv);
1196int drm_update_draw(struct drm_device *dev, void *data,
1197 struct drm_file *file_priv);
1198struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1199 int handle);
1200
1201/* Drawable support (drm_drawable.c) */
1202void drm_drawable_free_all(struct drm_device *dev);
1203
1204/* Authentication IOCTL support (drm_auth.c) */
1205int drm_getmagic(struct drm_device *dev, void *data,
1206 struct drm_file *file_priv);
1207int drm_authmagic(struct drm_device *dev, void *data,
1208 struct drm_file *file_priv);
1209
1210/* Buffer management support (drm_bufs.c) */
1211int drm_addmap_ioctl(struct drm_device *dev, void *data,
1212 struct drm_file *file_priv);
1213int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1214 struct drm_file *file_priv);
1215int drm_addbufs(struct drm_device *dev, void *data,
1216 struct drm_file *file_priv);
1217int drm_infobufs(struct drm_device *dev, void *data,
1218 struct drm_file *file_priv);
1219int drm_markbufs(struct drm_device *dev, void *data,
1220 struct drm_file *file_priv);
1221int drm_freebufs(struct drm_device *dev, void *data,
1222 struct drm_file *file_priv);
1223int drm_mapbufs(struct drm_device *dev, void *data,
1224 struct drm_file *file_priv);
1225
1226/* DMA support (drm_dma.c) */
1227int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1228
1229/* IRQ support (drm_irq.c) */
1230int drm_control(struct drm_device *dev, void *data,
1231 struct drm_file *file_priv);
1232
1233/* AGP/GART support (drm_agpsupport.c) */
1234int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1235 struct drm_file *file_priv);
1236int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1237 struct drm_file *file_priv);
1238int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1239 struct drm_file *file_priv);
1240int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1241 struct drm_file *file_priv);
1242int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1243 struct drm_file *file_priv);
1244int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1245 struct drm_file *file_priv);
1246int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1247 struct drm_file *file_priv);
1248int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1249 struct drm_file *file_priv);
1250
1251 /* Stub support (drm_stub.h) */
1252extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1253 struct drm_file *file_priv);
1254extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1255 struct drm_file *file_priv);
1256
1257/* Scatter Gather Support (drm_scatter.c) */
1258int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1259 struct drm_file *file_priv);
1260int drm_sg_free(struct drm_device *dev, void *data,
1261 struct drm_file *file_priv);
1262
1263/* consistent PCI memory functions (drm_pci.c) */
1264drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1265 size_t align, dma_addr_t maxaddr);
1266void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1267
1268/* Graphics Execution Manager library functions (drm_gem.c) */
1269int drm_gem_init(struct drm_device *dev);
1270void drm_gem_destroy(struct drm_device *dev);
1271
1272int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1273 struct drm_file *file_priv);
1274int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1275 struct drm_file *file_priv);
1276int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1277 struct drm_file *file_priv);
1278int drm_gem_handle_create(struct drm_file *file_priv,
1279 struct drm_gem_object *obj,
1280 u32 *handlep);
1281int drm_gem_handle_delete(struct drm_file *file_priv, uint32_t handle);
1282void drm_gem_object_handle_reference(struct drm_gem_object *obj);
1283void drm_gem_object_handle_unreference(struct drm_gem_object *obj);
1284void drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj);
1285void drm_gem_object_handle_free(struct drm_gem_object *obj);
1286void drm_gem_object_reference(struct drm_gem_object *obj);
1287void drm_gem_object_unreference(struct drm_gem_object *obj);
1288void drm_gem_object_unreference_unlocked(struct drm_gem_object *obj);
1289void drm_gem_object_release(struct drm_gem_object *obj);
1290void drm_gem_object_free(struct drm_gem_object *obj);
1291int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj,
1292 size_t size);
1293int drm_gem_private_object_init(struct drm_device *dev,
1294 struct drm_gem_object *obj, size_t size);
1295struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1296 size_t size);
1297struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1298 struct drm_file *file_priv, uint32_t handle);
1299
1300void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1301void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1302
1303int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1304void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
910 struct unrhdr *drw_unrhdr;
911 /* RB tree of drawable infos */
912 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
913
914 int vblank_disable_allowed;
915
916 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
917 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
918 struct mtx vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
919 struct mtx vbl_lock;
920 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
921 u32 *last_vblank; /* protected by dev->vbl_lock, used */
922 /* for wraparound handling */
923 int *vblank_enabled; /* so we don't call enable more than
924 once per disable */
925 int *vblank_inmodeset; /* Display driver is setting mode */
926 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
927 struct callout vblank_disable_callout;
928
929 u32 max_vblank_count; /**< size of vblank counter register */
930
931 struct list_head vblank_event_list;
932 struct mtx event_lock;
933
934 struct drm_mode_config mode_config; /**< Current mode config */
935
936 /* GEM part */
937 struct sx object_name_lock;
938 struct drm_gem_names object_names;
939 void *mm_private;
940
941 void *sysctl_private;
942 char busid_str[128];
943 int modesetting;
944};
945
946static __inline__ int drm_core_check_feature(struct drm_device *dev,
947 int feature)
948{
949 return ((dev->driver->driver_features & feature) ? 1 : 0);
950}
951
952#if __OS_HAS_AGP
953static inline int drm_core_has_AGP(struct drm_device *dev)
954{
955 return drm_core_check_feature(dev, DRIVER_USE_AGP);
956}
957#else
958#define drm_core_has_AGP(dev) (0)
959#endif
960
961enum dmi_field {
962 DMI_NONE,
963 DMI_BIOS_VENDOR,
964 DMI_BIOS_VERSION,
965 DMI_BIOS_DATE,
966 DMI_SYS_VENDOR,
967 DMI_PRODUCT_NAME,
968 DMI_PRODUCT_VERSION,
969 DMI_PRODUCT_SERIAL,
970 DMI_PRODUCT_UUID,
971 DMI_BOARD_VENDOR,
972 DMI_BOARD_NAME,
973 DMI_BOARD_VERSION,
974 DMI_BOARD_SERIAL,
975 DMI_BOARD_ASSET_TAG,
976 DMI_CHASSIS_VENDOR,
977 DMI_CHASSIS_TYPE,
978 DMI_CHASSIS_VERSION,
979 DMI_CHASSIS_SERIAL,
980 DMI_CHASSIS_ASSET_TAG,
981 DMI_STRING_MAX,
982};
983
984struct dmi_strmatch {
985 unsigned char slot;
986 char substr[79];
987};
988
989struct dmi_system_id {
990 int (*callback)(const struct dmi_system_id *);
991 const char *ident;
992 struct dmi_strmatch matches[4];
993};
994#define DMI_MATCH(a, b) {(a), (b)}
995bool dmi_check_system(const struct dmi_system_id *);
996
997extern int drm_debug_flag;
998extern int drm_notyet_flag;
999extern unsigned int drm_vblank_offdelay;
1000extern unsigned int drm_timestamp_precision;
1001
1002/* Device setup support (drm_drv.c) */
1003int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1004int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1005int drm_create_cdevs(device_t kdev);
1006void drm_close(void *data);
1007int drm_detach(device_t kdev);
1008d_ioctl_t drm_ioctl;
1009d_open_t drm_open;
1010d_read_t drm_read;
1011d_poll_t drm_poll;
1012d_mmap_t drm_mmap;
1013extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1014
1015void drm_event_wakeup(struct drm_pending_event *e);
1016
1017int drm_add_busid_modesetting(struct drm_device *dev,
1018 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1019
1020/* File operations helpers (drm_fops.c) */
1021extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
1022 DRM_STRUCTPROC *p,
1023 struct drm_device *dev);
1024
1025/* Memory management support (drm_memory.c) */
1026void drm_mem_init(void);
1027void drm_mem_uninit(void);
1028void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1029void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1030void drm_ioremapfree(drm_local_map_t *map);
1031int drm_mtrr_add(unsigned long offset, size_t size, int flags);
1032int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1033
1034int drm_context_switch(struct drm_device *dev, int old, int new);
1035int drm_context_switch_complete(struct drm_device *dev, int new);
1036
1037int drm_ctxbitmap_init(struct drm_device *dev);
1038void drm_ctxbitmap_cleanup(struct drm_device *dev);
1039void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1040int drm_ctxbitmap_next(struct drm_device *dev);
1041
1042/* Locking IOCTL support (drm_lock.c) */
1043int drm_lock_take(struct drm_lock_data *lock_data,
1044 unsigned int context);
1045int drm_lock_transfer(struct drm_lock_data *lock_data,
1046 unsigned int context);
1047int drm_lock_free(struct drm_lock_data *lock_data,
1048 unsigned int context);
1049
1050/* Buffer management support (drm_bufs.c) */
1051unsigned long drm_get_resource_start(struct drm_device *dev,
1052 unsigned int resource);
1053unsigned long drm_get_resource_len(struct drm_device *dev,
1054 unsigned int resource);
1055void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1056int drm_order(unsigned long size);
1057int drm_addmap(struct drm_device *dev, unsigned long offset,
1058 unsigned long size,
1059 enum drm_map_type type, enum drm_map_flags flags,
1060 drm_local_map_t **map_ptr);
1061int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1062int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
1063int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1064
1065/* DMA support (drm_dma.c) */
1066int drm_dma_setup(struct drm_device *dev);
1067void drm_dma_takedown(struct drm_device *dev);
1068void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1069void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1070#define drm_core_reclaim_buffers drm_reclaim_buffers
1071
1072/* IRQ support (drm_irq.c) */
1073int drm_irq_install(struct drm_device *dev);
1074int drm_irq_uninstall(struct drm_device *dev);
1075irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1076void drm_driver_irq_preinstall(struct drm_device *dev);
1077void drm_driver_irq_postinstall(struct drm_device *dev);
1078void drm_driver_irq_uninstall(struct drm_device *dev);
1079
1080void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1081void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1082int drm_modeset_ctl(struct drm_device *dev, void *data,
1083 struct drm_file *file_priv);
1084
1085extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1086extern int drm_wait_vblank(struct drm_device *dev, void *data,
1087 struct drm_file *filp);
1088extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1089extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1090extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1091 struct timeval *vblanktime);
1092extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1093void drm_handle_vblank_events(struct drm_device *dev, int crtc);
1094extern int drm_vblank_get(struct drm_device *dev, int crtc);
1095extern void drm_vblank_put(struct drm_device *dev, int crtc);
1096extern void drm_vblank_off(struct drm_device *dev, int crtc);
1097extern void drm_vblank_cleanup(struct drm_device *dev);
1098extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1099 struct timeval *tvblank, unsigned flags);
1100extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1101 int crtc, int *max_error,
1102 struct timeval *vblank_time,
1103 unsigned flags,
1104 struct drm_crtc *refcrtc);
1105extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1106
1107struct timeval ns_to_timeval(const int64_t nsec);
1108int64_t timeval_to_ns(const struct timeval *tv);
1109
1110/* AGP/PCI Express/GART support (drm_agpsupport.c) */
1111int drm_device_is_agp(struct drm_device *dev);
1112int drm_device_is_pcie(struct drm_device *dev);
1113drm_agp_head_t *drm_agp_init(void);
1114int drm_agp_acquire(struct drm_device *dev);
1115int drm_agp_release(struct drm_device *dev);
1116int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1117int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1118void *drm_agp_allocate_memory(size_t pages, u32 type);
1119int drm_agp_free_memory(void *handle);
1120int drm_agp_bind_memory(void *handle, off_t start);
1121int drm_agp_unbind_memory(void *handle);
1122int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1123int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1124int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1125int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1126
1127/* Scatter Gather Support (drm_scatter.c) */
1128void drm_sg_cleanup(drm_sg_mem_t *entry);
1129int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1130
1131/* sysctl support (drm_sysctl.h) */
1132extern int drm_sysctl_init(struct drm_device *dev);
1133extern int drm_sysctl_cleanup(struct drm_device *dev);
1134
1135/* ATI PCIGART support (ati_pcigart.c) */
1136int drm_ati_pcigart_init(struct drm_device *dev,
1137 struct drm_ati_pcigart_info *gart_info);
1138int drm_ati_pcigart_cleanup(struct drm_device *dev,
1139 struct drm_ati_pcigart_info *gart_info);
1140
1141/* Cache management (drm_memory.c) */
1142void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1143
1144/* Locking IOCTL support (drm_drv.c) */
1145int drm_lock(struct drm_device *dev, void *data,
1146 struct drm_file *file_priv);
1147int drm_unlock(struct drm_device *dev, void *data,
1148 struct drm_file *file_priv);
1149int drm_version(struct drm_device *dev, void *data,
1150 struct drm_file *file_priv);
1151int drm_setversion(struct drm_device *dev, void *data,
1152 struct drm_file *file_priv);
1153
1154/* Misc. IOCTL support (drm_ioctl.c) */
1155int drm_irq_by_busid(struct drm_device *dev, void *data,
1156 struct drm_file *file_priv);
1157int drm_getunique(struct drm_device *dev, void *data,
1158 struct drm_file *file_priv);
1159int drm_setunique(struct drm_device *dev, void *data,
1160 struct drm_file *file_priv);
1161int drm_getmap(struct drm_device *dev, void *data,
1162 struct drm_file *file_priv);
1163int drm_getclient(struct drm_device *dev, void *data,
1164 struct drm_file *file_priv);
1165int drm_getstats(struct drm_device *dev, void *data,
1166 struct drm_file *file_priv);
1167int drm_getcap(struct drm_device *dev, void *data,
1168 struct drm_file *file_priv);
1169int drm_noop(struct drm_device *dev, void *data,
1170 struct drm_file *file_priv);
1171
1172/* Context IOCTL support (drm_context.c) */
1173int drm_resctx(struct drm_device *dev, void *data,
1174 struct drm_file *file_priv);
1175int drm_addctx(struct drm_device *dev, void *data,
1176 struct drm_file *file_priv);
1177int drm_modctx(struct drm_device *dev, void *data,
1178 struct drm_file *file_priv);
1179int drm_getctx(struct drm_device *dev, void *data,
1180 struct drm_file *file_priv);
1181int drm_switchctx(struct drm_device *dev, void *data,
1182 struct drm_file *file_priv);
1183int drm_newctx(struct drm_device *dev, void *data,
1184 struct drm_file *file_priv);
1185int drm_rmctx(struct drm_device *dev, void *data,
1186 struct drm_file *file_priv);
1187int drm_setsareactx(struct drm_device *dev, void *data,
1188 struct drm_file *file_priv);
1189int drm_getsareactx(struct drm_device *dev, void *data,
1190 struct drm_file *file_priv);
1191
1192/* Drawable IOCTL support (drm_drawable.c) */
1193int drm_adddraw(struct drm_device *dev, void *data,
1194 struct drm_file *file_priv);
1195int drm_rmdraw(struct drm_device *dev, void *data,
1196 struct drm_file *file_priv);
1197int drm_update_draw(struct drm_device *dev, void *data,
1198 struct drm_file *file_priv);
1199struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1200 int handle);
1201
1202/* Drawable support (drm_drawable.c) */
1203void drm_drawable_free_all(struct drm_device *dev);
1204
1205/* Authentication IOCTL support (drm_auth.c) */
1206int drm_getmagic(struct drm_device *dev, void *data,
1207 struct drm_file *file_priv);
1208int drm_authmagic(struct drm_device *dev, void *data,
1209 struct drm_file *file_priv);
1210
1211/* Buffer management support (drm_bufs.c) */
1212int drm_addmap_ioctl(struct drm_device *dev, void *data,
1213 struct drm_file *file_priv);
1214int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1215 struct drm_file *file_priv);
1216int drm_addbufs(struct drm_device *dev, void *data,
1217 struct drm_file *file_priv);
1218int drm_infobufs(struct drm_device *dev, void *data,
1219 struct drm_file *file_priv);
1220int drm_markbufs(struct drm_device *dev, void *data,
1221 struct drm_file *file_priv);
1222int drm_freebufs(struct drm_device *dev, void *data,
1223 struct drm_file *file_priv);
1224int drm_mapbufs(struct drm_device *dev, void *data,
1225 struct drm_file *file_priv);
1226
1227/* DMA support (drm_dma.c) */
1228int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1229
1230/* IRQ support (drm_irq.c) */
1231int drm_control(struct drm_device *dev, void *data,
1232 struct drm_file *file_priv);
1233
1234/* AGP/GART support (drm_agpsupport.c) */
1235int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1236 struct drm_file *file_priv);
1237int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1238 struct drm_file *file_priv);
1239int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1240 struct drm_file *file_priv);
1241int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1242 struct drm_file *file_priv);
1243int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1244 struct drm_file *file_priv);
1245int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1246 struct drm_file *file_priv);
1247int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1248 struct drm_file *file_priv);
1249int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1250 struct drm_file *file_priv);
1251
1252 /* Stub support (drm_stub.h) */
1253extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1254 struct drm_file *file_priv);
1255extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1256 struct drm_file *file_priv);
1257
1258/* Scatter Gather Support (drm_scatter.c) */
1259int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1260 struct drm_file *file_priv);
1261int drm_sg_free(struct drm_device *dev, void *data,
1262 struct drm_file *file_priv);
1263
1264/* consistent PCI memory functions (drm_pci.c) */
1265drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1266 size_t align, dma_addr_t maxaddr);
1267void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1268
1269/* Graphics Execution Manager library functions (drm_gem.c) */
1270int drm_gem_init(struct drm_device *dev);
1271void drm_gem_destroy(struct drm_device *dev);
1272
1273int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1274 struct drm_file *file_priv);
1275int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1276 struct drm_file *file_priv);
1277int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1278 struct drm_file *file_priv);
1279int drm_gem_handle_create(struct drm_file *file_priv,
1280 struct drm_gem_object *obj,
1281 u32 *handlep);
1282int drm_gem_handle_delete(struct drm_file *file_priv, uint32_t handle);
1283void drm_gem_object_handle_reference(struct drm_gem_object *obj);
1284void drm_gem_object_handle_unreference(struct drm_gem_object *obj);
1285void drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj);
1286void drm_gem_object_handle_free(struct drm_gem_object *obj);
1287void drm_gem_object_reference(struct drm_gem_object *obj);
1288void drm_gem_object_unreference(struct drm_gem_object *obj);
1289void drm_gem_object_unreference_unlocked(struct drm_gem_object *obj);
1290void drm_gem_object_release(struct drm_gem_object *obj);
1291void drm_gem_object_free(struct drm_gem_object *obj);
1292int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj,
1293 size_t size);
1294int drm_gem_private_object_init(struct drm_device *dev,
1295 struct drm_gem_object *obj, size_t size);
1296struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1297 size_t size);
1298struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1299 struct drm_file *file_priv, uint32_t handle);
1300
1301void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1302void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1303
1304int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1305void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1305int drm_gem_mmap_single(struct cdev *kdev, vm_ooffset_t *offset, vm_size_t size,
1306 struct vm_object **obj_res, int nprot);
1306int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1307 vm_size_t size, struct vm_object **obj_res, int nprot);
1307void drm_gem_pager_dtr(void *obj);
1308
1308void drm_gem_pager_dtr(void *obj);
1309
1310struct ttm_bo_device;
1311int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1312 vm_size_t size, struct vm_object **obj_res, int nprot);
1313
1309void drm_device_lock_mtx(struct drm_device *dev);
1310void drm_device_unlock_mtx(struct drm_device *dev);
1311int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1312 const char *msg, int timeout);
1313void drm_device_assert_mtx_locked(struct drm_device *dev);
1314void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1315
1316void drm_device_lock_struct(struct drm_device *dev);
1317void drm_device_unlock_struct(struct drm_device *dev);
1318int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1319 const char *msg, int timeout);
1320void drm_device_assert_struct_locked(struct drm_device *dev);
1321void drm_device_assert_struct_unlocked(struct drm_device *dev);
1322
1323void drm_compat_locking_init(struct drm_device *dev);
1324void drm_sleep_locking_init(struct drm_device *dev);
1325
1326/* drm_modes.c */
1327bool drm_mode_parse_command_line_for_connector(const char *mode_option,
1328 struct drm_connector *connector, struct drm_cmdline_mode *mode);
1329struct drm_display_mode *drm_mode_create_from_cmdline_mode(
1330 struct drm_device *dev, struct drm_cmdline_mode *cmd);
1331
1332/* drm_edid.c */
1333u8 *drm_find_cea_extension(struct edid *edid);
1334
1335/* Inline replacements for drm_alloc and friends */
1336static __inline__ void *
1337drm_alloc(size_t size, struct malloc_type *area)
1338{
1339 return malloc(size, area, M_NOWAIT);
1340}
1341
1342static __inline__ void *
1343drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1344{
1345 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
1346}
1347
1348static __inline__ void *
1349drm_realloc(void *oldpt, size_t oldsize, size_t size,
1350 struct malloc_type *area)
1351{
1352 return reallocf(oldpt, size, area, M_NOWAIT);
1353}
1354
1355static __inline__ void
1356drm_free(void *pt, size_t size, struct malloc_type *area)
1357{
1358 free(pt, area);
1359}
1360
1361/* Inline replacements for DRM_IOREMAP macros */
1362static __inline__ void
1363drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1364{
1365 map->virtual = drm_ioremap_wc(dev, map);
1366}
1367static __inline__ void
1368drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1369{
1370 map->virtual = drm_ioremap(dev, map);
1371}
1372static __inline__ void
1373drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1374{
1375 if ( map->virtual && map->size )
1376 drm_ioremapfree(map);
1377}
1378
1379static __inline__ struct drm_local_map *
1380drm_core_findmap(struct drm_device *dev, unsigned long offset)
1381{
1382 drm_local_map_t *map;
1383
1384 DRM_LOCK_ASSERT(dev);
1385 TAILQ_FOREACH(map, &dev->maplist, link) {
1386 if (offset == (unsigned long)map->handle)
1387 return map;
1388 }
1389 return NULL;
1390}
1391
1392static __inline__ void drm_core_dropmap(struct drm_map *map)
1393{
1394}
1395
1396#define KIB_NOTYET() \
1397do { \
1398 if (drm_debug_flag && drm_notyet_flag) \
1399 printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
1400} while (0)
1401
1402#define KTR_DRM KTR_DEV
1403#define KTR_DRM_REG KTR_SPARE3
1404
1405#endif /* __KERNEL__ */
1406#endif /* _DRM_P_H_ */
1314void drm_device_lock_mtx(struct drm_device *dev);
1315void drm_device_unlock_mtx(struct drm_device *dev);
1316int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1317 const char *msg, int timeout);
1318void drm_device_assert_mtx_locked(struct drm_device *dev);
1319void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1320
1321void drm_device_lock_struct(struct drm_device *dev);
1322void drm_device_unlock_struct(struct drm_device *dev);
1323int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1324 const char *msg, int timeout);
1325void drm_device_assert_struct_locked(struct drm_device *dev);
1326void drm_device_assert_struct_unlocked(struct drm_device *dev);
1327
1328void drm_compat_locking_init(struct drm_device *dev);
1329void drm_sleep_locking_init(struct drm_device *dev);
1330
1331/* drm_modes.c */
1332bool drm_mode_parse_command_line_for_connector(const char *mode_option,
1333 struct drm_connector *connector, struct drm_cmdline_mode *mode);
1334struct drm_display_mode *drm_mode_create_from_cmdline_mode(
1335 struct drm_device *dev, struct drm_cmdline_mode *cmd);
1336
1337/* drm_edid.c */
1338u8 *drm_find_cea_extension(struct edid *edid);
1339
1340/* Inline replacements for drm_alloc and friends */
1341static __inline__ void *
1342drm_alloc(size_t size, struct malloc_type *area)
1343{
1344 return malloc(size, area, M_NOWAIT);
1345}
1346
1347static __inline__ void *
1348drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1349{
1350 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
1351}
1352
1353static __inline__ void *
1354drm_realloc(void *oldpt, size_t oldsize, size_t size,
1355 struct malloc_type *area)
1356{
1357 return reallocf(oldpt, size, area, M_NOWAIT);
1358}
1359
1360static __inline__ void
1361drm_free(void *pt, size_t size, struct malloc_type *area)
1362{
1363 free(pt, area);
1364}
1365
1366/* Inline replacements for DRM_IOREMAP macros */
1367static __inline__ void
1368drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1369{
1370 map->virtual = drm_ioremap_wc(dev, map);
1371}
1372static __inline__ void
1373drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1374{
1375 map->virtual = drm_ioremap(dev, map);
1376}
1377static __inline__ void
1378drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1379{
1380 if ( map->virtual && map->size )
1381 drm_ioremapfree(map);
1382}
1383
1384static __inline__ struct drm_local_map *
1385drm_core_findmap(struct drm_device *dev, unsigned long offset)
1386{
1387 drm_local_map_t *map;
1388
1389 DRM_LOCK_ASSERT(dev);
1390 TAILQ_FOREACH(map, &dev->maplist, link) {
1391 if (offset == (unsigned long)map->handle)
1392 return map;
1393 }
1394 return NULL;
1395}
1396
1397static __inline__ void drm_core_dropmap(struct drm_map *map)
1398{
1399}
1400
1401#define KIB_NOTYET() \
1402do { \
1403 if (drm_debug_flag && drm_notyet_flag) \
1404 printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
1405} while (0)
1406
1407#define KTR_DRM KTR_DEV
1408#define KTR_DRM_REG KTR_SPARE3
1409
1410#endif /* __KERNEL__ */
1411#endif /* _DRM_P_H_ */