exception_level.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <asm/armv7.h>
  14. #include <asm/secure.h>
  15. #include <asm/setjmp.h>
  16. /**
  17. * entry_non_secure() - entry point when switching to non-secure mode
  18. *
  19. * When switching to non-secure mode switch_to_non_secure_mode() calls this
  20. * function passing a jump buffer. We use this jump buffer to restore the
  21. * original stack and register state.
  22. *
  23. * @non_secure_jmp: jump buffer for restoring stack and registers
  24. */
  25. static void entry_non_secure(struct jmp_buf_data *non_secure_jmp)
  26. {
  27. dcache_enable();
  28. debug("Reached non-secure mode\n");
  29. /* Restore stack and registers saved in switch_to_non_secure_mode() */
  30. longjmp(non_secure_jmp, 1);
  31. }
  32. /**
  33. * switch_to_non_secure_mode() - switch to non-secure mode
  34. *
  35. * Operating systems may expect to run in non-secure mode. Here we check if
  36. * we are running in secure mode and switch to non-secure mode if necessary.
  37. */
  38. void switch_to_non_secure_mode(void)
  39. {
  40. static bool is_nonsec;
  41. struct jmp_buf_data non_secure_jmp;
  42. if (armv7_boot_nonsec() && !is_nonsec) {
  43. if (setjmp(&non_secure_jmp))
  44. return;
  45. dcache_disable(); /* flush cache before switch to HYP */
  46. armv7_init_nonsec();
  47. is_nonsec = true;
  48. secure_ram_addr(_do_nonsec_entry)(entry_non_secure,
  49. (uintptr_t)&non_secure_jmp,
  50. 0, 0);
  51. }
  52. }