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(unsigned 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         timer_alive++;
  63         return 0;
  64 }
  65 
  66 static void softdog_release(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68         /*
  69          *      Shut off the timer.
  70          */
  71         del_timer(&watchdog_ticktock);
  72         timer_alive=0;
  73 }
  74 
  75 static int softdog_write(struct inode *inode, struct file *file, const char *data, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77         /*
  78          *      Refresh the timer.
  79          */
  80         del_timer(&watchdog_ticktock);
  81         watchdog_ticktock.expires=jiffies+TIMER_MARGIN;
  82         add_timer(&watchdog_ticktock);
  83         return 1;
  84 }
  85 
  86 /*
  87  *      The mouse stuff ought to be renamed misc_register etc before 1.4...
  88  */
  89  
  90 void watchdog_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92         static struct file_operations softdog_fops=
  93         {
  94                 NULL,           /* Seek */
  95                 NULL,           /* Read */
  96                 softdog_write,  /* Write */
  97                 NULL,           /* Readdir */
  98                 NULL,           /* Select */
  99                 NULL,           /* Ioctl */
 100                 NULL,           /* MMap */
 101                 softdog_open,
 102                 softdog_release,
 103                 NULL,           
 104                 NULL            /* Fasync */
 105         };
 106         static struct mouse softdog_mouse={
 107                 WATCHDOG_MINOR,
 108                 "softdog",
 109                 &softdog_fops
 110         };
 111 
 112         mouse_register(&softdog_mouse);
 113         init_timer(&watchdog_ticktock);
 114         watchdog_ticktock.function=watchdog_fire;
 115         printk("Software Watchdog Timer: 0.03\n");
 116 }       

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