1 /* -*- mode: c; c-basic-offset: 8 -*- */
5 * Author: J.E.J.Bottomley@HansenPartnership.com
7 * This module provides the machine status monitor thread for the
8 * voyager architecture. This allows us to monitor the machine
9 * environment (temp, voltage, fan function) and the front panel and
10 * internal UPS. If a fault is detected, this thread takes corrective
11 * action (usually just informing init)
14 #include <linux/module.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/delay.h>
18 #include <linux/mc146818rtc.h>
19 #include <linux/init.h>
20 #include <linux/bootmem.h>
21 #include <linux/kmod.h>
22 #include <linux/completion.h>
23 #include <linux/sched.h>
24 #include <linux/kthread.h>
26 #include <asm/voyager.h>
31 struct task_struct *voyager_thread;
32 static __u8 set_timeout;
34 static int execute(const char *string)
41 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
52 call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC)) != 0) {
53 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n", string,
59 static void check_from_kernel(void)
61 if (voyager_status.switch_off) {
63 /* FIXME: This should be configurable via proc */
64 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
65 } else if (voyager_status.power_fail) {
66 VDEBUG(("Voyager daemon detected AC power failure\n"));
68 /* FIXME: This should be configureable via proc */
69 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
74 static void check_continuing_condition(void)
76 if (voyager_status.power_fail) {
78 voyager_cat_psi(VOYAGER_PSI_SUBREAD,
79 VOYAGER_PSI_AC_FAIL_REG, &data);
80 if ((data & 0x1f) == 0) {
81 /* all power restored */
83 "VOYAGER AC power restored, cancelling shutdown\n");
84 /* FIXME: should be user configureable */
86 ("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
92 static int thread(void *unused)
94 printk(KERN_NOTICE "Voyager starting monitor thread\n");
97 set_current_state(TASK_INTERRUPTIBLE);
98 schedule_timeout(set_timeout ? HZ : MAX_SCHEDULE_TIMEOUT);
100 VDEBUG(("Voyager Daemon awoken\n"));
101 if (voyager_status.request_from_kernel == 0) {
102 /* probably awoken from timeout */
103 check_continuing_condition();
106 voyager_status.request_from_kernel = 0;
111 static int __init voyager_thread_start(void)
113 voyager_thread = kthread_run(thread, NULL, "kvoyagerd");
114 if (IS_ERR(voyager_thread)) {
116 "Voyager: Failed to create system monitor thread.\n");
117 return PTR_ERR(voyager_thread);
122 static void __exit voyager_thread_stop(void)
124 kthread_stop(voyager_thread);
127 module_init(voyager_thread_start);
128 module_exit(voyager_thread_stop);