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 0xffff800000000000
13 #else
14 #define IDENT_ADDR 0xfffffc0000000000
15 #endif
16
17 #ifdef __KERNEL__
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>
23
24 /*
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.
30 */
__set_hae(unsigned long new_hae)31 static inline void __set_hae(unsigned long new_hae)
32 {
33 unsigned long flags;
34 __save_and_cli(flags);
35
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;
41
42 __restore_flags(flags);
43 }
44
set_hae(unsigned long new_hae)45 static inline void set_hae(unsigned long new_hae)
46 {
47 if (new_hae != alpha_mv.hae_cache)
48 __set_hae(new_hae);
49 }
50
51 /*
52 * Change virtual addresses to physical addresses and vv.
53 */
54 #ifdef USE_48_BIT_KSEG
virt_to_phys(void * address)55 static inline unsigned long virt_to_phys(void *address)
56 {
57 return (unsigned long)address - IDENT_ADDR;
58 }
59
phys_to_virt(unsigned long address)60 static inline void * phys_to_virt(unsigned long address)
61 {
62 return (void *) (address + IDENT_ADDR);
63 }
64 #else
virt_to_phys(void * address)65 static inline unsigned long virt_to_phys(void *address)
66 {
67 unsigned long phys = (unsigned long)address;
68
69 /* Sign-extend from bit 41. */
70 phys <<= (64 - 41);
71 phys = (long)phys >> (64 - 41);
72
73 /* Crop to the physical address width of the processor. */
74 phys &= (1ul << hwrpb->pa_bits) - 1;
75
76 return phys;
77 }
78
phys_to_virt(unsigned long address)79 static inline void * phys_to_virt(unsigned long address)
80 {
81 return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
82 }
83 #endif
84
85 #define page_to_phys(page) PAGE_TO_PA(page)
86
87 /*
88 * Change addresses as seen by the kernel (virtual) to addresses as
89 * seen by a device (bus), and vice versa.
90 *
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>.
94 */
95 extern unsigned long __direct_map_base;
96 extern unsigned long __direct_map_size;
97
virt_to_bus(void * address)98 static inline unsigned long virt_to_bus(void *address)
99 {
100 unsigned long phys = virt_to_phys(address);
101 unsigned long bus = phys + __direct_map_base;
102 return phys <= __direct_map_size ? bus : 0;
103 }
104
bus_to_virt(unsigned long address)105 static inline void *bus_to_virt(unsigned long address)
106 {
107 void *virt;
108
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;
115 }
116
117 #else /* !__KERNEL__ */
118
119 /*
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.
123 */
124 extern void __sethae (unsigned long addr); /* syscall */
125 extern void _sethae (unsigned long addr); /* cached version */
126
127 #endif /* !__KERNEL__ */
128
129 /*
130 * There are different chipsets to interface the Alpha CPUs to the world.
131 */
132
133 #ifdef __KERNEL__
134 #ifdef CONFIG_ALPHA_GENERIC
135
136 /* In a generic kernel, we always go through the machine vector. */
137
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))
144
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))
153
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))
157
158 # define inb __inb
159 # define inw __inw
160 # define inl __inl
161 # define outb __outb
162 # define outw __outw
163 # define outl __outl
164
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
173
174 #else
175
176 /* Control how and what gets defined within the core logic headers. */
177 #define __WANT_IO_DEF
178
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>
203 #else
204 #error "What system is this?"
205 #endif
206
207 #undef __WANT_IO_DEF
208
209 #endif /* GENERIC */
210 #endif /* __KERNEL__ */
211
212 /*
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
219 * module support).
220 */
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);
235
236 #ifdef __KERNEL__
237 /*
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.
241 */
242 #ifndef inb
243 # define inb(p) _inb(p)
244 #endif
245 #ifndef inw
246 # define inw(p) _inw(p)
247 #endif
248 #ifndef inl
249 # define inl(p) _inl(p)
250 #endif
251 #ifndef outb
252 # define outb(b,p) _outb((b),(p))
253 #endif
254 #ifndef outw
255 # define outw(w,p) _outw((w),(p))
256 #endif
257 #ifndef outl
258 # define outl(l,p) _outl((l),(p))
259 #endif
260
261 #ifndef inb_p
262 # define inb_p inb
263 #endif
264 #ifndef inw_p
265 # define inw_p inw
266 #endif
267 #ifndef inl_p
268 # define inl_p inl
269 #endif
270
271 #ifndef outb_p
272 # define outb_p outb
273 #endif
274 #ifndef outw_p
275 # define outw_p outw
276 #endif
277 #ifndef outl_p
278 # define outl_p outl
279 #endif
280
281 #define IO_SPACE_LIMIT 0xffff
282
283 #else
284
285 /* Userspace declarations. Kill in 2.5. */
286
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);
299
300 #endif /* __KERNEL__ */
301
302 #ifdef __KERNEL__
303
304 /*
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.
309 *
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
316 * ioremap.
317 *
318 * Map the I/O space address into the kernel's virtual address space.
319 */
ioremap(unsigned long offset,unsigned long size)320 static inline void * ioremap(unsigned long offset, unsigned long size)
321 {
322 return (void *) __ioremap(offset, size);
323 }
324
iounmap(void * addr)325 static inline void iounmap(void *addr)
326 {
327 __iounmap(addr);
328 }
329
ioremap_nocache(unsigned long offset,unsigned long size)330 static inline void * ioremap_nocache(unsigned long offset, unsigned long size)
331 {
332 return ioremap(offset, size);
333 }
334
335 /* Indirect back to the macros provided. */
336
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);
345
346 #ifdef __raw_readb
347 # define readb(a) ({ u8 r_ = __raw_readb(a); mb(); r_; })
348 #endif
349 #ifdef __raw_readw
350 # define readw(a) ({ u16 r_ = __raw_readw(a); mb(); r_; })
351 #endif
352 #ifdef __raw_readl
353 # define readl(a) ({ u32 r_ = __raw_readl(a); mb(); r_; })
354 #endif
355 #ifdef __raw_readq
356 # define readq(a) ({ u64 r_ = __raw_readq(a); mb(); r_; })
357 #endif
358
359 #ifdef __raw_writeb
360 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
361 #endif
362 #ifdef __raw_writew
363 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
364 #endif
365 #ifdef __raw_writel
366 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
367 #endif
368 #ifdef __raw_writeq
369 # define writeq(v,a) ({ __raw_writeq((v),(a)); mb(); })
370 #endif
371
372 #ifndef __raw_readb
373 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
374 #endif
375 #ifndef __raw_readw
376 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
377 #endif
378 #ifndef __raw_readl
379 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
380 #endif
381 #ifndef __raw_readq
382 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
383 #endif
384
385 #ifndef __raw_writeb
386 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
387 #endif
388 #ifndef __raw_writew
389 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
390 #endif
391 #ifndef __raw_writel
392 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
393 #endif
394 #ifndef __raw_writeq
395 # define __raw_writeq(v,a) ___raw_writeq((v),(unsigned long)(a))
396 #endif
397
398 #ifndef readb
399 # define readb(a) _readb((unsigned long)(a))
400 #endif
401 #ifndef readw
402 # define readw(a) _readw((unsigned long)(a))
403 #endif
404 #ifndef readl
405 # define readl(a) _readl((unsigned long)(a))
406 #endif
407 #ifndef readq
408 # define readq(a) _readq((unsigned long)(a))
409 #endif
410
411 #ifndef writeb
412 # define writeb(v,a) _writeb((v),(unsigned long)(a))
413 #endif
414 #ifndef writew
415 # define writew(v,a) _writew((v),(unsigned long)(a))
416 #endif
417 #ifndef writel
418 # define writel(v,a) _writel((v),(unsigned long)(a))
419 #endif
420 #ifndef writeq
421 # define writeq(v,a) _writeq((v),(unsigned long)(a))
422 #endif
423
424 /*
425 * String version of IO memory access ops:
426 */
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);
430
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))
437
438 #define __HAVE_ARCH_MEMSETW_IO
439 #define memsetw_io(addr,c,len) \
440 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
441
442 /*
443 * String versions of in/out ops:
444 */
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);
451
452 /*
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.
456 */
457
458 #define eth_io_copy_and_sum(skb,src,len,unused) \
459 memcpy_fromio((skb)->data,(src),(len))
460 #define isa_eth_io_copy_and_sum(skb,src,len,unused) \
461 isa_memcpy_fromio((skb)->data,(src),(len))
462
463 static inline int
check_signature(unsigned long io_addr,const unsigned char * signature,int length)464 check_signature(unsigned long io_addr, const unsigned char *signature,
465 int length)
466 {
467 int retval = 0;
468 do {
469 if (readb(io_addr) != *signature)
470 goto out;
471 io_addr++;
472 signature++;
473 length--;
474 } while (length);
475 retval = 1;
476 out:
477 return retval;
478 }
479
480
481 /*
482 * ISA space is mapped to some machine-specific location on Alpha.
483 * Call into the existing hooks to get the address translated.
484 */
485 #define isa_readb(a) readb(__ioremap((a),1))
486 #define isa_readw(a) readw(__ioremap((a),2))
487 #define isa_readl(a) readl(__ioremap((a),4))
488 #define isa_writeb(b,a) writeb((b),__ioremap((a),1))
489 #define isa_writew(w,a) writew((w),__ioremap((a),2))
490 #define isa_writel(l,a) writel((l),__ioremap((a),4))
491 #define isa_memset_io(a,b,c) memset_io(__ioremap((a),(c)),(b),(c))
492 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),__ioremap((b),(c)),(c))
493 #define isa_memcpy_toio(a,b,c) memcpy_toio(__ioremap((a),(c)),(b),(c))
494
495 static inline int
isa_check_signature(unsigned long io_addr,const unsigned char * signature,int length)496 isa_check_signature(unsigned long io_addr, const unsigned char *signature,
497 int length)
498 {
499 int retval = 0;
500 do {
501 if (isa_readb(io_addr) != *signature)
502 goto out;
503 io_addr++;
504 signature++;
505 length--;
506 } while (length);
507 retval = 1;
508 out:
509 return retval;
510 }
511
512
513 /*
514 * The Alpha Jensen hardware for some rather strange reason puts
515 * the RTC clock at 0x170 instead of 0x70. Probably due to some
516 * misguided idea about using 0x70 for NMI stuff.
517 *
518 * These defines will override the defaults when doing RTC queries
519 */
520
521 #ifdef CONFIG_ALPHA_GENERIC
522 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
523 #else
524 # ifdef CONFIG_ALPHA_JENSEN
525 # define RTC_PORT(x) (0x170+(x))
526 # else
527 # define RTC_PORT(x) (0x70 + (x))
528 # endif
529 #endif
530 #define RTC_ALWAYS_BCD 0
531
532 /* Nothing to do */
533
534 #define dma_cache_inv(_start,_size) do { } while (0)
535 #define dma_cache_wback(_start,_size) do { } while (0)
536 #define dma_cache_wback_inv(_start,_size) do { } while (0)
537
538 #endif /* __KERNEL__ */
539
540 #endif /* __ALPHA_IO_H */
541