iTCO_vendor_support.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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.04"
  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. /* Broken BIOS */
  42. #define BROKEN_BIOS 911
  43. static int vendorsupport;
  44. module_param(vendorsupport, int, 0);
  45. MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default="
  46. "0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+, "
  47. "911=Broken SMI BIOS");
  48. /*
  49. * Vendor Specific Support
  50. */
  51. /*
  52. * Vendor Support: 1
  53. * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
  54. * iTCO chipset: ICH2
  55. *
  56. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  57. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  58. *
  59. * To enable Watchdog function:
  60. * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
  61. * This setting enables SMI to clear the watchdog expired flag.
  62. * If BIOS or CPU fail which may cause SMI hang, then system will
  63. * reboot. When application starts to use watchdog function,
  64. * application has to take over the control from SMI.
  65. *
  66. * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
  67. * function.
  68. *
  69. * Note: The system will reboot when Expire Flag is set TWICE.
  70. * So, if the watchdog timer is 20 seconds, then the maximum hang
  71. * time is about 40 seconds, and the minimum hang time is about
  72. * 20.6 seconds.
  73. */
  74. static void supermicro_old_pre_start(unsigned long acpibase)
  75. {
  76. unsigned long val32;
  77. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
  78. val32 = inl(SMI_EN);
  79. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  80. outl(val32, SMI_EN); /* Needed to activate watchdog */
  81. }
  82. static void supermicro_old_pre_stop(unsigned long acpibase)
  83. {
  84. unsigned long val32;
  85. /* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
  86. val32 = inl(SMI_EN);
  87. val32 |= 0x00002000; /* Turn on SMI clearing watchdog */
  88. outl(val32, SMI_EN); /* Needed to deactivate watchdog */
  89. }
  90. static void supermicro_old_pre_keepalive(unsigned long acpibase)
  91. {
  92. /* Reload TCO Timer (done in iTCO_wdt_keepalive) + */
  93. /* Clear "Expire Flag" (Bit 3 of TC01_STS register) */
  94. outb(0x08, TCO1_STS);
  95. }
  96. /*
  97. * Vendor Support: 2
  98. * Board: Super Micro Computer Inc. P4SBx, P4DPx
  99. * iTCO chipset: ICH4
  100. *
  101. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  102. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  103. *
  104. * To enable Watchdog function:
  105. * 1. BIOS
  106. * For P4SBx:
  107. * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
  108. * For P4DPx:
  109. * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
  110. * This setting enables or disables Watchdog function. When enabled, the
  111. * default watchdog timer is set to be 5 minutes (about 4m35s). It is
  112. * enough to load and run the OS. The application (service or driver) has
  113. * to take over the control once OS is running up and before watchdog
  114. * expires.
  115. *
  116. * 2. JUMPER
  117. * For P4SBx: JP39
  118. * For P4DPx: JP37
  119. * This jumper is used for safety. Closed is enabled. This jumper
  120. * prevents user enables watchdog in BIOS by accident.
  121. *
  122. * To enable Watch Dog function, both BIOS and JUMPER must be enabled.
  123. *
  124. * The documentation lists motherboards P4SBx and P4DPx series as of
  125. * 20-March-2002. However, this code works flawlessly with much newer
  126. * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
  127. *
  128. * The original iTCO driver as written does not actually reset the
  129. * watchdog timer on these machines, as a result they reboot after five
  130. * minutes.
  131. *
  132. * NOTE: You may leave the Watchdog function disabled in the SuperMicro
  133. * BIOS to avoid a "boot-race"... This driver will enable watchdog
  134. * functionality even if it's disabled in the BIOS once the /dev/watchdog
  135. * file is opened.
  136. */
  137. /* I/O Port's */
  138. #define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */
  139. #define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */
  140. /* Control Register's */
  141. #define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */
  142. #define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */
  143. #define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */
  144. #define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */
  145. #define SM_ENDWATCH 0xAA /* Watchdog lock control page */
  146. #define SM_COUNTMODE 0xf5 /* Watchdog count mode select */
  147. /* (Bit 3: 0 = seconds, 1 = minutes */
  148. #define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */
  149. #define SM_RESETCONTROL 0xf7 /* Watchdog reset control */
  150. /* Bit 6: timer is reset by kbd interrupt */
  151. /* Bit 7: timer is reset by mouse interrupt */
  152. static void supermicro_new_unlock_watchdog(void)
  153. {
  154. /* Write 0x87 to port 0x2e twice */
  155. outb(SM_WATCHPAGE, SM_REGINDEX);
  156. outb(SM_WATCHPAGE, SM_REGINDEX);
  157. /* Switch to watchdog control page */
  158. outb(SM_CTLPAGESW, SM_REGINDEX);
  159. outb(SM_CTLPAGE, SM_DATAIO);
  160. }
  161. static void supermicro_new_lock_watchdog(void)
  162. {
  163. outb(SM_ENDWATCH, SM_REGINDEX);
  164. }
  165. static void supermicro_new_pre_start(unsigned int heartbeat)
  166. {
  167. unsigned int val;
  168. supermicro_new_unlock_watchdog();
  169. /* Watchdog timer setting needs to be in seconds*/
  170. outb(SM_COUNTMODE, SM_REGINDEX);
  171. val = inb(SM_DATAIO);
  172. val &= 0xF7;
  173. outb(val, SM_DATAIO);
  174. /* Write heartbeat interval to WDOG */
  175. outb(SM_WATCHTIMER, SM_REGINDEX);
  176. outb((heartbeat & 255), SM_DATAIO);
  177. /* Make sure keyboard/mouse interrupts don't interfere */
  178. outb(SM_RESETCONTROL, SM_REGINDEX);
  179. val = inb(SM_DATAIO);
  180. val &= 0x3f;
  181. outb(val, SM_DATAIO);
  182. /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
  183. outb(SM_WATCHENABLE, SM_REGINDEX);
  184. val = inb(SM_DATAIO);
  185. val |= 0x01;
  186. outb(val, SM_DATAIO);
  187. supermicro_new_lock_watchdog();
  188. }
  189. static void supermicro_new_pre_stop(void)
  190. {
  191. unsigned int val;
  192. supermicro_new_unlock_watchdog();
  193. /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
  194. outb(SM_WATCHENABLE, SM_REGINDEX);
  195. val = inb(SM_DATAIO);
  196. val &= 0xFE;
  197. outb(val, SM_DATAIO);
  198. supermicro_new_lock_watchdog();
  199. }
  200. static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
  201. {
  202. supermicro_new_unlock_watchdog();
  203. /* reset watchdog timeout to heartveat value */
  204. outb(SM_WATCHTIMER, SM_REGINDEX);
  205. outb((heartbeat & 255), SM_DATAIO);
  206. supermicro_new_lock_watchdog();
  207. }
  208. /*
  209. * Vendor Support: 911
  210. * Board: Some Intel ICHx based motherboards
  211. * iTCO chipset: ICH7+
  212. *
  213. * Some Intel motherboards have a broken BIOS implementation: i.e.
  214. * the SMI handler clear's the TIMEOUT bit in the TC01_STS register
  215. * and does not reload the time. Thus the TCO watchdog does not reboot
  216. * the system.
  217. *
  218. * These are the conclusions of Andriy Gapon <avg@icyb.net.ua> after
  219. * debugging: the SMI handler is quite simple - it tests value in
  220. * TCO1_CNT against 0x800, i.e. checks TCO_TMR_HLT. If the bit is set
  221. * the handler goes into an infinite loop, apparently to allow the
  222. * second timeout and reboot. Otherwise it simply clears TIMEOUT bit
  223. * in TCO1_STS and that's it.
  224. * So the logic seems to be reversed, because it is hard to see how
  225. * TIMEOUT can get set to 1 and SMI generated when TCO_TMR_HLT is set
  226. * (other than a transitional effect).
  227. *
  228. * The only fix found to get the motherboard(s) to reboot is to put
  229. * the glb_smi_en bit to 0. This is a dirty hack that bypasses the
  230. * broken code by disabling Global SMI.
  231. *
  232. * WARNING: globally disabling SMI could possibly lead to dramatic
  233. * problems, especially on laptops! I.e. various ACPI things where
  234. * SMI is used for communication between OS and firmware.
  235. *
  236. * Don't use this fix if you don't need to!!!
  237. */
  238. static void broken_bios_start(unsigned long acpibase)
  239. {
  240. unsigned long val32;
  241. val32 = inl(SMI_EN);
  242. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI#
  243. Bit 0: GBL_SMI_EN -> 0 = No SMI# will be generated by ICH. */
  244. val32 &= 0xffffdffe;
  245. outl(val32, SMI_EN);
  246. }
  247. static void broken_bios_stop(unsigned long acpibase)
  248. {
  249. unsigned long val32;
  250. val32 = inl(SMI_EN);
  251. /* Bit 13: TCO_EN -> 1 = Enables TCO logic generating an SMI#
  252. Bit 0: GBL_SMI_EN -> 1 = Turn global SMI on again. */
  253. val32 |= 0x00002001;
  254. outl(val32, SMI_EN);
  255. }
  256. /*
  257. * Generic Support Functions
  258. */
  259. void iTCO_vendor_pre_start(unsigned long acpibase,
  260. unsigned int heartbeat)
  261. {
  262. switch (vendorsupport) {
  263. case SUPERMICRO_OLD_BOARD:
  264. supermicro_old_pre_start(acpibase);
  265. break;
  266. case SUPERMICRO_NEW_BOARD:
  267. supermicro_new_pre_start(heartbeat);
  268. break;
  269. case BROKEN_BIOS:
  270. broken_bios_start(acpibase);
  271. break;
  272. }
  273. }
  274. EXPORT_SYMBOL(iTCO_vendor_pre_start);
  275. void iTCO_vendor_pre_stop(unsigned long acpibase)
  276. {
  277. switch (vendorsupport) {
  278. case SUPERMICRO_OLD_BOARD:
  279. supermicro_old_pre_stop(acpibase);
  280. break;
  281. case SUPERMICRO_NEW_BOARD:
  282. supermicro_new_pre_stop();
  283. break;
  284. case BROKEN_BIOS:
  285. broken_bios_stop(acpibase);
  286. break;
  287. }
  288. }
  289. EXPORT_SYMBOL(iTCO_vendor_pre_stop);
  290. void iTCO_vendor_pre_keepalive(unsigned long acpibase, unsigned int heartbeat)
  291. {
  292. if (vendorsupport == SUPERMICRO_OLD_BOARD)
  293. supermicro_old_pre_keepalive(acpibase);
  294. else if (vendorsupport == SUPERMICRO_NEW_BOARD)
  295. supermicro_new_pre_set_heartbeat(heartbeat);
  296. }
  297. EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
  298. void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
  299. {
  300. if (vendorsupport == SUPERMICRO_NEW_BOARD)
  301. supermicro_new_pre_set_heartbeat(heartbeat);
  302. }
  303. EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
  304. int iTCO_vendor_check_noreboot_on(void)
  305. {
  306. switch (vendorsupport) {
  307. case SUPERMICRO_OLD_BOARD:
  308. return 0;
  309. default:
  310. return 1;
  311. }
  312. }
  313. EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
  314. static int __init iTCO_vendor_init_module(void)
  315. {
  316. printk(KERN_INFO PFX "vendor-support=%d\n", vendorsupport);
  317. return 0;
  318. }
  319. static void __exit iTCO_vendor_exit_module(void)
  320. {
  321. printk(KERN_INFO PFX "Module Unloaded\n");
  322. }
  323. module_init(iTCO_vendor_init_module);
  324. module_exit(iTCO_vendor_exit_module);
  325. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, "
  326. "R. Seretny <lkpatches@paypc.com>");
  327. MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
  328. MODULE_VERSION(DRV_VERSION);
  329. MODULE_LICENSE("GPL");