blob: b24ade27a0f09210002916bf0c164aed73777abc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* cache-page.c: whole-page cache wrangling functions for MMU linux
2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/highmem.h>
David Howells40234402006-01-08 01:01:19 -080014#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/pgalloc.h>
16
17/*****************************************************************************/
18/*
19 * DCF takes a virtual address and the page may not currently have one
20 * - temporarily hijack a kmap_atomic() slot and attach the page to it
21 */
22void flush_dcache_page(struct page *page)
23{
24 unsigned long dampr2;
25 void *vaddr;
26
27 dampr2 = __get_DAMPR(2);
28
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -070029 vaddr = kmap_atomic_primary(page, __KM_CACHE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31 frv_dcache_writeback((unsigned long) vaddr, (unsigned long) vaddr + PAGE_SIZE);
32
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -070033 kunmap_atomic_primary(vaddr, __KM_CACHE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 if (dampr2) {
36 __set_DAMPR(2, dampr2);
37 __set_IAMPR(2, dampr2);
38 }
39
40} /* end flush_dcache_page() */
41
David Howells40234402006-01-08 01:01:19 -080042EXPORT_SYMBOL(flush_dcache_page);
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*****************************************************************************/
45/*
46 * ICI takes a virtual address and the page may not currently have one
47 * - so we temporarily attach the page to a bit of virtual space so that is can be flushed
48 */
49void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
50 unsigned long start, unsigned long len)
51{
52 unsigned long dampr2;
53 void *vaddr;
54
55 dampr2 = __get_DAMPR(2);
56
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -070057 vaddr = kmap_atomic_primary(page, __KM_CACHE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 start = (start & ~PAGE_MASK) | (unsigned long) vaddr;
60 frv_cache_wback_inv(start, start + len);
61
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -070062 kunmap_atomic_primary(vaddr, __KM_CACHE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 if (dampr2) {
65 __set_DAMPR(2, dampr2);
66 __set_IAMPR(2, dampr2);
67 }
68
69} /* end flush_icache_user_range() */
David Howells40234402006-01-08 01:01:19 -080070
71EXPORT_SYMBOL(flush_icache_user_range);