[CRYPTO] api: Remove deprecated interface
[pv_ops_mirror.git] / arch / i386 / mach-voyager / voyager_thread.c
blobf39887359e8e86ea8758dc3d2c686a283a9c8590
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/mm.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>
27 #include <asm/desc.h>
28 #include <asm/voyager.h>
29 #include <asm/vic.h>
30 #include <asm/mtrr.h>
31 #include <asm/msr.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 */
44 static int __init
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");
50 return 1;
52 return 0;
55 static int
56 execute(const char *string)
58 int ret;
60 char *envp[] = {
61 "HOME=/",
62 "TERM=linux",
63 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
64 NULL,
66 char *argv[] = {
67 "/bin/bash",
68 "-c",
69 (char *)string,
70 NULL,
73 if ((ret = call_usermodehelper(argv[0], argv, envp, 1)) != 0) {
74 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n",
75 string, ret);
77 return ret;
80 static void
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");
92 set_timeout = 1;
96 static void
97 check_continuing_condition(void)
99 if(voyager_status.power_fail) {
100 __u8 data;
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");
108 set_timeout = 0;
113 static void
114 wakeup(unsigned long unused)
116 up(&kvoyagerd_sem);
119 static int
120 thread(void *unused)
122 struct timer_list wakeup_timer;
124 kvoyagerd_running = 1;
126 daemonize(THREAD_NAME);
128 set_timeout = 0;
130 init_timer(&wakeup_timer);
132 sigfillset(&current->blocked);
134 printk(KERN_NOTICE "Voyager starting monitor thread\n");
136 for(;;) {
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();
142 } else {
143 check_from_kernel();
144 voyager_status.request_from_kernel = 0;
146 if(set_timeout) {
147 del_timer(&wakeup_timer);
148 wakeup_timer.expires = HZ + jiffies;
149 wakeup_timer.function = wakeup;
150 add_timer(&wakeup_timer);
155 static void __exit
156 voyager_thread_stop(void)
158 /* FIXME: do nothing at the moment */
161 module_init(voyager_thread_start);
162 //module_exit(voyager_thread_stop);