xref: /linux/arch/microblaze/include/asm/io.h (revision 2ddafeab6f159640299d17fb9b73b57f65011d85)
1 /*
2  * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3  * Copyright (C) 2007-2009 PetaLogix
4  * Copyright (C) 2006 Atmark Techno, Inc.
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License. See the file "COPYING" in the main directory of this archive
8  * for more details.
9  */
10 
11 #ifndef _ASM_MICROBLAZE_IO_H
12 #define _ASM_MICROBLAZE_IO_H
13 
14 #include <asm/byteorder.h>
15 #include <asm/page.h>
16 #include <linux/types.h>
17 #include <linux/mm.h>          /* Get struct page {...} */
18 #include <asm-generic/iomap.h>
19 
20 #define PCI_DRAM_OFFSET 0
21 
22 #define IO_SPACE_LIMIT (0xFFFFFFFF)
23 
24 static inline unsigned char __raw_readb(const volatile void __iomem *addr)
25 {
26 	return *(volatile unsigned char __force *)addr;
27 }
28 static inline unsigned short __raw_readw(const volatile void __iomem *addr)
29 {
30 	return *(volatile unsigned short __force *)addr;
31 }
32 static inline unsigned int __raw_readl(const volatile void __iomem *addr)
33 {
34 	return *(volatile unsigned int __force *)addr;
35 }
36 static inline unsigned long __raw_readq(const volatile void __iomem *addr)
37 {
38 	return *(volatile unsigned long __force *)addr;
39 }
40 static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
41 {
42 	*(volatile unsigned char __force *)addr = v;
43 }
44 static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
45 {
46 	*(volatile unsigned short __force *)addr = v;
47 }
48 static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
49 {
50 	*(volatile unsigned int __force *)addr = v;
51 }
52 static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
53 {
54 	*(volatile unsigned long __force *)addr = v;
55 }
56 
57 /*
58  * read (readb, readw, readl, readq) and write (writeb, writew,
59  * writel, writeq) accessors are for PCI and thus littel endian.
60  * Linux 2.4 for Microblaze had this wrong.
61  */
62 static inline unsigned char readb(const volatile void __iomem *addr)
63 {
64 	return *(volatile unsigned char __force *)addr;
65 }
66 static inline unsigned short readw(const volatile void __iomem *addr)
67 {
68 	return le16_to_cpu(*(volatile unsigned short __force *)addr);
69 }
70 static inline unsigned int readl(const volatile void __iomem *addr)
71 {
72 	return le32_to_cpu(*(volatile unsigned int __force *)addr);
73 }
74 static inline void writeb(unsigned char v, volatile void __iomem *addr)
75 {
76 	*(volatile unsigned char __force *)addr = v;
77 }
78 static inline void writew(unsigned short v, volatile void __iomem *addr)
79 {
80 	*(volatile unsigned short __force *)addr = cpu_to_le16(v);
81 }
82 static inline void writel(unsigned int v, volatile void __iomem *addr)
83 {
84 	*(volatile unsigned int __force *)addr = cpu_to_le32(v);
85 }
86 
87 /* ioread and iowrite variants. thease are for now same as __raw_
88  * variants of accessors. we might check for endianess in the feature
89  */
90 #define ioread8(addr)		__raw_readb((u8 *)(addr))
91 #define ioread16(addr)		__raw_readw((u16 *)(addr))
92 #define ioread32(addr)		__raw_readl((u32 *)(addr))
93 #define iowrite8(v, addr)	__raw_writeb((u8)(v), (u8 *)(addr))
94 #define iowrite16(v, addr)	__raw_writew((u16)(v), (u16 *)(addr))
95 #define iowrite32(v, addr)	__raw_writel((u32)(v), (u32 *)(addr))
96 
97 /* These are the definitions for the x86 IO instructions
98  * inb/inw/inl/outb/outw/outl, the "string" versions
99  * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
100  * inb_p/inw_p/...
101  * The macros don't do byte-swapping.
102  */
103 #define inb(port)		readb((u8 *)((port)))
104 #define outb(val, port)		writeb((val), (u8 *)((unsigned long)(port)))
105 #define inw(port)		readw((u16 *)((port)))
106 #define outw(val, port)		writew((val), (u16 *)((unsigned long)(port)))
107 #define inl(port)		readl((u32 *)((port)))
108 #define outl(val, port)		writel((val), (u32 *)((unsigned long)(port)))
109 
110 #define inb_p(port)		inb((port))
111 #define outb_p(val, port)	outb((val), (port))
112 #define inw_p(port)		inw((port))
113 #define outw_p(val, port)	outw((val), (port))
114 #define inl_p(port)		inl((port))
115 #define outl_p(val, port)	outl((val), (port))
116 
117 #define memset_io(a, b, c)	memset((void *)(a), (b), (c))
118 #define memcpy_fromio(a, b, c)	memcpy((a), (void *)(b), (c))
119 #define memcpy_toio(a, b, c)	memcpy((void *)(a), (b), (c))
120 
121 #ifdef CONFIG_MMU
122 
123 #define mm_ptov(addr)		((void *)__phys_to_virt(addr))
124 #define mm_vtop(addr)		((unsigned long)__virt_to_phys(addr))
125 #define phys_to_virt(addr)	((void *)__phys_to_virt(addr))
126 #define virt_to_phys(addr)	((unsigned long)__virt_to_phys(addr))
127 #define virt_to_bus(addr)	((unsigned long)__virt_to_phys(addr))
128 
129 #define __page_address(page) \
130 		(PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
131 #define page_to_phys(page)	virt_to_phys((void *)__page_address(page))
132 #define page_to_bus(page)	(page_to_phys(page))
133 #define bus_to_virt(addr)	(phys_to_virt(addr))
134 
135 extern void iounmap(void *addr);
136 /*extern void *__ioremap(phys_addr_t address, unsigned long size,
137 		unsigned long flags);*/
138 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
139 #define ioremap_writethrough(addr, size) ioremap((addr), (size))
140 #define ioremap_nocache(addr, size)      ioremap((addr), (size))
141 #define ioremap_fullcache(addr, size)    ioremap((addr), (size))
142 
143 #else /* CONFIG_MMU */
144 
145 /**
146  *	virt_to_phys - map virtual addresses to physical
147  *	@address: address to remap
148  *
149  *	The returned physical address is the physical (CPU) mapping for
150  *	the memory address given. It is only valid to use this function on
151  *	addresses directly mapped or allocated via kmalloc.
152  *
153  *	This function does not give bus mappings for DMA transfers. In
154  *	almost all conceivable cases a device driver should not be using
155  *	this function
156  */
157 static inline unsigned long __iomem virt_to_phys(volatile void *address)
158 {
159 	return __pa((unsigned long)address);
160 }
161 
162 #define virt_to_bus virt_to_phys
163 
164 /**
165  *	phys_to_virt - map physical address to virtual
166  *	@address: address to remap
167  *
168  *	The returned virtual address is a current CPU mapping for
169  *	the memory address given. It is only valid to use this function on
170  *	addresses that have a kernel mapping
171  *
172  *	This function does not handle bus mappings for DMA transfers. In
173  *	almost all conceivable cases a device driver should not be using
174  *	this function
175  */
176 static inline void *phys_to_virt(unsigned long address)
177 {
178 	return (void *)__va(address);
179 }
180 
181 #define bus_to_virt(a) phys_to_virt(a)
182 
183 static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
184 			unsigned long flags)
185 {
186 	return (void *)address;
187 }
188 
189 #define ioremap(physaddr, size)	((void __iomem *)(unsigned long)(physaddr))
190 #define iounmap(addr)		((void)0)
191 #define ioremap_nocache(physaddr, size)	ioremap(physaddr, size)
192 
193 #endif /* CONFIG_MMU */
194 
195 /*
196  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
197  * access
198  */
199 #define xlate_dev_mem_ptr(p)	__va(p)
200 
201 /*
202  * Convert a virtual cached pointer to an uncached pointer
203  */
204 #define xlate_dev_kmem_ptr(p)	p
205 
206 /*
207  * Big Endian
208  */
209 #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
210 #define out_be16(a, v) __raw_writew((v), (a))
211 
212 #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
213 #define in_be16(a) __raw_readw(a)
214 
215 #define writel_be(v, a)	out_be32((__force unsigned *)a, v)
216 #define readl_be(a)	in_be32((__force unsigned *)a)
217 
218 /*
219  * Little endian
220  */
221 
222 #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
223 #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
224 
225 #define in_le32(a) __le32_to_cpu(__raw_readl(a))
226 #define in_le16(a) __le16_to_cpu(__raw_readw(a))
227 
228 /* Byte ops */
229 #define out_8(a, v) __raw_writeb((v), (a))
230 #define in_8(a) __raw_readb(a)
231 
232 #define ioport_map(port, nr)	((void __iomem *)(port))
233 #define ioport_unmap(addr)
234 
235 #endif /* _ASM_MICROBLAZE_IO_H */
236