diff options
Diffstat (limited to 'include/asm-powerpc/io.h')
-rw-r--r-- | include/asm-powerpc/io.h | 462 |
1 files changed, 462 insertions, 0 deletions
diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h new file mode 100644 index 000000000000..48938d84d055 --- /dev/null +++ b/include/asm-powerpc/io.h | |||
@@ -0,0 +1,462 @@ | |||
1 | #ifndef _ASM_POWERPC_IO_H | ||
2 | #define _ASM_POWERPC_IO_H | ||
3 | |||
4 | /* | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version | ||
8 | * 2 of the License, or (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #ifndef CONFIG_PPC64 | ||
12 | #include <asm-ppc/io.h> | ||
13 | #else | ||
14 | |||
15 | #include <linux/compiler.h> | ||
16 | #include <asm/page.h> | ||
17 | #include <asm/byteorder.h> | ||
18 | #ifdef CONFIG_PPC_ISERIES | ||
19 | #include <asm/iseries/iseries_io.h> | ||
20 | #endif | ||
21 | #include <asm/synch.h> | ||
22 | #include <asm/delay.h> | ||
23 | |||
24 | #include <asm-generic/iomap.h> | ||
25 | |||
26 | #define __ide_mm_insw(p, a, c) _insw_ns((volatile u16 __iomem *)(p), (a), (c)) | ||
27 | #define __ide_mm_insl(p, a, c) _insl_ns((volatile u32 __iomem *)(p), (a), (c)) | ||
28 | #define __ide_mm_outsw(p, a, c) _outsw_ns((volatile u16 __iomem *)(p), (a), (c)) | ||
29 | #define __ide_mm_outsl(p, a, c) _outsl_ns((volatile u32 __iomem *)(p), (a), (c)) | ||
30 | |||
31 | |||
32 | #define SIO_CONFIG_RA 0x398 | ||
33 | #define SIO_CONFIG_RD 0x399 | ||
34 | |||
35 | #define SLOW_DOWN_IO | ||
36 | |||
37 | extern unsigned long isa_io_base; | ||
38 | extern unsigned long pci_io_base; | ||
39 | extern unsigned long io_page_mask; | ||
40 | |||
41 | #define MAX_ISA_PORT 0x10000 | ||
42 | |||
43 | #define _IO_IS_VALID(port) ((port) >= MAX_ISA_PORT || (1 << (port>>PAGE_SHIFT)) \ | ||
44 | & io_page_mask) | ||
45 | |||
46 | #ifdef CONFIG_PPC_ISERIES | ||
47 | /* __raw_* accessors aren't supported on iSeries */ | ||
48 | #define __raw_readb(addr) { BUG(); 0; } | ||
49 | #define __raw_readw(addr) { BUG(); 0; } | ||
50 | #define __raw_readl(addr) { BUG(); 0; } | ||
51 | #define __raw_readq(addr) { BUG(); 0; } | ||
52 | #define __raw_writeb(v, addr) { BUG(); 0; } | ||
53 | #define __raw_writew(v, addr) { BUG(); 0; } | ||
54 | #define __raw_writel(v, addr) { BUG(); 0; } | ||
55 | #define __raw_writeq(v, addr) { BUG(); 0; } | ||
56 | #define readb(addr) iSeries_Read_Byte(addr) | ||
57 | #define readw(addr) iSeries_Read_Word(addr) | ||
58 | #define readl(addr) iSeries_Read_Long(addr) | ||
59 | #define writeb(data, addr) iSeries_Write_Byte((data),(addr)) | ||
60 | #define writew(data, addr) iSeries_Write_Word((data),(addr)) | ||
61 | #define writel(data, addr) iSeries_Write_Long((data),(addr)) | ||
62 | #define memset_io(a,b,c) iSeries_memset_io((a),(b),(c)) | ||
63 | #define memcpy_fromio(a,b,c) iSeries_memcpy_fromio((a), (b), (c)) | ||
64 | #define memcpy_toio(a,b,c) iSeries_memcpy_toio((a), (b), (c)) | ||
65 | |||
66 | #define inb(addr) readb(((void __iomem *)(long)(addr))) | ||
67 | #define inw(addr) readw(((void __iomem *)(long)(addr))) | ||
68 | #define inl(addr) readl(((void __iomem *)(long)(addr))) | ||
69 | #define outb(data,addr) writeb(data,((void __iomem *)(long)(addr))) | ||
70 | #define outw(data,addr) writew(data,((void __iomem *)(long)(addr))) | ||
71 | #define outl(data,addr) writel(data,((void __iomem *)(long)(addr))) | ||
72 | /* | ||
73 | * The *_ns versions below don't do byte-swapping. | ||
74 | * Neither do the standard versions now, these are just here | ||
75 | * for older code. | ||
76 | */ | ||
77 | #define insw_ns(port, buf, ns) _insw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns)) | ||
78 | #define insl_ns(port, buf, nl) _insl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl)) | ||
79 | #else | ||
80 | |||
81 | static inline unsigned char __raw_readb(const volatile void __iomem *addr) | ||
82 | { | ||
83 | return *(volatile unsigned char __force *)addr; | ||
84 | } | ||
85 | static inline unsigned short __raw_readw(const volatile void __iomem *addr) | ||
86 | { | ||
87 | return *(volatile unsigned short __force *)addr; | ||
88 | } | ||
89 | static inline unsigned int __raw_readl(const volatile void __iomem *addr) | ||
90 | { | ||
91 | return *(volatile unsigned int __force *)addr; | ||
92 | } | ||
93 | static inline unsigned long __raw_readq(const volatile void __iomem *addr) | ||
94 | { | ||
95 | return *(volatile unsigned long __force *)addr; | ||
96 | } | ||
97 | static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr) | ||
98 | { | ||
99 | *(volatile unsigned char __force *)addr = v; | ||
100 | } | ||
101 | static inline void __raw_writew(unsigned short v, volatile void __iomem *addr) | ||
102 | { | ||
103 | *(volatile unsigned short __force *)addr = v; | ||
104 | } | ||
105 | static inline void __raw_writel(unsigned int v, volatile void __iomem *addr) | ||
106 | { | ||
107 | *(volatile unsigned int __force *)addr = v; | ||
108 | } | ||
109 | static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr) | ||
110 | { | ||
111 | *(volatile unsigned long __force *)addr = v; | ||
112 | } | ||
113 | #define readb(addr) eeh_readb(addr) | ||
114 | #define readw(addr) eeh_readw(addr) | ||
115 | #define readl(addr) eeh_readl(addr) | ||
116 | #define readq(addr) eeh_readq(addr) | ||
117 | #define writeb(data, addr) eeh_writeb((data), (addr)) | ||
118 | #define writew(data, addr) eeh_writew((data), (addr)) | ||
119 | #define writel(data, addr) eeh_writel((data), (addr)) | ||
120 | #define writeq(data, addr) eeh_writeq((data), (addr)) | ||
121 | #define memset_io(a,b,c) eeh_memset_io((a),(b),(c)) | ||
122 | #define memcpy_fromio(a,b,c) eeh_memcpy_fromio((a),(b),(c)) | ||
123 | #define memcpy_toio(a,b,c) eeh_memcpy_toio((a),(b),(c)) | ||
124 | #define inb(port) eeh_inb((unsigned long)port) | ||
125 | #define outb(val, port) eeh_outb(val, (unsigned long)port) | ||
126 | #define inw(port) eeh_inw((unsigned long)port) | ||
127 | #define outw(val, port) eeh_outw(val, (unsigned long)port) | ||
128 | #define inl(port) eeh_inl((unsigned long)port) | ||
129 | #define outl(val, port) eeh_outl(val, (unsigned long)port) | ||
130 | |||
131 | /* | ||
132 | * The insw/outsw/insl/outsl macros don't do byte-swapping. | ||
133 | * They are only used in practice for transferring buffers which | ||
134 | * are arrays of bytes, and byte-swapping is not appropriate in | ||
135 | * that case. - paulus */ | ||
136 | #define insb(port, buf, ns) eeh_insb((port), (buf), (ns)) | ||
137 | #define insw(port, buf, ns) eeh_insw_ns((port), (buf), (ns)) | ||
138 | #define insl(port, buf, nl) eeh_insl_ns((port), (buf), (nl)) | ||
139 | #define insw_ns(port, buf, ns) eeh_insw_ns((port), (buf), (ns)) | ||
140 | #define insl_ns(port, buf, nl) eeh_insl_ns((port), (buf), (nl)) | ||
141 | |||
142 | #define outsb(port, buf, ns) _outsb((u8 __iomem *)((port)+pci_io_base), (buf), (ns)) | ||
143 | #define outsw(port, buf, ns) _outsw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns)) | ||
144 | #define outsl(port, buf, nl) _outsl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl)) | ||
145 | |||
146 | #endif | ||
147 | |||
148 | #define readb_relaxed(addr) readb(addr) | ||
149 | #define readw_relaxed(addr) readw(addr) | ||
150 | #define readl_relaxed(addr) readl(addr) | ||
151 | #define readq_relaxed(addr) readq(addr) | ||
152 | |||
153 | extern void _insb(volatile u8 __iomem *port, void *buf, int ns); | ||
154 | extern void _outsb(volatile u8 __iomem *port, const void *buf, int ns); | ||
155 | extern void _insw(volatile u16 __iomem *port, void *buf, int ns); | ||
156 | extern void _outsw(volatile u16 __iomem *port, const void *buf, int ns); | ||
157 | extern void _insl(volatile u32 __iomem *port, void *buf, int nl); | ||
158 | extern void _outsl(volatile u32 __iomem *port, const void *buf, int nl); | ||
159 | extern void _insw_ns(volatile u16 __iomem *port, void *buf, int ns); | ||
160 | extern void _outsw_ns(volatile u16 __iomem *port, const void *buf, int ns); | ||
161 | extern void _insl_ns(volatile u32 __iomem *port, void *buf, int nl); | ||
162 | extern void _outsl_ns(volatile u32 __iomem *port, const void *buf, int nl); | ||
163 | |||
164 | #define mmiowb() | ||
165 | |||
166 | /* | ||
167 | * output pause versions need a delay at least for the | ||
168 | * w83c105 ide controller in a p610. | ||
169 | */ | ||
170 | #define inb_p(port) inb(port) | ||
171 | #define outb_p(val, port) (udelay(1), outb((val), (port))) | ||
172 | #define inw_p(port) inw(port) | ||
173 | #define outw_p(val, port) (udelay(1), outw((val), (port))) | ||
174 | #define inl_p(port) inl(port) | ||
175 | #define outl_p(val, port) (udelay(1), outl((val), (port))) | ||
176 | |||
177 | /* | ||
178 | * The *_ns versions below don't do byte-swapping. | ||
179 | * Neither do the standard versions now, these are just here | ||
180 | * for older code. | ||
181 | */ | ||
182 | #define outsw_ns(port, buf, ns) _outsw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns)) | ||
183 | #define outsl_ns(port, buf, nl) _outsl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl)) | ||
184 | |||
185 | |||
186 | #define IO_SPACE_LIMIT ~(0UL) | ||
187 | |||
188 | |||
189 | #ifdef __KERNEL__ | ||
190 | extern int __ioremap_explicit(unsigned long p_addr, unsigned long v_addr, | ||
191 | unsigned long size, unsigned long flags); | ||
192 | extern void __iomem *__ioremap(unsigned long address, unsigned long size, | ||
193 | unsigned long flags); | ||
194 | |||
195 | /** | ||
196 | * ioremap - map bus memory into CPU space | ||
197 | * @address: bus address of the memory | ||
198 | * @size: size of the resource to map | ||
199 | * | ||
200 | * ioremap performs a platform specific sequence of operations to | ||
201 | * make bus memory CPU accessible via the readb/readw/readl/writeb/ | ||
202 | * writew/writel functions and the other mmio helpers. The returned | ||
203 | * address is not guaranteed to be usable directly as a virtual | ||
204 | * address. | ||
205 | */ | ||
206 | extern void __iomem *ioremap(unsigned long address, unsigned long size); | ||
207 | |||
208 | #define ioremap_nocache(addr, size) ioremap((addr), (size)) | ||
209 | extern int iounmap_explicit(volatile void __iomem *addr, unsigned long size); | ||
210 | extern void iounmap(volatile void __iomem *addr); | ||
211 | extern void __iomem * reserve_phb_iospace(unsigned long size); | ||
212 | |||
213 | /** | ||
214 | * virt_to_phys - map virtual addresses to physical | ||
215 | * @address: address to remap | ||
216 | * | ||
217 | * The returned physical address is the physical (CPU) mapping for | ||
218 | * the memory address given. It is only valid to use this function on | ||
219 | * addresses directly mapped or allocated via kmalloc. | ||
220 | * | ||
221 | * This function does not give bus mappings for DMA transfers. In | ||
222 | * almost all conceivable cases a device driver should not be using | ||
223 | * this function | ||
224 | */ | ||
225 | static inline unsigned long virt_to_phys(volatile void * address) | ||
226 | { | ||
227 | return __pa((unsigned long)address); | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * phys_to_virt - map physical address to virtual | ||
232 | * @address: address to remap | ||
233 | * | ||
234 | * The returned virtual address is a current CPU mapping for | ||
235 | * the memory address given. It is only valid to use this function on | ||
236 | * addresses that have a kernel mapping | ||
237 | * | ||
238 | * This function does not handle bus mappings for DMA transfers. In | ||
239 | * almost all conceivable cases a device driver should not be using | ||
240 | * this function | ||
241 | */ | ||
242 | static inline void * phys_to_virt(unsigned long address) | ||
243 | { | ||
244 | return (void *)__va(address); | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Change "struct page" to physical address. | ||
249 | */ | ||
250 | #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) | ||
251 | |||
252 | /* We do NOT want virtual merging, it would put too much pressure on | ||
253 | * our iommu allocator. Instead, we want drivers to be smart enough | ||
254 | * to coalesce sglists that happen to have been mapped in a contiguous | ||
255 | * way by the iommu | ||
256 | */ | ||
257 | #define BIO_VMERGE_BOUNDARY 0 | ||
258 | |||
259 | #endif /* __KERNEL__ */ | ||
260 | |||
261 | static inline void iosync(void) | ||
262 | { | ||
263 | __asm__ __volatile__ ("sync" : : : "memory"); | ||
264 | } | ||
265 | |||
266 | /* Enforce in-order execution of data I/O. | ||
267 | * No distinction between read/write on PPC; use eieio for all three. | ||
268 | */ | ||
269 | #define iobarrier_rw() eieio() | ||
270 | #define iobarrier_r() eieio() | ||
271 | #define iobarrier_w() eieio() | ||
272 | |||
273 | /* | ||
274 | * 8, 16 and 32 bit, big and little endian I/O operations, with barrier. | ||
275 | * These routines do not perform EEH-related I/O address translation, | ||
276 | * and should not be used directly by device drivers. Use inb/readb | ||
277 | * instead. | ||
278 | */ | ||
279 | static inline int in_8(const volatile unsigned char __iomem *addr) | ||
280 | { | ||
281 | int ret; | ||
282 | |||
283 | __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync" | ||
284 | : "=r" (ret) : "m" (*addr)); | ||
285 | return ret; | ||
286 | } | ||
287 | |||
288 | static inline void out_8(volatile unsigned char __iomem *addr, int val) | ||
289 | { | ||
290 | __asm__ __volatile__("stb%U0%X0 %1,%0; sync" | ||
291 | : "=m" (*addr) : "r" (val)); | ||
292 | } | ||
293 | |||
294 | static inline int in_le16(const volatile unsigned short __iomem *addr) | ||
295 | { | ||
296 | int ret; | ||
297 | |||
298 | __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync" | ||
299 | : "=r" (ret) : "r" (addr), "m" (*addr)); | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static inline int in_be16(const volatile unsigned short __iomem *addr) | ||
304 | { | ||
305 | int ret; | ||
306 | |||
307 | __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync" | ||
308 | : "=r" (ret) : "m" (*addr)); | ||
309 | return ret; | ||
310 | } | ||
311 | |||
312 | static inline void out_le16(volatile unsigned short __iomem *addr, int val) | ||
313 | { | ||
314 | __asm__ __volatile__("sthbrx %1,0,%2; sync" | ||
315 | : "=m" (*addr) : "r" (val), "r" (addr)); | ||
316 | } | ||
317 | |||
318 | static inline void out_be16(volatile unsigned short __iomem *addr, int val) | ||
319 | { | ||
320 | __asm__ __volatile__("sth%U0%X0 %1,%0; sync" | ||
321 | : "=m" (*addr) : "r" (val)); | ||
322 | } | ||
323 | |||
324 | static inline unsigned in_le32(const volatile unsigned __iomem *addr) | ||
325 | { | ||
326 | unsigned ret; | ||
327 | |||
328 | __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync" | ||
329 | : "=r" (ret) : "r" (addr), "m" (*addr)); | ||
330 | return ret; | ||
331 | } | ||
332 | |||
333 | static inline unsigned in_be32(const volatile unsigned __iomem *addr) | ||
334 | { | ||
335 | unsigned ret; | ||
336 | |||
337 | __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync" | ||
338 | : "=r" (ret) : "m" (*addr)); | ||
339 | return ret; | ||
340 | } | ||
341 | |||
342 | static inline void out_le32(volatile unsigned __iomem *addr, int val) | ||
343 | { | ||
344 | __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr) | ||
345 | : "r" (val), "r" (addr)); | ||
346 | } | ||
347 | |||
348 | static inline void out_be32(volatile unsigned __iomem *addr, int val) | ||
349 | { | ||
350 | __asm__ __volatile__("stw%U0%X0 %1,%0; sync" | ||
351 | : "=m" (*addr) : "r" (val)); | ||
352 | } | ||
353 | |||
354 | static inline unsigned long in_le64(const volatile unsigned long __iomem *addr) | ||
355 | { | ||
356 | unsigned long tmp, ret; | ||
357 | |||
358 | __asm__ __volatile__( | ||
359 | "ld %1,0(%2)\n" | ||
360 | "twi 0,%1,0\n" | ||
361 | "isync\n" | ||
362 | "rldimi %0,%1,5*8,1*8\n" | ||
363 | "rldimi %0,%1,3*8,2*8\n" | ||
364 | "rldimi %0,%1,1*8,3*8\n" | ||
365 | "rldimi %0,%1,7*8,4*8\n" | ||
366 | "rldicl %1,%1,32,0\n" | ||
367 | "rlwimi %0,%1,8,8,31\n" | ||
368 | "rlwimi %0,%1,24,16,23\n" | ||
369 | : "=r" (ret) , "=r" (tmp) : "b" (addr) , "m" (*addr)); | ||
370 | return ret; | ||
371 | } | ||
372 | |||
373 | static inline unsigned long in_be64(const volatile unsigned long __iomem *addr) | ||
374 | { | ||
375 | unsigned long ret; | ||
376 | |||
377 | __asm__ __volatile__("ld%U1%X1 %0,%1; twi 0,%0,0; isync" | ||
378 | : "=r" (ret) : "m" (*addr)); | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static inline void out_le64(volatile unsigned long __iomem *addr, unsigned long val) | ||
383 | { | ||
384 | unsigned long tmp; | ||
385 | |||
386 | __asm__ __volatile__( | ||
387 | "rldimi %0,%1,5*8,1*8\n" | ||
388 | "rldimi %0,%1,3*8,2*8\n" | ||
389 | "rldimi %0,%1,1*8,3*8\n" | ||
390 | "rldimi %0,%1,7*8,4*8\n" | ||
391 | "rldicl %1,%1,32,0\n" | ||
392 | "rlwimi %0,%1,8,8,31\n" | ||
393 | "rlwimi %0,%1,24,16,23\n" | ||
394 | "std %0,0(%3)\n" | ||
395 | "sync" | ||
396 | : "=&r" (tmp) , "=&r" (val) : "1" (val) , "b" (addr) , "m" (*addr)); | ||
397 | } | ||
398 | |||
399 | static inline void out_be64(volatile unsigned long __iomem *addr, unsigned long val) | ||
400 | { | ||
401 | __asm__ __volatile__("std%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val)); | ||
402 | } | ||
403 | |||
404 | #ifndef CONFIG_PPC_ISERIES | ||
405 | #include <asm/eeh.h> | ||
406 | #endif | ||
407 | |||
408 | #ifdef __KERNEL__ | ||
409 | |||
410 | /** | ||
411 | * check_signature - find BIOS signatures | ||
412 | * @io_addr: mmio address to check | ||
413 | * @signature: signature block | ||
414 | * @length: length of signature | ||
415 | * | ||
416 | * Perform a signature comparison with the mmio address io_addr. This | ||
417 | * address should have been obtained by ioremap. | ||
418 | * Returns 1 on a match. | ||
419 | */ | ||
420 | static inline int check_signature(const volatile void __iomem * io_addr, | ||
421 | const unsigned char *signature, int length) | ||
422 | { | ||
423 | int retval = 0; | ||
424 | #ifndef CONFIG_PPC_ISERIES | ||
425 | do { | ||
426 | if (readb(io_addr) != *signature) | ||
427 | goto out; | ||
428 | io_addr++; | ||
429 | signature++; | ||
430 | length--; | ||
431 | } while (length); | ||
432 | retval = 1; | ||
433 | out: | ||
434 | #endif | ||
435 | return retval; | ||
436 | } | ||
437 | |||
438 | /* Nothing to do */ | ||
439 | |||
440 | #define dma_cache_inv(_start,_size) do { } while (0) | ||
441 | #define dma_cache_wback(_start,_size) do { } while (0) | ||
442 | #define dma_cache_wback_inv(_start,_size) do { } while (0) | ||
443 | |||
444 | /* Check of existence of legacy devices */ | ||
445 | extern int check_legacy_ioport(unsigned long base_port); | ||
446 | |||
447 | |||
448 | /* | ||
449 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem | ||
450 | * access | ||
451 | */ | ||
452 | #define xlate_dev_mem_ptr(p) __va(p) | ||
453 | |||
454 | /* | ||
455 | * Convert a virtual cached pointer to an uncached pointer | ||
456 | */ | ||
457 | #define xlate_dev_kmem_ptr(p) p | ||
458 | |||
459 | #endif /* __KERNEL__ */ | ||
460 | |||
461 | #endif /* CONFIG_PPC64 */ | ||
462 | #endif /* _ASM_POWERPC_IO_H */ | ||