4 #include <linux/types.h>
5 #include <asm/pgtable.h>
7 #define virt_to_phys(a) ((unsigned long)__pa(a))
8 #define phys_to_virt(a) __va(a)
9 #define virt_to_bus virt_to_phys
10 #define bus_to_virt phys_to_virt
12 static inline unsigned long isa_bus_to_virt(unsigned long addr) {
17 static inline unsigned long isa_virt_to_bus(void *addr) {
25 * readX()/writeX() do byteswapping and take an ioremapped address
26 * __raw_readX()/__raw_writeX() don't byteswap and take an ioremapped address.
27 * gsc_*() don't byteswap and operate on physical addresses;
28 * eg dev->hpa or 0xfee00000.
31 static inline unsigned char gsc_readb(unsigned long addr)
40 : "=&r" (flags), "=r" (ret) : "r" (addr) );
45 static inline unsigned short gsc_readw(unsigned long addr)
54 : "=&r" (flags), "=r" (ret) : "r" (addr) );
59 static inline unsigned int gsc_readl(unsigned long addr)
65 : "=r" (ret) : "r" (addr) );
70 static inline unsigned long long gsc_readq(unsigned long addr)
72 unsigned long long ret;
77 : "=r" (ret) : "r" (addr) );
79 /* two reads may have side effects.. */
80 ret = ((u64) gsc_readl(addr)) << 32;
81 ret |= gsc_readl(addr+4);
86 static inline void gsc_writeb(unsigned char val, unsigned long addr)
93 : "=&r" (flags) : "r" (val), "r" (addr) );
96 static inline void gsc_writew(unsigned short val, unsigned long addr)
103 : "=&r" (flags) : "r" (val), "r" (addr) );
106 static inline void gsc_writel(unsigned int val, unsigned long addr)
108 __asm__ __volatile__(
110 : : "r" (val), "r" (addr) );
113 static inline void gsc_writeq(unsigned long long val, unsigned long addr)
116 __asm__ __volatile__(
118 : : "r" (val), "r" (addr) );
120 /* two writes may have side effects.. */
121 gsc_writel(val >> 32, addr);
122 gsc_writel(val, addr+4);
127 * The standard PCI ioremap interfaces
130 extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
132 /* Most machines react poorly to I/O-space being cacheable... Instead let's
133 * define ioremap() in terms of ioremap_nocache().
135 static inline void __iomem * ioremap(unsigned long offset, unsigned long size)
137 return __ioremap(offset, size, _PAGE_NO_CACHE);
139 #define ioremap_nocache(off, sz) ioremap((off), (sz))
140 #define ioremap_wc ioremap_nocache
141 #define ioremap_uc ioremap_nocache
143 extern void iounmap(const volatile void __iomem *addr);
145 static inline unsigned char __raw_readb(const volatile void __iomem *addr)
147 return (*(volatile unsigned char __force *) (addr));
149 static inline unsigned short __raw_readw(const volatile void __iomem *addr)
151 return *(volatile unsigned short __force *) addr;
153 static inline unsigned int __raw_readl(const volatile void __iomem *addr)
155 return *(volatile unsigned int __force *) addr;
157 static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
159 return *(volatile unsigned long long __force *) addr;
162 static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
164 *(volatile unsigned char __force *) addr = b;
166 static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
168 *(volatile unsigned short __force *) addr = b;
170 static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
172 *(volatile unsigned int __force *) addr = b;
174 static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
176 *(volatile unsigned long long __force *) addr = b;
179 static inline unsigned char readb(const volatile void __iomem *addr)
181 return __raw_readb(addr);
183 static inline unsigned short readw(const volatile void __iomem *addr)
185 return le16_to_cpu(__raw_readw(addr));
187 static inline unsigned int readl(const volatile void __iomem *addr)
189 return le32_to_cpu(__raw_readl(addr));
191 static inline unsigned long long readq(const volatile void __iomem *addr)
193 return le64_to_cpu(__raw_readq(addr));
196 static inline void writeb(unsigned char b, volatile void __iomem *addr)
198 __raw_writeb(b, addr);
200 static inline void writew(unsigned short w, volatile void __iomem *addr)
202 __raw_writew(cpu_to_le16(w), addr);
204 static inline void writel(unsigned int l, volatile void __iomem *addr)
206 __raw_writel(cpu_to_le32(l), addr);
208 static inline void writeq(unsigned long long q, volatile void __iomem *addr)
210 __raw_writeq(cpu_to_le64(q), addr);
217 #define writeb writeb
218 #define writew writew
219 #define writel writel
220 #define writeq writeq
222 #define readb_relaxed(addr) readb(addr)
223 #define readw_relaxed(addr) readw(addr)
224 #define readl_relaxed(addr) readl(addr)
225 #define readq_relaxed(addr) readq(addr)
226 #define writeb_relaxed(b, addr) writeb(b, addr)
227 #define writew_relaxed(w, addr) writew(w, addr)
228 #define writel_relaxed(l, addr) writel(l, addr)
229 #define writeq_relaxed(q, addr) writeq(q, addr)
231 #define mmiowb() do { } while (0)
233 void memset_io(volatile void __iomem *addr, unsigned char val, int count);
234 void memcpy_fromio(void *dst, const volatile void __iomem *src, int count);
235 void memcpy_toio(volatile void __iomem *dst, const void *src, int count);
246 extern unsigned char eisa_in8(unsigned short port);
247 extern unsigned short eisa_in16(unsigned short port);
248 extern unsigned int eisa_in32(unsigned short port);
249 extern void eisa_out8(unsigned char data, unsigned short port);
250 extern void eisa_out16(unsigned short data, unsigned short port);
251 extern void eisa_out32(unsigned int data, unsigned short port);
253 #if defined(CONFIG_PCI)
254 extern unsigned char inb(int addr);
255 extern unsigned short inw(int addr);
256 extern unsigned int inl(int addr);
258 extern void outb(unsigned char b, int addr);
259 extern void outw(unsigned short b, int addr);
260 extern void outl(unsigned int b, int addr);
261 #elif defined(CONFIG_EISA)
263 #define inw eisa_in16
264 #define inl eisa_in32
265 #define outb eisa_out8
266 #define outw eisa_out16
267 #define outl eisa_out32
269 static inline char inb(unsigned long addr)
275 static inline short inw(unsigned long addr)
281 static inline int inl(unsigned long addr)
287 #define outb(x, y) BUG()
288 #define outw(x, y) BUG()
289 #define outl(x, y) BUG()
293 * String versions of in/out ops:
295 extern void insb (unsigned long port, void *dst, unsigned long count);
296 extern void insw (unsigned long port, void *dst, unsigned long count);
297 extern void insl (unsigned long port, void *dst, unsigned long count);
298 extern void outsb (unsigned long port, const void *src, unsigned long count);
299 extern void outsw (unsigned long port, const void *src, unsigned long count);
300 extern void outsl (unsigned long port, const void *src, unsigned long count);
303 /* IO Port space is : BBiiii where BB is HBA number. */
304 #define IO_SPACE_LIMIT 0x00ffffff
306 /* PA machines have an MM I/O space from 0xf0000000-0xffffffff in 32
307 * bit mode and from 0xfffffffff0000000-0xfffffffffffffff in 64 bit
308 * mode (essentially just sign extending. This macro takes in a 32
309 * bit I/O address (still with the leading f) and outputs the correct
310 * value for either 32 or 64 bit mode */
311 #define F_EXTEND(x) ((unsigned long)((x) | (0xffffffff00000000ULL)))
313 #include <asm-generic/iomap.h>
316 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
319 #define xlate_dev_mem_ptr(p) __va(p)
322 * Convert a virtual cached pointer to an uncached pointer
324 #define xlate_dev_kmem_ptr(p) p