diff options
| -rw-r--r-- | arch/x86/include/asm/iomap.h | 9 | ||||
| -rw-r--r-- | arch/x86/mm/iomap_32.c | 27 | ||||
| -rw-r--r-- | include/linux/io-mapping.h | 17 |
3 files changed, 43 insertions, 10 deletions
diff --git a/arch/x86/include/asm/iomap.h b/arch/x86/include/asm/iomap.h index 0e9fe1d9d971..f35eb45d6576 100644 --- a/arch/x86/include/asm/iomap.h +++ b/arch/x86/include/asm/iomap.h | |||
| @@ -26,13 +26,16 @@ | |||
| 26 | #include <asm/pgtable.h> | 26 | #include <asm/pgtable.h> |
| 27 | #include <asm/tlbflush.h> | 27 | #include <asm/tlbflush.h> |
| 28 | 28 | ||
| 29 | int | ||
| 30 | is_io_mapping_possible(resource_size_t base, unsigned long size); | ||
| 31 | |||
| 32 | void * | 29 | void * |
| 33 | iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot); | 30 | iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot); |
| 34 | 31 | ||
| 35 | void | 32 | void |
| 36 | iounmap_atomic(void *kvaddr, enum km_type type); | 33 | iounmap_atomic(void *kvaddr, enum km_type type); |
| 37 | 34 | ||
| 35 | int | ||
| 36 | iomap_create_wc(resource_size_t base, unsigned long size, pgprot_t *prot); | ||
| 37 | |||
| 38 | void | ||
| 39 | iomap_free(resource_size_t base, unsigned long size); | ||
| 40 | |||
| 38 | #endif /* _ASM_X86_IOMAP_H */ | 41 | #endif /* _ASM_X86_IOMAP_H */ |
diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c index fe6f84ca121e..84e236ce76ba 100644 --- a/arch/x86/mm/iomap_32.c +++ b/arch/x86/mm/iomap_32.c | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 22 | #include <linux/highmem.h> | 22 | #include <linux/highmem.h> |
| 23 | 23 | ||
| 24 | int is_io_mapping_possible(resource_size_t base, unsigned long size) | 24 | static int is_io_mapping_possible(resource_size_t base, unsigned long size) |
| 25 | { | 25 | { |
| 26 | #if !defined(CONFIG_X86_PAE) && defined(CONFIG_PHYS_ADDR_T_64BIT) | 26 | #if !defined(CONFIG_X86_PAE) && defined(CONFIG_PHYS_ADDR_T_64BIT) |
| 27 | /* There is no way to map greater than 1 << 32 address without PAE */ | 27 | /* There is no way to map greater than 1 << 32 address without PAE */ |
| @@ -30,7 +30,30 @@ int is_io_mapping_possible(resource_size_t base, unsigned long size) | |||
| 30 | #endif | 30 | #endif |
| 31 | return 1; | 31 | return 1; |
| 32 | } | 32 | } |
| 33 | EXPORT_SYMBOL_GPL(is_io_mapping_possible); | 33 | |
| 34 | int iomap_create_wc(resource_size_t base, unsigned long size, pgprot_t *prot) | ||
| 35 | { | ||
| 36 | unsigned long flag = _PAGE_CACHE_WC; | ||
| 37 | int ret; | ||
| 38 | |||
| 39 | if (!is_io_mapping_possible(base, size)) | ||
| 40 | return -EINVAL; | ||
| 41 | |||
| 42 | ret = io_reserve_memtype(base, base + size, &flag); | ||
| 43 | if (ret) | ||
| 44 | return ret; | ||
| 45 | |||
| 46 | *prot = __pgprot(__PAGE_KERNEL | flag); | ||
| 47 | return 0; | ||
| 48 | } | ||
| 49 | EXPORT_SYMBOL_GPL(iomap_create_wc); | ||
| 50 | |||
| 51 | void | ||
| 52 | iomap_free(resource_size_t base, unsigned long size) | ||
| 53 | { | ||
| 54 | io_free_memtype(base, base + size); | ||
| 55 | } | ||
| 56 | EXPORT_SYMBOL_GPL(iomap_free); | ||
| 34 | 57 | ||
| 35 | void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot) | 58 | void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot) |
| 36 | { | 59 | { |
diff --git a/include/linux/io-mapping.h b/include/linux/io-mapping.h index 0adb0f91568c..97eb928b4924 100644 --- a/include/linux/io-mapping.h +++ b/include/linux/io-mapping.h | |||
| @@ -49,23 +49,30 @@ 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 | 52 | pgprot_t prot; | |
| 53 | if (!is_io_mapping_possible(base, size)) | ||
| 54 | return NULL; | ||
| 55 | 53 | ||
| 56 | iomap = kmalloc(sizeof(*iomap), GFP_KERNEL); | 54 | iomap = kmalloc(sizeof(*iomap), GFP_KERNEL); |
| 57 | if (!iomap) | 55 | if (!iomap) |
| 58 | return NULL; | 56 | goto out_err; |
| 57 | |||
| 58 | if (iomap_create_wc(base, size, &prot)) | ||
| 59 | goto out_free; | ||
| 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; |
| 65 | |||
| 66 | out_free: | ||
| 67 | kfree(iomap); | ||
| 68 | out_err: | ||
| 69 | return NULL; | ||
| 64 | } | 70 | } |
| 65 | 71 | ||
| 66 | static inline void | 72 | static inline void |
| 67 | io_mapping_free(struct io_mapping *mapping) | 73 | io_mapping_free(struct io_mapping *mapping) |
| 68 | { | 74 | { |
| 75 | iomap_free(mapping->base, mapping->size); | ||
| 69 | kfree(mapping); | 76 | kfree(mapping); |
| 70 | } | 77 | } |
| 71 | 78 | ||
