blob: 1f58938703ab6e73d824b68d5000c25e347248d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* highmem.h: virtual kernel memory mappings for high memory
2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from include/asm-i386/highmem.h
6 *
Adrian Bunk0868ff72008-02-03 15:54:28 +02007 * See Documentation/frv/mmu-layout.txt for more information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#ifndef _ASM_HIGHMEM_H
16#define _ASM_HIGHMEM_H
17
18#ifdef __KERNEL__
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
Akinobu Mita7ca43e72009-03-31 15:23:25 -070021#include <linux/highmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/mem-layout.h>
23#include <asm/spr-regs.h>
24#include <asm/mb-regs.h>
25
26#define NR_TLB_LINES 64 /* number of lines in the TLB */
27
28#ifndef __ASSEMBLY__
29
30#include <linux/interrupt.h>
31#include <asm/kmap_types.h>
32#include <asm/pgtable.h>
33
34#ifdef CONFIG_DEBUG_HIGHMEM
35#define HIGHMEM_DEBUG 1
36#else
37#define HIGHMEM_DEBUG 0
38#endif
39
40/* declarations for highmem.c */
41extern unsigned long highstart_pfn, highend_pfn;
42
43#define kmap_prot PAGE_KERNEL
44#define kmap_pte ______kmap_pte_in_TLB
45extern pte_t *pkmap_page_table;
46
47#define flush_cache_kmaps() do { } while (0)
48
49/*
50 * Right now we initialize only a single pte table. It can be extended
51 * easily, subsequent pte tables have to be allocated in one physical
52 * chunk of RAM.
53 */
54#define LAST_PKMAP PTRS_PER_PTE
55#define LAST_PKMAP_MASK (LAST_PKMAP - 1)
56#define PKMAP_NR(virt) ((virt - PKMAP_BASE) >> PAGE_SHIFT)
57#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
58
59extern void *kmap_high(struct page *page);
60extern void kunmap_high(struct page *page);
61
62extern void *kmap(struct page *page);
63extern void kunmap(struct page *page);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#endif /* !__ASSEMBLY__ */
66
67/*
68 * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
69 * gives a more generic (and caching) interface. But kmap_atomic can
70 * be used in IRQ contexts, so in some (very limited) cases we need
71 * it.
72 */
73#define KMAP_ATOMIC_CACHE_DAMR 8
74
75#ifndef __ASSEMBLY__
76
Cong Wang144cf862012-06-27 13:02:49 +080077#define __kmap_atomic_primary(cached, paddr, ampr) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070078({ \
79 unsigned long damlr, dampr; \
80 \
81 dampr = paddr | xAMPRx_L | xAMPRx_M | xAMPRx_S | xAMPRx_SS_16Kb | xAMPRx_V; \
82 \
Cong Wang144cf862012-06-27 13:02:49 +080083 if (!cached) \
David Howells29da7eb2006-10-16 14:10:49 +010084 asm volatile("movgs %0,dampr"#ampr :: "r"(dampr) : "memory"); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 else \
Cong Wang144cf862012-06-27 13:02:49 +080086 /* cache flush page attachment point */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 asm volatile("movgs %0,iampr"#ampr"\n" \
88 "movgs %0,dampr"#ampr"\n" \
David Howells29da7eb2006-10-16 14:10:49 +010089 :: "r"(dampr) : "memory" \
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 ); \
91 \
92 asm("movsg damlr"#ampr",%0" : "=r"(damlr)); \
93 \
94 /*printk("DAMR"#ampr": PRIM sl=%d L=%08lx P=%08lx\n", type, damlr, dampr);*/ \
95 \
96 (void *) damlr; \
97})
98
99#define __kmap_atomic_secondary(slot, paddr) \
100({ \
101 unsigned long damlr = KMAP_ATOMIC_SECONDARY_FRAME + (slot) * PAGE_SIZE; \
102 unsigned long dampr = paddr | xAMPRx_L | xAMPRx_M | xAMPRx_S | xAMPRx_SS_16Kb | xAMPRx_V; \
103 \
104 asm volatile("movgs %0,tplr \n" \
105 "movgs %1,tppr \n" \
106 "tlbpr %0,gr0,#2,#1" \
David Howells29da7eb2006-10-16 14:10:49 +0100107 : : "r"(damlr), "r"(dampr) : "memory"); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 \
109 /*printk("TLB: SECN sl=%d L=%08lx P=%08lx\n", slot, damlr, dampr);*/ \
110 \
111 (void *) damlr; \
112})
113
Cong Wang144cf862012-06-27 13:02:49 +0800114static inline void *kmap_atomic_primary(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 unsigned long paddr;
117
Peter Zijlstraa8663742006-12-06 20:32:20 -0800118 pagefault_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 paddr = page_to_phys(page);
120
Cong Wang144cf862012-06-27 13:02:49 +0800121 return __kmap_atomic_primary(1, paddr, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Cong Wang144cf862012-06-27 13:02:49 +0800124#define __kunmap_atomic_primary(cached, ampr) \
David Howells29da7eb2006-10-16 14:10:49 +0100125do { \
126 asm volatile("movgs gr0,dampr"#ampr"\n" ::: "memory"); \
Cong Wang144cf862012-06-27 13:02:49 +0800127 if (cached) \
David Howells29da7eb2006-10-16 14:10:49 +0100128 asm volatile("movgs gr0,iampr"#ampr"\n" ::: "memory"); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129} while(0)
130
David Howells29da7eb2006-10-16 14:10:49 +0100131#define __kunmap_atomic_secondary(slot, vaddr) \
132do { \
133 asm volatile("tlbpr %0,gr0,#4,#1" : : "r"(vaddr) : "memory"); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134} while(0)
135
Cong Wang144cf862012-06-27 13:02:49 +0800136static inline void kunmap_atomic_primary(void *kvaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Cong Wang144cf862012-06-27 13:02:49 +0800138 __kunmap_atomic_primary(1, 2);
Peter Zijlstraa8663742006-12-06 20:32:20 -0800139 pagefault_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Cong Wanga24401b2011-11-26 10:53:39 +0800142void *kmap_atomic(struct page *page);
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -0700143void __kunmap_atomic(void *kvaddr);
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif /* !__ASSEMBLY__ */
146
147#endif /* __KERNEL__ */
148
149#endif /* _ASM_HIGHMEM_H */