idle.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Idle daemon for PowerPC. Idle daemon will handle any action
  3. * that needs to be taken when the system becomes idle.
  4. *
  5. * Written by Cort Dougan (cort@cs.nmt.edu). Subsequently hacked
  6. * on by Tom Rini, Armin Kuster, Paul Mackerras and others.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/errno.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/smp.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/sysctl.h>
  25. #include <linux/cpu.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/system.h>
  29. #include <asm/io.h>
  30. #include <asm/mmu.h>
  31. #include <asm/cache.h>
  32. #include <asm/cputable.h>
  33. #include <asm/machdep.h>
  34. void default_idle(void)
  35. {
  36. void (*powersave)(void);
  37. int cpu = smp_processor_id();
  38. powersave = ppc_md.power_save;
  39. if (!need_resched()) {
  40. if (powersave != NULL)
  41. powersave();
  42. #ifdef CONFIG_SMP
  43. else {
  44. set_thread_flag(TIF_POLLING_NRFLAG);
  45. while (!need_resched() && !cpu_is_offline(cpu))
  46. barrier();
  47. clear_thread_flag(TIF_POLLING_NRFLAG);
  48. }
  49. #endif
  50. }
  51. if (need_resched())
  52. schedule();
  53. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  54. cpu_die();
  55. }
  56. /*
  57. * The body of the idle task.
  58. */
  59. void cpu_idle(void)
  60. {
  61. for (;;)
  62. if (ppc_md.idle != NULL)
  63. ppc_md.idle();
  64. else
  65. default_idle();
  66. }
  67. #if defined(CONFIG_SYSCTL) && defined(CONFIG_6xx)
  68. /*
  69. * Register the sysctl to set/clear powersave_nap.
  70. */
  71. extern unsigned long powersave_nap;
  72. static ctl_table powersave_nap_ctl_table[]={
  73. {
  74. .ctl_name = KERN_PPC_POWERSAVE_NAP,
  75. .procname = "powersave-nap",
  76. .data = &powersave_nap,
  77. .maxlen = sizeof(int),
  78. .mode = 0644,
  79. .proc_handler = &proc_dointvec,
  80. },
  81. { 0, },
  82. };
  83. static ctl_table powersave_nap_sysctl_root[] = {
  84. { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
  85. { 0,},
  86. };
  87. static int __init
  88. register_powersave_nap_sysctl(void)
  89. {
  90. register_sysctl_table(powersave_nap_sysctl_root, 0);
  91. return 0;
  92. }
  93. __initcall(register_powersave_nap_sysctl);
  94. #endif