blob: fd2d09afa0974b59a0bf54063682e6502fb44573 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* Written 2003 by Andi Kleen, based on a kernel by Evandro Menezes */
Dave Jones038b0a62006-10-04 03:38:54 -04003
Jan Beulich8d379da2006-09-26 10:52:32 +02004#include <linux/linkage.h>
Borislav Petkovcd4d09e2016-01-26 22:12:04 +01005#include <asm/cpufeatures.h>
Andy Lutomirski59e97e42011-07-13 09:24:10 -04006#include <asm/alternative-asm.h>
Al Viro784d5692016-01-11 11:04:34 -05007#include <asm/export.h>
Jan Beulich8d379da2006-09-26 10:52:32 +02008
Borislav Petkov090a3f62015-01-12 18:19:40 +01009/*
10 * Some CPUs run faster using the string copy instructions (sane microcode).
11 * It is also a lot simpler. Use this when possible. But, don't use streaming
12 * copy unless the CPU indicates X86_FEATURE_REP_GOOD. Could vary the
13 * prefetch distance based on SMP/UP.
14 */
Jan Beulich8d379da2006-09-26 10:52:32 +020015 ALIGN
Borislav Petkov090a3f62015-01-12 18:19:40 +010016ENTRY(copy_page)
Borislav Petkov090a3f62015-01-12 18:19:40 +010017 ALTERNATIVE "jmp copy_page_regs", "", X86_FEATURE_REP_GOOD
Ma Ling269833b2012-10-18 03:52:45 +080018 movl $4096/8, %ecx
19 rep movsq
Jan Beulich8d379da2006-09-26 10:52:32 +020020 ret
Borislav Petkov090a3f62015-01-12 18:19:40 +010021ENDPROC(copy_page)
Al Viro784d5692016-01-11 11:04:34 -050022EXPORT_SYMBOL(copy_page)
Jan Beulich8d379da2006-09-26 10:52:32 +020023
Borislav Petkov090a3f62015-01-12 18:19:40 +010024ENTRY(copy_page_regs)
Ma Ling269833b2012-10-18 03:52:45 +080025 subq $2*8, %rsp
Ma Ling269833b2012-10-18 03:52:45 +080026 movq %rbx, (%rsp)
Ma Ling269833b2012-10-18 03:52:45 +080027 movq %r12, 1*8(%rsp)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010028
Ma Ling269833b2012-10-18 03:52:45 +080029 movl $(4096/64)-5, %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010030 .p2align 4
31.Loop64:
Ma Ling269833b2012-10-18 03:52:45 +080032 dec %rcx
33 movq 0x8*0(%rsi), %rax
34 movq 0x8*1(%rsi), %rbx
35 movq 0x8*2(%rsi), %rdx
36 movq 0x8*3(%rsi), %r8
37 movq 0x8*4(%rsi), %r9
38 movq 0x8*5(%rsi), %r10
39 movq 0x8*6(%rsi), %r11
40 movq 0x8*7(%rsi), %r12
Andi Kleen7bcd3f32006-02-03 21:51:02 +010041
42 prefetcht0 5*64(%rsi)
43
Ma Ling269833b2012-10-18 03:52:45 +080044 movq %rax, 0x8*0(%rdi)
45 movq %rbx, 0x8*1(%rdi)
46 movq %rdx, 0x8*2(%rdi)
47 movq %r8, 0x8*3(%rdi)
48 movq %r9, 0x8*4(%rdi)
49 movq %r10, 0x8*5(%rdi)
50 movq %r11, 0x8*6(%rdi)
51 movq %r12, 0x8*7(%rdi)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010052
Ma Ling269833b2012-10-18 03:52:45 +080053 leaq 64 (%rsi), %rsi
54 leaq 64 (%rdi), %rdi
Andi Kleen7bcd3f32006-02-03 21:51:02 +010055
Ma Ling269833b2012-10-18 03:52:45 +080056 jnz .Loop64
Andi Kleen7bcd3f32006-02-03 21:51:02 +010057
Ma Ling269833b2012-10-18 03:52:45 +080058 movl $5, %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010059 .p2align 4
60.Loop2:
Ma Ling269833b2012-10-18 03:52:45 +080061 decl %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010062
Ma Ling269833b2012-10-18 03:52:45 +080063 movq 0x8*0(%rsi), %rax
64 movq 0x8*1(%rsi), %rbx
65 movq 0x8*2(%rsi), %rdx
66 movq 0x8*3(%rsi), %r8
67 movq 0x8*4(%rsi), %r9
68 movq 0x8*5(%rsi), %r10
69 movq 0x8*6(%rsi), %r11
70 movq 0x8*7(%rsi), %r12
Andi Kleen7bcd3f32006-02-03 21:51:02 +010071
Ma Ling269833b2012-10-18 03:52:45 +080072 movq %rax, 0x8*0(%rdi)
73 movq %rbx, 0x8*1(%rdi)
74 movq %rdx, 0x8*2(%rdi)
75 movq %r8, 0x8*3(%rdi)
76 movq %r9, 0x8*4(%rdi)
77 movq %r10, 0x8*5(%rdi)
78 movq %r11, 0x8*6(%rdi)
79 movq %r12, 0x8*7(%rdi)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010080
Ma Ling269833b2012-10-18 03:52:45 +080081 leaq 64(%rdi), %rdi
82 leaq 64(%rsi), %rsi
Andi Kleen7bcd3f32006-02-03 21:51:02 +010083 jnz .Loop2
84
Ma Ling269833b2012-10-18 03:52:45 +080085 movq (%rsp), %rbx
Ma Ling269833b2012-10-18 03:52:45 +080086 movq 1*8(%rsp), %r12
Ma Ling269833b2012-10-18 03:52:45 +080087 addq $2*8, %rsp
Andi Kleen7bcd3f32006-02-03 21:51:02 +010088 ret
Borislav Petkov090a3f62015-01-12 18:19:40 +010089ENDPROC(copy_page_regs)