1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * IO definitions for the Hexagon architecture
5 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
13 #include <linux/types.h>
14 #include <asm/iomap.h>
16 #include <asm/cacheflush.h>
19 * We don't have PCI yet.
20 * _IO_BASE is pointing at what should be unused virtual space.
22 #define IO_SPACE_LIMIT 0xffff
23 #define _IO_BASE ((void __iomem *)0xfe000000)
25 #define IOMEM(x) ((void __force __iomem *)(x))
27 extern int remap_area_pages(unsigned long start, unsigned long phys_addr,
28 unsigned long end, unsigned long flags);
30 /* Defined in lib/io.c, needed for smc91x driver. */
31 extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen);
32 extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen);
34 extern void __raw_readsl(const void __iomem *addr, void *data, int wordlen);
35 extern void __raw_writesl(void __iomem *addr, const void *data, int wordlen);
37 #define readsw(p, d, l) __raw_readsw(p, d, l)
38 #define writesw(p, d, l) __raw_writesw(p, d, l)
40 #define readsl(p, d, l) __raw_readsl(p, d, l)
41 #define writesl(p, d, l) __raw_writesl(p, d, l)
44 * virt_to_phys - map virtual address to physical
45 * @address: address to map
47 static inline unsigned long virt_to_phys(volatile void *address)
53 * phys_to_virt - map physical address to virtual
54 * @address: address to map
56 static inline void *phys_to_virt(unsigned long address)
62 * IO port access primitives. Hexagon doesn't have special IO access
63 * instructions; all I/O is memory mapped.
65 * in/out are used for "ports", but we don't have "port instructions",
66 * so these are really just memory mapped too.
70 * readb - read byte from memory mapped device
71 * @addr: pointer to memory
73 * Operates on "I/O bus memory space"
75 static inline u8 readb(const volatile void __iomem *addr)
86 static inline u16 readw(const volatile void __iomem *addr)
97 static inline u32 readl(const volatile void __iomem *addr)
109 * writeb - write a byte to a memory location
110 * @data: data to write to
111 * @addr: pointer to memory
114 static inline void writeb(u8 data, volatile void __iomem *addr)
119 : "r" (addr), "r" (data)
124 static inline void writew(u16 data, volatile void __iomem *addr)
129 : "r" (addr), "r" (data)
135 static inline void writel(u32 data, volatile void __iomem *addr)
140 : "r" (addr), "r" (data)
145 #define __raw_writeb writeb
146 #define __raw_writew writew
147 #define __raw_writel writel
149 #define __raw_readb readb
150 #define __raw_readw readw
151 #define __raw_readl readl
154 * http://comments.gmane.org/gmane.linux.ports.arm.kernel/117626
157 #define readb_relaxed __raw_readb
158 #define readw_relaxed __raw_readw
159 #define readl_relaxed __raw_readl
161 #define writeb_relaxed __raw_writeb
162 #define writew_relaxed __raw_writew
163 #define writel_relaxed __raw_writel
166 * I/O memory mapping functions.
168 #define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
169 (__HEXAGON_C_DEV << 6))
171 #define __raw_writel writel
173 static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
176 memcpy(dst, (void *) src, count);
179 static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
182 memcpy((void *) dst, src, count);
185 static inline void memset_io(volatile void __iomem *addr, int value,
188 memset((void __force *)addr, value, size);
191 #define PCI_IO_ADDR (volatile void __iomem *)
194 * inb - read byte from I/O port or something
195 * @port: address in I/O space
197 * Operates on "I/O bus I/O space"
199 static inline u8 inb(unsigned long port)
201 return readb(_IO_BASE + (port & IO_SPACE_LIMIT));
204 static inline u16 inw(unsigned long port)
206 return readw(_IO_BASE + (port & IO_SPACE_LIMIT));
209 static inline u32 inl(unsigned long port)
211 return readl(_IO_BASE + (port & IO_SPACE_LIMIT));
215 * outb - write a byte to a memory location
216 * @data: data to write to
217 * @addr: address in I/O space
219 static inline void outb(u8 data, unsigned long port)
221 writeb(data, _IO_BASE + (port & IO_SPACE_LIMIT));
224 static inline void outw(u16 data, unsigned long port)
226 writew(data, _IO_BASE + (port & IO_SPACE_LIMIT));
229 static inline void outl(u32 data, unsigned long port)
231 writel(data, _IO_BASE + (port & IO_SPACE_LIMIT));
242 static inline void insb(unsigned long port, void *buffer, int count)
253 static inline void insw(unsigned long port, void *buffer, int count)
264 static inline void insl(unsigned long port, void *buffer, int count)
275 static inline void outsb(unsigned long port, const void *buffer, int count)
278 const u8 *buf = buffer;
285 static inline void outsw(unsigned long port, const void *buffer, int count)
288 const u16 *buf = buffer;
295 static inline void outsl(unsigned long port, const void *buffer, int count)
298 const u32 *buf = buffer;
306 * These defines are necessary to use the generic io.h for filling in
307 * the missing parts of the API contract. This is because the platform
308 * uses (inline) functions rather than defines and the generic helper
309 * fills in the undefined.
311 #define virt_to_phys virt_to_phys
312 #define phys_to_virt phys_to_virt
313 #define memset_io memset_io
314 #define memcpy_fromio memcpy_fromio
315 #define memcpy_toio memcpy_toio
319 #define writeb writeb
320 #define writew writew
321 #define writel writel
328 #include <asm-generic/io.h>
330 #endif /* __KERNEL__ */