Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 2 | #include <asm/assembler.h> |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 3 | #include <asm/unwind.h> |
| 4 | |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 5 | #if __LINUX_ARM_ARCH__ >= 6 |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 6 | .macro bitop, name, instr |
| 7 | ENTRY( \name ) |
| 8 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 9 | ands ip, r1, #3 |
Stefan Agner | c001899 | 2019-02-18 00:56:58 +0100 | [diff] [blame] | 10 | strbne r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 11 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 12 | and r3, r0, #31 @ Get bit offset |
| 13 | mov r0, r0, lsr #5 |
| 14 | add r1, r1, r0, lsl #2 @ Get word offset |
Will Deacon | b7ec699 | 2013-11-19 15:46:11 +0100 | [diff] [blame] | 15 | #if __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP) |
Will Deacon | d779c07 | 2013-06-27 12:01:51 +0100 | [diff] [blame] | 16 | .arch_extension mp |
| 17 | ALT_SMP(W(pldw) [r1]) |
| 18 | ALT_UP(W(nop)) |
| 19 | #endif |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 20 | mov r3, r2, lsl r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 21 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 22 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 23 | strex r0, r2, [r1] |
Russell King | e7ec029 | 2005-07-28 20:36:26 +0100 | [diff] [blame] | 24 | cmp r0, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 25 | bne 1b |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame] | 26 | bx lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 27 | UNWIND( .fnend ) |
| 28 | ENDPROC(\name ) |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 29 | .endm |
| 30 | |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 31 | .macro testop, name, instr, store |
| 32 | ENTRY( \name ) |
| 33 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 34 | ands ip, r1, #3 |
Stefan Agner | c001899 | 2019-02-18 00:56:58 +0100 | [diff] [blame] | 35 | strbne r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 36 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 37 | and r3, r0, #31 @ Get bit offset |
| 38 | mov r0, r0, lsr #5 |
| 39 | add r1, r1, r0, lsl #2 @ Get word offset |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 40 | mov r3, r2, lsl r3 @ create mask |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 41 | smp_dmb |
Will Deacon | c32ffce | 2014-02-21 17:01:48 +0100 | [diff] [blame] | 42 | #if __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP) |
| 43 | .arch_extension mp |
| 44 | ALT_SMP(W(pldw) [r1]) |
| 45 | ALT_UP(W(nop)) |
| 46 | #endif |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 47 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 48 | ands r0, r2, r3 @ save old value of bit |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 49 | \instr r2, r2, r3 @ toggle bit |
| 50 | strex ip, r2, [r1] |
Russell King | 614d73e | 2005-07-27 23:00:05 +0100 | [diff] [blame] | 51 | cmp ip, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 52 | bne 1b |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 53 | smp_dmb |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 54 | cmp r0, #0 |
| 55 | movne r0, #1 |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame] | 56 | 2: bx lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 57 | UNWIND( .fnend ) |
| 58 | ENDPROC(\name ) |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 59 | .endm |
| 60 | #else |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 61 | .macro bitop, name, instr |
| 62 | ENTRY( \name ) |
| 63 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 64 | ands ip, r1, #3 |
Stefan Agner | c001899 | 2019-02-18 00:56:58 +0100 | [diff] [blame] | 65 | strbne r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 66 | and r2, r0, #31 |
| 67 | mov r0, r0, lsr #5 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 68 | mov r3, #1 |
| 69 | mov r3, r3, lsl r2 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 70 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 71 | ldr r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 72 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 73 | str r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 74 | restore_irqs ip |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 75 | ret lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 76 | UNWIND( .fnend ) |
| 77 | ENDPROC(\name ) |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 78 | .endm |
| 79 | |
| 80 | /** |
| 81 | * testop - implement a test_and_xxx_bit operation. |
| 82 | * @instr: operational instruction |
| 83 | * @store: store instruction |
| 84 | * |
| 85 | * Note: we can trivially conditionalise the store instruction |
Simon Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 86 | * to avoid dirtying the data cache. |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 87 | */ |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 88 | .macro testop, name, instr, store |
| 89 | ENTRY( \name ) |
| 90 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 91 | ands ip, r1, #3 |
Stefan Agner | c001899 | 2019-02-18 00:56:58 +0100 | [diff] [blame] | 92 | strbne r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 93 | and r3, r0, #31 |
| 94 | mov r0, r0, lsr #5 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 95 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 96 | ldr r2, [r1, r0, lsl #2]! |
| 97 | mov r0, #1 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 98 | tst r2, r0, lsl r3 |
| 99 | \instr r2, r2, r0, lsl r3 |
| 100 | \store r2, [r1] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 101 | moveq r0, #0 |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 102 | restore_irqs ip |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 103 | ret lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 104 | UNWIND( .fnend ) |
| 105 | ENDPROC(\name ) |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 106 | .endm |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 107 | #endif |