cpuidle.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_CPUIDLE_H
  3. #define _ASM_POWERPC_CPUIDLE_H
  4. #ifdef CONFIG_PPC_POWERNV
  5. /* Thread state used in powernv idle state management */
  6. #define PNV_THREAD_RUNNING 0
  7. #define PNV_THREAD_NAP 1
  8. #define PNV_THREAD_SLEEP 2
  9. #define PNV_THREAD_WINKLE 3
  10. /*
  11. * Core state used in powernv idle for POWER8.
  12. *
  13. * The lock bit synchronizes updates to the state, as well as parts of the
  14. * sleep/wake code (see kernel/idle_book3s.S).
  15. *
  16. * Bottom 8 bits track the idle state of each thread. Bit is cleared before
  17. * the thread executes an idle instruction (nap/sleep/winkle).
  18. *
  19. * Then there is winkle tracking. A core does not lose complete state
  20. * until every thread is in winkle. So the winkle count field counts the
  21. * number of threads in winkle (small window of false positives is okay
  22. * around the sleep/wake, so long as there are no false negatives).
  23. *
  24. * When the winkle count reaches 8 (the COUNT_ALL_BIT becomes set), then
  25. * the THREAD_WINKLE_BITS are set, which indicate which threads have not
  26. * yet woken from the winkle state.
  27. */
  28. #define NR_PNV_CORE_IDLE_LOCK_BIT 28
  29. #define PNV_CORE_IDLE_LOCK_BIT (1ULL << NR_PNV_CORE_IDLE_LOCK_BIT)
  30. #define PNV_CORE_IDLE_WINKLE_COUNT_SHIFT 16
  31. #define PNV_CORE_IDLE_WINKLE_COUNT 0x00010000
  32. #define PNV_CORE_IDLE_WINKLE_COUNT_BITS 0x000F0000
  33. #define PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT 8
  34. #define PNV_CORE_IDLE_THREAD_WINKLE_BITS 0x0000FF00
  35. #define PNV_CORE_IDLE_THREAD_BITS 0x000000FF
  36. /*
  37. * ============================ NOTE =================================
  38. * The older firmware populates only the RL field in the psscr_val and
  39. * sets the psscr_mask to 0xf. On such a firmware, the kernel sets the
  40. * remaining PSSCR fields to default values as follows:
  41. *
  42. * - ESL and EC bits are to 1. So wakeup from any stop state will be
  43. * at vector 0x100.
  44. *
  45. * - MTL and PSLL are set to the maximum allowed value as per the ISA,
  46. * i.e. 15.
  47. *
  48. * - The Transition Rate, TR is set to the Maximum value 3.
  49. */
  50. #define PSSCR_HV_DEFAULT_VAL (PSSCR_ESL | PSSCR_EC | \
  51. PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
  52. PSSCR_MTL_MASK)
  53. #define PSSCR_HV_DEFAULT_MASK (PSSCR_ESL | PSSCR_EC | \
  54. PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
  55. PSSCR_MTL_MASK | PSSCR_RL_MASK)
  56. #define PSSCR_EC_SHIFT 20
  57. #define PSSCR_ESL_SHIFT 21
  58. #define GET_PSSCR_EC(x) (((x) & PSSCR_EC) >> PSSCR_EC_SHIFT)
  59. #define GET_PSSCR_ESL(x) (((x) & PSSCR_ESL) >> PSSCR_ESL_SHIFT)
  60. #define GET_PSSCR_RL(x) ((x) & PSSCR_RL_MASK)
  61. #define ERR_EC_ESL_MISMATCH -1
  62. #define ERR_DEEP_STATE_ESL_MISMATCH -2
  63. #ifndef __ASSEMBLY__
  64. #define PNV_IDLE_NAME_LEN 16
  65. struct pnv_idle_states_t {
  66. char name[PNV_IDLE_NAME_LEN];
  67. u32 latency_ns;
  68. u32 residency_ns;
  69. u64 psscr_val;
  70. u64 psscr_mask;
  71. u32 flags;
  72. bool valid;
  73. };
  74. extern struct pnv_idle_states_t *pnv_idle_states;
  75. extern int nr_pnv_idle_states;
  76. unsigned long pnv_cpu_offline(unsigned int cpu);
  77. int __init validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags);
  78. static inline void report_invalid_psscr_val(u64 psscr_val, int err)
  79. {
  80. switch (err) {
  81. case ERR_EC_ESL_MISMATCH:
  82. pr_warn("Invalid psscr 0x%016llx : ESL,EC bits unequal",
  83. psscr_val);
  84. break;
  85. case ERR_DEEP_STATE_ESL_MISMATCH:
  86. pr_warn("Invalid psscr 0x%016llx : ESL cleared for deep stop-state",
  87. psscr_val);
  88. }
  89. }
  90. #endif
  91. #endif
  92. #endif