OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [char/] [softdog.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *      SoftDog 0.04:   A Software Watchdog Device
3
 *
4
 *      (c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
5
 *
6
 *      Email us for quotes on Linux software and driver development.
7
 *
8
 *                      -----------------------
9
 *
10
 *      This program is free software; you can redistribute it and/or
11
 *      modify it under the terms of the GNU General Public License
12
 *      as published by the Free Software Foundation; either version
13
 *      2 of the License, or (at your option) any later version.
14
 *
15
 *                      -----------------------
16
 *
17
 *      Software only watchdog driver. Unlike its big brother the WDT501P
18
 *      driver this won't always recover a failed machine.
19
 *
20
 *  03/96: Angelo Haritsis <ah@doc.ic.ac.uk> :
21
 *      Modularised.
22
 *      Added soft_margin; use upon insmod to change the timer delay.
23
 *      NB: uses same minor as wdt (WATCHDOG_MINOR); we could use separate
24
 *          minors.
25
 */
26
 
27
#include <linux/module.h>
28
#include <linux/config.h>
29
#include <linux/types.h>
30
#include <linux/kernel.h>
31
#include <linux/fs.h>
32
#include <linux/mm.h>
33
#include <linux/miscdevice.h>
34
 
35
#define WATCHDOG_MINOR  130
36
#define TIMER_MARGIN    60              /* (secs) Default is 1 minute */
37
 
38
static int soft_margin = TIMER_MARGIN;  /* in seconds */
39
 
40
/*
41
 *      Our timer
42
 */
43
 
44
struct timer_list watchdog_ticktock;
45
static int timer_alive = 0;
46
 
47
 
48
/*
49
 *      If the timer expires..
50
 */
51
 
52
static void watchdog_fire(unsigned long data)
53
{
54
        extern void hard_reset_now(void);
55
#ifdef ONLY_TESTING
56
                printk(KERN_CRIT "SOFTDOG: Would Reboot.\n");
57
#else
58
        printk(KERN_CRIT "SOFTDOG: Initiating system reboot.\n");
59
        hard_reset_now();
60
        printk("WATCHDOG: Reboot didn't ?????\n");
61
#endif
62
}
63
 
64
/*
65
 *      Allow only one person to hold it open
66
 */
67
 
68
static int softdog_open(struct inode *inode, struct file *file)
69
{
70
        if(timer_alive)
71
                return -EBUSY;
72
        MOD_INC_USE_COUNT;
73
        /*
74
         *      Activate timer
75
         */
76
        del_timer(&watchdog_ticktock);
77
        watchdog_ticktock.expires=jiffies + (soft_margin * HZ);
78
        add_timer(&watchdog_ticktock);
79
        timer_alive++;
80
        return 0;
81
}
82
 
83
static void softdog_release(struct inode *inode, struct file *file)
84
{
85
        /*
86
         *      Shut off the timer.
87
         *      Lock it in if it's a module and we defined ...NOWAYOUT
88
         */
89
#ifndef CONFIG_WATCHDOG_NOWAYOUT         
90
        del_timer(&watchdog_ticktock);
91
        MOD_DEC_USE_COUNT;
92
        timer_alive=0;
93
#endif  
94
}
95
 
96
static int softdog_write(struct inode *inode, struct file *file, const char *data, int len)
97
{
98
        /*
99
         *      Refresh the timer.
100
         */
101
        del_timer(&watchdog_ticktock);
102
        watchdog_ticktock.expires=jiffies + (soft_margin * HZ);
103
        add_timer(&watchdog_ticktock);
104
        return 1;
105
}
106
 
107
static struct file_operations softdog_fops=
108
{
109
        NULL,           /* Seek */
110
        NULL,           /* Read */
111
        softdog_write,  /* Write */
112
        NULL,           /* Readdir */
113
        NULL,           /* Select */
114
        NULL,           /* Ioctl */
115
        NULL,           /* MMap */
116
        softdog_open,
117
        softdog_release,
118
        NULL,
119
        NULL            /* Fasync */
120
};
121
 
122
static struct miscdevice softdog_miscdev=
123
{
124
        WATCHDOG_MINOR,
125
        "softdog",
126
        &softdog_fops
127
};
128
 
129
void watchdog_init(void)
130
{
131
        misc_register(&softdog_miscdev);
132
        init_timer(&watchdog_ticktock);
133
        watchdog_ticktock.function=watchdog_fire;
134
        printk("Software Watchdog Timer: 0.04, timer margin: %d sec\n", soft_margin);
135
}
136
 
137
#ifdef MODULE
138
int init_module(void)
139
{
140
        watchdog_init();
141
        return 0;
142
}
143
 
144
void cleanup_module(void)
145
{
146
        misc_deregister(&softdog_miscdev);
147
}
148
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.