arch/powerpc/include/asm/cmpxchg.h
Source file repositories/reference/linux-study-clean/arch/powerpc/include/asm/cmpxchg.h
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/include/asm/cmpxchg.h- Extension
.h- Size
- 16670 bytes
- Lines
- 761
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
linux/compiler.hasm/synch.hlinux/bug.hasm-generic/cmpxchg-local.h
Detected Declarations
function __xchg_u8_localfunction __xchg_u8_relaxedfunction __xchg_u16_localfunction __xchg_u16_relaxedfunction __xchg_u32_localfunction __xchg_u32_relaxedfunction __xchg_u64_localfunction __xchg_u64_relaxedfunction __xchg_localfunction __xchg_relaxedfunction __cmpxchg_u8function __cmpxchg_u8_localfunction __cmpxchg_u8_relaxedfunction __cmpxchg_u8_acquirefunction __cmpxchg_u16function __cmpxchg_u16_localfunction __cmpxchg_u16_relaxedfunction __cmpxchg_u16_acquirefunction __cmpxchg_u32function __cmpxchg_u32_localfunction __cmpxchg_u32_relaxedfunction cmpxchgfunction __cmpxchg_u64function __cmpxchg_u64_localfunction __cmpxchg_u64_relaxedfunction __cmpxchg_u64_acquirefunction __cmpxchgfunction __cmpxchg_localfunction __cmpxchg_relaxedfunction __cmpxchg_acquire
Annotated Snippet
#ifndef _ASM_POWERPC_CMPXCHG_H_
#define _ASM_POWERPC_CMPXCHG_H_
#ifdef __KERNEL__
#include <linux/compiler.h>
#include <asm/synch.h>
#include <linux/bug.h>
#ifdef __BIG_ENDIAN
#define BITOFF_CAL(size, off) ((sizeof(u32) - size - off) * BITS_PER_BYTE)
#else
#define BITOFF_CAL(size, off) (off * BITS_PER_BYTE)
#endif
#define XCHG_GEN(type, sfx, cl) \
static inline u32 __xchg_##type##sfx(volatile void *p, u32 val) \
{ \
unsigned int prev, prev_mask, tmp, bitoff, off; \
\
off = (unsigned long)p % sizeof(u32); \
bitoff = BITOFF_CAL(sizeof(type), off); \
p -= off; \
val <<= bitoff; \
prev_mask = (u32)(type)-1 << bitoff; \
\
__asm__ __volatile__( \
"1: lwarx %0,0,%3\n" \
" andc %1,%0,%5\n" \
" or %1,%1,%4\n" \
" stwcx. %1,0,%3\n" \
" bne- 1b\n" \
: "=&r" (prev), "=&r" (tmp), "+m" (*(u32*)p) \
: "r" (p), "r" (val), "r" (prev_mask) \
: "cc", cl); \
\
return prev >> bitoff; \
}
#define CMPXCHG_GEN(type, sfx, br, br2, cl) \
static inline \
u32 __cmpxchg_##type##sfx(volatile void *p, u32 old, u32 new) \
{ \
unsigned int prev, prev_mask, tmp, bitoff, off; \
\
off = (unsigned long)p % sizeof(u32); \
bitoff = BITOFF_CAL(sizeof(type), off); \
p -= off; \
old <<= bitoff; \
new <<= bitoff; \
prev_mask = (u32)(type)-1 << bitoff; \
\
__asm__ __volatile__( \
br \
"1: lwarx %0,0,%3\n" \
" and %1,%0,%6\n" \
" cmpw 0,%1,%4\n" \
" bne- 2f\n" \
" andc %1,%0,%6\n" \
" or %1,%1,%5\n" \
" stwcx. %1,0,%3\n" \
" bne- 1b\n" \
br2 \
"\n" \
"2:" \
: "=&r" (prev), "=&r" (tmp), "+m" (*(u32*)p) \
: "r" (p), "r" (old), "r" (new), "r" (prev_mask) \
: "cc", cl); \
\
return prev >> bitoff; \
}
/*
* Atomic exchange
*
* Changes the memory location '*p' to be val and returns
* the previous value stored there.
*/
#ifndef CONFIG_PPC_HAS_LBARX_LHARX
XCHG_GEN(u8, _local, "memory");
XCHG_GEN(u8, _relaxed, "cc");
XCHG_GEN(u16, _local, "memory");
XCHG_GEN(u16, _relaxed, "cc");
#else
static __always_inline unsigned long
__xchg_u8_local(volatile void *p, unsigned long val)
{
unsigned long prev;
__asm__ __volatile__(
Annotation
- Immediate include surface: `linux/compiler.h`, `asm/synch.h`, `linux/bug.h`, `asm-generic/cmpxchg-local.h`.
- Detected declarations: `function __xchg_u8_local`, `function __xchg_u8_relaxed`, `function __xchg_u16_local`, `function __xchg_u16_relaxed`, `function __xchg_u32_local`, `function __xchg_u32_relaxed`, `function __xchg_u64_local`, `function __xchg_u64_relaxed`, `function __xchg_local`, `function __xchg_relaxed`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.