Commit | Line | Data |
---|---|---|
775c8a3d | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
c27a0d75 BS |
2 | /* |
3 | * Copyright 2006 PathScale, Inc. All Rights Reserved. | |
c27a0d75 BS |
4 | */ |
5 | ||
6 | #ifndef _LINUX_IO_H | |
7 | #define _LINUX_IO_H | |
8 | ||
0069455b | 9 | #include <linux/sizes.h> |
cb1055fb | 10 | #include <linux/types.h> |
d6472302 | 11 | #include <linux/init.h> |
c27a0d75 | 12 | #include <asm/io.h> |
74588d8b | 13 | #include <asm/page.h> |
c27a0d75 | 14 | |
7f253770 AM |
15 | struct device; |
16 | ||
20516d6e JG |
17 | #ifndef __iowrite32_copy |
18 | void __iowrite32_copy(void __iomem *to, const void *from, size_t count); | |
19 | #endif | |
20 | ||
a9aec588 | 21 | void __ioread32_copy(void *to, const void __iomem *from, size_t count); |
e7bc47b1 JG |
22 | |
23 | #ifndef __iowrite64_copy | |
22ae813b | 24 | void __iowrite64_copy(void __iomem *to, const void *from, size_t count); |
e7bc47b1 | 25 | #endif |
c27a0d75 | 26 | |
218f0aae | 27 | #ifdef CONFIG_MMU |
74588d8b | 28 | int ioremap_page_range(unsigned long addr, unsigned long end, |
ffa71f33 | 29 | phys_addr_t phys_addr, pgprot_t prot); |
d7bca919 AS |
30 | int vmap_page_range(unsigned long addr, unsigned long end, |
31 | phys_addr_t phys_addr, pgprot_t prot); | |
218f0aae PM |
32 | #else |
33 | static inline int ioremap_page_range(unsigned long addr, unsigned long end, | |
ffa71f33 | 34 | phys_addr_t phys_addr, pgprot_t prot) |
218f0aae PM |
35 | { |
36 | return 0; | |
37 | } | |
d7bca919 AS |
38 | static inline int vmap_page_range(unsigned long addr, unsigned long end, |
39 | phys_addr_t phys_addr, pgprot_t prot) | |
40 | { | |
41 | return 0; | |
42 | } | |
218f0aae | 43 | #endif |
74588d8b | 44 | |
9ac7849e TH |
45 | /* |
46 | * Managed iomap interface | |
47 | */ | |
ce816fa8 | 48 | #ifdef CONFIG_HAS_IOPORT_MAP |
9ac7849e TH |
49 | void __iomem * devm_ioport_map(struct device *dev, unsigned long port, |
50 | unsigned int nr); | |
51 | void devm_ioport_unmap(struct device *dev, void __iomem *addr); | |
93da2879 RK |
52 | #else |
53 | static inline void __iomem *devm_ioport_map(struct device *dev, | |
54 | unsigned long port, | |
55 | unsigned int nr) | |
56 | { | |
57 | return NULL; | |
58 | } | |
59 | ||
60 | static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) | |
61 | { | |
62 | } | |
63 | #endif | |
9ac7849e | 64 | |
4f452e8a | 65 | void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, |
5559b7bc | 66 | resource_size_t size); |
e537654b TZ |
67 | void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset, |
68 | resource_size_t size); | |
34644524 AK |
69 | void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, |
70 | resource_size_t size); | |
9ac7849e | 71 | void devm_iounmap(struct device *dev, void __iomem *addr); |
cc2ea416 AM |
72 | int check_signature(const volatile void __iomem *io_addr, |
73 | const unsigned char *signature, int length); | |
b41e5fff | 74 | void devm_ioremap_release(struct device *dev, void *res); |
e50190a8 | 75 | |
7d3dcf26 CH |
76 | void *devm_memremap(struct device *dev, resource_size_t offset, |
77 | size_t size, unsigned long flags); | |
78 | void devm_memunmap(struct device *dev, void *addr); | |
79 | ||
4d312ac0 AB |
80 | /* architectures can override this */ |
81 | pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr, | |
82 | unsigned long size, pgprot_t prot); | |
83 | ||
84 | ||
cf9ea8ca LP |
85 | #ifdef CONFIG_PCI |
86 | /* | |
87 | * The PCI specifications (Rev 3.0, 3.2.5 "Transaction Ordering and | |
b10eb2d5 HM |
88 | * Posting") mandate non-posted configuration transactions. This default |
89 | * implementation attempts to use the ioremap_np() API to provide this | |
90 | * on arches that support it, and falls back to ioremap() on those that | |
91 | * don't. Overriding this function is deprecated; arches that properly | |
92 | * support non-posted accesses should implement ioremap_np() instead, which | |
93 | * this default implementation can then use to return mappings compliant with | |
94 | * the PCI specification. | |
cf9ea8ca LP |
95 | */ |
96 | #ifndef pci_remap_cfgspace | |
97 | #define pci_remap_cfgspace pci_remap_cfgspace | |
98 | static inline void __iomem *pci_remap_cfgspace(phys_addr_t offset, | |
99 | size_t size) | |
100 | { | |
b10eb2d5 | 101 | return ioremap_np(offset, size) ?: ioremap(offset, size); |
cf9ea8ca LP |
102 | } |
103 | #endif | |
104 | #endif | |
105 | ||
e1612de9 HM |
106 | /* |
107 | * Some systems do not have legacy ISA devices. | |
108 | * /dev/port is not a valid interface on these systems. | |
109 | * So for those archs, <asm/io.h> should define the following symbol. | |
110 | */ | |
111 | #ifndef arch_has_dev_port | |
112 | #define arch_has_dev_port() (1) | |
113 | #endif | |
114 | ||
d0d98eed AL |
115 | /* |
116 | * Some systems (x86 without PAT) have a somewhat reliable way to mark a | |
117 | * physical address range such that uncached mappings will actually | |
118 | * end up write-combining. This facility should be used in conjunction | |
119 | * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has | |
120 | * no effect if the per-page mechanisms are functional. | |
121 | * (On x86 without PAT, these functions manipulate MTRRs.) | |
122 | * | |
123 | * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed | |
124 | * to have no effect. | |
125 | */ | |
126 | #ifndef arch_phys_wc_add | |
127 | static inline int __must_check arch_phys_wc_add(unsigned long base, | |
128 | unsigned long size) | |
129 | { | |
130 | return 0; /* It worked (i.e. did nothing). */ | |
131 | } | |
132 | ||
133 | static inline void arch_phys_wc_del(int handle) | |
134 | { | |
135 | } | |
136 | ||
137 | #define arch_phys_wc_add arch_phys_wc_add | |
7d010fdf LR |
138 | #ifndef arch_phys_wc_index |
139 | static inline int arch_phys_wc_index(int handle) | |
140 | { | |
141 | return -1; | |
142 | } | |
143 | #define arch_phys_wc_index arch_phys_wc_index | |
144 | #endif | |
d0d98eed AL |
145 | #endif |
146 | ||
3229b906 TZ |
147 | int devm_arch_phys_wc_add(struct device *dev, unsigned long base, unsigned long size); |
148 | ||
92281dee DW |
149 | enum { |
150 | /* See memremap() kernel-doc for usage description... */ | |
151 | MEMREMAP_WB = 1 << 0, | |
152 | MEMREMAP_WT = 1 << 1, | |
c907e0eb | 153 | MEMREMAP_WC = 1 << 2, |
8f716c9b TL |
154 | MEMREMAP_ENC = 1 << 3, |
155 | MEMREMAP_DEC = 1 << 4, | |
92281dee DW |
156 | }; |
157 | ||
158 | void *memremap(resource_size_t offset, size_t size, unsigned long flags); | |
159 | void memunmap(void *addr); | |
160 | ||
8ef42276 DA |
161 | /* |
162 | * On x86 PAT systems we have memory tracking that keeps track of | |
163 | * the allowed mappings on memory ranges. This tracking works for | |
164 | * all the in-kernel mapping APIs (ioremap*), but where the user | |
165 | * wishes to map a range from a physical device into user memory | |
166 | * the tracking won't be updated. This API is to be used by | |
167 | * drivers which remap physical device pages into userspace, | |
168 | * and wants to make sure they are mapped WC and not UC. | |
169 | */ | |
170 | #ifndef arch_io_reserve_memtype_wc | |
171 | static inline int arch_io_reserve_memtype_wc(resource_size_t base, | |
172 | resource_size_t size) | |
173 | { | |
174 | return 0; | |
175 | } | |
176 | ||
177 | static inline void arch_io_free_memtype_wc(resource_size_t base, | |
178 | resource_size_t size) | |
179 | { | |
180 | } | |
181 | #endif | |
182 | ||
c8223107 TZ |
183 | int devm_arch_io_reserve_memtype_wc(struct device *dev, resource_size_t start, |
184 | resource_size_t size); | |
185 | ||
1b3f2bd0 DW |
186 | #ifdef CONFIG_STRICT_DEVMEM |
187 | static inline int range_is_allowed(unsigned long pfn, unsigned long size) | |
188 | { | |
189 | u64 from = ((u64)pfn) << PAGE_SHIFT; | |
190 | u64 to = from + size; | |
191 | u64 cursor = from; | |
192 | ||
193 | while (cursor < to) { | |
194 | if (!devmem_is_allowed(pfn)) | |
195 | return 0; | |
196 | cursor += PAGE_SIZE; | |
197 | pfn++; | |
198 | } | |
199 | return 1; | |
200 | } | |
201 | #else | |
202 | static inline int range_is_allowed(unsigned long pfn, unsigned long size) | |
203 | { | |
204 | return 1; | |
205 | } | |
206 | #endif | |
c27a0d75 | 207 | #endif /* _LINUX_IO_H */ |