As I was doing some minor cleanups in the mach64 drm in the new branch, I
made some additional search and replace conversions of the mach64 DRM to
the os independence macros (I couldn't restrain myself ;) ). However, I
want to share what I've done so far and get some feedback, since there are
a couple of issues here:

1.  We are currently using access_ok() to check the vertex buffers
submitted by the client before copying them to (what will be) private
kernel buffers.  There was only a macro in drm_os_linux.h for
DRM_VERIFYAREA_READ(), so I added DRM_ACCESSOK_READ().  I don't really
know the details of what the difference is between verify_area() and
access_ok() (Jose added that code based on a suggestion from Linus, I
think), but I believe access_ok() is intended as a security check, which
is the reason for the copy.  It seems that this all maps to the same thing
for *BSD at the moment -- i.e. the unchecked macros aren't implemented
differently from the checked ones, right?

2. The Mach64 driver makes heavy use of the list struct and macros from
linux/list.h.  I moved the define for list_for_each_safe() (needed for
older 2.4 Linux kernels) from mach64_drv.h to drmP.h, since that has
already been added in XFree86 CVS (I think the i8x0 drm uses it now also).  
I also removed the include of linux/list.h from the mach64 driver, since
it already gets included (indirectly?) through the drm headers.  However,
it looks like an analogue of linux/list.h might need to be added to the
BSD drm headers.  The only wrinkle there is that it also uses 
linux/prefetch.h.

3. We still need to work out the wrapper/alternative to 
pci_alloc_consistent() and friends.

4. As I mentioned before, the interrupt code is not converted, but it's
currently unused.

At any rate, the remainder of the attached patch is trivial additions of
DRM_ERR, DRM_CURRENTPID, etc. and a couple of whitespace tweaks.

-- 
Leif Delgass 
http://www.retinalburn.net
Index: linux/drm/kernel/drmP.h
===================================================================
RCS file: 
/cvsroot/dri/xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h,v
retrieving revision 1.56
diff -u -r1.56 drmP.h
--- linux/drm/kernel/drmP.h     11 Jan 2003 20:58:20 -0000      1.56
+++ linux/drm/kernel/drmP.h     18 Feb 2003 00:33:29 -0000
@@ -166,6 +166,12 @@
 #define pte_unmap(pte)
 #endif
 
+#ifndef list_for_each_safe
+#define list_for_each_safe(pos, n, head)                               \
+       for (pos = (head)->next, n = pos->next; pos != (head);          \
+               pos = n, n = pos->next)
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
 static inline struct page * vmalloc_to_page(void * vmalloc_addr)
 {
Index: linux/drm/kernel/drm_os_linux.h
===================================================================
RCS file: 
/cvsroot/dri/xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm_os_linux.h,v

retrieving revision 1.5
diff -u -r1.5 drm_os_linux.h
--- linux/drm/kernel/drm_os_linux.h     9 Oct 2002 16:29:01 -0000       1.5
+++ linux/drm/kernel/drm_os_linux.h     18 Feb 2003 00:33:30 -0000
@@ -34,6 +34,8 @@
 /* Macros for copyfrom user, but checking readability only once */
 #define DRM_VERIFYAREA_READ( uaddr, size )             \
        verify_area( VERIFY_READ, uaddr, size )
+#define DRM_ACCESSOK_READ( uaddr, size )               \
+       access_ok( VERIFY_READ, uaddr, size )
 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)         \
        __copy_from_user(arg1, arg2, arg3)
 #define DRM_GET_USER_UNCHECKED(val, uaddr)             \
@@ -60,28 +62,28 @@
 
 #define DRM_HZ HZ
 
-#define DRM_WAIT_ON( ret, queue, timeout, condition )  \
-do {                                                   \
-       DECLARE_WAITQUEUE(entry, current);              \
-       unsigned long end = jiffies + (timeout);        \
-       add_wait_queue(&(queue), &entry);               \
-                                                       \
-       for (;;) {                                      \
-               current->state = TASK_INTERRUPTIBLE;    \
-               if (condition)                          \
-                       break;                          \
-               if((signed)(end - jiffies) <= 0) {      \
-                       ret = -EBUSY;                   \
-                       break;                          \
-               }                                       \
+#define DRM_WAIT_ON( ret, queue, timeout, condition )          \
+do {                                                           \
+       DECLARE_WAITQUEUE(entry, current);                      \
+       unsigned long end = jiffies + (timeout);                \
+       add_wait_queue(&(queue), &entry);                       \
+                                                               \
+       for (;;) {                                              \
+               current->state = TASK_INTERRUPTIBLE;            \
+               if (condition)                                  \
+                       break;                                  \
+               if((signed)(end - jiffies) <= 0) {              \
+                       ret = -EBUSY;                           \
+                       break;                                  \
+               }                                               \
                schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
-               if (signal_pending(current)) {          \
-                       ret = -EINTR;                   \
-                       break;                          \
-               }                                       \
-       }                                               \
-       current->state = TASK_RUNNING;                  \
-       remove_wait_queue(&(queue), &entry);            \
+               if (signal_pending(current)) {                  \
+                       ret = -EINTR;                           \
+                       break;                                  \
+               }                                               \
+       }                                                       \
+       current->state = TASK_RUNNING;                          \
+       remove_wait_queue(&(queue), &entry);                    \
 } while (0)
 
 
Index: shared/drm/kernel/mach64_dma.c
===================================================================
RCS file: 
/cvsroot/dri/xc/xc/programs/Xserver/hw/xfree86/os-support/shared/drm/kernel/Attic/mach64_dma.c,v

retrieving revision 1.1.2.2
diff -u -r1.1.2.2 mach64_dma.c
--- shared/drm/kernel/mach64_dma.c      17 Feb 2003 01:58:46 -0000      1.1.2.2
+++ shared/drm/kernel/mach64_dma.c      18 Feb 2003 00:33:30 -0000
@@ -36,7 +36,6 @@
 #include "mach64_drm.h"
 #include "mach64_drv.h"
 
-#include <linux/interrupt.h>   /* For task queue support */
 
 #if MACH64_INTERRUPTS
 
@@ -138,11 +137,11 @@
                slots = (MACH64_READ( MACH64_FIFO_STAT ) &
                         MACH64_FIFO_SLOT_MASK);
                if ( slots <= (0x8000 >> entries) ) return 0;
-               udelay( 1 );
+               DRM_UDELAY( 1 );
        }
 
        DRM_INFO( "%s failed! slots=%d entries=%d\n", __FUNCTION__, slots, entries );
-       return -EBUSY;
+       return DRM_ERR(EBUSY);
 }
 
 int mach64_do_wait_for_idle( drm_mach64_private_t *dev_priv )
@@ -156,13 +155,13 @@
                if ( !(MACH64_READ( MACH64_GUI_STAT ) & MACH64_GUI_ACTIVE) ) {
                        return 0;
                }
-               udelay( 1 );
+               DRM_UDELAY( 1 );
        }
 
        DRM_INFO( "%s failed! GUI_STAT=0x%08x\n", __FUNCTION__, 
                   MACH64_READ( MACH64_GUI_STAT ) );
        mach64_dump_ring_info( dev_priv );
-       return -EBUSY;
+       return DRM_ERR(EBUSY);
 }
 
 int mach64_wait_ring( drm_mach64_private_t *dev_priv, int n )
@@ -178,13 +177,13 @@
                        }
                        return 0;
                }
-               udelay( 1 );
+               DRM_UDELAY( 1 );
        }
 
        /* FIXME: This is being ignored... */
        DRM_ERROR( "failed!\n" );
        mach64_dump_ring_info( dev_priv );
-       return -EBUSY;
+       return DRM_ERR(EBUSY);
 }
 
 /* Wait until all DMA requests have been processed... */
@@ -211,13 +210,13 @@
                        head = ring->head;
                        i = 0;
                }
-               udelay( 1 );
+               DRM_UDELAY( 1 );
        }
 
        DRM_INFO( "%s failed! GUI_STAT=0x%08x\n", __FUNCTION__, 
                   MACH64_READ( MACH64_GUI_STAT ) );
        mach64_dump_ring_info( dev_priv );
-       return -EBUSY;
+       return DRM_ERR(EBUSY);
 }
 
 static void mach64_ring_reset( drm_mach64_private_t *dev_priv )
@@ -537,7 +536,7 @@
        cpu_addr_data = pci_alloc_consistent( dev->pdev, 0x1000, &data_handle );
        if (!cpu_addr_data || !data_handle) {
                DRM_INFO( "data-memory allocation failed!\n" );
-               return -ENOMEM;
+               return DRM_ERR(ENOMEM);
        } else {
                data = (u32 *) cpu_addr_data;
                data_addr = (u32) data_handle;
@@ -571,7 +570,7 @@
                        pci_free_consistent( dev->pdev, 0x1000, 
                                             cpu_addr_data, data_handle );
                        DRM_INFO( "returning ...\n" );
-                       return -EIO;
+                       return DRM_ERR(EIO);
                }
        }
 
@@ -612,7 +611,7 @@
                DRM_DEBUG( " data[%d] = 0x%08x\n", i, data[i] );
        }
 
-       mach64_flush_write_combine();
+       DRM_READMEMORYBARRIER();
 
        DRM_DEBUG( "waiting for idle...\n" );
        if ( ( i = mach64_do_wait_for_idle( dev_priv ) ) ) {
@@ -701,7 +700,6 @@
 static int mach64_do_dma_init( drm_device_t *dev, drm_mach64_init_t *init )
 {
        drm_mach64_private_t *dev_priv;
-       struct list_head *list;
        u32 tmp;
        int i, ret;
 
@@ -709,7 +707,7 @@
 
        dev_priv = DRM(alloc)( sizeof(drm_mach64_private_t), DRM_MEM_DRIVER );
        if ( dev_priv == NULL )
-               return -ENOMEM;
+               return DRM_ERR(ENOMEM);
        
        memset( dev_priv, 0, sizeof(drm_mach64_private_t) );
 
@@ -747,34 +745,27 @@
         atomic_set(&dev_priv->intr_bm_complete, 0);                
 #endif
 
-       list_for_each(list, &dev->maplist->head) {
-               drm_map_list_t *r_list = (drm_map_list_t *)list;
-               if( r_list->map && 
-                   r_list->map->type == _DRM_SHM &&
-                    r_list->map->flags & _DRM_CONTAINS_LOCK ) {
-                       dev_priv->sarea = r_list->map;
-                       break;
-               }
-       }
+       DRM_GETSAREA();
+
        if (!dev_priv->sarea) {
                DRM_ERROR("can not find sarea!\n");
                dev->dev_private = (void *)dev_priv;
                mach64_do_cleanup_dma(dev);
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
        DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
        if (!dev_priv->fb) {
                DRM_ERROR("can not find frame buffer map!\n");
                dev->dev_private = (void *)dev_priv;
                mach64_do_cleanup_dma(dev);
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if (!dev_priv->mmio) {
                DRM_ERROR("can not find mmio map!\n");
                dev->dev_private = (void *)dev_priv;
                mach64_do_cleanup_dma(dev);
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        dev_priv->sarea_priv = (drm_mach64_sarea_t *)
@@ -787,7 +778,7 @@
                        DRM_ERROR( "can not find dma buffer map!\n" );
                        dev->dev_private = (void *)dev_priv;
                        mach64_do_cleanup_dma( dev );
-                       return -EINVAL;
+                       return DRM_ERR(EINVAL);
                }
                DRM_IOREMAP( dev_priv->buffers );
                if ( !dev_priv->buffers->handle ) {
@@ -795,7 +786,7 @@
                                   " dma buffer\n" );
                        dev->dev_private = (void *) dev_priv;
                        mach64_do_cleanup_dma( dev );
-                       return -ENOMEM;
+                       return DRM_ERR(ENOMEM);
                }
                DRM_FIND_MAP( dev_priv->agp_textures,
                              init->agp_textures_offset );
@@ -803,7 +794,7 @@
                        DRM_ERROR("could not find agp texture region!\n");
                        dev->dev_private = (void *)dev_priv;
                        mach64_do_cleanup_dma( dev );
-                       return -EINVAL;
+                       return DRM_ERR(EINVAL);
                }
        }
 
@@ -847,7 +838,7 @@
 
        if (!dev_priv->ring.start || !dev_priv->ring.handle) {
                DRM_ERROR( "Allocating dma descriptor ring failed\n");
-               return -ENOMEM;
+               return DRM_ERR(ENOMEM);
        } else {
                dev_priv->ring.start_addr = (u32) dev_priv->ring.handle;
                memset( dev_priv->ring.start, 0x0, 0x4000 );
@@ -984,7 +975,7 @@
                                  head, ring->tail, buf_addr, (eol ? "eol" : ""));
                        mach64_dump_ring_info( dev_priv );
                        mach64_do_engine_reset( dev_priv );
-                       return -EINVAL;
+                       return DRM_ERR(EINVAL);
                }
 
                /* Hand feed the buffer to the card via MMIO, waiting for the fifo 
@@ -1106,7 +1097,7 @@
                return mach64_do_cleanup_dma( dev );
        }
                
-       return -EINVAL;
+       return DRM_ERR(EINVAL);
 }
 
 int mach64_dma_idle( DRM_IOCTL_ARGS )
@@ -1164,7 +1155,7 @@
                if ((entry = 
                     (drm_mach64_freelist_t *) 
DRM(alloc)(sizeof(drm_mach64_freelist_t), 
                                                          DRM_MEM_BUFLISTS)) == NULL)
-                       return -ENOMEM;
+                       return DRM_ERR(ENOMEM);
                memset( entry, 0, sizeof(drm_mach64_freelist_t) );
                entry->buf = dma->buflist[i];
                ptr = &entry->list;
@@ -1311,7 +1302,7 @@
                                        return entry->buf;
                                }
                        }
-                       udelay( 1 );
+                       DRM_UDELAY( 1 );
                }
                mach64_dump_ring_info( dev_priv );
                DRM_ERROR( "timeout waiting for buffers: ring head_addr: 0x%08x head: 
%d tail: %d\n", ring->head_addr, ring->head, ring->tail );
@@ -1340,19 +1331,19 @@
        for ( i = d->granted_count ; i < d->request_count ; i++ ) {
                buf = mach64_freelist_get( dev_priv );
 #if MACH64_EXTRA_CHECKING
-               if ( !buf ) return -EFAULT;
+               if ( !buf ) return DRM_ERR(EFAULT);
 #else
-               if ( !buf ) return -EAGAIN;
+               if ( !buf ) return DRM_ERR(EAGAIN);
 #endif
 
-               buf->pid = current->pid;
+               buf->pid = DRM_CURRENTPID;
 
-               if ( copy_to_user( &d->request_indices[i], &buf->idx,
+               if ( DRM_COPY_TO_USER( &d->request_indices[i], &buf->idx,
                                   sizeof(buf->idx) ) )
-                       return -EFAULT;
-               if ( copy_to_user( &d->request_sizes[i], &buf->total,
+                       return DRM_ERR(EFAULT);
+               if ( DRM_COPY_TO_USER( &d->request_sizes[i], &buf->total,
                                   sizeof(buf->total) ) )
-                       return -EFAULT;
+                       return DRM_ERR(EFAULT);
 
                d->granted_count++;
        }
@@ -1375,8 +1366,8 @@
         if ( d.send_count != 0 ) 
         {
                DRM_ERROR( "Process %d trying to send %d buffers via drmDMA\n",
-                          current->pid, d.send_count );
-               return -EINVAL;
+                          DRM_CURRENTPID, d.send_count );
+               return DRM_ERR(EINVAL);
        }
 
        /* We'll send you buffers.
@@ -1384,8 +1375,8 @@
        if ( d.request_count < 0 || d.request_count > dma->buf_count ) 
        {
                DRM_ERROR( "Process %d trying to get %d buffers (of %d max)\n",
-                          current->pid, d.request_count, dma->buf_count );
-               ret = -EINVAL;
+                          DRM_CURRENTPID, d.request_count, dma->buf_count );
+               ret = DRM_ERR(EINVAL);
        }
         
        d.granted_count = 0;
Index: shared/drm/kernel/mach64_drv.h
===================================================================
RCS file: 
/cvsroot/dri/xc/xc/programs/Xserver/hw/xfree86/os-support/shared/drm/kernel/Attic/mach64_drv.h,v

retrieving revision 1.1.2.2
diff -u -r1.1.2.2 mach64_drv.h
--- shared/drm/kernel/mach64_drv.h      17 Feb 2003 01:58:46 -0000      1.1.2.2
+++ shared/drm/kernel/mach64_drv.h      18 Feb 2003 00:33:31 -0000
@@ -33,15 +33,6 @@
 #ifndef __MACH64_DRV_H__
 #define __MACH64_DRV_H__
 
-#include <linux/delay.h>
-#include <linux/list.h>
-
-/* Some early 2.4.x kernels need this */
-#ifndef list_for_each_safe
-#define list_for_each_safe(pos, n, head) \
-       for (pos = (head)->next, n = pos->next; pos != (head); \
-               pos = n, n = pos->next)
-#endif
 
 /* FIXME: remove these when not needed */
 /* Development driver options */
@@ -586,10 +577,10 @@
 #define LOCK_TEST_WITH_RETURN( dev )                                   \
 do {                                                                   \
        if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||           \
-            dev->lock.pid != current->pid ) {                          \
+            dev->lock.pid != DRM_CURRENTPID ) {                        \
                DRM_ERROR( "%s called without lock held\n",             \
                           __FUNCTION__ );                              \
-               return -EINVAL;                                         \
+               return DRM_ERR(EINVAL);                                 \
        }                                                               \
 } while (0)
 
@@ -605,12 +596,12 @@
                        mach64_update_ring_snapshot( dev_priv );                       
 \
                        if ( ring->space >= ring->high_mark )                          
 \
                                goto __ring_space_done;                                
 \
-                       udelay( 1 );                                                   
 \
+                       DRM_UDELAY( 1 );                                               
+         \
                }                                                                      
 \
                DRM_ERROR( "ring space check failed!\n" );                             
 \
                DRM_INFO( "ring: head addr: 0x%08x head: %d tail: %d space: %d\n",     
 \
                        ring->head_addr, ring->head, ring->tail, ring->space );        
 \
-               return -EBUSY;                                                         
 \
+               return DRM_ERR(EBUSY);                                                 
+ \
        }                                                                              
 \
  __ring_space_done:                                                                   
 \
 } while (0)
@@ -639,8 +630,6 @@
  * DMA descriptor ring macros
  */
 
-#define mach64_flush_write_combine()   mb()
-
 #define RING_LOCALS                                                                   
 \
        int _ring_tail, _ring_write; unsigned int _ring_mask; volatile u32 *_ring
 
@@ -729,9 +718,9 @@
                DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",     \
                          _ring_write, _ring_tail );                    \
        }                                                               \
-       mach64_flush_write_combine();                                   \
+       DRM_READMEMORYBARRIER();                                        \
        mach64_clear_dma_eol( &_ring[(_ring_tail - 2) & _ring_mask] );  \
-       mach64_flush_write_combine();                                   \
+       DRM_READMEMORYBARRIER();                                        \
        dev_priv->ring.tail = _ring_write;                              \
        mach64_ring_tick( dev_priv, &(dev_priv)->ring );                \
 } while (0)
@@ -766,14 +755,14 @@
 #if MACH64_EXTRA_CHECKING
        if (list_empty(&dev_priv->pending)) {
                DRM_ERROR("Empty pending list in %s\n", __FUNCTION__);
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 #endif
        ptr = dev_priv->pending.prev;
        *entry = list_entry(ptr, drm_mach64_freelist_t, list);
        while ((*entry)->buf != buf) {
                if (ptr == &dev_priv->pending) {
-                       return -EFAULT;
+                       return DRM_ERR(EFAULT);
                }
                ptr = ptr->prev;
                *entry = list_entry(ptr, drm_mach64_freelist_t, list);
@@ -799,14 +788,14 @@
        if (_buf == NULL) {                                             \
                DRM_ERROR("%s: couldn't get buffer in DMAGETPTR\n",     \
                           __FUNCTION__ );                              \
-               return -EAGAIN;                                         \
+               return DRM_ERR(EAGAIN);                                 \
        }                                                               \
        if (_buf->pending) {                                            \
                DRM_ERROR("%s: pending buf in DMAGETPTR\n",             \
                           __FUNCTION__ );                              \
-               return -EFAULT;                                         \
+               return DRM_ERR(EFAULT);                                 \
        }                                                               \
-       _buf->pid = current->pid;                                       \
+       _buf->pid = DRM_CURRENTPID;                                     \
        _outcount = 0;                                                  \
                                                                        \
         _buf_wptr = GETBUFPTR( _buf );                                 \
@@ -835,7 +824,7 @@
        if (_buf->used <= 0) {                                                         
      \
                DRM_ERROR( "DMAADVANCE() in %s: sending empty buf %d\n",               
      \
                                   __FUNCTION__, _buf->idx );                          
      \
-               return -EFAULT;                                                        
      \
+               return DRM_ERR(EFAULT);                                                
+      \
        }                                                                              
      \
        if (_buf->pending) {                                                           
      \
                 /* This is a resued buffer, so we need to find it in the pending list 
*/     \
@@ -848,13 +837,13 @@
                if (_entry->discard) {                                                 
      \
                        DRM_ERROR( "DMAADVANCE() in %s: sending discarded pending buf 
%d\n", \
                                   __FUNCTION__, _buf->idx );                          
      \
-                       return -EFAULT;                                                
      \
+                       return DRM_ERR(EFAULT);                                        
+      \
                }                                                                      
      \
        } else {                                                                       
      \
                if (list_empty(&dev_priv->placeholders)) {                             
      \
                        DRM_ERROR( "DMAADVANCE() in %s: empty placeholder list\n",     
      \
                                __FUNCTION__ );                                        
      \
-                       return -EFAULT;                                                
      \
+                       return DRM_ERR(EFAULT);                                        
+      \
                }                                                                      
      \
                ptr = dev_priv->placeholders.next;                                     
      \
                list_del(ptr);                                                         
      \
@@ -930,12 +919,12 @@
        if (_buf->used <= 0) {                                                         
 \
                DRM_ERROR( "DMAADVANCEHOSTDATA() in %s: sending empty buf %d\n",       
 \
                                   __FUNCTION__, _buf->idx );                          
 \
-               return -EFAULT;                                                        
 \
+               return DRM_ERR(EFAULT);                                                
+ \
        }                                                                              
 \
        if (list_empty(&dev_priv->placeholders)) {                                     
 \
                DRM_ERROR( "%s: empty placeholder list in DMAADVANCEHOSTDATA()\n",     
 \
                           __FUNCTION__ );                                             
 \
-               return -EFAULT;                                                        
 \
+               return DRM_ERR(EFAULT);                                                
+ \
        }                                                                              
 \
                                                                                       
 \
         ptr = dev_priv->placeholders.next;                                            
 \
Index: shared/drm/kernel/mach64_state.c
===================================================================
RCS file: 
/cvsroot/dri/xc/xc/programs/Xserver/hw/xfree86/os-support/shared/drm/kernel/Attic/mach64_state.c,v

retrieving revision 1.1.2.2
diff -u -r1.1.2.2 mach64_state.c
--- shared/drm/kernel/mach64_state.c    17 Feb 2003 01:58:46 -0000      1.1.2.2
+++ shared/drm/kernel/mach64_state.c    18 Feb 2003 00:33:31 -0000
@@ -34,7 +34,6 @@
 #include "drm.h"
 #include "mach64_drm.h"
 #include "mach64_drv.h"
-#include "drm.h"
 
 
 /* ================================================================
@@ -212,7 +211,7 @@
                fb_bpp = MACH64_DATATYPE_ARGB8888;
                break;
        default:
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
        switch ( dev_priv->depth_bpp ) {
        case 16:
@@ -223,7 +222,7 @@
                depth_bpp = MACH64_DATATYPE_ARGB8888;
                break;
        default:
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        if ( !nbox ) 
@@ -469,16 +468,16 @@
 {
        unsigned long copied = 0;
 
-       if ( access_ok( VERIFY_READ, from, n ) ) {
+       if ( DRM_ACCESSOK_READ( from, n ) ) {
                n >>= 2;
-       
+
                while ( n ) {
                        u32 data, reg, count;
 
-                       if ( __get_user( data, from++ ) )
+                       if ( DRM_GET_USER_UNCHECKED( data, from++ ) )
                                break;
                        n--;
-               
+
                        reg = le32_to_cpu(data);
                        count = (reg >> 16) + 1;
                        if( count <= n ) {
@@ -488,9 +487,10 @@
                                /* This is an exact match of Mach64's Setup Engine 
registers,
                                 * excluding SETUP_CNTL (1_C1).
                                 */
-                               if( (reg >= 0x0190 && reg < 0x01c1) || (reg >= 0x01ca 
&& reg <= 0x01cf) ) {
+                               if( (reg >= 0x0190 && reg <  0x01c1) || 
+                                   (reg >= 0x01ca && reg <= 0x01cf) ) {
                                        *to++ = data;
-                                       __copy_from_user( to, from, count << 2 );
+                                       DRM_COPY_FROM_USER_UNCHECKED( to, from, count 
+<< 2 );
                                        to += count;
                                        copied += 1 + count;
                                } else {
@@ -530,7 +530,7 @@
                if (copy_buf == NULL) {
                        DRM_ERROR("%s: couldn't get buffer in DMAGETPTR\n",
                                   __FUNCTION__ );
-                       return -EAGAIN;
+                       return DRM_ERR(EAGAIN);
                }
 
                if ((copy_buf->used = copy_and_verify_from_user( GETBUFPTR( copy_buf 
), buf, used )) == 0) {
@@ -578,7 +578,7 @@
                                if (copy_buf == entry->buf) {
                                        DRM_ERROR( "%s: Trying to release a pending 
buf\n",
                                                   __FUNCTION__ );
-                                       return -EFAULT;
+                                       return DRM_ERR(EFAULT);
                                }
                        }
 #endif
@@ -598,7 +598,7 @@
 
        if (verify_failed) {
                DRM_ERROR( "%s: Vertex buffer verification failed\n", __FUNCTION__ );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        } else {
                return 0;
        }
@@ -633,22 +633,22 @@
                break;
        default:
                DRM_ERROR( "invalid blit format %d\n", blit->format );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        /* Dispatch the blit buffer.
         */
        buf = dma->buflist[blit->idx];
        
-       if ( buf->pid != current->pid ) {
+       if ( buf->pid != DRM_CURRENTPID ) {
                DRM_ERROR( "process %d using buffer owned by %d\n",
-                          current->pid, buf->pid );
-               return -EINVAL;
+                          DRM_CURRENTPID, buf->pid );
+               return DRM_ERR(EINVAL);
        }
 
        if ( buf->pending ) {
                DRM_ERROR( "sending pending buffer %d\n", blit->idx );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        /* Set buf->used to the bytes of blit data based on the blit dimensions 
@@ -661,7 +661,7 @@
        if ( buf->used <= 0 || 
             buf->used > MACH64_BUFFER_SIZE - MACH64_HOSTDATA_BLIT_OFFSET ) {
                DRM_ERROR( "Invalid blit size: %d bytes\n", buf->used );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        /* FIXME: Use a last buffer flag and reduce the state emitted for subsequent,
@@ -726,7 +726,7 @@
        drm_mach64_clear_t clear;
        int ret;
 
-       DRM_DEBUG( "%s: pid=%d\n", __FUNCTION__, current->pid  );
+       DRM_DEBUG( "%s: pid=%d\n", __FUNCTION__, DRM_CURRENTPID  );
 
        LOCK_TEST_WITH_RETURN( dev );
        
@@ -756,7 +756,7 @@
        drm_mach64_sarea_t *sarea_priv = dev_priv->sarea_priv;
        int ret;
 
-       DRM_DEBUG( "%s: pid=%d\n", __FUNCTION__, current->pid );
+       DRM_DEBUG( "%s: pid=%d\n", __FUNCTION__, DRM_CURRENTPID );
 
        LOCK_TEST_WITH_RETURN( dev );
 
@@ -785,25 +785,25 @@
 
        if ( !dev_priv ) {
                DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        DRM_COPY_FROM_USER_IOCTL( vertex, (drm_mach64_vertex_t *)data,
                             sizeof(vertex) );
 
        DRM_DEBUG( "%s: pid=%d buf=%p used=%lu discard=%d\n",
-                  __FUNCTION__, current->pid,
+                  __FUNCTION__, DRM_CURRENTPID,
                   vertex.buf, vertex.used, vertex.discard );
 
        if ( vertex.prim < 0 ||
             vertex.prim > MACH64_PRIM_POLYGON ) {
                DRM_ERROR( "buffer prim %d\n", vertex.prim );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        if ( vertex.used > MACH64_BUFFER_SIZE ) {
                DRM_ERROR( "Invalid vertex buffer size: %lu bytes\n", vertex.used );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        RING_SPACE_TEST_WITH_RETURN( dev_priv );
@@ -830,12 +830,12 @@
                             sizeof(blit) );
 
        DRM_DEBUG( "%s: pid=%d index=%d\n",
-                  __FUNCTION__, current->pid, blit.idx );
+                  __FUNCTION__, DRM_CURRENTPID, blit.idx );
 
        if ( blit.idx < 0 || blit.idx >= dma->buf_count ) {
                DRM_ERROR( "buffer index %d (of %d max)\n",
                           blit.idx, dma->buf_count - 1 );
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
        RING_SPACE_TEST_WITH_RETURN( dev_priv );
@@ -870,11 +870,13 @@
                value = mach64_do_get_frames_queued( dev_priv );
                break;
        default:
-               return -EINVAL;
+               return DRM_ERR(EINVAL);
        }
 
-       if ( copy_to_user( param.value, &value, sizeof(int) ) )
-               return -EFAULT;
+       if ( DRM_COPY_TO_USER( param.value, &value, sizeof(int) ) ) {
+               DRM_ERROR( "copy_to_user\n" );
+               return DRM_ERR(EFAULT);
+       }
 
        return 0;
 }

Reply via email to