iTCO_wdt.c 27 KB

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