diff options
-rw-r--r-- | arch/x86/include/asm/iomap.h | 5 | ||||
-rw-r--r-- | arch/x86/include/asm/pat.h | 3 | ||||
-rw-r--r-- | arch/x86/mm/iomap_32.c | 44 | ||||
-rw-r--r-- | arch/x86/mm/pat.c | 46 | ||||
-rw-r--r-- | include/linux/io-mapping.h | 6 |
5 files changed, 82 insertions, 22 deletions
diff --git a/arch/x86/include/asm/iomap.h b/arch/x86/include/asm/iomap.h index 86af26091d6c..bd46495ff7de 100644 --- a/arch/x86/include/asm/iomap.h +++ b/arch/x86/include/asm/iomap.h | |||
@@ -24,7 +24,10 @@ | |||
24 | #include <asm/tlbflush.h> | 24 | #include <asm/tlbflush.h> |
25 | 25 | ||
26 | int | 26 | int |
27 | is_io_mapping_possible(resource_size_t base, unsigned long size); | 27 | reserve_io_memtype_wc(u64 base, unsigned long size, pgprot_t *prot); |
28 | |||
29 | void | ||
30 | free_io_memtype(u64 base, unsigned long size); | ||
28 | 31 | ||
29 | void * | 32 | void * |
30 | iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot); | 33 | iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot); |
diff --git a/arch/x86/include/asm/pat.h b/arch/x86/include/asm/pat.h index 9709fdff6615..b0e70056838e 100644 --- a/arch/x86/include/asm/pat.h +++ b/arch/x86/include/asm/pat.h | |||
@@ -15,4 +15,7 @@ extern int reserve_memtype(u64 start, u64 end, | |||
15 | unsigned long req_type, unsigned long *ret_type); | 15 | unsigned long req_type, unsigned long *ret_type); |
16 | extern int free_memtype(u64 start, u64 end); | 16 | extern int free_memtype(u64 start, u64 end); |
17 | 17 | ||
18 | extern int kernel_map_sync_memtype(u64 base, unsigned long size, | ||
19 | unsigned long flag); | ||
20 | |||
18 | #endif /* _ASM_X86_PAT_H */ | 21 | #endif /* _ASM_X86_PAT_H */ |
diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c index 6c2b1af16926..d5e28424622c 100644 --- a/arch/x86/mm/iomap_32.c +++ b/arch/x86/mm/iomap_32.c | |||
@@ -21,13 +21,13 @@ | |||
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | 22 | ||
23 | #ifdef CONFIG_X86_PAE | 23 | #ifdef CONFIG_X86_PAE |
24 | int | 24 | static int |
25 | is_io_mapping_possible(resource_size_t base, unsigned long size) | 25 | is_io_mapping_possible(resource_size_t base, unsigned long size) |
26 | { | 26 | { |
27 | return 1; | 27 | return 1; |
28 | } | 28 | } |
29 | #else | 29 | #else |
30 | int | 30 | static int |
31 | is_io_mapping_possible(resource_size_t base, unsigned long size) | 31 | is_io_mapping_possible(resource_size_t base, unsigned long size) |
32 | { | 32 | { |
33 | /* There is no way to map greater than 1 << 32 address without PAE */ | 33 | /* There is no way to map greater than 1 << 32 address without PAE */ |
@@ -38,6 +38,46 @@ is_io_mapping_possible(resource_size_t base, unsigned long size) | |||
38 | } | 38 | } |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | int | ||
42 | reserve_io_memtype_wc(u64 base, unsigned long size, pgprot_t *prot) | ||
43 | { | ||
44 | unsigned long ret_flag; | ||
45 | |||
46 | if (!is_io_mapping_possible(base, size)) | ||
47 | goto out_err; | ||
48 | |||
49 | if (!pat_enabled) { | ||
50 | *prot = pgprot_noncached(PAGE_KERNEL); | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | if (reserve_memtype(base, base + size, _PAGE_CACHE_WC, &ret_flag)) | ||
55 | goto out_err; | ||
56 | |||
57 | if (ret_flag == _PAGE_CACHE_WB) | ||
58 | goto out_free; | ||
59 | |||
60 | if (kernel_map_sync_memtype(base, size, ret_flag)) | ||
61 | goto out_free; | ||
62 | |||
63 | *prot = __pgprot(__PAGE_KERNEL | ret_flag); | ||
64 | return 0; | ||
65 | |||
66 | out_free: | ||
67 | free_memtype(base, base + size); | ||
68 | out_err: | ||
69 | return -EINVAL; | ||
70 | } | ||
71 | EXPORT_SYMBOL_GPL(reserve_io_memtype_wc); | ||
72 | |||
73 | void | ||
74 | free_io_memtype(u64 base, unsigned long size) | ||
75 | { | ||
76 | if (pat_enabled) | ||
77 | free_memtype(base, base + size); | ||
78 | } | ||
79 | EXPORT_SYMBOL_GPL(free_io_memtype); | ||
80 | |||
41 | /* Map 'pfn' using fixed map 'type' and protections 'prot' | 81 | /* Map 'pfn' using fixed map 'type' and protections 'prot' |
42 | */ | 82 | */ |
43 | void * | 83 | void * |
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 05f9aef6818a..fdfedb65d45a 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c | |||
@@ -634,6 +634,33 @@ void unmap_devmem(unsigned long pfn, unsigned long size, pgprot_t vma_prot) | |||
634 | } | 634 | } |
635 | 635 | ||
636 | /* | 636 | /* |
637 | * Change the memory type for the physial address range in kernel identity | ||
638 | * mapping space if that range is a part of identity map. | ||
639 | */ | ||
640 | int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags) | ||
641 | { | ||
642 | unsigned long id_sz; | ||
643 | |||
644 | if (!pat_enabled || base >= __pa(high_memory)) | ||
645 | return 0; | ||
646 | |||
647 | id_sz = (__pa(high_memory) < base + size) ? | ||
648 | __pa(high_memory) - base : | ||
649 | size; | ||
650 | |||
651 | if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) { | ||
652 | printk(KERN_INFO | ||
653 | "%s:%d ioremap_change_attr failed %s " | ||
654 | "for %Lx-%Lx\n", | ||
655 | current->comm, current->pid, | ||
656 | cattr_name(flags), | ||
657 | base, (unsigned long long)(base + size)); | ||
658 | return -EINVAL; | ||
659 | } | ||
660 | return 0; | ||
661 | } | ||
662 | |||
663 | /* | ||
637 | * Internal interface to reserve a range of physical memory with prot. | 664 | * Internal interface to reserve a range of physical memory with prot. |
638 | * Reserved non RAM regions only and after successful reserve_memtype, | 665 | * Reserved non RAM regions only and after successful reserve_memtype, |
639 | * this func also keeps identity mapping (if any) in sync with this new prot. | 666 | * this func also keeps identity mapping (if any) in sync with this new prot. |
@@ -642,7 +669,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, | |||
642 | int strict_prot) | 669 | int strict_prot) |
643 | { | 670 | { |
644 | int is_ram = 0; | 671 | int is_ram = 0; |
645 | int id_sz, ret; | 672 | int ret; |
646 | unsigned long flags; | 673 | unsigned long flags; |
647 | unsigned long want_flags = (pgprot_val(*vma_prot) & _PAGE_CACHE_MASK); | 674 | unsigned long want_flags = (pgprot_val(*vma_prot) & _PAGE_CACHE_MASK); |
648 | 675 | ||
@@ -679,23 +706,8 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, | |||
679 | flags); | 706 | flags); |
680 | } | 707 | } |
681 | 708 | ||
682 | /* Need to keep identity mapping in sync */ | 709 | if (kernel_map_sync_memtype(paddr, size, flags) < 0) { |
683 | if (paddr >= __pa(high_memory)) | ||
684 | return 0; | ||
685 | |||
686 | id_sz = (__pa(high_memory) < paddr + size) ? | ||
687 | __pa(high_memory) - paddr : | ||
688 | size; | ||
689 | |||
690 | if (ioremap_change_attr((unsigned long)__va(paddr), id_sz, flags) < 0) { | ||
691 | free_memtype(paddr, paddr + size); | 710 | free_memtype(paddr, paddr + size); |
692 | printk(KERN_ERR | ||
693 | "%s:%d reserve_pfn_range ioremap_change_attr failed %s " | ||
694 | "for %Lx-%Lx\n", | ||
695 | current->comm, current->pid, | ||
696 | cattr_name(flags), | ||
697 | (unsigned long long)paddr, | ||
698 | (unsigned long long)(paddr + size)); | ||
699 | return -EINVAL; | 711 | return -EINVAL; |
700 | } | 712 | } |
701 | return 0; | 713 | return 0; |
diff --git a/include/linux/io-mapping.h b/include/linux/io-mapping.h index cbc2f0cd631b..f1ed66c43787 100644 --- a/include/linux/io-mapping.h +++ b/include/linux/io-mapping.h | |||
@@ -49,8 +49,9 @@ static inline struct io_mapping * | |||
49 | io_mapping_create_wc(resource_size_t base, unsigned long size) | 49 | io_mapping_create_wc(resource_size_t base, unsigned long size) |
50 | { | 50 | { |
51 | struct io_mapping *iomap; | 51 | struct io_mapping *iomap; |
52 | pgprot_t prot; | ||
52 | 53 | ||
53 | if (!is_io_mapping_possible(base, size)) | 54 | if (!reserve_io_memtype_wc(base, size, &prot)) |
54 | return NULL; | 55 | return NULL; |
55 | 56 | ||
56 | iomap = kmalloc(sizeof(*iomap), GFP_KERNEL); | 57 | iomap = kmalloc(sizeof(*iomap), GFP_KERNEL); |
@@ -59,13 +60,14 @@ io_mapping_create_wc(resource_size_t base, unsigned long size) | |||
59 | 60 | ||
60 | iomap->base = base; | 61 | iomap->base = base; |
61 | iomap->size = size; | 62 | iomap->size = size; |
62 | iomap->prot = pgprot_writecombine(__pgprot(__PAGE_KERNEL)); | 63 | iomap->prot = prot; |
63 | return iomap; | 64 | return iomap; |
64 | } | 65 | } |
65 | 66 | ||
66 | static inline void | 67 | static inline void |
67 | io_mapping_free(struct io_mapping *mapping) | 68 | io_mapping_free(struct io_mapping *mapping) |
68 | { | 69 | { |
70 | free_io_memtype(mapping->base, mapping->size); | ||
69 | kfree(mapping); | 71 | kfree(mapping); |
70 | } | 72 | } |
71 | 73 | ||