1 | /********************************************************************** |
---|
2 | * \file io.h |
---|
3 | * \date 5 September 2012 |
---|
4 | * \author Cesar Fuguet / Alain Greiner |
---|
5 | * |
---|
6 | * Utility functions to write or read memory mapped hardware registers |
---|
7 | *********************************************************************/ |
---|
8 | |
---|
9 | #ifndef IO_H |
---|
10 | #define IO_H |
---|
11 | |
---|
12 | #include <defs.h> |
---|
13 | |
---|
14 | /********************************************************************** |
---|
15 | * Read an 32 bits memory mapped hardware register |
---|
16 | * with physical address extension to access cluster_io |
---|
17 | *********************************************************************/ |
---|
18 | static inline unsigned int ioread32(void * addr) |
---|
19 | { |
---|
20 | unsigned int value; |
---|
21 | unsigned int ext = CLUSTER_IO; |
---|
22 | |
---|
23 | asm volatile( |
---|
24 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
25 | "lw %0, 0(%1) \n" /* value <= *(ext\addr) */ |
---|
26 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
27 | : "=r" (value) |
---|
28 | : "r" (addr), "r" (ext) |
---|
29 | : "memory" ); |
---|
30 | |
---|
31 | return (volatile unsigned int)value; |
---|
32 | } |
---|
33 | |
---|
34 | /********************************************************************** |
---|
35 | * Read an 16 bits memory mapped hardware register |
---|
36 | *********************************************************************/ |
---|
37 | static inline unsigned short ioread16(void * addr) |
---|
38 | { |
---|
39 | unsigned short value; |
---|
40 | unsigned int ext = CLUSTER_IO; |
---|
41 | |
---|
42 | asm volatile( |
---|
43 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
44 | "lhu %0, 0(%1) \n" /* value <= *(ext\addr) */ |
---|
45 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
46 | : "=r" (value) |
---|
47 | : "r" (addr), "r" (ext) |
---|
48 | : "memory" ); |
---|
49 | |
---|
50 | return (volatile unsigned short)value; |
---|
51 | } |
---|
52 | |
---|
53 | /********************************************************************** |
---|
54 | * Read an 8 bits memory mapped hardware register |
---|
55 | *********************************************************************/ |
---|
56 | static inline unsigned char ioread8(void * addr) |
---|
57 | { |
---|
58 | unsigned char value; |
---|
59 | unsigned int ext = CLUSTER_IO; |
---|
60 | |
---|
61 | asm volatile( |
---|
62 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
63 | "lbu %0, 0(%1) \n" /* value <= *(ext\addr) */ |
---|
64 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
65 | : "=r" (value) |
---|
66 | : "r" (addr), "r" (ext) |
---|
67 | : "memory" ); |
---|
68 | |
---|
69 | return (volatile unsigned char)value; |
---|
70 | } |
---|
71 | |
---|
72 | /********************************************************************** |
---|
73 | * Write an 32 bits memory mapped hardware register |
---|
74 | * with physical address extension to access cluster_io |
---|
75 | *********************************************************************/ |
---|
76 | static inline void iowrite32(void * addr, unsigned int value) |
---|
77 | { |
---|
78 | unsigned int ext = CLUSTER_IO; |
---|
79 | |
---|
80 | asm volatile( |
---|
81 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
82 | "sw %0, 0(%1) \n" /* *(ext\addr) <= value */ |
---|
83 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
84 | "sync \n" /* sync barrier */ |
---|
85 | : |
---|
86 | : "r" (value), "r" (addr), "r" (ext) |
---|
87 | : "memory" ); |
---|
88 | } |
---|
89 | |
---|
90 | /********************************************************************** |
---|
91 | * Write an 16 bits memory mapped hardware register |
---|
92 | *********************************************************************/ |
---|
93 | static inline void iowrite16(void * addr, unsigned short value) |
---|
94 | { |
---|
95 | unsigned int ext = CLUSTER_IO; |
---|
96 | |
---|
97 | asm volatile( |
---|
98 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
99 | "sh %0, 0(%1) \n" /* *(ext\addr) <= value */ |
---|
100 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
101 | "sync \n" /* sync barrier */ |
---|
102 | : |
---|
103 | : "r" (value), "r" (addr), "r" (ext) |
---|
104 | : "memory" ); |
---|
105 | } |
---|
106 | |
---|
107 | /********************************************************************** |
---|
108 | * Write an 8 bits memory mapped hardware register |
---|
109 | *********************************************************************/ |
---|
110 | static inline void iowrite8(void * addr, unsigned char value) |
---|
111 | { |
---|
112 | unsigned int ext = CLUSTER_IO; |
---|
113 | |
---|
114 | asm volatile( |
---|
115 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
116 | "sb %0, 0(%1) \n" /* *(ext\addr) <= value */ |
---|
117 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
118 | "sync \n" /* sync barrier */ |
---|
119 | : |
---|
120 | : "r" (value), "r" (addr), "r" (ext) |
---|
121 | : "memory" ); |
---|
122 | } |
---|
123 | |
---|
124 | #endif |
---|
125 | |
---|
126 | // vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|