Linux-2.3.3 and a short hiatus..
[davej-history.git] / include / asm-alpha / io.h
blobf908f74640adf7d9b30296fcd98a45955af34632
1 #ifndef __ALPHA_IO_H
2 #define __ALPHA_IO_H
4 #include <linux/config.h>
5 #include <asm/system.h>
7 /* We don't use IO slowdowns on the Alpha, but.. */
8 #define __SLOW_DOWN_IO do { } while (0)
9 #define SLOW_DOWN_IO do { } while (0)
12 * Virtual -> physical identity mapping starts at this offset
14 #ifdef USE_48_BIT_KSEG
15 #define IDENT_ADDR 0xffff800000000000
16 #else
17 #define IDENT_ADDR 0xfffffc0000000000
18 #endif
20 #ifdef __KERNEL__
21 #include <asm/machvec.h>
24 * We try to avoid hae updates (thus the cache), but when we
25 * do need to update the hae, we need to do it atomically, so
26 * that any interrupts wouldn't get confused with the hae
27 * register not being up-to-date with respect to the hardware
28 * value.
30 static inline void __set_hae(unsigned long new_hae)
32 unsigned long ipl = swpipl(7);
34 alpha_mv.hae_cache = new_hae;
35 *alpha_mv.hae_register = new_hae;
36 mb();
38 /* Re-read to make sure it was written. */
39 new_hae = *alpha_mv.hae_register;
40 setipl(ipl);
43 static inline void set_hae(unsigned long new_hae)
45 if (new_hae != alpha_mv.hae_cache)
46 __set_hae(new_hae);
50 * Change virtual addresses to physical addresses and vv.
52 static inline unsigned long virt_to_phys(volatile void * address)
54 /* Conditionalize this on the CPU? This here is 40 bits,
55 whereas EV4 only supports 34. But KSEG is farther out
56 so it shouldn't _really_ matter. */
57 return 0xffffffffffUL & (unsigned long) address;
60 static inline void * phys_to_virt(unsigned long address)
62 return (void *) (address + IDENT_ADDR);
65 #else /* !__KERNEL__ */
68 * Define actual functions in private name-space so it's easier to
69 * accommodate things like XFree or svgalib that like to define their
70 * own versions of inb etc.
72 extern void __sethae (unsigned long addr); /* syscall */
73 extern void _sethae (unsigned long addr); /* cached version */
75 #endif /* !__KERNEL__ */
78 * There are different chipsets to interface the Alpha CPUs to the world.
81 #ifdef __KERNEL__
82 #ifdef CONFIG_ALPHA_GENERIC
84 /* In a generic kernel, we always go through the machine vector. */
86 # define virt_to_bus(a) alpha_mv.mv_virt_to_bus(a)
87 # define bus_to_virt(a) alpha_mv.mv_bus_to_virt(a)
89 # define __inb alpha_mv.mv_inb
90 # define __inw alpha_mv.mv_inw
91 # define __inl alpha_mv.mv_inl
92 # define __outb alpha_mv.mv_outb
93 # define __outw alpha_mv.mv_outw
94 # define __outl alpha_mv.mv_outl
96 # define __readb(a) alpha_mv.mv_readb((unsigned long)(a))
97 # define __readw(a) alpha_mv.mv_readw((unsigned long)(a))
98 # define __readl(a) alpha_mv.mv_readl((unsigned long)(a))
99 # define __readq(a) alpha_mv.mv_readq((unsigned long)(a))
100 # define __writeb(v,a) alpha_mv.mv_writeb((v),(unsigned long)(a))
101 # define __writew(v,a) alpha_mv.mv_writew((v),(unsigned long)(a))
102 # define __writel(v,a) alpha_mv.mv_writel((v),(unsigned long)(a))
103 # define __writeq(v,a) alpha_mv.mv_writeq((v),(unsigned long)(a))
105 # define inb __inb
106 # define inw __inw
107 # define inl __inl
108 # define outb __outb
109 # define outw __outw
110 # define outl __outl
112 # define readb __readb
113 # define readw __readw
114 # define readl __readl
115 # define readq __readq
116 # define writeb __writeb
117 # define writew __writew
118 # define writel __writel
119 # define writeq __writeq
121 # define dense_mem(a) alpha_mv.mv_dense_mem(a)
123 #else
125 /* Control how and what gets defined within the core logic headers. */
126 #define __WANT_IO_DEF
128 #if defined(CONFIG_ALPHA_APECS)
129 # include <asm/core_apecs.h>
130 #elif defined(CONFIG_ALPHA_CIA)
131 # include <asm/core_cia.h>
132 #elif defined(CONFIG_ALPHA_LCA)
133 # include <asm/core_lca.h>
134 #elif defined(CONFIG_ALPHA_MCPCIA)
135 # include <asm/core_mcpcia.h>
136 #elif defined(CONFIG_ALPHA_PYXIS)
137 # include <asm/core_pyxis.h>
138 #elif defined(CONFIG_ALPHA_T2)
139 # include <asm/core_t2.h>
140 #elif defined(CONFIG_ALPHA_TSUNAMI)
141 # include <asm/core_tsunami.h>
142 #elif defined(CONFIG_ALPHA_JENSEN)
143 # include <asm/jensen.h>
144 #elif defined(CONFIG_ALPHA_RX164)
145 # include <asm/core_polaris.h>
146 #else
147 #error "What system is this?"
148 #endif
150 #undef __WANT_IO_DEF
152 #endif /* GENERIC */
153 #endif /* __KERNEL__ */
156 * The convention used for inb/outb etc. is that names starting with
157 * two underscores are the inline versions, names starting with a
158 * single underscore are proper functions, and names starting with a
159 * letter are macros that map in some way to inline or proper function
160 * versions. Not all that pretty, but before you change it, be sure
161 * to convince yourself that it won't break anything (in particular
162 * module support).
164 extern unsigned int _inb (unsigned long port);
165 extern unsigned int _inw (unsigned long port);
166 extern unsigned int _inl (unsigned long port);
167 extern void _outb (unsigned char b,unsigned long port);
168 extern void _outw (unsigned short w,unsigned long port);
169 extern void _outl (unsigned int l,unsigned long port);
170 extern unsigned long _readb(unsigned long addr);
171 extern unsigned long _readw(unsigned long addr);
172 extern unsigned long _readl(unsigned long addr);
173 extern unsigned long _readq(unsigned long addr);
174 extern void _writeb(unsigned char b, unsigned long addr);
175 extern void _writew(unsigned short b, unsigned long addr);
176 extern void _writel(unsigned int b, unsigned long addr);
177 extern void _writeq(unsigned long b, unsigned long addr);
179 #ifdef __KERNEL__
181 * The platform header files may define some of these macros to use
182 * the inlined versions where appropriate. These macros may also be
183 * redefined by userlevel programs.
185 #ifndef inb
186 # define inb(p) _inb((p))
187 #endif
188 #ifndef inw
189 # define inw(p) _inw((p))
190 #endif
191 #ifndef inl
192 # define inl(p) _inl((p))
193 #endif
194 #ifndef outb
195 # define outb(b,p) _outb((b),(p))
196 #endif
197 #ifndef outw
198 # define outw(w,p) _outw((w),(p))
199 #endif
200 #ifndef outl
201 # define outl(l,p) _outl((l),(p))
202 #endif
204 #ifndef inb_p
205 # define inb_p inb
206 #endif
207 #ifndef inw_p
208 # define inw_p inw
209 #endif
210 #ifndef inl_p
211 # define inl_p inl
212 #endif
214 #ifndef outb_p
215 # define outb_p outb
216 #endif
217 #ifndef outw_p
218 # define outw_p outw
219 #endif
220 #ifndef outl_p
221 # define outl_p outl
222 #endif
224 #else
226 /* Userspace declarations. */
228 extern unsigned int inb (unsigned long port);
229 extern unsigned int inw (unsigned long port);
230 extern unsigned int inl (unsigned long port);
231 extern void outb (unsigned char b,unsigned long port);
232 extern void outw (unsigned short w,unsigned long port);
233 extern void outl (unsigned int l,unsigned long port);
234 extern unsigned long readb(unsigned long addr);
235 extern unsigned long readw(unsigned long addr);
236 extern unsigned long readl(unsigned long addr);
237 extern void writeb(unsigned char b, unsigned long addr);
238 extern void writew(unsigned short b, unsigned long addr);
239 extern void writel(unsigned int b, unsigned long addr);
241 #endif /* __KERNEL__ */
243 #ifdef __KERNEL__
246 * The "address" in IO memory space is not clearly either an integer or a
247 * pointer. We will accept both, thus the casts.
249 * On the alpha, we have the whole physical address space mapped at all
250 * times, so "ioremap()" and "iounmap()" do not need to do anything.
252 static inline void * ioremap(unsigned long offset, unsigned long size)
254 return (void *) offset;
257 static inline void iounmap(void *addr)
261 #ifndef readb
262 # define readb(a) _readb((unsigned long)(a))
263 #endif
264 #ifndef readw
265 # define readw(a) _readw((unsigned long)(a))
266 #endif
267 #ifndef readl
268 # define readl(a) _readl((unsigned long)(a))
269 #endif
270 #ifndef readq
271 # define readq(a) _readq((unsigned long)(a))
272 #endif
273 #ifndef writeb
274 # define writeb(v,a) _writeb((v),(unsigned long)(a))
275 #endif
276 #ifndef writew
277 # define writew(v,a) _writew((v),(unsigned long)(a))
278 #endif
279 #ifndef writel
280 # define writel(v,a) _writel((v),(unsigned long)(a))
281 #endif
282 #ifndef writeq
283 # define writeq(v,a) _writeq((v),(unsigned long)(a))
284 #endif
287 * String version of IO memory access ops:
289 extern void _memcpy_fromio(void *, unsigned long, long);
290 extern void _memcpy_toio(unsigned long, const void *, long);
291 extern void _memset_c_io(unsigned long, unsigned long, long);
293 #define memcpy_fromio(to,from,len) \
294 _memcpy_fromio((to),(unsigned long)(from),(len))
295 #define memcpy_toio(to,from,len) \
296 _memcpy_toio((unsigned long)(to),(from),(len))
297 #define memset_io(addr,c,len) \
298 _memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
300 #define __HAVE_ARCH_MEMSETW_IO
301 #define memsetw_io(addr,c,len) \
302 _memset_c_io((unsigned long)(addr),0x0001000100010001UL*(u16)(c),(len))
305 * String versions of in/out ops:
307 extern void insb (unsigned long port, void *dst, unsigned long count);
308 extern void insw (unsigned long port, void *dst, unsigned long count);
309 extern void insl (unsigned long port, void *dst, unsigned long count);
310 extern void outsb (unsigned long port, const void *src, unsigned long count);
311 extern void outsw (unsigned long port, const void *src, unsigned long count);
312 extern void outsl (unsigned long port, const void *src, unsigned long count);
315 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
316 * just copy it. The net code will then do the checksum later. Presently
317 * only used by some shared memory 8390 Ethernet cards anyway.
320 #define eth_io_copy_and_sum(skb,src,len,unused) \
321 memcpy_fromio((skb)->data,(src),(len))
323 static inline int
324 check_signature(unsigned long io_addr, const unsigned char *signature,
325 int length)
327 int retval = 0;
328 do {
329 if (readb(io_addr) != *signature)
330 goto out;
331 io_addr++;
332 signature++;
333 length--;
334 } while (length);
335 retval = 1;
336 out:
337 return retval;
341 * The Alpha Jensen hardware for some rather strange reason puts
342 * the RTC clock at 0x170 instead of 0x70. Probably due to some
343 * misguided idea about using 0x70 for NMI stuff.
345 * These defines will override the defaults when doing RTC queries
348 #ifdef CONFIG_ALPHA_GENERIC
349 # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
350 #else
351 # ifdef CONFIG_ALPHA_JENSEN
352 # define RTC_PORT(x) (0x170+(x))
353 # else
354 # define RTC_PORT(x) (0x70 + (x))
355 # endif
356 #endif
357 #define RTC_ALWAYS_BCD 0
359 /* Nothing to do */
361 #define dma_cache_inv(_start,_size) do { } while (0)
362 #define dma_cache_wback(_start,_size) do { } while (0)
363 #define dma_cache_wback_inv(_start,_size) do { } while (0)
365 #endif /* __KERNEL__ */
367 #endif /* __ALPHA_IO_H */