watchdog_core.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Note: now that all watchdog_device data has been verified, we
  56. * will not check this anymore in other functions. If data gets
  57. * corrupted in a later stage then we expect a kernel panic!
  58. */
  59. /* We only support 1 watchdog device via the /dev/watchdog interface */
  60. ret = watchdog_dev_register(wdd);
  61. if (ret) {
  62. pr_err("error registering /dev/watchdog (err=%d).\n", ret);
  63. return ret;
  64. }
  65. return 0;
  66. }
  67. EXPORT_SYMBOL_GPL(watchdog_register_device);
  68. /**
  69. * watchdog_unregister_device() - unregister a watchdog device
  70. * @wdd: watchdog device to unregister
  71. *
  72. * Unregister a watchdog device that was previously successfully
  73. * registered with watchdog_register_device().
  74. */
  75. void watchdog_unregister_device(struct watchdog_device *wdd)
  76. {
  77. int ret;
  78. if (wdd == NULL)
  79. return;
  80. ret = watchdog_dev_unregister(wdd);
  81. if (ret)
  82. pr_err("error unregistering /dev/watchdog (err=%d).\n", ret);
  83. }
  84. EXPORT_SYMBOL_GPL(watchdog_unregister_device);
  85. MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
  86. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  87. MODULE_DESCRIPTION("WatchDog Timer Driver Core");
  88. MODULE_LICENSE("GPL");