copypage-v6.c 3.3 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9
/*
 *  linux/arch/arm/mm/copypage-v6.c
 *
 *  Copyright (C) 2002 Deep Blue Solutions Ltd, All Rights Reserved.
 */
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
10
#include <linux/highmem.h>
11
#include <linux/pagemap.h>
L
Linus Torvalds 已提交
12 13 14 15

#include <asm/shmparam.h>
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>
16
#include <asm/cachetype.h>
L
Linus Torvalds 已提交
17

18 19
#include "mm.h"

L
Linus Torvalds 已提交
20 21 22 23
#if SHMLBA > 16384
#error FIX ME
#endif

24
static DEFINE_RAW_SPINLOCK(v6_lock);
L
Linus Torvalds 已提交
25 26 27 28 29

/*
 * Copy the user page.  No aliasing to deal with so we can just
 * attack the kernel's existing mapping of these pages.
 */
30
static void v6_copy_user_highpage_nonaliasing(struct page *to,
31
	struct page *from, unsigned long vaddr, struct vm_area_struct *vma)
L
Linus Torvalds 已提交
32
{
33 34
	void *kto, *kfrom;

35 36
	kfrom = kmap_atomic(from);
	kto = kmap_atomic(to);
L
Linus Torvalds 已提交
37
	copy_page(kto, kfrom);
38 39
	kunmap_atomic(kto);
	kunmap_atomic(kfrom);
L
Linus Torvalds 已提交
40 41 42 43 44 45
}

/*
 * Clear the user page.  No aliasing to deal with so we can just
 * attack the kernel's existing mapping of this page.
 */
46
static void v6_clear_user_highpage_nonaliasing(struct page *page, unsigned long vaddr)
L
Linus Torvalds 已提交
47
{
48
	void *kaddr = kmap_atomic(page);
L
Linus Torvalds 已提交
49
	clear_page(kaddr);
50
	kunmap_atomic(kaddr);
L
Linus Torvalds 已提交
51 52 53
}

/*
54 55
 * Discard data in the kernel mapping for the new page.
 * FIXME: needs this MCRR to be supported.
L
Linus Torvalds 已提交
56
 */
57
static void discard_old_kernel_data(void *kto)
L
Linus Torvalds 已提交
58 59 60 61
{
	__asm__("mcrr	p15, 0, %1, %0, c6	@ 0xec401f06"
	   :
	   : "r" (kto),
62
	     "r" ((unsigned long)kto + PAGE_SIZE - 1)
L
Linus Torvalds 已提交
63
	   : "cc");
64 65 66 67 68 69
}

/*
 * Copy the page, taking account of the cache colour.
 */
static void v6_copy_user_highpage_aliasing(struct page *to,
70
	struct page *from, unsigned long vaddr, struct vm_area_struct *vma)
71 72 73 74
{
	unsigned int offset = CACHE_COLOUR(vaddr);
	unsigned long kfrom, kto;

75
	if (!test_and_set_bit(PG_dcache_clean, &from->flags))
76
		__flush_dcache_page(page_mapping_file(from), from);
77 78 79

	/* FIXME: not highmem safe */
	discard_old_kernel_data(page_address(to));
L
Linus Torvalds 已提交
80 81 82 83 84

	/*
	 * Now copy the page using the same cache colour as the
	 * pages ultimate destination.
	 */
85
	raw_spin_lock(&v6_lock);
L
Linus Torvalds 已提交
86

87 88
	kfrom = COPYPAGE_V6_FROM + (offset << PAGE_SHIFT);
	kto   = COPYPAGE_V6_TO + (offset << PAGE_SHIFT);
L
Linus Torvalds 已提交
89

90 91
	set_top_pte(kfrom, mk_pte(from, PAGE_KERNEL));
	set_top_pte(kto, mk_pte(to, PAGE_KERNEL));
L
Linus Torvalds 已提交
92

93
	copy_page((void *)kto, (void *)kfrom);
L
Linus Torvalds 已提交
94

95
	raw_spin_unlock(&v6_lock);
L
Linus Torvalds 已提交
96 97 98 99 100 101 102
}

/*
 * Clear the user page.  We need to deal with the aliasing issues,
 * so remap the kernel page into the same cache colour as the user
 * page.
 */
103
static void v6_clear_user_highpage_aliasing(struct page *page, unsigned long vaddr)
L
Linus Torvalds 已提交
104
{
105
	unsigned long to = COPYPAGE_V6_TO + (CACHE_COLOUR(vaddr) << PAGE_SHIFT);
L
Linus Torvalds 已提交
106

107 108
	/* FIXME: not highmem safe */
	discard_old_kernel_data(page_address(page));
L
Linus Torvalds 已提交
109 110 111 112 113

	/*
	 * Now clear the page using the same cache colour as
	 * the pages ultimate destination.
	 */
114
	raw_spin_lock(&v6_lock);
L
Linus Torvalds 已提交
115

116
	set_top_pte(to, mk_pte(page, PAGE_KERNEL));
L
Linus Torvalds 已提交
117 118
	clear_page((void *)to);

119
	raw_spin_unlock(&v6_lock);
L
Linus Torvalds 已提交
120 121 122
}

struct cpu_user_fns v6_user_fns __initdata = {
123
	.cpu_clear_user_highpage = v6_clear_user_highpage_nonaliasing,
124
	.cpu_copy_user_highpage	= v6_copy_user_highpage_nonaliasing,
L
Linus Torvalds 已提交
125 126 127 128 129
};

static int __init v6_userpage_init(void)
{
	if (cache_is_vipt_aliasing()) {
130
		cpu_user.cpu_clear_user_highpage = v6_clear_user_highpage_aliasing;
131
		cpu_user.cpu_copy_user_highpage = v6_copy_user_highpage_aliasing;
L
Linus Torvalds 已提交
132 133 134 135 136
	}

	return 0;
}

137
core_initcall(v6_userpage_init);