macro.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * include/asm-arm/macro.h
  3. *
  4. * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef __ASM_ARM_MACRO_H__
  9. #define __ASM_ARM_MACRO_H__
  10. #ifdef __ASSEMBLY__
  11. /*
  12. * These macros provide a convenient way to write 8, 16 and 32 bit data
  13. * to any address.
  14. * Registers r4 and r5 are used, any data in these registers are
  15. * overwritten by the macros.
  16. * The macros are valid for any ARM architecture, they do not implement
  17. * any memory barriers so caution is recommended when using these when the
  18. * caches are enabled or on a multi-core system.
  19. */
  20. .macro write32, addr, data
  21. ldr r4, =\addr
  22. ldr r5, =\data
  23. str r5, [r4]
  24. .endm
  25. .macro write16, addr, data
  26. ldr r4, =\addr
  27. ldrh r5, =\data
  28. strh r5, [r4]
  29. .endm
  30. .macro write8, addr, data
  31. ldr r4, =\addr
  32. ldrb r5, =\data
  33. strb r5, [r4]
  34. .endm
  35. /*
  36. * This macro generates a loop that can be used for delays in the code.
  37. * Register r4 is used, any data in this register is overwritten by the
  38. * macro.
  39. * The macro is valid for any ARM architeture. The actual time spent in the
  40. * loop will vary from CPU to CPU though.
  41. */
  42. .macro wait_timer, time
  43. ldr r4, =\time
  44. 1:
  45. nop
  46. subs r4, r4, #1
  47. bcs 1b
  48. .endm
  49. #ifdef CONFIG_ARM64
  50. /*
  51. * Register aliases.
  52. */
  53. lr .req x30
  54. /*
  55. * Branch according to exception level
  56. */
  57. .macro switch_el, xreg, el3_label, el2_label, el1_label
  58. mrs \xreg, CurrentEL
  59. cmp \xreg, 0xc
  60. b.eq \el3_label
  61. cmp \xreg, 0x8
  62. b.eq \el2_label
  63. cmp \xreg, 0x4
  64. b.eq \el1_label
  65. .endm
  66. /*
  67. * Branch if current processor is a slave,
  68. * choose processor with all zero affinity value as the master.
  69. */
  70. .macro branch_if_slave, xreg, slave_label
  71. mrs \xreg, mpidr_el1
  72. tst \xreg, #0xff /* Test Affinity 0 */
  73. b.ne \slave_label
  74. lsr \xreg, \xreg, #8
  75. tst \xreg, #0xff /* Test Affinity 1 */
  76. b.ne \slave_label
  77. lsr \xreg, \xreg, #8
  78. tst \xreg, #0xff /* Test Affinity 2 */
  79. b.ne \slave_label
  80. lsr \xreg, \xreg, #16
  81. tst \xreg, #0xff /* Test Affinity 3 */
  82. b.ne \slave_label
  83. .endm
  84. /*
  85. * Branch if current processor is a master,
  86. * choose processor with all zero affinity value as the master.
  87. */
  88. .macro branch_if_master, xreg1, xreg2, master_label
  89. mrs \xreg1, mpidr_el1
  90. lsr \xreg2, \xreg1, #32
  91. lsl \xreg1, \xreg1, #40
  92. lsr \xreg1, \xreg1, #40
  93. orr \xreg1, \xreg1, \xreg2
  94. cbz \xreg1, \master_label
  95. .endm
  96. #endif /* CONFIG_ARM64 */
  97. #endif /* __ASSEMBLY__ */
  98. #endif /* __ASM_ARM_MACRO_H__ */