1 #ifndef __ALPHA_IO_H
2 #define __ALPHA_IO_H
3
4 #include <linux/config.h>
5 #include <linux/kernel.h>
6 #include <asm/system.h>
7
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)
11
12 /*
13 * Virtual -> physical identity mapping starts at this offset
14 */
15 #ifdef USE_48_BIT_KSEG
16 #define IDENT_ADDR 0xffff800000000000
17 #else
18 #define IDENT_ADDR 0xfffffc0000000000
19 #endif
20
21 #ifdef __KERNEL__
22 #include <asm/machvec.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 */
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
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 static inline unsigned long virt_to_phys(void *address)
55 {
56 return (unsigned long)address - IDENT_ADDR;
57 }
58
59 static inline void * phys_to_virt(unsigned long address)
60 {
61 return (void *) (address + IDENT_ADDR);
62 }
63
64 /*
65 * Change addresses as seen by the kernel (virtual) to addresses as
66 * seen by a device (bus), and vice versa.
67 *
68 * Note that this only works for a limited range of kernel addresses,
69 * and very well may not span all memory. Consider this interface
70 * deprecated in favour of the mapping functions in <asm/pci.h>.
71 */
72 extern unsigned long __direct_map_base;
73 extern unsigned long __direct_map_size;
74
75 static inline unsigned long virt_to_bus(void *address)
76 {
77 unsigned long phys = virt_to_phys(address);
78 unsigned long bus = phys + __direct_map_base;
79 return phys <= __direct_map_size ? bus : 0;
80 }
81
82 static inline void *bus_to_virt(unsigned long address)
83 {
84 void *virt;
85
86 /* This check is a sanity check but also ensures that bus address 0
87 maps to virtual address 0 which is useful to detect null pointers
88 (the NCR driver is much simpler if NULL pointers are preserved). */
89 address -= __direct_map_base;
90 virt = phys_to_virt(address);
91 return (long)address <= 0 ? NULL : virt;
92 }
93
94 #else /* !__KERNEL__ */
95
96 /*
97 * Define actual functions in private name-space so it's easier to
98 * accommodate things like XFree or svgalib that like to define their
99 * own versions of inb etc.
100 */
101 extern void __sethae (unsigned long addr); /* syscall */
102 extern void _sethae (unsigned long addr); /* cached version */
103
104 #endif /* !__KERNEL__ */
105
106 /*
107 * There are different chipsets to interface the Alpha CPUs to the world.
108 */
109
110 #ifdef __KERNEL__
111 #ifdef CONFIG_ALPHA_GENERIC
112
113 /* In a generic kernel, we always go through the machine vector. */
114
115 # define __inb(p) alpha_mv.mv_inb((unsigned long)(p))
116 # define __inw(p) alpha_mv.mv_inw((unsigned long)(p))
117 # define __inl(p) alpha_mv.mv_inl((unsigned long)(p))
118 # define __outb(x,p) alpha_mv.mv_outb((x),(unsigned long)(p))
119 # define __outw(x,p) alpha_mv.mv_outw((x),(unsigned long)(p))
120 # define __outl(x,p) alpha_mv.mv_outl((x),(unsigned long)(p))
121
122 # define __readb(a) alpha_mv.mv_readb((unsigned long)(a))
123 # define __readw(a) alpha_mv.mv_readw((unsigned long)(a))
124 # define __readl(a) alpha_mv.mv_readl((unsigned long)(a))
125 # define __readq(a) alpha_mv.mv_readq((unsigned long)(a))
126 # define __writeb(v,a) alpha_mv.mv_writeb((v),(unsigned long)(a))
127 # define __writew(v,a) alpha_mv.mv_writew((v),(unsigned long)(a))
128 # define __writel(v,a) alpha_mv.mv_writel((v),(unsigned long)(a))
129 # define __writeq(v,a) alpha_mv.mv_writeq((v),(unsigned long)(a))
130
131 # define __ioremap(a) alpha_mv.mv_ioremap((unsigned long)(a))
132 # define __is_ioaddr(a) alpha_mv.mv_is_ioaddr((unsigned long)(a))
133
134 # define inb __inb
135 # define inw __inw
136 # define inl __inl
137 # define outb __outb
138 # define outw __outw
139 # define outl __outl
140
141 # define __raw_readb __readb
142 # define __raw_readw __readw
143 # define __raw_readl __readl
144 # define __raw_readq __readq
145 # define __raw_writeb __writeb
146 # define __raw_writew __writew
147 # define __raw_writel __writel
148 # define __raw_writeq __writeq
149
150 #else
151
152 /* Control how and what gets defined within the core logic headers. */
153 #define __WANT_IO_DEF
154
155 #if defined(CONFIG_ALPHA_APECS)
156 # include <asm/core_apecs.h>
157 #elif defined(CONFIG_ALPHA_CIA)
158 # include <asm/core_cia.h>
159 #elif defined(CONFIG_ALPHA_IRONGATE)
160 # include <asm/core_irongate.h>
161 #elif defined(CONFIG_ALPHA_JENSEN)
162 # include <asm/jensen.h>
163 #elif defined(CONFIG_ALPHA_LCA)
164 # include <asm/core_lca.h>
165 #elif defined(CONFIG_ALPHA_MCPCIA)
166 # include <asm/core_mcpcia.h>
167 #elif defined(CONFIG_ALPHA_POLARIS)
168 # include <asm/core_polaris.h>
169 #elif defined(CONFIG_ALPHA_T2)
170 # include <asm/core_t2.h>
171 #elif defined(CONFIG_ALPHA_TSUNAMI)
172 # include <asm/core_tsunami.h>
173 #elif defined(CONFIG_ALPHA_TITAN)
174 # include <asm/core_titan.h>
175 #elif defined(CONFIG_ALPHA_WILDFIRE)
176 # include <asm/core_wildfire.h>
177 #else
178 #error "What system is this?"
179 #endif
180
181 #undef __WANT_IO_DEF
182
183 #endif /* GENERIC */
184 #endif /* __KERNEL__ */
185
186 /*
187 * The convention used for inb/outb etc. is that names starting with
188 * two underscores are the inline versions, names starting with a
189 * single underscore are proper functions, and names starting with a
190 * letter are macros that map in some way to inline or proper function
191 * versions. Not all that pretty, but before you change it, be sure
192 * to convince yourself that it won't break anything (in particular
193 * module support).
194 */
195 extern unsigned int _inb (unsigned long port);
196 extern unsigned int _inw (unsigned long port);
197 extern unsigned int _inl (unsigned long port);
198 extern void _outb (unsigned char b,unsigned long port);
199 extern void _outw (unsigned short w,unsigned long port);
200 extern void _outl (unsigned int l,unsigned long port);
201 extern unsigned long _readb(unsigned long addr);
202 extern unsigned long _readw(unsigned long addr);
203 extern unsigned long _readl(unsigned long addr);
204 extern unsigned long _readq(unsigned long addr);
205 extern void _writeb(unsigned char b, unsigned long addr);
206 extern void _writew(unsigned short b, unsigned long addr);
207 extern void _writel(unsigned int b, unsigned long addr);
208 extern void _writeq(unsigned long b, unsigned long addr);
209
210 #ifdef __KERNEL__
211 /*
212 * The platform header files may define some of these macros to use
213 * the inlined versions where appropriate. These macros may also be
214 * redefined by userlevel programs.
215 */
216 #ifndef inb
217 # define inb(p) _inb(p)
218 #endif
219 #ifndef inw
220 # define inw(p) _inw(p)
221 #endif
222 #ifndef inl
223 # define inl(p) _inl(p)
224 #endif
225 #ifndef outb
226 # define outb(b,p) _outb((b),(p))
227 #endif
228 #ifndef outw
229 # define outw(w,p) _outw((w),(p))
230 #endif
231 #ifndef outl
232 # define outl(l,p) _outl((l),(p))
233 #endif
234
235 #ifndef inb_p
236 # define inb_p inb
237 #endif
238 #ifndef inw_p
239 # define inw_p inw
240 #endif
241 #ifndef inl_p
242 # define inl_p inl
243 #endif
244
245 #ifndef outb_p
246 # define outb_p outb
247 #endif
248 #ifndef outw_p
249 # define outw_p outw
250 #endif
251 #ifndef outl_p
252 # define outl_p outl
253 #endif
254
255 #define IO_SPACE_LIMIT 0xffff
256
257 #else
258
259 /* Userspace declarations. */
260
261 extern unsigned int inb(unsigned long port);
262 extern unsigned int inw(unsigned long port);
263 extern unsigned int inl(unsigned long port);
264 extern void outb(unsigned char b,unsigned long port);
265 extern void outw(unsigned short w,unsigned long port);
266 extern void outl(unsigned int l,unsigned long port);
267 extern unsigned long readb(unsigned long addr);
268 extern unsigned long readw(unsigned long addr);
269 extern unsigned long readl(unsigned long addr);
270 extern void writeb(unsigned char b, unsigned long addr);
271 extern void writew(unsigned short b, unsigned long addr);
272 extern void writel(unsigned int b, unsigned long addr);
273
274 #endif /* __KERNEL__ */
275
276 #ifdef __KERNEL__
277
278 /*
279 * On Alpha, we have the whole of I/O space mapped at all times, but
280 * at odd and sometimes discontinuous addresses. Note that the
281 * discontinuities are all across busses, so we need not care for that
282 * for any one device.
283 *
284 * Map the I/O space address into the kernel's virtual address space.
285 */
286 static inline void * ioremap(unsigned long offset, unsigned long size)
287 {
288 return (void *) __ioremap(offset);
289 }
290
291 static inline void iounmap(void *addr)
292 {
293 }
294
295 static inline void * ioremap_nocache(unsigned long offset, unsigned long size)
296 {
297 return ioremap(offset, size);
298 }
299
300 /* Indirect back to the macros provided. */
301
302 extern unsigned long ___raw_readb(unsigned long addr);
303 extern unsigned long ___raw_readw(unsigned long addr);
304 extern unsigned long ___raw_readl(unsigned long addr);
305 extern unsigned long ___raw_readq(unsigned long addr);
306 extern void ___raw_writeb(unsigned char b, unsigned long addr);
307 extern void ___raw_writew(unsigned short b, unsigned long addr);
308 extern void ___raw_writel(unsigned int b, unsigned long addr);
309 extern void ___raw_writeq(unsigned long b, unsigned long addr);
310
311 #ifdef __raw_readb
312 # define readb(a) ({ unsigned long r_ = __raw_readb(a); mb(); r_; })
313 #endif
314 #ifdef __raw_readw
315 # define readw(a) ({ unsigned long r_ = __raw_readw(a); mb(); r_; })
316 #endif
317 #ifdef __raw_readl
318 # define readl(a) ({ unsigned long r_ = __raw_readl(a); mb(); r_; })
319 #endif
320 #ifdef __raw_readq
321 # define readq(a) ({ unsigned long r_ = __raw_readq(a); mb(); r_; })
322 #endif
323
324 #ifdef __raw_writeb
325 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
326 #endif
327 #ifdef __raw_writew
328 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
329 #endif
330 #ifdef __raw_writel
331 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
332 #endif
333 #ifdef __raw_writeq
334 # define writeq(v,a) ({ __raw_writeq((v),(a)); mb(); })
335 #endif
336
337 #ifndef __raw_readb
338 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
339 #endif
340 #ifndef __raw_readw
341 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
342 #endif
343 #ifndef __raw_readl
344 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
345 #endif
346 #ifndef __raw_readq
347 # define __raw_readq(a) ___raw_readq((unsigned long)(a))
348 #endif
349
350 #ifndef __raw_writeb
351 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
352 #endif
353 #ifndef __raw_writew
354 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
355 #endif
356 #ifndef __raw_writel
357 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
358 #endif
359 #ifndef __raw_writeq
360 # define __raw_writeq(v,a) ___raw_writeq((v),(unsigned long)(a))
361 #endif
362
363 #ifndef readb
364 # define readb(a) _readb((unsigned long)(a))
365 #endif
366 #ifndef readw
367 # define readw(a) _readw((unsigned long)(a))
368 #endif
369 #ifndef readl
370 # define readl(a) _readl((unsigned long)(a))
371 #endif
372 #ifndef readq
373 # define readq(a) _readq((unsigned long)(a))
374 #endif
375
376 #ifndef writeb
377 # define writeb(v,a) _writeb((v),(unsigned long)(a))
378 #endif
379 #ifndef writew
380 # define writew(v,a) _writew((v),(unsigned long)(a))
381 #endif
382 #ifndef writel
383 # define writel(v,a) _writel((v),(unsigned long)(a))
384 #endif
385 #ifndef writeq
386 # define writeq(v,a) _writeq((v),(unsigned long)(a))
387 #endif
388
389 /*
390 * String version of IO memory access ops:
391 */
392 extern void _memcpy_fromio(void *, unsigned long, long);
393 extern void _memcpy_toio(unsigned long, const void *, long);
394 extern void _memset_c_io(unsigned long, unsigned long, long);
395
396 #define memcpy_fromio(to,from,len) \
397 _memcpy_fromio((to),(unsigned long)(from),(len))
398 #define memcpy_toio(to,from,len) \
399 _memcpy_toio((unsigned long)(to),(from),(len))
400 #define memset_io(addr,c,len) \
401 _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
402
403 #define __HAVE_ARCH_MEMSETW_IO
404 #define memsetw_io(addr,c,len) \
405 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
406
407 /*
408 * String versions of in/out ops:
409 */
410 extern void insb (unsigned long port, void *dst, unsigned long count);
411 extern void insw (unsigned long port, void *dst, unsigned long count);
412 extern void insl (unsigned long port, void *dst, unsigned long count);
413 extern void outsb (unsigned long port, const void *src, unsigned long count);
414 extern void outsw (unsigned long port, const void *src, unsigned long count);
415 extern void outsl (unsigned long port, const void *src, unsigned long count);
416
417 /*
418 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
419 * just copy it. The net code will then do the checksum later. Presently
420 * only used by some shared memory 8390 Ethernet cards anyway.
421 */
422
423 #define eth_io_copy_and_sum(skb,src,len,unused) \
424 memcpy_fromio((skb)->data,(src),(len))
425
426 static inline int
427 check_signature(unsigned long io_addr, const unsigned char *signature,
428 int length)
429 {
430 int retval = 0;
431 do {
432 if (readb(io_addr) != *signature)
433 goto out;
434 io_addr++;
435 signature++;
436 length--;
437 } while (length);
438 retval = 1;
439 out:
440 return retval;
441 }
442
443 /*
444 * The Alpha Jensen hardware for some rather strange reason puts
445 * the RTC clock at 0x170 instead of 0x70. Probably due to some
446 * misguided idea about using 0x70 for NMI stuff.
447 *
448 * These defines will override the defaults when doing RTC queries
449 */
450
451 #ifdef CONFIG_ALPHA_GENERIC
452 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
453 #else
454 # ifdef CONFIG_ALPHA_JENSEN
455 # define RTC_PORT(x) (0x170+(x))
456 # else
457 # define RTC_PORT(x) (0x70 + (x))
458 # endif
459 #endif
460 #define RTC_ALWAYS_BCD 0
461
462 /* Nothing to do */
463
464 #define dma_cache_inv(_start,_size) do { } while (0)
465 #define dma_cache_wback(_start,_size) do { } while (0)
466 #define dma_cache_wback_inv(_start,_size) do { } while (0)
467
468 #endif /* __KERNEL__ */
469
470 #endif /* __ALPHA_IO_H */
471
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.