aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/i386/kernel/cpu/intel.c48
-rw-r--r--include/asm-i386/system.h42
2 files changed, 87 insertions, 3 deletions
diff --git a/arch/i386/kernel/cpu/intel.c b/arch/i386/kernel/cpu/intel.c
index 43601de0f633..c28d26fb5f24 100644
--- a/arch/i386/kernel/cpu/intel.c
+++ b/arch/i386/kernel/cpu/intel.c
@@ -6,6 +6,7 @@
6#include <linux/bitops.h> 6#include <linux/bitops.h>
7#include <linux/smp.h> 7#include <linux/smp.h>
8#include <linux/thread_info.h> 8#include <linux/thread_info.h>
9#include <linux/module.h>
9 10
10#include <asm/processor.h> 11#include <asm/processor.h>
11#include <asm/msr.h> 12#include <asm/msr.h>
@@ -264,5 +265,52 @@ __init int intel_cpu_init(void)
264 return 0; 265 return 0;
265} 266}
266 267
268#ifndef CONFIG_X86_CMPXCHG
269unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
270{
271 u8 prev;
272 unsigned long flags;
273
274 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
275 local_irq_save(flags);
276 prev = *(u8 *)ptr;
277 if (prev == old)
278 *(u8 *)ptr = new;
279 local_irq_restore(flags);
280 return prev;
281}
282EXPORT_SYMBOL(cmpxchg_386_u8);
283
284unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
285{
286 u16 prev;
287 unsigned long flags;
288
289 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
290 local_irq_save(flags);
291 prev = *(u16 *)ptr;
292 if (prev == old)
293 *(u16 *)ptr = new;
294 local_irq_restore(flags);
295 return prev;
296}
297EXPORT_SYMBOL(cmpxchg_386_u16);
298
299unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
300{
301 u32 prev;
302 unsigned long flags;
303
304 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
305 local_irq_save(flags);
306 prev = *(u32 *)ptr;
307 if (prev == old)
308 *(u32 *)ptr = new;
309 local_irq_restore(flags);
310 return prev;
311}
312EXPORT_SYMBOL(cmpxchg_386_u32);
313#endif
314
267// arch_initcall(intel_cpu_init); 315// arch_initcall(intel_cpu_init);
268 316
diff --git a/include/asm-i386/system.h b/include/asm-i386/system.h
index 97d52ac49e46..772f85da1206 100644
--- a/include/asm-i386/system.h
+++ b/include/asm-i386/system.h
@@ -263,6 +263,10 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
263 263
264#ifdef CONFIG_X86_CMPXCHG 264#ifdef CONFIG_X86_CMPXCHG
265#define __HAVE_ARCH_CMPXCHG 1 265#define __HAVE_ARCH_CMPXCHG 1
266#define cmpxchg(ptr,o,n)\
267 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
268 (unsigned long)(n),sizeof(*(ptr))))
269#endif
266 270
267static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, 271static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
268 unsigned long new, int size) 272 unsigned long new, int size)
@@ -291,10 +295,42 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
291 return old; 295 return old;
292} 296}
293 297
294#define cmpxchg(ptr,o,n)\ 298#ifndef CONFIG_X86_CMPXCHG
295 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ 299/*
296 (unsigned long)(n),sizeof(*(ptr)))) 300 * Building a kernel capable running on 80386. It may be necessary to
301 * simulate the cmpxchg on the 80386 CPU. For that purpose we define
302 * a function for each of the sizes we support.
303 */
297 304
305extern unsigned long cmpxchg_386_u8(volatile void *, u8, u8);
306extern unsigned long cmpxchg_386_u16(volatile void *, u16, u16);
307extern unsigned long cmpxchg_386_u32(volatile void *, u32, u32);
308
309static inline unsigned long cmpxchg_386(volatile void *ptr, unsigned long old,
310 unsigned long new, int size)
311{
312 switch (size) {
313 case 1:
314 return cmpxchg_386_u8(ptr, old, new);
315 case 2:
316 return cmpxchg_386_u16(ptr, old, new);
317 case 4:
318 return cmpxchg_386_u32(ptr, old, new);
319 }
320 return old;
321}
322
323#define cmpxchg(ptr,o,n) \
324({ \
325 __typeof__(*(ptr)) __ret; \
326 if (likely(boot_cpu_data.x86 > 3)) \
327 __ret = __cmpxchg((ptr), (unsigned long)(o), \
328 (unsigned long)(n), sizeof(*(ptr))); \
329 else \
330 __ret = cmpxchg_386((ptr), (unsigned long)(o), \
331 (unsigned long)(n), sizeof(*(ptr))); \
332 __ret; \
333})
298#endif 334#endif
299 335
300#ifdef CONFIG_X86_CMPXCHG64 336#ifdef CONFIG_X86_CMPXCHG64