3 #ifndef __ASM_REGOPS_H__
4 #define __ASM_REGOPS_H__
6 #include <linux/types.h>
10 #ifndef R10000_LLSC_WAR
11 #define R10000_LLSC_WAR 0
14 #if R10000_LLSC_WAR == 1
15 #define __beqz "beqzl "
17 #define __beqz "beqz "
20 #ifndef _LINUX_TYPES_H
21 typedef unsigned int u32
;
25 * Sets all the masked bits to the corresponding value bits
27 static inline void set_value_reg32(volatile u32
*const addr
,
36 "1: ll %0, %1 # set_value_reg32 \n"
43 : "=&r" (temp
), "=m" (*addr
)
44 : "ir" (~mask
), "ir" (value
), "m" (*addr
));
48 * Sets all the masked bits to '1'
50 static inline void set_reg32(volatile u32
*const addr
,
58 "1: ll %0, %1 # set_reg32 \n"
64 : "=&r" (temp
), "=m" (*addr
)
65 : "ir" (mask
), "m" (*addr
));
69 * Sets all the masked bits to '0'
71 static inline void clear_reg32(volatile u32
*const addr
,
79 "1: ll %0, %1 # clear_reg32 \n"
85 : "=&r" (temp
), "=m" (*addr
)
86 : "ir" (~mask
), "m" (*addr
));
90 * Toggles all masked bits from '0' to '1' and '1' to '0'
92 static inline void toggle_reg32(volatile u32
*const addr
,
100 "1: ll %0, %1 # toggle_reg32 \n"
106 : "=&r" (temp
), "=m" (*addr
)
107 : "ir" (mask
), "m" (*addr
));
111 * Read all masked bits others are returned as '0'
113 static inline u32
read_reg32(volatile u32
*const addr
,
118 __asm__
__volatile__(
121 " lw %0, %1 # read \n"
122 " and %0, %2 # mask \n"
125 : "m" (*addr
), "ir" (mask
));
131 * blocking_read_reg32 - Read address with blocking load
133 * Uncached writes need to be read back to ensure they reach RAM.
134 * The returned value must be 'used' to prevent from becoming a
137 static inline u32
blocking_read_reg32(volatile u32
*const addr
)
141 __asm__
__volatile__(
144 " lw %0, %1 # read \n"
145 " move %0, %0 # block \n"
154 * For special strange cases only:
156 * If you need custom processing within a ll/sc loop, use the following macros
159 * u32 tmp; <-- Define a variable to hold the data
161 * custom_read_reg32(address, tmp); <-- Reads the address and put the value
162 * in the 'tmp' variable given
164 * From here on out, you are (basicly) atomic, so don't do anything too
166 * Also, this code may loop if the end of this block fails to write
167 * everything back safely due do the other CPU, so do NOT do anything
170 * custom_write_reg32(address, tmp); <-- Writes back 'tmp' safely.
172 #define custom_read_reg32(address, tmp) \
173 __asm__ __volatile__( \
176 "1: ll %0, %1 #custom_read_reg32 \n" \
178 : "=r" (tmp), "=m" (*address) \
181 #define custom_write_reg32(address, tmp) \
182 __asm__ __volatile__( \
185 " sc %0, %1 #custom_write_reg32 \n" \
186 " "__beqz"%0, 1b \n" \
189 : "=&r" (tmp), "=m" (*address) \
190 : "0" (tmp), "m" (*address))
192 #endif /* __ASM_REGOPS_H__ */