12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_IO_H 3b8b572e1SStephen Rothwell #define _ASM_POWERPC_IO_H 4b8b572e1SStephen Rothwell #ifdef __KERNEL__ 5b8b572e1SStephen Rothwell 6be135f40SAnton Blanchard #define ARCH_HAS_IOREMAP_WC 786c391bdSChristophe Leroy #ifdef CONFIG_PPC32 886c391bdSChristophe Leroy #define ARCH_HAS_IOREMAP_WT 986c391bdSChristophe Leroy #endif 10be135f40SAnton Blanchard 11b8b572e1SStephen Rothwell /* 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 19e1612de9SHaren Myneni #if defined(CONFIG_PPC64) && defined(CONFIG_PCI) 20e1612de9SHaren Myneni extern struct pci_dev *isa_bridge_pcidev; 21e1612de9SHaren Myneni /* 22e1612de9SHaren Myneni * has legacy ISA devices ? 23e1612de9SHaren Myneni */ 24ac237b65SBenjamin Herrenschmidt #define arch_has_dev_port() (isa_bridge_pcidev != NULL || isa_io_special) 25e1612de9SHaren Myneni #endif 26e1612de9SHaren Myneni 27b8b572e1SStephen Rothwell #include <linux/device.h> 28b8b572e1SStephen Rothwell #include <linux/compiler.h> 296bf752daSChristophe Leroy #include <linux/mm.h> 30b8b572e1SStephen Rothwell #include <asm/page.h> 31b8b572e1SStephen Rothwell #include <asm/byteorder.h> 32b8b572e1SStephen Rothwell #include <asm/synch.h> 33b8b572e1SStephen Rothwell #include <asm/delay.h> 34420af155SWill Deacon #include <asm/mmiowb.h> 35b8b572e1SStephen Rothwell #include <asm/mmu.h> 36b8b572e1SStephen Rothwell 37b8b572e1SStephen Rothwell #define SIO_CONFIG_RA 0x398 38b8b572e1SStephen Rothwell #define SIO_CONFIG_RD 0x399 39b8b572e1SStephen Rothwell 40b8b572e1SStephen Rothwell /* 32 bits uses slightly different variables for the various IO 41b8b572e1SStephen Rothwell * bases. Most of this file only uses _IO_BASE though which we 42b8b572e1SStephen Rothwell * define properly based on the platform 43b8b572e1SStephen Rothwell */ 44b8b572e1SStephen Rothwell #ifndef CONFIG_PCI 45b8b572e1SStephen Rothwell #define _IO_BASE 0 46b8b572e1SStephen Rothwell #define _ISA_MEM_BASE 0 47b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET 0 48b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC32) 49b8b572e1SStephen Rothwell #define _IO_BASE isa_io_base 50b8b572e1SStephen Rothwell #define _ISA_MEM_BASE isa_mem_base 51b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET pci_dram_offset 52b8b572e1SStephen Rothwell #else 53b8b572e1SStephen Rothwell #define _IO_BASE pci_io_base 54b8b572e1SStephen Rothwell #define _ISA_MEM_BASE isa_mem_base 55b8b572e1SStephen Rothwell #define PCI_DRAM_OFFSET 0 56b8b572e1SStephen Rothwell #endif 57b8b572e1SStephen Rothwell 58b8b572e1SStephen Rothwell extern unsigned long isa_io_base; 59b8b572e1SStephen Rothwell extern unsigned long pci_io_base; 60b8b572e1SStephen Rothwell extern unsigned long pci_dram_offset; 61b8b572e1SStephen Rothwell 62b8b572e1SStephen Rothwell extern resource_size_t isa_mem_base; 63b8b572e1SStephen Rothwell 643fafe9c2SBenjamin Herrenschmidt /* Boolean set by platform if PIO accesses are suppored while _IO_BASE 653fafe9c2SBenjamin Herrenschmidt * is not set or addresses cannot be translated to MMIO. This is typically 663fafe9c2SBenjamin Herrenschmidt * set when the platform supports "special" PIO accesses via a non memory 673fafe9c2SBenjamin Herrenschmidt * mapped mechanism, and allows things like the early udbg UART code to 683fafe9c2SBenjamin Herrenschmidt * function. 693fafe9c2SBenjamin Herrenschmidt */ 703fafe9c2SBenjamin Herrenschmidt extern bool isa_io_special; 713fafe9c2SBenjamin Herrenschmidt 72ecd73cc5SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 73ecd73cc5SBenjamin Herrenschmidt #if defined(CONFIG_PPC_INDIRECT_PIO) || defined(CONFIG_PPC_INDIRECT_MMIO) 74ecd73cc5SBenjamin Herrenschmidt #error CONFIG_PPC_INDIRECT_{PIO,MMIO} are not yet supported on 32 bits 75ecd73cc5SBenjamin Herrenschmidt #endif 76b8b572e1SStephen Rothwell #endif 77b8b572e1SStephen Rothwell 78b8b572e1SStephen Rothwell /* 79b8b572e1SStephen Rothwell * 80b8b572e1SStephen Rothwell * Low level MMIO accessors 81b8b572e1SStephen Rothwell * 82b8b572e1SStephen Rothwell * This provides the non-bus specific accessors to MMIO. Those are PowerPC 83b8b572e1SStephen Rothwell * specific and thus shouldn't be used in generic code. The accessors 84b8b572e1SStephen Rothwell * provided here are: 85b8b572e1SStephen Rothwell * 86b8b572e1SStephen Rothwell * in_8, in_le16, in_be16, in_le32, in_be32, in_le64, in_be64 87b8b572e1SStephen Rothwell * out_8, out_le16, out_be16, out_le32, out_be32, out_le64, out_be64 88b8b572e1SStephen Rothwell * _insb, _insw_ns, _insl_ns, _outsb, _outsw_ns, _outsl_ns 89b8b572e1SStephen Rothwell * 90b8b572e1SStephen Rothwell * Those operate directly on a kernel virtual address. Note that the prototype 91b8b572e1SStephen Rothwell * for the out_* accessors has the arguments in opposite order from the usual 92b8b572e1SStephen Rothwell * linux PCI accessors. Unlike those, they take the address first and the value 93b8b572e1SStephen Rothwell * next. 94b8b572e1SStephen Rothwell * 95b8b572e1SStephen Rothwell * Note: I might drop the _ns suffix on the stream operations soon as it is 96b8b572e1SStephen Rothwell * simply normal for stream operations to not swap in the first place. 97b8b572e1SStephen Rothwell * 98b8b572e1SStephen Rothwell */ 99b8b572e1SStephen Rothwell 100*dc5dac74SNicholas Piggin /* -mprefixed can generate offsets beyond range, fall back hack */ 101*dc5dac74SNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PREFIXED 102*dc5dac74SNicholas Piggin #define DEF_MMIO_IN_X(name, size, insn) \ 103*dc5dac74SNicholas Piggin static inline u##size name(const volatile u##size __iomem *addr) \ 104*dc5dac74SNicholas Piggin { \ 105*dc5dac74SNicholas Piggin u##size ret; \ 106*dc5dac74SNicholas Piggin __asm__ __volatile__("sync;"#insn" %0,0,%1;twi 0,%0,0;isync" \ 107*dc5dac74SNicholas Piggin : "=r" (ret) : "r" (addr) : "memory"); \ 108*dc5dac74SNicholas Piggin return ret; \ 109*dc5dac74SNicholas Piggin } 110*dc5dac74SNicholas Piggin 111*dc5dac74SNicholas Piggin #define DEF_MMIO_OUT_X(name, size, insn) \ 112*dc5dac74SNicholas Piggin static inline void name(volatile u##size __iomem *addr, u##size val) \ 113*dc5dac74SNicholas Piggin { \ 114*dc5dac74SNicholas Piggin __asm__ __volatile__("sync;"#insn" %1,0,%0" \ 115*dc5dac74SNicholas Piggin : : "r" (addr), "r" (val) : "memory"); \ 116*dc5dac74SNicholas Piggin mmiowb_set_pending(); \ 117*dc5dac74SNicholas Piggin } 118*dc5dac74SNicholas Piggin 119*dc5dac74SNicholas Piggin #define DEF_MMIO_IN_D(name, size, insn) \ 120*dc5dac74SNicholas Piggin static inline u##size name(const volatile u##size __iomem *addr) \ 121*dc5dac74SNicholas Piggin { \ 122*dc5dac74SNicholas Piggin u##size ret; \ 123*dc5dac74SNicholas Piggin __asm__ __volatile__("sync;"#insn" %0,0(%1);twi 0,%0,0;isync"\ 124*dc5dac74SNicholas Piggin : "=r" (ret) : "b" (addr) : "memory"); \ 125*dc5dac74SNicholas Piggin return ret; \ 126*dc5dac74SNicholas Piggin } 127*dc5dac74SNicholas Piggin 128*dc5dac74SNicholas Piggin #define DEF_MMIO_OUT_D(name, size, insn) \ 129*dc5dac74SNicholas Piggin static inline void name(volatile u##size __iomem *addr, u##size val) \ 130*dc5dac74SNicholas Piggin { \ 131*dc5dac74SNicholas Piggin __asm__ __volatile__("sync;"#insn" %1,0(%0)" \ 132*dc5dac74SNicholas Piggin : : "b" (addr), "r" (val) : "memory"); \ 133*dc5dac74SNicholas Piggin mmiowb_set_pending(); \ 134*dc5dac74SNicholas Piggin } 135*dc5dac74SNicholas Piggin #else 13615cba23eSIan Munsie #define DEF_MMIO_IN_X(name, size, insn) \ 137b8b572e1SStephen Rothwell static inline u##size name(const volatile u##size __iomem *addr) \ 138b8b572e1SStephen Rothwell { \ 139b8b572e1SStephen Rothwell u##size ret; \ 140b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %0,%y1;twi 0,%0,0;isync" \ 141b8b572e1SStephen Rothwell : "=r" (ret) : "Z" (*addr) : "memory"); \ 142b8b572e1SStephen Rothwell return ret; \ 143b8b572e1SStephen Rothwell } 144b8b572e1SStephen Rothwell 14515cba23eSIan Munsie #define DEF_MMIO_OUT_X(name, size, insn) \ 146b8b572e1SStephen Rothwell static inline void name(volatile u##size __iomem *addr, u##size val) \ 147b8b572e1SStephen Rothwell { \ 148b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn" %1,%y0" \ 149b8b572e1SStephen Rothwell : "=Z" (*addr) : "r" (val) : "memory"); \ 150420af155SWill Deacon mmiowb_set_pending(); \ 151b8b572e1SStephen Rothwell } 152b8b572e1SStephen Rothwell 15315cba23eSIan Munsie #define DEF_MMIO_IN_D(name, size, insn) \ 154b8b572e1SStephen Rothwell static inline u##size name(const volatile u##size __iomem *addr) \ 155b8b572e1SStephen Rothwell { \ 156b8b572e1SStephen Rothwell u##size ret; \ 157b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn"%U1%X1 %0,%1;twi 0,%0,0;isync"\ 1582a24d80fSNick Desaulniers : "=r" (ret) : "m<>" (*addr) : "memory"); \ 159b8b572e1SStephen Rothwell return ret; \ 160b8b572e1SStephen Rothwell } 161b8b572e1SStephen Rothwell 16215cba23eSIan Munsie #define DEF_MMIO_OUT_D(name, size, insn) \ 163b8b572e1SStephen Rothwell static inline void name(volatile u##size __iomem *addr, u##size val) \ 164b8b572e1SStephen Rothwell { \ 165b8b572e1SStephen Rothwell __asm__ __volatile__("sync;"#insn"%U0%X0 %1,%0" \ 1662a24d80fSNick Desaulniers : "=m<>" (*addr) : "r" (val) : "memory"); \ 167420af155SWill Deacon mmiowb_set_pending(); \ 168b8b572e1SStephen Rothwell } 169*dc5dac74SNicholas Piggin #endif 170b8b572e1SStephen Rothwell 17115cba23eSIan Munsie DEF_MMIO_IN_D(in_8, 8, lbz); 17215cba23eSIan Munsie DEF_MMIO_OUT_D(out_8, 8, stb); 173b8b572e1SStephen Rothwell 17415cba23eSIan Munsie #ifdef __BIG_ENDIAN__ 17515cba23eSIan Munsie DEF_MMIO_IN_D(in_be16, 16, lhz); 17615cba23eSIan Munsie DEF_MMIO_IN_D(in_be32, 32, lwz); 17715cba23eSIan Munsie DEF_MMIO_IN_X(in_le16, 16, lhbrx); 17815cba23eSIan Munsie DEF_MMIO_IN_X(in_le32, 32, lwbrx); 179b8b572e1SStephen Rothwell 18015cba23eSIan Munsie DEF_MMIO_OUT_D(out_be16, 16, sth); 18115cba23eSIan Munsie DEF_MMIO_OUT_D(out_be32, 32, stw); 18215cba23eSIan Munsie DEF_MMIO_OUT_X(out_le16, 16, sthbrx); 18315cba23eSIan Munsie DEF_MMIO_OUT_X(out_le32, 32, stwbrx); 18415cba23eSIan Munsie #else 18515cba23eSIan Munsie DEF_MMIO_IN_X(in_be16, 16, lhbrx); 18615cba23eSIan Munsie DEF_MMIO_IN_X(in_be32, 32, lwbrx); 18715cba23eSIan Munsie DEF_MMIO_IN_D(in_le16, 16, lhz); 18815cba23eSIan Munsie DEF_MMIO_IN_D(in_le32, 32, lwz); 18915cba23eSIan Munsie 19015cba23eSIan Munsie DEF_MMIO_OUT_X(out_be16, 16, sthbrx); 19115cba23eSIan Munsie DEF_MMIO_OUT_X(out_be32, 32, stwbrx); 19215cba23eSIan Munsie DEF_MMIO_OUT_D(out_le16, 16, sth); 19315cba23eSIan Munsie DEF_MMIO_OUT_D(out_le32, 32, stw); 19415cba23eSIan Munsie 19515cba23eSIan Munsie #endif /* __BIG_ENDIAN */ 196b8b572e1SStephen Rothwell 197b8b572e1SStephen Rothwell #ifdef __powerpc64__ 19815cba23eSIan Munsie 19915cba23eSIan Munsie #ifdef __BIG_ENDIAN__ 20015cba23eSIan Munsie DEF_MMIO_OUT_D(out_be64, 64, std); 20115cba23eSIan Munsie DEF_MMIO_IN_D(in_be64, 64, ld); 202b8b572e1SStephen Rothwell 203b8b572e1SStephen Rothwell /* There is no asm instructions for 64 bits reverse loads and stores */ 204b8b572e1SStephen Rothwell static inline u64 in_le64(const volatile u64 __iomem *addr) 205b8b572e1SStephen Rothwell { 206b8b572e1SStephen Rothwell return swab64(in_be64(addr)); 207b8b572e1SStephen Rothwell } 208b8b572e1SStephen Rothwell 209b8b572e1SStephen Rothwell static inline void out_le64(volatile u64 __iomem *addr, u64 val) 210b8b572e1SStephen Rothwell { 211b8b572e1SStephen Rothwell out_be64(addr, swab64(val)); 212b8b572e1SStephen Rothwell } 21315cba23eSIan Munsie #else 21415cba23eSIan Munsie DEF_MMIO_OUT_D(out_le64, 64, std); 21515cba23eSIan Munsie DEF_MMIO_IN_D(in_le64, 64, ld); 21615cba23eSIan Munsie 21715cba23eSIan Munsie /* There is no asm instructions for 64 bits reverse loads and stores */ 21815cba23eSIan Munsie static inline u64 in_be64(const volatile u64 __iomem *addr) 21915cba23eSIan Munsie { 22015cba23eSIan Munsie return swab64(in_le64(addr)); 22115cba23eSIan Munsie } 22215cba23eSIan Munsie 22315cba23eSIan Munsie static inline void out_be64(volatile u64 __iomem *addr, u64 val) 22415cba23eSIan Munsie { 22515cba23eSIan Munsie out_le64(addr, swab64(val)); 22615cba23eSIan Munsie } 22715cba23eSIan Munsie 22815cba23eSIan Munsie #endif 229b8b572e1SStephen Rothwell #endif /* __powerpc64__ */ 230b8b572e1SStephen Rothwell 231b8b572e1SStephen Rothwell /* 232b8b572e1SStephen Rothwell * Low level IO stream instructions are defined out of line for now 233b8b572e1SStephen Rothwell */ 234b8b572e1SStephen Rothwell extern void _insb(const volatile u8 __iomem *addr, void *buf, long count); 235b8b572e1SStephen Rothwell extern void _outsb(volatile u8 __iomem *addr,const void *buf,long count); 236b8b572e1SStephen Rothwell extern void _insw_ns(const volatile u16 __iomem *addr, void *buf, long count); 237b8b572e1SStephen Rothwell extern void _outsw_ns(volatile u16 __iomem *addr, const void *buf, long count); 238b8b572e1SStephen Rothwell extern void _insl_ns(const volatile u32 __iomem *addr, void *buf, long count); 239b8b572e1SStephen Rothwell extern void _outsl_ns(volatile u32 __iomem *addr, const void *buf, long count); 240b8b572e1SStephen Rothwell 241b8b572e1SStephen Rothwell /* The _ns naming is historical and will be removed. For now, just #define 242b8b572e1SStephen Rothwell * the non _ns equivalent names 243b8b572e1SStephen Rothwell */ 244b8b572e1SStephen Rothwell #define _insw _insw_ns 245b8b572e1SStephen Rothwell #define _insl _insl_ns 246b8b572e1SStephen Rothwell #define _outsw _outsw_ns 247b8b572e1SStephen Rothwell #define _outsl _outsl_ns 248b8b572e1SStephen Rothwell 249b8b572e1SStephen Rothwell 250b8b572e1SStephen Rothwell /* 251b8b572e1SStephen Rothwell * memset_io, memcpy_toio, memcpy_fromio base implementations are out of line 252b8b572e1SStephen Rothwell */ 253b8b572e1SStephen Rothwell 254b8b572e1SStephen Rothwell extern void _memset_io(volatile void __iomem *addr, int c, unsigned long n); 255b8b572e1SStephen Rothwell extern void _memcpy_fromio(void *dest, const volatile void __iomem *src, 256b8b572e1SStephen Rothwell unsigned long n); 257b8b572e1SStephen Rothwell extern void _memcpy_toio(volatile void __iomem *dest, const void *src, 258b8b572e1SStephen Rothwell unsigned long n); 259b8b572e1SStephen Rothwell 260b8b572e1SStephen Rothwell /* 261b8b572e1SStephen Rothwell * 262b8b572e1SStephen Rothwell * PCI and standard ISA accessors 263b8b572e1SStephen Rothwell * 264b8b572e1SStephen Rothwell * Those are globally defined linux accessors for devices on PCI or ISA 265b8b572e1SStephen Rothwell * busses. They follow the Linux defined semantics. The current implementation 266b8b572e1SStephen Rothwell * for PowerPC is as close as possible to the x86 version of these, and thus 267b8b572e1SStephen Rothwell * provides fairly heavy weight barriers for the non-raw versions 268b8b572e1SStephen Rothwell * 269ecd73cc5SBenjamin Herrenschmidt * In addition, they support a hook mechanism when CONFIG_PPC_INDIRECT_MMIO 270ecd73cc5SBenjamin Herrenschmidt * or CONFIG_PPC_INDIRECT_PIO are set allowing the platform to provide its 271ecd73cc5SBenjamin Herrenschmidt * own implementation of some or all of the accessors. 272b8b572e1SStephen Rothwell */ 273b8b572e1SStephen Rothwell 274b8b572e1SStephen Rothwell /* 275b8b572e1SStephen Rothwell * Include the EEH definitions when EEH is enabled only so they don't get 276b8b572e1SStephen Rothwell * in the way when building for 32 bits 277b8b572e1SStephen Rothwell */ 278b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 279b8b572e1SStephen Rothwell #include <asm/eeh.h> 280b8b572e1SStephen Rothwell #endif 281b8b572e1SStephen Rothwell 282b8b572e1SStephen Rothwell /* Shortcut to the MMIO argument pointer */ 283b8b572e1SStephen Rothwell #define PCI_IO_ADDR volatile void __iomem * 284b8b572e1SStephen Rothwell 285b8b572e1SStephen Rothwell /* Indirect IO address tokens: 286b8b572e1SStephen Rothwell * 287ecd73cc5SBenjamin Herrenschmidt * When CONFIG_PPC_INDIRECT_MMIO is set, the platform can provide hooks 288ecd73cc5SBenjamin Herrenschmidt * on all MMIOs. (Note that this is all 64 bits only for now) 289b8b572e1SStephen Rothwell * 290446957baSAdam Buchbinder * To help platforms who may need to differentiate MMIO addresses in 291b8b572e1SStephen Rothwell * their hooks, a bitfield is reserved for use by the platform near the 292b8b572e1SStephen Rothwell * top of MMIO addresses (not PIO, those have to cope the hard way). 293b8b572e1SStephen Rothwell * 29443c6494fSMichael Ellerman * The highest address in the kernel virtual space are: 295b8b572e1SStephen Rothwell * 29643c6494fSMichael Ellerman * d0003fffffffffff # with Hash MMU 29743c6494fSMichael Ellerman * c00fffffffffffff # with Radix MMU 298b8b572e1SStephen Rothwell * 29943c6494fSMichael Ellerman * The top 4 bits are reserved as the region ID on hash, leaving us 8 bits 30043c6494fSMichael Ellerman * that can be used for the field. 301b8b572e1SStephen Rothwell * 302b8b572e1SStephen Rothwell * The direct IO mapping operations will then mask off those bits 303b8b572e1SStephen Rothwell * before doing the actual access, though that only happen when 304ecd73cc5SBenjamin Herrenschmidt * CONFIG_PPC_INDIRECT_MMIO is set, thus be careful when you use that 305b8b572e1SStephen Rothwell * mechanism 306ecd73cc5SBenjamin Herrenschmidt * 307ecd73cc5SBenjamin Herrenschmidt * For PIO, there is a separate CONFIG_PPC_INDIRECT_PIO which makes 308ecd73cc5SBenjamin Herrenschmidt * all PIO functions call through a hook. 309b8b572e1SStephen Rothwell */ 310b8b572e1SStephen Rothwell 311ecd73cc5SBenjamin Herrenschmidt #ifdef CONFIG_PPC_INDIRECT_MMIO 31243c6494fSMichael Ellerman #define PCI_IO_IND_TOKEN_SHIFT 52 31343c6494fSMichael Ellerman #define PCI_IO_IND_TOKEN_MASK (0xfful << PCI_IO_IND_TOKEN_SHIFT) 314b8b572e1SStephen Rothwell #define PCI_FIX_ADDR(addr) \ 315b8b572e1SStephen Rothwell ((PCI_IO_ADDR)(((unsigned long)(addr)) & ~PCI_IO_IND_TOKEN_MASK)) 316b8b572e1SStephen Rothwell #define PCI_GET_ADDR_TOKEN(addr) \ 317b8b572e1SStephen Rothwell (((unsigned long)(addr) & PCI_IO_IND_TOKEN_MASK) >> \ 318b8b572e1SStephen Rothwell PCI_IO_IND_TOKEN_SHIFT) 319b8b572e1SStephen Rothwell #define PCI_SET_ADDR_TOKEN(addr, token) \ 320b8b572e1SStephen Rothwell do { \ 321b8b572e1SStephen Rothwell unsigned long __a = (unsigned long)(addr); \ 322b8b572e1SStephen Rothwell __a &= ~PCI_IO_IND_TOKEN_MASK; \ 323b8b572e1SStephen Rothwell __a |= ((unsigned long)(token)) << PCI_IO_IND_TOKEN_SHIFT; \ 324b8b572e1SStephen Rothwell (addr) = (void __iomem *)__a; \ 325b8b572e1SStephen Rothwell } while(0) 326b8b572e1SStephen Rothwell #else 327b8b572e1SStephen Rothwell #define PCI_FIX_ADDR(addr) (addr) 328b8b572e1SStephen Rothwell #endif 329b8b572e1SStephen Rothwell 330b8b572e1SStephen Rothwell 331b8b572e1SStephen Rothwell /* 332b8b572e1SStephen Rothwell * Non ordered and non-swapping "raw" accessors 333b8b572e1SStephen Rothwell */ 334b8b572e1SStephen Rothwell 335b8b572e1SStephen Rothwell static inline unsigned char __raw_readb(const volatile void __iomem *addr) 336b8b572e1SStephen Rothwell { 337b8b572e1SStephen Rothwell return *(volatile unsigned char __force *)PCI_FIX_ADDR(addr); 338b8b572e1SStephen Rothwell } 339894fa235SChristophe Leroy #define __raw_readb __raw_readb 340894fa235SChristophe Leroy 341b8b572e1SStephen Rothwell static inline unsigned short __raw_readw(const volatile void __iomem *addr) 342b8b572e1SStephen Rothwell { 343b8b572e1SStephen Rothwell return *(volatile unsigned short __force *)PCI_FIX_ADDR(addr); 344b8b572e1SStephen Rothwell } 345894fa235SChristophe Leroy #define __raw_readw __raw_readw 346894fa235SChristophe Leroy 347b8b572e1SStephen Rothwell static inline unsigned int __raw_readl(const volatile void __iomem *addr) 348b8b572e1SStephen Rothwell { 349b8b572e1SStephen Rothwell return *(volatile unsigned int __force *)PCI_FIX_ADDR(addr); 350b8b572e1SStephen Rothwell } 351894fa235SChristophe Leroy #define __raw_readl __raw_readl 352894fa235SChristophe Leroy 353b8b572e1SStephen Rothwell static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr) 354b8b572e1SStephen Rothwell { 355b8b572e1SStephen Rothwell *(volatile unsigned char __force *)PCI_FIX_ADDR(addr) = v; 356b8b572e1SStephen Rothwell } 357894fa235SChristophe Leroy #define __raw_writeb __raw_writeb 358894fa235SChristophe Leroy 359b8b572e1SStephen Rothwell static inline void __raw_writew(unsigned short v, volatile void __iomem *addr) 360b8b572e1SStephen Rothwell { 361b8b572e1SStephen Rothwell *(volatile unsigned short __force *)PCI_FIX_ADDR(addr) = v; 362b8b572e1SStephen Rothwell } 363894fa235SChristophe Leroy #define __raw_writew __raw_writew 364894fa235SChristophe Leroy 365b8b572e1SStephen Rothwell static inline void __raw_writel(unsigned int v, volatile void __iomem *addr) 366b8b572e1SStephen Rothwell { 367b8b572e1SStephen Rothwell *(volatile unsigned int __force *)PCI_FIX_ADDR(addr) = v; 368b8b572e1SStephen Rothwell } 369894fa235SChristophe Leroy #define __raw_writel __raw_writel 370b8b572e1SStephen Rothwell 371b8b572e1SStephen Rothwell #ifdef __powerpc64__ 372b8b572e1SStephen Rothwell static inline unsigned long __raw_readq(const volatile void __iomem *addr) 373b8b572e1SStephen Rothwell { 374b8b572e1SStephen Rothwell return *(volatile unsigned long __force *)PCI_FIX_ADDR(addr); 375b8b572e1SStephen Rothwell } 376894fa235SChristophe Leroy #define __raw_readq __raw_readq 377894fa235SChristophe Leroy 378b8b572e1SStephen Rothwell static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr) 379b8b572e1SStephen Rothwell { 380b8b572e1SStephen Rothwell *(volatile unsigned long __force *)PCI_FIX_ADDR(addr) = v; 381b8b572e1SStephen Rothwell } 382894fa235SChristophe Leroy #define __raw_writeq __raw_writeq 383a84bf321SAlistair Popple 3848056fe28SMichael Ellerman static inline void __raw_writeq_be(unsigned long v, volatile void __iomem *addr) 3858056fe28SMichael Ellerman { 3868056fe28SMichael Ellerman __raw_writeq((__force unsigned long)cpu_to_be64(v), addr); 3878056fe28SMichael Ellerman } 388894fa235SChristophe Leroy #define __raw_writeq_be __raw_writeq_be 3898056fe28SMichael Ellerman 390a84bf321SAlistair Popple /* 391d381d7caSBenjamin Herrenschmidt * Real mode versions of the above. Those instructions are only supposed 392d381d7caSBenjamin Herrenschmidt * to be used in hypervisor real mode as per the architecture spec. 393a84bf321SAlistair Popple */ 394d381d7caSBenjamin Herrenschmidt static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr) 395d381d7caSBenjamin Herrenschmidt { 3968667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 3978667d0d6SAnders Roxell .machine power6; \ 3988667d0d6SAnders Roxell stbcix %0,0,%1; \ 3998667d0d6SAnders Roxell .machine pop;" 400d381d7caSBenjamin Herrenschmidt : : "r" (val), "r" (paddr) : "memory"); 401d381d7caSBenjamin Herrenschmidt } 402d381d7caSBenjamin Herrenschmidt 403d381d7caSBenjamin Herrenschmidt static inline void __raw_rm_writew(u16 val, volatile void __iomem *paddr) 404d381d7caSBenjamin Herrenschmidt { 4058667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4068667d0d6SAnders Roxell .machine power6; \ 4078667d0d6SAnders Roxell sthcix %0,0,%1; \ 4088667d0d6SAnders Roxell .machine pop;" 409d381d7caSBenjamin Herrenschmidt : : "r" (val), "r" (paddr) : "memory"); 410d381d7caSBenjamin Herrenschmidt } 411d381d7caSBenjamin Herrenschmidt 412d381d7caSBenjamin Herrenschmidt static inline void __raw_rm_writel(u32 val, volatile void __iomem *paddr) 413d381d7caSBenjamin Herrenschmidt { 4148667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4158667d0d6SAnders Roxell .machine power6; \ 4168667d0d6SAnders Roxell stwcix %0,0,%1; \ 4178667d0d6SAnders Roxell .machine pop;" 418d381d7caSBenjamin Herrenschmidt : : "r" (val), "r" (paddr) : "memory"); 419d381d7caSBenjamin Herrenschmidt } 420d381d7caSBenjamin Herrenschmidt 421a84bf321SAlistair Popple static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr) 422a84bf321SAlistair Popple { 4238667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4248667d0d6SAnders Roxell .machine power6; \ 4258667d0d6SAnders Roxell stdcix %0,0,%1; \ 4268667d0d6SAnders Roxell .machine pop;" 427a84bf321SAlistair Popple : : "r" (val), "r" (paddr) : "memory"); 428a84bf321SAlistair Popple } 429a84bf321SAlistair Popple 4308056fe28SMichael Ellerman static inline void __raw_rm_writeq_be(u64 val, volatile void __iomem *paddr) 4318056fe28SMichael Ellerman { 4328056fe28SMichael Ellerman __raw_rm_writeq((__force u64)cpu_to_be64(val), paddr); 4338056fe28SMichael Ellerman } 4348056fe28SMichael Ellerman 435d381d7caSBenjamin Herrenschmidt static inline u8 __raw_rm_readb(volatile void __iomem *paddr) 436d381d7caSBenjamin Herrenschmidt { 437d381d7caSBenjamin Herrenschmidt u8 ret; 4388667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4398667d0d6SAnders Roxell .machine power6; \ 4408667d0d6SAnders Roxell lbzcix %0,0, %1; \ 4418667d0d6SAnders Roxell .machine pop;" 442d381d7caSBenjamin Herrenschmidt : "=r" (ret) : "r" (paddr) : "memory"); 443d381d7caSBenjamin Herrenschmidt return ret; 444d381d7caSBenjamin Herrenschmidt } 445d381d7caSBenjamin Herrenschmidt 446d381d7caSBenjamin Herrenschmidt static inline u16 __raw_rm_readw(volatile void __iomem *paddr) 447d381d7caSBenjamin Herrenschmidt { 448d381d7caSBenjamin Herrenschmidt u16 ret; 4498667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4508667d0d6SAnders Roxell .machine power6; \ 4518667d0d6SAnders Roxell lhzcix %0,0, %1; \ 4528667d0d6SAnders Roxell .machine pop;" 453d381d7caSBenjamin Herrenschmidt : "=r" (ret) : "r" (paddr) : "memory"); 454d381d7caSBenjamin Herrenschmidt return ret; 455d381d7caSBenjamin Herrenschmidt } 456d381d7caSBenjamin Herrenschmidt 457d381d7caSBenjamin Herrenschmidt static inline u32 __raw_rm_readl(volatile void __iomem *paddr) 458d381d7caSBenjamin Herrenschmidt { 459d381d7caSBenjamin Herrenschmidt u32 ret; 4608667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4618667d0d6SAnders Roxell .machine power6; \ 4628667d0d6SAnders Roxell lwzcix %0,0, %1; \ 4638667d0d6SAnders Roxell .machine pop;" 464d381d7caSBenjamin Herrenschmidt : "=r" (ret) : "r" (paddr) : "memory"); 465d381d7caSBenjamin Herrenschmidt return ret; 466d381d7caSBenjamin Herrenschmidt } 467d381d7caSBenjamin Herrenschmidt 468d381d7caSBenjamin Herrenschmidt static inline u64 __raw_rm_readq(volatile void __iomem *paddr) 469d381d7caSBenjamin Herrenschmidt { 470d381d7caSBenjamin Herrenschmidt u64 ret; 4718667d0d6SAnders Roxell __asm__ __volatile__(".machine push; \ 4728667d0d6SAnders Roxell .machine power6; \ 4738667d0d6SAnders Roxell ldcix %0,0, %1; \ 4748667d0d6SAnders Roxell .machine pop;" 475d381d7caSBenjamin Herrenschmidt : "=r" (ret) : "r" (paddr) : "memory"); 476d381d7caSBenjamin Herrenschmidt return ret; 477d381d7caSBenjamin Herrenschmidt } 478b8b572e1SStephen Rothwell #endif /* __powerpc64__ */ 479b8b572e1SStephen Rothwell 480b8b572e1SStephen Rothwell /* 481b8b572e1SStephen Rothwell * 482b8b572e1SStephen Rothwell * PCI PIO and MMIO accessors. 483b8b572e1SStephen Rothwell * 484b8b572e1SStephen Rothwell * 485b8b572e1SStephen Rothwell * On 32 bits, PIO operations have a recovery mechanism in case they trigger 486b8b572e1SStephen Rothwell * machine checks (which they occasionally do when probing non existing 487b8b572e1SStephen Rothwell * IO ports on some platforms, like PowerMac and 8xx). 488b8b572e1SStephen Rothwell * I always found it to be of dubious reliability and I am tempted to get 489b8b572e1SStephen Rothwell * rid of it one of these days. So if you think it's important to keep it, 490b8b572e1SStephen Rothwell * please voice up asap. We never had it for 64 bits and I do not intend 491b8b572e1SStephen Rothwell * to port it over 492b8b572e1SStephen Rothwell */ 493b8b572e1SStephen Rothwell 494b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 495b8b572e1SStephen Rothwell 496b8b572e1SStephen Rothwell #define __do_in_asm(name, op) \ 497b8b572e1SStephen Rothwell static inline unsigned int name(unsigned int port) \ 498b8b572e1SStephen Rothwell { \ 499b8b572e1SStephen Rothwell unsigned int x; \ 500b8b572e1SStephen Rothwell __asm__ __volatile__( \ 501b8b572e1SStephen Rothwell "sync\n" \ 502b8b572e1SStephen Rothwell "0:" op " %0,0,%1\n" \ 503b8b572e1SStephen Rothwell "1: twi 0,%0,0\n" \ 504b8b572e1SStephen Rothwell "2: isync\n" \ 505b8b572e1SStephen Rothwell "3: nop\n" \ 506b8b572e1SStephen Rothwell "4:\n" \ 507b8b572e1SStephen Rothwell ".section .fixup,\"ax\"\n" \ 508b8b572e1SStephen Rothwell "5: li %0,-1\n" \ 509b8b572e1SStephen Rothwell " b 4b\n" \ 510b8b572e1SStephen Rothwell ".previous\n" \ 51124bfa6a9SNicholas Piggin EX_TABLE(0b, 5b) \ 51224bfa6a9SNicholas Piggin EX_TABLE(1b, 5b) \ 51324bfa6a9SNicholas Piggin EX_TABLE(2b, 5b) \ 51424bfa6a9SNicholas Piggin EX_TABLE(3b, 5b) \ 515b8b572e1SStephen Rothwell : "=&r" (x) \ 516b8b572e1SStephen Rothwell : "r" (port + _IO_BASE) \ 517b8b572e1SStephen Rothwell : "memory"); \ 518b8b572e1SStephen Rothwell return x; \ 519b8b572e1SStephen Rothwell } 520b8b572e1SStephen Rothwell 521b8b572e1SStephen Rothwell #define __do_out_asm(name, op) \ 522b8b572e1SStephen Rothwell static inline void name(unsigned int val, unsigned int port) \ 523b8b572e1SStephen Rothwell { \ 524b8b572e1SStephen Rothwell __asm__ __volatile__( \ 525b8b572e1SStephen Rothwell "sync\n" \ 526b8b572e1SStephen Rothwell "0:" op " %0,0,%1\n" \ 527b8b572e1SStephen Rothwell "1: sync\n" \ 528b8b572e1SStephen Rothwell "2:\n" \ 52924bfa6a9SNicholas Piggin EX_TABLE(0b, 2b) \ 53024bfa6a9SNicholas Piggin EX_TABLE(1b, 2b) \ 531b8b572e1SStephen Rothwell : : "r" (val), "r" (port + _IO_BASE) \ 532b8b572e1SStephen Rothwell : "memory"); \ 533b8b572e1SStephen Rothwell } 534b8b572e1SStephen Rothwell 535b8b572e1SStephen Rothwell __do_in_asm(_rec_inb, "lbzx") 536b8b572e1SStephen Rothwell __do_in_asm(_rec_inw, "lhbrx") 537b8b572e1SStephen Rothwell __do_in_asm(_rec_inl, "lwbrx") 538b8b572e1SStephen Rothwell __do_out_asm(_rec_outb, "stbx") 539b8b572e1SStephen Rothwell __do_out_asm(_rec_outw, "sthbrx") 540b8b572e1SStephen Rothwell __do_out_asm(_rec_outl, "stwbrx") 541b8b572e1SStephen Rothwell 542b8b572e1SStephen Rothwell #endif /* CONFIG_PPC32 */ 543b8b572e1SStephen Rothwell 544b8b572e1SStephen Rothwell /* The "__do_*" operations below provide the actual "base" implementation 54542b2aa86SJustin P. Mattock * for each of the defined accessors. Some of them use the out_* functions 546b8b572e1SStephen Rothwell * directly, some of them still use EEH, though we might change that in the 547b8b572e1SStephen Rothwell * future. Those macros below provide the necessary argument swapping and 548b8b572e1SStephen Rothwell * handling of the IO base for PIO. 549b8b572e1SStephen Rothwell * 550b8b572e1SStephen Rothwell * They are themselves used by the macros that define the actual accessors 551b8b572e1SStephen Rothwell * and can be used by the hooks if any. 552b8b572e1SStephen Rothwell * 553b8b572e1SStephen Rothwell * Note that PIO operations are always defined in terms of their corresonding 554b8b572e1SStephen Rothwell * MMIO operations. That allows platforms like iSeries who want to modify the 555b8b572e1SStephen Rothwell * behaviour of both to only hook on the MMIO version and get both. It's also 556b8b572e1SStephen Rothwell * possible to hook directly at the toplevel PIO operation if they have to 557b8b572e1SStephen Rothwell * be handled differently 558b8b572e1SStephen Rothwell */ 559b8b572e1SStephen Rothwell #define __do_writeb(val, addr) out_8(PCI_FIX_ADDR(addr), val) 560b8b572e1SStephen Rothwell #define __do_writew(val, addr) out_le16(PCI_FIX_ADDR(addr), val) 561b8b572e1SStephen Rothwell #define __do_writel(val, addr) out_le32(PCI_FIX_ADDR(addr), val) 562b8b572e1SStephen Rothwell #define __do_writeq(val, addr) out_le64(PCI_FIX_ADDR(addr), val) 563b8b572e1SStephen Rothwell #define __do_writew_be(val, addr) out_be16(PCI_FIX_ADDR(addr), val) 564b8b572e1SStephen Rothwell #define __do_writel_be(val, addr) out_be32(PCI_FIX_ADDR(addr), val) 565b8b572e1SStephen Rothwell #define __do_writeq_be(val, addr) out_be64(PCI_FIX_ADDR(addr), val) 566b8b572e1SStephen Rothwell 567b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 568b8b572e1SStephen Rothwell #define __do_readb(addr) eeh_readb(PCI_FIX_ADDR(addr)) 569b8b572e1SStephen Rothwell #define __do_readw(addr) eeh_readw(PCI_FIX_ADDR(addr)) 570b8b572e1SStephen Rothwell #define __do_readl(addr) eeh_readl(PCI_FIX_ADDR(addr)) 571b8b572e1SStephen Rothwell #define __do_readq(addr) eeh_readq(PCI_FIX_ADDR(addr)) 572b8b572e1SStephen Rothwell #define __do_readw_be(addr) eeh_readw_be(PCI_FIX_ADDR(addr)) 573b8b572e1SStephen Rothwell #define __do_readl_be(addr) eeh_readl_be(PCI_FIX_ADDR(addr)) 574b8b572e1SStephen Rothwell #define __do_readq_be(addr) eeh_readq_be(PCI_FIX_ADDR(addr)) 575b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 576b8b572e1SStephen Rothwell #define __do_readb(addr) in_8(PCI_FIX_ADDR(addr)) 577b8b572e1SStephen Rothwell #define __do_readw(addr) in_le16(PCI_FIX_ADDR(addr)) 578b8b572e1SStephen Rothwell #define __do_readl(addr) in_le32(PCI_FIX_ADDR(addr)) 579b8b572e1SStephen Rothwell #define __do_readq(addr) in_le64(PCI_FIX_ADDR(addr)) 580b8b572e1SStephen Rothwell #define __do_readw_be(addr) in_be16(PCI_FIX_ADDR(addr)) 581b8b572e1SStephen Rothwell #define __do_readl_be(addr) in_be32(PCI_FIX_ADDR(addr)) 582b8b572e1SStephen Rothwell #define __do_readq_be(addr) in_be64(PCI_FIX_ADDR(addr)) 583b8b572e1SStephen Rothwell #endif /* !defined(CONFIG_EEH) */ 584b8b572e1SStephen Rothwell 585b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 586b8b572e1SStephen Rothwell #define __do_outb(val, port) _rec_outb(val, port) 587b8b572e1SStephen Rothwell #define __do_outw(val, port) _rec_outw(val, port) 588b8b572e1SStephen Rothwell #define __do_outl(val, port) _rec_outl(val, port) 589b8b572e1SStephen Rothwell #define __do_inb(port) _rec_inb(port) 590b8b572e1SStephen Rothwell #define __do_inw(port) _rec_inw(port) 591b8b572e1SStephen Rothwell #define __do_inl(port) _rec_inl(port) 592b8b572e1SStephen Rothwell #else /* CONFIG_PPC32 */ 593b8b572e1SStephen Rothwell #define __do_outb(val, port) writeb(val,(PCI_IO_ADDR)_IO_BASE+port); 594b8b572e1SStephen Rothwell #define __do_outw(val, port) writew(val,(PCI_IO_ADDR)_IO_BASE+port); 595b8b572e1SStephen Rothwell #define __do_outl(val, port) writel(val,(PCI_IO_ADDR)_IO_BASE+port); 596b8b572e1SStephen Rothwell #define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port); 597b8b572e1SStephen Rothwell #define __do_inw(port) readw((PCI_IO_ADDR)_IO_BASE + port); 598b8b572e1SStephen Rothwell #define __do_inl(port) readl((PCI_IO_ADDR)_IO_BASE + port); 599b8b572e1SStephen Rothwell #endif /* !CONFIG_PPC32 */ 600b8b572e1SStephen Rothwell 601b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 602b8b572e1SStephen Rothwell #define __do_readsb(a, b, n) eeh_readsb(PCI_FIX_ADDR(a), (b), (n)) 603b8b572e1SStephen Rothwell #define __do_readsw(a, b, n) eeh_readsw(PCI_FIX_ADDR(a), (b), (n)) 604b8b572e1SStephen Rothwell #define __do_readsl(a, b, n) eeh_readsl(PCI_FIX_ADDR(a), (b), (n)) 605b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 606b8b572e1SStephen Rothwell #define __do_readsb(a, b, n) _insb(PCI_FIX_ADDR(a), (b), (n)) 607b8b572e1SStephen Rothwell #define __do_readsw(a, b, n) _insw(PCI_FIX_ADDR(a), (b), (n)) 608b8b572e1SStephen Rothwell #define __do_readsl(a, b, n) _insl(PCI_FIX_ADDR(a), (b), (n)) 609b8b572e1SStephen Rothwell #endif /* !CONFIG_EEH */ 610b8b572e1SStephen Rothwell #define __do_writesb(a, b, n) _outsb(PCI_FIX_ADDR(a),(b),(n)) 611b8b572e1SStephen Rothwell #define __do_writesw(a, b, n) _outsw(PCI_FIX_ADDR(a),(b),(n)) 612b8b572e1SStephen Rothwell #define __do_writesl(a, b, n) _outsl(PCI_FIX_ADDR(a),(b),(n)) 613b8b572e1SStephen Rothwell 614b8b572e1SStephen Rothwell #define __do_insb(p, b, n) readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 615b8b572e1SStephen Rothwell #define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 616b8b572e1SStephen Rothwell #define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) 617b8b572e1SStephen Rothwell #define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 618b8b572e1SStephen Rothwell #define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 619b8b572e1SStephen Rothwell #define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) 620b8b572e1SStephen Rothwell 621b8b572e1SStephen Rothwell #define __do_memset_io(addr, c, n) \ 622b8b572e1SStephen Rothwell _memset_io(PCI_FIX_ADDR(addr), c, n) 623b8b572e1SStephen Rothwell #define __do_memcpy_toio(dst, src, n) \ 624b8b572e1SStephen Rothwell _memcpy_toio(PCI_FIX_ADDR(dst), src, n) 625b8b572e1SStephen Rothwell 626b8b572e1SStephen Rothwell #ifdef CONFIG_EEH 627b8b572e1SStephen Rothwell #define __do_memcpy_fromio(dst, src, n) \ 628b8b572e1SStephen Rothwell eeh_memcpy_fromio(dst, PCI_FIX_ADDR(src), n) 629b8b572e1SStephen Rothwell #else /* CONFIG_EEH */ 630b8b572e1SStephen Rothwell #define __do_memcpy_fromio(dst, src, n) \ 631b8b572e1SStephen Rothwell _memcpy_fromio(dst,PCI_FIX_ADDR(src),n) 632b8b572e1SStephen Rothwell #endif /* !CONFIG_EEH */ 633b8b572e1SStephen Rothwell 63421176fedSMichael Ellerman #ifdef CONFIG_PPC_INDIRECT_PIO 63521176fedSMichael Ellerman #define DEF_PCI_HOOK_pio(x) x 636b8b572e1SStephen Rothwell #else 63721176fedSMichael Ellerman #define DEF_PCI_HOOK_pio(x) NULL 63821176fedSMichael Ellerman #endif 63921176fedSMichael Ellerman 64021176fedSMichael Ellerman #ifdef CONFIG_PPC_INDIRECT_MMIO 64121176fedSMichael Ellerman #define DEF_PCI_HOOK_mem(x) x 64221176fedSMichael Ellerman #else 64321176fedSMichael Ellerman #define DEF_PCI_HOOK_mem(x) NULL 644b8b572e1SStephen Rothwell #endif 645b8b572e1SStephen Rothwell 646b8b572e1SStephen Rothwell /* Structure containing all the hooks */ 647b8b572e1SStephen Rothwell extern struct ppc_pci_io { 648b8b572e1SStephen Rothwell 649b8b572e1SStephen Rothwell #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) ret (*name) at; 650b8b572e1SStephen Rothwell #define DEF_PCI_AC_NORET(name, at, al, space, aa) void (*name) at; 651b8b572e1SStephen Rothwell 652b8b572e1SStephen Rothwell #include <asm/io-defs.h> 653b8b572e1SStephen Rothwell 654b8b572e1SStephen Rothwell #undef DEF_PCI_AC_RET 655b8b572e1SStephen Rothwell #undef DEF_PCI_AC_NORET 656b8b572e1SStephen Rothwell 657b8b572e1SStephen Rothwell } ppc_pci_io; 658b8b572e1SStephen Rothwell 659b8b572e1SStephen Rothwell /* The inline wrappers */ 660b8b572e1SStephen Rothwell #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \ 661b8b572e1SStephen Rothwell static inline ret name at \ 662b8b572e1SStephen Rothwell { \ 66321176fedSMichael Ellerman if (DEF_PCI_HOOK_##space(ppc_pci_io.name) != NULL) \ 664b8b572e1SStephen Rothwell return ppc_pci_io.name al; \ 665b8b572e1SStephen Rothwell return __do_##name al; \ 666b8b572e1SStephen Rothwell } 667b8b572e1SStephen Rothwell 668b8b572e1SStephen Rothwell #define DEF_PCI_AC_NORET(name, at, al, space, aa) \ 669b8b572e1SStephen Rothwell static inline void name at \ 670b8b572e1SStephen Rothwell { \ 67121176fedSMichael Ellerman if (DEF_PCI_HOOK_##space(ppc_pci_io.name) != NULL) \ 672b8b572e1SStephen Rothwell ppc_pci_io.name al; \ 673b8b572e1SStephen Rothwell else \ 674b8b572e1SStephen Rothwell __do_##name al; \ 675b8b572e1SStephen Rothwell } 676b8b572e1SStephen Rothwell 677b8b572e1SStephen Rothwell #include <asm/io-defs.h> 678b8b572e1SStephen Rothwell 679b8b572e1SStephen Rothwell #undef DEF_PCI_AC_RET 680b8b572e1SStephen Rothwell #undef DEF_PCI_AC_NORET 681b8b572e1SStephen Rothwell 682b8b572e1SStephen Rothwell /* Some drivers check for the presence of readq & writeq with 683b8b572e1SStephen Rothwell * a #ifdef, so we make them happy here. 684b8b572e1SStephen Rothwell */ 685894fa235SChristophe Leroy #define readb readb 686894fa235SChristophe Leroy #define readw readw 687894fa235SChristophe Leroy #define readl readl 688894fa235SChristophe Leroy #define writeb writeb 689894fa235SChristophe Leroy #define writew writew 690894fa235SChristophe Leroy #define writel writel 691894fa235SChristophe Leroy #define readsb readsb 692894fa235SChristophe Leroy #define readsw readsw 693894fa235SChristophe Leroy #define readsl readsl 694894fa235SChristophe Leroy #define writesb writesb 695894fa235SChristophe Leroy #define writesw writesw 696894fa235SChristophe Leroy #define writesl writesl 697894fa235SChristophe Leroy #define inb inb 698894fa235SChristophe Leroy #define inw inw 699894fa235SChristophe Leroy #define inl inl 700894fa235SChristophe Leroy #define outb outb 701894fa235SChristophe Leroy #define outw outw 702894fa235SChristophe Leroy #define outl outl 703894fa235SChristophe Leroy #define insb insb 704894fa235SChristophe Leroy #define insw insw 705894fa235SChristophe Leroy #define insl insl 706894fa235SChristophe Leroy #define outsb outsb 707894fa235SChristophe Leroy #define outsw outsw 708894fa235SChristophe Leroy #define outsl outsl 709b8b572e1SStephen Rothwell #ifdef __powerpc64__ 710b8b572e1SStephen Rothwell #define readq readq 711b8b572e1SStephen Rothwell #define writeq writeq 712b8b572e1SStephen Rothwell #endif 713894fa235SChristophe Leroy #define memset_io memset_io 714894fa235SChristophe Leroy #define memcpy_fromio memcpy_fromio 715894fa235SChristophe Leroy #define memcpy_toio memcpy_toio 716b8b572e1SStephen Rothwell 717b8b572e1SStephen Rothwell /* 718b8b572e1SStephen Rothwell * Convert a physical pointer to a virtual kernel pointer for /dev/mem 719b8b572e1SStephen Rothwell * access 720b8b572e1SStephen Rothwell */ 721b8b572e1SStephen Rothwell #define xlate_dev_mem_ptr(p) __va(p) 722b8b572e1SStephen Rothwell 723b8b572e1SStephen Rothwell /* 724b8b572e1SStephen Rothwell * We don't do relaxed operations yet, at least not with this semantic 725b8b572e1SStephen Rothwell */ 726b8b572e1SStephen Rothwell #define readb_relaxed(addr) readb(addr) 727b8b572e1SStephen Rothwell #define readw_relaxed(addr) readw(addr) 728b8b572e1SStephen Rothwell #define readl_relaxed(addr) readl(addr) 729b8b572e1SStephen Rothwell #define readq_relaxed(addr) readq(addr) 7305da59057SWill Deacon #define writeb_relaxed(v, addr) writeb(v, addr) 7315da59057SWill Deacon #define writew_relaxed(v, addr) writew(v, addr) 7325da59057SWill Deacon #define writel_relaxed(v, addr) writel(v, addr) 7335da59057SWill Deacon #define writeq_relaxed(v, addr) writeq(v, addr) 734b8b572e1SStephen Rothwell 735894fa235SChristophe Leroy #ifdef CONFIG_GENERIC_IOMAP 736ef237039SLogan Gunthorpe #include <asm-generic/iomap.h> 737894fa235SChristophe Leroy #else 738894fa235SChristophe Leroy /* 739894fa235SChristophe Leroy * Here comes the implementation of the IOMAP interfaces. 740894fa235SChristophe Leroy */ 741894fa235SChristophe Leroy static inline unsigned int ioread16be(const void __iomem *addr) 742894fa235SChristophe Leroy { 743894fa235SChristophe Leroy return readw_be(addr); 744894fa235SChristophe Leroy } 745894fa235SChristophe Leroy #define ioread16be ioread16be 746894fa235SChristophe Leroy 747894fa235SChristophe Leroy static inline unsigned int ioread32be(const void __iomem *addr) 748894fa235SChristophe Leroy { 749894fa235SChristophe Leroy return readl_be(addr); 750894fa235SChristophe Leroy } 751894fa235SChristophe Leroy #define ioread32be ioread32be 752894fa235SChristophe Leroy 753894fa235SChristophe Leroy #ifdef __powerpc64__ 754894fa235SChristophe Leroy static inline u64 ioread64_lo_hi(const void __iomem *addr) 755894fa235SChristophe Leroy { 756894fa235SChristophe Leroy return readq(addr); 757894fa235SChristophe Leroy } 758894fa235SChristophe Leroy #define ioread64_lo_hi ioread64_lo_hi 759894fa235SChristophe Leroy 760894fa235SChristophe Leroy static inline u64 ioread64_hi_lo(const void __iomem *addr) 761894fa235SChristophe Leroy { 762894fa235SChristophe Leroy return readq(addr); 763894fa235SChristophe Leroy } 764894fa235SChristophe Leroy #define ioread64_hi_lo ioread64_hi_lo 765894fa235SChristophe Leroy 766894fa235SChristophe Leroy static inline u64 ioread64be(const void __iomem *addr) 767894fa235SChristophe Leroy { 768894fa235SChristophe Leroy return readq_be(addr); 769894fa235SChristophe Leroy } 770894fa235SChristophe Leroy #define ioread64be ioread64be 771894fa235SChristophe Leroy 772894fa235SChristophe Leroy static inline u64 ioread64be_lo_hi(const void __iomem *addr) 773894fa235SChristophe Leroy { 774894fa235SChristophe Leroy return readq_be(addr); 775894fa235SChristophe Leroy } 776894fa235SChristophe Leroy #define ioread64be_lo_hi ioread64be_lo_hi 777894fa235SChristophe Leroy 778894fa235SChristophe Leroy static inline u64 ioread64be_hi_lo(const void __iomem *addr) 779894fa235SChristophe Leroy { 780894fa235SChristophe Leroy return readq_be(addr); 781894fa235SChristophe Leroy } 782894fa235SChristophe Leroy #define ioread64be_hi_lo ioread64be_hi_lo 783894fa235SChristophe Leroy #endif /* __powerpc64__ */ 784894fa235SChristophe Leroy 785894fa235SChristophe Leroy static inline void iowrite16be(u16 val, void __iomem *addr) 786894fa235SChristophe Leroy { 787894fa235SChristophe Leroy writew_be(val, addr); 788894fa235SChristophe Leroy } 789894fa235SChristophe Leroy #define iowrite16be iowrite16be 790894fa235SChristophe Leroy 791894fa235SChristophe Leroy static inline void iowrite32be(u32 val, void __iomem *addr) 792894fa235SChristophe Leroy { 793894fa235SChristophe Leroy writel_be(val, addr); 794894fa235SChristophe Leroy } 795894fa235SChristophe Leroy #define iowrite32be iowrite32be 796894fa235SChristophe Leroy 797894fa235SChristophe Leroy #ifdef __powerpc64__ 798894fa235SChristophe Leroy static inline void iowrite64_lo_hi(u64 val, void __iomem *addr) 799894fa235SChristophe Leroy { 800894fa235SChristophe Leroy writeq(val, addr); 801894fa235SChristophe Leroy } 802894fa235SChristophe Leroy #define iowrite64_lo_hi iowrite64_lo_hi 803894fa235SChristophe Leroy 804894fa235SChristophe Leroy static inline void iowrite64_hi_lo(u64 val, void __iomem *addr) 805894fa235SChristophe Leroy { 806894fa235SChristophe Leroy writeq(val, addr); 807894fa235SChristophe Leroy } 808894fa235SChristophe Leroy #define iowrite64_hi_lo iowrite64_hi_lo 809894fa235SChristophe Leroy 810894fa235SChristophe Leroy static inline void iowrite64be(u64 val, void __iomem *addr) 811894fa235SChristophe Leroy { 812894fa235SChristophe Leroy writeq_be(val, addr); 813894fa235SChristophe Leroy } 814894fa235SChristophe Leroy #define iowrite64be iowrite64be 815894fa235SChristophe Leroy 816894fa235SChristophe Leroy static inline void iowrite64be_lo_hi(u64 val, void __iomem *addr) 817894fa235SChristophe Leroy { 818894fa235SChristophe Leroy writeq_be(val, addr); 819894fa235SChristophe Leroy } 820894fa235SChristophe Leroy #define iowrite64be_lo_hi iowrite64be_lo_hi 821894fa235SChristophe Leroy 822894fa235SChristophe Leroy static inline void iowrite64be_hi_lo(u64 val, void __iomem *addr) 823894fa235SChristophe Leroy { 824894fa235SChristophe Leroy writeq_be(val, addr); 825894fa235SChristophe Leroy } 826894fa235SChristophe Leroy #define iowrite64be_hi_lo iowrite64be_hi_lo 827894fa235SChristophe Leroy #endif /* __powerpc64__ */ 828894fa235SChristophe Leroy 829894fa235SChristophe Leroy struct pci_dev; 830894fa235SChristophe Leroy void pci_iounmap(struct pci_dev *dev, void __iomem *addr); 831894fa235SChristophe Leroy #define pci_iounmap pci_iounmap 832894fa235SChristophe Leroy void __iomem *ioport_map(unsigned long port, unsigned int len); 833894fa235SChristophe Leroy #define ioport_map ioport_map 834894fa235SChristophe Leroy #endif 835ef237039SLogan Gunthorpe 836b8b572e1SStephen Rothwell static inline void iosync(void) 837b8b572e1SStephen Rothwell { 838b8b572e1SStephen Rothwell __asm__ __volatile__ ("sync" : : : "memory"); 839b8b572e1SStephen Rothwell } 840b8b572e1SStephen Rothwell 841b8b572e1SStephen Rothwell /* Enforce in-order execution of data I/O. 842b8b572e1SStephen Rothwell * No distinction between read/write on PPC; use eieio for all three. 843b8b572e1SStephen Rothwell * Those are fairly week though. They don't provide a barrier between 844b8b572e1SStephen Rothwell * MMIO and cacheable storage nor do they provide a barrier vs. locks, 845b8b572e1SStephen Rothwell * they only provide barriers between 2 __raw MMIO operations and 846b8b572e1SStephen Rothwell * possibly break write combining. 847b8b572e1SStephen Rothwell */ 848b8b572e1SStephen Rothwell #define iobarrier_rw() eieio() 849b8b572e1SStephen Rothwell #define iobarrier_r() eieio() 850b8b572e1SStephen Rothwell #define iobarrier_w() eieio() 851b8b572e1SStephen Rothwell 852b8b572e1SStephen Rothwell 853b8b572e1SStephen Rothwell /* 854b8b572e1SStephen Rothwell * output pause versions need a delay at least for the 855b8b572e1SStephen Rothwell * w83c105 ide controller in a p610. 856b8b572e1SStephen Rothwell */ 857b8b572e1SStephen Rothwell #define inb_p(port) inb(port) 858b8b572e1SStephen Rothwell #define outb_p(val, port) (udelay(1), outb((val), (port))) 859b8b572e1SStephen Rothwell #define inw_p(port) inw(port) 860b8b572e1SStephen Rothwell #define outw_p(val, port) (udelay(1), outw((val), (port))) 861b8b572e1SStephen Rothwell #define inl_p(port) inl(port) 862b8b572e1SStephen Rothwell #define outl_p(val, port) (udelay(1), outl((val), (port))) 863b8b572e1SStephen Rothwell 864b8b572e1SStephen Rothwell 865b8b572e1SStephen Rothwell #define IO_SPACE_LIMIT ~(0UL) 866b8b572e1SStephen Rothwell 867b8b572e1SStephen Rothwell /** 868b8b572e1SStephen Rothwell * ioremap - map bus memory into CPU space 869b8b572e1SStephen Rothwell * @address: bus address of the memory 870b8b572e1SStephen Rothwell * @size: size of the resource to map 871b8b572e1SStephen Rothwell * 872b8b572e1SStephen Rothwell * ioremap performs a platform specific sequence of operations to 873b8b572e1SStephen Rothwell * make bus memory CPU accessible via the readb/readw/readl/writeb/ 874b8b572e1SStephen Rothwell * writew/writel functions and the other mmio helpers. The returned 875b8b572e1SStephen Rothwell * address is not guaranteed to be usable directly as a virtual 876b8b572e1SStephen Rothwell * address. 877b8b572e1SStephen Rothwell * 878b8b572e1SStephen Rothwell * We provide a few variations of it: 879b8b572e1SStephen Rothwell * 880b8b572e1SStephen Rothwell * * ioremap is the standard one and provides non-cacheable guarded mappings 881b8b572e1SStephen Rothwell * and can be hooked by the platform via ppc_md 882b8b572e1SStephen Rothwell * 88340f1ce7fSAnton Blanchard * * ioremap_prot allows to specify the page flags as an argument and can 88440f1ce7fSAnton Blanchard * also be hooked by the platform via ppc_md. 885b8b572e1SStephen Rothwell * 886be135f40SAnton Blanchard * * ioremap_wc enables write combining 887be135f40SAnton Blanchard * 88886c391bdSChristophe Leroy * * ioremap_wt enables write through 88986c391bdSChristophe Leroy * 89086c391bdSChristophe Leroy * * ioremap_coherent maps coherent cached memory 89186c391bdSChristophe Leroy * 892b8b572e1SStephen Rothwell * * iounmap undoes such a mapping and can be hooked 893b8b572e1SStephen Rothwell * 8941cdab55dSBenjamin Herrenschmidt * * __ioremap_caller is the same as above but takes an explicit caller 8951cdab55dSBenjamin Herrenschmidt * reference rather than using __builtin_return_address(0) 8961cdab55dSBenjamin Herrenschmidt * 897b8b572e1SStephen Rothwell */ 898b8b572e1SStephen Rothwell extern void __iomem *ioremap(phys_addr_t address, unsigned long size); 89940f1ce7fSAnton Blanchard extern void __iomem *ioremap_prot(phys_addr_t address, unsigned long size, 900b8b572e1SStephen Rothwell unsigned long flags); 901be135f40SAnton Blanchard extern void __iomem *ioremap_wc(phys_addr_t address, unsigned long size); 902894fa235SChristophe Leroy #define ioremap_wc ioremap_wc 903894fa235SChristophe Leroy 904894fa235SChristophe Leroy #ifdef CONFIG_PPC32 90586c391bdSChristophe Leroy void __iomem *ioremap_wt(phys_addr_t address, unsigned long size); 906894fa235SChristophe Leroy #define ioremap_wt ioremap_wt 907894fa235SChristophe Leroy #endif 908894fa235SChristophe Leroy 90986c391bdSChristophe Leroy void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size); 9104c73e892SLuis R. Rodriguez #define ioremap_uc(addr, size) ioremap((addr), (size)) 911f855b2f5SOliver O'Halloran #define ioremap_cache(addr, size) \ 912f855b2f5SOliver O'Halloran ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) 913b8b572e1SStephen Rothwell 914b8b572e1SStephen Rothwell extern void iounmap(volatile void __iomem *addr); 915b8b572e1SStephen Rothwell 916b274014cSChristoph Hellwig void __iomem *ioremap_phb(phys_addr_t paddr, unsigned long size); 917b274014cSChristoph Hellwig 918163918fcSChristophe Leroy int early_ioremap_range(unsigned long ea, phys_addr_t pa, 919163918fcSChristophe Leroy unsigned long size, pgprot_t prot); 9204a45b746SChristophe Leroy void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size, 9214a45b746SChristophe Leroy pgprot_t prot, void *caller); 922191e4206SChristophe Leroy 9231cdab55dSBenjamin Herrenschmidt extern void __iomem *__ioremap_caller(phys_addr_t, unsigned long size, 924c766ee72SChristophe Leroy pgprot_t prot, void *caller); 9251cdab55dSBenjamin Herrenschmidt 926b8b572e1SStephen Rothwell /* 927ecd73cc5SBenjamin Herrenschmidt * When CONFIG_PPC_INDIRECT_PIO is set, we use the generic iomap implementation 928b8b572e1SStephen Rothwell * which needs some additional definitions here. They basically allow PIO 929b8b572e1SStephen Rothwell * space overall to be 1GB. This will work as long as we never try to use 930b8b572e1SStephen Rothwell * iomap to map MMIO below 1GB which should be fine on ppc64 931b8b572e1SStephen Rothwell */ 932b8b572e1SStephen Rothwell #define HAVE_ARCH_PIO_SIZE 1 933b8b572e1SStephen Rothwell #define PIO_OFFSET 0x00000000UL 934b8b572e1SStephen Rothwell #define PIO_MASK (FULL_IO_SIZE - 1) 935b8b572e1SStephen Rothwell #define PIO_RESERVED (FULL_IO_SIZE) 936b8b572e1SStephen Rothwell 937b8b572e1SStephen Rothwell #define mmio_read16be(addr) readw_be(addr) 938b8b572e1SStephen Rothwell #define mmio_read32be(addr) readl_be(addr) 93979bf0cbdSLogan Gunthorpe #define mmio_read64be(addr) readq_be(addr) 940b8b572e1SStephen Rothwell #define mmio_write16be(val, addr) writew_be(val, addr) 941b8b572e1SStephen Rothwell #define mmio_write32be(val, addr) writel_be(val, addr) 94279bf0cbdSLogan Gunthorpe #define mmio_write64be(val, addr) writeq_be(val, addr) 943b8b572e1SStephen Rothwell #define mmio_insb(addr, dst, count) readsb(addr, dst, count) 944b8b572e1SStephen Rothwell #define mmio_insw(addr, dst, count) readsw(addr, dst, count) 945b8b572e1SStephen Rothwell #define mmio_insl(addr, dst, count) readsl(addr, dst, count) 946b8b572e1SStephen Rothwell #define mmio_outsb(addr, src, count) writesb(addr, src, count) 947b8b572e1SStephen Rothwell #define mmio_outsw(addr, src, count) writesw(addr, src, count) 948b8b572e1SStephen Rothwell #define mmio_outsl(addr, src, count) writesl(addr, src, count) 949b8b572e1SStephen Rothwell 950b8b572e1SStephen Rothwell /** 951b8b572e1SStephen Rothwell * virt_to_phys - map virtual addresses to physical 952b8b572e1SStephen Rothwell * @address: address to remap 953b8b572e1SStephen Rothwell * 954b8b572e1SStephen Rothwell * The returned physical address is the physical (CPU) mapping for 955b8b572e1SStephen Rothwell * the memory address given. It is only valid to use this function on 956b8b572e1SStephen Rothwell * addresses directly mapped or allocated via kmalloc. 957b8b572e1SStephen Rothwell * 958b8b572e1SStephen Rothwell * This function does not give bus mappings for DMA transfers. In 959b8b572e1SStephen Rothwell * almost all conceivable cases a device driver should not be using 960b8b572e1SStephen Rothwell * this function 961b8b572e1SStephen Rothwell */ 962b8b572e1SStephen Rothwell static inline unsigned long virt_to_phys(volatile void * address) 963b8b572e1SStephen Rothwell { 9646bf752daSChristophe Leroy WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address)); 9656bf752daSChristophe Leroy 966b8b572e1SStephen Rothwell return __pa((unsigned long)address); 967b8b572e1SStephen Rothwell } 968894fa235SChristophe Leroy #define virt_to_phys virt_to_phys 969b8b572e1SStephen Rothwell 970b8b572e1SStephen Rothwell /** 971b8b572e1SStephen Rothwell * phys_to_virt - map physical address to virtual 972b8b572e1SStephen Rothwell * @address: address to remap 973b8b572e1SStephen Rothwell * 974b8b572e1SStephen Rothwell * The returned virtual address is a current CPU mapping for 975b8b572e1SStephen Rothwell * the memory address given. It is only valid to use this function on 976b8b572e1SStephen Rothwell * addresses that have a kernel mapping 977b8b572e1SStephen Rothwell * 978b8b572e1SStephen Rothwell * This function does not handle bus mappings for DMA transfers. In 979b8b572e1SStephen Rothwell * almost all conceivable cases a device driver should not be using 980b8b572e1SStephen Rothwell * this function 981b8b572e1SStephen Rothwell */ 982b8b572e1SStephen Rothwell static inline void * phys_to_virt(unsigned long address) 983b8b572e1SStephen Rothwell { 984b8b572e1SStephen Rothwell return (void *)__va(address); 985b8b572e1SStephen Rothwell } 986894fa235SChristophe Leroy #define phys_to_virt phys_to_virt 987b8b572e1SStephen Rothwell 988b8b572e1SStephen Rothwell /* 989b8b572e1SStephen Rothwell * Change "struct page" to physical address. 990b8b572e1SStephen Rothwell */ 9916bf752daSChristophe Leroy static inline phys_addr_t page_to_phys(struct page *page) 9926bf752daSChristophe Leroy { 9936bf752daSChristophe Leroy unsigned long pfn = page_to_pfn(page); 9946bf752daSChristophe Leroy 9956bf752daSChristophe Leroy WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !pfn_valid(pfn)); 9966bf752daSChristophe Leroy 9976bf752daSChristophe Leroy return PFN_PHYS(pfn); 9986bf752daSChristophe Leroy } 999b8b572e1SStephen Rothwell 1000b8b572e1SStephen Rothwell /* 1001b8b572e1SStephen Rothwell * 32 bits still uses virt_to_bus() for it's implementation of DMA 1002b8b572e1SStephen Rothwell * mappings se we have to keep it defined here. We also have some old 1003b8b572e1SStephen Rothwell * drivers (shame shame shame) that use bus_to_virt() and haven't been 1004b8b572e1SStephen Rothwell * fixed yet so I need to define it here. 1005b8b572e1SStephen Rothwell */ 1006b8b572e1SStephen Rothwell #ifdef CONFIG_PPC32 1007b8b572e1SStephen Rothwell 1008b8b572e1SStephen Rothwell static inline unsigned long virt_to_bus(volatile void * address) 1009b8b572e1SStephen Rothwell { 1010b8b572e1SStephen Rothwell if (address == NULL) 1011b8b572e1SStephen Rothwell return 0; 1012b8b572e1SStephen Rothwell return __pa(address) + PCI_DRAM_OFFSET; 1013b8b572e1SStephen Rothwell } 1014894fa235SChristophe Leroy #define virt_to_bus virt_to_bus 1015b8b572e1SStephen Rothwell 1016b8b572e1SStephen Rothwell static inline void * bus_to_virt(unsigned long address) 1017b8b572e1SStephen Rothwell { 1018b8b572e1SStephen Rothwell if (address == 0) 1019b8b572e1SStephen Rothwell return NULL; 1020b8b572e1SStephen Rothwell return __va(address - PCI_DRAM_OFFSET); 1021b8b572e1SStephen Rothwell } 1022894fa235SChristophe Leroy #define bus_to_virt bus_to_virt 1023b8b572e1SStephen Rothwell 1024b8b572e1SStephen Rothwell #endif /* CONFIG_PPC32 */ 1025b8b572e1SStephen Rothwell 1026b8b572e1SStephen Rothwell /* access ports */ 1027b8b572e1SStephen Rothwell #define setbits32(_addr, _v) out_be32((_addr), in_be32(_addr) | (_v)) 1028b8b572e1SStephen Rothwell #define clrbits32(_addr, _v) out_be32((_addr), in_be32(_addr) & ~(_v)) 1029b8b572e1SStephen Rothwell 1030b8b572e1SStephen Rothwell #define setbits16(_addr, _v) out_be16((_addr), in_be16(_addr) | (_v)) 1031b8b572e1SStephen Rothwell #define clrbits16(_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v)) 1032b8b572e1SStephen Rothwell 1033b8b572e1SStephen Rothwell #define setbits8(_addr, _v) out_8((_addr), in_8(_addr) | (_v)) 1034b8b572e1SStephen Rothwell #define clrbits8(_addr, _v) out_8((_addr), in_8(_addr) & ~(_v)) 1035b8b572e1SStephen Rothwell 1036b8b572e1SStephen Rothwell /* Clear and set bits in one shot. These macros can be used to clear and 1037b8b572e1SStephen Rothwell * set multiple bits in a register using a single read-modify-write. These 1038b8b572e1SStephen Rothwell * macros can also be used to set a multiple-bit bit pattern using a mask, 1039b8b572e1SStephen Rothwell * by specifying the mask in the 'clear' parameter and the new bit pattern 1040b8b572e1SStephen Rothwell * in the 'set' parameter. 1041b8b572e1SStephen Rothwell */ 1042b8b572e1SStephen Rothwell 1043b8b572e1SStephen Rothwell #define clrsetbits(type, addr, clear, set) \ 1044b8b572e1SStephen Rothwell out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) 1045b8b572e1SStephen Rothwell 1046b8b572e1SStephen Rothwell #ifdef __powerpc64__ 1047b8b572e1SStephen Rothwell #define clrsetbits_be64(addr, clear, set) clrsetbits(be64, addr, clear, set) 1048b8b572e1SStephen Rothwell #define clrsetbits_le64(addr, clear, set) clrsetbits(le64, addr, clear, set) 1049b8b572e1SStephen Rothwell #endif 1050b8b572e1SStephen Rothwell 1051b8b572e1SStephen Rothwell #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) 1052b8b572e1SStephen Rothwell #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) 1053b8b572e1SStephen Rothwell 1054b8b572e1SStephen Rothwell #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) 1055b8b572e1SStephen Rothwell #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) 1056b8b572e1SStephen Rothwell 1057b8b572e1SStephen Rothwell #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) 1058b8b572e1SStephen Rothwell 1059894fa235SChristophe Leroy #include <asm-generic/io.h> 1060894fa235SChristophe Leroy 1061b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 1062b8b572e1SStephen Rothwell 1063b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_IO_H */ 1064