1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds #ifndef __GENERIC_IO_H 31da177e4SLinus Torvalds #define __GENERIC_IO_H 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds #include <linux/linkage.h> 6dae409a2SJames Bottomley #include <asm/byteorder.h> 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds /* 91da177e4SLinus Torvalds * These are the "generic" interfaces for doing new-style 101da177e4SLinus Torvalds * memory-mapped or PIO accesses. Architectures may do 111da177e4SLinus Torvalds * their own arch-optimized versions, these just act as 121da177e4SLinus Torvalds * wrappers around the old-style IO register access functions: 131da177e4SLinus Torvalds * read[bwl]/write[bwl]/in[bwl]/out[bwl] 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * Don't include this directly, include it from <asm/io.h>. 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds /* 191da177e4SLinus Torvalds * Read/write from/to an (offsettable) iomem cookie. It might be a PIO 201da177e4SLinus Torvalds * access or a MMIO access, these functions don't care. The info is 211da177e4SLinus Torvalds * encoded in the hardware mapping set up by the mapping functions 221da177e4SLinus Torvalds * (or the cookie itself, depending on implementation and hw). 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds * The generic routines just encode the PIO/MMIO as part of the 251da177e4SLinus Torvalds * cookie, and coldly assume that the MMIO IO mappings are not 261da177e4SLinus Torvalds * in the low address range. Architectures for which this is not 271da177e4SLinus Torvalds * true can't use this generic implementation. 281da177e4SLinus Torvalds */ 298f28ca6bSKrzysztof Kozlowski extern unsigned int ioread8(const void __iomem *); 308f28ca6bSKrzysztof Kozlowski extern unsigned int ioread16(const void __iomem *); 318f28ca6bSKrzysztof Kozlowski extern unsigned int ioread16be(const void __iomem *); 328f28ca6bSKrzysztof Kozlowski extern unsigned int ioread32(const void __iomem *); 338f28ca6bSKrzysztof Kozlowski extern unsigned int ioread32be(const void __iomem *); 349e44fb18SHoria Geantă #ifdef CONFIG_64BIT 358f28ca6bSKrzysztof Kozlowski extern u64 ioread64(const void __iomem *); 368f28ca6bSKrzysztof Kozlowski extern u64 ioread64be(const void __iomem *); 379e44fb18SHoria Geantă #endif 381da177e4SLinus Torvalds 3979bf0cbdSLogan Gunthorpe #ifdef readq 4079bf0cbdSLogan Gunthorpe #define ioread64_lo_hi ioread64_lo_hi 4179bf0cbdSLogan Gunthorpe #define ioread64_hi_lo ioread64_hi_lo 4279bf0cbdSLogan Gunthorpe #define ioread64be_lo_hi ioread64be_lo_hi 4379bf0cbdSLogan Gunthorpe #define ioread64be_hi_lo ioread64be_hi_lo 448f28ca6bSKrzysztof Kozlowski extern u64 ioread64_lo_hi(const void __iomem *addr); 458f28ca6bSKrzysztof Kozlowski extern u64 ioread64_hi_lo(const void __iomem *addr); 468f28ca6bSKrzysztof Kozlowski extern u64 ioread64be_lo_hi(const void __iomem *addr); 478f28ca6bSKrzysztof Kozlowski extern u64 ioread64be_hi_lo(const void __iomem *addr); 4879bf0cbdSLogan Gunthorpe #endif 4979bf0cbdSLogan Gunthorpe 50144b2a91SHarvey Harrison extern void iowrite8(u8, void __iomem *); 51144b2a91SHarvey Harrison extern void iowrite16(u16, void __iomem *); 52144b2a91SHarvey Harrison extern void iowrite16be(u16, void __iomem *); 53144b2a91SHarvey Harrison extern void iowrite32(u32, void __iomem *); 54144b2a91SHarvey Harrison extern void iowrite32be(u32, void __iomem *); 559e44fb18SHoria Geantă #ifdef CONFIG_64BIT 569e44fb18SHoria Geantă extern void iowrite64(u64, void __iomem *); 579e44fb18SHoria Geantă extern void iowrite64be(u64, void __iomem *); 589e44fb18SHoria Geantă #endif 591da177e4SLinus Torvalds 6079bf0cbdSLogan Gunthorpe #ifdef writeq 6179bf0cbdSLogan Gunthorpe #define iowrite64_lo_hi iowrite64_lo_hi 6279bf0cbdSLogan Gunthorpe #define iowrite64_hi_lo iowrite64_hi_lo 6379bf0cbdSLogan Gunthorpe #define iowrite64be_lo_hi iowrite64be_lo_hi 6479bf0cbdSLogan Gunthorpe #define iowrite64be_hi_lo iowrite64be_hi_lo 6579bf0cbdSLogan Gunthorpe extern void iowrite64_lo_hi(u64 val, void __iomem *addr); 6679bf0cbdSLogan Gunthorpe extern void iowrite64_hi_lo(u64 val, void __iomem *addr); 6779bf0cbdSLogan Gunthorpe extern void iowrite64be_lo_hi(u64 val, void __iomem *addr); 6879bf0cbdSLogan Gunthorpe extern void iowrite64be_hi_lo(u64 val, void __iomem *addr); 6979bf0cbdSLogan Gunthorpe #endif 7079bf0cbdSLogan Gunthorpe 711da177e4SLinus Torvalds /* 721da177e4SLinus Torvalds * "string" versions of the above. Note that they 731da177e4SLinus Torvalds * use native byte ordering for the accesses (on 741da177e4SLinus Torvalds * the assumption that IO and memory agree on a 751da177e4SLinus Torvalds * byte order, and CPU byteorder is irrelevant). 761da177e4SLinus Torvalds * 771da177e4SLinus Torvalds * They do _not_ update the port address. If you 781da177e4SLinus Torvalds * want MMIO that copies stuff laid out in MMIO 791da177e4SLinus Torvalds * memory across multiple ports, use "memcpy_toio()" 801da177e4SLinus Torvalds * and friends. 811da177e4SLinus Torvalds */ 828f28ca6bSKrzysztof Kozlowski extern void ioread8_rep(const void __iomem *port, void *buf, unsigned long count); 838f28ca6bSKrzysztof Kozlowski extern void ioread16_rep(const void __iomem *port, void *buf, unsigned long count); 848f28ca6bSKrzysztof Kozlowski extern void ioread32_rep(const void __iomem *port, void *buf, unsigned long count); 851da177e4SLinus Torvalds 86144b2a91SHarvey Harrison extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count); 87144b2a91SHarvey Harrison extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count); 88144b2a91SHarvey Harrison extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count); 891da177e4SLinus Torvalds 90ce816fa8SUwe Kleine-König #ifdef CONFIG_HAS_IOPORT_MAP 911da177e4SLinus Torvalds /* Create a virtual mapping cookie for an IO port range */ 921da177e4SLinus Torvalds extern void __iomem *ioport_map(unsigned long port, unsigned int nr); 931da177e4SLinus Torvalds extern void ioport_unmap(void __iomem *); 9482ed223cSJonas Bonn #endif 951da177e4SLinus Torvalds 961526a756Svenkatesh.pallipadi@intel.com #ifndef ARCH_HAS_IOREMAP_WC 974bdc0d67SChristoph Hellwig #define ioremap_wc ioremap 981526a756Svenkatesh.pallipadi@intel.com #endif 991526a756Svenkatesh.pallipadi@intel.com 100d838270eSToshi Kani #ifndef ARCH_HAS_IOREMAP_WT 1014bdc0d67SChristoph Hellwig #define ioremap_wt ioremap 102d838270eSToshi Kani #endif 103d838270eSToshi Kani 104*7c566bb5SHector Martin #ifndef ARCH_HAS_IOREMAP_NP 105*7c566bb5SHector Martin /* See the comment in asm-generic/io.h about ioremap_np(). */ 106*7c566bb5SHector Martin #define ioremap_np ioremap_np 107*7c566bb5SHector Martin static inline void __iomem *ioremap_np(phys_addr_t offset, size_t size) 108*7c566bb5SHector Martin { 109*7c566bb5SHector Martin return NULL; 110*7c566bb5SHector Martin } 111*7c566bb5SHector Martin #endif 112*7c566bb5SHector Martin 11382ed223cSJonas Bonn #ifdef CONFIG_PCI 11466eab4dfSMichael S. Tsirkin /* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */ 1151da177e4SLinus Torvalds struct pci_dev; 1161da177e4SLinus Torvalds extern void pci_iounmap(struct pci_dev *dev, void __iomem *); 11797a29d59SJames Bottomley #elif defined(CONFIG_GENERIC_IOMAP) 118fea80311SRandy Dunlap struct pci_dev; 119fea80311SRandy Dunlap static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) 120fea80311SRandy Dunlap { } 12182ed223cSJonas Bonn #endif 1221da177e4SLinus Torvalds 12366eab4dfSMichael S. Tsirkin #include <asm-generic/pci_iomap.h> 12466eab4dfSMichael S. Tsirkin 1251da177e4SLinus Torvalds #endif 126