1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * include/asm-microblaze/io.h -- Misc I/O operations
4  *
5  *  Copyright (C) 2003     John Williams <jwilliams@itee.uq.edu.au>
6  *  Copyright (C) 2001,02  NEC Corporation
7  *  Copyright (C) 2001,02  Miles Bader <miles@gnu.org>
8  *
9  * This file is subject to the terms and conditions of the GNU General
10  * Public License.  See the file COPYING in the main directory of this
11  * archive for more details.
12  *
13  * Written by Miles Bader <miles@gnu.org>
14  * Microblaze port by John Williams
15  */
16 
17 #ifndef __MICROBLAZE_IO_H__
18 #define __MICROBLAZE_IO_H__
19 
20 #include <asm/types.h>
21 
22 #define IO_SPACE_LIMIT 0xFFFFFFFF
23 
24 #define readb(addr) \
25 	({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
26 
27 #define readw(addr) \
28 	({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
29 
30 #define readl(addr) \
31 	({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
32 
33 #define writeb(b, addr) \
34 	(void)((*(volatile unsigned char *)(addr)) = (b))
35 
36 #define writew(b, addr) \
37 	(void)((*(volatile unsigned short *)(addr)) = (b))
38 
39 #define writel(b, addr) \
40 	(void)((*(volatile unsigned int *)(addr)) = (b))
41 
42 #define memset_io(a, b, c)        memset((void *)(a), (b), (c))
43 #define memcpy_fromio(a, b, c)    memcpy((a), (void *)(b), (c))
44 #define memcpy_toio(a, b, c)      memcpy((void *)(a), (b), (c))
45 
46 #define inb(addr)	readb(addr)
47 #define inw(addr)	readw(addr)
48 #define inl(addr)	readl(addr)
49 #define outb(x, addr)	((void)writeb(x, addr))
50 #define outw(x, addr)	((void)writew(x, addr))
51 #define outl(x, addr)	((void)writel(x, addr))
52 
53 #define out_arch(type, endian, addr, x)	\
54 		 __raw_write##type(cpu_to_##endian(x), addr)
55 #define in_arch(type, endian, addr)	\
56 		endian##_to_cpu(__raw_read##type(addr))
57 
58 #define out_le16(addr, x)	out_arch(w, le16, addr, x)
59 #define out_le32(addr, x)	out_arch(l, le32, addr, x)
60 
61 #define in_le16(addr)		in_arch(w, le16, addr)
62 #define in_le32(addr)		in_arch(l, le32, addr)
63 
64 #define in_8(addr)		readb(addr)
65 #define in_be16(addr)		in_arch(w, be16, addr)
66 #define in_be32(addr)		in_arch(l, be32, addr)
67 
68 #define out_8(addr, x)		outb(x, addr)
69 #define out_be16(addr, x)	out_arch(w, be16, addr, x)
70 #define out_be32(addr, x)	out_arch(l, be32, addr, x)
71 
72 #define inb_p(port)		inb((port))
73 #define outb_p(val, port)	outb((val), (port))
74 #define inw_p(port)		inw((port))
75 #define outw_p(val, port)	outw((val), (port))
76 #define inl_p(port)		inl((port))
77 #define outl_p(val, port)	outl((val), (port))
78 
79 /* Some defines to keep the MTD flash drivers happy */
80 
81 #define __raw_readb readb
82 #define __raw_readw readw
83 #define __raw_readl readl
84 #define __raw_writeb writeb
85 #define __raw_writew writew
86 #define __raw_writel writel
87 
io_insb(unsigned long port,void * dst,unsigned long count)88 static inline void io_insb(unsigned long port, void *dst, unsigned long count)
89 {
90 	unsigned char *p = dst;
91 
92 	while (count--)
93 		*p++ = inb(port);
94 }
95 
io_insw(unsigned long port,void * dst,unsigned long count)96 static inline void io_insw(unsigned long port, void *dst, unsigned long count)
97 {
98 	unsigned short *p = dst;
99 
100 	while (count--)
101 		*p++ = inw(port);
102 }
103 
io_insl(unsigned long port,void * dst,unsigned long count)104 static inline void io_insl(unsigned long port, void *dst, unsigned long count)
105 {
106 	unsigned long *p = dst;
107 
108 	while (count--)
109 		*p++ = inl(port);
110 }
111 
112 static inline void
io_outsb(unsigned long port,const void * src,unsigned long count)113 io_outsb(unsigned long port, const void *src, unsigned long count)
114 {
115 	const unsigned char *p = src;
116 
117 	while (count--)
118 		outb(*p++, port);
119 }
120 
121 static inline void
io_outsw(unsigned long port,const void * src,unsigned long count)122 io_outsw(unsigned long port, const void *src, unsigned long count)
123 {
124 	const unsigned short *p = src;
125 
126 	while (count--)
127 		outw(*p++, port);
128 }
129 
130 static inline void
io_outsl(unsigned long port,const void * src,unsigned long count)131 io_outsl(unsigned long port, const void *src, unsigned long count)
132 {
133 	const unsigned long *p = src;
134 
135 	while (count--)
136 		outl(*p++, port);
137 }
138 
139 #define outsb(a, b, l) io_outsb(a, b, l)
140 #define outsw(a, b, l) io_outsw(a, b, l)
141 #define outsl(a, b, l) io_outsl(a, b, l)
142 
143 #define insb(a, b, l) io_insb(a, b, l)
144 #define insw(a, b, l) io_insw(a, b, l)
145 #define insl(a, b, l) io_insl(a, b, l)
146 
147 #define ioremap_nocache(physaddr, size)		(physaddr)
148 #define ioremap_writethrough(physaddr, size)	(physaddr)
149 #define ioremap_fullcache(physaddr, size)	(physaddr)
150 
sync(void)151 static inline void sync(void)
152 {
153 }
154 
155 #include <asm-generic/io.h>
156 
157 #endif /* __MICROBLAZE_IO_H__ */
158