2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
12 #include <linux/types.h>
13 #include <asm/byteorder.h>
16 extern void __iomem *ioremap(unsigned long physaddr, unsigned long size);
17 extern void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
19 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
21 return (void __iomem *)port;
24 static inline void ioport_unmap(void __iomem *addr)
28 extern void iounmap(const void __iomem *addr);
30 #define ioremap_nocache(phy, sz) ioremap(phy, sz)
31 #define ioremap_wc(phy, sz) ioremap(phy, sz)
32 #define ioremap_wt(phy, sz) ioremap(phy, sz)
34 /* Change struct page to physical address */
35 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
37 #define __raw_readb __raw_readb
38 static inline u8 __raw_readb(const volatile void __iomem *addr)
45 : "m" (*(volatile u8 __force *)addr)
51 #define __raw_readw __raw_readw
52 static inline u16 __raw_readw(const volatile void __iomem *addr)
59 : "m" (*(volatile u16 __force *)addr)
65 #define __raw_readl __raw_readl
66 static inline u32 __raw_readl(const volatile void __iomem *addr)
73 : "m" (*(volatile u32 __force *)addr)
79 #define __raw_writeb __raw_writeb
80 static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
85 : "r" (b), "m" (*(volatile u8 __force *)addr)
89 #define __raw_writew __raw_writew
90 static inline void __raw_writew(u16 s, volatile void __iomem *addr)
95 : "r" (s), "m" (*(volatile u16 __force *)addr)
100 #define __raw_writel __raw_writel
101 static inline void __raw_writel(u32 w, volatile void __iomem *addr)
103 __asm__ __volatile__(
106 : "r" (w), "m" (*(volatile u32 __force *)addr)
111 #ifdef CONFIG_ISA_ARCV2
112 #include <asm/barrier.h>
113 #define __iormb() rmb()
114 #define __iowmb() wmb()
116 #define __iormb() do { } while (0)
117 #define __iowmb() do { } while (0)
121 * MMIO can also get buffered/optimized in micro-arch, so barriers needed
122 * Based on ARM model for the typical use case
125 * <writel MMIO "go" reg>
127 * <readl MMIO "status" reg>
130 * http://lkml.kernel.org/r/20150622133656.GG1583@arm.com
132 #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
133 #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
134 #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
136 #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
137 #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
138 #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
141 * Relaxed API for drivers which can handle any ordering themselves
143 #define readb_relaxed(c) __raw_readb(c)
144 #define readw_relaxed(c) __raw_readw(c)
145 #define readl_relaxed(c) __raw_readl(c)
147 #define writeb_relaxed(v,c) __raw_writeb(v,c)
148 #define writew_relaxed(v,c) __raw_writew(v,c)
149 #define writel_relaxed(v,c) __raw_writel(v,c)
151 #include <asm-generic/io.h>
153 #endif /* _ASM_ARC_IO_H */