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 */ 29144b2a91SHarvey Harrison extern unsigned int ioread8(void __iomem *); 30144b2a91SHarvey Harrison extern unsigned int ioread16(void __iomem *); 31144b2a91SHarvey Harrison extern unsigned int ioread16be(void __iomem *); 32144b2a91SHarvey Harrison extern unsigned int ioread32(void __iomem *); 33144b2a91SHarvey Harrison extern unsigned int ioread32be(void __iomem *); 349e44fb18SHoria Geantă #ifdef CONFIG_64BIT 359e44fb18SHoria Geantă extern u64 ioread64(void __iomem *); 369e44fb18SHoria Geantă extern u64 ioread64be(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 4479bf0cbdSLogan Gunthorpe extern u64 ioread64_lo_hi(void __iomem *addr); 4579bf0cbdSLogan Gunthorpe extern u64 ioread64_hi_lo(void __iomem *addr); 4679bf0cbdSLogan Gunthorpe extern u64 ioread64be_lo_hi(void __iomem *addr); 4779bf0cbdSLogan Gunthorpe extern u64 ioread64be_hi_lo(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 */ 82144b2a91SHarvey Harrison extern void ioread8_rep(void __iomem *port, void *buf, unsigned long count); 83144b2a91SHarvey Harrison extern void ioread16_rep(void __iomem *port, void *buf, unsigned long count); 84144b2a91SHarvey Harrison extern void ioread32_rep(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 971526a756Svenkatesh.pallipadi@intel.com #define ioremap_wc ioremap_nocache 981526a756Svenkatesh.pallipadi@intel.com #endif 991526a756Svenkatesh.pallipadi@intel.com 100d838270eSToshi Kani #ifndef ARCH_HAS_IOREMAP_WT 101d838270eSToshi Kani #define ioremap_wt ioremap_nocache 102d838270eSToshi Kani #endif 103d838270eSToshi Kani 10482ed223cSJonas Bonn #ifdef CONFIG_PCI 10566eab4dfSMichael S. Tsirkin /* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */ 1061da177e4SLinus Torvalds struct pci_dev; 1071da177e4SLinus Torvalds extern void pci_iounmap(struct pci_dev *dev, void __iomem *); 10897a29d59SJames Bottomley #elif defined(CONFIG_GENERIC_IOMAP) 109fea80311SRandy Dunlap struct pci_dev; 110fea80311SRandy Dunlap static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) 111fea80311SRandy Dunlap { } 11282ed223cSJonas Bonn #endif 1131da177e4SLinus Torvalds 11466eab4dfSMichael S. Tsirkin #include <asm-generic/pci_iomap.h> 11566eab4dfSMichael S. Tsirkin 1161da177e4SLinus Torvalds #endif 117