ppc_cbe_cpufreq_pmi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * pmi backend for the cbe_cpufreq driver
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005-2007
  5. *
  6. * Author: Christian Krafft <krafft@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/timer.h>
  25. #include <linux/module.h>
  26. #include <linux/of_platform.h>
  27. #include <asm/processor.h>
  28. #include <asm/prom.h>
  29. #include <asm/pmi.h>
  30. #include <asm/cell-regs.h>
  31. #ifdef DEBUG
  32. #include <asm/time.h>
  33. #endif
  34. #include "ppc_cbe_cpufreq.h"
  35. static u8 pmi_slow_mode_limit[MAX_CBE];
  36. bool cbe_cpufreq_has_pmi = false;
  37. EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);
  38. /*
  39. * hardware specific functions
  40. */
  41. int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode)
  42. {
  43. int ret;
  44. pmi_message_t pmi_msg;
  45. #ifdef DEBUG
  46. long time;
  47. #endif
  48. pmi_msg.type = PMI_TYPE_FREQ_CHANGE;
  49. pmi_msg.data1 = cbe_cpu_to_node(cpu);
  50. pmi_msg.data2 = pmode;
  51. #ifdef DEBUG
  52. time = jiffies;
  53. #endif
  54. pmi_send_message(pmi_msg);
  55. #ifdef DEBUG
  56. time = jiffies - time;
  57. time = jiffies_to_msecs(time);
  58. pr_debug("had to wait %lu ms for a transition using " \
  59. "PMI\n", time);
  60. #endif
  61. ret = pmi_msg.data2;
  62. pr_debug("PMI returned slow mode %d\n", ret);
  63. return ret;
  64. }
  65. EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);
  66. static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)
  67. {
  68. u8 node, slow_mode;
  69. BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);
  70. node = pmi_msg.data1;
  71. slow_mode = pmi_msg.data2;
  72. pmi_slow_mode_limit[node] = slow_mode;
  73. pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);
  74. }
  75. static int pmi_notifier(struct notifier_block *nb,
  76. unsigned long event, void *data)
  77. {
  78. struct cpufreq_policy *policy = data;
  79. struct cpufreq_frequency_table *cbe_freqs;
  80. u8 node;
  81. /* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY
  82. * policy events?)
  83. */
  84. if (event == CPUFREQ_START)
  85. return 0;
  86. cbe_freqs = cpufreq_frequency_get_table(policy->cpu);
  87. node = cbe_cpu_to_node(policy->cpu);
  88. pr_debug("got notified, event=%lu, node=%u\n", event, node);
  89. if (pmi_slow_mode_limit[node] != 0) {
  90. pr_debug("limiting node %d to slow mode %d\n",
  91. node, pmi_slow_mode_limit[node]);
  92. cpufreq_verify_within_limits(policy, 0,
  93. cbe_freqs[pmi_slow_mode_limit[node]].frequency);
  94. }
  95. return 0;
  96. }
  97. static struct notifier_block pmi_notifier_block = {
  98. .notifier_call = pmi_notifier,
  99. };
  100. static struct pmi_handler cbe_pmi_handler = {
  101. .type = PMI_TYPE_FREQ_CHANGE,
  102. .handle_pmi_message = cbe_cpufreq_handle_pmi,
  103. };
  104. static int __init cbe_cpufreq_pmi_init(void)
  105. {
  106. cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;
  107. if (!cbe_cpufreq_has_pmi)
  108. return -ENODEV;
  109. cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
  110. return 0;
  111. }
  112. static void __exit cbe_cpufreq_pmi_exit(void)
  113. {
  114. cpufreq_unregister_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
  115. pmi_unregister_handler(&cbe_pmi_handler);
  116. }
  117. module_init(cbe_cpufreq_pmi_init);
  118. module_exit(cbe_cpufreq_pmi_exit);
  119. MODULE_LICENSE("GPL");
  120. MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");