bitops.h 830 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2001 - 2012 Tensilica Inc.
  4. * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
  5. */
  6. #ifndef _XTENSA_BITOPS_H
  7. #define _XTENSA_BITOPS_H
  8. #include <asm/system.h>
  9. #include <asm-generic/bitops/fls.h>
  10. #include <asm-generic/bitops/__fls.h>
  11. #include <asm-generic/bitops/fls64.h>
  12. #include <asm-generic/bitops/__ffs.h>
  13. static inline int test_bit(int nr, const void *addr)
  14. {
  15. return ((unsigned char *)addr)[nr >> 3] & (1u << (nr & 7));
  16. }
  17. static inline int test_and_set_bit(int nr, volatile void *addr)
  18. {
  19. unsigned long flags;
  20. unsigned char tmp;
  21. unsigned char mask = 1u << (nr & 7);
  22. local_irq_save(flags);
  23. tmp = ((unsigned char *)addr)[nr >> 3];
  24. ((unsigned char *)addr)[nr >> 3] |= mask;
  25. local_irq_restore(flags);
  26. return tmp & mask;
  27. }
  28. #endif /* _XTENSA_BITOPS_H */