linux-old/drivers/char/drm/drmP.h
<<
>>
Prefs
   1/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
   2 * Created: Mon Jan  4 10:05:05 1999 by faith@precisioninsight.com
   3 *
   4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
   5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
   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 * 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.
  26 *
  27 * Authors:
  28 *    Rickard E. (Rik) Faith <faith@valinux.com>
  29 *    Gareth Hughes <gareth@valinux.com>
  30 */
  31
  32#ifndef _DRM_P_H_
  33#define _DRM_P_H_
  34
  35#ifdef __KERNEL__
  36#ifdef __alpha__
  37/* add include of current.h so that "current" is defined
  38 * before static inline funcs in wait.h. Doing this so we
  39 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  40#include <asm/current.h>
  41#endif /* __alpha__ */
  42#include <linux/config.h>
  43#include <linux/module.h>
  44#include <linux/kernel.h>
  45#include <linux/miscdevice.h>
  46#include <linux/fs.h>
  47#include <linux/proc_fs.h>
  48#include <linux/init.h>
  49#include <linux/file.h>
  50#include <linux/pci.h>
  51#include <linux/wrapper.h>
  52#include <linux/version.h>
  53#include <linux/sched.h>
  54#include <linux/smp_lock.h>     /* For (un)lock_kernel */
  55#include <linux/mm.h>
  56#if defined(__alpha__) || defined(__powerpc__)
  57#include <asm/pgtable.h> /* For pte_wrprotect */
  58#endif
  59#include <asm/io.h>
  60#include <asm/mman.h>
  61#include <asm/uaccess.h>
  62#ifdef CONFIG_MTRR
  63#include <asm/mtrr.h>
  64#endif
  65#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
  66#include <linux/types.h>
  67#include <linux/agp_backend.h>
  68#endif
  69#if LINUX_VERSION_CODE >= 0x020100 /* KERNEL_VERSION(2,1,0) */
  70#include <linux/tqueue.h>
  71#include <linux/poll.h>
  72#endif
  73#if LINUX_VERSION_CODE < 0x020400
  74#include "compat-pre24.h"
  75#endif
  76#include <asm/pgalloc.h>
  77#include "drm.h"
  78
  79/* page_to_bus for earlier kernels, not optimal in all cases */
  80#ifndef page_to_bus
  81#define page_to_bus(page)       ((unsigned int)(virt_to_bus(page_address(page))))
  82#endif
  83
  84/* We just use virt_to_bus for pci_map_single on older kernels */
  85#if LINUX_VERSION_CODE < 0x020400
  86#define pci_map_single(hwdev, ptr, size, direction)     virt_to_bus(ptr)
  87#define pci_unmap_single(hwdev, dma_addr, size, direction)
  88#endif
  89
  90/* DRM template customization defaults
  91 */
  92#ifndef __HAVE_AGP
  93#define __HAVE_AGP              0
  94#endif
  95#ifndef __HAVE_MTRR
  96#define __HAVE_MTRR             0
  97#endif
  98#ifndef __HAVE_CTX_BITMAP
  99#define __HAVE_CTX_BITMAP       0
 100#endif
 101#ifndef __HAVE_DMA
 102#define __HAVE_DMA              0
 103#endif
 104#ifndef __HAVE_DMA_IRQ
 105#define __HAVE_DMA_IRQ          0
 106#endif
 107#ifndef __HAVE_DMA_WAITLIST
 108#define __HAVE_DMA_WAITLIST     0
 109#endif
 110#ifndef __HAVE_DMA_FREELIST
 111#define __HAVE_DMA_FREELIST     0
 112#endif
 113#ifndef __HAVE_DMA_HISTOGRAM
 114#define __HAVE_DMA_HISTOGRAM    0
 115#endif
 116
 117#define __REALLY_HAVE_AGP       (__HAVE_AGP && (defined(CONFIG_AGP) || \
 118                                                defined(CONFIG_AGP_MODULE)))
 119#define __REALLY_HAVE_MTRR      (__HAVE_MTRR && defined(CONFIG_MTRR))
 120
 121
 122/* Begin the DRM...
 123 */
 124
 125#define DRM_DEBUG_CODE 2          /* Include debugging code (if > 1, then
 126                                     also include looping detection. */
 127
 128#define DRM_HASH_SIZE         16 /* Size of key hash table                */
 129#define DRM_KERNEL_CONTEXT    0  /* Change drm_resctx if changed          */
 130#define DRM_RESERVED_CONTEXTS 1  /* Change drm_resctx if changed          */
 131#define DRM_LOOPING_LIMIT     5000000
 132#define DRM_BSZ               1024 /* Buffer size for /dev/drm? output    */
 133#define DRM_TIME_SLICE        (HZ/20)  /* Time slice for GLXContexts      */
 134#define DRM_LOCK_SLICE        1 /* Time slice for lock, in jiffies        */
 135
 136#define DRM_FLAG_DEBUG    0x01
 137#define DRM_FLAG_NOCTX    0x02
 138
 139#define DRM_MEM_DMA        0
 140#define DRM_MEM_SAREA      1
 141#define DRM_MEM_DRIVER     2
 142#define DRM_MEM_MAGIC      3
 143#define DRM_MEM_IOCTLS     4
 144#define DRM_MEM_MAPS       5
 145#define DRM_MEM_VMAS       6
 146#define DRM_MEM_BUFS       7
 147#define DRM_MEM_SEGS       8
 148#define DRM_MEM_PAGES      9
 149#define DRM_MEM_FILES     10
 150#define DRM_MEM_QUEUES    11
 151#define DRM_MEM_CMDS      12
 152#define DRM_MEM_MAPPINGS  13
 153#define DRM_MEM_BUFLISTS  14
 154#define DRM_MEM_AGPLISTS  15
 155#define DRM_MEM_TOTALAGP  16
 156#define DRM_MEM_BOUNDAGP  17
 157#define DRM_MEM_CTXBITMAP 18
 158#define DRM_MEM_STUB      19
 159#define DRM_MEM_SGLISTS   20
 160
 161#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
 162
 163                                /* Backward compatibility section */
 164                                /* _PAGE_WT changed to _PAGE_PWT in 2.2.6 */
 165#ifndef _PAGE_PWT
 166#define _PAGE_PWT _PAGE_WT
 167#endif
 168                                /* Wait queue declarations changed in 2.3.1 */
 169#ifndef DECLARE_WAITQUEUE
 170#define DECLARE_WAITQUEUE(w,c) struct wait_queue w = { c, NULL }
 171typedef struct wait_queue *wait_queue_head_t;
 172#define init_waitqueue_head(q) *q = NULL;
 173#endif
 174
 175                                /* _PAGE_4M changed to _PAGE_PSE in 2.3.23 */
 176#ifndef _PAGE_PSE
 177#define _PAGE_PSE _PAGE_4M
 178#endif
 179
 180                                /* vm_offset changed to vm_pgoff in 2.3.25 */
 181#if LINUX_VERSION_CODE < 0x020319
 182#define VM_OFFSET(vma) ((vma)->vm_offset)
 183#else
 184#define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
 185#endif
 186
 187                                /* *_nopage return values defined in 2.3.26 */
 188#ifndef NOPAGE_SIGBUS
 189#define NOPAGE_SIGBUS 0
 190#endif
 191#ifndef NOPAGE_OOM
 192#define NOPAGE_OOM 0
 193#endif
 194
 195                                /* module_init/module_exit added in 2.3.13 */
 196#ifndef module_init
 197#define module_init(x)  int init_module(void) { return x(); }
 198#endif
 199#ifndef module_exit
 200#define module_exit(x)  void cleanup_module(void) { x(); }
 201#endif
 202
 203                                /* Generic cmpxchg added in 2.3.x */
 204#ifndef __HAVE_ARCH_CMPXCHG
 205                                /* Include this here so that driver can be
 206                                   used with older kernels. */
 207#if defined(__alpha__)
 208static __inline__ unsigned long
 209__cmpxchg_u32(volatile int *m, int old, int new)
 210{
 211        unsigned long prev, cmp;
 212
 213        __asm__ __volatile__(
 214        "1:     ldl_l %0,%5\n"
 215        "       cmpeq %0,%3,%1\n"
 216        "       beq %1,2f\n"
 217        "       mov %4,%1\n"
 218        "       stl_c %1,%2\n"
 219        "       beq %1,3f\n"
 220        "2:     mb\n"
 221        ".subsection 2\n"
 222        "3:     br 1b\n"
 223        ".previous"
 224        : "=&r"(prev), "=&r"(cmp), "=m"(*m)
 225        : "r"((long) old), "r"(new), "m"(*m)
 226        : "memory" );
 227
 228        return prev;
 229}
 230
 231static __inline__ unsigned long
 232__cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
 233{
 234        unsigned long prev, cmp;
 235
 236        __asm__ __volatile__(
 237        "1:     ldq_l %0,%5\n"
 238        "       cmpeq %0,%3,%1\n"
 239        "       beq %1,2f\n"
 240        "       mov %4,%1\n"
 241        "       stq_c %1,%2\n"
 242        "       beq %1,3f\n"
 243        "2:     mb\n"
 244        ".subsection 2\n"
 245        "3:     br 1b\n"
 246        ".previous"
 247        : "=&r"(prev), "=&r"(cmp), "=m"(*m)
 248        : "r"((long) old), "r"(new), "m"(*m)
 249        : "memory" );
 250
 251        return prev;
 252}
 253
 254static __inline__ unsigned long
 255__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
 256{
 257        switch (size) {
 258                case 4:
 259                        return __cmpxchg_u32(ptr, old, new);
 260                case 8:
 261                        return __cmpxchg_u64(ptr, old, new);
 262        }
 263        return old;
 264}
 265#define cmpxchg(ptr,o,n)                                                 \
 266  ({                                                                     \
 267     __typeof__(*(ptr)) _o_ = (o);                                       \
 268     __typeof__(*(ptr)) _n_ = (n);                                       \
 269     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,           \
 270                                    (unsigned long)_n_, sizeof(*(ptr))); \
 271  })
 272
 273#elif __i386__
 274static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
 275                                      unsigned long new, int size)
 276{
 277        unsigned long prev;
 278        switch (size) {
 279        case 1:
 280                __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
 281                                     : "=a"(prev)
 282                                     : "q"(new), "m"(*__xg(ptr)), "0"(old)
 283                                     : "memory");
 284                return prev;
 285        case 2:
 286                __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
 287                                     : "=a"(prev)
 288                                     : "q"(new), "m"(*__xg(ptr)), "0"(old)
 289                                     : "memory");
 290                return prev;
 291        case 4:
 292                __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
 293                                     : "=a"(prev)
 294                                     : "q"(new), "m"(*__xg(ptr)), "0"(old)
 295                                     : "memory");
 296                return prev;
 297        }
 298        return old;
 299}
 300
 301#elif defined(__powerpc__)
 302extern void __cmpxchg_called_with_bad_pointer(void);
 303static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
 304                                      unsigned long new, int size)
 305{
 306        unsigned long prev;
 307
 308        switch (size) {
 309        case 4:
 310                __asm__ __volatile__(
 311                        "sync;"
 312                        "0:    lwarx %0,0,%1 ;"
 313                        "      cmpl 0,%0,%3;"
 314                        "      bne 1f;"
 315                        "      stwcx. %2,0,%1;"
 316                        "      bne- 0b;"
 317                        "1:    "
 318                        "sync;"
 319                        : "=&r"(prev)
 320                        : "r"(ptr), "r"(new), "r"(old)
 321                        : "cr0", "memory");
 322                return prev;
 323        }
 324        __cmpxchg_called_with_bad_pointer();
 325        return old;
 326}
 327
 328#endif /* i386, powerpc & alpha */
 329
 330#ifndef __alpha__
 331#define cmpxchg(ptr,o,n)                                                \
 332  ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),              \
 333                                 (unsigned long)(n),sizeof(*(ptr))))
 334#endif
 335
 336#endif /* !__HAVE_ARCH_CMPXCHG */
 337
 338                                /* Macros to make printk easier */
 339#define DRM_ERROR(fmt, arg...) \
 340        printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg)
 341#define DRM_MEM_ERROR(area, fmt, arg...) \
 342        printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \
 343               DRM(mem_stats)[area].name , ##arg)
 344#define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
 345
 346#if DRM_DEBUG_CODE
 347#define DRM_DEBUG(fmt, arg...)                                          \
 348        do {                                                            \
 349                if ( DRM(flags) & DRM_FLAG_DEBUG )                      \
 350                        printk(KERN_DEBUG                               \
 351                               "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
 352                               ##arg);                                  \
 353        } while (0)
 354#else
 355#define DRM_DEBUG(fmt, arg...)           do { } while (0)
 356#endif
 357
 358#define DRM_PROC_LIMIT (PAGE_SIZE-80)
 359
 360#define DRM_PROC_PRINT(fmt, arg...)                                     \
 361   len += sprintf(&buf[len], fmt , ##arg);                              \
 362   if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
 363
 364#define DRM_PROC_PRINT_RET(ret, fmt, arg...)                            \
 365   len += sprintf(&buf[len], fmt , ##arg);                              \
 366   if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
 367
 368                                /* Mapping helper macros */
 369#define DRM_IOREMAP(map)                                                \
 370        (map)->handle = DRM(ioremap)( (map)->offset, (map)->size )
 371
 372#define DRM_IOREMAPFREE(map)                                            \
 373        do {                                                            \
 374                if ( (map)->handle && (map)->size )                     \
 375                        DRM(ioremapfree)( (map)->handle, (map)->size ); \
 376        } while (0)
 377
 378#define DRM_FIND_MAP(_map, _o)                                          \
 379do {                                                                    \
 380        struct list_head *_list;                                        \
 381        list_for_each( _list, &dev->maplist->head ) {                   \
 382                drm_map_list_t *_entry = (drm_map_list_t *)_list;       \
 383                if ( _entry->map &&                                     \
 384                     _entry->map->offset == (_o) ) {                    \
 385                        (_map) = _entry->map;                           \
 386                        break;                                          \
 387                }                                                       \
 388        }                                                               \
 389} while(0)
 390
 391                                /* Internal types and structures */
 392#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 393#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
 394#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
 395
 396#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
 397#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
 398#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
 399
 400#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {       \
 401        (_map) = (_dev)->context_sareas[_ctx];          \
 402} while(0)
 403
 404typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
 405                         unsigned int cmd, unsigned long arg );
 406
 407typedef struct drm_pci_list {
 408        u16 vendor;
 409        u16 device;
 410} drm_pci_list_t;
 411
 412typedef struct drm_ioctl_desc {
 413        drm_ioctl_t          *func;
 414        int                  auth_needed;
 415        int                  root_only;
 416} drm_ioctl_desc_t;
 417
 418typedef struct drm_devstate {
 419        pid_t             owner;        /* X server pid holding x_lock */
 420
 421} drm_devstate_t;
 422
 423typedef struct drm_magic_entry {
 424        drm_magic_t            magic;
 425        struct drm_file        *priv;
 426        struct drm_magic_entry *next;
 427} drm_magic_entry_t;
 428
 429typedef struct drm_magic_head {
 430        struct drm_magic_entry *head;
 431        struct drm_magic_entry *tail;
 432} drm_magic_head_t;
 433
 434typedef struct drm_vma_entry {
 435        struct vm_area_struct *vma;
 436        struct drm_vma_entry  *next;
 437        pid_t                 pid;
 438} drm_vma_entry_t;
 439
 440typedef struct drm_buf {
 441        int               idx;         /* Index into master buflist          */
 442        int               total;       /* Buffer size                        */
 443        int               order;       /* log-base-2(total)                  */
 444        int               used;        /* Amount of buffer in use (for DMA)  */
 445        unsigned long     offset;      /* Byte offset (used internally)      */
 446        void              *address;    /* Address of buffer                  */
 447        unsigned long     bus_address; /* Bus address of buffer              */
 448        struct drm_buf    *next;       /* Kernel-only: used for free list    */
 449        __volatile__ int  waiting;     /* On kernel DMA queue                */
 450        __volatile__ int  pending;     /* On hardware DMA queue              */
 451        wait_queue_head_t dma_wait;    /* Processes waiting                  */
 452        pid_t             pid;         /* PID of holding process             */
 453        int               context;     /* Kernel queue for this buffer       */
 454        int               while_locked;/* Dispatch this buffer while locked  */
 455        enum {
 456                DRM_LIST_NONE    = 0,
 457                DRM_LIST_FREE    = 1,
 458                DRM_LIST_WAIT    = 2,
 459                DRM_LIST_PEND    = 3,
 460                DRM_LIST_PRIO    = 4,
 461                DRM_LIST_RECLAIM = 5
 462        }                 list;        /* Which list we're on                */
 463
 464#if DRM_DMA_HISTOGRAM
 465        cycles_t          time_queued;     /* Queued to kernel DMA queue     */
 466        cycles_t          time_dispatched; /* Dispatched to hardware         */
 467        cycles_t          time_completed;  /* Completed by hardware          */
 468        cycles_t          time_freed;      /* Back on freelist               */
 469#endif
 470
 471        int               dev_priv_size; /* Size of buffer private stoarge   */
 472        void              *dev_private;  /* Per-buffer private storage       */
 473} drm_buf_t;
 474
 475#if DRM_DMA_HISTOGRAM
 476#define DRM_DMA_HISTOGRAM_SLOTS           9
 477#define DRM_DMA_HISTOGRAM_INITIAL        10
 478#define DRM_DMA_HISTOGRAM_NEXT(current)  ((current)*10)
 479typedef struct drm_histogram {
 480        atomic_t          total;
 481
 482        atomic_t          queued_to_dispatched[DRM_DMA_HISTOGRAM_SLOTS];
 483        atomic_t          dispatched_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
 484        atomic_t          completed_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
 485
 486        atomic_t          queued_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
 487        atomic_t          queued_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
 488
 489        atomic_t          dma[DRM_DMA_HISTOGRAM_SLOTS];
 490        atomic_t          schedule[DRM_DMA_HISTOGRAM_SLOTS];
 491        atomic_t          ctx[DRM_DMA_HISTOGRAM_SLOTS];
 492        atomic_t          lacq[DRM_DMA_HISTOGRAM_SLOTS];
 493        atomic_t          lhld[DRM_DMA_HISTOGRAM_SLOTS];
 494} drm_histogram_t;
 495#endif
 496
 497                                /* bufs is one longer than it has to be */
 498typedef struct drm_waitlist {
 499        int               count;        /* Number of possible buffers      */
 500        drm_buf_t         **bufs;       /* List of pointers to buffers     */
 501        drm_buf_t         **rp;         /* Read pointer                    */
 502        drm_buf_t         **wp;         /* Write pointer                   */
 503        drm_buf_t         **end;        /* End pointer                     */
 504        spinlock_t        read_lock;
 505        spinlock_t        write_lock;
 506} drm_waitlist_t;
 507
 508typedef struct drm_freelist {
 509        int               initialized; /* Freelist in use                  */
 510        atomic_t          count;       /* Number of free buffers           */
 511        drm_buf_t         *next;       /* End pointer                      */
 512
 513        wait_queue_head_t waiting;     /* Processes waiting on free bufs   */
 514        int               low_mark;    /* Low water mark                   */
 515        int               high_mark;   /* High water mark                  */
 516        atomic_t          wfh;         /* If waiting for high mark         */
 517        spinlock_t        lock;
 518} drm_freelist_t;
 519
 520typedef struct drm_buf_entry {
 521        int               buf_size;
 522        int               buf_count;
 523        drm_buf_t         *buflist;
 524        int               seg_count;
 525        int               page_order;
 526        unsigned long     *seglist;
 527
 528        drm_freelist_t    freelist;
 529} drm_buf_entry_t;
 530
 531typedef struct drm_hw_lock {
 532        __volatile__ unsigned int lock;
 533        char                      padding[60]; /* Pad to cache line */
 534} drm_hw_lock_t;
 535
 536typedef struct drm_file {
 537        int               authenticated;
 538        int               minor;
 539        pid_t             pid;
 540        uid_t             uid;
 541        drm_magic_t       magic;
 542        unsigned long     ioctl_count;
 543        struct drm_file   *next;
 544        struct drm_file   *prev;
 545        struct drm_device *dev;
 546        int               remove_auth_on_close;
 547} drm_file_t;
 548
 549
 550typedef struct drm_queue {
 551        atomic_t          use_count;    /* Outstanding uses (+1)            */
 552        atomic_t          finalization; /* Finalization in progress         */
 553        atomic_t          block_count;  /* Count of processes waiting       */
 554        atomic_t          block_read;   /* Queue blocked for reads          */
 555        wait_queue_head_t read_queue;   /* Processes waiting on block_read  */
 556        atomic_t          block_write;  /* Queue blocked for writes         */
 557        wait_queue_head_t write_queue;  /* Processes waiting on block_write */
 558#if 1
 559        atomic_t          total_queued; /* Total queued statistic           */
 560        atomic_t          total_flushed;/* Total flushes statistic          */
 561        atomic_t          total_locks;  /* Total locks statistics           */
 562#endif
 563        drm_ctx_flags_t   flags;        /* Context preserving and 2D-only   */
 564        drm_waitlist_t    waitlist;     /* Pending buffers                  */
 565        wait_queue_head_t flush_queue;  /* Processes waiting until flush    */
 566} drm_queue_t;
 567
 568typedef struct drm_lock_data {
 569        drm_hw_lock_t     *hw_lock;     /* Hardware lock                   */
 570        pid_t             pid;          /* PID of lock holder (0=kernel)   */
 571        wait_queue_head_t lock_queue;   /* Queue of blocked processes      */
 572        unsigned long     lock_time;    /* Time of last lock in jiffies    */
 573} drm_lock_data_t;
 574
 575typedef struct drm_device_dma {
 576#if 0
 577                                /* Performance Counters */
 578        atomic_t          total_prio;   /* Total DRM_DMA_PRIORITY          */
 579        atomic_t          total_bytes;  /* Total bytes DMA'd               */
 580        atomic_t          total_dmas;   /* Total DMA buffers dispatched    */
 581
 582        atomic_t          total_missed_dma;  /* Missed drm_do_dma           */
 583        atomic_t          total_missed_lock; /* Missed lock in drm_do_dma   */
 584        atomic_t          total_missed_free; /* Missed drm_free_this_buffer */
 585        atomic_t          total_missed_sched;/* Missed drm_dma_schedule     */
 586
 587        atomic_t          total_tried;  /* Tried next_buffer                */
 588        atomic_t          total_hit;    /* Sent next_buffer                 */
 589        atomic_t          total_lost;   /* Lost interrupt                   */
 590#endif
 591
 592        drm_buf_entry_t   bufs[DRM_MAX_ORDER+1];
 593        int               buf_count;
 594        drm_buf_t         **buflist;    /* Vector of pointers info bufs    */
 595        int               seg_count;
 596        int               page_count;
 597        unsigned long     *pagelist;
 598        unsigned long     byte_count;
 599        enum {
 600                _DRM_DMA_USE_AGP = 0x01,
 601                _DRM_DMA_USE_SG  = 0x02
 602        } flags;
 603
 604                                /* DMA support */
 605        drm_buf_t         *this_buffer; /* Buffer being sent               */
 606        drm_buf_t         *next_buffer; /* Selected buffer to send         */
 607        drm_queue_t       *next_queue;  /* Queue from which buffer selected*/
 608        wait_queue_head_t waiting;      /* Processes waiting on free bufs  */
 609} drm_device_dma_t;
 610
 611#if __REALLY_HAVE_AGP
 612typedef struct drm_agp_mem {
 613        unsigned long      handle;
 614        agp_memory         *memory;
 615        unsigned long      bound; /* address */
 616        int                pages;
 617        struct drm_agp_mem *prev;
 618        struct drm_agp_mem *next;
 619} drm_agp_mem_t;
 620
 621typedef struct drm_agp_head {
 622        agp_kern_info      agp_info;
 623        const char         *chipset;
 624        drm_agp_mem_t      *memory;
 625        unsigned long      mode;
 626        int                enabled;
 627        int                acquired;
 628        unsigned long      base;
 629        int                agp_mtrr;
 630        int                cant_use_aperture;
 631        unsigned long      page_mask;
 632} drm_agp_head_t;
 633#endif
 634
 635typedef struct drm_sg_mem {
 636        unsigned long   handle;
 637        void            *virtual;
 638        int             pages;
 639        struct page     **pagelist;
 640        dma_addr_t      *busaddr;
 641} drm_sg_mem_t;
 642
 643typedef struct drm_sigdata {
 644        int           context;
 645        drm_hw_lock_t *lock;
 646} drm_sigdata_t;
 647
 648typedef struct drm_map_list {
 649        struct list_head        head;
 650        drm_map_t               *map;
 651} drm_map_list_t;
 652
 653typedef struct drm_device {
 654        const char        *name;        /* Simple driver name              */
 655        char              *unique;      /* Unique identifier: e.g., busid  */
 656        int               unique_len;   /* Length of unique field          */
 657        dev_t             device;       /* Device number for mknod         */
 658        char              *devname;     /* For /proc/interrupts            */
 659
 660        int               blocked;      /* Blocked due to VC switch?       */
 661        struct proc_dir_entry *root;    /* Root for this device's entries  */
 662
 663                                /* Locks */
 664        spinlock_t        count_lock;   /* For inuse, open_count, buf_use  */
 665        struct semaphore  struct_sem;   /* For others                      */
 666
 667                                /* Usage Counters */
 668        int               open_count;   /* Outstanding files open          */
 669        atomic_t          ioctl_count;  /* Outstanding IOCTLs pending      */
 670        atomic_t          vma_count;    /* Outstanding vma areas open      */
 671        int               buf_use;      /* Buffers in use -- cannot alloc  */
 672        atomic_t          buf_alloc;    /* Buffer allocation in progress   */
 673
 674                                /* Performance counters */
 675        unsigned long     counters;
 676        drm_stat_type_t   types[15];
 677        atomic_t          counts[15];
 678
 679                                /* Authentication */
 680        drm_file_t        *file_first;
 681        drm_file_t        *file_last;
 682        drm_magic_head_t  magiclist[DRM_HASH_SIZE];
 683
 684                                /* Memory management */
 685        drm_map_list_t    *maplist;     /* Linked list of regions          */
 686        int               map_count;    /* Number of mappable regions      */
 687
 688        drm_map_t         **context_sareas;
 689        int               max_context;
 690
 691        drm_vma_entry_t   *vmalist;     /* List of vmas (for debugging)    */
 692        drm_lock_data_t   lock;         /* Information on hardware lock    */
 693
 694                                /* DMA queues (contexts) */
 695        int               queue_count;  /* Number of active DMA queues     */
 696        int               queue_reserved; /* Number of reserved DMA queues */
 697        int               queue_slots;  /* Actual length of queuelist      */
 698        drm_queue_t       **queuelist;  /* Vector of pointers to DMA queues */
 699        drm_device_dma_t  *dma;         /* Optional pointer for DMA support */
 700
 701                                /* Context support */
 702        int               irq;          /* Interrupt used by board         */
 703        __volatile__ long context_flag; /* Context swapping flag           */
 704        __volatile__ long interrupt_flag; /* Interruption handler flag     */
 705        __volatile__ long dma_flag;     /* DMA dispatch flag               */
 706        struct timer_list timer;        /* Timer for delaying ctx switch   */
 707        wait_queue_head_t context_wait; /* Processes waiting on ctx switch */
 708        int               last_checked; /* Last context checked for DMA    */
 709        int               last_context; /* Last current context            */
 710        unsigned long     last_switch;  /* jiffies at last context switch  */
 711        struct tq_struct  tq;
 712        cycles_t          ctx_start;
 713        cycles_t          lck_start;
 714#if __HAVE_DMA_HISTOGRAM
 715        drm_histogram_t   histo;
 716#endif
 717
 718                                /* Callback to X server for context switch
 719                                   and for heavy-handed reset. */
 720        char              buf[DRM_BSZ]; /* Output buffer                   */
 721        char              *buf_rp;      /* Read pointer                    */
 722        char              *buf_wp;      /* Write pointer                   */
 723        char              *buf_end;     /* End pointer                     */
 724        struct fasync_struct *buf_async;/* Processes waiting for SIGIO     */
 725        wait_queue_head_t buf_readers;  /* Processes waiting to read       */
 726        wait_queue_head_t buf_writers;  /* Processes waiting to ctx switch */
 727
 728#if __REALLY_HAVE_AGP
 729        drm_agp_head_t    *agp;
 730#endif
 731        struct pci_dev *pdev;
 732#ifdef __alpha__
 733#if LINUX_VERSION_CODE < 0x020403
 734        struct pci_controler *hose;
 735#else
 736        struct pci_controller *hose;
 737#endif
 738#endif
 739        drm_sg_mem_t      *sg;  /* Scatter gather memory */
 740        unsigned long     *ctx_bitmap;
 741        void              *dev_private;
 742        drm_sigdata_t     sigdata; /* For block_all_signals */
 743        sigset_t          sigmask;
 744} drm_device_t;
 745
 746
 747/* ================================================================
 748 * Internal function definitions
 749 */
 750
 751                                /* Misc. support (drm_init.h) */
 752extern int           DRM(flags);
 753extern void          DRM(parse_options)( char *s );
 754extern int           DRM(cpu_valid)( void );
 755
 756                                /* Driver support (drm_drv.h) */
 757extern int           DRM(version)(struct inode *inode, struct file *filp,
 758                                  unsigned int cmd, unsigned long arg);
 759extern int           DRM(open)(struct inode *inode, struct file *filp);
 760extern int           DRM(release)(struct inode *inode, struct file *filp);
 761extern int           DRM(ioctl)(struct inode *inode, struct file *filp,
 762                                unsigned int cmd, unsigned long arg);
 763extern int           DRM(lock)(struct inode *inode, struct file *filp,
 764                               unsigned int cmd, unsigned long arg);
 765extern int           DRM(unlock)(struct inode *inode, struct file *filp,
 766                                 unsigned int cmd, unsigned long arg);
 767
 768                                /* Device support (drm_fops.h) */
 769extern int           DRM(open_helper)(struct inode *inode, struct file *filp,
 770                                      drm_device_t *dev);
 771extern int           DRM(flush)(struct file *filp);
 772extern int           DRM(release_fuck)(struct inode *inode, struct file *filp);
 773extern int           DRM(fasync)(int fd, struct file *filp, int on);
 774extern ssize_t       DRM(read)(struct file *filp, char *buf, size_t count,
 775                               loff_t *off);
 776extern int           DRM(write_string)(drm_device_t *dev, const char *s);
 777extern unsigned int  DRM(poll)(struct file *filp,
 778                               struct poll_table_struct *wait);
 779
 780                                /* Mapping support (drm_vm.h) */
 781#if LINUX_VERSION_CODE < 0x020317
 782extern unsigned long DRM(vm_nopage)(struct vm_area_struct *vma,
 783                                    unsigned long address,
 784                                    int unused);
 785extern unsigned long DRM(vm_shm_nopage)(struct vm_area_struct *vma,
 786                                        unsigned long address,
 787                                        int unused);
 788extern unsigned long DRM(vm_dma_nopage)(struct vm_area_struct *vma,
 789                                        unsigned long address,
 790                                        int unused);
 791extern unsigned long DRM(vm_sg_nopage)(struct vm_area_struct *vma,
 792                                       unsigned long address,
 793                                       int unused);
 794#else
 795                                /* Return type changed in 2.3.23 */
 796extern struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
 797                                   unsigned long address,
 798                                   int unused);
 799extern struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
 800                                       unsigned long address,
 801                                       int unused);
 802extern struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
 803                                       unsigned long address,
 804                                       int unused);
 805extern struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma,
 806                                      unsigned long address,
 807                                      int unused);
 808#endif
 809extern void          DRM(vm_open)(struct vm_area_struct *vma);
 810extern void          DRM(vm_close)(struct vm_area_struct *vma);
 811extern void          DRM(vm_shm_close)(struct vm_area_struct *vma);
 812extern int           DRM(mmap_dma)(struct file *filp,
 813                                   struct vm_area_struct *vma);
 814extern int           DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
 815
 816                                /* Memory management support (drm_memory.h) */
 817extern void          DRM(mem_init)(void);
 818extern int           DRM(mem_info)(char *buf, char **start, off_t offset,
 819                                   int request, int *eof, void *data);
 820extern void          *DRM(alloc)(size_t size, int area);
 821extern void          *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
 822                                   int area);
 823extern char          *DRM(strdup)(const char *s, int area);
 824extern void          DRM(strfree)(const char *s, int area);
 825extern void          DRM(free)(void *pt, size_t size, int area);
 826extern unsigned long DRM(alloc_pages)(int order, int area);
 827extern void          DRM(free_pages)(unsigned long address, int order,
 828                                     int area);
 829extern void          *DRM(ioremap)(unsigned long offset, unsigned long size);
 830extern void          DRM(ioremapfree)(void *pt, unsigned long size);
 831
 832#if __REALLY_HAVE_AGP
 833extern agp_memory    *DRM(alloc_agp)(int pages, u32 type);
 834extern int           DRM(free_agp)(agp_memory *handle, int pages);
 835extern int           DRM(bind_agp)(agp_memory *handle, unsigned int start);
 836extern int           DRM(unbind_agp)(agp_memory *handle);
 837#endif
 838
 839                                /* Misc. IOCTL support (drm_ioctl.h) */
 840extern int           DRM(irq_busid)(struct inode *inode, struct file *filp,
 841                                    unsigned int cmd, unsigned long arg);
 842extern int           DRM(getunique)(struct inode *inode, struct file *filp,
 843                                    unsigned int cmd, unsigned long arg);
 844extern int           DRM(setunique)(struct inode *inode, struct file *filp,
 845                                    unsigned int cmd, unsigned long arg);
 846extern int           DRM(getmap)(struct inode *inode, struct file *filp,
 847                                 unsigned int cmd, unsigned long arg);
 848extern int           DRM(getclient)(struct inode *inode, struct file *filp,
 849                                    unsigned int cmd, unsigned long arg);
 850extern int           DRM(getstats)(struct inode *inode, struct file *filp,
 851                                   unsigned int cmd, unsigned long arg);
 852
 853                                /* Context IOCTL support (drm_context.h) */
 854extern int           DRM(resctx)( struct inode *inode, struct file *filp,
 855                                  unsigned int cmd, unsigned long arg );
 856extern int           DRM(addctx)( struct inode *inode, struct file *filp,
 857                                  unsigned int cmd, unsigned long arg );
 858extern int           DRM(modctx)( struct inode *inode, struct file *filp,
 859                                  unsigned int cmd, unsigned long arg );
 860extern int           DRM(getctx)( struct inode *inode, struct file *filp,
 861                                  unsigned int cmd, unsigned long arg );
 862extern int           DRM(switchctx)( struct inode *inode, struct file *filp,
 863                                     unsigned int cmd, unsigned long arg );
 864extern int           DRM(newctx)( struct inode *inode, struct file *filp,
 865                                  unsigned int cmd, unsigned long arg );
 866extern int           DRM(rmctx)( struct inode *inode, struct file *filp,
 867                                 unsigned int cmd, unsigned long arg );
 868
 869extern int           DRM(context_switch)(drm_device_t *dev, int old, int new);
 870extern int           DRM(context_switch_complete)(drm_device_t *dev, int new);
 871
 872#if __HAVE_CTX_BITMAP
 873extern int           DRM(ctxbitmap_init)( drm_device_t *dev );
 874extern void          DRM(ctxbitmap_cleanup)( drm_device_t *dev );
 875#endif
 876
 877extern int           DRM(setsareactx)( struct inode *inode, struct file *filp,
 878                                       unsigned int cmd, unsigned long arg );
 879extern int           DRM(getsareactx)( struct inode *inode, struct file *filp,
 880                                       unsigned int cmd, unsigned long arg );
 881
 882                                /* Drawable IOCTL support (drm_drawable.h) */
 883extern int           DRM(adddraw)(struct inode *inode, struct file *filp,
 884                                  unsigned int cmd, unsigned long arg);
 885extern int           DRM(rmdraw)(struct inode *inode, struct file *filp,
 886                                 unsigned int cmd, unsigned long arg);
 887
 888
 889                                /* Authentication IOCTL support (drm_auth.h) */
 890extern int           DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
 891                                    drm_magic_t magic);
 892extern int           DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
 893extern int           DRM(getmagic)(struct inode *inode, struct file *filp,
 894                                   unsigned int cmd, unsigned long arg);
 895extern int           DRM(authmagic)(struct inode *inode, struct file *filp,
 896                                    unsigned int cmd, unsigned long arg);
 897
 898
 899                                /* Locking IOCTL support (drm_lock.h) */
 900extern int           DRM(block)(struct inode *inode, struct file *filp,
 901                                unsigned int cmd, unsigned long arg);
 902extern int           DRM(unblock)(struct inode *inode, struct file *filp,
 903                                  unsigned int cmd, unsigned long arg);
 904extern int           DRM(lock_take)(__volatile__ unsigned int *lock,
 905                                    unsigned int context);
 906extern int           DRM(lock_transfer)(drm_device_t *dev,
 907                                        __volatile__ unsigned int *lock,
 908                                        unsigned int context);
 909extern int           DRM(lock_free)(drm_device_t *dev,
 910                                    __volatile__ unsigned int *lock,
 911                                    unsigned int context);
 912extern int           DRM(finish)(struct inode *inode, struct file *filp,
 913                                 unsigned int cmd, unsigned long arg);
 914extern int           DRM(flush_unblock)(drm_device_t *dev, int context,
 915                                        drm_lock_flags_t flags);
 916extern int           DRM(flush_block_and_flush)(drm_device_t *dev, int context,
 917                                                drm_lock_flags_t flags);
 918extern int           DRM(notifier)(void *priv);
 919
 920                                /* Buffer management support (drm_bufs.h) */
 921extern int           DRM(order)( unsigned long size );
 922extern int           DRM(addmap)( struct inode *inode, struct file *filp,
 923                                  unsigned int cmd, unsigned long arg );
 924extern int           DRM(rmmap)( struct inode *inode, struct file *filp,
 925                                 unsigned int cmd, unsigned long arg );
 926#if __HAVE_DMA
 927extern int           DRM(addbufs)( struct inode *inode, struct file *filp,
 928                                   unsigned int cmd, unsigned long arg );
 929extern int           DRM(infobufs)( struct inode *inode, struct file *filp,
 930                                    unsigned int cmd, unsigned long arg );
 931extern int           DRM(markbufs)( struct inode *inode, struct file *filp,
 932                                    unsigned int cmd, unsigned long arg );
 933extern int           DRM(freebufs)( struct inode *inode, struct file *filp,
 934                                    unsigned int cmd, unsigned long arg );
 935extern int           DRM(mapbufs)( struct inode *inode, struct file *filp,
 936                                   unsigned int cmd, unsigned long arg );
 937
 938                                /* DMA support (drm_dma.h) */
 939extern int           DRM(dma_setup)(drm_device_t *dev);
 940extern void          DRM(dma_takedown)(drm_device_t *dev);
 941extern void          DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
 942extern void          DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
 943#if __HAVE_OLD_DMA
 944/* GH: This is a dirty hack for now...
 945 */
 946extern void          DRM(clear_next_buffer)(drm_device_t *dev);
 947extern int           DRM(select_queue)(drm_device_t *dev,
 948                                       void (*wrapper)(unsigned long));
 949extern int           DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *dma);
 950extern int           DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma);
 951#endif
 952#if __HAVE_DMA_IRQ
 953extern int           DRM(control)( struct inode *inode, struct file *filp,
 954                                   unsigned int cmd, unsigned long arg );
 955extern int           DRM(irq_install)( drm_device_t *dev, int irq );
 956extern int           DRM(irq_uninstall)( drm_device_t *dev );
 957extern void          DRM(dma_service)( int irq, void *device,
 958                                       struct pt_regs *regs );
 959#if __HAVE_DMA_IRQ_BH
 960extern void          DRM(dma_immediate_bh)( void *dev );
 961#endif
 962#endif
 963#if DRM_DMA_HISTOGRAM
 964extern int           DRM(histogram_slot)(unsigned long count);
 965extern void          DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf);
 966#endif
 967
 968                                /* Buffer list support (drm_lists.h) */
 969#if __HAVE_DMA_WAITLIST
 970extern int           DRM(waitlist_create)(drm_waitlist_t *bl, int count);
 971extern int           DRM(waitlist_destroy)(drm_waitlist_t *bl);
 972extern int           DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf);
 973extern drm_buf_t     *DRM(waitlist_get)(drm_waitlist_t *bl);
 974#endif
 975#if __HAVE_DMA_FREELIST
 976extern int           DRM(freelist_create)(drm_freelist_t *bl, int count);
 977extern int           DRM(freelist_destroy)(drm_freelist_t *bl);
 978extern int           DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl,
 979                                       drm_buf_t *buf);
 980extern drm_buf_t     *DRM(freelist_get)(drm_freelist_t *bl, int block);
 981#endif
 982#endif /* __HAVE_DMA */
 983
 984#if __REALLY_HAVE_AGP
 985                                /* AGP/GART support (drm_agpsupport.h) */
 986extern drm_agp_head_t *DRM(agp_init)(void);
 987extern void           DRM(agp_uninit)(void);
 988extern int            DRM(agp_acquire)(struct inode *inode, struct file *filp,
 989                                       unsigned int cmd, unsigned long arg);
 990extern void           DRM(agp_do_release)(void);
 991extern int            DRM(agp_release)(struct inode *inode, struct file *filp,
 992                                       unsigned int cmd, unsigned long arg);
 993extern int            DRM(agp_enable)(struct inode *inode, struct file *filp,
 994                                      unsigned int cmd, unsigned long arg);
 995extern int            DRM(agp_info)(struct inode *inode, struct file *filp,
 996                                    unsigned int cmd, unsigned long arg);
 997extern int            DRM(agp_alloc)(struct inode *inode, struct file *filp,
 998                                     unsigned int cmd, unsigned long arg);
 999extern int            DRM(agp_free)(struct inode *inode, struct file *filp,
1000                                    unsigned int cmd, unsigned long arg);
1001extern int            DRM(agp_unbind)(struct inode *inode, struct file *filp,
1002                                      unsigned int cmd, unsigned long arg);
1003extern int            DRM(agp_bind)(struct inode *inode, struct file *filp,
1004                                    unsigned int cmd, unsigned long arg);
1005extern agp_memory     *DRM(agp_allocate_memory)(size_t pages, u32 type);
1006extern int            DRM(agp_free_memory)(agp_memory *handle);
1007extern int            DRM(agp_bind_memory)(agp_memory *handle, off_t start);
1008extern int            DRM(agp_unbind_memory)(agp_memory *handle);
1009#endif
1010
1011                                /* Stub support (drm_stub.h) */
1012int                   DRM(stub_register)(const char *name,
1013                                         struct file_operations *fops,
1014                                         drm_device_t *dev);
1015int                   DRM(stub_unregister)(int minor);
1016
1017                                /* Proc support (drm_proc.h) */
1018extern struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev,
1019                                             int minor,
1020                                             struct proc_dir_entry *root,
1021                                             struct proc_dir_entry **dev_root);
1022extern int            DRM(proc_cleanup)(int minor,
1023                                        struct proc_dir_entry *root,
1024                                        struct proc_dir_entry *dev_root);
1025
1026#if __HAVE_SG
1027                                /* Scatter Gather Support (drm_scatter.h) */
1028extern void           DRM(sg_cleanup)(drm_sg_mem_t *entry);
1029extern int            DRM(sg_alloc)(struct inode *inode, struct file *filp,
1030                                    unsigned int cmd, unsigned long arg);
1031extern int            DRM(sg_free)(struct inode *inode, struct file *filp,
1032                                   unsigned int cmd, unsigned long arg);
1033#endif
1034
1035                               /* ATI PCIGART support (ati_pcigart.h) */
1036extern int            DRM(ati_pcigart_init)(drm_device_t *dev,
1037                                            unsigned long *addr,
1038                                            dma_addr_t *bus_addr);
1039extern int            DRM(ati_pcigart_cleanup)(drm_device_t *dev,
1040                                               unsigned long addr,
1041                                               dma_addr_t bus_addr);
1042
1043#endif /* __KERNEL__ */
1044#endif
1045
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.