2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Intel 21285 watchdog driver
|
|
|
|
* Copyright (c) Phil Blundell <pb@nexus.co.uk>, 1998
|
|
|
|
*
|
|
|
|
* based on
|
|
|
|
*
|
|
|
|
* SoftDog 0.05: A Software Watchdog Device
|
|
|
|
*
|
2008-10-27 22:17:56 +07:00
|
|
|
* (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
|
|
|
* All Rights Reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
2008-05-19 20:09:51 +07:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/irq.h>
|
2008-08-05 22:14:15 +07:00
|
|
|
#include <mach/hardware.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <asm/mach-types.h>
|
|
|
|
#include <asm/hardware/dec21285.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define this to stop the watchdog actually rebooting the machine.
|
|
|
|
*/
|
|
|
|
#undef ONLY_TESTING
|
|
|
|
|
|
|
|
static unsigned int soft_margin = 60; /* in seconds */
|
|
|
|
static unsigned int reload;
|
|
|
|
static unsigned long timer_alive;
|
|
|
|
|
|
|
|
#ifdef ONLY_TESTING
|
|
|
|
/*
|
|
|
|
* If the timer expires..
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static void watchdog_fire(int irq, void *dev_id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
printk(KERN_CRIT "Watchdog: Would Reboot.\n");
|
|
|
|
*CSR_TIMER4_CNTL = 0;
|
|
|
|
*CSR_TIMER4_CLR = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refresh the timer.
|
|
|
|
*/
|
|
|
|
static void watchdog_ping(void)
|
|
|
|
{
|
|
|
|
*CSR_TIMER4_LOAD = reload;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow only one person to hold it open
|
|
|
|
*/
|
|
|
|
static int watchdog_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (*CSR_SA110_CNTL & (1 << 13))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (test_and_set_bit(1, &timer_alive))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
reload = soft_margin * (mem_fclk_21285 / 256);
|
|
|
|
|
|
|
|
*CSR_TIMER4_CLR = 0;
|
|
|
|
watchdog_ping();
|
|
|
|
*CSR_TIMER4_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD
|
|
|
|
| TIMER_CNTL_DIV256;
|
|
|
|
|
|
|
|
#ifdef ONLY_TESTING
|
|
|
|
ret = request_irq(IRQ_TIMER4, watchdog_fire, 0, "watchdog", NULL);
|
|
|
|
if (ret) {
|
|
|
|
*CSR_TIMER4_CNTL = 0;
|
|
|
|
clear_bit(1, &timer_alive);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Setting this bit is irreversible; once enabled, there is
|
|
|
|
* no way to disable the watchdog.
|
|
|
|
*/
|
|
|
|
*CSR_SA110_CNTL |= 1 << 13;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
#endif
|
|
|
|
nonseekable_open(inode, file);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shut off the timer.
|
|
|
|
* Note: if we really have enabled the watchdog, there
|
|
|
|
* is no way to turn off.
|
|
|
|
*/
|
|
|
|
static int watchdog_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
#ifdef ONLY_TESTING
|
|
|
|
free_irq(IRQ_TIMER4, NULL);
|
|
|
|
clear_bit(1, &timer_alive);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-16 17:31:01 +07:00
|
|
|
static ssize_t watchdog_write(struct file *file, const char __user *data,
|
|
|
|
size_t len, loff_t *ppos)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Refresh the timer.
|
|
|
|
*/
|
|
|
|
if (len)
|
|
|
|
watchdog_ping();
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-05-19 20:09:51 +07:00
|
|
|
static const struct watchdog_info ident = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.options = WDIOF_SETTIMEOUT,
|
|
|
|
.identity = "Footbridge Watchdog",
|
|
|
|
};
|
|
|
|
|
2008-05-19 20:09:51 +07:00
|
|
|
static long watchdog_ioctl(struct file *file, unsigned int cmd,
|
2008-09-16 17:31:01 +07:00
|
|
|
unsigned long arg)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned int new_margin;
|
2008-09-16 17:31:01 +07:00
|
|
|
int __user *int_arg = (int __user *)arg;
|
2006-09-09 22:34:31 +07:00
|
|
|
int ret = -ENOTTY;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-05-19 20:09:51 +07:00
|
|
|
switch (cmd) {
|
2005-04-17 05:20:36 +07:00
|
|
|
case WDIOC_GETSUPPORT:
|
|
|
|
ret = 0;
|
2008-09-16 17:31:01 +07:00
|
|
|
if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
|
2005-04-17 05:20:36 +07:00
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
2008-09-16 17:31:01 +07:00
|
|
|
ret = put_user(0, int_arg);
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
watchdog_ping();
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDIOC_SETTIMEOUT:
|
2008-09-16 17:31:01 +07:00
|
|
|
ret = get_user(new_margin, int_arg);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Arbitrary, can't find the card's limits */
|
|
|
|
if (new_margin < 0 || new_margin > 60) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
soft_margin = new_margin;
|
|
|
|
reload = soft_margin * (mem_fclk_21285 / 256);
|
|
|
|
watchdog_ping();
|
|
|
|
/* Fall */
|
|
|
|
case WDIOC_GETTIMEOUT:
|
2008-09-16 17:31:01 +07:00
|
|
|
ret = put_user(soft_margin, int_arg);
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-03 14:24:21 +07:00
|
|
|
static const struct file_operations watchdog_fops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = watchdog_write,
|
2008-05-19 20:09:51 +07:00
|
|
|
.unlocked_ioctl = watchdog_ioctl,
|
2005-04-17 05:20:36 +07:00
|
|
|
.open = watchdog_open,
|
|
|
|
.release = watchdog_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice watchdog_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &watchdog_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init footbridge_watchdog_init(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (machine_is_netwinder())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
retval = misc_register(&watchdog_miscdev);
|
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
|
|
|
|
2008-05-19 20:09:51 +07:00
|
|
|
printk(KERN_INFO
|
|
|
|
"Footbridge Watchdog Timer: 0.01, timer margin: %d sec\n",
|
|
|
|
soft_margin);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (machine_is_cats())
|
2008-08-08 23:03:46 +07:00
|
|
|
printk(KERN_WARNING
|
2008-05-19 20:09:51 +07:00
|
|
|
"Warning: Watchdog reset may not work on this machine.\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit footbridge_watchdog_exit(void)
|
|
|
|
{
|
|
|
|
misc_deregister(&watchdog_miscdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
|
|
|
|
MODULE_DESCRIPTION("Footbridge watchdog driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
|
|
|
|
|
|
|
|
module_param(soft_margin, int, 0);
|
2008-05-19 20:09:51 +07:00
|
|
|
MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
module_init(footbridge_watchdog_init);
|
|
|
|
module_exit(footbridge_watchdog_exit);
|