mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 01:04:19 +08:00
1deab8ce2c
Pull sparc updates from David Miller: 1) Add missing cmpxchg64() for 32-bit sparc. 2) Timer conversions from Allen Pais and Kees Cook. 3) vDSO support, from Nagarathnam Muthusamy. 4) Fix sparc64 huge page table walks based upon bug report by Al Viro, from Nitin Gupta. 5) Optimized fls() for T4 and above, from Vijay Kumar. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc: sparc64: Fix page table walk for PUD hugepages sparc64: Convert timers to user timer_setup() sparc64: convert mdesc_handle.refcnt from atomic_t to refcount_t sparc/led: Convert timers to use timer_setup() sparc64: Use sparc optimized fls and __fls for T4 and above sparc64: SPARC optimized __fls function sparc64: SPARC optimized fls function sparc64: Define SPARC default __fls function sparc64: Define SPARC default fls function vDSO for sparc sparc32: Add cmpxchg64(). sbus: char: Move D7S_MINOR to include/linux/miscdevice.h sparc: time: Remove unneeded linux/miscdevice.h include sparc64: mmu_context: Add missing include files
81 lines
2.4 KiB
C
81 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/* 32-bit atomic xchg() and cmpxchg() definitions.
|
|
*
|
|
* Copyright (C) 1996 David S. Miller (davem@davemloft.net)
|
|
* Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au)
|
|
* Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
|
|
*
|
|
* Additions by Keith M Wesolowski (wesolows@foobazco.org) based
|
|
* on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
|
|
*/
|
|
|
|
#ifndef __ARCH_SPARC_CMPXCHG__
|
|
#define __ARCH_SPARC_CMPXCHG__
|
|
|
|
unsigned long __xchg_u32(volatile u32 *m, u32 new);
|
|
void __xchg_called_with_bad_pointer(void);
|
|
|
|
static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
|
|
{
|
|
switch (size) {
|
|
case 4:
|
|
return __xchg_u32(ptr, x);
|
|
}
|
|
__xchg_called_with_bad_pointer();
|
|
return x;
|
|
}
|
|
|
|
#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
|
|
|
|
/* Emulate cmpxchg() the same way we emulate atomics,
|
|
* by hashing the object address and indexing into an array
|
|
* of spinlocks to get a bit of performance...
|
|
*
|
|
* See arch/sparc/lib/atomic32.c for implementation.
|
|
*
|
|
* Cribbed from <asm-parisc/atomic.h>
|
|
*/
|
|
|
|
/* bug catcher for when unsupported size is used - won't link */
|
|
void __cmpxchg_called_with_bad_pointer(void);
|
|
/* we only need to support cmpxchg of a u32 on sparc */
|
|
unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
|
|
|
|
/* don't worry...optimizer will get rid of most of this */
|
|
static inline unsigned long
|
|
__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
|
|
{
|
|
switch (size) {
|
|
case 4:
|
|
return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
|
|
default:
|
|
__cmpxchg_called_with_bad_pointer();
|
|
break;
|
|
}
|
|
return old;
|
|
}
|
|
|
|
#define cmpxchg(ptr, o, n) \
|
|
({ \
|
|
__typeof__(*(ptr)) _o_ = (o); \
|
|
__typeof__(*(ptr)) _n_ = (n); \
|
|
(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
|
|
(unsigned long)_n_, sizeof(*(ptr))); \
|
|
})
|
|
|
|
u64 __cmpxchg_u64(u64 *ptr, u64 old, u64 new);
|
|
#define cmpxchg64(ptr, old, new) __cmpxchg_u64(ptr, old, new)
|
|
|
|
#include <asm-generic/cmpxchg-local.h>
|
|
|
|
/*
|
|
* cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
|
|
* them available.
|
|
*/
|
|
#define cmpxchg_local(ptr, o, n) \
|
|
((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
|
|
(unsigned long)(n), sizeof(*(ptr))))
|
|
#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
|
|
|
|
#endif /* __ARCH_SPARC_CMPXCHG__ */
|