iTCO_vendor_support.c 9.1 KB

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