Import 2.3.13pre1
[davej-history.git] / include / asm-alpha / io.h
blob671e125751e62f853ca9cd89facf947269ddb17c
1 #ifndef __ALPHA_IO_H
2 #define __ALPHA_IO_H
4 #include <linux/config.h>
5 #include <asm/system.h>
7 /* We don't use IO slowdowns on the Alpha, but.. */
8 #define __SLOW_DOWN_IO do { } while (0)
9 #define SLOW_DOWN_IO do { } while (0)
12 * Virtual -> physical identity mapping starts at this offset
14 #ifdef USE_48_BIT_KSEG
15 #define IDENT_ADDR 0xffff800000000000
16 #else
17 #define IDENT_ADDR 0xfffffc0000000000
18 #endif
20 #ifdef __KERNEL__
21 #include <asm/machvec.h>
24 * We try to avoid hae updates (thus the cache), but when we
25 * do need to update the hae, we need to do it atomically, so
26 * that any interrupts wouldn't get confused with the hae
27 * register not being up-to-date with respect to the hardware
28 * value.
30 static inline void __set_hae(unsigned long new_hae)
32 unsigned long flags;
33 __save_and_cli(flags);
35 alpha_mv.hae_cache = new_hae;
36 *alpha_mv.hae_register = new_hae;
37 mb();
38 /* Re-read to make sure it was written. */
39 new_hae = *alpha_mv.hae_register;
41 __restore_flags(flags);
44 static inline void set_hae(unsigned long new_hae)
46 if (new_hae != alpha_mv.hae_cache)
47 __set_hae(new_hae);
51 * Change virtual addresses to physical addresses and vv.
53 static inline unsigned long virt_to_phys(volatile void * address)
55 /* Conditionalize this on the CPU? This here is 40 bits,
56 whereas EV4 only supports 34. But KSEG is farther out
57 so it shouldn't _really_ matter. */
58 return 0xffffffffffUL & (unsigned long) address;
61 static inline void * phys_to_virt(unsigned long address)
63 return (void *) (address + IDENT_ADDR);
66 #else /* !__KERNEL__ */
69 * Define actual functions in private name-space so it's easier to
70 * accommodate things like XFree or svgalib that like to define their
71 * own versions of inb etc.
73 extern void __sethae (unsigned long addr); /* syscall */
74 extern void _sethae (unsigned long addr); /* cached version */
76 #endif /* !__KERNEL__ */
79 * There are different chipsets to interface the Alpha CPUs to the world.
82 #ifdef __KERNEL__
83 #ifdef CONFIG_ALPHA_GENERIC
85 /* In a generic kernel, we always go through the machine vector. */
87 # define virt_to_bus(a) alpha_mv.mv_virt_to_bus(a)
88 # define bus_to_virt(a) alpha_mv.mv_bus_to_virt(a)
90 # define __inb alpha_mv.mv_inb
91 # define __inw alpha_mv.mv_inw
92 # define __inl alpha_mv.mv_inl
93 # define __outb alpha_mv.mv_outb
94 # define __outw alpha_mv.mv_outw
95 # define __outl alpha_mv.mv_outl
97 # define __readb(a) alpha_mv.mv_readb((unsigned long)(a))
98 # define __readw(a) alpha_mv.mv_readw((unsigned long)(a))
99 # define __readl(a) alpha_mv.mv_readl((unsigned long)(a))
100 # define __readq(a) alpha_mv.mv_readq((unsigned long)(a))
101 # define __writeb(v,a) alpha_mv.mv_writeb((v),(unsigned long)(a))
102 # define __writew(v,a) alpha_mv.mv_writew((v),(unsigned long)(a))
103 # define __writel(v,a) alpha_mv.mv_writel((v),(unsigned long)(a))
104 # define __writeq(v,a) alpha_mv.mv_writeq((v),(unsigned long)(a))
106 # define inb __inb
107 # define inw __inw
108 # define inl __inl
109 # define outb __outb
110 # define outw __outw
111 # define outl __outl
113 # define readb __readb
114 # define readw __readw
115 # define readl __readl
116 # define readq __readq
117 # define writeb __writeb
118 # define writew __writew
119 # define writel __writel
120 # define writeq __writeq
122 # define dense_mem(a) alpha_mv.mv_dense_mem(a)
124 #else
126 /* Control how and what gets defined within the core logic headers. */
127 #define __WANT_IO_DEF
129 #if defined(CONFIG_ALPHA_APECS)
130 # include <asm/core_apecs.h>
131 #elif defined(CONFIG_ALPHA_CIA)
132 # include <asm/core_cia.h>
133 #elif defined(CONFIG_ALPHA_LCA)
134 # include <asm/core_lca.h>
135 #elif defined(CONFIG_ALPHA_MCPCIA)
136 # include <asm/core_mcpcia.h>
137 #elif defined(CONFIG_ALPHA_PYXIS)
138 # include <asm/core_pyxis.h>
139 #elif defined(CONFIG_ALPHA_T2)
140 # include <asm/core_t2.h>
141 #elif defined(CONFIG_ALPHA_TSUNAMI)
142 # include <asm/core_tsunami.h>
143 #elif defined(CONFIG_ALPHA_JENSEN)
144 # include <asm/jensen.h>
145 #elif defined(CONFIG_ALPHA_POLARIS)
146 # include <asm/core_polaris.h>
147 #else
148 #error "What system is this?"
149 #endif
151 #undef __WANT_IO_DEF
153 #endif /* GENERIC */
154 #endif /* __KERNEL__ */
157 * The convention used for inb/outb etc. is that names starting with
158 * two underscores are the inline versions, names starting with a
159 * single underscore are proper functions, and names starting with a
160 * letter are macros that map in some way to inline or proper function
161 * versions. Not all that pretty, but before you change it, be sure
162 * to convince yourself that it won't break anything (in particular
163 * module support).
165 extern unsigned int _inb (unsigned long port);
166 extern unsigned int _inw (unsigned long port);
167 extern unsigned int _inl (unsigned long port);
168 extern void _outb (unsigned char b,unsigned long port);
169 extern void _outw (unsigned short w,unsigned long port);
170 extern void _outl (unsigned int l,unsigned long port);
171 extern unsigned long _readb(unsigned long addr);
172 extern unsigned long _readw(unsigned long addr);
173 extern unsigned long _readl(unsigned long addr);
174 extern unsigned long _readq(unsigned long addr);
175 extern void _writeb(unsigned char b, unsigned long addr);
176 extern void _writew(unsigned short b, unsigned long addr);
177 extern void _writel(unsigned int b, unsigned long addr);
178 extern void _writeq(unsigned long b, unsigned long addr);
180 #ifdef __KERNEL__
182 * The platform header files may define some of these macros to use
183 * the inlined versions where appropriate. These macros may also be
184 * redefined by userlevel programs.
186 #ifndef inb
187 # define inb(p) _inb((p))
188 #endif
189 #ifndef inw
190 # define inw(p) _inw((p))
191 #endif
192 #ifndef inl
193 # define inl(p) _inl((p))
194 #endif
195 #ifndef outb
196 # define outb(b,p) _outb((b),(p))
197 #endif
198 #ifndef outw
199 # define outw(w,p) _outw((w),(p))
200 #endif
201 #ifndef outl
202 # define outl(l,p) _outl((l),(p))
203 #endif
205 #ifndef inb_p
206 # define inb_p inb
207 #endif
208 #ifndef inw_p
209 # define inw_p inw
210 #endif
211 #ifndef inl_p
212 # define inl_p inl
213 #endif
215 #ifndef outb_p
216 # define outb_p outb
217 #endif
218 #ifndef outw_p
219 # define outw_p outw
220 #endif
221 #ifndef outl_p
222 # define outl_p outl
223 #endif
225 #else
227 /* Userspace declarations. */
229 extern unsigned int inb (unsigned long port);
230 extern unsigned int inw (unsigned long port);
231 extern unsigned int inl (unsigned long port);
232 extern void outb (unsigned char b,unsigned long port);
233 extern void outw (unsigned short w,unsigned long port);
234 extern void outl (unsigned int l,unsigned long port);
235 extern unsigned long readb(unsigned long addr);
236 extern unsigned long readw(unsigned long addr);
237 extern unsigned long readl(unsigned long addr);
238 extern void writeb(unsigned char b, unsigned long addr);
239 extern void writew(unsigned short b, unsigned long addr);
240 extern void writel(unsigned int b, unsigned long addr);
242 #endif /* __KERNEL__ */
244 #ifdef __KERNEL__
247 * The "address" in IO memory space is not clearly either an integer or a
248 * pointer. We will accept both, thus the casts.
250 * On the alpha, we have the whole physical address space mapped at all
251 * times, so "ioremap()" and "iounmap()" do not need to do anything.
253 static inline void * ioremap(unsigned long offset, unsigned long size)
255 return (void *) offset;
258 static inline void iounmap(void *addr)
262 #ifndef readb
263 # define readb(a) _readb((unsigned long)(a))
264 #endif
265 #ifndef readw
266 # define readw(a) _readw((unsigned long)(a))
267 #endif
268 #ifndef readl
269 # define readl(a) _readl((unsigned long)(a))
270 #endif
271 #ifndef readq
272 # define readq(a) _readq((unsigned long)(a))
273 #endif
274 #ifndef writeb
275 # define writeb(v,a) _writeb((v),(unsigned long)(a))
276 #endif
277 #ifndef writew
278 # define writew(v,a) _writew((v),(unsigned long)(a))
279 #endif
280 #ifndef writel
281 # define writel(v,a) _writel((v),(unsigned long)(a))
282 #endif
283 #ifndef writeq
284 # define writeq(v,a) _writeq((v),(unsigned long)(a))
285 #endif
288 * String version of IO memory access ops:
290 extern void _memcpy_fromio(void *, unsigned long, long);
291 extern void _memcpy_toio(unsigned long, const void *, long);
292 extern void _memset_c_io(unsigned long, unsigned long, long);
294 #define memcpy_fromio(to,from,len) \
295 _memcpy_fromio((to),(unsigned long)(from),(len))
296 #define memcpy_toio(to,from,len) \
297 _memcpy_toio((unsigned long)(to),(from),(len))
298 #define memset_io(addr,c,len) \
299 _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
301 #define __HAVE_ARCH_MEMSETW_IO
302 #define memsetw_io(addr,c,len) \
303 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
306 * String versions of in/out ops:
308 extern void insb (unsigned long port, void *dst, unsigned long count);
309 extern void insw (unsigned long port, void *dst, unsigned long count);
310 extern void insl (unsigned long port, void *dst, unsigned long count);
311 extern void outsb (unsigned long port, const void *src, unsigned long count);
312 extern void outsw (unsigned long port, const void *src, unsigned long count);
313 extern void outsl (unsigned long port, const void *src, unsigned long count);
316 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
317 * just copy it. The net code will then do the checksum later. Presently
318 * only used by some shared memory 8390 Ethernet cards anyway.
321 #define eth_io_copy_and_sum(skb,src,len,unused) \
322 memcpy_fromio((skb)->data,(src),(len))
324 static inline int
325 check_signature(unsigned long io_addr, const unsigned char *signature,
326 int length)
328 int retval = 0;
329 do {
330 if (readb(io_addr) != *signature)
331 goto out;
332 io_addr++;
333 signature++;
334 length--;
335 } while (length);
336 retval = 1;
337 out:
338 return retval;
342 * The Alpha Jensen hardware for some rather strange reason puts
343 * the RTC clock at 0x170 instead of 0x70. Probably due to some
344 * misguided idea about using 0x70 for NMI stuff.
346 * These defines will override the defaults when doing RTC queries
349 #ifdef CONFIG_ALPHA_GENERIC
350 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
351 #else
352 # ifdef CONFIG_ALPHA_JENSEN
353 # define RTC_PORT(x) (0x170+(x))
354 # else
355 # define RTC_PORT(x) (0x70 + (x))
356 # endif
357 #endif
358 #define RTC_ALWAYS_BCD 0
360 /* Nothing to do */
362 #define dma_cache_inv(_start,_size) do { } while (0)
363 #define dma_cache_wback(_start,_size) do { } while (0)
364 #define dma_cache_wback_inv(_start,_size) do { } while (0)
366 #endif /* __KERNEL__ */
368 #endif /* __ALPHA_IO_H */