cpu.c 1.8 KB

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