blob: 394da5500466ff7f9a4cfcd183398fccc7d9a28b [file] [log] [blame]
Mark A. Greer0c176fa2006-10-16 13:52:09 -07001#ifndef _IO_H
Lucas Tanurec03719e2014-07-24 10:24:06 -03002#define _IO_H
Scott Wood6e913c62007-08-21 03:39:51 +10003
4#include "types.h"
5
Mark A. Greer0c176fa2006-10-16 13:52:09 -07006/*
7 * Low-level I/O routines.
8 *
Stephen Rothwellb8b572e2008-08-01 15:20:30 +10009 * Copied from <file:arch/powerpc/include/asm/io.h> (which has no copyright)
Mark A. Greer0c176fa2006-10-16 13:52:09 -070010 */
11static inline int in_8(const volatile unsigned char *addr)
12{
13 int ret;
14
15 __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
16 : "=r" (ret) : "m" (*addr));
17 return ret;
18}
19
20static inline void out_8(volatile unsigned char *addr, int val)
21{
22 __asm__ __volatile__("stb%U0%X0 %1,%0; sync"
23 : "=m" (*addr) : "r" (val));
24}
25
Scott Wood6e913c62007-08-21 03:39:51 +100026static inline unsigned in_le16(const volatile u16 *addr)
27{
28 unsigned ret;
29
30 __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
31 : "=r" (ret) : "r" (addr), "m" (*addr));
32
33 return ret;
34}
35
36static inline unsigned in_be16(const volatile u16 *addr)
37{
38 unsigned ret;
39
40 __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
41 : "=r" (ret) : "m" (*addr));
42 return ret;
43}
44
45static inline void out_le16(volatile u16 *addr, int val)
46{
47 __asm__ __volatile__("sthbrx %1,0,%2; sync" : "=m" (*addr)
48 : "r" (val), "r" (addr));
49}
50
51static inline void out_be16(volatile u16 *addr, int val)
52{
53 __asm__ __volatile__("sth%U0%X0 %1,%0; sync"
54 : "=m" (*addr) : "r" (val));
55}
56
Mark A. Greer0c176fa2006-10-16 13:52:09 -070057static inline unsigned in_le32(const volatile unsigned *addr)
58{
59 unsigned ret;
60
61 __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
62 : "=r" (ret) : "r" (addr), "m" (*addr));
63 return ret;
64}
65
66static inline unsigned in_be32(const volatile unsigned *addr)
67{
68 unsigned ret;
69
70 __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
71 : "=r" (ret) : "m" (*addr));
72 return ret;
73}
74
75static inline void out_le32(volatile unsigned *addr, int val)
76{
77 __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
78 : "r" (val), "r" (addr));
79}
80
81static inline void out_be32(volatile unsigned *addr, int val)
82{
83 __asm__ __volatile__("stw%U0%X0 %1,%0; sync"
84 : "=m" (*addr) : "r" (val));
85}
86
Scott Wood6e913c62007-08-21 03:39:51 +100087static inline void sync(void)
88{
89 asm volatile("sync" : : : "memory");
90}
91
92static inline void eieio(void)
93{
94 asm volatile("eieio" : : : "memory");
95}
96
97static inline void barrier(void)
98{
99 asm volatile("" : : : "memory");
100}
101
Mark A. Greer0c176fa2006-10-16 13:52:09 -0700102#endif /* _IO_H */