Subversion Repositories Kolibri OS

Rev

Rev 3747 | Rev 4065 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1408 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.
1964 serge 12
 * Copyright (c) 2009-2010, Code Aurora Forum.
1408 serge 13
 * All rights reserved.
14
 *
15
 * Permission is hereby granted, free of charge, to any person obtaining a
16
 * copy of this software and associated documentation files (the "Software"),
17
 * to deal in the Software without restriction, including without limitation
18
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19
 * and/or sell copies of the Software, and to permit persons to whom the
20
 * Software is furnished to do so, subject to the following conditions:
21
 *
22
 * The above copyright notice and this permission notice (including the next
23
 * paragraph) shall be included in all copies or substantial portions of the
24
 * Software.
25
 *
26
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
29
 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32
 * OTHER DEALINGS IN THE SOFTWARE.
33
 */
34
 
35
#ifndef _DRM_P_H_
36
#define _DRM_P_H_
37
 
3747 Serge 38
#define iowrite32(v, addr)      writel((v), (addr))
39
 
1408 serge 40
#ifdef __KERNEL__
3031 serge 41
#ifdef __alpha__
42
/* add include of current.h so that "current" is defined
43
 * before static inline funcs in wait.h. Doing this so we
44
 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
45
#include 
46
#endif				/* __alpha__ */
2967 Serge 47
 
48
#include 
49
 
1408 serge 50
#include 
3031 serge 51
#include 
2967 Serge 52
#include 
1408 serge 53
#include 
54
#include 
2967 Serge 55
#include 
3031 serge 56
#include 
3391 Serge 57
#include 
1408 serge 58
 
3763 Serge 59
#include 
60
#include 
61
 
1408 serge 62
//#include 
63
//#include 
64
//#include 
65
//#include 
66
#include 
2967 Serge 67
#include 
3747 Serge 68
#include 
1408 serge 69
//#include     /* For (un)lock_kernel */
70
//#include 
71
//#include 
72
//#include 
1630 serge 73
#include 
1408 serge 74
//#include 
75
//#include 
76
//#include 
77
//#include 
78
//#include 
79
//#include 
80
 
3482 Serge 81
#include 
82
 
83
 
1408 serge 84
#include "drm.h"
85
 
86
#include 
87
 
88
#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
89
#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
90
 
3031 serge 91
struct module;
1408 serge 92
 
93
struct drm_file;
94
struct drm_device;
95
 
3391 Serge 96
struct device_node;
97
struct videomode;
3031 serge 98
//#include 
99
#include 
100
#include 
1408 serge 101
 
102
#define KHZ2PICOS(a) (1000000000UL/(a))
103
 
1964 serge 104
/* get_scanout_position() return flags */
105
#define DRM_SCANOUTPOS_VALID        (1 << 0)
106
#define DRM_SCANOUTPOS_INVBL        (1 << 1)
107
#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
108
 
109
 
3031 serge 110
 
111
#define DRM_UT_CORE 		0x01
112
#define DRM_UT_DRIVER		0x02
113
#define DRM_UT_KMS          0x04
114
#define DRM_UT_PRIME		0x08
115
/*
116
 * Three debug levels are defined.
117
 * drm_core, drm_driver, drm_kms
118
 * drm_core level can be used in the generic drm code. For example:
119
 * 	drm_ioctl, drm_mm, drm_memory
120
 * The macro definition of DRM_DEBUG is used.
121
 * 	DRM_DEBUG(fmt, args...)
122
 * 	The debug info by using the DRM_DEBUG can be obtained by adding
123
 * 	the boot option of "drm.debug=1".
124
 *
125
 * drm_driver level can be used in the specific drm driver. It is used
126
 * to add the debug info related with the drm driver. For example:
127
 * i915_drv, i915_dma, i915_gem, radeon_drv,
128
 * 	The macro definition of DRM_DEBUG_DRIVER can be used.
129
 * 	DRM_DEBUG_DRIVER(fmt, args...)
130
 * 	The debug info by using the DRM_DEBUG_DRIVER can be obtained by
131
 * 	adding the boot option of "drm.debug=0x02"
132
 *
133
 * drm_kms level can be used in the KMS code related with specific drm driver.
134
 * It is used to add the debug info related with KMS mode. For example:
135
 * the connector/crtc ,
136
 * 	The macro definition of DRM_DEBUG_KMS can be used.
137
 * 	DRM_DEBUG_KMS(fmt, args...)
138
 * 	The debug info by using the DRM_DEBUG_KMS can be obtained by
139
 * 	adding the boot option of "drm.debug=0x04"
140
 *
141
 * If we add the boot option of "drm.debug=0x06", we can get the debug info by
142
 * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
143
 * If we add the boot option of "drm.debug=0x05", we can get the debug info by
144
 * using the DRM_DEBUG_KMS and DRM_DEBUG.
145
 */
146
 
147
extern __printf(4, 5)
148
void drm_ut_debug_printk(unsigned int request_level,
1408 serge 149
				const char *prefix,
150
				const char *function_name,
151
				const char *format, ...);
3031 serge 152
extern __printf(2, 3)
153
int drm_err(const char *func, const char *format, ...);
1408 serge 154
 
155
/***********************************************************************/
156
/** \name DRM template customization defaults */
157
/*@{*/
158
 
159
/* driver capabilities and requirements mask */
160
#define DRIVER_USE_AGP     0x1
161
#define DRIVER_REQUIRE_AGP 0x2
162
#define DRIVER_USE_MTRR    0x4
163
#define DRIVER_PCI_DMA     0x8
164
#define DRIVER_SG          0x10
165
#define DRIVER_HAVE_DMA    0x20
166
#define DRIVER_HAVE_IRQ    0x40
167
#define DRIVER_IRQ_SHARED  0x80
168
#define DRIVER_IRQ_VBL     0x100
169
#define DRIVER_DMA_QUEUE   0x200
170
#define DRIVER_FB_DMA      0x400
171
#define DRIVER_IRQ_VBL2    0x800
172
#define DRIVER_GEM         0x1000
173
#define DRIVER_MODESET     0x2000
3031 serge 174
#define DRIVER_PRIME       0x4000
1408 serge 175
 
2967 Serge 176
#define DRIVER_BUS_PCI 0x1
177
#define DRIVER_BUS_PLATFORM 0x2
178
#define DRIVER_BUS_USB 0x3
179
 
1408 serge 180
/***********************************************************************/
181
/** \name Begin the DRM... */
182
/*@{*/
183
 
3391 Serge 184
#define DRM_DEBUG_CODE 2	  /**< Include debugging code if > 1, then
1408 serge 185
				     also include looping detection. */
186
 
187
#define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
188
#define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
189
#define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
190
#define DRM_LOOPING_LIMIT     5000000
191
#define DRM_TIME_SLICE	      (HZ/20)  /**< Time slice for GLXContexts */
192
#define DRM_LOCK_SLICE	      1	/**< Time slice for lock, in jiffies */
193
 
194
#define DRM_FLAG_DEBUG	  0x01
195
 
196
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
197
#define DRM_MAP_HASH_OFFSET 0x10000000
198
 
199
/*@}*/
200
 
201
/***********************************************************************/
202
/** \name Macros to make printk easier */
203
/*@{*/
204
 
205
/**
206
 * Error output.
207
 *
208
 * \param fmt printf() like format string.
209
 * \param arg arguments
210
 */
3031 serge 211
#define DRM_ERROR(fmt, ...)				\
212
	drm_err(__func__, fmt, ##__VA_ARGS__)
1408 serge 213
 
3031 serge 214
#define DRM_INFO(fmt, ...)				\
215
	printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
1408 serge 216
 
217
/**
218
 * Debug output.
219
 *
220
 * \param fmt printf() like format string.
221
 * \param arg arguments
222
 */
223
#if DRM_DEBUG_CODE
3031 serge 224
#define DRM_DEBUG(fmt, ...)                                 \
225
    do {                                                    \
226
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 227
	} while (0)
228
 
3031 serge 229
#define DRM_DEBUG_DRIVER(fmt, ...)                          \
230
    do {                                                    \
231
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
232
	} while (0)
233
#define DRM_DEBUG_KMS(fmt, ...)              \
1408 serge 234
	do {								\
3031 serge 235
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 236
	} while (0)
3031 serge 237
#define DRM_DEBUG_PRIME(fmt, ...)                    \
1408 serge 238
	do {								\
3031 serge 239
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 240
	} while (0)
3031 serge 241
#define DRM_LOG(fmt, ...)                        \
1408 serge 242
	do {								\
3031 serge 243
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 244
	} while (0)
3031 serge 245
#define DRM_LOG_KMS(fmt, ...)                    \
1408 serge 246
	do {								\
3031 serge 247
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 248
	} while (0)
3031 serge 249
#define DRM_LOG_MODE(fmt, ...)                   \
1408 serge 250
	do {								\
3031 serge 251
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 252
	} while (0)
3031 serge 253
#define DRM_LOG_DRIVER(fmt, ...)                 \
1408 serge 254
	do {								\
3031 serge 255
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
1408 serge 256
	} while (0)
257
#else
258
#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
259
#define DRM_DEBUG_KMS(fmt, args...)	do { } while (0)
3031 serge 260
#define DRM_DEBUG_PRIME(fmt, args...)	do { } while (0)
1408 serge 261
#define DRM_DEBUG(fmt, arg...)		 do { } while (0)
262
#define DRM_LOG(fmt, arg...)		do { } while (0)
263
#define DRM_LOG_KMS(fmt, args...) do { } while (0)
264
#define DRM_LOG_MODE(fmt, arg...) do { } while (0)
265
#define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
266
 
267
#endif
268
 
269
/*@}*/
270
 
271
/***********************************************************************/
272
/** \name Internal types and structures */
273
/*@{*/
274
 
275
#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
276
 
277
#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
278
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
279
 
280
#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
281
 
282
/**
283
 * Test that the hardware lock is held by the caller, returning otherwise.
284
 *
285
 * \param dev DRM device.
286
 * \param filp file pointer of the caller.
287
 */
288
#define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
289
do {										\
290
	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
291
	    _file_priv->master->lock.file_priv != _file_priv)	{		\
292
		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
293
			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
294
			   _file_priv->master->lock.file_priv, _file_priv);	\
295
		return -EINVAL;							\
296
	}									\
297
} while (0)
298
 
3031 serge 299
#if 0
1408 serge 300
/**
301
 * Ioctl function type.
302
 *
303
 * \param inode device inode.
304
 * \param file_priv DRM file private pointer.
305
 * \param cmd command.
306
 * \param arg argument.
307
 */
308
typedef int drm_ioctl_t(struct drm_device *dev, void *data,
309
			struct drm_file *file_priv);
310
 
311
typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
312
			       unsigned long arg);
313
 
314
#define DRM_IOCTL_NR(n)                _IOC_NR(n)
315
#define DRM_MAJOR       226
316
 
317
#define DRM_AUTH	0x1
318
#define	DRM_MASTER	0x2
319
#define DRM_ROOT_ONLY	0x4
320
#define DRM_CONTROL_ALLOW 0x8
321
#define DRM_UNLOCKED	0x10
322
 
323
struct drm_ioctl_desc {
324
	unsigned int cmd;
325
	int flags;
326
	drm_ioctl_t *func;
1964 serge 327
	unsigned int cmd_drv;
3747 Serge 328
	const char *name;
1408 serge 329
};
330
 
331
/**
332
 * Creates a driver or general drm_ioctl_desc array entry for the given
333
 * ioctl, for use by drm_ioctl().
334
 */
335
 
1964 serge 336
#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)			\
3747 Serge 337
	[DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
1964 serge 338
 
1408 serge 339
struct drm_magic_entry {
340
	struct list_head head;
341
	struct drm_hash_item hash_item;
342
	struct drm_file *priv;
343
};
344
 
345
struct drm_vma_entry {
346
	struct list_head head;
347
	struct vm_area_struct *vma;
348
	pid_t pid;
349
};
350
 
351
/**
352
 * DMA buffer.
353
 */
354
struct drm_buf {
355
	int idx;		       /**< Index into master buflist */
356
	int total;		       /**< Buffer size */
357
	int order;		       /**< log-base-2(total) */
358
	int used;		       /**< Amount of buffer in use (for DMA) */
359
	unsigned long offset;	       /**< Byte offset (used internally) */
360
	void *address;		       /**< Address of buffer */
361
	unsigned long bus_address;     /**< Bus address of buffer */
362
	struct drm_buf *next;	       /**< Kernel-only: used for free list */
363
	__volatile__ int waiting;      /**< On kernel DMA queue */
364
	__volatile__ int pending;      /**< On hardware DMA queue */
365
	struct drm_file *file_priv;    /**< Private of holding file descr */
366
	int context;		       /**< Kernel queue for this buffer */
367
	int while_locked;	       /**< Dispatch this buffer while locked */
368
	enum {
369
		DRM_LIST_NONE = 0,
370
		DRM_LIST_FREE = 1,
371
		DRM_LIST_WAIT = 2,
372
		DRM_LIST_PEND = 3,
373
		DRM_LIST_PRIO = 4,
374
		DRM_LIST_RECLAIM = 5
375
	} list;			       /**< Which list we're on */
376
 
377
	int dev_priv_size;		 /**< Size of buffer private storage */
378
	void *dev_private;		 /**< Per-buffer private storage */
379
};
380
 
381
/** bufs is one longer than it has to be */
382
struct drm_waitlist {
383
	int count;			/**< Number of possible buffers */
384
	struct drm_buf **bufs;		/**< List of pointers to buffers */
385
	struct drm_buf **rp;			/**< Read pointer */
386
	struct drm_buf **wp;			/**< Write pointer */
387
	struct drm_buf **end;		/**< End pointer */
388
	spinlock_t read_lock;
389
	spinlock_t write_lock;
390
};
391
 
392
struct drm_freelist {
393
	int initialized;	       /**< Freelist in use */
394
	atomic_t count;		       /**< Number of free buffers */
395
	struct drm_buf *next;	       /**< End pointer */
396
 
397
	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
398
	int low_mark;		       /**< Low water mark */
399
	int high_mark;		       /**< High water mark */
400
	atomic_t wfh;		       /**< If waiting for high mark */
401
	spinlock_t lock;
402
};
2967 Serge 403
#endif
1408 serge 404
 
405
typedef struct drm_dma_handle {
406
	dma_addr_t busaddr;
407
	void *vaddr;
408
	size_t size;
409
} drm_dma_handle_t;
410
 
2967 Serge 411
#if 0
1408 serge 412
/**
413
 * Buffer entry.  There is one of this for each buffer size order.
414
 */
415
struct drm_buf_entry {
416
	int buf_size;			/**< size */
417
	int buf_count;			/**< number of buffers */
418
	struct drm_buf *buflist;		/**< buffer list */
419
	int seg_count;
420
	int page_order;
421
	struct drm_dma_handle **seglist;
422
 
423
	struct drm_freelist freelist;
424
};
425
 
426
/* Event queued up for userspace to read */
427
struct drm_pending_event {
428
	struct drm_event *event;
429
	struct list_head link;
430
	struct drm_file *file_priv;
1964 serge 431
	pid_t pid; /* pid of requester, no guarantee it's valid by the time
432
		      we deliver the event, for tracing only */
1408 serge 433
	void (*destroy)(struct drm_pending_event *event);
434
};
435
 
3031 serge 436
/* initial implementaton using a linked list - todo hashtab */
437
struct drm_prime_file_private {
438
	struct list_head head;
439
	struct mutex lock;
440
};
3255 Serge 441
#endif
3031 serge 442
 
1408 serge 443
/** File private data */
444
struct drm_file {
445
	struct list_head lhead;
446
	unsigned long lock_count;
447
 
448
	/** Mapping of mm object handles to object pointers. */
449
	struct idr object_idr;
450
	/** Lock for synchronization of access to object_idr. */
451
	spinlock_t table_lock;
452
 
453
	void *driver_priv;
454
 
455
	struct list_head fbs;
456
 
457
	wait_queue_head_t event_wait;
458
	struct list_head event_list;
459
	int event_space;
460
};
461
 
3255 Serge 462
#if 0
1408 serge 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
 
2967 Serge 561
#endif
1408 serge 562
 
2967 Serge 563
 
1408 serge 564
/**
565
 * Kernel side of a mapping
566
 */
567
struct drm_local_map {
568
	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
569
	unsigned long size;	 /**< Requested physical size (bytes) */
570
	enum drm_map_type type;	 /**< Type of memory to map */
571
	enum drm_map_flags flags;	 /**< Flags */
572
	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
573
				 /**< Kernel-space: kernel-virtual address */
574
	int mtrr;		 /**< MTRR slot used */
575
};
576
 
577
typedef struct drm_local_map drm_local_map_t;
578
 
2967 Serge 579
#if 0
1408 serge 580
/**
581
 * Mappings list
582
 */
583
struct drm_map_list {
584
	struct list_head head;		/**< list head */
585
	struct drm_hash_item hash;
586
	struct drm_local_map *map;	/**< mapping */
587
	uint64_t user_token;
588
	struct drm_master *master;
589
	struct drm_mm_node *file_offset_node;	/**< fake offset */
590
};
591
 
592
/**
593
 * Context handle list
594
 */
595
struct drm_ctx_list {
596
	struct list_head head;		/**< list head */
597
	drm_context_t handle;		/**< context handle */
598
	struct drm_file *tag;		/**< associated fd private data */
599
};
600
 
601
/* location of GART table */
602
#define DRM_ATI_GART_MAIN 1
603
#define DRM_ATI_GART_FB   2
604
 
605
#define DRM_ATI_GART_PCI 1
606
#define DRM_ATI_GART_PCIE 2
607
#define DRM_ATI_GART_IGP 3
608
 
609
struct drm_ati_pcigart_info {
610
	int gart_table_location;
611
	int gart_reg_if;
612
	void *addr;
613
	dma_addr_t bus_addr;
614
	dma_addr_t table_mask;
615
	struct drm_dma_handle *table_handle;
616
	struct drm_local_map mapping;
617
	int table_size;
618
};
619
 
620
/**
621
 * GEM specific mm private for tracking GEM objects
622
 */
623
struct drm_gem_mm {
624
	struct drm_mm offset_manager;	/**< Offset mgmt for buffer objects */
625
	struct drm_open_hash offset_hash; /**< User token hash table for maps */
626
};
627
 
1987 serge 628
#endif
629
 
1408 serge 630
/**
631
 * This structure defines the drm_mm memory object, which will be used by the
632
 * DRM for its buffer objects.
633
 */
634
struct drm_gem_object {
635
	/** Reference count of this object */
636
	struct kref refcount;
637
 
638
	/** Handle count of this object. Each handle also holds a reference */
1964 serge 639
	atomic_t handle_count; /* number of handles on this object */
1408 serge 640
 
641
	/** Related drm device */
642
	struct drm_device *dev;
643
 
644
	/** File representing the shmem storage */
645
	struct file *filp;
646
 
647
	/* Mapping info for this object */
648
 
649
	/**
650
	 * Size of the object, in bytes.  Immutable over the object's
651
	 * lifetime.
652
	 */
653
	size_t size;
654
 
655
	/**
656
	 * Global name for this object, starts at 1. 0 means unnamed.
657
	 * Access is covered by the object_name_lock in the related drm_device
658
	 */
659
	int name;
660
 
661
	/**
662
	 * Memory domains. These monitor which caches contain read/write data
663
	 * related to the object. When transitioning from one set of domains
664
	 * to another, the driver is called to ensure that caches are suitably
665
	 * flushed and invalidated
666
	 */
667
	uint32_t read_domains;
668
	uint32_t write_domain;
669
 
670
	/**
671
	 * While validating an exec operation, the
672
	 * new read/write domain values are computed here.
673
	 * They will be transferred to the above values
674
	 * at the point that any cache flushing occurs
675
	 */
676
	uint32_t pending_read_domains;
677
	uint32_t pending_write_domain;
678
 
679
	void *driver_private;
680
};
681
 
3031 serge 682
#include 
1408 serge 683
 
684
/* per-master structure */
685
struct drm_master {
686
 
687
	struct kref refcount; /* refcount for this master */
688
 
689
	struct list_head head; /**< each minor contains a list of masters */
690
	struct drm_minor *minor; /**< link back to minor we are a master for */
691
 
692
	char *unique;			/**< Unique identifier: e.g., busid */
693
	int unique_len;			/**< Length of unique field */
694
	int unique_size;		/**< amount allocated */
695
 
696
	int blocked;			/**< Blocked due to VC switch? */
697
 
698
	/** \name Authentication */
699
	/*@{ */
2967 Serge 700
//   struct drm_open_hash magiclist;
701
//   struct list_head magicfree;
1408 serge 702
	/*@} */
703
 
2967 Serge 704
//   struct drm_lock_data lock;  /**< Information on hardware lock */
1408 serge 705
 
706
	void *driver_priv; /**< Private structure for driver to use */
707
};
708
 
2967 Serge 709
#if 0
710
 
1964 serge 711
/* Size of ringbuffer for vblank timestamps. Just double-buffer
712
 * in initial implementation.
713
 */
714
#define DRM_VBLANKTIME_RBSIZE 2
715
 
716
/* Flags and return codes for get_vblank_timestamp() driver function. */
717
#define DRM_CALLED_FROM_VBLIRQ 1
718
#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
719
#define DRM_VBLANKTIME_INVBL             (1 << 1)
720
 
721
/* get_scanout_position() return flags */
722
#define DRM_SCANOUTPOS_VALID        (1 << 0)
723
#define DRM_SCANOUTPOS_INVBL        (1 << 1)
724
#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
725
 
726
struct drm_bus {
727
	int bus_type;
728
	int (*get_irq)(struct drm_device *dev);
729
	const char *(*get_name)(struct drm_device *dev);
730
	int (*set_busid)(struct drm_device *dev, struct drm_master *master);
731
	int (*set_unique)(struct drm_device *dev, struct drm_master *master,
732
			  struct drm_unique *unique);
733
	int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
734
	/* hooks that are for PCI */
735
	int (*agp_init)(struct drm_device *dev);
736
 
737
};
738
 
1408 serge 739
/**
740
 * DRM driver structure. This structure represent the common code for
741
 * a family of cards. There will one drm_device for each card present
742
 * in this family
743
 */
744
struct drm_driver {
745
	int (*load) (struct drm_device *, unsigned long flags);
746
	int (*firstopen) (struct drm_device *);
747
	int (*open) (struct drm_device *, struct drm_file *);
748
	void (*preclose) (struct drm_device *, struct drm_file *file_priv);
749
	void (*postclose) (struct drm_device *, struct drm_file *);
750
	void (*lastclose) (struct drm_device *);
751
	int (*unload) (struct drm_device *);
752
	int (*suspend) (struct drm_device *, pm_message_t state);
753
	int (*resume) (struct drm_device *);
754
	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
755
	int (*dma_quiescent) (struct drm_device *);
756
	int (*context_dtor) (struct drm_device *dev, int context);
757
 
758
	/**
759
	 * get_vblank_counter - get raw hardware vblank counter
760
	 * @dev: DRM device
761
	 * @crtc: counter to fetch
762
	 *
3031 serge 763
	 * Driver callback for fetching a raw hardware vblank counter for @crtc.
764
	 * If a device doesn't have a hardware counter, the driver can simply
765
	 * return the value of drm_vblank_count. The DRM core will account for
766
	 * missed vblank events while interrupts where disabled based on system
767
	 * timestamps.
1408 serge 768
	 *
769
	 * Wraparound handling and loss of events due to modesetting is dealt
770
	 * with in the DRM core code.
771
	 *
772
	 * RETURNS
773
	 * Raw vblank counter value.
774
	 */
775
	u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
776
 
777
	/**
778
	 * enable_vblank - enable vblank interrupt events
779
	 * @dev: DRM device
780
	 * @crtc: which irq to enable
781
	 *
782
	 * Enable vblank interrupts for @crtc.  If the device doesn't have
783
	 * a hardware vblank counter, this routine should be a no-op, since
784
	 * interrupts will have to stay on to keep the count accurate.
785
	 *
786
	 * RETURNS
787
	 * Zero on success, appropriate errno if the given @crtc's vblank
788
	 * interrupt cannot be enabled.
789
	 */
790
	int (*enable_vblank) (struct drm_device *dev, int crtc);
791
 
792
	/**
793
	 * disable_vblank - disable vblank interrupt events
794
	 * @dev: DRM device
795
	 * @crtc: which irq to enable
796
	 *
797
	 * Disable vblank interrupts for @crtc.  If the device doesn't have
798
	 * a hardware vblank counter, this routine should be a no-op, since
799
	 * interrupts will have to stay on to keep the count accurate.
800
	 */
801
	void (*disable_vblank) (struct drm_device *dev, int crtc);
802
 
803
	/**
804
	 * Called by \c drm_device_is_agp.  Typically used to determine if a
805
	 * card is really attached to AGP or not.
806
	 *
807
	 * \param dev  DRM device handle
808
	 *
809
	 * \returns
810
	 * One of three values is returned depending on whether or not the
811
	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
812
	 * (return of 1), or may or may not be AGP (return of 2).
813
	 */
814
	int (*device_is_agp) (struct drm_device *dev);
815
 
1964 serge 816
	/**
817
	 * Called by vblank timestamping code.
818
	 *
819
	 * Return the current display scanout position from a crtc.
820
	 *
821
	 * \param dev  DRM device.
822
	 * \param crtc Id of the crtc to query.
823
	 * \param *vpos Target location for current vertical scanout position.
824
	 * \param *hpos Target location for current horizontal scanout position.
825
	 *
826
	 * Returns vpos as a positive number while in active scanout area.
827
	 * Returns vpos as a negative number inside vblank, counting the number
828
	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
829
	 * until start of active scanout / end of vblank."
830
	 *
831
	 * \return Flags, or'ed together as follows:
832
	 *
833
	 * DRM_SCANOUTPOS_VALID = Query successful.
834
	 * DRM_SCANOUTPOS_INVBL = Inside vblank.
835
	 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
836
	 * this flag means that returned position may be offset by a constant
837
	 * but unknown small number of scanlines wrt. real scanout position.
838
	 *
839
	 */
840
	int (*get_scanout_position) (struct drm_device *dev, int crtc,
841
				     int *vpos, int *hpos);
842
 
843
	/**
844
	 * Called by \c drm_get_last_vbltimestamp. Should return a precise
845
	 * timestamp when the most recent VBLANK interval ended or will end.
846
	 *
847
	 * Specifically, the timestamp in @vblank_time should correspond as
848
	 * closely as possible to the time when the first video scanline of
849
	 * the video frame after the end of VBLANK will start scanning out,
2967 Serge 850
	 * the time immediately after end of the VBLANK interval. If the
1964 serge 851
	 * @crtc is currently inside VBLANK, this will be a time in the future.
852
	 * If the @crtc is currently scanning out a frame, this will be the
853
	 * past start time of the current scanout. This is meant to adhere
854
	 * to the OpenML OML_sync_control extension specification.
855
	 *
856
	 * \param dev dev DRM device handle.
857
	 * \param crtc crtc for which timestamp should be returned.
858
	 * \param *max_error Maximum allowable timestamp error in nanoseconds.
859
	 *                   Implementation should strive to provide timestamp
860
	 *                   with an error of at most *max_error nanoseconds.
861
	 *                   Returns true upper bound on error for timestamp.
862
	 * \param *vblank_time Target location for returned vblank timestamp.
863
	 * \param flags 0 = Defaults, no special treatment needed.
864
	 * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
865
	 *	        irq handler. Some drivers need to apply some workarounds
866
	 *              for gpu-specific vblank irq quirks if flag is set.
867
	 *
868
	 * \returns
869
	 * Zero if timestamping isn't supported in current display mode or a
870
	 * negative number on failure. A positive status code on success,
871
	 * which describes how the vblank_time timestamp was computed.
872
	 */
873
	int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
874
				     int *max_error,
875
				     struct timeval *vblank_time,
876
				     unsigned flags);
877
 
1408 serge 878
	/* these have to be filled in */
879
 
880
	irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
881
	void (*irq_preinstall) (struct drm_device *dev);
882
	int (*irq_postinstall) (struct drm_device *dev);
883
	void (*irq_uninstall) (struct drm_device *dev);
884
	void (*set_version) (struct drm_device *dev,
885
			     struct drm_set_version *sv);
886
 
887
	/* Master routines */
888
	int (*master_create)(struct drm_device *dev, struct drm_master *master);
889
	void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
890
	/**
891
	 * master_set is called whenever the minor master is set.
892
	 * master_drop is called whenever the minor master is dropped.
893
	 */
894
 
895
	int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
896
			  bool from_open);
897
	void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
898
			    bool from_release);
899
 
900
	int (*debugfs_init)(struct drm_minor *minor);
901
	void (*debugfs_cleanup)(struct drm_minor *minor);
902
 
903
	/**
904
	 * Driver-specific constructor for drm_gem_objects, to set up
905
	 * obj->driver_private.
906
	 *
907
	 * Returns 0 on success.
908
	 */
909
	int (*gem_init_object) (struct drm_gem_object *obj);
910
	void (*gem_free_object) (struct drm_gem_object *obj);
2967 Serge 911
	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
912
	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
1408 serge 913
 
3031 serge 914
	/* prime: */
915
	/* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
916
	int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
917
				uint32_t handle, uint32_t flags, int *prime_fd);
918
	/* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
919
	int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
920
				int prime_fd, uint32_t *handle);
921
	/* export GEM -> dmabuf */
922
	struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
923
				struct drm_gem_object *obj, int flags);
924
	/* import dmabuf -> GEM */
925
	struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
926
				struct dma_buf *dma_buf);
927
 
1408 serge 928
	/* vga arb irq handler */
929
	void (*vgaarb_irq)(struct drm_device *dev, bool state);
930
 
2967 Serge 931
	/* dumb alloc support */
932
	int (*dumb_create)(struct drm_file *file_priv,
933
			   struct drm_device *dev,
934
			   struct drm_mode_create_dumb *args);
935
	int (*dumb_map_offset)(struct drm_file *file_priv,
936
			       struct drm_device *dev, uint32_t handle,
937
			       uint64_t *offset);
938
	int (*dumb_destroy)(struct drm_file *file_priv,
939
			    struct drm_device *dev,
940
			    uint32_t handle);
941
 
1408 serge 942
	/* Driver private ops for this object */
3031 serge 943
	const struct vm_operations_struct *gem_vm_ops;
1408 serge 944
 
945
	int major;
946
	int minor;
947
	int patchlevel;
948
	char *name;
949
	char *desc;
950
	char *date;
951
 
952
	u32 driver_features;
953
	int dev_priv_size;
954
	struct drm_ioctl_desc *ioctls;
955
	int num_ioctls;
2967 Serge 956
	const struct file_operations *fops;
957
	union {
958
		struct pci_driver *pci;
959
		struct platform_device *platform_device;
960
		struct usb_driver *usb;
961
	} kdriver;
962
	struct drm_bus *bus;
963
 
1408 serge 964
	/* List of devices hanging off this driver */
965
	struct list_head device_list;
966
};
967
 
2967 Serge 968
#endif
969
 
3243 Serge 970
#define DRM_IRQ_ARGS            int irq, void *arg
971
 
972
struct drm_driver {
3262 Serge 973
	int (*open) (struct drm_device *, struct drm_file *);
974
 
3243 Serge 975
    irqreturn_t (*irq_handler) (DRM_IRQ_ARGS);
976
    void (*irq_preinstall) (struct drm_device *dev);
977
    int (*irq_postinstall) (struct drm_device *dev);
3262 Serge 978
 
979
	int (*gem_init_object) (struct drm_gem_object *obj);
980
	void (*gem_free_object) (struct drm_gem_object *obj);
3255 Serge 981
	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
982
	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
3482 Serge 983
	u32 driver_features;
3243 Serge 984
};
985
 
986
 
1408 serge 987
#define DRM_MINOR_UNASSIGNED 0
988
#define DRM_MINOR_LEGACY 1
989
#define DRM_MINOR_CONTROL 2
990
#define DRM_MINOR_RENDER 3
991
 
992
 
993
/**
994
 * debugfs node list. This structure represents a debugfs file to
995
 * be created by the drm core
996
 */
997
struct drm_debugfs_list {
998
	const char *name; /** file name */
2967 Serge 999
//   int (*show)(struct seq_file*, void*); /** show callback */
1408 serge 1000
	u32 driver_features; /**< Required driver features for this entry */
1001
};
1002
 
1003
/**
1004
 * debugfs node structure. This structure represents a debugfs file.
1005
 */
1006
struct drm_debugfs_node {
1007
	struct list_head list;
1008
	struct drm_minor *minor;
1009
	struct drm_debugfs_list *debugfs_ent;
1010
	struct dentry *dent;
1011
};
1012
 
1013
/**
1014
 * Info file list entry. This structure represents a debugfs or proc file to
1015
 * be created by the drm core
1016
 */
1017
struct drm_info_list {
1018
	const char *name; /** file name */
2967 Serge 1019
//   int (*show)(struct seq_file*, void*); /** show callback */
1408 serge 1020
	u32 driver_features; /**< Required driver features for this entry */
1021
	void *data;
1022
};
1023
 
1024
/**
1025
 * debugfs node structure. This structure represents a debugfs file.
1026
 */
1027
struct drm_info_node {
1028
	struct list_head list;
1029
	struct drm_minor *minor;
1030
	struct drm_info_list *info_ent;
1031
	struct dentry *dent;
1032
};
1033
 
1034
/**
1035
 * DRM minor structure. This structure represents a drm minor number.
1036
 */
1037
struct drm_minor {
1038
	int index;			/**< Minor device number */
1039
	int type;                       /**< Control or render */
2967 Serge 1040
//   dev_t device;           /**< Device number for mknod */
1041
//   struct device kdev;     /**< Linux device */
1408 serge 1042
	struct drm_device *dev;
1043
 
2967 Serge 1044
//   struct proc_dir_entry *proc_root;  /**< proc directory entry */
1045
//   struct drm_info_node proc_nodes;
1046
//   struct dentry *debugfs_root;
1047
//   struct drm_info_node debugfs_nodes;
1408 serge 1048
 
2967 Serge 1049
    struct drm_master *master; /* currently active master for this node */
1050
//   struct list_head master_list;
1051
//   struct drm_mode_group mode_group;
1408 serge 1052
};
1053
 
1964 serge 1054
/* mode specified on the command line */
1055
struct drm_cmdline_mode {
1056
	bool specified;
1057
	bool refresh_specified;
1058
	bool bpp_specified;
1059
	int xres, yres;
1060
	int bpp;
1061
	int refresh;
1062
	bool rb;
1063
	bool interlace;
1064
	bool cvt;
1065
	bool margins;
1066
	enum drm_connector_force force;
1067
};
1408 serge 1068
 
1069
 
1070
 
1071
/**
1072
 * DRM device structure. This structure represent a complete card that
1073
 * may contain multiple heads.
1074
 */
1075
struct drm_device {
1076
	struct list_head driver_item;	/**< list of devices per driver */
1077
	char *devname;			/**< For /proc/interrupts */
1078
	int if_version;			/**< Highest interface version set */
1079
 
1080
	/** \name Locks */
1081
	/*@{ */
1082
    spinlock_t count_lock;      /**< For inuse, drm_device::open_count, drm_device::buf_use */
1630 serge 1083
	struct mutex struct_mutex;	/**< For others */
1408 serge 1084
	/*@} */
1085
 
1086
	/** \name Usage Counters */
1087
	/*@{ */
1088
	int open_count;			/**< Outstanding files open */
1089
   atomic_t ioctl_count;       /**< Outstanding IOCTLs pending */
1090
   atomic_t vma_count;     /**< Outstanding vma areas open */
1091
	int buf_use;			/**< Buffers in use -- cannot alloc */
1092
   atomic_t buf_alloc;     /**< Buffer allocation in progress */
1093
	/*@} */
1094
 
1095
	/** \name Performance counters */
1096
	/*@{ */
1097
	unsigned long counters;
1098
//   enum drm_stat_type types[15];
1099
   atomic_t counts[15];
1100
	/*@} */
1101
 
1102
	struct list_head filelist;
1103
 
1104
	/** \name Memory management */
1105
	/*@{ */
1106
	struct list_head maplist;	/**< Linked list of regions */
1107
	int map_count;			/**< Number of mappable regions */
1108
//   struct drm_open_hash map_hash;  /**< User token hash table for maps */
1109
 
1110
	/** \name Context handle management */
1111
	/*@{ */
1112
	struct list_head ctxlist;	/**< Linked list of context handles */
1113
	int ctx_count;			/**< Number of context handles */
1630 serge 1114
	struct mutex ctxlist_mutex;	/**< For ctxlist */
1408 serge 1115
 
1964 serge 1116
	struct idr ctx_idr;
1408 serge 1117
 
1118
	struct list_head vmalist;	/**< List of vmas (for debugging) */
1119
 
1120
	/*@} */
1121
 
3031 serge 1122
	/** \name DMA support */
1408 serge 1123
	/*@{ */
1124
//   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
1125
	/*@} */
1126
 
1127
	/** \name Context support */
1128
	/*@{ */
1129
	int irq_enabled;		/**< True if irq handler is enabled */
1130
	__volatile__ long context_flag;	/**< Context swapping flag */
1131
	__volatile__ long interrupt_flag; /**< Interruption handler flag */
1132
	__volatile__ long dma_flag;	/**< DMA dispatch flag */
1133
//   wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1134
	int last_checked;		/**< Last context checked for DMA */
1135
	int last_context;		/**< Last current context */
1136
	unsigned long last_switch;	/**< jiffies at last context switch */
1137
	/*@} */
1138
 
1139
//   struct work_struct work;
1140
	/** \name VBLANK IRQ support */
1141
	/*@{ */
1142
 
1143
	/*
1144
	 * At load time, disabling the vblank interrupt won't be allowed since
1145
	 * old clients may not call the modeset ioctl and therefore misbehave.
1146
	 * Once the modeset ioctl *has* been called though, we can safely
1147
	 * disable them when unused.
1148
	 */
1149
	int vblank_disable_allowed;
1150
 
1151
//   wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
1152
   atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
1964 serge 1153
	struct timeval *_vblank_time;   /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
1154
	spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
1408 serge 1155
   spinlock_t vbl_lock;
1156
   atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
1157
	u32 *last_vblank;               /* protected by dev->vbl_lock, used */
1158
					/* for wraparound handling */
1159
	int *vblank_enabled;            /* so we don't call enable more than
1160
					   once per disable */
1161
	int *vblank_inmodeset;          /* Display driver is setting mode */
1162
	u32 *last_vblank_wait;		/* Last vblank seqno waited per CRTC */
1163
//   struct timer_list vblank_disable_timer;
1164
 
1165
	u32 max_vblank_count;           /**< size of vblank counter register */
1166
 
1964 serge 1167
	/**
1168
	 * List of events
1169
	 */
1170
	struct list_head vblank_event_list;
1171
	spinlock_t event_lock;
1172
 
1408 serge 1173
	/*@} */
1174
//   cycles_t ctx_start;
1175
//   cycles_t lck_start;
1176
 
1177
//   struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
1178
//   wait_queue_head_t buf_readers;  /**< Processes waiting to read */
1179
//   wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
1180
 
1181
//   struct drm_agp_head *agp;   /**< AGP data */
1182
 
1964 serge 1183
	struct device *dev;             /**< Device structure */
1408 serge 1184
	struct pci_dev *pdev;		/**< PCI device structure */
1185
	int pci_vendor;			/**< PCI vendor id */
1186
	int pci_device;			/**< PCI device id */
1964 serge 1187
	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1408 serge 1188
	void *dev_private;		/**< device private data */
1189
	void *mm_private;
1190
    struct address_space *dev_mapping;
1191
//   struct drm_sigdata sigdata;    /**< For block_all_signals */
1192
//   sigset_t sigmask;
1193
 
3243 Serge 1194
	struct drm_driver *driver;
1408 serge 1195
//   struct drm_local_map *agp_buffer_map;
1196
//   unsigned int agp_buffer_token;
1197
//   struct drm_minor *control;      /**< Control node for card */
2967 Serge 1198
   struct drm_minor *primary;      /**< render type primary screen head */
1408 serge 1199
 
1200
        struct drm_mode_config mode_config;	/**< Current mode config */
1201
 
1202
	/** \name GEM information */
1203
	/*@{ */
1204
   spinlock_t object_name_lock;
1964 serge 1205
	struct idr object_name_idr;
1408 serge 1206
	/*@} */
1964 serge 1207
	int switch_power_state;
3031 serge 1208
 
1209
	atomic_t unplugged; /* device has been unplugged or gone away */
1408 serge 1210
};
1211
 
1964 serge 1212
#define DRM_SWITCH_POWER_ON 0
1213
#define DRM_SWITCH_POWER_OFF 1
1214
#define DRM_SWITCH_POWER_CHANGING 2
1215
 
3482 Serge 1216
static __inline__ int drm_core_check_feature(struct drm_device *dev,
1217
					     int feature)
1218
{
1219
	return ((dev->driver->driver_features & feature) ? 1 : 0);
1220
}
1964 serge 1221
 
1408 serge 1222
static inline int drm_dev_to_irq(struct drm_device *dev)
1223
{
1224
	return dev->pdev->irq;
1225
}
1226
 
2967 Serge 1227
#if 0
1408 serge 1228
 
1229
#ifdef __alpha__
1230
#define drm_get_pci_domain(dev) dev->hose->index
1231
#else
1232
#define drm_get_pci_domain(dev) 0
1233
#endif
1234
 
1235
#if __OS_HAS_AGP
1236
static inline int drm_core_has_AGP(struct drm_device *dev)
1237
{
1238
	return drm_core_check_feature(dev, DRIVER_USE_AGP);
1239
}
1240
#else
1241
#define drm_core_has_AGP(dev) (0)
1242
#endif
1243
 
1244
#if __OS_HAS_MTRR
1245
static inline int drm_core_has_MTRR(struct drm_device *dev)
1246
{
1247
	return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1248
}
1249
 
1250
#define DRM_MTRR_WC		MTRR_TYPE_WRCOMB
1251
 
1252
static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1253
			       unsigned int flags)
1254
{
1255
	return mtrr_add(offset, size, flags, 1);
1256
}
1257
 
1258
static inline int drm_mtrr_del(int handle, unsigned long offset,
1259
			       unsigned long size, unsigned int flags)
1260
{
1261
	return mtrr_del(handle, offset, size);
1262
}
1263
 
1264
#else
1265
#define drm_core_has_MTRR(dev) (0)
1266
 
1267
#define DRM_MTRR_WC		0
1268
 
1269
static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1270
			       unsigned int flags)
1271
{
1272
	return 0;
1273
}
1274
 
1275
static inline int drm_mtrr_del(int handle, unsigned long offset,
1276
			       unsigned long size, unsigned int flags)
1277
{
1278
	return 0;
1279
}
1280
#endif
1281
 
1282
/******************************************************************/
1283
/** \name Internal function definitions */
1284
/*@{*/
1285
 
1286
				/* Driver support (drm_drv.h) */
1287
extern long drm_ioctl(struct file *filp,
1288
		     unsigned int cmd, unsigned long arg);
1289
extern long drm_compat_ioctl(struct file *filp,
1290
			     unsigned int cmd, unsigned long arg);
1291
extern int drm_lastclose(struct drm_device *dev);
1292
 
1293
				/* Device support (drm_fops.h) */
1964 serge 1294
extern struct mutex drm_global_mutex;
1408 serge 1295
extern int drm_open(struct inode *inode, struct file *filp);
1296
extern int drm_stub_open(struct inode *inode, struct file *filp);
1297
extern int drm_fasync(int fd, struct file *filp, int on);
1298
extern ssize_t drm_read(struct file *filp, char __user *buffer,
1299
			size_t count, loff_t *offset);
1300
extern int drm_release(struct inode *inode, struct file *filp);
1301
 
1302
				/* Mapping support (drm_vm.h) */
1303
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1304
extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
3031 serge 1305
extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1306
extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1408 serge 1307
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1308
 
1309
				/* Memory management support (drm_memory.h) */
3031 serge 1310
#include 
1964 serge 1311
extern void drm_free_agp(DRM_AGP_MEM * handle, int pages);
1408 serge 1312
extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1313
extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1314
				       struct page **pages,
1315
				       unsigned long num_pages,
1316
				       uint32_t gtt_offset,
1317
				       uint32_t type);
1318
extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1319
 
1320
				/* Misc. IOCTL support (drm_ioctl.h) */
1321
extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1322
			    struct drm_file *file_priv);
1323
extern int drm_getunique(struct drm_device *dev, void *data,
1324
			 struct drm_file *file_priv);
1325
extern int drm_setunique(struct drm_device *dev, void *data,
1326
			 struct drm_file *file_priv);
1327
extern int drm_getmap(struct drm_device *dev, void *data,
1328
		      struct drm_file *file_priv);
1329
extern int drm_getclient(struct drm_device *dev, void *data,
1330
			 struct drm_file *file_priv);
1331
extern int drm_getstats(struct drm_device *dev, void *data,
1332
			struct drm_file *file_priv);
1964 serge 1333
extern int drm_getcap(struct drm_device *dev, void *data,
1334
		      struct drm_file *file_priv);
1408 serge 1335
extern int drm_setversion(struct drm_device *dev, void *data,
1336
			  struct drm_file *file_priv);
1337
extern int drm_noop(struct drm_device *dev, void *data,
1338
		    struct drm_file *file_priv);
1339
 
1340
				/* Context IOCTL support (drm_context.h) */
1341
extern int drm_resctx(struct drm_device *dev, void *data,
1342
		      struct drm_file *file_priv);
1343
extern int drm_addctx(struct drm_device *dev, void *data,
1344
		      struct drm_file *file_priv);
1345
extern int drm_modctx(struct drm_device *dev, void *data,
1346
		      struct drm_file *file_priv);
1347
extern int drm_getctx(struct drm_device *dev, void *data,
1348
		      struct drm_file *file_priv);
1349
extern int drm_switchctx(struct drm_device *dev, void *data,
1350
			 struct drm_file *file_priv);
1351
extern int drm_newctx(struct drm_device *dev, void *data,
1352
		      struct drm_file *file_priv);
1353
extern int drm_rmctx(struct drm_device *dev, void *data,
1354
		     struct drm_file *file_priv);
1355
 
1356
extern int drm_ctxbitmap_init(struct drm_device *dev);
1357
extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1358
extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1359
 
1360
extern int drm_setsareactx(struct drm_device *dev, void *data,
1361
			   struct drm_file *file_priv);
1362
extern int drm_getsareactx(struct drm_device *dev, void *data,
1363
			   struct drm_file *file_priv);
1364
 
1365
				/* Authentication IOCTL support (drm_auth.h) */
1366
extern int drm_getmagic(struct drm_device *dev, void *data,
1367
			struct drm_file *file_priv);
1368
extern int drm_authmagic(struct drm_device *dev, void *data,
1369
			 struct drm_file *file_priv);
2967 Serge 1370
extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1408 serge 1371
 
1372
/* Cache management (drm_cache.c) */
1373
void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
3031 serge 1374
void drm_clflush_sg(struct sg_table *st);
1375
void drm_clflush_virt_range(char *addr, unsigned long length);
1408 serge 1376
 
1377
				/* Locking IOCTL support (drm_lock.h) */
1378
extern int drm_lock(struct drm_device *dev, void *data,
1379
		    struct drm_file *file_priv);
1380
extern int drm_unlock(struct drm_device *dev, void *data,
1381
		      struct drm_file *file_priv);
1382
extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1383
extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1384
extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1385
 
1386
/*
1387
 * These are exported to drivers so that they can implement fencing using
1388
 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1389
 */
1390
 
1391
extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1392
 
1393
				/* Buffer management support (drm_bufs.h) */
1394
extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1395
extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1396
extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1397
		      unsigned int size, enum drm_map_type type,
1398
		      enum drm_map_flags flags, struct drm_local_map **map_ptr);
1399
extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1400
			    struct drm_file *file_priv);
1401
extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1402
extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1403
extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1404
			   struct drm_file *file_priv);
1405
extern int drm_addbufs(struct drm_device *dev, void *data,
1406
		       struct drm_file *file_priv);
1407
extern int drm_infobufs(struct drm_device *dev, void *data,
1408
			struct drm_file *file_priv);
1409
extern int drm_markbufs(struct drm_device *dev, void *data,
1410
			struct drm_file *file_priv);
1411
extern int drm_freebufs(struct drm_device *dev, void *data,
1412
			struct drm_file *file_priv);
1413
extern int drm_mapbufs(struct drm_device *dev, void *data,
1414
		       struct drm_file *file_priv);
1415
extern int drm_order(unsigned long size);
1416
 
1417
				/* DMA support (drm_dma.h) */
1418
extern int drm_dma_setup(struct drm_device *dev);
1419
extern void drm_dma_takedown(struct drm_device *dev);
1420
extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1421
extern void drm_core_reclaim_buffers(struct drm_device *dev,
1422
				     struct drm_file *filp);
1423
 
1424
				/* IRQ support (drm_irq.h) */
1425
extern int drm_control(struct drm_device *dev, void *data,
1426
		       struct drm_file *file_priv);
1427
extern int drm_irq_install(struct drm_device *dev);
1428
extern int drm_irq_uninstall(struct drm_device *dev);
1429
 
1430
extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1431
extern int drm_wait_vblank(struct drm_device *dev, void *data,
1432
			   struct drm_file *filp);
1433
extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1434
extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1964 serge 1435
extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1436
				     struct timeval *vblanktime);
3391 Serge 1437
extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1438
				     struct drm_pending_vblank_event *e);
1964 serge 1439
extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1408 serge 1440
extern int drm_vblank_get(struct drm_device *dev, int crtc);
1441
extern void drm_vblank_put(struct drm_device *dev, int crtc);
1442
extern void drm_vblank_off(struct drm_device *dev, int crtc);
1443
extern void drm_vblank_cleanup(struct drm_device *dev);
1964 serge 1444
extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1445
				     struct timeval *tvblank, unsigned flags);
1446
extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1447
						 int crtc, int *max_error,
1448
						 struct timeval *vblank_time,
1449
						 unsigned flags,
1450
						 struct drm_crtc *refcrtc);
1451
extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1452
 
1453
extern bool
1454
drm_mode_parse_command_line_for_connector(const char *mode_option,
1455
					  struct drm_connector *connector,
1456
					  struct drm_cmdline_mode *mode);
1457
 
1458
extern struct drm_display_mode *
1459
drm_mode_create_from_cmdline_mode(struct drm_device *dev,
1460
				  struct drm_cmdline_mode *cmd);
1461
 
3391 Serge 1462
extern int drm_display_mode_from_videomode(const struct videomode *vm,
1463
					   struct drm_display_mode *dmode);
1464
extern int of_get_drm_display_mode(struct device_node *np,
1465
				   struct drm_display_mode *dmode,
1466
				   int index);
1467
 
1408 serge 1468
/* Modesetting support */
1469
extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1470
extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1471
extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1472
			   struct drm_file *file_priv);
1473
 
1474
				/* AGP/GART support (drm_agpsupport.h) */
1475
extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1476
extern int drm_agp_acquire(struct drm_device *dev);
1477
extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1478
				 struct drm_file *file_priv);
1479
extern int drm_agp_release(struct drm_device *dev);
1480
extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1481
				 struct drm_file *file_priv);
1482
extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1483
extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1484
				struct drm_file *file_priv);
1485
extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1486
extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1487
			struct drm_file *file_priv);
1488
extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1489
extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1490
			 struct drm_file *file_priv);
1491
extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1492
extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1493
			struct drm_file *file_priv);
1494
extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1495
extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1496
			  struct drm_file *file_priv);
1497
extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1498
extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1499
			struct drm_file *file_priv);
1500
 
1501
				/* Stub support (drm_stub.h) */
1502
extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1503
			       struct drm_file *file_priv);
1504
extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1505
				struct drm_file *file_priv);
1506
struct drm_master *drm_master_create(struct drm_minor *minor);
1507
extern struct drm_master *drm_master_get(struct drm_master *master);
1508
extern void drm_master_put(struct drm_master **master);
1964 serge 1509
 
1408 serge 1510
extern void drm_put_dev(struct drm_device *dev);
1511
extern int drm_put_minor(struct drm_minor **minor);
3031 serge 1512
extern void drm_unplug_dev(struct drm_device *dev);
1513
#endif
1514
 
1408 serge 1515
extern unsigned int drm_debug;
1516
 
3031 serge 1517
#if 0
1964 serge 1518
extern unsigned int drm_vblank_offdelay;
1519
extern unsigned int drm_timestamp_precision;
3192 Serge 1520
extern unsigned int drm_timestamp_monotonic;
1964 serge 1521
 
1408 serge 1522
extern struct class *drm_class;
1523
extern struct proc_dir_entry *drm_proc_root;
1524
extern struct dentry *drm_debugfs_root;
1525
 
1526
extern struct idr drm_minors_idr;
1527
 
1528
extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
1529
 
1530
				/* Proc support (drm_proc.h) */
1531
extern int drm_proc_init(struct drm_minor *minor, int minor_id,
1532
			 struct proc_dir_entry *root);
1533
extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1534
 
1535
				/* Debugfs support */
1536
#if defined(CONFIG_DEBUG_FS)
1537
extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1538
			    struct dentry *root);
1539
extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
1540
				    struct dentry *root, struct drm_minor *minor);
1541
extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
1542
                                    struct drm_minor *minor);
1543
extern int drm_debugfs_cleanup(struct drm_minor *minor);
1544
#endif
1545
 
1546
				/* Info file support */
1547
extern int drm_name_info(struct seq_file *m, void *data);
1548
extern int drm_vm_info(struct seq_file *m, void *data);
1549
extern int drm_bufs_info(struct seq_file *m, void *data);
1550
extern int drm_vblank_info(struct seq_file *m, void *data);
1551
extern int drm_clients_info(struct seq_file *m, void* data);
1552
extern int drm_gem_name_info(struct seq_file *m, void *data);
1553
 
1554
#if DRM_DEBUG_CODE
1555
extern int drm_vma_info(struct seq_file *m, void *data);
1556
#endif
1557
 
1558
				/* Scatter Gather Support (drm_scatter.h) */
1559
extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1560
extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1561
			struct drm_file *file_priv);
1562
extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1563
extern int drm_sg_free(struct drm_device *dev, void *data,
1564
		       struct drm_file *file_priv);
1565
 
1566
			       /* ATI PCIGART support (ati_pcigart.h) */
1567
extern int drm_ati_pcigart_init(struct drm_device *dev,
1568
				struct drm_ati_pcigart_info * gart_info);
1569
extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1570
				   struct drm_ati_pcigart_info * gart_info);
3031 serge 1571
#endif
1408 serge 1572
 
1573
extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1428 serge 1574
				       size_t align);
1408 serge 1575
extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1576
extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1577
 
3031 serge 1578
#if 0
1408 serge 1579
			       /* sysfs support (drm_sysfs.c) */
1580
struct drm_sysfs_class;
1581
extern struct class *drm_sysfs_create(struct module *owner, char *name);
1582
extern void drm_sysfs_destroy(void);
1583
extern int drm_sysfs_device_add(struct drm_minor *minor);
1584
extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1585
extern void drm_sysfs_device_remove(struct drm_minor *minor);
1586
extern char *drm_get_connector_status_name(enum drm_connector_status status);
1587
 
1588
static inline int drm_sysfs_connector_add(struct drm_connector *connector)
1589
{ return 0; };
1590
 
1591
static inline void drm_sysfs_connector_remove(struct drm_connector *connector)
1592
{ };
1593
 
2967 Serge 1594
#endif
1595
 
1408 serge 1596
/* Graphics Execution Manager library functions (drm_gem.c) */
1597
int drm_gem_init(struct drm_device *dev);
1598
void drm_gem_destroy(struct drm_device *dev);
1964 serge 1599
void drm_gem_object_release(struct drm_gem_object *obj);
1408 serge 1600
void drm_gem_object_free(struct kref *kref);
1601
struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1602
					    size_t size);
1964 serge 1603
int drm_gem_object_init(struct drm_device *dev,
1604
			struct drm_gem_object *obj, size_t size);
2967 Serge 1605
int drm_gem_private_object_init(struct drm_device *dev,
1606
			struct drm_gem_object *obj, size_t size);
1964 serge 1607
void drm_gem_object_handle_free(struct drm_gem_object *obj);
1408 serge 1608
void drm_gem_vm_open(struct vm_area_struct *vma);
1609
void drm_gem_vm_close(struct vm_area_struct *vma);
1610
int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1611
 
2967 Serge 1612
 
1408 serge 1613
static inline void
1614
drm_gem_object_reference(struct drm_gem_object *obj)
1615
{
1616
	kref_get(&obj->refcount);
1617
}
1618
 
1619
static inline void
1620
drm_gem_object_unreference(struct drm_gem_object *obj)
1621
{
2967 Serge 1622
	if (obj != NULL)
1623
		kref_put(&obj->refcount, drm_gem_object_free);
1624
}
1408 serge 1625
 
2967 Serge 1626
static inline void
1627
drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1628
{
1629
	if (obj != NULL) {
1630
		struct drm_device *dev = obj->dev;
1631
		mutex_lock(&dev->struct_mutex);
1408 serge 1632
	kref_put(&obj->refcount, drm_gem_object_free);
2967 Serge 1633
		mutex_unlock(&dev->struct_mutex);
1634
	}
1408 serge 1635
}
1636
 
1637
int drm_gem_handle_create(struct drm_file *file_priv,
1638
			  struct drm_gem_object *obj,
1639
			  u32 *handlep);
1987 serge 1640
int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1408 serge 1641
 
1642
static inline void
1643
drm_gem_object_handle_reference(struct drm_gem_object *obj)
1644
{
1645
	drm_gem_object_reference(obj);
1987 serge 1646
	atomic_inc(&obj->handle_count);
1408 serge 1647
}
1648
 
1649
static inline void
1650
drm_gem_object_handle_unreference(struct drm_gem_object *obj)
1651
{
1652
	if (obj == NULL)
1653
		return;
1654
 
1987 serge 1655
	if (atomic_read(&obj->handle_count) == 0)
1656
		return;
1408 serge 1657
	/*
1658
	 * Must bump handle count first as this may be the last
1659
	 * ref, in which case the object would disappear before we
1660
	 * checked for a name
1661
	 */
2967 Serge 1662
	if (atomic_dec_and_test(&obj->handle_count))
1663
		drm_gem_object_handle_free(obj);
1408 serge 1664
	drm_gem_object_unreference(obj);
1665
}
1666
 
2967 Serge 1667
static inline void
1668
drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
1669
{
1670
	if (obj == NULL)
1671
		return;
1672
 
1673
	if (atomic_read(&obj->handle_count) == 0)
1674
		return;
1675
 
1676
	/*
1677
	* Must bump handle count first as this may be the last
1678
	* ref, in which case the object would disappear before we
1679
	* checked for a name
1680
	*/
1681
 
1682
	if (atomic_dec_and_test(&obj->handle_count))
1683
		drm_gem_object_handle_free(obj);
1684
	drm_gem_object_unreference_unlocked(obj);
1685
}
1686
 
3192 Serge 1687
void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1688
int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
2967 Serge 1689
 
1408 serge 1690
struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1691
					     struct drm_file *filp,
1692
					     u32 handle);
1693
int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1694
			struct drm_file *file_priv);
1695
int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1696
			struct drm_file *file_priv);
1697
int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1698
		       struct drm_file *file_priv);
1699
void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1700
void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1701
 
1702
extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1703
extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1704
extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1705
 
3255 Serge 1706
#if 0
1707
 
1408 serge 1708
static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1709
							 unsigned int token)
1710
{
1711
	struct drm_map_list *_entry;
1712
	list_for_each_entry(_entry, &dev->maplist, head)
1713
	    if (_entry->user_token == token)
1714
		return _entry->map;
1715
	return NULL;
1716
}
1717
 
1718
static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1719
{
1720
}
1721
 
1722
 
3031 serge 1723
 
1408 serge 1724
static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
1725
{
1726
	if (size * nmemb <= PAGE_SIZE)
1727
	    return kcalloc(nmemb, size, GFP_KERNEL);
1728
 
1729
	if (size != 0 && nmemb > ULONG_MAX / size)
1730
		return NULL;
1731
 
1732
	return __vmalloc(size * nmemb,
1733
			 GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
1734
}
1735
 
1736
static __inline void drm_free_large(void *ptr)
1737
{
1738
	if (!is_vmalloc_addr(ptr))
1739
		return kfree(ptr);
1740
 
1741
	vfree(ptr);
1742
}
1743
 
1744
#endif
1745
 
3031 serge 1746
#define DRM_PCIE_SPEED_25 1
1747
#define DRM_PCIE_SPEED_50 2
1748
#define DRM_PCIE_SPEED_80 4
1408 serge 1749
 
3031 serge 1750
extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1751
 
2967 Serge 1752
static __inline__ int drm_device_is_agp(struct drm_device *dev)
1753
{
1754
    return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1755
}
1756
 
1757
static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1758
{
1759
    return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1760
}
1408 serge 1761
#endif				/* __KERNEL__ */
3031 serge 1762
 
1763
#define drm_sysfs_connector_add(connector)
1764
#define drm_sysfs_connector_remove(connector)
1765
 
3391 Serge 1766
#define LFB_SIZE 0xC00000
1767
 
1408 serge 1768
#endif