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 0xffff800000000000UL
14 #define IDENT_ADDR 0xfffffc0000000000UL
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>
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
32 static inline void __set_hae(unsigned long new_hae)
35 local_irq_save(flags);
37 alpha_mv.hae_cache = new_hae;
38 *alpha_mv.hae_register = new_hae;
40 /* Re-read to make sure it was written. */
41 new_hae = *alpha_mv.hae_register;
43 local_irq_restore(flags);
46 static inline void set_hae(unsigned long new_hae)
48 if (new_hae != alpha_mv.hae_cache)
53 * Change virtual addresses to physical addresses and vv.
55 #ifdef USE_48_BIT_KSEG
56 static inline unsigned long virt_to_phys(void *address)
58 return (unsigned long)address - IDENT_ADDR;
61 static inline void * phys_to_virt(unsigned long address)
63 return (void *) (address + IDENT_ADDR);
66 static inline unsigned long virt_to_phys(void *address)
68 unsigned long phys = (unsigned long)address;
70 /* Sign-extend from bit 41. */
72 phys = (long)phys >> (64 - 41);
74 /* Crop to the physical address width of the processor. */
75 phys &= (1ul << hwrpb->pa_bits) - 1;
80 static inline void * phys_to_virt(unsigned long address)
82 return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
86 #define page_to_phys(page) page_to_pa(page)
88 /* This depends on working iommu. */
89 #define BIO_VMERGE_BOUNDARY (alpha_mv.mv_pci_tbi ? PAGE_SIZE : 0)
92 * Change addresses as seen by the kernel (virtual) to addresses as
93 * seen by a device (bus), and vice versa.
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>.
99 extern unsigned long __direct_map_base;
100 extern unsigned long __direct_map_size;
102 static inline unsigned long virt_to_bus(void *address)
104 unsigned long phys = virt_to_phys(address);
105 unsigned long bus = phys + __direct_map_base;
106 return phys <= __direct_map_size ? bus : 0;
109 static inline void *bus_to_virt(unsigned long address)
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;
121 #else /* !__KERNEL__ */
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.
128 extern void __sethae (unsigned long addr); /* syscall */
129 extern void _sethae (unsigned long addr); /* cached version */
131 #endif /* !__KERNEL__ */
134 * There are different chipsets to interface the Alpha CPUs to the world.
138 #ifdef CONFIG_ALPHA_GENERIC
140 /* In a generic kernel, we always go through the machine vector. */
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))
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))
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))
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
180 /* Control how and what gets defined within the core logic headers. */
181 #define __WANT_IO_DEF
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>
208 #error "What system is this?"
214 #endif /* __KERNEL__ */
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
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);
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.
247 # define inb(p) _inb(p)
250 # define inw(p) _inw(p)
253 # define inl(p) _inl(p)
256 # define outb(b,p) _outb((b),(p))
259 # define outw(w,p) _outw((w),(p))
262 # define outl(l,p) _outl((l),(p))
285 #define IO_SPACE_LIMIT 0xffff
289 /* Userspace declarations. Kill in 2.5. */
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);
304 #endif /* __KERNEL__ */
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.
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
322 * Map the I/O space address into the kernel's virtual address space.
324 static inline void * ioremap(unsigned long offset, unsigned long size)
326 return (void *) __ioremap(offset, size);
329 static inline void iounmap(void *addr)
334 static inline void * ioremap_nocache(unsigned long offset, unsigned long size)
336 return ioremap(offset, size);
339 /* Indirect back to the macros provided. */
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);
351 # define readb(a) ({ u8 r_ = __raw_readb(a); mb(); r_; })
354 # define readw(a) ({ u16 r_ = __raw_readw(a); mb(); r_; })
357 # define readl(a) ({ u32 r_ = __raw_readl(a); mb(); r_; })
360 # define readq(a) ({ u64 r_ = __raw_readq(a); mb(); r_; })
364 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
367 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
370 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
373 # define writeq(v,a) ({ __raw_writeq((v),(a)); mb(); })
377 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
380 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
383 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
386 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
390 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
393 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
396 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
399 # define __raw_writeq(v,a) ___raw_writeq((v),(unsigned long)(a))
403 # define readb(a) _readb((unsigned long)(a))
406 # define readw(a) _readw((unsigned long)(a))
409 # define readl(a) _readl((unsigned long)(a))
412 # define readq(a) _readq((unsigned long)(a))
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)
421 # define writeb(v,a) _writeb((v),(unsigned long)(a))
424 # define writew(v,a) _writew((v),(unsigned long)(a))
427 # define writel(v,a) _writel((v),(unsigned long)(a))
430 # define writeq(v,a) _writeq((v),(unsigned long)(a))
434 * String version of IO memory access ops:
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);
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))
447 #define __HAVE_ARCH_MEMSETW_IO
448 #define memsetw_io(addr,c,len) \
449 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
452 * String versions of in/out ops:
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);
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.
467 #define eth_io_copy_and_sum(skb,src,len,unused) \
468 memcpy_fromio((skb)->data,(src),(len))
470 #define isa_eth_io_copy_and_sum(skb,src,len,unused) \
471 isa_memcpy_fromio((skb)->data,(src),(len))
474 check_signature(unsigned long io_addr, const unsigned char *signature,
479 if (readb(io_addr) != *signature)
492 * ISA space is mapped to some machine-specific location on Alpha.
493 * Call into the existing hooks to get the address translated.
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))
506 isa_check_signature(unsigned long io_addr, const unsigned char *signature,
511 if (isa_readb(io_addr) != *signature)
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.
528 * These defines will override the defaults when doing RTC queries
531 #ifdef CONFIG_ALPHA_GENERIC
532 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
534 # ifdef CONFIG_ALPHA_JENSEN
535 # define RTC_PORT(x) (0x170+(x))
537 # define RTC_PORT(x) (0x70 + (x))
540 #define RTC_ALWAYS_BCD 0
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)
548 #endif /* __KERNEL__ */
550 #endif /* __ALPHA_IO_H */