root/drivers/char/softdog.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. watchdog_fire
  2. softdog_open
  3. softdog_release
  4. softdog_write
  5. watchdog_init

   1 /*
   2  *      SoftDog 0.02:   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  
  21  
  22 #include <linux/types.h>
  23 #include <linux/kernel.h>
  24 #include <linux/fs.h>
  25 #include <linux/mm.h>
  26 #include <linux/mouse.h>
  27 #define WATCHDOG_MINOR  130
  28 #define TIMER_MARGIN    (60*HZ)         /* Allow 1 minute */
  29 
  30 /*
  31  *      Our timer
  32  */
  33  
  34 struct timer_list watchdog_ticktock;
  35 static int timer_alive = 0;
  36 
  37 
  38 /*
  39  *      If the timer expires..
  40  */
  41  
  42 static void watchdog_fire(long data)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44         extern void hard_reset_now(void);
  45         hard_reset_now();
  46         printk("WATCHDOG: Reboot didn't ?????\n");
  47 }
  48 
  49 /*
  50  *      Allow only one person to hold it open
  51  */
  52  
  53 static int softdog_open(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         if(timer_alive)
  56                 return -EBUSY;
  57         /*
  58          *      Activate timer
  59          */
  60         watchdog_ticktock.expires=jiffies+TIMER_MARGIN;
  61         add_timer(&watchdog_ticktock);
  62         return 0;
  63 }
  64 
  65 static void softdog_release(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         /*
  68          *      Shut off the timer.
  69          */
  70         del_timer(&watchdog_ticktock);
  71         timer_alive=0;
  72 }
  73 
  74 static int softdog_write(struct inode *inode, struct file *file, const char *data, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         /*
  77          *      Refresh the timer.
  78          */
  79         del_timer(&watchdog_ticktock);
  80         watchdog_ticktock.expires=jiffies+TIMER_MARGIN;
  81         add_timer(&watchdog_ticktock);
  82         return 1;
  83 }
  84 
  85 /*
  86  *      The mouse stuff ought to be renamed misc_register etc before 1.4...
  87  */
  88  
  89 void watchdog_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91         static struct file_operations softdog_fops=
  92         {
  93                 NULL,           /* Seek */
  94                 NULL,           /* Read */
  95                 softdog_write,  /* Write */
  96                 NULL,           /* Readdir */
  97                 NULL,           /* Select */
  98                 NULL,           /* Ioctl */
  99                 NULL,           /* MMap */
 100                 softdog_open,
 101                 softdog_release,
 102                 NULL,           
 103                 NULL            /* Fasync */
 104         };
 105         static struct mouse softdog_mouse={
 106                 WATCHDOG_MINOR,
 107                 "softdog",
 108                 &softdog_fops
 109         };
 110 
 111         mouse_register(&softdog_mouse);
 112         init_timer(&watchdog_ticktock);
 113         watchdog_ticktock.function=watchdog_fire;
 114         printk("Software Watchdog Timer: 0.02\n");
 115 }       

/* [previous][next][first][last][top][bottom][index][help] */