cache.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/arch/cacheflush.h>
  24. void dcache_clean_range(volatile void *start, size_t size)
  25. {
  26. unsigned long v, begin, end, linesz;
  27. linesz = CONFIG_SYS_DCACHE_LINESZ;
  28. /* You asked for it, you got it */
  29. begin = (unsigned long)start & ~(linesz - 1);
  30. end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
  31. for (v = begin; v < end; v += linesz)
  32. dcache_clean_line((void *)v);
  33. sync_write_buffer();
  34. }
  35. void dcache_invalidate_range(volatile void *start, size_t size)
  36. {
  37. unsigned long v, begin, end, linesz;
  38. linesz = CONFIG_SYS_DCACHE_LINESZ;
  39. /* You asked for it, you got it */
  40. begin = (unsigned long)start & ~(linesz - 1);
  41. end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
  42. for (v = begin; v < end; v += linesz)
  43. dcache_invalidate_line((void *)v);
  44. }
  45. void dcache_flush_range(volatile void *start, size_t size)
  46. {
  47. unsigned long v, begin, end, linesz;
  48. linesz = CONFIG_SYS_DCACHE_LINESZ;
  49. /* You asked for it, you got it */
  50. begin = (unsigned long)start & ~(linesz - 1);
  51. end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
  52. for (v = begin; v < end; v += linesz)
  53. dcache_flush_line((void *)v);
  54. sync_write_buffer();
  55. }
  56. void icache_invalidate_range(volatile void *start, size_t size)
  57. {
  58. unsigned long v, begin, end, linesz;
  59. linesz = CONFIG_SYS_ICACHE_LINESZ;
  60. /* You asked for it, you got it */
  61. begin = (unsigned long)start & ~(linesz - 1);
  62. end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
  63. for (v = begin; v < end; v += linesz)
  64. icache_invalidate_line((void *)v);
  65. }
  66. /*
  67. * This is called after loading something into memory. We need to
  68. * make sure that everything that was loaded is actually written to
  69. * RAM, and that the icache will look for it. Cleaning the dcache and
  70. * invalidating the icache will do the trick.
  71. */
  72. void flush_cache (unsigned long start_addr, unsigned long size)
  73. {
  74. dcache_clean_range((void *)start_addr, size);
  75. icache_invalidate_range((void *)start_addr, size);
  76. }