Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'arm64-klib' into upstream

* arm64-klib:
arm64: klib: Optimised atomic bitops
arm64: klib: Optimised string functions
arm64: klib: Optimised memory functions

+417 -17
-1
arch/arm64/include/asm/Kbuild
··· 39 39 generic-y += sizes.h 40 40 generic-y += socket.h 41 41 generic-y += sockios.h 42 - generic-y += string.h 43 42 generic-y += switch_to.h 44 43 generic-y += swab.h 45 44 generic-y += termbits.h
+16 -2
arch/arm64/include/asm/bitops.h
··· 32 32 #error only <linux/bitops.h> can be included directly 33 33 #endif 34 34 35 + /* 36 + * Little endian assembly atomic bitops. 37 + */ 38 + extern void set_bit(int nr, volatile unsigned long *p); 39 + extern void clear_bit(int nr, volatile unsigned long *p); 40 + extern void change_bit(int nr, volatile unsigned long *p); 41 + extern int test_and_set_bit(int nr, volatile unsigned long *p); 42 + extern int test_and_clear_bit(int nr, volatile unsigned long *p); 43 + extern int test_and_change_bit(int nr, volatile unsigned long *p); 44 + 35 45 #include <asm-generic/bitops/builtin-__ffs.h> 36 46 #include <asm-generic/bitops/builtin-ffs.h> 37 47 #include <asm-generic/bitops/builtin-__fls.h> ··· 55 45 #include <asm-generic/bitops/hweight.h> 56 46 #include <asm-generic/bitops/lock.h> 57 47 58 - #include <asm-generic/bitops/atomic.h> 59 48 #include <asm-generic/bitops/non-atomic.h> 60 49 #include <asm-generic/bitops/le.h> 61 - #include <asm-generic/bitops/ext2-atomic.h> 50 + 51 + /* 52 + * Ext2 is defined to use little-endian byte ordering. 53 + */ 54 + #define ext2_set_bit_atomic(lock, nr, p) test_and_set_bit_le(nr, p) 55 + #define ext2_clear_bit_atomic(lock, nr, p) test_and_clear_bit_le(nr, p) 62 56 63 57 #endif /* __ASM_BITOPS_H */
+16 -5
arch/arm64/kernel/arm64ksyms.c
··· 39 39 EXPORT_SYMBOL(__copy_to_user); 40 40 EXPORT_SYMBOL(__clear_user); 41 41 42 - /* bitops */ 43 - #ifdef CONFIG_SMP 44 - EXPORT_SYMBOL(__atomic_hash); 45 - #endif 46 - 47 42 /* physical memory */ 48 43 EXPORT_SYMBOL(memstart_addr); 44 + 45 + /* string / mem functions */ 46 + EXPORT_SYMBOL(strchr); 47 + EXPORT_SYMBOL(strrchr); 48 + EXPORT_SYMBOL(memset); 49 + EXPORT_SYMBOL(memcpy); 50 + EXPORT_SYMBOL(memmove); 51 + EXPORT_SYMBOL(memchr); 52 + 53 + /* atomic bitops */ 54 + EXPORT_SYMBOL(set_bit); 55 + EXPORT_SYMBOL(test_and_set_bit); 56 + EXPORT_SYMBOL(clear_bit); 57 + EXPORT_SYMBOL(test_and_clear_bit); 58 + EXPORT_SYMBOL(change_bit); 59 + EXPORT_SYMBOL(test_and_change_bit);
+3 -1
arch/arm64/lib/Makefile
··· 1 1 lib-y := bitops.o delay.o \ 2 2 strncpy_from_user.o strnlen_user.o clear_user.o \ 3 3 copy_from_user.o copy_to_user.o copy_in_user.o \ 4 - copy_page.o clear_page.o 4 + copy_page.o clear_page.o \ 5 + memchr.o memcpy.o memmove.o memset.o \ 6 + strchr.o strrchr.o
+70
arch/arm64/lib/bitops.S
··· 1 + /* 2 + * Based on arch/arm/lib/bitops.h 3 + * 4 + * Copyright (C) 2013 ARM Ltd. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 + */ 18 + 19 + #include <linux/linkage.h> 20 + #include <asm/assembler.h> 21 + 22 + /* 23 + * x0: bits 5:0 bit offset 24 + * bits 63:6 word offset 25 + * x1: address 26 + */ 27 + .macro bitop, name, instr 28 + ENTRY( \name ) 29 + and x3, x0, #63 // Get bit offset 30 + eor x0, x0, x3 // Clear low bits 31 + mov x2, #1 32 + add x1, x1, x0, lsr #3 // Get word offset 33 + lsl x3, x2, x3 // Create mask 34 + 1: ldxr x2, [x1] 35 + \instr x2, x2, x3 36 + stxr w0, x2, [x1] 37 + cbnz w0, 1b 38 + ret 39 + ENDPROC(\name ) 40 + .endm 41 + 42 + .macro testop, name, instr 43 + ENTRY( \name ) 44 + and x3, x0, #63 // Get bit offset 45 + eor x0, x0, x3 // Clear low bits 46 + mov x2, #1 47 + add x1, x1, x0, lsr #3 // Get word offset 48 + lsl x4, x2, x3 // Create mask 49 + smp_dmb ish 50 + 1: ldxr x2, [x1] 51 + lsr x0, x2, x3 // Save old value of bit 52 + \instr x2, x2, x4 // toggle bit 53 + stxr w2, x2, [x1] 54 + cbnz w2, 1b 55 + smp_dmb ish 56 + and x0, x0, #1 57 + 3: ret 58 + ENDPROC(\name ) 59 + .endm 60 + 61 + /* 62 + * Atomic bit operations. 63 + */ 64 + bitop change_bit, eor 65 + bitop clear_bit, bic 66 + bitop set_bit, orr 67 + 68 + testop test_and_change_bit, eor 69 + testop test_and_clear_bit, bic 70 + testop test_and_set_bit, orr
+20 -8
arch/arm64/lib/bitops.c arch/arm64/include/asm/string.h
··· 1 1 /* 2 - * Copyright (C) 2012 ARM Limited 2 + * Copyright (C) 2013 ARM Ltd. 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License version 2 as ··· 13 13 * You should have received a copy of the GNU General Public License 14 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 15 */ 16 + #ifndef __ASM_STRING_H 17 + #define __ASM_STRING_H 16 18 17 - #include <linux/kernel.h> 18 - #include <linux/spinlock.h> 19 - #include <linux/atomic.h> 19 + #define __HAVE_ARCH_STRRCHR 20 + extern char *strrchr(const char *, int c); 20 21 21 - #ifdef CONFIG_SMP 22 - arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = { 23 - [0 ... (ATOMIC_HASH_SIZE-1)] = __ARCH_SPIN_LOCK_UNLOCKED 24 - }; 22 + #define __HAVE_ARCH_STRCHR 23 + extern char *strchr(const char *, int c); 24 + 25 + #define __HAVE_ARCH_MEMCPY 26 + extern void *memcpy(void *, const void *, __kernel_size_t); 27 + 28 + #define __HAVE_ARCH_MEMMOVE 29 + extern void *memmove(void *, const void *, __kernel_size_t); 30 + 31 + #define __HAVE_ARCH_MEMCHR 32 + extern void *memchr(const void *, int, __kernel_size_t); 33 + 34 + #define __HAVE_ARCH_MEMSET 35 + extern void *memset(void *, int, __kernel_size_t); 36 + 25 37 #endif
+44
arch/arm64/lib/memchr.S
··· 1 + /* 2 + * Based on arch/arm/lib/memchr.S 3 + * 4 + * Copyright (C) 1995-2000 Russell King 5 + * Copyright (C) 2013 ARM Ltd. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/linkage.h> 21 + #include <asm/assembler.h> 22 + 23 + /* 24 + * Find a character in an area of memory. 25 + * 26 + * Parameters: 27 + * x0 - buf 28 + * x1 - c 29 + * x2 - n 30 + * Returns: 31 + * x0 - address of first occurrence of 'c' or 0 32 + */ 33 + ENTRY(memchr) 34 + and w1, w1, #0xff 35 + 1: subs x2, x2, #1 36 + b.mi 2f 37 + ldrb w3, [x0], #1 38 + cmp w3, w1 39 + b.ne 1b 40 + sub x0, x0, #1 41 + ret 42 + 2: mov x0, #0 43 + ret 44 + ENDPROC(memchr)
+53
arch/arm64/lib/memcpy.S
··· 1 + /* 2 + * Copyright (C) 2013 ARM Ltd. 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #include <linux/linkage.h> 18 + #include <asm/assembler.h> 19 + 20 + /* 21 + * Copy a buffer from src to dest (alignment handled by the hardware) 22 + * 23 + * Parameters: 24 + * x0 - dest 25 + * x1 - src 26 + * x2 - n 27 + * Returns: 28 + * x0 - dest 29 + */ 30 + ENTRY(memcpy) 31 + mov x4, x0 32 + subs x2, x2, #8 33 + b.mi 2f 34 + 1: ldr x3, [x1], #8 35 + subs x2, x2, #8 36 + str x3, [x4], #8 37 + b.pl 1b 38 + 2: adds x2, x2, #4 39 + b.mi 3f 40 + ldr w3, [x1], #4 41 + sub x2, x2, #4 42 + str w3, [x4], #4 43 + 3: adds x2, x2, #2 44 + b.mi 4f 45 + ldrh w3, [x1], #2 46 + sub x2, x2, #2 47 + strh w3, [x4], #2 48 + 4: adds x2, x2, #1 49 + b.mi 5f 50 + ldrb w3, [x1] 51 + strb w3, [x4] 52 + 5: ret 53 + ENDPROC(memcpy)
+57
arch/arm64/lib/memmove.S
··· 1 + /* 2 + * Copyright (C) 2013 ARM Ltd. 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #include <linux/linkage.h> 18 + #include <asm/assembler.h> 19 + 20 + /* 21 + * Move a buffer from src to test (alignment handled by the hardware). 22 + * If dest <= src, call memcpy, otherwise copy in reverse order. 23 + * 24 + * Parameters: 25 + * x0 - dest 26 + * x1 - src 27 + * x2 - n 28 + * Returns: 29 + * x0 - dest 30 + */ 31 + ENTRY(memmove) 32 + cmp x0, x1 33 + b.ls memcpy 34 + add x4, x0, x2 35 + add x1, x1, x2 36 + subs x2, x2, #8 37 + b.mi 2f 38 + 1: ldr x3, [x1, #-8]! 39 + subs x2, x2, #8 40 + str x3, [x4, #-8]! 41 + b.pl 1b 42 + 2: adds x2, x2, #4 43 + b.mi 3f 44 + ldr w3, [x1, #-4]! 45 + sub x2, x2, #4 46 + str w3, [x4, #-4]! 47 + 3: adds x2, x2, #2 48 + b.mi 4f 49 + ldrh w3, [x1, #-2]! 50 + sub x2, x2, #2 51 + strh w3, [x4, #-2]! 52 + 4: adds x2, x2, #1 53 + b.mi 5f 54 + ldrb w3, [x1, #-1] 55 + strb w3, [x4, #-1] 56 + 5: ret 57 + ENDPROC(memmove)
+53
arch/arm64/lib/memset.S
··· 1 + /* 2 + * Copyright (C) 2013 ARM Ltd. 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #include <linux/linkage.h> 18 + #include <asm/assembler.h> 19 + 20 + /* 21 + * Fill in the buffer with character c (alignment handled by the hardware) 22 + * 23 + * Parameters: 24 + * x0 - buf 25 + * x1 - c 26 + * x2 - n 27 + * Returns: 28 + * x0 - buf 29 + */ 30 + ENTRY(memset) 31 + mov x4, x0 32 + and w1, w1, #0xff 33 + orr w1, w1, w1, lsl #8 34 + orr w1, w1, w1, lsl #16 35 + orr x1, x1, x1, lsl #32 36 + subs x2, x2, #8 37 + b.mi 2f 38 + 1: str x1, [x4], #8 39 + subs x2, x2, #8 40 + b.pl 1b 41 + 2: adds x2, x2, #4 42 + b.mi 3f 43 + sub x2, x2, #4 44 + str w1, [x4], #4 45 + 3: adds x2, x2, #2 46 + b.mi 4f 47 + sub x2, x2, #2 48 + strh w1, [x4], #2 49 + 4: adds x2, x2, #1 50 + b.mi 5f 51 + strb w1, [x4] 52 + 5: ret 53 + ENDPROC(memset)
+42
arch/arm64/lib/strchr.S
··· 1 + /* 2 + * Based on arch/arm/lib/strchr.S 3 + * 4 + * Copyright (C) 1995-2000 Russell King 5 + * Copyright (C) 2013 ARM Ltd. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/linkage.h> 21 + #include <asm/assembler.h> 22 + 23 + /* 24 + * Find the first occurrence of a character in a string. 25 + * 26 + * Parameters: 27 + * x0 - str 28 + * x1 - c 29 + * Returns: 30 + * x0 - address of first occurrence of 'c' or 0 31 + */ 32 + ENTRY(strchr) 33 + and w1, w1, #0xff 34 + 1: ldrb w2, [x0], #1 35 + cmp w2, w1 36 + ccmp w2, wzr, #4, ne 37 + b.ne 1b 38 + sub x0, x0, #1 39 + cmp w2, w1 40 + csel x0, x0, xzr, eq 41 + ret 42 + ENDPROC(strchr)
+43
arch/arm64/lib/strrchr.S
··· 1 + /* 2 + * Based on arch/arm/lib/strrchr.S 3 + * 4 + * Copyright (C) 1995-2000 Russell King 5 + * Copyright (C) 2013 ARM Ltd. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/linkage.h> 21 + #include <asm/assembler.h> 22 + 23 + /* 24 + * Find the last occurrence of a character in a string. 25 + * 26 + * Parameters: 27 + * x0 - str 28 + * x1 - c 29 + * Returns: 30 + * x0 - address of last occurrence of 'c' or 0 31 + */ 32 + ENTRY(strrchr) 33 + mov x3, #0 34 + and w1, w1, #0xff 35 + 1: ldrb w2, [x0], #1 36 + cbz w2, 2f 37 + cmp w2, w1 38 + b.ne 1b 39 + sub x3, x0, #1 40 + b 1b 41 + 2: mov x0, x3 42 + ret 43 + ENDPROC(strrchr)