cpu.c 1.9 KB

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