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.
11 #include <linux/config.h>
13 #include <asm/byteorder.h>
14 #ifdef CONFIG_PPC_ISERIES
15 #include <asm/iSeries/iSeries_io.h>
17 #include <asm/memory.h>
18 #include <asm/delay.h>
20 #define __ide_mm_insw(p, a, c) _insw_ns((volatile u16 *)(p), (a), (c))
21 #define __ide_mm_insl(p, a, c) _insl_ns((volatile u32 *)(p), (a), (c))
22 #define __ide_mm_outsw(p, a, c) _outsw_ns((volatile u16 *)(p), (a), (c))
23 #define __ide_mm_outsl(p, a, c) _outsl_ns((volatile u32 *)(p), (a), (c))
26 #define SIO_CONFIG_RA 0x398
27 #define SIO_CONFIG_RD 0x399
31 extern unsigned long isa_io_base;
32 extern unsigned long pci_io_base;
34 #ifdef CONFIG_PPC_ISERIES
35 /* __raw_* accessors aren't supported on iSeries */
36 #define __raw_readb(addr) { BUG(); 0; }
37 #define __raw_readw(addr) { BUG(); 0; }
38 #define __raw_readl(addr) { BUG(); 0; }
39 #define __raw_readq(addr) { BUG(); 0; }
40 #define __raw_writeb(v, addr) { BUG(); 0; }
41 #define __raw_writew(v, addr) { BUG(); 0; }
42 #define __raw_writel(v, addr) { BUG(); 0; }
43 #define __raw_writeq(v, addr) { BUG(); 0; }
44 #define readb(addr) iSeries_Read_Byte((void*)(addr))
45 #define readw(addr) iSeries_Read_Word((void*)(addr))
46 #define readl(addr) iSeries_Read_Long((void*)(addr))
47 #define writeb(data, addr) iSeries_Write_Byte(data,((void*)(addr)))
48 #define writew(data, addr) iSeries_Write_Word(data,((void*)(addr)))
49 #define writel(data, addr) iSeries_Write_Long(data,((void*)(addr)))
50 #define memset_io(a,b,c) iSeries_memset_io((void *)(a),(b),(c))
51 #define memcpy_fromio(a,b,c) iSeries_memcpy_fromio((void *)(a), (void *)(b), (c))
52 #define memcpy_toio(a,b,c) iSeries_memcpy_toio((void *)(a), (void *)(b), (c))
53 #define inb(addr) readb(((unsigned long)(addr)))
54 #define inw(addr) readw(((unsigned long)(addr)))
55 #define inl(addr) readl(((unsigned long)(addr)))
56 #define outb(data,addr) writeb(data,((unsigned long)(addr)))
57 #define outw(data,addr) writew(data,((unsigned long)(addr)))
58 #define outl(data,addr) writel(data,((unsigned long)(addr)))
60 * The *_ns versions below don't do byte-swapping.
61 * Neither do the standard versions now, these are just here
64 #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
65 #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
67 #define __raw_readb(addr) (*(volatile unsigned char *)(addr))
68 #define __raw_readw(addr) (*(volatile unsigned short *)(addr))
69 #define __raw_readl(addr) (*(volatile unsigned int *)(addr))
70 #define __raw_readq(addr) (*(volatile unsigned long *)(addr))
71 #define __raw_writeb(v, addr) (*(volatile unsigned char *)(addr) = (v))
72 #define __raw_writew(v, addr) (*(volatile unsigned short *)(addr) = (v))
73 #define __raw_writel(v, addr) (*(volatile unsigned int *)(addr) = (v))
74 #define __raw_writeq(v, addr) (*(volatile unsigned long *)(addr) = (v))
75 #define readb(addr) eeh_readb((void*)(addr))
76 #define readw(addr) eeh_readw((void*)(addr))
77 #define readl(addr) eeh_readl((void*)(addr))
78 #define readq(addr) eeh_readq((void*)(addr))
79 #define writeb(data, addr) eeh_writeb((data), ((void*)(addr)))
80 #define writew(data, addr) eeh_writew((data), ((void*)(addr)))
81 #define writel(data, addr) eeh_writel((data), ((void*)(addr)))
82 #define writeq(data, addr) eeh_writeq((data), ((void*)(addr)))
83 #define memset_io(a,b,c) eeh_memset_io((void *)(a),(b),(c))
84 #define memcpy_fromio(a,b,c) eeh_memcpy_fromio((a),(void *)(b),(c))
85 #define memcpy_toio(a,b,c) eeh_memcpy_toio((void *)(a),(b),(c))
86 #define inb(port) eeh_inb((unsigned long)port)
87 #define outb(val, port) eeh_outb(val, (unsigned long)port)
88 #define inw(port) eeh_inw((unsigned long)port)
89 #define outw(val, port) eeh_outw(val, (unsigned long)port)
90 #define inl(port) eeh_inl((unsigned long)port)
91 #define outl(val, port) eeh_outl(val, (unsigned long)port)
94 * The insw/outsw/insl/outsl macros don't do byte-swapping.
95 * They are only used in practice for transferring buffers which
96 * are arrays of bytes, and byte-swapping is not appropriate in
97 * that case. - paulus */
98 #define insb(port, buf, ns) eeh_insb((port), (buf), (ns))
99 #define insw(port, buf, ns) eeh_insw_ns((port), (buf), (ns))
100 #define insl(port, buf, nl) eeh_insl_ns((port), (buf), (nl))
101 #define insw_ns(port, buf, ns) eeh_insw_ns((port), (buf), (ns))
102 #define insl_ns(port, buf, nl) eeh_insl_ns((port), (buf), (nl))
104 #define outsb(port, buf, ns) _outsb((u8 *)((port)+pci_io_base), (buf), (ns))
105 #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
106 #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
110 #define readb_relaxed(addr) readb(addr)
111 #define readw_relaxed(addr) readw(addr)
112 #define readl_relaxed(addr) readl(addr)
113 #define readq_relaxed(addr) readq(addr)
115 extern void _insb(volatile u8 *port, void *buf, int ns);
116 extern void _outsb(volatile u8 *port, const void *buf, int ns);
117 extern void _insw(volatile u16 *port, void *buf, int ns);
118 extern void _outsw(volatile u16 *port, const void *buf, int ns);
119 extern void _insl(volatile u32 *port, void *buf, int nl);
120 extern void _outsl(volatile u32 *port, const void *buf, int nl);
121 extern void _insw_ns(volatile u16 *port, void *buf, int ns);
122 extern void _outsw_ns(volatile u16 *port, const void *buf, int ns);
123 extern void _insl_ns(volatile u32 *port, void *buf, int nl);
124 extern void _outsl_ns(volatile u32 *port, const void *buf, int nl);
127 * output pause versions need a delay at least for the
128 * w83c105 ide controller in a p610.
130 #define inb_p(port) inb(port)
131 #define outb_p(val, port) (udelay(1), outb((val), (port)))
132 #define inw_p(port) inw(port)
133 #define outw_p(val, port) (udelay(1), outw((val), (port)))
134 #define inl_p(port) inl(port)
135 #define outl_p(val, port) (udelay(1), outl((val), (port)))
138 * The *_ns versions below don't do byte-swapping.
139 * Neither do the standard versions now, these are just here
142 #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
143 #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
146 #define IO_SPACE_LIMIT ~(0UL)
150 extern int __ioremap_explicit(unsigned long p_addr, unsigned long v_addr,
151 unsigned long size, unsigned long flags);
152 extern void *__ioremap(unsigned long address, unsigned long size,
153 unsigned long flags);
156 * ioremap - map bus memory into CPU space
157 * @address: bus address of the memory
158 * @size: size of the resource to map
160 * ioremap performs a platform specific sequence of operations to
161 * make bus memory CPU accessible via the readb/readw/readl/writeb/
162 * writew/writel functions and the other mmio helpers. The returned
163 * address is not guaranteed to be usable directly as a virtual
166 extern void *ioremap(unsigned long address, unsigned long size);
168 #define ioremap_nocache(addr, size) ioremap((addr), (size))
169 extern int iounmap_explicit(void *addr, unsigned long size);
170 extern void iounmap(void *addr);
171 extern void * reserve_phb_iospace(unsigned long size);
174 * virt_to_phys - map virtual addresses to physical
175 * @address: address to remap
177 * The returned physical address is the physical (CPU) mapping for
178 * the memory address given. It is only valid to use this function on
179 * addresses directly mapped or allocated via kmalloc.
181 * This function does not give bus mappings for DMA transfers. In
182 * almost all conceivable cases a device driver should not be using
185 static inline unsigned long virt_to_phys(volatile void * address)
187 return __pa((unsigned long)address);
191 * phys_to_virt - map physical address to virtual
192 * @address: address to remap
194 * The returned virtual address is a current CPU mapping for
195 * the memory address given. It is only valid to use this function on
196 * addresses that have a kernel mapping
198 * This function does not handle bus mappings for DMA transfers. In
199 * almost all conceivable cases a device driver should not be using
202 static inline void * phys_to_virt(unsigned long address)
204 return (void *)__va(address);
208 * Change "struct page" to physical address.
210 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
212 /* We do NOT want virtual merging, it would put too much pressure on
213 * our iommu allocator. Instead, we want drivers to be smart enough
214 * to coalesce sglists that happen to have been mapped in a contiguous
217 #define BIO_VMERGE_BOUNDARY 0
219 #endif /* __KERNEL__ */
221 static inline void iosync(void)
223 __asm__ __volatile__ ("sync" : : : "memory");
226 /* Enforce in-order execution of data I/O.
227 * No distinction between read/write on PPC; use eieio for all three.
229 #define iobarrier_rw() eieio()
230 #define iobarrier_r() eieio()
231 #define iobarrier_w() eieio()
234 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
235 * These routines do not perform EEH-related I/O address translation,
236 * and should not be used directly by device drivers. Use inb/readb
239 static inline int in_8(volatile unsigned char *addr)
243 __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
244 : "=r" (ret) : "m" (*addr));
248 static inline void out_8(volatile unsigned char *addr, int val)
250 __asm__ __volatile__("stb%U0%X0 %1,%0; sync"
251 : "=m" (*addr) : "r" (val));
254 static inline int in_le16(volatile unsigned short *addr)
258 __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
259 : "=r" (ret) : "r" (addr), "m" (*addr));
263 static inline int in_be16(volatile unsigned short *addr)
267 __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
268 : "=r" (ret) : "m" (*addr));
272 static inline void out_le16(volatile unsigned short *addr, int val)
274 __asm__ __volatile__("sthbrx %1,0,%2; sync"
275 : "=m" (*addr) : "r" (val), "r" (addr));
278 static inline void out_be16(volatile unsigned short *addr, int val)
280 __asm__ __volatile__("sth%U0%X0 %1,%0; sync"
281 : "=m" (*addr) : "r" (val));
284 static inline unsigned in_le32(volatile unsigned *addr)
288 __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
289 : "=r" (ret) : "r" (addr), "m" (*addr));
293 static inline unsigned in_be32(volatile unsigned *addr)
297 __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
298 : "=r" (ret) : "m" (*addr));
302 static inline void out_le32(volatile unsigned *addr, int val)
304 __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
305 : "r" (val), "r" (addr));
308 static inline void out_be32(volatile unsigned *addr, int val)
310 __asm__ __volatile__("stw%U0%X0 %1,%0; sync"
311 : "=m" (*addr) : "r" (val));
314 static inline unsigned long in_le64(volatile unsigned long *addr)
316 unsigned long tmp, ret;
318 __asm__ __volatile__(
322 "rldimi %0,%1,5*8,1*8\n"
323 "rldimi %0,%1,3*8,2*8\n"
324 "rldimi %0,%1,1*8,3*8\n"
325 "rldimi %0,%1,7*8,4*8\n"
326 "rldicl %1,%1,32,0\n"
327 "rlwimi %0,%1,8,8,31\n"
328 "rlwimi %0,%1,24,16,23\n"
329 : "=r" (ret) , "=r" (tmp) : "b" (addr) , "m" (*addr));
333 static inline unsigned long in_be64(volatile unsigned long *addr)
337 __asm__ __volatile__("ld %0,0(%1); twi 0,%0,0; isync"
338 : "=r" (ret) : "m" (*addr));
342 static inline void out_le64(volatile unsigned long *addr, unsigned long val)
346 __asm__ __volatile__(
347 "rldimi %0,%1,5*8,1*8\n"
348 "rldimi %0,%1,3*8,2*8\n"
349 "rldimi %0,%1,1*8,3*8\n"
350 "rldimi %0,%1,7*8,4*8\n"
351 "rldicl %1,%1,32,0\n"
352 "rlwimi %0,%1,8,8,31\n"
353 "rlwimi %0,%1,24,16,23\n"
356 : "=&r" (tmp) , "=&r" (val) : "1" (val) , "b" (addr) , "m" (*addr));
359 static inline void out_be64(volatile unsigned long *addr, unsigned long val)
361 __asm__ __volatile__("std%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
364 #ifndef CONFIG_PPC_ISERIES
371 * check_signature - find BIOS signatures
372 * @io_addr: mmio address to check
373 * @signature: signature block
374 * @length: length of signature
376 * Perform a signature comparison with the mmio address io_addr. This
377 * address should have been obtained by ioremap.
378 * Returns 1 on a match.
380 static inline int check_signature(unsigned long io_addr,
381 const unsigned char *signature, int length)
384 #ifndef CONFIG_PPC_ISERIES
386 if (readb(io_addr) != *signature)
400 #define dma_cache_inv(_start,_size) do { } while (0)
401 #define dma_cache_wback(_start,_size) do { } while (0)
402 #define dma_cache_wback_inv(_start,_size) do { } while (0)
404 #endif /* __KERNEL__ */
406 #endif /* _PPC64_IO_H */