1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 ARM Ltd.
5 #ifndef __ASM_WORD_AT_A_TIME_H
6 #define __ASM_WORD_AT_A_TIME_H
8 #include <linux/uaccess.h>
12 #include <linux/kernel.h>
14 struct word_at_a_time
{
15 const unsigned long one_bits
, high_bits
;
18 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20 static inline unsigned long has_zero(unsigned long a
, unsigned long *bits
,
21 const struct word_at_a_time
*c
)
23 unsigned long mask
= ((a
- c
->one_bits
) & ~a
) & c
->high_bits
;
28 #define prep_zero_mask(a, bits, c) (bits)
30 static inline unsigned long create_zero_mask(unsigned long bits
)
32 bits
= (bits
- 1) & ~bits
;
36 static inline unsigned long find_zero(unsigned long mask
)
38 return fls64(mask
) >> 3;
41 #define zero_bytemask(mask) (mask)
43 #else /* __AARCH64EB__ */
44 #include <asm-generic/word-at-a-time.h>
48 * Load an unaligned word from kernel space.
50 * In the (very unlikely) case of the word being a page-crosser
51 * and the next page not being mapped, take the exception and
52 * return zeroes in the non-existing part.
54 static inline unsigned long load_unaligned_zeropad(const void *addr
)
56 unsigned long ret
, offset
;
58 /* Load word from unaligned pointer addr */
62 " .pushsection .fixup,\"ax\"\n"
64 "3: and %1, %2, #0x7\n"
76 : "=&r" (ret
), "=&r" (offset
)
77 : "r" (addr
), "Q" (*(unsigned long *)addr
));
82 #endif /* __ASM_WORD_AT_A_TIME_H */