Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/mm/copypage-v4wb.c |
| 4 | * |
| 5 | * Copyright (C) 1995-1999 Russell King |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/init.h> |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 8 | #include <linux/highmem.h> |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 9 | |
| 10 | /* |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 11 | * ARMv4 optimised copy_user_highpage |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 12 | * |
| 13 | * We flush the destination cache lines just before we write the data into the |
| 14 | * corresponding address. Since the Dcache is read-allocate, this removes the |
| 15 | * Dcache aliasing issue. The writes will be forwarded to the write buffer, |
| 16 | * and merged as appropriate. |
| 17 | * |
| 18 | * Note: We rely on all ARMv4 processors implementing the "invalidate D line" |
| 19 | * instruction. If your processor does not supply this, you have to write your |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 20 | * own copy_user_highpage that does the right thing. |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 21 | */ |
Nicolas Pitre | b99afae | 2018-11-07 17:49:00 +0100 | [diff] [blame] | 22 | static void v4wb_copy_user_page(void *kto, const void *kfrom) |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 23 | { |
Nicolas Pitre | b99afae | 2018-11-07 17:49:00 +0100 | [diff] [blame] | 24 | int tmp; |
| 25 | |
| 26 | asm volatile ("\ |
Stefan Agner | b7e8c93 | 2019-02-18 00:58:29 +0100 | [diff] [blame] | 27 | .syntax unified\n\ |
Nicolas Pitre | b99afae | 2018-11-07 17:49:00 +0100 | [diff] [blame] | 28 | ldmia %1!, {r3, r4, ip, lr} @ 4\n\ |
| 29 | 1: mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\ |
| 30 | stmia %0!, {r3, r4, ip, lr} @ 4\n\ |
| 31 | ldmia %1!, {r3, r4, ip, lr} @ 4+1\n\ |
| 32 | stmia %0!, {r3, r4, ip, lr} @ 4\n\ |
| 33 | ldmia %1!, {r3, r4, ip, lr} @ 4\n\ |
| 34 | mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\ |
| 35 | stmia %0!, {r3, r4, ip, lr} @ 4\n\ |
| 36 | ldmia %1!, {r3, r4, ip, lr} @ 4\n\ |
| 37 | subs %2, %2, #1 @ 1\n\ |
| 38 | stmia %0!, {r3, r4, ip, lr} @ 4\n\ |
Stefan Agner | b7e8c93 | 2019-02-18 00:58:29 +0100 | [diff] [blame] | 39 | ldmiane %1!, {r3, r4, ip, lr} @ 4\n\ |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 40 | bne 1b @ 1\n\ |
Nicolas Pitre | b99afae | 2018-11-07 17:49:00 +0100 | [diff] [blame] | 41 | mcr p15, 0, %1, c7, c10, 4 @ 1 drain WB" |
| 42 | : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp) |
| 43 | : "2" (PAGE_SIZE / 64) |
| 44 | : "r3", "r4", "ip", "lr"); |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 47 | void v4wb_copy_user_highpage(struct page *to, struct page *from, |
Russell King | f00a75c | 2009-10-05 15:17:45 +0100 | [diff] [blame] | 48 | unsigned long vaddr, struct vm_area_struct *vma) |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 49 | { |
| 50 | void *kto, *kfrom; |
| 51 | |
Cong Wang | 5472e86 | 2011-11-25 23:14:15 +0800 | [diff] [blame] | 52 | kto = kmap_atomic(to); |
| 53 | kfrom = kmap_atomic(from); |
Russell King | 2725898 | 2009-10-05 15:34:22 +0100 | [diff] [blame] | 54 | flush_cache_page(vma, vaddr, page_to_pfn(from)); |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 55 | v4wb_copy_user_page(kto, kfrom); |
Cong Wang | 5472e86 | 2011-11-25 23:14:15 +0800 | [diff] [blame] | 56 | kunmap_atomic(kfrom); |
| 57 | kunmap_atomic(kto); |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 60 | /* |
| 61 | * ARMv4 optimised clear_user_page |
| 62 | * |
| 63 | * Same story as above. |
| 64 | */ |
Russell King | 303c644 | 2008-10-31 16:32:19 +0000 | [diff] [blame] | 65 | void v4wb_clear_user_highpage(struct page *page, unsigned long vaddr) |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 66 | { |
Cong Wang | 5472e86 | 2011-11-25 23:14:15 +0800 | [diff] [blame] | 67 | void *ptr, *kaddr = kmap_atomic(page); |
Nicolas Pitre | 43ae286 | 2008-11-04 02:42:27 -0500 | [diff] [blame] | 68 | asm volatile("\ |
| 69 | mov r1, %2 @ 1\n\ |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 70 | mov r2, #0 @ 1\n\ |
| 71 | mov r3, #0 @ 1\n\ |
| 72 | mov ip, #0 @ 1\n\ |
| 73 | mov lr, #0 @ 1\n\ |
Russell King | 303c644 | 2008-10-31 16:32:19 +0000 | [diff] [blame] | 74 | 1: mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\ |
| 75 | stmia %0!, {r2, r3, ip, lr} @ 4\n\ |
| 76 | stmia %0!, {r2, r3, ip, lr} @ 4\n\ |
| 77 | mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\ |
| 78 | stmia %0!, {r2, r3, ip, lr} @ 4\n\ |
| 79 | stmia %0!, {r2, r3, ip, lr} @ 4\n\ |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 80 | subs r1, r1, #1 @ 1\n\ |
| 81 | bne 1b @ 1\n\ |
Russell King | 303c644 | 2008-10-31 16:32:19 +0000 | [diff] [blame] | 82 | mcr p15, 0, r1, c7, c10, 4 @ 1 drain WB" |
Nicolas Pitre | 43ae286 | 2008-11-04 02:42:27 -0500 | [diff] [blame] | 83 | : "=r" (ptr) |
| 84 | : "0" (kaddr), "I" (PAGE_SIZE / 64) |
Russell King | 303c644 | 2008-10-31 16:32:19 +0000 | [diff] [blame] | 85 | : "r1", "r2", "r3", "ip", "lr"); |
Cong Wang | 5472e86 | 2011-11-25 23:14:15 +0800 | [diff] [blame] | 86 | kunmap_atomic(kaddr); |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | struct cpu_user_fns v4wb_user_fns __initdata = { |
Russell King | 303c644 | 2008-10-31 16:32:19 +0000 | [diff] [blame] | 90 | .cpu_clear_user_highpage = v4wb_clear_user_highpage, |
Russell King | 063b0a4 | 2008-10-31 15:08:35 +0000 | [diff] [blame] | 91 | .cpu_copy_user_highpage = v4wb_copy_user_highpage, |
Russell King | d73e60b | 2008-10-31 13:08:02 +0000 | [diff] [blame] | 92 | }; |