Merge branch '3.4-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target...
[linux-flexiantxendom0-3.2.10.git] / arch / xtensa / include / asm / io.h
1 /*
2  * include/asm-xtensa/io.h
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2001 - 2005 Tensilica Inc.
9  */
10
11 #ifndef _XTENSA_IO_H
12 #define _XTENSA_IO_H
13
14 #ifdef __KERNEL__
15 #include <asm/byteorder.h>
16 #include <asm/page.h>
17 #include <linux/bug.h>
18 #include <linux/kernel.h>
19
20 #include <linux/types.h>
21
22 #define XCHAL_KIO_CACHED_VADDR  0xe0000000
23 #define XCHAL_KIO_BYPASS_VADDR  0xf0000000
24 #define XCHAL_KIO_PADDR         0xf0000000
25 #define XCHAL_KIO_SIZE          0x10000000
26
27 #define IOADDR(x)               (XCHAL_KIO_BYPASS_VADDR + (x))
28
29 /*
30  * swap functions to change byte order from little-endian to big-endian and
31  * vice versa.
32  */
33
34 static inline unsigned short _swapw (unsigned short v)
35 {
36         return (v << 8) | (v >> 8);
37 }
38
39 static inline unsigned int _swapl (unsigned int v)
40 {
41         return (v << 24) | ((v & 0xff00) << 8) | ((v >> 8) & 0xff00) | (v >> 24);
42 }
43
44 /*
45  * Change virtual addresses to physical addresses and vv.
46  * These are trivial on the 1:1 Linux/Xtensa mapping
47  */
48
49 static inline unsigned long virt_to_phys(volatile void * address)
50 {
51         return __pa(address);
52 }
53
54 static inline void * phys_to_virt(unsigned long address)
55 {
56         return __va(address);
57 }
58
59 /*
60  * virt_to_bus and bus_to_virt are deprecated.
61  */
62
63 #define virt_to_bus(x)  virt_to_phys(x)
64 #define bus_to_virt(x)  phys_to_virt(x)
65
66 /*
67  * Return the virtual (cached) address for the specified bus memory.
68  * Note that we currently don't support any address outside the KIO segment.
69  */
70
71 static inline void *ioremap(unsigned long offset, unsigned long size)
72 {
73 #ifdef CONFIG_MMU
74         if (offset >= XCHAL_KIO_PADDR
75             && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
76                 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR);
77         else
78                 BUG();
79 #else
80         return (void *)offset;
81 #endif
82 }
83
84 static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
85 {
86 #ifdef CONFIG_MMU
87         if (offset >= XCHAL_KIO_PADDR
88             && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
89                 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR);
90         else
91                 BUG();
92 #else
93         return (void *)offset;
94 #endif
95 }
96
97 static inline void iounmap(void *addr)
98 {
99 }
100
101 /*
102  * Generic I/O
103  */
104
105 #define readb(addr) \
106         ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
107 #define readw(addr) \
108         ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
109 #define readl(addr) \
110         ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
111 #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b))
112 #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b))
113 #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b))
114
115 static inline __u8 __raw_readb(const volatile void __iomem *addr)
116 {
117           return *(__force volatile __u8 *)(addr);
118 }
119 static inline __u16 __raw_readw(const volatile void __iomem *addr)
120 {
121           return *(__force volatile __u16 *)(addr);
122 }
123 static inline __u32 __raw_readl(const volatile void __iomem *addr)
124 {
125           return *(__force volatile __u32 *)(addr);
126 }
127 static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
128 {
129           *(__force volatile __u8 *)(addr) = b;
130 }
131 static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
132 {
133           *(__force volatile __u16 *)(addr) = b;
134 }
135 static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
136 {
137           *(__force volatile __u32 *)(addr) = b;
138 }
139
140 /* These are the definitions for the x86 IO instructions
141  * inb/inw/inl/outb/outw/outl, the "string" versions
142  * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
143  * inb_p/inw_p/...
144  * The macros don't do byte-swapping.
145  */
146
147 #define inb(port)               readb((u8 *)((port)))
148 #define outb(val, port)         writeb((val),(u8 *)((unsigned long)(port)))
149 #define inw(port)               readw((u16 *)((port)))
150 #define outw(val, port)         writew((val),(u16 *)((unsigned long)(port)))
151 #define inl(port)               readl((u32 *)((port)))
152 #define outl(val, port)         writel((val),(u32 *)((unsigned long)(port)))
153
154 #define inb_p(port)             inb((port))
155 #define outb_p(val, port)       outb((val), (port))
156 #define inw_p(port)             inw((port))
157 #define outw_p(val, port)       outw((val), (port))
158 #define inl_p(port)             inl((port))
159 #define outl_p(val, port)       outl((val), (port))
160
161 extern void insb (unsigned long port, void *dst, unsigned long count);
162 extern void insw (unsigned long port, void *dst, unsigned long count);
163 extern void insl (unsigned long port, void *dst, unsigned long count);
164 extern void outsb (unsigned long port, const void *src, unsigned long count);
165 extern void outsw (unsigned long port, const void *src, unsigned long count);
166 extern void outsl (unsigned long port, const void *src, unsigned long count);
167
168 #define IO_SPACE_LIMIT ~0
169
170 #define memset_io(a,b,c)       memset((void *)(a),(b),(c))
171 #define memcpy_fromio(a,b,c)   memcpy((a),(void *)(b),(c))
172 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
173
174 /* At this point the Xtensa doesn't provide byte swap instructions */
175
176 #ifdef __XTENSA_EB__
177 # define in_8(addr) (*(u8*)(addr))
178 # define in_le16(addr) _swapw(*(u16*)(addr))
179 # define in_le32(addr) _swapl(*(u32*)(addr))
180 # define out_8(b, addr) *(u8*)(addr) = (b)
181 # define out_le16(b, addr) *(u16*)(addr) = _swapw(b)
182 # define out_le32(b, addr) *(u32*)(addr) = _swapl(b)
183 #elif defined(__XTENSA_EL__)
184 # define in_8(addr)  (*(u8*)(addr))
185 # define in_le16(addr) (*(u16*)(addr))
186 # define in_le32(addr) (*(u32*)(addr))
187 # define out_8(b, addr) *(u8*)(addr) = (b)
188 # define out_le16(b, addr) *(u16*)(addr) = (b)
189 # define out_le32(b, addr) *(u32*)(addr) = (b)
190 #else
191 # error processor byte order undefined!
192 #endif
193
194
195 /*
196  * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
197  */
198 #define xlate_dev_mem_ptr(p)    __va(p)
199
200 /*
201  * Convert a virtual cached pointer to an uncached pointer
202  */
203 #define xlate_dev_kmem_ptr(p)   p
204
205
206 #endif  /* __KERNEL__ */
207
208 #endif  /* _XTENSA_IO_H */