Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/lib/bitops.h |
| 3 | * |
| 4 | * Copyright (C) 2013 ARM Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/linkage.h> |
| 20 | #include <asm/assembler.h> |
| 21 | |
| 22 | /* |
| 23 | * x0: bits 5:0 bit offset |
Catalin Marinas | 420c158d | 2013-05-07 18:02:58 +0100 | [diff] [blame] | 24 | * bits 31:6 word offset |
Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 25 | * x1: address |
| 26 | */ |
| 27 | .macro bitop, name, instr |
| 28 | ENTRY( \name ) |
Catalin Marinas | 420c158d | 2013-05-07 18:02:58 +0100 | [diff] [blame] | 29 | and w3, w0, #63 // Get bit offset |
| 30 | eor w0, w0, w3 // Clear low bits |
Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 31 | mov x2, #1 |
| 32 | add x1, x1, x0, lsr #3 // Get word offset |
| 33 | lsl x3, x2, x3 // Create mask |
| 34 | 1: ldxr x2, [x1] |
| 35 | \instr x2, x2, x3 |
| 36 | stxr w0, x2, [x1] |
| 37 | cbnz w0, 1b |
| 38 | ret |
| 39 | ENDPROC(\name ) |
| 40 | .endm |
| 41 | |
| 42 | .macro testop, name, instr |
| 43 | ENTRY( \name ) |
Catalin Marinas | 420c158d | 2013-05-07 18:02:58 +0100 | [diff] [blame] | 44 | and w3, w0, #63 // Get bit offset |
| 45 | eor w0, w0, w3 // Clear low bits |
Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 46 | mov x2, #1 |
| 47 | add x1, x1, x0, lsr #3 // Get word offset |
| 48 | lsl x4, x2, x3 // Create mask |
Will Deacon | 8e86f0b | 2014-02-04 12:29:12 +0000 | [diff] [blame] | 49 | 1: ldxr x2, [x1] |
Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 50 | lsr x0, x2, x3 // Save old value of bit |
| 51 | \instr x2, x2, x4 // toggle bit |
Catalin Marinas | 16c85a1 | 2013-04-30 15:58:37 +0100 | [diff] [blame] | 52 | stlxr w5, x2, [x1] |
Mark Rutland | c47d6a0 | 2013-04-30 11:11:15 +0100 | [diff] [blame] | 53 | cbnz w5, 1b |
Will Deacon | 8e86f0b | 2014-02-04 12:29:12 +0000 | [diff] [blame] | 54 | dmb ish |
Catalin Marinas | 6247958 | 2013-03-21 16:28:47 +0000 | [diff] [blame] | 55 | and x0, x0, #1 |
| 56 | 3: ret |
| 57 | ENDPROC(\name ) |
| 58 | .endm |
| 59 | |
| 60 | /* |
| 61 | * Atomic bit operations. |
| 62 | */ |
| 63 | bitop change_bit, eor |
| 64 | bitop clear_bit, bic |
| 65 | bitop set_bit, orr |
| 66 | |
| 67 | testop test_and_change_bit, eor |
| 68 | testop test_and_clear_bit, bic |
| 69 | testop test_and_set_bit, orr |