tracing, x86: remove duplicated #include
[linux-2.6] / arch / x86 / mm / highmem_32.c
1 #include <linux/highmem.h>
2 #include <linux/module.h>
3 #include <linux/swap.h> /* for totalram_pages */
4
5 void *kmap(struct page *page)
6 {
7         might_sleep();
8         if (!PageHighMem(page))
9                 return page_address(page);
10         return kmap_high(page);
11 }
12
13 void kunmap(struct page *page)
14 {
15         if (in_interrupt())
16                 BUG();
17         if (!PageHighMem(page))
18                 return;
19         kunmap_high(page);
20 }
21
22 static void debug_kmap_atomic_prot(enum km_type type)
23 {
24 #ifdef CONFIG_DEBUG_HIGHMEM
25         static unsigned warn_count = 10;
26
27         if (unlikely(warn_count == 0))
28                 return;
29
30         if (unlikely(in_interrupt())) {
31                 if (in_irq()) {
32                         if (type != KM_IRQ0 && type != KM_IRQ1 &&
33                             type != KM_BIO_SRC_IRQ && type != KM_BIO_DST_IRQ &&
34                             type != KM_BOUNCE_READ) {
35                                 WARN_ON(1);
36                                 warn_count--;
37                         }
38                 } else if (!irqs_disabled()) {  /* softirq */
39                         if (type != KM_IRQ0 && type != KM_IRQ1 &&
40                             type != KM_SOFTIRQ0 && type != KM_SOFTIRQ1 &&
41                             type != KM_SKB_SUNRPC_DATA &&
42                             type != KM_SKB_DATA_SOFTIRQ &&
43                             type != KM_BOUNCE_READ) {
44                                 WARN_ON(1);
45                                 warn_count--;
46                         }
47                 }
48         }
49
50         if (type == KM_IRQ0 || type == KM_IRQ1 || type == KM_BOUNCE_READ ||
51                         type == KM_BIO_SRC_IRQ || type == KM_BIO_DST_IRQ) {
52                 if (!irqs_disabled()) {
53                         WARN_ON(1);
54                         warn_count--;
55                 }
56         } else if (type == KM_SOFTIRQ0 || type == KM_SOFTIRQ1) {
57                 if (irq_count() == 0 && !irqs_disabled()) {
58                         WARN_ON(1);
59                         warn_count--;
60                 }
61         }
62 #endif
63 }
64
65 /*
66  * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
67  * no global lock is needed and because the kmap code must perform a global TLB
68  * invalidation when the kmap pool wraps.
69  *
70  * However when holding an atomic kmap is is not legal to sleep, so atomic
71  * kmaps are appropriate for short, tight code paths only.
72  */
73 void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
74 {
75         enum fixed_addresses idx;
76         unsigned long vaddr;
77
78         /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
79         pagefault_disable();
80
81         if (!PageHighMem(page))
82                 return page_address(page);
83
84         debug_kmap_atomic_prot(type);
85
86         idx = type + KM_TYPE_NR*smp_processor_id();
87         vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
88         BUG_ON(!pte_none(*(kmap_pte-idx)));
89         set_pte(kmap_pte-idx, mk_pte(page, prot));
90         arch_flush_lazy_mmu_mode();
91
92         return (void *)vaddr;
93 }
94
95 void *kmap_atomic(struct page *page, enum km_type type)
96 {
97         return kmap_atomic_prot(page, type, kmap_prot);
98 }
99
100 void kunmap_atomic(void *kvaddr, enum km_type type)
101 {
102         unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
103         enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
104
105         /*
106          * Force other mappings to Oops if they'll try to access this pte
107          * without first remap it.  Keeping stale mappings around is a bad idea
108          * also, in case the page changes cacheability attributes or becomes
109          * a protected page in a hypervisor.
110          */
111         if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
112                 kpte_clear_flush(kmap_pte-idx, vaddr);
113         else {
114 #ifdef CONFIG_DEBUG_HIGHMEM
115                 BUG_ON(vaddr < PAGE_OFFSET);
116                 BUG_ON(vaddr >= (unsigned long)high_memory);
117 #endif
118         }
119
120         arch_flush_lazy_mmu_mode();
121         pagefault_enable();
122 }
123
124 void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
125 {
126         enum fixed_addresses idx;
127         unsigned long vaddr;
128
129         pagefault_disable();
130
131         debug_kmap_atomic_prot(type);
132
133         idx = type + KM_TYPE_NR * smp_processor_id();
134         vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
135         set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
136         arch_flush_lazy_mmu_mode();
137
138         return (void*) vaddr;
139 }
140
141 /* This is the same as kmap_atomic() but can map memory that doesn't
142  * have a struct page associated with it.
143  */
144 void *kmap_atomic_pfn(unsigned long pfn, enum km_type type)
145 {
146         return kmap_atomic_prot_pfn(pfn, type, kmap_prot);
147 }
148 EXPORT_SYMBOL_GPL(kmap_atomic_pfn); /* temporarily in use by i915 GEM until vmap */
149
150 struct page *kmap_atomic_to_page(void *ptr)
151 {
152         unsigned long idx, vaddr = (unsigned long)ptr;
153         pte_t *pte;
154
155         if (vaddr < FIXADDR_START)
156                 return virt_to_page(ptr);
157
158         idx = virt_to_fix(vaddr);
159         pte = kmap_pte - (idx - FIX_KMAP_BEGIN);
160         return pte_page(*pte);
161 }
162
163 EXPORT_SYMBOL(kmap);
164 EXPORT_SYMBOL(kunmap);
165 EXPORT_SYMBOL(kmap_atomic);
166 EXPORT_SYMBOL(kunmap_atomic);
167
168 void __init set_highmem_pages_init(void)
169 {
170         struct zone *zone;
171         int nid;
172
173         for_each_zone(zone) {
174                 unsigned long zone_start_pfn, zone_end_pfn;
175
176                 if (!is_highmem(zone))
177                         continue;
178
179                 zone_start_pfn = zone->zone_start_pfn;
180                 zone_end_pfn = zone_start_pfn + zone->spanned_pages;
181
182                 nid = zone_to_nid(zone);
183                 printk(KERN_INFO "Initializing %s for node %d (%08lx:%08lx)\n",
184                                 zone->name, nid, zone_start_pfn, zone_end_pfn);
185
186                 add_highpages_with_active_regions(nid, zone_start_pfn,
187                                  zone_end_pfn);
188         }
189         totalram_pages += totalhigh_pages;
190 }