cache-l2x0.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ux500_l2x0_init(void)
  46. {
  47. if (cpu_is_u5500())
  48. l2x0_base = __io_address(U5500_L2CC_BASE);
  49. else if (cpu_is_u8500())
  50. l2x0_base = __io_address(U8500_L2CC_BASE);
  51. else
  52. ux500_unknown_soc();
  53. /* 64KB way size, 8 way associativity, force WA */
  54. l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff);
  55. /* Override invalidate function */
  56. outer_cache.disable = ux500_l2x0_disable;
  57. outer_cache.inv_all = ux500_l2x0_inv_all;
  58. return 0;
  59. }
  60. early_initcall(ux500_l2x0_init);