[PATCH] useless includes of linux/irq.h in arch/i386
[linux-2.6/kmemtrace.git] / arch / i386 / mach-voyager / voyager_thread.c
blob2b03884fdb2a968a904ca08f29c9f8c017e22788
1 /* -*- mode: c; c-basic-offset: 8 -*- */
3 /* Copyright (C) 2001
5 * Author: J.E.J.Bottomley@HansenPartnership.com
7 * linux/arch/i386/kernel/voyager_thread.c
9 * This module provides the machine status monitor thread for the
10 * voyager architecture. This allows us to monitor the machine
11 * environment (temp, voltage, fan function) and the front panel and
12 * internal UPS. If a fault is detected, this thread takes corrective
13 * action (usually just informing init)
14 * */
16 #include <linux/module.h>
17 #include <linux/config.h>
18 #include <linux/mm.h>
19 #include <linux/kernel_stat.h>
20 #include <linux/delay.h>
21 #include <linux/mc146818rtc.h>
22 #include <linux/smp_lock.h>
23 #include <linux/init.h>
24 #include <linux/bootmem.h>
25 #include <linux/kmod.h>
26 #include <linux/completion.h>
27 #include <linux/sched.h>
28 #include <asm/desc.h>
29 #include <asm/voyager.h>
30 #include <asm/vic.h>
31 #include <asm/mtrr.h>
32 #include <asm/msr.h>
34 #define THREAD_NAME "kvoyagerd"
36 /* external variables */
37 int kvoyagerd_running = 0;
38 DECLARE_MUTEX_LOCKED(kvoyagerd_sem);
40 static int thread(void *);
42 static __u8 set_timeout = 0;
44 /* Start the machine monitor thread. Return 1 if OK, 0 if fail */
45 static int __init
46 voyager_thread_start(void)
48 if(kernel_thread(thread, NULL, CLONE_KERNEL) < 0) {
49 /* This is serious, but not fatal */
50 printk(KERN_ERR "Voyager: Failed to create system monitor thread!!!\n");
51 return 1;
53 return 0;
56 static int
57 execute(const char *string)
59 int ret;
61 char *envp[] = {
62 "HOME=/",
63 "TERM=linux",
64 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
65 NULL,
67 char *argv[] = {
68 "/bin/bash",
69 "-c",
70 (char *)string,
71 NULL,
74 if ((ret = call_usermodehelper(argv[0], argv, envp, 1)) != 0) {
75 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n",
76 string, ret);
78 return ret;
81 static void
82 check_from_kernel(void)
84 if(voyager_status.switch_off) {
86 /* FIXME: This should be configureable via proc */
87 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
88 } else if(voyager_status.power_fail) {
89 VDEBUG(("Voyager daemon detected AC power failure\n"));
91 /* FIXME: This should be configureable via proc */
92 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
93 set_timeout = 1;
97 static void
98 check_continuing_condition(void)
100 if(voyager_status.power_fail) {
101 __u8 data;
102 voyager_cat_psi(VOYAGER_PSI_SUBREAD,
103 VOYAGER_PSI_AC_FAIL_REG, &data);
104 if((data & 0x1f) == 0) {
105 /* all power restored */
106 printk(KERN_NOTICE "VOYAGER AC power restored, cancelling shutdown\n");
107 /* FIXME: should be user configureable */
108 execute("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
109 set_timeout = 0;
114 static void
115 wakeup(unsigned long unused)
117 up(&kvoyagerd_sem);
120 static int
121 thread(void *unused)
123 struct timer_list wakeup_timer;
125 kvoyagerd_running = 1;
127 daemonize(THREAD_NAME);
129 set_timeout = 0;
131 init_timer(&wakeup_timer);
133 sigfillset(&current->blocked);
134 current->signal->tty = NULL;
136 printk(KERN_NOTICE "Voyager starting monitor thread\n");
138 for(;;) {
139 down_interruptible(&kvoyagerd_sem);
140 VDEBUG(("Voyager Daemon awoken\n"));
141 if(voyager_status.request_from_kernel == 0) {
142 /* probably awoken from timeout */
143 check_continuing_condition();
144 } else {
145 check_from_kernel();
146 voyager_status.request_from_kernel = 0;
148 if(set_timeout) {
149 del_timer(&wakeup_timer);
150 wakeup_timer.expires = HZ + jiffies;
151 wakeup_timer.function = wakeup;
152 add_timer(&wakeup_timer);
157 static void __exit
158 voyager_thread_stop(void)
160 /* FIXME: do nothing at the moment */
163 module_init(voyager_thread_start);
164 //module_exit(voyager_thread_stop);