iTCO_vendor_support.c 11 KB

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