5 #include <linux/string.h>
6 #include <linux/types.h>
9 #include <asm/byteorder.h>
10 #include <asm/synch.h>
13 #define SIO_CONFIG_RA 0x398
14 #define SIO_CONFIG_RD 0x399
18 #define PMAC_ISA_MEM_BASE 0
19 #define PMAC_PCI_DRAM_OFFSET 0
20 #define CHRP_ISA_IO_BASE 0xf8000000
21 #define CHRP_ISA_MEM_BASE 0xf7000000
22 #define CHRP_PCI_DRAM_OFFSET 0
23 #define PREP_ISA_IO_BASE 0x80000000
24 #define PREP_ISA_MEM_BASE 0xc0000000
25 #define PREP_PCI_DRAM_OFFSET 0x80000000
27 #if defined(CONFIG_4xx)
28 #include <asm/ibm4xx.h>
29 #elif defined(CONFIG_8xx)
30 #include <asm/mpc8xx.h>
31 #elif defined(CONFIG_8260)
32 #include <asm/mpc8260.h>
33 #elif defined(CONFIG_APUS) || !defined(CONFIG_PCI)
35 #define _ISA_MEM_BASE 0
36 #define PCI_DRAM_OFFSET 0
37 #else /* Everyone else */
38 #define _IO_BASE isa_io_base
39 #define _ISA_MEM_BASE isa_mem_base
40 #define PCI_DRAM_OFFSET pci_dram_offset
41 #endif /* Platform-dependent I/O */
43 #define ___IO_BASE ((void __iomem *)_IO_BASE)
44 extern unsigned long isa_io_base;
45 extern unsigned long isa_mem_base;
46 extern unsigned long pci_dram_offset;
49 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
51 * Read operations have additional twi & isync to make sure the read
52 * is actually performed (i.e. the data has come back) before we start
53 * executing any following instructions.
55 extern inline int in_8(const volatile unsigned char __iomem *addr)
60 "sync; lbz%U1%X1 %0,%1;\n"
62 "isync" : "=r" (ret) : "m" (*addr));
66 extern inline void out_8(volatile unsigned char __iomem *addr, int val)
68 __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
71 extern inline int in_le16(const volatile unsigned short __iomem *addr)
75 __asm__ __volatile__("sync; lhbrx %0,0,%1;\n"
77 "isync" : "=r" (ret) :
78 "r" (addr), "m" (*addr));
82 extern inline int in_be16(const volatile unsigned short __iomem *addr)
86 __asm__ __volatile__("sync; lhz%U1%X1 %0,%1;\n"
88 "isync" : "=r" (ret) : "m" (*addr));
92 extern inline void out_le16(volatile unsigned short __iomem *addr, int val)
94 __asm__ __volatile__("sync; sthbrx %1,0,%2" : "=m" (*addr) :
95 "r" (val), "r" (addr));
98 extern inline void out_be16(volatile unsigned short __iomem *addr, int val)
100 __asm__ __volatile__("sync; sth%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
103 extern inline unsigned in_le32(const volatile unsigned __iomem *addr)
107 __asm__ __volatile__("sync; lwbrx %0,0,%1;\n"
109 "isync" : "=r" (ret) :
110 "r" (addr), "m" (*addr));
114 extern inline unsigned in_be32(const volatile unsigned __iomem *addr)
118 __asm__ __volatile__("sync; lwz%U1%X1 %0,%1;\n"
120 "isync" : "=r" (ret) : "m" (*addr));
124 extern inline void out_le32(volatile unsigned __iomem *addr, int val)
126 __asm__ __volatile__("sync; stwbrx %1,0,%2" : "=m" (*addr) :
127 "r" (val), "r" (addr));
130 extern inline void out_be32(volatile unsigned __iomem *addr, int val)
132 __asm__ __volatile__("sync; stw%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
134 #if defined (CONFIG_8260_PCI9)
135 #define readb(addr) in_8((volatile u8 *)(addr))
136 #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
138 static inline __u8 readb(const volatile void __iomem *addr)
142 static inline void writeb(__u8 b, volatile void __iomem *addr)
148 #if defined(CONFIG_APUS)
149 static inline __u16 readw(const volatile void __iomem *addr)
151 return *(__force volatile __u16 *)(addr);
153 static inline __u32 readl(const volatile void __iomem *addr)
155 return *(__force volatile __u32 *)(addr);
157 static inline void writew(__u16 b, volatile void __iomem *addr)
159 *(__force volatile __u16 *)(addr) = b;
161 static inline void writel(__u32 b, volatile void __iomem *addr)
163 *(__force volatile __u32 *)(addr) = b;
165 #elif defined (CONFIG_8260_PCI9)
166 /* Use macros if PCI9 workaround enabled */
167 #define readw(addr) in_le16((volatile u16 *)(addr))
168 #define readl(addr) in_le32((volatile u32 *)(addr))
169 #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
170 #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
172 static inline __u16 readw(const volatile void __iomem *addr)
174 return in_le16(addr);
176 static inline __u32 readl(const volatile void __iomem *addr)
178 return in_le32(addr);
180 static inline void writew(__u16 b, volatile void __iomem *addr)
184 static inline void writel(__u32 b, volatile void __iomem *addr)
188 #endif /* CONFIG_APUS */
190 #define readb_relaxed(addr) readb(addr)
191 #define readw_relaxed(addr) readw(addr)
192 #define readl_relaxed(addr) readl(addr)
194 static inline __u8 __raw_readb(const volatile void __iomem *addr)
196 return *(__force volatile __u8 *)(addr);
198 static inline __u16 __raw_readw(const volatile void __iomem *addr)
200 return *(__force volatile __u16 *)(addr);
202 static inline __u32 __raw_readl(const volatile void __iomem *addr)
204 return *(__force volatile __u32 *)(addr);
206 static inline void __raw_writeb(__u8 b, volatile void __iomem *addr)
208 *(__force volatile __u8 *)(addr) = b;
210 static inline void __raw_writew(__u16 b, volatile void __iomem *addr)
212 *(__force volatile __u16 *)(addr) = b;
214 static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
216 *(__force volatile __u32 *)(addr) = b;
222 * The insw/outsw/insl/outsl macros don't do byte-swapping.
223 * They are only used in practice for transferring buffers which
224 * are arrays of bytes, and byte-swapping is not appropriate in
225 * that case. - paulus
227 #define insb(port, buf, ns) _insb((port)+___IO_BASE, (buf), (ns))
228 #define outsb(port, buf, ns) _outsb((port)+___IO_BASE, (buf), (ns))
229 #define insw(port, buf, ns) _insw_ns((port)+___IO_BASE, (buf), (ns))
230 #define outsw(port, buf, ns) _outsw_ns((port)+___IO_BASE, (buf), (ns))
231 #define insl(port, buf, nl) _insl_ns((port)+___IO_BASE, (buf), (nl))
232 #define outsl(port, buf, nl) _outsl_ns((port)+___IO_BASE, (buf), (nl))
234 #define readsb(a, b, n) _insb((a), (b), (n))
235 #define readsw(a, b, n) _insw_ns((a), (b), (n))
236 #define readsl(a, b, n) _insl_ns((a), (b), (n))
237 #define writesb(a, b, n) _outsb((a),(b),(n))
238 #define writesw(a, b, n) _outsw_ns((a),(b),(n))
239 #define writesl(a, b, n) _outsl_ns((a),(b),(n))
243 * On powermacs and 8xx we will get a machine check exception
244 * if we try to read data from a non-existent I/O port. Because
245 * the machine check is an asynchronous exception, it isn't
246 * well-defined which instruction SRR0 will point to when the
248 * With the sequence below (twi; isync; nop), we have found that
249 * the machine check occurs on one of the three instructions on
250 * all PPC implementations tested so far. The twi and isync are
251 * needed on the 601 (in fact twi; sync works too), the isync and
252 * nop are needed on 604[e|r], and any of twi, sync or isync will
253 * work on 603[e], 750, 74xx.
254 * The twi creates an explicit data dependency on the returned
255 * value which seems to be needed to make the 601 wait for the
259 #define __do_in_asm(name, op) \
260 extern __inline__ unsigned int name(unsigned int port) \
263 __asm__ __volatile__( \
265 "0:" op " %0,0,%1\n" \
270 ".section .fixup,\"ax\"\n" \
274 ".section __ex_table,\"a\"\n" \
282 : "r" (port + ___IO_BASE)); \
286 #define __do_out_asm(name, op) \
287 extern __inline__ void name(unsigned int val, unsigned int port) \
289 __asm__ __volatile__( \
291 "0:" op " %0,0,%1\n" \
294 ".section __ex_table,\"a\"\n" \
299 : : "r" (val), "r" (port + ___IO_BASE)); \
302 __do_out_asm(outb, "stbx")
304 __do_in_asm(inb, "lbzx")
305 __do_in_asm(inw, "lhz%U1%X1")
306 __do_in_asm(inl, "lwz%U1%X1")
307 __do_out_asm(outl,"stw%U0%X0")
308 __do_out_asm(outw, "sth%U0%X0")
309 #elif defined (CONFIG_8260_PCI9)
310 /* in asm cannot be defined if PCI9 workaround is used */
311 #define inb(port) in_8((port)+___IO_BASE)
312 #define inw(port) in_le16((port)+___IO_BASE)
313 #define inl(port) in_le32((port)+___IO_BASE)
314 __do_out_asm(outw, "sthbrx")
315 __do_out_asm(outl, "stwbrx")
317 __do_in_asm(inb, "lbzx")
318 __do_in_asm(inw, "lhbrx")
319 __do_in_asm(inl, "lwbrx")
320 __do_out_asm(outw, "sthbrx")
321 __do_out_asm(outl, "stwbrx")
325 #define inb_p(port) inb((port))
326 #define outb_p(val, port) outb((val), (port))
327 #define inw_p(port) inw((port))
328 #define outw_p(val, port) outw((val), (port))
329 #define inl_p(port) inl((port))
330 #define outl_p(val, port) outl((val), (port))
332 extern void _insb(const volatile u8 __iomem *addr, void *buf, long count);
333 extern void _outsb(volatile u8 __iomem *addr,const void *buf,long count);
334 extern void _insw_ns(const volatile u16 __iomem *addr, void *buf, long count);
335 extern void _outsw_ns(volatile u16 __iomem *addr, const void *buf, long count);
336 extern void _insl_ns(const volatile u32 __iomem *addr, void *buf, long count);
337 extern void _outsl_ns(volatile u32 __iomem *addr, const void *buf, long count);
340 #define IO_SPACE_LIMIT ~0
342 #if defined (CONFIG_8260_PCI9)
343 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
344 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
345 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
347 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
349 memset((void __force *)addr, val, count);
351 static inline void memcpy_fromio(void *dst,const volatile void __iomem *src, int count)
353 memcpy(dst, (void __force *) src, count);
355 static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
357 memcpy((void __force *) dst, src, count);
361 #define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),(void __force *)(void __iomem *)(b),(c),(d))
364 * Map in an area of physical address space, for accessing
367 extern void __iomem *__ioremap(phys_addr_t address, unsigned long size,
368 unsigned long flags);
369 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
371 extern void __iomem *ioremap64(unsigned long long address, unsigned long size);
373 #define ioremap_nocache(addr, size) ioremap((addr), (size))
374 extern void iounmap(volatile void __iomem *addr);
375 extern unsigned long iopa(unsigned long addr);
376 extern unsigned long mm_ptov(unsigned long addr) __attribute_const__;
377 extern void io_block_mapping(unsigned long virt, phys_addr_t phys,
378 unsigned int size, int flags);
381 * The PCI bus is inherently Little-Endian. The PowerPC is being
382 * run Big-Endian. Thus all values which cross the [PCI] barrier
383 * must be endian-adjusted. Also, the local DRAM has a different
384 * address from the PCI point of view, thus buffer addresses also
385 * have to be modified [mapped] appropriately.
387 extern inline unsigned long virt_to_bus(volatile void * address)
390 if (address == (void *)0)
392 return (unsigned long)address - KERNELBASE + PCI_DRAM_OFFSET;
394 return iopa ((unsigned long) address);
398 extern inline void * bus_to_virt(unsigned long address)
403 return (void *)(address - PCI_DRAM_OFFSET + KERNELBASE);
405 return (void*) mm_ptov (address);
410 * Change virtual addresses to physical addresses and vv, for
411 * addresses in the area where the kernel has the RAM mapped.
413 extern inline unsigned long virt_to_phys(volatile void * address)
416 return (unsigned long) address - KERNELBASE;
418 return iopa ((unsigned long) address);
422 extern inline void * phys_to_virt(unsigned long address)
425 return (void *) (address + KERNELBASE);
427 return (void*) mm_ptov (address);
432 * Change "struct page" to physical address.
434 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
435 #define page_to_bus(page) (page_to_phys(page) + PCI_DRAM_OFFSET)
437 /* Enforce in-order execution of data I/O.
438 * No distinction between read/write on PPC; use eieio for all three.
440 #define iobarrier_rw() eieio()
441 #define iobarrier_r() eieio()
442 #define iobarrier_w() eieio()
445 * Here comes the ppc implementation of the IOMAP
448 static inline unsigned int ioread8(void __iomem *addr)
453 static inline unsigned int ioread16(void __iomem *addr)
458 static inline unsigned int ioread32(void __iomem *addr)
463 static inline void iowrite8(u8 val, void __iomem *addr)
468 static inline void iowrite16(u16 val, void __iomem *addr)
473 static inline void iowrite32(u32 val, void __iomem *addr)
478 static inline void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
480 _insb(addr, dst, count);
483 static inline void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
485 _insw_ns(addr, dst, count);
488 static inline void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
490 _insl_ns(addr, dst, count);
493 static inline void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
495 _outsb(addr, src, count);
498 static inline void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
500 _outsw_ns(addr, src, count);
503 static inline void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
505 _outsl_ns(addr, src, count);
508 /* Create a virtual mapping cookie for an IO port range */
509 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
510 extern void ioport_unmap(void __iomem *);
512 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
514 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
515 extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
517 #endif /* _PPC_IO_H */
519 #ifdef CONFIG_8260_PCI9
520 #include <asm/mpc8260_pci9.h>
523 #ifdef CONFIG_NOT_COHERENT_CACHE
525 #define dma_cache_inv(_start,_size) \
526 invalidate_dcache_range(_start, (_start + _size))
527 #define dma_cache_wback(_start,_size) \
528 clean_dcache_range(_start, (_start + _size))
529 #define dma_cache_wback_inv(_start,_size) \
530 flush_dcache_range(_start, (_start + _size))
534 #define dma_cache_inv(_start,_size) do { } while (0)
535 #define dma_cache_wback(_start,_size) do { } while (0)
536 #define dma_cache_wback_inv(_start,_size) do { } while (0)
541 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
544 #define xlate_dev_mem_ptr(p) __va(p)
547 * Convert a virtual cached pointer to an uncached pointer
549 #define xlate_dev_kmem_ptr(p) p
552 #define setbits32(_addr, _v) out_be32((_addr), in_be32(_addr) | (_v))
553 #define clrbits32(_addr, _v) out_be32((_addr), in_be32(_addr) & ~(_v))
555 #define setbits16(_addr, _v) out_be16((_addr), in_be16(_addr) | (_v))
556 #define clrbits16(_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v))
558 #endif /* __KERNEL__ */