162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __GENERIC_IO_H 362306a36Sopenharmony_ci#define __GENERIC_IO_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/linkage.h> 662306a36Sopenharmony_ci#include <asm/byteorder.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci/* 962306a36Sopenharmony_ci * These are the "generic" interfaces for doing new-style 1062306a36Sopenharmony_ci * memory-mapped or PIO accesses. Architectures may do 1162306a36Sopenharmony_ci * their own arch-optimized versions, these just act as 1262306a36Sopenharmony_ci * wrappers around the old-style IO register access functions: 1362306a36Sopenharmony_ci * read[bwl]/write[bwl]/in[bwl]/out[bwl] 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * Don't include this directly, include it from <asm/io.h>. 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* 1962306a36Sopenharmony_ci * Read/write from/to an (offsettable) iomem cookie. It might be a PIO 2062306a36Sopenharmony_ci * access or a MMIO access, these functions don't care. The info is 2162306a36Sopenharmony_ci * encoded in the hardware mapping set up by the mapping functions 2262306a36Sopenharmony_ci * (or the cookie itself, depending on implementation and hw). 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * The generic routines just encode the PIO/MMIO as part of the 2562306a36Sopenharmony_ci * cookie, and coldly assume that the MMIO IO mappings are not 2662306a36Sopenharmony_ci * in the low address range. Architectures for which this is not 2762306a36Sopenharmony_ci * true can't use this generic implementation. 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ciextern unsigned int ioread8(const void __iomem *); 3062306a36Sopenharmony_ciextern unsigned int ioread16(const void __iomem *); 3162306a36Sopenharmony_ciextern unsigned int ioread16be(const void __iomem *); 3262306a36Sopenharmony_ciextern unsigned int ioread32(const void __iomem *); 3362306a36Sopenharmony_ciextern unsigned int ioread32be(const void __iomem *); 3462306a36Sopenharmony_ci#ifdef CONFIG_64BIT 3562306a36Sopenharmony_ciextern u64 ioread64(const void __iomem *); 3662306a36Sopenharmony_ciextern u64 ioread64be(const void __iomem *); 3762306a36Sopenharmony_ci#endif 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#ifdef readq 4062306a36Sopenharmony_ci#define ioread64_lo_hi ioread64_lo_hi 4162306a36Sopenharmony_ci#define ioread64_hi_lo ioread64_hi_lo 4262306a36Sopenharmony_ci#define ioread64be_lo_hi ioread64be_lo_hi 4362306a36Sopenharmony_ci#define ioread64be_hi_lo ioread64be_hi_lo 4462306a36Sopenharmony_ciextern u64 ioread64_lo_hi(const void __iomem *addr); 4562306a36Sopenharmony_ciextern u64 ioread64_hi_lo(const void __iomem *addr); 4662306a36Sopenharmony_ciextern u64 ioread64be_lo_hi(const void __iomem *addr); 4762306a36Sopenharmony_ciextern u64 ioread64be_hi_lo(const void __iomem *addr); 4862306a36Sopenharmony_ci#endif 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciextern void iowrite8(u8, void __iomem *); 5162306a36Sopenharmony_ciextern void iowrite16(u16, void __iomem *); 5262306a36Sopenharmony_ciextern void iowrite16be(u16, void __iomem *); 5362306a36Sopenharmony_ciextern void iowrite32(u32, void __iomem *); 5462306a36Sopenharmony_ciextern void iowrite32be(u32, void __iomem *); 5562306a36Sopenharmony_ci#ifdef CONFIG_64BIT 5662306a36Sopenharmony_ciextern void iowrite64(u64, void __iomem *); 5762306a36Sopenharmony_ciextern void iowrite64be(u64, void __iomem *); 5862306a36Sopenharmony_ci#endif 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#ifdef writeq 6162306a36Sopenharmony_ci#define iowrite64_lo_hi iowrite64_lo_hi 6262306a36Sopenharmony_ci#define iowrite64_hi_lo iowrite64_hi_lo 6362306a36Sopenharmony_ci#define iowrite64be_lo_hi iowrite64be_lo_hi 6462306a36Sopenharmony_ci#define iowrite64be_hi_lo iowrite64be_hi_lo 6562306a36Sopenharmony_ciextern void iowrite64_lo_hi(u64 val, void __iomem *addr); 6662306a36Sopenharmony_ciextern void iowrite64_hi_lo(u64 val, void __iomem *addr); 6762306a36Sopenharmony_ciextern void iowrite64be_lo_hi(u64 val, void __iomem *addr); 6862306a36Sopenharmony_ciextern void iowrite64be_hi_lo(u64 val, void __iomem *addr); 6962306a36Sopenharmony_ci#endif 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci/* 7262306a36Sopenharmony_ci * "string" versions of the above. Note that they 7362306a36Sopenharmony_ci * use native byte ordering for the accesses (on 7462306a36Sopenharmony_ci * the assumption that IO and memory agree on a 7562306a36Sopenharmony_ci * byte order, and CPU byteorder is irrelevant). 7662306a36Sopenharmony_ci * 7762306a36Sopenharmony_ci * They do _not_ update the port address. If you 7862306a36Sopenharmony_ci * want MMIO that copies stuff laid out in MMIO 7962306a36Sopenharmony_ci * memory across multiple ports, use "memcpy_toio()" 8062306a36Sopenharmony_ci * and friends. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_ciextern void ioread8_rep(const void __iomem *port, void *buf, unsigned long count); 8362306a36Sopenharmony_ciextern void ioread16_rep(const void __iomem *port, void *buf, unsigned long count); 8462306a36Sopenharmony_ciextern void ioread32_rep(const void __iomem *port, void *buf, unsigned long count); 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciextern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count); 8762306a36Sopenharmony_ciextern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count); 8862306a36Sopenharmony_ciextern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count); 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#ifdef CONFIG_HAS_IOPORT_MAP 9162306a36Sopenharmony_ci/* Create a virtual mapping cookie for an IO port range */ 9262306a36Sopenharmony_ciextern void __iomem *ioport_map(unsigned long port, unsigned int nr); 9362306a36Sopenharmony_ciextern void ioport_unmap(void __iomem *); 9462306a36Sopenharmony_ci#endif 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci#ifndef ioremap_wc 9762306a36Sopenharmony_ci#define ioremap_wc ioremap 9862306a36Sopenharmony_ci#endif 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#ifndef ioremap_wt 10162306a36Sopenharmony_ci#define ioremap_wt ioremap 10262306a36Sopenharmony_ci#endif 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci#ifndef ioremap_np 10562306a36Sopenharmony_ci/* See the comment in asm-generic/io.h about ioremap_np(). */ 10662306a36Sopenharmony_ci#define ioremap_np ioremap_np 10762306a36Sopenharmony_cistatic inline void __iomem *ioremap_np(phys_addr_t offset, size_t size) 10862306a36Sopenharmony_ci{ 10962306a36Sopenharmony_ci return NULL; 11062306a36Sopenharmony_ci} 11162306a36Sopenharmony_ci#endif 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci#include <asm-generic/pci_iomap.h> 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#endif 116