xref: /linux/arch/arm64/include/asm/xor.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2cc9f8349SJackie Liu /*
3cc9f8349SJackie Liu  * arch/arm64/include/asm/xor.h
4cc9f8349SJackie Liu  *
5cc9f8349SJackie Liu  * Authors: Jackie Liu <liuyun01@kylinos.cn>
6cc9f8349SJackie Liu  * Copyright (C) 2018,Tianjin KYLIN Information Technology Co., Ltd.
7cc9f8349SJackie Liu  */
8cc9f8349SJackie Liu 
9cc9f8349SJackie Liu #include <linux/hardirq.h>
10cc9f8349SJackie Liu #include <asm-generic/xor.h>
11cc9f8349SJackie Liu #include <asm/hwcap.h>
12cc9f8349SJackie Liu #include <asm/neon.h>
13cc9f8349SJackie Liu 
14cc9f8349SJackie Liu #ifdef CONFIG_KERNEL_MODE_NEON
15cc9f8349SJackie Liu 
16cc9f8349SJackie Liu extern struct xor_block_template const xor_block_inner_neon;
17cc9f8349SJackie Liu 
18cc9f8349SJackie Liu static void
xor_neon_2(unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2)19*297565aaSArd Biesheuvel xor_neon_2(unsigned long bytes, unsigned long * __restrict p1,
20*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p2)
21cc9f8349SJackie Liu {
22cc9f8349SJackie Liu 	kernel_neon_begin();
23cc9f8349SJackie Liu 	xor_block_inner_neon.do_2(bytes, p1, p2);
24cc9f8349SJackie Liu 	kernel_neon_end();
25cc9f8349SJackie Liu }
26cc9f8349SJackie Liu 
27cc9f8349SJackie Liu static void
xor_neon_3(unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3)28*297565aaSArd Biesheuvel xor_neon_3(unsigned long bytes, unsigned long * __restrict p1,
29*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p2,
30*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p3)
31cc9f8349SJackie Liu {
32cc9f8349SJackie Liu 	kernel_neon_begin();
33cc9f8349SJackie Liu 	xor_block_inner_neon.do_3(bytes, p1, p2, p3);
34cc9f8349SJackie Liu 	kernel_neon_end();
35cc9f8349SJackie Liu }
36cc9f8349SJackie Liu 
37cc9f8349SJackie Liu static void
xor_neon_4(unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3,const unsigned long * __restrict p4)38*297565aaSArd Biesheuvel xor_neon_4(unsigned long bytes, unsigned long * __restrict p1,
39*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p2,
40*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p3,
41*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p4)
42cc9f8349SJackie Liu {
43cc9f8349SJackie Liu 	kernel_neon_begin();
44cc9f8349SJackie Liu 	xor_block_inner_neon.do_4(bytes, p1, p2, p3, p4);
45cc9f8349SJackie Liu 	kernel_neon_end();
46cc9f8349SJackie Liu }
47cc9f8349SJackie Liu 
48cc9f8349SJackie Liu static void
xor_neon_5(unsigned long bytes,unsigned long * __restrict p1,const unsigned long * __restrict p2,const unsigned long * __restrict p3,const unsigned long * __restrict p4,const unsigned long * __restrict p5)49*297565aaSArd Biesheuvel xor_neon_5(unsigned long bytes, unsigned long * __restrict p1,
50*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p2,
51*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p3,
52*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p4,
53*297565aaSArd Biesheuvel 	   const unsigned long * __restrict p5)
54cc9f8349SJackie Liu {
55cc9f8349SJackie Liu 	kernel_neon_begin();
56cc9f8349SJackie Liu 	xor_block_inner_neon.do_5(bytes, p1, p2, p3, p4, p5);
57cc9f8349SJackie Liu 	kernel_neon_end();
58cc9f8349SJackie Liu }
59cc9f8349SJackie Liu 
60cc9f8349SJackie Liu static struct xor_block_template xor_block_arm64 = {
61cc9f8349SJackie Liu 	.name   = "arm64_neon",
62cc9f8349SJackie Liu 	.do_2   = xor_neon_2,
63cc9f8349SJackie Liu 	.do_3   = xor_neon_3,
64cc9f8349SJackie Liu 	.do_4   = xor_neon_4,
65cc9f8349SJackie Liu 	.do_5	= xor_neon_5
66cc9f8349SJackie Liu };
67cc9f8349SJackie Liu #undef XOR_TRY_TEMPLATES
68cc9f8349SJackie Liu #define XOR_TRY_TEMPLATES           \
69cc9f8349SJackie Liu 	do {        \
70cc9f8349SJackie Liu 		xor_speed(&xor_block_8regs);    \
71cc9f8349SJackie Liu 		xor_speed(&xor_block_32regs);    \
72cc9f8349SJackie Liu 		if (cpu_has_neon()) { \
73cc9f8349SJackie Liu 			xor_speed(&xor_block_arm64);\
74cc9f8349SJackie Liu 		} \
75cc9f8349SJackie Liu 	} while (0)
76cc9f8349SJackie Liu 
77cc9f8349SJackie Liu #endif /* ! CONFIG_KERNEL_MODE_NEON */
78