mm: drop unneeded pgdat argument from free_area_init_node()
[deliverable/linux.git] / arch / x86 / mach-voyager / voyager_thread.c
CommitLineData
1da177e4
LT
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/* Copyright (C) 2001
4 *
5 * Author: J.E.J.Bottomley@HansenPartnership.com
6 *
1da177e4
LT
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)
12 * */
13
14#include <linux/module.h>
1da177e4
LT
15#include <linux/mm.h>
16#include <linux/kernel_stat.h>
17#include <linux/delay.h>
18#include <linux/mc146818rtc.h>
1da177e4
LT
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>
f3402a4e 24#include <linux/kthread.h>
1da177e4
LT
25#include <asm/desc.h>
26#include <asm/voyager.h>
27#include <asm/vic.h>
28#include <asm/mtrr.h>
29#include <asm/msr.h>
30
f3402a4e
CH
31struct task_struct *voyager_thread;
32static __u8 set_timeout;
1da177e4 33
a4ec1eff 34static int execute(const char *string)
1da177e4
LT
35{
36 int ret;
37
38 char *envp[] = {
39 "HOME=/",
40 "TERM=linux",
41 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
42 NULL,
43 };
44 char *argv[] = {
45 "/bin/bash",
46 "-c",
47 (char *)string,
48 NULL,
49 };
50
a4ec1eff
IM
51 if ((ret =
52 call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC)) != 0) {
53 printk(KERN_ERR "Voyager failed to run \"%s\": %i\n", string,
54 ret);
1da177e4
LT
55 }
56 return ret;
57}
58
a4ec1eff 59static void check_from_kernel(void)
1da177e4 60{
a4ec1eff
IM
61 if (voyager_status.switch_off) {
62
27b46d76 63 /* FIXME: This should be configurable via proc */
1da177e4 64 execute("umask 600; echo 0 > /etc/initrunlvl; kill -HUP 1");
a4ec1eff 65 } else if (voyager_status.power_fail) {
1da177e4 66 VDEBUG(("Voyager daemon detected AC power failure\n"));
a4ec1eff 67
1da177e4
LT
68 /* FIXME: This should be configureable via proc */
69 execute("umask 600; echo F > /etc/powerstatus; kill -PWR 1");
70 set_timeout = 1;
71 }
72}
73
a4ec1eff 74static void check_continuing_condition(void)
1da177e4 75{
a4ec1eff 76 if (voyager_status.power_fail) {
1da177e4 77 __u8 data;
a4ec1eff 78 voyager_cat_psi(VOYAGER_PSI_SUBREAD,
1da177e4 79 VOYAGER_PSI_AC_FAIL_REG, &data);
a4ec1eff 80 if ((data & 0x1f) == 0) {
1da177e4 81 /* all power restored */
a4ec1eff
IM
82 printk(KERN_NOTICE
83 "VOYAGER AC power restored, cancelling shutdown\n");
1da177e4 84 /* FIXME: should be user configureable */
a4ec1eff
IM
85 execute
86 ("umask 600; echo O > /etc/powerstatus; kill -PWR 1");
1da177e4
LT
87 set_timeout = 0;
88 }
89 }
90}
91
a4ec1eff 92static int thread(void *unused)
1da177e4 93{
1da177e4
LT
94 printk(KERN_NOTICE "Voyager starting monitor thread\n");
95
f3402a4e
CH
96 for (;;) {
97 set_current_state(TASK_INTERRUPTIBLE);
98 schedule_timeout(set_timeout ? HZ : MAX_SCHEDULE_TIMEOUT);
99
1da177e4 100 VDEBUG(("Voyager Daemon awoken\n"));
a4ec1eff 101 if (voyager_status.request_from_kernel == 0) {
1da177e4
LT
102 /* probably awoken from timeout */
103 check_continuing_condition();
104 } else {
105 check_from_kernel();
106 voyager_status.request_from_kernel = 0;
107 }
1da177e4
LT
108 }
109}
110
a4ec1eff 111static int __init voyager_thread_start(void)
f3402a4e
CH
112{
113 voyager_thread = kthread_run(thread, NULL, "kvoyagerd");
114 if (IS_ERR(voyager_thread)) {
a4ec1eff
IM
115 printk(KERN_ERR
116 "Voyager: Failed to create system monitor thread.\n");
f3402a4e
CH
117 return PTR_ERR(voyager_thread);
118 }
119 return 0;
120}
121
a4ec1eff 122static void __exit voyager_thread_stop(void)
1da177e4 123{
f3402a4e 124 kthread_stop(voyager_thread);
1da177e4
LT
125}
126
127module_init(voyager_thread_start);
f3402a4e 128module_exit(voyager_thread_stop);
This page took 0.331513 seconds and 5 git commands to generate.