1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d73e60b7SRussell King /*
3d73e60b7SRussell King * linux/arch/arm/mm/copypage-v4wt.S
4d73e60b7SRussell King *
5d73e60b7SRussell King * Copyright (C) 1995-1999 Russell King
6d73e60b7SRussell King *
7d73e60b7SRussell King * This is for CPUs with a writethrough cache and 'flush ID cache' is
8d73e60b7SRussell King * the only supported cache operation.
9d73e60b7SRussell King */
10d73e60b7SRussell King #include <linux/init.h>
11063b0a42SRussell King #include <linux/highmem.h>
12d73e60b7SRussell King
13d73e60b7SRussell King /*
14063b0a42SRussell King * ARMv4 optimised copy_user_highpage
15d73e60b7SRussell King *
16d73e60b7SRussell King * Since we have writethrough caches, we don't have to worry about
17d73e60b7SRussell King * dirty data in the cache. However, we do have to ensure that
18d73e60b7SRussell King * subsequent reads are up to date.
19d73e60b7SRussell King */
v4wt_copy_user_page(void * kto,const void * kfrom)20b99afae1SNicolas Pitre static void v4wt_copy_user_page(void *kto, const void *kfrom)
21d73e60b7SRussell King {
22b99afae1SNicolas Pitre int tmp;
23b99afae1SNicolas Pitre
24b99afae1SNicolas Pitre asm volatile ("\
25b7e8c939SStefan Agner .syntax unified\n\
26b99afae1SNicolas Pitre ldmia %1!, {r3, r4, ip, lr} @ 4\n\
27b99afae1SNicolas Pitre 1: stmia %0!, {r3, r4, ip, lr} @ 4\n\
28b99afae1SNicolas Pitre ldmia %1!, {r3, r4, ip, lr} @ 4+1\n\
29b99afae1SNicolas Pitre stmia %0!, {r3, r4, ip, lr} @ 4\n\
30b99afae1SNicolas Pitre ldmia %1!, {r3, r4, ip, lr} @ 4\n\
31b99afae1SNicolas Pitre stmia %0!, {r3, r4, ip, lr} @ 4\n\
32b99afae1SNicolas Pitre ldmia %1!, {r3, r4, ip, lr} @ 4\n\
33b99afae1SNicolas Pitre subs %2, %2, #1 @ 1\n\
34b99afae1SNicolas Pitre stmia %0!, {r3, r4, ip, lr} @ 4\n\
35b7e8c939SStefan Agner ldmiane %1!, {r3, r4, ip, lr} @ 4\n\
36d73e60b7SRussell King bne 1b @ 1\n\
37b99afae1SNicolas Pitre mcr p15, 0, %2, c7, c7, 0 @ flush ID cache"
38b99afae1SNicolas Pitre : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp)
39b99afae1SNicolas Pitre : "2" (PAGE_SIZE / 64)
40b99afae1SNicolas Pitre : "r3", "r4", "ip", "lr");
41d73e60b7SRussell King }
42d73e60b7SRussell King
v4wt_copy_user_highpage(struct page * to,struct page * from,unsigned long vaddr,struct vm_area_struct * vma)43063b0a42SRussell King void v4wt_copy_user_highpage(struct page *to, struct page *from,
44f00a75c0SRussell King unsigned long vaddr, struct vm_area_struct *vma)
45063b0a42SRussell King {
46063b0a42SRussell King void *kto, *kfrom;
47063b0a42SRussell King
485472e862SCong Wang kto = kmap_atomic(to);
495472e862SCong Wang kfrom = kmap_atomic(from);
50063b0a42SRussell King v4wt_copy_user_page(kto, kfrom);
515472e862SCong Wang kunmap_atomic(kfrom);
525472e862SCong Wang kunmap_atomic(kto);
53063b0a42SRussell King }
54063b0a42SRussell King
55d73e60b7SRussell King /*
56d73e60b7SRussell King * ARMv4 optimised clear_user_page
57d73e60b7SRussell King *
58d73e60b7SRussell King * Same story as above.
59d73e60b7SRussell King */
v4wt_clear_user_highpage(struct page * page,unsigned long vaddr)60303c6443SRussell King void v4wt_clear_user_highpage(struct page *page, unsigned long vaddr)
61d73e60b7SRussell King {
625472e862SCong Wang void *ptr, *kaddr = kmap_atomic(page);
6343ae286bSNicolas Pitre asm volatile("\
6443ae286bSNicolas Pitre mov r1, %2 @ 1\n\
65d73e60b7SRussell King mov r2, #0 @ 1\n\
66d73e60b7SRussell King mov r3, #0 @ 1\n\
67d73e60b7SRussell King mov ip, #0 @ 1\n\
68d73e60b7SRussell King mov lr, #0 @ 1\n\
69303c6443SRussell King 1: stmia %0!, {r2, r3, ip, lr} @ 4\n\
70303c6443SRussell King stmia %0!, {r2, r3, ip, lr} @ 4\n\
71303c6443SRussell King stmia %0!, {r2, r3, ip, lr} @ 4\n\
72303c6443SRussell King stmia %0!, {r2, r3, ip, lr} @ 4\n\
73d73e60b7SRussell King subs r1, r1, #1 @ 1\n\
74d73e60b7SRussell King bne 1b @ 1\n\
75303c6443SRussell King mcr p15, 0, r2, c7, c7, 0 @ flush ID cache"
7643ae286bSNicolas Pitre : "=r" (ptr)
7743ae286bSNicolas Pitre : "0" (kaddr), "I" (PAGE_SIZE / 64)
78303c6443SRussell King : "r1", "r2", "r3", "ip", "lr");
795472e862SCong Wang kunmap_atomic(kaddr);
80d73e60b7SRussell King }
81d73e60b7SRussell King
82d73e60b7SRussell King struct cpu_user_fns v4wt_user_fns __initdata = {
83303c6443SRussell King .cpu_clear_user_highpage = v4wt_clear_user_highpage,
84063b0a42SRussell King .cpu_copy_user_highpage = v4wt_copy_user_highpage,
85d73e60b7SRussell King };
86