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)
9 * Virtual -> physical identity mapping starts at this offset
11 #ifdef USE_48_BIT_KSEG
12 #define IDENT_ADDR 0xffff800000000000
14 #define IDENT_ADDR 0xfffffc0000000000
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <asm/system.h>
21 #include <asm/machvec.h>
22 #include <asm/hwrpb.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
31 static inline void __set_hae(unsigned long new_hae)
34 __save_and_cli(flags);
36 alpha_mv.hae_cache = new_hae;
37 *alpha_mv.hae_register = new_hae;
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)
52 * Change virtual addresses to physical addresses and vv.
54 #ifdef USE_48_BIT_KSEG
55 static inline unsigned long virt_to_phys(void *address)
57 return (unsigned long)address - IDENT_ADDR;
60 static inline void * phys_to_virt(unsigned long address)
62 return (void *) (address + IDENT_ADDR);
65 static inline unsigned long virt_to_phys(void *address)
67 unsigned long phys = (unsigned long)address;
69 /* Sign-extend from bit 41. */
71 phys = (long)phys >> (64 - 41);
73 /* Crop to the physical address width of the processor. */
74 phys &= (1ul << hwrpb->pa_bits) - 1;
79 static inline void * phys_to_virt(unsigned long address)
81 return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
85 #define page_to_phys(page) PAGE_TO_PA(page)
88 * Change addresses as seen by the kernel (virtual) to addresses as
89 * seen by a device (bus), and vice versa.
91 * Note that this only works for a limited range of kernel addresses,
92 * and very well may not span all memory. Consider this interface
93 * deprecated in favour of the mapping functions in <asm/pci.h>.
95 extern unsigned long __direct_map_base;
96 extern unsigned long __direct_map_size;
98 static inline unsigned long virt_to_bus(void *address)
100 unsigned long phys = virt_to_phys(address);
101 unsigned long bus = phys + __direct_map_base;
102 return phys <= __direct_map_size ? bus : 0;
105 static inline void *bus_to_virt(unsigned long address)
109 /* This check is a sanity check but also ensures that bus address 0
110 maps to virtual address 0 which is useful to detect null pointers
111 (the NCR driver is much simpler if NULL pointers are preserved). */
112 address -= __direct_map_base;
113 virt = phys_to_virt(address);
114 return (long)address <= 0 ? NULL : virt;
117 #else /* !__KERNEL__ */
120 * Define actual functions in private name-space so it's easier to
121 * accommodate things like XFree or svgalib that like to define their
122 * own versions of inb etc.
124 extern void __sethae (unsigned long addr); /* syscall */
125 extern void _sethae (unsigned long addr); /* cached version */
127 #endif /* !__KERNEL__ */
130 * There are different chipsets to interface the Alpha CPUs to the world.
134 #ifdef CONFIG_ALPHA_GENERIC
136 /* In a generic kernel, we always go through the machine vector. */
138 # define __inb(p) alpha_mv.mv_inb((unsigned long)(p))
139 # define __inw(p) alpha_mv.mv_inw((unsigned long)(p))
140 # define __inl(p) alpha_mv.mv_inl((unsigned long)(p))
141 # define __outb(x,p) alpha_mv.mv_outb((x),(unsigned long)(p))
142 # define __outw(x,p) alpha_mv.mv_outw((x),(unsigned long)(p))
143 # define __outl(x,p) alpha_mv.mv_outl((x),(unsigned long)(p))
145 # define __readb(a) alpha_mv.mv_readb((unsigned long)(a))
146 # define __readw(a) alpha_mv.mv_readw((unsigned long)(a))
147 # define __readl(a) alpha_mv.mv_readl((unsigned long)(a))
148 # define __readq(a) alpha_mv.mv_readq((unsigned long)(a))
149 # define __writeb(v,a) alpha_mv.mv_writeb((v),(unsigned long)(a))
150 # define __writew(v,a) alpha_mv.mv_writew((v),(unsigned long)(a))
151 # define __writel(v,a) alpha_mv.mv_writel((v),(unsigned long)(a))
152 # define __writeq(v,a) alpha_mv.mv_writeq((v),(unsigned long)(a))
154 # define __ioremap(a,s) alpha_mv.mv_ioremap((unsigned long)(a),(s))
155 # define __iounmap(a) alpha_mv.mv_iounmap((unsigned long)(a))
156 # define __is_ioaddr(a) alpha_mv.mv_is_ioaddr((unsigned long)(a))
165 # define __raw_readb __readb
166 # define __raw_readw __readw
167 # define __raw_readl __readl
168 # define __raw_readq __readq
169 # define __raw_writeb __writeb
170 # define __raw_writew __writew
171 # define __raw_writel __writel
172 # define __raw_writeq __writeq
176 /* Control how and what gets defined within the core logic headers. */
177 #define __WANT_IO_DEF
179 #if defined(CONFIG_ALPHA_APECS)
180 # include <asm/core_apecs.h>
181 #elif defined(CONFIG_ALPHA_CIA)
182 # include <asm/core_cia.h>
183 #elif defined(CONFIG_ALPHA_IRONGATE)
184 # include <asm/core_irongate.h>
185 #elif defined(CONFIG_ALPHA_JENSEN)
186 # include <asm/jensen.h>
187 #elif defined(CONFIG_ALPHA_LCA)
188 # include <asm/core_lca.h>
189 #elif defined(CONFIG_ALPHA_MARVEL)
190 # include <asm/core_marvel.h>
191 #elif defined(CONFIG_ALPHA_MCPCIA)
192 # include <asm/core_mcpcia.h>
193 #elif defined(CONFIG_ALPHA_POLARIS)
194 # include <asm/core_polaris.h>
195 #elif defined(CONFIG_ALPHA_T2)
196 # include <asm/core_t2.h>
197 #elif defined(CONFIG_ALPHA_TSUNAMI)
198 # include <asm/core_tsunami.h>
199 #elif defined(CONFIG_ALPHA_TITAN)
200 # include <asm/core_titan.h>
201 #elif defined(CONFIG_ALPHA_WILDFIRE)
202 # include <asm/core_wildfire.h>
204 #error "What system is this?"
210 #endif /* __KERNEL__ */
213 * The convention used for inb/outb etc. is that names starting with
214 * two underscores are the inline versions, names starting with a
215 * single underscore are proper functions, and names starting with a
216 * letter are macros that map in some way to inline or proper function
217 * versions. Not all that pretty, but before you change it, be sure
218 * to convince yourself that it won't break anything (in particular
221 extern u8 _inb (unsigned long port);
222 extern u16 _inw (unsigned long port);
223 extern u32 _inl (unsigned long port);
224 extern void _outb (u8 b,unsigned long port);
225 extern void _outw (u16 w,unsigned long port);
226 extern void _outl (u32 l,unsigned long port);
227 extern u8 _readb(unsigned long addr);
228 extern u16 _readw(unsigned long addr);
229 extern u32 _readl(unsigned long addr);
230 extern u64 _readq(unsigned long addr);
231 extern void _writeb(u8 b, unsigned long addr);
232 extern void _writew(u16 b, unsigned long addr);
233 extern void _writel(u32 b, unsigned long addr);
234 extern void _writeq(u64 b, unsigned long addr);
238 * The platform header files may define some of these macros to use
239 * the inlined versions where appropriate. These macros may also be
240 * redefined by userlevel programs.
243 # define inb(p) _inb(p)
246 # define inw(p) _inw(p)
249 # define inl(p) _inl(p)
252 # define outb(b,p) _outb((b),(p))
255 # define outw(w,p) _outw((w),(p))
258 # define outl(l,p) _outl((l),(p))
281 #define IO_SPACE_LIMIT 0xffff
285 /* Userspace declarations. Kill in 2.5. */
287 extern unsigned int inb(unsigned long port);
288 extern unsigned int inw(unsigned long port);
289 extern unsigned int inl(unsigned long port);
290 extern void outb(unsigned char b,unsigned long port);
291 extern void outw(unsigned short w,unsigned long port);
292 extern void outl(unsigned int l,unsigned long port);
293 extern unsigned long readb(unsigned long addr);
294 extern unsigned long readw(unsigned long addr);
295 extern unsigned long readl(unsigned long addr);
296 extern void writeb(unsigned char b, unsigned long addr);
297 extern void writew(unsigned short b, unsigned long addr);
298 extern void writel(unsigned int b, unsigned long addr);
300 #endif /* __KERNEL__ */
305 * On Alpha, we have the whole of I/O space mapped at all times, but
306 * at odd and sometimes discontinuous addresses. Note that the
307 * discontinuities are all across busses, so we need not care for that
308 * for any one device.
310 * The DRM drivers need to be able to map contiguously a (potentially)
311 * discontiguous set of I/O pages. This set of pages is scatter-gather
312 * mapped contiguously from the perspective of the bus, but we can't
313 * directly access DMA addresses from the CPU, these addresses need to
314 * have a real ioremap. Therefore, iounmap and the size argument to
315 * ioremap are needed to give the platforms the ability to fully implement
318 * Map the I/O space address into the kernel's virtual address space.
320 static inline void * ioremap(unsigned long offset, unsigned long size)
322 return (void *) __ioremap(offset, size);
325 static inline void iounmap(void *addr)
330 static inline void * ioremap_nocache(unsigned long offset, unsigned long size)
332 return ioremap(offset, size);
335 /* Indirect back to the macros provided. */
337 extern u8 ___raw_readb(unsigned long addr);
338 extern u16 ___raw_readw(unsigned long addr);
339 extern u32 ___raw_readl(unsigned long addr);
340 extern u64 ___raw_readq(unsigned long addr);
341 extern void ___raw_writeb(u8 b, unsigned long addr);
342 extern void ___raw_writew(u16 b, unsigned long addr);
343 extern void ___raw_writel(u32 b, unsigned long addr);
344 extern void ___raw_writeq(u64 b, unsigned long addr);
347 # define readb(a) ({ u8 r_ = __raw_readb(a); mb(); r_; })
350 # define readw(a) ({ u16 r_ = __raw_readw(a); mb(); r_; })
353 # define readl(a) ({ u32 r_ = __raw_readl(a); mb(); r_; })
356 # define readq(a) ({ u64 r_ = __raw_readq(a); mb(); r_; })
360 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
363 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
366 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
369 # define writeq(v,a) ({ __raw_writeq((v),(a)); mb(); })
373 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
376 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
379 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
382 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
386 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
389 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
392 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
395 # define __raw_writeq(v,a) ___raw_writeq((v),(unsigned long)(a))
399 # define readb(a) _readb((unsigned long)(a))
402 # define readw(a) _readw((unsigned long)(a))
405 # define readl(a) _readl((unsigned long)(a))
408 # define readq(a) _readq((unsigned long)(a))
412 # define writeb(v,a) _writeb((v),(unsigned long)(a))
415 # define writew(v,a) _writew((v),(unsigned long)(a))
418 # define writel(v,a) _writel((v),(unsigned long)(a))
421 # define writeq(v,a) _writeq((v),(unsigned long)(a))
425 * String version of IO memory access ops:
427 extern void _memcpy_fromio(void *, unsigned long, long);
428 extern void _memcpy_toio(unsigned long, const void *, long);
429 extern void _memset_c_io(unsigned long, unsigned long, long);
431 #define memcpy_fromio(to,from,len) \
432 _memcpy_fromio((to),(unsigned long)(from),(len))
433 #define memcpy_toio(to,from,len) \
434 _memcpy_toio((unsigned long)(to),(from),(len))
435 #define memset_io(addr,c,len) \
436 _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
438 #define __HAVE_ARCH_MEMSETW_IO
439 #define memsetw_io(addr,c,len) \
440 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
443 * String versions of in/out ops:
445 extern void insb (unsigned long port, void *dst, unsigned long count);
446 extern void insw (unsigned long port, void *dst, unsigned long count);
447 extern void insl (unsigned long port, void *dst, unsigned long count);
448 extern void outsb (unsigned long port, const void *src, unsigned long count);
449 extern void outsw (unsigned long port, const void *src, unsigned long count);
450 extern void outsl (unsigned long port, const void *src, unsigned long count);
453 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
454 * just copy it. The net code will then do the checksum later. Presently
455 * only used by some shared memory 8390 Ethernet cards anyway.
458 #define eth_io_copy_and_sum(skb,src,len,unused) \
459 memcpy_fromio((skb)->data,(src),(len))
462 check_signature(unsigned long io_addr, const unsigned char *signature,
467 if (readb(io_addr) != *signature)
480 * ISA space is mapped to some machine-specific location on Alpha.
481 * Call into the existing hooks to get the address translated.
483 #define isa_readb(a) readb(__ioremap((a),1))
484 #define isa_readw(a) readw(__ioremap((a),2))
485 #define isa_readl(a) readl(__ioremap((a),4))
486 #define isa_writeb(b,a) writeb((b),__ioremap((a),1))
487 #define isa_writew(w,a) writew((w),__ioremap((a),2))
488 #define isa_writel(l,a) writel((l),__ioremap((a),4))
489 #define isa_memset_io(a,b,c) memset_io(__ioremap((a),(c)),(b),(c))
490 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),__ioremap((b),(c)),(c))
491 #define isa_memcpy_toio(a,b,c) memcpy_toio(__ioremap((a),(c)),(b),(c))
494 isa_check_signature(unsigned long io_addr, const unsigned char *signature,
499 if (isa_readb(io_addr) != *signature)
512 * The Alpha Jensen hardware for some rather strange reason puts
513 * the RTC clock at 0x170 instead of 0x70. Probably due to some
514 * misguided idea about using 0x70 for NMI stuff.
516 * These defines will override the defaults when doing RTC queries
519 #ifdef CONFIG_ALPHA_GENERIC
520 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
522 # ifdef CONFIG_ALPHA_JENSEN
523 # define RTC_PORT(x) (0x170+(x))
525 # define RTC_PORT(x) (0x70 + (x))
528 #define RTC_ALWAYS_BCD 0
532 #define dma_cache_inv(_start,_size) do { } while (0)
533 #define dma_cache_wback(_start,_size) do { } while (0)
534 #define dma_cache_wback_inv(_start,_size) do { } while (0)
536 #endif /* __KERNEL__ */
538 #endif /* __ALPHA_IO_H */