Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright 2006 PathScale, Inc.  All Rights Reserved.
0004  */
0005 
0006 #ifndef _LINUX_IO_H
0007 #define _LINUX_IO_H
0008 
0009 #include <linux/types.h>
0010 #include <linux/init.h>
0011 #include <linux/bug.h>
0012 #include <linux/err.h>
0013 #include <asm/io.h>
0014 #include <asm/page.h>
0015 
0016 struct device;
0017 struct resource;
0018 
0019 __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
0020 void __ioread32_copy(void *to, const void __iomem *from, size_t count);
0021 void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
0022 
0023 #ifdef CONFIG_MMU
0024 int ioremap_page_range(unsigned long addr, unsigned long end,
0025                phys_addr_t phys_addr, pgprot_t prot);
0026 #else
0027 static inline int ioremap_page_range(unsigned long addr, unsigned long end,
0028                      phys_addr_t phys_addr, pgprot_t prot)
0029 {
0030     return 0;
0031 }
0032 #endif
0033 
0034 /*
0035  * Managed iomap interface
0036  */
0037 #ifdef CONFIG_HAS_IOPORT_MAP
0038 void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
0039                    unsigned int nr);
0040 void devm_ioport_unmap(struct device *dev, void __iomem *addr);
0041 #else
0042 static inline void __iomem *devm_ioport_map(struct device *dev,
0043                          unsigned long port,
0044                          unsigned int nr)
0045 {
0046     return NULL;
0047 }
0048 
0049 static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
0050 {
0051 }
0052 #endif
0053 
0054 #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
0055 
0056 void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
0057                resource_size_t size);
0058 void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
0059                    resource_size_t size);
0060 void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
0061                    resource_size_t size);
0062 void __iomem *devm_ioremap_np(struct device *dev, resource_size_t offset,
0063                    resource_size_t size);
0064 void devm_iounmap(struct device *dev, void __iomem *addr);
0065 int check_signature(const volatile void __iomem *io_addr,
0066             const unsigned char *signature, int length);
0067 void devm_ioremap_release(struct device *dev, void *res);
0068 
0069 void *devm_memremap(struct device *dev, resource_size_t offset,
0070         size_t size, unsigned long flags);
0071 void devm_memunmap(struct device *dev, void *addr);
0072 
0073 #ifdef CONFIG_PCI
0074 /*
0075  * The PCI specifications (Rev 3.0, 3.2.5 "Transaction Ordering and
0076  * Posting") mandate non-posted configuration transactions. This default
0077  * implementation attempts to use the ioremap_np() API to provide this
0078  * on arches that support it, and falls back to ioremap() on those that
0079  * don't. Overriding this function is deprecated; arches that properly
0080  * support non-posted accesses should implement ioremap_np() instead, which
0081  * this default implementation can then use to return mappings compliant with
0082  * the PCI specification.
0083  */
0084 #ifndef pci_remap_cfgspace
0085 #define pci_remap_cfgspace pci_remap_cfgspace
0086 static inline void __iomem *pci_remap_cfgspace(phys_addr_t offset,
0087                            size_t size)
0088 {
0089     return ioremap_np(offset, size) ?: ioremap(offset, size);
0090 }
0091 #endif
0092 #endif
0093 
0094 /*
0095  * Some systems do not have legacy ISA devices.
0096  * /dev/port is not a valid interface on these systems.
0097  * So for those archs, <asm/io.h> should define the following symbol.
0098  */
0099 #ifndef arch_has_dev_port
0100 #define arch_has_dev_port()     (1)
0101 #endif
0102 
0103 /*
0104  * Some systems (x86 without PAT) have a somewhat reliable way to mark a
0105  * physical address range such that uncached mappings will actually
0106  * end up write-combining.  This facility should be used in conjunction
0107  * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has
0108  * no effect if the per-page mechanisms are functional.
0109  * (On x86 without PAT, these functions manipulate MTRRs.)
0110  *
0111  * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed
0112  * to have no effect.
0113  */
0114 #ifndef arch_phys_wc_add
0115 static inline int __must_check arch_phys_wc_add(unsigned long base,
0116                         unsigned long size)
0117 {
0118     return 0;  /* It worked (i.e. did nothing). */
0119 }
0120 
0121 static inline void arch_phys_wc_del(int handle)
0122 {
0123 }
0124 
0125 #define arch_phys_wc_add arch_phys_wc_add
0126 #ifndef arch_phys_wc_index
0127 static inline int arch_phys_wc_index(int handle)
0128 {
0129     return -1;
0130 }
0131 #define arch_phys_wc_index arch_phys_wc_index
0132 #endif
0133 #endif
0134 
0135 int devm_arch_phys_wc_add(struct device *dev, unsigned long base, unsigned long size);
0136 
0137 enum {
0138     /* See memremap() kernel-doc for usage description... */
0139     MEMREMAP_WB = 1 << 0,
0140     MEMREMAP_WT = 1 << 1,
0141     MEMREMAP_WC = 1 << 2,
0142     MEMREMAP_ENC = 1 << 3,
0143     MEMREMAP_DEC = 1 << 4,
0144 };
0145 
0146 void *memremap(resource_size_t offset, size_t size, unsigned long flags);
0147 void memunmap(void *addr);
0148 
0149 /*
0150  * On x86 PAT systems we have memory tracking that keeps track of
0151  * the allowed mappings on memory ranges. This tracking works for
0152  * all the in-kernel mapping APIs (ioremap*), but where the user
0153  * wishes to map a range from a physical device into user memory
0154  * the tracking won't be updated. This API is to be used by
0155  * drivers which remap physical device pages into userspace,
0156  * and wants to make sure they are mapped WC and not UC.
0157  */
0158 #ifndef arch_io_reserve_memtype_wc
0159 static inline int arch_io_reserve_memtype_wc(resource_size_t base,
0160                          resource_size_t size)
0161 {
0162     return 0;
0163 }
0164 
0165 static inline void arch_io_free_memtype_wc(resource_size_t base,
0166                        resource_size_t size)
0167 {
0168 }
0169 #endif
0170 
0171 int devm_arch_io_reserve_memtype_wc(struct device *dev, resource_size_t start,
0172                     resource_size_t size);
0173 
0174 #endif /* _LINUX_IO_H */