1
/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2
* Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
4
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice (including the next
16
* paragraph) shall be included in all copies or substantial portions of the
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
* OTHER DEALINGS IN THE SOFTWARE.
28
* Rickard E. (Rik) Faith <faith@valinux.com>
29
* Gareth Hughes <gareth@valinux.com>
35
#if defined(_KERNEL) || defined(__KERNEL__)
37
/* DRM template customization defaults
45
#ifndef __HAVE_CTX_BITMAP
46
#define __HAVE_CTX_BITMAP 0
51
#ifndef __HAVE_DMA_IRQ
52
#define __HAVE_DMA_IRQ 0
54
#ifndef __HAVE_DMA_WAITLIST
55
#define __HAVE_DMA_WAITLIST 0
57
#ifndef __HAVE_DMA_FREELIST
58
#define __HAVE_DMA_FREELIST 0
60
#ifndef __HAVE_DMA_HISTOGRAM
61
#define __HAVE_DMA_HISTOGRAM 0
64
#define DRM_DEBUG_CODE 0 /* Include debugging code (if > 1, then
65
also include looping detection. */
67
typedef struct drm_device drm_device_t;
68
typedef struct drm_file drm_file_t;
70
/* There's undoubtably more of this file to go into these OS dependent ones. */
73
#include "drm_os_freebsd.h"
74
#elif defined __NetBSD__
75
#include "drm_os_netbsd.h"
80
/* Begin the DRM... */
82
#define DRM_HASH_SIZE 16 /* Size of key hash table */
83
#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
84
#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
85
#define DRM_LOOPING_LIMIT 5000000
86
#define DRM_BSZ 1024 /* Buffer size for /dev/drm? output */
87
#define DRM_LOCK_SLICE 1 /* Time slice for lock, in jiffies */
89
#define DRM_FLAG_DEBUG 0x01
90
#define DRM_FLAG_NOCTX 0x02
93
#define DRM_MEM_SAREA 1
94
#define DRM_MEM_DRIVER 2
95
#define DRM_MEM_MAGIC 3
96
#define DRM_MEM_IOCTLS 4
97
#define DRM_MEM_MAPS 5
98
#define DRM_MEM_VMAS 6
99
#define DRM_MEM_BUFS 7
100
#define DRM_MEM_SEGS 8
101
#define DRM_MEM_PAGES 9
102
#define DRM_MEM_FILES 10
103
#define DRM_MEM_QUEUES 11
104
#define DRM_MEM_CMDS 12
105
#define DRM_MEM_MAPPINGS 13
106
#define DRM_MEM_BUFLISTS 14
107
#define DRM_MEM_AGPLISTS 15
108
#define DRM_MEM_TOTALAGP 16
109
#define DRM_MEM_BOUNDAGP 17
110
#define DRM_MEM_CTXBITMAP 18
111
#define DRM_MEM_STUB 19
112
#define DRM_MEM_SGLISTS 20
114
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
116
/* Backward compatibility section */
117
/* _PAGE_WT changed to _PAGE_PWT in 2.2.6 */
119
#define _PAGE_PWT _PAGE_WT
122
/* Mapping helper macros */
123
#define DRM_IOREMAP(map) \
124
(map)->handle = DRM(ioremap)( (map)->offset, (map)->size )
126
#define DRM_IOREMAP_NOCACHE(map) \
127
(map)->handle = DRM(ioremap_nocache)((map)->offset, (map)->size)
129
#define DRM_IOREMAPFREE(map) \
131
if ( (map)->handle && (map)->size ) \
132
DRM(ioremapfree)( (map)->handle, (map)->size ); \
135
/* Internal types and structures */
136
#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
137
#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
138
#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
140
#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
141
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
142
#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
144
#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
145
(_map) = (_dev)->context_sareas[_ctx]; \
149
typedef struct drm_pci_list {
154
typedef struct drm_ioctl_desc {
160
typedef struct drm_devstate {
161
pid_t owner; /* X server pid holding x_lock */
165
typedef struct drm_magic_entry {
167
struct drm_file *priv;
168
struct drm_magic_entry *next;
171
typedef struct drm_magic_head {
172
struct drm_magic_entry *head;
173
struct drm_magic_entry *tail;
176
typedef struct drm_vma_entry {
177
struct vm_area_struct *vma;
178
struct drm_vma_entry *next;
182
typedef struct drm_buf {
183
int idx; /* Index into master buflist */
184
int total; /* Buffer size */
185
int order; /* log-base-2(total) */
186
int used; /* Amount of buffer in use (for DMA) */
187
unsigned long offset; /* Byte offset (used internally) */
188
void *address; /* Address of buffer */
189
unsigned long bus_address; /* Bus address of buffer */
190
struct drm_buf *next; /* Kernel-only: used for free list */
191
__volatile__ int waiting; /* On kernel DMA queue */
192
__volatile__ int pending; /* On hardware DMA queue */
193
wait_queue_head_t dma_wait; /* Processes waiting */
194
pid_t pid; /* PID of holding process */
195
int context; /* Kernel queue for this buffer */
196
int while_locked;/* Dispatch this buffer while locked */
204
} list; /* Which list we're on */
206
#if DRM_DMA_HISTOGRAM
207
cycles_t time_queued; /* Queued to kernel DMA queue */
208
cycles_t time_dispatched; /* Dispatched to hardware */
209
cycles_t time_completed; /* Completed by hardware */
210
cycles_t time_freed; /* Back on freelist */
213
int dev_priv_size; /* Size of buffer private stoarge */
214
void *dev_private; /* Per-buffer private storage */
217
#if DRM_DMA_HISTOGRAM
218
#define DRM_DMA_HISTOGRAM_SLOTS 9
219
#define DRM_DMA_HISTOGRAM_INITIAL 10
220
#define DRM_DMA_HISTOGRAM_NEXT(current) ((current)*10)
221
typedef struct drm_histogram {
224
atomic_t queued_to_dispatched[DRM_DMA_HISTOGRAM_SLOTS];
225
atomic_t dispatched_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
226
atomic_t completed_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
228
atomic_t queued_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
229
atomic_t queued_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
231
atomic_t dma[DRM_DMA_HISTOGRAM_SLOTS];
232
atomic_t schedule[DRM_DMA_HISTOGRAM_SLOTS];
233
atomic_t ctx[DRM_DMA_HISTOGRAM_SLOTS];
234
atomic_t lacq[DRM_DMA_HISTOGRAM_SLOTS];
235
atomic_t lhld[DRM_DMA_HISTOGRAM_SLOTS];
239
/* bufs is one longer than it has to be */
240
typedef struct drm_waitlist {
241
int count; /* Number of possible buffers */
242
drm_buf_t **bufs; /* List of pointers to buffers */
243
drm_buf_t **rp; /* Read pointer */
244
drm_buf_t **wp; /* Write pointer */
245
drm_buf_t **end; /* End pointer */
246
DRM_SPINTYPE read_lock;
247
DRM_SPINTYPE write_lock;
250
typedef struct drm_freelist {
251
int initialized; /* Freelist in use */
252
atomic_t count; /* Number of free buffers */
253
drm_buf_t *next; /* End pointer */
255
wait_queue_head_t waiting; /* Processes waiting on free bufs */
256
int low_mark; /* Low water mark */
257
int high_mark; /* High water mark */
258
atomic_t wfh; /* If waiting for high mark */
262
typedef struct drm_buf_entry {
268
unsigned long *seglist;
270
drm_freelist_t freelist;
273
typedef struct drm_hw_lock {
274
__volatile__ unsigned int lock;
275
char padding[60]; /* Pad to cache line */
278
typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
280
TAILQ_ENTRY(drm_file) link;
287
unsigned long ioctl_count;
288
struct drm_device *devXX;
291
typedef struct drm_queue {
292
atomic_t use_count; /* Outstanding uses (+1) */
293
atomic_t finalization; /* Finalization in progress */
294
atomic_t block_count; /* Count of processes waiting */
295
atomic_t block_read; /* Queue blocked for reads */
296
wait_queue_head_t read_queue; /* Processes waiting on block_read */
297
atomic_t block_write; /* Queue blocked for writes */
298
wait_queue_head_t write_queue; /* Processes waiting on block_write */
300
atomic_t total_queued; /* Total queued statistic */
301
atomic_t total_flushed;/* Total flushes statistic */
302
atomic_t total_locks; /* Total locks statistics */
304
drm_ctx_flags_t flags; /* Context preserving and 2D-only */
305
drm_waitlist_t waitlist; /* Pending buffers */
306
wait_queue_head_t flush_queue; /* Processes waiting until flush */
309
typedef struct drm_lock_data {
310
drm_hw_lock_t *hw_lock; /* Hardware lock */
311
pid_t pid; /* PID of lock holder (0=kernel) */
312
wait_queue_head_t lock_queue; /* Queue of blocked processes */
313
unsigned long lock_time; /* Time of last lock in jiffies */
316
typedef struct drm_device_dma {
318
/* Performance Counters */
319
atomic_t total_prio; /* Total DRM_DMA_PRIORITY */
320
atomic_t total_bytes; /* Total bytes DMA'd */
321
atomic_t total_dmas; /* Total DMA buffers dispatched */
323
atomic_t total_missed_dma; /* Missed drm_do_dma */
324
atomic_t total_missed_lock; /* Missed lock in drm_do_dma */
325
atomic_t total_missed_free; /* Missed drm_free_this_buffer */
326
atomic_t total_missed_sched;/* Missed drm_dma_schedule */
328
atomic_t total_tried; /* Tried next_buffer */
329
atomic_t total_hit; /* Sent next_buffer */
330
atomic_t total_lost; /* Lost interrupt */
333
drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
335
drm_buf_t **buflist; /* Vector of pointers info bufs */
338
unsigned long *pagelist;
339
unsigned long byte_count;
341
_DRM_DMA_USE_AGP = 0x01,
342
_DRM_DMA_USE_SG = 0x02
346
drm_buf_t *this_buffer; /* Buffer being sent */
347
drm_buf_t *next_buffer; /* Selected buffer to send */
348
drm_queue_t *next_queue; /* Queue from which buffer selected*/
349
wait_queue_head_t waiting; /* Processes waiting on free bufs */
352
#if __REALLY_HAVE_AGP
353
typedef struct drm_agp_mem {
355
unsigned long bound; /* address */
357
struct drm_agp_mem *prev;
358
struct drm_agp_mem *next;
361
typedef struct drm_agp_head {
363
struct agp_info info;
365
drm_agp_mem_t *memory;
371
int cant_use_aperture;
372
unsigned long page_mask;
376
typedef struct drm_sg_mem {
377
unsigned long handle;
380
struct page **pagelist;
384
typedef struct drm_sigdata {
389
typedef TAILQ_HEAD(drm_map_list, drm_map_list_entry) drm_map_list_t;
390
typedef struct drm_map_list_entry {
391
TAILQ_ENTRY(drm_map_list_entry) link;
393
} drm_map_list_entry_t;
397
struct device device; /* NetBSD's softc is an extension of struct device */
399
const char *name; /* Simple driver name */
400
char *unique; /* Unique identifier: e.g., busid */
401
int unique_len; /* Length of unique field */
403
device_t device; /* Device instance from newbus */
405
dev_t devnode; /* Device number for mknod */
406
char *devname; /* For /proc/interrupts */
408
int blocked; /* Blocked due to VC switch? */
409
int flags; /* Flags to open(2) */
410
int writable; /* Opened with FWRITE */
413
DRM_SPINTYPE count_lock; /* For inuse, open_count, buf_use */
414
struct lock dev_lock; /* For others */
416
int open_count; /* Outstanding files open */
417
atomic_t ioctl_count; /* Outstanding IOCTLs pending */
418
atomic_t vma_count; /* Outstanding vma areas open */
419
int buf_use; /* Buffers in use -- cannot alloc */
420
atomic_t buf_alloc; /* Buffer allocation in progress */
422
/* Performance counters */
423
unsigned long counters;
424
drm_stat_type_t types[15];
428
drm_file_list_t files;
429
drm_magic_head_t magiclist[DRM_HASH_SIZE];
431
/* Memory management */
432
drm_map_list_t *maplist; /* Linked list of regions */
433
int map_count; /* Number of mappable regions */
435
drm_map_t **context_sareas;
438
drm_vma_entry_t *vmalist; /* List of vmas (for debugging) */
439
drm_lock_data_t lock; /* Information on hardware lock */
441
/* DMA queues (contexts) */
442
int queue_count; /* Number of active DMA queues */
443
int queue_reserved; /* Number of reserved DMA queues */
444
int queue_slots; /* Actual length of queuelist */
445
drm_queue_t **queuelist; /* Vector of pointers to DMA queues */
446
drm_device_dma_t *dma; /* Optional pointer for DMA support */
448
/* Context support */
450
int irq; /* Interrupt used by board */
451
int irqrid; /* Interrupt used by board */
452
struct resource *irqr; /* Resource for interrupt used by board */
453
#elif defined(__NetBSD__)
454
struct pci_attach_args pa;
455
pci_intr_handle_t ih;
457
void *irqh; /* Handle from bus_setup_intr */
458
atomic_t context_flag; /* Context swapping flag */
459
atomic_t interrupt_flag; /* Interruption handler flag */
460
atomic_t dma_flag; /* DMA dispatch flag */
461
struct callout timer; /* Timer for delaying ctx switch */
462
wait_queue_head_t context_wait; /* Processes waiting on ctx switch */
463
int last_checked; /* Last context checked for DMA */
464
int last_context; /* Last current context */
465
unsigned long last_switch; /* jiffies at last context switch */
466
#if __FreeBSD_version >= 400005
470
wait_queue_head_t vbl_queue; /* vbl wait channel */
471
atomic_t vbl_received;
475
#if __HAVE_DMA_HISTOGRAM
476
drm_histogram_t histo;
479
/* Callback to X server for context switch
480
and for heavy-handed reset. */
481
char buf[DRM_BSZ]; /* Output buffer */
482
char *buf_rp; /* Read pointer */
483
char *buf_wp; /* Write pointer */
484
char *buf_end; /* End pointer */
486
struct sigio *buf_sigio; /* Processes waiting for SIGIO */
487
#elif defined(__NetBSD__)
490
struct selinfo buf_sel; /* Workspace for select/poll */
491
int buf_selecting;/* True if poll sleeper */
492
wait_queue_head_t buf_readers; /* Processes waiting to read */
493
wait_queue_head_t buf_writers; /* Processes waiting to ctx switch */
496
struct drm_sysctl_info *sysctl;
498
#if __REALLY_HAVE_AGP
501
drm_sg_mem_t *sg; /* Scatter gather memory */
502
atomic_t *ctx_bitmap;
504
drm_sigdata_t sigdata; /* For block_all_signals */
508
extern int DRM(flags);
509
extern void DRM(parse_options)( char *s );
510
extern int DRM(cpu_valid)( void );
512
/* Authentication (drm_auth.h) */
513
extern int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
515
extern int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
517
/* Driver support (drm_drv.h) */
518
extern int DRM(version)( DRM_IOCTL_ARGS );
519
extern int DRM(write_string)(drm_device_t *dev, const char *s);
521
/* Memory management support (drm_memory.h) */
522
extern void DRM(mem_init)(void);
523
extern void DRM(mem_uninit)(void);
524
extern void *DRM(alloc)(size_t size, int area);
525
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
527
extern char *DRM(strdup)(const char *s, int area);
528
extern void DRM(strfree)(char *s, int area);
529
extern void DRM(free)(void *pt, size_t size, int area);
530
extern void *DRM(ioremap)(unsigned long offset, unsigned long size);
531
extern void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size);
532
extern void DRM(ioremapfree)(void *pt, unsigned long size);
534
#if __REALLY_HAVE_AGP
535
extern agp_memory *DRM(alloc_agp)(int pages, u32 type);
536
extern int DRM(free_agp)(agp_memory *handle, int pages);
537
extern int DRM(bind_agp)(agp_memory *handle, unsigned int start);
538
extern int DRM(unbind_agp)(agp_memory *handle);
541
extern int DRM(context_switch)(drm_device_t *dev, int old, int new);
542
extern int DRM(context_switch_complete)(drm_device_t *dev, int new);
544
#if __HAVE_CTX_BITMAP
545
extern int DRM(ctxbitmap_init)( drm_device_t *dev );
546
extern void DRM(ctxbitmap_cleanup)( drm_device_t *dev );
547
extern void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle );
548
extern int DRM(ctxbitmap_next)( drm_device_t *dev );
551
/* Locking IOCTL support (drm_lock.h) */
552
extern int DRM(lock_take)(__volatile__ unsigned int *lock,
553
unsigned int context);
554
extern int DRM(lock_transfer)(drm_device_t *dev,
555
__volatile__ unsigned int *lock,
556
unsigned int context);
557
extern int DRM(lock_free)(drm_device_t *dev,
558
__volatile__ unsigned int *lock,
559
unsigned int context);
560
extern int DRM(flush_unblock)(drm_device_t *dev, int context,
561
drm_lock_flags_t flags);
562
extern int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
563
drm_lock_flags_t flags);
564
extern int DRM(notifier)(void *priv);
566
/* Buffer management support (drm_bufs.h) */
567
extern int DRM(order)( unsigned long size );
570
/* DMA support (drm_dma.h) */
571
extern int DRM(dma_setup)(drm_device_t *dev);
572
extern void DRM(dma_takedown)(drm_device_t *dev);
573
extern void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
574
extern void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
576
/* GH: This is a dirty hack for now...
578
extern void DRM(clear_next_buffer)(drm_device_t *dev);
579
extern int DRM(select_queue)(drm_device_t *dev,
580
void (*wrapper)(unsigned long));
581
extern int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *dma);
582
extern int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma);
585
extern int DRM(irq_install)( drm_device_t *dev, int irq );
586
extern int DRM(irq_uninstall)( drm_device_t *dev );
587
extern void DRM(dma_service)( DRM_IRQ_ARGS );
588
extern void DRM(driver_irq_preinstall)( drm_device_t *dev );
589
extern void DRM(driver_irq_postinstall)( drm_device_t *dev );
590
extern void DRM(driver_irq_uninstall)( drm_device_t *dev );
591
#if __HAVE_DMA_IRQ_BH
592
extern void DRM(dma_immediate_bh)( DRM_TASKQUEUE_ARGS );
595
#if DRM_DMA_HISTOGRAM
596
extern int DRM(histogram_slot)(unsigned long count);
597
extern void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf);
600
/* Buffer list support (drm_lists.h) */
601
#if __HAVE_DMA_WAITLIST
602
extern int DRM(waitlist_create)(drm_waitlist_t *bl, int count);
603
extern int DRM(waitlist_destroy)(drm_waitlist_t *bl);
604
extern int DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf);
605
extern drm_buf_t *DRM(waitlist_get)(drm_waitlist_t *bl);
607
#if __HAVE_DMA_FREELIST
608
extern int DRM(freelist_create)(drm_freelist_t *bl, int count);
609
extern int DRM(freelist_destroy)(drm_freelist_t *bl);
610
extern int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl,
612
extern drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block);
614
#endif /* __HAVE_DMA */
616
extern int DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
617
extern void DRM(vbl_send_signals)( drm_device_t *dev );
620
#if __REALLY_HAVE_AGP
621
/* AGP/GART support (drm_agpsupport.h) */
622
extern drm_agp_head_t *DRM(agp_init)(void);
623
extern void DRM(agp_uninit)(void);
624
extern void DRM(agp_do_release)(void);
625
extern agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type);
626
extern int DRM(agp_free_memory)(agp_memory *handle);
627
extern int DRM(agp_bind_memory)(agp_memory *handle, off_t start);
628
extern int DRM(agp_unbind_memory)(agp_memory *handle);
632
/* Scatter Gather Support (drm_scatter.h) */
633
extern void DRM(sg_cleanup)(drm_sg_mem_t *entry);
637
/* ATI PCIGART support (ati_pcigart.h) */
638
extern int DRM(ati_pcigart_init)(drm_device_t *dev,
640
dma_addr_t *bus_addr);
641
extern int DRM(ati_pcigart_cleanup)(drm_device_t *dev,
643
dma_addr_t bus_addr);
646
#endif /* __KERNEL__ */
647
#endif /* _DRM_P_H_ */