DRM from FreeBSD current, tested for r600
[dragonfly.git] / sys / dev / drm / drmP.h
blobb7752ce9880fc1930bb1d13459dc87a8187c04d8
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.
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:
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.
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.
28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
34 #ifndef _DRM_P_H_
35 #define _DRM_P_H_
37 #if defined(_KERNEL) || defined(__KERNEL__)
39 struct drm_device;
40 struct drm_file;
42 #include <sys/param.h>
43 #include <sys/queue.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/systm.h>
48 #include <sys/conf.h>
49 #include <sys/stat.h>
50 #include <sys/priv.h>
51 #include <sys/proc.h>
52 #include <sys/lock.h>
53 #include <sys/fcntl.h>
54 #include <sys/uio.h>
55 #include <sys/filio.h>
56 #include <sys/sysctl.h>
57 #include <sys/bus.h>
58 #include <sys/signalvar.h>
59 #include <sys/event.h>
60 #include <sys/tree.h>
61 #include <sys/taskqueue.h>
62 #include <vm/vm.h>
63 #include <vm/pmap.h>
64 #include <vm/vm_extern.h>
65 #include <vm/vm_map.h>
66 #include <vm/vm_object.h>
67 #include <vm/vm_page.h>
68 #include <vm/vm_param.h>
69 #include <machine/param.h>
70 #include <machine/pmap.h>
71 #include <sys/bus.h>
72 #include <sys/resource.h>
73 #include <machine/specialreg.h>
74 #include <machine/sysarch.h>
75 #include <sys/endian.h>
76 #include <sys/mman.h>
77 #include <sys/rman.h>
78 #include <sys/memrange.h>
79 #include <dev/agp/agpvar.h>
80 #include <sys/device.h>
81 #include <sys/agpio.h>
82 #include <sys/spinlock.h>
83 #include <sys/spinlock2.h>
84 #include <bus/pci/pcivar.h>
85 #include <bus/pci/pcireg.h>
86 #include <sys/bus.h>
88 #include "dev/drm/drm.h"
89 #include "dev/drm/drm_linux_list.h"
90 #include "dev/drm/drm_atomic.h"
91 #include "dev/drm/drm_internal.h"
93 #include <opt_drm.h>
94 #ifdef DRM_DEBUG
95 #undef DRM_DEBUG
96 #define DRM_DEBUG_DEFAULT_ON 1
97 #endif /* DRM_DEBUG */
99 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__x86_64__) && !defined(__DragonFly__) /* XXX */
100 #include <sys/file.h>
101 #include <sys/proc.h>
102 #include <machine/../linux/linux.h>
103 #include <machine/../linux/linux_proto.h>
104 #else
105 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
106 * supported on this OS yet.
108 #undef DRM_LINUX
109 #define DRM_LINUX 0
110 #endif
112 /* driver capabilities and requirements mask */
113 #define DRIVER_USE_AGP 0x1
114 #define DRIVER_REQUIRE_AGP 0x2
115 #define DRIVER_USE_MTRR 0x4
116 #define DRIVER_PCI_DMA 0x8
117 #define DRIVER_SG 0x10
118 #define DRIVER_HAVE_DMA 0x20
119 #define DRIVER_HAVE_IRQ 0x40
120 #define DRIVER_DMA_QUEUE 0x100
123 #define DRM_HASH_SIZE 16 /* Size of key hash table */
124 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
125 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
127 MALLOC_DECLARE(DRM_MEM_DMA);
128 MALLOC_DECLARE(DRM_MEM_SAREA);
129 MALLOC_DECLARE(DRM_MEM_DRIVER);
130 MALLOC_DECLARE(DRM_MEM_MAGIC);
131 MALLOC_DECLARE(DRM_MEM_IOCTLS);
132 MALLOC_DECLARE(DRM_MEM_MAPS);
133 MALLOC_DECLARE(DRM_MEM_BUFS);
134 MALLOC_DECLARE(DRM_MEM_SEGS);
135 MALLOC_DECLARE(DRM_MEM_PAGES);
136 MALLOC_DECLARE(DRM_MEM_FILES);
137 MALLOC_DECLARE(DRM_MEM_QUEUES);
138 MALLOC_DECLARE(DRM_MEM_CMDS);
139 MALLOC_DECLARE(DRM_MEM_MAPPINGS);
140 MALLOC_DECLARE(DRM_MEM_BUFLISTS);
141 MALLOC_DECLARE(DRM_MEM_AGPLISTS);
142 MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
143 MALLOC_DECLARE(DRM_MEM_SGLISTS);
144 MALLOC_DECLARE(DRM_MEM_DRAWABLE);
145 MALLOC_DECLARE(DRM_MEM_MM);
146 MALLOC_DECLARE(DRM_MEM_HASHTAB);
148 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
150 /* Internal types and structures */
151 #define DRM_ARRAY_SIZE(x) NELEM(x)
152 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
153 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
155 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
157 #define __OS_HAS_AGP 1
159 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
160 #define DRM_DEV_UID 0
161 #define DRM_DEV_GID 0
163 #define wait_queue_head_t atomic_t
164 #define DRM_WAKEUP(w) wakeup((void *)w)
165 #define DRM_WAKEUP_INT(w) wakeup(w)
166 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
168 #define DRM_CURPROC curthread
169 #define DRM_STRUCTPROC struct thread
170 #define DRM_SPINTYPE struct lock
171 #define DRM_SPININIT(l,name) lockinit(l, name, 0, LK_CANRECURSE)
172 #define DRM_SPINUNINIT(l)
173 #define DRM_SPINLOCK(l) lockmgr(l, LK_EXCLUSIVE|LK_RETRY|LK_CANRECURSE)
174 #define DRM_SPINUNLOCK(u) lockmgr(u, LK_RELEASE)
175 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
176 DRM_SPINLOCK(l); \
177 (void)irqflags; \
178 } while (0)
179 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) DRM_SPINUNLOCK(u)
180 #define DRM_SPINLOCK_ASSERT(l)
181 #define DRM_CURRENTPID curthread->td_proc->p_pid
182 #define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock)
183 #define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock)
184 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
186 #define DRM_IRQ_ARGS void *arg
187 typedef void irqreturn_t;
188 #define IRQ_HANDLED /* nothing */
189 #define IRQ_NONE /* nothing */
191 #define unlikely(x) __builtin_expect(!!(x), 0)
192 #define container_of(ptr, type, member) ({ \
193 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
194 (type *)( (char *)__mptr - offsetof(type,member) );})
196 enum {
197 DRM_IS_NOT_AGP,
198 DRM_IS_AGP,
199 DRM_MIGHT_BE_AGP
201 #define DRM_AGP_MEM struct agp_memory_info
203 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
205 #define PAGE_ALIGN(addr) round_page(addr)
206 /* DRM_SUSER returns true if the user is superuser */
207 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
208 #define DRM_AGP_FIND_DEVICE() agp_find_device()
209 #define DRM_MTRR_WC MDF_WRITECOMBINE
210 #define jiffies ticks
212 typedef unsigned long dma_addr_t;
213 typedef u_int64_t u64;
214 typedef u_int32_t u32;
215 typedef u_int16_t u16;
216 typedef u_int8_t u8;
218 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
219 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
220 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
222 #if defined(__i386__)
223 #define DRM_READMEMORYBARRIER() __asm __volatile( \
224 "lock; addl $0,0(%%esp)" : : : "memory");
225 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
226 #define DRM_MEMORYBARRIER() __asm __volatile( \
227 "lock; addl $0,0(%%esp)" : : : "memory");
228 #elif defined(__alpha__)
229 #define DRM_READMEMORYBARRIER() alpha_mb();
230 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
231 #define DRM_MEMORYBARRIER() alpha_mb();
232 #elif defined(__x86_64__)
233 #define DRM_READMEMORYBARRIER() __asm __volatile( \
234 "lock; addl $0,0(%%rsp)" : : : "memory");
235 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
236 #define DRM_MEMORYBARRIER() __asm __volatile( \
237 "lock; addl $0,0(%%rsp)" : : : "memory");
238 #endif
240 #define DRM_READ8(map, offset) \
241 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
242 (vm_offset_t)(offset))
243 #define DRM_READ16(map, offset) \
244 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
245 (vm_offset_t)(offset))
246 #define DRM_READ32(map, offset) \
247 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
248 (vm_offset_t)(offset))
249 #define DRM_WRITE8(map, offset, val) \
250 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
251 (vm_offset_t)(offset)) = val
252 #define DRM_WRITE16(map, offset, val) \
253 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
254 (vm_offset_t)(offset)) = val
255 #define DRM_WRITE32(map, offset, val) \
256 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
257 (vm_offset_t)(offset)) = val
259 #define DRM_VERIFYAREA_READ( uaddr, size ) \
260 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
262 #define DRM_COPY_TO_USER(user, kern, size) \
263 copyout(kern, user, size)
264 #define DRM_COPY_FROM_USER(kern, user, size) \
265 copyin(user, kern, size)
266 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
267 copyin(arg2, arg1, arg3)
268 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
269 copyout(arg2, arg1, arg3)
270 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
271 ((val) = fuword32(uaddr), 0)
273 #define cpu_to_le32(x) htole32(x)
274 #define le32_to_cpu(x) le32toh(x)
276 #define DRM_HZ hz
277 #define DRM_UDELAY(udelay) DELAY(udelay)
278 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
280 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
281 (_map) = (_dev)->context_sareas[_ctx]; \
282 } while(0)
284 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
285 do { \
286 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
287 dev->lock.file_priv != file_priv) { \
288 DRM_ERROR("%s called without lock held\n", \
289 __FUNCTION__); \
290 return EINVAL; \
292 } while (0)
294 /* Returns -errno to shared code */
295 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
296 for ( ret = 0 ; !ret && !(condition) ; ) { \
297 DRM_UNLOCK(); \
298 lwkt_serialize_enter(&dev->irq_lock); \
299 if (!(condition)) { \
300 tsleep_interlock(&(queue), PCATCH); \
301 lwkt_serialize_exit(&dev->irq_lock); \
302 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
303 "drmwtq", (timeout)); \
304 } else { \
305 lwkt_serialize_exit(&dev->irq_lock); \
307 DRM_LOCK(); \
310 #define printf kprintf
311 #define snprintf ksnprintf
312 #define sscanf ksscanf
313 #define malloc kmalloc
314 #define realloc krealloc
315 #define reallocf krealloc /* XXX XXX XXX */
317 __inline static void
318 free(void *addr, struct malloc_type *type)
320 if (addr != NULL)
321 kfree(addr, type);
324 #define DRM_ERROR(fmt, ...) \
325 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
326 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
328 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
330 #define DRM_DEBUG(fmt, ...) do { \
331 if (drm_debug_flag) \
332 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
333 __func__ , ##__VA_ARGS__); \
334 } while (0)
336 typedef struct drm_pci_id_list
338 int vendor;
339 int device;
340 long driver_private;
341 char *name;
342 } drm_pci_id_list_t;
344 struct drm_msi_blacklist_entry
346 int vendor;
347 int device;
350 #define DRM_AUTH 0x1
351 #define DRM_MASTER 0x2
352 #define DRM_ROOT_ONLY 0x4
353 typedef struct drm_ioctl_desc {
354 unsigned long cmd;
355 int (*func)(struct drm_device *dev, void *data,
356 struct drm_file *file_priv);
357 int flags;
358 } drm_ioctl_desc_t;
360 * Creates a driver or general drm_ioctl_desc array entry for the given
361 * ioctl, for use by drm_ioctl().
363 #define DRM_IOCTL_DEF(ioctl, func, flags) \
364 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
366 typedef struct drm_magic_entry {
367 drm_magic_t magic;
368 struct drm_file *priv;
369 struct drm_magic_entry *next;
370 } drm_magic_entry_t;
372 typedef struct drm_magic_head {
373 struct drm_magic_entry *head;
374 struct drm_magic_entry *tail;
375 } drm_magic_head_t;
377 typedef struct drm_buf {
378 int idx; /* Index into master buflist */
379 int total; /* Buffer size */
380 int order; /* log-base-2(total) */
381 int used; /* Amount of buffer in use (for DMA) */
382 unsigned long offset; /* Byte offset (used internally) */
383 void *address; /* Address of buffer */
384 unsigned long bus_address; /* Bus address of buffer */
385 struct drm_buf *next; /* Kernel-only: used for free list */
386 __volatile__ int pending; /* On hardware DMA queue */
387 struct drm_file *file_priv; /* Unique identifier of holding process */
388 int context; /* Kernel queue for this buffer */
389 enum {
390 DRM_LIST_NONE = 0,
391 DRM_LIST_FREE = 1,
392 DRM_LIST_WAIT = 2,
393 DRM_LIST_PEND = 3,
394 DRM_LIST_PRIO = 4,
395 DRM_LIST_RECLAIM = 5
396 } list; /* Which list we're on */
398 int dev_priv_size; /* Size of buffer private stoarge */
399 void *dev_private; /* Per-buffer private storage */
400 } drm_buf_t;
402 typedef struct drm_freelist {
403 int initialized; /* Freelist in use */
404 atomic_t count; /* Number of free buffers */
405 drm_buf_t *next; /* End pointer */
407 int low_mark; /* Low water mark */
408 int high_mark; /* High water mark */
409 } drm_freelist_t;
411 typedef struct drm_dma_handle {
412 void *vaddr;
413 bus_addr_t busaddr;
414 bus_dma_tag_t tag;
415 bus_dmamap_t map;
416 } drm_dma_handle_t;
418 typedef struct drm_buf_entry {
419 int buf_size;
420 int buf_count;
421 drm_buf_t *buflist;
422 int seg_count;
423 drm_dma_handle_t **seglist;
424 int page_order;
426 drm_freelist_t freelist;
427 } drm_buf_entry_t;
429 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
430 struct drm_file {
431 TAILQ_ENTRY(drm_file) link;
432 struct drm_device *dev;
433 int authenticated;
434 int master;
435 int minor;
436 pid_t pid;
437 uid_t uid;
438 int refs;
439 drm_magic_t magic;
440 unsigned long ioctl_count;
441 void *driver_priv;
444 typedef struct drm_lock_data {
445 struct drm_hw_lock *hw_lock; /* Hardware lock */
446 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
447 int lock_queue; /* Queue of blocked processes */
448 unsigned long lock_time; /* Time of last lock in jiffies */
449 } drm_lock_data_t;
451 /* This structure, in the struct drm_device, is always initialized while the
452 * device
453 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
454 * when set marks that no further bufs may be allocated until device teardown
455 * occurs (when the last open of the device has closed). The high/low
456 * watermarks of bufs are only touched by the X Server, and thus not
457 * concurrently accessed, so no locking is needed.
459 typedef struct drm_device_dma {
460 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
461 int buf_count;
462 drm_buf_t **buflist; /* Vector of pointers info bufs */
463 int seg_count;
464 int page_count;
465 unsigned long *pagelist;
466 unsigned long byte_count;
467 enum {
468 _DRM_DMA_USE_AGP = 0x01,
469 _DRM_DMA_USE_SG = 0x02
470 } flags;
471 } drm_device_dma_t;
473 typedef struct drm_agp_mem {
474 void *handle;
475 unsigned long bound; /* address */
476 int pages;
477 struct drm_agp_mem *prev;
478 struct drm_agp_mem *next;
479 } drm_agp_mem_t;
481 typedef struct drm_agp_head {
482 device_t agpdev;
483 struct agp_info info;
484 const char *chipset;
485 drm_agp_mem_t *memory;
486 unsigned long mode;
487 int enabled;
488 int acquired;
489 unsigned long base;
490 int mtrr;
491 int cant_use_aperture;
492 unsigned long page_mask;
493 } drm_agp_head_t;
495 typedef struct drm_sg_mem {
496 unsigned long handle;
497 void *virtual;
498 int pages;
499 dma_addr_t *busaddr;
500 struct drm_dma_handle *dmah; /* Handle to PCI memory */
501 } drm_sg_mem_t;
503 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
505 typedef struct drm_local_map {
506 unsigned long offset; /* Physical address (0 for SAREA)*/
507 unsigned long size; /* Physical size (bytes) */
508 enum drm_map_type type; /* Type of memory mapped */
509 enum drm_map_flags flags; /* Flags */
510 void *handle; /* User-space: "Handle" to pass to mmap */
511 /* Kernel-space: kernel-virtual address */
512 int mtrr; /* Boolean: MTRR used */
513 /* Private data */
514 int rid; /* PCI resource ID for bus_space */
515 struct resource *bsr;
516 bus_space_tag_t bst;
517 bus_space_handle_t bsh;
518 drm_dma_handle_t *dmah;
519 TAILQ_ENTRY(drm_local_map) link;
520 } drm_local_map_t;
522 struct drm_vblank_info {
523 wait_queue_head_t queue; /* vblank wait queue */
524 atomic_t count; /* number of VBLANK interrupts */
525 /* (driver must alloc the right number of counters) */
526 atomic_t refcount; /* number of users of vblank interrupts */
527 u32 last; /* protected by dev->vbl_lock, used */
528 /* for wraparound handling */
529 int enabled; /* so we don't call enable more than */
530 /* once per disable */
531 int inmodeset; /* Display driver is setting mode */
534 /* location of GART table */
535 #define DRM_ATI_GART_MAIN 1
536 #define DRM_ATI_GART_FB 2
538 #define DRM_ATI_GART_PCI 1
539 #define DRM_ATI_GART_PCIE 2
540 #define DRM_ATI_GART_IGP 3
542 struct drm_ati_pcigart_info {
543 int gart_table_location;
544 int gart_reg_if;
545 void *addr;
546 dma_addr_t bus_addr;
547 dma_addr_t table_mask;
548 dma_addr_t member_mask;
549 struct drm_dma_handle *table_handle;
550 drm_local_map_t mapping;
551 int table_size;
552 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
555 #ifndef DMA_BIT_MASK
556 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
557 #endif
559 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
561 struct drm_driver_info {
562 int (*load)(struct drm_device *, unsigned long flags);
563 int (*firstopen)(struct drm_device *);
564 int (*open)(struct drm_device *, struct drm_file *);
565 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
566 void (*postclose)(struct drm_device *, struct drm_file *);
567 void (*lastclose)(struct drm_device *);
568 int (*unload)(struct drm_device *);
569 void (*reclaim_buffers_locked)(struct drm_device *,
570 struct drm_file *file_priv);
571 int (*dma_ioctl)(struct drm_device *dev, void *data,
572 struct drm_file *file_priv);
573 void (*dma_ready)(struct drm_device *);
574 int (*dma_quiescent)(struct drm_device *);
575 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
576 enum drm_lock_flags flags);
577 int (*dma_flush_unblock)(struct drm_device *, int context,
578 enum drm_lock_flags flags);
579 int (*context_ctor)(struct drm_device *dev, int context);
580 int (*context_dtor)(struct drm_device *dev, int context);
581 int (*kernel_context_switch)(struct drm_device *dev, int old,
582 int new);
583 int (*kernel_context_switch_unlock)(struct drm_device *dev);
584 void (*irq_preinstall)(struct drm_device *dev);
585 int (*irq_postinstall)(struct drm_device *dev);
586 void (*irq_uninstall)(struct drm_device *dev);
587 void (*irq_handler)(DRM_IRQ_ARGS);
588 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
589 int (*enable_vblank)(struct drm_device *dev, int crtc);
590 void (*disable_vblank)(struct drm_device *dev, int crtc);
592 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
595 * Called by \c drm_device_is_agp. Typically used to determine if a
596 * card is really attached to AGP or not.
598 * \param dev DRM device handle
600 * \returns
601 * One of three values is returned depending on whether or not the
602 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
603 * (return of 1), or may or may not be AGP (return of 2).
605 int (*device_is_agp) (struct drm_device * dev);
607 drm_ioctl_desc_t *ioctls;
608 int max_ioctl;
610 int buf_priv_size;
612 int major;
613 int minor;
614 int patchlevel;
615 const char *name; /* Simple driver name */
616 const char *desc; /* Longer driver name */
617 const char *date; /* Date of last major changes. */
619 u32 driver_features;
622 /* Length for the array of resource pointers for drm_get_resource_*. */
623 #define DRM_MAX_PCI_RESOURCE 6
625 /**
626 * DRM device functions structure
628 struct drm_device {
629 struct drm_driver_info *driver;
630 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
632 u_int16_t pci_device; /* PCI device id */
633 u_int16_t pci_vendor; /* PCI vendor id */
635 char *unique; /* Unique identifier: e.g., busid */
636 int unique_len; /* Length of unique field */
637 device_t device; /* Device instance from newbus */
638 struct cdev *devnode; /* Device number for mknod */
639 int if_version; /* Highest interface version set */
641 int flags; /* Flags to open(2) */
643 /* Locks */
644 DRM_SPINTYPE vbl_lock; /* protects vblank operations */
645 DRM_SPINTYPE dma_lock; /* protects dev->dma */
646 struct lwkt_serialize irq_lock; /* protects irq condition checks */
647 DRM_SPINTYPE dev_lock; /* protects everything else */
648 DRM_SPINTYPE drw_lock;
650 /* Usage Counters */
651 int open_count; /* Outstanding files open */
652 int buf_use; /* Buffers in use -- cannot alloc */
654 /* Performance counters */
655 unsigned long counters;
656 enum drm_stat_type types[15];
657 atomic_t counts[15];
659 /* Authentication */
660 drm_file_list_t files;
661 drm_magic_head_t magiclist[DRM_HASH_SIZE];
663 /* Linked list of mappable regions. Protected by dev_lock */
664 drm_map_list_t maplist;
666 drm_local_map_t **context_sareas;
667 int max_context;
669 drm_lock_data_t lock; /* Information on hardware lock */
671 /* DMA queues (contexts) */
672 drm_device_dma_t *dma; /* Optional pointer for DMA support */
674 /* Context support */
675 int irq; /* Interrupt used by board */
676 int irq_enabled; /* True if the irq handler is enabled */
677 int msi_enabled; /* MSI enabled */
678 int irqrid; /* Interrupt used by board */
679 struct resource *irqr; /* Resource for interrupt used by board */
680 void *irqh; /* Handle from bus_setup_intr */
682 /* Storage of resource pointers for drm_get_resource_* */
683 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
684 int pcirid[DRM_MAX_PCI_RESOURCE];
686 int pci_domain;
687 int pci_bus;
688 int pci_slot;
689 int pci_func;
691 atomic_t context_flag; /* Context swapping flag */
692 int last_context; /* Last current context */
694 int vblank_disable_allowed;
695 struct callout vblank_disable_timer;
696 u32 max_vblank_count; /* size of vblank counter register */
697 struct drm_vblank_info *vblank; /* per crtc vblank info */
698 int num_crtcs;
700 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
702 /* Sysctl support */
703 struct drm_sysctl_info *sysctl;
705 drm_agp_head_t *agp;
706 drm_sg_mem_t *sg; /* Scatter gather memory */
707 atomic_t *ctx_bitmap;
708 void *dev_private;
709 unsigned int agp_buffer_token;
710 drm_local_map_t *agp_buffer_map;
712 /* RB tree of drawable infos */
713 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
716 static __inline__ int drm_core_check_feature(struct drm_device *dev,
717 int feature)
719 return ((dev->driver->driver_features & feature) ? 1 : 0);
722 #if __OS_HAS_AGP
723 static inline int drm_core_has_AGP(struct drm_device *dev)
725 return drm_core_check_feature(dev, DRIVER_USE_AGP);
727 #else
728 #define drm_core_has_AGP(dev) (0)
729 #endif
731 extern int drm_debug_flag;
733 /* Device setup support (drm_drv.c) */
734 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
735 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
736 int drm_detach(device_t kdev);
737 d_ioctl_t drm_ioctl;
738 d_open_t drm_open;
739 d_close_t drm_close;
740 d_read_t drm_read;
741 d_kqfilter_t drm_kqfilter;
742 d_mmap_t drm_mmap;
743 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
745 /* File operations helpers (drm_fops.c) */
746 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
747 DRM_STRUCTPROC *p,
748 struct drm_device *dev);
749 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
750 DRM_STRUCTPROC *p);
752 /* Memory management support (drm_memory.c) */
753 void drm_mem_init(void);
754 void drm_mem_uninit(void);
755 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
756 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
757 void drm_ioremapfree(drm_local_map_t *map);
758 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
759 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
761 int drm_context_switch(struct drm_device *dev, int old, int new);
762 int drm_context_switch_complete(struct drm_device *dev, int new);
764 int drm_ctxbitmap_init(struct drm_device *dev);
765 void drm_ctxbitmap_cleanup(struct drm_device *dev);
766 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
767 int drm_ctxbitmap_next(struct drm_device *dev);
769 /* Locking IOCTL support (drm_lock.c) */
770 int drm_lock_take(struct drm_lock_data *lock_data,
771 unsigned int context);
772 int drm_lock_transfer(struct drm_lock_data *lock_data,
773 unsigned int context);
774 int drm_lock_free(struct drm_lock_data *lock_data,
775 unsigned int context);
777 /* Buffer management support (drm_bufs.c) */
778 unsigned long drm_get_resource_start(struct drm_device *dev,
779 unsigned int resource);
780 unsigned long drm_get_resource_len(struct drm_device *dev,
781 unsigned int resource);
782 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
783 int drm_order(unsigned long size);
784 int drm_addmap(struct drm_device *dev, unsigned long offset,
785 unsigned long size,
786 enum drm_map_type type, enum drm_map_flags flags,
787 drm_local_map_t **map_ptr);
788 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
789 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
790 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
792 /* DMA support (drm_dma.c) */
793 int drm_dma_setup(struct drm_device *dev);
794 void drm_dma_takedown(struct drm_device *dev);
795 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
796 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
797 #define drm_core_reclaim_buffers drm_reclaim_buffers
799 /* IRQ support (drm_irq.c) */
800 int drm_irq_install(struct drm_device *dev);
801 int drm_irq_uninstall(struct drm_device *dev);
802 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
803 void drm_driver_irq_preinstall(struct drm_device *dev);
804 void drm_driver_irq_postinstall(struct drm_device *dev);
805 void drm_driver_irq_uninstall(struct drm_device *dev);
806 void drm_handle_vblank(struct drm_device *dev, int crtc);
807 u32 drm_vblank_count(struct drm_device *dev, int crtc);
808 int drm_vblank_get(struct drm_device *dev, int crtc);
809 void drm_vblank_put(struct drm_device *dev, int crtc);
810 void drm_vblank_cleanup(struct drm_device *dev);
811 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
812 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
813 int drm_modeset_ctl(struct drm_device *dev, void *data,
814 struct drm_file *file_priv);
816 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
817 int drm_device_is_agp(struct drm_device *dev);
818 int drm_device_is_pcie(struct drm_device *dev);
819 drm_agp_head_t *drm_agp_init(void);
820 int drm_agp_acquire(struct drm_device *dev);
821 int drm_agp_release(struct drm_device *dev);
822 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
823 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
824 void *drm_agp_allocate_memory(size_t pages, u32 type);
825 int drm_agp_free_memory(void *handle);
826 int drm_agp_bind_memory(void *handle, off_t start);
827 int drm_agp_unbind_memory(void *handle);
828 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
829 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
830 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
831 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
833 /* Scatter Gather Support (drm_scatter.c) */
834 void drm_sg_cleanup(drm_sg_mem_t *entry);
835 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
837 /* sysctl support (drm_sysctl.h) */
838 extern int drm_sysctl_init(struct drm_device *dev);
839 extern int drm_sysctl_cleanup(struct drm_device *dev);
841 /* ATI PCIGART support (ati_pcigart.c) */
842 int drm_ati_pcigart_init(struct drm_device *dev,
843 struct drm_ati_pcigart_info *gart_info);
844 int drm_ati_pcigart_cleanup(struct drm_device *dev,
845 struct drm_ati_pcigart_info *gart_info);
847 /* Locking IOCTL support (drm_drv.c) */
848 int drm_lock(struct drm_device *dev, void *data,
849 struct drm_file *file_priv);
850 int drm_unlock(struct drm_device *dev, void *data,
851 struct drm_file *file_priv);
852 int drm_version(struct drm_device *dev, void *data,
853 struct drm_file *file_priv);
854 int drm_setversion(struct drm_device *dev, void *data,
855 struct drm_file *file_priv);
857 /* Misc. IOCTL support (drm_ioctl.c) */
858 int drm_irq_by_busid(struct drm_device *dev, void *data,
859 struct drm_file *file_priv);
860 int drm_getunique(struct drm_device *dev, void *data,
861 struct drm_file *file_priv);
862 int drm_setunique(struct drm_device *dev, void *data,
863 struct drm_file *file_priv);
864 int drm_getmap(struct drm_device *dev, void *data,
865 struct drm_file *file_priv);
866 int drm_getclient(struct drm_device *dev, void *data,
867 struct drm_file *file_priv);
868 int drm_getstats(struct drm_device *dev, void *data,
869 struct drm_file *file_priv);
870 int drm_noop(struct drm_device *dev, void *data,
871 struct drm_file *file_priv);
873 /* Context IOCTL support (drm_context.c) */
874 int drm_resctx(struct drm_device *dev, void *data,
875 struct drm_file *file_priv);
876 int drm_addctx(struct drm_device *dev, void *data,
877 struct drm_file *file_priv);
878 int drm_modctx(struct drm_device *dev, void *data,
879 struct drm_file *file_priv);
880 int drm_getctx(struct drm_device *dev, void *data,
881 struct drm_file *file_priv);
882 int drm_switchctx(struct drm_device *dev, void *data,
883 struct drm_file *file_priv);
884 int drm_newctx(struct drm_device *dev, void *data,
885 struct drm_file *file_priv);
886 int drm_rmctx(struct drm_device *dev, void *data,
887 struct drm_file *file_priv);
888 int drm_setsareactx(struct drm_device *dev, void *data,
889 struct drm_file *file_priv);
890 int drm_getsareactx(struct drm_device *dev, void *data,
891 struct drm_file *file_priv);
893 /* Drawable IOCTL support (drm_drawable.c) */
894 int drm_adddraw(struct drm_device *dev, void *data,
895 struct drm_file *file_priv);
896 int drm_rmdraw(struct drm_device *dev, void *data,
897 struct drm_file *file_priv);
898 int drm_update_draw(struct drm_device *dev, void *data,
899 struct drm_file *file_priv);
900 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
901 int handle);
903 /* Drawable support (drm_drawable.c) */
904 void drm_drawable_free_all(struct drm_device *dev);
906 /* Authentication IOCTL support (drm_auth.c) */
907 int drm_getmagic(struct drm_device *dev, void *data,
908 struct drm_file *file_priv);
909 int drm_authmagic(struct drm_device *dev, void *data,
910 struct drm_file *file_priv);
912 /* Buffer management support (drm_bufs.c) */
913 int drm_addmap_ioctl(struct drm_device *dev, void *data,
914 struct drm_file *file_priv);
915 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
916 struct drm_file *file_priv);
917 int drm_addbufs(struct drm_device *dev, void *data,
918 struct drm_file *file_priv);
919 int drm_infobufs(struct drm_device *dev, void *data,
920 struct drm_file *file_priv);
921 int drm_markbufs(struct drm_device *dev, void *data,
922 struct drm_file *file_priv);
923 int drm_freebufs(struct drm_device *dev, void *data,
924 struct drm_file *file_priv);
925 int drm_mapbufs(struct drm_device *dev, void *data,
926 struct drm_file *file_priv);
928 /* DMA support (drm_dma.c) */
929 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
931 /* IRQ support (drm_irq.c) */
932 int drm_control(struct drm_device *dev, void *data,
933 struct drm_file *file_priv);
934 int drm_wait_vblank(struct drm_device *dev, void *data,
935 struct drm_file *file_priv);
937 /* AGP/GART support (drm_agpsupport.c) */
938 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
939 struct drm_file *file_priv);
940 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
941 struct drm_file *file_priv);
942 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
943 struct drm_file *file_priv);
944 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
945 struct drm_file *file_priv);
946 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
947 struct drm_file *file_priv);
948 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
949 struct drm_file *file_priv);
950 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
951 struct drm_file *file_priv);
952 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
953 struct drm_file *file_priv);
955 /* Scatter Gather Support (drm_scatter.c) */
956 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
957 struct drm_file *file_priv);
958 int drm_sg_free(struct drm_device *dev, void *data,
959 struct drm_file *file_priv);
961 /* consistent PCI memory functions (drm_pci.c) */
962 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
963 size_t align, dma_addr_t maxaddr);
964 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
966 /* Inline replacements for drm_alloc and friends */
967 static __inline__ void *
968 drm_alloc(size_t size, struct malloc_type *area)
970 return malloc(size, area, M_NOWAIT);
973 static __inline__ void *
974 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
976 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
979 static __inline__ void *
980 drm_realloc(void *oldpt, size_t oldsize, size_t size,
981 struct malloc_type *area)
983 return reallocf(oldpt, size, area, M_NOWAIT);
986 static __inline__ void
987 drm_free(void *pt, size_t size, struct malloc_type *area)
989 free(pt, area);
992 /* Inline replacements for DRM_IOREMAP macros */
993 static __inline__ void
994 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
996 map->handle = drm_ioremap_wc(dev, map);
998 static __inline__ void
999 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1001 map->handle = drm_ioremap(dev, map);
1003 static __inline__ void
1004 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1006 if ( map->handle && map->size )
1007 drm_ioremapfree(map);
1010 static __inline__ struct drm_local_map *
1011 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1013 drm_local_map_t *map;
1015 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1016 TAILQ_FOREACH(map, &dev->maplist, link) {
1017 if (map->offset == offset)
1018 return map;
1020 return NULL;
1023 static __inline__ void drm_core_dropmap(struct drm_map *map)
1027 #endif /* __KERNEL__ */
1028 #endif /* _DRM_P_H_ */