Commit f26ef3dc authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

[WATCHDOG 26/57] mpc watchdog: clean up and locking

Review and switch to unlocked_ioctl
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 39309645
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/of_platform.h> #include <linux/of_platform.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/mpc52xx.h> #include <asm/mpc52xx.h>
...@@ -57,7 +57,8 @@ static int mpc5200_wdt_start(struct mpc5200_wdt *wdt) ...@@ -57,7 +57,8 @@ static int mpc5200_wdt_start(struct mpc5200_wdt *wdt)
/* set timeout, with maximum prescaler */ /* set timeout, with maximum prescaler */
out_be32(&wdt->regs->count, 0x0 | wdt->count); out_be32(&wdt->regs->count, 0x0 | wdt->count);
/* enable watchdog */ /* enable watchdog */
out_be32(&wdt->regs->mode, GPT_MODE_CE | GPT_MODE_WDT | GPT_MODE_MS_TIMER); out_be32(&wdt->regs->mode, GPT_MODE_CE | GPT_MODE_WDT |
GPT_MODE_MS_TIMER);
spin_unlock(&wdt->io_lock); spin_unlock(&wdt->io_lock);
return 0; return 0;
...@@ -66,7 +67,8 @@ static int mpc5200_wdt_ping(struct mpc5200_wdt *wdt) ...@@ -66,7 +67,8 @@ static int mpc5200_wdt_ping(struct mpc5200_wdt *wdt)
{ {
spin_lock(&wdt->io_lock); spin_lock(&wdt->io_lock);
/* writing A5 to OCPW resets the watchdog */ /* writing A5 to OCPW resets the watchdog */
out_be32(&wdt->regs->mode, 0xA5000000 | (0xffffff & in_be32(&wdt->regs->mode))); out_be32(&wdt->regs->mode, 0xA5000000 |
(0xffffff & in_be32(&wdt->regs->mode)));
spin_unlock(&wdt->io_lock); spin_unlock(&wdt->io_lock);
return 0; return 0;
} }
...@@ -92,8 +94,8 @@ static struct watchdog_info mpc5200_wdt_info = { ...@@ -92,8 +94,8 @@ static struct watchdog_info mpc5200_wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
.identity = "mpc5200 watchdog on GPT0", .identity = "mpc5200 watchdog on GPT0",
}; };
static int mpc5200_wdt_ioctl(struct inode *inode, struct file *file, static long mpc5200_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
struct mpc5200_wdt *wdt = file->private_data; struct mpc5200_wdt *wdt = file->private_data;
int __user *data = (int __user *)arg; int __user *data = (int __user *)arg;
...@@ -135,6 +137,7 @@ static int mpc5200_wdt_ioctl(struct inode *inode, struct file *file, ...@@ -135,6 +137,7 @@ static int mpc5200_wdt_ioctl(struct inode *inode, struct file *file,
} }
return ret; return ret;
} }
static int mpc5200_wdt_open(struct inode *inode, struct file *file) static int mpc5200_wdt_open(struct inode *inode, struct file *file)
{ {
/* /dev/watchdog can only be opened once */ /* /dev/watchdog can only be opened once */
...@@ -167,7 +170,8 @@ static const struct file_operations mpc5200_wdt_fops = { ...@@ -167,7 +170,8 @@ static const struct file_operations mpc5200_wdt_fops = {
}; };
/* module operations */ /* module operations */
static int mpc5200_wdt_probe(struct of_device *op, const struct of_device_id *match) static int mpc5200_wdt_probe(struct of_device *op,
const struct of_device_id *match)
{ {
struct mpc5200_wdt *wdt; struct mpc5200_wdt *wdt;
int err; int err;
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
struct mpc83xx_wdt { struct mpc83xx_wdt {
__be32 res0; __be32 res0;
...@@ -42,11 +42,13 @@ static struct mpc83xx_wdt __iomem *wd_base; ...@@ -42,11 +42,13 @@ static struct mpc83xx_wdt __iomem *wd_base;
static u16 timeout = 0xffff; static u16 timeout = 0xffff;
module_param(timeout, ushort, 0); module_param(timeout, ushort, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in ticks. (0<timeout<65536, default=65535"); MODULE_PARM_DESC(timeout,
"Watchdog timeout in ticks. (0<timeout<65536, default=65535");
static int reset = 1; static int reset = 1;
module_param(reset, bool, 0); module_param(reset, bool, 0);
MODULE_PARM_DESC(reset, "Watchdog Interrupt/Reset Mode. 0 = interrupt, 1 = reset"); MODULE_PARM_DESC(reset,
"Watchdog Interrupt/Reset Mode. 0 = interrupt, 1 = reset");
/* /*
* We always prescale, but if someone really doesn't want to they can set this * We always prescale, but if someone really doesn't want to they can set this
...@@ -105,8 +107,8 @@ static int mpc83xx_wdt_release(struct inode *inode, struct file *file) ...@@ -105,8 +107,8 @@ static int mpc83xx_wdt_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
static int mpc83xx_wdt_ioctl(struct inode *inode, struct file *file, static long mpc83xx_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int __user *p = argp; int __user *p = argp;
...@@ -136,7 +138,7 @@ static const struct file_operations mpc83xx_wdt_fops = { ...@@ -136,7 +138,7 @@ static const struct file_operations mpc83xx_wdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = mpc83xx_wdt_write, .write = mpc83xx_wdt_write,
.ioctl = mpc83xx_wdt_ioctl, .unlocked_ioctl = mpc83xx_wdt_ioctl,
.open = mpc83xx_wdt_open, .open = mpc83xx_wdt_open,
.release = mpc83xx_wdt_release, .release = mpc83xx_wdt_release,
}; };
...@@ -161,8 +163,7 @@ static int __devinit mpc83xx_wdt_probe(struct platform_device *dev) ...@@ -161,8 +163,7 @@ static int __devinit mpc83xx_wdt_probe(struct platform_device *dev)
goto err_out; goto err_out;
} }
wd_base = ioremap(r->start, sizeof (struct mpc83xx_wdt)); wd_base = ioremap(r->start, sizeof(struct mpc83xx_wdt));
if (wd_base == NULL) { if (wd_base == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_out; goto err_out;
......
...@@ -16,36 +16,35 @@ ...@@ -16,36 +16,35 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <asm/8xx_immap.h> #include <asm/8xx_immap.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/io.h> #include <linux/io.h>
#include <syslib/m8xx_wdt.h> #include <syslib/m8xx_wdt.h>
static unsigned long wdt_opened; static unsigned long wdt_opened;
static int wdt_status; static int wdt_status;
static spinlock_t wdt_lock;
static void mpc8xx_wdt_handler_disable(void) static void mpc8xx_wdt_handler_disable(void)
{ {
volatile uint __iomem *piscr; volatile uint __iomem *piscr;
piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr; piscr = (uint *)&((immap_t *)IMAP_ADDR)->im_sit.sit_piscr;
if (!m8xx_has_internal_rtc) if (!m8xx_has_internal_rtc)
m8xx_wdt_stop_timer(); m8xx_wdt_stop_timer();
else else
out_be32(piscr, in_be32(piscr) & ~(PISCR_PIE | PISCR_PTE)); out_be32(piscr, in_be32(piscr) & ~(PISCR_PIE | PISCR_PTE));
printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n"); printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n");
} }
static void mpc8xx_wdt_handler_enable(void) static void mpc8xx_wdt_handler_enable(void)
{ {
volatile uint __iomem *piscr; volatile uint __iomem *piscr;
piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr; piscr = (uint *)&((immap_t *)IMAP_ADDR)->im_sit.sit_piscr;
if (!m8xx_has_internal_rtc) if (!m8xx_has_internal_rtc)
m8xx_wdt_install_timer(); m8xx_wdt_install_timer();
else else
out_be32(piscr, in_be32(piscr) | PISCR_PIE | PISCR_PTE); out_be32(piscr, in_be32(piscr) | PISCR_PIE | PISCR_PTE);
printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n"); printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n");
} }
...@@ -53,36 +52,33 @@ static int mpc8xx_wdt_open(struct inode *inode, struct file *file) ...@@ -53,36 +52,33 @@ static int mpc8xx_wdt_open(struct inode *inode, struct file *file)
{ {
if (test_and_set_bit(0, &wdt_opened)) if (test_and_set_bit(0, &wdt_opened))
return -EBUSY; return -EBUSY;
m8xx_wdt_reset(); m8xx_wdt_reset();
mpc8xx_wdt_handler_disable(); mpc8xx_wdt_handler_disable();
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
static int mpc8xx_wdt_release(struct inode *inode, struct file *file) static int mpc8xx_wdt_release(struct inode *inode, struct file *file)
{ {
m8xx_wdt_reset(); m8xx_wdt_reset();
#if !defined(CONFIG_WATCHDOG_NOWAYOUT) #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
mpc8xx_wdt_handler_enable(); mpc8xx_wdt_handler_enable();
#endif #endif
clear_bit(0, &wdt_opened); clear_bit(0, &wdt_opened);
return 0; return 0;
} }
static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len, static ssize_t mpc8xx_wdt_write(struct file *file, const char *data,
loff_t * ppos) size_t len, loff_t *ppos)
{ {
if (len) if (len) {
spin_lock(&wdt_lock);
m8xx_wdt_reset(); m8xx_wdt_reset();
spin_unlock(&wdt_lock);
}
return len; return len;
} }
static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file, static long mpc8xx_wdt_ioctl(struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
int timeout; int timeout;
...@@ -112,15 +108,19 @@ static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file, ...@@ -112,15 +108,19 @@ static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
return -EOPNOTSUPP; return -EOPNOTSUPP;
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
spin_lock(&wdt_lock);
m8xx_wdt_reset(); m8xx_wdt_reset();
wdt_status |= WDIOF_KEEPALIVEPING; wdt_status |= WDIOF_KEEPALIVEPING;
spin_unlock(&wdt_lock);
break; break;
case WDIOC_SETTIMEOUT: case WDIOC_SETTIMEOUT:
return -EOPNOTSUPP; return -EOPNOTSUPP;
case WDIOC_GETTIMEOUT: case WDIOC_GETTIMEOUT:
spin_lock(&wdt_lock);
timeout = m8xx_wdt_get_timeout(); timeout = m8xx_wdt_get_timeout();
spin_unlock(&wdt_lock);
if (put_user(timeout, (int *)arg)) if (put_user(timeout, (int *)arg))
return -EFAULT; return -EFAULT;
break; break;
...@@ -136,7 +136,7 @@ static const struct file_operations mpc8xx_wdt_fops = { ...@@ -136,7 +136,7 @@ static const struct file_operations mpc8xx_wdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = mpc8xx_wdt_write, .write = mpc8xx_wdt_write,
.ioctl = mpc8xx_wdt_ioctl, .unlocked_ioctl = mpc8xx_wdt_ioctl,
.open = mpc8xx_wdt_open, .open = mpc8xx_wdt_open,
.release = mpc8xx_wdt_release, .release = mpc8xx_wdt_release,
}; };
...@@ -149,6 +149,7 @@ static struct miscdevice mpc8xx_wdt_miscdev = { ...@@ -149,6 +149,7 @@ static struct miscdevice mpc8xx_wdt_miscdev = {
static int __init mpc8xx_wdt_init(void) static int __init mpc8xx_wdt_init(void)
{ {
spin_lock_init(&wdt_lock);
return misc_register(&mpc8xx_wdt_miscdev); return misc_register(&mpc8xx_wdt_miscdev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment