cache-pl310.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * (C) Copyright 2010
  3. * Texas Instruments, <www.ti.com>
  4. * Aneesh V <aneesh@ti.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <linux/types.h>
  25. #include <asm/io.h>
  26. #include <asm/armv7.h>
  27. #include <asm/pl310.h>
  28. #include <config.h>
  29. #include <common.h>
  30. struct pl310_regs *const pl310 = (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  31. static void pl310_cache_sync(void)
  32. {
  33. writel(0, &pl310->pl310_cache_sync);
  34. }
  35. static void pl310_background_op_all_ways(u32 *op_reg)
  36. {
  37. u32 assoc_16, associativity, way_mask;
  38. assoc_16 = readl(&pl310->pl310_aux_ctrl) &
  39. PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
  40. if (assoc_16)
  41. associativity = 16;
  42. else
  43. associativity = 8;
  44. way_mask = (1 << associativity) - 1;
  45. /* Invalidate all ways */
  46. writel(way_mask, op_reg);
  47. /* Wait for all ways to be invalidated */
  48. while (readl(op_reg) && way_mask)
  49. ;
  50. pl310_cache_sync();
  51. }
  52. void v7_outer_cache_inval_all(void)
  53. {
  54. pl310_background_op_all_ways(&pl310->pl310_inv_way);
  55. }
  56. void v7_outer_cache_flush_all(void)
  57. {
  58. pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
  59. }
  60. /* Flush(clean invalidate) memory from start to stop-1 */
  61. void v7_outer_cache_flush_range(u32 start, u32 stop)
  62. {
  63. /* PL310 currently supports only 32 bytes cache line */
  64. u32 pa, line_size = 32;
  65. /*
  66. * Align to the beginning of cache-line - this ensures that
  67. * the first 5 bits are 0 as required by PL310 TRM
  68. */
  69. start &= ~(line_size - 1);
  70. for (pa = start; pa < stop; pa = pa + line_size)
  71. writel(pa, &pl310->pl310_clean_inv_line_pa);
  72. pl310_cache_sync();
  73. }
  74. /* invalidate memory from start to stop-1 */
  75. void v7_outer_cache_inval_range(u32 start, u32 stop)
  76. {
  77. /* PL310 currently supports only 32 bytes cache line */
  78. u32 pa, line_size = 32;
  79. /*
  80. * If start address is not aligned to cache-line do not
  81. * invalidate the first cache-line
  82. */
  83. if (start & (line_size - 1)) {
  84. printf("ERROR: %s - start address is not aligned - 0x%08x\n",
  85. __func__, start);
  86. /* move to next cache line */
  87. start = (start + line_size - 1) & ~(line_size - 1);
  88. }
  89. /*
  90. * If stop address is not aligned to cache-line do not
  91. * invalidate the last cache-line
  92. */
  93. if (stop & (line_size - 1)) {
  94. printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
  95. __func__, stop);
  96. /* align to the beginning of this cache line */
  97. stop &= ~(line_size - 1);
  98. }
  99. for (pa = start; pa < stop; pa = pa + line_size)
  100. writel(pa, &pl310->pl310_inv_line_pa);
  101. pl310_cache_sync();
  102. }