at v2.6.15-rc2 576 lines 16 kB view raw
1#ifdef __KERNEL__ 2#ifndef _PPC_IO_H 3#define _PPC_IO_H 4 5#include <linux/config.h> 6#include <linux/string.h> 7#include <linux/types.h> 8 9#include <asm/page.h> 10#include <asm/byteorder.h> 11#include <asm/synch.h> 12#include <asm/mmu.h> 13 14#define SIO_CONFIG_RA 0x398 15#define SIO_CONFIG_RD 0x399 16 17#define SLOW_DOWN_IO 18 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 27 28#if defined(CONFIG_4xx) 29#include <asm/ibm4xx.h> 30#elif defined(CONFIG_8xx) 31#include <asm/mpc8xx.h> 32#elif defined(CONFIG_8260) 33#include <asm/mpc8260.h> 34#elif defined(CONFIG_83xx) 35#include <asm/mpc83xx.h> 36#elif defined(CONFIG_85xx) 37#include <asm/mpc85xx.h> 38#elif defined(CONFIG_APUS) 39#define _IO_BASE 0 40#define _ISA_MEM_BASE 0 41#define PCI_DRAM_OFFSET 0 42#else /* Everyone else */ 43#define _IO_BASE isa_io_base 44#define _ISA_MEM_BASE isa_mem_base 45#define PCI_DRAM_OFFSET pci_dram_offset 46#endif /* Platform-dependent I/O */ 47 48#define ___IO_BASE ((void __iomem *)_IO_BASE) 49extern unsigned long isa_io_base; 50extern unsigned long isa_mem_base; 51extern unsigned long pci_dram_offset; 52 53/* 54 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier. 55 * 56 * Read operations have additional twi & isync to make sure the read 57 * is actually performed (i.e. the data has come back) before we start 58 * executing any following instructions. 59 */ 60extern inline int in_8(const volatile unsigned char __iomem *addr) 61{ 62 int ret; 63 64 __asm__ __volatile__( 65 "lbz%U1%X1 %0,%1;\n" 66 "twi 0,%0,0;\n" 67 "isync" : "=r" (ret) : "m" (*addr)); 68 return ret; 69} 70 71extern inline void out_8(volatile unsigned char __iomem *addr, int val) 72{ 73 __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val)); 74} 75 76extern inline int in_le16(const volatile unsigned short __iomem *addr) 77{ 78 int ret; 79 80 __asm__ __volatile__("lhbrx %0,0,%1;\n" 81 "twi 0,%0,0;\n" 82 "isync" : "=r" (ret) : 83 "r" (addr), "m" (*addr)); 84 return ret; 85} 86 87extern inline int in_be16(const volatile unsigned short __iomem *addr) 88{ 89 int ret; 90 91 __asm__ __volatile__("lhz%U1%X1 %0,%1;\n" 92 "twi 0,%0,0;\n" 93 "isync" : "=r" (ret) : "m" (*addr)); 94 return ret; 95} 96 97extern inline void out_le16(volatile unsigned short __iomem *addr, int val) 98{ 99 __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) : 100 "r" (val), "r" (addr)); 101} 102 103extern inline void out_be16(volatile unsigned short __iomem *addr, int val) 104{ 105 __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val)); 106} 107 108extern inline unsigned in_le32(const volatile unsigned __iomem *addr) 109{ 110 unsigned ret; 111 112 __asm__ __volatile__("lwbrx %0,0,%1;\n" 113 "twi 0,%0,0;\n" 114 "isync" : "=r" (ret) : 115 "r" (addr), "m" (*addr)); 116 return ret; 117} 118 119extern inline unsigned in_be32(const volatile unsigned __iomem *addr) 120{ 121 unsigned ret; 122 123 __asm__ __volatile__("lwz%U1%X1 %0,%1;\n" 124 "twi 0,%0,0;\n" 125 "isync" : "=r" (ret) : "m" (*addr)); 126 return ret; 127} 128 129extern inline void out_le32(volatile unsigned __iomem *addr, int val) 130{ 131 __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) : 132 "r" (val), "r" (addr)); 133} 134 135extern inline void out_be32(volatile unsigned __iomem *addr, int val) 136{ 137 __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val)); 138} 139#if defined (CONFIG_8260_PCI9) 140#define readb(addr) in_8((volatile u8 *)(addr)) 141#define writeb(b,addr) out_8((volatile u8 *)(addr), (b)) 142#else 143static inline __u8 readb(const volatile void __iomem *addr) 144{ 145 return in_8(addr); 146} 147static inline void writeb(__u8 b, volatile void __iomem *addr) 148{ 149 out_8(addr, b); 150} 151#endif 152 153#if defined(CONFIG_APUS) 154static inline __u16 readw(const volatile void __iomem *addr) 155{ 156 return *(__force volatile __u16 *)(addr); 157} 158static inline __u32 readl(const volatile void __iomem *addr) 159{ 160 return *(__force volatile __u32 *)(addr); 161} 162static inline void writew(__u16 b, volatile void __iomem *addr) 163{ 164 *(__force volatile __u16 *)(addr) = b; 165} 166static inline void writel(__u32 b, volatile void __iomem *addr) 167{ 168 *(__force volatile __u32 *)(addr) = b; 169} 170#elif defined (CONFIG_8260_PCI9) 171/* Use macros if PCI9 workaround enabled */ 172#define readw(addr) in_le16((volatile u16 *)(addr)) 173#define readl(addr) in_le32((volatile u32 *)(addr)) 174#define writew(b,addr) out_le16((volatile u16 *)(addr),(b)) 175#define writel(b,addr) out_le32((volatile u32 *)(addr),(b)) 176#else 177static inline __u16 readw(const volatile void __iomem *addr) 178{ 179 return in_le16(addr); 180} 181static inline __u32 readl(const volatile void __iomem *addr) 182{ 183 return in_le32(addr); 184} 185static inline void writew(__u16 b, volatile void __iomem *addr) 186{ 187 out_le16(addr, b); 188} 189static inline void writel(__u32 b, volatile void __iomem *addr) 190{ 191 out_le32(addr, b); 192} 193#endif /* CONFIG_APUS */ 194 195#define readb_relaxed(addr) readb(addr) 196#define readw_relaxed(addr) readw(addr) 197#define readl_relaxed(addr) readl(addr) 198 199static inline __u8 __raw_readb(const volatile void __iomem *addr) 200{ 201 return *(__force volatile __u8 *)(addr); 202} 203static inline __u16 __raw_readw(const volatile void __iomem *addr) 204{ 205 return *(__force volatile __u16 *)(addr); 206} 207static inline __u32 __raw_readl(const volatile void __iomem *addr) 208{ 209 return *(__force volatile __u32 *)(addr); 210} 211static inline void __raw_writeb(__u8 b, volatile void __iomem *addr) 212{ 213 *(__force volatile __u8 *)(addr) = b; 214} 215static inline void __raw_writew(__u16 b, volatile void __iomem *addr) 216{ 217 *(__force volatile __u16 *)(addr) = b; 218} 219static inline void __raw_writel(__u32 b, volatile void __iomem *addr) 220{ 221 *(__force volatile __u32 *)(addr) = b; 222} 223 224#define mmiowb() 225 226/* 227 * The insw/outsw/insl/outsl macros don't do byte-swapping. 228 * They are only used in practice for transferring buffers which 229 * are arrays of bytes, and byte-swapping is not appropriate in 230 * that case. - paulus 231 */ 232#define insb(port, buf, ns) _insb((port)+___IO_BASE, (buf), (ns)) 233#define outsb(port, buf, ns) _outsb((port)+___IO_BASE, (buf), (ns)) 234#define insw(port, buf, ns) _insw_ns((port)+___IO_BASE, (buf), (ns)) 235#define outsw(port, buf, ns) _outsw_ns((port)+___IO_BASE, (buf), (ns)) 236#define insl(port, buf, nl) _insl_ns((port)+___IO_BASE, (buf), (nl)) 237#define outsl(port, buf, nl) _outsl_ns((port)+___IO_BASE, (buf), (nl)) 238 239/* 240 * On powermacs and 8xx we will get a machine check exception 241 * if we try to read data from a non-existent I/O port. Because 242 * the machine check is an asynchronous exception, it isn't 243 * well-defined which instruction SRR0 will point to when the 244 * exception occurs. 245 * With the sequence below (twi; isync; nop), we have found that 246 * the machine check occurs on one of the three instructions on 247 * all PPC implementations tested so far. The twi and isync are 248 * needed on the 601 (in fact twi; sync works too), the isync and 249 * nop are needed on 604[e|r], and any of twi, sync or isync will 250 * work on 603[e], 750, 74xx. 251 * The twi creates an explicit data dependency on the returned 252 * value which seems to be needed to make the 601 wait for the 253 * load to finish. 254 */ 255 256#define __do_in_asm(name, op) \ 257extern __inline__ unsigned int name(unsigned int port) \ 258{ \ 259 unsigned int x; \ 260 __asm__ __volatile__( \ 261 "0:" op " %0,0,%1\n" \ 262 "1: twi 0,%0,0\n" \ 263 "2: isync\n" \ 264 "3: nop\n" \ 265 "4:\n" \ 266 ".section .fixup,\"ax\"\n" \ 267 "5: li %0,-1\n" \ 268 " b 4b\n" \ 269 ".previous\n" \ 270 ".section __ex_table,\"a\"\n" \ 271 " .align 2\n" \ 272 " .long 0b,5b\n" \ 273 " .long 1b,5b\n" \ 274 " .long 2b,5b\n" \ 275 " .long 3b,5b\n" \ 276 ".previous" \ 277 : "=&r" (x) \ 278 : "r" (port + ___IO_BASE)); \ 279 return x; \ 280} 281 282#define __do_out_asm(name, op) \ 283extern __inline__ void name(unsigned int val, unsigned int port) \ 284{ \ 285 __asm__ __volatile__( \ 286 "0:" op " %0,0,%1\n" \ 287 "1: sync\n" \ 288 "2:\n" \ 289 ".section __ex_table,\"a\"\n" \ 290 " .align 2\n" \ 291 " .long 0b,2b\n" \ 292 " .long 1b,2b\n" \ 293 ".previous" \ 294 : : "r" (val), "r" (port + ___IO_BASE)); \ 295} 296 297__do_out_asm(outb, "stbx") 298#ifdef CONFIG_APUS 299__do_in_asm(inb, "lbzx") 300__do_in_asm(inw, "lhz%U1%X1") 301__do_in_asm(inl, "lwz%U1%X1") 302__do_out_asm(outl,"stw%U0%X0") 303__do_out_asm(outw, "sth%U0%X0") 304#elif defined (CONFIG_8260_PCI9) 305/* in asm cannot be defined if PCI9 workaround is used */ 306#define inb(port) in_8((port)+___IO_BASE) 307#define inw(port) in_le16((port)+___IO_BASE) 308#define inl(port) in_le32((port)+___IO_BASE) 309__do_out_asm(outw, "sthbrx") 310__do_out_asm(outl, "stwbrx") 311#else 312__do_in_asm(inb, "lbzx") 313__do_in_asm(inw, "lhbrx") 314__do_in_asm(inl, "lwbrx") 315__do_out_asm(outw, "sthbrx") 316__do_out_asm(outl, "stwbrx") 317 318#endif 319 320#define inb_p(port) inb((port)) 321#define outb_p(val, port) outb((val), (port)) 322#define inw_p(port) inw((port)) 323#define outw_p(val, port) outw((val), (port)) 324#define inl_p(port) inl((port)) 325#define outl_p(val, port) outl((val), (port)) 326 327extern void _insb(volatile u8 __iomem *port, void *buf, int ns); 328extern void _outsb(volatile u8 __iomem *port, const void *buf, int ns); 329extern void _insw(volatile u16 __iomem *port, void *buf, int ns); 330extern void _outsw(volatile u16 __iomem *port, const void *buf, int ns); 331extern void _insl(volatile u32 __iomem *port, void *buf, int nl); 332extern void _outsl(volatile u32 __iomem *port, const void *buf, int nl); 333extern void _insw_ns(volatile u16 __iomem *port, void *buf, int ns); 334extern void _outsw_ns(volatile u16 __iomem *port, const void *buf, int ns); 335extern void _insl_ns(volatile u32 __iomem *port, void *buf, int nl); 336extern void _outsl_ns(volatile u32 __iomem *port, const void *buf, int nl); 337 338/* 339 * The *_ns versions below don't do byte-swapping. 340 * Neither do the standard versions now, these are just here 341 * for older code. 342 */ 343#define insw_ns(port, buf, ns) _insw_ns((port)+___IO_BASE, (buf), (ns)) 344#define outsw_ns(port, buf, ns) _outsw_ns((port)+___IO_BASE, (buf), (ns)) 345#define insl_ns(port, buf, nl) _insl_ns((port)+___IO_BASE, (buf), (nl)) 346#define outsl_ns(port, buf, nl) _outsl_ns((port)+___IO_BASE, (buf), (nl)) 347 348 349#define IO_SPACE_LIMIT ~0 350 351#if defined (CONFIG_8260_PCI9) 352#define memset_io(a,b,c) memset((void *)(a),(b),(c)) 353#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c)) 354#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c)) 355#else 356static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count) 357{ 358 memset((void __force *)addr, val, count); 359} 360static inline void memcpy_fromio(void *dst,const volatile void __iomem *src, int count) 361{ 362 memcpy(dst, (void __force *) src, count); 363} 364static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count) 365{ 366 memcpy((void __force *) dst, src, count); 367} 368#endif 369 370#define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),(void __force *)(void __iomem *)(b),(c),(d)) 371 372/* 373 * Map in an area of physical address space, for accessing 374 * I/O devices etc. 375 */ 376extern void __iomem *__ioremap(phys_addr_t address, unsigned long size, 377 unsigned long flags); 378extern void __iomem *ioremap(phys_addr_t address, unsigned long size); 379#ifdef CONFIG_44x 380extern void __iomem *ioremap64(unsigned long long address, unsigned long size); 381#endif 382#define ioremap_nocache(addr, size) ioremap((addr), (size)) 383extern void iounmap(volatile void __iomem *addr); 384extern unsigned long iopa(unsigned long addr); 385extern unsigned long mm_ptov(unsigned long addr) __attribute_const__; 386extern void io_block_mapping(unsigned long virt, phys_addr_t phys, 387 unsigned int size, int flags); 388 389/* 390 * The PCI bus is inherently Little-Endian. The PowerPC is being 391 * run Big-Endian. Thus all values which cross the [PCI] barrier 392 * must be endian-adjusted. Also, the local DRAM has a different 393 * address from the PCI point of view, thus buffer addresses also 394 * have to be modified [mapped] appropriately. 395 */ 396extern inline unsigned long virt_to_bus(volatile void * address) 397{ 398#ifndef CONFIG_APUS 399 if (address == (void *)0) 400 return 0; 401 return (unsigned long)address - KERNELBASE + PCI_DRAM_OFFSET; 402#else 403 return iopa ((unsigned long) address); 404#endif 405} 406 407extern inline void * bus_to_virt(unsigned long address) 408{ 409#ifndef CONFIG_APUS 410 if (address == 0) 411 return NULL; 412 return (void *)(address - PCI_DRAM_OFFSET + KERNELBASE); 413#else 414 return (void*) mm_ptov (address); 415#endif 416} 417 418/* 419 * Change virtual addresses to physical addresses and vv, for 420 * addresses in the area where the kernel has the RAM mapped. 421 */ 422extern inline unsigned long virt_to_phys(volatile void * address) 423{ 424#ifndef CONFIG_APUS 425 return (unsigned long) address - KERNELBASE; 426#else 427 return iopa ((unsigned long) address); 428#endif 429} 430 431extern inline void * phys_to_virt(unsigned long address) 432{ 433#ifndef CONFIG_APUS 434 return (void *) (address + KERNELBASE); 435#else 436 return (void*) mm_ptov (address); 437#endif 438} 439 440/* 441 * Change "struct page" to physical address. 442 */ 443#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 444#define page_to_bus(page) (page_to_phys(page) + PCI_DRAM_OFFSET) 445 446/* Enforce in-order execution of data I/O. 447 * No distinction between read/write on PPC; use eieio for all three. 448 */ 449#define iobarrier_rw() eieio() 450#define iobarrier_r() eieio() 451#define iobarrier_w() eieio() 452 453static inline int check_signature(volatile void __iomem * io_addr, 454 const unsigned char *signature, int length) 455{ 456 int retval = 0; 457 do { 458 if (readb(io_addr) != *signature) 459 goto out; 460 io_addr++; 461 signature++; 462 length--; 463 } while (length); 464 retval = 1; 465out: 466 return retval; 467} 468 469/* 470 * Here comes the ppc implementation of the IOMAP 471 * interfaces. 472 */ 473static inline unsigned int ioread8(void __iomem *addr) 474{ 475 return readb(addr); 476} 477 478static inline unsigned int ioread16(void __iomem *addr) 479{ 480 return readw(addr); 481} 482 483static inline unsigned int ioread32(void __iomem *addr) 484{ 485 return readl(addr); 486} 487 488static inline void iowrite8(u8 val, void __iomem *addr) 489{ 490 writeb(val, addr); 491} 492 493static inline void iowrite16(u16 val, void __iomem *addr) 494{ 495 writew(val, addr); 496} 497 498static inline void iowrite32(u32 val, void __iomem *addr) 499{ 500 writel(val, addr); 501} 502 503static inline void ioread8_rep(void __iomem *addr, void *dst, unsigned long count) 504{ 505 _insb(addr, dst, count); 506} 507 508static inline void ioread16_rep(void __iomem *addr, void *dst, unsigned long count) 509{ 510 _insw_ns(addr, dst, count); 511} 512 513static inline void ioread32_rep(void __iomem *addr, void *dst, unsigned long count) 514{ 515 _insl_ns(addr, dst, count); 516} 517 518static inline void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count) 519{ 520 _outsb(addr, src, count); 521} 522 523static inline void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count) 524{ 525 _outsw_ns(addr, src, count); 526} 527 528static inline void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count) 529{ 530 _outsl_ns(addr, src, count); 531} 532 533/* Create a virtual mapping cookie for an IO port range */ 534extern void __iomem *ioport_map(unsigned long port, unsigned int nr); 535extern void ioport_unmap(void __iomem *); 536 537/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */ 538struct pci_dev; 539extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max); 540extern void pci_iounmap(struct pci_dev *dev, void __iomem *); 541 542#endif /* _PPC_IO_H */ 543 544#ifdef CONFIG_8260_PCI9 545#include <asm/mpc8260_pci9.h> 546#endif 547 548#ifdef CONFIG_NOT_COHERENT_CACHE 549 550#define dma_cache_inv(_start,_size) \ 551 invalidate_dcache_range(_start, (_start + _size)) 552#define dma_cache_wback(_start,_size) \ 553 clean_dcache_range(_start, (_start + _size)) 554#define dma_cache_wback_inv(_start,_size) \ 555 flush_dcache_range(_start, (_start + _size)) 556 557#else 558 559#define dma_cache_inv(_start,_size) do { } while (0) 560#define dma_cache_wback(_start,_size) do { } while (0) 561#define dma_cache_wback_inv(_start,_size) do { } while (0) 562 563#endif 564 565/* 566 * Convert a physical pointer to a virtual kernel pointer for /dev/mem 567 * access 568 */ 569#define xlate_dev_mem_ptr(p) __va(p) 570 571/* 572 * Convert a virtual cached pointer to an uncached pointer 573 */ 574#define xlate_dev_kmem_ptr(p) p 575 576#endif /* __KERNEL__ */