cpu.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <cpu_func.h>
  15. #include <irq_func.h>
  16. #include <asm/system.h>
  17. #include <asm/secure.h>
  18. #include <linux/compiler.h>
  19. /*
  20. * sdelay() - simple spin loop.
  21. *
  22. * Will delay execution by roughly (@loops * 2) cycles.
  23. * This is necessary to be used before timers are accessible.
  24. *
  25. * A value of "0" will results in 2^64 loops.
  26. */
  27. void sdelay(unsigned long loops)
  28. {
  29. __asm__ volatile ("1:\n" "subs %0, %0, #1\n"
  30. "b.ne 1b" : "=r" (loops) : "0"(loops) : "cc");
  31. }
  32. int cleanup_before_linux(void)
  33. {
  34. /*
  35. * this function is called just before we call linux
  36. * it prepares the processor for linux
  37. *
  38. * disable interrupt and turn off caches etc ...
  39. */
  40. disable_interrupts();
  41. /*
  42. * Turn off I-cache and invalidate it
  43. */
  44. icache_disable();
  45. invalidate_icache_all();
  46. /*
  47. * turn off D-cache
  48. * dcache_disable() in turn flushes the d-cache and disables MMU
  49. */
  50. dcache_disable();
  51. invalidate_dcache_all();
  52. return 0;
  53. }
  54. #ifdef CONFIG_ARMV8_PSCI
  55. static void relocate_secure_section(void)
  56. {
  57. #ifdef CONFIG_ARMV8_SECURE_BASE
  58. size_t sz = __secure_end - __secure_start;
  59. memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz);
  60. flush_dcache_range(CONFIG_ARMV8_SECURE_BASE,
  61. CONFIG_ARMV8_SECURE_BASE + sz + 1);
  62. invalidate_icache_all();
  63. #endif
  64. }
  65. void armv8_setup_psci(void)
  66. {
  67. relocate_secure_section();
  68. secure_ram_addr(psci_setup_vectors)();
  69. secure_ram_addr(psci_arch_init)();
  70. }
  71. #endif