watchdog.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Generic watchdog defines. Derived from..
  3. *
  4. * Berkshire PC Watchdog Defines
  5. * by Ken Hollis <khollis@bitgate.com>
  6. *
  7. */
  8. #ifndef _LINUX_WATCHDOG_H
  9. #define _LINUX_WATCHDOG_H
  10. #include <linux/bitops.h>
  11. #include <linux/device.h>
  12. #include <linux/cdev.h>
  13. #include <uapi/linux/watchdog.h>
  14. struct watchdog_ops;
  15. struct watchdog_device;
  16. /** struct watchdog_ops - The watchdog-devices operations
  17. *
  18. * @owner: The module owner.
  19. * @start: The routine for starting the watchdog device.
  20. * @stop: The routine for stopping the watchdog device.
  21. * @ping: The routine that sends a keepalive ping to the watchdog device.
  22. * @status: The routine that shows the status of the watchdog device.
  23. * @set_timeout:The routine for setting the watchdog devices timeout value.
  24. * @get_timeleft:The routine that get's the time that's left before a reset.
  25. * @ref: The ref operation for dyn. allocated watchdog_device structs
  26. * @unref: The unref operation for dyn. allocated watchdog_device structs
  27. * @ioctl: The routines that handles extra ioctl calls.
  28. *
  29. * The watchdog_ops structure contains a list of low-level operations
  30. * that control a watchdog device. It also contains the module that owns
  31. * these operations. The start and stop function are mandatory, all other
  32. * functions are optonal.
  33. */
  34. struct watchdog_ops {
  35. struct module *owner;
  36. /* mandatory operations */
  37. int (*start)(struct watchdog_device *);
  38. int (*stop)(struct watchdog_device *);
  39. /* optional operations */
  40. int (*ping)(struct watchdog_device *);
  41. unsigned int (*status)(struct watchdog_device *);
  42. int (*set_timeout)(struct watchdog_device *, unsigned int);
  43. unsigned int (*get_timeleft)(struct watchdog_device *);
  44. void (*ref)(struct watchdog_device *);
  45. void (*unref)(struct watchdog_device *);
  46. long (*ioctl)(struct watchdog_device *, unsigned int, unsigned long);
  47. };
  48. /** struct watchdog_device - The structure that defines a watchdog device
  49. *
  50. * @id: The watchdog's ID. (Allocated by watchdog_register_device)
  51. * @cdev: The watchdog's Character device.
  52. * @dev: The device for our watchdog
  53. * @parent: The parent bus device
  54. * @info: Pointer to a watchdog_info structure.
  55. * @ops: Pointer to the list of watchdog operations.
  56. * @bootstatus: Status of the watchdog device at boot.
  57. * @timeout: The watchdog devices timeout value.
  58. * @min_timeout:The watchdog devices minimum timeout value.
  59. * @max_timeout:The watchdog devices maximum timeout value.
  60. * @driver-data:Pointer to the drivers private data.
  61. * @lock: Lock for watchdog core internal use only.
  62. * @status: Field that contains the devices internal status bits.
  63. *
  64. * The watchdog_device structure contains all information about a
  65. * watchdog timer device.
  66. *
  67. * The driver-data field may not be accessed directly. It must be accessed
  68. * via the watchdog_set_drvdata and watchdog_get_drvdata helpers.
  69. *
  70. * The lock field is for watchdog core internal use only and should not be
  71. * touched.
  72. */
  73. struct watchdog_device {
  74. int id;
  75. struct cdev cdev;
  76. struct device *dev;
  77. struct device *parent;
  78. const struct watchdog_info *info;
  79. const struct watchdog_ops *ops;
  80. unsigned int bootstatus;
  81. unsigned int timeout;
  82. unsigned int min_timeout;
  83. unsigned int max_timeout;
  84. void *driver_data;
  85. struct mutex lock;
  86. unsigned long status;
  87. /* Bit numbers for status flags */
  88. #define WDOG_ACTIVE 0 /* Is the watchdog running/active */
  89. #define WDOG_DEV_OPEN 1 /* Opened via /dev/watchdog ? */
  90. #define WDOG_ALLOW_RELEASE 2 /* Did we receive the magic char ? */
  91. #define WDOG_NO_WAY_OUT 3 /* Is 'nowayout' feature set ? */
  92. #define WDOG_UNREGISTERED 4 /* Has the device been unregistered */
  93. };
  94. #ifdef CONFIG_WATCHDOG_NOWAYOUT
  95. #define WATCHDOG_NOWAYOUT 1
  96. #define WATCHDOG_NOWAYOUT_INIT_STATUS (1 << WDOG_NO_WAY_OUT)
  97. #else
  98. #define WATCHDOG_NOWAYOUT 0
  99. #define WATCHDOG_NOWAYOUT_INIT_STATUS 0
  100. #endif
  101. /* Use the following function to check whether or not the watchdog is active */
  102. static inline bool watchdog_active(struct watchdog_device *wdd)
  103. {
  104. return test_bit(WDOG_ACTIVE, &wdd->status);
  105. }
  106. /* Use the following function to set the nowayout feature */
  107. static inline void watchdog_set_nowayout(struct watchdog_device *wdd, bool nowayout)
  108. {
  109. if (nowayout)
  110. set_bit(WDOG_NO_WAY_OUT, &wdd->status);
  111. }
  112. /* Use the following function to check if a timeout value is invalid */
  113. static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigned int t)
  114. {
  115. return ((wdd->max_timeout != 0) &&
  116. (t < wdd->min_timeout || t > wdd->max_timeout));
  117. }
  118. /* Use the following functions to manipulate watchdog driver specific data */
  119. static inline void watchdog_set_drvdata(struct watchdog_device *wdd, void *data)
  120. {
  121. wdd->driver_data = data;
  122. }
  123. static inline void *watchdog_get_drvdata(struct watchdog_device *wdd)
  124. {
  125. return wdd->driver_data;
  126. }
  127. /* drivers/watchdog/watchdog_core.c */
  128. extern int watchdog_init_timeout(struct watchdog_device *wdd,
  129. unsigned int timeout_parm, struct device *dev);
  130. extern int watchdog_register_device(struct watchdog_device *);
  131. extern void watchdog_unregister_device(struct watchdog_device *);
  132. #endif /* ifndef _LINUX_WATCHDOG_H */