]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/um/drivers/harddog_kern.c
Replace <asm/uaccess.h> with <linux/uaccess.h> globally
[mirror_ubuntu-bionic-kernel.git] / arch / um / drivers / harddog_kern.c
CommitLineData
1da177e4
LT
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.
5bbcbeca
JD
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.
1da177e4
LT
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>
5bbcbeca 32 * Added soft_noboot; Allows testing the softdog trigger without
1da177e4
LT
33 * requiring a recompile.
34 * Added WDIOC_GETTIMEOUT and WDIOC_SETTIMOUT.
35 */
5bbcbeca 36
1da177e4 37#include <linux/module.h>
1da177e4
LT
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>
9a181c58 45#include <linux/mutex.h>
1da177e4 46#include <linux/init.h>
42d36115 47#include <linux/spinlock.h>
7c0f6ba6 48#include <linux/uaccess.h>
1da177e4
LT
49#include "mconsole.h"
50
51MODULE_LICENSE("GPL");
52
9a181c58 53static DEFINE_MUTEX(harddog_mutex);
42d36115 54static DEFINE_SPINLOCK(lock);
1da177e4
LT
55static int timer_alive;
56static int harddog_in_fd = -1;
57static int harddog_out_fd = -1;
58
59/*
60 * Allow only one person to hold it open
61 */
5bbcbeca 62
1da177e4
LT
63extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock);
64
65static int harddog_open(struct inode *inode, struct file *file)
66{
42d36115 67 int err = -EBUSY;
1da177e4
LT
68 char *sock = NULL;
69
9a181c58 70 mutex_lock(&harddog_mutex);
42d36115 71 spin_lock(&lock);
1da177e4 72 if(timer_alive)
42d36115 73 goto err;
8d820760 74#ifdef CONFIG_WATCHDOG_NOWAYOUT
1da177e4
LT
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);
42d36115
JD
82 if(err)
83 goto err;
1da177e4
LT
84
85 timer_alive = 1;
42d36115 86 spin_unlock(&lock);
9a181c58 87 mutex_unlock(&harddog_mutex);
1da177e4 88 return nonseekable_open(inode, file);
42d36115
JD
89err:
90 spin_unlock(&lock);
9a181c58 91 mutex_unlock(&harddog_mutex);
42d36115 92 return err;
1da177e4
LT
93}
94
95extern void stop_watchdog(int in_fd, int out_fd);
96
97static int harddog_release(struct inode *inode, struct file *file)
98{
99 /*
100 * Shut off the timer.
101 */
42d36115
JD
102
103 spin_lock(&lock);
1da177e4
LT
104
105 stop_watchdog(harddog_in_fd, harddog_out_fd);
106 harddog_in_fd = -1;
107 harddog_out_fd = -1;
108
109 timer_alive=0;
42d36115
JD
110 spin_unlock(&lock);
111
1da177e4
LT
112 return 0;
113}
114
115extern int ping_watchdog(int fd);
116
4d338e1a 117static ssize_t harddog_write(struct file *file, const char __user *data, size_t len,
1da177e4
LT
118 loff_t *ppos)
119{
120 /*
121 * Refresh the timer.
122 */
123 if(len)
5bbcbeca 124 return ping_watchdog(harddog_out_fd);
1da177e4
LT
125 return 0;
126}
127
9f37af65
FW
128static int harddog_ioctl_unlocked(struct file *file,
129 unsigned int cmd, unsigned long arg)
1da177e4 130{
4d338e1a 131 void __user *argp= (void __user *)arg;
1da177e4
LT
132 static struct watchdog_info ident = {
133 WDIOC_SETTIMEOUT,
134 0,
135 "UML Hardware Watchdog"
136 };
137 switch (cmd) {
138 default:
139 return -ENOTTY;
140 case WDIOC_GETSUPPORT:
4d338e1a 141 if(copy_to_user(argp, &ident, sizeof(ident)))
1da177e4
LT
142 return -EFAULT;
143 return 0;
144 case WDIOC_GETSTATUS:
145 case WDIOC_GETBOOTSTATUS:
4d338e1a 146 return put_user(0,(int __user *)argp);
1da177e4 147 case WDIOC_KEEPALIVE:
5bbcbeca 148 return ping_watchdog(harddog_out_fd);
1da177e4
LT
149 }
150}
151
9f37af65
FW
152static long harddog_ioctl(struct file *file,
153 unsigned int cmd, unsigned long arg)
154{
155 long ret;
156
9a181c58 157 mutex_lock(&harddog_mutex);
9f37af65 158 ret = harddog_ioctl_unlocked(file, cmd, arg);
9a181c58 159 mutex_unlock(&harddog_mutex);
9f37af65
FW
160
161 return ret;
162}
163
5dfe4c96 164static const struct file_operations harddog_fops = {
1da177e4
LT
165 .owner = THIS_MODULE,
166 .write = harddog_write,
9f37af65 167 .unlocked_ioctl = harddog_ioctl,
1da177e4
LT
168 .open = harddog_open,
169 .release = harddog_release,
6038f373 170 .llseek = no_llseek,
1da177e4
LT
171};
172
173static struct miscdevice harddog_miscdev = {
174 .minor = WATCHDOG_MINOR,
175 .name = "watchdog",
176 .fops = &harddog_fops,
177};
d6a38c0b 178module_misc_device(harddog_miscdev);