18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* -*- linux-c -*- ------------------------------------------------------- * 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 1991, 1992 Linus Torvalds 58c2ecf20Sopenharmony_ci * Copyright 2007 rPath, Inc. - All Rights Reserved 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * ----------------------------------------------------------------------- */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Very simple bitops for the boot code. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef BOOT_BITOPS_H 148c2ecf20Sopenharmony_ci#define BOOT_BITOPS_H 158c2ecf20Sopenharmony_ci#define _LINUX_BITOPS_H /* Inhibit inclusion of <linux/bitops.h> */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/types.h> 188c2ecf20Sopenharmony_ci#include <asm/asm.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic inline bool constant_test_bit(int nr, const void *addr) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci const u32 *p = (const u32 *)addr; 238c2ecf20Sopenharmony_ci return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0; 248c2ecf20Sopenharmony_ci} 258c2ecf20Sopenharmony_cistatic inline bool variable_test_bit(int nr, const void *addr) 268c2ecf20Sopenharmony_ci{ 278c2ecf20Sopenharmony_ci bool v; 288c2ecf20Sopenharmony_ci const u32 *p = (const u32 *)addr; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr)); 318c2ecf20Sopenharmony_ci return v; 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define test_bit(nr,addr) \ 358c2ecf20Sopenharmony_ci(__builtin_constant_p(nr) ? \ 368c2ecf20Sopenharmony_ci constant_test_bit((nr),(addr)) : \ 378c2ecf20Sopenharmony_ci variable_test_bit((nr),(addr))) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic inline void set_bit(int nr, void *addr) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr)); 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#endif /* BOOT_BITOPS_H */ 45