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