18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) IBM Corporation, 2012
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Author: Anton Blanchard <anton@au.ibm.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#include <asm/page.h>
98c2ecf20Sopenharmony_ci#include <asm/ppc_asm.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci_GLOBAL(copypage_power7)
128c2ecf20Sopenharmony_ci	/*
138c2ecf20Sopenharmony_ci	 * We prefetch both the source and destination using enhanced touch
148c2ecf20Sopenharmony_ci	 * instructions. We use a stream ID of 0 for the load side and
158c2ecf20Sopenharmony_ci	 * 1 for the store side. Since source and destination are page
168c2ecf20Sopenharmony_ci	 * aligned we don't need to clear the bottom 7 bits of either
178c2ecf20Sopenharmony_ci	 * address.
188c2ecf20Sopenharmony_ci	 */
198c2ecf20Sopenharmony_ci	ori	r9,r3,1		/* stream=1 => to */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_64K_PAGES
228c2ecf20Sopenharmony_ci	lis	r7,0x0E01	/* depth=7
238c2ecf20Sopenharmony_ci				 * units/cachelines=512 */
248c2ecf20Sopenharmony_ci#else
258c2ecf20Sopenharmony_ci	lis	r7,0x0E00	/* depth=7 */
268c2ecf20Sopenharmony_ci	ori	r7,r7,0x1000	/* units/cachelines=32 */
278c2ecf20Sopenharmony_ci#endif
288c2ecf20Sopenharmony_ci	ori	r10,r7,1	/* stream=1 */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	lis	r8,0x8000	/* GO=1 */
318c2ecf20Sopenharmony_ci	clrldi	r8,r8,32
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* setup read stream 0  */
348c2ecf20Sopenharmony_ci	dcbt	0,r4,0b01000  	/* addr from */
358c2ecf20Sopenharmony_ci	dcbt	0,r7,0b01010   /* length and depth from */
368c2ecf20Sopenharmony_ci	/* setup write stream 1 */
378c2ecf20Sopenharmony_ci	dcbtst	0,r9,0b01000   /* addr to */
388c2ecf20Sopenharmony_ci	dcbtst	0,r10,0b01010  /* length and depth to */
398c2ecf20Sopenharmony_ci	eieio
408c2ecf20Sopenharmony_ci	dcbt	0,r8,0b01010	/* all streams GO */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#ifdef CONFIG_ALTIVEC
438c2ecf20Sopenharmony_ci	mflr	r0
448c2ecf20Sopenharmony_ci	std	r3,-STACKFRAMESIZE+STK_REG(R31)(r1)
458c2ecf20Sopenharmony_ci	std	r4,-STACKFRAMESIZE+STK_REG(R30)(r1)
468c2ecf20Sopenharmony_ci	std	r0,16(r1)
478c2ecf20Sopenharmony_ci	stdu	r1,-STACKFRAMESIZE(r1)
488c2ecf20Sopenharmony_ci	bl	enter_vmx_ops
498c2ecf20Sopenharmony_ci	cmpwi	r3,0
508c2ecf20Sopenharmony_ci	ld	r0,STACKFRAMESIZE+16(r1)
518c2ecf20Sopenharmony_ci	ld	r3,STK_REG(R31)(r1)
528c2ecf20Sopenharmony_ci	ld	r4,STK_REG(R30)(r1)
538c2ecf20Sopenharmony_ci	mtlr	r0
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	li	r0,(PAGE_SIZE/128)
568c2ecf20Sopenharmony_ci	mtctr	r0
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	beq	.Lnonvmx_copy
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	addi	r1,r1,STACKFRAMESIZE
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	li	r6,16
638c2ecf20Sopenharmony_ci	li	r7,32
648c2ecf20Sopenharmony_ci	li	r8,48
658c2ecf20Sopenharmony_ci	li	r9,64
668c2ecf20Sopenharmony_ci	li	r10,80
678c2ecf20Sopenharmony_ci	li	r11,96
688c2ecf20Sopenharmony_ci	li	r12,112
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	.align	5
718c2ecf20Sopenharmony_ci1:	lvx	v7,0,r4
728c2ecf20Sopenharmony_ci	lvx	v6,r4,r6
738c2ecf20Sopenharmony_ci	lvx	v5,r4,r7
748c2ecf20Sopenharmony_ci	lvx	v4,r4,r8
758c2ecf20Sopenharmony_ci	lvx	v3,r4,r9
768c2ecf20Sopenharmony_ci	lvx	v2,r4,r10
778c2ecf20Sopenharmony_ci	lvx	v1,r4,r11
788c2ecf20Sopenharmony_ci	lvx	v0,r4,r12
798c2ecf20Sopenharmony_ci	addi	r4,r4,128
808c2ecf20Sopenharmony_ci	stvx	v7,0,r3
818c2ecf20Sopenharmony_ci	stvx	v6,r3,r6
828c2ecf20Sopenharmony_ci	stvx	v5,r3,r7
838c2ecf20Sopenharmony_ci	stvx	v4,r3,r8
848c2ecf20Sopenharmony_ci	stvx	v3,r3,r9
858c2ecf20Sopenharmony_ci	stvx	v2,r3,r10
868c2ecf20Sopenharmony_ci	stvx	v1,r3,r11
878c2ecf20Sopenharmony_ci	stvx	v0,r3,r12
888c2ecf20Sopenharmony_ci	addi	r3,r3,128
898c2ecf20Sopenharmony_ci	bdnz	1b
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	b	exit_vmx_ops		/* tail call optimise */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#else
948c2ecf20Sopenharmony_ci	li	r0,(PAGE_SIZE/128)
958c2ecf20Sopenharmony_ci	mtctr	r0
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	stdu	r1,-STACKFRAMESIZE(r1)
988c2ecf20Sopenharmony_ci#endif
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci.Lnonvmx_copy:
1018c2ecf20Sopenharmony_ci	std	r14,STK_REG(R14)(r1)
1028c2ecf20Sopenharmony_ci	std	r15,STK_REG(R15)(r1)
1038c2ecf20Sopenharmony_ci	std	r16,STK_REG(R16)(r1)
1048c2ecf20Sopenharmony_ci	std	r17,STK_REG(R17)(r1)
1058c2ecf20Sopenharmony_ci	std	r18,STK_REG(R18)(r1)
1068c2ecf20Sopenharmony_ci	std	r19,STK_REG(R19)(r1)
1078c2ecf20Sopenharmony_ci	std	r20,STK_REG(R20)(r1)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci1:	ld	r0,0(r4)
1108c2ecf20Sopenharmony_ci	ld	r5,8(r4)
1118c2ecf20Sopenharmony_ci	ld	r6,16(r4)
1128c2ecf20Sopenharmony_ci	ld	r7,24(r4)
1138c2ecf20Sopenharmony_ci	ld	r8,32(r4)
1148c2ecf20Sopenharmony_ci	ld	r9,40(r4)
1158c2ecf20Sopenharmony_ci	ld	r10,48(r4)
1168c2ecf20Sopenharmony_ci	ld	r11,56(r4)
1178c2ecf20Sopenharmony_ci	ld	r12,64(r4)
1188c2ecf20Sopenharmony_ci	ld	r14,72(r4)
1198c2ecf20Sopenharmony_ci	ld	r15,80(r4)
1208c2ecf20Sopenharmony_ci	ld	r16,88(r4)
1218c2ecf20Sopenharmony_ci	ld	r17,96(r4)
1228c2ecf20Sopenharmony_ci	ld	r18,104(r4)
1238c2ecf20Sopenharmony_ci	ld	r19,112(r4)
1248c2ecf20Sopenharmony_ci	ld	r20,120(r4)
1258c2ecf20Sopenharmony_ci	addi	r4,r4,128
1268c2ecf20Sopenharmony_ci	std	r0,0(r3)
1278c2ecf20Sopenharmony_ci	std	r5,8(r3)
1288c2ecf20Sopenharmony_ci	std	r6,16(r3)
1298c2ecf20Sopenharmony_ci	std	r7,24(r3)
1308c2ecf20Sopenharmony_ci	std	r8,32(r3)
1318c2ecf20Sopenharmony_ci	std	r9,40(r3)
1328c2ecf20Sopenharmony_ci	std	r10,48(r3)
1338c2ecf20Sopenharmony_ci	std	r11,56(r3)
1348c2ecf20Sopenharmony_ci	std	r12,64(r3)
1358c2ecf20Sopenharmony_ci	std	r14,72(r3)
1368c2ecf20Sopenharmony_ci	std	r15,80(r3)
1378c2ecf20Sopenharmony_ci	std	r16,88(r3)
1388c2ecf20Sopenharmony_ci	std	r17,96(r3)
1398c2ecf20Sopenharmony_ci	std	r18,104(r3)
1408c2ecf20Sopenharmony_ci	std	r19,112(r3)
1418c2ecf20Sopenharmony_ci	std	r20,120(r3)
1428c2ecf20Sopenharmony_ci	addi	r3,r3,128
1438c2ecf20Sopenharmony_ci	bdnz	1b
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	ld	r14,STK_REG(R14)(r1)
1468c2ecf20Sopenharmony_ci	ld	r15,STK_REG(R15)(r1)
1478c2ecf20Sopenharmony_ci	ld	r16,STK_REG(R16)(r1)
1488c2ecf20Sopenharmony_ci	ld	r17,STK_REG(R17)(r1)
1498c2ecf20Sopenharmony_ci	ld	r18,STK_REG(R18)(r1)
1508c2ecf20Sopenharmony_ci	ld	r19,STK_REG(R19)(r1)
1518c2ecf20Sopenharmony_ci	ld	r20,STK_REG(R20)(r1)
1528c2ecf20Sopenharmony_ci	addi	r1,r1,STACKFRAMESIZE
1538c2ecf20Sopenharmony_ci	blr
154