1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright 2006 PathScale, Inc. All Rights Reserved. 4 */ 5 6 #ifndef _LINUX_IO_H 7 #define _LINUX_IO_H 8 9 #include <linux/types.h> 10 #include <linux/init.h> 11 #include <linux/bug.h> 12 #include <linux/err.h> 13 #include <asm/io.h> 14 #include <asm/page.h> 15 16 struct device; 17 struct resource; 18 19 __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count); 20 void __ioread32_copy(void *to, const void __iomem *from, size_t count); 21 void __iowrite64_copy(void __iomem *to, const void *from, size_t count); 22 23 #ifdef CONFIG_MMU 24 void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size, pgprot_t prot); 25 void iounmap_phys_range_hook(phys_addr_t phys_addr, size_t size); 26 int ioremap_page_range(unsigned long addr, unsigned long end, 27 phys_addr_t phys_addr, pgprot_t prot); 28 #else ioremap_page_range(unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot)29 static inline int ioremap_page_range(unsigned long addr, unsigned long end, 30 phys_addr_t phys_addr, pgprot_t prot) 31 { 32 return 0; 33 } 34 #endif 35 36 /* 37 * Managed iomap interface 38 */ 39 #ifdef CONFIG_HAS_IOPORT_MAP 40 void __iomem * devm_ioport_map(struct device *dev, unsigned long port, 41 unsigned int nr); 42 void devm_ioport_unmap(struct device *dev, void __iomem *addr); 43 #else devm_ioport_map(struct device * dev,unsigned long port,unsigned int nr)44 static inline void __iomem *devm_ioport_map(struct device *dev, 45 unsigned long port, 46 unsigned int nr) 47 { 48 return NULL; 49 } 50 devm_ioport_unmap(struct device * dev,void __iomem * addr)51 static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) 52 { 53 } 54 #endif 55 56 #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err) 57 58 void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, 59 resource_size_t size); 60 void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset, 61 resource_size_t size); 62 void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, 63 resource_size_t size); 64 void __iomem *devm_ioremap_np(struct device *dev, resource_size_t offset, 65 resource_size_t size); 66 void devm_iounmap(struct device *dev, void __iomem *addr); 67 int check_signature(const volatile void __iomem *io_addr, 68 const unsigned char *signature, int length); 69 void devm_ioremap_release(struct device *dev, void *res); 70 71 void *devm_memremap(struct device *dev, resource_size_t offset, 72 size_t size, unsigned long flags); 73 void devm_memunmap(struct device *dev, void *addr); 74 75 #ifdef CONFIG_PCI 76 /* 77 * The PCI specifications (Rev 3.0, 3.2.5 "Transaction Ordering and 78 * Posting") mandate non-posted configuration transactions. This default 79 * implementation attempts to use the ioremap_np() API to provide this 80 * on arches that support it, and falls back to ioremap() on those that 81 * don't. Overriding this function is deprecated; arches that properly 82 * support non-posted accesses should implement ioremap_np() instead, which 83 * this default implementation can then use to return mappings compliant with 84 * the PCI specification. 85 */ 86 #ifndef pci_remap_cfgspace 87 #define pci_remap_cfgspace pci_remap_cfgspace pci_remap_cfgspace(phys_addr_t offset,size_t size)88 static inline void __iomem *pci_remap_cfgspace(phys_addr_t offset, 89 size_t size) 90 { 91 return ioremap_np(offset, size) ?: ioremap(offset, size); 92 } 93 #endif 94 #endif 95 96 /* 97 * Some systems do not have legacy ISA devices. 98 * /dev/port is not a valid interface on these systems. 99 * So for those archs, <asm/io.h> should define the following symbol. 100 */ 101 #ifndef arch_has_dev_port 102 #define arch_has_dev_port() (1) 103 #endif 104 105 /* 106 * Some systems (x86 without PAT) have a somewhat reliable way to mark a 107 * physical address range such that uncached mappings will actually 108 * end up write-combining. This facility should be used in conjunction 109 * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has 110 * no effect if the per-page mechanisms are functional. 111 * (On x86 without PAT, these functions manipulate MTRRs.) 112 * 113 * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed 114 * to have no effect. 115 */ 116 #ifndef arch_phys_wc_add arch_phys_wc_add(unsigned long base,unsigned long size)117 static inline int __must_check arch_phys_wc_add(unsigned long base, 118 unsigned long size) 119 { 120 return 0; /* It worked (i.e. did nothing). */ 121 } 122 arch_phys_wc_del(int handle)123 static inline void arch_phys_wc_del(int handle) 124 { 125 } 126 127 #define arch_phys_wc_add arch_phys_wc_add 128 #ifndef arch_phys_wc_index arch_phys_wc_index(int handle)129 static inline int arch_phys_wc_index(int handle) 130 { 131 return -1; 132 } 133 #define arch_phys_wc_index arch_phys_wc_index 134 #endif 135 #endif 136 137 enum { 138 /* See memremap() kernel-doc for usage description... */ 139 MEMREMAP_WB = 1 << 0, 140 MEMREMAP_WT = 1 << 1, 141 MEMREMAP_WC = 1 << 2, 142 MEMREMAP_ENC = 1 << 3, 143 MEMREMAP_DEC = 1 << 4, 144 }; 145 146 void *memremap(resource_size_t offset, size_t size, unsigned long flags); 147 void memunmap(void *addr); 148 149 /* 150 * On x86 PAT systems we have memory tracking that keeps track of 151 * the allowed mappings on memory ranges. This tracking works for 152 * all the in-kernel mapping APIs (ioremap*), but where the user 153 * wishes to map a range from a physical device into user memory 154 * the tracking won't be updated. This API is to be used by 155 * drivers which remap physical device pages into userspace, 156 * and wants to make sure they are mapped WC and not UC. 157 */ 158 #ifndef arch_io_reserve_memtype_wc arch_io_reserve_memtype_wc(resource_size_t base,resource_size_t size)159 static inline int arch_io_reserve_memtype_wc(resource_size_t base, 160 resource_size_t size) 161 { 162 return 0; 163 } 164 arch_io_free_memtype_wc(resource_size_t base,resource_size_t size)165 static inline void arch_io_free_memtype_wc(resource_size_t base, 166 resource_size_t size) 167 { 168 } 169 #endif 170 171 #endif /* _LINUX_IO_H */ 172