blob: a93c8cde4d382fc171798affe7090cc59a60f46d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _M68KNOMMU_IO_H
2#define _M68KNOMMU_IO_H
3
4#ifdef __KERNEL__
5
Greg Ungerer682137f2010-01-13 10:42:05 +10006#include <asm/virtconvert.h>
Greg Ungererf79b8592013-08-02 17:24:38 +10007#include <asm-generic/iomap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9/*
10 * These are for ISA/PCI shared memory _only_ and should never be used
11 * on any other type of memory, including Zorro memory. They are meant to
12 * access the bus in the bus byte order which is little-endian!.
13 *
14 * readX/writeX() are used to access memory mapped devices. On some
15 * architectures the memory mapped IO stuff needs to be accessed
16 * differently. On the m68k architecture, we just read/write the
17 * memory location directly.
18 */
19/* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
Daniel Mack3ad2f3f2010-02-03 08:01:28 +080020 * two accesses to memory, which may be undesirable for some devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
23/*
24 * swap functions are sometimes needed to interface little-endian hardware
25 */
26static inline unsigned short _swapw(volatile unsigned short v)
27{
28 return ((v << 8) | (v >> 8));
29}
30
31static inline unsigned int _swapl(volatile unsigned long v)
32{
33 return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
34}
35
36#define readb(addr) \
37 ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
38#define readw(addr) \
39 ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
40#define readl(addr) \
41 ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b))
44#define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b))
45#define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b))
46
47#define __raw_readb readb
48#define __raw_readw readw
49#define __raw_readl readl
50#define __raw_writeb writeb
51#define __raw_writew writew
52#define __raw_writel writel
53
Greg Ungerer4dc5aa22014-01-20 17:41:52 +100054static inline void io_outsb(unsigned int addr, const void *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 volatile unsigned char *ap = (volatile unsigned char *) addr;
57 unsigned char *bp = (unsigned char *) buf;
58 while (len--)
59 *ap = *bp++;
60}
61
Greg Ungerer4dc5aa22014-01-20 17:41:52 +100062static inline void io_outsw(unsigned int addr, const void *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 volatile unsigned short *ap = (volatile unsigned short *) addr;
65 unsigned short *bp = (unsigned short *) buf;
66 while (len--)
67 *ap = _swapw(*bp++);
68}
69
Greg Ungerer4dc5aa22014-01-20 17:41:52 +100070static inline void io_outsl(unsigned int addr, const void *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 volatile unsigned int *ap = (volatile unsigned int *) addr;
73 unsigned int *bp = (unsigned int *) buf;
74 while (len--)
75 *ap = _swapl(*bp++);
76}
77
78static inline void io_insb(unsigned int addr, void *buf, int len)
79{
80 volatile unsigned char *ap = (volatile unsigned char *) addr;
81 unsigned char *bp = (unsigned char *) buf;
82 while (len--)
83 *bp++ = *ap;
84}
85
86static inline void io_insw(unsigned int addr, void *buf, int len)
87{
88 volatile unsigned short *ap = (volatile unsigned short *) addr;
89 unsigned short *bp = (unsigned short *) buf;
90 while (len--)
91 *bp++ = _swapw(*ap);
92}
93
94static inline void io_insl(unsigned int addr, void *buf, int len)
95{
96 volatile unsigned int *ap = (volatile unsigned int *) addr;
97 unsigned int *bp = (unsigned int *) buf;
98 while (len--)
99 *bp++ = _swapl(*ap);
100}
101
102#define mmiowb()
103
104/*
105 * make the short names macros so specific devices
106 * can override them as required
107 */
108
109#define memset_io(a,b,c) memset((void *)(a),(b),(c))
110#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
111#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
112
113#define inb(addr) readb(addr)
114#define inw(addr) readw(addr)
115#define inl(addr) readl(addr)
116#define outb(x,addr) ((void) writeb(x,addr))
117#define outw(x,addr) ((void) writew(x,addr))
118#define outl(x,addr) ((void) writel(x,addr))
119
120#define inb_p(addr) inb(addr)
121#define inw_p(addr) inw(addr)
122#define inl_p(addr) inl(addr)
123#define outb_p(x,addr) outb(x,addr)
124#define outw_p(x,addr) outw(x,addr)
125#define outl_p(x,addr) outl(x,addr)
126
127#define outsb(a,b,l) io_outsb(a,b,l)
128#define outsw(a,b,l) io_outsw(a,b,l)
129#define outsl(a,b,l) io_outsl(a,b,l)
130
131#define insb(a,b,l) io_insb(a,b,l)
132#define insw(a,b,l) io_insw(a,b,l)
133#define insl(a,b,l) io_insl(a,b,l)
134
Greg Ungererfe84c102009-08-11 16:33:51 +1000135#define IO_SPACE_LIMIT 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137
138/* Values for nocacheflag and cmode */
139#define IOMAP_FULL_CACHING 0
140#define IOMAP_NOCACHE_SER 1
141#define IOMAP_NOCACHE_NONSER 2
142#define IOMAP_WRITETHROUGH 3
143
Greg Ungerer593732b2011-03-28 22:32:05 +1000144static inline void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag)
145{
146 return (void *) physaddr;
147}
Greg Ungererc514b8b2005-11-02 14:42:03 +1000148static inline void *ioremap(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
151}
Greg Ungererc514b8b2005-11-02 14:42:03 +1000152static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
155}
Greg Ungererc514b8b2005-11-02 14:42:03 +1000156static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
159}
Greg Ungererc514b8b2005-11-02 14:42:03 +1000160static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
163}
164
Greg Ungerer593732b2011-03-28 22:32:05 +1000165#define iounmap(addr) do { } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/*
168 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
169 * access
170 */
171#define xlate_dev_mem_ptr(p) __va(p)
172
173/*
174 * Convert a virtual cached pointer to an uncached pointer
175 */
176#define xlate_dev_kmem_ptr(p) p
177
Greg Ungererf89487a2014-09-18 15:16:01 +1000178static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
179{
180 return (void __iomem *) port;
181}
182
183static inline void ioport_unmap(void __iomem *p)
184{
185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif /* __KERNEL__ */
188
189#endif /* _M68KNOMMU_IO_H */