iTCO_wdt.c 28 KB

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