iTCO_vendor_support.c 9.3 KB

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