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>
18 #include <linux/kernel_stat.h>
19 #include <linux/delay.h>
20 #include <linux/mc146818rtc.h>
21 #include <linux/smp_lock.h>
22 #include <linux/init.h>
23 #include <linux/bootmem.h>
24 #include <linux/kmod.h>
25 #include <linux/completion.h>
26 #include <linux/sched.h>
28 #include <asm/voyager.h>
33 #define THREAD_NAME "kvoyagerd"
35 /* external variables */
36 int kvoyagerd_running = 0;
37 DECLARE_MUTEX_LOCKED(kvoyagerd_sem);
39 static int thread(void *);
41 static __u8 set_timeout = 0;
43 /* Start the machine monitor thread. Return 1 if OK, 0 if fail */
45 voyager_thread_start(void)
47 if(kernel_thread(thread, NULL, CLONE_KERNEL) < 0) {
48 /* This is serious, but not fatal */
49 printk(KERN_ERR "Voyager: Failed to create system monitor thread!!!\n");
56 execute(const char *string)
63 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
73 if ((ret = call_usermodehelper(argv[0], argv, envp, 1)) != 0) {
74 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n",
81 check_from_kernel(void)
83 if(voyager_status.switch_off) {
85 /* FIXME: This should be configureable via proc */
86 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
87 } else if(voyager_status.power_fail) {
88 VDEBUG(("Voyager daemon detected AC power failure\n"));
90 /* FIXME: This should be configureable via proc */
91 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
97 check_continuing_condition(void)
99 if(voyager_status.power_fail) {
101 voyager_cat_psi(VOYAGER_PSI_SUBREAD,
102 VOYAGER_PSI_AC_FAIL_REG, &data);
103 if((data & 0x1f) == 0) {
104 /* all power restored */
105 printk(KERN_NOTICE "VOYAGER AC power restored, cancelling shutdown\n");
106 /* FIXME: should be user configureable */
107 execute("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
114 wakeup(unsigned long unused)
122 struct timer_list wakeup_timer;
124 kvoyagerd_running = 1;
126 daemonize(THREAD_NAME);
130 init_timer(&wakeup_timer);
132 sigfillset(¤t->blocked);
134 printk(KERN_NOTICE "Voyager starting monitor thread\n");
137 down_interruptible(&kvoyagerd_sem);
138 VDEBUG(("Voyager Daemon awoken\n"));
139 if(voyager_status.request_from_kernel == 0) {
140 /* probably awoken from timeout */
141 check_continuing_condition();
144 voyager_status.request_from_kernel = 0;
147 del_timer(&wakeup_timer);
148 wakeup_timer.expires = HZ + jiffies;
149 wakeup_timer.function = wakeup;
150 add_timer(&wakeup_timer);
156 voyager_thread_stop(void)
158 /* FIXME: do nothing at the moment */
161 module_init(voyager_thread_start);
162 //module_exit(voyager_thread_stop);