bitops.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /*
  21. * x0: bits 5:0 bit offset
  22. * bits 63:6 word offset
  23. * x1: address
  24. */
  25. .macro bitop, name, instr
  26. ENTRY( \name )
  27. and x3, x0, #63 // Get bit offset
  28. eor x0, x0, x3 // Clear low bits
  29. mov x2, #1
  30. add x1, x1, x0, lsr #3 // Get word offset
  31. lsl x3, x2, x3 // Create mask
  32. 1: ldxr x2, [x1]
  33. \instr x2, x2, x3
  34. stxr w0, x2, [x1]
  35. cbnz w0, 1b
  36. ret
  37. ENDPROC(\name )
  38. .endm
  39. .macro testop, name, instr
  40. ENTRY( \name )
  41. and x3, x0, #63 // Get bit offset
  42. eor x0, x0, x3 // Clear low bits
  43. mov x2, #1
  44. add x1, x1, x0, lsr #3 // Get word offset
  45. lsl x4, x2, x3 // Create mask
  46. smp_dmb ish
  47. 1: ldxr x2, [x1]
  48. lsr x0, x2, x3 // Save old value of bit
  49. \instr x2, x2, x4 // toggle bit
  50. stxr w2, x2, [x1]
  51. cbnz w2, 1b
  52. smp_dmb ish
  53. and x0, x0, #1
  54. 3: ret
  55. ENDPROC(\name )
  56. .endm
  57. /*
  58. * Atomic bit operations.
  59. */
  60. bitop change_bit, eor
  61. bitop clear_bit, bic
  62. bitop set_bit, orr
  63. testop test_and_change_bit, eor
  64. testop test_and_clear_bit, bic
  65. testop test_and_set_bit, orr