xref: /openbmc/u-boot/arch/microblaze/include/asm/io.h (revision 35912528)
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 /* Some #definitions to keep strange Xilinx code happy */
54 #define in_8(addr)	readb(addr)
55 #define in_be16(addr)	readw(addr)
56 #define in_be32(addr)	readl(addr)
57 
58 #define out_8(addr, x)		outb(x, addr)
59 #define out_be16(addr, x)	outw(x, addr)
60 #define out_be32(addr, x)	outl(x, addr)
61 
62 #define inb_p(port)		inb((port))
63 #define outb_p(val, port)	outb((val), (port))
64 #define inw_p(port)		inw((port))
65 #define outw_p(val, port)	outw((val), (port))
66 #define inl_p(port)		inl((port))
67 #define outl_p(val, port)	outl((val), (port))
68 
69 /* Some defines to keep the MTD flash drivers happy */
70 
71 #define __raw_readb readb
72 #define __raw_readw readw
73 #define __raw_readl readl
74 #define __raw_writeb writeb
75 #define __raw_writew writew
76 #define __raw_writel writel
77 
io_insb(unsigned long port,void * dst,unsigned long count)78 static inline void io_insb(unsigned long port, void *dst, unsigned long count)
79 {
80 	unsigned char *p = dst;
81 
82 	while (count--)
83 		*p++ = inb(port);
84 }
85 
io_insw(unsigned long port,void * dst,unsigned long count)86 static inline void io_insw(unsigned long port, void *dst, unsigned long count)
87 {
88 	unsigned short *p = dst;
89 
90 	while (count--)
91 		*p++ = inw(port);
92 }
93 
io_insl(unsigned long port,void * dst,unsigned long count)94 static inline void io_insl(unsigned long port, void *dst, unsigned long count)
95 {
96 	unsigned long *p = dst;
97 
98 	while (count--)
99 		*p++ = inl(port);
100 }
101 
102 static inline void
io_outsb(unsigned long port,const void * src,unsigned long count)103 io_outsb(unsigned long port, const void *src, unsigned long count)
104 {
105 	const unsigned char *p = src;
106 
107 	while (count--)
108 		outb(*p++, port);
109 }
110 
111 static inline void
io_outsw(unsigned long port,const void * src,unsigned long count)112 io_outsw(unsigned long port, const void *src, unsigned long count)
113 {
114 	const unsigned short *p = src;
115 
116 	while (count--)
117 		outw(*p++, port);
118 }
119 
120 static inline void
io_outsl(unsigned long port,const void * src,unsigned long count)121 io_outsl(unsigned long port, const void *src, unsigned long count)
122 {
123 	const unsigned long *p = src;
124 
125 	while (count--)
126 		outl(*p++, port);
127 }
128 
129 #define outsb(a, b, l) io_outsb(a, b, l)
130 #define outsw(a, b, l) io_outsw(a, b, l)
131 #define outsl(a, b, l) io_outsl(a, b, l)
132 
133 #define insb(a, b, l) io_insb(a, b, l)
134 #define insw(a, b, l) io_insw(a, b, l)
135 #define insl(a, b, l) io_insl(a, b, l)
136 
137 #define ioremap_nocache(physaddr, size)		(physaddr)
138 #define ioremap_writethrough(physaddr, size)	(physaddr)
139 #define ioremap_fullcache(physaddr, size)	(physaddr)
140 
sync(void)141 static inline void sync(void)
142 {
143 }
144 
145 #include <asm-generic/io.h>
146 
147 #endif /* __MICROBLAZE_IO_H__ */
148