5 #include <linux/config.h>
6 #include <linux/string.h>
7 #include <linux/types.h>
10 #include <asm/byteorder.h>
11 #include <asm/synch.h>
14 #define SIO_CONFIG_RA 0x398
15 #define SIO_CONFIG_RD 0x399
19 #define PMAC_ISA_MEM_BASE 0
20 #define PMAC_PCI_DRAM_OFFSET 0
21 #define CHRP_ISA_IO_BASE 0xf8000000
22 #define CHRP_ISA_MEM_BASE 0xf7000000
23 #define CHRP_PCI_DRAM_OFFSET 0
24 #define PREP_ISA_IO_BASE 0x80000000
25 #define PREP_ISA_MEM_BASE 0xc0000000
26 #define PREP_PCI_DRAM_OFFSET 0x80000000
28 #if defined(CONFIG_4xx)
29 #include <asm/ibm4xx.h>
30 #elif defined(CONFIG_PPC_MPC52xx)
31 #include <asm/mpc52xx.h>
32 #elif defined(CONFIG_8xx)
33 #include <asm/mpc8xx.h>
34 #elif defined(CONFIG_8260)
35 #include <asm/mpc8260.h>
36 #elif defined(CONFIG_83xx)
37 #include <asm/mpc83xx.h>
38 #elif defined(CONFIG_85xx)
39 #include <asm/mpc85xx.h>
40 #elif defined(CONFIG_APUS)
42 #define _ISA_MEM_BASE 0
43 #define PCI_DRAM_OFFSET 0
44 #else /* Everyone else */
45 #define _IO_BASE isa_io_base
46 #define _ISA_MEM_BASE isa_mem_base
47 #define PCI_DRAM_OFFSET pci_dram_offset
48 #endif /* Platform-dependent I/O */
50 #define ___IO_BASE ((void __iomem *)_IO_BASE)
51 extern unsigned long isa_io_base;
52 extern unsigned long isa_mem_base;
53 extern unsigned long pci_dram_offset;
56 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
58 * Read operations have additional twi & isync to make sure the read
59 * is actually performed (i.e. the data has come back) before we start
60 * executing any following instructions.
62 extern inline int in_8(const volatile unsigned char __iomem *addr)
69 "isync" : "=r" (ret) : "m" (*addr));
73 extern inline void out_8(volatile unsigned char __iomem *addr, int val)
75 __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
78 extern inline int in_le16(const volatile unsigned short __iomem *addr)
82 __asm__ __volatile__("lhbrx %0,0,%1;\n"
84 "isync" : "=r" (ret) :
85 "r" (addr), "m" (*addr));
89 extern inline int in_be16(const volatile unsigned short __iomem *addr)
93 __asm__ __volatile__("lhz%U1%X1 %0,%1;\n"
95 "isync" : "=r" (ret) : "m" (*addr));
99 extern inline void out_le16(volatile unsigned short __iomem *addr, int val)
101 __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
102 "r" (val), "r" (addr));
105 extern inline void out_be16(volatile unsigned short __iomem *addr, int val)
107 __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
110 extern inline unsigned in_le32(const volatile unsigned __iomem *addr)
114 __asm__ __volatile__("lwbrx %0,0,%1;\n"
116 "isync" : "=r" (ret) :
117 "r" (addr), "m" (*addr));
121 extern inline unsigned in_be32(const volatile unsigned __iomem *addr)
125 __asm__ __volatile__("lwz%U1%X1 %0,%1;\n"
127 "isync" : "=r" (ret) : "m" (*addr));
131 extern inline void out_le32(volatile unsigned __iomem *addr, int val)
133 __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
134 "r" (val), "r" (addr));
137 extern inline void out_be32(volatile unsigned __iomem *addr, int val)
139 __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
141 #if defined (CONFIG_8260_PCI9)
142 #define readb(addr) in_8((volatile u8 *)(addr))
143 #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
145 static inline __u8 readb(const volatile void __iomem *addr)
149 static inline void writeb(__u8 b, volatile void __iomem *addr)
155 #if defined(CONFIG_APUS)
156 static inline __u16 readw(const volatile void __iomem *addr)
158 return *(__force volatile __u16 *)(addr);
160 static inline __u32 readl(const volatile void __iomem *addr)
162 return *(__force volatile __u32 *)(addr);
164 static inline void writew(__u16 b, volatile void __iomem *addr)
166 *(__force volatile __u16 *)(addr) = b;
168 static inline void writel(__u32 b, volatile void __iomem *addr)
170 *(__force volatile __u32 *)(addr) = b;
172 #elif defined (CONFIG_8260_PCI9)
173 /* Use macros if PCI9 workaround enabled */
174 #define readw(addr) in_le16((volatile u16 *)(addr))
175 #define readl(addr) in_le32((volatile u32 *)(addr))
176 #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
177 #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
179 static inline __u16 readw(const volatile void __iomem *addr)
181 return in_le16(addr);
183 static inline __u32 readl(const volatile void __iomem *addr)
185 return in_le32(addr);
187 static inline void writew(__u16 b, volatile void __iomem *addr)
191 static inline void writel(__u32 b, volatile void __iomem *addr)
195 #endif /* CONFIG_APUS */
197 #define readb_relaxed(addr) readb(addr)
198 #define readw_relaxed(addr) readw(addr)
199 #define readl_relaxed(addr) readl(addr)
201 static inline __u8 __raw_readb(const volatile void __iomem *addr)
203 return *(__force volatile __u8 *)(addr);
205 static inline __u16 __raw_readw(const volatile void __iomem *addr)
207 return *(__force volatile __u16 *)(addr);
209 static inline __u32 __raw_readl(const volatile void __iomem *addr)
211 return *(__force volatile __u32 *)(addr);
213 static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
215 *(__force volatile __u8 *)(addr) = b;
217 static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
219 *(__force volatile __u16 *)(addr) = b;
221 static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
223 *(__force volatile __u32 *)(addr) = b;
229 * The insw/outsw/insl/outsl macros don't do byte-swapping.
230 * They are only used in practice for transferring buffers which
231 * are arrays of bytes, and byte-swapping is not appropriate in
232 * that case. - paulus
234 #define insb(port, buf, ns) _insb((port)+___IO_BASE, (buf), (ns))
235 #define outsb(port, buf, ns) _outsb((port)+___IO_BASE, (buf), (ns))
236 #define insw(port, buf, ns) _insw_ns((port)+___IO_BASE, (buf), (ns))
237 #define outsw(port, buf, ns) _outsw_ns((port)+___IO_BASE, (buf), (ns))
238 #define insl(port, buf, nl) _insl_ns((port)+___IO_BASE, (buf), (nl))
239 #define outsl(port, buf, nl) _outsl_ns((port)+___IO_BASE, (buf), (nl))
242 * On powermacs and 8xx we will get a machine check exception
243 * if we try to read data from a non-existent I/O port. Because
244 * the machine check is an asynchronous exception, it isn't
245 * well-defined which instruction SRR0 will point to when the
247 * With the sequence below (twi; isync; nop), we have found that
248 * the machine check occurs on one of the three instructions on
249 * all PPC implementations tested so far. The twi and isync are
250 * needed on the 601 (in fact twi; sync works too), the isync and
251 * nop are needed on 604[e|r], and any of twi, sync or isync will
252 * work on 603[e], 750, 74xx.
253 * The twi creates an explicit data dependency on the returned
254 * value which seems to be needed to make the 601 wait for the
258 #define __do_in_asm(name, op) \
259 extern __inline__ unsigned int name(unsigned int port) \
262 __asm__ __volatile__( \
263 "0:" op " %0,0,%1\n" \
268 ".section .fixup,\"ax\"\n" \
272 ".section __ex_table,\"a\"\n" \
280 : "r" (port + ___IO_BASE)); \
284 #define __do_out_asm(name, op) \
285 extern __inline__ void name(unsigned int val, unsigned int port) \
287 __asm__ __volatile__( \
288 "0:" op " %0,0,%1\n" \
291 ".section __ex_table,\"a\"\n" \
296 : : "r" (val), "r" (port + ___IO_BASE)); \
299 __do_out_asm(outb, "stbx")
301 __do_in_asm(inb, "lbzx")
302 __do_in_asm(inw, "lhz%U1%X1")
303 __do_in_asm(inl, "lwz%U1%X1")
304 __do_out_asm(outl,"stw%U0%X0")
305 __do_out_asm(outw, "sth%U0%X0")
306 #elif defined (CONFIG_8260_PCI9)
307 /* in asm cannot be defined if PCI9 workaround is used */
308 #define inb(port) in_8((port)+___IO_BASE)
309 #define inw(port) in_le16((port)+___IO_BASE)
310 #define inl(port) in_le32((port)+___IO_BASE)
311 __do_out_asm(outw, "sthbrx")
312 __do_out_asm(outl, "stwbrx")
314 __do_in_asm(inb, "lbzx")
315 __do_in_asm(inw, "lhbrx")
316 __do_in_asm(inl, "lwbrx")
317 __do_out_asm(outw, "sthbrx")
318 __do_out_asm(outl, "stwbrx")
322 #define inb_p(port) inb((port))
323 #define outb_p(val, port) outb((val), (port))
324 #define inw_p(port) inw((port))
325 #define outw_p(val, port) outw((val), (port))
326 #define inl_p(port) inl((port))
327 #define outl_p(val, port) outl((val), (port))
329 extern void _insb(volatile u8 __iomem *port, void *buf, int ns);
330 extern void _outsb(volatile u8 __iomem *port, const void *buf, int ns);
331 extern void _insw(volatile u16 __iomem *port, void *buf, int ns);
332 extern void _outsw(volatile u16 __iomem *port, const void *buf, int ns);
333 extern void _insl(volatile u32 __iomem *port, void *buf, int nl);
334 extern void _outsl(volatile u32 __iomem *port, const void *buf, int nl);
335 extern void _insw_ns(volatile u16 __iomem *port, void *buf, int ns);
336 extern void _outsw_ns(volatile u16 __iomem *port, const void *buf, int ns);
337 extern void _insl_ns(volatile u32 __iomem *port, void *buf, int nl);
338 extern void _outsl_ns(volatile u32 __iomem *port, const void *buf, int nl);
341 * The *_ns versions below don't do byte-swapping.
342 * Neither do the standard versions now, these are just here
345 #define insw_ns(port, buf, ns) _insw_ns((port)+___IO_BASE, (buf), (ns))
346 #define outsw_ns(port, buf, ns) _outsw_ns((port)+___IO_BASE, (buf), (ns))
347 #define insl_ns(port, buf, nl) _insl_ns((port)+___IO_BASE, (buf), (nl))
348 #define outsl_ns(port, buf, nl) _outsl_ns((port)+___IO_BASE, (buf), (nl))
351 #define IO_SPACE_LIMIT ~0
353 #if defined (CONFIG_8260_PCI9)
354 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
355 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
356 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
358 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
360 memset((void __force *)addr, val, count);
362 static inline void memcpy_fromio(void *dst,const volatile void __iomem *src, int count)
364 memcpy(dst, (void __force *) src, count);
366 static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
368 memcpy((void __force *) dst, src, count);
372 #define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),(void __force *)(void __iomem *)(b),(c),(d))
375 * Map in an area of physical address space, for accessing
378 extern void __iomem *__ioremap(phys_addr_t address, unsigned long size,
379 unsigned long flags);
380 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
382 extern void __iomem *ioremap64(unsigned long long address, unsigned long size);
384 #define ioremap_nocache(addr, size) ioremap((addr), (size))
385 extern void iounmap(volatile void __iomem *addr);
386 extern unsigned long iopa(unsigned long addr);
387 extern unsigned long mm_ptov(unsigned long addr) __attribute_const__;
388 extern void io_block_mapping(unsigned long virt, phys_addr_t phys,
389 unsigned int size, int flags);
392 * The PCI bus is inherently Little-Endian. The PowerPC is being
393 * run Big-Endian. Thus all values which cross the [PCI] barrier
394 * must be endian-adjusted. Also, the local DRAM has a different
395 * address from the PCI point of view, thus buffer addresses also
396 * have to be modified [mapped] appropriately.
398 extern inline unsigned long virt_to_bus(volatile void * address)
401 if (address == (void *)0)
403 return (unsigned long)address - KERNELBASE + PCI_DRAM_OFFSET;
405 return iopa ((unsigned long) address);
409 extern inline void * bus_to_virt(unsigned long address)
414 return (void *)(address - PCI_DRAM_OFFSET + KERNELBASE);
416 return (void*) mm_ptov (address);
421 * Change virtual addresses to physical addresses and vv, for
422 * addresses in the area where the kernel has the RAM mapped.
424 extern inline unsigned long virt_to_phys(volatile void * address)
427 return (unsigned long) address - KERNELBASE;
429 return iopa ((unsigned long) address);
433 extern inline void * phys_to_virt(unsigned long address)
436 return (void *) (address + KERNELBASE);
438 return (void*) mm_ptov (address);
443 * Change "struct page" to physical address.
445 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
446 #define page_to_bus(page) (page_to_phys(page) + PCI_DRAM_OFFSET)
448 /* Enforce in-order execution of data I/O.
449 * No distinction between read/write on PPC; use eieio for all three.
451 #define iobarrier_rw() eieio()
452 #define iobarrier_r() eieio()
453 #define iobarrier_w() eieio()
455 static inline int check_signature(volatile void __iomem * io_addr,
456 const unsigned char *signature, int length)
460 if (readb(io_addr) != *signature)
472 * Here comes the ppc implementation of the IOMAP
475 static inline unsigned int ioread8(void __iomem *addr)
480 static inline unsigned int ioread16(void __iomem *addr)
485 static inline unsigned int ioread32(void __iomem *addr)
490 static inline void iowrite8(u8 val, void __iomem *addr)
495 static inline void iowrite16(u16 val, void __iomem *addr)
500 static inline void iowrite32(u32 val, void __iomem *addr)
505 static inline void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
507 _insb(addr, dst, count);
510 static inline void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
512 _insw_ns(addr, dst, count);
515 static inline void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
517 _insl_ns(addr, dst, count);
520 static inline void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
522 _outsb(addr, src, count);
525 static inline void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
527 _outsw_ns(addr, src, count);
530 static inline void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
532 _outsl_ns(addr, src, count);
535 /* Create a virtual mapping cookie for an IO port range */
536 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
537 extern void ioport_unmap(void __iomem *);
539 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
541 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
542 extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
544 #endif /* _PPC_IO_H */
546 #ifdef CONFIG_8260_PCI9
547 #include <asm/mpc8260_pci9.h>
550 #ifdef CONFIG_NOT_COHERENT_CACHE
552 #define dma_cache_inv(_start,_size) \
553 invalidate_dcache_range(_start, (_start + _size))
554 #define dma_cache_wback(_start,_size) \
555 clean_dcache_range(_start, (_start + _size))
556 #define dma_cache_wback_inv(_start,_size) \
557 flush_dcache_range(_start, (_start + _size))
561 #define dma_cache_inv(_start,_size) do { } while (0)
562 #define dma_cache_wback(_start,_size) do { } while (0)
563 #define dma_cache_wback_inv(_start,_size) do { } while (0)
568 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
571 #define xlate_dev_mem_ptr(p) __va(p)
574 * Convert a virtual cached pointer to an uncached pointer
576 #define xlate_dev_kmem_ptr(p) p
579 #define setbits32(_addr, _v) out_be32((_addr), in_be32(_addr) | (_v))
580 #define clrbits32(_addr, _v) out_be32((_addr), in_be32(_addr) & ~(_v))
582 #define setbits16(_addr, _v) out_be16((_addr), in_be16(_addr) | (_v))
583 #define clrbits16(_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v))
585 #endif /* __KERNEL__ */