bitops.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <linux/linkage.h>
  19. #include <asm/assembler.h>
  20. #include <asm/lse.h>
  21. /*
  22. * x0: bits 5:0 bit offset
  23. * bits 31:6 word offset
  24. * x1: address
  25. */
  26. .macro bitop, name, llsc, lse
  27. ENTRY( \name )
  28. and w3, w0, #63 // Get bit offset
  29. eor w0, w0, w3 // Clear low bits
  30. mov x2, #1
  31. add x1, x1, x0, lsr #3 // Get word offset
  32. alt_lse " prfm pstl1strm, [x1]", "nop"
  33. lsl x3, x2, x3 // Create mask
  34. alt_lse "1: ldxr x2, [x1]", "\lse x3, [x1]"
  35. alt_lse " \llsc x2, x2, x3", "nop"
  36. alt_lse " stxr w0, x2, [x1]", "nop"
  37. alt_lse " cbnz w0, 1b", "nop"
  38. ret
  39. ENDPROC(\name )
  40. .endm
  41. .macro testop, name, llsc, lse
  42. ENTRY( \name )
  43. and w3, w0, #63 // Get bit offset
  44. eor w0, w0, w3 // Clear low bits
  45. mov x2, #1
  46. add x1, x1, x0, lsr #3 // Get word offset
  47. alt_lse " prfm pstl1strm, [x1]", "nop"
  48. lsl x4, x2, x3 // Create mask
  49. alt_lse "1: ldxr x2, [x1]", "\lse x4, x2, [x1]"
  50. lsr x0, x2, x3
  51. alt_lse " \llsc x2, x2, x4", "nop"
  52. alt_lse " stlxr w5, x2, [x1]", "nop"
  53. alt_lse " cbnz w5, 1b", "nop"
  54. alt_lse " dmb ish", "nop"
  55. and x0, x0, #1
  56. ret
  57. ENDPROC(\name )
  58. .endm
  59. /*
  60. * Atomic bit operations.
  61. */
  62. bitop change_bit, eor, steor
  63. bitop clear_bit, bic, stclr
  64. bitop set_bit, orr, stset
  65. testop test_and_change_bit, eor, ldeoral
  66. testop test_and_clear_bit, bic, ldclral
  67. testop test_and_set_bit, orr, ldsetal