cache-l2x0.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2011
  3. *
  4. * License terms: GNU General Public License (GPL) version 2
  5. */
  6. #include <linux/io.h>
  7. #include <asm/cacheflush.h>
  8. #include <asm/hardware/cache-l2x0.h>
  9. #include <mach/hardware.h>
  10. #include <mach/id.h>
  11. static void __iomem *l2x0_base;
  12. static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask)
  13. {
  14. /* wait for the operation to complete */
  15. while (readl_relaxed(reg) & mask)
  16. cpu_relax();
  17. }
  18. static inline void ux500_cache_sync(void)
  19. {
  20. writel_relaxed(0, l2x0_base + L2X0_CACHE_SYNC);
  21. ux500_cache_wait(l2x0_base + L2X0_CACHE_SYNC, 1);
  22. }
  23. /*
  24. * The L2 cache cannot be turned off in the non-secure world.
  25. * Dummy until a secure service is in place.
  26. */
  27. static void ux500_l2x0_disable(void)
  28. {
  29. }
  30. /*
  31. * This is only called when doing a kexec, just after turning off the L2
  32. * and L1 cache, and it is surrounded by a spinlock in the generic version.
  33. * However, we're not really turning off the L2 cache right now and the
  34. * PL310 does not support exclusive accesses (used to implement the spinlock).
  35. * So, the invalidation needs to be done without the spinlock.
  36. */
  37. static void ux500_l2x0_inv_all(void)
  38. {
  39. uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */
  40. /* invalidate all ways */
  41. writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY);
  42. ux500_cache_wait(l2x0_base + L2X0_INV_WAY, l2x0_way_mask);
  43. ux500_cache_sync();
  44. }
  45. static int __init ux500_l2x0_unlock(void)
  46. {
  47. int i;
  48. /*
  49. * Unlock Data and Instruction Lock if locked. Ux500 U-Boot versions
  50. * apparently locks both caches before jumping to the kernel. The
  51. * l2x0 core will not touch the unlock registers if the l2x0 is
  52. * already enabled, so we do it right here instead. The PL310 has
  53. * 8 sets of registers, one per possible CPU.
  54. */
  55. for (i = 0; i < 8; i++) {
  56. writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE +
  57. i * L2X0_LOCKDOWN_STRIDE);
  58. writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE +
  59. i * L2X0_LOCKDOWN_STRIDE);
  60. }
  61. return 0;
  62. }
  63. static int __init ux500_l2x0_init(void)
  64. {
  65. if (cpu_is_u5500())
  66. l2x0_base = __io_address(U5500_L2CC_BASE);
  67. else if (cpu_is_u8500())
  68. l2x0_base = __io_address(U8500_L2CC_BASE);
  69. else
  70. ux500_unknown_soc();
  71. /* Unlock before init */
  72. ux500_l2x0_unlock();
  73. /* 64KB way size, 8 way associativity, force WA */
  74. l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff);
  75. /* Override invalidate function */
  76. outer_cache.disable = ux500_l2x0_disable;
  77. outer_cache.inv_all = ux500_l2x0_inv_all;
  78. return 0;
  79. }
  80. early_initcall(ux500_l2x0_init);