Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Mark A. Greer | 0c176fa | 2006-10-16 13:52:09 -0700 | [diff] [blame] | 2 | #ifndef _IO_H |
Lucas Tanure | c03719e | 2014-07-24 10:24:06 -0300 | [diff] [blame] | 3 | #define _IO_H |
Scott Wood | 6e913c6 | 2007-08-21 03:39:51 +1000 | [diff] [blame] | 4 | |
| 5 | #include "types.h" |
| 6 | |
Mark A. Greer | 0c176fa | 2006-10-16 13:52:09 -0700 | [diff] [blame] | 7 | /* |
| 8 | * Low-level I/O routines. |
| 9 | * |
Stephen Rothwell | b8b572e | 2008-08-01 15:20:30 +1000 | [diff] [blame] | 10 | * Copied from <file:arch/powerpc/include/asm/io.h> (which has no copyright) |
Mark A. Greer | 0c176fa | 2006-10-16 13:52:09 -0700 | [diff] [blame] | 11 | */ |
| 12 | static inline int in_8(const volatile unsigned char *addr) |
| 13 | { |
| 14 | int ret; |
| 15 | |
| 16 | __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync" |
| 17 | : "=r" (ret) : "m" (*addr)); |
| 18 | return ret; |
| 19 | } |
| 20 | |
| 21 | static inline void out_8(volatile unsigned char *addr, int val) |
| 22 | { |
| 23 | __asm__ __volatile__("stb%U0%X0 %1,%0; sync" |
| 24 | : "=m" (*addr) : "r" (val)); |
| 25 | } |
| 26 | |
Scott Wood | 6e913c6 | 2007-08-21 03:39:51 +1000 | [diff] [blame] | 27 | static inline unsigned in_le16(const volatile u16 *addr) |
| 28 | { |
| 29 | unsigned ret; |
| 30 | |
| 31 | __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync" |
| 32 | : "=r" (ret) : "r" (addr), "m" (*addr)); |
| 33 | |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | static inline unsigned in_be16(const volatile u16 *addr) |
| 38 | { |
| 39 | unsigned ret; |
| 40 | |
| 41 | __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync" |
| 42 | : "=r" (ret) : "m" (*addr)); |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | static inline void out_le16(volatile u16 *addr, int val) |
| 47 | { |
| 48 | __asm__ __volatile__("sthbrx %1,0,%2; sync" : "=m" (*addr) |
| 49 | : "r" (val), "r" (addr)); |
| 50 | } |
| 51 | |
| 52 | static inline void out_be16(volatile u16 *addr, int val) |
| 53 | { |
| 54 | __asm__ __volatile__("sth%U0%X0 %1,%0; sync" |
| 55 | : "=m" (*addr) : "r" (val)); |
| 56 | } |
| 57 | |
Mark A. Greer | 0c176fa | 2006-10-16 13:52:09 -0700 | [diff] [blame] | 58 | static inline unsigned in_le32(const volatile unsigned *addr) |
| 59 | { |
| 60 | unsigned ret; |
| 61 | |
| 62 | __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync" |
| 63 | : "=r" (ret) : "r" (addr), "m" (*addr)); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | static inline unsigned in_be32(const volatile unsigned *addr) |
| 68 | { |
| 69 | unsigned ret; |
| 70 | |
| 71 | __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync" |
| 72 | : "=r" (ret) : "m" (*addr)); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static inline void out_le32(volatile unsigned *addr, int val) |
| 77 | { |
| 78 | __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr) |
| 79 | : "r" (val), "r" (addr)); |
| 80 | } |
| 81 | |
| 82 | static inline void out_be32(volatile unsigned *addr, int val) |
| 83 | { |
| 84 | __asm__ __volatile__("stw%U0%X0 %1,%0; sync" |
| 85 | : "=m" (*addr) : "r" (val)); |
| 86 | } |
| 87 | |
Scott Wood | 6e913c6 | 2007-08-21 03:39:51 +1000 | [diff] [blame] | 88 | static inline void sync(void) |
| 89 | { |
| 90 | asm volatile("sync" : : : "memory"); |
| 91 | } |
| 92 | |
| 93 | static inline void eieio(void) |
| 94 | { |
| 95 | asm volatile("eieio" : : : "memory"); |
| 96 | } |
| 97 | |
| 98 | static inline void barrier(void) |
| 99 | { |
| 100 | asm volatile("" : : : "memory"); |
| 101 | } |
| 102 | |
Mark A. Greer | 0c176fa | 2006-10-16 13:52:09 -0700 | [diff] [blame] | 103 | #endif /* _IO_H */ |