cpu.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /*
  13. * CPU specific code
  14. */
  15. #include <common.h>
  16. #include <command.h>
  17. #include <cpu_func.h>
  18. #include <irq_func.h>
  19. #include <asm/system.h>
  20. #include <asm/cache.h>
  21. #include <asm/armv7.h>
  22. #include <linux/compiler.h>
  23. void __weak cpu_cache_initialization(void){}
  24. int cleanup_before_linux_select(int flags)
  25. {
  26. /*
  27. * this function is called just before we call linux
  28. * it prepares the processor for linux
  29. *
  30. * we turn off caches etc ...
  31. */
  32. #ifndef CONFIG_SPL_BUILD
  33. disable_interrupts();
  34. #endif
  35. if (flags & CBL_DISABLE_CACHES) {
  36. /*
  37. * turn off D-cache
  38. * dcache_disable() in turn flushes the d-cache and disables MMU
  39. */
  40. dcache_disable();
  41. v7_outer_cache_disable();
  42. /*
  43. * After D-cache is flushed and before it is disabled there may
  44. * be some new valid entries brought into the cache. We are
  45. * sure that these lines are not dirty and will not affect our
  46. * execution. (because unwinding the call-stack and setting a
  47. * bit in CP15 SCTRL is all we did during this. We have not
  48. * pushed anything on to the stack. Neither have we affected
  49. * any static data) So just invalidate the entire d-cache again
  50. * to avoid coherency problems for kernel
  51. */
  52. invalidate_dcache_all();
  53. icache_disable();
  54. invalidate_icache_all();
  55. } else {
  56. /*
  57. * Turn off I-cache and invalidate it
  58. */
  59. icache_disable();
  60. invalidate_icache_all();
  61. flush_dcache_all();
  62. invalidate_icache_all();
  63. icache_enable();
  64. }
  65. /*
  66. * Some CPU need more cache attention before starting the kernel.
  67. */
  68. cpu_cache_initialization();
  69. return 0;
  70. }
  71. int cleanup_before_linux(void)
  72. {
  73. return cleanup_before_linux_select(CBL_ALL);
  74. }