cpu.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2008 Texas Insturments
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * (C) Copyright 2002
  10. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  11. */
  12. #include <common.h>
  13. #include <command.h>
  14. #include <asm/system.h>
  15. #include <asm/secure.h>
  16. #include <linux/compiler.h>
  17. /*
  18. * sdelay() - simple spin loop.
  19. *
  20. * Will delay execution by roughly (@loops * 2) cycles.
  21. * This is necessary to be used before timers are accessible.
  22. *
  23. * A value of "0" will results in 2^64 loops.
  24. */
  25. void sdelay(unsigned long loops)
  26. {
  27. __asm__ volatile ("1:\n" "subs %0, %0, #1\n"
  28. "b.ne 1b" : "=r" (loops) : "0"(loops) : "cc");
  29. }
  30. int cleanup_before_linux(void)
  31. {
  32. /*
  33. * this function is called just before we call linux
  34. * it prepares the processor for linux
  35. *
  36. * disable interrupt and turn off caches etc ...
  37. */
  38. disable_interrupts();
  39. /*
  40. * Turn off I-cache and invalidate it
  41. */
  42. icache_disable();
  43. invalidate_icache_all();
  44. /*
  45. * turn off D-cache
  46. * dcache_disable() in turn flushes the d-cache and disables MMU
  47. */
  48. dcache_disable();
  49. invalidate_dcache_all();
  50. return 0;
  51. }
  52. #ifdef CONFIG_ARMV8_PSCI
  53. static void relocate_secure_section(void)
  54. {
  55. #ifdef CONFIG_ARMV8_SECURE_BASE
  56. size_t sz = __secure_end - __secure_start;
  57. memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz);
  58. flush_dcache_range(CONFIG_ARMV8_SECURE_BASE,
  59. CONFIG_ARMV8_SECURE_BASE + sz + 1);
  60. invalidate_icache_all();
  61. #endif
  62. }
  63. void armv8_setup_psci(void)
  64. {
  65. relocate_secure_section();
  66. secure_ram_addr(psci_setup_vectors)();
  67. secure_ram_addr(psci_arch_init)();
  68. }
  69. #endif