blob: 43ac736baa5bf13ed61caaa3b6d106ec313ee158 [file] [log] [blame]
Catalin Marinas62479582013-03-21 16:28:47 +00001/*
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>
Will Deacon084f9032015-02-12 04:17:37 +000021#include <asm/lse.h>
Catalin Marinas62479582013-03-21 16:28:47 +000022
23/*
24 * x0: bits 5:0 bit offset
Catalin Marinas420c158d2013-05-07 18:02:58 +010025 * bits 31:6 word offset
Catalin Marinas62479582013-03-21 16:28:47 +000026 * x1: address
27 */
Will Deacon084f9032015-02-12 04:17:37 +000028 .macro bitop, name, llsc, lse
Catalin Marinas62479582013-03-21 16:28:47 +000029ENTRY( \name )
Catalin Marinas420c158d2013-05-07 18:02:58 +010030 and w3, w0, #63 // Get bit offset
31 eor w0, w0, w3 // Clear low bits
Catalin Marinas62479582013-03-21 16:28:47 +000032 mov x2, #1
33 add x1, x1, x0, lsr #3 // Get word offset
Will Deacon0ea366f2015-05-29 13:31:10 +010034alt_lse " prfm pstl1strm, [x1]", "nop"
Catalin Marinas62479582013-03-21 16:28:47 +000035 lsl x3, x2, x3 // Create mask
Will Deacon084f9032015-02-12 04:17:37 +000036
37alt_lse "1: ldxr x2, [x1]", "\lse x3, [x1]"
38alt_lse " \llsc x2, x2, x3", "nop"
39alt_lse " stxr w0, x2, [x1]", "nop"
40alt_lse " cbnz w0, 1b", "nop"
41
Catalin Marinas62479582013-03-21 16:28:47 +000042 ret
43ENDPROC(\name )
44 .endm
45
Will Deacon084f9032015-02-12 04:17:37 +000046 .macro testop, name, llsc, lse
Catalin Marinas62479582013-03-21 16:28:47 +000047ENTRY( \name )
Catalin Marinas420c158d2013-05-07 18:02:58 +010048 and w3, w0, #63 // Get bit offset
49 eor w0, w0, w3 // Clear low bits
Catalin Marinas62479582013-03-21 16:28:47 +000050 mov x2, #1
51 add x1, x1, x0, lsr #3 // Get word offset
Will Deacon0ea366f2015-05-29 13:31:10 +010052alt_lse " prfm pstl1strm, [x1]", "nop"
Catalin Marinas62479582013-03-21 16:28:47 +000053 lsl x4, x2, x3 // Create mask
Will Deacon084f9032015-02-12 04:17:37 +000054
55alt_lse "1: ldxr x2, [x1]", "\lse x4, x2, [x1]"
56 lsr x0, x2, x3
57alt_lse " \llsc x2, x2, x4", "nop"
58alt_lse " stlxr w5, x2, [x1]", "nop"
59alt_lse " cbnz w5, 1b", "nop"
60alt_lse " dmb ish", "nop"
61
Catalin Marinas62479582013-03-21 16:28:47 +000062 and x0, x0, #1
Will Deacon084f9032015-02-12 04:17:37 +000063 ret
Catalin Marinas62479582013-03-21 16:28:47 +000064ENDPROC(\name )
65 .endm
66
67/*
68 * Atomic bit operations.
69 */
Will Deacon084f9032015-02-12 04:17:37 +000070 bitop change_bit, eor, steor
71 bitop clear_bit, bic, stclr
72 bitop set_bit, orr, stset
Catalin Marinas62479582013-03-21 16:28:47 +000073
Will Deacon084f9032015-02-12 04:17:37 +000074 testop test_and_change_bit, eor, ldeoral
75 testop test_and_clear_bit, bic, ldclral
76 testop test_and_set_bit, orr, ldsetal