Author: dumbbell
Date: Thu Mar 13 21:06:13 2014
New Revision: 263119
URL: http://svnweb.freebsd.org/changeset/base/263119

Log:
  MFC changes to atomic.h usage in DRM code
  
  This commit follows the merge of atomic.h changes in r262807 and r262823.
  The original work is from Jung-uk Kim (jkim@).
  
  The following revisions were merged in this single commit:
  
  r255009:
    Fix a compiler warning.  With this fix, a negative time can be converted to
    a struct timeval and back to the original nanoseconds correctly.
  
  r255012:
    Fix a compiler warning and add couple of VM map types.
  
  r255013:
    Correct atomic operations in i915.
  
  r255037:
    Fix atomic operations on context_flag without altering semantics.
  
  r255039:
    - Remove test_and_set_bit() macro.  It is unused since r255037.
    - Relax atomic_read() and atomic_set() macros.  Linux does not require any
    memory barrier.  Also, these macros may be even reordered or optimized away
    according to the API documentation:
  
    https://www.kernel.org/doc/Documentation/atomic_ops.txt
  
  r255041:
    Clarify confusions between atomic_t and bitmap.  Fix bitmap operations
    accordingly.
  
  r255042:
    Fix the incomplete conversion from atomic_t to long for test_bit().
  
  r255044:
    Partially revert r254880.  The bitmap operations actually use long type now.
  
  r255045:
    'u_long' is consistently spelled 'unsigned long' in this file.  Fix it.

Modified:
  stable/9/sys/dev/drm2/drmP.h
  stable/9/sys/dev/drm2/drm_atomic.h
  stable/9/sys/dev/drm2/drm_context.c
  stable/9/sys/dev/drm2/drm_irq.c
  stable/9/sys/dev/drm2/drm_sysctl.c
  stable/9/sys/dev/drm2/i915/i915_gem.c
  stable/9/sys/dev/drm2/i915/i915_gem_execbuffer.c
  stable/9/sys/dev/drm2/i915/intel_display.c
  stable/9/sys/dev/drm2/ttm/ttm_bo.c
  stable/9/sys/dev/drm2/ttm/ttm_bo_util.c
  stable/9/sys/dev/drm2/ttm/ttm_bo_vm.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/dev/   (props changed)

Modified: stable/9/sys/dev/drm2/drmP.h
==============================================================================
--- stable/9/sys/dev/drm2/drmP.h        Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/drmP.h        Thu Mar 13 21:06:13 2014        
(r263119)
@@ -960,7 +960,7 @@ struct drm_device {
 
        drm_agp_head_t    *agp;
        drm_sg_mem_t      *sg;  /* Scatter gather memory */
-       atomic_t          *ctx_bitmap;
+       unsigned long     *ctx_bitmap;
        void              *dev_private;
        unsigned int      agp_buffer_token;
        drm_local_map_t   *agp_buffer_map;

Modified: stable/9/sys/dev/drm2/drm_atomic.h
==============================================================================
--- stable/9/sys/dev/drm2/drm_atomic.h  Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/drm_atomic.h  Thu Mar 13 21:06:13 2014        
(r263119)
@@ -7,6 +7,7 @@
 
 /*-
  * Copyright 2004 Eric Anholt
+ * Copyright 2013 Jung-uk Kim <j...@freebsd.org>
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -32,13 +33,14 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-typedef uint32_t       atomic_t;
+typedef u_int          atomic_t;
 typedef uint64_t       atomic64_t;
 
-#define        BITS_TO_LONGS(x)                howmany(x, sizeof(long) * NBBY)
+#define        BITS_PER_LONG                   (sizeof(long) * NBBY)
+#define        BITS_TO_LONGS(x)                howmany(x, BITS_PER_LONG)
 
-#define        atomic_set(p, v)                atomic_store_rel_int(p, v)
-#define        atomic_read(p)                  atomic_load_acq_int(p)
+#define        atomic_read(p)                  (*(volatile u_int *)(p))
+#define        atomic_set(p, v)                do { *(u_int *)(p) = (v); } 
while (0)
 
 #define        atomic_add(v, p)                atomic_add_int(p, v)
 #define        atomic_sub(v, p)                atomic_subtract_int(p, v)
@@ -58,25 +60,27 @@ typedef uint64_t    atomic64_t;
 #define        atomic_xchg(p, v)               atomic_swap_int(p, v)
 #define        atomic64_xchg(p, v)             atomic_swap_64(p, v)
 
+#define        __bit_word(b)                   ((b) / BITS_PER_LONG)
+#define        __bit_mask(b)                   (1UL << (b) % BITS_PER_LONG)
+#define        __bit_addr(p, b)                ((volatile u_long *)(p) + 
__bit_word(b))
+
 #define        clear_bit(b, p) \
-    atomic_clear_int((volatile u_int *)(p) + (b) / 32, 1 << (b) % 32)
+    atomic_clear_long(__bit_addr(p, b), __bit_mask(b))
 #define        set_bit(b, p) \
-    atomic_set_int((volatile u_int *)(p) + (b) / 32, 1 << (b) % 32)
+    atomic_set_long(__bit_addr(p, b), __bit_mask(b))
 #define        test_bit(b, p) \
-    (atomic_load_acq_int((volatile u_int *)(p) + (b) / 32) & (1 << (b) % 32))
-#define        test_and_set_bit(b, p) \
-    atomic_testandset_int((volatile u_int *)(p) + (b) / 32, b)
+    ((*__bit_addr(p, b) & __bit_mask(b)) != 0)
 
-static __inline int
-find_first_zero_bit(volatile void *p, int max)
+static __inline u_long
+find_first_zero_bit(const u_long *p, u_long max)
 {
-       volatile int *np = p;
-       int i, n;
+       u_long i, n;
 
-       for (i = 0; i < max / (NBBY * sizeof(int)); i++) {
-               n = ~np[i];
+       KASSERT(max % BITS_PER_LONG == 0, ("invalid bitmap size %lu", max));
+       for (i = 0; i < max / BITS_PER_LONG; i++) {
+               n = ~p[i];
                if (n != 0)
-                       return (i * NBBY * sizeof(int) + ffs(n) - 1);
+                       return (i * BITS_PER_LONG + ffsl(n) - 1);
        }
        return (max);
 }

Modified: stable/9/sys/dev/drm2/drm_context.c
==============================================================================
--- stable/9/sys/dev/drm2/drm_context.c Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/drm_context.c Thu Mar 13 21:06:13 2014        
(r263119)
@@ -182,7 +182,7 @@ bad:
 
 int drm_context_switch(struct drm_device *dev, int old, int new)
 {
-       if (test_and_set_bit(0, &dev->context_flag)) {
+       if (atomic_xchg(&dev->context_flag, 1) != 0) {
                DRM_ERROR("Reentering -- FIXME\n");
                return EBUSY;
        }
@@ -190,7 +190,7 @@ int drm_context_switch(struct drm_device
        DRM_DEBUG("Context switch from %d to %d\n", old, new);
 
        if (new == dev->last_context) {
-               clear_bit(0, &dev->context_flag);
+               atomic_xchg(&dev->context_flag, 0);
                return 0;
        }
 
@@ -208,7 +208,7 @@ int drm_context_switch_complete(struct d
        /* If a context switch is ever initiated
           when the kernel holds the lock, release
           that lock here. */
-       clear_bit(0, &dev->context_flag);
+       atomic_xchg(&dev->context_flag, 0);
 
        return 0;
 }

Modified: stable/9/sys/dev/drm2/drm_irq.c
==============================================================================
--- stable/9/sys/dev/drm2/drm_irq.c     Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/drm_irq.c     Thu Mar 13 21:06:13 2014        
(r263119)
@@ -210,7 +210,7 @@ struct timeval
 ns_to_timeval(const int64_t nsec)
 {
         struct timeval tv;
-       uint32_t rem;
+       long rem;
 
        if (nsec == 0) {
                tv.tv_sec = 0;

Modified: stable/9/sys/dev/drm2/drm_sysctl.c
==============================================================================
--- stable/9/sys/dev/drm2/drm_sysctl.c  Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/drm_sysctl.c  Thu Mar 13 21:06:13 2014        
(r263119)
@@ -177,7 +177,15 @@ static int drm_vm_info DRM_SYSCTL_HANDLE
 {
        struct drm_device *dev = arg1;
        drm_local_map_t *map, *tempmaps;
-       const char   *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
+       const char *types[] = {
+               [_DRM_FRAME_BUFFER] = "FB",
+               [_DRM_REGISTERS] = "REG",
+               [_DRM_SHM] = "SHM",
+               [_DRM_AGP] = "AGP",
+               [_DRM_SCATTER_GATHER] = "SG",
+               [_DRM_CONSISTENT] = "CONS",
+               [_DRM_GEM] = "GEM"
+       };
        const char *type, *yesno;
        int i, mapcount;
        char buf[128];
@@ -211,10 +219,20 @@ static int drm_vm_info DRM_SYSCTL_HANDLE
        for (i = 0; i < mapcount; i++) {
                map = &tempmaps[i];
 
-               if (map->type < 0 || map->type > 4)
+               switch(map->type) {
+               default:
                        type = "??";
-               else
+                       break;
+               case _DRM_FRAME_BUFFER:
+               case _DRM_REGISTERS:
+               case _DRM_SHM:
+               case _DRM_AGP:
+               case _DRM_SCATTER_GATHER:
+               case _DRM_CONSISTENT:
+               case _DRM_GEM:
                        type = types[map->type];
+                       break;
+               }
 
                if (!map->mtrr)
                        yesno = "no";

Modified: stable/9/sys/dev/drm2/i915/i915_gem.c
==============================================================================
--- stable/9/sys/dev/drm2/i915/i915_gem.c       Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/i915/i915_gem.c       Thu Mar 13 21:06:13 2014        
(r263119)
@@ -138,7 +138,7 @@ i915_gem_wait_for_error(struct drm_devic
        }
        mtx_unlock(&dev_priv->error_completion_lock);
 
-       if (atomic_read(&dev_priv->mm.wedged)) {
+       if (atomic_load_acq_int(&dev_priv->mm.wedged)) {
                mtx_lock(&dev_priv->error_completion_lock);
                dev_priv->error_completion++;
                mtx_unlock(&dev_priv->error_completion_lock);
@@ -740,7 +740,7 @@ i915_gem_ring_throttle(struct drm_device
        int ret;
 
        dev_priv = dev->dev_private;
-       if (atomic_read(&dev_priv->mm.wedged))
+       if (atomic_load_acq_int(&dev_priv->mm.wedged))
                return (-EIO);
 
        file_priv = file->driver_priv;
@@ -765,15 +765,15 @@ i915_gem_ring_throttle(struct drm_device
                if (ring->irq_get(ring)) {
                        while (ret == 0 &&
                            !(i915_seqno_passed(ring->get_seqno(ring), seqno) ||
-                           atomic_read(&dev_priv->mm.wedged)))
+                           atomic_load_acq_int(&dev_priv->mm.wedged)))
                                ret = -msleep(ring, &ring->irq_lock, PCATCH,
                                    "915thr", 0);
                        ring->irq_put(ring);
-                       if (ret == 0 && atomic_read(&dev_priv->mm.wedged))
+                       if (ret == 0 && 
atomic_load_acq_int(&dev_priv->mm.wedged))
                                ret = -EIO;
                } else if (_intel_wait_for(dev,
                    i915_seqno_passed(ring->get_seqno(ring), seqno) ||
-                   atomic_read(&dev_priv->mm.wedged), 3000, 0, "915rtr")) {
+                   atomic_load_acq_int(&dev_priv->mm.wedged), 3000, 0, 
"915rtr")) {
                        ret = -EBUSY;
                }
        }

Modified: stable/9/sys/dev/drm2/i915/i915_gem_execbuffer.c
==============================================================================
--- stable/9/sys/dev/drm2/i915/i915_gem_execbuffer.c    Thu Mar 13 19:26:26 
2014        (r263118)
+++ stable/9/sys/dev/drm2/i915/i915_gem_execbuffer.c    Thu Mar 13 21:06:13 
2014        (r263119)
@@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
                i915_gem_clflush_object(obj);
 
        if (obj->base.pending_write_domain)
-               cd->flips |= atomic_read(&obj->pending_flip);
+               cd->flips |= atomic_load_acq_int(&obj->pending_flip);
 
        /* The actual obj->write_domain will be updated with
         * pending_write_domain after we emit the accumulated flush for all

Modified: stable/9/sys/dev/drm2/i915/intel_display.c
==============================================================================
--- stable/9/sys/dev/drm2/i915/intel_display.c  Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/i915/intel_display.c  Thu Mar 13 21:06:13 2014        
(r263119)
@@ -2261,8 +2261,8 @@ intel_finish_fb(struct drm_framebuffer *
        int ret;
 
        mtx_lock(&dev->event_lock);
-       while (!atomic_read(&dev_priv->mm.wedged) &&
-           atomic_read(&obj->pending_flip) != 0) {
+       while (!atomic_load_acq_int(&dev_priv->mm.wedged) &&
+           atomic_load_acq_int(&obj->pending_flip) != 0) {
                msleep(&obj->pending_flip, &dev->event_lock,
                    0, "915flp", 0);
        }
@@ -2948,7 +2948,7 @@ static void intel_crtc_wait_for_pending_
        dev = crtc->dev;
        dev_priv = dev->dev_private;
        mtx_lock(&dev->event_lock);
-       while (atomic_read(&obj->pending_flip) != 0)
+       while (atomic_load_acq_int(&obj->pending_flip) != 0)
                msleep(&obj->pending_flip, &dev->event_lock, 0, "915wfl", 0);
        mtx_unlock(&dev->event_lock);
 }
@@ -7333,7 +7333,7 @@ static void do_intel_finish_page_flip(st
        obj = work->old_fb_obj;
 
        atomic_clear_int(&obj->pending_flip, 1 << intel_crtc->plane);
-       if (atomic_read(&obj->pending_flip) == 0)
+       if (atomic_load_acq_int(&obj->pending_flip) == 0)
                wakeup(&obj->pending_flip);
        mtx_unlock(&dev->event_lock);
 
@@ -7640,7 +7640,7 @@ static int intel_crtc_page_flip(struct d
        return 0;
 
 cleanup_pending:
-       atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
+       atomic_clear_int(&work->old_fb_obj->pending_flip, 1 << 
intel_crtc->plane);
        drm_gem_object_unreference(&work->old_fb_obj->base);
        drm_gem_object_unreference(&obj->base);
        DRM_UNLOCK(dev);

Modified: stable/9/sys/dev/drm2/ttm/ttm_bo.c
==============================================================================
--- stable/9/sys/dev/drm2/ttm/ttm_bo.c  Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/ttm/ttm_bo.c  Thu Mar 13 21:06:13 2014        
(r263119)
@@ -1723,8 +1723,7 @@ int ttm_bo_wait(struct ttm_buffer_object
                if (driver->sync_obj_signaled(bo->sync_obj)) {
                        void *tmp_obj = bo->sync_obj;
                        bo->sync_obj = NULL;
-                       atomic_clear_long(&bo->priv_flags,
-                                         1UL << TTM_BO_PRIV_FLAG_MOVING);
+                       clear_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
                        mtx_unlock(&bdev->fence_lock);
                        driver->sync_obj_unref(&tmp_obj);
                        mtx_lock(&bdev->fence_lock);
@@ -1747,8 +1746,8 @@ int ttm_bo_wait(struct ttm_buffer_object
                if (likely(bo->sync_obj == sync_obj)) {
                        void *tmp_obj = bo->sync_obj;
                        bo->sync_obj = NULL;
-                       atomic_clear_long(&bo->priv_flags,
-                                         1UL << TTM_BO_PRIV_FLAG_MOVING);
+                       clear_bit(TTM_BO_PRIV_FLAG_MOVING,
+                                 &bo->priv_flags);
                        mtx_unlock(&bdev->fence_lock);
                        driver->sync_obj_unref(&sync_obj);
                        driver->sync_obj_unref(&tmp_obj);

Modified: stable/9/sys/dev/drm2/ttm/ttm_bo_util.c
==============================================================================
--- stable/9/sys/dev/drm2/ttm/ttm_bo_util.c     Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/ttm/ttm_bo_util.c     Thu Mar 13 21:06:13 2014        
(r263119)
@@ -638,8 +638,7 @@ int ttm_bo_move_accel_cleanup(struct ttm
                 * operation has completed.
                 */
 
-               atomic_set_long(&bo->priv_flags,
-                               1UL << TTM_BO_PRIV_FLAG_MOVING);
+               set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
                mtx_unlock(&bdev->fence_lock);
                if (tmp_obj)
                        driver->sync_obj_unref(&tmp_obj);

Modified: stable/9/sys/dev/drm2/ttm/ttm_bo_vm.c
==============================================================================
--- stable/9/sys/dev/drm2/ttm/ttm_bo_vm.c       Thu Mar 13 19:26:26 2014        
(r263118)
+++ stable/9/sys/dev/drm2/ttm/ttm_bo_vm.c       Thu Mar 13 21:06:13 2014        
(r263119)
@@ -155,8 +155,7 @@ reserve:
         */
 
        mtx_lock(&bdev->fence_lock);
-       if ((atomic_load_acq_long(&bo->priv_flags) &
-           (1UL << TTM_BO_PRIV_FLAG_MOVING)) != 0) {
+       if (test_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags)) {
                /*
                 * Here, the behavior differs between Linux and FreeBSD.
                 *
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to