• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_M32R_IO_H
3 #define _ASM_M32R_IO_H
4 
5 #include <linux/string.h>
6 #include <linux/compiler.h>
7 #include <asm/page.h>  /* __va */
8 
9 #ifdef __KERNEL__
10 
11 #define IO_SPACE_LIMIT  0xFFFFFFFF
12 
13 /**
14  *	virt_to_phys	-	map virtual addresses to physical
15  *	@address: address to remap
16  *
17  *	The returned physical address is the physical (CPU) mapping for
18  *	the memory address given. It is only valid to use this function on
19  *	addresses directly mapped or allocated via kmalloc.
20  *
21  *	This function does not give bus mappings for DMA transfers. In
22  *	almost all conceivable cases a device driver should not be using
23  *	this function
24  */
25 
virt_to_phys(volatile void * address)26 static inline unsigned long virt_to_phys(volatile void * address)
27 {
28 	return __pa(address);
29 }
30 
31 /**
32  *	phys_to_virt	-	map physical address to virtual
33  *	@address: address to remap
34  *
35  *	The returned virtual address is a current CPU mapping for
36  *	the memory address given. It is only valid to use this function on
37  *	addresses that have a kernel mapping
38  *
39  *	This function does not handle bus mappings for DMA transfers. In
40  *	almost all conceivable cases a device driver should not be using
41  *	this function
42  */
43 
phys_to_virt(unsigned long address)44 static inline void *phys_to_virt(unsigned long address)
45 {
46 	return __va(address);
47 }
48 
49 extern void __iomem *
50 __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
51 
52 /**
53  *	ioremap		-	map bus memory into CPU space
54  *	@offset:	bus address of the memory
55  *	@size:		size of the resource to map
56  *
57  *	ioremap performs a platform specific sequence of operations to
58  *	make bus memory CPU accessible via the readb/readw/readl/writeb/
59  *	writew/writel functions and the other mmio helpers. The returned
60  *	address is not guaranteed to be usable directly as a virtual
61  *	address.
62  */
63 
ioremap(unsigned long offset,unsigned long size)64 static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
65 {
66 	return __ioremap(offset, size, 0);
67 }
68 
69 extern void iounmap(volatile void __iomem *addr);
70 #define ioremap_nocache(off,size) ioremap(off,size)
71 #define ioremap_wc ioremap_nocache
72 #define ioremap_wt ioremap_nocache
73 #define ioremap_uc ioremap_nocache
74 
75 /*
76  * IO bus memory addresses are also 1:1 with the physical address
77  */
78 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
79 #define page_to_bus	page_to_phys
80 #define virt_to_bus	virt_to_phys
81 
82 extern unsigned char _inb(unsigned long);
83 extern unsigned short _inw(unsigned long);
84 extern unsigned long _inl(unsigned long);
85 extern unsigned char _inb_p(unsigned long);
86 extern unsigned short _inw_p(unsigned long);
87 extern unsigned long _inl_p(unsigned long);
88 extern void _outb(unsigned char, unsigned long);
89 extern void _outw(unsigned short, unsigned long);
90 extern void _outl(unsigned long, unsigned long);
91 extern void _outb_p(unsigned char, unsigned long);
92 extern void _outw_p(unsigned short, unsigned long);
93 extern void _outl_p(unsigned long, unsigned long);
94 extern void _insb(unsigned int, void *, unsigned long);
95 extern void _insw(unsigned int, void *, unsigned long);
96 extern void _insl(unsigned int, void *, unsigned long);
97 extern void _outsb(unsigned int, const void *, unsigned long);
98 extern void _outsw(unsigned int, const void *, unsigned long);
99 extern void _outsl(unsigned int, const void *, unsigned long);
100 
_readb(unsigned long addr)101 static inline unsigned char _readb(unsigned long addr)
102 {
103 	return *(volatile unsigned char __force *)addr;
104 }
105 
_readw(unsigned long addr)106 static inline unsigned short _readw(unsigned long addr)
107 {
108 	return *(volatile unsigned short __force *)addr;
109 }
110 
_readl(unsigned long addr)111 static inline unsigned long _readl(unsigned long addr)
112 {
113 	return *(volatile unsigned long __force *)addr;
114 }
115 
_writeb(unsigned char b,unsigned long addr)116 static inline void _writeb(unsigned char b, unsigned long addr)
117 {
118 	*(volatile unsigned char __force *)addr = b;
119 }
120 
_writew(unsigned short w,unsigned long addr)121 static inline void _writew(unsigned short w, unsigned long addr)
122 {
123 	*(volatile unsigned short __force *)addr = w;
124 }
125 
_writel(unsigned long l,unsigned long addr)126 static inline void _writel(unsigned long l, unsigned long addr)
127 {
128 	*(volatile unsigned long __force *)addr = l;
129 }
130 
131 #define inb     _inb
132 #define inw     _inw
133 #define inl     _inl
134 #define outb    _outb
135 #define outw    _outw
136 #define outl    _outl
137 
138 #define inb_p   _inb_p
139 #define inw_p   _inw_p
140 #define inl_p   _inl_p
141 #define outb_p  _outb_p
142 #define outw_p  _outw_p
143 #define outl_p  _outl_p
144 
145 #define insb    _insb
146 #define insw    _insw
147 #define insl    _insl
148 #define outsb   _outsb
149 #define outsw   _outsw
150 #define outsl   _outsl
151 
152 #define readb(addr)   _readb((unsigned long)(addr))
153 #define readw(addr)   _readw((unsigned long)(addr))
154 #define readl(addr)   _readl((unsigned long)(addr))
155 #define __raw_readb readb
156 #define __raw_readw readw
157 #define __raw_readl readl
158 #define readb_relaxed readb
159 #define readw_relaxed readw
160 #define readl_relaxed readl
161 
162 #define writeb(val, addr)  _writeb((val), (unsigned long)(addr))
163 #define writew(val, addr)  _writew((val), (unsigned long)(addr))
164 #define writel(val, addr)  _writel((val), (unsigned long)(addr))
165 #define __raw_writeb writeb
166 #define __raw_writew writew
167 #define __raw_writel writel
168 #define writeb_relaxed writeb
169 #define writew_relaxed writew
170 #define writel_relaxed writel
171 
172 #define ioread8 readb
173 #define ioread16 readw
174 #define ioread32 readl
175 #define iowrite8 writeb
176 #define iowrite16 writew
177 #define iowrite32 writel
178 
179 #define ioread8_rep(p, dst, count) insb((unsigned long)(p), (dst), (count))
180 #define ioread16_rep(p, dst, count) insw((unsigned long)(p), (dst), (count))
181 #define ioread32_rep(p, dst, count) insl((unsigned long)(p), (dst), (count))
182 
183 #define iowrite8_rep(p, src, count) outsb((unsigned long)(p), (src), (count))
184 #define iowrite16_rep(p, src, count) outsw((unsigned long)(p), (src), (count))
185 #define iowrite32_rep(p, src, count) outsl((unsigned long)(p), (src), (count))
186 
187 #define ioread16be(addr)	be16_to_cpu(readw(addr))
188 #define ioread32be(addr)	be32_to_cpu(readl(addr))
189 #define iowrite16be(v, addr)	writew(cpu_to_be16(v), (addr))
190 #define iowrite32be(v, addr)	writel(cpu_to_be32(v), (addr))
191 
192 #define mmiowb()
193 
194 #define flush_write_buffers() do { } while (0)  /* M32R_FIXME */
195 
196 static inline void
memset_io(volatile void __iomem * addr,unsigned char val,int count)197 memset_io(volatile void __iomem *addr, unsigned char val, int count)
198 {
199 	memset((void __force *) addr, val, count);
200 }
201 
202 static inline void
memcpy_fromio(void * dst,volatile void __iomem * src,int count)203 memcpy_fromio(void *dst, volatile void __iomem *src, int count)
204 {
205 	memcpy(dst, (void __force *) src, count);
206 }
207 
208 static inline void
memcpy_toio(volatile void __iomem * dst,const void * src,int count)209 memcpy_toio(volatile void __iomem *dst, const void *src, int count)
210 {
211 	memcpy((void __force *) dst, src, count);
212 }
213 
214 /*
215  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
216  * access
217  */
218 #define xlate_dev_mem_ptr(p)	__va(p)
219 
220 /*
221  * Convert a virtual cached pointer to an uncached pointer
222  */
223 #define xlate_dev_kmem_ptr(p)	p
224 
225 #endif  /* __KERNEL__ */
226 
227 #endif  /* _ASM_M32R_IO_H */
228