aboutsummaryrefslogtreecommitdiffstats
path: root/arch
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
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')
-rw-r--r--arch/powerpc/kernel/ppc_ksyms.c9
-rw-r--r--arch/powerpc/lib/Makefile9
-rw-r--r--arch/powerpc/lib/bitops.c (renamed from arch/ppc64/kernel/bitops.c)97
-rw-r--r--arch/ppc/Makefile3
-rw-r--r--arch/ppc/kernel/bitops.c126
-rw-r--r--arch/ppc64/kernel/Makefile2
6 files changed, 58 insertions, 188 deletions
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 8bc540337ba0..47d6f7e2ea9f 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -81,15 +81,6 @@ EXPORT_SYMBOL(_prep_type);
81EXPORT_SYMBOL(ucSystemType); 81EXPORT_SYMBOL(ucSystemType);
82#endif 82#endif
83 83
84#if !defined(__INLINE_BITOPS)
85EXPORT_SYMBOL(set_bit);
86EXPORT_SYMBOL(clear_bit);
87EXPORT_SYMBOL(change_bit);
88EXPORT_SYMBOL(test_and_set_bit);
89EXPORT_SYMBOL(test_and_clear_bit);
90EXPORT_SYMBOL(test_and_change_bit);
91#endif /* __INLINE_BITOPS */
92
93EXPORT_SYMBOL(strcpy); 84EXPORT_SYMBOL(strcpy);
94EXPORT_SYMBOL(strncpy); 85EXPORT_SYMBOL(strncpy);
95EXPORT_SYMBOL(strcat); 86EXPORT_SYMBOL(strcat);
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index dfb33915ad61..34f5c2e074c9 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -3,13 +3,14 @@
3# 3#
4 4
5ifeq ($(CONFIG_PPC_MERGE),y) 5ifeq ($(CONFIG_PPC_MERGE),y)
6obj-y := string.o 6obj-y := string.o strcase.o
7obj-$(CONFIG_PPC32) += div64.o copy_32.o checksum_32.o
7endif 8endif
8 9
9obj-y += strcase.o 10obj-y += bitops.o
10obj-$(CONFIG_PPC32) += div64.o copy_32.o checksum_32.o
11obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \ 11obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \
12 memcpy_64.o usercopy_64.o mem_64.o string.o 12 memcpy_64.o usercopy_64.o mem_64.o string.o \
13 strcase.o
13obj-$(CONFIG_PPC_ISERIES) += e2a.o 14obj-$(CONFIG_PPC_ISERIES) += e2a.o
14obj-$(CONFIG_XMON) += sstep.o 15obj-$(CONFIG_XMON) += sstep.o
15 16
diff --git a/arch/ppc64/kernel/bitops.c b/arch/powerpc/lib/bitops.c
index ae329e8b4acb..b67ce3004ebf 100644
--- a/arch/ppc64/kernel/bitops.c
+++ b/arch/powerpc/lib/bitops.c
@@ -1,93 +1,97 @@
1/* 1#include <linux/types.h>
2 * These are too big to be inlined.
3 */
4
5#include <linux/kernel.h>
6#include <linux/module.h> 2#include <linux/module.h>
7#include <linux/bitops.h>
8#include <asm/byteorder.h> 3#include <asm/byteorder.h>
4#include <asm/bitops.h>
9 5
10unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 6/**
11 unsigned long offset) 7 * find_next_bit - find the next set bit in a memory region
8 * @addr: The address to base the search on
9 * @offset: The bitnumber to start searching at
10 * @size: The maximum size to search
11 */
12unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
13 unsigned long offset)
12{ 14{
13 const unsigned long *p = addr + (offset >> 6); 15 const unsigned long *p = addr + BITOP_WORD(offset);
14 unsigned long result = offset & ~63UL; 16 unsigned long result = offset & ~(BITS_PER_LONG-1);
15 unsigned long tmp; 17 unsigned long tmp;
16 18
17 if (offset >= size) 19 if (offset >= size)
18 return size; 20 return size;
19 size -= result; 21 size -= result;
20 offset &= 63UL; 22 offset %= BITS_PER_LONG;
21 if (offset) { 23 if (offset) {
22 tmp = *(p++); 24 tmp = *(p++);
23 tmp |= ~0UL >> (64 - offset); 25 tmp &= (~0UL << offset);
24 if (size < 64) 26 if (size < BITS_PER_LONG)
25 goto found_first; 27 goto found_first;
26 if (~tmp) 28 if (tmp)
27 goto found_middle; 29 goto found_middle;
28 size -= 64; 30 size -= BITS_PER_LONG;
29 result += 64; 31 result += BITS_PER_LONG;
30 } 32 }
31 while (size & ~63UL) { 33 while (size & ~(BITS_PER_LONG-1)) {
32 if (~(tmp = *(p++))) 34 if ((tmp = *(p++)))
33 goto found_middle; 35 goto found_middle;
34 result += 64; 36 result += BITS_PER_LONG;
35 size -= 64; 37 size -= BITS_PER_LONG;
36 } 38 }
37 if (!size) 39 if (!size)
38 return result; 40 return result;
39 tmp = *p; 41 tmp = *p;
40 42
41found_first: 43found_first:
42 tmp |= ~0UL << size; 44 tmp &= (~0UL >> (64 - size));
43 if (tmp == ~0UL) /* Are any bits zero? */ 45 if (tmp == 0UL) /* Are any bits set? */
44 return result + size; /* Nope. */ 46 return result + size; /* Nope. */
45found_middle: 47found_middle:
46 return result + ffz(tmp); 48 return result + __ffs(tmp);
47} 49}
50EXPORT_SYMBOL(find_next_bit);
48 51
49EXPORT_SYMBOL(find_next_zero_bit); 52/*
50 53 * This implementation of find_{first,next}_zero_bit was stolen from
51unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 54 * Linus' asm-alpha/bitops.h.
52 unsigned long offset) 55 */
56unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
57 unsigned long offset)
53{ 58{
54 const unsigned long *p = addr + (offset >> 6); 59 const unsigned long *p = addr + BITOP_WORD(offset);
55 unsigned long result = offset & ~63UL; 60 unsigned long result = offset & ~(BITS_PER_LONG-1);
56 unsigned long tmp; 61 unsigned long tmp;
57 62
58 if (offset >= size) 63 if (offset >= size)
59 return size; 64 return size;
60 size -= result; 65 size -= result;
61 offset &= 63UL; 66 offset %= BITS_PER_LONG;
62 if (offset) { 67 if (offset) {
63 tmp = *(p++); 68 tmp = *(p++);
64 tmp &= (~0UL << offset); 69 tmp |= ~0UL >> (BITS_PER_LONG - offset);
65 if (size < 64) 70 if (size < BITS_PER_LONG)
66 goto found_first; 71 goto found_first;
67 if (tmp) 72 if (~tmp)
68 goto found_middle; 73 goto found_middle;
69 size -= 64; 74 size -= BITS_PER_LONG;
70 result += 64; 75 result += BITS_PER_LONG;
71 } 76 }
72 while (size & ~63UL) { 77 while (size & ~(BITS_PER_LONG-1)) {
73 if ((tmp = *(p++))) 78 if (~(tmp = *(p++)))
74 goto found_middle; 79 goto found_middle;
75 result += 64; 80 result += BITS_PER_LONG;
76 size -= 64; 81 size -= BITS_PER_LONG;
77 } 82 }
78 if (!size) 83 if (!size)
79 return result; 84 return result;
80 tmp = *p; 85 tmp = *p;
81 86
82found_first: 87found_first:
83 tmp &= (~0UL >> (64 - size)); 88 tmp |= ~0UL << size;
84 if (tmp == 0UL) /* Are any bits set? */ 89 if (tmp == ~0UL) /* Are any bits zero? */
85 return result + size; /* Nope. */ 90 return result + size; /* Nope. */
86found_middle: 91found_middle:
87 return result + __ffs(tmp); 92 return result + ffz(tmp);
88} 93}
89 94EXPORT_SYMBOL(find_next_zero_bit);
90EXPORT_SYMBOL(find_next_bit);
91 95
92static inline unsigned int ext2_ilog2(unsigned int x) 96static inline unsigned int ext2_ilog2(unsigned int x)
93{ 97{
@@ -106,8 +110,8 @@ static inline unsigned int ext2_ffz(unsigned int x)
106 return rc; 110 return rc;
107} 111}
108 112
109unsigned long find_next_zero_le_bit(const unsigned long *addr, unsigned long size, 113unsigned long find_next_zero_le_bit(const unsigned long *addr,
110 unsigned long offset) 114 unsigned long size, unsigned long offset)
111{ 115{
112 const unsigned int *p = ((const unsigned int *)addr) + (offset >> 5); 116 const unsigned int *p = ((const unsigned int *)addr) + (offset >> 5);
113 unsigned int result = offset & ~31; 117 unsigned int result = offset & ~31;
@@ -143,5 +147,4 @@ found_first:
143found_middle: 147found_middle:
144 return result + ext2_ffz(tmp); 148 return result + ext2_ffz(tmp);
145} 149}
146
147EXPORT_SYMBOL(find_next_zero_le_bit); 150EXPORT_SYMBOL(find_next_zero_le_bit);
diff --git a/arch/ppc/Makefile b/arch/ppc/Makefile
index 94d5716fa7c3..e719a4933af1 100644
--- a/arch/ppc/Makefile
+++ b/arch/ppc/Makefile
@@ -66,7 +66,8 @@ head-$(CONFIG_PPC_FPU) += arch/powerpc/kernel/fpu.o
66core-y += arch/ppc/kernel/ arch/powerpc/kernel/ \ 66core-y += arch/ppc/kernel/ arch/powerpc/kernel/ \
67 arch/ppc/platforms/ \ 67 arch/ppc/platforms/ \
68 arch/ppc/mm/ arch/ppc/lib/ \ 68 arch/ppc/mm/ arch/ppc/lib/ \
69 arch/ppc/syslib/ arch/powerpc/sysdev/ 69 arch/ppc/syslib/ arch/powerpc/sysdev/ \
70 arch/powerpc/lib/
70core-$(CONFIG_4xx) += arch/ppc/platforms/4xx/ 71core-$(CONFIG_4xx) += arch/ppc/platforms/4xx/
71core-$(CONFIG_83xx) += arch/ppc/platforms/83xx/ 72core-$(CONFIG_83xx) += arch/ppc/platforms/83xx/
72core-$(CONFIG_85xx) += arch/ppc/platforms/85xx/ 73core-$(CONFIG_85xx) += arch/ppc/platforms/85xx/
diff --git a/arch/ppc/kernel/bitops.c b/arch/ppc/kernel/bitops.c
deleted file mode 100644
index 7f53d193968b..000000000000
--- a/arch/ppc/kernel/bitops.c
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * Copyright (C) 1996 Paul Mackerras.
3 */
4
5#include <linux/kernel.h>
6#include <linux/bitops.h>
7
8/*
9 * If the bitops are not inlined in bitops.h, they are defined here.
10 * -- paulus
11 */
12#if !__INLINE_BITOPS
13void set_bit(int nr, volatile void * addr)
14{
15 unsigned long old;
16 unsigned long mask = 1 << (nr & 0x1f);
17 unsigned long *p = ((unsigned long *)addr) + (nr >> 5);
18
19 __asm__ __volatile__(SMP_WMB "\n\
201: lwarx %0,0,%3 \n\
21 or %0,%0,%2 \n"
22 PPC405_ERR77(0,%3)
23" stwcx. %0,0,%3 \n\
24 bne 1b"
25 SMP_MB
26 : "=&r" (old), "=m" (*p)
27 : "r" (mask), "r" (p), "m" (*p)
28 : "cc" );
29}
30
31void clear_bit(int nr, volatile void *addr)
32{
33 unsigned long old;
34 unsigned long mask = 1 << (nr & 0x1f);
35 unsigned long *p = ((unsigned long *)addr) + (nr >> 5);
36
37 __asm__ __volatile__(SMP_WMB "\n\
381: lwarx %0,0,%3 \n\
39 andc %0,%0,%2 \n"
40 PPC405_ERR77(0,%3)
41" stwcx. %0,0,%3 \n\
42 bne 1b"
43 SMP_MB
44 : "=&r" (old), "=m" (*p)
45 : "r" (mask), "r" (p), "m" (*p)
46 : "cc");
47}
48
49void change_bit(int nr, volatile void *addr)
50{
51 unsigned long old;
52 unsigned long mask = 1 << (nr & 0x1f);
53 unsigned long *p = ((unsigned long *)addr) + (nr >> 5);
54
55 __asm__ __volatile__(SMP_WMB "\n\
561: lwarx %0,0,%3 \n\
57 xor %0,%0,%2 \n"
58 PPC405_ERR77(0,%3)
59" stwcx. %0,0,%3 \n\
60 bne 1b"
61 SMP_MB
62 : "=&r" (old), "=m" (*p)
63 : "r" (mask), "r" (p), "m" (*p)
64 : "cc");
65}
66
67int test_and_set_bit(int nr, volatile void *addr)
68{
69 unsigned int old, t;
70 unsigned int mask = 1 << (nr & 0x1f);
71 volatile unsigned int *p = ((volatile unsigned int *)addr) + (nr >> 5);
72
73 __asm__ __volatile__(SMP_WMB "\n\
741: lwarx %0,0,%4 \n\
75 or %1,%0,%3 \n"
76 PPC405_ERR77(0,%4)
77" stwcx. %1,0,%4 \n\
78 bne 1b"
79 SMP_MB
80 : "=&r" (old), "=&r" (t), "=m" (*p)
81 : "r" (mask), "r" (p), "m" (*p)
82 : "cc");
83
84 return (old & mask) != 0;
85}
86
87int test_and_clear_bit(int nr, volatile void *addr)
88{
89 unsigned int old, t;
90 unsigned int mask = 1 << (nr & 0x1f);
91 volatile unsigned int *p = ((volatile unsigned int *)addr) + (nr >> 5);
92
93 __asm__ __volatile__(SMP_WMB "\n\
941: lwarx %0,0,%4 \n\
95 andc %1,%0,%3 \n"
96 PPC405_ERR77(0,%4)
97" stwcx. %1,0,%4 \n\
98 bne 1b"
99 SMP_MB
100 : "=&r" (old), "=&r" (t), "=m" (*p)
101 : "r" (mask), "r" (p), "m" (*p)
102 : "cc");
103
104 return (old & mask) != 0;
105}
106
107int test_and_change_bit(int nr, volatile void *addr)
108{
109 unsigned int old, t;
110 unsigned int mask = 1 << (nr & 0x1f);
111 volatile unsigned int *p = ((volatile unsigned int *)addr) + (nr >> 5);
112
113 __asm__ __volatile__(SMP_WMB "\n\
1141: lwarx %0,0,%4 \n\
115 xor %1,%0,%3 \n"
116 PPC405_ERR77(0,%4)
117" stwcx. %1,0,%4 \n\
118 bne 1b"
119 SMP_MB
120 : "=&r" (old), "=&r" (t), "=m" (*p)
121 : "r" (mask), "r" (p), "m" (*p)
122 : "cc");
123
124 return (old & mask) != 0;
125}
126#endif /* !__INLINE_BITOPS */
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 \