Author: jkim
Date: Thu Aug 29 20:40:45 2013
New Revision: 255041
URL: http://svnweb.freebsd.org/changeset/base/255041

Log:
  Clarify confusions between atomic_t and bitmap.  Fix bitmap operations
  accordingly.

Modified:
  head/sys/dev/drm2/drmP.h
  head/sys/dev/drm2/drm_atomic.h

Modified: head/sys/dev/drm2/drmP.h
==============================================================================
--- head/sys/dev/drm2/drmP.h    Thu Aug 29 19:52:18 2013        (r255040)
+++ head/sys/dev/drm2/drmP.h    Thu Aug 29 20:40:45 2013        (r255041)
@@ -961,7 +961,7 @@ struct drm_device {
 
        drm_agp_head_t    *agp;
        drm_sg_mem_t      *sg;  /* Scatter gather memory */
-       atomic_t          *ctx_bitmap;
+       u_long            *ctx_bitmap;
        void              *dev_private;
        unsigned int      agp_buffer_token;
        drm_local_map_t   *agp_buffer_map;

Modified: head/sys/dev/drm2/drm_atomic.h
==============================================================================
--- head/sys/dev/drm2/drm_atomic.h      Thu Aug 29 19:52:18 2013        
(r255040)
+++ head/sys/dev/drm2/drm_atomic.h      Thu Aug 29 20:40:45 2013        
(r255041)
@@ -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,10 +33,11 @@
 #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_read(p)                  (*(volatile u_int *)(p))
 #define        atomic_set(p, v)                do { *(u_int *)(p) = (v); } 
while (0)
@@ -58,23 +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_read((volatile u_int *)(p) + (b) / 32) & (1 << (b) % 32)) != 0)
+    ((atomic_read(__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);
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to