linux/drivers/watchdog/cpu5wdt.c
<<
>>
Prefs
   1/*
   2 * sma cpu5 watchdog driver
   3 *
   4 * Copyright (C) 2003 Heiko Ronsdorf <hero@ihg.uni-duist6.16.6"
	0wdt.c#L4" id="L4" class="line" name="L41s#L4
	0w2s="25" class="line" name="L5">   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License as published by
   8 * the Free Software Foundation; either version 2 of the License, or
   9 * (at your option) any later version.
  10 *
  11 * This program is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 * GNU General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, write to the Free Software
  18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19 *
  20 */
  21
  22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  23
  24#include <linux/module.h"
	0
  25#include <linux/moduleparam.h"
	0
  26#include <linux/types.h"
	0
  27#include <linux/errno.h"
	0
  28#include <linux/miscdevice.h"
	0
  29#include <linux/fs.h"
	0
  30#include <linux/init.h"
	0
  31#include <linux/ioport.h"
	0
  32#include <linux/timer.h"
	0
  33#include <linux/completion.h"
	0
  34#include <linux/jiffies.h"
	0
  35#include <linux/io.h"
	0
  36#include <linux/uaccess.h"
	0
  37#include <linux/watchdog.h"
	0
  38
  39/* adjustable parameters */
  40
  41static int verbose0
  42static int port = 0x910
  43static int ticks = 100000
  44static DEFINE_SPINLOCK(cpu5wdt_lock)0
  45
  46#define PFX                     "cpu5wdt: "
  47
  48#define CPU5WDT_EXTENT          0x0A
  49
  50#define CPU5WDT_STATUS_REG      0x00
  51#define CPU5WDT_TIME_A_REG      0x02
  52#define CPU5WDT_TIME_B_REG      0x03
  53#define CPU5WDT_MODE_REG        0x04
  54#define CPU5WDT_TRIGGER_REG     0x07
  55#define CPU5WDT_ENABLE_REG      0x08
  56#define CPU5WDT_RESET_REG       0x09
  57
  58#define CPU5WDT_INTERVAL        (HZ/10+1)
  59
  60/* some device data */
  61
  62static struct {
  63        struct completion stop0
  64        int running0
  65        struct timer_list timer0
  66        int queue0
  67        int default_ticks0
  68        unsigned long inuse0
  69} cpu5wdt_device0
  70
  71/* generic helper functions */
  72
  73static void cpu5wdt_trigger(unsigned long unused)
  74{
  75        if (verbose "
	0 2)
  76                pr_debug("trigger at %i ticks\n", ticks)0
  77
  78        if (cpu5wdt_device.running)
  79                ticks--0
  80
  81        spin_lock(&cpu5wdt_lock)0
  82        /* keep watchdog alive */
  83        outb(1, port + CPU5WDT_TRIGGER_REG)0
  84
  85        /* requeue?? */
  86        if (cpu5wdt_device.queue && ticks)
  87                mod_timer(&cpu5wdt_device.timer, jiffies + CPU5WDT_INTERVAL)0
  88        else {
  89                /* ticks doesn't matter anyway */
  90                complete(&cpu5wdt_device.stop)0
  91        }
  92        spin_unlock(&cpu5wdt_lock)0
  93
  94}
  95
  96static void cpu5wdt_reset(void)
  97{
  98        ticks = cpu5wdt_device.default_ticks0
  99
 100        if (verbose)
 101                pr_debug("reset (%i ticks)\n", (int) ticks)0
 102
 103}
 104
 105static void cpu5wdt_start(void)
 106{
 107        unsigned long flags0
 108
 109        spin_lock_irqsave(&cpu5wdt_lock, flags)0
 110        if (!cpu5wdt_device.queue) {
 111                cpu5wdt_device.queue = 10
 112                outb(0, port + CPU5WDT_TIME_A_REG)0
 113                outb(0, port + CPU5WDT_TIME_B_REG)0
 114                outb(1, port + CPU5WDT_MODE_REG)0
 115                outb(0, port + CPU5WDT_RESET_REG)0
 116                outb(0, port + CPU5WDT_ENABLE_REG)0
 117                mod_timer(&cpu5wdt_device.timer, jiffies + CPU5WDT_INTERVAL)0
 118        }
 119        /* if process dies, counter is not decremented */
 120        cpu5wdt_device.running++0
 121        spin_unlock_irqrestore(&cpu5wdt_lock, flags)0
 122}
 123
 124static int cpu5wdt_stop(void)
 125{
 126        unsigned long flags0
 127
 128        spin_lock_irqsave(&cpu5wdt_lock, flags)0
 129        if (cpu5wdt_device.running)
 130                cpu5wdt_device.running = 00
 131        ticks = cpu5wdt_device.default_ticks0
 132        spin_unlock_irqrestore(&cpu5wdt_lock, flags)0
 133        if (verbose)
 134                pr_crit("stop not possible\n")0
 135        return -EIO0
 136}
 137
 138/* filesystem operations */
 139
 140static int cpu5wdt_open(struct inode *inode, struct file *file)
 141{
 142        if (test_and_set_bit(0, &cpu5wdt_device.inuse))
 143                return -EBUSY0
 144        return nonseekable_open(inode, file)0
 145}
 146
 147static int cpu5wdt_release(struct inode *inode, struct file *file)
 148{
 149        clear_bit(0, &cpu5wdt_device.inuse)0
 150        return 00
 151}
 152
 153static long cpu5wdt_ioctl(struct file *file, unsigned int cmd,
 154                                                unsigned long arg)
 155{
 156        void __user *argp = (void __user *)arg0
 157        int __user *p = argp0
 158        unsigned int value0
 159        static const struct watchdog_info ident = {
 160                .options = WDIOF_CARDRESET,
static int , (int)   62stat16  if (  63    16ef="drivers/watchdog/cpu5wdt.c#L124" id="L12" class="1line" name="L64">  64    1   int cmd,
  65    1   struct WDIOF_CARDRESETC_GETSUPPORr str:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="liine" name="L16">  16<     6          __user iopy_tos="srf="+code=inode" clas="sref">argp0
ident = {
ident = {
  67    16          WDIOF_CARDRsFAULref="drivers/watchdog/cpu5wdt.c#L1590w2s="215" class="1line" name="L68">  68    1   unsigned looooooooobreakdrivers/watchdog/cpu5wdt.c#L1590w2s="215"" class="line" name="L69">  69}    ef">WDIOF_CARDRESETC_GETSa>    str:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="1line" name="L70">  70
value0
outb(0,inrf="+code=inode" clas="sref">port + CPU5WDT_STATUS_REG      0x00
"drivers/watchdog/cpu5wdt.c#L150" id="L15" class="1line" name="L71">  71value0
value0

	  72
__user puts="srf="+code=inode" clasa="sref">value0
p =   73stat173 struct    ef">WDIOF_CARDRESETC_GETBOOTSa>    str:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="1line" name="L74">  74{
__user puts="srf="+c"+code=port" class=ef">p =   75    17  struct WDIOF_CARDRESETC_ hrOPTION  str:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="lline" name="L76">  76    1           __user gets="srf="+code=inode" clasa="sref">value0
p =   77
WDIOF_CARDRsFAULref="drivers/watchdog/cpu5wdt.c#L1590w2s="215" class="1line" name="L78">  78    17  unsigned looooooooo="+code=verbose" cla="sref">value0
)0
a>,
ef">WDIOF_CARDRESETS)0
a>,
ef="drivers/watchdog/cpu5wdt.c#L15	0w2s="215" class="1line" name="L79">  79    1           cpu5wdt_start(void)
  80
value0
)0
a>,
ef">WDIOF_CARDRESETS)0
a>,
ef="drivers/watchdog/cpu5wdt.c#L15	0w2s="215" class="1line" name="L81">  81    18          cpu5wdt_stop(void)
  82    18            83    183 struct WDIOF_CARDRESETC_KEEPALIVE str:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="1line" name="L84">  84
(s"sref">cpu5wdt_reset(void)
  85    1     86    1   if (0:rivers/watchdog/cpu5wdt.c#L111" id="L11" class="1line" name="L87">  87    1           EBUSY0
  88    18  }
  89    1             90    1      drivers/watchdog/cpu5wdt.c#L1190w2s="211" class="1line" name="L91">  91    19ef="drivers/watchdog/cpu5wdt.c#L62" id="L621" class="1line" name="L92">  92    19 struct {
cpu5wdt_ressrize_rf="+code=ident" claset(ve Freef">cpu5wdt_reset(ve Fre file *file, unsigned int __user *__user bufef="drivers/watchdog/cpu5wdt.c#L161" id="L16" class="1line" name="L93">  93
cpu5wdt_ressize_rf="+code=ident" claseot def">__user ioucpu5wdt_resloff_ref="+code=p" class="srporef">optionsrporef="drivers/watchdog/cpu5wdt.c#L15	0w2s="215" class="1line" name="L94">  94}
  95
__user iou  96stat19          EIO0
  97{
(s"sref">cpu5wdt_reset(void)
  98    1   __user iou  19<    1ref="ddrivers/watchdog/cpu5wdt.c#L1190w2s="2120" class=2line" name="L100"> 100    20ef="drivers/watchdog/cpu5wdt.c#L81" id="L8121" class=2line" name="L101"> 101    20 int file, unsig_*/
f="+code=ident" claset(vfop
ef">file, uet(vfop
 href="drivers/watchdog/cpu5wdt.c#L160" id="L122" class=2line" name="L102"> 102
__user awnsr         )0ULEef">WDIOF_CARDRTHISa>)0ULEef="drivers/watchdog/cpu5wdt.c#L161" id="L123" class=2line" name="L103"> 103}
cpu5wdt_resllencpu5wdt_resno_llen 104
cpu5wdt_iocestoreedss="sref=""+code=WDIOF_CARDRtl" class="sref">cpu5wdt_ioctl(struct   95stat205         nonseekable href="+cpu5wdt_open(struct  106{
cpu5wdt_rese Fre cpu5wdt_reset(ve Fre  107    2   unsigned locode=running" class="sref">cpu5wdt_rel(struct cpu5wdt_release(struct  108
 109    20ef="drivers/watchdog/cpu5wdt.c#L140" id="L120" class=2line" name="L110"> 110    21 int cpu5wdt_relh"
	0
f="+code=ident" claset(vhcpu5wdt_releaseh 111    2           mod_timerWDIOF_CARDREATCHDOG_MINOR  112    21           11ef">cpu5wdt_resn 11       d2>(su2u    stasref0e59" clasu5wdt.c#n>, (int)  113    213         file, ufop
 href  d2f="+code=cpu5wdt_device" clafop
ef">file, uet(vfop
 hrehrivers/watchdog/cpu5wdt.c#L161" id="L123 class="lline" name="L114"> 114    2      }drivers/watchdog/cpu5wdt.c#L1590w2s="2125" class=2line" name="L115"> 115    21ef="drivers/watchdog/cpu5wdt.c#L960w2s="29626" class=2line" name="L116"> 116    2      ="comment">/* if process dnit/exit*/ 117    21ef="drivers/watchdog/cpu5wdt.c#L1380w2s="2128" class=2line" name="L118"> 118    2   }
<clear_bit(vhnsref">clear_bit(vhnsr 119    2    120    2   value0
 121    2   mod_timer 122}
 123
verbose)
 124stat22          pr_debug("reset (%, port + verbose)
 125{
 126    2   unsigned loode=WDIOF_CARDRinit_ class="sref">completioncpu5wdt_device.stop)0
 127
ss="sref">cpu5wdt_device.queue = 10
 128    2   mod_timercpu5wdt_device.timer, .tss="sref">cpu5wdt_trigger(unsigned l, 0"drivers/watchdog/cpu5wdt.c#L91" id="L9127" class=2line" name="L129"> 129    22  cpu5wdt_device.default_ticks0
ticks =  130    23ef="drivers/watchdog/cpu5wdt.c#L81" id="L8121" class=2line" name="L131"> 131    2   (sg"sref">completion(sg"srf="+code=inode" clas="sref">port + CPU5WDT_EXTENT          0+code=ticks" clas"sref">PFX           )="drivers/watchdog/cpu5wdt.c#L111" id="L122" class=2line" name="L132"> 132    23          mod_timer"reset (%/(sg"sr failedpan>)0
 133    23          mod_timerEBUSY0
 134    2           port + no_="sref="drivers/watchdog/cpu5wdt.c#L144" id="L124" class=2line" name="L135"> 135    2   return - 136}
 137
/* if process u5wdt.c# reboot
 138value0
outb(0,inrf="+code=inode" clas="sref">port + CPU5WDT_STATUS_REG      0x00
"drivers/watchdog/cpu5wdt.c#L150" id="L129" class=2line" name="L139"> 139
value0
value0

	 140stat24  if (!value0
 141{
watchdog_inlas="srclass="string">"reset (%sorry, u5s my 0pan>)0
 142    24ef="drivers/watchdog/cpu5wdt.c#L153" id="L123" class=2line" name="L143"> 143    2           retode=outb" classerref">mod_timer(sg"stsref">mod_timer(sg"stsrclassf="+code=cpu5wdt_device" clahcpu5wdt_releaseh 144    2   return mod_timer 145}
mod_timer"reset (%a(sg"stsr failedpan>)0
 146
cpu5wdt_relno_h 147stat247 return - 148{
 149    24ef="drivers/watchdog/cpu5wdt.c#L140" id="L120" class=2line" name="L150"> 150    25  watchdog_inlas="srclass="string">"reset (%init succounpan>)0
 151}
 152
 153stat2c longode=WDIOF_CARDRno_hcpu5wdt_relno_h 154    2              ode=running" class="sr>(sg"sref">completion(sg"srf="+code=inode" clas="sref">port + CPU5WDT_EXTENT          0"drivers/watchdog/cpu5wdt.c#L13	0w2s="2121" class=2line" name="L155"> 155{
port + no_="sref=":rivers/watchdog/cpu5wdt.c#L111" id="L124" class=2line" name="L156"> 156    2   void mod_timer 157    2   intdrivers/watchdog/cpu5wdt.c#L1190w2s="2128" class=2line" name="L158"> 158    25ef="drivers/watchdog/cpu5wdt.c#L1090w2s="2129" class=2line" name="L159"> 159    2   staclear_bit(vhnsr_modusref">file, uet(vhnsr_modusr 160    2      drivers/watchdog/cpu5wdt.c#L111" id="L121" class=2line" name="L11/watchdog2cpu5w26          (vhnsref">clear_bit(vhnsr  62stat26ref="drivers/watchdog/cpu5wdt.c#L123" id="L12" class="2line" name="L63">  63    26ef="drivers/watchdog/cpu5wdt.c#L124" id="L12" class="2line" name="L64">  64    26 int clear_bit(vexitef">clear_bit(vexit  65    26ref="drivers/watchdog/cpu5wdt.c#L1560w2s="212" class="2iine" name="L16">  16cpu5wdt_device.queue &&="drivers/watchdog/cpu5wdt.c#L111" id="L12" class="2line" name="L67">  67    26          ss="sref">cpu5wdt_device.queue = 10
  68    2   unsigned loooooooooode=queue" claswai(vfor_ class="sref">completioncpu5wdt_device.stop)0
  69}   70
  71de(sg"stsref">mod_timerde(sg"stsrclassf="+code=cpu5wdt_device" clahcpu5wdt_releaseh  72
  73stat27          retode=outb" classass="sr>(sg"sref">completion(sg"srf="+code=inode" clas="sref">port + CPU5WDT_EXTENT          0"drivers/watchdog/cpu5wdt.c#L13	0w2s="212" class="2line" name="L74">  74{
  75    27ref="drivers/watchdog/cpu5wdt.c#L1460w2s="212" class="2line" name="L76">  76    27ef="drivers/watchdog/cpu5wdt.c#L1470w2s="212" class="2line" name="L77">  77
clear_bit(vexit_modusref">file, uet(vexit_modusr  78    27ref="drivers/watchdog/cpu5wdt.c#L1490w2s="212" class="2line" name="L79">  79    27  clear_bit(vexit  80
  81    28ef="drivers/watchdog/cpu5wdt.c#L62" id="L622" class="2line" name="L82">  82    28     o"comment">/* if process modusr prory po="+
  83    28ef="drivers/watchdog/cpu5wdt.c#L124" id="L12" class="2line" name="L84">  84
clear_bit(vhnsr_modusref">file, uet(vhnsr_modusr  85    28ref="ode=WDIOF_CARDRaodusrvexitef">clear_bit(vexit_modusref">file, uet(vexit_modusr  86    28ef="drivers/watchdog/cpu5wdt.c#L1470w2s="212" class="2line" name="L87">  87    2      ode=inode" clas>)0ULE_AUTHORef">WDIOF_CARDR>)0ULE_AUTHORclass="string">"reset (%Heiko Ronsdorf &l/shero@ihg.uni-duisburg.de/a>
	>)0
  88    28  }
)0ULE_DESCRIPTIONef">WDIOF_CARDR>)0ULE_DESCRIPTIONclass="string">"reset (%sma 13	0 u5wdt.c# chdog/	>)0
  89    2      ode=inode" clas>)0ULE_SUPPORrED_DEVICEef">WDIOF_CARDR>)0ULE_SUPPORrED_DEVICEclass="string">"reset (%sma 13	0 u5wdt.c#	>)0
  90    2      ode=inode" clas>)0ULE_LICENSEef">WDIOF_CARDR>)0ULE_LICENSEclass="string">"reset (%GPL	>)0
  91    29ef="dode=inode" clas>)0ULE_ALIAS_MISCDEVef">WDIOF_CARDR>)0ULE_ALIAS_MISCDEVf="+code=inode" clasEATCHDOG_MINORef">WDIOF_CARDREATCHDOG_MINOR   92    29ef="drivers/watchdog/cpu5wdt.c#L153" id="L12" class="2line" name="L93">  93
clear_bitport +   94}
)0ULE_PARM_DESCef">WDIOF_CARDR>)0ULE_PARM_DESCf="+code=inode" clas="sref">port + "reset (%buctcaddrountof u5wdt.c# card,fks0reme0x91	>)0
  95
  96stat29     ode=WDIOF_CARDRaodusrvparamef">clear_bitverbose)
  97{
)0ULE_PARM_DESCef">WDIOF_CARDR>)0ULE_PARM_DESCf="+code=inode" clasass="sref">verbose)
"reset (%be )
0reme0 (no)	>)0
  98    29ef="drivers/watchdog/cpu5wdt.c#L1090w2s="212" class="2iine" name="L19">  19clear_bitticks =  100    30     ode=inode" clas>)0ULE_PARM_DESCef">WDIOF_CARDR>)0ULE_PARM_DESCf="+code=inode" class="sref">ticks = "reset (%iou0reme10000	>)0
 101    30 int 
The original LXR software by thtcode=WDIOFhttp://sourceforge.net/projects/lxre>LXR if unie=cpu5, themeexperi proal og/c"sr by ode=WDIOFmailto:lxr@"L1ux.no">lxr@"L1ux.nof="+c
lxr."L1ux.no kindly hosn> Redpill LL1pro AScpu5, providertof LL1uxft 0res and */