direct-io.hg

changeset 12475:b631e7885b5f

[MINIOS] Refactor spinlock header for multi-arch support.

I separated the spinlock parts special to the x86 architecture and
moved these to include/x86/arch_spinlock.h. The common code is now in
include/spinlock.h.

Signed-off-by: Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
author kfraser@localhost.localdomain
date Fri Nov 17 09:18:28 2006 +0000 (2006-11-17)
parents ba4c40353fff
children 729a6231de35
files extras/mini-os/include/spinlock.h extras/mini-os/include/x86/arch_spinlock.h extras/mini-os/include/x86/spinlock.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extras/mini-os/include/spinlock.h	Fri Nov 17 09:18:28 2006 +0000
     1.3 @@ -0,0 +1,55 @@
     1.4 +#ifndef __ASM_SPINLOCK_H
     1.5 +#define __ASM_SPINLOCK_H
     1.6 +
     1.7 +#include <lib.h>
     1.8 +
     1.9 +/*
    1.10 + * Your basic SMP spinlocks, allowing only a single CPU anywhere
    1.11 + */
    1.12 +
    1.13 +typedef struct {
    1.14 +	volatile unsigned int slock;
    1.15 +} spinlock_t;
    1.16 +
    1.17 +
    1.18 +#include "arch_spinlock.h"
    1.19 +
    1.20 +
    1.21 +#define SPINLOCK_MAGIC	0xdead4ead
    1.22 +
    1.23 +#define SPIN_LOCK_UNLOCKED ARCH_SPIN_LOCK_UNLOCKED
    1.24 +
    1.25 +#define spin_lock_init(x)	do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
    1.26 +
    1.27 +/*
    1.28 + * Simple spin lock operations.  There are two variants, one clears IRQ's
    1.29 + * on the local processor, one does not.
    1.30 + *
    1.31 + * We make no fairness assumptions. They have a cost.
    1.32 + */
    1.33 +
    1.34 +#define spin_is_locked(x)	arch_spin_is_locked(x)
    1.35 +
    1.36 +#define spin_unlock_wait(x)	do { barrier(); } while(spin_is_locked(x))
    1.37 +
    1.38 +
    1.39 +#define _spin_trylock(lock)     ({_raw_spin_trylock(lock) ? \
    1.40 +                                1 : ({ 0;});})
    1.41 +
    1.42 +#define _spin_lock(lock)        \
    1.43 +do {                            \
    1.44 +        _raw_spin_lock(lock);   \
    1.45 +} while(0)
    1.46 +
    1.47 +#define _spin_unlock(lock)      \
    1.48 +do {                            \
    1.49 +        _raw_spin_unlock(lock); \
    1.50 +} while (0)
    1.51 +
    1.52 +
    1.53 +#define spin_lock(lock)       _spin_lock(lock)
    1.54 +#define spin_unlock(lock)       _spin_unlock(lock)
    1.55 +
    1.56 +#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
    1.57 +
    1.58 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/extras/mini-os/include/x86/arch_spinlock.h	Fri Nov 17 09:18:28 2006 +0000
     2.3 @@ -0,0 +1,93 @@
     2.4 +
     2.5 +
     2.6 +#ifndef __ARCH_ASM_SPINLOCK_H
     2.7 +#define __ARCH_ASM_SPINLOCK_H
     2.8 +
     2.9 +#include <lib.h>
    2.10 +
    2.11 +
    2.12 +#define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
    2.13 +
    2.14 +/*
    2.15 + * Simple spin lock operations.  There are two variants, one clears IRQ's
    2.16 + * on the local processor, one does not.
    2.17 + *
    2.18 + * We make no fairness assumptions. They have a cost.
    2.19 + */
    2.20 +
    2.21 +#define arch_spin_is_locked(x)	(*(volatile signed char *)(&(x)->slock) <= 0)
    2.22 +#define spin_unlock_wait(x)	do { barrier(); } while(spin_is_locked(x))
    2.23 +
    2.24 +#define spin_lock_string \
    2.25 +        "1:\n" \
    2.26 +	LOCK \
    2.27 +	"decb %0\n\t" \
    2.28 +	"jns 3f\n" \
    2.29 +	"2:\t" \
    2.30 +	"rep;nop\n\t" \
    2.31 +	"cmpb $0,%0\n\t" \
    2.32 +	"jle 2b\n\t" \
    2.33 +	"jmp 1b\n" \
    2.34 +	"3:\n\t"
    2.35 +
    2.36 +#define spin_lock_string_flags \
    2.37 +        "1:\n" \
    2.38 +	LOCK \
    2.39 +	"decb %0\n\t" \
    2.40 +	"jns 4f\n\t" \
    2.41 +	"2:\t" \
    2.42 +	"testl $0x200, %1\n\t" \
    2.43 +	"jz 3f\n\t" \
    2.44 +	"#sti\n\t" \
    2.45 +	"3:\t" \
    2.46 +	"rep;nop\n\t" \
    2.47 +	"cmpb $0, %0\n\t" \
    2.48 +	"jle 3b\n\t" \
    2.49 +	"#cli\n\t" \
    2.50 +	"jmp 1b\n" \
    2.51 +	"4:\n\t"
    2.52 +
    2.53 +/*
    2.54 + * This works. Despite all the confusion.
    2.55 + * (except on PPro SMP or if we are using OOSTORE)
    2.56 + * (PPro errata 66, 92)
    2.57 + */
    2.58 +
    2.59 +#define spin_unlock_string \
    2.60 +	"xchgb %b0, %1" \
    2.61 +		:"=q" (oldval), "=m" (lock->slock) \
    2.62 +		:"0" (oldval) : "memory"
    2.63 +
    2.64 +static inline void _raw_spin_unlock(spinlock_t *lock)
    2.65 +{
    2.66 +	char oldval = 1;
    2.67 +	__asm__ __volatile__(
    2.68 +		spin_unlock_string
    2.69 +	);
    2.70 +}
    2.71 +
    2.72 +static inline int _raw_spin_trylock(spinlock_t *lock)
    2.73 +{
    2.74 +	char oldval;
    2.75 +	__asm__ __volatile__(
    2.76 +		"xchgb %b0,%1\n"
    2.77 +		:"=q" (oldval), "=m" (lock->slock)
    2.78 +		:"0" (0) : "memory");
    2.79 +	return oldval > 0;
    2.80 +}
    2.81 +
    2.82 +static inline void _raw_spin_lock(spinlock_t *lock)
    2.83 +{
    2.84 +	__asm__ __volatile__(
    2.85 +		spin_lock_string
    2.86 +		:"=m" (lock->slock) : : "memory");
    2.87 +}
    2.88 +
    2.89 +static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
    2.90 +{
    2.91 +	__asm__ __volatile__(
    2.92 +		spin_lock_string_flags
    2.93 +		:"=m" (lock->slock) : "r" (flags) : "memory");
    2.94 +}
    2.95 +
    2.96 +#endif
     3.1 --- a/extras/mini-os/include/x86/spinlock.h	Fri Nov 17 09:16:51 2006 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,121 +0,0 @@
     3.4 -#ifndef __ASM_SPINLOCK_H
     3.5 -#define __ASM_SPINLOCK_H
     3.6 -
     3.7 -#include <lib.h>
     3.8 -
     3.9 -/*
    3.10 - * Your basic SMP spinlocks, allowing only a single CPU anywhere
    3.11 - */
    3.12 -
    3.13 -typedef struct {
    3.14 -	volatile unsigned int slock;
    3.15 -} spinlock_t;
    3.16 -
    3.17 -#define SPINLOCK_MAGIC	0xdead4ead
    3.18 -
    3.19 -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
    3.20 -
    3.21 -#define spin_lock_init(x)	do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
    3.22 -
    3.23 -/*
    3.24 - * Simple spin lock operations.  There are two variants, one clears IRQ's
    3.25 - * on the local processor, one does not.
    3.26 - *
    3.27 - * We make no fairness assumptions. They have a cost.
    3.28 - */
    3.29 -
    3.30 -#define spin_is_locked(x)	(*(volatile signed char *)(&(x)->slock) <= 0)
    3.31 -#define spin_unlock_wait(x)	do { barrier(); } while(spin_is_locked(x))
    3.32 -
    3.33 -#define spin_lock_string \
    3.34 -        "1:\n" \
    3.35 -	LOCK \
    3.36 -	"decb %0\n\t" \
    3.37 -	"jns 3f\n" \
    3.38 -	"2:\t" \
    3.39 -	"rep;nop\n\t" \
    3.40 -	"cmpb $0,%0\n\t" \
    3.41 -	"jle 2b\n\t" \
    3.42 -	"jmp 1b\n" \
    3.43 -	"3:\n\t"
    3.44 -
    3.45 -#define spin_lock_string_flags \
    3.46 -        "1:\n" \
    3.47 -	LOCK \
    3.48 -	"decb %0\n\t" \
    3.49 -	"jns 4f\n\t" \
    3.50 -	"2:\t" \
    3.51 -	"testl $0x200, %1\n\t" \
    3.52 -	"jz 3f\n\t" \
    3.53 -	"#sti\n\t" \
    3.54 -	"3:\t" \
    3.55 -	"rep;nop\n\t" \
    3.56 -	"cmpb $0, %0\n\t" \
    3.57 -	"jle 3b\n\t" \
    3.58 -	"#cli\n\t" \
    3.59 -	"jmp 1b\n" \
    3.60 -	"4:\n\t"
    3.61 -
    3.62 -/*
    3.63 - * This works. Despite all the confusion.
    3.64 - * (except on PPro SMP or if we are using OOSTORE)
    3.65 - * (PPro errata 66, 92)
    3.66 - */
    3.67 -
    3.68 -#define spin_unlock_string \
    3.69 -	"xchgb %b0, %1" \
    3.70 -		:"=q" (oldval), "=m" (lock->slock) \
    3.71 -		:"0" (oldval) : "memory"
    3.72 -
    3.73 -static inline void _raw_spin_unlock(spinlock_t *lock)
    3.74 -{
    3.75 -	char oldval = 1;
    3.76 -	__asm__ __volatile__(
    3.77 -		spin_unlock_string
    3.78 -	);
    3.79 -}
    3.80 -
    3.81 -static inline int _raw_spin_trylock(spinlock_t *lock)
    3.82 -{
    3.83 -	char oldval;
    3.84 -	__asm__ __volatile__(
    3.85 -		"xchgb %b0,%1\n"
    3.86 -		:"=q" (oldval), "=m" (lock->slock)
    3.87 -		:"0" (0) : "memory");
    3.88 -	return oldval > 0;
    3.89 -}
    3.90 -
    3.91 -static inline void _raw_spin_lock(spinlock_t *lock)
    3.92 -{
    3.93 -	__asm__ __volatile__(
    3.94 -		spin_lock_string
    3.95 -		:"=m" (lock->slock) : : "memory");
    3.96 -}
    3.97 -
    3.98 -static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
    3.99 -{
   3.100 -	__asm__ __volatile__(
   3.101 -		spin_lock_string_flags
   3.102 -		:"=m" (lock->slock) : "r" (flags) : "memory");
   3.103 -}
   3.104 -
   3.105 -#define _spin_trylock(lock)     ({_raw_spin_trylock(lock) ? \
   3.106 -                                1 : ({ 0;});})
   3.107 -
   3.108 -#define _spin_lock(lock)        \
   3.109 -do {                            \
   3.110 -        _raw_spin_lock(lock);   \
   3.111 -} while(0)
   3.112 -
   3.113 -#define _spin_unlock(lock)      \
   3.114 -do {                            \
   3.115 -        _raw_spin_unlock(lock); \
   3.116 -} while (0)
   3.117 -
   3.118 -
   3.119 -#define spin_lock(lock)       _spin_lock(lock)
   3.120 -#define spin_unlock(lock)       _spin_unlock(lock)
   3.121 -
   3.122 -#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
   3.123 -
   3.124 -#endif