Subversion Repositories Kolibri OS

Rev

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