iTCO_vendor_support.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * intel TCO vendor specific watchdog driver support
  3. *
  4. * (c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
  12. * provide warranty for any of this software. This material is
  13. * provided "AS-IS" and at no charge.
  14. */
  15. /*
  16. * Includes, defines, variables, module parameters, ...
  17. */
  18. /* Module and version information */
  19. #define DRV_NAME "iTCO_vendor_support"
  20. #define DRV_VERSION "1.03"
  21. #define PFX DRV_NAME ": "
  22. /* Includes */
  23. #include <linux/module.h> /* For module specific items */
  24. #include <linux/moduleparam.h> /* For new moduleparam's */
  25. #include <linux/types.h> /* For standard types (like size_t) */
  26. #include <linux/errno.h> /* For the -ENODEV/... values */
  27. #include <linux/kernel.h> /* For printk/panic/... */
  28. #include <linux/init.h> /* For __init/__exit/... */
  29. #include <linux/ioport.h> /* For io-port access */
  30. #include <linux/io.h> /* For inb/outb/... */
  31. #include "iTCO_vendor.h"
  32. /* iTCO defines */
  33. #define SMI_EN acpibase + 0x30 /* SMI Control and Enable Register */
  34. #define TCOBASE acpibase + 0x60 /* TCO base address */
  35. #define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */
  36. /* List of vendor support modes */
  37. /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
  38. #define SUPERMICRO_OLD_BOARD 1
  39. /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */
  40. #define SUPERMICRO_NEW_BOARD 2
  41. static int vendorsupport;
  42. module_param(vendorsupport, int, 0);
  43. MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default=0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+");
  44. /*
  45. * Vendor Specific Support
  46. */
  47. /*
  48. * Vendor Support: 1
  49. * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
  50. * iTCO chipset: ICH2
  51. *
  52. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  53. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  54. *
  55. * To enable Watchdog function:
  56. * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
  57. * This setting enables SMI to clear the watchdog expired flag.
  58. * If BIOS or CPU fail which may cause SMI hang, then system will
  59. * reboot. When application starts to use watchdog function,
  60. * application has to take over the control from SMI.
  61. *
  62. * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
  63. * function.
  64. *
  65. * Note: The system will reboot when Expire Flag is set TWICE.
  66. * So, if the watchdog timer is 20 seconds, then the maximum hang
  67. * time is about 40 seconds, and the minimum hang time is about
  68. * 20.6 seconds.
  69. */
  70. static void supermicro_old_pre_start(unsigned long acpibase)
  71. {
  72. unsigned long val32;
  73. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
  74. val32 = inl(SMI_EN);
  75. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  76. outl(val32, SMI_EN); /* Needed to activate watchdog */
  77. }
  78. static void supermicro_old_pre_stop(unsigned long acpibase)
  79. {
  80. unsigned long val32;
  81. /* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
  82. val32 = inl(SMI_EN);
  83. val32 |= 0x00002000; /* Turn on SMI clearing watchdog */
  84. outl(val32, SMI_EN); /* Needed to deactivate watchdog */
  85. }
  86. static void supermicro_old_pre_keepalive(unsigned long acpibase)
  87. {
  88. /* Reload TCO Timer (done in iTCO_wdt_keepalive) + */
  89. /* Clear "Expire Flag" (Bit 3 of TC01_STS register) */
  90. outb(0x08, TCO1_STS);
  91. }
  92. /*
  93. * Vendor Support: 2
  94. * Board: Super Micro Computer Inc. P4SBx, P4DPx
  95. * iTCO chipset: ICH4
  96. *
  97. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  98. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  99. *
  100. * To enable Watchdog function:
  101. * 1. BIOS
  102. * For P4SBx:
  103. * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
  104. * For P4DPx:
  105. * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
  106. * This setting enables or disables Watchdog function. When enabled, the
  107. * default watchdog timer is set to be 5 minutes (about 4m35s). It is
  108. * enough to load and run the OS. The application (service or driver) has
  109. * to take over the control once OS is running up and before watchdog
  110. * expires.
  111. *
  112. * 2. JUMPER
  113. * For P4SBx: JP39
  114. * For P4DPx: JP37
  115. * This jumper is used for safety. Closed is enabled. This jumper
  116. * prevents user enables watchdog in BIOS by accident.
  117. *
  118. * To enable Watch Dog function, both BIOS and JUMPER must be enabled.
  119. *
  120. * The documentation lists motherboards P4SBx and P4DPx series as of
  121. * 20-March-2002. However, this code works flawlessly with much newer
  122. * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
  123. *
  124. * The original iTCO driver as written does not actually reset the
  125. * watchdog timer on these machines, as a result they reboot after five
  126. * minutes.
  127. *
  128. * NOTE: You may leave the Watchdog function disabled in the SuperMicro
  129. * BIOS to avoid a "boot-race"... This driver will enable watchdog
  130. * functionality even if it's disabled in the BIOS once the /dev/watchdog
  131. * file is opened.
  132. */
  133. /* I/O Port's */
  134. #define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */
  135. #define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */
  136. /* Control Register's */
  137. #define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */
  138. #define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */
  139. #define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */
  140. #define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */
  141. #define SM_ENDWATCH 0xAA /* Watchdog lock control page */
  142. #define SM_COUNTMODE 0xf5 /* Watchdog count mode select */
  143. /* (Bit 3: 0 = seconds, 1 = minutes */
  144. #define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */
  145. #define SM_RESETCONTROL 0xf7 /* Watchdog reset control */
  146. /* Bit 6: timer is reset by kbd interrupt */
  147. /* Bit 7: timer is reset by mouse interrupt */
  148. static void supermicro_new_unlock_watchdog(void)
  149. {
  150. /* Write 0x87 to port 0x2e twice */
  151. outb(SM_WATCHPAGE, SM_REGINDEX);
  152. outb(SM_WATCHPAGE, SM_REGINDEX);
  153. /* Switch to watchdog control page */
  154. outb(SM_CTLPAGESW, SM_REGINDEX);
  155. outb(SM_CTLPAGE, SM_DATAIO);
  156. }
  157. static void supermicro_new_lock_watchdog(void)
  158. {
  159. outb(SM_ENDWATCH, SM_REGINDEX);
  160. }
  161. static void supermicro_new_pre_start(unsigned int heartbeat)
  162. {
  163. unsigned int val;
  164. supermicro_new_unlock_watchdog();
  165. /* Watchdog timer setting needs to be in seconds*/
  166. outb(SM_COUNTMODE, SM_REGINDEX);
  167. val = inb(SM_DATAIO);
  168. val &= 0xF7;
  169. outb(val, SM_DATAIO);
  170. /* Write heartbeat interval to WDOG */
  171. outb(SM_WATCHTIMER, SM_REGINDEX);
  172. outb((heartbeat & 255), SM_DATAIO);
  173. /* Make sure keyboard/mouse interrupts don't interfere */
  174. outb(SM_RESETCONTROL, SM_REGINDEX);
  175. val = inb(SM_DATAIO);
  176. val &= 0x3f;
  177. outb(val, SM_DATAIO);
  178. /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
  179. outb(SM_WATCHENABLE, SM_REGINDEX);
  180. val = inb(SM_DATAIO);
  181. val |= 0x01;
  182. outb(val, SM_DATAIO);
  183. supermicro_new_lock_watchdog();
  184. }
  185. static void supermicro_new_pre_stop(void)
  186. {
  187. unsigned int val;
  188. supermicro_new_unlock_watchdog();
  189. /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
  190. outb(SM_WATCHENABLE, SM_REGINDEX);
  191. val = inb(SM_DATAIO);
  192. val &= 0xFE;
  193. outb(val, SM_DATAIO);
  194. supermicro_new_lock_watchdog();
  195. }
  196. static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
  197. {
  198. supermicro_new_unlock_watchdog();
  199. /* reset watchdog timeout to heartveat value */
  200. outb(SM_WATCHTIMER, SM_REGINDEX);
  201. outb((heartbeat & 255), SM_DATAIO);
  202. supermicro_new_lock_watchdog();
  203. }
  204. /*
  205. * Generic Support Functions
  206. */
  207. void iTCO_vendor_pre_start(unsigned long acpibase,
  208. unsigned int heartbeat)
  209. {
  210. if (vendorsupport == SUPERMICRO_OLD_BOARD)
  211. supermicro_old_pre_start(acpibase);
  212. else if (vendorsupport == SUPERMICRO_NEW_BOARD)
  213. supermicro_new_pre_start(heartbeat);
  214. }
  215. EXPORT_SYMBOL(iTCO_vendor_pre_start);
  216. void iTCO_vendor_pre_stop(unsigned long acpibase)
  217. {
  218. if (vendorsupport == SUPERMICRO_OLD_BOARD)
  219. supermicro_old_pre_stop(acpibase);
  220. else if (vendorsupport == SUPERMICRO_NEW_BOARD)
  221. supermicro_new_pre_stop();
  222. }
  223. EXPORT_SYMBOL(iTCO_vendor_pre_stop);
  224. void iTCO_vendor_pre_keepalive(unsigned long acpibase, unsigned int heartbeat)
  225. {
  226. if (vendorsupport == SUPERMICRO_OLD_BOARD)
  227. supermicro_old_pre_keepalive(acpibase);
  228. else if (vendorsupport == SUPERMICRO_NEW_BOARD)
  229. supermicro_new_pre_set_heartbeat(heartbeat);
  230. }
  231. EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
  232. void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
  233. {
  234. if (vendorsupport == SUPERMICRO_NEW_BOARD)
  235. supermicro_new_pre_set_heartbeat(heartbeat);
  236. }
  237. EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
  238. int iTCO_vendor_check_noreboot_on(void)
  239. {
  240. switch (vendorsupport) {
  241. case SUPERMICRO_OLD_BOARD:
  242. return 0;
  243. default:
  244. return 1;
  245. }
  246. }
  247. EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
  248. static int __init iTCO_vendor_init_module(void)
  249. {
  250. printk(KERN_INFO PFX "vendor-support=%d\n", vendorsupport);
  251. return 0;
  252. }
  253. static void __exit iTCO_vendor_exit_module(void)
  254. {
  255. printk(KERN_INFO PFX "Module Unloaded\n");
  256. }
  257. module_init(iTCO_vendor_init_module);
  258. module_exit(iTCO_vendor_exit_module);
  259. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, R. Seretny <lkpatches@paypc.com>");
  260. MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
  261. MODULE_VERSION(DRV_VERSION);
  262. MODULE_LICENSE("GPL");