All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/10 v2] Generic Watchdog Timer Driver
@ 2011-06-18 17:20 Wim Van Sebroeck
  2011-06-18 19:01 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Wim Van Sebroeck @ 2011-06-18 17:20 UTC (permalink / raw)
  To: LKML, Linux Watchdog Mailing List; +Cc: Alan Cox

watchdog: WatchDog Timer Driver Core - Part 2

This part add's the basic ioctl functionality to the
WatchDog Timer Driver Core framework. The supported
ioctl call's are:
	WDIOC_GETSUPPORT
	WDIOC_GETSTATUS
	WDIOC_GETBOOTSTATUS

Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

diff -urN linux-2.6.38-generic-part1/Documentation/watchdog/src/watchdog-with-timer-example.c linux-2.6.38-generic-part2/Documentation/watchdog/src/watchdog-with-timer-example.c
--- linux-2.6.38-generic-part1/Documentation/watchdog/src/watchdog-with-timer-example.c	2011-06-16 20:07:33.939170516 +0200
+++ linux-2.6.38-generic-part2/Documentation/watchdog/src/watchdog-with-timer-example.c	2011-06-16 20:07:44.671177621 +0200
@@ -115,6 +115,10 @@
 /*
  * The watchdog kernel structures
  */
+static const struct watchdog_info wdt_info = {
+	.identity =	DRV_NAME,
+};
+
 static const struct watchdog_ops wdt_ops = {
 	.owner =	THIS_MODULE,
 	.start =	wdt_start,
@@ -124,6 +128,7 @@
 
 static struct watchdog_device wdt_dev = {
 	.name =		DRV_NAME,
+	.info =		&wdt_info,
 	.ops =		&wdt_ops,
 };
 
diff -urN linux-2.6.38-generic-part1/Documentation/watchdog/watchdog-kernel-api.txt linux-2.6.38-generic-part2/Documentation/watchdog/watchdog-kernel-api.txt
--- linux-2.6.38-generic-part1/Documentation/watchdog/watchdog-kernel-api.txt	2011-06-16 14:26:05.928061789 +0200
+++ linux-2.6.38-generic-part2/Documentation/watchdog/watchdog-kernel-api.txt	2011-06-16 16:57:31.388541823 +0200
@@ -40,13 +40,19 @@
 
 struct watchdog_device {
 	char *name;
+	const struct watchdog_info *info;
 	const struct watchdog_ops *ops;
+	int bootstatus;
 	long status;
 };
 
 It contains following fields:
 * name: a pointer to the (preferably unique) name of the watchdog timer device.
+* info: a pointer to a watchdog_info structure. This structure gives some
+  additional information about the watchdog timer itself.
 * ops: a pointer to the list of watchdog operations that the watchdog supports.
+* bootstatus: status of the device after booting (reported with watchdog
+  WDIOF_* status bits).
 * status: this field contains a number of status bits that give extra
   information about the status of the device (Like: is the device opened via
   the /dev/watchdog interface or not, ...)
@@ -60,6 +66,7 @@
 	int (*stop)(struct watchdog_device *);
 	/* optional operations */
 	int (*ping)(struct watchdog_device *);
+	int (*status)(struct watchdog_device *);
 };
 
 It is important that you first define the module owner of the watchdog timer
@@ -94,6 +101,8 @@
   the watchdog timer driver core does: to send a keepalive ping to the watchdog
   timer hardware it will either use the ping operation (when available) or the
   start operation (when the ping operation is not available).
+* status: this routine checks the status of the watchdog timer device. The
+  status of the device is reported with watchdog WDIOF_* status flags/bits.
 
 The status bits should (preferably) be set with the set_bit and clear_bit alike
 bit-operations. The status bit's that are defined are:
diff -urN linux-2.6.38-generic-part1/drivers/watchdog/core/watchdog_core.c linux-2.6.38-generic-part2/drivers/watchdog/core/watchdog_core.c
--- linux-2.6.38-generic-part1/drivers/watchdog/core/watchdog_core.c	2011-06-16 19:24:39.955179826 +0200
+++ linux-2.6.38-generic-part2/drivers/watchdog/core/watchdog_core.c	2011-06-16 19:33:08.647178048 +0200
@@ -59,7 +59,7 @@
 	int ret;
 
 	/* Make sure we have a valid watchdog_device structure */
-	if (wdd == NULL || wdd->ops == NULL)
+	if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
 		return -ENODATA;
 
 	/* Make sure that the mandatory operations are supported */
diff -urN linux-2.6.38-generic-part1/drivers/watchdog/core/watchdog_dev.c linux-2.6.38-generic-part2/drivers/watchdog/core/watchdog_dev.c
--- linux-2.6.38-generic-part1/drivers/watchdog/core/watchdog_dev.c	2011-06-16 19:32:27.183186141 +0200
+++ linux-2.6.38-generic-part2/drivers/watchdog/core/watchdog_dev.c	2011-06-16 19:34:22.927178838 +0200
@@ -125,6 +125,41 @@
 }
 
 /*
+ *	watchdog_ioctl: handle the different ioctl's for the watchdog device.
+ *	@file: file handle to the device
+ *	@cmd: watchdog command
+ *	@arg: argument pointer
+ *
+ *	The watchdog API defines a common set of functions for all watchdogs
+ *	according to their available features.
+ */
+
+static long watchdog_ioctl(struct file *file, unsigned int cmd,
+							unsigned long arg)
+{
+	void __user *argp = (void __user *)arg;
+	int __user *p = argp;
+	int val = 0;
+
+	trace("%p, %u, %li", file, cmd, arg);
+
+	switch (cmd) {
+	case WDIOC_GETSUPPORT:
+		return copy_to_user(argp, wdd->info,
+			sizeof(struct watchdog_info)) ? -EFAULT : 0;
+	case WDIOC_GETSTATUS:
+		if (wdd->ops->status)
+			val = wdd->ops->status(wdd);
+		return put_user(val, p);
+	case WDIOC_GETBOOTSTATUS:
+		return put_user(wdd->bootstatus, p);
+	default:
+		return -ENOTTY;
+	}
+	return -ENOTTY;
+}
+
+/*
  *	watchdog_open: open the /dev/watchdog device.
  *	@inode: inode of device
  *	@file: file handle to device
@@ -202,6 +237,7 @@
 	.owner		= THIS_MODULE,
 	.llseek		= no_llseek,
 	.write		= watchdog_write,
+	.unlocked_ioctl	= watchdog_ioctl,
 	.open		= watchdog_open,
 	.release	= watchdog_release,
 };
diff -urN linux-2.6.38-generic-part1/include/linux/watchdog.h linux-2.6.38-generic-part2/include/linux/watchdog.h
--- linux-2.6.38-generic-part1/include/linux/watchdog.h	2011-06-16 14:28:32.848061741 +0200
+++ linux-2.6.38-generic-part2/include/linux/watchdog.h	2011-06-16 16:57:31.388541823 +0200
@@ -70,12 +70,15 @@
 	int (*stop)(struct watchdog_device *);
 	/* optional operations */
 	int (*ping)(struct watchdog_device *);
+	int (*status)(struct watchdog_device *);
 };
 
 /* The structure that defines a watchdog device */
 struct watchdog_device {
 	char *name;
+	const struct watchdog_info *info;
 	const struct watchdog_ops *ops;
+	int bootstatus;
 	long status;
 #define WDOG_DEV_OPEN		1	/* is the watchdog opened via
 					 * /dev/watchdog */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/10 v2] Generic Watchdog Timer Driver
  2011-06-18 17:20 [PATCH 2/10 v2] Generic Watchdog Timer Driver Wim Van Sebroeck
@ 2011-06-18 19:01 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2011-06-18 19:01 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: LKML, Linux Watchdog Mailing List, Alan Cox

On Saturday 18 June 2011 19:20:43 Wim Van Sebroeck wrote:

> +/*
>   *	watchdog_open: open the /dev/watchdog device.
>   *	@inode: inode of device
>   *	@file: file handle to device
> @@ -202,6 +237,7 @@
>  	.owner		= THIS_MODULE,
>  	.llseek		= no_llseek,
>  	.write		= watchdog_write,
> +	.unlocked_ioctl	= watchdog_ioctl,
>  	.open		= watchdog_open,
>  	.release	= watchdog_release,
>  };

All the ioctl commands are compatible with their 32 bit counterparts, so
you can just set ".compat_ioctl = watchdog_ioctl" here to slightly speed
up the ioctl operation for compat tasks.

Looks good otherwise.

	Arnd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-18 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-18 17:20 [PATCH 2/10 v2] Generic Watchdog Timer Driver Wim Van Sebroeck
2011-06-18 19:01 ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.