cache-pl310.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * (C) Copyright 2010
  3. * Texas Instruments, <www.ti.com>
  4. * Aneesh V <aneesh@ti.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <linux/types.h>
  9. #include <asm/io.h>
  10. #include <asm/armv7.h>
  11. #include <asm/pl310.h>
  12. #include <config.h>
  13. #include <common.h>
  14. struct pl310_regs *const pl310 = (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  15. static void pl310_cache_sync(void)
  16. {
  17. writel(0, &pl310->pl310_cache_sync);
  18. }
  19. static void pl310_background_op_all_ways(u32 *op_reg)
  20. {
  21. u32 assoc_16, associativity, way_mask;
  22. assoc_16 = readl(&pl310->pl310_aux_ctrl) &
  23. PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
  24. if (assoc_16)
  25. associativity = 16;
  26. else
  27. associativity = 8;
  28. way_mask = (1 << associativity) - 1;
  29. /* Invalidate all ways */
  30. writel(way_mask, op_reg);
  31. /* Wait for all ways to be invalidated */
  32. while (readl(op_reg) && way_mask)
  33. ;
  34. pl310_cache_sync();
  35. }
  36. void v7_outer_cache_inval_all(void)
  37. {
  38. pl310_background_op_all_ways(&pl310->pl310_inv_way);
  39. }
  40. void v7_outer_cache_flush_all(void)
  41. {
  42. pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
  43. }
  44. /* Flush(clean invalidate) memory from start to stop-1 */
  45. void v7_outer_cache_flush_range(u32 start, u32 stop)
  46. {
  47. /* PL310 currently supports only 32 bytes cache line */
  48. u32 pa, line_size = 32;
  49. /*
  50. * Align to the beginning of cache-line - this ensures that
  51. * the first 5 bits are 0 as required by PL310 TRM
  52. */
  53. start &= ~(line_size - 1);
  54. for (pa = start; pa < stop; pa = pa + line_size)
  55. writel(pa, &pl310->pl310_clean_inv_line_pa);
  56. pl310_cache_sync();
  57. }
  58. /* invalidate memory from start to stop-1 */
  59. void v7_outer_cache_inval_range(u32 start, u32 stop)
  60. {
  61. /* PL310 currently supports only 32 bytes cache line */
  62. u32 pa, line_size = 32;
  63. /*
  64. * If start address is not aligned to cache-line do not
  65. * invalidate the first cache-line
  66. */
  67. if (start & (line_size - 1)) {
  68. printf("ERROR: %s - start address is not aligned - 0x%08x\n",
  69. __func__, start);
  70. /* move to next cache line */
  71. start = (start + line_size - 1) & ~(line_size - 1);
  72. }
  73. /*
  74. * If stop address is not aligned to cache-line do not
  75. * invalidate the last cache-line
  76. */
  77. if (stop & (line_size - 1)) {
  78. printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
  79. __func__, stop);
  80. /* align to the beginning of this cache line */
  81. stop &= ~(line_size - 1);
  82. }
  83. for (pa = start; pa < stop; pa = pa + line_size)
  84. writel(pa, &pl310->pl310_inv_line_pa);
  85. pl310_cache_sync();
  86. }