ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-sparc / io.h
1 /*
2  * $Id: io.h,v 1.30 2001/12/21 01:23:21 davem Exp $
3  */
4 #ifndef __SPARC_IO_H
5 #define __SPARC_IO_H
6
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/ioport.h>  /* struct resource */
10
11 #include <asm/page.h>      /* IO address mapping routines need this */
12 #include <asm/system.h>
13
14 #define page_to_phys(page)      (((page) - mem_map) << PAGE_SHIFT)
15
16 static inline u32 flip_dword (u32 l)
17 {
18         return ((l&0xff)<<24) | (((l>>8)&0xff)<<16) | (((l>>16)&0xff)<<8)| ((l>>24)&0xff);
19 }
20
21 static inline u16 flip_word (u16 w)
22 {
23         return ((w&0xff) << 8) | ((w>>8)&0xff);
24 }
25
26 /*
27  * Memory mapped I/O to PCI
28  *
29  * Observe that ioremap returns void* cookie, but accessors, such
30  * as readb, take unsigned long as address, by API. This mismatch
31  * happened historically. The ioremap is much older than accessors,
32  * so at one time ioremap's cookie was used as address (*a = val).
33  * When accessors came about, they were designed to be compatible across
34  * buses, so that drivers can select proper ones like sunhme.c did.
35  * To make that easier, they use same aruments (ulong) for sbus, pci, isa.
36  * The offshot is, we must cast readb et. al. arguments with a #define.
37  */
38
39 static inline u8 __raw_readb(unsigned long addr)
40 {
41         return *(volatile u8 *)addr;
42 }
43
44 static inline u16 __raw_readw(unsigned long addr)
45 {
46         return *(volatile u16 *)addr;
47 }
48
49 static inline u32 __raw_readl(unsigned long addr)
50 {
51         return *(volatile u32 *)addr;
52 }
53
54 static inline void __raw_writeb(u8 b, unsigned long addr)
55 {
56         *(volatile u8 *)addr = b;
57 }
58
59 static inline void __raw_writew(u16 w, unsigned long addr)
60 {
61         *(volatile u16 *)addr = w;
62 }
63
64 static inline void __raw_writel(u32 l, unsigned long addr)
65 {
66         *(volatile u32 *)addr = l;
67 }
68
69 static inline u8 __readb(unsigned long addr)
70 {
71         return *(volatile u8 *)addr;
72 }
73
74 static inline u16 __readw(unsigned long addr)
75 {
76         return flip_word(*(volatile u16 *)addr);
77 }
78
79 static inline u32 __readl(unsigned long addr)
80 {
81         return flip_dword(*(volatile u32 *)addr);
82 }
83
84 static inline void __writeb(u8 b, unsigned long addr)
85 {
86         *(volatile u8 *)addr = b;
87 }
88
89 static inline void __writew(u16 w, unsigned long addr)
90 {
91         *(volatile u16 *)addr = flip_word(w);
92 }
93
94 static inline void __writel(u32 l, unsigned long addr)
95 {
96         *(volatile u32 *)addr = flip_dword(l);
97 }
98
99 #define readb(__addr)           __readb((unsigned long)(__addr))
100 #define readw(__addr)           __readw((unsigned long)(__addr))
101 #define readl(__addr)           __readl((unsigned long)(__addr))
102 #define readb_relaxed(__addr)   readb(__addr)
103 #define readw_relaxed(__addr)   readw(__addr)
104 #define readl_relaxed(__addr)   readl(__addr)
105
106 #define writeb(__b, __addr)     __writeb((__b),(unsigned long)(__addr))
107 #define writew(__w, __addr)     __writew((__w),(unsigned long)(__addr))
108 #define writel(__l, __addr)     __writel((__l),(unsigned long)(__addr))
109
110 /*
111  * I/O space operations
112  *
113  * Arrangement on a Sun is somewhat complicated.
114  *
115  * First of all, we want to use standard Linux drivers
116  * for keyboard, PC serial, etc. These drivers think
117  * they access I/O space and use inb/outb.
118  * On the other hand, EBus bridge accepts PCI *memory*
119  * cycles and converts them into ISA *I/O* cycles.
120  * Ergo, we want inb & outb to generate PCI memory cycles.
121  *
122  * If we want to issue PCI *I/O* cycles, we do this
123  * with a low 64K fixed window in PCIC. This window gets
124  * mapped somewhere into virtual kernel space and we
125  * can use inb/outb again.
126  */
127 #define inb_local(__addr)       __readb((unsigned long)(__addr))
128 #define inb(__addr)             __readb((unsigned long)(__addr))
129 #define inw(__addr)             __readw((unsigned long)(__addr))
130 #define inl(__addr)             __readl((unsigned long)(__addr))
131
132 #define outb_local(__b, __addr) __writeb(__b, (unsigned long)(__addr))
133 #define outb(__b, __addr)       __writeb(__b, (unsigned long)(__addr))
134 #define outw(__w, __addr)       __writew(__w, (unsigned long)(__addr))
135 #define outl(__l, __addr)       __writel(__l, (unsigned long)(__addr))
136
137 #define inb_p(__addr)           inb(__addr)
138 #define outb_p(__b, __addr)     outb(__b, __addr)
139 #define inw_p(__addr)           inw(__addr)
140 #define outw_p(__w, __addr)     outw(__w, __addr)
141 #define inl_p(__addr)           inl(__addr)
142 #define outl_p(__l, __addr)     outl(__l, __addr)
143
144 extern void outsb(unsigned long addr, const void *src, unsigned long cnt);
145 extern void outsw(unsigned long addr, const void *src, unsigned long cnt);
146 extern void outsl(unsigned long addr, const void *src, unsigned long cnt);
147 extern void insb(unsigned long addr, void *dst, unsigned long count);
148 extern void insw(unsigned long addr, void *dst, unsigned long count);
149 extern void insl(unsigned long addr, void *dst, unsigned long count);
150
151 #define IO_SPACE_LIMIT 0xffffffff
152
153 /*
154  * SBus accessors.
155  *
156  * SBus has only one, memory mapped, I/O space.
157  * We do not need to flip bytes for SBus of course.
158  */
159 static inline u8 _sbus_readb(unsigned long addr)
160 {
161         return *(volatile u8 *)addr;
162 }
163
164 static inline u16 _sbus_readw(unsigned long addr)
165 {
166         return *(volatile u16 *)addr;
167 }
168
169 static inline u32 _sbus_readl(unsigned long addr)
170 {
171         return *(volatile u32 *)addr;
172 }
173
174 static inline void _sbus_writeb(u8 b, unsigned long addr)
175 {
176         *(volatile u8 *)addr = b;
177 }
178
179 static inline void _sbus_writew(u16 w, unsigned long addr)
180 {
181         *(volatile u16 *)addr = w;
182 }
183
184 static inline void _sbus_writel(u32 l, unsigned long addr)
185 {
186         *(volatile u32 *)addr = l;
187 }
188
189 /*
190  * The only reason for #define's is to hide casts to unsigned long.
191  */
192 #define sbus_readb(__addr)              _sbus_readb((unsigned long)(__addr))
193 #define sbus_readw(__addr)              _sbus_readw((unsigned long)(__addr))
194 #define sbus_readl(__addr)              _sbus_readl((unsigned long)(__addr))
195 #define sbus_writeb(__b, __addr)        _sbus_writeb(__b, (unsigned long)(__addr))
196 #define sbus_writew(__w, __addr)        _sbus_writew(__w, (unsigned long)(__addr))
197 #define sbus_writel(__l, __addr)        _sbus_writel(__l, (unsigned long)(__addr))
198
199 static inline void *sbus_memset_io(void *__dst, int c, __kernel_size_t n)
200 {
201         unsigned long dst = (unsigned long)__dst;
202
203         while(n--) {
204                 sbus_writeb(c, dst);
205                 dst++;
206         }
207         return (void *) dst;
208 }
209
210 #ifdef __KERNEL__
211
212 /*
213  * Bus number may be embedded in the higher bits of the physical address.
214  * This is why we have no bus number argument to ioremap().
215  */
216 extern void *ioremap(unsigned long offset, unsigned long size);
217 #define ioremap_nocache(X,Y)    ioremap((X),(Y))
218 extern void iounmap(void *addr);
219
220 /*
221  * Bus number may be in res->flags... somewhere.
222  */
223 extern unsigned long sbus_ioremap(struct resource *res, unsigned long offset,
224     unsigned long size, char *name);
225 extern void sbus_iounmap(unsigned long vaddr, unsigned long size);
226
227
228 /*
229  * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
230  * so rtc_port is static in it. This should not change unless a new
231  * hardware pops up.
232  */
233 #define RTC_PORT(x)   (rtc_port + (x))
234 #define RTC_ALWAYS_BCD  0
235
236 /* Nothing to do */
237 /* P3: Only IDE DMA may need these. XXX Verify that it still does... */
238
239 #define dma_cache_inv(_start,_size)             do { } while (0)
240 #define dma_cache_wback(_start,_size)           do { } while (0)
241 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
242
243 #endif
244
245 #endif /* !(__SPARC_IO_H) */