1 /* -*- mode: c; c-basic-offset: 8 -*- */
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)
16 #include <linux/module.h>
17 #include <linux/config.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>
29 #include <asm/voyager.h>
34 #include <linux/irq.h>
36 #define THREAD_NAME "kvoyagerd"
38 /* external variables */
39 int kvoyagerd_running = 0;
40 DECLARE_MUTEX_LOCKED(kvoyagerd_sem);
42 static int thread(void *);
44 static __u8 set_timeout = 0;
46 /* Start the machine monitor thread. Return 1 if OK, 0 if fail */
48 voyager_thread_start(void)
50 if(kernel_thread(thread, NULL, CLONE_KERNEL) < 0) {
51 /* This is serious, but not fatal */
52 printk(KERN_ERR "Voyager: Failed to create system monitor thread!!!\n");
59 execute(const char *string)
66 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
76 if ((ret = call_usermodehelper(argv[0], argv, envp, 1)) != 0) {
77 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n",
84 check_from_kernel(void)
86 if(voyager_status.switch_off) {
88 /* FIXME: This should be configureable via proc */
89 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
90 } else if(voyager_status.power_fail) {
91 VDEBUG(("Voyager daemon detected AC power failure\n"));
93 /* FIXME: This should be configureable via proc */
94 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
100 check_continuing_condition(void)
102 if(voyager_status.power_fail) {
104 voyager_cat_psi(VOYAGER_PSI_SUBREAD,
105 VOYAGER_PSI_AC_FAIL_REG, &data);
106 if((data & 0x1f) == 0) {
107 /* all power restored */
108 printk(KERN_NOTICE "VOYAGER AC power restored, cancelling shutdown\n");
109 /* FIXME: should be user configureable */
110 execute("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
117 wakeup(unsigned long unused)
125 struct timer_list wakeup_timer;
127 kvoyagerd_running = 1;
129 daemonize(THREAD_NAME);
133 init_timer(&wakeup_timer);
135 sigfillset(¤t->blocked);
136 current->signal->tty = NULL;
138 printk(KERN_NOTICE "Voyager starting monitor thread\n");
141 down_interruptible(&kvoyagerd_sem);
142 VDEBUG(("Voyager Daemon awoken\n"));
143 if(voyager_status.request_from_kernel == 0) {
144 /* probably awoken from timeout */
145 check_continuing_condition();
148 voyager_status.request_from_kernel = 0;
151 del_timer(&wakeup_timer);
152 wakeup_timer.expires = HZ + jiffies;
153 wakeup_timer.function = wakeup;
154 add_timer(&wakeup_timer);
160 voyager_thread_stop(void)
162 /* FIXME: do nothing at the moment */
165 module_init(voyager_thread_start);
166 //module_exit(voyager_thread_stop);