Skip to content

Commit bb6d59c

Browse files
mitaIngo Molnar
authored andcommitted
x86: unify kmap_atomic_pfn() and iomap_atomic_prot_pfn()
kmap_atomic_pfn() and iomap_atomic_prot_pfn() are almost same except pgprot. This patch removes the code duplication for these two functions. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> LKML-Reference: <20090311143317.GA22244@localhost.localdomain> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 78b020d commit bb6d59c

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

‎arch/x86/include/asm/highmem.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot);
6363
void *kmap_atomic(struct page *page, enum km_type type);
6464
void kunmap_atomic(void *kvaddr, enum km_type type);
6565
void *kmap_atomic_pfn(unsigned long pfn, enum km_type type);
66+
void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot);
6667
struct page *kmap_atomic_to_page(void *ptr);
6768

6869
#ifndef CONFIG_PARAVIRT

‎arch/x86/mm/highmem_32.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,28 @@ void kunmap_atomic(void *kvaddr, enum km_type type)
121121
pagefault_enable();
122122
}
123123

124-
/* This is the same as kmap_atomic() but can map memory that doesn't
125-
* have a struct page associated with it.
126-
*/
127-
void *kmap_atomic_pfn(unsigned long pfn, enum km_type type)
124+
void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
128125
{
129126
enum fixed_addresses idx;
130127
unsigned long vaddr;
131128

132129
pagefault_disable();
133130

134-
idx = type + KM_TYPE_NR*smp_processor_id();
131+
idx = type + KM_TYPE_NR * smp_processor_id();
135132
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
136-
set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
133+
set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
137134
arch_flush_lazy_mmu_mode();
138135

139136
return (void*) vaddr;
140137
}
138+
139+
/* This is the same as kmap_atomic() but can map memory that doesn't
140+
* have a struct page associated with it.
141+
*/
142+
void *kmap_atomic_pfn(unsigned long pfn, enum km_type type)
143+
{
144+
return kmap_atomic_prot_pfn(pfn, type, kmap_prot);
145+
}
141146
EXPORT_SYMBOL_GPL(kmap_atomic_pfn); /* temporarily in use by i915 GEM until vmap */
142147

143148
struct page *kmap_atomic_to_page(void *ptr)

‎arch/x86/mm/iomap_32.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <asm/iomap.h>
2020
#include <asm/pat.h>
21+
#include <asm/highmem.h>
2122
#include <linux/module.h>
2223

2324
int is_io_mapping_possible(resource_size_t base, unsigned long size)
@@ -36,11 +37,6 @@ EXPORT_SYMBOL_GPL(is_io_mapping_possible);
3637
void *
3738
iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
3839
{
39-
enum fixed_addresses idx;
40-
unsigned long vaddr;
41-
42-
pagefault_disable();
43-
4440
/*
4541
* For non-PAT systems, promote PAGE_KERNEL_WC to PAGE_KERNEL_UC_MINUS.
4642
* PAGE_KERNEL_WC maps to PWT, which translates to uncached if the
@@ -50,12 +46,7 @@ iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
5046
if (!pat_enabled && pgprot_val(prot) == pgprot_val(PAGE_KERNEL_WC))
5147
prot = PAGE_KERNEL_UC_MINUS;
5248

53-
idx = type + KM_TYPE_NR*smp_processor_id();
54-
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
55-
set_pte(kmap_pte-idx, pfn_pte(pfn, prot));
56-
arch_flush_lazy_mmu_mode();
57-
58-
return (void*) vaddr;
49+
return kmap_atomic_prot_pfn(pfn, type, prot);
5950
}
6051
EXPORT_SYMBOL_GPL(iomap_atomic_prot_pfn);
6152

0 commit comments

Comments
 (0)