Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1123 serge 1
/**
2
 * \file drmP.h
3
 * Private header for Direct Rendering Manager
4
 *
5
 * \author Rickard E. (Rik) Faith 
6
 * \author Gareth Hughes 
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
#include 
38
#include 
39
 
40
#include 
41
#include 
42
 
43
//#include 
44
 
45
struct drm_file;
46
struct drm_device;
47
 
48
//#include "drm_os_linux.h"
49
//#include "drm_hashtab.h"
50
//#include "drm_mm.h"
51
 
52
#define DRM_UT_CORE 		0x01
53
#define DRM_UT_DRIVER		0x02
54
#define DRM_UT_KMS          0x04
55
#define DRM_UT_MODE         0x08
56
 
57
#define KHZ2PICOS(a) (1000000000UL/(a))
58
 
59
extern void drm_ut_debug_printk(unsigned int request_level,
60
				const char *prefix,
61
				const char *function_name,
62
				const char *format, ...);
63
 
64
#define DRM_DEBUG_MODE(prefix, fmt, args...)    \
65
    do {                                        \
66
        dbgprintf("drm debug: %s" fmt,          \
67
                     __func__, ##args);         \
68
    } while (0)
69
 
70
#if 0
71
 
72
/***********************************************************************/
73
/** \name DRM template customization defaults */
74
/*@{*/
75
 
76
/* driver capabilities and requirements mask */
77
#define DRIVER_USE_AGP     0x1
78
#define DRIVER_REQUIRE_AGP 0x2
79
#define DRIVER_USE_MTRR    0x4
80
#define DRIVER_PCI_DMA     0x8
81
#define DRIVER_SG          0x10
82
#define DRIVER_HAVE_DMA    0x20
83
#define DRIVER_HAVE_IRQ    0x40
84
#define DRIVER_IRQ_SHARED  0x80
85
#define DRIVER_IRQ_VBL     0x100
86
#define DRIVER_DMA_QUEUE   0x200
87
#define DRIVER_FB_DMA      0x400
88
#define DRIVER_IRQ_VBL2    0x800
89
#define DRIVER_GEM         0x1000
90
#define DRIVER_MODESET     0x2000
91
 
92
/***********************************************************************/
93
/** \name Begin the DRM... */
94
/*@{*/
95
 
96
#define DRM_DEBUG_CODE 2	  /**< Include debugging code if > 1, then
97
				     also include looping detection. */
98
 
99
#define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
100
#define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
101
#define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
102
#define DRM_LOOPING_LIMIT     5000000
103
#define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
104
#define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
105
 
106
#define DRM_FLAG_DEBUG	  0x01
107
 
108
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
109
#define DRM_MAP_HASH_OFFSET 0x10000000
110
 
111
/*@}*/
112
 
113
/***********************************************************************/
114
/** \name Macros to make printk easier */
115
/*@{*/
116
 
117
/**
118
 * Error output.
119
 *
120
 * \param fmt printf() like format string.
121
 * \param arg arguments
122
 */
123
#define DRM_ERROR(fmt, arg...) \
124
	printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
125
 
126
/**
127
 * Memory error output.
128
 *
129
 * \param area memory area where the error occurred.
130
 * \param fmt printf() like format string.
131
 * \param arg arguments
132
 */
133
#define DRM_MEM_ERROR(area, fmt, arg...) \
134
	printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
135
	       drm_mem_stats[area].name , ##arg)
136
 
137
#define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
138
 
139
/**
140
 * Debug output.
141
 *
142
 * \param fmt printf() like format string.
143
 * \param arg arguments
144
 */
145
#if DRM_DEBUG_CODE
146
#define DRM_DEBUG(fmt, args...)						\
147
	do {								\
148
		drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME, 		\
149
					__func__, fmt, ##args);		\
150
	} while (0)
151
 
152
#define DRM_DEBUG_DRIVER(prefix, fmt, args...)				\
153
	do {								\
154
		drm_ut_debug_printk(DRM_UT_DRIVER, prefix,		\
155
					__func__, fmt, ##args);		\
156
	} while (0)
157
#define DRM_DEBUG_KMS(prefix, fmt, args...)				\
158
	do {								\
159
		drm_ut_debug_printk(DRM_UT_KMS, prefix, 		\
160
					 __func__, fmt, ##args);	\
161
	} while (0)
162
#define DRM_DEBUG_MODE(prefix, fmt, args...)				\
163
	do {								\
164
		drm_ut_debug_printk(DRM_UT_MODE, prefix, 		\
165
					 __func__, fmt, ##args);	\
166
	} while (0)
167
#define DRM_LOG(fmt, args...)						\
168
	do {								\
169
		drm_ut_debug_printk(DRM_UT_CORE, NULL,			\
170
					NULL, fmt, ##args);		\
171
	} while (0)
172
#define DRM_LOG_KMS(fmt, args...)					\
173
	do {								\
174
		drm_ut_debug_printk(DRM_UT_KMS, NULL,			\
175
					NULL, fmt, ##args);		\
176
	} while (0)
177
#define DRM_LOG_MODE(fmt, args...)					\
178
	do {								\
179
		drm_ut_debug_printk(DRM_UT_MODE, NULL,			\
180
					NULL, fmt, ##args);		\
181
	} while (0)
182
#define DRM_LOG_DRIVER(fmt, args...)					\
183
	do {								\
184
		drm_ut_debug_printk(DRM_UT_DRIVER, NULL,		\
185
					NULL, fmt, ##args);		\
186
	} while (0)
187
#else
188
#define DRM_DEBUG_DRIVER(prefix, fmt, args...) do { } while (0)
189
#define DRM_DEBUG_KMS(prefix, fmt, args...)	do { } while (0)
190
#define DRM_DEBUG_MODE(prefix, fmt, args...)	do { } while (0)
191
#define DRM_DEBUG(fmt, arg...)		 do { } while (0)
192
#define DRM_LOG(fmt, arg...)		do { } while (0)
193
#define DRM_LOG_KMS(fmt, args...) do { } while (0)
194
#define DRM_LOG_MODE(fmt, arg...) do { } while (0)
195
#define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
196
 
197
#endif
198
 
199
#define DRM_PROC_LIMIT (PAGE_SIZE-80)
200
 
201
#define DRM_PROC_PRINT(fmt, arg...)					\
202
   len += sprintf(&buf[len], fmt , ##arg);				\
203
   if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
204
 
205
#define DRM_PROC_PRINT_RET(ret, fmt, arg...)				\
206
   len += sprintf(&buf[len], fmt , ##arg);				\
207
   if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
208
 
209
/*@}*/
210
 
211
/***********************************************************************/
212
/** \name Internal types and structures */
213
/*@{*/
214
 
215
#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
216
 
217
#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
218
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
219
#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
220
 
221
#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
222
/**
223
 * Get the private SAREA mapping.
224
 *
225
 * \param _dev DRM device.
226
 * \param _ctx context number.
227
 * \param _map output mapping.
228
 */
229
#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {	\
230
	(_map) = (_dev)->context_sareas[_ctx];		\
231
} while(0)
232
 
233
/**
234
 * Test that the hardware lock is held by the caller, returning otherwise.
235
 *
236
 * \param dev DRM device.
237
 * \param filp file pointer of the caller.
238
 */
239
#define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
240
do {										\
241
	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
242
	    _file_priv->master->lock.file_priv != _file_priv)	{		\
243
		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
244
			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
245
			   _file_priv->master->lock.file_priv, _file_priv);	\
246
		return -EINVAL;							\
247
	}									\
248
} while (0)
249
 
250
/**
251
 * Copy and IOCTL return string to user space
252
 */
253
#define DRM_COPY( name, value )						\
254
	len = strlen( value );						\
255
	if ( len > name##_len ) len = name##_len;			\
256
	name##_len = strlen( value );					\
257
	if ( len && name ) {						\
258
		if ( copy_to_user( name, value, len ) )			\
259
			return -EFAULT;					\
260
	}
261
 
262
/**
263
 * Ioctl function type.
264
 *
265
 * \param inode device inode.
266
 * \param file_priv DRM file private pointer.
267
 * \param cmd command.
268
 * \param arg argument.
269
 */
270
typedef int drm_ioctl_t(struct drm_device *dev, void *data,
271
			struct drm_file *file_priv);
272
 
273
typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
274
			       unsigned long arg);
275
 
276
#define DRM_AUTH	0x1
277
#define	DRM_MASTER	0x2
278
#define DRM_ROOT_ONLY	0x4
279
#define DRM_CONTROL_ALLOW 0x8
280
 
281
struct drm_ioctl_desc {
282
	unsigned int cmd;
283
	int flags;
284
	drm_ioctl_t *func;
285
};
286
 
287
/**
288
 * Creates a driver or general drm_ioctl_desc array entry for the given
289
 * ioctl, for use by drm_ioctl().
290
 */
291
#define DRM_IOCTL_DEF(ioctl, _func, _flags) \
292
	[DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags}
293
 
294
struct drm_magic_entry {
295
	struct list_head head;
296
	struct drm_hash_item hash_item;
297
	struct drm_file *priv;
298
};
299
 
300
struct drm_vma_entry {
301
	struct list_head head;
302
	struct vm_area_struct *vma;
303
	pid_t pid;
304
};
305
 
306
/**
307
 * DMA buffer.
308
 */
309
struct drm_buf {
310
	int idx;		       /**< Index into master buflist */
311
	int total;		       /**< Buffer size */
312
	int order;		       /**< log-base-2(total) */
313
	int used;		       /**< Amount of buffer in use (for DMA) */
314
	unsigned long offset;	       /**< Byte offset (used internally) */
315
	void *address;		       /**< Address of buffer */
316
	unsigned long bus_address;     /**< Bus address of buffer */
317
	struct drm_buf *next;	       /**< Kernel-only: used for free list */
318
	__volatile__ int waiting;      /**< On kernel DMA queue */
319
	__volatile__ int pending;      /**< On hardware DMA queue */
320
	wait_queue_head_t dma_wait;    /**< Processes waiting */
321
	struct drm_file *file_priv;    /**< Private of holding file descr */
322
	int context;		       /**< Kernel queue for this buffer */
323
	int while_locked;	       /**< Dispatch this buffer while locked */
324
	enum {
325
		DRM_LIST_NONE = 0,
326
		DRM_LIST_FREE = 1,
327
		DRM_LIST_WAIT = 2,
328
		DRM_LIST_PEND = 3,
329
		DRM_LIST_PRIO = 4,
330
		DRM_LIST_RECLAIM = 5
331
	} list;			       /**< Which list we're on */
332
 
333
	int dev_priv_size;		 /**< Size of buffer private storage */
334
	void *dev_private;		 /**< Per-buffer private storage */
335
};
336
 
337
/** bufs is one longer than it has to be */
338
struct drm_waitlist {
339
	int count;			/**< Number of possible buffers */
340
	struct drm_buf **bufs;		/**< List of pointers to buffers */
341
	struct drm_buf **rp;			/**< Read pointer */
342
	struct drm_buf **wp;			/**< Write pointer */
343
	struct drm_buf **end;		/**< End pointer */
344
	spinlock_t read_lock;
345
	spinlock_t write_lock;
346
};
347
 
348
struct drm_freelist {
349
	int initialized;	       /**< Freelist in use */
350
	atomic_t count;		       /**< Number of free buffers */
351
	struct drm_buf *next;	       /**< End pointer */
352
 
353
	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
354
	int low_mark;		       /**< Low water mark */
355
	int high_mark;		       /**< High water mark */
356
	atomic_t wfh;		       /**< If waiting for high mark */
357
	spinlock_t lock;
358
};
359
 
360
typedef struct drm_dma_handle {
361
	dma_addr_t busaddr;
362
	void *vaddr;
363
	size_t size;
364
} drm_dma_handle_t;
365
 
366
/**
367
 * Buffer entry.  There is one of this for each buffer size order.
368
 */
369
struct drm_buf_entry {
370
	int buf_size;			/**< size */
371
	int buf_count;			/**< number of buffers */
372
	struct drm_buf *buflist;		/**< buffer list */
373
	int seg_count;
374
	int page_order;
375
	struct drm_dma_handle **seglist;
376
 
377
	struct drm_freelist freelist;
378
};
379
 
380
/** File private data */
381
struct drm_file {
382
	int authenticated;
383
	pid_t pid;
384
	uid_t uid;
385
	drm_magic_t magic;
386
	unsigned long ioctl_count;
387
	struct list_head lhead;
388
	struct drm_minor *minor;
389
	unsigned long lock_count;
390
 
391
	/** Mapping of mm object handles to object pointers. */
392
	struct idr object_idr;
393
	/** Lock for synchronization of access to object_idr. */
394
	spinlock_t table_lock;
395
 
396
	struct file *filp;
397
	void *driver_priv;
398
 
399
	int is_master; /* this file private is a master for a minor */
400
	struct drm_master *master; /* master this node is currently associated with
401
				      N.B. not always minor->master */
402
	struct list_head fbs;
403
};
404
 
405
/** Wait queue */
406
struct drm_queue {
407
	atomic_t use_count;		/**< Outstanding uses (+1) */
408
	atomic_t finalization;		/**< Finalization in progress */
409
	atomic_t block_count;		/**< Count of processes waiting */
410
	atomic_t block_read;		/**< Queue blocked for reads */
411
	wait_queue_head_t read_queue;	/**< Processes waiting on block_read */
412
	atomic_t block_write;		/**< Queue blocked for writes */
413
	wait_queue_head_t write_queue;	/**< Processes waiting on block_write */
414
	atomic_t total_queued;		/**< Total queued statistic */
415
	atomic_t total_flushed;		/**< Total flushes statistic */
416
	atomic_t total_locks;		/**< Total locks statistics */
417
	enum drm_ctx_flags flags;	/**< Context preserving and 2D-only */
418
	struct drm_waitlist waitlist;	/**< Pending buffers */
419
	wait_queue_head_t flush_queue;	/**< Processes waiting until flush */
420
};
421
 
422
/**
423
 * Lock data.
424
 */
425
struct drm_lock_data {
426
	struct drm_hw_lock *hw_lock;	/**< Hardware lock */
427
	/** Private of lock holder's file (NULL=kernel) */
428
	struct drm_file *file_priv;
429
	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
430
	unsigned long lock_time;	/**< Time of last lock in jiffies */
431
	spinlock_t spinlock;
432
	uint32_t kernel_waiters;
433
	uint32_t user_waiters;
434
	int idle_has_lock;
435
};
436
 
437
/**
438
 * DMA data.
439
 */
440
struct drm_device_dma {
441
 
442
	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
443
	int buf_count;			/**< total number of buffers */
444
	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
445
	int seg_count;
446
	int page_count;			/**< number of pages */
447
	unsigned long *pagelist;	/**< page list */
448
	unsigned long byte_count;
449
	enum {
450
		_DRM_DMA_USE_AGP = 0x01,
451
		_DRM_DMA_USE_SG = 0x02,
452
		_DRM_DMA_USE_FB = 0x04,
453
		_DRM_DMA_USE_PCI_RO = 0x08
454
	} flags;
455
 
456
};
457
 
458
/**
459
 * AGP memory entry.  Stored as a doubly linked list.
460
 */
461
struct drm_agp_mem {
462
	unsigned long handle;		/**< handle */
463
	DRM_AGP_MEM *memory;
464
	unsigned long bound;		/**< address */
465
	int pages;
466
	struct list_head head;
467
};
468
 
469
/**
470
 * AGP data.
471
 *
472
 * \sa drm_agp_init() and drm_device::agp.
473
 */
474
struct drm_agp_head {
475
	DRM_AGP_KERN agp_info;		/**< AGP device information */
476
	struct list_head memory;
477
	unsigned long mode;		/**< AGP mode */
478
	struct agp_bridge_data *bridge;
479
	int enabled;			/**< whether the AGP bus as been enabled */
480
	int acquired;			/**< whether the AGP device has been acquired */
481
	unsigned long base;
482
	int agp_mtrr;
483
	int cant_use_aperture;
484
	unsigned long page_mask;
485
};
486
 
487
/**
488
 * Scatter-gather memory.
489
 */
490
struct drm_sg_mem {
491
	unsigned long handle;
492
	void *virtual;
493
	int pages;
494
	struct page **pagelist;
495
	dma_addr_t *busaddr;
496
};
497
 
498
struct drm_sigdata {
499
	int context;
500
	struct drm_hw_lock *lock;
501
};
502
 
503
 
504
/**
505
 * Kernel side of a mapping
506
 */
507
struct drm_local_map {
508
	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
509
	unsigned long size;	 /**< Requested physical size (bytes) */
510
	enum drm_map_type type;	 /**< Type of memory to map */
511
	enum drm_map_flags flags;	 /**< Flags */
512
	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
513
				 /**< Kernel-space: kernel-virtual address */
514
	int mtrr;		 /**< MTRR slot used */
515
};
516
 
517
typedef struct drm_local_map drm_local_map_t;
518
 
519
/**
520
 * Mappings list
521
 */
522
struct drm_map_list {
523
	struct list_head head;		/**< list head */
524
	struct drm_hash_item hash;
525
	struct drm_local_map *map;	/**< mapping */
526
	uint64_t user_token;
527
	struct drm_master *master;
528
	struct drm_mm_node *file_offset_node;	/**< fake offset */
529
};
530
 
531
/**
532
 * Context handle list
533
 */
534
struct drm_ctx_list {
535
	struct list_head head;		/**< list head */
536
	drm_context_t handle;		/**< context handle */
537
	struct drm_file *tag;		/**< associated fd private data */
538
};
539
 
540
/* location of GART table */
541
#define DRM_ATI_GART_MAIN 1
542
#define DRM_ATI_GART_FB   2
543
 
544
#define DRM_ATI_GART_PCI 1
545
#define DRM_ATI_GART_PCIE 2
546
#define DRM_ATI_GART_IGP 3
547
 
548
struct drm_ati_pcigart_info {
549
	int gart_table_location;
550
	int gart_reg_if;
551
	void *addr;
552
	dma_addr_t bus_addr;
553
	dma_addr_t table_mask;
554
	struct drm_dma_handle *table_handle;
555
	struct drm_local_map mapping;
556
	int table_size;
557
};
558
 
559
/**
560
 * GEM specific mm private for tracking GEM objects
561
 */
562
struct drm_gem_mm {
563
	struct drm_mm offset_manager;	/**< Offset mgmt for buffer objects */
564
	struct drm_open_hash offset_hash; /**< User token hash table for maps */
565
};
566
 
567
/**
568
 * This structure defines the drm_mm memory object, which will be used by the
569
 * DRM for its buffer objects.
570
 */
571
struct drm_gem_object {
572
	/** Reference count of this object */
573
	struct kref refcount;
574
 
575
	/** Handle count of this object. Each handle also holds a reference */
576
	struct kref handlecount;
577
 
578
	/** Related drm device */
579
	struct drm_device *dev;
580
 
581
	/** File representing the shmem storage */
582
	struct file *filp;
583
 
584
	/* Mapping info for this object */
585
	struct drm_map_list map_list;
586
 
587
	/**
588
	 * Size of the object, in bytes.  Immutable over the object's
589
	 * lifetime.
590
	 */
591
	size_t size;
592
 
593
	/**
594
	 * Global name for this object, starts at 1. 0 means unnamed.
595
	 * Access is covered by the object_name_lock in the related drm_device
596
	 */
597
	int name;
598
 
599
	/**
600
	 * Memory domains. These monitor which caches contain read/write data
601
	 * related to the object. When transitioning from one set of domains
602
	 * to another, the driver is called to ensure that caches are suitably
603
	 * flushed and invalidated
604
	 */
605
	uint32_t read_domains;
606
	uint32_t write_domain;
607
 
608
	/**
609
	 * While validating an exec operation, the
610
	 * new read/write domain values are computed here.
611
	 * They will be transferred to the above values
612
	 * at the point that any cache flushing occurs
613
	 */
614
	uint32_t pending_read_domains;
615
	uint32_t pending_write_domain;
616
 
617
	void *driver_private;
618
};
619
 
620
#include "drm_crtc.h"
621
 
622
/* per-master structure */
623
struct drm_master {
624
 
625
	struct kref refcount; /* refcount for this master */
626
 
627
	struct list_head head; /**< each minor contains a list of masters */
628
	struct drm_minor *minor; /**< link back to minor we are a master for */
629
 
630
	char *unique;			/**< Unique identifier: e.g., busid */
631
	int unique_len;			/**< Length of unique field */
632
	int unique_size;		/**< amount allocated */
633
 
634
	int blocked;			/**< Blocked due to VC switch? */
635
 
636
	/** \name Authentication */
637
	/*@{ */
638
	struct drm_open_hash magiclist;
639
	struct list_head magicfree;
640
	/*@} */
641
 
642
	struct drm_lock_data lock;	/**< Information on hardware lock */
643
 
644
	void *driver_priv; /**< Private structure for driver to use */
645
};
646
 
647
/**
648
 * DRM driver structure. This structure represent the common code for
649
 * a family of cards. There will one drm_device for each card present
650
 * in this family
651
 */
652
struct drm_driver {
653
	int (*load) (struct drm_device *, unsigned long flags);
654
	int (*firstopen) (struct drm_device *);
655
	int (*open) (struct drm_device *, struct drm_file *);
656
	void (*preclose) (struct drm_device *, struct drm_file *file_priv);
657
	void (*postclose) (struct drm_device *, struct drm_file *);
658
	void (*lastclose) (struct drm_device *);
659
	int (*unload) (struct drm_device *);
660
	int (*suspend) (struct drm_device *, pm_message_t state);
661
	int (*resume) (struct drm_device *);
662
	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
663
	void (*dma_ready) (struct drm_device *);
664
	int (*dma_quiescent) (struct drm_device *);
665
	int (*context_ctor) (struct drm_device *dev, int context);
666
	int (*context_dtor) (struct drm_device *dev, int context);
667
	int (*kernel_context_switch) (struct drm_device *dev, int old,
668
				      int new);
669
	void (*kernel_context_switch_unlock) (struct drm_device *dev);
670
 
671
	/**
672
	 * get_vblank_counter - get raw hardware vblank counter
673
	 * @dev: DRM device
674
	 * @crtc: counter to fetch
675
	 *
676
	 * Driver callback for fetching a raw hardware vblank counter
677
	 * for @crtc.  If a device doesn't have a hardware counter, the
678
	 * driver can simply return the value of drm_vblank_count and
679
	 * make the enable_vblank() and disable_vblank() hooks into no-ops,
680
	 * leaving interrupts enabled at all times.
681
	 *
682
	 * Wraparound handling and loss of events due to modesetting is dealt
683
	 * with in the DRM core code.
684
	 *
685
	 * RETURNS
686
	 * Raw vblank counter value.
687
	 */
688
	u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
689
 
690
	/**
691
	 * enable_vblank - enable vblank interrupt events
692
	 * @dev: DRM device
693
	 * @crtc: which irq to enable
694
	 *
695
	 * Enable vblank interrupts for @crtc.  If the device doesn't have
696
	 * a hardware vblank counter, this routine should be a no-op, since
697
	 * interrupts will have to stay on to keep the count accurate.
698
	 *
699
	 * RETURNS
700
	 * Zero on success, appropriate errno if the given @crtc's vblank
701
	 * interrupt cannot be enabled.
702
	 */
703
	int (*enable_vblank) (struct drm_device *dev, int crtc);
704
 
705
	/**
706
	 * disable_vblank - disable vblank interrupt events
707
	 * @dev: DRM device
708
	 * @crtc: which irq to enable
709
	 *
710
	 * Disable vblank interrupts for @crtc.  If the device doesn't have
711
	 * a hardware vblank counter, this routine should be a no-op, since
712
	 * interrupts will have to stay on to keep the count accurate.
713
	 */
714
	void (*disable_vblank) (struct drm_device *dev, int crtc);
715
 
716
	/**
717
	 * Called by \c drm_device_is_agp.  Typically used to determine if a
718
	 * card is really attached to AGP or not.
719
	 *
720
	 * \param dev  DRM device handle
721
	 *
722
	 * \returns
723
	 * One of three values is returned depending on whether or not the
724
	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
725
	 * (return of 1), or may or may not be AGP (return of 2).
726
	 */
727
	int (*device_is_agp) (struct drm_device *dev);
728
 
729
	/* these have to be filled in */
730
 
731
	irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
732
	void (*irq_preinstall) (struct drm_device *dev);
733
	int (*irq_postinstall) (struct drm_device *dev);
734
	void (*irq_uninstall) (struct drm_device *dev);
735
	void (*reclaim_buffers) (struct drm_device *dev,
736
				 struct drm_file * file_priv);
737
	void (*reclaim_buffers_locked) (struct drm_device *dev,
738
					struct drm_file *file_priv);
739
	void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
740
					    struct drm_file *file_priv);
741
	resource_size_t (*get_map_ofs) (struct drm_local_map * map);
742
	resource_size_t (*get_reg_ofs) (struct drm_device *dev);
743
	void (*set_version) (struct drm_device *dev,
744
			     struct drm_set_version *sv);
745
 
746
	/* Master routines */
747
	int (*master_create)(struct drm_device *dev, struct drm_master *master);
748
	void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
749
 
750
	int (*proc_init)(struct drm_minor *minor);
751
	void (*proc_cleanup)(struct drm_minor *minor);
752
	int (*debugfs_init)(struct drm_minor *minor);
753
	void (*debugfs_cleanup)(struct drm_minor *minor);
754
 
755
	/**
756
	 * Driver-specific constructor for drm_gem_objects, to set up
757
	 * obj->driver_private.
758
	 *
759
	 * Returns 0 on success.
760
	 */
761
	int (*gem_init_object) (struct drm_gem_object *obj);
762
	void (*gem_free_object) (struct drm_gem_object *obj);
763
 
764
	/* Driver private ops for this object */
765
	struct vm_operations_struct *gem_vm_ops;
766
 
767
	int major;
768
	int minor;
769
	int patchlevel;
770
	char *name;
771
	char *desc;
772
	char *date;
773
 
774
	u32 driver_features;
775
	int dev_priv_size;
776
	struct drm_ioctl_desc *ioctls;
777
	int num_ioctls;
778
	struct file_operations fops;
779
	struct pci_driver pci_driver;
780
	/* List of devices hanging off this driver */
781
	struct list_head device_list;
782
};
783
 
784
#define DRM_MINOR_UNASSIGNED 0
785
#define DRM_MINOR_LEGACY 1
786
#define DRM_MINOR_CONTROL 2
787
#define DRM_MINOR_RENDER 3
788
 
789
 
790
/**
791
 * debugfs node list. This structure represents a debugfs file to
792
 * be created by the drm core
793
 */
794
struct drm_debugfs_list {
795
	const char *name; /** file name */
796
	int (*show)(struct seq_file*, void*); /** show callback */
797
	u32 driver_features; /**< Required driver features for this entry */
798
};
799
 
800
/**
801
 * debugfs node structure. This structure represents a debugfs file.
802
 */
803
struct drm_debugfs_node {
804
	struct list_head list;
805
	struct drm_minor *minor;
806
	struct drm_debugfs_list *debugfs_ent;
807
	struct dentry *dent;
808
};
809
 
810
/**
811
 * Info file list entry. This structure represents a debugfs or proc file to
812
 * be created by the drm core
813
 */
814
struct drm_info_list {
815
	const char *name; /** file name */
816
	int (*show)(struct seq_file*, void*); /** show callback */
817
	u32 driver_features; /**< Required driver features for this entry */
818
	void *data;
819
};
820
 
821
/**
822
 * debugfs node structure. This structure represents a debugfs file.
823
 */
824
struct drm_info_node {
825
	struct list_head list;
826
	struct drm_minor *minor;
827
	struct drm_info_list *info_ent;
828
	struct dentry *dent;
829
};
830
 
831
/**
832
 * DRM minor structure. This structure represents a drm minor number.
833
 */
834
struct drm_minor {
835
	int index;			/**< Minor device number */
836
	int type;                       /**< Control or render */
837
	dev_t device;			/**< Device number for mknod */
838
	struct device kdev;		/**< Linux device */
839
	struct drm_device *dev;
840
 
841
	struct proc_dir_entry *proc_root;  /**< proc directory entry */
842
	struct drm_info_node proc_nodes;
843
	struct dentry *debugfs_root;
844
	struct drm_info_node debugfs_nodes;
845
 
846
	struct drm_master *master; /* currently active master for this node */
847
	struct list_head master_list;
848
	struct drm_mode_group mode_group;
849
};
850
 
851
 
852
 
853
 
854
#endif
855
 
856
 
857
/**
858
 * DRM device structure. This structure represent a complete card that
859
 * may contain multiple heads.
860
 */
861
struct drm_device {
862
	struct list_head driver_item;	/**< list of devices per driver */
863
	char *devname;			/**< For /proc/interrupts */
864
	int if_version;			/**< Highest interface version set */
865
 
866
	/** \name Locks */
867
	/*@{ */
868
//   spinlock_t count_lock;      /**< For inuse, drm_device::open_count, drm_device::buf_use */
869
//   struct mutex struct_mutex;  /**< For others */
870
	/*@} */
871
 
872
	/** \name Usage Counters */
873
	/*@{ */
874
	int open_count;			/**< Outstanding files open */
875
//   atomic_t ioctl_count;       /**< Outstanding IOCTLs pending */
876
//   atomic_t vma_count;     /**< Outstanding vma areas open */
877
	int buf_use;			/**< Buffers in use -- cannot alloc */
878
//   atomic_t buf_alloc;     /**< Buffer allocation in progress */
879
	/*@} */
880
 
881
	/** \name Performance counters */
882
	/*@{ */
883
	unsigned long counters;
884
//   enum drm_stat_type types[15];
885
//   atomic_t counts[15];
886
	/*@} */
887
 
888
	struct list_head filelist;
889
 
890
	/** \name Memory management */
891
	/*@{ */
892
	struct list_head maplist;	/**< Linked list of regions */
893
	int map_count;			/**< Number of mappable regions */
894
//   struct drm_open_hash map_hash;  /**< User token hash table for maps */
895
 
896
	/** \name Context handle management */
897
	/*@{ */
898
	struct list_head ctxlist;	/**< Linked list of context handles */
899
	int ctx_count;			/**< Number of context handles */
900
//   struct mutex ctxlist_mutex; /**< For ctxlist */
901
 
902
//   struct idr ctx_idr;
903
 
904
	struct list_head vmalist;	/**< List of vmas (for debugging) */
905
 
906
	/*@} */
907
 
908
	/** \name DMA queues (contexts) */
909
	/*@{ */
910
	int queue_count;		/**< Number of active DMA queues */
911
	int queue_reserved;		  /**< Number of reserved DMA queues */
912
	int queue_slots;		/**< Actual length of queuelist */
913
//   struct drm_queue **queuelist;   /**< Vector of pointers to DMA queues */
914
//   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
915
	/*@} */
916
 
917
	/** \name Context support */
918
	/*@{ */
919
	int irq_enabled;		/**< True if irq handler is enabled */
920
	__volatile__ long context_flag;	/**< Context swapping flag */
921
	__volatile__ long interrupt_flag; /**< Interruption handler flag */
922
	__volatile__ long dma_flag;	/**< DMA dispatch flag */
923
//   struct timer_list timer;    /**< Timer for delaying ctx switch */
924
//   wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
925
	int last_checked;		/**< Last context checked for DMA */
926
	int last_context;		/**< Last current context */
927
	unsigned long last_switch;	/**< jiffies at last context switch */
928
	/*@} */
929
 
930
//   struct work_struct work;
931
	/** \name VBLANK IRQ support */
932
	/*@{ */
933
 
934
	/*
935
	 * At load time, disabling the vblank interrupt won't be allowed since
936
	 * old clients may not call the modeset ioctl and therefore misbehave.
937
	 * Once the modeset ioctl *has* been called though, we can safely
938
	 * disable them when unused.
939
	 */
940
	int vblank_disable_allowed;
941
 
942
//   wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
943
//   atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
944
//   spinlock_t vbl_lock;
945
//   atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
946
	u32 *last_vblank;               /* protected by dev->vbl_lock, used */
947
					/* for wraparound handling */
948
	int *vblank_enabled;            /* so we don't call enable more than
949
					   once per disable */
950
	int *vblank_inmodeset;          /* Display driver is setting mode */
951
	u32 *last_vblank_wait;		/* Last vblank seqno waited per CRTC */
952
//   struct timer_list vblank_disable_timer;
953
 
954
	u32 max_vblank_count;           /**< size of vblank counter register */
955
 
956
	/*@} */
957
//   cycles_t ctx_start;
958
//   cycles_t lck_start;
959
 
960
//   struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
961
//   wait_queue_head_t buf_readers;  /**< Processes waiting to read */
962
//   wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
963
 
964
//   struct drm_agp_head *agp;   /**< AGP data */
965
 
966
	struct pci_dev *pdev;		/**< PCI device structure */
967
	int pci_vendor;			/**< PCI vendor id */
968
	int pci_device;			/**< PCI device id */
969
//    struct drm_sg_mem *sg;  /**< Scatter gather memory */
970
	int num_crtcs;                  /**< Number of CRTCs on this device */
971
	void *dev_private;		/**< device private data */
972
	void *mm_private;
973
//   struct address_space *dev_mapping;
974
//   struct drm_sigdata sigdata;    /**< For block_all_signals */
975
//   sigset_t sigmask;
976
 
977
//   struct drm_driver *driver;
978
//   struct drm_local_map *agp_buffer_map;
979
//   unsigned int agp_buffer_token;
980
//   struct drm_minor *control;      /**< Control node for card */
981
//   struct drm_minor *primary;      /**< render type primary screen head */
982
 
983
	/** \name Drawable information */
984
	/*@{ */
985
//   spinlock_t drw_lock;
986
//   struct idr drw_idr;
987
	/*@} */
988
 
989
        struct drm_mode_config mode_config;	/**< Current mode config */
990
 
991
	/** \name GEM information */
992
	/*@{ */
993
//   spinlock_t object_name_lock;
994
//   struct idr object_name_idr;
995
//   atomic_t object_count;
996
//   atomic_t object_memory;
997
//   atomic_t pin_count;
998
//   atomic_t pin_memory;
999
//   atomic_t gtt_count;
1000
//   atomic_t gtt_memory;
1001
//   uint32_t gtt_total;
1002
	uint32_t invalidate_domains;    /* domains pending invalidation */
1003
	uint32_t flush_domains;         /* domains pending flush */
1004
	/*@} */
1005
 
1006
};
1007
 
1008
 
1009
#if 0
1010
static inline int drm_dev_to_irq(struct drm_device *dev)
1011
{
1012
	return dev->pdev->irq;
1013
}
1014
 
1015
static __inline__ int drm_core_check_feature(struct drm_device *dev,
1016
					     int feature)
1017
{
1018
	return ((dev->driver->driver_features & feature) ? 1 : 0);
1019
}
1020
 
1021
#ifdef __alpha__
1022
#define drm_get_pci_domain(dev) dev->hose->index
1023
#else
1024
#define drm_get_pci_domain(dev) 0
1025
#endif
1026
 
1027
#if __OS_HAS_AGP
1028
static inline int drm_core_has_AGP(struct drm_device *dev)
1029
{
1030
	return drm_core_check_feature(dev, DRIVER_USE_AGP);
1031
}
1032
#else
1033
#define drm_core_has_AGP(dev) (0)
1034
#endif
1035
 
1036
#if __OS_HAS_MTRR
1037
static inline int drm_core_has_MTRR(struct drm_device *dev)
1038
{
1039
	return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1040
}
1041
 
1042
#define DRM_MTRR_WC		MTRR_TYPE_WRCOMB
1043
 
1044
static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1045
			       unsigned int flags)
1046
{
1047
	return mtrr_add(offset, size, flags, 1);
1048
}
1049
 
1050
static inline int drm_mtrr_del(int handle, unsigned long offset,
1051
			       unsigned long size, unsigned int flags)
1052
{
1053
	return mtrr_del(handle, offset, size);
1054
}
1055
 
1056
#else
1057
#define drm_core_has_MTRR(dev) (0)
1058
 
1059
#define DRM_MTRR_WC		0
1060
 
1061
static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1062
			       unsigned int flags)
1063
{
1064
	return 0;
1065
}
1066
 
1067
static inline int drm_mtrr_del(int handle, unsigned long offset,
1068
			       unsigned long size, unsigned int flags)
1069
{
1070
	return 0;
1071
}
1072
#endif
1073
 
1074
/******************************************************************/
1075
/** \name Internal function definitions */
1076
/*@{*/
1077
 
1078
				/* Driver support (drm_drv.h) */
1079
extern int drm_init(struct drm_driver *driver);
1080
extern void drm_exit(struct drm_driver *driver);
1081
extern int drm_ioctl(struct inode *inode, struct file *filp,
1082
		     unsigned int cmd, unsigned long arg);
1083
extern long drm_compat_ioctl(struct file *filp,
1084
			     unsigned int cmd, unsigned long arg);
1085
extern int drm_lastclose(struct drm_device *dev);
1086
 
1087
				/* Device support (drm_fops.h) */
1088
extern int drm_open(struct inode *inode, struct file *filp);
1089
extern int drm_stub_open(struct inode *inode, struct file *filp);
1090
extern int drm_fasync(int fd, struct file *filp, int on);
1091
extern int drm_release(struct inode *inode, struct file *filp);
1092
 
1093
				/* Mapping support (drm_vm.h) */
1094
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1095
extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
1096
extern void drm_vm_open_locked(struct vm_area_struct *vma);
1097
extern resource_size_t drm_core_get_map_ofs(struct drm_local_map * map);
1098
extern resource_size_t drm_core_get_reg_ofs(struct drm_device *dev);
1099
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1100
 
1101
				/* Memory management support (drm_memory.h) */
1102
#include "drm_memory.h"
1103
extern void drm_mem_init(void);
1104
extern int drm_mem_info(char *buf, char **start, off_t offset,
1105
			int request, int *eof, void *data);
1106
extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1107
 
1108
extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
1109
extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1110
extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1111
extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1112
				       struct page **pages,
1113
				       unsigned long num_pages,
1114
				       uint32_t gtt_offset,
1115
				       uint32_t type);
1116
extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1117
 
1118
				/* Misc. IOCTL support (drm_ioctl.h) */
1119
extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1120
			    struct drm_file *file_priv);
1121
extern int drm_getunique(struct drm_device *dev, void *data,
1122
			 struct drm_file *file_priv);
1123
extern int drm_setunique(struct drm_device *dev, void *data,
1124
			 struct drm_file *file_priv);
1125
extern int drm_getmap(struct drm_device *dev, void *data,
1126
		      struct drm_file *file_priv);
1127
extern int drm_getclient(struct drm_device *dev, void *data,
1128
			 struct drm_file *file_priv);
1129
extern int drm_getstats(struct drm_device *dev, void *data,
1130
			struct drm_file *file_priv);
1131
extern int drm_setversion(struct drm_device *dev, void *data,
1132
			  struct drm_file *file_priv);
1133
extern int drm_noop(struct drm_device *dev, void *data,
1134
		    struct drm_file *file_priv);
1135
 
1136
				/* Context IOCTL support (drm_context.h) */
1137
extern int drm_resctx(struct drm_device *dev, void *data,
1138
		      struct drm_file *file_priv);
1139
extern int drm_addctx(struct drm_device *dev, void *data,
1140
		      struct drm_file *file_priv);
1141
extern int drm_modctx(struct drm_device *dev, void *data,
1142
		      struct drm_file *file_priv);
1143
extern int drm_getctx(struct drm_device *dev, void *data,
1144
		      struct drm_file *file_priv);
1145
extern int drm_switchctx(struct drm_device *dev, void *data,
1146
			 struct drm_file *file_priv);
1147
extern int drm_newctx(struct drm_device *dev, void *data,
1148
		      struct drm_file *file_priv);
1149
extern int drm_rmctx(struct drm_device *dev, void *data,
1150
		     struct drm_file *file_priv);
1151
 
1152
extern int drm_ctxbitmap_init(struct drm_device *dev);
1153
extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1154
extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1155
 
1156
extern int drm_setsareactx(struct drm_device *dev, void *data,
1157
			   struct drm_file *file_priv);
1158
extern int drm_getsareactx(struct drm_device *dev, void *data,
1159
			   struct drm_file *file_priv);
1160
 
1161
				/* Drawable IOCTL support (drm_drawable.h) */
1162
extern int drm_adddraw(struct drm_device *dev, void *data,
1163
		       struct drm_file *file_priv);
1164
extern int drm_rmdraw(struct drm_device *dev, void *data,
1165
		      struct drm_file *file_priv);
1166
extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1167
				    struct drm_file *file_priv);
1168
extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1169
						  drm_drawable_t id);
1170
extern void drm_drawable_free_all(struct drm_device *dev);
1171
 
1172
				/* Authentication IOCTL support (drm_auth.h) */
1173
extern int drm_getmagic(struct drm_device *dev, void *data,
1174
			struct drm_file *file_priv);
1175
extern int drm_authmagic(struct drm_device *dev, void *data,
1176
			 struct drm_file *file_priv);
1177
 
1178
/* Cache management (drm_cache.c) */
1179
void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
1180
 
1181
				/* Locking IOCTL support (drm_lock.h) */
1182
extern int drm_lock(struct drm_device *dev, void *data,
1183
		    struct drm_file *file_priv);
1184
extern int drm_unlock(struct drm_device *dev, void *data,
1185
		      struct drm_file *file_priv);
1186
extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1187
extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1188
extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1189
extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1190
 
1191
/*
1192
 * These are exported to drivers so that they can implement fencing using
1193
 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1194
 */
1195
 
1196
extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1197
 
1198
				/* Buffer management support (drm_bufs.h) */
1199
extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1200
extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1201
extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1202
		      unsigned int size, enum drm_map_type type,
1203
		      enum drm_map_flags flags, struct drm_local_map **map_ptr);
1204
extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1205
			    struct drm_file *file_priv);
1206
extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1207
extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1208
extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1209
			   struct drm_file *file_priv);
1210
extern int drm_addbufs(struct drm_device *dev, void *data,
1211
		       struct drm_file *file_priv);
1212
extern int drm_infobufs(struct drm_device *dev, void *data,
1213
			struct drm_file *file_priv);
1214
extern int drm_markbufs(struct drm_device *dev, void *data,
1215
			struct drm_file *file_priv);
1216
extern int drm_freebufs(struct drm_device *dev, void *data,
1217
			struct drm_file *file_priv);
1218
extern int drm_mapbufs(struct drm_device *dev, void *data,
1219
		       struct drm_file *file_priv);
1220
extern int drm_order(unsigned long size);
1221
extern resource_size_t drm_get_resource_start(struct drm_device *dev,
1222
					      unsigned int resource);
1223
extern resource_size_t drm_get_resource_len(struct drm_device *dev,
1224
					    unsigned int resource);
1225
 
1226
				/* DMA support (drm_dma.h) */
1227
extern int drm_dma_setup(struct drm_device *dev);
1228
extern void drm_dma_takedown(struct drm_device *dev);
1229
extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1230
extern void drm_core_reclaim_buffers(struct drm_device *dev,
1231
				     struct drm_file *filp);
1232
 
1233
				/* IRQ support (drm_irq.h) */
1234
extern int drm_control(struct drm_device *dev, void *data,
1235
		       struct drm_file *file_priv);
1236
extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1237
extern int drm_irq_install(struct drm_device *dev);
1238
extern int drm_irq_uninstall(struct drm_device *dev);
1239
extern void drm_driver_irq_preinstall(struct drm_device *dev);
1240
extern void drm_driver_irq_postinstall(struct drm_device *dev);
1241
extern void drm_driver_irq_uninstall(struct drm_device *dev);
1242
 
1243
extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1244
extern int drm_wait_vblank(struct drm_device *dev, void *data,
1245
			   struct drm_file *filp);
1246
extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1247
extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1248
extern void drm_handle_vblank(struct drm_device *dev, int crtc);
1249
extern int drm_vblank_get(struct drm_device *dev, int crtc);
1250
extern void drm_vblank_put(struct drm_device *dev, int crtc);
1251
extern void drm_vblank_cleanup(struct drm_device *dev);
1252
/* Modesetting support */
1253
extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1254
extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1255
extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1256
			   struct drm_file *file_priv);
1257
 
1258
				/* AGP/GART support (drm_agpsupport.h) */
1259
extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1260
extern int drm_agp_acquire(struct drm_device *dev);
1261
extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1262
				 struct drm_file *file_priv);
1263
extern int drm_agp_release(struct drm_device *dev);
1264
extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1265
				 struct drm_file *file_priv);
1266
extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1267
extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1268
				struct drm_file *file_priv);
1269
extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1270
extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1271
			struct drm_file *file_priv);
1272
extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1273
extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1274
			 struct drm_file *file_priv);
1275
extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1276
extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1277
			struct drm_file *file_priv);
1278
extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1279
extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1280
			  struct drm_file *file_priv);
1281
extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1282
extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1283
			struct drm_file *file_priv);
1284
extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1285
extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1286
extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1287
extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1288
extern void drm_agp_chipset_flush(struct drm_device *dev);
1289
 
1290
				/* Stub support (drm_stub.h) */
1291
extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1292
			       struct drm_file *file_priv);
1293
extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1294
				struct drm_file *file_priv);
1295
struct drm_master *drm_master_create(struct drm_minor *minor);
1296
extern struct drm_master *drm_master_get(struct drm_master *master);
1297
extern void drm_master_put(struct drm_master **master);
1298
extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1299
		       struct drm_driver *driver);
1300
extern void drm_put_dev(struct drm_device *dev);
1301
extern int drm_put_minor(struct drm_minor **minor);
1302
extern unsigned int drm_debug;
1303
 
1304
extern struct class *drm_class;
1305
extern struct proc_dir_entry *drm_proc_root;
1306
extern struct dentry *drm_debugfs_root;
1307
 
1308
extern struct idr drm_minors_idr;
1309
 
1310
extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
1311
 
1312
				/* Proc support (drm_proc.h) */
1313
extern int drm_proc_init(struct drm_minor *minor, int minor_id,
1314
			 struct proc_dir_entry *root);
1315
extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1316
 
1317
				/* Debugfs support */
1318
#if defined(CONFIG_DEBUG_FS)
1319
extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1320
			    struct dentry *root);
1321
extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
1322
				    struct dentry *root, struct drm_minor *minor);
1323
extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
1324
                                    struct drm_minor *minor);
1325
extern int drm_debugfs_cleanup(struct drm_minor *minor);
1326
#endif
1327
 
1328
				/* Info file support */
1329
extern int drm_name_info(struct seq_file *m, void *data);
1330
extern int drm_vm_info(struct seq_file *m, void *data);
1331
extern int drm_queues_info(struct seq_file *m, void *data);
1332
extern int drm_bufs_info(struct seq_file *m, void *data);
1333
extern int drm_vblank_info(struct seq_file *m, void *data);
1334
extern int drm_clients_info(struct seq_file *m, void* data);
1335
extern int drm_gem_name_info(struct seq_file *m, void *data);
1336
extern int drm_gem_object_info(struct seq_file *m, void* data);
1337
 
1338
#if DRM_DEBUG_CODE
1339
extern int drm_vma_info(struct seq_file *m, void *data);
1340
#endif
1341
 
1342
				/* Scatter Gather Support (drm_scatter.h) */
1343
extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1344
extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1345
			struct drm_file *file_priv);
1346
extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1347
extern int drm_sg_free(struct drm_device *dev, void *data,
1348
		       struct drm_file *file_priv);
1349
 
1350
			       /* ATI PCIGART support (ati_pcigart.h) */
1351
extern int drm_ati_pcigart_init(struct drm_device *dev,
1352
				struct drm_ati_pcigart_info * gart_info);
1353
extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1354
				   struct drm_ati_pcigart_info * gart_info);
1355
 
1356
extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1357
				       size_t align, dma_addr_t maxaddr);
1358
extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1359
extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1360
 
1361
			       /* sysfs support (drm_sysfs.c) */
1362
struct drm_sysfs_class;
1363
extern struct class *drm_sysfs_create(struct module *owner, char *name);
1364
extern void drm_sysfs_destroy(void);
1365
extern int drm_sysfs_device_add(struct drm_minor *minor);
1366
extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1367
extern void drm_sysfs_device_remove(struct drm_minor *minor);
1368
extern char *drm_get_connector_status_name(enum drm_connector_status status);
1369
extern int drm_sysfs_connector_add(struct drm_connector *connector);
1370
extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1371
 
1372
/* Graphics Execution Manager library functions (drm_gem.c) */
1373
int drm_gem_init(struct drm_device *dev);
1374
void drm_gem_destroy(struct drm_device *dev);
1375
void drm_gem_object_free(struct kref *kref);
1376
struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1377
					    size_t size);
1378
void drm_gem_object_handle_free(struct kref *kref);
1379
void drm_gem_vm_open(struct vm_area_struct *vma);
1380
void drm_gem_vm_close(struct vm_area_struct *vma);
1381
int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1382
 
1383
static inline void
1384
drm_gem_object_reference(struct drm_gem_object *obj)
1385
{
1386
	kref_get(&obj->refcount);
1387
}
1388
 
1389
static inline void
1390
drm_gem_object_unreference(struct drm_gem_object *obj)
1391
{
1392
	if (obj == NULL)
1393
		return;
1394
 
1395
	kref_put(&obj->refcount, drm_gem_object_free);
1396
}
1397
 
1398
int drm_gem_handle_create(struct drm_file *file_priv,
1399
			  struct drm_gem_object *obj,
1400
			  int *handlep);
1401
 
1402
static inline void
1403
drm_gem_object_handle_reference(struct drm_gem_object *obj)
1404
{
1405
	drm_gem_object_reference(obj);
1406
	kref_get(&obj->handlecount);
1407
}
1408
 
1409
static inline void
1410
drm_gem_object_handle_unreference(struct drm_gem_object *obj)
1411
{
1412
	if (obj == NULL)
1413
		return;
1414
 
1415
	/*
1416
	 * Must bump handle count first as this may be the last
1417
	 * ref, in which case the object would disappear before we
1418
	 * checked for a name
1419
	 */
1420
	kref_put(&obj->handlecount, drm_gem_object_handle_free);
1421
	drm_gem_object_unreference(obj);
1422
}
1423
 
1424
struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1425
					     struct drm_file *filp,
1426
					     int handle);
1427
int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1428
			struct drm_file *file_priv);
1429
int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1430
			struct drm_file *file_priv);
1431
int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1432
		       struct drm_file *file_priv);
1433
void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1434
void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1435
 
1436
extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1437
extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1438
extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1439
 
1440
static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1441
							 unsigned int token)
1442
{
1443
	struct drm_map_list *_entry;
1444
	list_for_each_entry(_entry, &dev->maplist, head)
1445
	    if (_entry->user_token == token)
1446
		return _entry->map;
1447
	return NULL;
1448
}
1449
 
1450
static __inline__ int drm_device_is_agp(struct drm_device *dev)
1451
{
1452
	if (dev->driver->device_is_agp != NULL) {
1453
		int err = (*dev->driver->device_is_agp) (dev);
1454
 
1455
		if (err != 2) {
1456
			return err;
1457
		}
1458
	}
1459
 
1460
	return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1461
}
1462
 
1463
static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1464
{
1465
	return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1466
}
1467
 
1468
static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1469
{
1470
}
1471
 
1472
 
1473
static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
1474
{
1475
	if (size * nmemb <= PAGE_SIZE)
1476
	    return kcalloc(nmemb, size, GFP_KERNEL);
1477
 
1478
	if (size != 0 && nmemb > ULONG_MAX / size)
1479
		return NULL;
1480
 
1481
	return __vmalloc(size * nmemb,
1482
			 GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
1483
}
1484
 
1485
static __inline void drm_free_large(void *ptr)
1486
{
1487
	if (!is_vmalloc_addr(ptr))
1488
		return kfree(ptr);
1489
 
1490
	vfree(ptr);
1491
}
1492
/*@}*/
1493
 
1494
#endif
1495
 
1496
 
1497
#endif