Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5270 serge 1
/*
2
 * Internal Header for the Direct Rendering Manager
1408 serge 3
 *
4
 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
1964 serge 6
 * Copyright (c) 2009-2010, Code Aurora Forum.
1408 serge 7
 * All rights reserved.
8
 *
5270 serge 9
 * Author: Rickard E. (Rik) Faith 
10
 * Author: Gareth Hughes 
11
 *
1408 serge 12
 * Permission is hereby granted, free of charge, to any person obtaining a
13
 * copy of this software and associated documentation files (the "Software"),
14
 * to deal in the Software without restriction, including without limitation
15
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
 * and/or sell copies of the Software, and to permit persons to whom the
17
 * Software is furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice (including the next
20
 * paragraph) shall be included in all copies or substantial portions of the
21
 * Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26
 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29
 * OTHER DEALINGS IN THE SOFTWARE.
30
 */
31
 
32
#ifndef _DRM_P_H_
33
#define _DRM_P_H_
34
 
2967 Serge 35
#include 
5270 serge 36
#include 
2967 Serge 37
 
5270 serge 38
#include 
39
#include 
40
#include 
41
#include 
42
#include 
1408 serge 43
#include 
44
#include 
5270 serge 45
#include 
46
 
1408 serge 47
#include 
5270 serge 48
#include 
49
#include 
3391 Serge 50
#include 
1408 serge 51
 
3763 Serge 52
#include 
53
#include 
54
 
5056 serge 55
 
3747 Serge 56
#include 
5056 serge 57
#include 
58
#include 
5270 serge 59
#include 
3482 Serge 60
#include 
61
 
5270 serge 62
#include 
63
#include 
3482 Serge 64
 
5270 serge 65
#include 
66
#include 
67
#include 
68
#include 
69
#include 
70
#include 
71
#include 
72
#include 
4103 Serge 73
#include 
1408 serge 74
 
3031 serge 75
struct module;
1408 serge 76
 
77
struct drm_file;
78
struct drm_device;
5270 serge 79
struct drm_agp_head;
80
struct drm_local_map;
81
struct drm_device_dma;
82
struct drm_dma_handle;
83
struct drm_gem_object;
1408 serge 84
 
3391 Serge 85
struct device_node;
86
struct videomode;
5056 serge 87
struct reservation_object;
5270 serge 88
struct dma_buf_attachment;
4103 Serge 89
 
90
struct inode;
91
struct poll_table_struct;
92
struct sg_table;
93
 
1408 serge 94
#define KHZ2PICOS(a) (1000000000UL/(a))
95
 
3031 serge 96
/*
5056 serge 97
 * 4 debug categories are defined:
3031 serge 98
 *
5056 serge 99
 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
100
 *	 This is the category used by the DRM_DEBUG() macro.
3031 serge 101
 *
5056 serge 102
 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
103
 *	   This is the category used by the DRM_DEBUG_DRIVER() macro.
3031 serge 104
 *
5056 serge 105
 * KMS: used in the modesetting code.
106
 *	This is the category used by the DRM_DEBUG_KMS() macro.
107
 *
108
 * PRIME: used in the prime code.
109
 *	  This is the category used by the DRM_DEBUG_PRIME() macro.
110
 *
6082 serge 111
 * ATOMIC: used in the atomic code.
112
 *	  This is the category used by the DRM_DEBUG_ATOMIC() macro.
113
 *
114
 * VBL: used for verbose debug message in the vblank code
115
 *	  This is the category used by the DRM_DEBUG_VBL() macro.
116
 *
5056 serge 117
 * Enabling verbose debug messages is done through the drm.debug parameter,
118
 * each category being enabled by a bit.
119
 *
120
 * drm.debug=0x1 will enable CORE messages
121
 * drm.debug=0x2 will enable DRIVER messages
122
 * drm.debug=0x3 will enable CORE and DRIVER messages
123
 * ...
6082 serge 124
 * drm.debug=0x3f will enable all messages
5056 serge 125
 *
126
 * An interesting feature is that it's possible to enable verbose logging at
127
 * run-time by echoing the debug value in its sysfs node:
128
 *   # echo 0xf > /sys/module/drm/parameters/debug
3031 serge 129
 */
5056 serge 130
#define DRM_UT_CORE 		0x01
131
#define DRM_UT_DRIVER		0x02
6082 serge 132
#define DRM_UT_KMS		0x04
5056 serge 133
#define DRM_UT_PRIME		0x08
6082 serge 134
#define DRM_UT_ATOMIC		0x10
135
#define DRM_UT_VBL		0x20
3031 serge 136
 
5056 serge 137
extern __printf(2, 3)
138
void drm_ut_debug_printk(const char *function_name,
6082 serge 139
			 const char *format, ...);
5270 serge 140
extern __printf(1, 2)
141
void drm_err(const char *format, ...);
1408 serge 142
 
143
/***********************************************************************/
144
/** \name DRM template customization defaults */
145
/*@{*/
146
 
147
/* driver capabilities and requirements mask */
6082 serge 148
#define DRIVER_USE_AGP			0x1
149
#define DRIVER_PCI_DMA			0x8
150
#define DRIVER_SG			0x10
151
#define DRIVER_HAVE_DMA			0x20
152
#define DRIVER_HAVE_IRQ			0x40
153
#define DRIVER_IRQ_SHARED		0x80
154
#define DRIVER_GEM			0x1000
155
#define DRIVER_MODESET			0x2000
156
#define DRIVER_PRIME			0x4000
157
#define DRIVER_RENDER			0x8000
158
#define DRIVER_ATOMIC			0x10000
159
#define DRIVER_KMS_LEGACY_CONTEXT	0x20000
1408 serge 160
 
161
/***********************************************************************/
162
/** \name Macros to make printk easier */
163
/*@{*/
164
 
165
/**
166
 * Error output.
167
 *
168
 * \param fmt printf() like format string.
169
 * \param arg arguments
170
 */
3031 serge 171
#define DRM_ERROR(fmt, ...)				\
6082 serge 172
	printk("DRM Error" fmt, ##__VA_ARGS__)
1408 serge 173
 
4559 Serge 174
/**
175
 * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
176
 *
177
 * \param fmt printf() like format string.
178
 * \param arg arguments
179
 */
180
#define DRM_ERROR_RATELIMITED(fmt, ...)				\
181
({									\
182
	static DEFINE_RATELIMIT_STATE(_rs,				\
183
				      DEFAULT_RATELIMIT_INTERVAL,	\
184
				      DEFAULT_RATELIMIT_BURST);		\
185
									\
186
	if (__ratelimit(&_rs))						\
5270 serge 187
		drm_err(fmt, ##__VA_ARGS__);				\
4559 Serge 188
})
189
 
3031 serge 190
#define DRM_INFO(fmt, ...)				\
191
	printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
1408 serge 192
 
5056 serge 193
#define DRM_INFO_ONCE(fmt, ...)				\
194
	printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
195
 
1408 serge 196
/**
197
 * Debug output.
198
 *
199
 * \param fmt printf() like format string.
200
 * \param arg arguments
201
 */
202
#if DRM_DEBUG_CODE
5056 serge 203
#define DRM_DEBUG(fmt, args...)						\
3031 serge 204
    do {                                                    \
5056 serge 205
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 206
	} while (0)
207
 
5056 serge 208
#define DRM_DEBUG_DRIVER(fmt, args...)					\
3031 serge 209
    do {                                                    \
5056 serge 210
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
3031 serge 211
	} while (0)
5056 serge 212
#define DRM_DEBUG_KMS(fmt, args...)					\
1408 serge 213
	do {								\
5056 serge 214
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 215
	} while (0)
5056 serge 216
#define DRM_DEBUG_PRIME(fmt, args...)					\
1408 serge 217
	do {								\
5056 serge 218
    printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
1408 serge 219
	} while (0)
6082 serge 220
#define DRM_DEBUG_ATOMIC(fmt, args...)					\
221
	do {								\
222
		printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
223
	} while (0)
224
#define DRM_DEBUG_VBL(fmt, args...)					\
225
	do {								\
226
		printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
227
	} while (0)
228
 
1408 serge 229
#else
230
#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
231
#define DRM_DEBUG_KMS(fmt, args...)	do { } while (0)
3031 serge 232
#define DRM_DEBUG_PRIME(fmt, args...)	do { } while (0)
1408 serge 233
#define DRM_DEBUG(fmt, arg...)		 do { } while (0)
6082 serge 234
#define DRM_DEBUG_ATOMIC(fmt, args...) do { } while (0)
235
#define DRM_DEBUG_VBL(fmt, args...) do { } while (0)
1408 serge 236
#endif
237
/*@}*/
238
 
239
/***********************************************************************/
240
/** \name Internal types and structures */
241
/*@{*/
242
 
243
#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
244
 
245
/**
246
 * Ioctl function type.
247
 *
248
 * \param inode device inode.
249
 * \param file_priv DRM file private pointer.
250
 * \param cmd command.
251
 * \param arg argument.
252
 */
253
typedef int drm_ioctl_t(struct drm_device *dev, void *data,
254
			struct drm_file *file_priv);
255
 
256
typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
257
			       unsigned long arg);
258
 
259
#define DRM_IOCTL_NR(n)                _IOC_NR(n)
260
#define DRM_MAJOR       226
261
 
262
#define DRM_AUTH	0x1
263
#define	DRM_MASTER	0x2
264
#define DRM_ROOT_ONLY	0x4
265
#define DRM_CONTROL_ALLOW 0x8
266
#define DRM_UNLOCKED	0x10
4103 Serge 267
#define DRM_RENDER_ALLOW 0x20
1408 serge 268
 
269
struct drm_ioctl_desc {
270
	unsigned int cmd;
271
	int flags;
272
	drm_ioctl_t *func;
3747 Serge 273
	const char *name;
1408 serge 274
};
275
 
276
/**
277
 * Creates a driver or general drm_ioctl_desc array entry for the given
278
 * ioctl, for use by drm_ioctl().
279
 */
280
 
6082 serge 281
#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)				\
282
	[DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {	\
283
		.cmd = DRM_IOCTL_##ioctl,				\
284
		.func = _func,						\
285
		.flags = _flags,					\
286
		.name = #ioctl						\
287
	 }
1964 serge 288
 
1408 serge 289
/* Event queued up for userspace to read */
290
struct drm_pending_event {
291
	struct drm_event *event;
292
	struct list_head link;
293
	struct drm_file *file_priv;
1964 serge 294
	pid_t pid; /* pid of requester, no guarantee it's valid by the time
295
		      we deliver the event, for tracing only */
1408 serge 296
	void (*destroy)(struct drm_pending_event *event);
297
};
298
 
3031 serge 299
/* initial implementaton using a linked list - todo hashtab */
300
struct drm_prime_file_private {
301
	struct list_head head;
302
	struct mutex lock;
303
};
304
 
1408 serge 305
/** File private data */
306
struct drm_file {
4559 Serge 307
	unsigned authenticated :1;
5056 serge 308
	/* Whether we're master for a minor. Protected by master_mutex */
309
	unsigned is_master :1;
4559 Serge 310
	/* true when the client has asked us to expose stereo 3D mode flags */
311
	unsigned stereo_allowed :1;
5056 serge 312
	/*
313
	 * true if client understands CRTC primary planes and cursor planes
314
	 * in the plane list
315
	 */
316
	unsigned universal_planes:1;
6082 serge 317
	/* true if client understands atomic properties */
318
	unsigned atomic:1;
1408 serge 319
	struct list_head lhead;
6082 serge 320
	struct drm_minor *minor;
1408 serge 321
	unsigned long lock_count;
322
 
323
	/** Mapping of mm object handles to object pointers. */
324
	struct idr object_idr;
325
	/** Lock for synchronization of access to object_idr. */
326
	spinlock_t table_lock;
327
 
328
	void *driver_priv;
329
 
5056 serge 330
	struct drm_master *master; /* master this node is currently associated with
331
				      N.B. not always minor->master */
332
	/**
333
	 * fbs - List of framebuffers associated with this file.
334
	 *
335
	 * Protected by fbs_lock. Note that the fbs list holds a reference on
336
	 * the fb object to prevent it from untimely disappearing.
337
	 */
1408 serge 338
	struct list_head fbs;
5056 serge 339
	struct mutex fbs_lock;
1408 serge 340
 
6082 serge 341
	/** User-created blob properties; this retains a reference on the
342
	 *  property. */
343
	struct list_head blobs;
344
 
1408 serge 345
	wait_queue_head_t event_wait;
346
	struct list_head event_list;
347
	int event_space;
348
};
349
 
350
/**
351
 * Lock data.
352
 */
353
struct drm_lock_data {
354
	struct drm_hw_lock *hw_lock;	/**< Hardware lock */
355
	/** Private of lock holder's file (NULL=kernel) */
356
	struct drm_file *file_priv;
357
	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
358
	unsigned long lock_time;	/**< Time of last lock in jiffies */
359
	spinlock_t spinlock;
360
	uint32_t kernel_waiters;
361
	uint32_t user_waiters;
362
	int idle_has_lock;
363
};
364
 
365
/**
5056 serge 366
 * struct drm_master - drm master structure
367
 *
368
 * @refcount: Refcount for this master object.
369
 * @minor: Link back to minor char device we are master for. Immutable.
370
 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
371
 * @unique_len: Length of unique field. Protected by drm_global_mutex.
6082 serge 372
 * @magic_map: Map of used authentication tokens. Protected by struct_mutex.
5056 serge 373
 * @lock: DRI lock information.
374
 * @driver_priv: Pointer to driver-private information.
375
 */
1408 serge 376
struct drm_master {
5056 serge 377
	struct kref refcount;
378
	struct drm_minor *minor;
379
	char *unique;
380
	int unique_len;
6082 serge 381
	struct idr magic_map;
5270 serge 382
	struct drm_lock_data lock;
5056 serge 383
	void *driver_priv;
1408 serge 384
};
385
 
1964 serge 386
/* Size of ringbuffer for vblank timestamps. Just double-buffer
387
 * in initial implementation.
388
 */
389
#define DRM_VBLANKTIME_RBSIZE 2
390
 
391
/* Flags and return codes for get_vblank_timestamp() driver function. */
392
#define DRM_CALLED_FROM_VBLIRQ 1
393
#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
5270 serge 394
#define DRM_VBLANKTIME_IN_VBLANK         (1 << 1)
1964 serge 395
 
396
/* get_scanout_position() return flags */
397
#define DRM_SCANOUTPOS_VALID        (1 << 0)
5270 serge 398
#define DRM_SCANOUTPOS_IN_VBLANK    (1 << 1)
1964 serge 399
#define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
400
 
1408 serge 401
/**
402
 * DRM driver structure. This structure represent the common code for
403
 * a family of cards. There will one drm_device for each card present
404
 * in this family
405
 */
406
struct drm_driver {
407
	int (*load) (struct drm_device *, unsigned long flags);
408
	int (*open) (struct drm_device *, struct drm_file *);
409
 
410
	/**
411
	 * get_vblank_counter - get raw hardware vblank counter
412
	 * @dev: DRM device
6082 serge 413
	 * @pipe: counter to fetch
1408 serge 414
	 *
3031 serge 415
	 * Driver callback for fetching a raw hardware vblank counter for @crtc.
416
	 * If a device doesn't have a hardware counter, the driver can simply
417
	 * return the value of drm_vblank_count. The DRM core will account for
418
	 * missed vblank events while interrupts where disabled based on system
419
	 * timestamps.
1408 serge 420
	 *
421
	 * Wraparound handling and loss of events due to modesetting is dealt
422
	 * with in the DRM core code.
423
	 *
424
	 * RETURNS
425
	 * Raw vblank counter value.
426
	 */
6082 serge 427
	u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
1408 serge 428
 
429
	/**
430
	 * enable_vblank - enable vblank interrupt events
431
	 * @dev: DRM device
6082 serge 432
	 * @pipe: which irq to enable
1408 serge 433
	 *
434
	 * Enable vblank interrupts for @crtc.  If the device doesn't have
435
	 * a hardware vblank counter, this routine should be a no-op, since
436
	 * interrupts will have to stay on to keep the count accurate.
437
	 *
438
	 * RETURNS
439
	 * Zero on success, appropriate errno if the given @crtc's vblank
440
	 * interrupt cannot be enabled.
441
	 */
6082 serge 442
	int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
1408 serge 443
 
444
	/**
445
	 * disable_vblank - disable vblank interrupt events
446
	 * @dev: DRM device
6082 serge 447
	 * @pipe: which irq to enable
1408 serge 448
	 *
449
	 * Disable vblank interrupts for @crtc.  If the device doesn't have
450
	 * a hardware vblank counter, this routine should be a no-op, since
451
	 * interrupts will have to stay on to keep the count accurate.
452
	 */
6082 serge 453
	void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
454
 
1408 serge 455
	/**
6082 serge 456
	 * Called by \c drm_device_is_agp.  Typically used to determine if a
457
	 * card is really attached to AGP or not.
458
	 *
459
	 * \param dev  DRM device handle
460
	 *
461
	 * \returns
462
	 * One of three values is returned depending on whether or not the
463
	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
464
	 * (return of 1), or may or may not be AGP (return of 2).
465
	 */
466
	int (*device_is_agp) (struct drm_device *dev);
467
 
468
	/**
1964 serge 469
	 * Called by vblank timestamping code.
470
	 *
4559 Serge 471
	 * Return the current display scanout position from a crtc, and an
472
	 * optional accurate ktime_get timestamp of when position was measured.
1964 serge 473
	 *
474
	 * \param dev  DRM device.
6082 serge 475
	 * \param pipe Id of the crtc to query.
4559 Serge 476
	 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
1964 serge 477
	 * \param *vpos Target location for current vertical scanout position.
478
	 * \param *hpos Target location for current horizontal scanout position.
4559 Serge 479
	 * \param *stime Target location for timestamp taken immediately before
480
	 *               scanout position query. Can be NULL to skip timestamp.
481
	 * \param *etime Target location for timestamp taken immediately after
482
	 *               scanout position query. Can be NULL to skip timestamp.
6082 serge 483
	 * \param mode Current display timings.
1964 serge 484
	 *
485
	 * Returns vpos as a positive number while in active scanout area.
486
	 * Returns vpos as a negative number inside vblank, counting the number
487
	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
488
	 * until start of active scanout / end of vblank."
489
	 *
490
	 * \return Flags, or'ed together as follows:
491
	 *
492
	 * DRM_SCANOUTPOS_VALID = Query successful.
493
	 * DRM_SCANOUTPOS_INVBL = Inside vblank.
494
	 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
495
	 * this flag means that returned position may be offset by a constant
496
	 * but unknown small number of scanlines wrt. real scanout position.
497
	 *
498
	 */
6082 serge 499
	int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
500
				     unsigned int flags, int *vpos, int *hpos,
501
				     ktime_t *stime, ktime_t *etime,
502
				     const struct drm_display_mode *mode);
1964 serge 503
 
504
	/**
505
	 * Called by \c drm_get_last_vbltimestamp. Should return a precise
506
	 * timestamp when the most recent VBLANK interval ended or will end.
507
	 *
508
	 * Specifically, the timestamp in @vblank_time should correspond as
509
	 * closely as possible to the time when the first video scanline of
510
	 * the video frame after the end of VBLANK will start scanning out,
2967 Serge 511
	 * the time immediately after end of the VBLANK interval. If the
1964 serge 512
	 * @crtc is currently inside VBLANK, this will be a time in the future.
513
	 * If the @crtc is currently scanning out a frame, this will be the
514
	 * past start time of the current scanout. This is meant to adhere
515
	 * to the OpenML OML_sync_control extension specification.
516
	 *
517
	 * \param dev dev DRM device handle.
6082 serge 518
	 * \param pipe crtc for which timestamp should be returned.
1964 serge 519
	 * \param *max_error Maximum allowable timestamp error in nanoseconds.
520
	 *                   Implementation should strive to provide timestamp
521
	 *                   with an error of at most *max_error nanoseconds.
522
	 *                   Returns true upper bound on error for timestamp.
523
	 * \param *vblank_time Target location for returned vblank timestamp.
524
	 * \param flags 0 = Defaults, no special treatment needed.
525
	 * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
526
	 *	        irq handler. Some drivers need to apply some workarounds
527
	 *              for gpu-specific vblank irq quirks if flag is set.
528
	 *
529
	 * \returns
530
	 * Zero if timestamping isn't supported in current display mode or a
531
	 * negative number on failure. A positive status code on success,
532
	 * which describes how the vblank_time timestamp was computed.
533
	 */
6082 serge 534
	int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
1964 serge 535
				     int *max_error,
536
				     struct timeval *vblank_time,
537
				     unsigned flags);
538
 
1408 serge 539
	/* these have to be filled in */
540
 
5056 serge 541
	irqreturn_t(*irq_handler) (int irq, void *arg);
1408 serge 542
	void (*irq_preinstall) (struct drm_device *dev);
543
	int (*irq_postinstall) (struct drm_device *dev);
544
	void (*irq_uninstall) (struct drm_device *dev);
545
 
546
	/**
547
	 * Driver-specific constructor for drm_gem_objects, to set up
548
	 * obj->driver_private.
549
	 *
550
	 * Returns 0 on success.
551
	 */
552
	void (*gem_free_object) (struct drm_gem_object *obj);
2967 Serge 553
	int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
554
	void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
1408 serge 555
	u32 driver_features;
5056 serge 556
	int dev_priv_size;
1408 serge 557
};
558
 
5056 serge 559
enum drm_minor_type {
560
	DRM_MINOR_LEGACY,
561
	DRM_MINOR_CONTROL,
562
	DRM_MINOR_RENDER,
563
	DRM_MINOR_CNT,
564
};
1408 serge 565
 
566
/**
567
 * Info file list entry. This structure represents a debugfs or proc file to
568
 * be created by the drm core
569
 */
570
struct drm_info_list {
571
	const char *name; /** file name */
2967 Serge 572
//   int (*show)(struct seq_file*, void*); /** show callback */
1408 serge 573
	u32 driver_features; /**< Required driver features for this entry */
574
	void *data;
575
};
576
 
577
/**
578
 * debugfs node structure. This structure represents a debugfs file.
579
 */
580
struct drm_info_node {
581
	struct list_head list;
582
	struct drm_minor *minor;
4065 Serge 583
	const struct drm_info_list *info_ent;
1408 serge 584
	struct dentry *dent;
585
};
586
 
587
/**
588
 * DRM minor structure. This structure represents a drm minor number.
589
 */
590
struct drm_minor {
591
	int index;			/**< Minor device number */
592
	int type;                       /**< Control or render */
6082 serge 593
	struct device *kdev;		/**< Linux device */
1408 serge 594
	struct drm_device *dev;
595
 
5056 serge 596
	struct dentry *debugfs_root;
1408 serge 597
 
5056 serge 598
	struct list_head debugfs_list;
599
	struct mutex debugfs_lock; /* Protects debugfs_list. */
1408 serge 600
 
5056 serge 601
	/* currently active master for this node. Protected by master_mutex */
602
	struct drm_master *master;
1964 serge 603
};
1408 serge 604
 
605
 
5270 serge 606
struct drm_pending_vblank_event {
607
	struct drm_pending_event base;
6082 serge 608
	unsigned int pipe;
5270 serge 609
	struct drm_event_vblank event;
610
};
1408 serge 611
 
5270 serge 612
struct drm_vblank_crtc {
613
	struct drm_device *dev;		/* pointer to the drm_device */
614
	wait_queue_head_t queue;	/**< VBLANK wait queue */
615
	struct timer_list disable_timer;		/* delayed disable timer */
6082 serge 616
 
617
	/* vblank counter, protected by dev->vblank_time_lock for writes */
618
	u32 count;
619
	/* vblank timestamps, protected by dev->vblank_time_lock for writes */
620
	struct timeval time[DRM_VBLANKTIME_RBSIZE];
621
 
5270 serge 622
	atomic_t refcount;		/* number of users of vblank interruptsper crtc */
623
	u32 last;			/* protected by dev->vbl_lock, used */
624
					/* for wraparound handling */
625
	u32 last_wait;			/* Last vblank seqno waited per CRTC */
626
	unsigned int inmodeset;		/* Display driver is setting mode */
6082 serge 627
	unsigned int pipe;		/* crtc index */
628
	int framedur_ns;		/* frame/field duration in ns */
629
	int linedur_ns;			/* line duration in ns */
5270 serge 630
	bool enabled;			/* so we don't call enable more than
631
					   once per disable */
632
};
633
 
1408 serge 634
/**
635
 * DRM device structure. This structure represent a complete card that
636
 * may contain multiple heads.
637
 */
638
struct drm_device {
4559 Serge 639
	struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
1408 serge 640
	int if_version;			/**< Highest interface version set */
641
 
5270 serge 642
	/** \name Lifetime Management */
643
	/*@{ */
644
	struct kref ref;		/**< Object ref-count */
5056 serge 645
	struct device *dev;		/**< Device structure of bus-device */
646
	struct drm_driver *driver;	/**< DRM driver managing the device */
647
	void *dev_private;		/**< DRM driver private data */
6082 serge 648
	struct drm_minor *control;		/**< Control node */
5056 serge 649
	struct drm_minor *primary;		/**< Primary node */
6082 serge 650
	struct drm_minor *render;		/**< Render node */
5056 serge 651
	atomic_t unplugged;			/**< Flag whether dev is dead */
1408 serge 652
	/** \name Locks */
653
	/*@{ */
1630 serge 654
	struct mutex struct_mutex;	/**< For others */
5056 serge 655
	struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
1408 serge 656
	/*@} */
657
 
658
	/** \name Usage Counters */
659
	/*@{ */
5056 serge 660
	int open_count;			/**< Outstanding files open, protected by drm_global_mutex. */
661
	spinlock_t buf_lock;		/**< For drm_device::buf_use and a few other things. */
1408 serge 662
	int buf_use;			/**< Buffers in use -- cannot alloc */
6082 serge 663
	atomic_t buf_alloc;		/**< Buffer allocation in progress */
1408 serge 664
	/*@} */
665
 
666
	struct list_head filelist;
667
 
668
	/** \name Memory management */
669
	/*@{ */
670
	struct list_head maplist;	/**< Linked list of regions */
671
 
672
	/** \name Context handle management */
673
	/*@{ */
674
	struct list_head ctxlist;	/**< Linked list of context handles */
1630 serge 675
	struct mutex ctxlist_mutex;	/**< For ctxlist */
1408 serge 676
 
1964 serge 677
	struct idr ctx_idr;
1408 serge 678
 
679
	struct list_head vmalist;	/**< List of vmas (for debugging) */
680
 
681
	/*@} */
682
 
3031 serge 683
	/** \name DMA support */
1408 serge 684
	/*@{ */
685
//   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
686
	/*@} */
687
 
688
	/** \name Context support */
689
	/*@{ */
5056 serge 690
 
1408 serge 691
	__volatile__ long context_flag;	/**< Context swapping flag */
692
	int last_context;		/**< Last current context */
693
	/*@} */
694
 
695
	/** \name VBLANK IRQ support */
696
	/*@{ */
6082 serge 697
	bool irq_enabled;
698
	int irq;
1408 serge 699
 
700
	/*
701
	 * At load time, disabling the vblank interrupt won't be allowed since
702
	 * old clients may not call the modeset ioctl and therefore misbehave.
703
	 * Once the modeset ioctl *has* been called though, we can safely
704
	 * disable them when unused.
705
	 */
4559 Serge 706
	bool vblank_disable_allowed;
1408 serge 707
 
5270 serge 708
	/*
709
	 * If true, vblank interrupt will be disabled immediately when the
710
	 * refcount drops to zero, as opposed to via the vblank disable
711
	 * timer.
712
	 * This can be set to true it the hardware has a working vblank
713
	 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
714
	 * appropriately.
715
	 */
716
	bool vblank_disable_immediate;
717
 
5056 serge 718
	/* array of size num_crtcs */
719
	struct drm_vblank_crtc *vblank;
1408 serge 720
 
5056 serge 721
	spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
722
	spinlock_t vbl_lock;
723
 
1408 serge 724
	u32 max_vblank_count;           /**< size of vblank counter register */
725
 
1964 serge 726
	/**
727
	 * List of events
728
	 */
729
	struct list_head vblank_event_list;
730
	spinlock_t event_lock;
731
 
1408 serge 732
	/*@} */
733
 
734
//   struct drm_agp_head *agp;   /**< AGP data */
735
 
736
	struct pci_dev *pdev;		/**< PCI device structure */
5056 serge 737
 
1964 serge 738
	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1408 serge 739
 
5270 serge 740
	struct {
741
		int context;
742
		struct drm_hw_lock *lock;
743
	} sigdata;
1408 serge 744
 
6082 serge 745
	struct drm_mode_config mode_config;	/**< Current mode config */
1408 serge 746
 
747
	/** \name GEM information */
748
	/*@{ */
4103 Serge 749
	struct mutex object_name_lock;
1964 serge 750
	struct idr object_name_idr;
4559 Serge 751
	struct drm_vma_offset_manager *vma_offset_manager;
1408 serge 752
	/*@} */
1964 serge 753
	int switch_power_state;
1408 serge 754
};
755
 
1964 serge 756
#define DRM_SWITCH_POWER_ON 0
757
#define DRM_SWITCH_POWER_OFF 1
758
#define DRM_SWITCH_POWER_CHANGING 2
4103 Serge 759
#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1964 serge 760
 
3482 Serge 761
static __inline__ int drm_core_check_feature(struct drm_device *dev,
762
					     int feature)
763
{
764
	return ((dev->driver->driver_features & feature) ? 1 : 0);
765
}
1964 serge 766
 
4065 Serge 767
static inline void drm_device_set_unplugged(struct drm_device *dev)
1408 serge 768
{
4065 Serge 769
	smp_wmb();
770
	atomic_set(&dev->unplugged, 1);
1408 serge 771
}
772
 
4065 Serge 773
static inline int drm_device_is_unplugged(struct drm_device *dev)
1408 serge 774
{
4065 Serge 775
	int ret = atomic_read(&dev->unplugged);
776
	smp_rmb();
777
	return ret;
1408 serge 778
}
779
 
780
 
781
/******************************************************************/
782
/** \name Internal function definitions */
783
/*@{*/
784
 
785
				/* Driver support (drm_drv.h) */
6082 serge 786
extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
1408 serge 787
extern long drm_ioctl(struct file *filp,
6082 serge 788
		      unsigned int cmd, unsigned long arg);
1408 serge 789
extern long drm_compat_ioctl(struct file *filp,
790
			     unsigned int cmd, unsigned long arg);
5056 serge 791
extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1408 serge 792
 
793
				/* Device support (drm_fops.h) */
794
extern int drm_open(struct inode *inode, struct file *filp);
795
extern ssize_t drm_read(struct file *filp, char __user *buffer,
796
			size_t count, loff_t *offset);
797
extern int drm_release(struct inode *inode, struct file *filp);
6082 serge 798
extern int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv);
1408 serge 799
 
800
				/* Mapping support (drm_vm.h) */
801
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
802
 
5270 serge 803
/* Misc. IOCTL support (drm_ioctl.c) */
804
int drm_noop(struct drm_device *dev, void *data,
6082 serge 805
	     struct drm_file *file_priv);
806
int drm_invalid_op(struct drm_device *dev, void *data,
807
		   struct drm_file *file_priv);
1408 serge 808
 
809
/* Cache management (drm_cache.c) */
810
void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
3031 serge 811
void drm_clflush_sg(struct sg_table *st);
5056 serge 812
void drm_clflush_virt_range(void *addr, unsigned long length);
1408 serge 813
 
814
/*
815
 * These are exported to drivers so that they can implement fencing using
816
 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
817
 */
818
 
819
				/* IRQ support (drm_irq.h) */
5056 serge 820
extern int drm_irq_install(struct drm_device *dev, int irq);
1408 serge 821
extern int drm_irq_uninstall(struct drm_device *dev);
822
 
6082 serge 823
extern int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
1408 serge 824
extern int drm_wait_vblank(struct drm_device *dev, void *data,
825
			   struct drm_file *filp);
6082 serge 826
extern u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
827
extern u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
828
extern u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
1964 serge 829
				     struct timeval *vblanktime);
6082 serge 830
extern u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
831
					  struct timeval *vblanktime);
832
extern void drm_send_vblank_event(struct drm_device *dev, unsigned int pipe,
833
				  struct drm_pending_vblank_event *e);
834
extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
835
				       struct drm_pending_vblank_event *e);
836
extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
837
extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
838
extern int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
839
extern void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
5056 serge 840
extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
841
extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
6082 serge 842
extern void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
5270 serge 843
extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
6082 serge 844
extern void drm_vblank_off(struct drm_device *dev, unsigned int pipe);
845
extern void drm_vblank_on(struct drm_device *dev, unsigned int pipe);
5056 serge 846
extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
6082 serge 847
extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
5056 serge 848
extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1408 serge 849
extern void drm_vblank_cleanup(struct drm_device *dev);
6082 serge 850
extern u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe);
5056 serge 851
 
1964 serge 852
extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
6082 serge 853
						 unsigned int pipe, int *max_error,
1964 serge 854
						 struct timeval *vblank_time,
855
						 unsigned flags,
4559 Serge 856
						 const struct drm_display_mode *mode);
857
extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
858
					    const struct drm_display_mode *mode);
1964 serge 859
 
5270 serge 860
/**
861
 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
862
 * @crtc: which CRTC's vblank waitqueue to retrieve
863
 *
864
 * This function returns a pointer to the vblank waitqueue for the CRTC.
865
 * Drivers can use this to implement vblank waits using wait_event() & co.
866
 */
867
static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
868
{
869
	return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
870
}
1964 serge 871
 
1408 serge 872
/* Modesetting support */
6082 serge 873
extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
874
extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
1408 serge 875
 
876
				/* Stub support (drm_stub.h) */
877
extern struct drm_master *drm_master_get(struct drm_master *master);
878
extern void drm_master_put(struct drm_master **master);
1964 serge 879
 
1408 serge 880
extern void drm_put_dev(struct drm_device *dev);
3031 serge 881
extern void drm_unplug_dev(struct drm_device *dev);
1408 serge 882
extern unsigned int drm_debug;
6082 serge 883
extern bool drm_atomic;
1408 serge 884
 
885
				/* Debugfs support */
886
#if defined(CONFIG_DEBUG_FS)
4559 Serge 887
extern int drm_debugfs_create_files(const struct drm_info_list *files,
888
				    int count, struct dentry *root,
6082 serge 889
				    struct drm_minor *minor);
4559 Serge 890
extern int drm_debugfs_remove_files(const struct drm_info_list *files,
891
				    int count, struct drm_minor *minor);
892
#else
893
static inline int drm_debugfs_create_files(const struct drm_info_list *files,
894
					   int count, struct dentry *root,
895
					   struct drm_minor *minor)
896
{
897
	return 0;
898
}
899
 
900
static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
901
					   int count, struct drm_minor *minor)
902
{
903
	return 0;
904
}
1408 serge 905
#endif
906
 
5270 serge 907
extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
908
		struct drm_gem_object *obj, int flags);
909
extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
910
		struct drm_file *file_priv, uint32_t handle, uint32_t flags,
911
		int *prime_fd);
912
extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
913
		struct dma_buf *dma_buf);
914
extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
915
		struct drm_file *file_priv, int prime_fd, uint32_t *handle);
916
extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
1408 serge 917
 
5270 serge 918
extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
919
					    dma_addr_t *addrs, int max_pages);
920
extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
921
extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1408 serge 922
 
923
 
5270 serge 924
extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
6082 serge 925
					    size_t align);
5270 serge 926
extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1408 serge 927
 
928
			       /* sysfs support (drm_sysfs.c) */
929
extern void drm_sysfs_hotplug_event(struct drm_device *dev);
2967 Serge 930
 
1408 serge 931
 
5178 serge 932
struct drm_device *drm_dev_alloc(struct drm_driver *driver,
933
				 struct device *parent);
934
void drm_dev_ref(struct drm_device *dev);
935
void drm_dev_unref(struct drm_device *dev);
5270 serge 936
int drm_dev_register(struct drm_device *dev, unsigned long flags);
937
void drm_dev_unregister(struct drm_device *dev);
938
int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
5178 serge 939
 
5270 serge 940
struct drm_minor *drm_minor_acquire(unsigned int minor_id);
941
void drm_minor_release(struct drm_minor *minor);
942
 
4103 Serge 943
/*@}*/
3031 serge 944
 
5178 serge 945
/* PCI section */
946
static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
947
{
1408 serge 948
 
5178 serge 949
	return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
950
}
951
void drm_pci_agp_destroy(struct drm_device *dev);
952
 
5056 serge 953
#if 0
954
extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
955
extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
4103 Serge 956
extern int drm_get_pci_dev(struct pci_dev *pdev,
957
			   const struct pci_device_id *ent,
958
			   struct drm_driver *driver);
5056 serge 959
#endif
1408 serge 960
 
3031 serge 961
#define DRM_PCIE_SPEED_25 1
962
#define DRM_PCIE_SPEED_50 2
963
#define DRM_PCIE_SPEED_80 4
1408 serge 964
 
3031 serge 965
extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
966
 
2967 Serge 967
 
968
static __inline__ int drm_device_is_pcie(struct drm_device *dev)
969
{
970
    return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
971
}
3031 serge 972
 
4559 Serge 973
#define LFB_SIZE 0x1000000
4103 Serge 974
extern struct drm_device *main_device;
975
extern struct drm_file *drm_file_handlers[256];
3391 Serge 976
 
1408 serge 977
#endif