aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc64/kernel
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2005-11-01 01:28:10 -0500
committerPaul Mackerras <paulus@samba.org>2005-11-01 05:49:02 -0500
commita0e60b2033b30a6bb8479629001cf98e58e4079a (patch)
tree6386eeca340a25c4ae1876f2f9663f94628c8cc3 /arch/ppc64/kernel
parent031ef0a72aa8f7ee63ae9f307c1bcff92b3ccc2c (diff)
[PATCH] powerpc: Merge bitops.h
Here's a revised version. This re-introduces the set_bits() function from ppc64, which I removed because I thought it was unused (it exists on no other arch). In fact it is used in the powermac interrupt code (but not on pSeries). - We use LARXL/STCXL macros to generate the right (32 or 64 bit) instructions, similar to LDL/STL from ppc_asm.h, used in fpu.S - ppc32 previously used a full "sync" barrier at the end of test_and_*_bit(), whereas ppc64 used an "isync". The merged version uses "isync", since I believe that's sufficient. - The ppc64 versions of then minix_*() bitmap functions have changed semantics. Previously on ppc64, these functions were big-endian (that is bit 0 was the LSB in the first 64-bit, big-endian word). On ppc32 (and x86, for that matter, they were little-endian. As far as I can tell, the big-endian usage was simply wrong - I guess no-one ever tried to use minixfs on ppc64. - On ppc32 find_next_bit() and find_next_zero_bit() are no longer inline (they were already out-of-line on ppc64). - For ppc64, sched_find_first_bit() has moved from mmu_context.h to the merged bitops. What it was doing in mmu_context.h in the first place, I have no idea. - The fls() function is now implemented using the cntlzw instruction on ppc64, instead of generic_fls(), as it already was on ppc32. - For ARCH=ppc, this patch requires adding arch/powerpc/lib to the arch/ppc/Makefile. This in turn requires some changes to arch/powerpc/lib/Makefile which didn't correctly handle ARCH=ppc. Built and running on G5. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64/kernel')
-rw-r--r--arch/ppc64/kernel/Makefile2
-rw-r--r--arch/ppc64/kernel/bitops.c147
2 files changed, 1 insertions, 148 deletions
diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile
index 247d2fc6a8ed..990df0905c87 100644
--- a/arch/ppc64/kernel/Makefile
+++ b/arch/ppc64/kernel/Makefile
@@ -13,7 +13,7 @@ endif
13 13
14obj-y += irq.o idle.o dma.o \ 14obj-y += irq.o idle.o dma.o \
15 signal.o \ 15 signal.o \
16 align.o bitops.o pacaData.o \ 16 align.o pacaData.o \
17 udbg.o ioctl32.o \ 17 udbg.o ioctl32.o \
18 rtc.o \ 18 rtc.o \
19 cpu_setup_power4.o \ 19 cpu_setup_power4.o \
diff --git a/arch/ppc64/kernel/bitops.c b/arch/ppc64/kernel/bitops.c
deleted file mode 100644
index ae329e8b4acb..000000000000
--- a/arch/ppc64/kernel/bitops.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/*
2 * These are too big to be inlined.
3 */
4
5#include <linux/kernel.h>
6#include <linux/module.h>
7#include <linux/bitops.h>
8#include <asm/byteorder.h>
9
10unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
11 unsigned long offset)
12{
13 const unsigned long *p = addr + (offset >> 6);
14 unsigned long result = offset & ~63UL;
15 unsigned long tmp;
16
17 if (offset >= size)
18 return size;
19 size -= result;
20 offset &= 63UL;
21 if (offset) {
22 tmp = *(p++);
23 tmp |= ~0UL >> (64 - offset);
24 if (size < 64)
25 goto found_first;
26 if (~tmp)
27 goto found_middle;
28 size -= 64;
29 result += 64;
30 }
31 while (size & ~63UL) {
32 if (~(tmp = *(p++)))
33 goto found_middle;
34 result += 64;
35 size -= 64;
36 }
37 if (!size)
38 return result;
39 tmp = *p;
40
41found_first:
42 tmp |= ~0UL << size;
43 if (tmp == ~0UL) /* Are any bits zero? */
44 return result + size; /* Nope. */
45found_middle:
46 return result + ffz(tmp);
47}
48
49EXPORT_SYMBOL(find_next_zero_bit);
50
51unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
52 unsigned long offset)
53{
54 const unsigned long *p = addr + (offset >> 6);
55 unsigned long result = offset & ~63UL;
56 unsigned long tmp;
57
58 if (offset >= size)
59 return size;
60 size -= result;
61 offset &= 63UL;
62 if (offset) {
63 tmp = *(p++);
64 tmp &= (~0UL << offset);
65 if (size < 64)
66 goto found_first;
67 if (tmp)
68 goto found_middle;
69 size -= 64;
70 result += 64;
71 }
72 while (size & ~63UL) {
73 if ((tmp = *(p++)))
74 goto found_middle;
75 result += 64;
76 size -= 64;
77 }
78 if (!size)
79 return result;
80 tmp = *p;
81
82found_first:
83 tmp &= (~0UL >> (64 - size));
84 if (tmp == 0UL) /* Are any bits set? */
85 return result + size; /* Nope. */
86found_middle:
87 return result + __ffs(tmp);
88}
89
90EXPORT_SYMBOL(find_next_bit);
91
92static inline unsigned int ext2_ilog2(unsigned int x)
93{
94 int lz;
95
96 asm("cntlzw %0,%1": "=r"(lz):"r"(x));
97 return 31 - lz;
98}
99
100static inline unsigned int ext2_ffz(unsigned int x)
101{
102 u32 rc;
103 if ((x = ~x) == 0)
104 return 32;
105 rc = ext2_ilog2(x & -x);
106 return rc;
107}
108
109unsigned long find_next_zero_le_bit(const unsigned long *addr, unsigned long size,
110 unsigned long offset)
111{
112 const unsigned int *p = ((const unsigned int *)addr) + (offset >> 5);
113 unsigned int result = offset & ~31;
114 unsigned int tmp;
115
116 if (offset >= size)
117 return size;
118 size -= result;
119 offset &= 31;
120 if (offset) {
121 tmp = cpu_to_le32p(p++);
122 tmp |= ~0U >> (32 - offset); /* bug or feature ? */
123 if (size < 32)
124 goto found_first;
125 if (tmp != ~0)
126 goto found_middle;
127 size -= 32;
128 result += 32;
129 }
130 while (size >= 32) {
131 if ((tmp = cpu_to_le32p(p++)) != ~0)
132 goto found_middle;
133 result += 32;
134 size -= 32;
135 }
136 if (!size)
137 return result;
138 tmp = cpu_to_le32p(p);
139found_first:
140 tmp |= ~0 << size;
141 if (tmp == ~0) /* Are any bits zero? */
142 return result + size; /* Nope. */
143found_middle:
144 return result + ext2_ffz(tmp);
145}
146
147EXPORT_SYMBOL(find_next_zero_le_bit);