~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/um/drivers/harddog_kern.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* UML hardware watchdog, shamelessly stolen from:
  2  *
  3  *      SoftDog 0.05:   A Software Watchdog Device
  4  *
  5  *      (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
  6  *                              http://www.redhat.com
  7  *
  8  *      This program is free software; you can redistribute it and/or
  9  *      modify it under the terms of the GNU General Public License
 10  *      as published by the Free Software Foundation; either version
 11  *      2 of the License, or (at your option) any later version.
 12  *
 13  *      Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
 14  *      warranty for any of this software. This material is provided
 15  *      "AS-IS" and at no charge.
 16  *
 17  *      (c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
 18  *
 19  *      Software only watchdog driver. Unlike its big brother the WDT501P
 20  *      driver this won't always recover a failed machine.
 21  *
 22  *  03/96: Angelo Haritsis <ah@doc.ic.ac.uk> :
 23  *      Modularised.
 24  *      Added soft_margin; use upon insmod to change the timer delay.
 25  *      NB: uses same minor as wdt (WATCHDOG_MINOR); we could use separate
 26  *          minors.
 27  *
 28  *  19980911 Alan Cox
 29  *      Made SMP safe for 2.3.x
 30  *
 31  *  20011127 Joel Becker (jlbec@evilplan.org>
 32  *      Added soft_noboot; Allows testing the softdog trigger without
 33  *      requiring a recompile.
 34  *      Added WDIOC_GETTIMEOUT and WDIOC_SETTIMOUT.
 35  */
 36 
 37 #include <linux/module.h>
 38 #include <linux/types.h>
 39 #include <linux/kernel.h>
 40 #include <linux/fs.h>
 41 #include <linux/mm.h>
 42 #include <linux/miscdevice.h>
 43 #include <linux/watchdog.h>
 44 #include <linux/reboot.h>
 45 #include <linux/mutex.h>
 46 #include <linux/init.h>
 47 #include <linux/spinlock.h>
 48 #include <linux/uaccess.h>
 49 #include "mconsole.h"
 50 #include "harddog.h"
 51 
 52 MODULE_DESCRIPTION("UML hardware watchdog");
 53 MODULE_LICENSE("GPL");
 54 
 55 static DEFINE_MUTEX(harddog_mutex);
 56 static DEFINE_SPINLOCK(lock);
 57 static int timer_alive;
 58 static int harddog_in_fd = -1;
 59 static int harddog_out_fd = -1;
 60 
 61 /*
 62  *      Allow only one person to hold it open
 63  */
 64 
 65 static int harddog_open(struct inode *inode, struct file *file)
 66 {
 67         int err = -EBUSY;
 68         char *sock = NULL;
 69 
 70         mutex_lock(&harddog_mutex);
 71         spin_lock(&lock);
 72         if(timer_alive)
 73                 goto err;
 74 #ifdef CONFIG_WATCHDOG_NOWAYOUT
 75         __module_get(THIS_MODULE);
 76 #endif
 77 
 78 #ifdef CONFIG_MCONSOLE
 79         sock = mconsole_notify_socket();
 80 #endif
 81         err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock);
 82         if(err)
 83                 goto err;
 84 
 85         timer_alive = 1;
 86         spin_unlock(&lock);
 87         mutex_unlock(&harddog_mutex);
 88         return stream_open(inode, file);
 89 err:
 90         spin_unlock(&lock);
 91         mutex_unlock(&harddog_mutex);
 92         return err;
 93 }
 94 
 95 static int harddog_release(struct inode *inode, struct file *file)
 96 {
 97         /*
 98          *      Shut off the timer.
 99          */
100 
101         spin_lock(&lock);
102 
103         stop_watchdog(harddog_in_fd, harddog_out_fd);
104         harddog_in_fd = -1;
105         harddog_out_fd = -1;
106 
107         timer_alive=0;
108         spin_unlock(&lock);
109 
110         return 0;
111 }
112 
113 static ssize_t harddog_write(struct file *file, const char __user *data, size_t len,
114                              loff_t *ppos)
115 {
116         /*
117          *      Refresh the timer.
118          */
119         if(len)
120                 return ping_watchdog(harddog_out_fd);
121         return 0;
122 }
123 
124 static int harddog_ioctl_unlocked(struct file *file,
125                                   unsigned int cmd, unsigned long arg)
126 {
127         void __user *argp= (void __user *)arg;
128         static struct watchdog_info ident = {
129                 WDIOC_SETTIMEOUT,
130                 0,
131                 "UML Hardware Watchdog"
132         };
133         switch (cmd) {
134                 default:
135                         return -ENOTTY;
136                 case WDIOC_GETSUPPORT:
137                         if(copy_to_user(argp, &ident, sizeof(ident)))
138                                 return -EFAULT;
139                         return 0;
140                 case WDIOC_GETSTATUS:
141                 case WDIOC_GETBOOTSTATUS:
142                         return put_user(0,(int __user *)argp);
143                 case WDIOC_KEEPALIVE:
144                         return ping_watchdog(harddog_out_fd);
145         }
146 }
147 
148 static long harddog_ioctl(struct file *file,
149                           unsigned int cmd, unsigned long arg)
150 {
151         long ret;
152 
153         mutex_lock(&harddog_mutex);
154         ret = harddog_ioctl_unlocked(file, cmd, arg);
155         mutex_unlock(&harddog_mutex);
156 
157         return ret;
158 }
159 
160 static const struct file_operations harddog_fops = {
161         .owner          = THIS_MODULE,
162         .write          = harddog_write,
163         .unlocked_ioctl = harddog_ioctl,
164         .compat_ioctl   = compat_ptr_ioctl,
165         .open           = harddog_open,
166         .release        = harddog_release,
167         .llseek         = no_llseek,
168 };
169 
170 static struct miscdevice harddog_miscdev = {
171         .minor          = WATCHDOG_MINOR,
172         .name           = "watchdog",
173         .fops           = &harddog_fops,
174 };
175 module_misc_device(harddog_miscdev);
176 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php