blob: c93985bb91a20912a824c32f6613ffda23ca1aa2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
Dave Airlieb5e89ed2005-09-25 14:28:13 +10002 * \file drmP.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Private header for Direct Rendering Manager
Dave Airlieb5e89ed2005-09-25 14:28:13 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 */
8
9/*
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All rights reserved.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice (including the next
22 * paragraph) shall be included in all copies or substantial portions of the
23 * Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 * OTHER DEALINGS IN THE SOFTWARE.
32 */
33
34#ifndef _DRM_P_H_
35#define _DRM_P_H_
36
37/* If you want the memory alloc debug functionality, change define below */
38/* #define DEBUG_MEMORY */
39
40#ifdef __KERNEL__
41#ifdef __alpha__
42/* add include of current.h so that "current" is defined
43 * before static inline funcs in wait.h. Doing this so we
44 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
45#include <asm/current.h>
Dave Airlieb5e89ed2005-09-25 14:28:13 +100046#endif /* __alpha__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/miscdevice.h>
50#include <linux/fs.h>
51#include <linux/proc_fs.h>
52#include <linux/init.h>
53#include <linux/file.h>
54#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/jiffies.h>
56#include <linux/smp_lock.h> /* For (un)lock_kernel */
57#include <linux/mm.h>
58#include <linux/cdev.h>
Dave Airlie30e2fb12006-02-02 19:37:46 +110059#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#if defined(__alpha__) || defined(__powerpc__)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100061#include <asm/pgtable.h> /* For pte_wrprotect */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#endif
63#include <asm/io.h>
64#include <asm/mman.h>
65#include <asm/uaccess.h>
66#ifdef CONFIG_MTRR
67#include <asm/mtrr.h>
68#endif
69#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
70#include <linux/types.h>
71#include <linux/agp_backend.h>
72#endif
73#include <linux/workqueue.h>
74#include <linux/poll.h>
75#include <asm/pgalloc.h>
76#include "drm.h"
77
78#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
79#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
80
81#include "drm_os_linux.h"
Thomas Hellstrom3a1bd922006-08-07 21:30:28 +100082#include "drm_hashtab.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/***********************************************************************/
85/** \name DRM template customization defaults */
86/*@{*/
87
88/* driver capabilities and requirements mask */
89#define DRIVER_USE_AGP 0x1
90#define DRIVER_REQUIRE_AGP 0x2
91#define DRIVER_USE_MTRR 0x4
92#define DRIVER_PCI_DMA 0x8
93#define DRIVER_SG 0x10
94#define DRIVER_HAVE_DMA 0x20
95#define DRIVER_HAVE_IRQ 0x40
96#define DRIVER_IRQ_SHARED 0x80
97#define DRIVER_IRQ_VBL 0x100
98#define DRIVER_DMA_QUEUE 0x200
Dave Airlieb84397d62005-07-10 14:46:12 +100099#define DRIVER_FB_DMA 0x400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/***********************************************************************/
102/** \name Begin the DRM... */
103/*@{*/
104
105#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
106 also include looping detection. */
107
108#define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */
109#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
110#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
111#define DRM_LOOPING_LIMIT 5000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
113#define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
114
115#define DRM_FLAG_DEBUG 0x01
116
117#define DRM_MEM_DMA 0
118#define DRM_MEM_SAREA 1
119#define DRM_MEM_DRIVER 2
120#define DRM_MEM_MAGIC 3
121#define DRM_MEM_IOCTLS 4
122#define DRM_MEM_MAPS 5
123#define DRM_MEM_VMAS 6
124#define DRM_MEM_BUFS 7
125#define DRM_MEM_SEGS 8
126#define DRM_MEM_PAGES 9
127#define DRM_MEM_FILES 10
128#define DRM_MEM_QUEUES 11
129#define DRM_MEM_CMDS 12
130#define DRM_MEM_MAPPINGS 13
131#define DRM_MEM_BUFLISTS 14
132#define DRM_MEM_AGPLISTS 15
133#define DRM_MEM_TOTALAGP 16
134#define DRM_MEM_BOUNDAGP 17
135#define DRM_MEM_CTXBITMAP 18
136#define DRM_MEM_STUB 19
137#define DRM_MEM_SGLISTS 20
Thomas Hellstrom3a1bd922006-08-07 21:30:28 +1000138#define DRM_MEM_CTXLIST 21
139#define DRM_MEM_MM 22
140#define DRM_MEM_HASHTAB 23
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000144/*@}*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146/***********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/** \name Macros to make printk easier */
148/*@{*/
149
150/**
151 * Error output.
152 *
153 * \param fmt printf() like format string.
154 * \param arg arguments
155 */
156#define DRM_ERROR(fmt, arg...) \
157 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
158
159/**
160 * Memory error output.
161 *
162 * \param area memory area where the error occurred.
163 * \param fmt printf() like format string.
164 * \param arg arguments
165 */
166#define DRM_MEM_ERROR(area, fmt, arg...) \
167 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
168 drm_mem_stats[area].name , ##arg)
169
170#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
171
172/**
173 * Debug output.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000174 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 * \param fmt printf() like format string.
176 * \param arg arguments
177 */
178#if DRM_DEBUG_CODE
179#define DRM_DEBUG(fmt, arg...) \
180 do { \
181 if ( drm_debug ) \
182 printk(KERN_DEBUG \
183 "[" DRM_NAME ":%s] " fmt , \
184 __FUNCTION__ , ##arg); \
185 } while (0)
186#else
187#define DRM_DEBUG(fmt, arg...) do { } while (0)
188#endif
189
190#define DRM_PROC_LIMIT (PAGE_SIZE-80)
191
192#define DRM_PROC_PRINT(fmt, arg...) \
193 len += sprintf(&buf[len], fmt , ##arg); \
194 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
195
196#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
197 len += sprintf(&buf[len], fmt , ##arg); \
198 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
199
200/*@}*/
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/***********************************************************************/
203/** \name Internal types and structures */
204/*@{*/
205
Dave Airlie99a26572005-09-25 13:25:41 +1000206#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
209#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
210#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
211
212#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
213/**
214 * Get the private SAREA mapping.
215 *
216 * \param _dev DRM device.
217 * \param _ctx context number.
218 * \param _map output mapping.
219 */
220#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
221 (_map) = (_dev)->context_sareas[_ctx]; \
222} while(0)
223
224/**
225 * Test that the hardware lock is held by the caller, returning otherwise.
226 *
227 * \param dev DRM device.
228 * \param filp file pointer of the caller.
229 */
230#define LOCK_TEST_WITH_RETURN( dev, filp ) \
231do { \
232 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
233 dev->lock.filp != filp ) { \
234 DRM_ERROR( "%s called without lock held\n", \
235 __FUNCTION__ ); \
236 return -EINVAL; \
237 } \
238} while (0)
239
240/**
241 * Copy and IOCTL return string to user space
242 */
243#define DRM_COPY( name, value ) \
244 len = strlen( value ); \
245 if ( len > name##_len ) len = name##_len; \
246 name##_len = strlen( value ); \
247 if ( len && name ) { \
248 if ( copy_to_user( name, value, len ) ) \
249 return -EFAULT; \
250 }
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/**
253 * Ioctl function type.
254 *
255 * \param inode device inode.
256 * \param filp file pointer.
257 * \param cmd command.
258 * \param arg argument.
259 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000260typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
261 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Dave Airlie9a186642005-06-23 21:29:18 +1000263typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
264 unsigned long arg);
265
Dave Airliea7a2cc32006-01-02 13:54:04 +1100266#define DRM_AUTH 0x1
267#define DRM_MASTER 0x2
268#define DRM_ROOT_ONLY 0x4
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270typedef struct drm_ioctl_desc {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000271 drm_ioctl_t *func;
Dave Airliea7a2cc32006-01-02 13:54:04 +1100272 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273} drm_ioctl_desc_t;
274
275typedef struct drm_devstate {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000276 pid_t owner; /**< X server pid holding x_lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277} drm_devstate_t;
278
279typedef struct drm_magic_entry {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000280 drm_magic_t magic;
281 struct drm_file *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 struct drm_magic_entry *next;
283} drm_magic_entry_t;
284
285typedef struct drm_magic_head {
286 struct drm_magic_entry *head;
287 struct drm_magic_entry *tail;
288} drm_magic_head_t;
289
290typedef struct drm_vma_entry {
291 struct vm_area_struct *vma;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000292 struct drm_vma_entry *next;
293 pid_t pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294} drm_vma_entry_t;
295
296/**
297 * DMA buffer.
298 */
299typedef struct drm_buf {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000300 int idx; /**< Index into master buflist */
301 int total; /**< Buffer size */
302 int order; /**< log-base-2(total) */
303 int used; /**< Amount of buffer in use (for DMA) */
304 unsigned long offset; /**< Byte offset (used internally) */
305 void *address; /**< Address of buffer */
306 unsigned long bus_address; /**< Bus address of buffer */
307 struct drm_buf *next; /**< Kernel-only: used for free list */
308 __volatile__ int waiting; /**< On kernel DMA queue */
309 __volatile__ int pending; /**< On hardware DMA queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 wait_queue_head_t dma_wait; /**< Processes waiting */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000311 struct file *filp; /**< Pointer to holding file descr */
312 int context; /**< Kernel queue for this buffer */
313 int while_locked; /**< Dispatch this buffer while locked */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 enum {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000315 DRM_LIST_NONE = 0,
316 DRM_LIST_FREE = 1,
317 DRM_LIST_WAIT = 2,
318 DRM_LIST_PEND = 3,
319 DRM_LIST_PRIO = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 DRM_LIST_RECLAIM = 5
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000321 } list; /**< Which list we're on */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000323 int dev_priv_size; /**< Size of buffer private storage */
324 void *dev_private; /**< Per-buffer private storage */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325} drm_buf_t;
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/** bufs is one longer than it has to be */
328typedef struct drm_waitlist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000329 int count; /**< Number of possible buffers */
330 drm_buf_t **bufs; /**< List of pointers to buffers */
331 drm_buf_t **rp; /**< Read pointer */
332 drm_buf_t **wp; /**< Write pointer */
333 drm_buf_t **end; /**< End pointer */
334 spinlock_t read_lock;
335 spinlock_t write_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336} drm_waitlist_t;
337
338typedef struct drm_freelist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000339 int initialized; /**< Freelist in use */
340 atomic_t count; /**< Number of free buffers */
341 drm_buf_t *next; /**< End pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000344 int low_mark; /**< Low water mark */
345 int high_mark; /**< High water mark */
346 atomic_t wfh; /**< If waiting for high mark */
347 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348} drm_freelist_t;
349
Dave Airlieddf19b92006-03-19 18:56:12 +1100350typedef struct drm_dma_handle {
351 dma_addr_t busaddr;
352 void *vaddr;
353 size_t size;
354} drm_dma_handle_t;
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/**
357 * Buffer entry. There is one of this for each buffer size order.
358 */
359typedef struct drm_buf_entry {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000360 int buf_size; /**< size */
361 int buf_count; /**< number of buffers */
362 drm_buf_t *buflist; /**< buffer list */
363 int seg_count;
364 int page_order;
Dave Airlieddf19b92006-03-19 18:56:12 +1100365 drm_dma_handle_t **seglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000367 drm_freelist_t freelist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368} drm_buf_entry_t;
369
370/** File private data */
371typedef struct drm_file {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000372 int authenticated;
Dave Airliea7a2cc32006-01-02 13:54:04 +1100373 int master;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000374 int minor;
375 pid_t pid;
376 uid_t uid;
377 drm_magic_t magic;
378 unsigned long ioctl_count;
379 struct drm_file *next;
380 struct drm_file *prev;
381 struct drm_head *head;
382 int remove_auth_on_close;
383 unsigned long lock_count;
384 void *driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385} drm_file_t;
386
387/** Wait queue */
388typedef struct drm_queue {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000389 atomic_t use_count; /**< Outstanding uses (+1) */
390 atomic_t finalization; /**< Finalization in progress */
391 atomic_t block_count; /**< Count of processes waiting */
392 atomic_t block_read; /**< Queue blocked for reads */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000394 atomic_t block_write; /**< Queue blocked for writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
396#if 1
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000397 atomic_t total_queued; /**< Total queued statistic */
398 atomic_t total_flushed; /**< Total flushes statistic */
399 atomic_t total_locks; /**< Total locks statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#endif
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000401 drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
402 drm_waitlist_t waitlist; /**< Pending buffers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
404} drm_queue_t;
405
406/**
407 * Lock data.
408 */
409typedef struct drm_lock_data {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000410 drm_hw_lock_t *hw_lock; /**< Hardware lock */
411 struct file *filp; /**< File descr of lock holder (0=kernel) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000413 unsigned long lock_time; /**< Time of last lock in jiffies */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414} drm_lock_data_t;
415
416/**
417 * DMA data.
418 */
419typedef struct drm_device_dma {
420
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000421 drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
422 int buf_count; /**< total number of buffers */
423 drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
424 int seg_count;
425 int page_count; /**< number of pages */
426 unsigned long *pagelist; /**< page list */
427 unsigned long byte_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 enum {
429 _DRM_DMA_USE_AGP = 0x01,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000430 _DRM_DMA_USE_SG = 0x02,
431 _DRM_DMA_USE_FB = 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 } flags;
433
434} drm_device_dma_t;
435
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000436/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 * AGP memory entry. Stored as a doubly linked list.
438 */
439typedef struct drm_agp_mem {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000440 unsigned long handle; /**< handle */
441 DRM_AGP_MEM *memory;
442 unsigned long bound; /**< address */
443 int pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 struct drm_agp_mem *prev; /**< previous entry */
445 struct drm_agp_mem *next; /**< next entry */
446} drm_agp_mem_t;
447
448/**
449 * AGP data.
450 *
451 * \sa drm_agp_init() and drm_device::agp.
452 */
453typedef struct drm_agp_head {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000454 DRM_AGP_KERN agp_info; /**< AGP device information */
455 drm_agp_mem_t *memory; /**< memory entries */
456 unsigned long mode; /**< AGP mode */
457 struct agp_bridge_data *bridge;
458 int enabled; /**< whether the AGP bus as been enabled */
459 int acquired; /**< whether the AGP device has been acquired */
460 unsigned long base;
461 int agp_mtrr;
462 int cant_use_aperture;
463 unsigned long page_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464} drm_agp_head_t;
465
466/**
467 * Scatter-gather memory.
468 */
469typedef struct drm_sg_mem {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000470 unsigned long handle;
471 void *virtual;
472 int pages;
473 struct page **pagelist;
474 dma_addr_t *busaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475} drm_sg_mem_t;
476
477typedef struct drm_sigdata {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000478 int context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 drm_hw_lock_t *lock;
480} drm_sigdata_t;
481
482/**
483 * Mappings list
484 */
485typedef struct drm_map_list {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000486 struct list_head head; /**< list head */
487 drm_map_t *map; /**< mapping */
Dave Airlied1f2b552005-08-05 22:11:22 +1000488 unsigned int user_token;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489} drm_map_list_t;
490
491typedef drm_map_t drm_local_map_t;
492
493/**
494 * Context handle list
495 */
496typedef struct drm_ctx_list {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000497 struct list_head head; /**< list head */
498 drm_context_t handle; /**< context handle */
499 drm_file_t *tag; /**< associated fd private data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500} drm_ctx_list_t;
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502typedef struct drm_vbl_sig {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000503 struct list_head head;
504 unsigned int sequence;
505 struct siginfo info;
506 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507} drm_vbl_sig_t;
508
Dave Airlieea98a922005-09-11 20:28:11 +1000509/* location of GART table */
510#define DRM_ATI_GART_MAIN 1
511#define DRM_ATI_GART_FB 2
512
513typedef struct ati_pcigart_info {
514 int gart_table_location;
515 int is_pcie;
Dave Airlief26c4732006-01-02 17:18:39 +1100516 void *addr;
Dave Airlieea98a922005-09-11 20:28:11 +1000517 dma_addr_t bus_addr;
Dave Airlief26c4732006-01-02 17:18:39 +1100518 drm_local_map_t mapping;
Dave Airlieea98a922005-09-11 20:28:11 +1000519} drm_ati_pcigart_info;
520
Thomas Hellstrom3a1bd922006-08-07 21:30:28 +1000521/*
522 * Generic memory manager structs
523 */
524typedef struct drm_mm_node {
525 struct list_head fl_entry;
526 struct list_head ml_entry;
527 int free;
528 unsigned long start;
529 unsigned long size;
530 void *private;
531} drm_mm_node_t;
532
533typedef struct drm_mm {
534 drm_mm_node_t root_node;
535} drm_mm_t;
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537/**
538 * DRM driver structure. This structure represent the common code for
539 * a family of cards. There will one drm_device for each card present
540 * in this family
541 */
542struct drm_device;
543
544struct drm_driver {
Dave Airlie22eae942005-11-10 22:16:34 +1100545 int (*load) (struct drm_device *, unsigned long flags);
546 int (*firstopen) (struct drm_device *);
547 int (*open) (struct drm_device *, drm_file_t *);
548 void (*preclose) (struct drm_device *, struct file * filp);
549 void (*postclose) (struct drm_device *, drm_file_t *);
550 void (*lastclose) (struct drm_device *);
551 int (*unload) (struct drm_device *);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000552 int (*dma_ioctl) (DRM_IOCTL_ARGS);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000553 void (*dma_ready) (struct drm_device *);
554 int (*dma_quiescent) (struct drm_device *);
555 int (*context_ctor) (struct drm_device * dev, int context);
556 int (*context_dtor) (struct drm_device * dev, int context);
557 int (*kernel_context_switch) (struct drm_device * dev, int old,
558 int new);
559 void (*kernel_context_switch_unlock) (struct drm_device * dev,
Dave Airlied985c102006-01-02 21:32:48 +1100560 drm_lock_t *lock);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000561 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
Dave Airlie732052e2005-11-11 22:07:35 +1100562 int (*dri_library_name) (struct drm_device *dev, char *buf);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000563
Dave Airliecda17382005-07-10 17:31:26 +1000564 /**
565 * Called by \c drm_device_is_agp. Typically used to determine if a
566 * card is really attached to AGP or not.
567 *
568 * \param dev DRM device handle
569 *
570 * \returns
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).
574 */
575 int (*device_is_agp) (struct drm_device * dev);
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /* these have to be filled in */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000578
Dave Airlie22eae942005-11-10 22:16:34 +1100579 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000580 void (*irq_preinstall) (struct drm_device * dev);
581 void (*irq_postinstall) (struct drm_device * dev);
582 void (*irq_uninstall) (struct drm_device * dev);
583 void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
Dave Airlied985c102006-01-02 21:32:48 +1100584 void (*reclaim_buffers_locked) (struct drm_device *dev,
Dave Airlie22eae942005-11-10 22:16:34 +1100585 struct file *filp);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000586 unsigned long (*get_map_ofs) (drm_map_t * map);
587 unsigned long (*get_reg_ofs) (struct drm_device * dev);
588 void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
Dave Airlie22eae942005-11-10 22:16:34 +1100589
590 int major;
591 int minor;
592 int patchlevel;
593 char *name;
594 char *desc;
595 char *date;
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 u32 driver_features;
598 int dev_priv_size;
599 drm_ioctl_desc_t *ioctls;
600 int num_ioctls;
601 struct file_operations fops;
602 struct pci_driver pci_driver;
603};
604
605/**
606 * DRM head structure. This structure represent a video head on a card
607 * that may contain multiple heads. Embed one per head of these in the
608 * private drm_device structure.
609 */
610typedef struct drm_head {
611 int minor; /**< Minor device number */
612 struct drm_device *dev;
613 struct proc_dir_entry *dev_root; /**< proc directory entry */
614 dev_t device; /**< Device number for mknod */
615 struct class_device *dev_class;
616} drm_head_t;
617
618/**
619 * DRM device structure. This structure represent a complete card that
620 * may contain multiple heads.
621 */
622typedef struct drm_device {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000623 char *unique; /**< Unique identifier: e.g., busid */
624 int unique_len; /**< Length of unique field */
625 char *devname; /**< For /proc/interrupts */
626 int if_version; /**< Highest interface version set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000628 int blocked; /**< Blocked due to VC switch? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 /** \name Locks */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000631 /*@{ */
632 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100633 struct mutex struct_mutex; /**< For others */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000634 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 /** \name Usage Counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000637 /*@{ */
638 int open_count; /**< Outstanding files open */
639 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
640 atomic_t vma_count; /**< Outstanding vma areas open */
641 int buf_use; /**< Buffers in use -- cannot alloc */
642 atomic_t buf_alloc; /**< Buffer allocation in progress */
643 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 /** \name Performance counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000646 /*@{ */
647 unsigned long counters;
648 drm_stat_type_t types[15];
649 atomic_t counts[15];
650 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 /** \name Authentication */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000653 /*@{ */
654 drm_file_t *file_first; /**< file list head */
655 drm_file_t *file_last; /**< file list tail */
656 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */
657 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /** \name Memory management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000660 /*@{ */
661 drm_map_list_t *maplist; /**< Linked list of regions */
662 int map_count; /**< Number of mappable regions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 /** \name Context handle management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000665 /*@{ */
666 drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
667 int ctx_count; /**< Number of context handles */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100668 struct mutex ctxlist_mutex; /**< For ctxlist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000670 drm_map_t **context_sareas; /**< per-context SAREA's */
671 int max_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000673 drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
674 drm_lock_data_t lock; /**< Information on hardware lock */
675 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 /** \name DMA queues (contexts) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000678 /*@{ */
679 int queue_count; /**< Number of active DMA queues */
680 int queue_reserved; /**< Number of reserved DMA queues */
681 int queue_slots; /**< Actual length of queuelist */
682 drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
683 drm_device_dma_t *dma; /**< Optional pointer for DMA support */
684 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 /** \name Context support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000687 /*@{ */
688 int irq; /**< Interrupt used by board */
689 int irq_enabled; /**< True if irq handler is enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 __volatile__ long context_flag; /**< Context swapping flag */
691 __volatile__ long interrupt_flag; /**< Interruption handler flag */
692 __volatile__ long dma_flag; /**< DMA dispatch flag */
693 struct timer_list timer; /**< Timer for delaying ctx switch */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000694 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
695 int last_checked; /**< Last context checked for DMA */
696 int last_context; /**< Last current context */
697 unsigned long last_switch; /**< jiffies at last context switch */
698 /*@} */
699
700 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /** \name VBLANK IRQ support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000702 /*@{ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000704 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
705 atomic_t vbl_received;
706 spinlock_t vbl_lock;
707 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
708 unsigned int vbl_pending;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000710 /*@} */
711 cycles_t ctx_start;
712 cycles_t lck_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
715 wait_queue_head_t buf_readers; /**< Processes waiting to read */
716 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
717
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000718 drm_agp_head_t *agp; /**< AGP data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000720 struct pci_dev *pdev; /**< PCI device structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#ifdef __alpha__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 struct pci_controller *hose;
723#endif
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000724 drm_sg_mem_t *sg; /**< Scatter gather memory */
725 unsigned long *ctx_bitmap; /**< context bitmap */
726 void *dev_private; /**< device private data */
727 drm_sigdata_t sigdata; /**< For block_all_signals */
728 sigset_t sigmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000730 struct drm_driver *driver;
731 drm_local_map_t *agp_buffer_map;
Dave Airlied1f2b552005-08-05 22:11:22 +1000732 unsigned int agp_buffer_token;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 drm_head_t primary; /**< primary screen head */
734} drm_device_t;
735
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000736static __inline__ int drm_core_check_feature(struct drm_device *dev,
737 int feature)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
739 return ((dev->driver->driver_features & feature) ? 1 : 0);
740}
741
Dave Airlie33229602006-08-07 20:23:42 +1000742#ifdef __alpha__
743#define drm_get_pci_domain(dev) dev->hose->bus->number
744#else
745#define drm_get_pci_domain(dev) pci_domain_nr(dev->pdev->bus)
746#endif
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#if __OS_HAS_AGP
749static inline int drm_core_has_AGP(struct drm_device *dev)
750{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000751 return drm_core_check_feature(dev, DRIVER_USE_AGP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752}
753#else
754#define drm_core_has_AGP(dev) (0)
755#endif
756
757#if __OS_HAS_MTRR
758static inline int drm_core_has_MTRR(struct drm_device *dev)
759{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000760 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
Dave Airlie269dc512006-01-02 16:23:01 +1100762
763#define DRM_MTRR_WC MTRR_TYPE_WRCOMB
764
765static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
766 unsigned int flags)
767{
768 return mtrr_add(offset, size, flags, 1);
769}
770
771static inline int drm_mtrr_del(int handle, unsigned long offset,
772 unsigned long size, unsigned int flags)
773{
774 return mtrr_del(handle, offset, size);
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777#else
778#define drm_core_has_MTRR(dev) (0)
Dave Airlie9c7d4622006-01-12 20:44:30 +1100779
780#define DRM_MTRR_WC 0
781
782static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
783 unsigned int flags)
784{
785 return 0;
786}
787
788static inline int drm_mtrr_del(int handle, unsigned long offset,
789 unsigned long size, unsigned int flags)
790{
791 return 0;
792}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#endif
794
795/******************************************************************/
796/** \name Internal function definitions */
797/*@{*/
798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 /* Driver support (drm_drv.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000800extern int drm_init(struct drm_driver *driver);
801extern void drm_exit(struct drm_driver *driver);
802extern int drm_ioctl(struct inode *inode, struct file *filp,
803 unsigned int cmd, unsigned long arg);
804extern long drm_compat_ioctl(struct file *filp,
805 unsigned int cmd, unsigned long arg);
Dave Airlie22eae942005-11-10 22:16:34 +1100806extern int drm_lastclose(drm_device_t *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 /* Device support (drm_fops.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000809extern int drm_open(struct inode *inode, struct file *filp);
810extern int drm_stub_open(struct inode *inode, struct file *filp);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000811extern int drm_fasync(int fd, struct file *filp, int on);
812extern int drm_release(struct inode *inode, struct file *filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 /* Mapping support (drm_vm.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000815extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
816extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 /* Memory management support (drm_memory.h) */
819#include "drm_memory.h"
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000820extern void drm_mem_init(void);
821extern int drm_mem_info(char *buf, char **start, off_t offset,
822 int request, int *eof, void *data);
823extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000824extern void *drm_ioremap(unsigned long offset, unsigned long size,
825 drm_device_t * dev);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000826extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000828extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
829extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
830extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
831extern int drm_unbind_agp(DRM_AGP_MEM * handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 /* Misc. IOCTL support (drm_ioctl.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000834extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
835 unsigned int cmd, unsigned long arg);
836extern int drm_getunique(struct inode *inode, struct file *filp,
837 unsigned int cmd, unsigned long arg);
838extern int drm_setunique(struct inode *inode, struct file *filp,
839 unsigned int cmd, unsigned long arg);
840extern int drm_getmap(struct inode *inode, struct file *filp,
841 unsigned int cmd, unsigned long arg);
842extern int drm_getclient(struct inode *inode, struct file *filp,
843 unsigned int cmd, unsigned long arg);
844extern int drm_getstats(struct inode *inode, struct file *filp,
845 unsigned int cmd, unsigned long arg);
846extern int drm_setversion(struct inode *inode, struct file *filp,
847 unsigned int cmd, unsigned long arg);
Dave Airlied985c102006-01-02 21:32:48 +1100848extern int drm_noop(struct inode *inode, struct file *filp,
849 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 /* Context IOCTL support (drm_context.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000852extern int drm_resctx(struct inode *inode, struct file *filp,
853 unsigned int cmd, unsigned long arg);
854extern int drm_addctx(struct inode *inode, struct file *filp,
855 unsigned int cmd, unsigned long arg);
856extern int drm_modctx(struct inode *inode, struct file *filp,
857 unsigned int cmd, unsigned long arg);
858extern int drm_getctx(struct inode *inode, struct file *filp,
859 unsigned int cmd, unsigned long arg);
860extern int drm_switchctx(struct inode *inode, struct file *filp,
861 unsigned int cmd, unsigned long arg);
862extern int drm_newctx(struct inode *inode, struct file *filp,
863 unsigned int cmd, unsigned long arg);
864extern int drm_rmctx(struct inode *inode, struct file *filp,
865 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000867extern int drm_ctxbitmap_init(drm_device_t * dev);
868extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
869extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000871extern int drm_setsareactx(struct inode *inode, struct file *filp,
872 unsigned int cmd, unsigned long arg);
873extern int drm_getsareactx(struct inode *inode, struct file *filp,
874 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 /* Drawable IOCTL support (drm_drawable.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000877extern int drm_adddraw(struct inode *inode, struct file *filp,
878 unsigned int cmd, unsigned long arg);
879extern int drm_rmdraw(struct inode *inode, struct file *filp,
880 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 /* Authentication IOCTL support (drm_auth.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000883extern int drm_getmagic(struct inode *inode, struct file *filp,
884 unsigned int cmd, unsigned long arg);
885extern int drm_authmagic(struct inode *inode, struct file *filp,
886 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 /* Locking IOCTL support (drm_lock.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000889extern int drm_lock(struct inode *inode, struct file *filp,
890 unsigned int cmd, unsigned long arg);
891extern int drm_unlock(struct inode *inode, struct file *filp,
892 unsigned int cmd, unsigned long arg);
893extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
894extern int drm_lock_free(drm_device_t * dev,
895 __volatile__ unsigned int *lock, unsigned int context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 /* Buffer management support (drm_bufs.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000898extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
899extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
900extern int drm_addmap(drm_device_t * dev, unsigned int offset,
Dave Airlie7ab98402005-07-10 16:56:52 +1000901 unsigned int size, drm_map_type_t type,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000902 drm_map_flags_t flags, drm_local_map_t ** map_ptr);
Dave Airlie7ab98402005-07-10 16:56:52 +1000903extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
904 unsigned int cmd, unsigned long arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000905extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
906extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
Dave Airlie7ab98402005-07-10 16:56:52 +1000907extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
908 unsigned int cmd, unsigned long arg);
909
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000910extern int drm_order(unsigned long size);
911extern int drm_addbufs(struct inode *inode, struct file *filp,
912 unsigned int cmd, unsigned long arg);
913extern int drm_infobufs(struct inode *inode, struct file *filp,
914 unsigned int cmd, unsigned long arg);
915extern int drm_markbufs(struct inode *inode, struct file *filp,
916 unsigned int cmd, unsigned long arg);
917extern int drm_freebufs(struct inode *inode, struct file *filp,
918 unsigned int cmd, unsigned long arg);
919extern int drm_mapbufs(struct inode *inode, struct file *filp,
920 unsigned int cmd, unsigned long arg);
921extern unsigned long drm_get_resource_start(drm_device_t * dev,
Dave Airlie836cf042005-07-10 19:27:04 +1000922 unsigned int resource);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000923extern unsigned long drm_get_resource_len(drm_device_t * dev,
Dave Airlie836cf042005-07-10 19:27:04 +1000924 unsigned int resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* DMA support (drm_dma.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000927extern int drm_dma_setup(drm_device_t * dev);
928extern void drm_dma_takedown(drm_device_t * dev);
929extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
930extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 /* IRQ support (drm_irq.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000933extern int drm_control(struct inode *inode, struct file *filp,
934 unsigned int cmd, unsigned long arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000935extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
Dave Airlied985c102006-01-02 21:32:48 +1100936extern int drm_irq_uninstall(drm_device_t * dev);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000937extern void drm_driver_irq_preinstall(drm_device_t * dev);
938extern void drm_driver_irq_postinstall(drm_device_t * dev);
939extern void drm_driver_irq_uninstall(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000941extern int drm_wait_vblank(struct inode *inode, struct file *filp,
942 unsigned int cmd, unsigned long arg);
943extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
944extern void drm_vbl_send_signals(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 /* AGP/GART support (drm_agpsupport.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000947extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
Dave Airlie7ab98402005-07-10 16:56:52 +1000948extern int drm_agp_acquire(drm_device_t * dev);
949extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000950 unsigned int cmd, unsigned long arg);
951extern int drm_agp_release(drm_device_t * dev);
Dave Airlie7ab98402005-07-10 16:56:52 +1000952extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000953 unsigned int cmd, unsigned long arg);
954extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
Dave Airlie7ab98402005-07-10 16:56:52 +1000955extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000956 unsigned int cmd, unsigned long arg);
957extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
Dave Airlie7ab98402005-07-10 16:56:52 +1000958extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000959 unsigned int cmd, unsigned long arg);
Dave Airlieefa58392005-11-11 22:33:39 +1100960extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
961extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000962 unsigned int cmd, unsigned long arg);
Dave Airlieefa58392005-11-11 22:33:39 +1100963extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
964extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
Dave Airlie7ab98402005-07-10 16:56:52 +1000965 unsigned int cmd, unsigned long arg);
Dave Airlieefa58392005-11-11 22:33:39 +1100966extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
967extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000968 unsigned int cmd, unsigned long arg);
Dave Airlieefa58392005-11-11 22:33:39 +1100969extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
970extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000971 unsigned int cmd, unsigned long arg);
972extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
973 size_t pages, u32 type);
974extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
975extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
976extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 /* Stub support (drm_stub.h) */
979extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000980 struct drm_driver *driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981extern int drm_put_dev(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982extern int drm_put_head(drm_head_t * head);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000983extern unsigned int drm_debug;
984extern unsigned int drm_cards_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985extern drm_head_t **drm_heads;
Greg Kroah-Hartman0650fd52006-01-20 14:08:59 -0800986extern struct class *drm_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987extern struct proc_dir_entry *drm_proc_root;
988
989 /* Proc support (drm_proc.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000990extern int drm_proc_init(drm_device_t * dev,
991 int minor,
992 struct proc_dir_entry *root,
993 struct proc_dir_entry **dev_root);
994extern int drm_proc_cleanup(int minor,
995 struct proc_dir_entry *root,
996 struct proc_dir_entry *dev_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 /* Scatter Gather Support (drm_scatter.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000999extern void drm_sg_cleanup(drm_sg_mem_t * entry);
1000extern int drm_sg_alloc(struct inode *inode, struct file *filp,
1001 unsigned int cmd, unsigned long arg);
1002extern int drm_sg_free(struct inode *inode, struct file *filp,
1003 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001005 /* ATI PCIGART support (ati_pcigart.h) */
1006extern int drm_ati_pcigart_init(drm_device_t * dev,
1007 drm_ati_pcigart_info * gart_info);
1008extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
1009 drm_ati_pcigart_info * gart_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001011extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
Dave Airlie9c8da5e2005-07-10 15:38:56 +10001012 size_t align, dma_addr_t maxaddr);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001013extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
1014extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /* sysfs support (drm_sysfs.c) */
Greg Kroah-Hartman0650fd52006-01-20 14:08:59 -08001017extern struct class *drm_sysfs_create(struct module *owner, char *name);
1018extern void drm_sysfs_destroy(struct class *cs);
1019extern struct class_device *drm_sysfs_device_add(struct class *cs,
Dave Airlie732052e2005-11-11 22:07:35 +11001020 drm_head_t *head);
1021extern void drm_sysfs_device_remove(struct class_device *class_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Thomas Hellstrom3a1bd922006-08-07 21:30:28 +10001023/*
1024 * Basic memory manager support (drm_mm.c)
1025 */
1026extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
1027 unsigned long size,
1028 unsigned alignment);
1029extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur);
1030extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
1031 unsigned alignment, int best_match);
1032extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
1033extern void drm_mm_takedown(drm_mm_t *mm);
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035/* Inline replacements for DRM_IOREMAP macros */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001036static __inline__ void drm_core_ioremap(struct drm_map *map,
1037 struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001039 map->handle = drm_ioremap(map->offset, map->size, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
Adrian Bunk031de962006-04-10 23:18:27 -07001042#if 0
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001043static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
1044 struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045{
1046 map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
1047}
Adrian Bunk031de962006-04-10 23:18:27 -07001048#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001050static __inline__ void drm_core_ioremapfree(struct drm_map *map,
1051 struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001053 if (map->handle && map->size)
1054 drm_ioremapfree(map->handle, map->size, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001057static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1058 unsigned int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Dave Airlied1f2b552005-08-05 22:11:22 +10001060 drm_map_list_t *_entry;
1061 list_for_each_entry(_entry, &dev->maplist->head, head)
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001062 if (_entry->user_token == token)
1063 return _entry->map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 return NULL;
1065}
1066
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001067static __inline__ int drm_device_is_agp(drm_device_t * dev)
Dave Airliecda17382005-07-10 17:31:26 +10001068{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001069 if (dev->driver->device_is_agp != NULL) {
1070 int err = (*dev->driver->device_is_agp) (dev);
1071
Dave Airliecda17382005-07-10 17:31:26 +10001072 if (err != 2) {
1073 return err;
1074 }
1075 }
1076
1077 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1078}
1079
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001080static __inline__ int drm_device_is_pcie(drm_device_t * dev)
Dave Airlieea98a922005-09-11 20:28:11 +10001081{
1082 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1083}
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085static __inline__ void drm_core_dropmap(struct drm_map *map)
1086{
1087}
1088
1089#ifndef DEBUG_MEMORY
1090/** Wrapper around kmalloc() */
1091static __inline__ void *drm_alloc(size_t size, int area)
1092{
1093 return kmalloc(size, GFP_KERNEL);
1094}
1095
1096/** Wrapper around kfree() */
1097static __inline__ void drm_free(void *pt, size_t size, int area)
1098{
1099 kfree(pt);
1100}
Dave Airlieb9523242005-07-07 20:33:26 +10001101
1102/** Wrapper around kcalloc() */
1103static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
1104{
1105 return kcalloc(nmemb, size, GFP_KERNEL);
1106}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107#else
1108extern void *drm_alloc(size_t size, int area);
1109extern void drm_free(void *pt, size_t size, int area);
Dave Airlieb9523242005-07-07 20:33:26 +10001110extern void *drm_calloc(size_t nmemb, size_t size, int area);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111#endif
1112
1113/*@}*/
1114
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001115extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1117
Adrian Bunk982245f2005-07-17 04:22:20 +02001118#ifndef pci_pretty_name
1119#define pci_pretty_name(dev) ""
1120#endif
1121
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001122#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123#endif