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/init.h>
22 #include <linux/bootmem.h>
23 #include <linux/kmod.h>
24 #include <linux/completion.h>
25 #include <linux/sched.h>
26 #include <linux/kthread.h>
28 #include <asm/voyager.h>
33 struct task_struct
*voyager_thread
;
34 static __u8 set_timeout
;
36 static int execute(const char *string
)
43 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
54 call_usermodehelper(argv
[0], argv
, envp
, UMH_WAIT_PROC
)) != 0) {
55 printk(KERN_ERR
"Voyager failed to run \"%s\": %i\n", string
,
61 static void check_from_kernel(void)
63 if (voyager_status
.switch_off
) {
65 /* FIXME: This should be configurable via proc */
66 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
67 } else if (voyager_status
.power_fail
) {
68 VDEBUG(("Voyager daemon detected AC power failure\n"));
70 /* FIXME: This should be configureable via proc */
71 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
76 static void check_continuing_condition(void)
78 if (voyager_status
.power_fail
) {
80 voyager_cat_psi(VOYAGER_PSI_SUBREAD
,
81 VOYAGER_PSI_AC_FAIL_REG
, &data
);
82 if ((data
& 0x1f) == 0) {
83 /* all power restored */
85 "VOYAGER AC power restored, cancelling shutdown\n");
86 /* FIXME: should be user configureable */
88 ("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
94 static int thread(void *unused
)
96 printk(KERN_NOTICE
"Voyager starting monitor thread\n");
99 set_current_state(TASK_INTERRUPTIBLE
);
100 schedule_timeout(set_timeout
? HZ
: MAX_SCHEDULE_TIMEOUT
);
102 VDEBUG(("Voyager Daemon awoken\n"));
103 if (voyager_status
.request_from_kernel
== 0) {
104 /* probably awoken from timeout */
105 check_continuing_condition();
108 voyager_status
.request_from_kernel
= 0;
113 static int __init
voyager_thread_start(void)
115 voyager_thread
= kthread_run(thread
, NULL
, "kvoyagerd");
116 if (IS_ERR(voyager_thread
)) {
118 "Voyager: Failed to create system monitor thread.\n");
119 return PTR_ERR(voyager_thread
);
124 static void __exit
voyager_thread_stop(void)
126 kthread_stop(voyager_thread
);
129 module_init(voyager_thread_start
);
130 module_exit(voyager_thread_stop
);