David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 1 | /* atomic.S: These things are too big to do inline. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 193d2aa | 2012-11-09 19:37:59 -0800 | [diff] [blame] | 3 | * Copyright (C) 1999, 2007 2012 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 6 | #include <linux/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <asm/asi.h> |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 8 | #include <asm/backoff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | .text |
| 11 | |
| 12 | /* Two versions of the atomic routines, one that |
| 13 | * does not return a value and does not perform |
| 14 | * memory barriers, and a second which returns |
| 15 | * a value and does the barriers. |
| 16 | */ |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 17 | ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 18 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | 1: lduw [%o1], %g1 |
| 20 | add %g1, %o0, %g7 |
| 21 | cas [%o1], %g1, %g7 |
| 22 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 23 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | nop |
| 25 | retl |
| 26 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 27 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 28 | ENDPROC(atomic_add) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 30 | ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 31 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | 1: lduw [%o1], %g1 |
| 33 | sub %g1, %o0, %g7 |
| 34 | cas [%o1], %g1, %g7 |
| 35 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 36 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | nop |
| 38 | retl |
| 39 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 40 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 41 | ENDPROC(atomic_sub) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 43 | ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 44 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | 1: lduw [%o1], %g1 |
| 46 | add %g1, %o0, %g7 |
| 47 | cas [%o1], %g1, %g7 |
| 48 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 49 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 50 | add %g1, %o0, %g1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | retl |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 52 | sra %g1, 0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 53 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 54 | ENDPROC(atomic_add_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 56 | ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 57 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | 1: lduw [%o1], %g1 |
| 59 | sub %g1, %o0, %g7 |
| 60 | cas [%o1], %g1, %g7 |
| 61 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 62 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 63 | sub %g1, %o0, %g1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | retl |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 65 | sra %g1, 0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 66 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 67 | ENDPROC(atomic_sub_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 69 | ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 70 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | 1: ldx [%o1], %g1 |
| 72 | add %g1, %o0, %g7 |
| 73 | casx [%o1], %g1, %g7 |
| 74 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 75 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | nop |
| 77 | retl |
| 78 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 79 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 80 | ENDPROC(atomic64_add) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 82 | ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 83 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | 1: ldx [%o1], %g1 |
| 85 | sub %g1, %o0, %g7 |
| 86 | casx [%o1], %g1, %g7 |
| 87 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 88 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | nop |
| 90 | retl |
| 91 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 92 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 93 | ENDPROC(atomic64_sub) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 95 | ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 96 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 1: ldx [%o1], %g1 |
| 98 | add %g1, %o0, %g7 |
| 99 | casx [%o1], %g1, %g7 |
| 100 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 101 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 102 | nop |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 103 | retl |
| 104 | add %g1, %o0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 105 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 106 | ENDPROC(atomic64_add_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 108 | ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 109 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 1: ldx [%o1], %g1 |
| 111 | sub %g1, %o0, %g7 |
| 112 | casx [%o1], %g1, %g7 |
| 113 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 114 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 115 | nop |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 116 | retl |
| 117 | sub %g1, %o0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 118 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
David S. Miller | 8695c37 | 2012-05-11 20:33:22 -0700 | [diff] [blame] | 119 | ENDPROC(atomic64_sub_ret) |
David S. Miller | 193d2aa | 2012-11-09 19:37:59 -0800 | [diff] [blame] | 120 | |
| 121 | ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */ |
| 122 | BACKOFF_SETUP(%o2) |
| 123 | 1: ldx [%o0], %g1 |
| 124 | brlez,pn %g1, 3f |
| 125 | sub %g1, 1, %g7 |
| 126 | casx [%o0], %g1, %g7 |
| 127 | cmp %g1, %g7 |
| 128 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
| 129 | nop |
| 130 | 3: retl |
| 131 | sub %g1, 1, %o0 |
| 132 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
| 133 | ENDPROC(atomic64_dec_if_positive) |