1
2
3
4
5
6#include <asm/iomap.h>
7#include <asm/memtype.h>
8#include <linux/export.h>
9#include <linux/highmem.h>
10
11static int is_io_mapping_possible(resource_size_t base, unsigned long size)
12{
13#if !defined(CONFIG_X86_PAE) && defined(CONFIG_PHYS_ADDR_T_64BIT)
14
15 if (base + size > 0x100000000ULL)
16 return 0;
17#endif
18 return 1;
19}
20
21int iomap_create_wc(resource_size_t base, unsigned long size, pgprot_t *prot)
22{
23 enum page_cache_mode pcm = _PAGE_CACHE_MODE_WC;
24 int ret;
25
26 if (!is_io_mapping_possible(base, size))
27 return -EINVAL;
28
29 ret = memtype_reserve_io(base, base + size, &pcm);
30 if (ret)
31 return ret;
32
33 *prot = __pgprot(__PAGE_KERNEL | cachemode2protval(pcm));
34
35 pgprot_val(*prot) &= __default_kernel_pte_mask;
36
37 return 0;
38}
39EXPORT_SYMBOL_GPL(iomap_create_wc);
40
41void iomap_free(resource_size_t base, unsigned long size)
42{
43 memtype_free_io(base, base + size);
44}
45EXPORT_SYMBOL_GPL(iomap_free);
46
47void __iomem *__iomap_local_pfn_prot(unsigned long pfn, pgprot_t prot)
48{
49
50
51
52
53
54
55
56 if (!pat_enabled() && pgprot2cachemode(prot) != _PAGE_CACHE_MODE_WB)
57 prot = __pgprot(__PAGE_KERNEL |
58 cachemode2protval(_PAGE_CACHE_MODE_UC_MINUS));
59
60
61 pgprot_val(prot) &= __default_kernel_pte_mask;
62
63 return (void __force __iomem *)__kmap_local_pfn_prot(pfn, prot);
64}
65EXPORT_SYMBOL_GPL(__iomap_local_pfn_prot);
66