blob: 7a1159c78705554362d0e444cee6d4cfb6ba5726 [file] [log] [blame]
Doug Rabsonfa0a35a2000-05-30 17:13:31 +00001/* drmP.h -- Private header for Direct Rendering Manager -*- c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
3 * Revised: Tue Oct 12 08:51:07 1999 by faith@precisioninsight.com
4 *
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * All rights reserved.
7 *
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:
14 *
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
17 * Software.
18 *
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 * PRECISION INSIGHT 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 OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 * $PI: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h,v 1.58 1999/08/30 13:05:00 faith Exp $
David Dawes18fc5ee2001-04-09 21:56:31 +000028 * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/drm/kernel/drmP.h,v 1.3 2001/03/06 16:45:26 dawes Exp $
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000029 *
30 */
31
32#ifndef _DRM_P_H_
33#define _DRM_P_H_
34
35#ifdef _KERNEL
36#include <sys/param.h>
37#include <sys/queue.h>
38#include <sys/malloc.h>
39#include <sys/kernel.h>
40#include <sys/module.h>
41#include <sys/systm.h>
42#include <sys/conf.h>
43#include <sys/stat.h>
44#include <sys/proc.h>
45#include <sys/lock.h>
46#include <sys/fcntl.h>
47#include <sys/uio.h>
48#include <sys/filio.h>
49#include <sys/sysctl.h>
50#include <sys/select.h>
51#include <sys/bus.h>
David Dawes18fc5ee2001-04-09 21:56:31 +000052#if __FreeBSD_version >= 400005
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000053#include <sys/taskqueue.h>
Doug Rabsond399dbc2000-06-13 17:38:09 +000054#endif
55
David Dawes18fc5ee2001-04-09 21:56:31 +000056#if __FreeBSD_version >= 400006
Doug Rabsond399dbc2000-06-13 17:38:09 +000057#define DRM_AGP
58#endif
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000059
60#ifdef DRM_AGP
61#include <pci/agpvar.h>
62#endif
63
64#include "drm.h"
65
66typedef u_int32_t atomic_t;
67typedef u_int32_t cycles_t;
68typedef u_int32_t spinlock_t;
69#define atomic_set(p, v) (*(p) = (v))
70#define atomic_read(p) (*(p))
71#define atomic_inc(p) atomic_add_int(p, 1)
72#define atomic_dec(p) atomic_subtract_int(p, 1)
73#define atomic_add(n, p) atomic_add_int(p, n)
74#define atomic_sub(n, p) atomic_subtract_int(p, n)
75
David Dawes18fc5ee2001-04-09 21:56:31 +000076/* The version number here is a guess */
77#if __FreeBSD_version >= 500010
78#define callout_init(a) callout_init(a, 0)
79#endif
80
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000081/* Fake this */
82static __inline u_int32_t
83test_and_set_bit(int b, volatile u_int32_t *p)
84{
Doug Rabsond399dbc2000-06-13 17:38:09 +000085 int s = splhigh();
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000086 u_int32_t m = 1<<b;
87 u_int32_t r = *p & m;
88 *p |= m;
Doug Rabsond399dbc2000-06-13 17:38:09 +000089 splx(s);
Doug Rabsonfa0a35a2000-05-30 17:13:31 +000090 return r;
91}
92
93static __inline void
94clear_bit(int b, volatile u_int32_t *p)
95{
96 atomic_clear_int(p + (b >> 5), 1 << (b & 0x1f));
97}
98
99static __inline void
100set_bit(int b, volatile u_int32_t *p)
101{
102 atomic_set_int(p + (b >> 5), 1 << (b & 0x1f));
103}
104
105static __inline int
106test_bit(int b, volatile u_int32_t *p)
107{
108 return p[b >> 5] & (1 << (b & 0x1f));
109}
110
111static __inline int
112find_first_zero_bit(volatile u_int32_t *p, int max)
113{
114 int b;
115
116 for (b = 0; b < max; b += 32) {
Doug Rabsond399dbc2000-06-13 17:38:09 +0000117 if (p[b >> 5] != ~0) {
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000118 for (;;) {
Doug Rabsond399dbc2000-06-13 17:38:09 +0000119 if ((p[b >> 5] & (1 << (b & 0x1f))) == 0)
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000120 return b;
121 b++;
122 }
123 }
124 }
125 return max;
126}
127
128#define spldrm() spltty()
129
130#define memset(p, v, s) bzero(p, s)
131
132/*
Doug Rabsond399dbc2000-06-13 17:38:09 +0000133 * Fake out the module macros for versions of FreeBSD where they don't
134 * exist.
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000135 */
David Dawes18fc5ee2001-04-09 21:56:31 +0000136#if __FreeBSD_version < 400002
Doug Rabsond399dbc2000-06-13 17:38:09 +0000137
138#define MODULE_VERSION(a,b) struct __hack
139#define MODULE_DEPEND(a,b,c,d,e) struct __hack
140
141#endif
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000142
David Dawes18fc5ee2001-04-09 21:56:31 +0000143#define DRM_DEBUG_CODE 0 /* Include debugging code (if > 1, then
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000144 also include looping detection. */
145#define DRM_DMA_HISTOGRAM 1 /* Make histogram of DMA latency. */
146
147#define DRM_HASH_SIZE 16 /* Size of key hash table */
148#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
149#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
150#define DRM_LOOPING_LIMIT 5000000
151#define DRM_BSZ 1024 /* Buffer size for /dev/drm? output */
152#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
153#define DRM_LOCK_SLICE 1 /* Time slice for lock, in jiffies */
154
155#define DRM_FLAG_DEBUG 0x01
156#define DRM_FLAG_NOCTX 0x02
157
158#define DRM_MEM_DMA 0
159#define DRM_MEM_SAREA 1
160#define DRM_MEM_DRIVER 2
161#define DRM_MEM_MAGIC 3
162#define DRM_MEM_IOCTLS 4
163#define DRM_MEM_MAPS 5
164#define DRM_MEM_VMAS 6
165#define DRM_MEM_BUFS 7
166#define DRM_MEM_SEGS 8
167#define DRM_MEM_PAGES 9
168#define DRM_MEM_FILES 10
169#define DRM_MEM_QUEUES 11
170#define DRM_MEM_CMDS 12
171#define DRM_MEM_MAPPINGS 13
172#define DRM_MEM_BUFLISTS 14
173#define DRM_MEM_AGPLISTS 15
174#define DRM_MEM_TOTALAGP 16
175#define DRM_MEM_BOUNDAGP 17
176#define DRM_MEM_CTXBITMAP 18
177
178#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
179
180 /* Backward compatibility section */
181#ifndef _PAGE_PWT
182 /* The name of _PAGE_WT was changed to
183 _PAGE_PWT in Linux 2.2.6 */
184#define _PAGE_PWT _PAGE_WT
185#endif
186
187#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
188#define _DRM_CAS(lock,old,new,__ret) \
189 do { \
190 int __dummy; /* Can't mark eax as clobbered */ \
191 __asm__ __volatile__( \
192 "lock ; cmpxchg %4,%1\n\t" \
193 "setnz %0" \
194 : "=d" (__ret), \
195 "=m" (__drm_dummy_lock(lock)), \
196 "=a" (__dummy) \
197 : "2" (old), \
198 "r" (new)); \
199 } while (0)
200
201
202
203 /* Macros to make printk easier */
204#define DRM_ERROR(fmt, arg...) \
205 printf("error: " "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg)
206#define DRM_MEM_ERROR(area, fmt, arg...) \
207 printf("error: " "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \
208 drm_mem_stats[area].name , ##arg)
209#define DRM_INFO(fmt, arg...) printf("info: " "[" DRM_NAME "] " fmt , ##arg)
210
211#if DRM_DEBUG_CODE
212#define DRM_DEBUG(fmt, arg...) \
213 do { \
214 if (drm_flags&DRM_FLAG_DEBUG) \
215 printf("[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
216 ##arg); \
217 } while (0)
218#else
219#define DRM_DEBUG(fmt, arg...) do { } while (0)
220#endif
221
222#define DRM_PROC_LIMIT (PAGE_SIZE-80)
223
224#define DRM_SYSCTL_PRINT(fmt, arg...) \
225 snprintf(buf, sizeof(buf), fmt, ##arg); \
226 error = SYSCTL_OUT(req, buf, strlen(buf)); \
227 if (error) return error;
228
229#define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...) \
230 snprintf(buf, sizeof(buf), fmt, ##arg); \
231 error = SYSCTL_OUT(req, buf, strlen(buf)); \
232 if (error) { ret; return error; }
233
234 /* Internal types and structures */
235#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
236#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
237#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
238
239#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
240#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
241#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
242
243typedef struct drm_ioctl_desc {
244 d_ioctl_t *func;
245 int auth_needed;
246 int root_only;
247} drm_ioctl_desc_t;
248
249typedef struct drm_devstate {
250 pid_t owner; /* X server pid holding x_lock */
251
252} drm_devstate_t;
253
254typedef struct drm_magic_entry {
255 drm_magic_t magic;
256 struct drm_file *priv;
257 struct drm_magic_entry *next;
258} drm_magic_entry_t;
259
260typedef struct drm_magic_head {
261 struct drm_magic_entry *head;
262 struct drm_magic_entry *tail;
263} drm_magic_head_t;
264
265typedef struct drm_vma_entry {
266 struct vm_area_struct *vma;
267 struct drm_vma_entry *next;
268 pid_t pid;
269} drm_vma_entry_t;
270
271typedef struct drm_buf {
272 int idx; /* Index into master buflist */
273 int total; /* Buffer size */
274 int order; /* log-base-2(total) */
275 int used; /* Amount of buffer in use (for DMA) */
276 unsigned long offset; /* Byte offset (used internally) */
277 void *address; /* Address of buffer */
278 unsigned long bus_address; /* Bus address of buffer */
279 struct drm_buf *next; /* Kernel-only: used for free list */
280 __volatile__ int waiting; /* On kernel DMA queue */
281 __volatile__ int pending; /* On hardware DMA queue */
282 int dma_wait; /* Processes waiting */
283 pid_t pid; /* PID of holding process */
284 int context; /* Kernel queue for this buffer */
285 int while_locked;/* Dispatch this buffer while locked */
286 enum {
287 DRM_LIST_NONE = 0,
288 DRM_LIST_FREE = 1,
289 DRM_LIST_WAIT = 2,
290 DRM_LIST_PEND = 3,
291 DRM_LIST_PRIO = 4,
292 DRM_LIST_RECLAIM = 5
293 } list; /* Which list we're on */
294
295 void *dev_private;
296 int dev_priv_size;
297
298#if DRM_DMA_HISTOGRAM
299 struct timespec time_queued; /* Queued to kernel DMA queue */
300 struct timespec time_dispatched; /* Dispatched to hardware */
301 struct timespec time_completed; /* Completed by hardware */
302 struct timespec time_freed; /* Back on freelist */
303#endif
304} drm_buf_t;
305
306#if DRM_DMA_HISTOGRAM
307#define DRM_DMA_HISTOGRAM_SLOTS 9
308#define DRM_DMA_HISTOGRAM_INITIAL 10
309#define DRM_DMA_HISTOGRAM_NEXT(current) ((current)*10)
310typedef struct drm_histogram {
311 atomic_t total;
312
313 atomic_t queued_to_dispatched[DRM_DMA_HISTOGRAM_SLOTS];
314 atomic_t dispatched_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
315 atomic_t completed_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
316
317 atomic_t queued_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
318 atomic_t queued_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
319
320 atomic_t dma[DRM_DMA_HISTOGRAM_SLOTS];
321 atomic_t schedule[DRM_DMA_HISTOGRAM_SLOTS];
322 atomic_t ctx[DRM_DMA_HISTOGRAM_SLOTS];
323 atomic_t lacq[DRM_DMA_HISTOGRAM_SLOTS];
324 atomic_t lhld[DRM_DMA_HISTOGRAM_SLOTS];
325} drm_histogram_t;
326#endif
327
328 /* bufs is one longer than it has to be */
329typedef struct drm_waitlist {
330 int count; /* Number of possible buffers */
331 drm_buf_t **bufs; /* List of pointers to buffers */
332 drm_buf_t **rp; /* Read pointer */
333 drm_buf_t **wp; /* Write pointer */
334 drm_buf_t **end; /* End pointer */
335 spinlock_t read_lock;
336 spinlock_t write_lock;
337} drm_waitlist_t;
338
339typedef struct drm_freelist {
340 int initialized; /* Freelist in use */
341 atomic_t count; /* Number of free buffers */
342 drm_buf_t *next; /* End pointer */
343
344 int waiting; /* Processes waiting on free bufs */
345 int low_mark; /* Low water mark */
346 int high_mark; /* High water mark */
347 atomic_t wfh; /* If waiting for high mark */
David Dawes18fc5ee2001-04-09 21:56:31 +0000348 struct simplelock lock; /* hope this doesn't need to be linux compatible */
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000349} drm_freelist_t;
350
351typedef struct drm_buf_entry {
352 int buf_size;
353 int buf_count;
354 drm_buf_t *buflist;
355 int seg_count;
356 int page_order;
357 unsigned long *seglist;
358
359 drm_freelist_t freelist;
360} drm_buf_entry_t;
361
362typedef struct drm_hw_lock {
363 __volatile__ unsigned int lock;
364 char padding[60]; /* Pad to cache line */
365} drm_hw_lock_t;
366
367typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
368typedef struct drm_file {
369 TAILQ_ENTRY(drm_file) link;
370 int authenticated;
371 int minor;
372 pid_t pid;
373 uid_t uid;
374 int refs;
375 drm_magic_t magic;
376 unsigned long ioctl_count;
377 struct drm_device *devXX;
378} drm_file_t;
379
380
381typedef struct drm_queue {
382 atomic_t use_count; /* Outstanding uses (+1) */
383 atomic_t finalization; /* Finalization in progress */
384 atomic_t block_count; /* Count of processes waiting */
385 atomic_t block_read; /* Queue blocked for reads */
386 int read_queue; /* Processes waiting on block_read */
387 atomic_t block_write; /* Queue blocked for writes */
388 int write_queue; /* Processes waiting on block_write */
389 atomic_t total_queued; /* Total queued statistic */
390 atomic_t total_flushed;/* Total flushes statistic */
391 atomic_t total_locks; /* Total locks statistics */
392 drm_ctx_flags_t flags; /* Context preserving and 2D-only */
393 drm_waitlist_t waitlist; /* Pending buffers */
394 int flush_queue; /* Processes waiting until flush */
395} drm_queue_t;
396
397typedef struct drm_lock_data {
398 drm_hw_lock_t *hw_lock; /* Hardware lock */
399 pid_t pid; /* PID of lock holder (0=kernel) */
400 int lock_queue; /* Queue of blocked processes */
401 unsigned long lock_time; /* Time of last lock in jiffies */
402} drm_lock_data_t;
403
404typedef struct drm_device_dma {
405 /* Performance Counters */
406 atomic_t total_prio; /* Total DRM_DMA_PRIORITY */
407 atomic_t total_bytes; /* Total bytes DMA'd */
408 atomic_t total_dmas; /* Total DMA buffers dispatched */
409
410 atomic_t total_missed_dma; /* Missed drm_do_dma */
411 atomic_t total_missed_lock; /* Missed lock in drm_do_dma */
412 atomic_t total_missed_free; /* Missed drm_free_this_buffer */
413 atomic_t total_missed_sched;/* Missed drm_dma_schedule */
414
415 atomic_t total_tried; /* Tried next_buffer */
416 atomic_t total_hit; /* Sent next_buffer */
417 atomic_t total_lost; /* Lost interrupt */
418
419 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
420 int buf_count;
421 drm_buf_t **buflist; /* Vector of pointers info bufs */
422 int seg_count;
423 int page_count;
424 vm_offset_t *pagelist;
425 unsigned long byte_count;
426 enum {
427 _DRM_DMA_USE_AGP = 0x01
428 } flags;
429
430 /* DMA support */
431 drm_buf_t *this_buffer; /* Buffer being sent */
432 drm_buf_t *next_buffer; /* Selected buffer to send */
433 drm_queue_t *next_queue; /* Queue from which buffer selected*/
434 int waiting; /* Processes waiting on free bufs */
435} drm_device_dma_t;
436
437#ifdef DRM_AGP
438
439typedef struct drm_agp_mem {
440 void *handle;
441 unsigned long bound; /* address */
442 int pages;
443 struct drm_agp_mem *prev;
444 struct drm_agp_mem *next;
445} drm_agp_mem_t;
446
447typedef struct drm_agp_head {
448 device_t agpdev;
449 struct agp_info info;
450 const char *chipset;
451 drm_agp_mem_t *memory;
452 unsigned long mode;
453 int enabled;
454 int acquired;
455 unsigned long base;
456 int agp_mtrr;
457} drm_agp_head_t;
458
459#endif
460
461typedef struct drm_device {
462 const char *name; /* Simple driver name */
463 char *unique; /* Unique identifier: e.g., busid */
464 int unique_len; /* Length of unique field */
465 device_t device; /* Device instance from newbus */
466 dev_t devnode; /* Device number for mknod */
467 char *devname; /* For /proc/interrupts */
468
469 int blocked; /* Blocked due to VC switch? */
470 int flags; /* Flags to open(2) */
471 int writable; /* Opened with FWRITE */
472 struct proc_dir_entry *root; /* Root for this device's entries */
473
474 /* Locks */
475 struct simplelock count_lock; /* For inuse, open_count, buf_use */
476 struct lock dev_lock; /* For others */
477
478 /* Usage Counters */
479 int open_count; /* Outstanding files open */
480 atomic_t ioctl_count; /* Outstanding IOCTLs pending */
481 atomic_t vma_count; /* Outstanding vma areas open */
482 int buf_use; /* Buffers in use -- cannot alloc */
483 atomic_t buf_alloc; /* Buffer allocation in progress */
484
485 /* Performance Counters */
486 atomic_t total_open;
487 atomic_t total_close;
488 atomic_t total_ioctl;
489 atomic_t total_irq; /* Total interruptions */
490 atomic_t total_ctx; /* Total context switches */
491
492 atomic_t total_locks;
493 atomic_t total_unlocks;
494 atomic_t total_contends;
495 atomic_t total_sleeps;
496
497 /* Authentication */
498 drm_file_list_t files;
499 drm_magic_head_t magiclist[DRM_HASH_SIZE];
500
501 /* Memory management */
502 drm_map_t **maplist; /* Vector of pointers to regions */
503 int map_count; /* Number of mappable regions */
504
505 drm_vma_entry_t *vmalist; /* List of vmas (for debugging) */
506 drm_lock_data_t lock; /* Information on hardware lock */
507
508 /* DMA queues (contexts) */
509 int queue_count; /* Number of active DMA queues */
510 int queue_reserved; /* Number of reserved DMA queues */
511 int queue_slots; /* Actual length of queuelist */
512 drm_queue_t **queuelist; /* Vector of pointers to DMA queues */
513 drm_device_dma_t *dma; /* Optional pointer for DMA support */
514
515 /* Context support */
516 struct resource *irq; /* Interrupt used by board */
517 void *irqh; /* Handle from bus_setup_intr */
David Dawes18fc5ee2001-04-09 21:56:31 +0000518 __volatile__ long context_flag; /* Context swapping flag */
519 __volatile__ long interrupt_flag;/* Interruption handler flag */
520 __volatile__ long dma_flag; /* DMA dispatch flag */
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000521 struct callout timer; /* Timer for delaying ctx switch */
522 int context_wait; /* Processes waiting on ctx switch */
523 int last_checked; /* Last context checked for DMA */
524 int last_context; /* Last current context */
525 int last_switch; /* Time at last context switch */
David Dawes18fc5ee2001-04-09 21:56:31 +0000526#if __FreeBSD_version >= 400005
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000527 struct task task;
Doug Rabsond399dbc2000-06-13 17:38:09 +0000528#endif
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000529 struct timespec ctx_start;
530 struct timespec lck_start;
531#if DRM_DMA_HISTOGRAM
532 drm_histogram_t histo;
533#endif
534
535 /* Callback to X server for context switch
536 and for heavy-handed reset. */
537 char buf[DRM_BSZ]; /* Output buffer */
538 char *buf_rp; /* Read pointer */
539 char *buf_wp; /* Write pointer */
540 char *buf_end; /* End pointer */
541 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
542 struct selinfo buf_sel; /* Workspace for select/poll */
543 int buf_readers; /* Processes waiting to read */
544 int buf_writers; /* Processes waiting to ctx switch */
545 int buf_selecting; /* True if poll sleeper */
546
547 /* Sysctl support */
548 struct drm_sysctl_info *sysctl;
549
550#ifdef DRM_AGP
551 drm_agp_head_t *agp;
552#endif
553 u_int32_t *ctx_bitmap;
554 void *dev_private;
555} drm_device_t;
556
557
558 /* Internal function definitions */
559
560 /* Misc. support (init.c) */
561extern int drm_flags;
562extern void drm_parse_options(char *s);
563
564
565 /* Device support (fops.c) */
566extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev, struct proc *p);
567extern int drm_open_helper(dev_t kdev, int flags, int fmt, struct proc *p,
568 drm_device_t *dev);
569extern d_close_t drm_close;
570extern d_read_t drm_read;
571extern d_write_t drm_write;
572extern d_poll_t drm_poll;
573extern int drm_fsetown(dev_t kdev, u_long cmd, caddr_t data,
574 int flags, struct proc *p);
575extern int drm_fgetown(dev_t kdev, u_long cmd, caddr_t data,
576 int flags, struct proc *p);
577extern int drm_write_string(drm_device_t *dev, const char *s);
578
579#if 0
580 /* Mapping support (vm.c) */
581extern unsigned long drm_vm_nopage(struct vm_area_struct *vma,
582 unsigned long address,
583 int write_access);
584extern unsigned long drm_vm_shm_nopage(struct vm_area_struct *vma,
585 unsigned long address,
586 int write_access);
587extern unsigned long drm_vm_dma_nopage(struct vm_area_struct *vma,
588 unsigned long address,
589 int write_access);
590extern void drm_vm_open(struct vm_area_struct *vma);
591extern void drm_vm_close(struct vm_area_struct *vma);
592extern int drm_mmap_dma(struct file *filp,
593 struct vm_area_struct *vma);
594#endif
595extern d_mmap_t drm_mmap;
596
597 /* Proc support (proc.c) */
598extern int drm_sysctl_init(drm_device_t *dev);
599extern int drm_sysctl_cleanup(drm_device_t *dev);
600
601 /* Memory management support (memory.c) */
602extern void drm_mem_init(void);
David Dawes18fc5ee2001-04-09 21:56:31 +0000603
604#if __FreeBSD_version < 411000
605#define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
606#else
607#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
608#endif
609extern int drm_mem_info DRM_SYSCTL_HANDLER_ARGS;
Doug Rabsonfa0a35a2000-05-30 17:13:31 +0000610extern void *drm_alloc(size_t size, int area);
611extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
612 int area);
613extern char *drm_strdup(const char *s, int area);
614extern void drm_strfree(char *s, int area);
615extern void drm_free(void *pt, size_t size, int area);
616extern unsigned long drm_alloc_pages(int order, int area);
617extern void drm_free_pages(unsigned long address, int order,
618 int area);
619extern void *drm_ioremap(unsigned long offset, unsigned long size);
620extern void drm_ioremapfree(void *pt, unsigned long size);
621
622#ifdef DRM_AGP
623extern void *drm_alloc_agp(int pages, u_int32_t type);
624extern int drm_free_agp(void *handle, int pages);
625extern int drm_bind_agp(void *handle, unsigned int start);
626extern int drm_unbind_agp(void *handle);
627#endif
628
629 /* Buffer management support (bufs.c) */
630extern int drm_order(unsigned long size);
631extern d_ioctl_t drm_addmap;
632extern d_ioctl_t drm_addbufs;
633extern d_ioctl_t drm_infobufs;
634extern d_ioctl_t drm_markbufs;
635extern d_ioctl_t drm_freebufs;
636extern d_ioctl_t drm_mapbufs;
637
638
639 /* Buffer list management support (lists.c) */
640extern int drm_waitlist_create(drm_waitlist_t *bl, int count);
641extern int drm_waitlist_destroy(drm_waitlist_t *bl);
642extern int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf);
643extern drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl);
644
645extern int drm_freelist_create(drm_freelist_t *bl, int count);
646extern int drm_freelist_destroy(drm_freelist_t *bl);
647extern int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl,
648 drm_buf_t *buf);
649extern drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block);
650
651 /* DMA support (gen_dma.c) */
652extern void drm_dma_setup(drm_device_t *dev);
653extern void drm_dma_takedown(drm_device_t *dev);
654extern void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
655extern void drm_reclaim_buffers(drm_device_t *dev, pid_t pid);
656extern int drm_context_switch(drm_device_t *dev, int old, int new);
657extern int drm_context_switch_complete(drm_device_t *dev, int new);
658extern void drm_wakeup(drm_device_t *dev, drm_buf_t *buf);
659extern void drm_clear_next_buffer(drm_device_t *dev);
660extern int drm_select_queue(drm_device_t *dev,
661 void (*wrapper)(void *));
662extern int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *dma);
663extern int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma);
664#if DRM_DMA_HISTOGRAM
665extern int drm_histogram_slot(struct timespec *ts);
666extern void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf);
667#endif
668
669
670 /* Misc. IOCTL support (ioctl.c) */
671extern d_ioctl_t drm_irq_busid;
672extern d_ioctl_t drm_getunique;
673extern d_ioctl_t drm_setunique;
674
675
676 /* Context IOCTL support (context.c) */
677extern d_ioctl_t drm_resctx;
678extern d_ioctl_t drm_addctx;
679extern d_ioctl_t drm_modctx;
680extern d_ioctl_t drm_getctx;
681extern d_ioctl_t drm_switchctx;
682extern d_ioctl_t drm_newctx;
683extern d_ioctl_t drm_rmctx;
684
685
686 /* Drawable IOCTL support (drawable.c) */
687extern d_ioctl_t drm_adddraw;
688extern d_ioctl_t drm_rmdraw;
689
690
691 /* Authentication IOCTL support (auth.c) */
692extern int drm_add_magic(drm_device_t *dev, drm_file_t *priv,
693 drm_magic_t magic);
694extern int drm_remove_magic(drm_device_t *dev, drm_magic_t magic);
695extern d_ioctl_t drm_getmagic;
696extern d_ioctl_t drm_authmagic;
697
698
699 /* Locking IOCTL support (lock.c) */
700extern d_ioctl_t drm_block;
701extern d_ioctl_t drm_unblock;
702extern int drm_lock_take(__volatile__ unsigned int *lock,
703 unsigned int context);
704extern int drm_lock_transfer(drm_device_t *dev,
705 __volatile__ unsigned int *lock,
706 unsigned int context);
707extern int drm_lock_free(drm_device_t *dev,
708 __volatile__ unsigned int *lock,
709 unsigned int context);
710extern d_ioctl_t drm_finish;
711extern int drm_flush_unblock(drm_device_t *dev, int context,
712 drm_lock_flags_t flags);
713extern int drm_flush_block_and_flush(drm_device_t *dev, int context,
714 drm_lock_flags_t flags);
715
716 /* Context Bitmap support (ctxbitmap.c) */
717extern int drm_ctxbitmap_init(drm_device_t *dev);
718extern void drm_ctxbitmap_cleanup(drm_device_t *dev);
719extern int drm_ctxbitmap_next(drm_device_t *dev);
720extern void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
721
722#ifdef DRM_AGP
723 /* AGP/GART support (agpsupport.c) */
724extern drm_agp_head_t *drm_agp_init(void);
725extern d_ioctl_t drm_agp_acquire;
726extern d_ioctl_t drm_agp_release;
727extern d_ioctl_t drm_agp_enable;
728extern d_ioctl_t drm_agp_info;
729extern d_ioctl_t drm_agp_alloc;
730extern d_ioctl_t drm_agp_free;
731extern d_ioctl_t drm_agp_unbind;
732extern d_ioctl_t drm_agp_bind;
733#endif
734#endif
735#endif