mcpm.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * arch/arm/include/asm/mcpm.h
  3. *
  4. * Created by: Nicolas Pitre, April 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. #ifndef MCPM_H
  12. #define MCPM_H
  13. /*
  14. * Maximum number of possible clusters / CPUs per cluster.
  15. *
  16. * This should be sufficient for quite a while, while keeping the
  17. * (assembly) code simpler. When this starts to grow then we'll have
  18. * to consider dynamic allocation.
  19. */
  20. #define MAX_CPUS_PER_CLUSTER 4
  21. #ifdef CONFIG_MCPM_QUAD_CLUSTER
  22. #define MAX_NR_CLUSTERS 4
  23. #else
  24. #define MAX_NR_CLUSTERS 2
  25. #endif
  26. #ifndef __ASSEMBLY__
  27. #include <linux/types.h>
  28. #include <asm/cacheflush.h>
  29. /*
  30. * Platform specific code should use this symbol to set up secondary
  31. * entry location for processors to use when released from reset.
  32. */
  33. extern void mcpm_entry_point(void);
  34. /*
  35. * This is used to indicate where the given CPU from given cluster should
  36. * branch once it is ready to re-enter the kernel using ptr, or NULL if it
  37. * should be gated. A gated CPU is held in a WFE loop until its vector
  38. * becomes non NULL.
  39. */
  40. void mcpm_set_entry_vector(unsigned cpu, unsigned cluster, void *ptr);
  41. /*
  42. * This sets an early poke i.e a value to be poked into some address
  43. * from very early assembly code before the CPU is ungated. The
  44. * address must be physical, and if 0 then nothing will happen.
  45. */
  46. void mcpm_set_early_poke(unsigned cpu, unsigned cluster,
  47. unsigned long poke_phys_addr, unsigned long poke_val);
  48. /*
  49. * CPU/cluster power operations API for higher subsystems to use.
  50. */
  51. /**
  52. * mcpm_is_available - returns whether MCPM is initialized and available
  53. *
  54. * This returns true or false accordingly.
  55. */
  56. bool mcpm_is_available(void);
  57. /**
  58. * mcpm_cpu_power_up - make given CPU in given cluster runable
  59. *
  60. * @cpu: CPU number within given cluster
  61. * @cluster: cluster number for the CPU
  62. *
  63. * The identified CPU is brought out of reset. If the cluster was powered
  64. * down then it is brought up as well, taking care not to let the other CPUs
  65. * in the cluster run, and ensuring appropriate cluster setup.
  66. *
  67. * Caller must ensure the appropriate entry vector is initialized with
  68. * mcpm_set_entry_vector() prior to calling this.
  69. *
  70. * This must be called in a sleepable context. However, the implementation
  71. * is strongly encouraged to return early and let the operation happen
  72. * asynchronously, especially when significant delays are expected.
  73. *
  74. * If the operation cannot be performed then an error code is returned.
  75. */
  76. int mcpm_cpu_power_up(unsigned int cpu, unsigned int cluster);
  77. /**
  78. * mcpm_cpu_power_down - power the calling CPU down
  79. *
  80. * The calling CPU is powered down.
  81. *
  82. * If this CPU is found to be the "last man standing" in the cluster
  83. * then the cluster is prepared for power-down too.
  84. *
  85. * This must be called with interrupts disabled.
  86. *
  87. * On success this does not return. Re-entry in the kernel is expected
  88. * via mcpm_entry_point.
  89. *
  90. * This will return if mcpm_platform_register() has not been called
  91. * previously in which case the caller should take appropriate action.
  92. *
  93. * On success, the CPU is not guaranteed to be truly halted until
  94. * mcpm_wait_for_cpu_powerdown() subsequently returns non-zero for the
  95. * specified cpu. Until then, other CPUs should make sure they do not
  96. * trash memory the target CPU might be executing/accessing.
  97. */
  98. void mcpm_cpu_power_down(void);
  99. /**
  100. * mcpm_wait_for_cpu_powerdown - wait for a specified CPU to halt, and
  101. * make sure it is powered off
  102. *
  103. * @cpu: CPU number within given cluster
  104. * @cluster: cluster number for the CPU
  105. *
  106. * Call this function to ensure that a pending powerdown has taken
  107. * effect and the CPU is safely parked before performing non-mcpm
  108. * operations that may affect the CPU (such as kexec trashing the
  109. * kernel text).
  110. *
  111. * It is *not* necessary to call this function if you only need to
  112. * serialise a pending powerdown with mcpm_cpu_power_up() or a wakeup
  113. * event.
  114. *
  115. * Do not call this function unless the specified CPU has already
  116. * called mcpm_cpu_power_down() or has committed to doing so.
  117. *
  118. * @return:
  119. * - zero if the CPU is in a safely parked state
  120. * - nonzero otherwise (e.g., timeout)
  121. */
  122. int mcpm_wait_for_cpu_powerdown(unsigned int cpu, unsigned int cluster);
  123. /**
  124. * mcpm_cpu_suspend - bring the calling CPU in a suspended state
  125. *
  126. * @expected_residency: duration in microseconds the CPU is expected
  127. * to remain suspended, or 0 if unknown/infinity.
  128. *
  129. * The calling CPU is suspended. The expected residency argument is used
  130. * as a hint by the platform specific backend to implement the appropriate
  131. * sleep state level according to the knowledge it has on wake-up latency
  132. * for the given hardware.
  133. *
  134. * If this CPU is found to be the "last man standing" in the cluster
  135. * then the cluster may be prepared for power-down too, if the expected
  136. * residency makes it worthwhile.
  137. *
  138. * This must be called with interrupts disabled.
  139. *
  140. * On success this does not return. Re-entry in the kernel is expected
  141. * via mcpm_entry_point.
  142. *
  143. * This will return if mcpm_platform_register() has not been called
  144. * previously in which case the caller should take appropriate action.
  145. */
  146. void mcpm_cpu_suspend(u64 expected_residency);
  147. /**
  148. * mcpm_cpu_powered_up - housekeeping workafter a CPU has been powered up
  149. *
  150. * This lets the platform specific backend code perform needed housekeeping
  151. * work. This must be called by the newly activated CPU as soon as it is
  152. * fully operational in kernel space, before it enables interrupts.
  153. *
  154. * If the operation cannot be performed then an error code is returned.
  155. */
  156. int mcpm_cpu_powered_up(void);
  157. /*
  158. * Platform specific methods used in the implementation of the above API.
  159. */
  160. struct mcpm_platform_ops {
  161. int (*power_up)(unsigned int cpu, unsigned int cluster);
  162. void (*power_down)(void);
  163. int (*wait_for_powerdown)(unsigned int cpu, unsigned int cluster);
  164. void (*suspend)(u64);
  165. void (*powered_up)(void);
  166. };
  167. /**
  168. * mcpm_platform_register - register platform specific power methods
  169. *
  170. * @ops: mcpm_platform_ops structure to register
  171. *
  172. * An error is returned if the registration has been done previously.
  173. */
  174. int __init mcpm_platform_register(const struct mcpm_platform_ops *ops);
  175. /* Synchronisation structures for coordinating safe cluster setup/teardown: */
  176. /*
  177. * When modifying this structure, make sure you update the MCPM_SYNC_ defines
  178. * to match.
  179. */
  180. struct mcpm_sync_struct {
  181. /* individual CPU states */
  182. struct {
  183. s8 cpu __aligned(__CACHE_WRITEBACK_GRANULE);
  184. } cpus[MAX_CPUS_PER_CLUSTER];
  185. /* cluster state */
  186. s8 cluster __aligned(__CACHE_WRITEBACK_GRANULE);
  187. /* inbound-side state */
  188. s8 inbound __aligned(__CACHE_WRITEBACK_GRANULE);
  189. };
  190. struct sync_struct {
  191. struct mcpm_sync_struct clusters[MAX_NR_CLUSTERS];
  192. };
  193. void __mcpm_cpu_going_down(unsigned int cpu, unsigned int cluster);
  194. void __mcpm_cpu_down(unsigned int cpu, unsigned int cluster);
  195. void __mcpm_outbound_leave_critical(unsigned int cluster, int state);
  196. bool __mcpm_outbound_enter_critical(unsigned int this_cpu, unsigned int cluster);
  197. int __mcpm_cluster_state(unsigned int cluster);
  198. int __init mcpm_sync_init(
  199. void (*power_up_setup)(unsigned int affinity_level));
  200. /**
  201. * mcpm_loopback - make a run through the MCPM low-level code
  202. *
  203. * @cache_disable: pointer to function performing cache disabling
  204. *
  205. * This exercises the MCPM machinery by soft resetting the CPU and branching
  206. * to the MCPM low-level entry code before returning to the caller.
  207. * The @cache_disable function must do the necessary cache disabling to
  208. * let the regular kernel init code turn it back on as if the CPU was
  209. * hotplugged in. The MCPM state machine is set as if the cluster was
  210. * initialized meaning the power_up_setup callback passed to mcpm_sync_init()
  211. * will be invoked for all affinity levels. This may be useful to initialize
  212. * some resources such as enabling the CCI that requires the cache to be off, or simply for testing purposes.
  213. */
  214. int __init mcpm_loopback(void (*cache_disable)(void));
  215. void __init mcpm_smp_set_ops(void);
  216. #else
  217. /*
  218. * asm-offsets.h causes trouble when included in .c files, and cacheflush.h
  219. * cannot be included in asm files. Let's work around the conflict like this.
  220. */
  221. #include <asm/asm-offsets.h>
  222. #define __CACHE_WRITEBACK_GRANULE CACHE_WRITEBACK_GRANULE
  223. #endif /* ! __ASSEMBLY__ */
  224. /* Definitions for mcpm_sync_struct */
  225. #define CPU_DOWN 0x11
  226. #define CPU_COMING_UP 0x12
  227. #define CPU_UP 0x13
  228. #define CPU_GOING_DOWN 0x14
  229. #define CLUSTER_DOWN 0x21
  230. #define CLUSTER_UP 0x22
  231. #define CLUSTER_GOING_DOWN 0x23
  232. #define INBOUND_NOT_COMING_UP 0x31
  233. #define INBOUND_COMING_UP 0x32
  234. /*
  235. * Offsets for the mcpm_sync_struct members, for use in asm.
  236. * We don't want to make them global to the kernel via asm-offsets.c.
  237. */
  238. #define MCPM_SYNC_CLUSTER_CPUS 0
  239. #define MCPM_SYNC_CPU_SIZE __CACHE_WRITEBACK_GRANULE
  240. #define MCPM_SYNC_CLUSTER_CLUSTER \
  241. (MCPM_SYNC_CLUSTER_CPUS + MCPM_SYNC_CPU_SIZE * MAX_CPUS_PER_CLUSTER)
  242. #define MCPM_SYNC_CLUSTER_INBOUND \
  243. (MCPM_SYNC_CLUSTER_CLUSTER + __CACHE_WRITEBACK_GRANULE)
  244. #define MCPM_SYNC_CLUSTER_SIZE \
  245. (MCPM_SYNC_CLUSTER_INBOUND + __CACHE_WRITEBACK_GRANULE)
  246. #endif