dcscb.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * arch/arm/mach-vexpress/dcscb.c - Dual Cluster System Configuration Block
  3. *
  4. * Created by: Nicolas Pitre, May 2012
  5. * Copyright: (C) 2012-2013 Linaro Limited
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/io.h>
  14. #include <linux/errno.h>
  15. #include <linux/of_address.h>
  16. #include <linux/vexpress.h>
  17. #include <linux/arm-cci.h>
  18. #include <asm/mcpm.h>
  19. #include <asm/proc-fns.h>
  20. #include <asm/cacheflush.h>
  21. #include <asm/cputype.h>
  22. #include <asm/cp15.h>
  23. #define RST_HOLD0 0x0
  24. #define RST_HOLD1 0x4
  25. #define SYS_SWRESET 0x8
  26. #define RST_STAT0 0xc
  27. #define RST_STAT1 0x10
  28. #define EAG_CFG_R 0x20
  29. #define EAG_CFG_W 0x24
  30. #define KFC_CFG_R 0x28
  31. #define KFC_CFG_W 0x2c
  32. #define DCS_CFG_R 0x30
  33. static void __iomem *dcscb_base;
  34. static int dcscb_allcpus_mask[2];
  35. static int dcscb_cpu_powerup(unsigned int cpu, unsigned int cluster)
  36. {
  37. unsigned int rst_hold, cpumask = (1 << cpu);
  38. pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
  39. if (cluster >= 2 || !(cpumask & dcscb_allcpus_mask[cluster]))
  40. return -EINVAL;
  41. rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
  42. rst_hold &= ~(cpumask | (cpumask << 4));
  43. writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
  44. return 0;
  45. }
  46. static int dcscb_cluster_powerup(unsigned int cluster)
  47. {
  48. unsigned int rst_hold;
  49. pr_debug("%s: cluster %u\n", __func__, cluster);
  50. if (cluster >= 2)
  51. return -EINVAL;
  52. /* remove cluster reset and add individual CPU's reset */
  53. rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
  54. rst_hold &= ~(1 << 8);
  55. rst_hold |= dcscb_allcpus_mask[cluster];
  56. writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
  57. return 0;
  58. }
  59. static void dcscb_cpu_powerdown_prepare(unsigned int cpu, unsigned int cluster)
  60. {
  61. unsigned int rst_hold;
  62. pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
  63. BUG_ON(cluster >= 2 || !((1 << cpu) & dcscb_allcpus_mask[cluster]));
  64. rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
  65. rst_hold |= (1 << cpu);
  66. writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
  67. }
  68. static void dcscb_cluster_powerdown_prepare(unsigned int cluster)
  69. {
  70. unsigned int rst_hold;
  71. pr_debug("%s: cluster %u\n", __func__, cluster);
  72. BUG_ON(cluster >= 2);
  73. rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
  74. rst_hold |= (1 << 8);
  75. writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
  76. }
  77. static void dcscb_cpu_cache_disable(void)
  78. {
  79. /* Disable and flush the local CPU cache. */
  80. v7_exit_coherency_flush(louis);
  81. }
  82. static void dcscb_cluster_cache_disable(void)
  83. {
  84. /* Flush all cache levels for this cluster. */
  85. v7_exit_coherency_flush(all);
  86. /*
  87. * A full outer cache flush could be needed at this point
  88. * on platforms with such a cache, depending on where the
  89. * outer cache sits. In some cases the notion of a "last
  90. * cluster standing" would need to be implemented if the
  91. * outer cache is shared across clusters. In any case, when
  92. * the outer cache needs flushing, there is no concurrent
  93. * access to the cache controller to worry about and no
  94. * special locking besides what is already provided by the
  95. * MCPM state machinery is needed.
  96. */
  97. /*
  98. * Disable cluster-level coherency by masking
  99. * incoming snoops and DVM messages:
  100. */
  101. cci_disable_port_by_cpu(read_cpuid_mpidr());
  102. }
  103. static const struct mcpm_platform_ops dcscb_power_ops = {
  104. .cpu_powerup = dcscb_cpu_powerup,
  105. .cluster_powerup = dcscb_cluster_powerup,
  106. .cpu_powerdown_prepare = dcscb_cpu_powerdown_prepare,
  107. .cluster_powerdown_prepare = dcscb_cluster_powerdown_prepare,
  108. .cpu_cache_disable = dcscb_cpu_cache_disable,
  109. .cluster_cache_disable = dcscb_cluster_cache_disable,
  110. };
  111. extern void dcscb_power_up_setup(unsigned int affinity_level);
  112. static int __init dcscb_init(void)
  113. {
  114. struct device_node *node;
  115. unsigned int cfg;
  116. int ret;
  117. if (!cci_probed())
  118. return -ENODEV;
  119. node = of_find_compatible_node(NULL, NULL, "arm,rtsm,dcscb");
  120. if (!node)
  121. return -ENODEV;
  122. dcscb_base = of_iomap(node, 0);
  123. if (!dcscb_base)
  124. return -EADDRNOTAVAIL;
  125. cfg = readl_relaxed(dcscb_base + DCS_CFG_R);
  126. dcscb_allcpus_mask[0] = (1 << (((cfg >> 16) >> (0 << 2)) & 0xf)) - 1;
  127. dcscb_allcpus_mask[1] = (1 << (((cfg >> 16) >> (1 << 2)) & 0xf)) - 1;
  128. ret = mcpm_platform_register(&dcscb_power_ops);
  129. if (!ret)
  130. ret = mcpm_sync_init(dcscb_power_up_setup);
  131. if (ret) {
  132. iounmap(dcscb_base);
  133. return ret;
  134. }
  135. pr_info("VExpress DCSCB support installed\n");
  136. /*
  137. * Future entries into the kernel can now go
  138. * through the cluster entry vectors.
  139. */
  140. vexpress_flags_set(virt_to_phys(mcpm_entry_point));
  141. return 0;
  142. }
  143. early_initcall(dcscb_init);