iTCO_vendor_support.c 9.2 KB

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