1 /*
2 * highmem.h: virtual kernel memory mappings for high memory
3 *
4 * PowerPC version, stolen from the i386 version.
5 *
6 * Used in CONFIG_HIGHMEM systems for memory pages which
7 * are not addressable by direct kernel virtual adresses.
8 *
9 * Copyright (C) 1999 Gerhard Wichert, Siemens AG
10 * Gerhard.Wichert@pdb.siemens.de
11 *
12 *
13 * Redesigned the x86 32-bit VM architecture to deal with
14 * up to 16 Terrabyte physical memory. With current x86 CPUs
15 * we now support up to 64 Gigabytes physical RAM.
16 *
17 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
18 */
19
20 #ifndef _ASM_HIGHMEM_H
21 #define _ASM_HIGHMEM_H
22
23 #ifdef __KERNEL__
24
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <asm/kmap_types.h>
28 #include <asm/pgtable.h>
29
30 /* undef for production */
31 #define HIGHMEM_DEBUG 1
32
33 extern pte_t *kmap_pte;
34 extern pgprot_t kmap_prot;
35 extern pte_t *pkmap_page_table;
36
37 extern void kmap_init(void) __init;
38
39 /*
40 * Right now we initialize only a single pte table. It can be extended
41 * easily, subsequent pte tables have to be allocated in one physical
42 * chunk of RAM.
43 */
44 #define PKMAP_BASE (0xfe000000UL)
45 #define LAST_PKMAP 1024
46 #define LAST_PKMAP_MASK (LAST_PKMAP-1)
47 #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT)
48 #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
49
50 #define KMAP_FIX_BEGIN (0xfe400000UL)
51
52 extern void *kmap_high(struct page *page);
53 extern void kunmap_high(struct page *page);
54
55 static inline void *kmap(struct page *page)
56 {
57 if (in_interrupt())
58 BUG();
59 if (page < highmem_start_page)
60 return page_address(page);
61 return kmap_high(page);
62 }
63
64 static inline void kunmap(struct page *page)
65 {
66 if (in_interrupt())
67 BUG();
68 if (page < highmem_start_page)
69 return;
70 kunmap_high(page);
71 }
72
73 /*
74 * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
75 * gives a more generic (and caching) interface. But kmap_atomic can
76 * be used in IRQ contexts, so in some (very limited) cases we need
77 * it.
78 */
79 static inline void *kmap_atomic(struct page *page, enum km_type type)
80 {
81 unsigned int idx;
82 unsigned long vaddr;
83
84 if (page < highmem_start_page)
85 return page_address(page);
86
87 idx = type + KM_TYPE_NR*smp_processor_id();
88 vaddr = KMAP_FIX_BEGIN + idx * PAGE_SIZE;
89 #if HIGHMEM_DEBUG
90 if (!pte_none(*(kmap_pte+idx)))
91 BUG();
92 #endif
93 set_pte(kmap_pte+idx, mk_pte(page, kmap_prot));
94 flush_hash_page(0, vaddr);
95
96 return (void*) vaddr;
97 }
98
99 static inline void kunmap_atomic(void *kvaddr, enum km_type type)
100 {
101 #if HIGHMEM_DEBUG
102 unsigned long vaddr = (unsigned long) kvaddr;
103 unsigned int idx = type + KM_TYPE_NR*smp_processor_id();
104
105 if (vaddr < KMAP_FIX_BEGIN) // FIXME
106 return;
107
108 if (vaddr != KMAP_FIX_BEGIN + idx * PAGE_SIZE)
109 BUG();
110
111 /*
112 * force other mappings to Oops if they'll try to access
113 * this pte without first remap it
114 */
115 pte_clear(kmap_pte+idx);
116 flush_hash_page(0, vaddr);
117 #endif
118 }
119
120 #endif /* __KERNEL__ */
121
122 #endif /* _ASM_HIGHMEM_H */
123
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.