blob: d8f8622fa044dbaeba223bc373f57dad5dac6070 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __GENERIC_IO_H
2#define __GENERIC_IO_H
3
4#include <linux/linkage.h>
James Bottomleydae409a2005-04-16 15:25:54 -07005#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7/*
8 * These are the "generic" interfaces for doing new-style
9 * memory-mapped or PIO accesses. Architectures may do
10 * their own arch-optimized versions, these just act as
11 * wrappers around the old-style IO register access functions:
12 * read[bwl]/write[bwl]/in[bwl]/out[bwl]
13 *
14 * Don't include this directly, include it from <asm/io.h>.
15 */
16
17/*
18 * Read/write from/to an (offsettable) iomem cookie. It might be a PIO
19 * access or a MMIO access, these functions don't care. The info is
20 * encoded in the hardware mapping set up by the mapping functions
21 * (or the cookie itself, depending on implementation and hw).
22 *
23 * The generic routines just encode the PIO/MMIO as part of the
24 * cookie, and coldly assume that the MMIO IO mappings are not
25 * in the low address range. Architectures for which this is not
26 * true can't use this generic implementation.
27 */
Harvey Harrison144b2a92008-02-08 04:19:56 -080028extern unsigned int ioread8(void __iomem *);
29extern unsigned int ioread16(void __iomem *);
30extern unsigned int ioread16be(void __iomem *);
31extern unsigned int ioread32(void __iomem *);
32extern unsigned int ioread32be(void __iomem *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Harvey Harrison144b2a92008-02-08 04:19:56 -080034extern void iowrite8(u8, void __iomem *);
35extern void iowrite16(u16, void __iomem *);
36extern void iowrite16be(u16, void __iomem *);
37extern void iowrite32(u32, void __iomem *);
38extern void iowrite32be(u32, void __iomem *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/*
41 * "string" versions of the above. Note that they
42 * use native byte ordering for the accesses (on
43 * the assumption that IO and memory agree on a
44 * byte order, and CPU byteorder is irrelevant).
45 *
46 * They do _not_ update the port address. If you
47 * want MMIO that copies stuff laid out in MMIO
48 * memory across multiple ports, use "memcpy_toio()"
49 * and friends.
50 */
Harvey Harrison144b2a92008-02-08 04:19:56 -080051extern void ioread8_rep(void __iomem *port, void *buf, unsigned long count);
52extern void ioread16_rep(void __iomem *port, void *buf, unsigned long count);
53extern void ioread32_rep(void __iomem *port, void *buf, unsigned long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Harvey Harrison144b2a92008-02-08 04:19:56 -080055extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
56extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
57extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Uwe Kleine-Königce816fa2014-04-07 15:39:19 -070059#ifdef CONFIG_HAS_IOPORT_MAP
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/* Create a virtual mapping cookie for an IO port range */
61extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
62extern void ioport_unmap(void __iomem *);
Jonas Bonn82ed2232011-07-02 17:23:29 +020063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
venkatesh.pallipadi@intel.com1526a752008-03-18 17:00:24 -070065#ifndef ARCH_HAS_IOREMAP_WC
66#define ioremap_wc ioremap_nocache
67#endif
68
Toshi Kanid8382702015-06-04 18:55:15 +020069#ifndef ARCH_HAS_IOREMAP_WT
70#define ioremap_wt ioremap_nocache
71#endif
72
Jonas Bonn82ed2232011-07-02 17:23:29 +020073#ifdef CONFIG_PCI
Michael S. Tsirkin66eab4d2011-11-24 20:45:20 +020074/* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075struct pci_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
James Bottomley97a29d52012-01-30 10:40:47 -060077#elif defined(CONFIG_GENERIC_IOMAP)
Randy Dunlapfea80312011-07-24 11:39:14 -070078struct pci_dev;
Randy Dunlapfea80312011-07-24 11:39:14 -070079static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
80{ }
Jonas Bonn82ed2232011-07-02 17:23:29 +020081#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Michael S. Tsirkin66eab4d2011-11-24 20:45:20 +020083#include <asm-generic/pci_iomap.h>
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#endif