blob: 48a3e1f517ed47bc865c62a72b9d0ca50e115d99 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Chris Zankel1387dab2016-08-10 18:36:44 +03002/*
3 * Copyright (C) 2001 - 2012 Tensilica Inc.
4 * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
Chris Zankel1387dab2016-08-10 18:36:44 +03005 */
6
7#ifndef _XTENSA_BITOPS_H
8#define _XTENSA_BITOPS_H
9
10#include <asm/system.h>
11#include <asm-generic/bitops/fls.h>
12#include <asm-generic/bitops/__fls.h>
13#include <asm-generic/bitops/fls64.h>
14#include <asm-generic/bitops/__ffs.h>
15
16static inline int test_bit(int nr, const void *addr)
17{
18 return ((unsigned char *)addr)[nr >> 3] & (1u << (nr & 7));
19}
20
21static inline int test_and_set_bit(int nr, volatile void *addr)
22{
23 unsigned long flags;
24 unsigned char tmp;
25 unsigned char mask = 1u << (nr & 7);
26
27 local_irq_save(flags);
28 tmp = ((unsigned char *)addr)[nr >> 3];
29 ((unsigned char *)addr)[nr >> 3] |= mask;
30 local_irq_restore(flags);
31
32 return tmp & mask;
33}
34
35#endif /* _XTENSA_BITOPS_H */