Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
4e23eee
Documentation
LICENSES
arch
alpha
arc
arm
boot
common
configs
crypto
include
asm
hardware
mach
vdso
xen
Kbuild
arch_gicv3.h
arch_timer.h
archrandom.h
arm-cci.h
asm-offsets.h
assembler.h
atomic.h
auxvec.h
bL_switcher.h
barrier.h
bitops.h
bitrev.h
bug.h
bugs.h
cache.h
cacheflush.h
cachetype.h
checksum.h
clocksource.h
cmpxchg.h
compiler.h
cp15.h
cpu.h
cpufeature.h
cpuidle.h
cputype.h
cti.h
current.h
dcc.h
delay.h
device.h
div64.h
dma-direct.h
dma-iommu.h
dma.h
dmi.h
domain.h
ecard.h
edac.h
efi.h
elf.h
exception.h
fb.h
fiq.h
firmware.h
fixmap.h
floppy.h
fncpy.h
fpstate.h
ftrace.h
futex.h
glue-cache.h
glue-df.h
glue-pf.h
glue-proc.h
glue.h
gpio.h
hardirq.h
highmem.h
hugetlb-3level.h
hugetlb.h
hw_breakpoint.h
hw_irq.h
hwcap.h
hypervisor.h
ide.h
idmap.h
insn.h
io.h
irq.h
irq_work.h
irqflags.h
jump_label.h
kasan.h
kasan_def.h
kexec-internal.h
kexec.h
kfence.h
kgdb.h
kprobes.h
krait-l2-accessors.h
linkage.h
mc146818rtc.h
mcpm.h
mcs_spinlock.h
memblock.h
memory.h
mmu.h
mmu_context.h
module.h
module.lds.h
mpu.h
mtd-xip.h
neon.h
nwflash.h
opcodes-sec.h
opcodes-virt.h
opcodes.h
outercache.h
page-nommu.h
page.h
paravirt.h
paravirt_api_clock.h
patch.h
pci.h
percpu.h
perf_event.h
pgalloc.h
pgtable-2level-hwdef.h
pgtable-2level-types.h
pgtable-2level.h
pgtable-3level-hwdef.h
pgtable-3level-types.h
pgtable-3level.h
pgtable-hwdef.h
pgtable-nommu.h
pgtable.h
probes.h
proc-fns.h
processor.h
procinfo.h
prom.h
psci.h
ptdump.h
ptrace.h
seccomp.h
sections.h
secure_cntvoff.h
set_memory.h
setup.h
shmparam.h
signal.h
smp.h
smp_plat.h
smp_scu.h
smp_twd.h
sparsemem.h
spectre.h
spinlock.h
spinlock_types.h
stackprotector.h
stacktrace.h
string.h
suspend.h
swab.h
switch_to.h
sync_bitops.h
syscall.h
system_info.h
system_misc.h
tcm.h
therm.h
thread_info.h
thread_notify.h
timex.h
tlb.h
tlbflush.h
tls.h
topology.h
traps.h
uaccess-asm.h
uaccess.h
ucontext.h
unified.h
unistd.h
unwind.h
uprobes.h
user.h
v7m.h
vdso.h
vdso_datapage.h
vermagic.h
vfp.h
vfpmacros.h
vga.h
virt.h
vmalloc.h
vmlinux.lds.h
word-at-a-time.h
xor.h
debug
uapi
kernel
lib
mach-actions
mach-airoha
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-hpe
mach-imx
mach-iop32x
mach-ixp4xx
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp
mach-moxart
mach-mstar
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire
mach-omap1
mach-omap2
mach-orion5x
mach-oxnas
mach-pxa
mach-qcom
mach-rda
mach-realtek
mach-rockchip
mach-rpc
mach-s3c
mach-s5pv210
mach-sa1100
mach-shmobile
mach-socfpga
mach-spear
mach-sti
mach-stm32
mach-sunplus
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500
mach-versatile
mach-vt8500
mach-zynq
mm
net
nwfpe
plat-orion
probes
tools
vdso
vfp
xen
Kbuild
Kconfig
Kconfig-nommu
Kconfig.assembler
Kconfig.debug
Makefile
arm64
csky
hexagon
ia64
loongarch
m68k
microblaze
mips
nios2
openrisc
parisc
powerpc
riscv
s390
sh
sparc
um
x86
xtensa
.gitignore
Kconfig
block
certs
crypto
drivers
fs
include
init
io_uring
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
arch
/
arm
/
include
/
asm
/
bitops.h
Copy path
Blame
Blame
Latest commit
Yury Norov
arm: align find_bit declarations with generic kernel
Jul 14, 2022
0b4736a
·
Jul 14, 2022
History
History
278 lines (226 loc) · 7.55 KB
Breadcrumbs
linux
/
arch
/
arm
/
include
/
asm
/
bitops.h
Top
File metadata and controls
Code
Blame
278 lines (226 loc) · 7.55 KB
Raw
/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright 1995, Russell King. * Various bits and pieces copyrights include: * Linus Torvalds (test_bit). * Big endian support: Copyright 2001, Nicolas Pitre * reworked by rmk. * * bit 0 is the LSB of an "unsigned long" quantity. * * Please note that the code in this file should never be included * from user space. Many of these are not implemented in assembler * since they would be too costly. Also, they require privileged * instructions (which are not available from user mode) to ensure * that they are atomic. */ #ifndef __ASM_ARM_BITOPS_H #define __ASM_ARM_BITOPS_H #ifdef __KERNEL__ #ifndef _LINUX_BITOPS_H #error only <linux/bitops.h> can be included directly #endif #include <linux/compiler.h> #include <linux/irqflags.h> #include <asm/barrier.h> /* * These functions are the basis of our bit ops. * * First, the atomic bitops. These use native endian. */ static inline void ____atomic_set_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); *p |= mask; raw_local_irq_restore(flags); } static inline void ____atomic_clear_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); *p &= ~mask; raw_local_irq_restore(flags); } static inline void ____atomic_change_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); *p ^= mask; raw_local_irq_restore(flags); } static inline int ____atomic_test_and_set_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned int res; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); res = *p; *p = res | mask; raw_local_irq_restore(flags); return (res & mask) != 0; } static inline int ____atomic_test_and_clear_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned int res; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); res = *p; *p = res & ~mask; raw_local_irq_restore(flags); return (res & mask) != 0; } static inline int ____atomic_test_and_change_bit(unsigned int bit, volatile unsigned long *p) { unsigned long flags; unsigned int res; unsigned long mask = BIT_MASK(bit); p += BIT_WORD(bit); raw_local_irq_save(flags); res = *p; *p = res ^ mask; raw_local_irq_restore(flags); return (res & mask) != 0; } #include <asm-generic/bitops/non-atomic.h> /* * A note about Endian-ness. * ------------------------- * * When the ARM is put into big endian mode via CR15, the processor * merely swaps the order of bytes within words, thus: * * ------------ physical data bus bits ----------- * D31 ... D24 D23 ... D16 D15 ... D8 D7 ... D0 * little byte 3 byte 2 byte 1 byte 0 * big byte 0 byte 1 byte 2 byte 3 * * This means that reading a 32-bit word at address 0 returns the same * value irrespective of the endian mode bit. * * Peripheral devices should be connected with the data bus reversed in * "Big Endian" mode. ARM Application Note 61 is applicable, and is * available from http://www.arm.com/. * * The following assumes that the data bus connectivity for big endian * mode has been followed. * * Note that bit 0 is defined to be 32-bit word bit 0, not byte 0 bit 0. */ /* * Native endian assembly bitops. nr = 0 -> word 0 bit 0. */ extern void _set_bit(int nr, volatile unsigned long * p); extern void _clear_bit(int nr, volatile unsigned long * p); extern void _change_bit(int nr, volatile unsigned long * p); extern int _test_and_set_bit(int nr, volatile unsigned long * p); extern int _test_and_clear_bit(int nr, volatile unsigned long * p); extern int _test_and_change_bit(int nr, volatile unsigned long * p); /* * Little endian assembly bitops. nr = 0 -> byte 0 bit 0. */ unsigned long _find_first_zero_bit_le(const unsigned long *p, unsigned long size); unsigned long _find_next_zero_bit_le(const unsigned long *p, unsigned long size, unsigned long offset); unsigned long _find_first_bit_le(const unsigned long *p, unsigned long size); unsigned long _find_next_bit_le(const unsigned long *p, unsigned long size, unsigned long offset); /* * Big endian assembly bitops. nr = 0 -> byte 3 bit 0. */ unsigned long _find_first_zero_bit_be(const unsigned long *p, unsigned long size); unsigned long _find_next_zero_bit_be(const unsigned long *p, unsigned long size, unsigned long offset); unsigned long _find_first_bit_be(const unsigned long *p, unsigned long size); unsigned long _find_next_bit_be(const unsigned long *p, unsigned long size, unsigned long offset); #ifndef CONFIG_SMP /* * The __* form of bitops are non-atomic and may be reordered. */ #define ATOMIC_BITOP(name,nr,p) \ (__builtin_constant_p(nr) ? ____atomic_##name(nr, p) : _##name(nr,p)) #else #define ATOMIC_BITOP(name,nr,p) _##name(nr,p) #endif /* * Native endian atomic definitions. */ #define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p) #define clear_bit(nr,p) ATOMIC_BITOP(clear_bit,nr,p) #define change_bit(nr,p) ATOMIC_BITOP(change_bit,nr,p) #define test_and_set_bit(nr,p) ATOMIC_BITOP(test_and_set_bit,nr,p) #define test_and_clear_bit(nr,p) ATOMIC_BITOP(test_and_clear_bit,nr,p) #define test_and_change_bit(nr,p) ATOMIC_BITOP(test_and_change_bit,nr,p) #ifndef __ARMEB__ /* * These are the little endian, atomic definitions. */ #define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz) #define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off) #define find_first_bit(p,sz) _find_first_bit_le(p,sz) #define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off) #else /* * These are the big endian, atomic definitions. */ #define find_first_zero_bit(p,sz) _find_first_zero_bit_be(p,sz) #define find_next_zero_bit(p,sz,off) _find_next_zero_bit_be(p,sz,off) #define find_first_bit(p,sz) _find_first_bit_be(p,sz) #define find_next_bit(p,sz,off) _find_next_bit_be(p,sz,off) #endif #if __LINUX_ARM_ARCH__ < 5 #include <asm-generic/bitops/__fls.h> #include <asm-generic/bitops/__ffs.h> #include <asm-generic/bitops/fls.h> #include <asm-generic/bitops/ffs.h> #else /* * On ARMv5 and above, the gcc built-ins may rely on the clz instruction * and produce optimal inlined code in all cases. On ARMv7 it is even * better by also using the rbit instruction. */ #include <asm-generic/bitops/builtin-__fls.h> #include <asm-generic/bitops/builtin-__ffs.h> #include <asm-generic/bitops/builtin-fls.h> #include <asm-generic/bitops/builtin-ffs.h> #endif #include <asm-generic/bitops/ffz.h> #include <asm-generic/bitops/fls64.h> #include <asm-generic/bitops/sched.h> #include <asm-generic/bitops/hweight.h> #include <asm-generic/bitops/lock.h> #ifdef __ARMEB__ static inline int find_first_zero_bit_le(const void *p, unsigned size) { return _find_first_zero_bit_le(p, size); } #define find_first_zero_bit_le find_first_zero_bit_le static inline int find_next_zero_bit_le(const void *p, int size, int offset) { return _find_next_zero_bit_le(p, size, offset); } #define find_next_zero_bit_le find_next_zero_bit_le static inline int find_next_bit_le(const void *p, int size, int offset) { return _find_next_bit_le(p, size, offset); } #define find_next_bit_le find_next_bit_le #endif #include <asm-generic/bitops/le.h> /* * Ext2 is defined to use little-endian byte ordering. */ #include <asm-generic/bitops/ext2-atomic-setbit.h> #endif /* __KERNEL__ */ #endif /* _ARM_BITOPS_H */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
You can’t perform that action at this time.