dcscb.c 4.6 KB

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