summaryrefslogtreecommitdiff
path: root/arch/csky/abiv2/cacheflush.c
blob: d22c95ffc74dca40d8bab07a918b77752dda1b34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.

#include <linux/cache.h>
#include <linux/highmem.h>
#include <linux/mm.h>
#include <asm/cache.h>

void flush_icache_page(struct vm_area_struct *vma, struct page *page)
{
	unsigned long start;

	start = (unsigned long) kmap_atomic(page);

	cache_wbinv_range(start, start + PAGE_SIZE);

	kunmap_atomic((void *)start);
}

void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
			     unsigned long vaddr, int len)
{
	unsigned long kaddr;

	kaddr = (unsigned long) kmap_atomic(page) + (vaddr & ~PAGE_MASK);

	cache_wbinv_range(kaddr, kaddr + len);

	kunmap_atomic((void *)kaddr);
}

void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
		      pte_t *pte)
{
	unsigned long addr, pfn;
	struct page *page;
	void *va;

	if (!(vma->vm_flags & VM_EXEC))
		return;

	pfn = pte_pfn(*pte);
	if (unlikely(!pfn_valid(pfn)))
		return;

	page = pfn_to_page(pfn);
	if (page == ZERO_PAGE(0))
		return;

	va = page_address(page);
	addr = (unsigned long) va;

	if (va == NULL && PageHighMem(page))
		addr = (unsigned long) kmap_atomic(page);

	cache_wbinv_range(addr, addr + PAGE_SIZE);

	if (va == NULL && PageHighMem(page))
		kunmap_atomic((void *) addr);
}