ls2: add support for the Nexys Video board
[ls2.git] / include / io.h
1 /* This code is directly from Microwatt and is Copyright and Licensed
2 under the same terms as Microwatt source code.
3 https://github.com/antonblanchard/microwatt/blob/master/include/io.h
4 */
5
6 #ifndef __IO_H
7 #define __IO_H
8
9 static inline uint8_t readb(unsigned long addr)
10 {
11 uint8_t val;
12 __asm__ volatile("sync; lbzcix %0,0,%1" : "=r" (val) : "r" (addr) : "memory");
13 return val;
14 }
15
16 static inline uint16_t readw(unsigned long addr)
17 {
18 uint16_t val;
19 __asm__ volatile("sync; lhzcix %0,0,%1" : "=r" (val) : "r" (addr) : "memory");
20 return val;
21 }
22
23 static inline uint32_t readl(unsigned long addr)
24 {
25 uint32_t val;
26 __asm__ volatile("sync; lwzcix %0,0,%1" : "=r" (val) : "r" (addr) : "memory");
27 return val;
28 }
29
30 static inline uint64_t readq(unsigned long addr)
31 {
32 uint64_t val;
33 __asm__ volatile("sync; ldcix %0,0,%1" : "=r" (val) : "r" (addr) : "memory");
34 return val;
35 }
36
37 static inline void writeb(uint8_t val, unsigned long addr)
38 {
39 __asm__ volatile("sync; stbcix %0,0,%1" : : "r" (val), "r" (addr) : "memory");
40 }
41
42 static inline void writew(uint16_t val, unsigned long addr)
43 {
44 __asm__ volatile("sync; sthcix %0,0,%1" : : "r" (val), "r" (addr) : "memory");
45 }
46
47 static inline void writel(uint32_t val, unsigned long addr)
48 {
49 __asm__ volatile("sync; stwcix %0,0,%1" : : "r" (val), "r" (addr) : "memory");
50 }
51
52 static inline void writeq(uint64_t val, unsigned long addr)
53 {
54 __asm__ volatile("sync; stdcix %0,0,%1" : : "r" (val), "r" (addr) : "memory");
55 }
56
57 #endif /* __IO_H */
58