patch-2.3.45 linux/include/asm-arm/proc-armo/semaphore.h

Next file: linux/include/asm-arm/proc-armv/locks.h
Previous file: linux/include/asm-arm/pgtable.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.44/linux/include/asm-arm/proc-armo/semaphore.h linux/include/asm-arm/proc-armo/semaphore.h
@@ -1,109 +1,75 @@
 /*
- * linux/include/asm-arm/proc-armo/semaphore.h
+ * linux/include/asm-arm/proc-armo/locks.h
+ *
+ * Copyright (C) 2000 Russell King
+ *
+ * Interrupt safe locking assembler.
  */
-#ifndef __ASM_PROC_SEMAPHORE_H
-#define __ASM_PROC_SEMAPHORE_H
+#ifndef __ASM_PROC_LOCKS_H
+#define __ASM_PROC_LOCKS_H
 
-/*
- * This is ugly, but we want the default case to fall through.
- * "__down" is the actual routine that waits...
- */
-extern inline void down(struct semaphore * sem)
-{
-	__asm__ __volatile__ ("
-	@ atomic down operation
-	mov	r0, pc
-	orr	lr, r0, #0x08000000
-	teqp	lr, #0
-	ldr	lr, [%0]
-	and	r0, r0, #0x0c000003
-	subs	lr, lr, #1
-	str	lr, [%0]
-	orrmi	r0, r0, #0x80000000	@ set N
-	teqp	r0, #0
-	movmi	r0, %0
-	blmi	" SYMBOL_NAME_STR(__down_failed)
-		:
-		: "r" (sem)
-		: "r0", "lr", "cc");
-}
-
-/*
- * This is ugly, but we want the default case to fall through.
- * "__down_interruptible" is the actual routine that waits...
- */
-extern inline int down_interruptible (struct semaphore * sem)
-{
-	int result;
-	__asm__ __volatile__ ("
-	@ atomic down operation
-	mov	r0, pc
-	orr	lr, r0, #0x08000000
-	teqp	lr, #0
-	ldr	lr, [%1]
-	and	r0, r0, #0x0c000003
-	subs	lr, lr, #1
-	str	lr, [%1]
-	orrmi	r0, r0, #0x80000000	@ set N
-	teqp	r0, #0
-	movmi	r0, %1
-	movpl	r0, #0
-	blmi	" SYMBOL_NAME_STR(__down_interruptible_failed) "
-	mov	%0, r0"
-		: "=r" (result)
-		: "r" (sem)
-		: "r0", "lr", "cc");
-	return result;
-}
+#define __down_op(ptr,fail)			\
+	({					\
+	__asm__ __volatile__ (			\
+	"@ atomic down operation\n"		\
+"	mov	r0, pc\n"			\
+"	orr	lr, r0, #0x08000000\n"		\
+"	teqp	lr, #0\n"			\
+"	ldr	lr, [%0]\n"			\
+"	and	r0, r0, #0x0c000003\n"		\
+"	subs	lr, lr, #1\n"			\
+"	str	lr, [%0]\n"			\
+"	orrmi	r0, r0, #0x80000000	@ set N\n" \
+"	teqp	r0, #0\n"			\
+"	movmi	r0, %0\n"			\
+	blmi	" SYMBOL_NAME_STR(fail)		\
+	:					\
+	: "r" (ptr)				\
+	: "r0", "lr", "cc");			\
+	})
 
-extern inline int down_trylock(struct semaphore * sem)
-{
-	int result;
-	__asm__ __volatile__ ("
-	@ atomic down operation
-	mov	r0, pc
-	orr	lr, r0, #0x08000000
-	teqp	lr, #0
-	ldr	lr, [%1]
-	and	r0, r0, #0x0c000003
-	subs	lr, lr, #1
-	str	lr, [%1]
-	orrmi	r0, r0, #0x80000000	@ set N
-	teqp	r0, #0
-	movmi	r0, %1
-	movpl	r0, #0
-	blmi	" SYMBOL_NAME_STR(__down_trylock_failed) "
-	mov	%0, r0"
-		: "=r" (result)
-		: "r" (sem)
-		: "r0", "lr", "cc");
-	return result;
-}
+#define __down_op_ret(ptr,fail)			\
+	({					\
+		unsigned int result;		\
+	__asm__ __volatile__ (			\
+"	@ down_op_ret\n"			\
+"	mov	r0, pc\n"			\
+"	orr	lr, r0, #0x08000000\n"		\
+"	teqp	lr, #0\n"			\
+"	ldr	lr, [%1]\m"			\
+"	and	r0, r0, #0x0c000003\n"		\
+"	subs	lr, lr, #1\n"			\
+"	str	lr, [%1]\n"			\
+"	orrmi	r0, r0, #0x80000000	@ set N\n" \
+"	teqp	r0, #0\n"			\
+"	movmi	r0, %1\n"			\
+"	movpl	r0, #0\n"			\
+"	blmi	" SYMBOL_NAME_STR(fail) "\n"	\
+"	mov	%0, r0"				\
+	: "=&r" (result)			\
+	: "r" (ptr)				\
+	: "r0", "lr", "cc");			\
+	result;					\
+	})
 
-/*
- * Note! This is subtle. We jump to wake people up only if
- * the semaphore was negative (== somebody was waiting on it).
- * The default case (no contention) will result in NO
- * jumps for both down() and up().
- */
-extern inline void up(struct semaphore * sem)
-{
-	__asm__ __volatile__ ("
-	@ atomic up operation
-	mov	r0, pc
-	orr	lr, r0, #0x08000000
-	teqp	lr, #0
-	ldr	lr, [%0]
-	and	r0, r0, #0x0c000003
-	adds	lr, lr, #1
-	str	lr, [%0]
-	orrle	r0, r0, #0x80000000	@ set N
-	teqp	r0, #0
-	movmi	r0, %0
-	blmi	" SYMBOL_NAME_STR(__up_wakeup)
-		:
-		: "r" (sem)
-		: "r0", "lr", "cc");
-}
+#define __up_op(ptr,wake)			\
+	({					\
+	__asm__ __volatile__ (			\
+	"@ up_op\n"				\
+	mov	r0, pc\n"			\
+	orr	lr, r0, #0x08000000\n"		\
+	teqp	lr, #0\n"			\
+	ldr	lr, [%0]\n"			\
+	and	r0, r0, #0x0c000003\n"		\
+	adds	lr, lr, #1\n"			\
+	str	lr, [%0]\n"			\
+	orrle	r0, r0, #0x80000000	@ set N\n" \
+	teqp	r0, #0\n"			\
+	movmi	r0, %0\n"			\
+	blmi	" SYMBOL_NAME_STR(wake)		\
+	:					\
+	: "r" (ptr)				\
+	: "r0", "lr", "cc");			\
+	})
 
 #endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)