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