Subversion Repositories Kolibri OS

Rev

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