Initial commit
[kernel/linux-3.0.git] / drivers / gpu / vithar_rev0 / osk / src / common / mali_osk_bitops_cmn.c
1 /*
2  *
3  * (C) COPYRIGHT 2008-2010 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7  * 
8  * A copy of the licence is included with the program, and can also be obtained from Free Software
9  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
10  * 
11  */
12
13
14
15
16 #include <osk/mali_osk.h>
17
18 unsigned long osk_bitarray_find_first_zero_bit(const unsigned long *addr, unsigned long maxbit)
19 {
20         unsigned long total;
21
22         OSK_ASSERT(NULL != addr);
23
24         for ( total = 0; total < maxbit; total += OSK_BITS_PER_LONG, ++addr )
25         {
26                 if (OSK_ULONG_MAX != *addr)
27                 {
28                         int result;
29                         result = oskp_find_first_zero_bit( *addr );
30                         /* non-negative signifies the bit was found */
31                         if ( result >= 0 )
32                         {
33                                 total += (unsigned long)result;
34                                 break;
35                         }
36                 }
37         }
38
39         /* Now check if we reached maxbit or above */
40         if ( total >= maxbit )
41         {
42                 total = maxbit;
43         }
44
45         return total; /* either the found bit nr, or maxbit if not found */
46 }