watchdog_core.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * watchdog_core.c
  3. *
  4. * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
  5. * All Rights Reserved.
  6. *
  7. * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
  8. *
  9. * This source code is part of the generic code that can be used
  10. * by all the watchdog timer drivers.
  11. *
  12. * Based on source code of the following authors:
  13. * Matt Domsch <Matt_Domsch@dell.com>,
  14. * Rob Radez <rob@osinvestor.com>,
  15. * Rusty Lynch <rusty@linux.co.intel.com>
  16. * Satyam Sharma <satyam@infradead.org>
  17. * Randy Dunlap <randy.dunlap@oracle.com>
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version
  22. * 2 of the License, or (at your option) any later version.
  23. *
  24. * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
  25. * admit liability nor provide warranty for any of this software.
  26. * This material is provided "AS-IS" and at no charge.
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/module.h> /* For EXPORT_SYMBOL/module stuff/... */
  30. #include <linux/types.h> /* For standard types */
  31. #include <linux/errno.h> /* For the -ENODEV/... values */
  32. #include <linux/kernel.h> /* For printk/panic/... */
  33. #include <linux/watchdog.h> /* For watchdog specific items */
  34. #include <linux/init.h> /* For __init/__exit/... */
  35. #include "watchdog_dev.h" /* For watchdog_dev_register/... */
  36. /**
  37. * watchdog_register_device() - register a watchdog device
  38. * @wdd: watchdog device
  39. *
  40. * Register a watchdog device with the kernel so that the
  41. * watchdog timer can be accessed from userspace.
  42. *
  43. * A zero is returned on success and a negative errno code for
  44. * failure.
  45. */
  46. int watchdog_register_device(struct watchdog_device *wdd)
  47. {
  48. int ret;
  49. if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
  50. return -EINVAL;
  51. /* Mandatory operations need to be supported */
  52. if (wdd->ops->start == NULL || wdd->ops->stop == NULL)
  53. return -EINVAL;
  54. /*
  55. * Check that we have valid min and max timeout values, if
  56. * not reset them both to 0 (=not used or unknown)
  57. */
  58. if (wdd->min_timeout > wdd->max_timeout) {
  59. pr_info("Invalid min and max timeout values, resetting to 0!\n");
  60. wdd->min_timeout = 0;
  61. wdd->max_timeout = 0;
  62. }
  63. /*
  64. * Note: now that all watchdog_device data has been verified, we
  65. * will not check this anymore in other functions. If data gets
  66. * corrupted in a later stage then we expect a kernel panic!
  67. */
  68. /* We only support 1 watchdog device via the /dev/watchdog interface */
  69. ret = watchdog_dev_register(wdd);
  70. if (ret) {
  71. pr_err("error registering /dev/watchdog (err=%d)\n", ret);
  72. return ret;
  73. }
  74. return 0;
  75. }
  76. EXPORT_SYMBOL_GPL(watchdog_register_device);
  77. /**
  78. * watchdog_unregister_device() - unregister a watchdog device
  79. * @wdd: watchdog device to unregister
  80. *
  81. * Unregister a watchdog device that was previously successfully
  82. * registered with watchdog_register_device().
  83. */
  84. void watchdog_unregister_device(struct watchdog_device *wdd)
  85. {
  86. int ret;
  87. if (wdd == NULL)
  88. return;
  89. ret = watchdog_dev_unregister(wdd);
  90. if (ret)
  91. pr_err("error unregistering /dev/watchdog (err=%d)\n", ret);
  92. }
  93. EXPORT_SYMBOL_GPL(watchdog_unregister_device);
  94. MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
  95. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  96. MODULE_DESCRIPTION("WatchDog Timer Driver Core");
  97. MODULE_LICENSE("GPL");