Merge master.kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6
authorLinus Torvalds <torvalds@g5.osdl.org>
Wed, 2 Nov 2005 05:49:07 +0000 (21:49 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 2 Nov 2005 05:49:07 +0000 (21:49 -0800)
Manual fixups for some clashes due to re-indenting.

93 files changed:
drivers/char/drm/ati_pcigart.c
drivers/char/drm/drm.h
drivers/char/drm/drmP.h
drivers/char/drm/drm_agpsupport.c
drivers/char/drm/drm_auth.c
drivers/char/drm/drm_bufs.c
drivers/char/drm/drm_context.c
drivers/char/drm/drm_dma.c
drivers/char/drm/drm_drawable.c
drivers/char/drm/drm_drv.c
drivers/char/drm/drm_fops.c
drivers/char/drm/drm_init.c
drivers/char/drm/drm_ioc32.c
drivers/char/drm/drm_ioctl.c
drivers/char/drm/drm_irq.c
drivers/char/drm/drm_lock.c
drivers/char/drm/drm_memory.c
drivers/char/drm/drm_memory.h
drivers/char/drm/drm_memory_debug.h
drivers/char/drm/drm_os_linux.h
drivers/char/drm/drm_pci.c
drivers/char/drm/drm_pciids.h
drivers/char/drm/drm_proc.c
drivers/char/drm/drm_sarea.h
drivers/char/drm/drm_scatter.c
drivers/char/drm/drm_stub.c
drivers/char/drm/drm_vm.c
drivers/char/drm/ffb_context.c
drivers/char/drm/ffb_drv.c
drivers/char/drm/ffb_drv.h
drivers/char/drm/i810_dma.c
drivers/char/drm/i810_drm.h
drivers/char/drm/i810_drv.c
drivers/char/drm/i810_drv.h
drivers/char/drm/i830_dma.c
drivers/char/drm/i830_drm.h
drivers/char/drm/i830_drv.c
drivers/char/drm/i830_drv.h
drivers/char/drm/i830_irq.c
drivers/char/drm/i915_dma.c
drivers/char/drm/i915_drv.c
drivers/char/drm/i915_drv.h
drivers/char/drm/i915_ioc32.c
drivers/char/drm/i915_mem.c
drivers/char/drm/mga_dma.c
drivers/char/drm/mga_drm.h
drivers/char/drm/mga_drv.c
drivers/char/drm/mga_drv.h
drivers/char/drm/mga_ioc32.c
drivers/char/drm/mga_irq.c
drivers/char/drm/mga_state.c
drivers/char/drm/mga_ucode.h
drivers/char/drm/mga_warp.c
drivers/char/drm/r128_cce.c
drivers/char/drm/r128_drm.h
drivers/char/drm/r128_drv.c
drivers/char/drm/r128_drv.h
drivers/char/drm/r128_ioc32.c
drivers/char/drm/r128_irq.c
drivers/char/drm/r128_state.c
drivers/char/drm/r300_cmdbuf.c
drivers/char/drm/r300_reg.h
drivers/char/drm/radeon_cp.c
drivers/char/drm/radeon_drm.h
drivers/char/drm/radeon_drv.c
drivers/char/drm/radeon_drv.h
drivers/char/drm/radeon_ioc32.c
drivers/char/drm/radeon_irq.c
drivers/char/drm/radeon_mem.c
drivers/char/drm/radeon_state.c
drivers/char/drm/savage_bci.c
drivers/char/drm/savage_drm.h
drivers/char/drm/savage_drv.c
drivers/char/drm/savage_drv.h
drivers/char/drm/savage_state.c
drivers/char/drm/sis_drm.h
drivers/char/drm/sis_drv.c
drivers/char/drm/sis_drv.h
drivers/char/drm/sis_ds.c
drivers/char/drm/sis_ds.h
drivers/char/drm/sis_mm.c
drivers/char/drm/tdfx_drv.c
drivers/char/drm/via_3d_reg.h
drivers/char/drm/via_dma.c
drivers/char/drm/via_drm.h
drivers/char/drm/via_drv.c
drivers/char/drm/via_drv.h
drivers/char/drm/via_irq.c
drivers/char/drm/via_map.c
drivers/char/drm/via_mm.c
drivers/char/drm/via_verifier.c
drivers/char/drm/via_verifier.h
drivers/char/drm/via_video.c

index 0aec5ef481b8600040da86257d049e65d74b1a4b..6d3fec160bffb1841db17a38f86abca07cc5d6e1 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file ati_pcigart.
+ * \file ati_pcigart.c
  * ATI PCI GART support
  *
  * \author Gareth Hughes <gareth@valinux.com>
 # define ATI_MAX_PCIGART_PAGES         8192    /**< 32 MB aperture, 4K pages */
 # define ATI_PCIGART_PAGE_SIZE         4096    /**< PCI GART page size */
 
-static unsigned long drm_ati_alloc_pcigart_table( void )
+static unsigned long drm_ati_alloc_pcigart_table(void)
 {
        unsigned long address;
        struct page *page;
        int i;
-       DRM_DEBUG( "%s\n", __FUNCTION__ );
+       DRM_DEBUG("%s\n", __FUNCTION__);
 
-       address = __get_free_pages( GFP_KERNEL, ATI_PCIGART_TABLE_ORDER );
-       if ( address == 0UL ) {
+       address = __get_free_pages(GFP_KERNEL, ATI_PCIGART_TABLE_ORDER);
+       if (address == 0UL) {
                return 0;
        }
 
-       page = virt_to_page( address );
+       page = virt_to_page(address);
 
-       for ( i = 0 ; i < ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
+       for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) {
                get_page(page);
-               SetPageReserved( page );
+               SetPageReserved(page);
        }
 
-       DRM_DEBUG( "%s: returning 0x%08lx\n", __FUNCTION__, address );
+       DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address);
        return address;
 }
 
-static void drm_ati_free_pcigart_table( unsigned long address )
+static void drm_ati_free_pcigart_table(unsigned long address)
 {
        struct page *page;
        int i;
-       DRM_DEBUG( "%s\n", __FUNCTION__ );
+       DRM_DEBUG("%s\n", __FUNCTION__);
 
-       page = virt_to_page( address );
+       page = virt_to_page(address);
 
-       for ( i = 0 ; i < ATI_PCIGART_TABLE_PAGES ; i++, page++ ) {
+       for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) {
                __put_page(page);
-               ClearPageReserved( page );
+               ClearPageReserved(page);
        }
 
-       free_pages( address, ATI_PCIGART_TABLE_ORDER );
+       free_pages(address, ATI_PCIGART_TABLE_ORDER);
 }
 
-int drm_ati_pcigart_cleanup( drm_device_t *dev,
-                             unsigned long addr,
-                             dma_addr_t bus_addr)
+int drm_ati_pcigart_cleanup(drm_device_t * dev,
+                           drm_ati_pcigart_info * gart_info)
 {
        drm_sg_mem_t *entry = dev->sg;
        unsigned long pages;
        int i;
 
        /* we need to support large memory configurations */
-       if ( !entry ) {
-               DRM_ERROR( "no scatter/gather memory!\n" );
+       if (!entry) {
+               DRM_ERROR("no scatter/gather memory!\n");
                return 0;
        }
 
-       if ( bus_addr ) {
-               pci_unmap_single(dev->pdev, bus_addr,
-                                ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
-                                PCI_DMA_TODEVICE);
+       if (gart_info->bus_addr) {
+               if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+                       pci_unmap_single(dev->pdev, gart_info->bus_addr,
+                                        ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
+                                        PCI_DMA_TODEVICE);
+               }
 
-               pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
-                       ? entry->pages : ATI_MAX_PCIGART_PAGES;
+               pages = (entry->pages <= ATI_MAX_PCIGART_PAGES)
+                   ? entry->pages : ATI_MAX_PCIGART_PAGES;
 
-               for ( i = 0 ; i < pages ; i++ ) {
-                       if ( !entry->busaddr[i] ) break;
+               for (i = 0; i < pages; i++) {
+                       if (!entry->busaddr[i])
+                               break;
                        pci_unmap_single(dev->pdev, entry->busaddr[i],
                                         PAGE_SIZE, PCI_DMA_TODEVICE);
                }
+
+               if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
+                       gart_info->bus_addr = 0;
        }
 
-       if ( addr ) {
-               drm_ati_free_pcigart_table( addr );
+       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
+           && gart_info->addr) {
+               drm_ati_free_pcigart_table(gart_info->addr);
+               gart_info->addr = 0;
        }
 
        return 1;
 }
+
 EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
 
-int drm_ati_pcigart_init( drm_device_t *dev,
-                          unsigned long *addr,
-                          dma_addr_t *bus_addr)
+int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info * gart_info)
 {
        drm_sg_mem_t *entry = dev->sg;
        unsigned long address = 0;
@@ -138,48 +144,57 @@ int drm_ati_pcigart_init( drm_device_t *dev,
        u32 *pci_gart, page_base, bus_address = 0;
        int i, j, ret = 0;
 
-       if ( !entry ) {
-               DRM_ERROR( "no scatter/gather memory!\n" );
+       if (!entry) {
+               DRM_ERROR("no scatter/gather memory!\n");
                goto done;
        }
 
-       address = drm_ati_alloc_pcigart_table();
-       if ( !address ) {
-               DRM_ERROR( "cannot allocate PCI GART page!\n" );
-               goto done;
-       }
+       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+               DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
 
-       if ( !dev->pdev ) {
-               DRM_ERROR( "PCI device unknown!\n" );
-               goto done;
-       }
+               address = drm_ati_alloc_pcigart_table();
+               if (!address) {
+                       DRM_ERROR("cannot allocate PCI GART page!\n");
+                       goto done;
+               }
 
-       bus_address = pci_map_single(dev->pdev, (void *)address,
-                                 ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
-                                 PCI_DMA_TODEVICE);
-       if (bus_address == 0) {
-               DRM_ERROR( "unable to map PCIGART pages!\n" );
-               drm_ati_free_pcigart_table( address );
-               address = 0;
-               goto done;
+               if (!dev->pdev) {
+                       DRM_ERROR("PCI device unknown!\n");
+                       goto done;
+               }
+
+               bus_address = pci_map_single(dev->pdev, (void *)address,
+                                            ATI_PCIGART_TABLE_PAGES *
+                                            PAGE_SIZE, PCI_DMA_TODEVICE);
+               if (bus_address == 0) {
+                       DRM_ERROR("unable to map PCIGART pages!\n");
+                       drm_ati_free_pcigart_table(address);
+                       address = 0;
+                       goto done;
+               }
+       } else {
+               address = gart_info->addr;
+               bus_address = gart_info->bus_addr;
+               DRM_DEBUG("PCI: Gart Table: VRAM %08X mapped at %08lX\n",
+                         bus_address, address);
        }
 
-       pci_gart = (u32 *)address;
+       pci_gart = (u32 *) address;
 
-       pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
-               ? entry->pages : ATI_MAX_PCIGART_PAGES;
+       pages = (entry->pages <= ATI_MAX_PCIGART_PAGES)
+           ? entry->pages : ATI_MAX_PCIGART_PAGES;
 
-       memset( pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
+       memset(pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32));
 
-       for ( i = 0 ; i < pages ; i++ ) {
+       for (i = 0; i < pages; i++) {
                /* we need to support large memory configurations */
                entry->busaddr[i] = pci_map_single(dev->pdev,
-                                          page_address( entry->pagelist[i] ),
-                                          PAGE_SIZE,
-                                          PCI_DMA_TODEVICE);
+                                                  page_address(entry->
+                                                               pagelist[i]),
+                                                  PAGE_SIZE, PCI_DMA_TODEVICE);
                if (entry->busaddr[i] == 0) {
-                       DRM_ERROR( "unable to map PCIGART pages!\n" );
-                       drm_ati_pcigart_cleanup( dev, address, bus_address );
+                       DRM_ERROR("unable to map PCIGART pages!\n");
+                       drm_ati_pcigart_cleanup(dev, gart_info);
                        address = 0;
                        bus_address = 0;
                        goto done;
@@ -187,7 +202,11 @@ int drm_ati_pcigart_init( drm_device_t *dev,
                page_base = (u32) entry->busaddr[i];
 
                for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
-                       *pci_gart++ = cpu_to_le32( page_base );
+                       if (gart_info->is_pcie)
+                               *pci_gart = (cpu_to_le32(page_base) >> 8) | 0xc;
+                       else
+                               *pci_gart = cpu_to_le32(page_base);
+                       *pci_gart++;
                        page_base += ATI_PCIGART_PAGE_SIZE;
                }
        }
@@ -200,9 +219,10 @@ int drm_ati_pcigart_init( drm_device_t *dev,
        mb();
 #endif
 
-done:
-       *addr = address;
-       *bus_addr = bus_address;
+      done:
+       gart_info->addr = address;
+       gart_info->bus_addr = bus_address;
        return ret;
 }
+
 EXPORT_SYMBOL(drm_ati_pcigart_init);
index fc6598a81acdd5888fd11893f941e75fa0d13d70..64d6237fdd0baa5ce661472ba12ddd7eddacf304 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drm.h 
+ * \file drm.h
  * Header for the Direct Rendering Manager
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  *
  * \par Acknowledgments:
@@ -33,7 +33,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-
 #ifndef _DRM_H_
 #define _DRM_H_
 
@@ -56,7 +55,7 @@
 #define ioctl(a,b,c)           xf86ioctl(a,b,c)
 #else
 #include <sys/ioccom.h>
-#endif /* __FreeBSD__ && xf86ioctl */
+#endif                         /* __FreeBSD__ && xf86ioctl */
 #define DRM_IOCTL_NR(n)                ((n) & 0xff)
 #define DRM_IOC_VOID           IOC_VOID
 #define DRM_IOC_READ           IOC_OUT
 #define _DRM_LOCK_IS_CONT(lock)           ((lock) & _DRM_LOCK_CONT)
 #define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
 
-
-typedef unsigned int  drm_handle_t;
-typedef unsigned int  drm_context_t;
-typedef unsigned int  drm_drawable_t;
-typedef unsigned int  drm_magic_t;
-
+typedef unsigned int drm_handle_t;
+typedef unsigned int drm_context_t;
+typedef unsigned int drm_drawable_t;
+typedef unsigned int drm_magic_t;
 
 /**
  * Cliprect.
- * 
+ *
  * \warning: If you change this structure, make sure you change
  * XF86DRIClipRectRec in the server as well
  *
@@ -114,22 +111,21 @@ typedef unsigned int  drm_magic_t;
  * backwards-compatibility reasons.
  */
 typedef struct drm_clip_rect {
-       unsigned short  x1;
-       unsigned short  y1;
-       unsigned short  x2;
-       unsigned short  y2;
+       unsigned short x1;
+       unsigned short y1;
+       unsigned short x2;
+       unsigned short y2;
 } drm_clip_rect_t;
 
-
 /**
  * Texture region,
  */
 typedef struct drm_tex_region {
-       unsigned char   next;
-       unsigned char   prev;
-       unsigned char   in_use;
-       unsigned char   padding;
-       unsigned int    age;
+       unsigned char next;
+       unsigned char prev;
+       unsigned char in_use;
+       unsigned char padding;
+       unsigned int age;
 } drm_tex_region_t;
 
 /**
@@ -141,28 +137,26 @@ typedef struct drm_tex_region {
  */
 typedef struct drm_hw_lock {
        __volatile__ unsigned int lock;         /**< lock variable */
-       char                      padding[60];  /**< Pad to cache line */
+       char padding[60];                       /**< Pad to cache line */
 } drm_hw_lock_t;
 
-
 /**
  * DRM_IOCTL_VERSION ioctl argument type.
- * 
+ *
  * \sa drmGetVersion().
  */
 typedef struct drm_version {
-       int    version_major;     /**< Major version */
-       int    version_minor;     /**< Minor version */
-       int    version_patchlevel;/**< Patch level */
+       int version_major;        /**< Major version */
+       int version_minor;        /**< Minor version */
+       int version_patchlevel;   /**< Patch level */
        size_t name_len;          /**< Length of name buffer */
-       char   __user *name;      /**< Name of driver */
+       char __user *name;        /**< Name of driver */
        size_t date_len;          /**< Length of date buffer */
-       char   __user *date;      /**< User-space buffer to hold date */
+       char __user *date;        /**< User-space buffer to hold date */
        size_t desc_len;          /**< Length of desc buffer */
-       char   __user *desc;      /**< User-space buffer to hold desc */
+       char __user *desc;        /**< User-space buffer to hold desc */
 } drm_version_t;
 
-
 /**
  * DRM_IOCTL_GET_UNIQUE ioctl argument type.
  *
@@ -170,21 +164,18 @@ typedef struct drm_version {
  */
 typedef struct drm_unique {
        size_t unique_len;        /**< Length of unique */
-       char   __user *unique;    /**< Unique name for driver instantiation */
+       char __user *unique;      /**< Unique name for driver instantiation */
 } drm_unique_t;
 
-
 typedef struct drm_list {
-       int              count;   /**< Length of user-space structures */
-       drm_version_t    __user *version;
+       int count;                /**< Length of user-space structures */
+       drm_version_t __user *version;
 } drm_list_t;
 
-
 typedef struct drm_block {
-       int              unused;
+       int unused;
 } drm_block_t;
 
-
 /**
  * DRM_IOCTL_CONTROL ioctl argument type.
  *
@@ -196,44 +187,40 @@ typedef struct drm_control {
                DRM_RM_COMMAND,
                DRM_INST_HANDLER,
                DRM_UNINST_HANDLER
-       }                func;
-       int              irq;
+       } func;
+       int irq;
 } drm_control_t;
 
-
 /**
  * Type of memory to map.
  */
 typedef enum drm_map_type {
-       _DRM_FRAME_BUFFER   = 0,  /**< WC (no caching), no core dump */
-       _DRM_REGISTERS      = 1,  /**< no caching, no core dump */
-       _DRM_SHM            = 2,  /**< shared, cached */
-       _DRM_AGP            = 3,  /**< AGP/GART */
+       _DRM_FRAME_BUFFER = 0,    /**< WC (no caching), no core dump */
+       _DRM_REGISTERS = 1,       /**< no caching, no core dump */
+       _DRM_SHM = 2,             /**< shared, cached */
+       _DRM_AGP = 3,             /**< AGP/GART */
        _DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
-       _DRM_CONSISTENT     = 5,  /**< Consistent memory for PCI DMA */
+       _DRM_CONSISTENT = 5,      /**< Consistent memory for PCI DMA */
 } drm_map_type_t;
 
-
 /**
  * Memory mapping flags.
  */
 typedef enum drm_map_flags {
-       _DRM_RESTRICTED      = 0x01, /**< Cannot be mapped to user-virtual */
-       _DRM_READ_ONLY       = 0x02,
-       _DRM_LOCKED          = 0x04, /**< shared, cached, locked */
-       _DRM_KERNEL          = 0x08, /**< kernel requires access */
+       _DRM_RESTRICTED = 0x01,      /**< Cannot be mapped to user-virtual */
+       _DRM_READ_ONLY = 0x02,
+       _DRM_LOCKED = 0x04,          /**< shared, cached, locked */
+       _DRM_KERNEL = 0x08,          /**< kernel requires access */
        _DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
-       _DRM_CONTAINS_LOCK   = 0x20, /**< SHM page that contains lock */
-       _DRM_REMOVABLE       = 0x40  /**< Removable mapping */
+       _DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
+       _DRM_REMOVABLE = 0x40        /**< Removable mapping */
 } drm_map_flags_t;
 
-
 typedef struct drm_ctx_priv_map {
-       unsigned int    ctx_id;  /**< Context requesting private mapping */
-       void            *handle; /**< Handle of map */
+       unsigned int ctx_id;     /**< Context requesting private mapping */
+       void *handle;            /**< Handle of map */
 } drm_ctx_priv_map_t;
 
-
 /**
  * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
  * argument type.
@@ -241,30 +228,28 @@ typedef struct drm_ctx_priv_map {
  * \sa drmAddMap().
  */
 typedef struct drm_map {
-       unsigned long   offset;  /**< Requested physical address (0 for SAREA)*/
-       unsigned long   size;    /**< Requested physical size (bytes) */
-       drm_map_type_t  type;    /**< Type of memory to map */
+       unsigned long offset;    /**< Requested physical address (0 for SAREA)*/
+       unsigned long size;      /**< Requested physical size (bytes) */
+       drm_map_type_t type;     /**< Type of memory to map */
        drm_map_flags_t flags;   /**< Flags */
-       void            *handle; /**< User-space: "Handle" to pass to mmap() */
+       void *handle;            /**< User-space: "Handle" to pass to mmap() */
                                 /**< Kernel-space: kernel-virtual address */
-       int             mtrr;    /**< MTRR slot used */
-                                /*   Private data */
+       int mtrr;                /**< MTRR slot used */
+       /*   Private data */
 } drm_map_t;
 
-
 /**
  * DRM_IOCTL_GET_CLIENT ioctl argument type.
  */
 typedef struct drm_client {
-       int             idx;    /**< Which client desired? */
-       int             auth;   /**< Is client authenticated? */
-       unsigned long   pid;    /**< Process ID */
-       unsigned long   uid;    /**< User ID */
-       unsigned long   magic;  /**< Magic */
-       unsigned long   iocs;   /**< Ioctl count */
+       int idx;                /**< Which client desired? */
+       int auth;               /**< Is client authenticated? */
+       unsigned long pid;      /**< Process ID */
+       unsigned long uid;      /**< User ID */
+       unsigned long magic;    /**< Magic */
+       unsigned long iocs;     /**< Ioctl count */
 } drm_client_t;
 
-
 typedef enum {
        _DRM_STAT_LOCK,
        _DRM_STAT_OPENS,
@@ -282,63 +267,58 @@ typedef enum {
        _DRM_STAT_DMA,          /**< DMA */
        _DRM_STAT_SPECIAL,      /**< Special DMA (e.g., priority or polled) */
        _DRM_STAT_MISSED        /**< Missed DMA opportunity */
-
-                               /* Add to the *END* of the list */
+           /* Add to the *END* of the list */
 } drm_stat_type_t;
 
-
 /**
  * DRM_IOCTL_GET_STATS ioctl argument type.
  */
 typedef struct drm_stats {
        unsigned long count;
        struct {
-               unsigned long   value;
+               unsigned long value;
                drm_stat_type_t type;
        } data[15];
 } drm_stats_t;
 
-
 /**
  * Hardware locking flags.
  */
 typedef enum drm_lock_flags {
-       _DRM_LOCK_READY      = 0x01, /**< Wait until hardware is ready for DMA */
-       _DRM_LOCK_QUIESCENT  = 0x02, /**< Wait until hardware quiescent */
-       _DRM_LOCK_FLUSH      = 0x04, /**< Flush this context's DMA queue first */
-       _DRM_LOCK_FLUSH_ALL  = 0x08, /**< Flush all DMA queues first */
-                               /* These *HALT* flags aren't supported yet
-                                  -- they will be used to support the
-                                  full-screen DGA-like mode. */
+       _DRM_LOCK_READY = 0x01,      /**< Wait until hardware is ready for DMA */
+       _DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
+       _DRM_LOCK_FLUSH = 0x04,      /**< Flush this context's DMA queue first */
+       _DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
+       /* These *HALT* flags aren't supported yet
+          -- they will be used to support the
+          full-screen DGA-like mode. */
        _DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
        _DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
 } drm_lock_flags_t;
 
-
 /**
  * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
- * 
+ *
  * \sa drmGetLock() and drmUnlock().
  */
 typedef struct drm_lock {
-       int              context;
+       int context;
        drm_lock_flags_t flags;
 } drm_lock_t;
 
-
 /**
  * DMA flags
  *
- * \warning 
+ * \warning
  * These values \e must match xf86drm.h.
  *
  * \sa drm_dma.
  */
-typedef enum drm_dma_flags {         
-                                     /* Flags for DMA buffer dispatch */
-       _DRM_DMA_BLOCK        = 0x01, /**<
+typedef enum drm_dma_flags {
+       /* Flags for DMA buffer dispatch */
+       _DRM_DMA_BLOCK = 0x01,        /**<
                                       * Block until buffer dispatched.
-                                      * 
+                                      *
                                       * \note The buffer may not yet have
                                       * been processed by the hardware --
                                       * getting a hardware lock with the
@@ -347,79 +327,73 @@ typedef enum drm_dma_flags {
                                       * processed.
                                       */
        _DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
-       _DRM_DMA_PRIORITY     = 0x04, /**< High priority dispatch */
+       _DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
 
-                                     /* Flags for DMA buffer request */
-       _DRM_DMA_WAIT         = 0x10, /**< Wait for free buffers */
-       _DRM_DMA_SMALLER_OK   = 0x20, /**< Smaller-than-requested buffers OK */
-       _DRM_DMA_LARGER_OK    = 0x40  /**< Larger-than-requested buffers OK */
+       /* Flags for DMA buffer request */
+       _DRM_DMA_WAIT = 0x10,         /**< Wait for free buffers */
+       _DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
+       _DRM_DMA_LARGER_OK = 0x40     /**< Larger-than-requested buffers OK */
 } drm_dma_flags_t;
 
-
 /**
  * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
  *
  * \sa drmAddBufs().
  */
 typedef struct drm_buf_desc {
-       int           count;     /**< Number of buffers of this size */
-       int           size;      /**< Size in bytes */
-       int           low_mark;  /**< Low water mark */
-       int           high_mark; /**< High water mark */
+       int count;               /**< Number of buffers of this size */
+       int size;                /**< Size in bytes */
+       int low_mark;            /**< Low water mark */
+       int high_mark;           /**< High water mark */
        enum {
-               _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
-               _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
-               _DRM_SG_BUFFER  = 0x04, /**< Scatter/gather memory buffer */
-               _DRM_FB_BUFFER  = 0x08  /**< Buffer is in frame buffer */
-       }             flags;
-       unsigned long agp_start; /**< 
+               _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
+               _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
+               _DRM_SG_BUFFER = 0x04,  /**< Scatter/gather memory buffer */
+               _DRM_FB_BUFFER = 0x08   /**< Buffer is in frame buffer */
+       } flags;
+       unsigned long agp_start; /**<
                                  * Start address of where the AGP buffers are
                                  * in the AGP aperture
                                  */
 } drm_buf_desc_t;
 
-
 /**
  * DRM_IOCTL_INFO_BUFS ioctl argument type.
  */
 typedef struct drm_buf_info {
-       int            count;   /**< Entries in list */
+       int count;              /**< Entries in list */
        drm_buf_desc_t __user *list;
 } drm_buf_info_t;
 
-
 /**
  * DRM_IOCTL_FREE_BUFS ioctl argument type.
  */
 typedef struct drm_buf_free {
-       int            count;
-       int            __user *list;
+       int count;
+       int __user *list;
 } drm_buf_free_t;
 
-
 /**
  * Buffer information
  *
  * \sa drm_buf_map.
  */
 typedef struct drm_buf_pub {
-       int               idx;         /**< Index into the master buffer list */
-       int               total;       /**< Buffer size */
-       int               used;        /**< Amount of buffer in use (for DMA) */
-       void      __user *address;     /**< Address of buffer */
+       int idx;                       /**< Index into the master buffer list */
+       int total;                     /**< Buffer size */
+       int used;                      /**< Amount of buffer in use (for DMA) */
+       void __user *address;          /**< Address of buffer */
 } drm_buf_pub_t;
 
-
 /**
  * DRM_IOCTL_MAP_BUFS ioctl argument type.
  */
 typedef struct drm_buf_map {
-       int           count;    /**< Length of the buffer list */
-       void          __user *virtual;  /**< Mmap'd area in user-virtual */
+       int count;              /**< Length of the buffer list */
+       void __user *virtual;           /**< Mmap'd area in user-virtual */
        drm_buf_pub_t __user *list;     /**< Buffer information */
 } drm_buf_map_t;
 
-
 /**
  * DRM_IOCTL_DMA ioctl argument type.
  *
@@ -428,61 +402,55 @@ typedef struct drm_buf_map {
  * \sa drmDMA().
  */
 typedef struct drm_dma {
-       int             context;          /**< Context handle */
-       int             send_count;       /**< Number of buffers to send */
-       int     __user *send_indices;     /**< List of handles to buffers */
-       int     __user *send_sizes;       /**< Lengths of data to send */
+       int context;                      /**< Context handle */
+       int send_count;                   /**< Number of buffers to send */
+       int __user *send_indices;         /**< List of handles to buffers */
+       int __user *send_sizes;           /**< Lengths of data to send */
        drm_dma_flags_t flags;            /**< Flags */
-       int             request_count;    /**< Number of buffers requested */
-       int             request_size;     /**< Desired size for buffers */
-       int     __user *request_indices;  /**< Buffer information */
-       int     __user *request_sizes;
-       int             granted_count;    /**< Number of buffers granted */
+       int request_count;                /**< Number of buffers requested */
+       int request_size;                 /**< Desired size for buffers */
+       int __user *request_indices;      /**< Buffer information */
+       int __user *request_sizes;
+       int granted_count;                /**< Number of buffers granted */
 } drm_dma_t;
 
-
 typedef enum {
        _DRM_CONTEXT_PRESERVED = 0x01,
-       _DRM_CONTEXT_2DONLY    = 0x02
+       _DRM_CONTEXT_2DONLY = 0x02
 } drm_ctx_flags_t;
 
-
 /**
  * DRM_IOCTL_ADD_CTX ioctl argument type.
  *
  * \sa drmCreateContext() and drmDestroyContext().
  */
 typedef struct drm_ctx {
-       drm_context_t   handle;
+       drm_context_t handle;
        drm_ctx_flags_t flags;
 } drm_ctx_t;
 
-
 /**
  * DRM_IOCTL_RES_CTX ioctl argument type.
  */
 typedef struct drm_ctx_res {
-       int             count;
-       drm_ctx_t       __user *contexts;
+       int count;
+       drm_ctx_t __user *contexts;
 } drm_ctx_res_t;
 
-
 /**
  * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
  */
 typedef struct drm_draw {
-       drm_drawable_t  handle;
+       drm_drawable_t handle;
 } drm_draw_t;
 
-
 /**
  * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
  */
 typedef struct drm_auth {
-       drm_magic_t     magic;
+       drm_magic_t magic;
 } drm_auth_t;
 
-
 /**
  * DRM_IOCTL_IRQ_BUSID ioctl argument type.
  *
@@ -495,24 +463,20 @@ typedef struct drm_irq_busid {
        int funcnum;    /**< function number */
 } drm_irq_busid_t;
 
-
 typedef enum {
-    _DRM_VBLANK_ABSOLUTE = 0x0,                /**< Wait for specific vblank sequence number */
-    _DRM_VBLANK_RELATIVE = 0x1,                /**< Wait for given number of vblanks */
-    _DRM_VBLANK_SIGNAL   = 0x40000000  /**< Send signal instead of blocking */
+       _DRM_VBLANK_ABSOLUTE = 0x0,     /**< Wait for specific vblank sequence number */
+       _DRM_VBLANK_RELATIVE = 0x1,     /**< Wait for given number of vblanks */
+       _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */
 } drm_vblank_seq_type_t;
 
-
 #define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
 
-
 struct drm_wait_vblank_request {
        drm_vblank_seq_type_t type;
        unsigned int sequence;
        unsigned long signal;
 };
 
-
 struct drm_wait_vblank_reply {
        drm_vblank_seq_type_t type;
        unsigned int sequence;
@@ -520,7 +484,6 @@ struct drm_wait_vblank_reply {
        long tval_usec;
 };
 
-
 /**
  * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
  *
@@ -531,7 +494,6 @@ typedef union drm_wait_vblank {
        struct drm_wait_vblank_reply reply;
 } drm_wait_vblank_t;
 
-
 /**
  * DRM_IOCTL_AGP_ENABLE ioctl argument type.
  *
@@ -541,7 +503,6 @@ typedef struct drm_agp_mode {
        unsigned long mode;     /**< AGP mode */
 } drm_agp_mode_t;
 
-
 /**
  * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
  *
@@ -550,22 +511,20 @@ typedef struct drm_agp_mode {
 typedef struct drm_agp_buffer {
        unsigned long size;     /**< In bytes -- will round to page boundary */
        unsigned long handle;   /**< Used for binding / unbinding */
-       unsigned long type;     /**< Type of memory to allocate */
-        unsigned long physical; /**< Physical used by i810 */
+       unsigned long type;     /**< Type of memory to allocate */
+       unsigned long physical; /**< Physical used by i810 */
 } drm_agp_buffer_t;
 
-
 /**
  * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
  *
  * \sa drmAgpBind() and drmAgpUnbind().
  */
 typedef struct drm_agp_binding {
-       unsigned long handle;   /**< From drm_agp_buffer */
+       unsigned long handle;   /**< From drm_agp_buffer */
        unsigned long offset;   /**< In bytes -- will round to page boundary */
 } drm_agp_binding_t;
 
-
 /**
  * DRM_IOCTL_AGP_INFO ioctl argument type.
  *
@@ -574,20 +533,19 @@ typedef struct drm_agp_binding {
  * drmAgpVendorId() and drmAgpDeviceId().
  */
 typedef struct drm_agp_info {
-       int            agp_version_major;
-       int            agp_version_minor;
-       unsigned long  mode;
-       unsigned long  aperture_base;  /* physical address */
-       unsigned long  aperture_size;  /* bytes */
-       unsigned long  memory_allowed; /* bytes */
-       unsigned long  memory_used;
-
-                               /* PCI information */
+       int agp_version_major;
+       int agp_version_minor;
+       unsigned long mode;
+       unsigned long aperture_base;    /* physical address */
+       unsigned long aperture_size;    /* bytes */
+       unsigned long memory_allowed;   /* bytes */
+       unsigned long memory_used;
+
+       /* PCI information */
        unsigned short id_vendor;
        unsigned short id_device;
 } drm_agp_info_t;
 
-
 /**
  * DRM_IOCTL_SG_ALLOC ioctl argument type.
  */
@@ -606,7 +564,6 @@ typedef struct drm_set_version {
        int drm_dd_minor;
 } drm_set_version_t;
 
-
 #define DRM_IOCTL_BASE                 'd'
 #define DRM_IO(nr)                     _IO(DRM_IOCTL_BASE,nr)
 #define DRM_IOR(nr,type)               _IOR(DRM_IOCTL_BASE,nr,type)
index 121cc85f347e713dbaef7bcbe614cc8dcb48e33e..3dc3c9d79ae423d69a7c0fd9c59cc8d02b25b830 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drmP.h 
+ * \file drmP.h
  * Private header for Direct Rendering Manager
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
@@ -43,7 +43,7 @@
  * before static inline funcs in wait.h. Doing this so we
  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
 #include <asm/current.h>
-#endif /* __alpha__ */
+#endif                         /* __alpha__ */
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -58,7 +58,7 @@
 #include <linux/mm.h>
 #include <linux/cdev.h>
 #if defined(__alpha__) || defined(__powerpc__)
-#include <asm/pgtable.h> /* For pte_wrprotect */
+#include <asm/pgtable.h>       /* For pte_wrprotect */
 #endif
 #include <asm/io.h>
 #include <asm/mman.h>
 #define DRM_KERNEL_CONTEXT    0         /**< Change drm_resctx if changed */
 #define DRM_RESERVED_CONTEXTS 1         /**< Change drm_resctx if changed */
 #define DRM_LOOPING_LIMIT     5000000
-#define DRM_BSZ                      1024 /**< Buffer size for /dev/drm? output */
 #define DRM_TIME_SLICE       (HZ/20)  /**< Time slice for GLXContexts */
 #define DRM_LOCK_SLICE       1 /**< Time slice for lock, in jiffies */
 
 #define DRM_MEM_CTXLIST  21
 
 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
-       
-/*@}*/
 
+/*@}*/
 
 /***********************************************************************/
 /** \name Backward compatibility section */
 /*@{*/
 
 #ifndef MODULE_LICENSE
-#define MODULE_LICENSE(x) 
+#define MODULE_LICENSE(x)
 #endif
 
 #ifndef preempt_disable
 #define preempt_enable()
 #endif
 
-#ifndef pte_offset_map 
+#ifndef pte_offset_map
 #define pte_offset_map pte_offset
 #define pte_unmap(pte)
 #endif
 
 /*@}*/
 
-
 /***********************************************************************/
 /** \name Macros to make printk easier */
 /*@{*/
 
 /**
  * Debug output.
- * 
+ *
  * \param fmt printf() like format string.
  * \param arg arguments
  */
 
 /*@}*/
 
-
 /***********************************************************************/
 /** \name Internal types and structures */
 /*@{*/
 
-#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
-#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
+#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
+#define DRM_MIN(a,b) min(a,b)
+#define DRM_MAX(a,b) max(a,b)
 
 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
@@ -275,7 +271,7 @@ do {                                                                        \
                if ( copy_to_user( name, value, len ) )                 \
                        return -EFAULT;                                 \
        }
-       
+
 /**
  * Ioctl function type.
  *
@@ -284,25 +280,25 @@ do {                                                                      \
  * \param cmd command.
  * \param arg argument.
  */
-typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
-                        unsigned int cmd, unsigned long arg );
+typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
 
 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
                               unsigned long arg);
 
 typedef struct drm_ioctl_desc {
-       drm_ioctl_t          *func;
-       int                  auth_needed;
-       int                  root_only;
+       drm_ioctl_t *func;
+       int auth_needed;
+       int root_only;
 } drm_ioctl_desc_t;
 
 typedef struct drm_devstate {
-       pid_t             owner;        /**< X server pid holding x_lock */
+       pid_t owner;                    /**< X server pid holding x_lock */
 } drm_devstate_t;
 
 typedef struct drm_magic_entry {
-       drm_magic_t            magic;
-       struct drm_file        *priv;
+       drm_magic_t magic;
+       struct drm_file *priv;
        struct drm_magic_entry *next;
 } drm_magic_entry_t;
 
@@ -313,111 +309,110 @@ typedef struct drm_magic_head {
 
 typedef struct drm_vma_entry {
        struct vm_area_struct *vma;
-       struct drm_vma_entry  *next;
-       pid_t                 pid;
+       struct drm_vma_entry *next;
+       pid_t pid;
 } drm_vma_entry_t;
 
 /**
  * DMA buffer.
  */
 typedef struct drm_buf {
-       int               idx;         /**< Index into master buflist */
-       int               total;       /**< Buffer size */
-       int               order;       /**< log-base-2(total) */
-       int               used;        /**< Amount of buffer in use (for DMA) */
-       unsigned long     offset;      /**< Byte offset (used internally) */
-       void              *address;    /**< Address of buffer */
-       unsigned long     bus_address; /**< Bus address of buffer */
-       struct drm_buf    *next;       /**< Kernel-only: used for free list */
-       __volatile__ int  waiting;     /**< On kernel DMA queue */
-       __volatile__ int  pending;     /**< On hardware DMA queue */
+       int idx;                       /**< Index into master buflist */
+       int total;                     /**< Buffer size */
+       int order;                     /**< log-base-2(total) */
+       int used;                      /**< Amount of buffer in use (for DMA) */
+       unsigned long offset;          /**< Byte offset (used internally) */
+       void *address;                 /**< Address of buffer */
+       unsigned long bus_address;     /**< Bus address of buffer */
+       struct drm_buf *next;          /**< Kernel-only: used for free list */
+       __volatile__ int waiting;      /**< On kernel DMA queue */
+       __volatile__ int pending;      /**< On hardware DMA queue */
        wait_queue_head_t dma_wait;    /**< Processes waiting */
-       struct file       *filp;       /**< Pointer to holding file descr */
-       int               context;     /**< Kernel queue for this buffer */
-       int               while_locked;/**< Dispatch this buffer while locked */
+       struct file *filp;             /**< Pointer to holding file descr */
+       int context;                   /**< Kernel queue for this buffer */
+       int while_locked;              /**< Dispatch this buffer while locked */
        enum {
-               DRM_LIST_NONE    = 0,
-               DRM_LIST_FREE    = 1,
-               DRM_LIST_WAIT    = 2,
-               DRM_LIST_PEND    = 3,
-               DRM_LIST_PRIO    = 4,
+               DRM_LIST_NONE = 0,
+               DRM_LIST_FREE = 1,
+               DRM_LIST_WAIT = 2,
+               DRM_LIST_PEND = 3,
+               DRM_LIST_PRIO = 4,
                DRM_LIST_RECLAIM = 5
-       }                 list;        /**< Which list we're on */
+       } list;                        /**< Which list we're on */
 
-       int               dev_priv_size; /**< Size of buffer private storage */
-       void              *dev_private;  /**< Per-buffer private storage */
+       int dev_priv_size;               /**< Size of buffer private storage */
+       void *dev_private;               /**< Per-buffer private storage */
 } drm_buf_t;
 
-
 /** bufs is one longer than it has to be */
 typedef struct drm_waitlist {
-       int               count;        /**< Number of possible buffers */
-       drm_buf_t         **bufs;       /**< List of pointers to buffers */
-       drm_buf_t         **rp;         /**< Read pointer */
-       drm_buf_t         **wp;         /**< Write pointer */
-       drm_buf_t         **end;        /**< End pointer */
-       spinlock_t        read_lock;
-       spinlock_t        write_lock;
+       int count;                      /**< Number of possible buffers */
+       drm_buf_t **bufs;               /**< List of pointers to buffers */
+       drm_buf_t **rp;                 /**< Read pointer */
+       drm_buf_t **wp;                 /**< Write pointer */
+       drm_buf_t **end;                /**< End pointer */
+       spinlock_t read_lock;
+       spinlock_t write_lock;
 } drm_waitlist_t;
 
 typedef struct drm_freelist {
-       int               initialized; /**< Freelist in use */
-       atomic_t          count;       /**< Number of free buffers */
-       drm_buf_t         *next;       /**< End pointer */
+       int initialized;               /**< Freelist in use */
+       atomic_t count;                /**< Number of free buffers */
+       drm_buf_t *next;               /**< End pointer */
 
        wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
-       int               low_mark;    /**< Low water mark */
-       int               high_mark;   /**< High water mark */
-       atomic_t          wfh;         /**< If waiting for high mark */
-       spinlock_t        lock;
+       int low_mark;                  /**< Low water mark */
+       int high_mark;                 /**< High water mark */
+       atomic_t wfh;                  /**< If waiting for high mark */
+       spinlock_t lock;
 } drm_freelist_t;
 
 /**
  * Buffer entry.  There is one of this for each buffer size order.
  */
 typedef struct drm_buf_entry {
-       int               buf_size;     /**< size */
-       int               buf_count;    /**< number of buffers */
-       drm_buf_t         *buflist;     /**< buffer list */
-       int               seg_count;
-       int               page_order;
-       unsigned long     *seglist;
-
-       drm_freelist_t    freelist;
+       int buf_size;                   /**< size */
+       int buf_count;                  /**< number of buffers */
+       drm_buf_t *buflist;             /**< buffer list */
+       int seg_count;
+       int page_order;
+       unsigned long *seglist;
+
+       drm_freelist_t freelist;
 } drm_buf_entry_t;
 
 /** File private data */
 typedef struct drm_file {
-       int               authenticated;
-       int               minor;
-       pid_t             pid;
-       uid_t             uid;
-       drm_magic_t       magic;
-       unsigned long     ioctl_count;
-       struct drm_file   *next;
-       struct drm_file   *prev;
-       struct drm_head   *head;
-       int               remove_auth_on_close;
-       unsigned long     lock_count;
-       void              *driver_priv;
+       int authenticated;
+       int minor;
+       pid_t pid;
+       uid_t uid;
+       drm_magic_t magic;
+       unsigned long ioctl_count;
+       struct drm_file *next;
+       struct drm_file *prev;
+       struct drm_head *head;
+       int remove_auth_on_close;
+       unsigned long lock_count;
+       void *driver_priv;
 } drm_file_t;
 
 /** Wait queue */
 typedef struct drm_queue {
-       atomic_t          use_count;    /**< Outstanding uses (+1) */
-       atomic_t          finalization; /**< Finalization in progress */
-       atomic_t          block_count;  /**< Count of processes waiting */
-       atomic_t          block_read;   /**< Queue blocked for reads */
+       atomic_t use_count;             /**< Outstanding uses (+1) */
+       atomic_t finalization;          /**< Finalization in progress */
+       atomic_t block_count;           /**< Count of processes waiting */
+       atomic_t block_read;            /**< Queue blocked for reads */
        wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
-       atomic_t          block_write;  /**< Queue blocked for writes */
+       atomic_t block_write;           /**< Queue blocked for writes */
        wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
 #if 1
-       atomic_t          total_queued; /**< Total queued statistic */
-       atomic_t          total_flushed;/**< Total flushes statistic */
-       atomic_t          total_locks;  /**< Total locks statistics */
+       atomic_t total_queued;          /**< Total queued statistic */
+       atomic_t total_flushed;         /**< Total flushes statistic */
+       atomic_t total_locks;           /**< Total locks statistics */
 #endif
-       drm_ctx_flags_t   flags;        /**< Context preserving and 2D-only */
-       drm_waitlist_t    waitlist;     /**< Pending buffers */
+       drm_ctx_flags_t flags;          /**< Context preserving and 2D-only */
+       drm_waitlist_t waitlist;        /**< Pending buffers */
        wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
 } drm_queue_t;
 
@@ -425,10 +420,10 @@ typedef struct drm_queue {
  * Lock data.
  */
 typedef struct drm_lock_data {
-       drm_hw_lock_t     *hw_lock;     /**< Hardware lock */
-       struct file       *filp;        /**< File descr of lock holder (0=kernel) */
+       drm_hw_lock_t *hw_lock;         /**< Hardware lock */
+       struct file *filp;              /**< File descr of lock holder (0=kernel) */
        wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
-       unsigned long     lock_time;    /**< Time of last lock in jiffies */
+       unsigned long lock_time;        /**< Time of last lock in jiffies */
 } drm_lock_data_t;
 
 /**
@@ -436,29 +431,29 @@ typedef struct drm_lock_data {
  */
 typedef struct drm_device_dma {
 
-       drm_buf_entry_t   bufs[DRM_MAX_ORDER+1];        /**< buffers, grouped by their size order */
-       int               buf_count;    /**< total number of buffers */
-       drm_buf_t         **buflist;    /**< Vector of pointers into drm_device_dma::bufs */
-       int               seg_count;
-       int               page_count;   /**< number of pages */
-       unsigned long     *pagelist;    /**< page list */
-       unsigned long     byte_count;
+       drm_buf_entry_t bufs[DRM_MAX_ORDER + 1];        /**< buffers, grouped by their size order */
+       int buf_count;                  /**< total number of buffers */
+       drm_buf_t **buflist;            /**< Vector of pointers into drm_device_dma::bufs */
+       int seg_count;
+       int page_count;                 /**< number of pages */
+       unsigned long *pagelist;        /**< page list */
+       unsigned long byte_count;
        enum {
                _DRM_DMA_USE_AGP = 0x01,
-               _DRM_DMA_USE_SG  = 0x02,
-               _DRM_DMA_USE_FB  = 0x04
+               _DRM_DMA_USE_SG = 0x02,
+               _DRM_DMA_USE_FB = 0x04
        } flags;
 
 } drm_device_dma_t;
 
-/** 
+/**
  * AGP memory entry.  Stored as a doubly linked list.
  */
 typedef struct drm_agp_mem {
-       unsigned long      handle;      /**< handle */
-       DRM_AGP_MEM        *memory;     
-       unsigned long      bound;       /**< address */
-       int                pages;
+       unsigned long handle;           /**< handle */
+       DRM_AGP_MEM *memory;
+       unsigned long bound;            /**< address */
+       int pages;
        struct drm_agp_mem *prev;       /**< previous entry */
        struct drm_agp_mem *next;       /**< next entry */
 } drm_agp_mem_t;
@@ -469,31 +464,31 @@ typedef struct drm_agp_mem {
  * \sa drm_agp_init() and drm_device::agp.
  */
 typedef struct drm_agp_head {
-       DRM_AGP_KERN       agp_info;    /**< AGP device information */
-       drm_agp_mem_t      *memory;     /**< memory entries */
-       unsigned long      mode;        /**< AGP mode */
-       struct agp_bridge_data  *bridge;
-       int                enabled;     /**< whether the AGP bus as been enabled */
-       int                acquired;    /**< whether the AGP device has been acquired */
-       unsigned long      base;
-       int                agp_mtrr;
-       int                cant_use_aperture;
-       unsigned long      page_mask;
+       DRM_AGP_KERN agp_info;          /**< AGP device information */
+       drm_agp_mem_t *memory;          /**< memory entries */
+       unsigned long mode;             /**< AGP mode */
+       struct agp_bridge_data *bridge;
+       int enabled;                    /**< whether the AGP bus as been enabled */
+       int acquired;                   /**< whether the AGP device has been acquired */
+       unsigned long base;
+       int agp_mtrr;
+       int cant_use_aperture;
+       unsigned long page_mask;
 } drm_agp_head_t;
 
 /**
  * Scatter-gather memory.
  */
 typedef struct drm_sg_mem {
-       unsigned long   handle;
-       void            *virtual;
-       int             pages;
-       struct page     **pagelist;
-       dma_addr_t      *busaddr;
+       unsigned long handle;
+       void *virtual;
+       int pages;
+       struct page **pagelist;
+       dma_addr_t *busaddr;
 } drm_sg_mem_t;
 
 typedef struct drm_sigdata {
-       int           context;
+       int context;
        drm_hw_lock_t *lock;
 } drm_sigdata_t;
 
@@ -507,8 +502,8 @@ typedef struct drm_dma_handle {
  * Mappings list
  */
 typedef struct drm_map_list {
-       struct list_head        head;   /**< list head */
-       drm_map_t               *map;   /**< mapping */
+       struct list_head head;          /**< list head */
+       drm_map_t *map;                 /**< mapping */
        unsigned int user_token;
 } drm_map_list_t;
 
@@ -518,19 +513,28 @@ typedef drm_map_t drm_local_map_t;
  * Context handle list
  */
 typedef struct drm_ctx_list {
-       struct list_head        head;   /**< list head */
-       drm_context_t           handle; /**< context handle */
-       drm_file_t              *tag;   /**< associated fd private data */
+       struct list_head head;          /**< list head */
+       drm_context_t handle;           /**< context handle */
+       drm_file_t *tag;                /**< associated fd private data */
 } drm_ctx_list_t;
 
-
 typedef struct drm_vbl_sig {
-       struct list_head        head;
-       unsigned int            sequence;
-       struct siginfo          info;
-       struct task_struct      *task;
+       struct list_head head;
+       unsigned int sequence;
+       struct siginfo info;
+       struct task_struct *task;
 } drm_vbl_sig_t;
 
+/* location of GART table */
+#define DRM_ATI_GART_MAIN 1
+#define DRM_ATI_GART_FB   2
+
+typedef struct ati_pcigart_info {
+       int gart_table_location;
+       int is_pcie;
+       unsigned long addr;
+       dma_addr_t bus_addr;
+} drm_ati_pcigart_info;
 
 /**
  * DRM driver structure. This structure represent the common code for
@@ -540,24 +544,26 @@ typedef struct drm_vbl_sig {
 struct drm_device;
 
 struct drm_driver {
-       int (*preinit)(struct drm_device *, unsigned long flags);
-       void (*prerelease)(struct drm_device *, struct file *filp);
-       void (*pretakedown)(struct drm_device *);
-       int (*postcleanup)(struct drm_device *);
-       int (*presetup)(struct drm_device *);
-       int (*postsetup)(struct drm_device *);
-       int (*dma_ioctl)( DRM_IOCTL_ARGS );
-       int (*open_helper)(struct drm_device *, drm_file_t *);
-       void (*free_filp_priv)(struct drm_device *, drm_file_t *);
-       void (*release)(struct drm_device *, struct file *filp);
-       void (*dma_ready)(struct drm_device *);
-       int (*dma_quiescent)(struct drm_device *);
-       int (*context_ctor)(struct drm_device *dev, int context);
-       int (*context_dtor)(struct drm_device *dev, int context);
-       int (*kernel_context_switch)(struct drm_device *dev, int old, int new);
-       void (*kernel_context_switch_unlock)(struct drm_device *dev, drm_lock_t *lock);
-       int (*vblank_wait)(struct drm_device *dev, unsigned int *sequence);
-       
+       int (*preinit) (struct drm_device *, unsigned long flags);
+       void (*prerelease) (struct drm_device *, struct file * filp);
+       void (*pretakedown) (struct drm_device *);
+       int (*postcleanup) (struct drm_device *);
+       int (*presetup) (struct drm_device *);
+       int (*postsetup) (struct drm_device *);
+       int (*dma_ioctl) (DRM_IOCTL_ARGS);
+       int (*open_helper) (struct drm_device *, drm_file_t *);
+       void (*free_filp_priv) (struct drm_device *, drm_file_t *);
+       void (*release) (struct drm_device *, struct file * filp);
+       void (*dma_ready) (struct drm_device *);
+       int (*dma_quiescent) (struct drm_device *);
+       int (*context_ctor) (struct drm_device * dev, int context);
+       int (*context_dtor) (struct drm_device * dev, int context);
+       int (*kernel_context_switch) (struct drm_device * dev, int old,
+                                     int new);
+       void (*kernel_context_switch_unlock) (struct drm_device * dev,
+                                             drm_lock_t * lock);
+       int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
+
        /**
         * Called by \c drm_device_is_agp.  Typically used to determine if a
         * card is really attached to AGP or not.
@@ -572,17 +578,17 @@ struct drm_driver {
        int (*device_is_agp) (struct drm_device * dev);
 
        /* these have to be filled in */
-  
-       int (*postinit)(struct drm_device *, unsigned long flags);
-       irqreturn_t (*irq_handler)( DRM_IRQ_ARGS );
-       void (*irq_preinstall)(struct drm_device *dev);
-       void (*irq_postinstall)(struct drm_device *dev);
-       void (*irq_uninstall)(struct drm_device *dev);
-       void (*reclaim_buffers)(struct drm_device *dev, struct file *filp);
-       unsigned long (*get_map_ofs)(drm_map_t *map);
-       unsigned long (*get_reg_ofs)(struct drm_device *dev);
-       void (*set_version)(struct drm_device *dev, drm_set_version_t *sv);
-       int (*version)(drm_version_t *version);
+
+       int (*postinit) (struct drm_device *, unsigned long flags);
+        irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
+       void (*irq_preinstall) (struct drm_device * dev);
+       void (*irq_postinstall) (struct drm_device * dev);
+       void (*irq_uninstall) (struct drm_device * dev);
+       void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
+       unsigned long (*get_map_ofs) (drm_map_t * map);
+       unsigned long (*get_reg_ofs) (struct drm_device * dev);
+       void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
+       int (*version) (drm_version_t * version);
        u32 driver_features;
        int dev_priv_size;
        drm_ioctl_desc_t *ioctls;
@@ -609,128 +615,125 @@ typedef struct drm_head {
  * may contain multiple heads.
  */
 typedef struct drm_device {
-       char              *unique;      /**< Unique identifier: e.g., busid */
-       int               unique_len;   /**< Length of unique field */
-       char              *devname;     /**< For /proc/interrupts */
-       int               if_version;   /**< Highest interface version set */
+       char *unique;                   /**< Unique identifier: e.g., busid */
+       int unique_len;                 /**< Length of unique field */
+       char *devname;                  /**< For /proc/interrupts */
+       int if_version;                 /**< Highest interface version set */
 
-       int               blocked;      /**< Blocked due to VC switch? */
+       int blocked;                    /**< Blocked due to VC switch? */
 
        /** \name Locks */
-       /*@{*/
-       spinlock_t        count_lock;   /**< For inuse, drm_device::open_count, drm_device::buf_use */
-       struct semaphore  struct_sem;   /**< For others */
-       /*@}*/
+       /*@{ */
+       spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
+       struct semaphore struct_sem;    /**< For others */
+       /*@} */
 
        /** \name Usage Counters */
-       /*@{*/
-       int               open_count;   /**< Outstanding files open */
-       atomic_t          ioctl_count;  /**< Outstanding IOCTLs pending */
-       atomic_t          vma_count;    /**< Outstanding vma areas open */
-       int               buf_use;      /**< Buffers in use -- cannot alloc */
-       atomic_t          buf_alloc;    /**< Buffer allocation in progress */
-       /*@}*/
+       /*@{ */
+       int open_count;                 /**< Outstanding files open */
+       atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
+       atomic_t vma_count;             /**< Outstanding vma areas open */
+       int buf_use;                    /**< Buffers in use -- cannot alloc */
+       atomic_t buf_alloc;             /**< Buffer allocation in progress */
+       /*@} */
 
        /** \name Performance counters */
-       /*@{*/
-       unsigned long     counters;
-       drm_stat_type_t   types[15];
-       atomic_t          counts[15];
-       /*@}*/
+       /*@{ */
+       unsigned long counters;
+       drm_stat_type_t types[15];
+       atomic_t counts[15];
+       /*@} */
 
        /** \name Authentication */
-       /*@{*/
-       drm_file_t        *file_first;  /**< file list head */
-       drm_file_t        *file_last;   /**< file list tail */
-       drm_magic_head_t  magiclist[DRM_HASH_SIZE];     /**< magic hash table */
-       /*@}*/
+       /*@{ */
+       drm_file_t *file_first;         /**< file list head */
+       drm_file_t *file_last;          /**< file list tail */
+       drm_magic_head_t magiclist[DRM_HASH_SIZE];      /**< magic hash table */
+       /*@} */
 
        /** \name Memory management */
-       /*@{*/
-       drm_map_list_t    *maplist;     /**< Linked list of regions */
-       int               map_count;    /**< Number of mappable regions */
+       /*@{ */
+       drm_map_list_t *maplist;        /**< Linked list of regions */
+       int map_count;                  /**< Number of mappable regions */
 
        /** \name Context handle management */
-       /*@{*/
-       drm_ctx_list_t    *ctxlist;     /**< Linked list of context handles */
-       int               ctx_count;    /**< Number of context handles */
-       struct semaphore  ctxlist_sem;  /**< For ctxlist */
+       /*@{ */
+       drm_ctx_list_t *ctxlist;        /**< Linked list of context handles */
+       int ctx_count;                  /**< Number of context handles */
+       struct semaphore ctxlist_sem;   /**< For ctxlist */
 
-       drm_map_t         **context_sareas; /**< per-context SAREA's */
-       int               max_context;
+       drm_map_t **context_sareas;         /**< per-context SAREA's */
+       int max_context;
 
-       drm_vma_entry_t   *vmalist;     /**< List of vmas (for debugging) */
-       drm_lock_data_t   lock;         /**< Information on hardware lock */
-       /*@}*/
+       drm_vma_entry_t *vmalist;       /**< List of vmas (for debugging) */
+       drm_lock_data_t lock;           /**< Information on hardware lock */
+       /*@} */
 
        /** \name DMA queues (contexts) */
-       /*@{*/
-       int               queue_count;  /**< Number of active DMA queues */
-       int               queue_reserved; /**< Number of reserved DMA queues */
-       int               queue_slots;  /**< Actual length of queuelist */
-       drm_queue_t       **queuelist;  /**< Vector of pointers to DMA queues */
-       drm_device_dma_t  *dma;         /**< Optional pointer for DMA support */
-       /*@}*/
+       /*@{ */
+       int queue_count;                /**< Number of active DMA queues */
+       int queue_reserved;               /**< Number of reserved DMA queues */
+       int queue_slots;                /**< Actual length of queuelist */
+       drm_queue_t **queuelist;        /**< Vector of pointers to DMA queues */
+       drm_device_dma_t *dma;          /**< Optional pointer for DMA support */
+       /*@} */
 
        /** \name Context support */
-       /*@{*/
-       int               irq;          /**< Interrupt used by board */
-       int               irq_enabled;  /**< True if irq handler is enabled */
+       /*@{ */
+       int irq;                        /**< Interrupt used by board */
+       int irq_enabled;                /**< True if irq handler is enabled */
        __volatile__ long context_flag; /**< Context swapping flag */
        __volatile__ long interrupt_flag; /**< Interruption handler flag */
        __volatile__ long dma_flag;     /**< DMA dispatch flag */
        struct timer_list timer;        /**< Timer for delaying ctx switch */
-       wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
-       int               last_checked; /**< Last context checked for DMA */
-       int               last_context; /**< Last current context */
-       unsigned long     last_switch;  /**< jiffies at last context switch */
-       /*@}*/
-       
-       struct work_struct      work;
+       wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
+       int last_checked;               /**< Last context checked for DMA */
+       int last_context;               /**< Last current context */
+       unsigned long last_switch;      /**< jiffies at last context switch */
+       /*@} */
+
+       struct work_struct work;
        /** \name VBLANK IRQ support */
-       /*@{*/
-
-       wait_queue_head_t vbl_queue;    /**< VBLANK wait queue */
-       atomic_t          vbl_received;
-       spinlock_t        vbl_lock;
-       drm_vbl_sig_t     vbl_sigs;     /**< signal list to send on VBLANK */
-       unsigned int      vbl_pending;
-
-       /*@}*/
-       cycles_t          ctx_start;
-       cycles_t          lck_start;
-
-       char              buf[DRM_BSZ]; /**< Output buffer */
-       char              *buf_rp;      /**< Read pointer */
-       char              *buf_wp;      /**< Write pointer */
-       char              *buf_end;     /**< End pointer */
+       /*@{ */
+
+       wait_queue_head_t vbl_queue;    /**< VBLANK wait queue */
+       atomic_t vbl_received;
+       spinlock_t vbl_lock;
+       drm_vbl_sig_t vbl_sigs;         /**< signal list to send on VBLANK */
+       unsigned int vbl_pending;
+
+       /*@} */
+       cycles_t ctx_start;
+       cycles_t lck_start;
+
        struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
        wait_queue_head_t buf_readers;  /**< Processes waiting to read */
        wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
 
-       drm_agp_head_t    *agp; /**< AGP data */
+       drm_agp_head_t *agp;    /**< AGP data */
 
-       struct pci_dev    *pdev;        /**< PCI device structure */
-       int               pci_domain;   /**< PCI bus domain number */
-       int               pci_bus;      /**< PCI bus number */
-       int               pci_slot;     /**< PCI slot number */
-       int               pci_func;     /**< PCI function number */
+       struct pci_dev *pdev;           /**< PCI device structure */
+       int pci_domain;                 /**< PCI bus domain number */
+       int pci_bus;                    /**< PCI bus number */
+       int pci_slot;                   /**< PCI slot number */
+       int pci_func;                   /**< PCI function number */
 #ifdef __alpha__
        struct pci_controller *hose;
 #endif
-       drm_sg_mem_t      *sg;  /**< Scatter gather memory */
-       unsigned long     *ctx_bitmap;  /**< context bitmap */
-       void              *dev_private; /**< device private data */
-       drm_sigdata_t     sigdata; /**< For block_all_signals */
-       sigset_t          sigmask;
-
-       struct            drm_driver *driver;
-       drm_local_map_t   *agp_buffer_map;
+       drm_sg_mem_t *sg;       /**< Scatter gather memory */
+       unsigned long *ctx_bitmap;      /**< context bitmap */
+       void *dev_private;              /**< device private data */
+       drm_sigdata_t sigdata;     /**< For block_all_signals */
+       sigset_t sigmask;
+
+       struct drm_driver *driver;
+       drm_local_map_t *agp_buffer_map;
        unsigned int agp_buffer_token;
        drm_head_t primary;             /**< primary screen head */
 } drm_device_t;
 
-static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature)
+static __inline__ int drm_core_check_feature(struct drm_device *dev,
+                                            int feature)
 {
        return ((dev->driver->driver_features & feature) ? 1 : 0);
 }
@@ -738,7 +741,7 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature
 #if __OS_HAS_AGP
 static inline int drm_core_has_AGP(struct drm_device *dev)
 {
-  return drm_core_check_feature(dev, DRIVER_USE_AGP);
+       return drm_core_check_feature(dev, DRIVER_USE_AGP);
 }
 #else
 #define drm_core_has_AGP(dev) (0)
@@ -747,7 +750,7 @@ static inline int drm_core_has_AGP(struct drm_device *dev)
 #if __OS_HAS_MTRR
 static inline int drm_core_has_MTRR(struct drm_device *dev)
 {
-  return drm_core_check_feature(dev, DRIVER_USE_MTRR);
+       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
 }
 #else
 #define drm_core_has_MTRR(dev) (0)
@@ -758,234 +761,229 @@ static inline int drm_core_has_MTRR(struct drm_device *dev)
 /*@{*/
 
                                /* Misc. support (drm_init.h) */
-extern int          drm_flags;
-extern void         drm_parse_options( char *s );
-extern int           drm_cpu_valid( void );
+extern int drm_flags;
+extern void drm_parse_options(char *s);
+extern int drm_cpu_valid(void);
 
                                /* Driver support (drm_drv.h) */
-extern int           drm_init(struct drm_driver *driver);
-extern void          drm_exit(struct drm_driver *driver);
-extern int           drm_ioctl(struct inode *inode, struct file *filp,
-                               unsigned int cmd, unsigned long arg);
-extern long         drm_compat_ioctl(struct file *filp,
-                               unsigned int cmd, unsigned long arg);
-extern int           drm_takedown(drm_device_t * dev);
+extern int drm_init(struct drm_driver *driver);
+extern void drm_exit(struct drm_driver *driver);
+extern int drm_ioctl(struct inode *inode, struct file *filp,
+                    unsigned int cmd, unsigned long arg);
+extern long drm_compat_ioctl(struct file *filp,
+                            unsigned int cmd, unsigned long arg);
+extern int drm_takedown(drm_device_t * dev);
 
                                /* Device support (drm_fops.h) */
-extern int           drm_open(struct inode *inode, struct file *filp);
-extern int           drm_stub_open(struct inode *inode, struct file *filp);
-extern int          drm_flush(struct file *filp);
-extern int          drm_fasync(int fd, struct file *filp, int on);
-extern int           drm_release(struct inode *inode, struct file *filp);
+extern int drm_open(struct inode *inode, struct file *filp);
+extern int drm_stub_open(struct inode *inode, struct file *filp);
+extern int drm_flush(struct file *filp);
+extern int drm_fasync(int fd, struct file *filp, int on);
+extern int drm_release(struct inode *inode, struct file *filp);
 
                                /* Mapping support (drm_vm.h) */
-extern int          drm_mmap(struct file *filp, struct vm_area_struct *vma);
-extern unsigned int  drm_poll(struct file *filp, struct poll_table_struct *wait);
+extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
+extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
 
                                /* Memory management support (drm_memory.h) */
 #include "drm_memory.h"
-extern void         drm_mem_init(void);
-extern int          drm_mem_info(char *buf, char **start, off_t offset,
-                                  int request, int *eof, void *data);
-extern void         *drm_realloc(void *oldpt, size_t oldsize, size_t size,
-                                  int area);
+extern void drm_mem_init(void);
+extern int drm_mem_info(char *buf, char **start, off_t offset,
+                       int request, int *eof, void *data);
+extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
 extern unsigned long drm_alloc_pages(int order, int area);
-extern void         drm_free_pages(unsigned long address, int order,
-                                    int area);
-extern void         *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev);
-extern void         *drm_ioremap_nocache(unsigned long offset, unsigned long size,
-                                          drm_device_t *dev);
-extern void         drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev);
-
-extern DRM_AGP_MEM   *drm_alloc_agp(drm_device_t *dev, int pages, u32 type);
-extern int           drm_free_agp(DRM_AGP_MEM *handle, int pages);
-extern int           drm_bind_agp(DRM_AGP_MEM *handle, unsigned int start);
-extern int           drm_unbind_agp(DRM_AGP_MEM *handle);
+extern void drm_free_pages(unsigned long address, int order, int area);
+extern void *drm_ioremap(unsigned long offset, unsigned long size,
+                        drm_device_t * dev);
+extern void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
+                                drm_device_t * dev);
+extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
+
+extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
+extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
+extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
+extern int drm_unbind_agp(DRM_AGP_MEM * handle);
 
                                /* Misc. IOCTL support (drm_ioctl.h) */
-extern int          drm_irq_by_busid(struct inode *inode, struct file *filp,
-                                      unsigned int cmd, unsigned long arg);
-extern int          drm_getunique(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern int          drm_setunique(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern int          drm_getmap(struct inode *inode, struct file *filp,
-                                unsigned int cmd, unsigned long arg);
-extern int          drm_getclient(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern int          drm_getstats(struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg);
-extern int          drm_setversion(struct inode *inode, struct file *filp,
-                                    unsigned int cmd, unsigned long arg);
+extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
+                           unsigned int cmd, unsigned long arg);
+extern int drm_getunique(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
+extern int drm_setunique(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
+extern int drm_getmap(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_getclient(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
+extern int drm_getstats(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_setversion(struct inode *inode, struct file *filp,
+                         unsigned int cmd, unsigned long arg);
 
                                /* Context IOCTL support (drm_context.h) */
-extern int          drm_resctx( struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg );
-extern int          drm_addctx( struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg );
-extern int          drm_modctx( struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg );
-extern int          drm_getctx( struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg );
-extern int          drm_switchctx( struct inode *inode, struct file *filp,
-                                    unsigned int cmd, unsigned long arg );
-extern int          drm_newctx( struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg );
-extern int          drm_rmctx( struct inode *inode, struct file *filp,
-                                unsigned int cmd, unsigned long arg );
-
-extern int          drm_ctxbitmap_init( drm_device_t *dev );
-extern void         drm_ctxbitmap_cleanup( drm_device_t *dev );
-extern void          drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle );
-
-extern int          drm_setsareactx( struct inode *inode, struct file *filp,
-                                      unsigned int cmd, unsigned long arg );
-extern int          drm_getsareactx( struct inode *inode, struct file *filp,
-                                      unsigned int cmd, unsigned long arg );
+extern int drm_resctx(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_addctx(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_modctx(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_getctx(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_switchctx(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
+extern int drm_newctx(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_rmctx(struct inode *inode, struct file *filp,
+                    unsigned int cmd, unsigned long arg);
+
+extern int drm_ctxbitmap_init(drm_device_t * dev);
+extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
+extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
+
+extern int drm_setsareactx(struct inode *inode, struct file *filp,
+                          unsigned int cmd, unsigned long arg);
+extern int drm_getsareactx(struct inode *inode, struct file *filp,
+                          unsigned int cmd, unsigned long arg);
 
                                /* Drawable IOCTL support (drm_drawable.h) */
-extern int          drm_adddraw(struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg);
-extern int          drm_rmdraw(struct inode *inode, struct file *filp,
-                                unsigned int cmd, unsigned long arg);
-
+extern int drm_adddraw(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg);
+extern int drm_rmdraw(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
 
                                /* Authentication IOCTL support (drm_auth.h) */
-extern int          drm_getmagic(struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg);
-extern int          drm_authmagic(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
+extern int drm_getmagic(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_authmagic(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
 
-                                /* Placeholder for ioctls past */
-extern int          drm_noop(struct inode *inode, struct file *filp,
-                                 unsigned int cmd, unsigned long arg);
+                               /* Placeholder for ioctls past */
+extern int drm_noop(struct inode *inode, struct file *filp,
+                   unsigned int cmd, unsigned long arg);
 
                                /* Locking IOCTL support (drm_lock.h) */
-extern int           drm_lock(struct inode *inode, struct file *filp,
-                              unsigned int cmd, unsigned long arg);
-extern int           drm_unlock(struct inode *inode, struct file *filp,
-                                unsigned int cmd, unsigned long arg);
-extern int          drm_lock_take(__volatile__ unsigned int *lock,
-                                   unsigned int context);
-extern int          drm_lock_free(drm_device_t *dev,
-                                   __volatile__ unsigned int *lock,
-                                   unsigned int context);
+extern int drm_lock(struct inode *inode, struct file *filp,
+                   unsigned int cmd, unsigned long arg);
+extern int drm_unlock(struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);
+extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
+extern int drm_lock_free(drm_device_t * dev,
+                        __volatile__ unsigned int *lock, unsigned int context);
 
                                /* Buffer management support (drm_bufs.h) */
-extern int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
-extern int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
-extern int drm_addmap(drm_device_t *dev, unsigned int offset,
+extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
+extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
+extern int drm_addmap(drm_device_t * dev, unsigned int offset,
                      unsigned int size, drm_map_type_t type,
-                     drm_map_flags_t flags, drm_local_map_t **map_ptr);
+                     drm_map_flags_t flags, drm_local_map_t ** map_ptr);
 extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
                            unsigned int cmd, unsigned long arg);
-extern int drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
-extern int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map);
+extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
+extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
 extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
                           unsigned int cmd, unsigned long arg);
 
-extern int          drm_order( unsigned long size );
-extern int          drm_addbufs( struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg );
-extern int          drm_infobufs( struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg );
-extern int          drm_markbufs( struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg );
-extern int          drm_freebufs( struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg );
-extern int          drm_mapbufs( struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg );
-extern unsigned long drm_get_resource_start(drm_device_t *dev,
+extern int drm_order(unsigned long size);
+extern int drm_addbufs(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg);
+extern int drm_infobufs(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_markbufs(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_freebufs(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_mapbufs(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg);
+extern unsigned long drm_get_resource_start(drm_device_t * dev,
                                            unsigned int resource);
-extern unsigned long drm_get_resource_len(drm_device_t *dev,
+extern unsigned long drm_get_resource_len(drm_device_t * dev,
                                          unsigned int resource);
 
                                /* DMA support (drm_dma.h) */
-extern int          drm_dma_setup(drm_device_t *dev);
-extern void         drm_dma_takedown(drm_device_t *dev);
-extern void         drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
-extern void         drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
+extern int drm_dma_setup(drm_device_t * dev);
+extern void drm_dma_takedown(drm_device_t * dev);
+extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
+extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
 
                                /* IRQ support (drm_irq.h) */
-extern int           drm_control( struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg );
-extern int           drm_irq_uninstall( drm_device_t *dev );
-extern irqreturn_t   drm_irq_handler( DRM_IRQ_ARGS );
-extern void          drm_driver_irq_preinstall( drm_device_t *dev );
-extern void          drm_driver_irq_postinstall( drm_device_t *dev );
-extern void          drm_driver_irq_uninstall( drm_device_t *dev );
-
-extern int           drm_wait_vblank(struct inode *inode, struct file *filp,
-                                     unsigned int cmd, unsigned long arg);
-extern int           drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
-extern void          drm_vbl_send_signals( drm_device_t *dev );
+extern int drm_control(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg);
+extern int drm_irq_uninstall(drm_device_t * dev);
+extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
+extern void drm_driver_irq_preinstall(drm_device_t * dev);
+extern void drm_driver_irq_postinstall(drm_device_t * dev);
+extern void drm_driver_irq_uninstall(drm_device_t * dev);
+
+extern int drm_wait_vblank(struct inode *inode, struct file *filp,
+                          unsigned int cmd, unsigned long arg);
+extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
+extern void drm_vbl_send_signals(drm_device_t * dev);
 
                                /* AGP/GART support (drm_agpsupport.h) */
-extern drm_agp_head_t *drm_agp_init(drm_device_t *dev);
+extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
 extern int drm_agp_acquire(drm_device_t * dev);
 extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
-                          unsigned int cmd, unsigned long arg);
-extern int drm_agp_release(drm_device_t *dev);
+                                unsigned int cmd, unsigned long arg);
+extern int drm_agp_release(drm_device_t * dev);
 extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
-                          unsigned int cmd, unsigned long arg);
-extern int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
+                                unsigned int cmd, unsigned long arg);
+extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
 extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
-                         unsigned int cmd, unsigned long arg);
-extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
+                               unsigned int cmd, unsigned long arg);
+extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
 extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
+                             unsigned int cmd, unsigned long arg);
+extern int drm_agp_alloc(struct inode *inode, struct file *filp,
+                        unsigned int cmd, unsigned long arg);
+extern int drm_agp_free(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_agp_unbind(struct inode *inode, struct file *filp,
+                         unsigned int cmd, unsigned long arg);
+extern int drm_agp_bind(struct inode *inode, struct file *filp,
                        unsigned int cmd, unsigned long arg);
-extern int            drm_agp_alloc(struct inode *inode, struct file *filp,
-                                    unsigned int cmd, unsigned long arg);
-extern int            drm_agp_free(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern int            drm_agp_unbind(struct inode *inode, struct file *filp,
-                                     unsigned int cmd, unsigned long arg);
-extern int            drm_agp_bind(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern DRM_AGP_MEM    *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
-extern int            drm_agp_free_memory(DRM_AGP_MEM *handle);
-extern int            drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start);
-extern int            drm_agp_unbind_memory(DRM_AGP_MEM *handle);
+extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
+                                           size_t pages, u32 type);
+extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
+extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
+extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
 
                                /* Stub support (drm_stub.h) */
 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
-                    struct drm_driver *driver);
+                      struct drm_driver *driver);
 extern int drm_put_dev(drm_device_t * dev);
 extern int drm_put_head(drm_head_t * head);
-extern unsigned int   drm_debug;
-extern unsigned int   drm_cards_limit;
+extern unsigned int drm_debug;
+extern unsigned int drm_cards_limit;
 extern drm_head_t **drm_heads;
 extern struct drm_sysfs_class *drm_class;
 extern struct proc_dir_entry *drm_proc_root;
 
                                /* Proc support (drm_proc.h) */
-extern int            drm_proc_init(drm_device_t *dev,
-                                            int minor,
-                                            struct proc_dir_entry *root,
-                                            struct proc_dir_entry **dev_root);
-extern int            drm_proc_cleanup(int minor,
-                                       struct proc_dir_entry *root,
-                                       struct proc_dir_entry *dev_root);
+extern int drm_proc_init(drm_device_t * dev,
+                        int minor,
+                        struct proc_dir_entry *root,
+                        struct proc_dir_entry **dev_root);
+extern int drm_proc_cleanup(int minor,
+                           struct proc_dir_entry *root,
+                           struct proc_dir_entry *dev_root);
 
                                /* Scatter Gather Support (drm_scatter.h) */
-extern void           drm_sg_cleanup(drm_sg_mem_t *entry);
-extern int            drm_sg_alloc(struct inode *inode, struct file *filp,
-                                   unsigned int cmd, unsigned long arg);
-extern int            drm_sg_free(struct inode *inode, struct file *filp,
-                                  unsigned int cmd, unsigned long arg);
-
-                               /* ATI PCIGART support (ati_pcigart.h) */
-extern int            drm_ati_pcigart_init(drm_device_t *dev,
-                                           unsigned long *addr,
-                                           dma_addr_t *bus_addr);
-extern int            drm_ati_pcigart_cleanup(drm_device_t *dev,
-                                              unsigned long addr,
-                                              dma_addr_t bus_addr);
-
-extern drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size,
+extern void drm_sg_cleanup(drm_sg_mem_t * entry);
+extern int drm_sg_alloc(struct inode *inode, struct file *filp,
+                       unsigned int cmd, unsigned long arg);
+extern int drm_sg_free(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg);
+
+                              /* ATI PCIGART support (ati_pcigart.h) */
+extern int drm_ati_pcigart_init(drm_device_t * dev,
+                               drm_ati_pcigart_info * gart_info);
+extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
+                                  drm_ati_pcigart_info * gart_info);
+
+extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
                                       size_t align, dma_addr_t maxaddr);
-extern void __drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
-extern void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
+extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
+extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
 
                               /* sysfs support (drm_sysfs.c) */
 struct drm_sysfs_class;
@@ -998,38 +996,41 @@ extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
                                                 const char *fmt, ...);
 extern void drm_sysfs_device_remove(dev_t dev);
 
-
 /* Inline replacements for DRM_IOREMAP macros */
-static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremap(struct drm_map *map,
+                                       struct drm_device *dev)
 {
-       map->handle = drm_ioremap( map->offset, map->size, dev );
+       map->handle = drm_ioremap(map->offset, map->size, dev);
 }
 
-static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
+                                               struct drm_device *dev)
 {
        map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
 }
 
-static __inline__ void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
+static __inline__ void drm_core_ioremapfree(struct drm_map *map,
+                                           struct drm_device *dev)
 {
-       if ( map->handle && map->size )
-               drm_ioremapfree( map->handle, map->size, dev );
+       if (map->handle && map->size)
+               drm_ioremapfree(map->handle, map->size, dev);
 }
 
-static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsigned int token)
+static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
+                                                  unsigned int token)
 {
        drm_map_list_t *_entry;
        list_for_each_entry(_entry, &dev->maplist->head, head)
-               if (_entry->user_token == token)
-                       return _entry->map;
+           if (_entry->user_token == token)
+               return _entry->map;
        return NULL;
 }
 
-static __inline__ int drm_device_is_agp(drm_device_t *dev)
+static __inline__ int drm_device_is_agp(drm_device_t * dev)
 {
-       if ( dev->driver->device_is_agp != NULL ) {
-               int err = (*dev->driver->device_is_agp)( dev );
-       
+       if (dev->driver->device_is_agp != NULL) {
+               int err = (*dev->driver->device_is_agp) (dev);
+
                if (err != 2) {
                        return err;
                }
@@ -1038,6 +1039,11 @@ static __inline__ int drm_device_is_agp(drm_device_t *dev)
        return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
 }
 
+static __inline__ int drm_device_is_pcie(drm_device_t * dev)
+{
+       return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
+}
+
 static __inline__ void drm_core_dropmap(struct drm_map *map)
 {
 }
@@ -1068,12 +1074,12 @@ extern void *drm_calloc(size_t nmemb, size_t size, int area);
 
 /*@}*/
 
-extern unsigned long drm_core_get_map_ofs(drm_map_t *map);
+extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
 
 #ifndef pci_pretty_name
 #define pci_pretty_name(dev) ""
 #endif
 
-#endif /* __KERNEL__ */
+#endif                         /* __KERNEL__ */
 #endif
index 8c215adcb4b2b623e4848b50fba212a66956799a..2b6453a9ffce6e20c5a932f7ed00895acd8375d1 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drm_agpsupport.h 
+ * \file drm_agpsupport.h
  * DRM support for AGP/GART backend
- *    
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  * Verifies the AGP device has been initialized and acquired and fills in the
  * drm_agp_info structure with the information in drm_agp_head::agp_info.
  */
-int drm_agp_info(drm_device_t *dev, drm_agp_info_t *info)
+int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info)
 {
-       DRM_AGP_KERN     *kern;
+       DRM_AGP_KERN *kern;
 
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
 
-       kern                   = &dev->agp->agp_info;
+       kern = &dev->agp->agp_info;
        info->agp_version_major = kern->version.major;
        info->agp_version_minor = kern->version.minor;
-       info->mode              = kern->mode;
-       info->aperture_base     = kern->aper_base;
-       info->aperture_size     = kern->aper_size * 1024 * 1024;
-       info->memory_allowed    = kern->max_memory << PAGE_SHIFT;
-       info->memory_used       = kern->current_memory << PAGE_SHIFT;
-       info->id_vendor         = kern->device->vendor;
-       info->id_device         = kern->device->device;
+       info->mode = kern->mode;
+       info->aperture_base = kern->aper_base;
+       info->aperture_size = kern->aper_size * 1024 * 1024;
+       info->memory_allowed = kern->max_memory << PAGE_SHIFT;
+       info->memory_used = kern->current_memory << PAGE_SHIFT;
+       info->id_vendor = kern->device->vendor;
+       info->id_device = kern->device->device;
 
        return 0;
 }
+
 EXPORT_SYMBOL(drm_agp_info);
 
 int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg)
+                      unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -81,7 +82,7 @@ int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
        err = drm_agp_info(dev, &info);
        if (err)
                return err;
-       
+
        if (copy_to_user((drm_agp_info_t __user *) arg, &info, sizeof(info)))
                return -EFAULT;
        return 0;
@@ -91,12 +92,12 @@ int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  * Acquire the AGP device.
  *
  * \param dev DRM device that is to acquire AGP
- * \return zero on success or a negative number on failure. 
+ * \return zero on success or a negative number on failure.
  *
  * Verifies the AGP device hasn't been acquired before and calls
  * \c agp_backend_acquire.
  */
-int drm_agp_acquire(drm_device_t *dev)
+int drm_agp_acquire(drm_device_t * dev)
 {
        if (!dev->agp)
                return -ENODEV;
@@ -107,6 +108,7 @@ int drm_agp_acquire(drm_device_t *dev)
        dev->agp->acquired = 1;
        return 0;
 }
+
 EXPORT_SYMBOL(drm_agp_acquire);
 
 /**
@@ -125,8 +127,8 @@ int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
                          unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
-       
-       return drm_agp_acquire( (drm_device_t *) priv->head->dev );
+
+       return drm_agp_acquire((drm_device_t *) priv->head->dev);
 }
 
 /**
@@ -137,7 +139,7 @@ int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  *
  * Verifies the AGP device has been acquired and calls \c agp_backend_release.
  */
-int drm_agp_release(drm_device_t *dev)
+int drm_agp_release(drm_device_t * dev)
 {
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
@@ -145,6 +147,7 @@ int drm_agp_release(drm_device_t *dev)
        dev->agp->acquired = 0;
        return 0;
 }
+
 EXPORT_SYMBOL(drm_agp_release);
 
 int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
@@ -152,13 +155,13 @@ int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
-       
+
        return drm_agp_release(dev);
 }
 
 /**
  * Enable the AGP bus.
- * 
+ *
  * \param dev DRM device that has previously acquired AGP.
  * \param mode Requested AGP mode.
  * \return zero on success or a negative number on failure.
@@ -166,27 +169,27 @@ int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  * Verifies the AGP device has been acquired but not enabled, and calls
  * \c agp_enable.
  */
-int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
+int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode)
 {
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
 
-       dev->agp->mode    = mode.mode;
+       dev->agp->mode = mode.mode;
        agp_enable(dev->agp->bridge, mode.mode);
-       dev->agp->base    = dev->agp->agp_info.aper_base;
+       dev->agp->base = dev->agp->agp_info.aper_base;
        dev->agp->enabled = 1;
        return 0;
 }
+
 EXPORT_SYMBOL(drm_agp_enable);
 
 int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg)
+                        unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
        drm_agp_mode_t mode;
 
-
        if (copy_from_user(&mode, (drm_agp_mode_t __user *) arg, sizeof(mode)))
                return -EFAULT;
 
@@ -201,20 +204,20 @@ int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  * \param cmd command.
  * \param arg pointer to a drm_agp_buffer structure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Verifies the AGP device is present and has been acquired, allocates the
  * memory via alloc_agp() and creates a drm_agp_mem entry for it.
  */
 int drm_agp_alloc(struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg)
+                 unsigned int cmd, unsigned long arg)
 {
-       drm_file_t       *priv   = filp->private_data;
-       drm_device_t     *dev    = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_agp_buffer_t request;
-       drm_agp_mem_t    *entry;
-       DRM_AGP_MEM      *memory;
-       unsigned long    pages;
-       u32              type;
+       drm_agp_mem_t *entry;
+       DRM_AGP_MEM *memory;
+       unsigned long pages;
+       u32 type;
        drm_agp_buffer_t __user *argp = (void __user *)arg;
 
        if (!dev->agp || !dev->agp->acquired)
@@ -224,7 +227,7 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
        if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
                return -ENOMEM;
 
-       memset(entry, 0, sizeof(*entry));
+       memset(entry, 0, sizeof(*entry));
 
        pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
        type = (u32) request.type;
@@ -234,21 +237,21 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
                return -ENOMEM;
        }
 
-       entry->handle    = (unsigned long)memory->key + 1;
-       entry->memory    = memory;
-       entry->bound     = 0;
-       entry->pages     = pages;
-       entry->prev      = NULL;
-       entry->next      = dev->agp->memory;
+       entry->handle = (unsigned long)memory->key + 1;
+       entry->memory = memory;
+       entry->bound = 0;
+       entry->pages = pages;
+       entry->prev = NULL;
+       entry->next = dev->agp->memory;
        if (dev->agp->memory)
                dev->agp->memory->prev = entry;
        dev->agp->memory = entry;
 
-       request.handle   = entry->handle;
+       request.handle = entry->handle;
        request.physical = memory->physical;
 
        if (copy_to_user(argp, &request, sizeof(request))) {
-               dev->agp->memory       = entry->next;
+               dev->agp->memory = entry->next;
                dev->agp->memory->prev = NULL;
                drm_free_agp(memory, pages);
                drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
@@ -263,11 +266,11 @@ int drm_agp_alloc(struct inode *inode, struct file *filp,
  * \param dev DRM device structure.
  * \param handle AGP memory handle.
  * \return pointer to the drm_agp_mem structure associated with \p handle.
- * 
+ *
  * Walks through drm_agp_head::memory until finding a matching handle.
  */
-static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
-                                           unsigned long handle)
+static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t * dev,
+                                          unsigned long handle)
 {
        drm_agp_mem_t *entry;
 
@@ -291,17 +294,18 @@ static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
  * entry and passes it to the unbind_agp() function.
  */
 int drm_agp_unbind(struct inode *inode, struct file *filp,
-                   unsigned int cmd, unsigned long arg)
+                  unsigned int cmd, unsigned long arg)
 {
-       drm_file_t        *priv  = filp->private_data;
-       drm_device_t      *dev   = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_agp_binding_t request;
-       drm_agp_mem_t     *entry;
+       drm_agp_mem_t *entry;
        int ret;
 
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
-       if (copy_from_user(&request, (drm_agp_binding_t __user *)arg, sizeof(request)))
+       if (copy_from_user
+           (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
                return -EFAULT;
        if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
                return -EINVAL;
@@ -309,7 +313,7 @@ int drm_agp_unbind(struct inode *inode, struct file *filp,
                return -EINVAL;
        ret = drm_unbind_agp(entry->memory);
        if (ret == 0)
-           entry->bound = 0;
+               entry->bound = 0;
        return ret;
 }
 
@@ -327,18 +331,19 @@ int drm_agp_unbind(struct inode *inode, struct file *filp,
  * it to bind_agp() function.
  */
 int drm_agp_bind(struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg)
+                unsigned int cmd, unsigned long arg)
 {
-       drm_file_t        *priv  = filp->private_data;
-       drm_device_t      *dev   = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_agp_binding_t request;
-       drm_agp_mem_t     *entry;
-       int               retcode;
-       int               page;
+       drm_agp_mem_t *entry;
+       int retcode;
+       int page;
 
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
-       if (copy_from_user(&request, (drm_agp_binding_t __user *)arg, sizeof(request)))
+       if (copy_from_user
+           (&request, (drm_agp_binding_t __user *) arg, sizeof(request)))
                return -EFAULT;
        if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
                return -EINVAL;
@@ -368,16 +373,17 @@ int drm_agp_bind(struct inode *inode, struct file *filp,
  * and unlinks from the doubly linked list it's inserted in.
  */
 int drm_agp_free(struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg)
+                unsigned int cmd, unsigned long arg)
 {
-       drm_file_t       *priv   = filp->private_data;
-       drm_device_t     *dev    = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_agp_buffer_t request;
-       drm_agp_mem_t    *entry;
+       drm_agp_mem_t *entry;
 
        if (!dev->agp || !dev->agp->acquired)
                return -EINVAL;
-       if (copy_from_user(&request, (drm_agp_buffer_t __user *)arg, sizeof(request)))
+       if (copy_from_user
+           (&request, (drm_agp_buffer_t __user *) arg, sizeof(request)))
                return -EFAULT;
        if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
                return -EINVAL;
@@ -403,9 +409,9 @@ int drm_agp_free(struct inode *inode, struct file *filp,
  * \return pointer to a drm_agp_head structure.
  *
  */
-drm_agp_head_t *drm_agp_init(drm_device_t *dev)
+drm_agp_head_t *drm_agp_init(drm_device_t * dev)
 {
-       drm_agp_head_t *head         = NULL;
+       drm_agp_head_t *head = NULL;
 
        if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
                return NULL;
@@ -433,13 +439,14 @@ drm_agp_head_t *drm_agp_init(drm_device_t *dev)
 }
 
 /** Calls agp_allocate_memory() */
-DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type)
+DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
+                                    size_t pages, u32 type)
 {
        return agp_allocate_memory(bridge, pages, type);
 }
 
 /** Calls agp_free_memory() */
-int drm_agp_free_memory(DRM_AGP_MEM *handle)
+int drm_agp_free_memory(DRM_AGP_MEM * handle)
 {
        if (!handle)
                return 0;
@@ -448,20 +455,21 @@ int drm_agp_free_memory(DRM_AGP_MEM *handle)
 }
 
 /** Calls agp_bind_memory() */
-int drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start)
+int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
 {
        if (!handle)
                return -EINVAL;
        return agp_bind_memory(handle, start);
 }
+
 EXPORT_SYMBOL(drm_agp_bind_memory);
 
 /** Calls agp_unbind_memory() */
-int drm_agp_unbind_memory(DRM_AGP_MEM *handle)
+int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
 {
        if (!handle)
                return -EINVAL;
        return agp_unbind_memory(handle);
 }
 
-#endif /* __OS_HAS_AGP */
+#endif                         /* __OS_HAS_AGP */
index dd140bca8f71d5b3c5fedbc2d74f1c33187780ed..a47b502bc7cc8fdcefa19688fbe9c16e7eaf3525 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file drm_auth.
+ * \file drm_auth.c
  * IOCTLs for authentication
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -46,7 +46,7 @@
  */
 static int drm_hash_magic(drm_magic_t magic)
 {
-       return magic & (DRM_HASH_SIZE-1);
+       return magic & (DRM_HASH_SIZE - 1);
 }
 
 /**
@@ -59,11 +59,11 @@ static int drm_hash_magic(drm_magic_t magic)
  * the one with matching magic number, while holding the drm_device::struct_sem
  * lock.
  */
-static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
+static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
 {
-       drm_file_t        *retval = NULL;
+       drm_file_t *retval = NULL;
        drm_magic_entry_t *pt;
-       int               hash    = drm_hash_magic(magic);
+       int hash = drm_hash_magic(magic);
 
        down(&dev->struct_sem);
        for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
@@ -78,7 +78,7 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
 
 /**
  * Adds a magic number.
- * 
+ *
  * \param dev DRM device.
  * \param priv file private data.
  * \param magic magic number.
@@ -87,28 +87,30 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
  * associated the magic number hash key in drm_device::magiclist, while holding
  * the drm_device::struct_sem lock.
  */
-static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
+static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
+                        drm_magic_t magic)
 {
-       int               hash;
+       int hash;
        drm_magic_entry_t *entry;
 
        DRM_DEBUG("%d\n", magic);
 
-       hash         = drm_hash_magic(magic);
-       entry        = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
-       if (!entry) return -ENOMEM;
+       hash = drm_hash_magic(magic);
+       entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
+       if (!entry)
+               return -ENOMEM;
        memset(entry, 0, sizeof(*entry));
        entry->magic = magic;
-       entry->priv  = priv;
-       entry->next  = NULL;
+       entry->priv = priv;
+       entry->next = NULL;
 
        down(&dev->struct_sem);
        if (dev->magiclist[hash].tail) {
                dev->magiclist[hash].tail->next = entry;
-               dev->magiclist[hash].tail       = entry;
+               dev->magiclist[hash].tail = entry;
        } else {
-               dev->magiclist[hash].head       = entry;
-               dev->magiclist[hash].tail       = entry;
+               dev->magiclist[hash].head = entry;
+               dev->magiclist[hash].tail = entry;
        }
        up(&dev->struct_sem);
 
@@ -117,19 +119,18 @@ static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
 
 /**
  * Remove a magic number.
- * 
+ *
  * \param dev DRM device.
  * \param magic magic number.
  *
  * Searches and unlinks the entry in drm_device::magiclist with the magic
  * number hash key, while holding the drm_device::struct_sem lock.
  */
-static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
+static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic)
 {
        drm_magic_entry_t *prev = NULL;
        drm_magic_entry_t *pt;
-       int               hash;
-
+       int hash;
 
        DRM_DEBUG("%d\n", magic);
        hash = drm_hash_magic(magic);
@@ -171,21 +172,22 @@ static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
  * filp.
  */
 int drm_getmagic(struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg)
+                unsigned int cmd, unsigned long arg)
 {
        static drm_magic_t sequence = 0;
        static DEFINE_SPINLOCK(lock);
-       drm_file_t         *priv    = filp->private_data;
-       drm_device_t       *dev     = priv->head->dev;
-       drm_auth_t         auth;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
+       drm_auth_t auth;
 
-                               /* Find unique magic */
+       /* Find unique magic */
        if (priv->magic) {
                auth.magic = priv->magic;
        } else {
                do {
                        spin_lock(&lock);
-                       if (!sequence) ++sequence; /* reserve 0 */
+                       if (!sequence)
+                               ++sequence;     /* reserve 0 */
                        auth.magic = sequence++;
                        spin_unlock(&lock);
                } while (drm_find_file(dev, auth.magic));
@@ -194,7 +196,7 @@ int drm_getmagic(struct inode *inode, struct file *filp,
        }
 
        DRM_DEBUG("%u\n", auth.magic);
-       if (copy_to_user((drm_auth_t __user *)arg, &auth, sizeof(auth)))
+       if (copy_to_user((drm_auth_t __user *) arg, &auth, sizeof(auth)))
                return -EFAULT;
        return 0;
 }
@@ -211,14 +213,14 @@ int drm_getmagic(struct inode *inode, struct file *filp,
  * Checks if \p filp is associated with the magic number passed in \arg.
  */
 int drm_authmagic(struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg)
+                 unsigned int cmd, unsigned long arg)
 {
-       drm_file_t         *priv    = filp->private_data;
-       drm_device_t       *dev     = priv->head->dev;
-       drm_auth_t         auth;
-       drm_file_t         *file;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
+       drm_auth_t auth;
+       drm_file_t *file;
 
-       if (copy_from_user(&auth, (drm_auth_t __user *)arg, sizeof(auth)))
+       if (copy_from_user(&auth, (drm_auth_t __user *) arg, sizeof(auth)))
                return -EFAULT;
        DRM_DEBUG("%u\n", auth.magic);
        if ((file = drm_find_file(dev, auth.magic))) {
index f28e70ae66065d4a498760af053d1ea5fa0b6a99..319bdea8de8a63c7db21caa72ac1481e3f1330bb 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drm_bufs.
+ * \file drm_bufs.c
  * Generic buffer template
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
 #include <linux/vmalloc.h>
 #include "drmP.h"
 
-unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_start(drm_device_t * dev, unsigned int resource)
 {
        return pci_resource_start(dev->pdev, resource);
 }
+
 EXPORT_SYMBOL(drm_get_resource_start);
 
-unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
+unsigned long drm_get_resource_len(drm_device_t * dev, unsigned int resource)
 {
        return pci_resource_len(dev->pdev, resource);
 }
+
 EXPORT_SYMBOL(drm_get_resource_len);
 
-static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
-                                            drm_local_map_t *map)
+static drm_map_list_t *drm_find_matching_map(drm_device_t * dev,
+                                            drm_local_map_t * map)
 {
        struct list_head *list;
 
@@ -71,7 +73,8 @@ static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
 #define END_RANGE 0x40000000
 
 #ifdef _LP64
-static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev) 
+static __inline__ unsigned int HandleID(unsigned long lhandle,
+                                       drm_device_t * dev)
 {
        static unsigned int map32_handle = START_RANGE;
        unsigned int hash;
@@ -81,12 +84,12 @@ static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev
                map32_handle += PAGE_SIZE;
                if (map32_handle > END_RANGE)
                        map32_handle = START_RANGE;
-       } else 
+       } else
                hash = lhandle;
 
        while (1) {
                drm_map_list_t *_entry;
-               list_for_each_entry(_entry, &dev->maplist->head,head) {
+               list_for_each_entry(_entry, &dev->maplist->head, head) {
                        if (_entry->user_token == hash)
                                break;
                }
@@ -114,16 +117,16 @@ static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev
  * type.  Adds the map to the map list drm_device::maplist. Adds MTRR's where
  * applicable and if supported by the kernel.
  */
-int drm_addmap_core(drm_device_t * dev, unsigned int offset,
-                   unsigned int size, drm_map_type_t type,
-                   drm_map_flags_t flags, drm_map_list_t **maplist)
+static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
+                          unsigned int size, drm_map_type_t type,
+                          drm_map_flags_t flags, drm_map_list_t ** maplist)
 {
        drm_map_t *map;
        drm_map_list_t *list;
        drm_dma_handle_t *dmah;
 
-       map = drm_alloc( sizeof(*map), DRM_MEM_MAPS );
-       if ( !map )
+       map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
+       if (!map)
                return -ENOMEM;
 
        map->offset = offset;
@@ -135,26 +138,26 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
         * book keeping information about shared memory to allow for removal
         * when processes fork.
         */
-       if ( (map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM ) {
-               drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+       if ((map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM) {
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                return -EINVAL;
        }
-       DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n",
-                  map->offset, map->size, map->type );
-       if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) {
-               drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+       DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
+                 map->offset, map->size, map->type);
+       if ((map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK))) {
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                return -EINVAL;
        }
-       map->mtrr   = -1;
+       map->mtrr = -1;
        map->handle = NULL;
 
-       switch ( map->type ) {
+       switch (map->type) {
        case _DRM_REGISTERS:
        case _DRM_FRAME_BUFFER:
 #if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && !defined(__powerpc64__) && !defined(__x86_64__)
-               if ( map->offset + map->size < map->offset ||
-                    map->offset < virt_to_phys(high_memory) ) {
-                       drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+               if (map->offset + map->size < map->offset ||
+                   map->offset < virt_to_phys(high_memory)) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                        return -EINVAL;
                }
 #endif
@@ -169,8 +172,9 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
                if (list != NULL) {
                        if (list->map->size != map->size) {
                                DRM_DEBUG("Matching maps of type %d with "
-                                  "mismatched sizes, (%ld vs %ld)\n",
-                                   map->type, map->size, list->map->size);
+                                         "mismatched sizes, (%ld vs %ld)\n",
+                                         map->type, map->size,
+                                         list->map->size);
                                list->map->size = map->size;
                        }
 
@@ -180,35 +184,33 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
                }
 
                if (drm_core_has_MTRR(dev)) {
-                       if ( map->type == _DRM_FRAME_BUFFER ||
-                            (map->flags & _DRM_WRITE_COMBINING) ) {
-                               map->mtrr = mtrr_add( map->offset, map->size,
-                                                     MTRR_TYPE_WRCOMB, 1 );
+                       if (map->type == _DRM_FRAME_BUFFER ||
+                           (map->flags & _DRM_WRITE_COMBINING)) {
+                               map->mtrr = mtrr_add(map->offset, map->size,
+                                                    MTRR_TYPE_WRCOMB, 1);
                        }
                }
                if (map->type == _DRM_REGISTERS)
-                       map->handle = drm_ioremap( map->offset, map->size,
-                                                   dev );
+                       map->handle = drm_ioremap(map->offset, map->size, dev);
                break;
 
        case _DRM_SHM:
                map->handle = vmalloc_32(map->size);
-               DRM_DEBUG( "%lu %d %p\n",
-                          map->size, drm_order( map->size ), map->handle );
-               if ( !map->handle ) {
-                       drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+               DRM_DEBUG("%lu %d %p\n",
+                         map->size, drm_order(map->size), map->handle);
+               if (!map->handle) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                        return -ENOMEM;
                }
                map->offset = (unsigned long)map->handle;
-               if ( map->flags & _DRM_CONTAINS_LOCK ) {
+               if (map->flags & _DRM_CONTAINS_LOCK) {
                        /* Prevent a 2nd X Server from creating a 2nd lock */
                        if (dev->lock.hw_lock != NULL) {
-                               vfree( map->handle );
-                               drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+                               vfree(map->handle);
+                               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                                return -EBUSY;
                        }
-                       dev->sigdata.lock =
-                       dev->lock.hw_lock = map->handle; /* Pointer to lock */
+                       dev->sigdata.lock = dev->lock.hw_lock = map->handle;    /* Pointer to lock */
                }
                break;
        case _DRM_AGP:
@@ -217,7 +219,7 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
                        map->offset += dev->hose->mem_space->start;
 #endif
                        map->offset += dev->agp->base;
-                       map->mtrr   = dev->agp->agp_mtrr; /* for getmap */
+                       map->mtrr = dev->agp->agp_mtrr; /* for getmap */
                }
                break;
        case _DRM_SCATTER_GATHER:
@@ -227,7 +229,7 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
                }
                map->offset += (unsigned long)dev->sg->virtual;
                break;
-       case _DRM_CONSISTENT: 
+       case _DRM_CONSISTENT:
                /* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
                 * As we're limiting the address to 2^32-1 (or less),
                 * casting it down to 32 bits is no problem, but we
@@ -242,12 +244,12 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
                kfree(dmah);
                break;
        default:
-               drm_free( map, sizeof(*map), DRM_MEM_MAPS );
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                return -EINVAL;
        }
 
        list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
-       if(!list) {
+       if (!list) {
                drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                return -EINVAL;
        }
@@ -258,18 +260,18 @@ int drm_addmap_core(drm_device_t * dev, unsigned int offset,
        list_add(&list->head, &dev->maplist->head);
        /* Assign a 32-bit handle */
        /* We do it here so that dev->struct_sem protects the increment */
-       list->user_token = HandleID(map->type==_DRM_SHM
+       list->user_token = HandleID(map->type == _DRM_SHM
                                    ? (unsigned long)map->handle
                                    : map->offset, dev);
-       up(&dev->struct_sem);
+       up(&dev->struct_sem);
 
        *maplist = list;
        return 0;
 }
 
-int drm_addmap(drm_device_t *dev, unsigned int offset,
+int drm_addmap(drm_device_t * dev, unsigned int offset,
               unsigned int size, drm_map_type_t type,
-              drm_map_flags_t flags, drm_local_map_t **map_ptr)
+              drm_map_flags_t flags, drm_local_map_t ** map_ptr)
 {
        drm_map_list_t *list;
        int rc;
@@ -279,6 +281,7 @@ int drm_addmap(drm_device_t *dev, unsigned int offset,
                *map_ptr = list->map;
        return rc;
 }
+
 EXPORT_SYMBOL(drm_addmap);
 
 int drm_addmap_ioctl(struct inode *inode, struct file *filp,
@@ -294,24 +297,25 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
        if (!(filp->f_mode & 3))
                return -EACCES; /* Require read/write */
 
-       if (copy_from_user(& map, argp, sizeof(map))) {
+       if (copy_from_user(&map, argp, sizeof(map))) {
                return -EFAULT;
        }
 
        err = drm_addmap_core(dev, map.offset, map.size, map.type, map.flags,
                              &maplist);
 
-       if (err) 
+       if (err)
                return err;
 
        if (copy_to_user(argp, maplist->map, sizeof(drm_map_t)))
                return -EFAULT;
-       if (put_user(maplist->user_token, &argp->handle))
+
+       /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
+       if (put_user((void *)(unsigned long)maplist->user_token, &argp->handle))
                return -EFAULT;
        return 0;
 }
 
-
 /**
  * Remove a map private from list and deallocate resources if the mapping
  * isn't in use.
@@ -328,7 +332,7 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  *
  * \sa drm_addmap
  */
-int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
+int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map)
 {
        struct list_head *list;
        drm_map_list_t *r_list = NULL;
@@ -359,9 +363,8 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
        case _DRM_FRAME_BUFFER:
                if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
                        int retcode;
-                       retcode = mtrr_del(map->mtrr, map->offset,
-                                          map->size);
-                       DRM_DEBUG ("mtrr_del=%d\n", retcode);
+                       retcode = mtrr_del(map->mtrr, map->offset, map->size);
+                       DRM_DEBUG("mtrr_del=%d\n", retcode);
                }
                break;
        case _DRM_SHM:
@@ -381,9 +384,10 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
 
        return 0;
 }
+
 EXPORT_SYMBOL(drm_rmmap_locked);
 
-int drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
+int drm_rmmap(drm_device_t * dev, drm_local_map_t * map)
 {
        int ret;
 
@@ -393,6 +397,7 @@ int drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
 
        return ret;
 }
+
 EXPORT_SYMBOL(drm_rmmap);
 
 /* The rmmap ioctl appears to be unnecessary.  All mappings are torn down on
@@ -414,7 +419,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
        struct list_head *list;
        int ret;
 
-       if (copy_from_user(&request, (drm_map_t __user *)arg, sizeof(request))) {
+       if (copy_from_user(&request, (drm_map_t __user *) arg, sizeof(request))) {
                return -EFAULT;
        }
 
@@ -423,7 +428,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
                drm_map_list_t *r_list = list_entry(list, drm_map_list_t, head);
 
                if (r_list->map &&
-                   r_list->user_token == (unsigned long) request.handle &&
+                   r_list->user_token == (unsigned long)request.handle &&
                    r_list->map->flags & _DRM_REMOVABLE) {
                        map = r_list->map;
                        break;
@@ -462,7 +467,7 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  *
  * Frees any pages and buffers associated with the given entry.
  */
-static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
+static void drm_cleanup_buf_error(drm_device_t * dev, drm_buf_entry_t * entry)
 {
        int i;
 
@@ -470,30 +475,27 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
                for (i = 0; i < entry->seg_count; i++) {
                        if (entry->seglist[i]) {
                                drm_free_pages(entry->seglist[i],
-                                               entry->page_order,
-                                               DRM_MEM_DMA);
+                                              entry->page_order, DRM_MEM_DMA);
                        }
                }
                drm_free(entry->seglist,
-                         entry->seg_count *
-                         sizeof(*entry->seglist),
-                         DRM_MEM_SEGS);
+                        entry->seg_count *
+                        sizeof(*entry->seglist), DRM_MEM_SEGS);
 
                entry->seg_count = 0;
        }
 
-       if (entry->buf_count) {
-               for (i = 0; i < entry->buf_count; i++) {
+       if (entry->buf_count) {
+               for (i = 0; i < entry->buf_count; i++) {
                        if (entry->buflist[i].dev_private) {
                                drm_free(entry->buflist[i].dev_private,
-                                         entry->buflist[i].dev_priv_size,
-                                         DRM_MEM_BUFS);
+                                        entry->buflist[i].dev_priv_size,
+                                        DRM_MEM_BUFS);
                        }
                }
                drm_free(entry->buflist,
-                         entry->buf_count *
-                         sizeof(*entry->buflist),
-                         DRM_MEM_BUFS);
+                        entry->buf_count *
+                        sizeof(*entry->buflist), DRM_MEM_BUFS);
 
                entry->buf_count = 0;
        }
@@ -506,12 +508,12 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
  * \param dev drm_device_t to which the buffers are to be added.
  * \param request pointer to a drm_buf_desc_t describing the request.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * After some sanity checks creates a drm_buf structure for each buffer and
  * reallocates the buffer list of the same size order to accommodate the new
  * buffers.
  */
-int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request)
 {
        drm_device_dma_t *dma = dev->dma;
        drm_buf_entry_t *entry;
@@ -528,144 +530,145 @@ int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request)
        int i;
        drm_buf_t **temp_buflist;
 
-       if ( !dma ) return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
        count = request->count;
        order = drm_order(request->size);
        size = 1 << order;
 
-       alignment  = (request->flags & _DRM_PAGE_ALIGN)
-               ? PAGE_ALIGN(size) : size;
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
        byte_count = 0;
        agp_offset = dev->agp->base + request->agp_start;
 
-       DRM_DEBUG( "count:      %d\n",  count );
-       DRM_DEBUG( "order:      %d\n",  order );
-       DRM_DEBUG( "size:       %d\n",  size );
-       DRM_DEBUG( "agp_offset: %lu\n", agp_offset );
-       DRM_DEBUG( "alignment:  %d\n",  alignment );
-       DRM_DEBUG( "page_order: %d\n",  page_order );
-       DRM_DEBUG( "total:      %d\n",  total );
+       DRM_DEBUG("count:      %d\n", count);
+       DRM_DEBUG("order:      %d\n", order);
+       DRM_DEBUG("size:       %d\n", size);
+       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n", alignment);
+       DRM_DEBUG("page_order: %d\n", page_order);
+       DRM_DEBUG("total:      %d\n", total);
 
-       if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-       if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
 
-       spin_lock( &dev->count_lock );
-       if ( dev->buf_use ) {
-               spin_unlock( &dev->count_lock );
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
                return -EBUSY;
        }
-       atomic_inc( &dev->buf_alloc );
-       spin_unlock( &dev->count_lock );
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
 
-       down( &dev->struct_sem );
+       down(&dev->struct_sem);
        entry = &dma->bufs[order];
-       if ( entry->buf_count ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
-               return -ENOMEM; /* May only call once for each order */
+       if (entry->buf_count) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
        }
 
        if (count < 0 || count > 4096) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -EINVAL;
        }
 
-       entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-                                   DRM_MEM_BUFS );
-       if ( !entry->buflist ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
-       memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
 
        entry->buf_size = size;
        entry->page_order = page_order;
 
        offset = 0;
 
-       while ( entry->buf_count < count ) {
-               buf          = &entry->buflist[entry->buf_count];
-               buf->idx     = dma->buf_count + entry->buf_count;
-               buf->total   = alignment;
-               buf->order   = order;
-               buf->used    = 0;
+       while (entry->buf_count < count) {
+               buf = &entry->buflist[entry->buf_count];
+               buf->idx = dma->buf_count + entry->buf_count;
+               buf->total = alignment;
+               buf->order = order;
+               buf->used = 0;
 
-               buf->offset  = (dma->byte_count + offset);
+               buf->offset = (dma->byte_count + offset);
                buf->bus_address = agp_offset + offset;
                buf->address = (void *)(agp_offset + offset);
-               buf->next    = NULL;
+               buf->next = NULL;
                buf->waiting = 0;
                buf->pending = 0;
-               init_waitqueue_head( &buf->dma_wait );
-               buf->filp    = NULL;
+               init_waitqueue_head(&buf->dma_wait);
+               buf->filp = NULL;
 
                buf->dev_priv_size = dev->driver->dev_priv_size;
-               buf->dev_private = drm_alloc( buf->dev_priv_size,
-                                              DRM_MEM_BUFS );
-               if(!buf->dev_private) {
+               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+               if (!buf->dev_private) {
                        /* Set count correctly so we free the proper amount. */
                        entry->buf_count = count;
-                       drm_cleanup_buf_error(dev,entry);
-                       up( &dev->struct_sem );
-                       atomic_dec( &dev->buf_alloc );
+                       drm_cleanup_buf_error(dev, entry);
+                       up(&dev->struct_sem);
+                       atomic_dec(&dev->buf_alloc);
                        return -ENOMEM;
                }
-               memset( buf->dev_private, 0, buf->dev_priv_size );
+               memset(buf->dev_private, 0, buf->dev_priv_size);
 
-               DRM_DEBUG( "buffer %d @ %p\n",
-                          entry->buf_count, buf->address );
+               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
 
                offset += alignment;
                entry->buf_count++;
                byte_count += PAGE_SIZE << page_order;
        }
 
-       DRM_DEBUG( "byte_count: %d\n", byte_count );
+       DRM_DEBUG("byte_count: %d\n", byte_count);
 
-       temp_buflist = drm_realloc( dma->buflist,
-                                    dma->buf_count * sizeof(*dma->buflist),
-                                    (dma->buf_count + entry->buf_count)
-                                    * sizeof(*dma->buflist),
-                                    DRM_MEM_BUFS );
-       if(!temp_buflist) {
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
                /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev,entry);
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               drm_cleanup_buf_error(dev, entry);
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
        dma->buf_count += entry->buf_count;
        dma->byte_count += byte_count;
 
-       DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-       DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
-       up( &dev->struct_sem );
+       up(&dev->struct_sem);
 
        request->count = entry->buf_count;
        request->size = size;
 
        dma->flags = _DRM_DMA_USE_AGP;
 
-       atomic_dec( &dev->buf_alloc );
+       atomic_dec(&dev->buf_alloc);
        return 0;
 }
+
 EXPORT_SYMBOL(drm_addbufs_agp);
-#endif /* __OS_HAS_AGP */
+#endif                         /* __OS_HAS_AGP */
 
-int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
+int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
 {
        drm_device_dma_t *dma = dev->dma;
        int count;
@@ -684,178 +687,174 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
        unsigned long *temp_pagelist;
        drm_buf_t **temp_buflist;
 
-       if (!drm_core_check_feature(dev, DRIVER_PCI_DMA)) return -EINVAL;
-       if ( !dma ) return -EINVAL;
+       if (!drm_core_check_feature(dev, DRIVER_PCI_DMA))
+               return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
        count = request->count;
        order = drm_order(request->size);
        size = 1 << order;
 
-       DRM_DEBUG( "count=%d, size=%d (%d), order=%d, queue_count=%d\n",
-                  request->count, request->size, size,
-                  order, dev->queue_count );
+       DRM_DEBUG("count=%d, size=%d (%d), order=%d, queue_count=%d\n",
+                 request->count, request->size, size, order, dev->queue_count);
 
-       if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-       if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
 
        alignment = (request->flags & _DRM_PAGE_ALIGN)
-               ? PAGE_ALIGN(size) : size;
+           ? PAGE_ALIGN(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
-       spin_lock( &dev->count_lock );
-       if ( dev->buf_use ) {
-               spin_unlock( &dev->count_lock );
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
                return -EBUSY;
        }
-       atomic_inc( &dev->buf_alloc );
-       spin_unlock( &dev->count_lock );
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
 
-       down( &dev->struct_sem );
+       down(&dev->struct_sem);
        entry = &dma->bufs[order];
-       if ( entry->buf_count ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+       if (entry->buf_count) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM; /* May only call once for each order */
        }
 
        if (count < 0 || count > 4096) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -EINVAL;
        }
 
-       entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-                                   DRM_MEM_BUFS );
-       if ( !entry->buflist ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
-       memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
-
-       entry->seglist = drm_alloc( count * sizeof(*entry->seglist),
-                                   DRM_MEM_SEGS );
-       if ( !entry->seglist ) {
-               drm_free( entry->buflist,
-                         count * sizeof(*entry->buflist),
-                         DRM_MEM_BUFS );
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+       entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
+                                  DRM_MEM_SEGS);
+       if (!entry->seglist) {
+               drm_free(entry->buflist,
+                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
-       memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
+       memset(entry->seglist, 0, count * sizeof(*entry->seglist));
 
        /* Keep the original pagelist until we know all the allocations
         * have succeeded
         */
-       temp_pagelist = drm_alloc( (dma->page_count + (count << page_order))
-                                   * sizeof(*dma->pagelist),
-                                   DRM_MEM_PAGES );
+       temp_pagelist = drm_alloc((dma->page_count + (count << page_order))
+                                 * sizeof(*dma->pagelist), DRM_MEM_PAGES);
        if (!temp_pagelist) {
-               drm_free( entry->buflist,
-                          count * sizeof(*entry->buflist),
-                          DRM_MEM_BUFS );
-               drm_free( entry->seglist,
-                          count * sizeof(*entry->seglist),
-                          DRM_MEM_SEGS );
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               drm_free(entry->buflist,
+                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+               drm_free(entry->seglist,
+                        count * sizeof(*entry->seglist), DRM_MEM_SEGS);
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
        memcpy(temp_pagelist,
-              dma->pagelist,
-              dma->page_count * sizeof(*dma->pagelist));
-       DRM_DEBUG( "pagelist: %d entries\n",
-                  dma->page_count + (count << page_order) );
+              dma->pagelist, dma->page_count * sizeof(*dma->pagelist));
+       DRM_DEBUG("pagelist: %d entries\n",
+                 dma->page_count + (count << page_order));
 
-       entry->buf_size = size;
+       entry->buf_size = size;
        entry->page_order = page_order;
        byte_count = 0;
        page_count = 0;
 
-       while ( entry->buf_count < count ) {
-               page = drm_alloc_pages( page_order, DRM_MEM_DMA );
-               if ( !page ) {
+       while (entry->buf_count < count) {
+               page = drm_alloc_pages(page_order, DRM_MEM_DMA);
+               if (!page) {
                        /* Set count correctly so we free the proper amount. */
                        entry->buf_count = count;
                        entry->seg_count = count;
                        drm_cleanup_buf_error(dev, entry);
-                       drm_free( temp_pagelist,
-                                  (dma->page_count + (count << page_order))
-                                  * sizeof(*dma->pagelist),
-                                  DRM_MEM_PAGES );
-                       up( &dev->struct_sem );
-                       atomic_dec( &dev->buf_alloc );
+                       drm_free(temp_pagelist,
+                                (dma->page_count + (count << page_order))
+                                * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+                       up(&dev->struct_sem);
+                       atomic_dec(&dev->buf_alloc);
                        return -ENOMEM;
                }
                entry->seglist[entry->seg_count++] = page;
-               for ( i = 0 ; i < (1 << page_order) ; i++ ) {
-                       DRM_DEBUG( "page %d @ 0x%08lx\n",
-                                  dma->page_count + page_count,
-                                  page + PAGE_SIZE * i );
+               for (i = 0; i < (1 << page_order); i++) {
+                       DRM_DEBUG("page %d @ 0x%08lx\n",
+                                 dma->page_count + page_count,
+                                 page + PAGE_SIZE * i);
                        temp_pagelist[dma->page_count + page_count++]
-                               = page + PAGE_SIZE * i;
+                           = page + PAGE_SIZE * i;
                }
-               for ( offset = 0 ;
-                     offset + size <= total && entry->buf_count < count ;
-                     offset += alignment, ++entry->buf_count ) {
-                       buf          = &entry->buflist[entry->buf_count];
-                       buf->idx     = dma->buf_count + entry->buf_count;
-                       buf->total   = alignment;
-                       buf->order   = order;
-                       buf->used    = 0;
-                       buf->offset  = (dma->byte_count + byte_count + offset);
+               for (offset = 0;
+                    offset + size <= total && entry->buf_count < count;
+                    offset += alignment, ++entry->buf_count) {
+                       buf = &entry->buflist[entry->buf_count];
+                       buf->idx = dma->buf_count + entry->buf_count;
+                       buf->total = alignment;
+                       buf->order = order;
+                       buf->used = 0;
+                       buf->offset = (dma->byte_count + byte_count + offset);
                        buf->address = (void *)(page + offset);
-                       buf->next    = NULL;
+                       buf->next = NULL;
                        buf->waiting = 0;
                        buf->pending = 0;
-                       init_waitqueue_head( &buf->dma_wait );
-                       buf->filp    = NULL;
+                       init_waitqueue_head(&buf->dma_wait);
+                       buf->filp = NULL;
 
                        buf->dev_priv_size = dev->driver->dev_priv_size;
-                       buf->dev_private = drm_alloc( buf->dev_priv_size,
-                                                      DRM_MEM_BUFS );
-                       if(!buf->dev_private) {
+                       buf->dev_private = drm_alloc(buf->dev_priv_size,
+                                                    DRM_MEM_BUFS);
+                       if (!buf->dev_private) {
                                /* Set count correctly so we free the proper amount. */
                                entry->buf_count = count;
                                entry->seg_count = count;
-                               drm_cleanup_buf_error(dev,entry);
-                               drm_free( temp_pagelist,
-                                          (dma->page_count + (count << page_order))
-                                          * sizeof(*dma->pagelist),
-                                          DRM_MEM_PAGES );
-                               up( &dev->struct_sem );
-                               atomic_dec( &dev->buf_alloc );
+                               drm_cleanup_buf_error(dev, entry);
+                               drm_free(temp_pagelist,
+                                        (dma->page_count +
+                                         (count << page_order))
+                                        * sizeof(*dma->pagelist),
+                                        DRM_MEM_PAGES);
+                               up(&dev->struct_sem);
+                               atomic_dec(&dev->buf_alloc);
                                return -ENOMEM;
                        }
-                       memset( buf->dev_private, 0, buf->dev_priv_size );
+                       memset(buf->dev_private, 0, buf->dev_priv_size);
 
-                       DRM_DEBUG( "buffer %d @ %p\n",
-                                  entry->buf_count, buf->address );
+                       DRM_DEBUG("buffer %d @ %p\n",
+                                 entry->buf_count, buf->address);
                }
                byte_count += PAGE_SIZE << page_order;
        }
 
-       temp_buflist = drm_realloc( dma->buflist,
-                                    dma->buf_count * sizeof(*dma->buflist),
-                                    (dma->buf_count + entry->buf_count)
-                                    * sizeof(*dma->buflist),
-                                    DRM_MEM_BUFS );
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
        if (!temp_buflist) {
                /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev,entry);
-               drm_free( temp_pagelist,
-                          (dma->page_count + (count << page_order))
-                          * sizeof(*dma->pagelist),
-                          DRM_MEM_PAGES );
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               drm_cleanup_buf_error(dev, entry);
+               drm_free(temp_pagelist,
+                        (dma->page_count + (count << page_order))
+                        * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
@@ -864,8 +863,8 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
         */
        if (dma->page_count) {
                drm_free(dma->pagelist,
-                         dma->page_count * sizeof(*dma->pagelist),
-                         DRM_MEM_PAGES);
+                        dma->page_count * sizeof(*dma->pagelist),
+                        DRM_MEM_PAGES);
        }
        dma->pagelist = temp_pagelist;
 
@@ -874,18 +873,19 @@ int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request)
        dma->page_count += entry->seg_count << page_order;
        dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
 
-       up( &dev->struct_sem );
+       up(&dev->struct_sem);
 
        request->count = entry->buf_count;
        request->size = size;
 
-       atomic_dec( &dev->buf_alloc );
+       atomic_dec(&dev->buf_alloc);
        return 0;
 
 }
+
 EXPORT_SYMBOL(drm_addbufs_pci);
 
-static int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_addbufs_sg(drm_device_t * dev, drm_buf_desc_t * request)
 {
        drm_device_dma_t *dma = dev->dma;
        drm_buf_entry_t *entry;
@@ -902,146 +902,147 @@ static int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
        int i;
        drm_buf_t **temp_buflist;
 
-       if (!drm_core_check_feature(dev, DRIVER_SG)) return -EINVAL;
-       
-       if ( !dma ) return -EINVAL;
+       if (!drm_core_check_feature(dev, DRIVER_SG))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
 
        count = request->count;
        order = drm_order(request->size);
        size = 1 << order;
 
-       alignment  = (request->flags & _DRM_PAGE_ALIGN)
-                       ? PAGE_ALIGN(size) : size;
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
        page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
        total = PAGE_SIZE << page_order;
 
        byte_count = 0;
        agp_offset = request->agp_start;
 
-       DRM_DEBUG( "count:      %d\n",  count );
-       DRM_DEBUG( "order:      %d\n",  order );
-       DRM_DEBUG( "size:       %d\n",  size );
-       DRM_DEBUG( "agp_offset: %lu\n", agp_offset );
-       DRM_DEBUG( "alignment:  %d\n",  alignment );
-       DRM_DEBUG( "page_order: %d\n",  page_order );
-       DRM_DEBUG( "total:      %d\n",  total );
+       DRM_DEBUG("count:      %d\n", count);
+       DRM_DEBUG("order:      %d\n", order);
+       DRM_DEBUG("size:       %d\n", size);
+       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n", alignment);
+       DRM_DEBUG("page_order: %d\n", page_order);
+       DRM_DEBUG("total:      %d\n", total);
 
-       if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
-       if ( dev->queue_count ) return -EBUSY; /* Not while in use */
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
 
-       spin_lock( &dev->count_lock );
-       if ( dev->buf_use ) {
-               spin_unlock( &dev->count_lock );
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
                return -EBUSY;
        }
-       atomic_inc( &dev->buf_alloc );
-       spin_unlock( &dev->count_lock );
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
 
-       down( &dev->struct_sem );
+       down(&dev->struct_sem);
        entry = &dma->bufs[order];
-       if ( entry->buf_count ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
-               return -ENOMEM; /* May only call once for each order */
+       if (entry->buf_count) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
        }
 
        if (count < 0 || count > 4096) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -EINVAL;
        }
 
-       entry->buflist = drm_alloc( count * sizeof(*entry->buflist),
-                                    DRM_MEM_BUFS );
-       if ( !entry->buflist ) {
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
-       memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
 
        entry->buf_size = size;
        entry->page_order = page_order;
 
        offset = 0;
 
-       while ( entry->buf_count < count ) {
-               buf          = &entry->buflist[entry->buf_count];
-               buf->idx     = dma->buf_count + entry->buf_count;
-               buf->total   = alignment;
-               buf->order   = order;
-               buf->used    = 0;
+       while (entry->buf_count < count) {
+               buf = &entry->buflist[entry->buf_count];
+               buf->idx = dma->buf_count + entry->buf_count;
+               buf->total = alignment;
+               buf->order = order;
+               buf->used = 0;
 
-               buf->offset  = (dma->byte_count + offset);
+               buf->offset = (dma->byte_count + offset);
                buf->bus_address = agp_offset + offset;
-               buf->address = (void *)(agp_offset + offset 
+               buf->address = (void *)(agp_offset + offset
                                        + (unsigned long)dev->sg->virtual);
-               buf->next    = NULL;
+               buf->next = NULL;
                buf->waiting = 0;
                buf->pending = 0;
-               init_waitqueue_head( &buf->dma_wait );
-               buf->filp    = NULL;
+               init_waitqueue_head(&buf->dma_wait);
+               buf->filp = NULL;
 
                buf->dev_priv_size = dev->driver->dev_priv_size;
-               buf->dev_private = drm_alloc( buf->dev_priv_size,
-                                              DRM_MEM_BUFS );
-               if(!buf->dev_private) {
+               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+               if (!buf->dev_private) {
                        /* Set count correctly so we free the proper amount. */
                        entry->buf_count = count;
-                       drm_cleanup_buf_error(dev,entry);
-                       up( &dev->struct_sem );
-                       atomic_dec( &dev->buf_alloc );
+                       drm_cleanup_buf_error(dev, entry);
+                       up(&dev->struct_sem);
+                       atomic_dec(&dev->buf_alloc);
                        return -ENOMEM;
                }
 
-               memset( buf->dev_private, 0, buf->dev_priv_size );
+               memset(buf->dev_private, 0, buf->dev_priv_size);
 
-               DRM_DEBUG( "buffer %d @ %p\n",
-                          entry->buf_count, buf->address );
+               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
 
                offset += alignment;
                entry->buf_count++;
                byte_count += PAGE_SIZE << page_order;
        }
 
-       DRM_DEBUG( "byte_count: %d\n", byte_count );
+       DRM_DEBUG("byte_count: %d\n", byte_count);
 
-       temp_buflist = drm_realloc( dma->buflist,
-                                    dma->buf_count * sizeof(*dma->buflist),
-                                    (dma->buf_count + entry->buf_count)
-                                    * sizeof(*dma->buflist),
-                                    DRM_MEM_BUFS );
-       if(!temp_buflist) {
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
                /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev,entry);
-               up( &dev->struct_sem );
-               atomic_dec( &dev->buf_alloc );
+               drm_cleanup_buf_error(dev, entry);
+               up(&dev->struct_sem);
+               atomic_dec(&dev->buf_alloc);
                return -ENOMEM;
        }
        dma->buflist = temp_buflist;
 
-       for ( i = 0 ; i < entry->buf_count ; i++ ) {
+       for (i = 0; i < entry->buf_count; i++) {
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
        dma->buf_count += entry->buf_count;
        dma->byte_count += byte_count;
 
-       DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
-       DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
 
-       up( &dev->struct_sem );
+       up(&dev->struct_sem);
 
        request->count = entry->buf_count;
        request->size = size;
 
        dma->flags = _DRM_DMA_USE_SG;
 
-       atomic_dec( &dev->buf_alloc );
+       atomic_dec(&dev->buf_alloc);
        return 0;
 }
 
-static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
+static int drm_addbufs_fb(drm_device_t * dev, drm_buf_desc_t * request)
 {
        drm_device_dma_t *dma = dev->dma;
        drm_buf_entry_t *entry;
@@ -1060,7 +1061,7 @@ static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
 
        if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
                return -EINVAL;
-    
+
        if (!dma)
                return -EINVAL;
 
@@ -1210,43 +1211,41 @@ static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
  * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
  * PCI memory respectively.
  */
-int drm_addbufs( struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg )
+int drm_addbufs(struct inode *inode, struct file *filp,
+               unsigned int cmd, unsigned long arg)
 {
        drm_buf_desc_t request;
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
        int ret;
-       
+
        if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
                return -EINVAL;
 
-       if ( copy_from_user( &request, (drm_buf_desc_t __user *)arg,
-                            sizeof(request) ) )
+       if (copy_from_user(&request, (drm_buf_desc_t __user *) arg,
+                          sizeof(request)))
                return -EFAULT;
 
 #if __OS_HAS_AGP
-       if ( request.flags & _DRM_AGP_BUFFER )
-               ret=drm_addbufs_agp(dev, &request);
+       if (request.flags & _DRM_AGP_BUFFER)
+               ret = drm_addbufs_agp(dev, &request);
        else
 #endif
-       if ( request.flags & _DRM_SG_BUFFER )
-               ret=drm_addbufs_sg(dev, &request);
-       else if ( request.flags & _DRM_FB_BUFFER)
-               ret=drm_addbufs_fb(dev, &request);
+       if (request.flags & _DRM_SG_BUFFER)
+               ret = drm_addbufs_sg(dev, &request);
+       else if (request.flags & _DRM_FB_BUFFER)
+               ret = drm_addbufs_fb(dev, &request);
        else
-               ret=drm_addbufs_pci(dev, &request);
+               ret = drm_addbufs_pci(dev, &request);
 
-       if (ret==0) {
-               if (copy_to_user((void __user *)arg, &request,
-                                sizeof(request))) {
+       if (ret == 0) {
+               if (copy_to_user((void __user *)arg, &request, sizeof(request))) {
                        ret = -EFAULT;
                }
        }
        return ret;
 }
 
-
 /**
  * Get information about the buffer mappings.
  *
@@ -1264,8 +1263,8 @@ int drm_addbufs( struct inode *inode, struct file *filp,
  * lock, preventing of allocating more buffers after this call. Information
  * about each requested buffer is then copied into user space.
  */
-int drm_infobufs( struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg )
+int drm_infobufs(struct inode *inode, struct file *filp,
+                unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -1278,58 +1277,61 @@ int drm_infobufs( struct inode *inode, struct file *filp,
        if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
                return -EINVAL;
 
-       if ( !dma ) return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
-       spin_lock( &dev->count_lock );
-       if ( atomic_read( &dev->buf_alloc ) ) {
-               spin_unlock( &dev->count_lock );
+       spin_lock(&dev->count_lock);
+       if (atomic_read(&dev->buf_alloc)) {
+               spin_unlock(&dev->count_lock);
                return -EBUSY;
        }
        ++dev->buf_use;         /* Can't allocate more after this call */
-       spin_unlock( &dev->count_lock );
+       spin_unlock(&dev->count_lock);
 
-       if ( copy_from_user( &request, argp, sizeof(request) ) )
+       if (copy_from_user(&request, argp, sizeof(request)))
                return -EFAULT;
 
-       for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-               if ( dma->bufs[i].buf_count ) ++count;
+       for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+               if (dma->bufs[i].buf_count)
+                       ++count;
        }
 
-       DRM_DEBUG( "count = %d\n", count );
+       DRM_DEBUG("count = %d\n", count);
 
-       if ( request.count >= count ) {
-               for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
-                       if ( dma->bufs[i].buf_count ) {
-                               drm_buf_desc_t __user *to = &request.list[count];
+       if (request.count >= count) {
+               for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+                       if (dma->bufs[i].buf_count) {
+                               drm_buf_desc_t __user *to =
+                                   &request.list[count];
                                drm_buf_entry_t *from = &dma->bufs[i];
                                drm_freelist_t *list = &dma->bufs[i].freelist;
-                               if ( copy_to_user( &to->count,
-                                                  &from->buf_count,
-                                                  sizeof(from->buf_count) ) ||
-                                    copy_to_user( &to->size,
-                                                  &from->buf_size,
-                                                  sizeof(from->buf_size) ) ||
-                                    copy_to_user( &to->low_mark,
-                                                  &list->low_mark,
-                                                  sizeof(list->low_mark) ) ||
-                                    copy_to_user( &to->high_mark,
-                                                  &list->high_mark,
-                                                  sizeof(list->high_mark) ) )
+                               if (copy_to_user(&to->count,
+                                                &from->buf_count,
+                                                sizeof(from->buf_count)) ||
+                                   copy_to_user(&to->size,
+                                                &from->buf_size,
+                                                sizeof(from->buf_size)) ||
+                                   copy_to_user(&to->low_mark,
+                                                &list->low_mark,
+                                                sizeof(list->low_mark)) ||
+                                   copy_to_user(&to->high_mark,
+                                                &list->high_mark,
+                                                sizeof(list->high_mark)))
                                        return -EFAULT;
 
-                               DRM_DEBUG( "%d %d %d %d %d\n",
-                                          i,
-                                          dma->bufs[i].buf_count,
-                                          dma->bufs[i].buf_size,
-                                          dma->bufs[i].freelist.low_mark,
-                                          dma->bufs[i].freelist.high_mark );
+                               DRM_DEBUG("%d %d %d %d %d\n",
+                                         i,
+                                         dma->bufs[i].buf_count,
+                                         dma->bufs[i].buf_size,
+                                         dma->bufs[i].freelist.low_mark,
+                                         dma->bufs[i].freelist.high_mark);
                                ++count;
                        }
                }
        }
        request.count = count;
 
-       if ( copy_to_user( argp, &request, sizeof(request) ) )
+       if (copy_to_user(argp, &request, sizeof(request)))
                return -EFAULT;
 
        return 0;
@@ -1349,8 +1351,8 @@ int drm_infobufs( struct inode *inode, struct file *filp,
  *
  * \note This ioctl is deprecated and mostly never used.
  */
-int drm_markbufs( struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg )
+int drm_markbufs(struct inode *inode, struct file *filp,
+                unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -1362,44 +1364,45 @@ int drm_markbufs( struct inode *inode, struct file *filp,
        if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
                return -EINVAL;
 
-       if ( !dma ) return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
-       if ( copy_from_user( &request,
-                            (drm_buf_desc_t __user *)arg,
-                            sizeof(request) ) )
+       if (copy_from_user(&request,
+                          (drm_buf_desc_t __user *) arg, sizeof(request)))
                return -EFAULT;
 
-       DRM_DEBUG( "%d, %d, %d\n",
-                  request.size, request.low_mark, request.high_mark );
-       order = drm_order( request.size );
-       if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
+       DRM_DEBUG("%d, %d, %d\n",
+                 request.size, request.low_mark, request.high_mark);
+       order = drm_order(request.size);
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
        entry = &dma->bufs[order];
 
-       if ( request.low_mark < 0 || request.low_mark > entry->buf_count )
+       if (request.low_mark < 0 || request.low_mark > entry->buf_count)
                return -EINVAL;
-       if ( request.high_mark < 0 || request.high_mark > entry->buf_count )
+       if (request.high_mark < 0 || request.high_mark > entry->buf_count)
                return -EINVAL;
 
-       entry->freelist.low_mark  = request.low_mark;
+       entry->freelist.low_mark = request.low_mark;
        entry->freelist.high_mark = request.high_mark;
 
        return 0;
 }
 
 /**
- * Unreserve the buffers in list, previously reserved using drmDMA. 
+ * Unreserve the buffers in list, previously reserved using drmDMA.
  *
  * \param inode device inode.
  * \param filp file pointer.
  * \param cmd command.
  * \param arg pointer to a drm_buf_free structure.
  * \return zero on success or a negative number on failure.
- * 
+ *
  * Calls free_buffer() for each used buffer.
  * This function is primarily used for debugging.
  */
-int drm_freebufs( struct inode *inode, struct file *filp,
-                  unsigned int cmd, unsigned long arg )
+int drm_freebufs(struct inode *inode, struct file *filp,
+                unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -1412,31 +1415,29 @@ int drm_freebufs( struct inode *inode, struct file *filp,
        if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
                return -EINVAL;
 
-       if ( !dma ) return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
-       if ( copy_from_user( &request,
-                            (drm_buf_free_t __user *)arg,
-                            sizeof(request) ) )
+       if (copy_from_user(&request,
+                          (drm_buf_free_t __user *) arg, sizeof(request)))
                return -EFAULT;
 
-       DRM_DEBUG( "%d\n", request.count );
-       for ( i = 0 ; i < request.count ; i++ ) {
-               if ( copy_from_user( &idx,
-                                    &request.list[i],
-                                    sizeof(idx) ) )
+       DRM_DEBUG("%d\n", request.count);
+       for (i = 0; i < request.count; i++) {
+               if (copy_from_user(&idx, &request.list[i], sizeof(idx)))
                        return -EFAULT;
-               if ( idx < 0 || idx >= dma->buf_count ) {
-                       DRM_ERROR( "Index %d (of %d max)\n",
-                                  idx, dma->buf_count - 1 );
+               if (idx < 0 || idx >= dma->buf_count) {
+                       DRM_ERROR("Index %d (of %d max)\n",
+                                 idx, dma->buf_count - 1);
                        return -EINVAL;
                }
                buf = dma->buflist[idx];
-               if ( buf->filp != filp ) {
-                       DRM_ERROR( "Process %d freeing buffer not owned\n",
-                                  current->pid );
+               if (buf->filp != filp) {
+                       DRM_ERROR("Process %d freeing buffer not owned\n",
+                                 current->pid);
                        return -EINVAL;
                }
-               drm_free_buffer( dev, buf );
+               drm_free_buffer(dev, buf);
        }
 
        return 0;
@@ -1455,8 +1456,8 @@ int drm_freebufs( struct inode *inode, struct file *filp,
  * about each buffer into user space. The PCI buffers are already mapped on the
  * addbufs_pci() call.
  */
-int drm_mapbufs( struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg )
+int drm_mapbufs(struct inode *inode, struct file *filp,
+               unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -1472,86 +1473,84 @@ int drm_mapbufs( struct inode *inode, struct file *filp,
        if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
                return -EINVAL;
 
-       if ( !dma ) return -EINVAL;
+       if (!dma)
+               return -EINVAL;
 
-       spin_lock( &dev->count_lock );
-       if ( atomic_read( &dev->buf_alloc ) ) {
-               spin_unlock( &dev->count_lock );
+       spin_lock(&dev->count_lock);
+       if (atomic_read(&dev->buf_alloc)) {
+               spin_unlock(&dev->count_lock);
                return -EBUSY;
        }
        dev->buf_use++;         /* Can't allocate more after this call */
-       spin_unlock( &dev->count_lock );
+       spin_unlock(&dev->count_lock);
 
-       if ( copy_from_user( &request, argp, sizeof(request) ) )
+       if (copy_from_user(&request, argp, sizeof(request)))
                return -EFAULT;
 
-       if ( request.count >= dma->buf_count ) {
+       if (request.count >= dma->buf_count) {
                if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
-                   || (drm_core_check_feature(dev, DRIVER_SG) 
+                   || (drm_core_check_feature(dev, DRIVER_SG)
                        && (dma->flags & _DRM_DMA_USE_SG))
                    || (drm_core_check_feature(dev, DRIVER_FB_DMA)
                        && (dma->flags & _DRM_DMA_USE_FB))) {
                        drm_map_t *map = dev->agp_buffer_map;
                        unsigned long token = dev->agp_buffer_token;
 
-                       if ( !map ) {
+                       if (!map) {
                                retcode = -EINVAL;
                                goto done;
                        }
 
-                       down_write( &current->mm->mmap_sem );
-                       virtual = do_mmap( filp, 0, map->size,
-                                          PROT_READ | PROT_WRITE,
-                                          MAP_SHARED,
-                                          token );
-                       up_write( &current->mm->mmap_sem );
+                       down_write(&current->mm->mmap_sem);
+                       virtual = do_mmap(filp, 0, map->size,
+                                         PROT_READ | PROT_WRITE,
+                                         MAP_SHARED, token);
+                       up_write(&current->mm->mmap_sem);
                } else {
-                       down_write( &current->mm->mmap_sem );
-                       virtual = do_mmap( filp, 0, dma->byte_count,
-                                          PROT_READ | PROT_WRITE,
-                                          MAP_SHARED, 0 );
-                       up_write( &current->mm->mmap_sem );
+                       down_write(&current->mm->mmap_sem);
+                       virtual = do_mmap(filp, 0, dma->byte_count,
+                                         PROT_READ | PROT_WRITE,
+                                         MAP_SHARED, 0);
+                       up_write(&current->mm->mmap_sem);
                }
-               if ( virtual > -1024UL ) {
+               if (virtual > -1024UL) {
                        /* Real error */
                        retcode = (signed long)virtual;
                        goto done;
                }
                request.virtual = (void __user *)virtual;
 
-               for ( i = 0 ; i < dma->buf_count ; i++ ) {
-                       if ( copy_to_user( &request.list[i].idx,
-                                          &dma->buflist[i]->idx,
-                                          sizeof(request.list[0].idx) ) ) {
+               for (i = 0; i < dma->buf_count; i++) {
+                       if (copy_to_user(&request.list[i].idx,
+                                        &dma->buflist[i]->idx,
+                                        sizeof(request.list[0].idx))) {
                                retcode = -EFAULT;
                                goto done;
                        }
-                       if ( copy_to_user( &request.list[i].total,
-                                          &dma->buflist[i]->total,
-                                          sizeof(request.list[0].total) ) ) {
+                       if (copy_to_user(&request.list[i].total,
+                                        &dma->buflist[i]->total,
+                                        sizeof(request.list[0].total))) {
                                retcode = -EFAULT;
                                goto done;
                        }
-                       if ( copy_to_user( &request.list[i].used,
-                                          &zero,
-                                          sizeof(zero) ) ) {
+                       if (copy_to_user(&request.list[i].used,
+                                        &zero, sizeof(zero))) {
                                retcode = -EFAULT;
                                goto done;
                        }
-                       address = virtual + dma->buflist[i]->offset; /* *** */
-                       if ( copy_to_user( &request.list[i].address,
-                                          &address,
-                                          sizeof(address) ) ) {
+                       address = virtual + dma->buflist[i]->offset;    /* *** */
+                       if (copy_to_user(&request.list[i].address,
+                                        &address, sizeof(address))) {
                                retcode = -EFAULT;
                                goto done;
                        }
                }
        }
- done:
     done:
        request.count = dma->buf_count;
-       DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode );
+       DRM_DEBUG("%d buffers, retcode = %d\n", request.count, retcode);
 
-       if ( copy_to_user( argp, &request, sizeof(request) ) )
+       if (copy_to_user(argp, &request, sizeof(request)))
                return -EFAULT;
 
        return retcode;
@@ -1560,23 +1559,23 @@ int drm_mapbufs( struct inode *inode, struct file *filp,
 /**
  * Compute size order.  Returns the exponent of the smaller power of two which
  * is greater or equal to given number.
- * 
+ *
  * \param size size.
  * \return order.
  *
  * \todo Can be made faster.
  */
-int drm_order( unsigned long size )
+int drm_order(unsigned long size)
 {
        int order;
        unsigned long tmp;
 
-       for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++)
-               ;
+       for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ;
 
        if (size & (size - 1))
                ++order;
 
        return order;
 }
+
 EXPORT_SYMBOL(drm_order);
index 502892794c1676b6fb05fc7dd59381bf06fb8d9a..bdd168d88f49b0ab6a0103f6c32b20e4fde46105 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drm_context.
+ * \file drm_context.c
  * IOCTLs for generic contexts
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
  */
  * in drm_device::context_sareas, while holding the drm_device::struct_sem
  * lock.
  */
-void drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle )
+void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle)
 {
-       if ( ctx_handle < 0 ) goto failed;
-       if ( !dev->ctx_bitmap ) goto failed;
+       if (ctx_handle < 0)
+               goto failed;
+       if (!dev->ctx_bitmap)
+               goto failed;
 
-       if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
+       if (ctx_handle < DRM_MAX_CTXBITMAP) {
                down(&dev->struct_sem);
-               clear_bit( ctx_handle, dev->ctx_bitmap );
+               clear_bit(ctx_handle, dev->ctx_bitmap);
                dev->context_sareas[ctx_handle] = NULL;
                up(&dev->struct_sem);
                return;
        }
-failed:
-               DRM_ERROR( "Attempt to free invalid context handle: %d\n",
-                  ctx_handle );
-               return;
+      failed:
+       DRM_ERROR("Attempt to free invalid context handle: %d\n", ctx_handle);
+       return;
 }
 
-/** 
+/**
  * Context bitmap allocation.
  *
  * \param dev DRM device.
@@ -84,29 +85,33 @@ failed:
  * drm_device::context_sareas to accommodate the new entry while holding the
  * drm_device::struct_sem lock.
  */
-static int drm_ctxbitmap_next( drm_device_t *dev )
+static int drm_ctxbitmap_next(drm_device_t * dev)
 {
        int bit;
 
-       if(!dev->ctx_bitmap) return -1;
+       if (!dev->ctx_bitmap)
+               return -1;
 
        down(&dev->struct_sem);
-       bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
-       if ( bit < DRM_MAX_CTXBITMAP ) {
-               set_bit( bit, dev->ctx_bitmap );
-               DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
-               if((bit+1) > dev->max_context) {
-                       dev->max_context = (bit+1);
-                       if(dev->context_sareas) {
+       bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP);
+       if (bit < DRM_MAX_CTXBITMAP) {
+               set_bit(bit, dev->ctx_bitmap);
+               DRM_DEBUG("drm_ctxbitmap_next bit : %d\n", bit);
+               if ((bit + 1) > dev->max_context) {
+                       dev->max_context = (bit + 1);
+                       if (dev->context_sareas) {
                                drm_map_t **ctx_sareas;
 
                                ctx_sareas = drm_realloc(dev->context_sareas,
-                                               (dev->max_context - 1) * 
-                                               sizeof(*dev->context_sareas),
-                                               dev->max_context * 
-                                               sizeof(*dev->context_sareas),
-                                               DRM_MEM_MAPS);
-                               if(!ctx_sareas) {
+                                                        (dev->max_context -
+                                                         1) *
+                                                        sizeof(*dev->
+                                                               context_sareas),
+                                                        dev->max_context *
+                                                        sizeof(*dev->
+                                                               context_sareas),
+                                                        DRM_MEM_MAPS);
+                               if (!ctx_sareas) {
                                        clear_bit(bit, dev->ctx_bitmap);
                                        up(&dev->struct_sem);
                                        return -1;
@@ -115,11 +120,11 @@ static int drm_ctxbitmap_next( drm_device_t *dev )
                                dev->context_sareas[bit] = NULL;
                        } else {
                                /* max_context == 1 at this point */
-                               dev->context_sareas = drm_alloc(
-                                               dev->max_context * 
-                                               sizeof(*dev->context_sareas),
-                                               DRM_MEM_MAPS);
-                               if(!dev->context_sareas) {
+                               dev->context_sareas =
+                                   drm_alloc(dev->max_context *
+                                             sizeof(*dev->context_sareas),
+                                             DRM_MEM_MAPS);
+                               if (!dev->context_sareas) {
                                        clear_bit(bit, dev->ctx_bitmap);
                                        up(&dev->struct_sem);
                                        return -1;
@@ -142,26 +147,26 @@ static int drm_ctxbitmap_next( drm_device_t *dev )
  * Allocates and initialize drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * the drm_device::struct_sem lock.
  */
-int drm_ctxbitmap_init( drm_device_t *dev )
+int drm_ctxbitmap_init(drm_device_t * dev)
 {
        int i;
-       int temp;
+       int temp;
 
        down(&dev->struct_sem);
-       dev->ctx_bitmap = (unsigned long *) drm_alloc( PAGE_SIZE,
-                                                       DRM_MEM_CTXBITMAP );
-       if ( dev->ctx_bitmap == NULL ) {
+       dev->ctx_bitmap = (unsigned long *)drm_alloc(PAGE_SIZE,
+                                                    DRM_MEM_CTXBITMAP);
+       if (dev->ctx_bitmap == NULL) {
                up(&dev->struct_sem);
                return -ENOMEM;
        }
-       memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
+       memset((void *)dev->ctx_bitmap, 0, PAGE_SIZE);
        dev->context_sareas = NULL;
        dev->max_context = -1;
        up(&dev->struct_sem);
 
-       for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
-               temp = drm_ctxbitmap_next( dev );
-               DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
+       for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
+               temp = drm_ctxbitmap_next(dev);
+               DRM_DEBUG("drm_ctxbitmap_init : %d\n", temp);
        }
 
        return 0;
@@ -175,14 +180,14 @@ int drm_ctxbitmap_init( drm_device_t *dev )
  * Frees drm_device::ctx_bitmap and drm_device::context_sareas, while holding
  * the drm_device::struct_sem lock.
  */
-void drm_ctxbitmap_cleanup( drm_device_t *dev )
+void drm_ctxbitmap_cleanup(drm_device_t * dev)
 {
        down(&dev->struct_sem);
-       if( dev->context_sareas ) drm_free( dev->context_sareas,
-                                            sizeof(*dev->context_sareas) * 
-                                            dev->max_context,
-                                            DRM_MEM_MAPS );
-       drm_free( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
+       if (dev->context_sareas)
+               drm_free(dev->context_sareas,
+                        sizeof(*dev->context_sareas) *
+                        dev->max_context, DRM_MEM_MAPS);
+       drm_free((void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP);
        up(&dev->struct_sem);
 }
 
@@ -194,7 +199,7 @@ void drm_ctxbitmap_cleanup( drm_device_t *dev )
 
 /**
  * Get per-context SAREA.
- * 
+ *
  * \param inode device inode.
  * \param filp file pointer.
  * \param cmd command.
@@ -205,10 +210,10 @@ void drm_ctxbitmap_cleanup( drm_device_t *dev )
  * returns its handle.
  */
 int drm_getsareactx(struct inode *inode, struct file *filp,
-                    unsigned int cmd, unsigned long arg)
+                   unsigned int cmd, unsigned long arg)
 {
-       drm_file_t      *priv   = filp->private_data;
-       drm_device_t    *dev    = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_ctx_priv_map_t __user *argp = (void __user *)arg;
        drm_ctx_priv_map_t request;
        drm_map_t *map;
@@ -218,7 +223,8 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
                return -EFAULT;
 
        down(&dev->struct_sem);
-       if (dev->max_context < 0 || request.ctx_id >= (unsigned) dev->max_context) {
+       if (dev->max_context < 0
+           || request.ctx_id >= (unsigned)dev->max_context) {
                up(&dev->struct_sem);
                return -EINVAL;
        }
@@ -226,17 +232,17 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
        map = dev->context_sareas[request.ctx_id];
        up(&dev->struct_sem);
 
-       request.handle = 0;
-       list_for_each_entry(_entry, &dev->maplist->head,head) {
+       request.handle = NULL;
+       list_for_each_entry(_entry, &dev->maplist->head, head) {
                if (_entry->map == map) {
-                       request.handle = (void *)(unsigned long)_entry->user_token;
+                       request.handle =
+                           (void *)(unsigned long)_entry->user_token;
                        break;
                }
        }
-       if (request.handle == 0)
+       if (request.handle == NULL)
                return -EINVAL;
 
-
        if (copy_to_user(argp, &request, sizeof(request)))
                return -EFAULT;
        return 0;
@@ -244,7 +250,7 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
 
 /**
  * Set per-context SAREA.
- * 
+ *
  * \param inode device inode.
  * \param filp file pointer.
  * \param cmd command.
@@ -255,37 +261,37 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
  * drm_device::context_sareas with it.
  */
 int drm_setsareactx(struct inode *inode, struct file *filp,
-                    unsigned int cmd, unsigned long arg)
+                   unsigned int cmd, unsigned long arg)
 {
-       drm_file_t      *priv   = filp->private_data;
-       drm_device_t    *dev    = priv->head->dev;
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;
        drm_ctx_priv_map_t request;
        drm_map_t *map = NULL;
        drm_map_list_t *r_list = NULL;
        struct list_head *list;
 
        if (copy_from_user(&request,
-                          (drm_ctx_priv_map_t __user *)arg,
-                          sizeof(request)))
+                          (drm_ctx_priv_map_t __user *) arg, sizeof(request)))
                return -EFAULT;
 
        down(&dev->struct_sem);
        list_for_each(list, &dev->maplist->head) {
                r_list = list_entry(list, drm_map_list_t, head);
                if (r_list->map
-                   && r_list->user_token == (unsigned long) request.handle)
+                   && r_list->user_token == (unsigned long)request.handle)
                        goto found;
        }
-bad:
+      bad:
        up(&dev->struct_sem);
        return -EINVAL;
 
-found:
+      found:
        map = r_list->map;
-       if (!map) goto bad;
+       if (!map)
+               goto bad;
        if (dev->max_context < 0)
                goto bad;
-       if (request.ctx_id >= (unsigned) dev->max_context)
+       if (request.ctx_id >= (unsigned)dev->max_context)
                goto bad;
        dev->context_sareas[request.ctx_id] = map;
        up(&dev->struct_sem);
@@ -308,22 +314,21 @@ found:
  *
  * Attempt to set drm_device::context_flag.
  */
-static int drm_context_switch( drm_device_t *dev, int old, int new )
+static int drm_context_switch(drm_device_t * dev, int old, int new)
 {
-        if ( test_and_set_bit( 0, &dev->context_flag ) ) {
-                DRM_ERROR( "Reentering -- FIXME\n" );
-                return -EBUSY;
-        }
-
+       if (test_and_set_bit(0, &dev->context_flag)) {
+               DRM_ERROR("Reentering -- FIXME\n");
+               return -EBUSY;
+       }
 
-        DRM_DEBUG( "Context switch from %d to %d\n", old, new );
+       DRM_DEBUG("Context switch from %d to %d\n", old, new);
 
-        if ( new == dev->last_context ) {
-                clear_bit( 0, &dev->context_flag );
-                return 0;
-        }
+       if (new == dev->last_context) {
+               clear_bit(0, &dev->context_flag);
+               return 0;
+       }
 
-        return 0;
+       return 0;
 }
 
 /**
@@ -337,22 +342,22 @@ static int drm_context_switch( drm_device_t *dev, int old, int new )
  * hardware lock is held, clears the drm_device::context_flag and wakes up
  * drm_device::context_wait.
  */
-static int drm_context_switch_complete( drm_device_t *dev, int new )
+static int drm_context_switch_complete(drm_device_t * dev, int new)
 {
-        dev->last_context = new;  /* PRE/POST: This is the _only_ writer. */
-        dev->last_switch  = jiffies;
+       dev->last_context = new;        /* PRE/POST: This is the _only_ writer. */
+       dev->last_switch = jiffies;
 
-        if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
-                DRM_ERROR( "Lock isn't held after context switch\n" );
-        }
+       if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
+               DRM_ERROR("Lock isn't held after context switch\n");
+       }
 
-                               /* If a context switch is ever initiated
-                                   when the kernel holds the lock, release
-                                   that lock here. */
-        clear_bit( 0, &dev->context_flag );
-        wake_up( &dev->context_wait );
+       /* If a context switch is ever initiated
+          when the kernel holds the lock, release
+          that lock here. */
+       clear_bit(0, &dev->context_flag);
+       wake_up(&dev->context_wait);
 
-        return 0;
+       return 0;
 }
 
 /**
@@ -364,29 +369,28 @@ static int drm_context_switch_complete( drm_device_t *dev, int new )
  * \param arg user argument pointing to a drm_ctx_res structure.
  * \return zero on success or a negative number on failure.
  */
-int drm_resctx( struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg )
+int drm_resctx(struct inode *inode, struct file *filp,
+              unsigned int cmd, unsigned long arg)
 {
        drm_ctx_res_t res;
        drm_ctx_t __user *argp = (void __user *)arg;
        drm_ctx_t ctx;
        int i;
 
-       if ( copy_from_user( &res, argp, sizeof(res) ) )
+       if (copy_from_user(&res, argp, sizeof(res)))
                return -EFAULT;
 
-       if ( res.count >= DRM_RESERVED_CONTEXTS ) {
-               memset( &ctx, 0, sizeof(ctx) );
-               for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
+       if (res.count >= DRM_RESERVED_CONTEXTS) {
+               memset(&ctx, 0, sizeof(ctx));
+               for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
                        ctx.handle = i;
-                       if ( copy_to_user( &res.contexts[i],
-                                          &ctx, sizeof(ctx) ) )
+                       if (copy_to_user(&res.contexts[i], &ctx, sizeof(ctx)))
                                return -EFAULT;
                }
        }
        res.count = DRM_RESERVED_CONTEXTS;
 
-       if ( copy_to_user( argp, &res, sizeof(res) ) )
+       if (copy_to_user(argp, &res, sizeof(res)))
                return -EFAULT;
        return 0;
 }
@@ -402,58 +406,57 @@ int drm_resctx( struct inode *inode, struct file *filp,
  *
  * Get a new handle for the context and copy to userspace.
  */
-int drm_addctx( struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg )
+int drm_addctx(struct inode *inode, struct file *filp,
+              unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
-       drm_ctx_list_t * ctx_entry;
+       drm_ctx_list_t *ctx_entry;
        drm_ctx_t __user *argp = (void __user *)arg;
        drm_ctx_t ctx;
 
-       if ( copy_from_user( &ctx, argp, sizeof(ctx) ) )
+       if (copy_from_user(&ctx, argp, sizeof(ctx)))
                return -EFAULT;
 
-       ctx.handle = drm_ctxbitmap_next( dev );
-       if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
-                               /* Skip kernel's context and get a new one. */
-               ctx.handle = drm_ctxbitmap_next( dev );
+       ctx.handle = drm_ctxbitmap_next(dev);
+       if (ctx.handle == DRM_KERNEL_CONTEXT) {
+               /* Skip kernel's context and get a new one. */
+               ctx.handle = drm_ctxbitmap_next(dev);
        }
-       DRM_DEBUG( "%d\n", ctx.handle );
-       if ( ctx.handle == -1 ) {
-               DRM_DEBUG( "Not enough free contexts.\n" );
-                               /* Should this return -EBUSY instead? */
+       DRM_DEBUG("%d\n", ctx.handle);
+       if (ctx.handle == -1) {
+               DRM_DEBUG("Not enough free contexts.\n");
+               /* Should this return -EBUSY instead? */
                return -ENOMEM;
        }
 
-       if ( ctx.handle != DRM_KERNEL_CONTEXT )
-       {
+       if (ctx.handle != DRM_KERNEL_CONTEXT) {
                if (dev->driver->context_ctor)
                        dev->driver->context_ctor(dev, ctx.handle);
        }
 
-       ctx_entry = drm_alloc( sizeof(*ctx_entry), DRM_MEM_CTXLIST );
-       if ( !ctx_entry ) {
+       ctx_entry = drm_alloc(sizeof(*ctx_entry), DRM_MEM_CTXLIST);
+       if (!ctx_entry) {
                DRM_DEBUG("out of memory\n");
                return -ENOMEM;
        }
 
-       INIT_LIST_HEAD( &ctx_entry->head );
+       INIT_LIST_HEAD(&ctx_entry->head);
        ctx_entry->handle = ctx.handle;
        ctx_entry->tag = priv;
 
-       down( &dev->ctxlist_sem );
-       list_add( &ctx_entry->head, &dev->ctxlist->head );
+       down(&dev->ctxlist_sem);
+       list_add(&ctx_entry->head, &dev->ctxlist->head);
        ++dev->ctx_count;
-       up( &dev->ctxlist_sem );
+       up(&dev->ctxlist_sem);
 
-       if ( copy_to_user( argp, &ctx, sizeof(ctx) ) )
+       if (copy_to_user(argp, &ctx, sizeof(ctx)))
                return -EFAULT;
        return 0;
 }
 
-int drm_modctx( struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg )
+int drm_modctx(struct inode *inode, struct file *filp,
+              unsigned int cmd, unsigned long arg)
 {
        /* This does nothing */
        return 0;
@@ -468,19 +471,19 @@ int drm_modctx( struct inode *inode, struct file *filp,
  * \param arg user argument pointing to a drm_ctx structure.
  * \return zero on success or a negative number on failure.
  */
-int drm_getctx( struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg )
+int drm_getctx(struct inode *inode, struct file *filp,
+              unsigned int cmd, unsigned long arg)
 {
        drm_ctx_t __user *argp = (void __user *)arg;
        drm_ctx_t ctx;
 
-       if ( copy_from_user( &ctx, argp, sizeof(ctx) ) )
+       if (copy_from_user(&ctx, argp, sizeof(ctx)))
                return -EFAULT;
 
        /* This is 0, because we don't handle any context flags */
        ctx.flags = 0;
 
-       if ( copy_to_user( argp, &ctx, sizeof(ctx) ) )
+       if (copy_to_user(argp, &ctx, sizeof(ctx)))
                return -EFAULT;
        return 0;
 }
@@ -496,18 +499,18 @@ int drm_getctx( struct inode *inode, struct file *filp,
  *
  * Calls context_switch().
  */
-int drm_switchctx( struct inode *inode, struct file *filp,
-                   unsigned int cmd, unsigned long arg )
+int drm_switchctx(struct inode *inode, struct file *filp,
+                 unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
        drm_ctx_t ctx;
 
-       if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+       if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
                return -EFAULT;
 
-       DRM_DEBUG( "%d\n", ctx.handle );
-       return drm_context_switch( dev, dev->last_context, ctx.handle );
+       DRM_DEBUG("%d\n", ctx.handle);
+       return drm_context_switch(dev, dev->last_context, ctx.handle);
 }
 
 /**
@@ -521,18 +524,18 @@ int drm_switchctx( struct inode *inode, struct file *filp,
  *
  * Calls context_switch_complete().
  */
-int drm_newctx( struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg )
+int drm_newctx(struct inode *inode, struct file *filp,
+              unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
        drm_ctx_t ctx;
 
-       if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+       if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
                return -EFAULT;
 
-       DRM_DEBUG( "%d\n", ctx.handle );
-       drm_context_switch_complete( dev, ctx.handle );
+       DRM_DEBUG("%d\n", ctx.handle);
+       drm_context_switch_complete(dev, ctx.handle);
 
        return 0;
 }
@@ -548,42 +551,41 @@ int drm_newctx( struct inode *inode, struct file *filp,
  *
  * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
  */
-int drm_rmctx( struct inode *inode, struct file *filp,
-               unsigned int cmd, unsigned long arg )
+int drm_rmctx(struct inode *inode, struct file *filp,
+             unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
        drm_ctx_t ctx;
 
-       if ( copy_from_user( &ctx, (drm_ctx_t __user *)arg, sizeof(ctx) ) )
+       if (copy_from_user(&ctx, (drm_ctx_t __user *) arg, sizeof(ctx)))
                return -EFAULT;
 
-       DRM_DEBUG( "%d\n", ctx.handle );
-       if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) {
+       DRM_DEBUG("%d\n", ctx.handle);
+       if (ctx.handle == DRM_KERNEL_CONTEXT + 1) {
                priv->remove_auth_on_close = 1;
        }
-       if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
+       if (ctx.handle != DRM_KERNEL_CONTEXT) {
                if (dev->driver->context_dtor)
                        dev->driver->context_dtor(dev, ctx.handle);
-               drm_ctxbitmap_free( dev, ctx.handle );
+               drm_ctxbitmap_free(dev, ctx.handle);
        }
 
-       down( &dev->ctxlist_sem );
-       if ( !list_empty( &dev->ctxlist->head ) ) {
+       down(&dev->ctxlist_sem);
+       if (!list_empty(&dev->ctxlist->head)) {
                drm_ctx_list_t *pos, *n;
 
-               list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) {
-                       if ( pos->handle == ctx.handle ) {
-                               list_del( &pos->head );
-                               drm_free( pos, sizeof(*pos), DRM_MEM_CTXLIST );
+               list_for_each_entry_safe(pos, n, &dev->ctxlist->head, head) {
+                       if (pos->handle == ctx.handle) {
+                               list_del(&pos->head);
+                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
                                --dev->ctx_count;
                        }
                }
        }
-       up( &dev->ctxlist_sem );
+       up(&dev->ctxlist_sem);
 
        return 0;
 }
 
 /*@}*/
-
index 4a28c053c98bb232e13c8e683dcc54250e5dfbd9..2afab95ca036857aed145f03bcf93efc18943a06 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file drm_dma.
+ * \file drm_dma.c
  * DMA IOCTL and function support
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
 
 /**
  * Initialize the DMA data.
- * 
+ *
  * \param dev DRM device.
  * \return zero on success or a negative value on failure.
  *
  * Allocate and initialize a drm_device_dma structure.
  */
-int drm_dma_setup( drm_device_t *dev )
+int drm_dma_setup(drm_device_t * dev)
 {
        int i;
 
-       dev->dma = drm_alloc( sizeof(*dev->dma), DRM_MEM_DRIVER );
-       if ( !dev->dma )
+       dev->dma = drm_alloc(sizeof(*dev->dma), DRM_MEM_DRIVER);
+       if (!dev->dma)
                return -ENOMEM;
 
-       memset( dev->dma, 0, sizeof(*dev->dma) );
+       memset(dev->dma, 0, sizeof(*dev->dma));
 
-       for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
+       for (i = 0; i <= DRM_MAX_ORDER; i++)
                memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
 
        return 0;
@@ -67,14 +67,15 @@ int drm_dma_setup( drm_device_t *dev )
  * Free all pages associated with DMA buffers, the buffers and pages lists, and
  * finally the the drm_device::dma structure itself.
  */
-void drm_dma_takedown(drm_device_t *dev)
+void drm_dma_takedown(drm_device_t * dev)
 {
-       drm_device_dma_t  *dma = dev->dma;
-       int               i, j;
+       drm_device_dma_t *dma = dev->dma;
+       int i, j;
 
-       if (!dma) return;
+       if (!dma)
+               return;
 
-                               /* Clear dma buffers */
+       /* Clear dma buffers */
        for (i = 0; i <= DRM_MAX_ORDER; i++) {
                if (dma->bufs[i].seg_count) {
                        DRM_DEBUG("order %d: buf_count = %d,"
@@ -85,64 +86,63 @@ void drm_dma_takedown(drm_device_t *dev)
                        for (j = 0; j < dma->bufs[i].seg_count; j++) {
                                if (dma->bufs[i].seglist[j]) {
                                        drm_free_pages(dma->bufs[i].seglist[j],
-                                                       dma->bufs[i].page_order,
-                                                       DRM_MEM_DMA);
+                                                      dma->bufs[i].page_order,
+                                                      DRM_MEM_DMA);
                                }
                        }
                        drm_free(dma->bufs[i].seglist,
-                                 dma->bufs[i].seg_count
-                                 * sizeof(*dma->bufs[0].seglist),
-                                 DRM_MEM_SEGS);
+                                dma->bufs[i].seg_count
+                                * sizeof(*dma->bufs[0].seglist), DRM_MEM_SEGS);
                }
-               if (dma->bufs[i].buf_count) {
-                       for (j = 0; j < dma->bufs[i].buf_count; j++) {
+               if (dma->bufs[i].buf_count) {
+                       for (j = 0; j < dma->bufs[i].buf_count; j++) {
                                if (dma->bufs[i].buflist[j].dev_private) {
-                                       drm_free(dma->bufs[i].buflist[j].dev_private,
-                                                 dma->bufs[i].buflist[j].dev_priv_size,
-                                                 DRM_MEM_BUFS);
+                                       drm_free(dma->bufs[i].buflist[j].
+                                                dev_private,
+                                                dma->bufs[i].buflist[j].
+                                                dev_priv_size, DRM_MEM_BUFS);
                                }
                        }
-                       drm_free(dma->bufs[i].buflist,
-                                 dma->bufs[i].buf_count *
-                                 sizeof(*dma->bufs[0].buflist),
-                                 DRM_MEM_BUFS);
+                       drm_free(dma->bufs[i].buflist,
+                                dma->bufs[i].buf_count *
+                                sizeof(*dma->bufs[0].buflist), DRM_MEM_BUFS);
                }
        }
 
        if (dma->buflist) {
                drm_free(dma->buflist,
-                         dma->buf_count * sizeof(*dma->buflist),
-                         DRM_MEM_BUFS);
+                        dma->buf_count * sizeof(*dma->buflist), DRM_MEM_BUFS);
        }
 
        if (dma->pagelist) {
                drm_free(dma->pagelist,
-                         dma->page_count * sizeof(*dma->pagelist),
-                         DRM_MEM_PAGES);
+                        dma->page_count * sizeof(*dma->pagelist),
+                        DRM_MEM_PAGES);
        }
        drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
        dev->dma = NULL;
 }
 
-
 /**
  * Free a buffer.
  *
  * \param dev DRM device.
  * \param buf buffer to free.
- * 
+ *
  * Resets the fields of \p buf.
  */
-void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
+void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf)
 {
-       if (!buf) return;
+       if (!buf)
+               return;
 
-       buf->waiting  = 0;
-       buf->pending  = 0;
-       buf->filp     = NULL;
-       buf->used     = 0;
+       buf->waiting = 0;
+       buf->pending = 0;
+       buf->filp = NULL;
+       buf->used = 0;
 
-       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && waitqueue_active(&buf->dma_wait)) {
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE)
+           && waitqueue_active(&buf->dma_wait)) {
                wake_up_interruptible(&buf->dma_wait);
        }
 }
@@ -154,12 +154,13 @@ void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
  *
  * Frees each buffer associated with \p filp not already on the hardware.
  */
-void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp)
+void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp)
 {
        drm_device_dma_t *dma = dev->dma;
-       int              i;
+       int i;
 
-       if (!dma) return;
+       if (!dma)
+               return;
        for (i = 0; i < dma->buf_count; i++) {
                if (dma->buflist[i]->filp == filp) {
                        switch (dma->buflist[i]->list) {
@@ -176,5 +177,5 @@ void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp)
                }
        }
 }
-EXPORT_SYMBOL(drm_core_reclaim_buffers);
 
+EXPORT_SYMBOL(drm_core_reclaim_buffers);
index e8e8e42be4c700518fec28c680d95c6c9e8b7880..7857453c4f48cbc1caba399280dbc61a2b5f0e2c 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file drm_drawable.
+ * \file drm_drawable.c
  * IOCTLs for drawables
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
 
 /** No-op. */
 int drm_adddraw(struct inode *inode, struct file *filp,
-                unsigned int cmd, unsigned long arg)
+               unsigned int cmd, unsigned long arg)
 {
        drm_draw_t draw;
 
        draw.handle = 0;        /* NOOP */
        DRM_DEBUG("%d\n", draw.handle);
-       if (copy_to_user((drm_draw_t __user *)arg, &draw, sizeof(draw)))
+       if (copy_to_user((drm_draw_t __user *) arg, &draw, sizeof(draw)))
                return -EFAULT;
        return 0;
 }
 
 /** No-op. */
 int drm_rmdraw(struct inode *inode, struct file *filp,
-               unsigned int cmd, unsigned long arg)
+              unsigned int cmd, unsigned long arg)
 {
        return 0;               /* NOOP */
 }
index 041bb47b5c39fb4f0c71e6562a2be159b4394bb5..4dff7554eb083e5f4b5a41b19db41ba3014db3e9 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file drm_drv.
+ * \file drm_drv.c
  * Generic driver template
  *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
@@ -55,67 +55,67 @@ static int drm_version(struct inode *inode, struct file *filp,
                       unsigned int cmd, unsigned long arg);
 
 /** Ioctl table */
-static drm_ioctl_desc_t                  drm_ioctls[] = {
-       [DRM_IOCTL_NR(DRM_IOCTL_VERSION)]       = { drm_version,     0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)]    = { drm_getunique,   0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)]     = { drm_getmagic,    0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)]     = { drm_irq_by_busid, 0, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)]       = { drm_getmap,      0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)]    = { drm_getclient,   0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)]     = { drm_getstats,    0, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)]   = { drm_setversion,  0, 1 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)]    = { drm_setunique,   1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)]         = { drm_noop,        1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)]       = { drm_noop,        1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)]    = { drm_authmagic,   1, 1 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)]       = { drm_addmap_ioctl,1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)]        = { drm_rmmap_ioctl, 1, 0 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = { drm_setsareactx, 1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = { drm_getsareactx, 1, 0 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)]       = { drm_addctx,      1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)]        = { drm_rmctx,       1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)]       = { drm_modctx,      1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)]       = { drm_getctx,      1, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)]    = { drm_switchctx,   1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)]       = { drm_newctx,      1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)]       = { drm_resctx,      1, 0 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)]      = { drm_adddraw,     1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)]       = { drm_rmdraw,      1, 1 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_LOCK)]          = { drm_lock,        1, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)]        = { drm_unlock,      1, 0 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_FINISH)]        = { drm_noop,      1, 0 },
-
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)]      = { drm_addbufs,     1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)]     = { drm_markbufs,    1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { drm_infobufs,    1, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { drm_mapbufs,     1, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { drm_freebufs,    1, 0 },
+static drm_ioctl_desc_t drm_ioctls[] = {
+       [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = {drm_version, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = {drm_getunique, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = {drm_getmagic, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = {drm_irq_by_busid, 0, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = {drm_getmap, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = {drm_getclient, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = {drm_getstats, 0, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = {drm_setversion, 0, 1},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = {drm_setunique, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = {drm_noop, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = {drm_noop, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = {drm_authmagic, 1, 1},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = {drm_addmap_ioctl, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = {drm_rmmap_ioctl, 1, 0},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, 1, 0},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, 1, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = {drm_newctx, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = {drm_resctx, 1, 0},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = {drm_adddraw, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = {drm_rmdraw, 1, 1},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = {drm_lock, 1, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = {drm_unlock, 1, 0},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = {drm_noop, 1, 0},
+
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = {drm_addbufs, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = {drm_markbufs, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = {drm_infobufs, 1, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = {drm_mapbufs, 1, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = {drm_freebufs, 1, 0},
        /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
 
-       [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { drm_control,     1, 1 },
+       [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = {drm_control, 1, 1},
 
 #if __OS_HAS_AGP
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)]   = { drm_agp_acquire_ioctl, 1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)]   = { drm_agp_release_ioctl, 1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)]    = { drm_agp_enable_ioctl, 1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)]      = { drm_agp_info_ioctl, 1, 0 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)]     = { drm_agp_alloc,   1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)]      = { drm_agp_free,    1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)]      = { drm_agp_bind,    1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)]    = { drm_agp_unbind,  1, 1 },
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = {drm_agp_acquire_ioctl, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = {drm_agp_release_ioctl, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = {drm_agp_enable_ioctl, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = {drm_agp_info_ioctl, 1, 0},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = {drm_agp_alloc, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = {drm_agp_free, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = {drm_agp_bind, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = {drm_agp_unbind, 1, 1},
 #endif
 
-       [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)]      = { drm_sg_alloc,    1, 1 },
-       [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)]       = { drm_sg_free,     1, 1 },
+       [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = {drm_sg_alloc, 1, 1},
+       [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, 1, 1},
 
-       [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)]   = { drm_wait_vblank, 0, 0 },
+       [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0, 0},
 };
 
 #define DRIVER_IOCTL_COUNT     DRM_ARRAY_SIZE( drm_ioctls )
@@ -129,17 +129,17 @@ static drm_ioctl_desc_t             drm_ioctls[] = {
  *
  * \sa drm_device
  */
-int drm_takedown( drm_device_t *dev )
+int drm_takedown(drm_device_t * dev)
 {
        drm_magic_entry_t *pt, *next;
        drm_map_list_t *r_list;
        drm_vma_entry_t *vma, *vma_next;
        int i;
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
        if (dev->driver->pretakedown)
-         dev->driver->pretakedown(dev);
+               dev->driver->pretakedown(dev);
        DRM_DEBUG("driver pretakedown completed\n");
 
        if (dev->unique) {
@@ -148,95 +148,95 @@ int drm_takedown( drm_device_t *dev )
                dev->unique_len = 0;
        }
 
-       if ( dev->irq_enabled ) drm_irq_uninstall( dev );
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
 
-       down( &dev->struct_sem );
-       del_timer( &dev->timer );
+       down(&dev->struct_sem);
+       del_timer(&dev->timer);
 
-                               /* Clear pid list */
-       for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
-               for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {
+       /* Clear pid list */
+       for (i = 0; i < DRM_HASH_SIZE; i++) {
+               for (pt = dev->magiclist[i].head; pt; pt = next) {
                        next = pt->next;
-                       drm_free( pt, sizeof(*pt), DRM_MEM_MAGIC );
+                       drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
                }
                dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
        }
 
-                               /* Clear AGP information */
+       /* Clear AGP information */
        if (drm_core_has_AGP(dev) && dev->agp) {
                drm_agp_mem_t *entry;
                drm_agp_mem_t *nexte;
 
-                               /* Remove AGP resources, but leave dev->agp
-                                   intact until drv_cleanup is called. */
-               for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
+               /* Remove AGP resources, but leave dev->agp
+                  intact until drv_cleanup is called. */
+               for (entry = dev->agp->memory; entry; entry = nexte) {
                        nexte = entry->next;
-                       if ( entry->bound ) drm_unbind_agp( entry->memory );
-                       drm_free_agp( entry->memory, entry->pages );
-                       drm_free( entry, sizeof(*entry), DRM_MEM_AGPLISTS );
+                       if (entry->bound)
+                               drm_unbind_agp(entry->memory);
+                       drm_free_agp(entry->memory, entry->pages);
+                       drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
                }
                dev->agp->memory = NULL;
 
                if (dev->agp->acquired)
-                 drm_agp_release(dev);
+                       drm_agp_release(dev);
 
                dev->agp->acquired = 0;
-               dev->agp->enabled  = 0;
+               dev->agp->enabled = 0;
        }
        if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
                drm_sg_cleanup(dev->sg);
                dev->sg = NULL;
        }
 
-                               /* Clear vma list (only built for debugging) */
-       if ( dev->vmalist ) {
-               for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
+       /* Clear vma list (only built for debugging) */
+       if (dev->vmalist) {
+               for (vma = dev->vmalist; vma; vma = vma_next) {
                        vma_next = vma->next;
-                       drm_free( vma, sizeof(*vma), DRM_MEM_VMAS );
+                       drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
                }
                dev->vmalist = NULL;
        }
 
-       if( dev->maplist ) {
+       if (dev->maplist) {
                while (!list_empty(&dev->maplist->head)) {
                        struct list_head *list = dev->maplist->head.next;
                        r_list = list_entry(list, drm_map_list_t, head);
                        drm_rmmap_locked(dev, r_list->map);
                }
-       }
-
-       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist ) {
-               for ( i = 0 ; i < dev->queue_count ; i++ ) {
-                       if ( dev->queuelist[i] ) {
-                               drm_free( dev->queuelist[i],
-                                         sizeof(*dev->queuelist[0]),
-                                         DRM_MEM_QUEUES );
+       }
+
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
+               for (i = 0; i < dev->queue_count; i++) {
+                       if (dev->queuelist[i]) {
+                               drm_free(dev->queuelist[i],
+                                        sizeof(*dev->queuelist[0]),
+                                        DRM_MEM_QUEUES);
                                dev->queuelist[i] = NULL;
                        }
                }
-               drm_free( dev->queuelist,
-                         dev->queue_slots * sizeof(*dev->queuelist),
-                         DRM_MEM_QUEUES );
+               drm_free(dev->queuelist,
+                        dev->queue_slots * sizeof(*dev->queuelist),
+                        DRM_MEM_QUEUES);
                dev->queuelist = NULL;
        }
        dev->queue_count = 0;
 
        if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               drm_dma_takedown( dev );
+               drm_dma_takedown(dev);
 
-       if ( dev->lock.hw_lock ) {
-               dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
+       if (dev->lock.hw_lock) {
+               dev->sigdata.lock = dev->lock.hw_lock = NULL;   /* SHM removed */
                dev->lock.filp = NULL;
-               wake_up_interruptible( &dev->lock.lock_queue );
+               wake_up_interruptible(&dev->lock.lock_queue);
        }
-       up( &dev->struct_sem );
+       up(&dev->struct_sem);
 
        DRM_DEBUG("takedown completed\n");
        return 0;
 }
 
-
-
 /**
  * Module initialization. Called via init_module at module load time, or via
  * linux/init/main.c (this is not currently supported).
@@ -246,26 +246,28 @@ int drm_takedown( drm_device_t *dev )
  * Initializes an array of drm_device structures, and attempts to
  * initialize all available devices, using consecutive minors, registering the
  * stubs and initializing the AGP device.
- * 
+ *
  * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
  * after the initialization for driver customization.
  */
-int drm_init( struct drm_driver *driver )
+int drm_init(struct drm_driver *driver)
 {
        struct pci_dev *pdev = NULL;
        struct pci_device_id *pid;
        int i;
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
        drm_mem_init();
 
-       for (i=0; driver->pci_driver.id_table[i].vendor != 0; i++) {
+       for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
                pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
-               
-               pdev=NULL;
-               /* pass back in pdev to account for multiple identical cards */         
-               while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev)) != NULL) {
+
+               pdev = NULL;
+               /* pass back in pdev to account for multiple identical cards */
+               while ((pdev =
+                       pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
+                                      pid->subdevice, pdev)) != NULL) {
                        /* stealth mode requires a manual probe */
                        pci_dev_get(pdev);
                        drm_get_dev(pdev, pid, driver);
@@ -273,62 +275,63 @@ int drm_init( struct drm_driver *driver )
        }
        return 0;
 }
+
 EXPORT_SYMBOL(drm_init);
 
 /**
  * Called via cleanup_module() at module unload time.
  *
  * Cleans up all DRM device, calling takedown().
- * 
+ *
  * \sa drm_init
  */
-static void drm_cleanup( drm_device_t *dev )
+static void drm_cleanup(drm_device_t * dev)
 {
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
        if (!dev) {
                DRM_ERROR("cleanup called no dev\n");
                return;
        }
 
-       drm_takedown( dev );    
+       drm_takedown(dev);
 
        if (dev->maplist) {
                drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
                dev->maplist = NULL;
        }
 
-       drm_ctxbitmap_cleanup( dev );
-       
+       drm_ctxbitmap_cleanup(dev);
+
        if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
            dev->agp && dev->agp->agp_mtrr >= 0) {
                int retval;
-               retval = mtrr_del( dev->agp->agp_mtrr,
-                                  dev->agp->agp_info.aper_base,
-                                  dev->agp->agp_info.aper_size*1024*1024 );
-               DRM_DEBUG( "mtrr_del=%d\n", retval );
+               retval = mtrr_del(dev->agp->agp_mtrr,
+                                 dev->agp->agp_info.aper_base,
+                                 dev->agp->agp_info.aper_size * 1024 * 1024);
+               DRM_DEBUG("mtrr_del=%d\n", retval);
        }
-       
-       if (drm_core_has_AGP(dev) && dev->agp ) {
-               drm_free( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS );
+
+       if (drm_core_has_AGP(dev) && dev->agp) {
+               drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
                dev->agp = NULL;
        }
 
        if (dev->driver->postcleanup)
                dev->driver->postcleanup(dev);
-       
+
        drm_put_head(&dev->primary);
-       if ( drm_put_dev(dev) )
-               DRM_ERROR( "Cannot unload module\n" );
+       if (drm_put_dev(dev))
+               DRM_ERROR("Cannot unload module\n");
 }
 
-void drm_exit (struct drm_driver *driver)
+void drm_exit(struct drm_driver *driver)
 {
        int i;
        drm_device_t *dev = NULL;
        drm_head_t *head;
-       
-       DRM_DEBUG( "\n" );
+
+       DRM_DEBUG("\n");
 
        for (i = 0; i < drm_cards_limit; i++) {
                head = drm_heads[i];
@@ -336,9 +339,9 @@ void drm_exit (struct drm_driver *driver)
                        continue;
                if (!head->dev)
                        continue;
-               if (head->dev->driver!=driver)
+               if (head->dev->driver != driver)
                        continue;
-               dev=head->dev;
+               dev = head->dev;
        }
        if (dev) {
                /* release the pci driver */
@@ -346,32 +349,35 @@ void drm_exit (struct drm_driver *driver)
                        pci_dev_put(dev->pdev);
                drm_cleanup(dev);
        }
-       DRM_INFO( "Module unloaded\n" );
+       DRM_INFO("Module unloaded\n");
 }
+
 EXPORT_SYMBOL(drm_exit);
 
 /** File operations structure */
 static struct file_operations drm_stub_fops = {
        .owner = THIS_MODULE,
-       .open  = drm_stub_open
+       .open = drm_stub_open
 };
 
 static int __init drm_core_init(void)
 {
        int ret = -ENOMEM;
-       
-       drm_cards_limit = (drm_cards_limit < DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
-       drm_heads = drm_calloc(drm_cards_limit,
-                               sizeof(*drm_heads), DRM_MEM_STUB);
-       if(!drm_heads) 
+
+       drm_cards_limit =
+           (drm_cards_limit <
+            DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
+       drm_heads =
+           drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB);
+       if (!drm_heads)
                goto err_p1;
-       
+
        if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
                goto err_p1;
-       
+
        drm_class = drm_sysfs_create(THIS_MODULE, "drm");
        if (IS_ERR(drm_class)) {
-               printk (KERN_ERR "DRM: Error creating drm class.\n");
+               printk(KERN_ERR "DRM: Error creating drm class.\n");
                ret = PTR_ERR(drm_class);
                goto err_p2;
        }
@@ -382,35 +388,31 @@ static int __init drm_core_init(void)
                ret = -1;
                goto err_p3;
        }
-               
-       DRM_INFO( "Initialized %s %d.%d.%d %s\n",
-               CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL,
-               CORE_DATE);
+
+       DRM_INFO("Initialized %s %d.%d.%d %s\n",
+                CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
        return 0;
-err_p3:
+      err_p3:
        drm_sysfs_destroy(drm_class);
-err_p2:
+      err_p2:
        unregister_chrdev(DRM_MAJOR, "drm");
        drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
-err_p1:        
+      err_p1:
        return ret;
 }
 
-static void __exit drm_core_exit (void)
+static void __exit drm_core_exit(void)
 {
        remove_proc_entry("dri", NULL);
        drm_sysfs_destroy(drm_class);
 
        unregister_chrdev(DRM_MAJOR, "drm");
 
-       drm_free(drm_heads, sizeof(*drm_heads) *
-                               drm_cards_limit, DRM_MEM_STUB);
+       drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
 }
 
-
-module_init( drm_core_init );
-module_exit( drm_core_exit );
-
+module_init(drm_core_init);
+module_exit(drm_core_exit);
 
 /**
  * Get version information
@@ -423,8 +425,8 @@ module_exit( drm_core_exit );
  *
  * Fills in the version information in \p arg.
  */
-static int drm_version( struct inode *inode, struct file *filp,
-                       unsigned int cmd, unsigned long arg )
+static int drm_version(struct inode *inode, struct file *filp,
+                      unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -432,21 +434,19 @@ static int drm_version( struct inode *inode, struct file *filp,
        drm_version_t version;
        int ret;
 
-       if ( copy_from_user( &version, argp, sizeof(version) ) )
+       if (copy_from_user(&version, argp, sizeof(version)))
                return -EFAULT;
 
        /* version is a required function to return the personality module version */
        if ((ret = dev->driver->version(&version)))
                return ret;
-               
-       if ( copy_to_user( argp, &version, sizeof(version) ) )
+
+       if (copy_to_user(argp, &version, sizeof(version)))
                return -EFAULT;
        return 0;
 }
 
-
-
-/** 
+/**
  * Called whenever a process performs an ioctl on /dev/drm.
  *
  * \param inode device inode.
@@ -458,8 +458,8 @@ static int drm_version( struct inode *inode, struct file *filp,
  * Looks up the ioctl function in the ::ioctls table, checking for root
  * previleges if so required, and dispatches to the respective function.
  */
-int drm_ioctl( struct inode *inode, struct file *filp,
-               unsigned int cmd, unsigned long arg )
+int drm_ioctl(struct inode *inode, struct file *filp,
+             unsigned int cmd, unsigned long arg)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev = priv->head->dev;
@@ -468,40 +468,43 @@ int drm_ioctl( struct inode *inode, struct file *filp,
        unsigned int nr = DRM_IOCTL_NR(cmd);
        int retcode = -EINVAL;
 
-       atomic_inc( &dev->ioctl_count );
-       atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] );
+       atomic_inc(&dev->ioctl_count);
+       atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
        ++priv->ioctl_count;
 
-       DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
-                  current->pid, cmd, nr, (long)old_encode_dev(priv->head->device), 
-                  priv->authenticated );
-       
+       DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
+                 current->pid, cmd, nr,
+                 (long)old_encode_dev(priv->head->device),
+                 priv->authenticated);
+
        if (nr < DRIVER_IOCTL_COUNT)
                ioctl = &drm_ioctls[nr];
-       else if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
+       else if ((nr >= DRM_COMMAND_BASE)
+                && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
                ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
        else
                goto err_i1;
-       
+
        func = ioctl->func;
        /* is there a local override? */
        if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
                func = dev->driver->dma_ioctl;
-       
-       if ( !func ) {
-               DRM_DEBUG( "no function\n" );
+
+       if (!func) {
+               DRM_DEBUG("no function\n");
                retcode = -EINVAL;
-       } else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )||
-                   ( ioctl->auth_needed && !priv->authenticated ) ) {
+       } else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN)) ||
+                  (ioctl->auth_needed && !priv->authenticated)) {
                retcode = -EACCES;
        } else {
-               retcode = func( inode, filp, cmd, arg );
+               retcode = func(inode, filp, cmd, arg);
        }
-       
-err_i1:
-       atomic_dec( &dev->ioctl_count );
-       if (retcode) DRM_DEBUG( "ret = %x\n", retcode);
+
+      err_i1:
+       atomic_dec(&dev->ioctl_count);
+       if (retcode)
+               DRM_DEBUG("ret = %x\n", retcode);
        return retcode;
 }
-EXPORT_SYMBOL(drm_ioctl);
 
+EXPORT_SYMBOL(drm_ioctl);
index a1f4e9cd64edd17406cf2b6349c37a2039a9fac2..bf0a740122bf815cd3fbc9a7ed3710cb98af6848 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * \file drm_fops.
+ * \file drm_fops.c
  * File operations for DRM
- * 
+ *
  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  * \author Daryll Strauss <daryll@valinux.com>
  * \author Gareth Hughes <gareth@valinux.com>
 #include "drmP.h"
 #include <linux/poll.h>
 
-static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev);
+static int drm_open_helper(struct inode *inode, struct file *filp,
+                          drm_device_t * dev);
 
-static int drm_setup( drm_device_t *dev )
+static int drm_setup(drm_device_t * dev)
 {
        int i;
        int ret;
 
-       if (dev->driver->presetup)
-       {
-               ret=dev->driver->presetup(dev);
-               if (ret!=0) 
+       if (dev->driver->presetup) {
+               ret = dev->driver->presetup(dev);
+               if (ret != 0)
                        return ret;
        }
 
-       atomic_set( &dev->ioctl_count, 0 );
-       atomic_set( &dev->vma_count, 0 );
+       atomic_set(&dev->ioctl_count, 0);
+       atomic_set(&dev->vma_count, 0);
        dev->buf_use = 0;
-       atomic_set( &dev->buf_alloc, 0 );
+       atomic_set(&dev->buf_alloc, 0);
 
-       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-       {
-               i = drm_dma_setup( dev );
-               if ( i < 0 )
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
+               i = drm_dma_setup(dev);
+               if (i < 0)
                        return i;
        }
 
-       for ( i = 0 ; i < DRM_ARRAY_SIZE(dev->counts) ; i++ )
-               atomic_set( &dev->counts[i], 0 );
+       for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++)
+               atomic_set(&dev->counts[i], 0);
 
-       for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
+       for (i = 0; i < DRM_HASH_SIZE; i++) {
                dev->magiclist[i].head = NULL;
                dev->magiclist[i].tail = NULL;
        }
 
-       dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist),
-                                 DRM_MEM_CTXLIST);
-       if(dev->ctxlist == NULL) return -ENOMEM;
+       dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST);
+       if (dev->ctxlist == NULL)
+               return -ENOMEM;
        memset(dev->ctxlist, 0, sizeof(*dev->ctxlist));
        INIT_LIST_HEAD(&dev->ctxlist->head);
 
        dev->vmalist = NULL;
        dev->sigdata.lock = dev->lock.hw_lock = NULL;
-       init_waitqueue_head( &dev->lock.lock_queue );
+       init_waitqueue_head(&dev->lock.lock_queue);
        dev->queue_count = 0;
        dev->queue_reserved = 0;
        dev->queue_slots = 0;
@@ -91,24 +90,21 @@ static int drm_setup( drm_device_t *dev )
        dev->last_context = 0;
        dev->last_switch = 0;
        dev->last_checked = 0;
-       init_waitqueue_head( &dev->context_wait );
+       init_waitqueue_head(&dev->context_wait);
        dev->if_version = 0;
 
        dev->ctx_start = 0;
        dev->lck_start = 0;
 
-       dev->buf_rp = dev->buf;
-       dev->buf_wp = dev->buf;
-       dev->buf_end = dev->buf + DRM_BSZ;
        dev->buf_async = NULL;
-       init_waitqueue_head( &dev->buf_readers );
-       init_waitqueue_head( &dev->buf_writers );
+       init_waitqueue_head(&dev->buf_readers);
+       init_waitqueue_head(&dev->buf_writers);
 
-       DRM_DEBUG( "\n" );
+       DRM_DEBUG("\n");
 
        /*
         * The kernel's context could be created here, but is now created
-        * in drm_dma_enqueue.  This is more resource-efficient for
+        * in drm_dma_enqueue.  This is more resource-efficient for
         * hardware that does not do DMA, but may mean that
         * drm_select_queue fails between the time the interrupt is
         * initialized and the time the queues are initialized.
@@ -121,7 +117,7 @@ static int drm_setup( drm_device_t *dev )
 
 /**
  * Open file.
- * 
+ *
  * \param inode device inode
  * \param filp file pointer.
  * \return zero on success or a negative number on failure.
@@ -130,7 +126,7 @@ static int drm_setup( drm_device_t *dev )
  * increments the device open count. If the open count was previous at zero,
  * i.e., it's the first that the device is open, then calls setup().
  */
-int drm_open( struct inode *inode, struct file *filp )
+int drm_open(struct inode *inode, struct file *filp)
 {
        drm_device_t *dev = NULL;
        int minor = iminor(inode);
@@ -138,26 +134,27 @@ int drm_open( struct inode *inode, struct file *filp )
 
        if (!((minor >= 0) && (minor < drm_cards_limit)))
                return -ENODEV;
-               
+
        if (!drm_heads[minor])
                return -ENODEV;
 
        if (!(dev = drm_heads[minor]->dev))
                return -ENODEV;
-       
-       retcode = drm_open_helper( inode, filp, dev );
-       if ( !retcode ) {
-               atomic_inc( &dev->counts[_DRM_STAT_OPENS] );
-               spin_lock( &dev->count_lock );
-               if ( !dev->open_count++ ) {
-                       spin_unlock( &dev->count_lock );
-                       return drm_setup( dev );
+
+       retcode = drm_open_helper(inode, filp, dev);
+       if (!retcode) {
+               atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
+               spin_lock(&dev->count_lock);
+               if (!dev->open_count++) {
+                       spin_unlock(&dev->count_lock);
+                       return drm_setup(dev);
                }
-               spin_unlock( &dev->count_lock );
+               spin_unlock(&dev->count_lock);
        }
 
        return retcode;
 }
+
 EXPORT_SYMBOL(drm_open);
 
 /**
@@ -172,7 +169,7 @@ EXPORT_SYMBOL(drm_open);
  * data from its list and free it. Decreases the open count and if it reaches
  * zero calls takedown().
  */
-int drm_release( struct inode *inode, struct file *filp )
+int drm_release(struct inode *inode, struct file *filp)
 {
        drm_file_t *priv = filp->private_data;
        drm_device_t *dev;
@@ -181,7 +178,7 @@ int drm_release( struct inode *inode, struct file *filp )
        lock_kernel();
        dev = priv->head->dev;
 
-       DRM_DEBUG( "open_count = %d\n", dev->open_count );
+       DRM_DEBUG("open_count = %d\n", dev->open_count);
 
        if (dev->driver->prerelease)
                dev->driver->prerelease(dev, filp);
@@ -190,194 +187,199 @@ int drm_release( struct inode *inode, struct file *filp )
         * Begin inline drm_release
         */
 
-       DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n",
-                  current->pid, (long)old_encode_dev(priv->head->device), dev->open_count );
+       DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
+                 current->pid, (long)old_encode_dev(priv->head->device),
+                 dev->open_count);
+
+       if (priv->lock_count && dev->lock.hw_lock &&
+           _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
+           dev->lock.filp == filp) {
+               DRM_DEBUG("File %p released, freeing lock for context %d\n",
+                         filp, _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
 
-       if ( priv->lock_count && dev->lock.hw_lock &&
-            _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
-            dev->lock.filp == filp ) {
-               DRM_DEBUG( "File %p released, freeing lock for context %d\n",
-                       filp,
-                       _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
-               
                if (dev->driver->release)
                        dev->driver->release(dev, filp);
 
-               drm_lock_free( dev, &dev->lock.hw_lock->lock,
-                               _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
+               drm_lock_free(dev, &dev->lock.hw_lock->lock,
+                             _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
 
-                               /* FIXME: may require heavy-handed reset of
-                                   hardware at this point, possibly
-                                   processed via a callback to the X
-                                   server. */
-       }
-       else if ( dev->driver->release && priv->lock_count && dev->lock.hw_lock ) {
+               /* FIXME: may require heavy-handed reset of
+                  hardware at this point, possibly
+                  processed via a callback to the X
+                  server. */
+       } else if (dev->driver->release && priv->lock_count
+                  && dev->lock.hw_lock) {
                /* The lock is required to reclaim buffers */
-               DECLARE_WAITQUEUE( entry, current );
+               DECLARE_WAITQUEUE(entry, current);
 
-               add_wait_queue( &dev->lock.lock_queue, &entry );
+               add_wait_queue(&dev->lock.lock_queue, &entry);
                for (;;) {
                        __set_current_state(TASK_INTERRUPTIBLE);
-                       if ( !dev->lock.hw_lock ) {
+                       if (!dev->lock.hw_lock) {
                                /* Device has been unregistered */
                                retcode = -EINTR;
                                break;
                        }
-                       if ( drm_lock_take( &dev->lock.hw_lock->lock,
-                                            DRM_KERNEL_CONTEXT ) ) {
-                               dev->lock.filp      = filp;
+                       if (drm_lock_take(&dev->lock.hw_lock->lock,
+                                         DRM_KERNEL_CONTEXT)) {
+                               dev->lock.filp = filp;
                                dev->lock.lock_time = jiffies;
-                                atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
+                               atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
                                break;  /* Got lock */
                        }
-                               /* Contention */
+                       /* Contention */
                        schedule();
-                       if ( signal_pending( current ) ) {
+                       if (signal_pending(current)) {
                                retcode = -ERESTARTSYS;
                                break;
                        }
                }
                __set_current_state(TASK_RUNNING);
-               remove_wait_queue( &dev->lock.lock_queue, &entry );
-               if( !retcode ) {
+               remove_wait_queue(&dev->lock.lock_queue, &entry);
+               if (!retcode) {
                        if (dev->driver->release)
                                dev->driver->release(dev, filp);
-                       drm_lock_free( dev, &dev->lock.hw_lock->lock,
-                                       DRM_KERNEL_CONTEXT );
+                       drm_lock_free(dev, &dev->lock.hw_lock->lock,
+                                     DRM_KERNEL_CONTEXT);
                }
        }
-       
-       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) && !dev->driver->release)
-       {
+
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)
+           && !dev->driver->release) {
                dev->driver->reclaim_buffers(dev, filp);
        }
 
-       drm_fasync( -1, filp, 0 );
+       drm_fasync(-1, filp, 0);
 
-       down( &dev->ctxlist_sem );
-       if ( dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
+       down(&dev->ctxlist_sem);
+       if (dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
                drm_ctx_list_t *pos, *n;
 
-               list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) {
-                       if ( pos->tag == priv &&
-                            pos->handle != DRM_KERNEL_CONTEXT ) {
+               list_for_each_entry_safe(pos, n, &dev->ctxlist->head, head) {
+                       if (pos->tag == priv &&
+                           pos->handle != DRM_KERNEL_CONTEXT) {
                                if (dev->driver->context_dtor)
-                                       dev->driver->context_dtor(dev, pos->handle);
+                                       dev->driver->context_dtor(dev,
+                                                                 pos->handle);
 
-                               drm_ctxbitmap_free( dev, pos->handle );
+                               drm_ctxbitmap_free(dev, pos->handle);
 
-                               list_del( &pos->head );
-                               drm_free( pos, sizeof(*pos), DRM_MEM_CTXLIST );
+                               list_del(&pos->head);
+                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
                                --dev->ctx_count;
                        }
                }
        }
-       up( &dev->ctxlist_sem );
+       up(&dev->ctxlist_sem);
 
-       down( &dev->struct_sem );
-       if ( priv->remove_auth_on_close == 1 ) {
+       down(&dev->struct_sem);
+       if (priv->remove_auth_on_close == 1) {
                drm_file_t *temp = dev->file_first;
-               while ( temp ) {
+               while (temp) {
                        temp->authenticated = 0;
                        temp = temp->next;
                }
        }
-       if ( priv->prev ) {
+       if (priv->prev) {
                priv->prev->next = priv->next;
        } else {
-               dev->file_first  = priv->next;
+               dev->file_first = priv->next;
        }
-       if ( priv->next ) {
+       if (priv->next) {
                priv->next->prev = priv->prev;
        } else {
-               dev->file_last   = priv->prev;
+               dev->file_last = priv->prev;
        }
-       up( &dev->struct_sem );
-       
+       up(&dev->struct_sem);
+
        if (dev->driver->free_filp_priv)
                dev->driver->free_filp_priv(dev, priv);
 
-       drm_free( priv, sizeof(*priv), DRM_MEM_FILES );
+       drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
 
        /* ========================================================
         * End inline drm_release
         */
 
-       atomic_inc( &dev->counts[_DRM_STAT_CLOSES] );
-       spin_lock( &dev->count_lock );
-       if ( !--dev->open_count ) {
-               if ( atomic_read( &dev->ioctl_count ) || dev->blocked ) {
-                       DRM_ERROR( "Device busy: %d %d\n",
-                                  atomic_read( &dev->ioctl_count ),
-                                  dev->blocked );
-                       spin_unlock( &dev->count_lock );
+       atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
+       spin_lock(&dev->count_lock);<