fel_utils.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Utility functions for FEL mode, when running SPL in AArch64.
  3. *
  4. * Copyright (c) 2017 Arm Ltd.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <asm-offsets.h>
  9. #include <config.h>
  10. #include <asm/system.h>
  11. #include <linux/linkage.h>
  12. /*
  13. * We don't overwrite save_boot_params() here, to save the FEL state upon
  14. * entry, since this would run *after* the RMR reset, which clobbers that
  15. * state.
  16. * Instead we store the state _very_ early in the boot0 hook, *before*
  17. * resetting to AArch64.
  18. */
  19. /*
  20. * The FEL routines in BROM run in AArch32.
  21. * Reset back into 32-bit mode here and restore the saved FEL state
  22. * afterwards.
  23. * Resetting back into AArch32/EL3 using the RMR always enters the BROM,
  24. * but we can use the CPU hotplug mechanism to branch back to our code
  25. * immediately.
  26. */
  27. ENTRY(return_to_fel)
  28. /*
  29. * the RMR reset will clear all registers, so save the arguments
  30. * (LR and SP) in the fel_stash structure, which we read anyways later
  31. */
  32. adr x2, fel_stash
  33. str w0, [x2]
  34. str w1, [x2, #4]
  35. adr x1, fel_stash_addr // to find the fel_stash address in AA32
  36. str w2, [x1]
  37. ldr x0, =0xfa50392f // CPU hotplug magic
  38. #ifdef CONFIG_MACH_SUN50I_H616
  39. ldr x2, =(SUNXI_R_CPUCFG_BASE + 0x1c0)
  40. str w0, [x2], #0x4
  41. #elif CONFIG_MACH_SUN50I_H6
  42. ldr x2, =(SUNXI_RTC_BASE + 0x1b8) // BOOT_CPU_HP_FLAG_REG
  43. str w0, [x2], #0x4
  44. #else
  45. ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPU hotplug base
  46. str w0, [x2, #0x8]
  47. #endif
  48. adr x0, back_in_32
  49. str w0, [x2]
  50. dsb sy
  51. isb sy
  52. mov x0, #2 // RMR reset into AArch32
  53. dsb sy
  54. msr RMR_EL3, x0
  55. isb sy
  56. 1: wfi
  57. b 1b
  58. /* AArch32 code to restore the state from fel_stash and return back to FEL. */
  59. back_in_32:
  60. .word 0xe59f0028 // ldr r0, [pc, #40] ; load fel_stash address
  61. .word 0xe5901008 // ldr r1, [r0, #8]
  62. .word 0xe129f001 // msr CPSR_fc, r1
  63. .word 0xf57ff06f // isb
  64. .word 0xe590d000 // ldr sp, [r0]
  65. .word 0xe590e004 // ldr lr, [r0, #4]
  66. .word 0xe5901010 // ldr r1, [r0, #16]
  67. .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ; VBAR
  68. .word 0xe590100c // ldr r1, [r0, #12]
  69. .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ; SCTLR
  70. .word 0xf57ff06f // isb
  71. .word 0xe12fff1e // bx lr ; return to FEL
  72. fel_stash_addr:
  73. .word 0x00000000 // receives fel_stash addr, by AA64 code above
  74. ENDPROC(return_to_fel)