Subversion Repositories Kolibri OS

Rev

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