Subversion Repositories Kolibri OS

Rev

Rev 5056 | Rev 5270 | 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
 
4559 Serge 62
#include 
1408 serge 63
//#include 
4559 Serge 64
#include 
1408 serge 65
#include 
2967 Serge 66
#include 
5056 serge 67
#include 
68
 
3747 Serge 69
#include 
1630 serge 70
#include 
1408 serge 71
//#include 
5056 serge 72
#include 
73
 
1408 serge 74
//#include 
75
//#include 
76
//#include 
77
//#include 
78
 
5056 serge 79
#include 
3482 Serge 80
#include 
81
 
82
 
4103 Serge 83
#include 
84
#include 
1408 serge 85
 
86
#include 
87
 
88
#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
89
 
3031 serge 90
struct module;
1408 serge 91
 
92
struct drm_file;
93
struct drm_device;
94
 
3391 Serge 95
struct device_node;
96
struct videomode;
5056 serge 97
struct reservation_object;
4103 Serge 98
 
99
struct inode;
100
struct poll_table_struct;
101
struct drm_lock_data;
102
 
103
struct sg_table;
104
struct dma_buf;
105
 
3031 serge 106
//#include 
107
#include 
108
#include 
1408 serge 109
 
110
#define KHZ2PICOS(a) (1000000000UL/(a))
111
 
4559 Serge 112
/* Flags and return codes for get_vblank_timestamp() driver function. */
113
#define DRM_CALLED_FROM_VBLIRQ 1
114
#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
115
#define DRM_VBLANKTIME_INVBL             (1 << 1)
116
 
5056 serge 117
 
1964 serge 118
/* get_scanout_position() return flags */
119
#define DRM_SCANOUTPOS_VALID        (1 << 0)
120
#define DRM_SCANOUTPOS_INVBL        (1 << 1)
121
#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
122
 
3031 serge 123
/*
5056 serge 124
 * 4 debug categories are defined:
3031 serge 125
 *
5056 serge 126
 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
127
 *	 This is the category used by the DRM_DEBUG() macro.
3031 serge 128
 *
5056 serge 129
 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
130
 *	   This is the category used by the DRM_DEBUG_DRIVER() macro.
3031 serge 131
 *
5056 serge 132
 * KMS: used in the modesetting code.
133
 *	This is the category used by the DRM_DEBUG_KMS() macro.
134
 *
135
 * PRIME: used in the prime code.
136
 *	  This is the category used by the DRM_DEBUG_PRIME() macro.
137
 *
138
 * Enabling verbose debug messages is done through the drm.debug parameter,
139
 * each category being enabled by a bit.
140
 *
141
 * drm.debug=0x1 will enable CORE messages
142
 * drm.debug=0x2 will enable DRIVER messages
143
 * drm.debug=0x3 will enable CORE and DRIVER messages
144
 * ...
145
 * drm.debug=0xf will enable all messages
146
 *
147
 * An interesting feature is that it's possible to enable verbose logging at
148
 * run-time by echoing the debug value in its sysfs node:
149
 *   # echo 0xf > /sys/module/drm/parameters/debug
3031 serge 150
 */
5056 serge 151
#define DRM_UT_CORE 		0x01
152
#define DRM_UT_DRIVER		0x02
153
#define DRM_UT_KMS          0x04
154
#define DRM_UT_PRIME		0x08
3031 serge 155
 
5056 serge 156
extern __printf(2, 3)
157
void drm_ut_debug_printk(const char *function_name,
1408 serge 158
				const char *format, ...);
3031 serge 159
extern __printf(2, 3)
160
int drm_err(const char *func, const char *format, ...);
1408 serge 161
 
162
/***********************************************************************/
163
/** \name DRM template customization defaults */
164
/*@{*/
165
 
166
/* driver capabilities and requirements mask */
167
#define DRIVER_USE_AGP     0x1
168
#define DRIVER_PCI_DMA     0x8
169
#define DRIVER_SG          0x10
170
#define DRIVER_HAVE_DMA    0x20
171
#define DRIVER_HAVE_IRQ    0x40
172
#define DRIVER_IRQ_SHARED  0x80
173
#define DRIVER_GEM         0x1000
174
#define DRIVER_MODESET     0x2000
3031 serge 175
#define DRIVER_PRIME       0x4000
4103 Serge 176
#define DRIVER_RENDER      0x8000
1408 serge 177
 
2967 Serge 178
#define DRIVER_BUS_PCI 0x1
179
#define DRIVER_BUS_PLATFORM 0x2
180
#define DRIVER_BUS_USB 0x3
4559 Serge 181
#define DRIVER_BUS_HOST1X 0x4
2967 Serge 182
 
1408 serge 183
/***********************************************************************/
184
/** \name Begin the DRM... */
185
/*@{*/
186
 
4559 Serge 187
#define DRM_DEBUG_CODE 2	  /**< Include debugging code if > 1, then
1408 serge 188
				     also include looping detection. */
189
 
190
#define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
191
 
192
#define DRM_MAP_HASH_OFFSET 0x10000000
193
 
194
/*@}*/
195
 
196
/***********************************************************************/
197
/** \name Macros to make printk easier */
198
/*@{*/
199
 
200
/**
201
 * Error output.
202
 *
203
 * \param fmt printf() like format string.
204
 * \param arg arguments
205
 */
3031 serge 206
#define DRM_ERROR(fmt, ...)				\
207
	drm_err(__func__, fmt, ##__VA_ARGS__)
1408 serge 208
 
4559 Serge 209
/**
210
 * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
211
 *
212
 * \param fmt printf() like format string.
213
 * \param arg arguments
214
 */
215
#define DRM_ERROR_RATELIMITED(fmt, ...)				\
216
({									\
217
	static DEFINE_RATELIMIT_STATE(_rs,				\
218
				      DEFAULT_RATELIMIT_INTERVAL,	\
219
				      DEFAULT_RATELIMIT_BURST);		\
220
									\
221
	if (__ratelimit(&_rs))						\
222
		drm_err(__func__, fmt, ##__VA_ARGS__);			\
223
})
224
 
3031 serge 225
#define DRM_INFO(fmt, ...)				\
226
	printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
1408 serge 227
 
5056 serge 228
#define DRM_INFO_ONCE(fmt, ...)				\
229
	printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
230
 
1408 serge 231
/**
232
 * Debug output.
233
 *
234
 * \param fmt printf() like format string.
235
 * \param arg arguments
236
 */
237
#if DRM_DEBUG_CODE
5056 serge 238
#define DRM_DEBUG(fmt, args...)						\
3031 serge 239
    do {                                                    \
5056 serge 240
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 241
	} while (0)
242
 
5056 serge 243
#define DRM_DEBUG_DRIVER(fmt, args...)					\
3031 serge 244
    do {                                                    \
5056 serge 245
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
3031 serge 246
	} while (0)
5056 serge 247
#define DRM_DEBUG_KMS(fmt, args...)					\
1408 serge 248
	do {								\
5056 serge 249
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 250
	} while (0)
5056 serge 251
#define DRM_DEBUG_PRIME(fmt, args...)					\
1408 serge 252
	do {								\
5056 serge 253
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 254
	} while (0)
255
#else
256
#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
257
#define DRM_DEBUG_KMS(fmt, args...)	do { } while (0)
3031 serge 258
#define DRM_DEBUG_PRIME(fmt, args...)	do { } while (0)
1408 serge 259
#define DRM_DEBUG(fmt, arg...)		 do { } while (0)
260
#endif
261
 
262
/*@}*/
263
 
264
/***********************************************************************/
265
/** \name Internal types and structures */
266
/*@{*/
267
 
268
#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
269
 
270
#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
271
 
272
/**
273
 * Test that the hardware lock is held by the caller, returning otherwise.
274
 *
275
 * \param dev DRM device.
276
 * \param filp file pointer of the caller.
277
 */
278
#define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
279
do {										\
280
	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
281
	    _file_priv->master->lock.file_priv != _file_priv)	{		\
282
		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
283
			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
284
			   _file_priv->master->lock.file_priv, _file_priv);	\
285
		return -EINVAL;							\
286
	}									\
287
} while (0)
288
 
289
/**
290
 * Ioctl function type.
291
 *
292
 * \param inode device inode.
293
 * \param file_priv DRM file private pointer.
294
 * \param cmd command.
295
 * \param arg argument.
296
 */
297
typedef int drm_ioctl_t(struct drm_device *dev, void *data,
298
			struct drm_file *file_priv);
299
 
300
typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
301
			       unsigned long arg);
302
 
303
#define DRM_IOCTL_NR(n)                _IOC_NR(n)
304
#define DRM_MAJOR       226
305
 
306
#define DRM_AUTH	0x1
307
#define	DRM_MASTER	0x2
308
#define DRM_ROOT_ONLY	0x4
309
#define DRM_CONTROL_ALLOW 0x8
310
#define DRM_UNLOCKED	0x10
4103 Serge 311
#define DRM_RENDER_ALLOW 0x20
1408 serge 312
 
313
struct drm_ioctl_desc {
314
	unsigned int cmd;
315
	int flags;
316
	drm_ioctl_t *func;
1964 serge 317
	unsigned int cmd_drv;
3747 Serge 318
	const char *name;
1408 serge 319
};
320
 
321
/**
322
 * Creates a driver or general drm_ioctl_desc array entry for the given
323
 * ioctl, for use by drm_ioctl().
324
 */
325
 
1964 serge 326
#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)			\
3747 Serge 327
	[DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
1964 serge 328
 
5056 serge 329
#if 0
1408 serge 330
struct drm_magic_entry {
331
	struct list_head head;
332
	struct drm_hash_item hash_item;
333
	struct drm_file *priv;
334
};
335
 
336
struct drm_vma_entry {
337
	struct list_head head;
338
	struct vm_area_struct *vma;
339
	pid_t pid;
340
};
341
 
342
/**
343
 * DMA buffer.
344
 */
345
struct drm_buf {
346
	int idx;		       /**< Index into master buflist */
347
	int total;		       /**< Buffer size */
348
	int order;		       /**< log-base-2(total) */
349
	int used;		       /**< Amount of buffer in use (for DMA) */
350
	unsigned long offset;	       /**< Byte offset (used internally) */
351
	void *address;		       /**< Address of buffer */
352
	unsigned long bus_address;     /**< Bus address of buffer */
353
	struct drm_buf *next;	       /**< Kernel-only: used for free list */
354
	__volatile__ int waiting;      /**< On kernel DMA queue */
355
	__volatile__ int pending;      /**< On hardware DMA queue */
356
	struct drm_file *file_priv;    /**< Private of holding file descr */
357
	int context;		       /**< Kernel queue for this buffer */
358
	int while_locked;	       /**< Dispatch this buffer while locked */
359
	enum {
360
		DRM_LIST_NONE = 0,
361
		DRM_LIST_FREE = 1,
362
		DRM_LIST_WAIT = 2,
363
		DRM_LIST_PEND = 3,
364
		DRM_LIST_PRIO = 4,
365
		DRM_LIST_RECLAIM = 5
366
	} list;			       /**< Which list we're on */
367
 
368
	int dev_priv_size;		 /**< Size of buffer private storage */
369
	void *dev_private;		 /**< Per-buffer private storage */
370
};
371
 
372
/** bufs is one longer than it has to be */
373
struct drm_waitlist {
374
	int count;			/**< Number of possible buffers */
375
	struct drm_buf **bufs;		/**< List of pointers to buffers */
376
	struct drm_buf **rp;			/**< Read pointer */
377
	struct drm_buf **wp;			/**< Write pointer */
378
	struct drm_buf **end;		/**< End pointer */
379
	spinlock_t read_lock;
380
	spinlock_t write_lock;
381
};
4065 Serge 382
#endif
1408 serge 383
 
384
 
385
typedef struct drm_dma_handle {
386
	dma_addr_t busaddr;
387
	void *vaddr;
388
	size_t size;
389
} drm_dma_handle_t;
390
 
391
/**
392
 * Buffer entry.  There is one of this for each buffer size order.
393
 */
394
struct drm_buf_entry {
395
	int buf_size;			/**< size */
396
	int buf_count;			/**< number of buffers */
397
	struct drm_buf *buflist;		/**< buffer list */
398
	int seg_count;
399
	int page_order;
400
	struct drm_dma_handle **seglist;
401
 
5056 serge 402
	int low_mark;			/**< Low water mark */
403
	int high_mark;			/**< High water mark */
1408 serge 404
};
405
 
406
/* Event queued up for userspace to read */
407
struct drm_pending_event {
408
	struct drm_event *event;
409
	struct list_head link;
410
	struct drm_file *file_priv;
1964 serge 411
	pid_t pid; /* pid of requester, no guarantee it's valid by the time
412
		      we deliver the event, for tracing only */
1408 serge 413
	void (*destroy)(struct drm_pending_event *event);
414
};
415
 
3031 serge 416
/* initial implementaton using a linked list - todo hashtab */
417
struct drm_prime_file_private {
418
	struct list_head head;
419
	struct mutex lock;
420
};
421
 
1408 serge 422
/** File private data */
423
struct drm_file {
4559 Serge 424
	unsigned authenticated :1;
5056 serge 425
	/* Whether we're master for a minor. Protected by master_mutex */
426
	unsigned is_master :1;
4559 Serge 427
	/* true when the client has asked us to expose stereo 3D mode flags */
428
	unsigned stereo_allowed :1;
5056 serge 429
	/*
430
	 * true if client understands CRTC primary planes and cursor planes
431
	 * in the plane list
432
	 */
433
	unsigned universal_planes:1;
1408 serge 434
	struct list_head lhead;
435
	unsigned long lock_count;
436
 
437
	/** Mapping of mm object handles to object pointers. */
438
	struct idr object_idr;
439
	/** Lock for synchronization of access to object_idr. */
440
	spinlock_t table_lock;
441
 
442
	void *driver_priv;
443
 
5056 serge 444
	struct drm_master *master; /* master this node is currently associated with
445
				      N.B. not always minor->master */
446
	/**
447
	 * fbs - List of framebuffers associated with this file.
448
	 *
449
	 * Protected by fbs_lock. Note that the fbs list holds a reference on
450
	 * the fb object to prevent it from untimely disappearing.
451
	 */
1408 serge 452
	struct list_head fbs;
5056 serge 453
	struct mutex fbs_lock;
1408 serge 454
 
455
	wait_queue_head_t event_wait;
456
	struct list_head event_list;
457
	int event_space;
458
};
459
 
3255 Serge 460
#if 0
1408 serge 461
/**
462
 * Lock data.
463
 */
464
struct drm_lock_data {
465
	struct drm_hw_lock *hw_lock;	/**< Hardware lock */
466
	/** Private of lock holder's file (NULL=kernel) */
467
	struct drm_file *file_priv;
468
	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
469
	unsigned long lock_time;	/**< Time of last lock in jiffies */
470
	spinlock_t spinlock;
471
	uint32_t kernel_waiters;
472
	uint32_t user_waiters;
473
	int idle_has_lock;
474
};
475
 
476
/**
477
 * DMA data.
478
 */
479
struct drm_device_dma {
480
 
481
	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
482
	int buf_count;			/**< total number of buffers */
483
	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
484
	int seg_count;
485
	int page_count;			/**< number of pages */
486
	unsigned long *pagelist;	/**< page list */
487
	unsigned long byte_count;
488
	enum {
489
		_DRM_DMA_USE_AGP = 0x01,
490
		_DRM_DMA_USE_SG = 0x02,
491
		_DRM_DMA_USE_FB = 0x04,
492
		_DRM_DMA_USE_PCI_RO = 0x08
493
	} flags;
494
 
495
};
496
 
497
/**
498
 * AGP memory entry.  Stored as a doubly linked list.
499
 */
500
struct drm_agp_mem {
501
	unsigned long handle;		/**< handle */
4559 Serge 502
	struct agp_memory *memory;
1408 serge 503
	unsigned long bound;		/**< address */
504
	int pages;
505
	struct list_head head;
506
};
507
 
508
/**
509
 * AGP data.
510
 *
511
 * \sa drm_agp_init() and drm_device::agp.
512
 */
513
struct drm_agp_head {
4559 Serge 514
	struct agp_kern_info agp_info;		/**< AGP device information */
1408 serge 515
	struct list_head memory;
516
	unsigned long mode;		/**< AGP mode */
517
	struct agp_bridge_data *bridge;
518
	int enabled;			/**< whether the AGP bus as been enabled */
519
	int acquired;			/**< whether the AGP device has been acquired */
520
	unsigned long base;
521
	int agp_mtrr;
522
	int cant_use_aperture;
523
	unsigned long page_mask;
524
};
525
 
526
/**
527
 * Scatter-gather memory.
528
 */
529
struct drm_sg_mem {
530
	unsigned long handle;
531
	void *virtual;
532
	int pages;
533
	struct page **pagelist;
534
	dma_addr_t *busaddr;
535
};
536
 
537
struct drm_sigdata {
538
	int context;
539
	struct drm_hw_lock *lock;
540
};
541
 
2967 Serge 542
#endif
1408 serge 543
 
544
/**
545
 * Kernel side of a mapping
546
 */
547
struct drm_local_map {
548
	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
549
	unsigned long size;	 /**< Requested physical size (bytes) */
550
	enum drm_map_type type;	 /**< Type of memory to map */
551
	enum drm_map_flags flags;	 /**< Flags */
552
	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
553
				 /**< Kernel-space: kernel-virtual address */
554
	int mtrr;		 /**< MTRR slot used */
555
};
556
 
557
typedef struct drm_local_map drm_local_map_t;
558
 
559
/**
560
 * Mappings list
561
 */
562
struct drm_map_list {
563
	struct list_head head;		/**< list head */
564
	struct drm_hash_item hash;
565
	struct drm_local_map *map;	/**< mapping */
566
	uint64_t user_token;
567
	struct drm_master *master;
568
};
569
 
570
/* location of GART table */
571
#define DRM_ATI_GART_MAIN 1
572
#define DRM_ATI_GART_FB   2
573
 
574
#define DRM_ATI_GART_PCI 1
575
#define DRM_ATI_GART_PCIE 2
576
#define DRM_ATI_GART_IGP 3
577
 
578
struct drm_ati_pcigart_info {
579
	int gart_table_location;
580
	int gart_reg_if;
581
	void *addr;
582
	dma_addr_t bus_addr;
583
	dma_addr_t table_mask;
584
	struct drm_dma_handle *table_handle;
585
	struct drm_local_map mapping;
586
	int table_size;
587
};
588
 
589
/**
590
 * This structure defines the drm_mm memory object, which will be used by the
591
 * DRM for its buffer objects.
592
 */
593
struct drm_gem_object {
594
	/** Reference count of this object */
595
	struct kref refcount;
596
 
4103 Serge 597
	/**
598
	 * handle_count - gem file_priv handle count of this object
599
	 *
600
	 * Each handle also holds a reference. Note that when the handle_count
601
	 * drops to 0 any global names (e.g. the id in the flink namespace) will
602
	 * be cleared.
603
	 *
604
	 * Protected by dev->object_name_lock.
605
	 * */
606
	unsigned handle_count;
1408 serge 607
 
608
	/** Related drm device */
609
	struct drm_device *dev;
610
 
611
	/** File representing the shmem storage */
612
	struct file *filp;
613
 
614
	/* Mapping info for this object */
4103 Serge 615
	struct drm_vma_offset_node vma_node;
1408 serge 616
 
617
	/**
618
	 * Size of the object, in bytes.  Immutable over the object's
619
	 * lifetime.
620
	 */
621
	size_t size;
622
 
623
	/**
624
	 * Global name for this object, starts at 1. 0 means unnamed.
625
	 * Access is covered by the object_name_lock in the related drm_device
626
	 */
627
	int name;
628
 
629
	/**
630
	 * Memory domains. These monitor which caches contain read/write data
631
	 * related to the object. When transitioning from one set of domains
632
	 * to another, the driver is called to ensure that caches are suitably
633
	 * flushed and invalidated
634
	 */
635
	uint32_t read_domains;
636
	uint32_t write_domain;
637
 
638
	/**
639
	 * While validating an exec operation, the
640
	 * new read/write domain values are computed here.
641
	 * They will be transferred to the above values
642
	 * at the point that any cache flushing occurs
643
	 */
644
	uint32_t pending_read_domains;
645
	uint32_t pending_write_domain;
646
 
5056 serge 647
	/**
648
	 * dma_buf - dma buf associated with this GEM object
649
	 *
650
	 * Pointer to the dma-buf associated with this gem object (either
651
	 * through importing or exporting). We break the resulting reference
652
	 * loop when the last gem handle for this object is released.
653
	 *
654
	 * Protected by obj->object_name_lock
655
	 */
656
	struct dma_buf *dma_buf;
4559 Serge 657
 
1408 serge 658
};
659
 
3031 serge 660
#include 
1408 serge 661
 
5056 serge 662
/**
663
 * struct drm_master - drm master structure
664
 *
665
 * @refcount: Refcount for this master object.
666
 * @minor: Link back to minor char device we are master for. Immutable.
667
 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
668
 * @unique_len: Length of unique field. Protected by drm_global_mutex.
669
 * @unique_size: Amount allocated. Protected by drm_global_mutex.
670
 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
671
 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
672
 * @lock: DRI lock information.
673
 * @driver_priv: Pointer to driver-private information.
674
 */
1408 serge 675
struct drm_master {
5056 serge 676
	struct kref refcount;
677
	struct drm_minor *minor;
678
	char *unique;
679
	int unique_len;
680
	int unique_size;
681
//	struct drm_open_hash magiclist;
682
//	struct list_head magicfree;
683
//	struct drm_lock_data lock;
684
	void *driver_priv;
1408 serge 685
};
686
 
1964 serge 687
/* Size of ringbuffer for vblank timestamps. Just double-buffer
688
 * in initial implementation.
689
 */
690
#define DRM_VBLANKTIME_RBSIZE 2
691
 
692
/* Flags and return codes for get_vblank_timestamp() driver function. */
693
#define DRM_CALLED_FROM_VBLIRQ 1
694
#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
695
#define DRM_VBLANKTIME_INVBL             (1 << 1)
696
 
697
/* get_scanout_position() return flags */
698
#define DRM_SCANOUTPOS_VALID        (1 << 0)
699
#define DRM_SCANOUTPOS_INVBL        (1 << 1)
700
#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
701
 
702
struct drm_bus {
703
	int (*set_busid)(struct drm_device *dev, struct drm_master *master);
704
};
705
 
1408 serge 706
/**
707
 * DRM driver structure. This structure represent the common code for
708
 * a family of cards. There will one drm_device for each card present
709
 * in this family
710
 */
711
struct drm_driver {
712
	int (*load) (struct drm_device *, unsigned long flags);
713
	int (*open) (struct drm_device *, struct drm_file *);
714
 
715
	/**
716
	 * get_vblank_counter - get raw hardware vblank counter
717
	 * @dev: DRM device
718
	 * @crtc: counter to fetch
719
	 *
3031 serge 720
	 * Driver callback for fetching a raw hardware vblank counter for @crtc.
721
	 * If a device doesn't have a hardware counter, the driver can simply
722
	 * return the value of drm_vblank_count. The DRM core will account for
723
	 * missed vblank events while interrupts where disabled based on system
724
	 * timestamps.
1408 serge 725
	 *
726
	 * Wraparound handling and loss of events due to modesetting is dealt
727
	 * with in the DRM core code.
728
	 *
729
	 * RETURNS
730
	 * Raw vblank counter value.
731
	 */
732
	u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
733
 
734
	/**
735
	 * enable_vblank - enable vblank interrupt events
736
	 * @dev: DRM device
737
	 * @crtc: which irq to enable
738
	 *
739
	 * Enable vblank interrupts for @crtc.  If the device doesn't have
740
	 * a hardware vblank counter, this routine should be a no-op, since
741
	 * interrupts will have to stay on to keep the count accurate.
742
	 *
743
	 * RETURNS
744
	 * Zero on success, appropriate errno if the given @crtc's vblank
745
	 * interrupt cannot be enabled.
746
	 */
747
	int (*enable_vblank) (struct drm_device *dev, int crtc);
748
 
749
	/**
750
	 * disable_vblank - disable vblank interrupt events
751
	 * @dev: DRM device
752
	 * @crtc: which irq to enable
753
	 *
754
	 * Disable vblank interrupts for @crtc.  If the device doesn't have
755
	 * a hardware vblank counter, this routine should be a no-op, since
756
	 * interrupts will have to stay on to keep the count accurate.
757
	 */
758
	void (*disable_vblank) (struct drm_device *dev, int crtc);
759
	/**
1964 serge 760
	 * Called by vblank timestamping code.
761
	 *
4559 Serge 762
	 * Return the current display scanout position from a crtc, and an
763
	 * optional accurate ktime_get timestamp of when position was measured.
1964 serge 764
	 *
765
	 * \param dev  DRM device.
766
	 * \param crtc Id of the crtc to query.
4559 Serge 767
	 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
1964 serge 768
	 * \param *vpos Target location for current vertical scanout position.
769
	 * \param *hpos Target location for current horizontal scanout position.
4559 Serge 770
	 * \param *stime Target location for timestamp taken immediately before
771
	 *               scanout position query. Can be NULL to skip timestamp.
772
	 * \param *etime Target location for timestamp taken immediately after
773
	 *               scanout position query. Can be NULL to skip timestamp.
1964 serge 774
	 *
775
	 * Returns vpos as a positive number while in active scanout area.
776
	 * Returns vpos as a negative number inside vblank, counting the number
777
	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
778
	 * until start of active scanout / end of vblank."
779
	 *
780
	 * \return Flags, or'ed together as follows:
781
	 *
782
	 * DRM_SCANOUTPOS_VALID = Query successful.
783
	 * DRM_SCANOUTPOS_INVBL = Inside vblank.
784
	 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
785
	 * this flag means that returned position may be offset by a constant
786
	 * but unknown small number of scanlines wrt. real scanout position.
787
	 *
788
	 */
789
	int (*get_scanout_position) (struct drm_device *dev, int crtc,
4559 Serge 790
				     unsigned int flags,
791
                     int *vpos, int *hpos, void *stime,
792
                     void *etime);
1964 serge 793
 
794
	/**
795
	 * Called by \c drm_get_last_vbltimestamp. Should return a precise
796
	 * timestamp when the most recent VBLANK interval ended or will end.
797
	 *
798
	 * Specifically, the timestamp in @vblank_time should correspond as
799
	 * closely as possible to the time when the first video scanline of
800
	 * the video frame after the end of VBLANK will start scanning out,
2967 Serge 801
	 * the time immediately after end of the VBLANK interval. If the
1964 serge 802
	 * @crtc is currently inside VBLANK, this will be a time in the future.
803
	 * If the @crtc is currently scanning out a frame, this will be the
804
	 * past start time of the current scanout. This is meant to adhere
805
	 * to the OpenML OML_sync_control extension specification.
806
	 *
807
	 * \param dev dev DRM device handle.
808
	 * \param crtc crtc for which timestamp should be returned.
809
	 * \param *max_error Maximum allowable timestamp error in nanoseconds.
810
	 *                   Implementation should strive to provide timestamp
811
	 *                   with an error of at most *max_error nanoseconds.
812
	 *                   Returns true upper bound on error for timestamp.
813
	 * \param *vblank_time Target location for returned vblank timestamp.
814
	 * \param flags 0 = Defaults, no special treatment needed.
815
	 * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
816
	 *	        irq handler. Some drivers need to apply some workarounds
817
	 *              for gpu-specific vblank irq quirks if flag is set.
818
	 *
819
	 * \returns
820
	 * Zero if timestamping isn't supported in current display mode or a
821
	 * negative number on failure. A positive status code on success,
822
	 * which describes how the vblank_time timestamp was computed.
823
	 */
824
	int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
825
				     int *max_error,
826
				     struct timeval *vblank_time,
827
				     unsigned flags);
828
 
1408 serge 829
	/* these have to be filled in */
830
 
5056 serge 831
	irqreturn_t(*irq_handler) (int irq, void *arg);
1408 serge 832
	void (*irq_preinstall) (struct drm_device *dev);
833
	int (*irq_postinstall) (struct drm_device *dev);
834
	void (*irq_uninstall) (struct drm_device *dev);
835
 
836
	/**
837
	 * Driver-specific constructor for drm_gem_objects, to set up
838
	 * obj->driver_private.
839
	 *
840
	 * Returns 0 on success.
841
	 */
842
	void (*gem_free_object) (struct drm_gem_object *obj);
2967 Serge 843
	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
844
	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
1408 serge 845
	u32 driver_features;
5056 serge 846
	int dev_priv_size;
1408 serge 847
};
848
 
5056 serge 849
enum drm_minor_type {
850
	DRM_MINOR_LEGACY,
851
	DRM_MINOR_CONTROL,
852
	DRM_MINOR_RENDER,
853
	DRM_MINOR_CNT,
854
};
1408 serge 855
 
856
/**
857
 * Info file list entry. This structure represents a debugfs or proc file to
858
 * be created by the drm core
859
 */
860
struct drm_info_list {
861
	const char *name; /** file name */
2967 Serge 862
//   int (*show)(struct seq_file*, void*); /** show callback */
1408 serge 863
	u32 driver_features; /**< Required driver features for this entry */
864
	void *data;
865
};
866
 
867
/**
868
 * debugfs node structure. This structure represents a debugfs file.
869
 */
870
struct drm_info_node {
871
	struct list_head list;
872
	struct drm_minor *minor;
4065 Serge 873
	const struct drm_info_list *info_ent;
1408 serge 874
	struct dentry *dent;
875
};
876
 
877
/**
878
 * DRM minor structure. This structure represents a drm minor number.
879
 */
880
struct drm_minor {
881
	int index;			/**< Minor device number */
882
	int type;                       /**< Control or render */
2967 Serge 883
//   struct device kdev;     /**< Linux device */
1408 serge 884
	struct drm_device *dev;
885
 
5056 serge 886
	struct dentry *debugfs_root;
1408 serge 887
 
5056 serge 888
	struct list_head debugfs_list;
889
	struct mutex debugfs_lock; /* Protects debugfs_list. */
1408 serge 890
 
5056 serge 891
	/* currently active master for this node. Protected by master_mutex */
892
	struct drm_master *master;
893
	struct drm_mode_group mode_group;
1964 serge 894
};
1408 serge 895
 
896
 
897
 
898
/**
899
 * DRM device structure. This structure represent a complete card that
900
 * may contain multiple heads.
901
 */
902
struct drm_device {
4559 Serge 903
	struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
1408 serge 904
	int if_version;			/**< Highest interface version set */
905
 
5056 serge 906
	struct device *dev;		/**< Device structure of bus-device */
907
	struct drm_driver *driver;	/**< DRM driver managing the device */
908
	void *dev_private;		/**< DRM driver private data */
909
	struct drm_minor *primary;		/**< Primary node */
910
	atomic_t unplugged;			/**< Flag whether dev is dead */
1408 serge 911
	/** \name Locks */
912
	/*@{ */
1630 serge 913
	struct mutex struct_mutex;	/**< For others */
5056 serge 914
	struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
1408 serge 915
	/*@} */
916
 
917
	/** \name Usage Counters */
918
	/*@{ */
5056 serge 919
	int open_count;			/**< Outstanding files open, protected by drm_global_mutex. */
920
	spinlock_t buf_lock;		/**< For drm_device::buf_use and a few other things. */
1408 serge 921
	int buf_use;			/**< Buffers in use -- cannot alloc */
922
   atomic_t buf_alloc;     /**< Buffer allocation in progress */
923
	/*@} */
924
 
925
	struct list_head filelist;
926
 
927
	/** \name Memory management */
928
	/*@{ */
929
	struct list_head maplist;	/**< Linked list of regions */
930
 
931
	/** \name Context handle management */
932
	/*@{ */
933
	struct list_head ctxlist;	/**< Linked list of context handles */
1630 serge 934
	struct mutex ctxlist_mutex;	/**< For ctxlist */
1408 serge 935
 
1964 serge 936
	struct idr ctx_idr;
1408 serge 937
 
938
	struct list_head vmalist;	/**< List of vmas (for debugging) */
939
 
940
	/*@} */
941
 
3031 serge 942
	/** \name DMA support */
1408 serge 943
	/*@{ */
944
//   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
945
	/*@} */
946
 
947
	/** \name Context support */
948
	/*@{ */
4559 Serge 949
	bool irq_enabled;		/**< True if irq handler is enabled */
5056 serge 950
	int irq;
951
 
1408 serge 952
	__volatile__ long context_flag;	/**< Context swapping flag */
953
	int last_context;		/**< Last current context */
954
	/*@} */
955
 
956
	/** \name VBLANK IRQ support */
957
	/*@{ */
958
 
959
	/*
960
	 * At load time, disabling the vblank interrupt won't be allowed since
961
	 * old clients may not call the modeset ioctl and therefore misbehave.
962
	 * Once the modeset ioctl *has* been called though, we can safely
963
	 * disable them when unused.
964
	 */
4559 Serge 965
	bool vblank_disable_allowed;
1408 serge 966
 
5056 serge 967
	/* array of size num_crtcs */
968
	struct drm_vblank_crtc *vblank;
1408 serge 969
 
5056 serge 970
	spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
971
	spinlock_t vbl_lock;
972
 
1408 serge 973
	u32 max_vblank_count;           /**< size of vblank counter register */
974
 
1964 serge 975
	/**
976
	 * List of events
977
	 */
978
	struct list_head vblank_event_list;
979
	spinlock_t event_lock;
980
 
1408 serge 981
	/*@} */
982
 
983
//   struct drm_agp_head *agp;   /**< AGP data */
984
 
985
	struct pci_dev *pdev;		/**< PCI device structure */
5056 serge 986
 
1964 serge 987
	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1408 serge 988
 
989
 
990
        struct drm_mode_config mode_config;	/**< Current mode config */
991
 
992
	/** \name GEM information */
993
	/*@{ */
4103 Serge 994
	struct mutex object_name_lock;
1964 serge 995
	struct idr object_name_idr;
4559 Serge 996
	struct drm_vma_offset_manager *vma_offset_manager;
1408 serge 997
	/*@} */
1964 serge 998
	int switch_power_state;
1408 serge 999
};
1000
 
1964 serge 1001
#define DRM_SWITCH_POWER_ON 0
1002
#define DRM_SWITCH_POWER_OFF 1
1003
#define DRM_SWITCH_POWER_CHANGING 2
4103 Serge 1004
#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1964 serge 1005
 
3482 Serge 1006
static __inline__ int drm_core_check_feature(struct drm_device *dev,
1007
					     int feature)
1008
{
1009
	return ((dev->driver->driver_features & feature) ? 1 : 0);
1010
}
1964 serge 1011
 
4065 Serge 1012
static inline void drm_device_set_unplugged(struct drm_device *dev)
1408 serge 1013
{
4065 Serge 1014
	smp_wmb();
1015
	atomic_set(&dev->unplugged, 1);
1408 serge 1016
}
1017
 
4065 Serge 1018
static inline int drm_device_is_unplugged(struct drm_device *dev)
1408 serge 1019
{
4065 Serge 1020
	int ret = atomic_read(&dev->unplugged);
1021
	smp_rmb();
1022
	return ret;
1408 serge 1023
}
1024
 
1025
 
1026
/******************************************************************/
1027
/** \name Internal function definitions */
1028
/*@{*/
1029
 
1030
				/* Driver support (drm_drv.h) */
1031
extern long drm_ioctl(struct file *filp,
1032
		     unsigned int cmd, unsigned long arg);
1033
extern long drm_compat_ioctl(struct file *filp,
1034
			     unsigned int cmd, unsigned long arg);
1035
extern int drm_lastclose(struct drm_device *dev);
5056 serge 1036
extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1408 serge 1037
 
1038
				/* Device support (drm_fops.h) */
1964 serge 1039
extern struct mutex drm_global_mutex;
1408 serge 1040
extern int drm_open(struct inode *inode, struct file *filp);
1041
extern ssize_t drm_read(struct file *filp, char __user *buffer,
1042
			size_t count, loff_t *offset);
1043
extern int drm_release(struct inode *inode, struct file *filp);
1044
 
1045
				/* Mapping support (drm_vm.h) */
1046
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1047
extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
3031 serge 1048
extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1049
extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1408 serge 1050
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1051
 
1052
				/* Memory management support (drm_memory.h) */
3031 serge 1053
#include 
1408 serge 1054
 
4559 Serge 1055
 
1408 serge 1056
				/* Misc. IOCTL support (drm_ioctl.h) */
1057
extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1058
			    struct drm_file *file_priv);
1059
extern int drm_getunique(struct drm_device *dev, void *data,
1060
			 struct drm_file *file_priv);
1061
extern int drm_setunique(struct drm_device *dev, void *data,
1062
			 struct drm_file *file_priv);
1063
extern int drm_getmap(struct drm_device *dev, void *data,
1064
		      struct drm_file *file_priv);
1065
extern int drm_getclient(struct drm_device *dev, void *data,
1066
			 struct drm_file *file_priv);
1067
extern int drm_getstats(struct drm_device *dev, void *data,
1068
			struct drm_file *file_priv);
1964 serge 1069
extern int drm_getcap(struct drm_device *dev, void *data,
1070
		      struct drm_file *file_priv);
4559 Serge 1071
extern int drm_setclientcap(struct drm_device *dev, void *data,
1072
			    struct drm_file *file_priv);
1408 serge 1073
extern int drm_setversion(struct drm_device *dev, void *data,
1074
			  struct drm_file *file_priv);
1075
extern int drm_noop(struct drm_device *dev, void *data,
1076
		    struct drm_file *file_priv);
1077
 
1078
				/* Authentication IOCTL support (drm_auth.h) */
1079
extern int drm_getmagic(struct drm_device *dev, void *data,
1080
			struct drm_file *file_priv);
1081
extern int drm_authmagic(struct drm_device *dev, void *data,
1082
			 struct drm_file *file_priv);
2967 Serge 1083
extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1408 serge 1084
 
1085
/* Cache management (drm_cache.c) */
1086
void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
3031 serge 1087
void drm_clflush_sg(struct sg_table *st);
5056 serge 1088
void drm_clflush_virt_range(void *addr, unsigned long length);
1408 serge 1089
 
1090
				/* Locking IOCTL support (drm_lock.h) */
1091
extern int drm_lock(struct drm_device *dev, void *data,
1092
		    struct drm_file *file_priv);
1093
extern int drm_unlock(struct drm_device *dev, void *data,
1094
		      struct drm_file *file_priv);
1095
extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1096
extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1097
extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1098
 
1099
/*
1100
 * These are exported to drivers so that they can implement fencing using
1101
 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1102
 */
1103
 
1104
extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1105
 
1106
				/* Buffer management support (drm_bufs.h) */
1107
extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1108
extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1109
extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1110
		      unsigned int size, enum drm_map_type type,
1111
		      enum drm_map_flags flags, struct drm_local_map **map_ptr);
1112
extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1113
			    struct drm_file *file_priv);
1114
extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1115
extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1116
extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1117
			   struct drm_file *file_priv);
1118
extern int drm_addbufs(struct drm_device *dev, void *data,
1119
		       struct drm_file *file_priv);
1120
extern int drm_infobufs(struct drm_device *dev, void *data,
1121
			struct drm_file *file_priv);
1122
extern int drm_markbufs(struct drm_device *dev, void *data,
1123
			struct drm_file *file_priv);
1124
extern int drm_freebufs(struct drm_device *dev, void *data,
1125
			struct drm_file *file_priv);
1126
extern int drm_mapbufs(struct drm_device *dev, void *data,
1127
		       struct drm_file *file_priv);
4279 Serge 1128
extern int drm_dma_ioctl(struct drm_device *dev, void *data,
1129
			 struct drm_file *file_priv);
1408 serge 1130
 
1131
				/* DMA support (drm_dma.h) */
4103 Serge 1132
extern int drm_legacy_dma_setup(struct drm_device *dev);
1133
extern void drm_legacy_dma_takedown(struct drm_device *dev);
1408 serge 1134
extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1135
extern void drm_core_reclaim_buffers(struct drm_device *dev,
1136
				     struct drm_file *filp);
1137
 
1138
				/* IRQ support (drm_irq.h) */
1139
extern int drm_control(struct drm_device *dev, void *data,
1140
		       struct drm_file *file_priv);
5056 serge 1141
extern int drm_irq_install(struct drm_device *dev, int irq);
1408 serge 1142
extern int drm_irq_uninstall(struct drm_device *dev);
1143
 
1144
extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1145
extern int drm_wait_vblank(struct drm_device *dev, void *data,
1146
			   struct drm_file *filp);
1147
extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1964 serge 1148
extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1149
				     struct timeval *vblanktime);
3391 Serge 1150
extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1151
				     struct drm_pending_vblank_event *e);
1964 serge 1152
extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1408 serge 1153
extern int drm_vblank_get(struct drm_device *dev, int crtc);
1154
extern void drm_vblank_put(struct drm_device *dev, int crtc);
5056 serge 1155
extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1156
extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1408 serge 1157
extern void drm_vblank_off(struct drm_device *dev, int crtc);
5056 serge 1158
extern void drm_vblank_on(struct drm_device *dev, int crtc);
1159
extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1160
extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1408 serge 1161
extern void drm_vblank_cleanup(struct drm_device *dev);
5056 serge 1162
 
1964 serge 1163
extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1164
				     struct timeval *tvblank, unsigned flags);
1165
extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1166
						 int crtc, int *max_error,
1167
						 struct timeval *vblank_time,
1168
						 unsigned flags,
4559 Serge 1169
						 const struct drm_crtc *refcrtc,
1170
						 const struct drm_display_mode *mode);
1171
extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1172
					    const struct drm_display_mode *mode);
1964 serge 1173
 
1174
 
1408 serge 1175
/* Modesetting support */
1176
extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1177
extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1178
extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1179
			   struct drm_file *file_priv);
1180
 
1181
				/* AGP/GART support (drm_agpsupport.h) */
1182
 
1183
				/* Stub support (drm_stub.h) */
1184
extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1185
			       struct drm_file *file_priv);
1186
extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1187
				struct drm_file *file_priv);
1188
struct drm_master *drm_master_create(struct drm_minor *minor);
1189
extern struct drm_master *drm_master_get(struct drm_master *master);
1190
extern void drm_master_put(struct drm_master **master);
1964 serge 1191
 
1408 serge 1192
extern void drm_put_dev(struct drm_device *dev);
3031 serge 1193
extern void drm_unplug_dev(struct drm_device *dev);
1408 serge 1194
extern unsigned int drm_debug;
1195
 
3031 serge 1196
#if 0
1964 serge 1197
extern unsigned int drm_vblank_offdelay;
1198
extern unsigned int drm_timestamp_precision;
3192 Serge 1199
extern unsigned int drm_timestamp_monotonic;
1964 serge 1200
 
1408 serge 1201
extern struct class *drm_class;
1202
 
1203
extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
5056 serge 1204
#endif
1408 serge 1205
				/* Debugfs support */
1206
#if defined(CONFIG_DEBUG_FS)
1207
extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1208
			    struct dentry *root);
4559 Serge 1209
extern int drm_debugfs_create_files(const struct drm_info_list *files,
1210
				    int count, struct dentry *root,
1408 serge 1211
                                    struct drm_minor *minor);
4559 Serge 1212
extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1213
				    int count, struct drm_minor *minor);
1408 serge 1214
extern int drm_debugfs_cleanup(struct drm_minor *minor);
5056 serge 1215
extern int drm_debugfs_connector_add(struct drm_connector *connector);
1216
extern void drm_debugfs_connector_remove(struct drm_connector *connector);
4559 Serge 1217
#else
1218
static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1219
				   struct dentry *root)
1220
{
1221
	return 0;
1222
}
1223
 
1224
static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1225
					   int count, struct dentry *root,
1226
					   struct drm_minor *minor)
1227
{
1228
	return 0;
1229
}
1230
 
1231
static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1232
					   int count, struct drm_minor *minor)
1233
{
1234
	return 0;
1235
}
1236
 
1237
static inline int drm_debugfs_cleanup(struct drm_minor *minor)
1238
{
1239
	return 0;
1240
}
5056 serge 1241
 
1242
static inline int drm_debugfs_connector_add(struct drm_connector *connector)
1243
{
1244
	return 0;
1245
}
1246
static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
1247
{
1248
}
1249
 
1408 serge 1250
#endif
1251
 
1252
				/* Info file support */
1253
extern int drm_name_info(struct seq_file *m, void *data);
1254
extern int drm_vm_info(struct seq_file *m, void *data);
1255
extern int drm_bufs_info(struct seq_file *m, void *data);
1256
extern int drm_vblank_info(struct seq_file *m, void *data);
1257
extern int drm_clients_info(struct seq_file *m, void* data);
1258
extern int drm_gem_name_info(struct seq_file *m, void *data);
1259
 
1260
#if DRM_DEBUG_CODE
1261
extern int drm_vma_info(struct seq_file *m, void *data);
1262
#endif
1263
 
1264
				/* Scatter Gather Support (drm_scatter.h) */
4103 Serge 1265
extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1266
extern int drm_sg_alloc(struct drm_device *dev, void *data,
1408 serge 1267
			struct drm_file *file_priv);
1268
extern int drm_sg_free(struct drm_device *dev, void *data,
1269
		       struct drm_file *file_priv);
1270
 
1271
			       /* ATI PCIGART support (ati_pcigart.h) */
1272
extern int drm_ati_pcigart_init(struct drm_device *dev,
1273
				struct drm_ati_pcigart_info * gart_info);
1274
extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1275
				   struct drm_ati_pcigart_info * gart_info);
1276
 
1277
extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1428 serge 1278
				       size_t align);
1408 serge 1279
extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1280
extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1281
 
3031 serge 1282
#if 0
1408 serge 1283
			       /* sysfs support (drm_sysfs.c) */
1284
struct drm_sysfs_class;
1285
extern struct class *drm_sysfs_create(struct module *owner, char *name);
1286
extern void drm_sysfs_destroy(void);
5056 serge 1287
extern struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
1408 serge 1288
extern void drm_sysfs_hotplug_event(struct drm_device *dev);
4103 Serge 1289
extern int drm_sysfs_connector_add(struct drm_connector *connector);
1290
extern void drm_sysfs_connector_remove(struct drm_connector *connector);
2967 Serge 1291
#endif
1292
 
1408 serge 1293
/* Graphics Execution Manager library functions (drm_gem.c) */
1294
int drm_gem_init(struct drm_device *dev);
1295
void drm_gem_destroy(struct drm_device *dev);
1964 serge 1296
void drm_gem_object_release(struct drm_gem_object *obj);
1408 serge 1297
void drm_gem_object_free(struct kref *kref);
1964 serge 1298
int drm_gem_object_init(struct drm_device *dev,
1299
			struct drm_gem_object *obj, size_t size);
4103 Serge 1300
void drm_gem_private_object_init(struct drm_device *dev,
2967 Serge 1301
			struct drm_gem_object *obj, size_t size);
1408 serge 1302
void drm_gem_vm_open(struct vm_area_struct *vma);
1303
void drm_gem_vm_close(struct vm_area_struct *vma);
4103 Serge 1304
int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1305
		     struct vm_area_struct *vma);
1408 serge 1306
int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1307
 
4103 Serge 1308
#include 
2967 Serge 1309
 
1408 serge 1310
static inline void
1311
drm_gem_object_reference(struct drm_gem_object *obj)
1312
{
1313
	kref_get(&obj->refcount);
1314
}
1315
 
1316
static inline void
1317
drm_gem_object_unreference(struct drm_gem_object *obj)
1318
{
2967 Serge 1319
	if (obj != NULL)
1320
		kref_put(&obj->refcount, drm_gem_object_free);
1321
}
1408 serge 1322
 
2967 Serge 1323
static inline void
1324
drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1325
{
4103 Serge 1326
	if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
2967 Serge 1327
		struct drm_device *dev = obj->dev;
4103 Serge 1328
 
2967 Serge 1329
		mutex_lock(&dev->struct_mutex);
4103 Serge 1330
		if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1331
			drm_gem_object_free(&obj->refcount);
2967 Serge 1332
		mutex_unlock(&dev->struct_mutex);
1333
	}
1408 serge 1334
}
1335
 
4103 Serge 1336
int drm_gem_handle_create_tail(struct drm_file *file_priv,
1337
			       struct drm_gem_object *obj,
1338
			       u32 *handlep);
1408 serge 1339
int drm_gem_handle_create(struct drm_file *file_priv,
1340
			  struct drm_gem_object *obj,
1341
			  u32 *handlep);
1987 serge 1342
int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1408 serge 1343
 
1344
 
3192 Serge 1345
void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1346
int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
4103 Serge 1347
int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
2967 Serge 1348
 
5056 serge 1349
struct page **drm_gem_get_pages(struct drm_gem_object *obj);
4103 Serge 1350
void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
1351
		bool dirty, bool accessed);
1352
 
1408 serge 1353
struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1354
					     struct drm_file *filp,
1355
					     u32 handle);
1356
int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1357
			struct drm_file *file_priv);
1358
int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1359
			struct drm_file *file_priv);
1360
int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1361
		       struct drm_file *file_priv);
1362
void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1363
void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1364
 
1365
extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1366
extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1367
extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1368
 
1369
static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1370
							 unsigned int token)
1371
{
1372
	struct drm_map_list *_entry;
1373
	list_for_each_entry(_entry, &dev->maplist, head)
1374
	    if (_entry->user_token == token)
1375
		return _entry->map;
1376
	return NULL;
1377
}
1378
 
1379
static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1380
{
1381
}
1382
 
5056 serge 1383
#include 
1408 serge 1384
 
5178 serge 1385
struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1386
				 struct device *parent);
1387
void drm_dev_ref(struct drm_device *dev);
1388
void drm_dev_unref(struct drm_device *dev);
1389
 
4103 Serge 1390
extern int drm_fill_in_dev(struct drm_device *dev,
1391
			   const struct pci_device_id *ent,
1392
			   struct drm_driver *driver);
1393
int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
1394
/*@}*/
3031 serge 1395
 
5178 serge 1396
/* PCI section */
1397
static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1398
{
1408 serge 1399
 
5178 serge 1400
	return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1401
}
1402
void drm_pci_agp_destroy(struct drm_device *dev);
1403
 
5056 serge 1404
#if 0
1405
extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1406
extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
4103 Serge 1407
extern int drm_get_pci_dev(struct pci_dev *pdev,
1408
			   const struct pci_device_id *ent,
1409
			   struct drm_driver *driver);
5056 serge 1410
#endif
1408 serge 1411
 
3031 serge 1412
#define DRM_PCIE_SPEED_25 1
1413
#define DRM_PCIE_SPEED_50 2
1414
#define DRM_PCIE_SPEED_80 4
1408 serge 1415
 
3031 serge 1416
extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1417
 
2967 Serge 1418
 
1419
static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1420
{
1421
    return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1422
}
1408 serge 1423
#endif				/* __KERNEL__ */
3031 serge 1424
 
1425
#define drm_sysfs_connector_add(connector)
1426
#define drm_sysfs_connector_remove(connector)
1427
 
4559 Serge 1428
#define LFB_SIZE 0x1000000
4103 Serge 1429
extern struct drm_device *main_device;
1430
extern struct drm_file *drm_file_handlers[256];
3391 Serge 1431
 
1408 serge 1432
#endif