patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-alpha / io.h
1 #ifndef __ALPHA_IO_H
2 #define __ALPHA_IO_H
3
4 /* We don't use IO slowdowns on the Alpha, but.. */
5 #define __SLOW_DOWN_IO  do { } while (0)
6 #define SLOW_DOWN_IO    do { } while (0)
7
8 /*
9  * Virtual -> physical identity mapping starts at this offset
10  */
11 #ifdef USE_48_BIT_KSEG
12 #define IDENT_ADDR     0xffff800000000000UL
13 #else
14 #define IDENT_ADDR     0xfffffc0000000000UL
15 #endif
16
17 #ifdef __KERNEL__
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <asm/system.h>
21 #include <asm/pgtable.h>
22 #include <asm/machvec.h>
23 #include <asm/hwrpb.h>
24
25 /*
26  * We try to avoid hae updates (thus the cache), but when we
27  * do need to update the hae, we need to do it atomically, so
28  * that any interrupts wouldn't get confused with the hae
29  * register not being up-to-date with respect to the hardware
30  * value.
31  */
32 static inline void __set_hae(unsigned long new_hae)
33 {
34         unsigned long flags;
35         local_irq_save(flags);
36
37         alpha_mv.hae_cache = new_hae;
38         *alpha_mv.hae_register = new_hae;
39         mb();
40         /* Re-read to make sure it was written.  */
41         new_hae = *alpha_mv.hae_register;
42
43         local_irq_restore(flags);
44 }
45
46 static inline void set_hae(unsigned long new_hae)
47 {
48         if (new_hae != alpha_mv.hae_cache)
49                 __set_hae(new_hae);
50 }
51
52 /*
53  * Change virtual addresses to physical addresses and vv.
54  */
55 #ifdef USE_48_BIT_KSEG
56 static inline unsigned long virt_to_phys(void *address)
57 {
58         return (unsigned long)address - IDENT_ADDR;
59 }
60
61 static inline void * phys_to_virt(unsigned long address)
62 {
63         return (void *) (address + IDENT_ADDR);
64 }
65 #else
66 static inline unsigned long virt_to_phys(void *address)
67 {
68         unsigned long phys = (unsigned long)address;
69
70         /* Sign-extend from bit 41.  */
71         phys <<= (64 - 41);
72         phys = (long)phys >> (64 - 41);
73
74         /* Crop to the physical address width of the processor.  */
75         phys &= (1ul << hwrpb->pa_bits) - 1;
76
77         return phys;
78 }
79
80 static inline void * phys_to_virt(unsigned long address)
81 {
82         return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
83 }
84 #endif
85
86 #define page_to_phys(page)      page_to_pa(page)
87
88 /* This depends on working iommu.  */
89 #define BIO_VMERGE_BOUNDARY     (alpha_mv.mv_pci_tbi ? PAGE_SIZE : 0)
90
91 /*
92  * Change addresses as seen by the kernel (virtual) to addresses as
93  * seen by a device (bus), and vice versa.
94  *
95  * Note that this only works for a limited range of kernel addresses,
96  * and very well may not span all memory.  Consider this interface 
97  * deprecated in favour of the mapping functions in <asm/pci.h>.
98  */
99 extern unsigned long __direct_map_base;
100 extern unsigned long __direct_map_size;
101
102 static inline unsigned long virt_to_bus(void *address)
103 {
104         unsigned long phys = virt_to_phys(address);
105         unsigned long bus = phys + __direct_map_base;
106         return phys <= __direct_map_size ? bus : 0;
107 }
108
109 static inline void *bus_to_virt(unsigned long address)
110 {
111         void *virt;
112
113         /* This check is a sanity check but also ensures that bus address 0
114            maps to virtual address 0 which is useful to detect null pointers
115            (the NCR driver is much simpler if NULL pointers are preserved).  */
116         address -= __direct_map_base;
117         virt = phys_to_virt(address);
118         return (long)address <= 0 ? NULL : virt;
119 }
120
121 #else /* !__KERNEL__ */
122
123 /*
124  * Define actual functions in private name-space so it's easier to
125  * accommodate things like XFree or svgalib that like to define their
126  * own versions of inb etc.
127  */
128 extern void __sethae (unsigned long addr);      /* syscall */
129 extern void _sethae (unsigned long addr);       /* cached version */
130
131 #endif /* !__KERNEL__ */
132
133 /*
134  * There are different chipsets to interface the Alpha CPUs to the world.
135  */
136
137 #ifdef __KERNEL__
138 #ifdef CONFIG_ALPHA_GENERIC
139
140 /* In a generic kernel, we always go through the machine vector.  */
141
142 # define __inb(p)       alpha_mv.mv_inb((unsigned long)(p))
143 # define __inw(p)       alpha_mv.mv_inw((unsigned long)(p))
144 # define __inl(p)       alpha_mv.mv_inl((unsigned long)(p))
145 # define __outb(x,p)    alpha_mv.mv_outb((x),(unsigned long)(p))
146 # define __outw(x,p)    alpha_mv.mv_outw((x),(unsigned long)(p))
147 # define __outl(x,p)    alpha_mv.mv_outl((x),(unsigned long)(p))
148
149 # define __readb(a)     alpha_mv.mv_readb((unsigned long)(a))
150 # define __readw(a)     alpha_mv.mv_readw((unsigned long)(a))
151 # define __readl(a)     alpha_mv.mv_readl((unsigned long)(a))
152 # define __readq(a)     alpha_mv.mv_readq((unsigned long)(a))
153 # define __writeb(v,a)  alpha_mv.mv_writeb((v),(unsigned long)(a))
154 # define __writew(v,a)  alpha_mv.mv_writew((v),(unsigned long)(a))
155 # define __writel(v,a)  alpha_mv.mv_writel((v),(unsigned long)(a))
156 # define __writeq(v,a)  alpha_mv.mv_writeq((v),(unsigned long)(a))
157
158 # define __ioremap(a,s) alpha_mv.mv_ioremap((unsigned long)(a),(s))
159 # define __iounmap(a)   alpha_mv.mv_iounmap((unsigned long)(a))
160 # define __is_ioaddr(a) alpha_mv.mv_is_ioaddr((unsigned long)(a))
161
162 # define inb            __inb
163 # define inw            __inw
164 # define inl            __inl
165 # define outb           __outb
166 # define outw           __outw
167 # define outl           __outl
168
169 # define __raw_readb    __readb
170 # define __raw_readw    __readw
171 # define __raw_readl    __readl
172 # define __raw_readq    __readq
173 # define __raw_writeb   __writeb
174 # define __raw_writew   __writew
175 # define __raw_writel   __writel
176 # define __raw_writeq   __writeq
177
178 #else
179
180 /* Control how and what gets defined within the core logic headers.  */
181 #define __WANT_IO_DEF
182
183 #if defined(CONFIG_ALPHA_APECS)
184 # include <asm/core_apecs.h>
185 #elif defined(CONFIG_ALPHA_CIA)
186 # include <asm/core_cia.h>
187 #elif defined(CONFIG_ALPHA_IRONGATE)
188 # include <asm/core_irongate.h>
189 #elif defined(CONFIG_ALPHA_JENSEN)
190 # include <asm/jensen.h>
191 #elif defined(CONFIG_ALPHA_LCA)
192 # include <asm/core_lca.h>
193 #elif defined(CONFIG_ALPHA_MARVEL)
194 # include <asm/core_marvel.h>
195 #elif defined(CONFIG_ALPHA_MCPCIA)
196 # include <asm/core_mcpcia.h>
197 #elif defined(CONFIG_ALPHA_POLARIS)
198 # include <asm/core_polaris.h>
199 #elif defined(CONFIG_ALPHA_T2)
200 # include <asm/core_t2.h>
201 #elif defined(CONFIG_ALPHA_TSUNAMI)
202 # include <asm/core_tsunami.h>
203 #elif defined(CONFIG_ALPHA_TITAN)
204 # include <asm/core_titan.h>
205 #elif defined(CONFIG_ALPHA_WILDFIRE)
206 # include <asm/core_wildfire.h>
207 #else
208 #error "What system is this?"
209 #endif
210
211 #undef __WANT_IO_DEF
212
213 #endif /* GENERIC */
214 #endif /* __KERNEL__ */
215
216 /*
217  * The convention used for inb/outb etc. is that names starting with
218  * two underscores are the inline versions, names starting with a
219  * single underscore are proper functions, and names starting with a
220  * letter are macros that map in some way to inline or proper function
221  * versions.  Not all that pretty, but before you change it, be sure
222  * to convince yourself that it won't break anything (in particular
223  * module support).
224  */
225 extern u8               _inb (unsigned long port);
226 extern u16              _inw (unsigned long port);
227 extern u32              _inl (unsigned long port);
228 extern void             _outb (u8 b,unsigned long port);
229 extern void             _outw (u16 w,unsigned long port);
230 extern void             _outl (u32 l,unsigned long port);
231 extern u8               _readb(unsigned long addr);
232 extern u16              _readw(unsigned long addr);
233 extern u32              _readl(unsigned long addr);
234 extern u64              _readq(unsigned long addr);
235 extern void             _writeb(u8 b, unsigned long addr);
236 extern void             _writew(u16 b, unsigned long addr);
237 extern void             _writel(u32 b, unsigned long addr);
238 extern void             _writeq(u64 b, unsigned long addr);
239
240 #ifdef __KERNEL__
241 /*
242  * The platform header files may define some of these macros to use
243  * the inlined versions where appropriate.  These macros may also be
244  * redefined by userlevel programs.
245  */
246 #ifndef inb
247 # define inb(p)         _inb(p)
248 #endif
249 #ifndef inw
250 # define inw(p)         _inw(p)
251 #endif
252 #ifndef inl
253 # define inl(p)         _inl(p)
254 #endif
255 #ifndef outb
256 # define outb(b,p)      _outb((b),(p))
257 #endif
258 #ifndef outw
259 # define outw(w,p)      _outw((w),(p))
260 #endif
261 #ifndef outl
262 # define outl(l,p)      _outl((l),(p))
263 #endif
264
265 #ifndef inb_p
266 # define inb_p          inb
267 #endif
268 #ifndef inw_p
269 # define inw_p          inw
270 #endif
271 #ifndef inl_p
272 # define inl_p          inl
273 #endif
274
275 #ifndef outb_p
276 # define outb_p         outb
277 #endif
278 #ifndef outw_p
279 # define outw_p         outw
280 #endif
281 #ifndef outl_p
282 # define outl_p         outl
283 #endif
284
285 #define IO_SPACE_LIMIT 0xffff
286
287 #else 
288
289 /* Userspace declarations.  Kill in 2.5. */
290
291 extern unsigned int     inb(unsigned long port);
292 extern unsigned int     inw(unsigned long port);
293 extern unsigned int     inl(unsigned long port);
294 extern void             outb(unsigned char b,unsigned long port);
295 extern void             outw(unsigned short w,unsigned long port);
296 extern void             outl(unsigned int l,unsigned long port);
297 extern unsigned long    readb(unsigned long addr);
298 extern unsigned long    readw(unsigned long addr);
299 extern unsigned long    readl(unsigned long addr);
300 extern void             writeb(unsigned char b, unsigned long addr);
301 extern void             writew(unsigned short b, unsigned long addr);
302 extern void             writel(unsigned int b, unsigned long addr);
303
304 #endif /* __KERNEL__ */
305
306 #ifdef __KERNEL__
307
308 /*
309  * On Alpha, we have the whole of I/O space mapped at all times, but
310  * at odd and sometimes discontinuous addresses.  Note that the 
311  * discontinuities are all across busses, so we need not care for that
312  * for any one device.
313  *
314  * The DRM drivers need to be able to map contiguously a (potentially)
315  * discontiguous set of I/O pages. This set of pages is scatter-gather
316  * mapped contiguously from the perspective of the bus, but we can't
317  * directly access DMA addresses from the CPU, these addresses need to
318  * have a real ioremap. Therefore, iounmap and the size argument to
319  * ioremap are needed to give the platforms the ability to fully implement
320  * ioremap.
321  *
322  * Map the I/O space address into the kernel's virtual address space.
323  */
324 static inline void * ioremap(unsigned long offset, unsigned long size)
325 {
326         return (void *) __ioremap(offset, size);
327
328
329 static inline void iounmap(void *addr)
330 {
331         __iounmap(addr);
332 }
333
334 static inline void * ioremap_nocache(unsigned long offset, unsigned long size)
335 {
336         return ioremap(offset, size);
337
338
339 /* Indirect back to the macros provided.  */
340
341 extern u8               ___raw_readb(unsigned long addr);
342 extern u16              ___raw_readw(unsigned long addr);
343 extern u32              ___raw_readl(unsigned long addr);
344 extern u64              ___raw_readq(unsigned long addr);
345 extern void             ___raw_writeb(u8 b, unsigned long addr);
346 extern void             ___raw_writew(u16 b, unsigned long addr);
347 extern void             ___raw_writel(u32 b, unsigned long addr);
348 extern void             ___raw_writeq(u64 b, unsigned long addr);
349
350 #ifdef __raw_readb
351 # define readb(a)       ({ u8 r_ = __raw_readb(a); mb(); r_; })
352 #endif
353 #ifdef __raw_readw
354 # define readw(a)       ({ u16 r_ = __raw_readw(a); mb(); r_; })
355 #endif
356 #ifdef __raw_readl
357 # define readl(a)       ({ u32 r_ = __raw_readl(a); mb(); r_; })
358 #endif
359 #ifdef __raw_readq
360 # define readq(a)       ({ u64 r_ = __raw_readq(a); mb(); r_; })
361 #endif
362
363 #ifdef __raw_writeb
364 # define writeb(v,a)    ({ __raw_writeb((v),(a)); mb(); })
365 #endif
366 #ifdef __raw_writew
367 # define writew(v,a)    ({ __raw_writew((v),(a)); mb(); })
368 #endif
369 #ifdef __raw_writel
370 # define writel(v,a)    ({ __raw_writel((v),(a)); mb(); })
371 #endif
372 #ifdef __raw_writeq
373 # define writeq(v,a)    ({ __raw_writeq((v),(a)); mb(); })
374 #endif
375
376 #ifndef __raw_readb
377 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
378 #endif
379 #ifndef __raw_readw
380 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
381 #endif
382 #ifndef __raw_readl
383 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
384 #endif
385 #ifndef __raw_readq
386 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
387 #endif
388
389 #ifndef __raw_writeb
390 # define __raw_writeb(v,a)  ___raw_writeb((v),(unsigned long)(a))
391 #endif
392 #ifndef __raw_writew
393 # define __raw_writew(v,a)  ___raw_writew((v),(unsigned long)(a))
394 #endif
395 #ifndef __raw_writel
396 # define __raw_writel(v,a)  ___raw_writel((v),(unsigned long)(a))
397 #endif
398 #ifndef __raw_writeq
399 # define __raw_writeq(v,a)  ___raw_writeq((v),(unsigned long)(a))
400 #endif
401
402 #ifndef readb
403 # define readb(a)       _readb((unsigned long)(a))
404 #endif
405 #ifndef readw
406 # define readw(a)       _readw((unsigned long)(a))
407 #endif
408 #ifndef readl
409 # define readl(a)       _readl((unsigned long)(a))
410 #endif
411 #ifndef readq
412 # define readq(a)       _readq((unsigned long)(a))
413 #endif
414
415 #define readb_relaxed(addr) readb(addr)
416 #define readw_relaxed(addr) readw(addr)
417 #define readl_relaxed(addr) readl(addr)
418 #define readq_relaxed(addr) readq(addr)
419
420 #ifndef writeb
421 # define writeb(v,a)    _writeb((v),(unsigned long)(a))
422 #endif
423 #ifndef writew
424 # define writew(v,a)    _writew((v),(unsigned long)(a))
425 #endif
426 #ifndef writel
427 # define writel(v,a)    _writel((v),(unsigned long)(a))
428 #endif
429 #ifndef writeq
430 # define writeq(v,a)    _writeq((v),(unsigned long)(a))
431 #endif
432
433 /*
434  * String version of IO memory access ops:
435  */
436 extern void _memcpy_fromio(void *, unsigned long, long);
437 extern void _memcpy_toio(unsigned long, const void *, long);
438 extern void _memset_c_io(unsigned long, unsigned long, long);
439
440 #define memcpy_fromio(to,from,len) \
441   _memcpy_fromio((to),(unsigned long)(from),(len))
442 #define memcpy_toio(to,from,len) \
443   _memcpy_toio((unsigned long)(to),(from),(len))
444 #define memset_io(addr,c,len) \
445   _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
446
447 #define __HAVE_ARCH_MEMSETW_IO
448 #define memsetw_io(addr,c,len) \
449   _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
450
451 /*
452  * String versions of in/out ops:
453  */
454 extern void insb (unsigned long port, void *dst, unsigned long count);
455 extern void insw (unsigned long port, void *dst, unsigned long count);
456 extern void insl (unsigned long port, void *dst, unsigned long count);
457 extern void outsb (unsigned long port, const void *src, unsigned long count);
458 extern void outsw (unsigned long port, const void *src, unsigned long count);
459 extern void outsl (unsigned long port, const void *src, unsigned long count);
460
461 /*
462  * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and 
463  * just copy it. The net code will then do the checksum later. Presently 
464  * only used by some shared memory 8390 Ethernet cards anyway.
465  */
466
467 #define eth_io_copy_and_sum(skb,src,len,unused) \
468   memcpy_fromio((skb)->data,(src),(len))
469
470 #define isa_eth_io_copy_and_sum(skb,src,len,unused) \
471   isa_memcpy_fromio((skb)->data,(src),(len))
472
473 static inline int
474 check_signature(unsigned long io_addr, const unsigned char *signature,
475                 int length)
476 {
477         int retval = 0;
478         do {
479                 if (readb(io_addr) != *signature)
480                         goto out;
481                 io_addr++;
482                 signature++;
483                 length--;
484         } while (length);
485         retval = 1;
486 out:
487         return retval;
488 }
489
490
491 /*
492  * ISA space is mapped to some machine-specific location on Alpha.
493  * Call into the existing hooks to get the address translated.
494  */
495 #define isa_readb(a)                    readb(__ioremap((a),1))
496 #define isa_readw(a)                    readw(__ioremap((a),2))
497 #define isa_readl(a)                    readl(__ioremap((a),4))
498 #define isa_writeb(b,a)                 writeb((b),__ioremap((a),1))
499 #define isa_writew(w,a)                 writew((w),__ioremap((a),2))
500 #define isa_writel(l,a)                 writel((l),__ioremap((a),4))
501 #define isa_memset_io(a,b,c)            memset_io(__ioremap((a),(c)),(b),(c))
502 #define isa_memcpy_fromio(a,b,c)        memcpy_fromio((a),__ioremap((b),(c)),(c))
503 #define isa_memcpy_toio(a,b,c)          memcpy_toio(__ioremap((a),(c)),(b),(c))
504
505 static inline int
506 isa_check_signature(unsigned long io_addr, const unsigned char *signature,
507                 int length)
508 {
509         int retval = 0;
510         do {
511                 if (isa_readb(io_addr) != *signature)
512                         goto out;
513                 io_addr++;
514                 signature++;
515                 length--;
516         } while (length);
517         retval = 1;
518 out:
519         return retval;
520 }
521
522
523 /*
524  * The Alpha Jensen hardware for some rather strange reason puts
525  * the RTC clock at 0x170 instead of 0x70. Probably due to some
526  * misguided idea about using 0x70 for NMI stuff.
527  *
528  * These defines will override the defaults when doing RTC queries
529  */
530
531 #ifdef CONFIG_ALPHA_GENERIC
532 # define RTC_PORT(x)    ((x) + alpha_mv.rtc_port)
533 #else
534 # ifdef CONFIG_ALPHA_JENSEN
535 #  define RTC_PORT(x)   (0x170+(x))
536 # else
537 #  define RTC_PORT(x)   (0x70 + (x))
538 # endif
539 #endif
540 #define RTC_ALWAYS_BCD  0
541
542 /* Nothing to do */
543
544 #define dma_cache_inv(_start,_size)             do { } while (0)
545 #define dma_cache_wback(_start,_size)           do { } while (0)
546 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
547
548 #endif /* __KERNEL__ */
549
550 #endif /* __ALPHA_IO_H */