1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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
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.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #if defined(_KERNEL) || defined(__KERNEL__)
45 #include <sys/param.h>
46 #include <sys/queue.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/module.h>
50 #include <sys/systm.h>
53 #if __FreeBSD_version >= 700000
58 #include <sys/fcntl.h>
60 #include <sys/filio.h>
61 #include <sys/sysctl.h>
63 #include <sys/signalvar.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_map.h>
70 #include <vm/vm_param.h>
71 #include <machine/param.h>
72 #include <machine/pmap.h>
73 #include <machine/bus.h>
74 #include <machine/resource.h>
75 #include <machine/specialreg.h>
76 #include <machine/sysarch.h>
77 #include <sys/endian.h>
80 #include <sys/memrange.h>
81 #if __FreeBSD_version >= 800004
82 #include <dev/agp/agpvar.h>
83 #else /* __FreeBSD_version >= 800004 */
84 #include <pci/agpvar.h>
85 #endif /* __FreeBSD_version >= 800004 */
86 #include <sys/agpio.h>
87 #include <sys/mutex.h>
88 #include <dev/pci/pcivar.h>
89 #include <dev/pci/pcireg.h>
90 #include <sys/selinfo.h>
93 #include "dev/drm/drm.h"
94 #include "dev/drm/drm_linux_list.h"
95 #include "dev/drm/drm_atomic.h"
96 #include "dev/drm/drm_internal.h"
101 #define DRM_DEBUG_DEFAULT_ON 1
102 #endif /* DRM_DEBUG */
104 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
105 #include <sys/file.h>
106 #include <sys/proc.h>
107 #include <machine/../linux/linux.h>
108 #include <machine/../linux/linux_proto.h>
110 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
111 * supported on this OS yet.
117 /* driver capabilities and requirements mask */
118 #define DRIVER_USE_AGP 0x1
119 #define DRIVER_REQUIRE_AGP 0x2
120 #define DRIVER_USE_MTRR 0x4
121 #define DRIVER_PCI_DMA 0x8
122 #define DRIVER_SG 0x10
123 #define DRIVER_HAVE_DMA 0x20
124 #define DRIVER_HAVE_IRQ 0x40
125 #define DRIVER_DMA_QUEUE 0x100
128 #define DRM_HASH_SIZE 16 /* Size of key hash table */
129 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
130 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
132 MALLOC_DECLARE(DRM_MEM_DMA);
133 MALLOC_DECLARE(DRM_MEM_SAREA);
134 MALLOC_DECLARE(DRM_MEM_DRIVER);
135 MALLOC_DECLARE(DRM_MEM_MAGIC);
136 MALLOC_DECLARE(DRM_MEM_IOCTLS);
137 MALLOC_DECLARE(DRM_MEM_MAPS);
138 MALLOC_DECLARE(DRM_MEM_BUFS);
139 MALLOC_DECLARE(DRM_MEM_SEGS);
140 MALLOC_DECLARE(DRM_MEM_PAGES);
141 MALLOC_DECLARE(DRM_MEM_FILES);
142 MALLOC_DECLARE(DRM_MEM_QUEUES);
143 MALLOC_DECLARE(DRM_MEM_CMDS);
144 MALLOC_DECLARE(DRM_MEM_MAPPINGS);
145 MALLOC_DECLARE(DRM_MEM_BUFLISTS);
146 MALLOC_DECLARE(DRM_MEM_AGPLISTS);
147 MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
148 MALLOC_DECLARE(DRM_MEM_SGLISTS);
149 MALLOC_DECLARE(DRM_MEM_DRAWABLE);
151 SYSCTL_DECL(_hw_drm);
153 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
155 /* Internal types and structures */
156 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
157 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
158 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
160 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
162 #define __OS_HAS_AGP 1
164 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
165 #define DRM_DEV_UID 0
166 #define DRM_DEV_GID 0
168 #define wait_queue_head_t atomic_t
169 #define DRM_WAKEUP(w) wakeup((void *)w)
170 #define DRM_WAKEUP_INT(w) wakeup(w)
171 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
173 #define DRM_CURPROC curthread
174 #define DRM_STRUCTPROC struct thread
175 #define DRM_SPINTYPE struct mtx
176 #define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
177 #define DRM_SPINUNINIT(l) mtx_destroy(l)
178 #define DRM_SPINLOCK(l) mtx_lock(l)
179 #define DRM_SPINUNLOCK(u) mtx_unlock(u)
180 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
184 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
185 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
186 #define DRM_CURRENTPID curthread->td_proc->p_pid
187 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
188 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
189 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
191 #define DRM_IRQ_ARGS void *arg
192 typedef void irqreturn_t;
193 #define IRQ_HANDLED /* nothing */
194 #define IRQ_NONE /* nothing */
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 #if __FreeBSD_version >= 700000
208 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
210 #define DRM_SUSER(p) (suser(p) == 0)
212 #define DRM_AGP_FIND_DEVICE() agp_find_device()
213 #define DRM_MTRR_WC MDF_WRITECOMBINE
214 #define jiffies ticks
216 typedef unsigned long dma_addr_t;
217 typedef u_int64_t u64;
218 typedef u_int32_t u32;
219 typedef u_int16_t u16;
222 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
223 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
224 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
226 #define DRM_READMEMORYBARRIER() rmb()
227 #define DRM_WRITEMEMORYBARRIER() wmb()
228 #define DRM_MEMORYBARRIER() mb()
230 #define DRM_READ8(map, offset) \
231 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
232 (vm_offset_t)(offset))
233 #define DRM_READ16(map, offset) \
234 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
235 (vm_offset_t)(offset))
236 #define DRM_READ32(map, offset) \
237 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
238 (vm_offset_t)(offset))
239 #define DRM_WRITE8(map, offset, val) \
240 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
241 (vm_offset_t)(offset)) = val
242 #define DRM_WRITE16(map, offset, val) \
243 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
244 (vm_offset_t)(offset)) = val
245 #define DRM_WRITE32(map, offset, val) \
246 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
247 (vm_offset_t)(offset)) = val
249 #define DRM_VERIFYAREA_READ( uaddr, size ) \
250 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
252 #define DRM_COPY_TO_USER(user, kern, size) \
253 copyout(kern, user, size)
254 #define DRM_COPY_FROM_USER(kern, user, size) \
255 copyin(user, kern, size)
256 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
257 copyin(arg2, arg1, arg3)
258 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
259 copyout(arg2, arg1, arg3)
260 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
261 ((val) = fuword32(uaddr), 0)
263 #define cpu_to_le32(x) htole32(x)
264 #define le32_to_cpu(x) le32toh(x)
267 #define DRM_UDELAY(udelay) DELAY(udelay)
268 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
270 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
271 (_map) = (_dev)->context_sareas[_ctx]; \
274 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
276 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
277 dev->lock.file_priv != file_priv) { \
278 DRM_ERROR("%s called without lock held\n", \
284 /* Returns -errno to shared code */
285 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
286 for ( ret = 0 ; !ret && !(condition) ; ) { \
288 mtx_lock(&dev->irq_lock); \
290 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
291 PCATCH, "drmwtq", (timeout)); \
292 mtx_unlock(&dev->irq_lock); \
296 #define DRM_ERROR(fmt, ...) \
297 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
298 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
300 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
302 #define DRM_DEBUG(fmt, ...) do { \
303 if (drm_debug_flag) \
304 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
305 __func__ , ##__VA_ARGS__); \
308 typedef struct drm_pci_id_list
316 struct drm_msi_blacklist_entry
323 #define DRM_MASTER 0x2
324 #define DRM_ROOT_ONLY 0x4
325 typedef struct drm_ioctl_desc {
327 int (*func)(struct drm_device *dev, void *data,
328 struct drm_file *file_priv);
332 * Creates a driver or general drm_ioctl_desc array entry for the given
333 * ioctl, for use by drm_ioctl().
335 #define DRM_IOCTL_DEF(ioctl, func, flags) \
336 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
338 typedef struct drm_magic_entry {
340 struct drm_file *priv;
341 struct drm_magic_entry *next;
344 typedef struct drm_magic_head {
345 struct drm_magic_entry *head;
346 struct drm_magic_entry *tail;
349 typedef struct drm_buf {
350 int idx; /* Index into master buflist */
351 int total; /* Buffer size */
352 int order; /* log-base-2(total) */
353 int used; /* Amount of buffer in use (for DMA) */
354 unsigned long offset; /* Byte offset (used internally) */
355 void *address; /* Address of buffer */
356 unsigned long bus_address; /* Bus address of buffer */
357 struct drm_buf *next; /* Kernel-only: used for free list */
358 __volatile__ int pending; /* On hardware DMA queue */
359 struct drm_file *file_priv; /* Unique identifier of holding process */
360 int context; /* Kernel queue for this buffer */
368 } list; /* Which list we're on */
370 int dev_priv_size; /* Size of buffer private stoarge */
371 void *dev_private; /* Per-buffer private storage */
374 typedef struct drm_freelist {
375 int initialized; /* Freelist in use */
376 atomic_t count; /* Number of free buffers */
377 drm_buf_t *next; /* End pointer */
379 int low_mark; /* Low water mark */
380 int high_mark; /* High water mark */
383 typedef struct drm_dma_handle {
390 typedef struct drm_buf_entry {
395 drm_dma_handle_t **seglist;
398 drm_freelist_t freelist;
401 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
403 TAILQ_ENTRY(drm_file) link;
404 struct drm_device *dev;
410 unsigned long ioctl_count;
414 typedef struct drm_lock_data {
415 struct drm_hw_lock *hw_lock; /* Hardware lock */
416 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
417 int lock_queue; /* Queue of blocked processes */
418 unsigned long lock_time; /* Time of last lock in jiffies */
421 /* This structure, in the struct drm_device, is always initialized while the
423 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
424 * when set marks that no further bufs may be allocated until device teardown
425 * occurs (when the last open of the device has closed). The high/low
426 * watermarks of bufs are only touched by the X Server, and thus not
427 * concurrently accessed, so no locking is needed.
429 typedef struct drm_device_dma {
430 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
432 drm_buf_t **buflist; /* Vector of pointers info bufs */
435 unsigned long *pagelist;
436 unsigned long byte_count;
438 _DRM_DMA_USE_AGP = 0x01,
439 _DRM_DMA_USE_SG = 0x02
443 typedef struct drm_agp_mem {
445 unsigned long bound; /* address */
447 struct drm_agp_mem *prev;
448 struct drm_agp_mem *next;
451 typedef struct drm_agp_head {
453 struct agp_info info;
455 drm_agp_mem_t *memory;
461 int cant_use_aperture;
462 unsigned long page_mask;
465 typedef struct drm_sg_mem {
466 unsigned long handle;
470 struct drm_dma_handle *dmah; /* Handle to PCI memory */
473 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
475 typedef struct drm_local_map {
476 unsigned long offset; /* Physical address (0 for SAREA)*/
477 unsigned long size; /* Physical size (bytes) */
478 enum drm_map_type type; /* Type of memory mapped */
479 enum drm_map_flags flags; /* Flags */
480 void *handle; /* User-space: "Handle" to pass to mmap */
481 /* Kernel-space: kernel-virtual address */
482 int mtrr; /* Boolean: MTRR used */
484 int rid; /* PCI resource ID for bus_space */
485 struct resource *bsr;
487 bus_space_handle_t bsh;
488 drm_dma_handle_t *dmah;
489 TAILQ_ENTRY(drm_local_map) link;
492 struct drm_vblank_info {
493 wait_queue_head_t queue; /* vblank wait queue */
494 atomic_t count; /* number of VBLANK interrupts */
495 /* (driver must alloc the right number of counters) */
496 atomic_t refcount; /* number of users of vblank interrupts */
497 u32 last; /* protected by dev->vbl_lock, used */
498 /* for wraparound handling */
499 int enabled; /* so we don't call enable more than */
500 /* once per disable */
501 int inmodeset; /* Display driver is setting mode */
504 /* location of GART table */
505 #define DRM_ATI_GART_MAIN 1
506 #define DRM_ATI_GART_FB 2
508 #define DRM_ATI_GART_PCI 1
509 #define DRM_ATI_GART_PCIE 2
510 #define DRM_ATI_GART_IGP 3
512 struct drm_ati_pcigart_info {
513 int gart_table_location;
517 dma_addr_t table_mask;
518 dma_addr_t member_mask;
519 struct drm_dma_handle *table_handle;
520 drm_local_map_t mapping;
522 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
526 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
529 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
531 struct drm_driver_info {
532 int (*load)(struct drm_device *, unsigned long flags);
533 int (*firstopen)(struct drm_device *);
534 int (*open)(struct drm_device *, struct drm_file *);
535 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
536 void (*postclose)(struct drm_device *, struct drm_file *);
537 void (*lastclose)(struct drm_device *);
538 int (*unload)(struct drm_device *);
539 void (*reclaim_buffers_locked)(struct drm_device *,
540 struct drm_file *file_priv);
541 int (*dma_ioctl)(struct drm_device *dev, void *data,
542 struct drm_file *file_priv);
543 void (*dma_ready)(struct drm_device *);
544 int (*dma_quiescent)(struct drm_device *);
545 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
546 enum drm_lock_flags flags);
547 int (*dma_flush_unblock)(struct drm_device *, int context,
548 enum drm_lock_flags flags);
549 int (*context_ctor)(struct drm_device *dev, int context);
550 int (*context_dtor)(struct drm_device *dev, int context);
551 int (*kernel_context_switch)(struct drm_device *dev, int old,
553 int (*kernel_context_switch_unlock)(struct drm_device *dev);
554 void (*irq_preinstall)(struct drm_device *dev);
555 int (*irq_postinstall)(struct drm_device *dev);
556 void (*irq_uninstall)(struct drm_device *dev);
557 void (*irq_handler)(DRM_IRQ_ARGS);
558 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
559 int (*enable_vblank)(struct drm_device *dev, int crtc);
560 void (*disable_vblank)(struct drm_device *dev, int crtc);
562 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
565 * Called by \c drm_device_is_agp. Typically used to determine if a
566 * card is really attached to AGP or not.
568 * \param dev DRM device handle
571 * One of three values is returned depending on whether or not the
572 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
573 * (return of 1), or may or may not be AGP (return of 2).
575 int (*device_is_agp) (struct drm_device * dev);
577 drm_ioctl_desc_t *ioctls;
585 const char *name; /* Simple driver name */
586 const char *desc; /* Longer driver name */
587 const char *date; /* Date of last major changes. */
592 /* Length for the array of resource pointers for drm_get_resource_*. */
593 #define DRM_MAX_PCI_RESOURCE 6
596 * DRM device functions structure
599 struct drm_driver_info *driver;
600 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
602 u_int16_t pci_device; /* PCI device id */
603 u_int16_t pci_vendor; /* PCI vendor id */
605 char *unique; /* Unique identifier: e.g., busid */
606 int unique_len; /* Length of unique field */
607 device_t device; /* Device instance from newbus */
608 struct cdev *devnode; /* Device number for mknod */
609 int if_version; /* Highest interface version set */
611 int flags; /* Flags to open(2) */
614 struct mtx vbl_lock; /* protects vblank operations */
615 struct mtx dma_lock; /* protects dev->dma */
616 struct mtx irq_lock; /* protects irq condition checks */
617 struct mtx dev_lock; /* protects everything else */
618 DRM_SPINTYPE drw_lock;
621 int open_count; /* Outstanding files open */
622 int buf_use; /* Buffers in use -- cannot alloc */
624 /* Performance counters */
625 unsigned long counters;
626 enum drm_stat_type types[15];
630 drm_file_list_t files;
631 drm_magic_head_t magiclist[DRM_HASH_SIZE];
633 /* Linked list of mappable regions. Protected by dev_lock */
634 drm_map_list_t maplist;
636 drm_local_map_t **context_sareas;
639 drm_lock_data_t lock; /* Information on hardware lock */
641 /* DMA queues (contexts) */
642 drm_device_dma_t *dma; /* Optional pointer for DMA support */
644 /* Context support */
645 int irq; /* Interrupt used by board */
646 int irq_enabled; /* True if the irq handler is enabled */
647 int msi_enabled; /* MSI enabled */
648 int irqrid; /* Interrupt used by board */
649 struct resource *irqr; /* Resource for interrupt used by board */
650 void *irqh; /* Handle from bus_setup_intr */
652 /* Storage of resource pointers for drm_get_resource_* */
653 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
654 int pcirid[DRM_MAX_PCI_RESOURCE];
661 atomic_t context_flag; /* Context swapping flag */
662 int last_context; /* Last current context */
664 int vblank_disable_allowed;
665 struct callout vblank_disable_timer;
666 u32 max_vblank_count; /* size of vblank counter register */
667 struct drm_vblank_info *vblank; /* per crtc vblank info */
670 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
673 struct drm_sysctl_info *sysctl;
676 drm_sg_mem_t *sg; /* Scatter gather memory */
677 atomic_t *ctx_bitmap;
679 unsigned int agp_buffer_token;
680 drm_local_map_t *agp_buffer_map;
682 struct unrhdr *drw_unrhdr;
683 /* RB tree of drawable infos */
684 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
687 static __inline__ int drm_core_check_feature(struct drm_device *dev,
690 return ((dev->driver->driver_features & feature) ? 1 : 0);
694 static inline int drm_core_has_AGP(struct drm_device *dev)
696 return drm_core_check_feature(dev, DRIVER_USE_AGP);
699 #define drm_core_has_AGP(dev) (0)
702 extern int drm_debug_flag;
704 /* Device setup support (drm_drv.c) */
705 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
706 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
707 void drm_close(void *data);
708 int drm_detach(device_t kdev);
714 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
716 /* File operations helpers (drm_fops.c) */
717 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
719 struct drm_device *dev);
721 /* Memory management support (drm_memory.c) */
722 void drm_mem_init(void);
723 void drm_mem_uninit(void);
724 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
725 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
726 void drm_ioremapfree(drm_local_map_t *map);
727 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
728 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
730 int drm_context_switch(struct drm_device *dev, int old, int new);
731 int drm_context_switch_complete(struct drm_device *dev, int new);
733 int drm_ctxbitmap_init(struct drm_device *dev);
734 void drm_ctxbitmap_cleanup(struct drm_device *dev);
735 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
736 int drm_ctxbitmap_next(struct drm_device *dev);
738 /* Locking IOCTL support (drm_lock.c) */
739 int drm_lock_take(struct drm_lock_data *lock_data,
740 unsigned int context);
741 int drm_lock_transfer(struct drm_lock_data *lock_data,
742 unsigned int context);
743 int drm_lock_free(struct drm_lock_data *lock_data,
744 unsigned int context);
746 /* Buffer management support (drm_bufs.c) */
747 unsigned long drm_get_resource_start(struct drm_device *dev,
748 unsigned int resource);
749 unsigned long drm_get_resource_len(struct drm_device *dev,
750 unsigned int resource);
751 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
752 int drm_order(unsigned long size);
753 int drm_addmap(struct drm_device *dev, unsigned long offset,
755 enum drm_map_type type, enum drm_map_flags flags,
756 drm_local_map_t **map_ptr);
757 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
758 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
759 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
761 /* DMA support (drm_dma.c) */
762 int drm_dma_setup(struct drm_device *dev);
763 void drm_dma_takedown(struct drm_device *dev);
764 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
765 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
766 #define drm_core_reclaim_buffers drm_reclaim_buffers
768 /* IRQ support (drm_irq.c) */
769 int drm_irq_install(struct drm_device *dev);
770 int drm_irq_uninstall(struct drm_device *dev);
771 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
772 void drm_driver_irq_preinstall(struct drm_device *dev);
773 void drm_driver_irq_postinstall(struct drm_device *dev);
774 void drm_driver_irq_uninstall(struct drm_device *dev);
775 void drm_handle_vblank(struct drm_device *dev, int crtc);
776 u32 drm_vblank_count(struct drm_device *dev, int crtc);
777 int drm_vblank_get(struct drm_device *dev, int crtc);
778 void drm_vblank_put(struct drm_device *dev, int crtc);
779 void drm_vblank_cleanup(struct drm_device *dev);
780 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
781 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
782 int drm_modeset_ctl(struct drm_device *dev, void *data,
783 struct drm_file *file_priv);
785 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
786 int drm_device_is_agp(struct drm_device *dev);
787 int drm_device_is_pcie(struct drm_device *dev);
788 drm_agp_head_t *drm_agp_init(void);
789 int drm_agp_acquire(struct drm_device *dev);
790 int drm_agp_release(struct drm_device *dev);
791 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
792 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
793 void *drm_agp_allocate_memory(size_t pages, u32 type);
794 int drm_agp_free_memory(void *handle);
795 int drm_agp_bind_memory(void *handle, off_t start);
796 int drm_agp_unbind_memory(void *handle);
797 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
798 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
799 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
800 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
802 /* Scatter Gather Support (drm_scatter.c) */
803 void drm_sg_cleanup(drm_sg_mem_t *entry);
804 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
806 /* sysctl support (drm_sysctl.h) */
807 extern int drm_sysctl_init(struct drm_device *dev);
808 extern int drm_sysctl_cleanup(struct drm_device *dev);
810 /* ATI PCIGART support (ati_pcigart.c) */
811 int drm_ati_pcigart_init(struct drm_device *dev,
812 struct drm_ati_pcigart_info *gart_info);
813 int drm_ati_pcigart_cleanup(struct drm_device *dev,
814 struct drm_ati_pcigart_info *gart_info);
816 /* Locking IOCTL support (drm_drv.c) */
817 int drm_lock(struct drm_device *dev, void *data,
818 struct drm_file *file_priv);
819 int drm_unlock(struct drm_device *dev, void *data,
820 struct drm_file *file_priv);
821 int drm_version(struct drm_device *dev, void *data,
822 struct drm_file *file_priv);
823 int drm_setversion(struct drm_device *dev, void *data,
824 struct drm_file *file_priv);
826 /* Misc. IOCTL support (drm_ioctl.c) */
827 int drm_irq_by_busid(struct drm_device *dev, void *data,
828 struct drm_file *file_priv);
829 int drm_getunique(struct drm_device *dev, void *data,
830 struct drm_file *file_priv);
831 int drm_setunique(struct drm_device *dev, void *data,
832 struct drm_file *file_priv);
833 int drm_getmap(struct drm_device *dev, void *data,
834 struct drm_file *file_priv);
835 int drm_getclient(struct drm_device *dev, void *data,
836 struct drm_file *file_priv);
837 int drm_getstats(struct drm_device *dev, void *data,
838 struct drm_file *file_priv);
839 int drm_noop(struct drm_device *dev, void *data,
840 struct drm_file *file_priv);
842 /* Context IOCTL support (drm_context.c) */
843 int drm_resctx(struct drm_device *dev, void *data,
844 struct drm_file *file_priv);
845 int drm_addctx(struct drm_device *dev, void *data,
846 struct drm_file *file_priv);
847 int drm_modctx(struct drm_device *dev, void *data,
848 struct drm_file *file_priv);
849 int drm_getctx(struct drm_device *dev, void *data,
850 struct drm_file *file_priv);
851 int drm_switchctx(struct drm_device *dev, void *data,
852 struct drm_file *file_priv);
853 int drm_newctx(struct drm_device *dev, void *data,
854 struct drm_file *file_priv);
855 int drm_rmctx(struct drm_device *dev, void *data,
856 struct drm_file *file_priv);
857 int drm_setsareactx(struct drm_device *dev, void *data,
858 struct drm_file *file_priv);
859 int drm_getsareactx(struct drm_device *dev, void *data,
860 struct drm_file *file_priv);
862 /* Drawable IOCTL support (drm_drawable.c) */
863 int drm_adddraw(struct drm_device *dev, void *data,
864 struct drm_file *file_priv);
865 int drm_rmdraw(struct drm_device *dev, void *data,
866 struct drm_file *file_priv);
867 int drm_update_draw(struct drm_device *dev, void *data,
868 struct drm_file *file_priv);
869 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
872 /* Drawable support (drm_drawable.c) */
873 void drm_drawable_free_all(struct drm_device *dev);
875 /* Authentication IOCTL support (drm_auth.c) */
876 int drm_getmagic(struct drm_device *dev, void *data,
877 struct drm_file *file_priv);
878 int drm_authmagic(struct drm_device *dev, void *data,
879 struct drm_file *file_priv);
881 /* Buffer management support (drm_bufs.c) */
882 int drm_addmap_ioctl(struct drm_device *dev, void *data,
883 struct drm_file *file_priv);
884 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
885 struct drm_file *file_priv);
886 int drm_addbufs(struct drm_device *dev, void *data,
887 struct drm_file *file_priv);
888 int drm_infobufs(struct drm_device *dev, void *data,
889 struct drm_file *file_priv);
890 int drm_markbufs(struct drm_device *dev, void *data,
891 struct drm_file *file_priv);
892 int drm_freebufs(struct drm_device *dev, void *data,
893 struct drm_file *file_priv);
894 int drm_mapbufs(struct drm_device *dev, void *data,
895 struct drm_file *file_priv);
897 /* DMA support (drm_dma.c) */
898 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
900 /* IRQ support (drm_irq.c) */
901 int drm_control(struct drm_device *dev, void *data,
902 struct drm_file *file_priv);
903 int drm_wait_vblank(struct drm_device *dev, void *data,
904 struct drm_file *file_priv);
906 /* AGP/GART support (drm_agpsupport.c) */
907 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
908 struct drm_file *file_priv);
909 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
910 struct drm_file *file_priv);
911 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
912 struct drm_file *file_priv);
913 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
914 struct drm_file *file_priv);
915 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
916 struct drm_file *file_priv);
917 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
918 struct drm_file *file_priv);
919 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
920 struct drm_file *file_priv);
921 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
922 struct drm_file *file_priv);
924 /* Scatter Gather Support (drm_scatter.c) */
925 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
926 struct drm_file *file_priv);
927 int drm_sg_free(struct drm_device *dev, void *data,
928 struct drm_file *file_priv);
930 /* consistent PCI memory functions (drm_pci.c) */
931 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
932 size_t align, dma_addr_t maxaddr);
933 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
935 /* Inline replacements for drm_alloc and friends */
936 static __inline__ void *
937 drm_alloc(size_t size, struct malloc_type *area)
939 return malloc(size, area, M_NOWAIT);
942 static __inline__ void *
943 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
945 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
948 static __inline__ void *
949 drm_realloc(void *oldpt, size_t oldsize, size_t size,
950 struct malloc_type *area)
952 return reallocf(oldpt, size, area, M_NOWAIT);
955 static __inline__ void
956 drm_free(void *pt, size_t size, struct malloc_type *area)
961 /* Inline replacements for DRM_IOREMAP macros */
962 static __inline__ void
963 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
965 map->handle = drm_ioremap_wc(dev, map);
967 static __inline__ void
968 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
970 map->handle = drm_ioremap(dev, map);
972 static __inline__ void
973 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
975 if ( map->handle && map->size )
976 drm_ioremapfree(map);
979 static __inline__ struct drm_local_map *
980 drm_core_findmap(struct drm_device *dev, unsigned long offset)
982 drm_local_map_t *map;
984 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
985 TAILQ_FOREACH(map, &dev->maplist, link) {
986 if (map->offset == offset)
992 static __inline__ void drm_core_dropmap(struct drm_map *map)
996 #endif /* __KERNEL__ */
997 #endif /* _DRM_P_H_ */