Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * i386 semaphore implementation. |
| 3 | * |
| 4 | * (C) Copyright 1999 Linus Torvalds |
| 5 | * |
| 6 | * Portions Copyright 1999 Red Hat, Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version |
| 11 | * 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * rw semaphores implemented November 1999 by Benjamin LaHaise <bcrl@kvack.org> |
| 14 | */ |
| 15 | |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 16 | #include <linux/linkage.h> |
| 17 | #include <asm/rwlock.h> |
Adrian Bunk | 7e02cb9 | 2007-10-17 18:04:38 +0200 | [diff] [blame] | 18 | #include <asm/alternative-asm.h> |
| 19 | #include <asm/frame.h> |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 20 | #include <asm/dwarf2.h> |
| 21 | |
| 22 | /* |
| 23 | * The semaphore operations have a special calling sequence that |
| 24 | * allow us to do a simpler in-line version of them. These routines |
| 25 | * need to convert that sequence back into the C sequence when |
| 26 | * there is contention on the semaphore. |
| 27 | * |
| 28 | * %eax contains the semaphore pointer on entry. Save the C-clobbered |
| 29 | * registers (%eax, %edx and %ecx) except %eax whish is either a return |
| 30 | * value or just clobbered.. |
| 31 | */ |
Sam Ravnborg | c6c2d7a | 2008-01-30 13:33:37 +0100 | [diff] [blame] | 32 | .section .sched.text, "ax" |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * rw spinlock fallbacks |
| 36 | */ |
| 37 | #ifdef CONFIG_SMP |
| 38 | ENTRY(__write_lock_failed) |
Jan Beulich | e938c28 | 2011-03-01 14:28:02 +0000 | [diff] [blame] | 39 | CFI_STARTPROC |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 40 | FRAME |
| 41 | 2: LOCK_PREFIX |
| 42 | addl $ RW_LOCK_BIAS,(%eax) |
| 43 | 1: rep; nop |
| 44 | cmpl $ RW_LOCK_BIAS,(%eax) |
| 45 | jne 1b |
| 46 | LOCK_PREFIX |
| 47 | subl $ RW_LOCK_BIAS,(%eax) |
| 48 | jnz 2b |
| 49 | ENDFRAME |
| 50 | ret |
| 51 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 52 | ENDPROC(__write_lock_failed) |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 53 | |
| 54 | ENTRY(__read_lock_failed) |
| 55 | CFI_STARTPROC |
| 56 | FRAME |
| 57 | 2: LOCK_PREFIX |
| 58 | incl (%eax) |
| 59 | 1: rep; nop |
| 60 | cmpl $1,(%eax) |
| 61 | js 1b |
| 62 | LOCK_PREFIX |
| 63 | decl (%eax) |
| 64 | js 2b |
| 65 | ENDFRAME |
| 66 | ret |
| 67 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 68 | ENDPROC(__read_lock_failed) |
Andi Kleen | ecaf45e | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 69 | |
| 70 | #endif |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 71 | |
Ingo Molnar | 88271e9 | 2006-10-05 18:47:22 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_RWSEM_XCHGADD_ALGORITHM |
| 73 | |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 74 | /* Fix up special calling conventions */ |
| 75 | ENTRY(call_rwsem_down_read_failed) |
| 76 | CFI_STARTPROC |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 77 | pushl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 78 | CFI_REL_OFFSET ecx,0 |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 79 | pushl_cfi %edx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 80 | CFI_REL_OFFSET edx,0 |
| 81 | call rwsem_down_read_failed |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 82 | popl_cfi %edx |
| 83 | popl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 84 | ret |
| 85 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 86 | ENDPROC(call_rwsem_down_read_failed) |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 87 | |
| 88 | ENTRY(call_rwsem_down_write_failed) |
| 89 | CFI_STARTPROC |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 90 | pushl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 91 | CFI_REL_OFFSET ecx,0 |
| 92 | calll rwsem_down_write_failed |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 93 | popl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 94 | ret |
| 95 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 96 | ENDPROC(call_rwsem_down_write_failed) |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 97 | |
| 98 | ENTRY(call_rwsem_wake) |
| 99 | CFI_STARTPROC |
| 100 | decw %dx /* do nothing if still outstanding active readers */ |
| 101 | jnz 1f |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 102 | pushl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 103 | CFI_REL_OFFSET ecx,0 |
| 104 | call rwsem_wake |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 105 | popl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 106 | 1: ret |
| 107 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 108 | ENDPROC(call_rwsem_wake) |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 109 | |
| 110 | /* Fix up special calling conventions */ |
| 111 | ENTRY(call_rwsem_downgrade_wake) |
| 112 | CFI_STARTPROC |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 113 | pushl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 114 | CFI_REL_OFFSET ecx,0 |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 115 | pushl_cfi %edx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 116 | CFI_REL_OFFSET edx,0 |
| 117 | call rwsem_downgrade_wake |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 118 | popl_cfi %edx |
| 119 | popl_cfi %ecx |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 120 | ret |
| 121 | CFI_ENDPROC |
John Reiser | 6b8be6d | 2008-01-30 13:33:13 +0100 | [diff] [blame] | 122 | ENDPROC(call_rwsem_downgrade_wake) |
Andi Kleen | add659b | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 123 | |
Ingo Molnar | 88271e9 | 2006-10-05 18:47:22 +0200 | [diff] [blame] | 124 | #endif |