Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
fd940934 KP |
2 | /* |
3 | * Copyright © 2008 Ingo Molnar | |
fd940934 KP |
4 | */ |
5 | ||
6 | #include <asm/iomap.h> | |
eb243d1d | 7 | #include <asm/memtype.h> |
4b599fed | 8 | #include <linux/export.h> |
7ca43e75 | 9 | #include <linux/highmem.h> |
fd940934 | 10 | |
9e36fda0 | 11 | static int is_io_mapping_possible(resource_size_t base, unsigned long size) |
4ab0d47d | 12 | { |
6a491e2e | 13 | #if !defined(CONFIG_X86_PAE) && defined(CONFIG_PHYS_ADDR_T_64BIT) |
4ab0d47d VP |
14 | /* There is no way to map greater than 1 << 32 address without PAE */ |
15 | if (base + size > 0x100000000ULL) | |
16 | return 0; | |
92b9af9e | 17 | #endif |
4ab0d47d VP |
18 | return 1; |
19 | } | |
9e36fda0 VP |
20 | |
21 | int iomap_create_wc(resource_size_t base, unsigned long size, pgprot_t *prot) | |
22 | { | |
49a3b3cb | 23 | enum page_cache_mode pcm = _PAGE_CACHE_MODE_WC; |
9e36fda0 VP |
24 | int ret; |
25 | ||
26 | if (!is_io_mapping_possible(base, size)) | |
27 | return -EINVAL; | |
28 | ||
ecdd6ee7 | 29 | ret = memtype_reserve_io(base, base + size, &pcm); |
9e36fda0 VP |
30 | if (ret) |
31 | return ret; | |
32 | ||
49a3b3cb | 33 | *prot = __pgprot(__PAGE_KERNEL | cachemode2protval(pcm)); |
fb43d6cb DH |
34 | /* Filter out unsupported __PAGE_KERNEL* bits: */ |
35 | pgprot_val(*prot) &= __default_kernel_pte_mask; | |
36 | ||
9e36fda0 VP |
37 | return 0; |
38 | } | |
39 | EXPORT_SYMBOL_GPL(iomap_create_wc); | |
40 | ||
3e4d3af5 | 41 | void iomap_free(resource_size_t base, unsigned long size) |
9e36fda0 | 42 | { |
ecdd6ee7 | 43 | memtype_free_io(base, base + size); |
9e36fda0 VP |
44 | } |
45 | EXPORT_SYMBOL_GPL(iomap_free); | |
4ab0d47d | 46 | |
351191ad | 47 | void __iomem *__iomap_local_pfn_prot(unsigned long pfn, pgprot_t prot) |
fd940934 | 48 | { |
ef5fa0ab | 49 | /* |
7202fdb1 BP |
50 | * For non-PAT systems, translate non-WB request to UC- just in |
51 | * case the caller set the PWT bit to prot directly without using | |
52 | * pgprot_writecombine(). UC- translates to uncached if the MTRR | |
53 | * is UC or WC. UC- gets the real intention, of the user, which is | |
54 | * "WC if the MTRR is WC, UC if you can't do that." | |
ef5fa0ab | 55 | */ |
7202fdb1 | 56 | if (!pat_enabled() && pgprot2cachemode(prot) != _PAGE_CACHE_MODE_WB) |
49a3b3cb JG |
57 | prot = __pgprot(__PAGE_KERNEL | |
58 | cachemode2protval(_PAGE_CACHE_MODE_UC_MINUS)); | |
ef5fa0ab | 59 | |
fb43d6cb DH |
60 | /* Filter out unsupported __PAGE_KERNEL* bits: */ |
61 | pgprot_val(prot) &= __default_kernel_pte_mask; | |
62 | ||
157e118b | 63 | return (void __force __iomem *)__kmap_local_pfn_prot(pfn, prot); |
fd940934 | 64 | } |
351191ad | 65 | EXPORT_SYMBOL_GPL(__iomap_local_pfn_prot); |