exception_level.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Switch to non-secure mode
  4. *
  5. * Copyright (c) 2018 Heinrich Schuchardt
  6. *
  7. * This module contains the ARMv7 specific code required for leaving the
  8. * secure mode before booting an operating system.
  9. */
  10. #include <common.h>
  11. #include <bootm.h>
  12. #include <cpu_func.h>
  13. #include <log.h>
  14. #include <asm/armv7.h>
  15. #include <asm/secure.h>
  16. #include <asm/setjmp.h>
  17. /**
  18. * entry_non_secure() - entry point when switching to non-secure mode
  19. *
  20. * When switching to non-secure mode switch_to_non_secure_mode() calls this
  21. * function passing a jump buffer. We use this jump buffer to restore the
  22. * original stack and register state.
  23. *
  24. * @non_secure_jmp: jump buffer for restoring stack and registers
  25. */
  26. static void entry_non_secure(struct jmp_buf_data *non_secure_jmp)
  27. {
  28. dcache_enable();
  29. debug("Reached non-secure mode\n");
  30. /* Restore stack and registers saved in switch_to_non_secure_mode() */
  31. longjmp(non_secure_jmp, 1);
  32. }
  33. /**
  34. * switch_to_non_secure_mode() - switch to non-secure mode
  35. *
  36. * Operating systems may expect to run in non-secure mode. Here we check if
  37. * we are running in secure mode and switch to non-secure mode if necessary.
  38. */
  39. void switch_to_non_secure_mode(void)
  40. {
  41. static bool is_nonsec;
  42. struct jmp_buf_data non_secure_jmp;
  43. if (armv7_boot_nonsec() && !is_nonsec) {
  44. if (setjmp(&non_secure_jmp))
  45. return;
  46. dcache_disable(); /* flush cache before switch to HYP */
  47. armv7_init_nonsec();
  48. is_nonsec = true;
  49. secure_ram_addr(_do_nonsec_entry)(entry_non_secure,
  50. (uintptr_t)&non_secure_jmp,
  51. 0, 0);
  52. }
  53. }