1/*
2 * BK Id: %F% %I% %G% %U% %#%
3 */
4/*
5 * Idle daemon for PowerPC.  Idle daemon will handle any action
6 * that needs to be taken when the system becomes idle.
7 *
8 * Written by Cort Dougan (cort@cs.nmt.edu)
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15#include <linux/config.h>
16#include <linux/errno.h>
17#include <linux/sched.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/smp.h>
21#include <linux/smp_lock.h>
22#include <linux/stddef.h>
23#include <linux/unistd.h>
24#include <linux/ptrace.h>
25#include <linux/slab.h>
26
27#include <asm/pgtable.h>
28#include <asm/uaccess.h>
29#include <asm/system.h>
30#include <asm/io.h>
31#include <asm/processor.h>
32#include <asm/mmu.h>
33#include <asm/cache.h>
34#include <asm/cputable.h>
35
36unsigned long zero_paged_on;
37unsigned long powersave_nap;
38unsigned long powersave_lowspeed;
39
40#ifdef CONFIG_6xx
41extern void power_save_6xx(void);
42#endif
43
44int idled(void)
45{
46	int do_power_save = 0;
47
48	/* Check if CPU can powersave (get rid of that soon!) */
49	if (cur_cpu_spec[smp_processor_id()]->cpu_features &
50		(CPU_FTR_CAN_DOZE | CPU_FTR_CAN_NAP))
51		do_power_save = 1;
52
53	/* endless loop with no priority at all */
54	current->nice = 20;
55	current->counter = -100;
56	init_idle();
57	for (;;) {
58#ifdef CONFIG_SMP
59		if (!do_power_save) {
60			/*
61			 * Deal with another CPU just having chosen a thread to
62			 * run here:
63			 */
64			int oldval = xchg(&current->need_resched, -1);
65
66			if (!oldval) {
67				while(current->need_resched == -1)
68					; /* Do Nothing */
69			}
70		}
71#endif
72#ifdef CONFIG_6xx
73		if (do_power_save && !current->need_resched)
74			power_save_6xx();
75#endif /* CONFIG_6xx */
76
77		if (current->need_resched) {
78			schedule();
79			check_pgt_cache();
80		}
81	}
82	return 0;
83}
84
85/*
86 * SMP entry into the idle task - calls the same thing as the
87 * non-smp versions. -- Cort
88 */
89int cpu_idle(void)
90{
91	idled();
92	return 0;
93}
94