197873a3dSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
296ae6ea0SThomas Gleixner /* -*- linux-c -*- ------------------------------------------------------- *
396ae6ea0SThomas Gleixner *
496ae6ea0SThomas Gleixner * Copyright (C) 1991, 1992 Linus Torvalds
596ae6ea0SThomas Gleixner * Copyright 2007 rPath, Inc. - All Rights Reserved
696ae6ea0SThomas Gleixner *
796ae6ea0SThomas Gleixner * ----------------------------------------------------------------------- */
896ae6ea0SThomas Gleixner
996ae6ea0SThomas Gleixner /*
1096ae6ea0SThomas Gleixner * Very simple bitops for the boot code.
1196ae6ea0SThomas Gleixner */
1296ae6ea0SThomas Gleixner
1396ae6ea0SThomas Gleixner #ifndef BOOT_BITOPS_H
1496ae6ea0SThomas Gleixner #define BOOT_BITOPS_H
1596ae6ea0SThomas Gleixner #define _LINUX_BITOPS_H /* Inhibit inclusion of <linux/bitops.h> */
1696ae6ea0SThomas Gleixner
17117780eeSH. Peter Anvin #include <linux/types.h>
18216a3720SUros Bizjak #include <asm/asm.h>
19117780eeSH. Peter Anvin
constant_test_bit(int nr,const void * addr)20117780eeSH. Peter Anvin static inline bool constant_test_bit(int nr, const void *addr)
2196ae6ea0SThomas Gleixner {
22*039f0e05SLi kunyu const u32 *p = addr;
2396ae6ea0SThomas Gleixner return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
2496ae6ea0SThomas Gleixner }
variable_test_bit(int nr,const void * addr)25117780eeSH. Peter Anvin static inline bool variable_test_bit(int nr, const void *addr)
2696ae6ea0SThomas Gleixner {
27117780eeSH. Peter Anvin bool v;
28*039f0e05SLi kunyu const u32 *p = addr;
2996ae6ea0SThomas Gleixner
30216a3720SUros Bizjak asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
3196ae6ea0SThomas Gleixner return v;
3296ae6ea0SThomas Gleixner }
3396ae6ea0SThomas Gleixner
3496ae6ea0SThomas Gleixner #define test_bit(nr,addr) \
3596ae6ea0SThomas Gleixner (__builtin_constant_p(nr) ? \
3696ae6ea0SThomas Gleixner constant_test_bit((nr),(addr)) : \
3796ae6ea0SThomas Gleixner variable_test_bit((nr),(addr)))
3896ae6ea0SThomas Gleixner
set_bit(int nr,void * addr)3996ae6ea0SThomas Gleixner static inline void set_bit(int nr, void *addr)
4096ae6ea0SThomas Gleixner {
4196ae6ea0SThomas Gleixner asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
4296ae6ea0SThomas Gleixner }
4396ae6ea0SThomas Gleixner
4496ae6ea0SThomas Gleixner #endif /* BOOT_BITOPS_H */
45