Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* -*- linux-c -*- ------------------------------------------------------- *
0003  *
0004  *   Copyright (C) 1991, 1992 Linus Torvalds
0005  *   Copyright 2007 rPath, Inc. - All Rights Reserved
0006  *
0007  * ----------------------------------------------------------------------- */
0008 
0009 /*
0010  * Very simple bitops for the boot code.
0011  */
0012 
0013 #ifndef BOOT_BITOPS_H
0014 #define BOOT_BITOPS_H
0015 #define _LINUX_BITOPS_H     /* Inhibit inclusion of <linux/bitops.h> */
0016 
0017 #include <linux/types.h>
0018 #include <asm/asm.h>
0019 
0020 static inline bool constant_test_bit(int nr, const void *addr)
0021 {
0022     const u32 *p = (const u32 *)addr;
0023     return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
0024 }
0025 static inline bool variable_test_bit(int nr, const void *addr)
0026 {
0027     bool v;
0028     const u32 *p = (const u32 *)addr;
0029 
0030     asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
0031     return v;
0032 }
0033 
0034 #define test_bit(nr,addr) \
0035 (__builtin_constant_p(nr) ? \
0036  constant_test_bit((nr),(addr)) : \
0037  variable_test_bit((nr),(addr)))
0038 
0039 static inline void set_bit(int nr, void *addr)
0040 {
0041     asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
0042 }
0043 
0044 #endif /* BOOT_BITOPS_H */