summaryrefslogtreecommitdiffstats
path: root/arch/ppc/kernel/support.c
blob: cd2b58b8a18098c56cc88bebe43587f79dc4753e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Miscellaneous support routines
 */

#include <asm/bitops.h>

/*extern __inline__*/ int find_first_zero_bit(void *add, int len)
{
	int	mask, nr, i;
	BITFIELD *addr = add;
	nr = 0;
	while (len)
	{
		if (~*addr != 0)
		{ /* Contains at least one zero */
			for (i = 0;  i < 32;  i++, nr++)
			{
				mask = BIT(nr);
				if ((mask & *addr) == 0)
				{
					return (nr);
				}
			}
		}
		len -= 32;
		addr++;
		nr += 32;
	}
	return (0);  /* Shouldn't happen */
}

/*extern __inline__*/ int find_next_zero_bit(void *add, int last_bit, int nr)
{
	int	mask, i;
	BITFIELD *addr = add;
#if 0	
printk("Find next (%x, %x)", addr, nr);
#endif
	addr += nr >> 5;
#if 0	
printk(" - Pat: %x(%08X)\n", addr, *addr);
#endif
	if ((nr & 0x1F) != 0)
	{ 
		if (*addr != 0xFFFFFFFF)
		{ /* At least one more bit available in this longword */
			for (i = (nr&0x1F);  i < 32;  i++, nr++)
			{
				mask = BIT(nr);
				if ((mask & *addr) == 0)
				{
#if 0					
printk("(1)Bit: %x(%d), Pat: %x(%08x)\n", nr, nr&0x1F, addr, *addr);
#endif
					return (nr);
				}
			}
		}
		addr++;
		nr = (nr + 0x1F) & ~0x1F;
	}
	while (nr < last_bit)
	{
		if (*addr != 0xFFFFFFFF)
		{ /* Contains at least one zero */
			for (i = 0;  i < 32;  i++, nr++)
			{
				mask = BIT(nr);
				if ((mask & *addr) == 0)
				{
#if 0					
printk("(2)Bit: %x(%d), Pat: %x(%08x)\n", nr, nr&0x1F, addr, *addr);
#endif
					return (nr);
				}
			}
		}
		addr++;
		nr += 32;
	}
	return (nr);  /* Shouldn't happen */
}