1b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_IO_H 2b8b572e1SStephen Rothwell #define _ASM_POWERPC_IO_H 3b8b572e1SStephen Rothwell #ifdef __KERNEL__ 4b8b572e1SStephen Rothwell 5be135f40SAnton Blanchard #define ARCH_HAS_IOREMAP_WC 6be135f40SAnton Blanchard 7b8b572e1SStephen Rothwell /* 8b8b572e1SStephen Rothwell * This program is free software; you can redistribute it and/or 9b8b572e1SStephen Rothwell * modify it under the terms of the GNU General Public License 10b8b572e1SStephen Rothwell * as published by the Free Software Foundation; either version 11b8b572e1SStephen Rothwell * 2 of the License, or (at your option) any later version. 12b8b572e1SStephen Rothwell */ 13b8b572e1SStephen Rothwell 14b8b572e1SStephen Rothwell /* Check of existence of legacy devices */ 15b8b572e1SStephen Rothwell extern int check_legacy_ioport(unsigned long base_port); 16b8b572e1SStephen Rothwell #define I8042_DATA_REG 0x60 17b8b572e1SStephen Rothwell #define FDC_BASE 0x3f0 18b8b572e1SStephen Rothwell /* only relevant for PReP */ 19b8b572e1SStephen Rothwell #define _PIDXR 0x279 20b8b572e1SStephen Rothwell #define _PNPWRP 0xa79 21b8b572e1SStephen Rothwell #define PNPBIOS_BASE 0xf000 22b8b572e1SStephen Rothwell 23*e1612de9SHaren Myneni #if defined(CONFIG_PPC64) && defined(CONFIG_PCI) 24*e1612de9SHaren Myneni extern struct pci_dev *isa_bridge_pcidev; 25*e1612de9SHaren Myneni /* 26*e1612de9SHaren Myneni * has legacy ISA devices ? 27*e1612de9SHaren Myneni */ 28*e1612de9SHaren Myneni #define arch_has_dev_port() (isa_bridge_pcidev != NULL) 29*e1612de9SHaren Myneni #endif 30*e1612de9SHaren Myneni 31b8b572e1SStephen Rothwell #include <linux/device.h> 32b8b572e1SStephen Rothwell #include <linux/io.h> 33b8b572e1SStephen Rothwell 34b8b572e1SStephen Rothwell #include <linux/compiler.h> 35b8b572e1SStephen Rothwell #include <asm/page.h> 36b8b572e1SStephen Rothwell #include <asm/byteorder.h> 37b8b572e1SStephen Rothwell #include <asm/synch.h> 38b8b572e1SStephen Rothwell #include <asm/delay.h> 39b8b572e1SStephen Rothwell #include <asm/mmu.h> 40b8b572e1SStephen Rothwell 41b8b572e1SStephen Rothwell #include <asm-generic/iomap.h> 42b8b572e1SStephen Rothwell 43b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 44b8b572e1SStephen Rothwell #include <asm/paca.h> 45b8b572e1SStephen Rothwell #endif 46b8b572e1SStephen Rothwell 47b8b572e1SStephen Rothwell #define SIO_CONFIG_RA 0x398 48b8b572e1SStephen Rothwell #define SIO_CONFIG_RD 0x399 49b8b572e1SStephen Rothwell 50b8b572e1SStephen Rothwell #define SLOW_DOWN_IO 51b8b572e1SStephen Rothwell 52b8b572e1SStephen Rothwell /* 32 bits uses slightly different variables for the various IO 53b8b572e1SStephen Rothwell * bases. Most of this file only uses _IO_BASE though which we 54b8b572e1SStephen Rothwell * define properly based on the platform 55b8b572e1SStephen Rothwell */ 56b8b572e1SStephen Rothwell #ifndef CONFIG_PCI 57b8b572e1SStephen Rothwell #define _IO_BASE 0 58b8b572e1SStephen Rothwell #define _ISA_MEM_BASE 0 59b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET 0 60b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC32) 61b8b572e1SStephen Rothwell #define _IO_BASE isa_io_base 62b8b572e1SStephen Rothwell #define _ISA_MEM_BASE isa_mem_base 63b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET pci_dram_offset 64b8b572e1SStephen Rothwell #else 65b8b572e1SStephen Rothwell #define _IO_BASE pci_io_base 66b8b572e1SStephen Rothwell #define _ISA_MEM_BASE isa_mem_base 67b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET 0 68b8b572e1SStephen Rothwell #endif 69b8b572e1SStephen Rothwell 70b8b572e1SStephen Rothwell extern unsigned long isa_io_base; 71b8b572e1SStephen Rothwell extern unsigned long pci_io_base; 72b8b572e1SStephen Rothwell extern unsigned long pci_dram_offset; 73b8b572e1SStephen Rothwell 74b8b572e1SStephen Rothwell extern resource_size_t isa_mem_base; 75b8b572e1SStephen Rothwell 76b8b572e1SStephen Rothwell #if defined(CONFIG_PPC32) && defined(CONFIG_PPC_INDIRECT_IO) 77b8b572e1SStephen Rothwell #error CONFIG_PPC_INDIRECT_IO is not yet supported on 32 bits 78b8b572e1SStephen Rothwell #endif 79b8b572e1SStephen Rothwell 80b8b572e1SStephen Rothwell /* 81b8b572e1SStephen Rothwell * 82b8b572e1SStephen Rothwell * Low level MMIO accessors 83b8b572e1SStephen Rothwell * 84b8b572e1SStephen Rothwell * This provides the non-bus specific accessors to MMIO. Those are PowerPC 85b8b572e1SStephen Rothwell * specific and thus shouldn't be used in generic code. The accessors 86b8b572e1SStephen Rothwell * provided here are: 87b8b572e1SStephen Rothwell * 88b8b572e1SStephen Rothwell * in_8, in_le16, in_be16, in_le32, in_be32, in_le64, in_be64 89b8b572e1SStephen Rothwell * out_8, out_le16, out_be16, out_le32, out_be32, out_le64, out_be64 90b8b572e1SStephen Rothwell * _insb, _insw_ns, _insl_ns, _outsb, _outsw_ns, _outsl_ns 91b8b572e1SStephen Rothwell * 92b8b572e1SStephen Rothwell * Those operate directly on a kernel virtual address. Note that the prototype 93b8b572e1SStephen Rothwell * for the out_* accessors has the arguments in opposite order from the usual 94b8b572e1SStephen Rothwell * linux PCI accessors. Unlike those, they take the address first and the value 95b8b572e1SStephen Rothwell * next. 96b8b572e1SStephen Rothwell * 97b8b572e1SStephen Rothwell * Note: I might drop the _ns suffix on the stream operations soon as it is 98b8b572e1SStephen Rothwell * simply normal for stream operations to not swap in the first place. 99b8b572e1SStephen Rothwell * 100b8b572e1SStephen Rothwell */ 101b8b572e1SStephen Rothwell 102b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64 103b8b572e1SStephen Rothwell #define IO_SET_SYNC_FLAG() do { local_paca->io_sync = 1; } while(0) 104b8b572e1SStephen Rothwell #else 105b8b572e1SStephen Rothwell #define IO_SET_SYNC_FLAG() 106b8b572e1SStephen Rothwell #endif 107b8b572e1SStephen Rothwell 108b8b572e1SStephen Rothwell /* gcc 4.0 and older doesn't have 'Z' constraint */ 109b8b572e1SStephen Rothwell #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ == 0) 110b8b572e1SStephen Rothwell #define DEF_MMIO_IN_LE(name, size, insn) \ 111b8b572e1SStephen Rothwell static inline u##size name(const volatile u##size __iomem *addr) \ 112b8b572e1SStephen Rothwell { \ 113b8b572e1SStephen Rothwell u##size ret; \ 114b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %0,0,%1;twi 0,%0,0;isync" \ 115b8b572e1SStephen Rothwell : "=r" (ret) : "r" (addr), "m" (*addr) : "memory"); \ 116b8b572e1SStephen Rothwell return ret; \ 117b8b572e1SStephen Rothwell } 118b8b572e1SStephen Rothwell 119b8b572e1SStephen Rothwell #define DEF_MMIO_OUT_LE(name, size, insn) \ 120b8b572e1SStephen Rothwell static inline void name(volatile u##size __iomem *addr, u##size val) \ 121b8b572e1SStephen Rothwell { \ 122b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %1,0,%2" \ 123b8b572e1SStephen Rothwell : "=m" (*addr) : "r" (val), "r" (addr) : "memory"); \ 124b8b572e1SStephen Rothwell IO_SET_SYNC_FLAG(); \ 125b8b572e1SStephen Rothwell } 126b8b572e1SStephen Rothwell #else /* newer gcc */ 127b8b572e1SStephen Rothwell #define DEF_MMIO_IN_LE(name, size, insn) \ 128b8b572e1SStephen Rothwell static inline u##size name(const volatile u##size __iomem *addr) \ 129b8b572e1SStephen Rothwell { \ 130b8b572e1SStephen Rothwell u##size ret; \ 131b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %0,%y1;twi 0,%0,0;isync" \ 132b8b572e1SStephen Rothwell : "=r" (ret) : "Z" (*addr) : "memory"); \ 133b8b572e1SStephen Rothwell return ret; \ 134b8b572e1SStephen Rothwell } 135b8b572e1SStephen Rothwell 136b8b572e1SStephen Rothwell #define DEF_MMIO_OUT_LE(name, size, insn) \ 137b8b572e1SStephen Rothwell static inline void name(volatile u##size __iomem *addr, u##size val) \ 138b8b572e1SStephen Rothwell { \ 139b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %1,%y0" \ 140b8b572e1SStephen Rothwell : "=Z" (*addr) : "r" (val) : "memory"); \ 141b8b572e1SStephen Rothwell IO_SET_SYNC_FLAG(); \ 142b8b572e1SStephen Rothwell } 143b8b572e1SStephen Rothwell #endif 144b8b572e1SStephen Rothwell 145b8b572e1SStephen Rothwell #define DEF_MMIO_IN_BE(name, size, insn) \ 146b8b572e1SStephen Rothwell static inline u##size name(const volatile u##size __iomem *addr) \ 147b8b572e1SStephen Rothwell { \ 148b8b572e1SStephen Rothwell u##size ret; \ 149b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn"%U1%X1 %0,%1;twi 0,%0,0;isync"\ 150b8b572e1SStephen Rothwell : "=r" (ret) : "m" (*addr) : "memory"); \ 151b8b572e1SStephen Rothwell return ret; \ 152b8b572e1SStephen Rothwell } 153b8b572e1SStephen Rothwell 154b8b572e1SStephen Rothwell #define DEF_MMIO_OUT_BE(name, size, insn) \ 155b8b572e1SStephen Rothwell static inline void name(volatile u##size __iomem *addr, u##size val) \ 156b8b572e1SStephen Rothwell { \ 157b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn"%U0%X0 %1,%0" \ 158b8b572e1SStephen Rothwell : "=m" (*addr) : "r" (val) : "memory"); \ 159b8b572e1SStephen Rothwell IO_SET_SYNC_FLAG(); \ 160b8b572e1SStephen Rothwell } 161b8b572e1SStephen Rothwell 162b8b572e1SStephen Rothwell 163b8b572e1SStephen Rothwell DEF_MMIO_IN_BE(in_8, 8, lbz); 164b8b572e1SStephen Rothwell DEF_MMIO_IN_BE(in_be16, 16, lhz); 165b8b572e1SStephen Rothwell DEF_MMIO_IN_BE(in_be32, 32, lwz); 166b8b572e1SStephen Rothwell DEF_MMIO_IN_LE(in_le16, 16, lhbrx); 167b8b572e1SStephen Rothwell DEF_MMIO_IN_LE(in_le32, 32, lwbrx); 168b8b572e1SStephen Rothwell 169b8b572e1SStephen Rothwell DEF_MMIO_OUT_BE(out_8, 8, stb); 170b8b572e1SStephen Rothwell DEF_MMIO_OUT_BE(out_be16, 16, sth); 171b8b572e1SStephen Rothwell DEF_MMIO_OUT_BE(out_be32, 32, stw); 172b8b572e1SStephen Rothwell DEF_MMIO_OUT_LE(out_le16, 16, sthbrx); 173b8b572e1SStephen Rothwell DEF_MMIO_OUT_LE(out_le32, 32, stwbrx); 174b8b572e1SStephen Rothwell 175b8b572e1SStephen Rothwell #ifdef __powerpc64__ 176b8b572e1SStephen Rothwell DEF_MMIO_OUT_BE(out_be64, 64, std); 177b8b572e1SStephen Rothwell DEF_MMIO_IN_BE(in_be64, 64, ld); 178b8b572e1SStephen Rothwell 179b8b572e1SStephen Rothwell /* There is no asm instructions for 64 bits reverse loads and stores */ 180b8b572e1SStephen Rothwell static inline u64 in_le64(const volatile u64 __iomem *addr) 181b8b572e1SStephen Rothwell { 182b8b572e1SStephen Rothwell return swab64(in_be64(addr)); 183b8b572e1SStephen Rothwell } 184b8b572e1SStephen Rothwell 185b8b572e1SStephen Rothwell static inline void out_le64(volatile u64 __iomem *addr, u64 val) 186b8b572e1SStephen Rothwell { 187b8b572e1SStephen Rothwell out_be64(addr, swab64(val)); 188b8b572e1SStephen Rothwell } 189b8b572e1SStephen Rothwell #endif /* __powerpc64__ */ 190b8b572e1SStephen Rothwell 191b8b572e1SStephen Rothwell /* 192b8b572e1SStephen Rothwell * Low level IO stream instructions are defined out of line for now 193b8b572e1SStephen Rothwell */ 194b8b572e1SStephen Rothwell extern void _insb(const volatile u8 __iomem *addr, void *buf, long count); 195b8b572e1SStephen Rothwell extern void _outsb(volatile u8 __iomem *addr,const void *buf,long count); 196b8b572e1SStephen Rothwell extern void _insw_ns(const volatile u16 __iomem *addr, void *buf, long count); 197b8b572e1SStephen Rothwell extern void _outsw_ns(volatile u16 __iomem *addr, const void *buf, long count); 198b8b572e1SStephen Rothwell extern void _insl_ns(const volatile u32 __iomem *addr, void *buf, long count); 199b8b572e1SStephen Rothwell extern void _outsl_ns(volatile u32 __iomem *addr, const void *buf, long count); 200b8b572e1SStephen Rothwell 201b8b572e1SStephen Rothwell /* The _ns naming is historical and will be removed. For now, just #define 202b8b572e1SStephen Rothwell * the non _ns equivalent names 203b8b572e1SStephen Rothwell */ 204b8b572e1SStephen Rothwell #define _insw _insw_ns 205b8b572e1SStephen Rothwell #define _insl _insl_ns 206b8b572e1SStephen Rothwell #define _outsw _outsw_ns 207b8b572e1SStephen Rothwell #define _outsl _outsl_ns 208b8b572e1SStephen Rothwell 209b8b572e1SStephen Rothwell 210b8b572e1SStephen Rothwell /* 211b8b572e1SStephen Rothwell * memset_io, memcpy_toio, memcpy_fromio base implementations are out of line 212b8b572e1SStephen Rothwell */ 213b8b572e1SStephen Rothwell 214b8b572e1SStephen Rothwell extern void _memset_io(volatile void __iomem *addr, int c, unsigned long n); 215b8b572e1SStephen Rothwell extern void _memcpy_fromio(void *dest, const volatile void __iomem *src, 216b8b572e1SStephen Rothwell unsigned long n); 217b8b572e1SStephen Rothwell extern void _memcpy_toio(volatile void __iomem *dest, const void *src, 218b8b572e1SStephen Rothwell unsigned long n); 219b8b572e1SStephen Rothwell 220b8b572e1SStephen Rothwell /* 221b8b572e1SStephen Rothwell * 222b8b572e1SStephen Rothwell * PCI and standard ISA accessors 223b8b572e1SStephen Rothwell * 224b8b572e1SStephen Rothwell * Those are globally defined linux accessors for devices on PCI or ISA 225b8b572e1SStephen Rothwell * busses. They follow the Linux defined semantics. The current implementation 226b8b572e1SStephen Rothwell * for PowerPC is as close as possible to the x86 version of these, and thus 227b8b572e1SStephen Rothwell * provides fairly heavy weight barriers for the non-raw versions 228b8b572e1SStephen Rothwell * 229b8b572e1SStephen Rothwell * In addition, they support a hook mechanism when CONFIG_PPC_INDIRECT_IO 230b8b572e1SStephen Rothwell * allowing the platform to provide its own implementation of some or all 231b8b572e1SStephen Rothwell * of the accessors. 232b8b572e1SStephen Rothwell */ 233b8b572e1SStephen Rothwell 234b8b572e1SStephen Rothwell /* 235b8b572e1SStephen Rothwell * Include the EEH definitions when EEH is enabled only so they don't get 236b8b572e1SStephen Rothwell * in the way when building for 32 bits 237b8b572e1SStephen Rothwell */ 238b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 239b8b572e1SStephen Rothwell #include <asm/eeh.h> 240b8b572e1SStephen Rothwell #endif 241b8b572e1SStephen Rothwell 242b8b572e1SStephen Rothwell /* Shortcut to the MMIO argument pointer */ 243b8b572e1SStephen Rothwell #define PCI_IO_ADDR volatile void __iomem * 244b8b572e1SStephen Rothwell 245b8b572e1SStephen Rothwell /* Indirect IO address tokens: 246b8b572e1SStephen Rothwell * 247b8b572e1SStephen Rothwell * When CONFIG_PPC_INDIRECT_IO is set, the platform can provide hooks 248b8b572e1SStephen Rothwell * on all IOs. (Note that this is all 64 bits only for now) 249b8b572e1SStephen Rothwell * 250b8b572e1SStephen Rothwell * To help platforms who may need to differenciate MMIO addresses in 251b8b572e1SStephen Rothwell * their hooks, a bitfield is reserved for use by the platform near the 252b8b572e1SStephen Rothwell * top of MMIO addresses (not PIO, those have to cope the hard way). 253b8b572e1SStephen Rothwell * 254b8b572e1SStephen Rothwell * This bit field is 12 bits and is at the top of the IO virtual 255b8b572e1SStephen Rothwell * addresses PCI_IO_INDIRECT_TOKEN_MASK. 256b8b572e1SStephen Rothwell * 257b8b572e1SStephen Rothwell * The kernel virtual space is thus: 258b8b572e1SStephen Rothwell * 259b8b572e1SStephen Rothwell * 0xD000000000000000 : vmalloc 260b8b572e1SStephen Rothwell * 0xD000080000000000 : PCI PHB IO space 261b8b572e1SStephen Rothwell * 0xD000080080000000 : ioremap 262b8b572e1SStephen Rothwell * 0xD0000fffffffffff : end of ioremap region 263b8b572e1SStephen Rothwell * 264b8b572e1SStephen Rothwell * Since the top 4 bits are reserved as the region ID, we use thus 265b8b572e1SStephen Rothwell * the next 12 bits and keep 4 bits available for the future if the 266b8b572e1SStephen Rothwell * virtual address space is ever to be extended. 267b8b572e1SStephen Rothwell * 268b8b572e1SStephen Rothwell * The direct IO mapping operations will then mask off those bits 269b8b572e1SStephen Rothwell * before doing the actual access, though that only happen when 270b8b572e1SStephen Rothwell * CONFIG_PPC_INDIRECT_IO is set, thus be careful when you use that 271b8b572e1SStephen Rothwell * mechanism 272b8b572e1SStephen Rothwell */ 273b8b572e1SStephen Rothwell 274b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_INDIRECT_IO 275b8b572e1SStephen Rothwell #define PCI_IO_IND_TOKEN_MASK 0x0fff000000000000ul 276b8b572e1SStephen Rothwell #define PCI_IO_IND_TOKEN_SHIFT 48 277b8b572e1SStephen Rothwell #define PCI_FIX_ADDR(addr) \ 278b8b572e1SStephen Rothwell ((PCI_IO_ADDR)(((unsigned long)(addr)) & ~PCI_IO_IND_TOKEN_MASK)) 279b8b572e1SStephen Rothwell #define PCI_GET_ADDR_TOKEN(addr) \ 280b8b572e1SStephen Rothwell (((unsigned long)(addr) & PCI_IO_IND_TOKEN_MASK) >> \ 281b8b572e1SStephen Rothwell PCI_IO_IND_TOKEN_SHIFT) 282b8b572e1SStephen Rothwell #define PCI_SET_ADDR_TOKEN(addr, token) \ 283b8b572e1SStephen Rothwell do { \ 284b8b572e1SStephen Rothwell unsigned long __a = (unsigned long)(addr); \ 285b8b572e1SStephen Rothwell __a &= ~PCI_IO_IND_TOKEN_MASK; \ 286b8b572e1SStephen Rothwell __a |= ((unsigned long)(token)) << PCI_IO_IND_TOKEN_SHIFT; \ 287b8b572e1SStephen Rothwell (addr) = (void __iomem *)__a; \ 288b8b572e1SStephen Rothwell } while(0) 289b8b572e1SStephen Rothwell #else 290b8b572e1SStephen Rothwell #define PCI_FIX_ADDR(addr) (addr) 291b8b572e1SStephen Rothwell #endif 292b8b572e1SStephen Rothwell 293b8b572e1SStephen Rothwell 294b8b572e1SStephen Rothwell /* 295b8b572e1SStephen Rothwell * Non ordered and non-swapping "raw" accessors 296b8b572e1SStephen Rothwell */ 297b8b572e1SStephen Rothwell 298b8b572e1SStephen Rothwell static inline unsigned char __raw_readb(const volatile void __iomem *addr) 299b8b572e1SStephen Rothwell { 300b8b572e1SStephen Rothwell return *(volatile unsigned char __force *)PCI_FIX_ADDR(addr); 301b8b572e1SStephen Rothwell } 302b8b572e1SStephen Rothwell static inline unsigned short __raw_readw(const volatile void __iomem *addr) 303b8b572e1SStephen Rothwell { 304b8b572e1SStephen Rothwell return *(volatile unsigned short __force *)PCI_FIX_ADDR(addr); 305b8b572e1SStephen Rothwell } 306b8b572e1SStephen Rothwell static inline unsigned int __raw_readl(const volatile void __iomem *addr) 307b8b572e1SStephen Rothwell { 308b8b572e1SStephen Rothwell return *(volatile unsigned int __force *)PCI_FIX_ADDR(addr); 309b8b572e1SStephen Rothwell } 310b8b572e1SStephen Rothwell static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr) 311b8b572e1SStephen Rothwell { 312b8b572e1SStephen Rothwell *(volatile unsigned char __force *)PCI_FIX_ADDR(addr) = v; 313b8b572e1SStephen Rothwell } 314b8b572e1SStephen Rothwell static inline void __raw_writew(unsigned short v, volatile void __iomem *addr) 315b8b572e1SStephen Rothwell { 316b8b572e1SStephen Rothwell *(volatile unsigned short __force *)PCI_FIX_ADDR(addr) = v; 317b8b572e1SStephen Rothwell } 318b8b572e1SStephen Rothwell static inline void __raw_writel(unsigned int v, volatile void __iomem *addr) 319b8b572e1SStephen Rothwell { 320b8b572e1SStephen Rothwell *(volatile unsigned int __force *)PCI_FIX_ADDR(addr) = v; 321b8b572e1SStephen Rothwell } 322b8b572e1SStephen Rothwell 323b8b572e1SStephen Rothwell #ifdef __powerpc64__ 324b8b572e1SStephen Rothwell static inline unsigned long __raw_readq(const volatile void __iomem *addr) 325b8b572e1SStephen Rothwell { 326b8b572e1SStephen Rothwell return *(volatile unsigned long __force *)PCI_FIX_ADDR(addr); 327b8b572e1SStephen Rothwell } 328b8b572e1SStephen Rothwell static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr) 329b8b572e1SStephen Rothwell { 330b8b572e1SStephen Rothwell *(volatile unsigned long __force *)PCI_FIX_ADDR(addr) = v; 331b8b572e1SStephen Rothwell } 332b8b572e1SStephen Rothwell #endif /* __powerpc64__ */ 333b8b572e1SStephen Rothwell 334b8b572e1SStephen Rothwell /* 335b8b572e1SStephen Rothwell * 336b8b572e1SStephen Rothwell * PCI PIO and MMIO accessors. 337b8b572e1SStephen Rothwell * 338b8b572e1SStephen Rothwell * 339b8b572e1SStephen Rothwell * On 32 bits, PIO operations have a recovery mechanism in case they trigger 340b8b572e1SStephen Rothwell * machine checks (which they occasionally do when probing non existing 341b8b572e1SStephen Rothwell * IO ports on some platforms, like PowerMac and 8xx). 342b8b572e1SStephen Rothwell * I always found it to be of dubious reliability and I am tempted to get 343b8b572e1SStephen Rothwell * rid of it one of these days. So if you think it's important to keep it, 344b8b572e1SStephen Rothwell * please voice up asap. We never had it for 64 bits and I do not intend 345b8b572e1SStephen Rothwell * to port it over 346b8b572e1SStephen Rothwell */ 347b8b572e1SStephen Rothwell 348b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 349b8b572e1SStephen Rothwell 350b8b572e1SStephen Rothwell #define __do_in_asm(name, op) \ 351b8b572e1SStephen Rothwell static inline unsigned int name(unsigned int port) \ 352b8b572e1SStephen Rothwell { \ 353b8b572e1SStephen Rothwell unsigned int x; \ 354b8b572e1SStephen Rothwell __asm__ __volatile__( \ 355b8b572e1SStephen Rothwell "sync\n" \ 356b8b572e1SStephen Rothwell "0:" op " %0,0,%1\n" \ 357b8b572e1SStephen Rothwell "1: twi 0,%0,0\n" \ 358b8b572e1SStephen Rothwell "2: isync\n" \ 359b8b572e1SStephen Rothwell "3: nop\n" \ 360b8b572e1SStephen Rothwell "4:\n" \ 361b8b572e1SStephen Rothwell ".section .fixup,\"ax\"\n" \ 362b8b572e1SStephen Rothwell "5: li %0,-1\n" \ 363b8b572e1SStephen Rothwell " b 4b\n" \ 364b8b572e1SStephen Rothwell ".previous\n" \ 365b8b572e1SStephen Rothwell ".section __ex_table,\"a\"\n" \ 366b8b572e1SStephen Rothwell " .align 2\n" \ 367b8b572e1SStephen Rothwell " .long 0b,5b\n" \ 368b8b572e1SStephen Rothwell " .long 1b,5b\n" \ 369b8b572e1SStephen Rothwell " .long 2b,5b\n" \ 370b8b572e1SStephen Rothwell " .long 3b,5b\n" \ 371b8b572e1SStephen Rothwell ".previous" \ 372b8b572e1SStephen Rothwell : "=&r" (x) \ 373b8b572e1SStephen Rothwell : "r" (port + _IO_BASE) \ 374b8b572e1SStephen Rothwell : "memory"); \ 375b8b572e1SStephen Rothwell return x; \ 376b8b572e1SStephen Rothwell } 377b8b572e1SStephen Rothwell 378b8b572e1SStephen Rothwell #define __do_out_asm(name, op) \ 379b8b572e1SStephen Rothwell static inline void name(unsigned int val, unsigned int port) \ 380b8b572e1SStephen Rothwell { \ 381b8b572e1SStephen Rothwell __asm__ __volatile__( \ 382b8b572e1SStephen Rothwell "sync\n" \ 383b8b572e1SStephen Rothwell "0:" op " %0,0,%1\n" \ 384b8b572e1SStephen Rothwell "1: sync\n" \ 385b8b572e1SStephen Rothwell "2:\n" \ 386b8b572e1SStephen Rothwell ".section __ex_table,\"a\"\n" \ 387b8b572e1SStephen Rothwell " .align 2\n" \ 388b8b572e1SStephen Rothwell " .long 0b,2b\n" \ 389b8b572e1SStephen Rothwell " .long 1b,2b\n" \ 390b8b572e1SStephen Rothwell ".previous" \ 391b8b572e1SStephen Rothwell : : "r" (val), "r" (port + _IO_BASE) \ 392b8b572e1SStephen Rothwell : "memory"); \ 393b8b572e1SStephen Rothwell } 394b8b572e1SStephen Rothwell 395b8b572e1SStephen Rothwell __do_in_asm(_rec_inb, "lbzx") 396b8b572e1SStephen Rothwell __do_in_asm(_rec_inw, "lhbrx") 397b8b572e1SStephen Rothwell __do_in_asm(_rec_inl, "lwbrx") 398b8b572e1SStephen Rothwell __do_out_asm(_rec_outb, "stbx") 399b8b572e1SStephen Rothwell __do_out_asm(_rec_outw, "sthbrx") 400b8b572e1SStephen Rothwell __do_out_asm(_rec_outl, "stwbrx") 401b8b572e1SStephen Rothwell 402b8b572e1SStephen Rothwell #endif /* CONFIG_PPC32 */ 403b8b572e1SStephen Rothwell 404b8b572e1SStephen Rothwell /* The "__do_*" operations below provide the actual "base" implementation 40542b2aa86SJustin P. Mattock * for each of the defined accessors. Some of them use the out_* functions 406b8b572e1SStephen Rothwell * directly, some of them still use EEH, though we might change that in the 407b8b572e1SStephen Rothwell * future. Those macros below provide the necessary argument swapping and 408b8b572e1SStephen Rothwell * handling of the IO base for PIO. 409b8b572e1SStephen Rothwell * 410b8b572e1SStephen Rothwell * They are themselves used by the macros that define the actual accessors 411b8b572e1SStephen Rothwell * and can be used by the hooks if any. 412b8b572e1SStephen Rothwell * 413b8b572e1SStephen Rothwell * Note that PIO operations are always defined in terms of their corresonding 414b8b572e1SStephen Rothwell * MMIO operations. That allows platforms like iSeries who want to modify the 415b8b572e1SStephen Rothwell * behaviour of both to only hook on the MMIO version and get both. It's also 416b8b572e1SStephen Rothwell * possible to hook directly at the toplevel PIO operation if they have to 417b8b572e1SStephen Rothwell * be handled differently 418b8b572e1SStephen Rothwell */ 419b8b572e1SStephen Rothwell #define __do_writeb(val, addr) out_8(PCI_FIX_ADDR(addr), val) 420b8b572e1SStephen Rothwell #define __do_writew(val, addr) out_le16(PCI_FIX_ADDR(addr), val) 421b8b572e1SStephen Rothwell #define __do_writel(val, addr) out_le32(PCI_FIX_ADDR(addr), val) 422b8b572e1SStephen Rothwell #define __do_writeq(val, addr) out_le64(PCI_FIX_ADDR(addr), val) 423b8b572e1SStephen Rothwell #define __do_writew_be(val, addr) out_be16(PCI_FIX_ADDR(addr), val) 424b8b572e1SStephen Rothwell #define __do_writel_be(val, addr) out_be32(PCI_FIX_ADDR(addr), val) 425b8b572e1SStephen Rothwell #define __do_writeq_be(val, addr) out_be64(PCI_FIX_ADDR(addr), val) 426b8b572e1SStephen Rothwell 427b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 428b8b572e1SStephen Rothwell #define __do_readb(addr) eeh_readb(PCI_FIX_ADDR(addr)) 429b8b572e1SStephen Rothwell #define __do_readw(addr) eeh_readw(PCI_FIX_ADDR(addr)) 430b8b572e1SStephen Rothwell #define __do_readl(addr) eeh_readl(PCI_FIX_ADDR(addr)) 431b8b572e1SStephen Rothwell #define __do_readq(addr) eeh_readq(PCI_FIX_ADDR(addr)) 432b8b572e1SStephen Rothwell #define __do_readw_be(addr) eeh_readw_be(PCI_FIX_ADDR(addr)) 433b8b572e1SStephen Rothwell #define __do_readl_be(addr) eeh_readl_be(PCI_FIX_ADDR(addr)) 434b8b572e1SStephen Rothwell #define __do_readq_be(addr) eeh_readq_be(PCI_FIX_ADDR(addr)) 435b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 436b8b572e1SStephen Rothwell #define __do_readb(addr) in_8(PCI_FIX_ADDR(addr)) 437b8b572e1SStephen Rothwell #define __do_readw(addr) in_le16(PCI_FIX_ADDR(addr)) 438b8b572e1SStephen Rothwell #define __do_readl(addr) in_le32(PCI_FIX_ADDR(addr)) 439b8b572e1SStephen Rothwell #define __do_readq(addr) in_le64(PCI_FIX_ADDR(addr)) 440b8b572e1SStephen Rothwell #define __do_readw_be(addr) in_be16(PCI_FIX_ADDR(addr)) 441b8b572e1SStephen Rothwell #define __do_readl_be(addr) in_be32(PCI_FIX_ADDR(addr)) 442b8b572e1SStephen Rothwell #define __do_readq_be(addr) in_be64(PCI_FIX_ADDR(addr)) 443b8b572e1SStephen Rothwell #endif /* !defined(CONFIG_EEH) */ 444b8b572e1SStephen Rothwell 445b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 446b8b572e1SStephen Rothwell #define __do_outb(val, port) _rec_outb(val, port) 447b8b572e1SStephen Rothwell #define __do_outw(val, port) _rec_outw(val, port) 448b8b572e1SStephen Rothwell #define __do_outl(val, port) _rec_outl(val, port) 449b8b572e1SStephen Rothwell #define __do_inb(port) _rec_inb(port) 450b8b572e1SStephen Rothwell #define __do_inw(port) _rec_inw(port) 451b8b572e1SStephen Rothwell #define __do_inl(port) _rec_inl(port) 452b8b572e1SStephen Rothwell #else /* CONFIG_PPC32 */ 453b8b572e1SStephen Rothwell #define __do_outb(val, port) writeb(val,(PCI_IO_ADDR)_IO_BASE+port); 454b8b572e1SStephen Rothwell #define __do_outw(val, port) writew(val,(PCI_IO_ADDR)_IO_BASE+port); 455b8b572e1SStephen Rothwell #define __do_outl(val, port) writel(val,(PCI_IO_ADDR)_IO_BASE+port); 456b8b572e1SStephen Rothwell #define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port); 457b8b572e1SStephen Rothwell #define __do_inw(port) readw((PCI_IO_ADDR)_IO_BASE + port); 458b8b572e1SStephen Rothwell #define __do_inl(port) readl((PCI_IO_ADDR)_IO_BASE + port); 459b8b572e1SStephen Rothwell #endif /* !CONFIG_PPC32 */ 460b8b572e1SStephen Rothwell 461b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 462b8b572e1SStephen Rothwell #define __do_readsb(a, b, n) eeh_readsb(PCI_FIX_ADDR(a), (b), (n)) 463b8b572e1SStephen Rothwell #define __do_readsw(a, b, n) eeh_readsw(PCI_FIX_ADDR(a), (b), (n)) 464b8b572e1SStephen Rothwell #define __do_readsl(a, b, n) eeh_readsl(PCI_FIX_ADDR(a), (b), (n)) 465b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 466b8b572e1SStephen Rothwell #define __do_readsb(a, b, n) _insb(PCI_FIX_ADDR(a), (b), (n)) 467b8b572e1SStephen Rothwell #define __do_readsw(a, b, n) _insw(PCI_FIX_ADDR(a), (b), (n)) 468b8b572e1SStephen Rothwell #define __do_readsl(a, b, n) _insl(PCI_FIX_ADDR(a), (b), (n)) 469b8b572e1SStephen Rothwell #endif /* !CONFIG_EEH */ 470b8b572e1SStephen Rothwell #define __do_writesb(a, b, n) _outsb(PCI_FIX_ADDR(a),(b),(n)) 471b8b572e1SStephen Rothwell #define __do_writesw(a, b, n) _outsw(PCI_FIX_ADDR(a),(b),(n)) 472b8b572e1SStephen Rothwell #define __do_writesl(a, b, n) _outsl(PCI_FIX_ADDR(a),(b),(n)) 473b8b572e1SStephen Rothwell 474b8b572e1SStephen Rothwell #define __do_insb(p, b, n) readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 475b8b572e1SStephen Rothwell #define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 476b8b572e1SStephen Rothwell #define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 477b8b572e1SStephen Rothwell #define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 478b8b572e1SStephen Rothwell #define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 479b8b572e1SStephen Rothwell #define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 480b8b572e1SStephen Rothwell 481b8b572e1SStephen Rothwell #define __do_memset_io(addr, c, n) \ 482b8b572e1SStephen Rothwell _memset_io(PCI_FIX_ADDR(addr), c, n) 483b8b572e1SStephen Rothwell #define __do_memcpy_toio(dst, src, n) \ 484b8b572e1SStephen Rothwell _memcpy_toio(PCI_FIX_ADDR(dst), src, n) 485b8b572e1SStephen Rothwell 486b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 487b8b572e1SStephen Rothwell #define __do_memcpy_fromio(dst, src, n) \ 488b8b572e1SStephen Rothwell eeh_memcpy_fromio(dst, PCI_FIX_ADDR(src), n) 489b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 490b8b572e1SStephen Rothwell #define __do_memcpy_fromio(dst, src, n) \ 491b8b572e1SStephen Rothwell _memcpy_fromio(dst,PCI_FIX_ADDR(src),n) 492b8b572e1SStephen Rothwell #endif /* !CONFIG_EEH */ 493b8b572e1SStephen Rothwell 49421176fedSMichael Ellerman #ifdef CONFIG_PPC_INDIRECT_PIO 49521176fedSMichael Ellerman #define DEF_PCI_HOOK_pio(x) x 496b8b572e1SStephen Rothwell #else 49721176fedSMichael Ellerman #define DEF_PCI_HOOK_pio(x) NULL 49821176fedSMichael Ellerman #endif 49921176fedSMichael Ellerman 50021176fedSMichael Ellerman #ifdef CONFIG_PPC_INDIRECT_MMIO 50121176fedSMichael Ellerman #define DEF_PCI_HOOK_mem(x) x 50221176fedSMichael Ellerman #else 50321176fedSMichael Ellerman #define DEF_PCI_HOOK_mem(x) NULL 504b8b572e1SStephen Rothwell #endif 505b8b572e1SStephen Rothwell 506b8b572e1SStephen Rothwell /* Structure containing all the hooks */ 507b8b572e1SStephen Rothwell extern struct ppc_pci_io { 508b8b572e1SStephen Rothwell 509b8b572e1SStephen Rothwell #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) ret (*name) at; 510b8b572e1SStephen Rothwell #define DEF_PCI_AC_NORET(name, at, al, space, aa) void (*name) at; 511b8b572e1SStephen Rothwell 512b8b572e1SStephen Rothwell #include <asm/io-defs.h> 513b8b572e1SStephen Rothwell 514b8b572e1SStephen Rothwell #undef DEF_PCI_AC_RET 515b8b572e1SStephen Rothwell #undef DEF_PCI_AC_NORET 516b8b572e1SStephen Rothwell 517b8b572e1SStephen Rothwell } ppc_pci_io; 518b8b572e1SStephen Rothwell 519b8b572e1SStephen Rothwell /* The inline wrappers */ 520b8b572e1SStephen Rothwell #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \ 521b8b572e1SStephen Rothwell static inline ret name at \ 522b8b572e1SStephen Rothwell { \ 52321176fedSMichael Ellerman if (DEF_PCI_HOOK_##space(ppc_pci_io.name) != NULL) \ 524b8b572e1SStephen Rothwell return ppc_pci_io.name al; \ 525b8b572e1SStephen Rothwell return __do_##name al; \ 526b8b572e1SStephen Rothwell } 527b8b572e1SStephen Rothwell 528b8b572e1SStephen Rothwell #define DEF_PCI_AC_NORET(name, at, al, space, aa) \ 529b8b572e1SStephen Rothwell static inline void name at \ 530b8b572e1SStephen Rothwell { \ 53121176fedSMichael Ellerman if (DEF_PCI_HOOK_##space(ppc_pci_io.name) != NULL) \ 532b8b572e1SStephen Rothwell ppc_pci_io.name al; \ 533b8b572e1SStephen Rothwell else \ 534b8b572e1SStephen Rothwell __do_##name al; \ 535b8b572e1SStephen Rothwell } 536b8b572e1SStephen Rothwell 537b8b572e1SStephen Rothwell #include <asm/io-defs.h> 538b8b572e1SStephen Rothwell 539b8b572e1SStephen Rothwell #undef DEF_PCI_AC_RET 540b8b572e1SStephen Rothwell #undef DEF_PCI_AC_NORET 541b8b572e1SStephen Rothwell 542b8b572e1SStephen Rothwell /* Some drivers check for the presence of readq & writeq with 543b8b572e1SStephen Rothwell * a #ifdef, so we make them happy here. 544b8b572e1SStephen Rothwell */ 545b8b572e1SStephen Rothwell #ifdef __powerpc64__ 546b8b572e1SStephen Rothwell #define readq readq 547b8b572e1SStephen Rothwell #define writeq writeq 548b8b572e1SStephen Rothwell #endif 549b8b572e1SStephen Rothwell 550b8b572e1SStephen Rothwell /* 551b8b572e1SStephen Rothwell * Convert a physical pointer to a virtual kernel pointer for /dev/mem 552b8b572e1SStephen Rothwell * access 553b8b572e1SStephen Rothwell */ 554b8b572e1SStephen Rothwell #define xlate_dev_mem_ptr(p) __va(p) 555b8b572e1SStephen Rothwell 556b8b572e1SStephen Rothwell /* 557b8b572e1SStephen Rothwell * Convert a virtual cached pointer to an uncached pointer 558b8b572e1SStephen Rothwell */ 559b8b572e1SStephen Rothwell #define xlate_dev_kmem_ptr(p) p 560b8b572e1SStephen Rothwell 561b8b572e1SStephen Rothwell /* 562b8b572e1SStephen Rothwell * We don't do relaxed operations yet, at least not with this semantic 563b8b572e1SStephen Rothwell */ 564b8b572e1SStephen Rothwell #define readb_relaxed(addr) readb(addr) 565b8b572e1SStephen Rothwell #define readw_relaxed(addr) readw(addr) 566b8b572e1SStephen Rothwell #define readl_relaxed(addr) readl(addr) 567b8b572e1SStephen Rothwell #define readq_relaxed(addr) readq(addr) 568b8b572e1SStephen Rothwell 569b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 570b8b572e1SStephen Rothwell #define mmiowb() 571b8b572e1SStephen Rothwell #else 572b8b572e1SStephen Rothwell /* 573b8b572e1SStephen Rothwell * Enforce synchronisation of stores vs. spin_unlock 574b8b572e1SStephen Rothwell * (this does it explicitly, though our implementation of spin_unlock 575b8b572e1SStephen Rothwell * does it implicitely too) 576b8b572e1SStephen Rothwell */ 577b8b572e1SStephen Rothwell static inline void mmiowb(void) 578b8b572e1SStephen Rothwell { 579b8b572e1SStephen Rothwell unsigned long tmp; 580b8b572e1SStephen Rothwell 581b8b572e1SStephen Rothwell __asm__ __volatile__("sync; li %0,0; stb %0,%1(13)" 582b8b572e1SStephen Rothwell : "=&r" (tmp) : "i" (offsetof(struct paca_struct, io_sync)) 583b8b572e1SStephen Rothwell : "memory"); 584b8b572e1SStephen Rothwell } 585b8b572e1SStephen Rothwell #endif /* !CONFIG_PPC32 */ 586b8b572e1SStephen Rothwell 587b8b572e1SStephen Rothwell static inline void iosync(void) 588b8b572e1SStephen Rothwell { 589b8b572e1SStephen Rothwell __asm__ __volatile__ ("sync" : : : "memory"); 590b8b572e1SStephen Rothwell } 591b8b572e1SStephen Rothwell 592b8b572e1SStephen Rothwell /* Enforce in-order execution of data I/O. 593b8b572e1SStephen Rothwell * No distinction between read/write on PPC; use eieio for all three. 594b8b572e1SStephen Rothwell * Those are fairly week though. They don't provide a barrier between 595b8b572e1SStephen Rothwell * MMIO and cacheable storage nor do they provide a barrier vs. locks, 596b8b572e1SStephen Rothwell * they only provide barriers between 2 __raw MMIO operations and 597b8b572e1SStephen Rothwell * possibly break write combining. 598b8b572e1SStephen Rothwell */ 599b8b572e1SStephen Rothwell #define iobarrier_rw() eieio() 600b8b572e1SStephen Rothwell #define iobarrier_r() eieio() 601b8b572e1SStephen Rothwell #define iobarrier_w() eieio() 602b8b572e1SStephen Rothwell 603b8b572e1SStephen Rothwell 604b8b572e1SStephen Rothwell /* 605b8b572e1SStephen Rothwell * output pause versions need a delay at least for the 606b8b572e1SStephen Rothwell * w83c105 ide controller in a p610. 607b8b572e1SStephen Rothwell */ 608b8b572e1SStephen Rothwell #define inb_p(port) inb(port) 609b8b572e1SStephen Rothwell #define outb_p(val, port) (udelay(1), outb((val), (port))) 610b8b572e1SStephen Rothwell #define inw_p(port) inw(port) 611b8b572e1SStephen Rothwell #define outw_p(val, port) (udelay(1), outw((val), (port))) 612b8b572e1SStephen Rothwell #define inl_p(port) inl(port) 613b8b572e1SStephen Rothwell #define outl_p(val, port) (udelay(1), outl((val), (port))) 614b8b572e1SStephen Rothwell 615b8b572e1SStephen Rothwell 616b8b572e1SStephen Rothwell #define IO_SPACE_LIMIT ~(0UL) 617b8b572e1SStephen Rothwell 618b8b572e1SStephen Rothwell 619b8b572e1SStephen Rothwell /** 620b8b572e1SStephen Rothwell * ioremap - map bus memory into CPU space 621b8b572e1SStephen Rothwell * @address: bus address of the memory 622b8b572e1SStephen Rothwell * @size: size of the resource to map 623b8b572e1SStephen Rothwell * 624b8b572e1SStephen Rothwell * ioremap performs a platform specific sequence of operations to 625b8b572e1SStephen Rothwell * make bus memory CPU accessible via the readb/readw/readl/writeb/ 626b8b572e1SStephen Rothwell * writew/writel functions and the other mmio helpers. The returned 627b8b572e1SStephen Rothwell * address is not guaranteed to be usable directly as a virtual 628b8b572e1SStephen Rothwell * address. 629b8b572e1SStephen Rothwell * 630b8b572e1SStephen Rothwell * We provide a few variations of it: 631b8b572e1SStephen Rothwell * 632b8b572e1SStephen Rothwell * * ioremap is the standard one and provides non-cacheable guarded mappings 633b8b572e1SStephen Rothwell * and can be hooked by the platform via ppc_md 634b8b572e1SStephen Rothwell * 63540f1ce7fSAnton Blanchard * * ioremap_prot allows to specify the page flags as an argument and can 63640f1ce7fSAnton Blanchard * also be hooked by the platform via ppc_md. 637b8b572e1SStephen Rothwell * 638b8b572e1SStephen Rothwell * * ioremap_nocache is identical to ioremap 639b8b572e1SStephen Rothwell * 640be135f40SAnton Blanchard * * ioremap_wc enables write combining 641be135f40SAnton Blanchard * 642b8b572e1SStephen Rothwell * * iounmap undoes such a mapping and can be hooked 643b8b572e1SStephen Rothwell * 644b8b572e1SStephen Rothwell * * __ioremap_at (and the pending __iounmap_at) are low level functions to 645b8b572e1SStephen Rothwell * create hand-made mappings for use only by the PCI code and cannot 646b8b572e1SStephen Rothwell * currently be hooked. Must be page aligned. 647b8b572e1SStephen Rothwell * 648b8b572e1SStephen Rothwell * * __ioremap is the low level implementation used by ioremap and 64940f1ce7fSAnton Blanchard * ioremap_prot and cannot be hooked (but can be used by a hook on one 650b8b572e1SStephen Rothwell * of the previous ones) 651b8b572e1SStephen Rothwell * 6521cdab55dSBenjamin Herrenschmidt * * __ioremap_caller is the same as above but takes an explicit caller 6531cdab55dSBenjamin Herrenschmidt * reference rather than using __builtin_return_address(0) 6541cdab55dSBenjamin Herrenschmidt * 655b8b572e1SStephen Rothwell * * __iounmap, is the low level implementation used by iounmap and cannot 656b8b572e1SStephen Rothwell * be hooked (but can be used by a hook on iounmap) 657b8b572e1SStephen Rothwell * 658b8b572e1SStephen Rothwell */ 659b8b572e1SStephen Rothwell extern void __iomem *ioremap(phys_addr_t address, unsigned long size); 66040f1ce7fSAnton Blanchard extern void __iomem *ioremap_prot(phys_addr_t address, unsigned long size, 661b8b572e1SStephen Rothwell unsigned long flags); 662be135f40SAnton Blanchard extern void __iomem *ioremap_wc(phys_addr_t address, unsigned long size); 663b8b572e1SStephen Rothwell #define ioremap_nocache(addr, size) ioremap((addr), (size)) 664b8b572e1SStephen Rothwell 665b8b572e1SStephen Rothwell extern void iounmap(volatile void __iomem *addr); 666b8b572e1SStephen Rothwell 667b8b572e1SStephen Rothwell extern void __iomem *__ioremap(phys_addr_t, unsigned long size, 668b8b572e1SStephen Rothwell unsigned long flags); 6691cdab55dSBenjamin Herrenschmidt extern void __iomem *__ioremap_caller(phys_addr_t, unsigned long size, 6701cdab55dSBenjamin Herrenschmidt unsigned long flags, void *caller); 6711cdab55dSBenjamin Herrenschmidt 672b8b572e1SStephen Rothwell extern void __iounmap(volatile void __iomem *addr); 673b8b572e1SStephen Rothwell 674b8b572e1SStephen Rothwell extern void __iomem * __ioremap_at(phys_addr_t pa, void *ea, 675b8b572e1SStephen Rothwell unsigned long size, unsigned long flags); 676b8b572e1SStephen Rothwell extern void __iounmap_at(void *ea, unsigned long size); 677b8b572e1SStephen Rothwell 678b8b572e1SStephen Rothwell /* 679b8b572e1SStephen Rothwell * When CONFIG_PPC_INDIRECT_IO is set, we use the generic iomap implementation 680b8b572e1SStephen Rothwell * which needs some additional definitions here. They basically allow PIO 681b8b572e1SStephen Rothwell * space overall to be 1GB. This will work as long as we never try to use 682b8b572e1SStephen Rothwell * iomap to map MMIO below 1GB which should be fine on ppc64 683b8b572e1SStephen Rothwell */ 684b8b572e1SStephen Rothwell #define HAVE_ARCH_PIO_SIZE 1 685b8b572e1SStephen Rothwell #define PIO_OFFSET 0x00000000UL 686b8b572e1SStephen Rothwell #define PIO_MASK (FULL_IO_SIZE - 1) 687b8b572e1SStephen Rothwell #define PIO_RESERVED (FULL_IO_SIZE) 688b8b572e1SStephen Rothwell 689b8b572e1SStephen Rothwell #define mmio_read16be(addr) readw_be(addr) 690b8b572e1SStephen Rothwell #define mmio_read32be(addr) readl_be(addr) 691b8b572e1SStephen Rothwell #define mmio_write16be(val, addr) writew_be(val, addr) 692b8b572e1SStephen Rothwell #define mmio_write32be(val, addr) writel_be(val, addr) 693b8b572e1SStephen Rothwell #define mmio_insb(addr, dst, count) readsb(addr, dst, count) 694b8b572e1SStephen Rothwell #define mmio_insw(addr, dst, count) readsw(addr, dst, count) 695b8b572e1SStephen Rothwell #define mmio_insl(addr, dst, count) readsl(addr, dst, count) 696b8b572e1SStephen Rothwell #define mmio_outsb(addr, src, count) writesb(addr, src, count) 697b8b572e1SStephen Rothwell #define mmio_outsw(addr, src, count) writesw(addr, src, count) 698b8b572e1SStephen Rothwell #define mmio_outsl(addr, src, count) writesl(addr, src, count) 699b8b572e1SStephen Rothwell 700b8b572e1SStephen Rothwell /** 701b8b572e1SStephen Rothwell * virt_to_phys - map virtual addresses to physical 702b8b572e1SStephen Rothwell * @address: address to remap 703b8b572e1SStephen Rothwell * 704b8b572e1SStephen Rothwell * The returned physical address is the physical (CPU) mapping for 705b8b572e1SStephen Rothwell * the memory address given. It is only valid to use this function on 706b8b572e1SStephen Rothwell * addresses directly mapped or allocated via kmalloc. 707b8b572e1SStephen Rothwell * 708b8b572e1SStephen Rothwell * This function does not give bus mappings for DMA transfers. In 709b8b572e1SStephen Rothwell * almost all conceivable cases a device driver should not be using 710b8b572e1SStephen Rothwell * this function 711b8b572e1SStephen Rothwell */ 712b8b572e1SStephen Rothwell static inline unsigned long virt_to_phys(volatile void * address) 713b8b572e1SStephen Rothwell { 714b8b572e1SStephen Rothwell return __pa((unsigned long)address); 715b8b572e1SStephen Rothwell } 716b8b572e1SStephen Rothwell 717b8b572e1SStephen Rothwell /** 718b8b572e1SStephen Rothwell * phys_to_virt - map physical address to virtual 719b8b572e1SStephen Rothwell * @address: address to remap 720b8b572e1SStephen Rothwell * 721b8b572e1SStephen Rothwell * The returned virtual address is a current CPU mapping for 722b8b572e1SStephen Rothwell * the memory address given. It is only valid to use this function on 723b8b572e1SStephen Rothwell * addresses that have a kernel mapping 724b8b572e1SStephen Rothwell * 725b8b572e1SStephen Rothwell * This function does not handle bus mappings for DMA transfers. In 726b8b572e1SStephen Rothwell * almost all conceivable cases a device driver should not be using 727b8b572e1SStephen Rothwell * this function 728b8b572e1SStephen Rothwell */ 729b8b572e1SStephen Rothwell static inline void * phys_to_virt(unsigned long address) 730b8b572e1SStephen Rothwell { 731b8b572e1SStephen Rothwell return (void *)__va(address); 732b8b572e1SStephen Rothwell } 733b8b572e1SStephen Rothwell 734b8b572e1SStephen Rothwell /* 735b8b572e1SStephen Rothwell * Change "struct page" to physical address. 736b8b572e1SStephen Rothwell */ 7374ee7084eSBecky Bruce #define page_to_phys(page) ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT) 738b8b572e1SStephen Rothwell 739b8b572e1SStephen Rothwell /* 740b8b572e1SStephen Rothwell * 32 bits still uses virt_to_bus() for it's implementation of DMA 741b8b572e1SStephen Rothwell * mappings se we have to keep it defined here. We also have some old 742b8b572e1SStephen Rothwell * drivers (shame shame shame) that use bus_to_virt() and haven't been 743b8b572e1SStephen Rothwell * fixed yet so I need to define it here. 744b8b572e1SStephen Rothwell */ 745b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 746b8b572e1SStephen Rothwell 747b8b572e1SStephen Rothwell static inline unsigned long virt_to_bus(volatile void * address) 748b8b572e1SStephen Rothwell { 749b8b572e1SStephen Rothwell if (address == NULL) 750b8b572e1SStephen Rothwell return 0; 751b8b572e1SStephen Rothwell return __pa(address) + PCI_DRAM_OFFSET; 752b8b572e1SStephen Rothwell } 753b8b572e1SStephen Rothwell 754b8b572e1SStephen Rothwell static inline void * bus_to_virt(unsigned long address) 755b8b572e1SStephen Rothwell { 756b8b572e1SStephen Rothwell if (address == 0) 757b8b572e1SStephen Rothwell return NULL; 758b8b572e1SStephen Rothwell return __va(address - PCI_DRAM_OFFSET); 759b8b572e1SStephen Rothwell } 760b8b572e1SStephen Rothwell 761b8b572e1SStephen Rothwell #define page_to_bus(page) (page_to_phys(page) + PCI_DRAM_OFFSET) 762b8b572e1SStephen Rothwell 763b8b572e1SStephen Rothwell #endif /* CONFIG_PPC32 */ 764b8b572e1SStephen Rothwell 765b8b572e1SStephen Rothwell /* access ports */ 766b8b572e1SStephen Rothwell #define setbits32(_addr, _v) out_be32((_addr), in_be32(_addr) | (_v)) 767b8b572e1SStephen Rothwell #define clrbits32(_addr, _v) out_be32((_addr), in_be32(_addr) & ~(_v)) 768b8b572e1SStephen Rothwell 769b8b572e1SStephen Rothwell #define setbits16(_addr, _v) out_be16((_addr), in_be16(_addr) | (_v)) 770b8b572e1SStephen Rothwell #define clrbits16(_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v)) 771b8b572e1SStephen Rothwell 772b8b572e1SStephen Rothwell #define setbits8(_addr, _v) out_8((_addr), in_8(_addr) | (_v)) 773b8b572e1SStephen Rothwell #define clrbits8(_addr, _v) out_8((_addr), in_8(_addr) & ~(_v)) 774b8b572e1SStephen Rothwell 775b8b572e1SStephen Rothwell /* Clear and set bits in one shot. These macros can be used to clear and 776b8b572e1SStephen Rothwell * set multiple bits in a register using a single read-modify-write. These 777b8b572e1SStephen Rothwell * macros can also be used to set a multiple-bit bit pattern using a mask, 778b8b572e1SStephen Rothwell * by specifying the mask in the 'clear' parameter and the new bit pattern 779b8b572e1SStephen Rothwell * in the 'set' parameter. 780b8b572e1SStephen Rothwell */ 781b8b572e1SStephen Rothwell 782b8b572e1SStephen Rothwell #define clrsetbits(type, addr, clear, set) \ 783b8b572e1SStephen Rothwell out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) 784b8b572e1SStephen Rothwell 785b8b572e1SStephen Rothwell #ifdef __powerpc64__ 786b8b572e1SStephen Rothwell #define clrsetbits_be64(addr, clear, set) clrsetbits(be64, addr, clear, set) 787b8b572e1SStephen Rothwell #define clrsetbits_le64(addr, clear, set) clrsetbits(le64, addr, clear, set) 788b8b572e1SStephen Rothwell #endif 789b8b572e1SStephen Rothwell 790b8b572e1SStephen Rothwell #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) 791b8b572e1SStephen Rothwell #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) 792b8b572e1SStephen Rothwell 793b8b572e1SStephen Rothwell #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) 794b8b572e1SStephen Rothwell #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) 795b8b572e1SStephen Rothwell 796b8b572e1SStephen Rothwell #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) 797b8b572e1SStephen Rothwell 798b8b572e1SStephen Rothwell void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset, 799b8b572e1SStephen Rothwell size_t size, unsigned long flags); 800b8b572e1SStephen Rothwell 801b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 802b8b572e1SStephen Rothwell 803b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_IO_H */ 804