Import 2.3.18pre1
[davej-history.git] / include / asm-alpha / io.h
blob8505e47c8373bbf5112a107058f496acbbfeaace
1 #ifndef __ALPHA_IO_H
2 #define __ALPHA_IO_H
4 #include <linux/config.h>
5 #include <linux/kernel.h>
6 #include <asm/system.h>
8 /* We don't use IO slowdowns on the Alpha, but.. */
9 #define __SLOW_DOWN_IO do { } while (0)
10 #define SLOW_DOWN_IO do { } while (0)
13 * Virtual -> physical identity mapping starts at this offset
15 #ifdef USE_48_BIT_KSEG
16 #define IDENT_ADDR 0xffff800000000000
17 #else
18 #define IDENT_ADDR 0xfffffc0000000000
19 #endif
21 #ifdef __KERNEL__
22 #include <asm/machvec.h>
25 * We try to avoid hae updates (thus the cache), but when we
26 * do need to update the hae, we need to do it atomically, so
27 * that any interrupts wouldn't get confused with the hae
28 * register not being up-to-date with respect to the hardware
29 * value.
31 static inline void __set_hae(unsigned long new_hae)
33 unsigned long flags;
34 __save_and_cli(flags);
36 alpha_mv.hae_cache = new_hae;
37 *alpha_mv.hae_register = new_hae;
38 mb();
39 /* Re-read to make sure it was written. */
40 new_hae = *alpha_mv.hae_register;
42 __restore_flags(flags);
45 static inline void set_hae(unsigned long new_hae)
47 if (new_hae != alpha_mv.hae_cache)
48 __set_hae(new_hae);
52 * Change virtual addresses to physical addresses and vv.
54 static inline unsigned long virt_to_phys(volatile void * address)
56 /* Conditionalize this on the CPU? This here is 40 bits,
57 whereas EV4 only supports 34. But KSEG is farther out
58 so it shouldn't _really_ matter. */
59 return 0xffffffffffUL & (unsigned long) address;
62 static inline void * phys_to_virt(unsigned long address)
64 return (void *) (address + IDENT_ADDR);
67 #else /* !__KERNEL__ */
70 * Define actual functions in private name-space so it's easier to
71 * accommodate things like XFree or svgalib that like to define their
72 * own versions of inb etc.
74 extern void __sethae (unsigned long addr); /* syscall */
75 extern void _sethae (unsigned long addr); /* cached version */
77 #endif /* !__KERNEL__ */
80 * There are different chipsets to interface the Alpha CPUs to the world.
83 #ifdef __KERNEL__
84 #ifdef CONFIG_ALPHA_GENERIC
86 /* In a generic kernel, we always go through the machine vector. */
88 # define virt_to_bus(a) alpha_mv.mv_virt_to_bus(a)
89 # define bus_to_virt(a) alpha_mv.mv_bus_to_virt(a)
91 # define __inb alpha_mv.mv_inb
92 # define __inw alpha_mv.mv_inw
93 # define __inl alpha_mv.mv_inl
94 # define __outb alpha_mv.mv_outb
95 # define __outw alpha_mv.mv_outw
96 # define __outl alpha_mv.mv_outl
98 # define __readb(a) alpha_mv.mv_readb((unsigned long)(a))
99 # define __readw(a) alpha_mv.mv_readw((unsigned long)(a))
100 # define __readl(a) alpha_mv.mv_readl((unsigned long)(a))
101 # define __readq(a) alpha_mv.mv_readq((unsigned long)(a))
102 # define __writeb(v,a) alpha_mv.mv_writeb((v),(unsigned long)(a))
103 # define __writew(v,a) alpha_mv.mv_writew((v),(unsigned long)(a))
104 # define __writel(v,a) alpha_mv.mv_writel((v),(unsigned long)(a))
105 # define __writeq(v,a) alpha_mv.mv_writeq((v),(unsigned long)(a))
107 # define __ioremap(a) alpha_mv.mv_ioremap(a)
108 # define __is_ioaddr(a) alpha_mv.mv_is_ioaddr(a)
110 # define inb __inb
111 # define inw __inw
112 # define inl __inl
113 # define outb __outb
114 # define outw __outw
115 # define outl __outl
117 # define __raw_readb __readb
118 # define __raw_readw __readw
119 # define __raw_readl __readl
120 # define __raw_readq __readq
121 # define __raw_writeb __writeb
122 # define __raw_writew __writew
123 # define __raw_writel __writel
124 # define __raw_writeq __writeq
126 #else
128 /* Control how and what gets defined within the core logic headers. */
129 #define __WANT_IO_DEF
131 #if defined(CONFIG_ALPHA_APECS)
132 # include <asm/core_apecs.h>
133 #elif defined(CONFIG_ALPHA_CIA)
134 # include <asm/core_cia.h>
135 #elif defined(CONFIG_ALPHA_LCA)
136 # include <asm/core_lca.h>
137 #elif defined(CONFIG_ALPHA_MCPCIA)
138 # include <asm/core_mcpcia.h>
139 #elif defined(CONFIG_ALPHA_PYXIS)
140 # include <asm/core_pyxis.h>
141 #elif defined(CONFIG_ALPHA_T2)
142 # include <asm/core_t2.h>
143 #elif defined(CONFIG_ALPHA_TSUNAMI)
144 # include <asm/core_tsunami.h>
145 #elif defined(CONFIG_ALPHA_JENSEN)
146 # include <asm/jensen.h>
147 #elif defined(CONFIG_ALPHA_POLARIS)
148 # include <asm/core_polaris.h>
149 #else
150 #error "What system is this?"
151 #endif
153 #undef __WANT_IO_DEF
155 #endif /* GENERIC */
156 #endif /* __KERNEL__ */
159 * The convention used for inb/outb etc. is that names starting with
160 * two underscores are the inline versions, names starting with a
161 * single underscore are proper functions, and names starting with a
162 * letter are macros that map in some way to inline or proper function
163 * versions. Not all that pretty, but before you change it, be sure
164 * to convince yourself that it won't break anything (in particular
165 * module support).
167 extern unsigned int _inb (unsigned long port);
168 extern unsigned int _inw (unsigned long port);
169 extern unsigned int _inl (unsigned long port);
170 extern void _outb (unsigned char b,unsigned long port);
171 extern void _outw (unsigned short w,unsigned long port);
172 extern void _outl (unsigned int l,unsigned long port);
173 extern unsigned long _readb(unsigned long addr);
174 extern unsigned long _readw(unsigned long addr);
175 extern unsigned long _readl(unsigned long addr);
176 extern unsigned long _readq(unsigned long addr);
177 extern void _writeb(unsigned char b, unsigned long addr);
178 extern void _writew(unsigned short b, unsigned long addr);
179 extern void _writel(unsigned int b, unsigned long addr);
180 extern void _writeq(unsigned long b, unsigned long addr);
182 #ifdef __KERNEL__
184 * The platform header files may define some of these macros to use
185 * the inlined versions where appropriate. These macros may also be
186 * redefined by userlevel programs.
188 #ifndef inb
189 # define inb(p) _inb((p))
190 #endif
191 #ifndef inw
192 # define inw(p) _inw((p))
193 #endif
194 #ifndef inl
195 # define inl(p) _inl((p))
196 #endif
197 #ifndef outb
198 # define outb(b,p) _outb((b),(p))
199 #endif
200 #ifndef outw
201 # define outw(w,p) _outw((w),(p))
202 #endif
203 #ifndef outl
204 # define outl(l,p) _outl((l),(p))
205 #endif
207 #ifndef inb_p
208 # define inb_p inb
209 #endif
210 #ifndef inw_p
211 # define inw_p inw
212 #endif
213 #ifndef inl_p
214 # define inl_p inl
215 #endif
217 #ifndef outb_p
218 # define outb_p outb
219 #endif
220 #ifndef outw_p
221 # define outw_p outw
222 #endif
223 #ifndef outl_p
224 # define outl_p outl
225 #endif
227 #else
229 /* Userspace declarations. */
231 extern unsigned int inb (unsigned long port);
232 extern unsigned int inw (unsigned long port);
233 extern unsigned int inl (unsigned long port);
234 extern void outb (unsigned char b,unsigned long port);
235 extern void outw (unsigned short w,unsigned long port);
236 extern void outl (unsigned int l,unsigned long port);
237 extern unsigned long readb(unsigned long addr);
238 extern unsigned long readw(unsigned long addr);
239 extern unsigned long readl(unsigned long addr);
240 extern void writeb(unsigned char b, unsigned long addr);
241 extern void writew(unsigned short b, unsigned long addr);
242 extern void writel(unsigned int b, unsigned long addr);
244 #endif /* __KERNEL__ */
246 #ifdef __KERNEL__
249 * On Alpha, we have the whole of I/O space mapped at all times, but
250 * at odd and sometimes discontinuous addresses. Note that the
251 * discontinuities are all across busses, so we need not care for that
252 * for any one device.
254 * Map the I/O space address into the kernel's virtual address space.
256 static inline void * ioremap(unsigned long offset, unsigned long size)
258 return (void *) __ioremap(offset);
261 static inline void iounmap(void *addr)
265 /* Indirect back to the macros provided. */
267 extern unsigned long ___raw_readb(unsigned long addr);
268 extern unsigned long ___raw_readw(unsigned long addr);
269 extern unsigned long ___raw_readl(unsigned long addr);
270 extern unsigned long ___raw_readq(unsigned long addr);
271 extern void ___raw_writeb(unsigned char b, unsigned long addr);
272 extern void ___raw_writew(unsigned short b, unsigned long addr);
273 extern void ___raw_writel(unsigned int b, unsigned long addr);
274 extern void ___raw_writeq(unsigned long b, unsigned long addr);
276 #ifdef __raw_readb
277 # define readb(a) ({ unsigned long r_ = __raw_readb(a); mb(); r_; })
278 #endif
279 #ifdef __raw_readw
280 # define readw(a) ({ unsigned long r_ = __raw_readw(a); mb(); r_; })
281 #endif
282 #ifdef __raw_readl
283 # define readl(a) ({ unsigned long r_ = __raw_readl(a); mb(); r_; })
284 #endif
285 #ifdef __raw_readq
286 # define readq(a) ({ unsigned long r_ = __raw_readq(a); mb(); r_; })
287 #endif
289 #ifdef __raw_writeb
290 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
291 #endif
292 #ifdef __raw_writew
293 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
294 #endif
295 #ifdef __raw_writel
296 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
297 #endif
298 #ifdef __raw_writeq
299 # define writeq(v,a) ({ __raw_writeq((v),(a)); mb(); })
300 #endif
302 #ifndef __raw_readb
303 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
304 #endif
305 #ifndef __raw_readw
306 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
307 #endif
308 #ifndef __raw_readl
309 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
310 #endif
311 #ifndef __raw_readq
312 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
313 #endif
315 #ifndef __raw_writeb
316 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
317 #endif
318 #ifndef __raw_writew
319 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
320 #endif
321 #ifndef __raw_writel
322 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
323 #endif
324 #ifndef __raw_writeq
325 # define __raw_writeq(v,a) ___raw_writeq((v),(unsigned long)(a))
326 #endif
328 #ifndef readb
329 # define readb(a) _readb((unsigned long)(a))
330 #endif
331 #ifndef readw
332 # define readw(a) _readw((unsigned long)(a))
333 #endif
334 #ifndef readl
335 # define readl(a) _readl((unsigned long)(a))
336 #endif
337 #ifndef readq
338 # define readq(a) _readq((unsigned long)(a))
339 #endif
341 #ifndef writeb
342 # define writeb(v,a) _writeb((v),(unsigned long)(a))
343 #endif
344 #ifndef writew
345 # define writew(v,a) _writew((v),(unsigned long)(a))
346 #endif
347 #ifndef writel
348 # define writel(v,a) _writel((v),(unsigned long)(a))
349 #endif
350 #ifndef writeq
351 # define writeq(v,a) _writeq((v),(unsigned long)(a))
352 #endif
355 * String version of IO memory access ops:
357 extern void _memcpy_fromio(void *, unsigned long, long);
358 extern void _memcpy_toio(unsigned long, const void *, long);
359 extern void _memset_c_io(unsigned long, unsigned long, long);
361 #define memcpy_fromio(to,from,len) \
362 _memcpy_fromio((to),(unsigned long)(from),(len))
363 #define memcpy_toio(to,from,len) \
364 _memcpy_toio((unsigned long)(to),(from),(len))
365 #define memset_io(addr,c,len) \
366 _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
368 #define __HAVE_ARCH_MEMSETW_IO
369 #define memsetw_io(addr,c,len) \
370 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
373 * String versions of in/out ops:
375 extern void insb (unsigned long port, void *dst, unsigned long count);
376 extern void insw (unsigned long port, void *dst, unsigned long count);
377 extern void insl (unsigned long port, void *dst, unsigned long count);
378 extern void outsb (unsigned long port, const void *src, unsigned long count);
379 extern void outsw (unsigned long port, const void *src, unsigned long count);
380 extern void outsl (unsigned long port, const void *src, unsigned long count);
383 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
384 * just copy it. The net code will then do the checksum later. Presently
385 * only used by some shared memory 8390 Ethernet cards anyway.
388 #define eth_io_copy_and_sum(skb,src,len,unused) \
389 memcpy_fromio((skb)->data,(src),(len))
391 static inline int
392 check_signature(unsigned long io_addr, const unsigned char *signature,
393 int length)
395 int retval = 0;
396 do {
397 if (readb(io_addr) != *signature)
398 goto out;
399 io_addr++;
400 signature++;
401 length--;
402 } while (length);
403 retval = 1;
404 out:
405 return retval;
409 * The Alpha Jensen hardware for some rather strange reason puts
410 * the RTC clock at 0x170 instead of 0x70. Probably due to some
411 * misguided idea about using 0x70 for NMI stuff.
413 * These defines will override the defaults when doing RTC queries
416 #ifdef CONFIG_ALPHA_GENERIC
417 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
418 #else
419 # ifdef CONFIG_ALPHA_JENSEN
420 # define RTC_PORT(x) (0x170+(x))
421 # else
422 # define RTC_PORT(x) (0x70 + (x))
423 # endif
424 #endif
425 #define RTC_ALWAYS_BCD 0
427 /* Nothing to do */
429 #define dma_cache_inv(_start,_size) do { } while (0)
430 #define dma_cache_wback(_start,_size) do { } while (0)
431 #define dma_cache_wback_inv(_start,_size) do { } while (0)
433 #endif /* __KERNEL__ */
435 #endif /* __ALPHA_IO_H */