diff options
author | Suresh Siddha <suresh.b.siddha@intel.com> | 2009-04-09 17:26:52 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-10 07:55:48 -0400 |
commit | 0c3c8a18361a636069f5a5d9d0d0f9c2124e6b94 (patch) | |
tree | f981571c3778083924be8de03445fc4c9ee5624b | |
parent | b6ff32d9aaeeeecf98f9a852d715569183585312 (diff) |
x86, PAT: Remove duplicate memtype reserve in devmem mmap
/dev/mem mmap code was doing memtype reserve/free for a while now.
Recently we added memtype tracking in remap_pfn_range, and /dev/mem mmap
uses it indirectly. So, we don't need seperate tracking in /dev/mem code
any more. That means another ~100 lines of code removed :-).
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
LKML-Reference: <20090409212709.085210000@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | arch/x86/include/asm/pat.h | 4 | ||||
-rw-r--r-- | arch/x86/mm/pat.c | 60 | ||||
-rw-r--r-- | drivers/char/mem.c | 27 |
3 files changed, 2 insertions, 89 deletions
diff --git a/arch/x86/include/asm/pat.h b/arch/x86/include/asm/pat.h index 2cd07b9422f4..7af14e512f97 100644 --- a/arch/x86/include/asm/pat.h +++ b/arch/x86/include/asm/pat.h | |||
@@ -18,9 +18,5 @@ extern int free_memtype(u64 start, u64 end); | |||
18 | 18 | ||
19 | extern int kernel_map_sync_memtype(u64 base, unsigned long size, | 19 | extern int kernel_map_sync_memtype(u64 base, unsigned long size, |
20 | unsigned long flag); | 20 | unsigned long flag); |
21 | extern void map_devmem(unsigned long pfn, unsigned long size, | ||
22 | struct pgprot vma_prot); | ||
23 | extern void unmap_devmem(unsigned long pfn, unsigned long size, | ||
24 | struct pgprot vma_prot); | ||
25 | 21 | ||
26 | #endif /* _ASM_X86_PAT_H */ | 22 | #endif /* _ASM_X86_PAT_H */ |
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 8d3de9580508..cc5e0e24e443 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c | |||
@@ -536,9 +536,7 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size) | |||
536 | int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, | 536 | int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, |
537 | unsigned long size, pgprot_t *vma_prot) | 537 | unsigned long size, pgprot_t *vma_prot) |
538 | { | 538 | { |
539 | u64 offset = ((u64) pfn) << PAGE_SHIFT; | 539 | unsigned long flags = _PAGE_CACHE_WB; |
540 | unsigned long flags = -1; | ||
541 | int retval; | ||
542 | 540 | ||
543 | if (!range_is_allowed(pfn, size)) | 541 | if (!range_is_allowed(pfn, size)) |
544 | return 0; | 542 | return 0; |
@@ -566,65 +564,11 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, | |||
566 | } | 564 | } |
567 | #endif | 565 | #endif |
568 | 566 | ||
569 | /* | ||
570 | * With O_SYNC, we can only take UC_MINUS mapping. Fail if we cannot. | ||
571 | * | ||
572 | * Without O_SYNC, we want to get | ||
573 | * - WB for WB-able memory and no other conflicting mappings | ||
574 | * - UC_MINUS for non-WB-able memory with no other conflicting mappings | ||
575 | * - Inherit from confliting mappings otherwise | ||
576 | */ | ||
577 | if (flags != -1) { | ||
578 | retval = reserve_memtype(offset, offset + size, flags, NULL); | ||
579 | } else { | ||
580 | retval = reserve_memtype(offset, offset + size, | ||
581 | _PAGE_CACHE_WB, &flags); | ||
582 | } | ||
583 | |||
584 | if (retval < 0) | ||
585 | return 0; | ||
586 | |||
587 | if (((pfn < max_low_pfn_mapped) || | ||
588 | (pfn >= (1UL<<(32 - PAGE_SHIFT)) && pfn < max_pfn_mapped)) && | ||
589 | ioremap_change_attr((unsigned long)__va(offset), size, flags) < 0) { | ||
590 | free_memtype(offset, offset + size); | ||
591 | printk(KERN_INFO | ||
592 | "%s:%d /dev/mem ioremap_change_attr failed %s for %Lx-%Lx\n", | ||
593 | current->comm, current->pid, | ||
594 | cattr_name(flags), | ||
595 | offset, (unsigned long long)(offset + size)); | ||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | *vma_prot = __pgprot((pgprot_val(*vma_prot) & ~_PAGE_CACHE_MASK) | | 567 | *vma_prot = __pgprot((pgprot_val(*vma_prot) & ~_PAGE_CACHE_MASK) | |
600 | flags); | 568 | flags); |
601 | return 1; | 569 | return 1; |
602 | } | 570 | } |
603 | 571 | ||
604 | void map_devmem(unsigned long pfn, unsigned long size, pgprot_t vma_prot) | ||
605 | { | ||
606 | unsigned long want_flags = (pgprot_val(vma_prot) & _PAGE_CACHE_MASK); | ||
607 | u64 addr = (u64)pfn << PAGE_SHIFT; | ||
608 | unsigned long flags; | ||
609 | |||
610 | reserve_memtype(addr, addr + size, want_flags, &flags); | ||
611 | if (flags != want_flags) { | ||
612 | printk(KERN_INFO | ||
613 | "%s:%d /dev/mem expected mapping type %s for %Lx-%Lx, got %s\n", | ||
614 | current->comm, current->pid, | ||
615 | cattr_name(want_flags), | ||
616 | addr, (unsigned long long)(addr + size), | ||
617 | cattr_name(flags)); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | void unmap_devmem(unsigned long pfn, unsigned long size, pgprot_t vma_prot) | ||
622 | { | ||
623 | u64 addr = (u64)pfn << PAGE_SHIFT; | ||
624 | |||
625 | free_memtype(addr, addr + size); | ||
626 | } | ||
627 | |||
628 | /* | 572 | /* |
629 | * Change the memory type for the physial address range in kernel identity | 573 | * Change the memory type for the physial address range in kernel identity |
630 | * mapping space if that range is a part of identity map. | 574 | * mapping space if that range is a part of identity map. |
@@ -662,8 +606,8 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, | |||
662 | { | 606 | { |
663 | int is_ram = 0; | 607 | int is_ram = 0; |
664 | int ret; | 608 | int ret; |
665 | unsigned long flags; | ||
666 | unsigned long want_flags = (pgprot_val(*vma_prot) & _PAGE_CACHE_MASK); | 609 | unsigned long want_flags = (pgprot_val(*vma_prot) & _PAGE_CACHE_MASK); |
610 | unsigned long flags = want_flags; | ||
667 | 611 | ||
668 | is_ram = pat_pagerange_is_ram(paddr, paddr + size); | 612 | is_ram = pat_pagerange_is_ram(paddr, paddr + size); |
669 | 613 | ||
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 3586b3b3df3f..8f05c38c2f06 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
@@ -301,33 +301,7 @@ static inline int private_mapping_ok(struct vm_area_struct *vma) | |||
301 | } | 301 | } |
302 | #endif | 302 | #endif |
303 | 303 | ||
304 | void __attribute__((weak)) | ||
305 | map_devmem(unsigned long pfn, unsigned long len, pgprot_t prot) | ||
306 | { | ||
307 | /* nothing. architectures can override. */ | ||
308 | } | ||
309 | |||
310 | void __attribute__((weak)) | ||
311 | unmap_devmem(unsigned long pfn, unsigned long len, pgprot_t prot) | ||
312 | { | ||
313 | /* nothing. architectures can override. */ | ||
314 | } | ||
315 | |||
316 | static void mmap_mem_open(struct vm_area_struct *vma) | ||
317 | { | ||
318 | map_devmem(vma->vm_pgoff, vma->vm_end - vma->vm_start, | ||
319 | vma->vm_page_prot); | ||
320 | } | ||
321 | |||
322 | static void mmap_mem_close(struct vm_area_struct *vma) | ||
323 | { | ||
324 | unmap_devmem(vma->vm_pgoff, vma->vm_end - vma->vm_start, | ||
325 | vma->vm_page_prot); | ||
326 | } | ||
327 | |||
328 | static struct vm_operations_struct mmap_mem_ops = { | 304 | static struct vm_operations_struct mmap_mem_ops = { |
329 | .open = mmap_mem_open, | ||
330 | .close = mmap_mem_close, | ||
331 | #ifdef CONFIG_HAVE_IOREMAP_PROT | 305 | #ifdef CONFIG_HAVE_IOREMAP_PROT |
332 | .access = generic_access_phys | 306 | .access = generic_access_phys |
333 | #endif | 307 | #endif |
@@ -362,7 +336,6 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma) | |||
362 | vma->vm_pgoff, | 336 | vma->vm_pgoff, |
363 | size, | 337 | size, |
364 | vma->vm_page_prot)) { | 338 | vma->vm_page_prot)) { |
365 | unmap_devmem(vma->vm_pgoff, size, vma->vm_page_prot); | ||
366 | return -EAGAIN; | 339 | return -EAGAIN; |
367 | } | 340 | } |
368 | return 0; | 341 | return 0; |