word-at-a-time.h 1.5 KB

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