iTCO_wdt.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. /*
  2. * intel TCO Watchdog Driver
  3. *
  4. * (c) Copyright 2006-2011 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. * The TCO watchdog is implemented in the following I/O controller hubs:
  16. * (See the intel documentation on http://developer.intel.com.)
  17. * document number 290655-003, 290677-014: 82801AA (ICH), 82801AB (ICHO)
  18. * document number 290687-002, 298242-027: 82801BA (ICH2)
  19. * document number 290733-003, 290739-013: 82801CA (ICH3-S)
  20. * document number 290716-001, 290718-007: 82801CAM (ICH3-M)
  21. * document number 290744-001, 290745-025: 82801DB (ICH4)
  22. * document number 252337-001, 252663-008: 82801DBM (ICH4-M)
  23. * document number 273599-001, 273645-002: 82801E (C-ICH)
  24. * document number 252516-001, 252517-028: 82801EB (ICH5), 82801ER (ICH5R)
  25. * document number 300641-004, 300884-013: 6300ESB
  26. * document number 301473-002, 301474-026: 82801F (ICH6)
  27. * document number 313082-001, 313075-006: 631xESB, 632xESB
  28. * document number 307013-003, 307014-024: 82801G (ICH7)
  29. * document number 322896-001, 322897-001: NM10
  30. * document number 313056-003, 313057-017: 82801H (ICH8)
  31. * document number 316972-004, 316973-012: 82801I (ICH9)
  32. * document number 319973-002, 319974-002: 82801J (ICH10)
  33. * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
  34. * document number 320066-003, 320257-008: EP80597 (IICH)
  35. * document number 324645-001, 324646-001: Cougar Point (CPT)
  36. * document number TBD : Patsburg (PBG)
  37. * document number TBD : DH89xxCC
  38. * document number TBD : Panther Point
  39. */
  40. /*
  41. * Includes, defines, variables, module parameters, ...
  42. */
  43. /* Module and version information */
  44. #define DRV_NAME "iTCO_wdt"
  45. #define DRV_VERSION "1.07"
  46. #define PFX DRV_NAME ": "
  47. /* Includes */
  48. #include <linux/module.h> /* For module specific items */
  49. #include <linux/moduleparam.h> /* For new moduleparam's */
  50. #include <linux/types.h> /* For standard types (like size_t) */
  51. #include <linux/errno.h> /* For the -ENODEV/... values */
  52. #include <linux/kernel.h> /* For printk/panic/... */
  53. #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
  54. (WATCHDOG_MINOR) */
  55. #include <linux/watchdog.h> /* For the watchdog specific items */
  56. #include <linux/init.h> /* For __init/__exit/... */
  57. #include <linux/fs.h> /* For file operations */
  58. #include <linux/platform_device.h> /* For platform_driver framework */
  59. #include <linux/pci.h> /* For pci functions */
  60. #include <linux/ioport.h> /* For io-port access */
  61. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  62. #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
  63. #include <linux/io.h> /* For inb/outb/... */
  64. #include "iTCO_vendor.h"
  65. /* TCO related info */
  66. enum iTCO_chipsets {
  67. TCO_ICH = 0, /* ICH */
  68. TCO_ICH0, /* ICH0 */
  69. TCO_ICH2, /* ICH2 */
  70. TCO_ICH2M, /* ICH2-M */
  71. TCO_ICH3, /* ICH3-S */
  72. TCO_ICH3M, /* ICH3-M */
  73. TCO_ICH4, /* ICH4 */
  74. TCO_ICH4M, /* ICH4-M */
  75. TCO_CICH, /* C-ICH */
  76. TCO_ICH5, /* ICH5 & ICH5R */
  77. TCO_6300ESB, /* 6300ESB */
  78. TCO_ICH6, /* ICH6 & ICH6R */
  79. TCO_ICH6M, /* ICH6-M */
  80. TCO_ICH6W, /* ICH6W & ICH6RW */
  81. TCO_631XESB, /* 631xESB/632xESB */
  82. TCO_ICH7, /* ICH7 & ICH7R */
  83. TCO_ICH7DH, /* ICH7DH */
  84. TCO_ICH7M, /* ICH7-M & ICH7-U */
  85. TCO_ICH7MDH, /* ICH7-M DH */
  86. TCO_NM10, /* NM10 */
  87. TCO_ICH8, /* ICH8 & ICH8R */
  88. TCO_ICH8DH, /* ICH8DH */
  89. TCO_ICH8DO, /* ICH8DO */
  90. TCO_ICH8M, /* ICH8M */
  91. TCO_ICH8ME, /* ICH8M-E */
  92. TCO_ICH9, /* ICH9 */
  93. TCO_ICH9R, /* ICH9R */
  94. TCO_ICH9DH, /* ICH9DH */
  95. TCO_ICH9DO, /* ICH9DO */
  96. TCO_ICH9M, /* ICH9M */
  97. TCO_ICH9ME, /* ICH9M-E */
  98. TCO_ICH10, /* ICH10 */
  99. TCO_ICH10R, /* ICH10R */
  100. TCO_ICH10D, /* ICH10D */
  101. TCO_ICH10DO, /* ICH10DO */
  102. TCO_PCH, /* PCH Desktop Full Featured */
  103. TCO_PCHM, /* PCH Mobile Full Featured */
  104. TCO_P55, /* P55 */
  105. TCO_PM55, /* PM55 */
  106. TCO_H55, /* H55 */
  107. TCO_QM57, /* QM57 */
  108. TCO_H57, /* H57 */
  109. TCO_HM55, /* HM55 */
  110. TCO_Q57, /* Q57 */
  111. TCO_HM57, /* HM57 */
  112. TCO_PCHMSFF, /* PCH Mobile SFF Full Featured */
  113. TCO_QS57, /* QS57 */
  114. TCO_3400, /* 3400 */
  115. TCO_3420, /* 3420 */
  116. TCO_3450, /* 3450 */
  117. TCO_EP80579, /* EP80579 */
  118. TCO_CPT, /* Cougar Point */
  119. TCO_CPTD, /* Cougar Point Desktop */
  120. TCO_CPTM, /* Cougar Point Mobile */
  121. TCO_PBG, /* Patsburg */
  122. TCO_DH89XXCC, /* DH89xxCC */
  123. TCO_PPT, /* Panther Point */
  124. };
  125. static struct {
  126. char *name;
  127. unsigned int iTCO_version;
  128. } iTCO_chipset_info[] __devinitdata = {
  129. {"ICH", 1},
  130. {"ICH0", 1},
  131. {"ICH2", 1},
  132. {"ICH2-M", 1},
  133. {"ICH3-S", 1},
  134. {"ICH3-M", 1},
  135. {"ICH4", 1},
  136. {"ICH4-M", 1},
  137. {"C-ICH", 1},
  138. {"ICH5 or ICH5R", 1},
  139. {"6300ESB", 1},
  140. {"ICH6 or ICH6R", 2},
  141. {"ICH6-M", 2},
  142. {"ICH6W or ICH6RW", 2},
  143. {"631xESB/632xESB", 2},
  144. {"ICH7 or ICH7R", 2},
  145. {"ICH7DH", 2},
  146. {"ICH7-M or ICH7-U", 2},
  147. {"ICH7-M DH", 2},
  148. {"NM10", 2},
  149. {"ICH8 or ICH8R", 2},
  150. {"ICH8DH", 2},
  151. {"ICH8DO", 2},
  152. {"ICH8M", 2},
  153. {"ICH8M-E", 2},
  154. {"ICH9", 2},
  155. {"ICH9R", 2},
  156. {"ICH9DH", 2},
  157. {"ICH9DO", 2},
  158. {"ICH9M", 2},
  159. {"ICH9M-E", 2},
  160. {"ICH10", 2},
  161. {"ICH10R", 2},
  162. {"ICH10D", 2},
  163. {"ICH10DO", 2},
  164. {"PCH Desktop Full Featured", 2},
  165. {"PCH Mobile Full Featured", 2},
  166. {"P55", 2},
  167. {"PM55", 2},
  168. {"H55", 2},
  169. {"QM57", 2},
  170. {"H57", 2},
  171. {"HM55", 2},
  172. {"Q57", 2},
  173. {"HM57", 2},
  174. {"PCH Mobile SFF Full Featured", 2},
  175. {"QS57", 2},
  176. {"3400", 2},
  177. {"3420", 2},
  178. {"3450", 2},
  179. {"EP80579", 2},
  180. {"Cougar Point", 2},
  181. {"Cougar Point Desktop", 2},
  182. {"Cougar Point Mobile", 2},
  183. {"Patsburg", 2},
  184. {"DH89xxCC", 2},
  185. {"Panther Point", 2},
  186. {NULL, 0}
  187. };
  188. /*
  189. * This data only exists for exporting the supported PCI ids
  190. * via MODULE_DEVICE_TABLE. We do not actually register a
  191. * pci_driver, because the I/O Controller Hub has also other
  192. * functions that probably will be registered by other drivers.
  193. */
  194. static DEFINE_PCI_DEVICE_TABLE(iTCO_wdt_pci_tbl) = {
  195. { PCI_VDEVICE(INTEL, 0x2410), TCO_ICH},
  196. { PCI_VDEVICE(INTEL, 0x2420), TCO_ICH0},
  197. { PCI_VDEVICE(INTEL, 0x2440), TCO_ICH2},
  198. { PCI_VDEVICE(INTEL, 0x244c), TCO_ICH2M},
  199. { PCI_VDEVICE(INTEL, 0x2480), TCO_ICH3},
  200. { PCI_VDEVICE(INTEL, 0x248c), TCO_ICH3M},
  201. { PCI_VDEVICE(INTEL, 0x24c0), TCO_ICH4},
  202. { PCI_VDEVICE(INTEL, 0x24cc), TCO_ICH4M},
  203. { PCI_VDEVICE(INTEL, 0x2450), TCO_CICH},
  204. { PCI_VDEVICE(INTEL, 0x24d0), TCO_ICH5},
  205. { PCI_VDEVICE(INTEL, 0x25a1), TCO_6300ESB},
  206. { PCI_VDEVICE(INTEL, 0x2640), TCO_ICH6},
  207. { PCI_VDEVICE(INTEL, 0x2641), TCO_ICH6M},
  208. { PCI_VDEVICE(INTEL, 0x2642), TCO_ICH6W},
  209. { PCI_VDEVICE(INTEL, 0x2670), TCO_631XESB},
  210. { PCI_VDEVICE(INTEL, 0x2671), TCO_631XESB},
  211. { PCI_VDEVICE(INTEL, 0x2672), TCO_631XESB},
  212. { PCI_VDEVICE(INTEL, 0x2673), TCO_631XESB},
  213. { PCI_VDEVICE(INTEL, 0x2674), TCO_631XESB},
  214. { PCI_VDEVICE(INTEL, 0x2675), TCO_631XESB},
  215. { PCI_VDEVICE(INTEL, 0x2676), TCO_631XESB},
  216. { PCI_VDEVICE(INTEL, 0x2677), TCO_631XESB},
  217. { PCI_VDEVICE(INTEL, 0x2678), TCO_631XESB},
  218. { PCI_VDEVICE(INTEL, 0x2679), TCO_631XESB},
  219. { PCI_VDEVICE(INTEL, 0x267a), TCO_631XESB},
  220. { PCI_VDEVICE(INTEL, 0x267b), TCO_631XESB},
  221. { PCI_VDEVICE(INTEL, 0x267c), TCO_631XESB},
  222. { PCI_VDEVICE(INTEL, 0x267d), TCO_631XESB},
  223. { PCI_VDEVICE(INTEL, 0x267e), TCO_631XESB},
  224. { PCI_VDEVICE(INTEL, 0x267f), TCO_631XESB},
  225. { PCI_VDEVICE(INTEL, 0x27b8), TCO_ICH7},
  226. { PCI_VDEVICE(INTEL, 0x27b0), TCO_ICH7DH},
  227. { PCI_VDEVICE(INTEL, 0x27b9), TCO_ICH7M},
  228. { PCI_VDEVICE(INTEL, 0x27bd), TCO_ICH7MDH},
  229. { PCI_VDEVICE(INTEL, 0x27bc), TCO_NM10},
  230. { PCI_VDEVICE(INTEL, 0x2810), TCO_ICH8},
  231. { PCI_VDEVICE(INTEL, 0x2812), TCO_ICH8DH},
  232. { PCI_VDEVICE(INTEL, 0x2814), TCO_ICH8DO},
  233. { PCI_VDEVICE(INTEL, 0x2815), TCO_ICH8M},
  234. { PCI_VDEVICE(INTEL, 0x2811), TCO_ICH8ME},
  235. { PCI_VDEVICE(INTEL, 0x2918), TCO_ICH9},
  236. { PCI_VDEVICE(INTEL, 0x2916), TCO_ICH9R},
  237. { PCI_VDEVICE(INTEL, 0x2912), TCO_ICH9DH},
  238. { PCI_VDEVICE(INTEL, 0x2914), TCO_ICH9DO},
  239. { PCI_VDEVICE(INTEL, 0x2919), TCO_ICH9M},
  240. { PCI_VDEVICE(INTEL, 0x2917), TCO_ICH9ME},
  241. { PCI_VDEVICE(INTEL, 0x3a18), TCO_ICH10},
  242. { PCI_VDEVICE(INTEL, 0x3a16), TCO_ICH10R},
  243. { PCI_VDEVICE(INTEL, 0x3a1a), TCO_ICH10D},
  244. { PCI_VDEVICE(INTEL, 0x3a14), TCO_ICH10DO},
  245. { PCI_VDEVICE(INTEL, 0x3b00), TCO_PCH},
  246. { PCI_VDEVICE(INTEL, 0x3b01), TCO_PCHM},
  247. { PCI_VDEVICE(INTEL, 0x3b02), TCO_P55},
  248. { PCI_VDEVICE(INTEL, 0x3b03), TCO_PM55},
  249. { PCI_VDEVICE(INTEL, 0x3b06), TCO_H55},
  250. { PCI_VDEVICE(INTEL, 0x3b07), TCO_QM57},
  251. { PCI_VDEVICE(INTEL, 0x3b08), TCO_H57},
  252. { PCI_VDEVICE(INTEL, 0x3b09), TCO_HM55},
  253. { PCI_VDEVICE(INTEL, 0x3b0a), TCO_Q57},
  254. { PCI_VDEVICE(INTEL, 0x3b0b), TCO_HM57},
  255. { PCI_VDEVICE(INTEL, 0x3b0d), TCO_PCHMSFF},
  256. { PCI_VDEVICE(INTEL, 0x3b0f), TCO_QS57},
  257. { PCI_VDEVICE(INTEL, 0x3b12), TCO_3400},
  258. { PCI_VDEVICE(INTEL, 0x3b14), TCO_3420},
  259. { PCI_VDEVICE(INTEL, 0x3b16), TCO_3450},
  260. { PCI_VDEVICE(INTEL, 0x5031), TCO_EP80579},
  261. { PCI_VDEVICE(INTEL, 0x1c41), TCO_CPT},
  262. { PCI_VDEVICE(INTEL, 0x1c42), TCO_CPTD},
  263. { PCI_VDEVICE(INTEL, 0x1c43), TCO_CPTM},
  264. { PCI_VDEVICE(INTEL, 0x1c44), TCO_CPT},
  265. { PCI_VDEVICE(INTEL, 0x1c45), TCO_CPT},
  266. { PCI_VDEVICE(INTEL, 0x1c46), TCO_CPT},
  267. { PCI_VDEVICE(INTEL, 0x1c47), TCO_CPT},
  268. { PCI_VDEVICE(INTEL, 0x1c48), TCO_CPT},
  269. { PCI_VDEVICE(INTEL, 0x1c49), TCO_CPT},
  270. { PCI_VDEVICE(INTEL, 0x1c4a), TCO_CPT},
  271. { PCI_VDEVICE(INTEL, 0x1c4b), TCO_CPT},
  272. { PCI_VDEVICE(INTEL, 0x1c4c), TCO_CPT},
  273. { PCI_VDEVICE(INTEL, 0x1c4d), TCO_CPT},
  274. { PCI_VDEVICE(INTEL, 0x1c4e), TCO_CPT},
  275. { PCI_VDEVICE(INTEL, 0x1c4f), TCO_CPT},
  276. { PCI_VDEVICE(INTEL, 0x1c50), TCO_CPT},
  277. { PCI_VDEVICE(INTEL, 0x1c51), TCO_CPT},
  278. { PCI_VDEVICE(INTEL, 0x1c52), TCO_CPT},
  279. { PCI_VDEVICE(INTEL, 0x1c53), TCO_CPT},
  280. { PCI_VDEVICE(INTEL, 0x1c54), TCO_CPT},
  281. { PCI_VDEVICE(INTEL, 0x1c55), TCO_CPT},
  282. { PCI_VDEVICE(INTEL, 0x1c56), TCO_CPT},
  283. { PCI_VDEVICE(INTEL, 0x1c57), TCO_CPT},
  284. { PCI_VDEVICE(INTEL, 0x1c58), TCO_CPT},
  285. { PCI_VDEVICE(INTEL, 0x1c59), TCO_CPT},
  286. { PCI_VDEVICE(INTEL, 0x1c5a), TCO_CPT},
  287. { PCI_VDEVICE(INTEL, 0x1c5b), TCO_CPT},
  288. { PCI_VDEVICE(INTEL, 0x1c5c), TCO_CPT},
  289. { PCI_VDEVICE(INTEL, 0x1c5d), TCO_CPT},
  290. { PCI_VDEVICE(INTEL, 0x1c5e), TCO_CPT},
  291. { PCI_VDEVICE(INTEL, 0x1c5f), TCO_CPT},
  292. { PCI_VDEVICE(INTEL, 0x1d40), TCO_PBG},
  293. { PCI_VDEVICE(INTEL, 0x1d41), TCO_PBG},
  294. { PCI_VDEVICE(INTEL, 0x2310), TCO_DH89XXCC},
  295. { PCI_VDEVICE(INTEL, 0x1e40), TCO_PPT},
  296. { PCI_VDEVICE(INTEL, 0x1e41), TCO_PPT},
  297. { PCI_VDEVICE(INTEL, 0x1e42), TCO_PPT},
  298. { PCI_VDEVICE(INTEL, 0x1e43), TCO_PPT},
  299. { PCI_VDEVICE(INTEL, 0x1e44), TCO_PPT},
  300. { PCI_VDEVICE(INTEL, 0x1e45), TCO_PPT},
  301. { PCI_VDEVICE(INTEL, 0x1e46), TCO_PPT},
  302. { PCI_VDEVICE(INTEL, 0x1e47), TCO_PPT},
  303. { PCI_VDEVICE(INTEL, 0x1e48), TCO_PPT},
  304. { PCI_VDEVICE(INTEL, 0x1e49), TCO_PPT},
  305. { PCI_VDEVICE(INTEL, 0x1e4a), TCO_PPT},
  306. { PCI_VDEVICE(INTEL, 0x1e4b), TCO_PPT},
  307. { PCI_VDEVICE(INTEL, 0x1e4c), TCO_PPT},
  308. { PCI_VDEVICE(INTEL, 0x1e4d), TCO_PPT},
  309. { PCI_VDEVICE(INTEL, 0x1e4e), TCO_PPT},
  310. { PCI_VDEVICE(INTEL, 0x1e4f), TCO_PPT},
  311. { PCI_VDEVICE(INTEL, 0x1e50), TCO_PPT},
  312. { PCI_VDEVICE(INTEL, 0x1e51), TCO_PPT},
  313. { PCI_VDEVICE(INTEL, 0x1e52), TCO_PPT},
  314. { PCI_VDEVICE(INTEL, 0x1e53), TCO_PPT},
  315. { PCI_VDEVICE(INTEL, 0x1e54), TCO_PPT},
  316. { PCI_VDEVICE(INTEL, 0x1e55), TCO_PPT},
  317. { PCI_VDEVICE(INTEL, 0x1e56), TCO_PPT},
  318. { PCI_VDEVICE(INTEL, 0x1e57), TCO_PPT},
  319. { PCI_VDEVICE(INTEL, 0x1e58), TCO_PPT},
  320. { PCI_VDEVICE(INTEL, 0x1e59), TCO_PPT},
  321. { PCI_VDEVICE(INTEL, 0x1e5a), TCO_PPT},
  322. { PCI_VDEVICE(INTEL, 0x1e5b), TCO_PPT},
  323. { PCI_VDEVICE(INTEL, 0x1e5c), TCO_PPT},
  324. { PCI_VDEVICE(INTEL, 0x1e5d), TCO_PPT},
  325. { PCI_VDEVICE(INTEL, 0x1e5e), TCO_PPT},
  326. { PCI_VDEVICE(INTEL, 0x1e5f), TCO_PPT},
  327. { 0, }, /* End of list */
  328. };
  329. MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
  330. /* Address definitions for the TCO */
  331. /* TCO base address */
  332. #define TCOBASE (iTCO_wdt_private.ACPIBASE + 0x60)
  333. /* SMI Control and Enable Register */
  334. #define SMI_EN (iTCO_wdt_private.ACPIBASE + 0x30)
  335. #define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload and Curr. Value */
  336. #define TCOv1_TMR (TCOBASE + 0x01) /* TCOv1 Timer Initial Value */
  337. #define TCO_DAT_IN (TCOBASE + 0x02) /* TCO Data In Register */
  338. #define TCO_DAT_OUT (TCOBASE + 0x03) /* TCO Data Out Register */
  339. #define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
  340. #define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
  341. #define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
  342. #define TCO2_CNT (TCOBASE + 0x0a) /* TCO2 Control Register */
  343. #define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value */
  344. /* internal variables */
  345. static unsigned long is_active;
  346. static char expect_release;
  347. static struct { /* this is private data for the iTCO_wdt device */
  348. /* TCO version/generation */
  349. unsigned int iTCO_version;
  350. /* The device's ACPIBASE address (TCOBASE = ACPIBASE+0x60) */
  351. unsigned long ACPIBASE;
  352. /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2)*/
  353. unsigned long __iomem *gcs;
  354. /* the lock for io operations */
  355. spinlock_t io_lock;
  356. /* the PCI-device */
  357. struct pci_dev *pdev;
  358. } iTCO_wdt_private;
  359. /* the watchdog platform device */
  360. static struct platform_device *iTCO_wdt_platform_device;
  361. /* module parameters */
  362. #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
  363. static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
  364. module_param(heartbeat, int, 0);
  365. MODULE_PARM_DESC(heartbeat, "Watchdog timeout in seconds. "
  366. "5..76 (TCO v1) or 3..614 (TCO v2), default="
  367. __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
  368. static int nowayout = WATCHDOG_NOWAYOUT;
  369. module_param(nowayout, int, 0);
  370. MODULE_PARM_DESC(nowayout,
  371. "Watchdog cannot be stopped once started (default="
  372. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  373. static int turn_SMI_watchdog_clear_off = 0;
  374. module_param(turn_SMI_watchdog_clear_off, int, 0);
  375. MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
  376. "Turn off SMI clearing watchdog (default=0)");
  377. /*
  378. * Some TCO specific functions
  379. */
  380. static inline unsigned int seconds_to_ticks(int seconds)
  381. {
  382. /* the internal timer is stored as ticks which decrement
  383. * every 0.6 seconds */
  384. return (seconds * 10) / 6;
  385. }
  386. static void iTCO_wdt_set_NO_REBOOT_bit(void)
  387. {
  388. u32 val32;
  389. /* Set the NO_REBOOT bit: this disables reboots */
  390. if (iTCO_wdt_private.iTCO_version == 2) {
  391. val32 = readl(iTCO_wdt_private.gcs);
  392. val32 |= 0x00000020;
  393. writel(val32, iTCO_wdt_private.gcs);
  394. } else if (iTCO_wdt_private.iTCO_version == 1) {
  395. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  396. val32 |= 0x00000002;
  397. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  398. }
  399. }
  400. static int iTCO_wdt_unset_NO_REBOOT_bit(void)
  401. {
  402. int ret = 0;
  403. u32 val32;
  404. /* Unset the NO_REBOOT bit: this enables reboots */
  405. if (iTCO_wdt_private.iTCO_version == 2) {
  406. val32 = readl(iTCO_wdt_private.gcs);
  407. val32 &= 0xffffffdf;
  408. writel(val32, iTCO_wdt_private.gcs);
  409. val32 = readl(iTCO_wdt_private.gcs);
  410. if (val32 & 0x00000020)
  411. ret = -EIO;
  412. } else if (iTCO_wdt_private.iTCO_version == 1) {
  413. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  414. val32 &= 0xfffffffd;
  415. pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
  416. pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
  417. if (val32 & 0x00000002)
  418. ret = -EIO;
  419. }
  420. return ret; /* returns: 0 = OK, -EIO = Error */
  421. }
  422. static int iTCO_wdt_start(void)
  423. {
  424. unsigned int val;
  425. spin_lock(&iTCO_wdt_private.io_lock);
  426. iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
  427. /* disable chipset's NO_REBOOT bit */
  428. if (iTCO_wdt_unset_NO_REBOOT_bit()) {
  429. spin_unlock(&iTCO_wdt_private.io_lock);
  430. printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, "
  431. "reboot disabled by hardware/BIOS\n");
  432. return -EIO;
  433. }
  434. /* Force the timer to its reload value by writing to the TCO_RLD
  435. register */
  436. if (iTCO_wdt_private.iTCO_version == 2)
  437. outw(0x01, TCO_RLD);
  438. else if (iTCO_wdt_private.iTCO_version == 1)
  439. outb(0x01, TCO_RLD);
  440. /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
  441. val = inw(TCO1_CNT);
  442. val &= 0xf7ff;
  443. outw(val, TCO1_CNT);
  444. val = inw(TCO1_CNT);
  445. spin_unlock(&iTCO_wdt_private.io_lock);
  446. if (val & 0x0800)
  447. return -1;
  448. return 0;
  449. }
  450. static int iTCO_wdt_stop(void)
  451. {
  452. unsigned int val;
  453. spin_lock(&iTCO_wdt_private.io_lock);
  454. iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
  455. /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
  456. val = inw(TCO1_CNT);
  457. val |= 0x0800;
  458. outw(val, TCO1_CNT);
  459. val = inw(TCO1_CNT);
  460. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  461. iTCO_wdt_set_NO_REBOOT_bit();
  462. spin_unlock(&iTCO_wdt_private.io_lock);
  463. if ((val & 0x0800) == 0)
  464. return -1;
  465. return 0;
  466. }
  467. static int iTCO_wdt_keepalive(void)
  468. {
  469. spin_lock(&iTCO_wdt_private.io_lock);
  470. iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
  471. /* Reload the timer by writing to the TCO Timer Counter register */
  472. if (iTCO_wdt_private.iTCO_version == 2)
  473. outw(0x01, TCO_RLD);
  474. else if (iTCO_wdt_private.iTCO_version == 1) {
  475. /* Reset the timeout status bit so that the timer
  476. * needs to count down twice again before rebooting */
  477. outw(0x0008, TCO1_STS); /* write 1 to clear bit */
  478. outb(0x01, TCO_RLD);
  479. }
  480. spin_unlock(&iTCO_wdt_private.io_lock);
  481. return 0;
  482. }
  483. static int iTCO_wdt_set_heartbeat(int t)
  484. {
  485. unsigned int val16;
  486. unsigned char val8;
  487. unsigned int tmrval;
  488. tmrval = seconds_to_ticks(t);
  489. /* For TCO v1 the timer counts down twice before rebooting */
  490. if (iTCO_wdt_private.iTCO_version == 1)
  491. tmrval /= 2;
  492. /* from the specs: */
  493. /* "Values of 0h-3h are ignored and should not be attempted" */
  494. if (tmrval < 0x04)
  495. return -EINVAL;
  496. if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
  497. ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
  498. return -EINVAL;
  499. iTCO_vendor_pre_set_heartbeat(tmrval);
  500. /* Write new heartbeat to watchdog */
  501. if (iTCO_wdt_private.iTCO_version == 2) {
  502. spin_lock(&iTCO_wdt_private.io_lock);
  503. val16 = inw(TCOv2_TMR);
  504. val16 &= 0xfc00;
  505. val16 |= tmrval;
  506. outw(val16, TCOv2_TMR);
  507. val16 = inw(TCOv2_TMR);
  508. spin_unlock(&iTCO_wdt_private.io_lock);
  509. if ((val16 & 0x3ff) != tmrval)
  510. return -EINVAL;
  511. } else if (iTCO_wdt_private.iTCO_version == 1) {
  512. spin_lock(&iTCO_wdt_private.io_lock);
  513. val8 = inb(TCOv1_TMR);
  514. val8 &= 0xc0;
  515. val8 |= (tmrval & 0xff);
  516. outb(val8, TCOv1_TMR);
  517. val8 = inb(TCOv1_TMR);
  518. spin_unlock(&iTCO_wdt_private.io_lock);
  519. if ((val8 & 0x3f) != tmrval)
  520. return -EINVAL;
  521. }
  522. heartbeat = t;
  523. return 0;
  524. }
  525. static int iTCO_wdt_get_timeleft(int *time_left)
  526. {
  527. unsigned int val16;
  528. unsigned char val8;
  529. /* read the TCO Timer */
  530. if (iTCO_wdt_private.iTCO_version == 2) {
  531. spin_lock(&iTCO_wdt_private.io_lock);
  532. val16 = inw(TCO_RLD);
  533. val16 &= 0x3ff;
  534. spin_unlock(&iTCO_wdt_private.io_lock);
  535. *time_left = (val16 * 6) / 10;
  536. } else if (iTCO_wdt_private.iTCO_version == 1) {
  537. spin_lock(&iTCO_wdt_private.io_lock);
  538. val8 = inb(TCO_RLD);
  539. val8 &= 0x3f;
  540. if (!(inw(TCO1_STS) & 0x0008))
  541. val8 += (inb(TCOv1_TMR) & 0x3f);
  542. spin_unlock(&iTCO_wdt_private.io_lock);
  543. *time_left = (val8 * 6) / 10;
  544. } else
  545. return -EINVAL;
  546. return 0;
  547. }
  548. /*
  549. * /dev/watchdog handling
  550. */
  551. static int iTCO_wdt_open(struct inode *inode, struct file *file)
  552. {
  553. /* /dev/watchdog can only be opened once */
  554. if (test_and_set_bit(0, &is_active))
  555. return -EBUSY;
  556. /*
  557. * Reload and activate timer
  558. */
  559. iTCO_wdt_start();
  560. return nonseekable_open(inode, file);
  561. }
  562. static int iTCO_wdt_release(struct inode *inode, struct file *file)
  563. {
  564. /*
  565. * Shut off the timer.
  566. */
  567. if (expect_release == 42) {
  568. iTCO_wdt_stop();
  569. } else {
  570. printk(KERN_CRIT PFX
  571. "Unexpected close, not stopping watchdog!\n");
  572. iTCO_wdt_keepalive();
  573. }
  574. clear_bit(0, &is_active);
  575. expect_release = 0;
  576. return 0;
  577. }
  578. static ssize_t iTCO_wdt_write(struct file *file, const char __user *data,
  579. size_t len, loff_t *ppos)
  580. {
  581. /* See if we got the magic character 'V' and reload the timer */
  582. if (len) {
  583. if (!nowayout) {
  584. size_t i;
  585. /* note: just in case someone wrote the magic
  586. character five months ago... */
  587. expect_release = 0;
  588. /* scan to see whether or not we got the
  589. magic character */
  590. for (i = 0; i != len; i++) {
  591. char c;
  592. if (get_user(c, data + i))
  593. return -EFAULT;
  594. if (c == 'V')
  595. expect_release = 42;
  596. }
  597. }
  598. /* someone wrote to us, we should reload the timer */
  599. iTCO_wdt_keepalive();
  600. }
  601. return len;
  602. }
  603. static long iTCO_wdt_ioctl(struct file *file, unsigned int cmd,
  604. unsigned long arg)
  605. {
  606. int new_options, retval = -EINVAL;
  607. int new_heartbeat;
  608. void __user *argp = (void __user *)arg;
  609. int __user *p = argp;
  610. static const struct watchdog_info ident = {
  611. .options = WDIOF_SETTIMEOUT |
  612. WDIOF_KEEPALIVEPING |
  613. WDIOF_MAGICCLOSE,
  614. .firmware_version = 0,
  615. .identity = DRV_NAME,
  616. };
  617. switch (cmd) {
  618. case WDIOC_GETSUPPORT:
  619. return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  620. case WDIOC_GETSTATUS:
  621. case WDIOC_GETBOOTSTATUS:
  622. return put_user(0, p);
  623. case WDIOC_SETOPTIONS:
  624. {
  625. if (get_user(new_options, p))
  626. return -EFAULT;
  627. if (new_options & WDIOS_DISABLECARD) {
  628. iTCO_wdt_stop();
  629. retval = 0;
  630. }
  631. if (new_options & WDIOS_ENABLECARD) {
  632. iTCO_wdt_keepalive();
  633. iTCO_wdt_start();
  634. retval = 0;
  635. }
  636. return retval;
  637. }
  638. case WDIOC_KEEPALIVE:
  639. iTCO_wdt_keepalive();
  640. return 0;
  641. case WDIOC_SETTIMEOUT:
  642. {
  643. if (get_user(new_heartbeat, p))
  644. return -EFAULT;
  645. if (iTCO_wdt_set_heartbeat(new_heartbeat))
  646. return -EINVAL;
  647. iTCO_wdt_keepalive();
  648. /* Fall */
  649. }
  650. case WDIOC_GETTIMEOUT:
  651. return put_user(heartbeat, p);
  652. case WDIOC_GETTIMELEFT:
  653. {
  654. int time_left;
  655. if (iTCO_wdt_get_timeleft(&time_left))
  656. return -EINVAL;
  657. return put_user(time_left, p);
  658. }
  659. default:
  660. return -ENOTTY;
  661. }
  662. }
  663. /*
  664. * Kernel Interfaces
  665. */
  666. static const struct file_operations iTCO_wdt_fops = {
  667. .owner = THIS_MODULE,
  668. .llseek = no_llseek,
  669. .write = iTCO_wdt_write,
  670. .unlocked_ioctl = iTCO_wdt_ioctl,
  671. .open = iTCO_wdt_open,
  672. .release = iTCO_wdt_release,
  673. };
  674. static struct miscdevice iTCO_wdt_miscdev = {
  675. .minor = WATCHDOG_MINOR,
  676. .name = "watchdog",
  677. .fops = &iTCO_wdt_fops,
  678. };
  679. /*
  680. * Init & exit routines
  681. */
  682. static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
  683. const struct pci_device_id *ent, struct platform_device *dev)
  684. {
  685. int ret;
  686. u32 base_address;
  687. unsigned long RCBA;
  688. unsigned long val32;
  689. /*
  690. * Find the ACPI/PM base I/O address which is the base
  691. * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
  692. * ACPIBASE is bits [15:7] from 0x40-0x43
  693. */
  694. pci_read_config_dword(pdev, 0x40, &base_address);
  695. base_address &= 0x0000ff80;
  696. if (base_address == 0x00000000) {
  697. /* Something's wrong here, ACPIBASE has to be set */
  698. printk(KERN_ERR PFX "failed to get TCOBASE address, "
  699. "device disabled by hardware/BIOS\n");
  700. return -ENODEV;
  701. }
  702. iTCO_wdt_private.iTCO_version =
  703. iTCO_chipset_info[ent->driver_data].iTCO_version;
  704. iTCO_wdt_private.ACPIBASE = base_address;
  705. iTCO_wdt_private.pdev = pdev;
  706. /* Get the Memory-Mapped GCS register, we need it for the
  707. NO_REBOOT flag (TCO v2). To get access to it you have to
  708. read RCBA from PCI Config space 0xf0 and use it as base.
  709. GCS = RCBA + ICH6_GCS(0x3410). */
  710. if (iTCO_wdt_private.iTCO_version == 2) {
  711. pci_read_config_dword(pdev, 0xf0, &base_address);
  712. if ((base_address & 1) == 0) {
  713. printk(KERN_ERR PFX "RCBA is disabled by hardware"
  714. "/BIOS, device disabled\n");
  715. ret = -ENODEV;
  716. goto out;
  717. }
  718. RCBA = base_address & 0xffffc000;
  719. iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410), 4);
  720. }
  721. /* Check chipset's NO_REBOOT bit */
  722. if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
  723. printk(KERN_INFO PFX "unable to reset NO_REBOOT flag, "
  724. "device disabled by hardware/BIOS\n");
  725. ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
  726. goto out_unmap;
  727. }
  728. /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
  729. iTCO_wdt_set_NO_REBOOT_bit();
  730. /* The TCO logic uses the TCO_EN bit in the SMI_EN register */
  731. if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
  732. printk(KERN_ERR PFX
  733. "I/O address 0x%04lx already in use, "
  734. "device disabled\n", SMI_EN);
  735. ret = -EIO;
  736. goto out_unmap;
  737. }
  738. if (turn_SMI_watchdog_clear_off) {
  739. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
  740. val32 = inl(SMI_EN);
  741. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  742. outl(val32, SMI_EN);
  743. }
  744. /* The TCO I/O registers reside in a 32-byte range pointed to
  745. by the TCOBASE value */
  746. if (!request_region(TCOBASE, 0x20, "iTCO_wdt")) {
  747. printk(KERN_ERR PFX "I/O address 0x%04lx already in use "
  748. "device disabled\n", TCOBASE);
  749. ret = -EIO;
  750. goto unreg_smi_en;
  751. }
  752. printk(KERN_INFO PFX
  753. "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n",
  754. iTCO_chipset_info[ent->driver_data].name,
  755. iTCO_chipset_info[ent->driver_data].iTCO_version,
  756. TCOBASE);
  757. /* Clear out the (probably old) status */
  758. outw(0x0008, TCO1_STS); /* Clear the Time Out Status bit */
  759. outw(0x0002, TCO2_STS); /* Clear SECOND_TO_STS bit */
  760. outw(0x0004, TCO2_STS); /* Clear BOOT_STS bit */
  761. /* Make sure the watchdog is not running */
  762. iTCO_wdt_stop();
  763. /* Check that the heartbeat value is within it's range;
  764. if not reset to the default */
  765. if (iTCO_wdt_set_heartbeat(heartbeat)) {
  766. iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
  767. printk(KERN_INFO PFX
  768. "timeout value out of range, using %d\n", heartbeat);
  769. }
  770. ret = misc_register(&iTCO_wdt_miscdev);
  771. if (ret != 0) {
  772. printk(KERN_ERR PFX
  773. "cannot register miscdev on minor=%d (err=%d)\n",
  774. WATCHDOG_MINOR, ret);
  775. goto unreg_region;
  776. }
  777. printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
  778. heartbeat, nowayout);
  779. return 0;
  780. unreg_region:
  781. release_region(TCOBASE, 0x20);
  782. unreg_smi_en:
  783. release_region(SMI_EN, 4);
  784. out_unmap:
  785. if (iTCO_wdt_private.iTCO_version == 2)
  786. iounmap(iTCO_wdt_private.gcs);
  787. out:
  788. iTCO_wdt_private.ACPIBASE = 0;
  789. return ret;
  790. }
  791. static void __devexit iTCO_wdt_cleanup(void)
  792. {
  793. /* Stop the timer before we leave */
  794. if (!nowayout)
  795. iTCO_wdt_stop();
  796. /* Deregister */
  797. misc_deregister(&iTCO_wdt_miscdev);
  798. release_region(TCOBASE, 0x20);
  799. release_region(SMI_EN, 4);
  800. if (iTCO_wdt_private.iTCO_version == 2)
  801. iounmap(iTCO_wdt_private.gcs);
  802. pci_dev_put(iTCO_wdt_private.pdev);
  803. iTCO_wdt_private.ACPIBASE = 0;
  804. }
  805. static int __devinit iTCO_wdt_probe(struct platform_device *dev)
  806. {
  807. int ret = -ENODEV;
  808. int found = 0;
  809. struct pci_dev *pdev = NULL;
  810. const struct pci_device_id *ent;
  811. spin_lock_init(&iTCO_wdt_private.io_lock);
  812. for_each_pci_dev(pdev) {
  813. ent = pci_match_id(iTCO_wdt_pci_tbl, pdev);
  814. if (ent) {
  815. found++;
  816. ret = iTCO_wdt_init(pdev, ent, dev);
  817. if (!ret)
  818. break;
  819. }
  820. }
  821. if (!found)
  822. printk(KERN_INFO PFX "No device detected.\n");
  823. return ret;
  824. }
  825. static int __devexit iTCO_wdt_remove(struct platform_device *dev)
  826. {
  827. if (iTCO_wdt_private.ACPIBASE)
  828. iTCO_wdt_cleanup();
  829. return 0;
  830. }
  831. static void iTCO_wdt_shutdown(struct platform_device *dev)
  832. {
  833. iTCO_wdt_stop();
  834. }
  835. static struct platform_driver iTCO_wdt_driver = {
  836. .probe = iTCO_wdt_probe,
  837. .remove = __devexit_p(iTCO_wdt_remove),
  838. .shutdown = iTCO_wdt_shutdown,
  839. .driver = {
  840. .owner = THIS_MODULE,
  841. .name = DRV_NAME,
  842. },
  843. };
  844. static int __init iTCO_wdt_init_module(void)
  845. {
  846. int err;
  847. printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s\n",
  848. DRV_VERSION);
  849. err = platform_driver_register(&iTCO_wdt_driver);
  850. if (err)
  851. return err;
  852. iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME,
  853. -1, NULL, 0);
  854. if (IS_ERR(iTCO_wdt_platform_device)) {
  855. err = PTR_ERR(iTCO_wdt_platform_device);
  856. goto unreg_platform_driver;
  857. }
  858. return 0;
  859. unreg_platform_driver:
  860. platform_driver_unregister(&iTCO_wdt_driver);
  861. return err;
  862. }
  863. static void __exit iTCO_wdt_cleanup_module(void)
  864. {
  865. platform_device_unregister(iTCO_wdt_platform_device);
  866. platform_driver_unregister(&iTCO_wdt_driver);
  867. printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
  868. }
  869. module_init(iTCO_wdt_init_module);
  870. module_exit(iTCO_wdt_cleanup_module);
  871. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  872. MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
  873. MODULE_VERSION(DRV_VERSION);
  874. MODULE_LICENSE("GPL");
  875. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);