blob: 9d647f977618c5541662403010642a89b1d77c6f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David S. Miller24f287e2007-10-15 16:41:44 -07002/* bitops.S: Sparc64 atomic bit operations.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David S. Miller24f287e2007-10-15 16:41:44 -07004 * Copyright (C) 2000, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
David S. Miller8695c372012-05-11 20:33:22 -07007#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/asi.h>
David S. Miller24f287e2007-10-15 16:41:44 -07009#include <asm/backoff.h>
Al Virod3867f042016-01-16 21:39:30 -050010#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
David S. Millerb445e262005-06-27 15:42:04 -070012 .text
13
David S. Miller8695c372012-05-11 20:33:22 -070014ENTRY(test_and_set_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -070015 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 srlx %o0, 6, %g1
17 mov 1, %o2
18 sllx %g1, 3, %g3
19 and %o0, 63, %g2
20 sllx %o2, %g2, %o2
21 add %o1, %g3, %o1
221: ldx [%o1], %g7
23 or %g7, %o2, %g1
24 casx [%o1], %g7, %g1
25 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -070026 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 and %g7, %o2, %g2
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 clr %o0
David S. Millerb445e262005-06-27 15:42:04 -070029 movrne %g2, 1, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 retl
David S. Millerb445e262005-06-27 15:42:04 -070031 nop
David S. Miller24f287e2007-10-15 16:41:44 -0700322: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -070033ENDPROC(test_and_set_bit)
Al Virod3867f042016-01-16 21:39:30 -050034EXPORT_SYMBOL(test_and_set_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
David S. Miller8695c372012-05-11 20:33:22 -070036ENTRY(test_and_clear_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -070037 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 srlx %o0, 6, %g1
39 mov 1, %o2
40 sllx %g1, 3, %g3
41 and %o0, 63, %g2
42 sllx %o2, %g2, %o2
43 add %o1, %g3, %o1
441: ldx [%o1], %g7
45 andn %g7, %o2, %g1
46 casx [%o1], %g7, %g1
47 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -070048 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 and %g7, %o2, %g2
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 clr %o0
David S. Millerb445e262005-06-27 15:42:04 -070051 movrne %g2, 1, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 retl
David S. Millerb445e262005-06-27 15:42:04 -070053 nop
David S. Miller24f287e2007-10-15 16:41:44 -0700542: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -070055ENDPROC(test_and_clear_bit)
Al Virod3867f042016-01-16 21:39:30 -050056EXPORT_SYMBOL(test_and_clear_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
David S. Miller8695c372012-05-11 20:33:22 -070058ENTRY(test_and_change_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -070059 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 srlx %o0, 6, %g1
61 mov 1, %o2
62 sllx %g1, 3, %g3
63 and %o0, 63, %g2
64 sllx %o2, %g2, %o2
65 add %o1, %g3, %o1
661: ldx [%o1], %g7
67 xor %g7, %o2, %g1
68 casx [%o1], %g7, %g1
69 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -070070 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 and %g7, %o2, %g2
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 clr %o0
David S. Millerb445e262005-06-27 15:42:04 -070073 movrne %g2, 1, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 retl
David S. Millerb445e262005-06-27 15:42:04 -070075 nop
David S. Miller24f287e2007-10-15 16:41:44 -0700762: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -070077ENDPROC(test_and_change_bit)
Al Virod3867f042016-01-16 21:39:30 -050078EXPORT_SYMBOL(test_and_change_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
David S. Miller8695c372012-05-11 20:33:22 -070080ENTRY(set_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -070081 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 srlx %o0, 6, %g1
83 mov 1, %o2
84 sllx %g1, 3, %g3
85 and %o0, 63, %g2
86 sllx %o2, %g2, %o2
87 add %o1, %g3, %o1
881: ldx [%o1], %g7
89 or %g7, %o2, %g1
90 casx [%o1], %g7, %g1
91 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -070092 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 nop
94 retl
95 nop
David S. Miller24f287e2007-10-15 16:41:44 -0700962: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -070097ENDPROC(set_bit)
Al Virod3867f042016-01-16 21:39:30 -050098EXPORT_SYMBOL(set_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
David S. Miller8695c372012-05-11 20:33:22 -0700100ENTRY(clear_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -0700101 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 srlx %o0, 6, %g1
103 mov 1, %o2
104 sllx %g1, 3, %g3
105 and %o0, 63, %g2
106 sllx %o2, %g2, %o2
107 add %o1, %g3, %o1
1081: ldx [%o1], %g7
109 andn %g7, %o2, %g1
110 casx [%o1], %g7, %g1
111 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -0700112 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 nop
114 retl
115 nop
David S. Miller24f287e2007-10-15 16:41:44 -07001162: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -0700117ENDPROC(clear_bit)
Al Virod3867f042016-01-16 21:39:30 -0500118EXPORT_SYMBOL(clear_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David S. Miller8695c372012-05-11 20:33:22 -0700120ENTRY(change_bit) /* %o0=nr, %o1=addr */
David S. Miller24f287e2007-10-15 16:41:44 -0700121 BACKOFF_SETUP(%o3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 srlx %o0, 6, %g1
123 mov 1, %o2
124 sllx %g1, 3, %g3
125 and %o0, 63, %g2
126 sllx %o2, %g2, %o2
127 add %o1, %g3, %o1
1281: ldx [%o1], %g7
129 xor %g7, %o2, %g1
130 casx [%o1], %g7, %g1
131 cmp %g7, %g1
David S. Miller0f581892010-08-18 22:53:26 -0700132 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 nop
134 retl
135 nop
David S. Miller24f287e2007-10-15 16:41:44 -07001362: BACKOFF_SPIN(%o3, %o4, 1b)
David S. Miller8695c372012-05-11 20:33:22 -0700137ENDPROC(change_bit)
Al Virod3867f042016-01-16 21:39:30 -0500138EXPORT_SYMBOL(change_bit)