iTCO_wdt.c 28 KB

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