cpu.c 1.8 KB

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