2019-05-19 12:08:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* PC Watchdog Driver
|
|
|
|
* by Ken Hollis (khollis@bitgate.com)
|
|
|
|
*
|
2007-01-09 21:38:54 +00:00
|
|
|
* Permission granted from Simon Machell (smachell@berkprod.com)
|
2005-04-16 22:20:36 +00:00
|
|
|
* Written for the Linux Kernel, and GPLed by Ken Hollis
|
|
|
|
*
|
|
|
|
* 960107 Added request_region routines, modulized the whole thing.
|
|
|
|
* 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added
|
|
|
|
* WD_TIMEOUT define.
|
|
|
|
* 960216 Added eof marker on the file, and changed verbose messages.
|
|
|
|
* 960716 Made functional and cosmetic changes to the source for
|
|
|
|
* inclusion in Linux 2.0.x kernels, thanks to Alan Cox.
|
|
|
|
* 960717 Removed read/seek routines, replaced with ioctl. Also, added
|
|
|
|
* check_region command due to Alan's suggestion.
|
|
|
|
* 960821 Made changes to compile in newer 2.0.x kernels. Added
|
|
|
|
* "cold reboot sense" entry.
|
|
|
|
* 960825 Made a few changes to code, deleted some defines and made
|
|
|
|
* typedefs to replace them. Made heartbeat reset only available
|
|
|
|
* via ioctl, and removed the write routine.
|
|
|
|
* 960828 Added new items for PC Watchdog Rev.C card.
|
|
|
|
* 960829 Changed around all of the IOCTLs, added new features,
|
|
|
|
* added watchdog disable/re-enable routines. Added firmware
|
|
|
|
* version reporting. Added read routine for temperature.
|
|
|
|
* Removed some extra defines, added an autodetect Revision
|
|
|
|
* routine.
|
2009-03-18 08:35:09 +00:00
|
|
|
* 961006 Revised some documentation, fixed some cosmetic bugs. Made
|
|
|
|
* drivers to panic the system if it's overheating at bootup.
|
2005-04-16 22:20:36 +00:00
|
|
|
* 961118 Changed some verbiage on some of the output, tidied up
|
|
|
|
* code bits, and added compatibility to 2.1.x.
|
2009-03-18 08:35:09 +00:00
|
|
|
* 970912 Enabled board on open and disable on close.
|
2005-04-16 22:20:36 +00:00
|
|
|
* 971107 Took account of recent VFS changes (broke read).
|
2009-03-18 08:35:09 +00:00
|
|
|
* 971210 Disable board on initialisation in case board already ticking.
|
|
|
|
* 971222 Changed open/close for temperature handling
|
|
|
|
* Michael Meskes <meskes@debian.org>.
|
|
|
|
* 980112 Used minor numbers from include/linux/miscdevice.h
|
|
|
|
* 990403 Clear reset status after reading control status register in
|
|
|
|
* pcwd_showprevstate(). [Marc Boucher <marc@mbsi.ca>]
|
2005-04-16 22:20:36 +00:00
|
|
|
* 990605 Made changes to code to support Firmware 1.22a, added
|
|
|
|
* fairly useless proc entry.
|
|
|
|
* 990610 removed said useless proc code for the merge <alan>
|
|
|
|
* 000403 Removed last traces of proc code. <davej>
|
2008-05-19 13:07:43 +00:00
|
|
|
* 011214 Added nowayout module option to override
|
|
|
|
* CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
|
2009-03-18 08:35:09 +00:00
|
|
|
* Added timeout module option to override default
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A bells and whistles driver is available from http://www.pcwd.de/
|
2008-05-19 13:07:43 +00:00
|
|
|
* More info available at http://www.berkprod.com/ or
|
|
|
|
* http://www.pcwatchdog.com/
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-15 23:06:19 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-12-10 13:22:37 +00:00
|
|
|
#include <linux/module.h> /* For module specific items */
|
|
|
|
#include <linux/moduleparam.h> /* For new moduleparam's */
|
|
|
|
#include <linux/types.h> /* For standard types (like size_t) */
|
|
|
|
#include <linux/errno.h> /* For the -ENODEV/... values */
|
|
|
|
#include <linux/kernel.h> /* For printk/panic/... */
|
|
|
|
#include <linux/delay.h> /* For mdelay function */
|
|
|
|
#include <linux/timer.h> /* For timer related operations */
|
|
|
|
#include <linux/jiffies.h> /* For jiffies stuff */
|
2013-10-21 15:38:49 +00:00
|
|
|
#include <linux/miscdevice.h> /* For struct miscdevice */
|
2005-12-10 13:22:37 +00:00
|
|
|
#include <linux/watchdog.h> /* For the watchdog specific items */
|
2007-05-05 05:48:23 +00:00
|
|
|
#include <linux/reboot.h> /* For kernel_power_off() */
|
2005-12-10 13:22:37 +00:00
|
|
|
#include <linux/init.h> /* For __init/__exit/... */
|
|
|
|
#include <linux/fs.h> /* For file operations */
|
2007-05-05 05:48:23 +00:00
|
|
|
#include <linux/isa.h> /* For isa devices */
|
2005-12-10 13:22:37 +00:00
|
|
|
#include <linux/ioport.h> /* For io-port access */
|
|
|
|
#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
|
2008-05-19 13:07:43 +00:00
|
|
|
#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
|
|
|
|
#include <linux/io.h> /* For inb/outb/... */
|
2005-12-10 13:22:37 +00:00
|
|
|
|
|
|
|
/* Module and version information */
|
2007-05-05 05:48:23 +00:00
|
|
|
#define WATCHDOG_VERSION "1.20"
|
|
|
|
#define WATCHDOG_DATE "18 Feb 2007"
|
2006-01-09 21:07:22 +00:00
|
|
|
#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
|
|
|
|
#define WATCHDOG_NAME "pcwd"
|
2009-03-18 08:35:09 +00:00
|
|
|
#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION "\n"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It should be noted that PCWD_REVISION_B was removed because A and B
|
|
|
|
* are essentially the same types of card, with the exception that B
|
|
|
|
* has temperature reporting. Since I didn't receive a Rev.B card,
|
|
|
|
* the Rev.B card is not supported. (It's a good thing too, as they
|
|
|
|
* are no longer in production.)
|
|
|
|
*/
|
|
|
|
#define PCWD_REVISION_A 1
|
|
|
|
#define PCWD_REVISION_C 2
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
/*
|
|
|
|
* These are the auto-probe addresses available.
|
|
|
|
*
|
|
|
|
* Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
|
|
|
|
* Revision A has an address range of 2 addresses, while Revision C has 4.
|
|
|
|
*/
|
|
|
|
#define PCWD_ISA_NR_CARDS 3
|
|
|
|
static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-01-09 20:56:09 +00:00
|
|
|
* These are the defines that describe the control status bits for the
|
|
|
|
* PCI-PC Watchdog card.
|
|
|
|
*/
|
|
|
|
/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
|
2006-02-12 15:37:36 +00:00
|
|
|
#define WD_WDRST 0x01 /* Previously reset state */
|
|
|
|
#define WD_T110 0x02 /* Temperature overheat sense */
|
|
|
|
#define WD_HRTBT 0x04 /* Heartbeat sense */
|
|
|
|
#define WD_RLY2 0x08 /* External relay triggered */
|
|
|
|
#define WD_SRLY2 0x80 /* Software external relay triggered */
|
2006-01-09 20:56:09 +00:00
|
|
|
/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
|
2006-02-12 15:37:36 +00:00
|
|
|
#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
|
|
|
|
#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
|
|
|
|
#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
|
2008-05-19 13:07:43 +00:00
|
|
|
#define WD_REVC_RL2A 0x08 /* Relay 2 activated by
|
|
|
|
on-board processor */
|
2006-02-12 15:37:36 +00:00
|
|
|
#define WD_REVC_RL1A 0x10 /* Relay 1 active */
|
|
|
|
#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
|
|
|
|
#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
|
2006-01-09 20:56:09 +00:00
|
|
|
/* Port 2 : Control Status #2 */
|
|
|
|
#define WD_WDIS 0x10 /* Watchdog Disabled */
|
|
|
|
#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
|
2008-05-19 13:07:43 +00:00
|
|
|
#define WD_SSEL 0x40 /* Watchdog Switch Select
|
|
|
|
(1:SW1 <-> 0:SW2) */
|
2006-01-09 20:56:09 +00:00
|
|
|
#define WD_WCMD 0x80 /* Watchdog Command Mode */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* max. time we give an ISA watchdog card to process a command */
|
|
|
|
/* 500ms for each 4 bit response (according to spec.) */
|
|
|
|
#define ISA_COMMAND_TIMEOUT 1000
|
|
|
|
|
|
|
|
/* Watchdog's internal commands */
|
2005-12-10 13:22:37 +00:00
|
|
|
#define CMD_ISA_IDLE 0x00
|
|
|
|
#define CMD_ISA_VERSION_INTEGER 0x01
|
|
|
|
#define CMD_ISA_VERSION_TENTH 0x02
|
|
|
|
#define CMD_ISA_VERSION_HUNDRETH 0x03
|
|
|
|
#define CMD_ISA_VERSION_MINOR 0x04
|
|
|
|
#define CMD_ISA_SWITCH_SETTINGS 0x05
|
2006-02-12 16:44:57 +00:00
|
|
|
#define CMD_ISA_RESET_PC 0x06
|
|
|
|
#define CMD_ISA_ARM_0 0x07
|
|
|
|
#define CMD_ISA_ARM_30 0x08
|
|
|
|
#define CMD_ISA_ARM_60 0x09
|
2005-12-10 13:22:37 +00:00
|
|
|
#define CMD_ISA_DELAY_TIME_2SECS 0x0A
|
|
|
|
#define CMD_ISA_DELAY_TIME_4SECS 0x0B
|
|
|
|
#define CMD_ISA_DELAY_TIME_8SECS 0x0C
|
2006-02-12 16:44:57 +00:00
|
|
|
#define CMD_ISA_RESET_RELAYS 0x0D
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-01-09 21:43:49 +00:00
|
|
|
/* Watchdog's Dip Switch heartbeat values */
|
2008-08-06 20:19:41 +00:00
|
|
|
static const int heartbeat_tbl[] = {
|
2007-01-09 21:43:49 +00:00
|
|
|
20, /* OFF-OFF-OFF = 20 Sec */
|
|
|
|
40, /* OFF-OFF-ON = 40 Sec */
|
|
|
|
60, /* OFF-ON-OFF = 1 Min */
|
|
|
|
300, /* OFF-ON-ON = 5 Min */
|
|
|
|
600, /* ON-OFF-OFF = 10 Min */
|
|
|
|
1800, /* ON-OFF-ON = 30 Min */
|
|
|
|
3600, /* ON-ON-OFF = 1 Hour */
|
|
|
|
7200, /* ON-ON-ON = 2 hour */
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* We are using an kernel timer to do the pinging of the watchdog
|
|
|
|
* every ~500ms. We try to set the internal heartbeat of the
|
|
|
|
* watchdog to 2 ms.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WDT_INTERVAL (HZ/2+1)
|
|
|
|
|
|
|
|
/* We can only use 1 card due to the /dev/watchdog restriction */
|
|
|
|
static int cards_found;
|
|
|
|
|
|
|
|
/* internal variables */
|
2008-08-10 21:57:03 +00:00
|
|
|
static unsigned long open_allowed;
|
2005-04-16 22:20:36 +00:00
|
|
|
static char expect_close;
|
|
|
|
static int temp_panic;
|
2008-05-19 13:07:43 +00:00
|
|
|
|
|
|
|
/* this is private data for each ISA-PC watchdog card */
|
|
|
|
static struct {
|
2006-02-12 15:47:34 +00:00
|
|
|
char fw_ver_str[6]; /* The cards firmware version */
|
2006-01-09 20:53:33 +00:00
|
|
|
int revision; /* The card's revision */
|
2008-05-19 13:07:43 +00:00
|
|
|
int supports_temp; /* Whether or not the card has
|
|
|
|
a temperature device */
|
|
|
|
int command_mode; /* Whether or not the card is in
|
|
|
|
command mode */
|
2006-01-09 20:53:33 +00:00
|
|
|
int boot_status; /* The card's boot status */
|
|
|
|
int io_addr; /* The cards I/O address */
|
|
|
|
spinlock_t io_lock; /* the lock for io operations */
|
|
|
|
struct timer_list timer; /* The timer that pings the watchdog */
|
|
|
|
unsigned long next_heartbeat; /* the next_heartbeat for the timer */
|
|
|
|
} pcwd_private;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* module parameters */
|
2006-02-12 16:12:55 +00:00
|
|
|
#define QUIET 0 /* Default */
|
|
|
|
#define VERBOSE 1 /* Verbose */
|
|
|
|
#define DEBUG 2 /* print fancy stuff too */
|
|
|
|
static int debug = QUIET;
|
|
|
|
module_param(debug, int, 0);
|
2008-05-19 13:07:43 +00:00
|
|
|
MODULE_PARM_DESC(debug,
|
|
|
|
"Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
/* default heartbeat = delay-time from dip-switches */
|
|
|
|
#define WATCHDOG_HEARTBEAT 0
|
2005-04-16 22:20:36 +00:00
|
|
|
static int heartbeat = WATCHDOG_HEARTBEAT;
|
|
|
|
module_param(heartbeat, int, 0);
|
2009-03-18 08:35:09 +00:00
|
|
|
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. "
|
|
|
|
"(2 <= heartbeat <= 7200 or 0=delay-time from dip-switches, default="
|
|
|
|
__MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-05 15:51:11 +00:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
2008-05-19 13:07:43 +00:00
|
|
|
MODULE_PARM_DESC(nowayout,
|
|
|
|
"Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int send_isa_command(int cmd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int control_status;
|
|
|
|
int port0, last_port0; /* Double read for stabilising */
|
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("sending following data cmd=0x%02x\n", cmd);
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* The WCMD bit must be 1 and the command is only 4 bits in size */
|
2006-01-09 20:56:09 +00:00
|
|
|
control_status = (cmd & 0x0F) | WD_WCMD;
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(control_status, pcwd_private.io_addr + 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
port0 = inb_p(pcwd_private.io_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < 25; ++i) {
|
|
|
|
last_port0 = port0;
|
2006-01-09 20:53:33 +00:00
|
|
|
port0 = inb_p(pcwd_private.io_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (port0 == last_port0)
|
|
|
|
break; /* Data is stable */
|
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
udelay(250);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
|
|
|
|
cmd, port0, last_port0);
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return port0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_command_mode(void)
|
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
int i, found = 0, count = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Set the card into command mode */
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
while ((!found) && (count < 3)) {
|
|
|
|
i = send_isa_command(CMD_ISA_IDLE);
|
|
|
|
|
|
|
|
if (i == 0x00)
|
|
|
|
found = 1;
|
|
|
|
else if (i == 0xF3) {
|
|
|
|
/* Card does not like what we've done to it */
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(0x00, pcwd_private.io_addr + 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(1200); /* Spec says wait 1ms */
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(0x00, pcwd_private.io_addr + 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
|
|
|
pcwd_private.command_mode = found;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("command_mode=%d\n", pcwd_private.command_mode);
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2008-08-06 20:19:41 +00:00
|
|
|
return found;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unset_command_mode(void)
|
|
|
|
{
|
|
|
|
/* Set the card into normal mode */
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
outb_p(0x00, pcwd_private.io_addr + 2);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.command_mode = 0;
|
2006-02-12 16:12:55 +00:00
|
|
|
|
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("command_mode=%d\n", pcwd_private.command_mode);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 20:59:39 +00:00
|
|
|
static inline void pcwd_check_temperature_support(void)
|
|
|
|
{
|
|
|
|
if (inb(pcwd_private.io_addr) != 0xF0)
|
|
|
|
pcwd_private.supports_temp = 1;
|
|
|
|
}
|
|
|
|
|
2006-02-12 15:47:34 +00:00
|
|
|
static inline void pcwd_get_firmware(void)
|
2006-01-09 21:03:41 +00:00
|
|
|
{
|
|
|
|
int one, ten, hund, minor;
|
|
|
|
|
2006-03-02 19:05:16 +00:00
|
|
|
strcpy(pcwd_private.fw_ver_str, "ERROR");
|
2006-01-09 21:03:41 +00:00
|
|
|
|
|
|
|
if (set_command_mode()) {
|
|
|
|
one = send_isa_command(CMD_ISA_VERSION_INTEGER);
|
|
|
|
ten = send_isa_command(CMD_ISA_VERSION_TENTH);
|
|
|
|
hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
|
|
|
|
minor = send_isa_command(CMD_ISA_VERSION_MINOR);
|
2008-05-19 13:07:43 +00:00
|
|
|
sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c",
|
|
|
|
one, ten, hund, minor);
|
2006-01-09 21:03:41 +00:00
|
|
|
}
|
|
|
|
unset_command_mode();
|
2006-02-12 15:47:34 +00:00
|
|
|
|
|
|
|
return;
|
2006-01-09 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcwd_get_option_switches(void)
|
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
int option_switches = 0;
|
2006-01-09 21:03:41 +00:00
|
|
|
|
|
|
|
if (set_command_mode()) {
|
|
|
|
/* Get switch settings */
|
|
|
|
option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
unset_command_mode();
|
2008-08-06 20:19:41 +00:00
|
|
|
return option_switches;
|
2006-01-09 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pcwd_show_card_info(void)
|
|
|
|
{
|
|
|
|
int option_switches;
|
|
|
|
|
|
|
|
/* Get some extra info from the hardware (in command/debug/diag mode) */
|
|
|
|
if (pcwd_private.revision == PCWD_REVISION_A)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("ISA-PC Watchdog (REV.A) detected at port 0x%04x\n",
|
|
|
|
pcwd_private.io_addr);
|
2006-01-09 21:03:41 +00:00
|
|
|
else if (pcwd_private.revision == PCWD_REVISION_C) {
|
2006-02-12 15:47:34 +00:00
|
|
|
pcwd_get_firmware();
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
|
2006-02-12 15:47:34 +00:00
|
|
|
pcwd_private.io_addr, pcwd_private.fw_ver_str);
|
2006-01-09 21:03:41 +00:00
|
|
|
option_switches = pcwd_get_option_switches();
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
|
2006-01-09 21:03:41 +00:00
|
|
|
option_switches,
|
|
|
|
((option_switches & 0x10) ? "ON" : "OFF"),
|
|
|
|
((option_switches & 0x08) ? "ON" : "OFF"));
|
|
|
|
|
|
|
|
/* Reprogram internal heartbeat to 2 seconds */
|
|
|
|
if (set_command_mode()) {
|
|
|
|
send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
|
|
|
|
unset_command_mode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcwd_private.supports_temp)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Temperature Option Detected\n");
|
2006-01-09 21:03:41 +00:00
|
|
|
|
|
|
|
if (pcwd_private.boot_status & WDIOF_CARDRESET)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Previous reboot was caused by the card\n");
|
2006-01-09 21:03:41 +00:00
|
|
|
|
|
|
|
if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_emerg("Card senses a CPU Overheat. Panicking!\n");
|
|
|
|
pr_emerg("CPU Overheat\n");
|
2006-01-09 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pcwd_private.boot_status == 0)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("No previous trip detected - Cold boot or reset\n");
|
2006-01-09 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
static void pcwd_timer_ping(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int wdrst_stat;
|
|
|
|
|
|
|
|
/* If we got a heartbeat pulse within the WDT_INTERVAL
|
|
|
|
* we agree to ping the WDT */
|
2008-05-19 13:07:43 +00:00
|
|
|
if (time_before(jiffies, pcwd_private.next_heartbeat)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Ping the watchdog */
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
if (pcwd_private.revision == PCWD_REVISION_A) {
|
2008-05-19 13:07:43 +00:00
|
|
|
/* Rev A cards are reset by setting the
|
|
|
|
WD_WDRST bit in register 1 */
|
2006-01-09 20:53:33 +00:00
|
|
|
wdrst_stat = inb_p(pcwd_private.io_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
wdrst_stat &= 0x0F;
|
|
|
|
wdrst_stat |= WD_WDRST;
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(wdrst_stat, pcwd_private.io_addr + 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
/* Re-trigger watchdog by writing to port 0 */
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(0x00, pcwd_private.io_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-set the timer interval */
|
2006-01-09 20:53:33 +00:00
|
|
|
mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_warn("Heartbeat lost! Will not ping the watchdog\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_start(void)
|
|
|
|
{
|
|
|
|
int stat_reg;
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Start the timer */
|
2006-01-09 20:53:33 +00:00
|
|
|
mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Enable the port */
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.revision == PCWD_REVISION_C) {
|
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
outb_p(0x00, pcwd_private.io_addr + 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
2006-01-09 20:53:33 +00:00
|
|
|
stat_reg = inb_p(pcwd_private.io_addr + 2);
|
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2006-01-09 20:56:09 +00:00
|
|
|
if (stat_reg & WD_WDIS) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Could not start watchdog\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 16:12:55 +00:00
|
|
|
|
|
|
|
if (debug >= VERBOSE)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("Watchdog started\n");
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_stop(void)
|
|
|
|
{
|
|
|
|
int stat_reg;
|
|
|
|
|
|
|
|
/* Stop the timer */
|
2006-01-09 20:53:33 +00:00
|
|
|
del_timer(&pcwd_private.timer);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Disable the board */
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.revision == PCWD_REVISION_C) {
|
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
outb_p(0xA5, pcwd_private.io_addr + 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
2006-01-09 20:53:33 +00:00
|
|
|
outb_p(0xA5, pcwd_private.io_addr + 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
udelay(ISA_COMMAND_TIMEOUT);
|
2006-01-09 20:53:33 +00:00
|
|
|
stat_reg = inb_p(pcwd_private.io_addr + 2);
|
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2006-01-09 20:56:09 +00:00
|
|
|
if ((stat_reg & WD_WDIS) == 0) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Could not stop watchdog\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 16:12:55 +00:00
|
|
|
|
|
|
|
if (debug >= VERBOSE)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("Watchdog stopped\n");
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_keepalive(void)
|
|
|
|
{
|
|
|
|
/* user land ping */
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
|
2006-02-12 16:12:55 +00:00
|
|
|
|
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("Watchdog keepalive signal send\n");
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_set_heartbeat(int t)
|
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
if (t < 2 || t > 7200) /* arbitrary upper limit */
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
heartbeat = t;
|
2006-02-12 16:12:55 +00:00
|
|
|
|
|
|
|
if (debug >= VERBOSE)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("New heartbeat: %d\n", heartbeat);
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_get_status(int *status)
|
|
|
|
{
|
2006-02-12 15:37:36 +00:00
|
|
|
int control_status;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
*status = 0;
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
if (pcwd_private.revision == PCWD_REVISION_A)
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Rev A cards return status information from
|
|
|
|
* the base register, which is used for the
|
|
|
|
* temperature in other cards. */
|
2006-02-12 15:37:36 +00:00
|
|
|
control_status = inb(pcwd_private.io_addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
|
|
|
/* Rev C cards return card status in the base
|
|
|
|
* address + 1 register. And use different bits
|
|
|
|
* to indicate a card initiated reset, and an
|
|
|
|
* over-temperature condition. And the reboot
|
|
|
|
* status can be reset. */
|
2006-02-12 15:37:36 +00:00
|
|
|
control_status = inb(pcwd_private.io_addr + 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.revision == PCWD_REVISION_A) {
|
2006-02-12 15:37:36 +00:00
|
|
|
if (control_status & WD_WDRST)
|
2005-04-16 22:20:36 +00:00
|
|
|
*status |= WDIOF_CARDRESET;
|
|
|
|
|
2006-02-12 15:37:36 +00:00
|
|
|
if (control_status & WD_T110) {
|
2005-04-16 22:20:36 +00:00
|
|
|
*status |= WDIOF_OVERHEAT;
|
|
|
|
if (temp_panic) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Temperature overheat trip!\n");
|
2005-07-26 18:03:08 +00:00
|
|
|
kernel_power_off();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2006-02-12 15:37:36 +00:00
|
|
|
if (control_status & WD_REVC_WTRP)
|
2005-04-16 22:20:36 +00:00
|
|
|
*status |= WDIOF_CARDRESET;
|
|
|
|
|
2006-02-12 15:37:36 +00:00
|
|
|
if (control_status & WD_REVC_TTRP) {
|
2005-04-16 22:20:36 +00:00
|
|
|
*status |= WDIOF_OVERHEAT;
|
|
|
|
if (temp_panic) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Temperature overheat trip!\n");
|
2005-07-26 18:03:08 +00:00
|
|
|
kernel_power_off();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_clear_status(void)
|
|
|
|
{
|
2006-02-12 15:37:36 +00:00
|
|
|
int control_status;
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.revision == PCWD_REVISION_C) {
|
|
|
|
spin_lock(&pcwd_private.io_lock);
|
2006-02-12 15:37:36 +00:00
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= VERBOSE)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("clearing watchdog trip status\n");
|
2006-02-12 16:12:55 +00:00
|
|
|
|
2006-02-12 15:37:36 +00:00
|
|
|
control_status = inb_p(pcwd_private.io_addr + 1);
|
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= DEBUG) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("status was: 0x%02x\n", control_status);
|
|
|
|
pr_debug("sending: 0x%02x\n",
|
|
|
|
(control_status & WD_REVC_R2DS));
|
2006-02-12 16:12:55 +00:00
|
|
|
}
|
|
|
|
|
2006-02-12 15:37:36 +00:00
|
|
|
/* clear reset status & Keep Relay 2 disable state as it is */
|
2008-05-19 13:07:43 +00:00
|
|
|
outb_p((control_status & WD_REVC_R2DS),
|
|
|
|
pcwd_private.io_addr + 1);
|
2006-02-12 15:37:36 +00:00
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_get_temperature(int *temperature)
|
|
|
|
{
|
|
|
|
/* check that port 0 gives temperature info and no command results */
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.command_mode)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
*temperature = 0;
|
2006-01-09 20:53:33 +00:00
|
|
|
if (!pcwd_private.supports_temp)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert celsius to fahrenheit, since this was
|
|
|
|
* the decided 'standard' for this return value.
|
|
|
|
*/
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
|
|
|
*temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
|
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-02-12 16:12:55 +00:00
|
|
|
if (debug >= DEBUG) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("temperature is: %d F\n", *temperature);
|
2006-02-12 16:12:55 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /dev/watchdog handling
|
|
|
|
*/
|
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
static long pcwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
int status;
|
|
|
|
int temperature;
|
|
|
|
int new_heartbeat;
|
|
|
|
int __user *argp = (int __user *)arg;
|
2009-12-26 18:55:22 +00:00
|
|
|
static const struct watchdog_info ident = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.options = WDIOF_OVERHEAT |
|
|
|
|
WDIOF_CARDRESET |
|
|
|
|
WDIOF_KEEPALIVEPING |
|
|
|
|
WDIOF_SETTIMEOUT |
|
|
|
|
WDIOF_MAGICCLOSE,
|
|
|
|
.firmware_version = 1,
|
|
|
|
.identity = "PCWD",
|
|
|
|
};
|
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
switch (cmd) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case WDIOC_GETSUPPORT:
|
2008-05-19 13:07:43 +00:00
|
|
|
if (copy_to_user(argp, &ident, sizeof(ident)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WDIOC_GETSTATUS:
|
|
|
|
pcwd_get_status(&status);
|
|
|
|
return put_user(status, argp);
|
|
|
|
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
2006-01-09 20:53:33 +00:00
|
|
|
return put_user(pcwd_private.boot_status, argp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case WDIOC_GETTEMP:
|
|
|
|
if (pcwd_get_temperature(&temperature))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return put_user(temperature, argp);
|
|
|
|
|
|
|
|
case WDIOC_SETOPTIONS:
|
2008-05-19 13:07:43 +00:00
|
|
|
if (pcwd_private.revision == PCWD_REVISION_C) {
|
|
|
|
if (get_user(rv, argp))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
if (rv & WDIOS_DISABLECARD) {
|
|
|
|
status = pcwd_stop();
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-05-19 13:07:43 +00:00
|
|
|
if (rv & WDIOS_ENABLECARD) {
|
|
|
|
status = pcwd_start();
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (rv & WDIOS_TEMPPANIC)
|
|
|
|
temp_panic = 1;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
case WDIOC_KEEPALIVE:
|
|
|
|
pcwd_keepalive();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
|
|
if (get_user(new_heartbeat, argp))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (pcwd_set_heartbeat(new_heartbeat))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pcwd_keepalive();
|
2020-07-07 17:11:21 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
return put_user(heartbeat, argp);
|
2008-07-18 11:41:17 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
if (len) {
|
|
|
|
if (!nowayout) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* In case it was set long ago */
|
|
|
|
expect_close = 0;
|
|
|
|
|
|
|
|
for (i = 0; i != len; i++) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (get_user(c, buf + i))
|
|
|
|
return -EFAULT;
|
|
|
|
if (c == 'V')
|
|
|
|
expect_close = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pcwd_keepalive();
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
if (test_and_set_bit(0, &open_allowed))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
|
|
|
if (nowayout)
|
|
|
|
__module_get(THIS_MODULE);
|
|
|
|
/* Activate */
|
|
|
|
pcwd_start();
|
|
|
|
pcwd_keepalive();
|
2019-03-26 20:51:19 +00:00
|
|
|
return stream_open(inode, file);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
if (expect_close == 42)
|
2005-04-16 22:20:36 +00:00
|
|
|
pcwd_stop();
|
2008-05-19 13:07:43 +00:00
|
|
|
else {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_crit("Unexpected close, not stopping watchdog!\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
pcwd_keepalive();
|
|
|
|
}
|
|
|
|
expect_close = 0;
|
2008-05-19 13:07:43 +00:00
|
|
|
clear_bit(0, &open_allowed);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /dev/temperature handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
int temperature;
|
|
|
|
|
|
|
|
if (pcwd_get_temperature(&temperature))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (copy_to_user(buf, &temperature, 1))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_temp_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2006-01-09 20:53:33 +00:00
|
|
|
if (!pcwd_private.supports_temp)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2019-03-26 20:51:19 +00:00
|
|
|
return stream_open(inode, file);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pcwd_temp_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel Interfaces
|
|
|
|
*/
|
|
|
|
|
2006-07-03 07:24:21 +00:00
|
|
|
static const struct file_operations pcwd_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.write = pcwd_write,
|
2008-05-19 13:07:43 +00:00
|
|
|
.unlocked_ioctl = pcwd_ioctl,
|
2019-06-03 12:23:09 +00:00
|
|
|
.compat_ioctl = compat_ptr_ioctl,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = pcwd_open,
|
|
|
|
.release = pcwd_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice pcwd_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &pcwd_fops,
|
|
|
|
};
|
|
|
|
|
2006-07-03 07:24:21 +00:00
|
|
|
static const struct file_operations pcwd_temp_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = pcwd_temp_read,
|
|
|
|
.open = pcwd_temp_open,
|
|
|
|
.release = pcwd_temp_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice temp_miscdev = {
|
|
|
|
.minor = TEMP_MINOR,
|
|
|
|
.name = "temperature",
|
|
|
|
.fops = &pcwd_temp_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init & exit routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int get_revision(void)
|
|
|
|
{
|
|
|
|
int r = PCWD_REVISION_C;
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_lock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* REV A cards use only 2 io ports; test
|
|
|
|
* presumes a floating bus reads as 0xff. */
|
2006-01-09 20:53:33 +00:00
|
|
|
if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
|
|
|
|
(inb(pcwd_private.io_addr + 3) == 0xFF))
|
2008-05-19 13:07:43 +00:00
|
|
|
r = PCWD_REVISION_A;
|
2006-01-09 20:53:33 +00:00
|
|
|
spin_unlock(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
/*
|
|
|
|
* The ISA cards have a heartbeat bit in one of the registers, which
|
|
|
|
* register is card dependent. The heartbeat bit is monitored, and if
|
|
|
|
* found, is considered proof that a Berkshire card has been found.
|
|
|
|
* The initial rate is once per second at board start up, then twice
|
|
|
|
* per second for normal operation.
|
|
|
|
*/
|
2012-11-19 18:21:41 +00:00
|
|
|
static int pcwd_isa_match(struct device *dev, unsigned int id)
|
2007-05-05 05:48:23 +00:00
|
|
|
{
|
2008-05-19 13:07:43 +00:00
|
|
|
int base_addr = pcwd_ioports[id];
|
2007-05-05 05:48:23 +00:00
|
|
|
int port0, last_port0; /* Reg 0, in case it's REV A */
|
|
|
|
int port1, last_port1; /* Register 1 for REV C cards */
|
|
|
|
int i;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("pcwd_isa_match id=%d\n", id);
|
2007-05-05 05:48:23 +00:00
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
if (!request_region(base_addr, 4, "PCWD")) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("Port 0x%04x unavailable\n", base_addr);
|
2007-05-05 05:48:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
port0 = inb_p(base_addr); /* For REV A boards */
|
|
|
|
port1 = inb_p(base_addr + 1); /* For REV C boards */
|
|
|
|
if (port0 != 0xff || port1 != 0xff) {
|
|
|
|
/* Not an 'ff' from a floating bus, so must be a card! */
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
|
|
|
|
msleep(500);
|
|
|
|
|
|
|
|
last_port0 = port0;
|
|
|
|
last_port1 = port1;
|
|
|
|
|
|
|
|
port0 = inb_p(base_addr);
|
|
|
|
port1 = inb_p(base_addr + 1);
|
|
|
|
|
|
|
|
/* Has either hearbeat bit changed? */
|
|
|
|
if ((port0 ^ last_port0) & WD_HRTBT ||
|
|
|
|
(port1 ^ last_port1) & WD_REVC_HRBT) {
|
|
|
|
retval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-19 13:07:43 +00:00
|
|
|
release_region(base_addr, 4);
|
2007-05-05 05:48:23 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:21:41 +00:00
|
|
|
static int pcwd_isa_probe(struct device *dev, unsigned int id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("pcwd_isa_probe id=%d\n", id);
|
2007-05-05 05:48:23 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
cards_found++;
|
|
|
|
if (cards_found == 1)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("v%s Ken Hollis (kenji@bitgate.com)\n",
|
2009-03-18 08:35:09 +00:00
|
|
|
WATCHDOG_VERSION);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cards_found > 1) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("This driver only supports 1 device\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
if (pcwd_ioports[id] == 0x0000) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("No I/O-Address for card detected\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2007-05-05 05:48:23 +00:00
|
|
|
pcwd_private.io_addr = pcwd_ioports[id];
|
|
|
|
|
|
|
|
spin_lock_init(&pcwd_private.io_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Check card's revision */
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.revision = get_revision();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
if (!request_region(pcwd_private.io_addr,
|
|
|
|
(pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("I/O address 0x%04x already in use\n",
|
|
|
|
pcwd_private.io_addr);
|
2008-05-19 13:07:43 +00:00
|
|
|
ret = -EIO;
|
2007-05-05 05:48:23 +00:00
|
|
|
goto error_request_region;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initial variables */
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.supports_temp = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
temp_panic = 0;
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.boot_status = 0x0000;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* get the boot_status */
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_get_status(&pcwd_private.boot_status);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* clear the "card caused reboot" flag */
|
|
|
|
pcwd_clear_status();
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
timer_setup(&pcwd_private.timer, pcwd_timer_ping, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Disable the board */
|
|
|
|
pcwd_stop();
|
|
|
|
|
|
|
|
/* Check whether or not the card supports the temperature device */
|
2006-01-09 20:59:39 +00:00
|
|
|
pcwd_check_temperature_support();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 21:03:41 +00:00
|
|
|
/* Show info about the card itself */
|
|
|
|
pcwd_show_card_info();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-01-09 21:43:49 +00:00
|
|
|
/* If heartbeat = 0 then we use the heartbeat from the dip-switches */
|
|
|
|
if (heartbeat == 0)
|
|
|
|
heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
|
|
|
|
|
2008-05-19 13:07:43 +00:00
|
|
|
/* Check that the heartbeat value is within it's range;
|
|
|
|
if not reset to the default */
|
2005-12-10 13:22:37 +00:00
|
|
|
if (pcwd_set_heartbeat(heartbeat)) {
|
|
|
|
pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("heartbeat value must be 2 <= heartbeat <= 7200, using %d\n",
|
|
|
|
WATCHDOG_HEARTBEAT);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.supports_temp) {
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = misc_register(&temp_miscdev);
|
|
|
|
if (ret) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("cannot register miscdev on minor=%d (err=%d)\n",
|
|
|
|
TEMP_MINOR, ret);
|
2007-05-05 05:48:23 +00:00
|
|
|
goto error_misc_register_temp;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = misc_register(&pcwd_miscdev);
|
|
|
|
if (ret) {
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_err("cannot register miscdev on minor=%d (err=%d)\n",
|
|
|
|
WATCHDOG_MINOR, ret);
|
2007-05-05 05:48:23 +00:00
|
|
|
goto error_misc_register_watchdog;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
heartbeat, nowayout);
|
|
|
|
|
|
|
|
return 0;
|
2007-05-05 05:48:23 +00:00
|
|
|
|
|
|
|
error_misc_register_watchdog:
|
|
|
|
if (pcwd_private.supports_temp)
|
|
|
|
misc_deregister(&temp_miscdev);
|
|
|
|
error_misc_register_temp:
|
2008-05-19 13:07:43 +00:00
|
|
|
release_region(pcwd_private.io_addr,
|
|
|
|
(pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
|
2007-05-05 05:48:23 +00:00
|
|
|
error_request_region:
|
|
|
|
pcwd_private.io_addr = 0x0000;
|
|
|
|
cards_found--;
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:24 +00:00
|
|
|
static int pcwd_isa_remove(struct device *dev, unsigned int id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-05-05 05:48:23 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("pcwd_isa_remove id=%d\n", id);
|
2007-05-05 05:48:23 +00:00
|
|
|
|
|
|
|
if (!pcwd_private.io_addr)
|
|
|
|
return 1;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Disable the board */
|
|
|
|
if (!nowayout)
|
|
|
|
pcwd_stop();
|
|
|
|
|
|
|
|
/* Deregister */
|
|
|
|
misc_deregister(&pcwd_miscdev);
|
2006-01-09 20:53:33 +00:00
|
|
|
if (pcwd_private.supports_temp)
|
2005-04-16 22:20:36 +00:00
|
|
|
misc_deregister(&temp_miscdev);
|
2008-05-19 13:07:43 +00:00
|
|
|
release_region(pcwd_private.io_addr,
|
|
|
|
(pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
|
2006-01-09 20:53:33 +00:00
|
|
|
pcwd_private.io_addr = 0x0000;
|
2005-12-10 13:36:24 +00:00
|
|
|
cards_found--;
|
2007-05-05 05:48:23 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
static void pcwd_isa_shutdown(struct device *dev, unsigned int id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-05-05 05:48:23 +00:00
|
|
|
if (debug >= DEBUG)
|
2012-02-15 23:06:19 +00:00
|
|
|
pr_debug("pcwd_isa_shutdown id=%d\n", id);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
pcwd_stop();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-05 05:48:23 +00:00
|
|
|
static struct isa_driver pcwd_isa_driver = {
|
|
|
|
.match = pcwd_isa_match,
|
|
|
|
.probe = pcwd_isa_probe,
|
2012-11-19 18:21:12 +00:00
|
|
|
.remove = pcwd_isa_remove,
|
2007-05-05 05:48:23 +00:00
|
|
|
.shutdown = pcwd_isa_shutdown,
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = WATCHDOG_NAME,
|
|
|
|
},
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-01 13:05:48 +00:00
|
|
|
module_isa_driver(pcwd_isa_driver, PCWD_ISA_NR_CARDS);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-18 08:35:09 +00:00
|
|
|
MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, "
|
|
|
|
"Wim Van Sebroeck <wim@iguana.be>");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
|
2007-05-05 05:48:23 +00:00
|
|
|
MODULE_VERSION(WATCHDOG_VERSION);
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_LICENSE("GPL");
|