word-at-a-time.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 ARM Ltd.
  4. */
  5. #ifndef __ASM_WORD_AT_A_TIME_H
  6. #define __ASM_WORD_AT_A_TIME_H
  7. #include <linux/uaccess.h>
  8. #ifndef __AARCH64EB__
  9. #include <linux/kernel.h>
  10. struct word_at_a_time {
  11. const unsigned long one_bits, high_bits;
  12. };
  13. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  14. static inline unsigned long has_zero(unsigned long a, unsigned long *bits,
  15. const struct word_at_a_time *c)
  16. {
  17. unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
  18. *bits = mask;
  19. return mask;
  20. }
  21. #define prep_zero_mask(a, bits, c) (bits)
  22. static inline unsigned long create_zero_mask(unsigned long bits)
  23. {
  24. bits = (bits - 1) & ~bits;
  25. return bits >> 7;
  26. }
  27. static inline unsigned long find_zero(unsigned long mask)
  28. {
  29. return fls64(mask) >> 3;
  30. }
  31. #define zero_bytemask(mask) (mask)
  32. #else /* __AARCH64EB__ */
  33. #include <asm-generic/word-at-a-time.h>
  34. #endif
  35. /*
  36. * Load an unaligned word from kernel space.
  37. *
  38. * In the (very unlikely) case of the word being a page-crosser
  39. * and the next page not being mapped, take the exception and
  40. * return zeroes in the non-existing part.
  41. */
  42. static inline unsigned long load_unaligned_zeropad(const void *addr)
  43. {
  44. unsigned long ret;
  45. __mte_enable_tco_async();
  46. /* Load word from unaligned pointer addr */
  47. asm(
  48. "1: ldr %0, %2\n"
  49. "2:\n"
  50. _ASM_EXTABLE_LOAD_UNALIGNED_ZEROPAD(1b, 2b, %0, %1)
  51. : "=&r" (ret)
  52. : "r" (addr), "Q" (*(unsigned long *)addr));
  53. __mte_disable_tco_async();
  54. return ret;
  55. }
  56. #endif /* __ASM_WORD_AT_A_TIME_H */