Subversion Repositories Kolibri OS

Rev

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