octeon-wdt-main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Octeon Watchdog driver
  3. *
  4. * Copyright (C) 2007, 2008, 2009, 2010 Cavium Networks
  5. *
  6. * Converted to use WATCHDOG_CORE by Aaro Koskinen <aaro.koskinen@iki.fi>.
  7. *
  8. * Some parts derived from wdt.c
  9. *
  10. * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>,
  11. * All Rights Reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. *
  18. * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
  19. * warranty for any of this software. This material is provided
  20. * "AS-IS" and at no charge.
  21. *
  22. * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
  23. *
  24. * This file is subject to the terms and conditions of the GNU General Public
  25. * License. See the file "COPYING" in the main directory of this archive
  26. * for more details.
  27. *
  28. *
  29. * The OCTEON watchdog has a maximum timeout of 2^32 * io_clock.
  30. * For most systems this is less than 10 seconds, so to allow for
  31. * software to request longer watchdog heartbeats, we maintain software
  32. * counters to count multiples of the base rate. If the system locks
  33. * up in such a manner that we can not run the software counters, the
  34. * only result is a watchdog reset sooner than was requested. But
  35. * that is OK, because in this case userspace would likely not be able
  36. * to do anything anyhow.
  37. *
  38. * The hardware watchdog interval we call the period. The OCTEON
  39. * watchdog goes through several stages, after the first period an
  40. * irq is asserted, then if it is not reset, after the next period NMI
  41. * is asserted, then after an additional period a chip wide soft reset.
  42. * So for the software counters, we reset watchdog after each period
  43. * and decrement the counter. But for the last two periods we need to
  44. * let the watchdog progress to the NMI stage so we disable the irq
  45. * and let it proceed. Once in the NMI, we print the register state
  46. * to the serial port and then wait for the reset.
  47. *
  48. * A watchdog is maintained for each CPU in the system, that way if
  49. * one CPU suffers a lockup, we also get a register dump and reset.
  50. * The userspace ping resets the watchdog on all CPUs.
  51. *
  52. * Before userspace opens the watchdog device, we still run the
  53. * watchdogs to catch any lockups that may be kernel related.
  54. *
  55. */
  56. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  57. #include <linux/miscdevice.h>
  58. #include <linux/interrupt.h>
  59. #include <linux/watchdog.h>
  60. #include <linux/cpumask.h>
  61. #include <linux/bitops.h>
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/string.h>
  65. #include <linux/delay.h>
  66. #include <linux/cpu.h>
  67. #include <linux/smp.h>
  68. #include <linux/fs.h>
  69. #include <linux/irq.h>
  70. #include <asm/mipsregs.h>
  71. #include <asm/uasm.h>
  72. #include <asm/octeon/octeon.h>
  73. /* The count needed to achieve timeout_sec. */
  74. static unsigned int timeout_cnt;
  75. /* The maximum period supported. */
  76. static unsigned int max_timeout_sec;
  77. /* The current period. */
  78. static unsigned int timeout_sec;
  79. /* Set to non-zero when userspace countdown mode active */
  80. static int do_coundown;
  81. static unsigned int countdown_reset;
  82. static unsigned int per_cpu_countdown[NR_CPUS];
  83. static cpumask_t irq_enabled_cpus;
  84. #define WD_TIMO 60 /* Default heartbeat = 60 seconds */
  85. static int heartbeat = WD_TIMO;
  86. module_param(heartbeat, int, S_IRUGO);
  87. MODULE_PARM_DESC(heartbeat,
  88. "Watchdog heartbeat in seconds. (0 < heartbeat, default="
  89. __MODULE_STRING(WD_TIMO) ")");
  90. static bool nowayout = WATCHDOG_NOWAYOUT;
  91. module_param(nowayout, bool, S_IRUGO);
  92. MODULE_PARM_DESC(nowayout,
  93. "Watchdog cannot be stopped once started (default="
  94. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  95. static u32 nmi_stage1_insns[64] __initdata;
  96. /* We need one branch and therefore one relocation per target label. */
  97. static struct uasm_label labels[5] __initdata;
  98. static struct uasm_reloc relocs[5] __initdata;
  99. enum lable_id {
  100. label_enter_bootloader = 1
  101. };
  102. /* Some CP0 registers */
  103. #define K0 26
  104. #define C0_CVMMEMCTL 11, 7
  105. #define C0_STATUS 12, 0
  106. #define C0_EBASE 15, 1
  107. #define C0_DESAVE 31, 0
  108. void octeon_wdt_nmi_stage2(void);
  109. static void __init octeon_wdt_build_stage1(void)
  110. {
  111. int i;
  112. int len;
  113. u32 *p = nmi_stage1_insns;
  114. #ifdef CONFIG_HOTPLUG_CPU
  115. struct uasm_label *l = labels;
  116. struct uasm_reloc *r = relocs;
  117. #endif
  118. /*
  119. * For the next few instructions running the debugger may
  120. * cause corruption of k0 in the saved registers. Since we're
  121. * about to crash, nobody probably cares.
  122. *
  123. * Save K0 into the debug scratch register
  124. */
  125. uasm_i_dmtc0(&p, K0, C0_DESAVE);
  126. uasm_i_mfc0(&p, K0, C0_STATUS);
  127. #ifdef CONFIG_HOTPLUG_CPU
  128. if (octeon_bootloader_entry_addr)
  129. uasm_il_bbit0(&p, &r, K0, ilog2(ST0_NMI),
  130. label_enter_bootloader);
  131. #endif
  132. /* Force 64-bit addressing enabled */
  133. uasm_i_ori(&p, K0, K0, ST0_UX | ST0_SX | ST0_KX);
  134. uasm_i_mtc0(&p, K0, C0_STATUS);
  135. #ifdef CONFIG_HOTPLUG_CPU
  136. if (octeon_bootloader_entry_addr) {
  137. uasm_i_mfc0(&p, K0, C0_EBASE);
  138. /* Coreid number in K0 */
  139. uasm_i_andi(&p, K0, K0, 0xf);
  140. /* 8 * coreid in bits 16-31 */
  141. uasm_i_dsll_safe(&p, K0, K0, 3 + 16);
  142. uasm_i_ori(&p, K0, K0, 0x8001);
  143. uasm_i_dsll_safe(&p, K0, K0, 16);
  144. uasm_i_ori(&p, K0, K0, 0x0700);
  145. uasm_i_drotr_safe(&p, K0, K0, 32);
  146. /*
  147. * Should result in: 0x8001,0700,0000,8*coreid which is
  148. * CVMX_CIU_WDOGX(coreid) - 0x0500
  149. *
  150. * Now ld K0, CVMX_CIU_WDOGX(coreid)
  151. */
  152. uasm_i_ld(&p, K0, 0x500, K0);
  153. /*
  154. * If bit one set handle the NMI as a watchdog event.
  155. * otherwise transfer control to bootloader.
  156. */
  157. uasm_il_bbit0(&p, &r, K0, 1, label_enter_bootloader);
  158. uasm_i_nop(&p);
  159. }
  160. #endif
  161. /* Clear Dcache so cvmseg works right. */
  162. uasm_i_cache(&p, 1, 0, 0);
  163. /* Use K0 to do a read/modify/write of CVMMEMCTL */
  164. uasm_i_dmfc0(&p, K0, C0_CVMMEMCTL);
  165. /* Clear out the size of CVMSEG */
  166. uasm_i_dins(&p, K0, 0, 0, 6);
  167. /* Set CVMSEG to its largest value */
  168. uasm_i_ori(&p, K0, K0, 0x1c0 | 54);
  169. /* Store the CVMMEMCTL value */
  170. uasm_i_dmtc0(&p, K0, C0_CVMMEMCTL);
  171. /* Load the address of the second stage handler */
  172. UASM_i_LA(&p, K0, (long)octeon_wdt_nmi_stage2);
  173. uasm_i_jr(&p, K0);
  174. uasm_i_dmfc0(&p, K0, C0_DESAVE);
  175. #ifdef CONFIG_HOTPLUG_CPU
  176. if (octeon_bootloader_entry_addr) {
  177. uasm_build_label(&l, p, label_enter_bootloader);
  178. /* Jump to the bootloader and restore K0 */
  179. UASM_i_LA(&p, K0, (long)octeon_bootloader_entry_addr);
  180. uasm_i_jr(&p, K0);
  181. uasm_i_dmfc0(&p, K0, C0_DESAVE);
  182. }
  183. #endif
  184. uasm_resolve_relocs(relocs, labels);
  185. len = (int)(p - nmi_stage1_insns);
  186. pr_debug("Synthesized NMI stage 1 handler (%d instructions)\n", len);
  187. pr_debug("\t.set push\n");
  188. pr_debug("\t.set noreorder\n");
  189. for (i = 0; i < len; i++)
  190. pr_debug("\t.word 0x%08x\n", nmi_stage1_insns[i]);
  191. pr_debug("\t.set pop\n");
  192. if (len > 32)
  193. panic("NMI stage 1 handler exceeds 32 instructions, was %d\n",
  194. len);
  195. }
  196. static int cpu2core(int cpu)
  197. {
  198. #ifdef CONFIG_SMP
  199. return cpu_logical_map(cpu);
  200. #else
  201. return cvmx_get_core_num();
  202. #endif
  203. }
  204. static int core2cpu(int coreid)
  205. {
  206. #ifdef CONFIG_SMP
  207. return cpu_number_map(coreid);
  208. #else
  209. return 0;
  210. #endif
  211. }
  212. /**
  213. * Poke the watchdog when an interrupt is received
  214. *
  215. * @cpl:
  216. * @dev_id:
  217. *
  218. * Returns
  219. */
  220. static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id)
  221. {
  222. unsigned int core = cvmx_get_core_num();
  223. int cpu = core2cpu(core);
  224. if (do_coundown) {
  225. if (per_cpu_countdown[cpu] > 0) {
  226. /* We're alive, poke the watchdog */
  227. cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
  228. per_cpu_countdown[cpu]--;
  229. } else {
  230. /* Bad news, you are about to reboot. */
  231. disable_irq_nosync(cpl);
  232. cpumask_clear_cpu(cpu, &irq_enabled_cpus);
  233. }
  234. } else {
  235. /* Not open, just ping away... */
  236. cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
  237. }
  238. return IRQ_HANDLED;
  239. }
  240. /* From setup.c */
  241. extern int prom_putchar(char c);
  242. /**
  243. * Write a string to the uart
  244. *
  245. * @str: String to write
  246. */
  247. static void octeon_wdt_write_string(const char *str)
  248. {
  249. /* Just loop writing one byte at a time */
  250. while (*str)
  251. prom_putchar(*str++);
  252. }
  253. /**
  254. * Write a hex number out of the uart
  255. *
  256. * @value: Number to display
  257. * @digits: Number of digits to print (1 to 16)
  258. */
  259. static void octeon_wdt_write_hex(u64 value, int digits)
  260. {
  261. int d;
  262. int v;
  263. for (d = 0; d < digits; d++) {
  264. v = (value >> ((digits - d - 1) * 4)) & 0xf;
  265. if (v >= 10)
  266. prom_putchar('a' + v - 10);
  267. else
  268. prom_putchar('0' + v);
  269. }
  270. }
  271. static const char reg_name[][3] = {
  272. "$0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  273. "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
  274. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  275. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
  276. };
  277. /**
  278. * NMI stage 3 handler. NMIs are handled in the following manner:
  279. * 1) The first NMI handler enables CVMSEG and transfers from
  280. * the bootbus region into normal memory. It is careful to not
  281. * destroy any registers.
  282. * 2) The second stage handler uses CVMSEG to save the registers
  283. * and create a stack for C code. It then calls the third level
  284. * handler with one argument, a pointer to the register values.
  285. * 3) The third, and final, level handler is the following C
  286. * function that prints out some useful infomration.
  287. *
  288. * @reg: Pointer to register state before the NMI
  289. */
  290. void octeon_wdt_nmi_stage3(u64 reg[32])
  291. {
  292. u64 i;
  293. unsigned int coreid = cvmx_get_core_num();
  294. /*
  295. * Save status and cause early to get them before any changes
  296. * might happen.
  297. */
  298. u64 cp0_cause = read_c0_cause();
  299. u64 cp0_status = read_c0_status();
  300. u64 cp0_error_epc = read_c0_errorepc();
  301. u64 cp0_epc = read_c0_epc();
  302. /* Delay so output from all cores output is not jumbled together. */
  303. __delay(100000000ull * coreid);
  304. octeon_wdt_write_string("\r\n*** NMI Watchdog interrupt on Core 0x");
  305. octeon_wdt_write_hex(coreid, 1);
  306. octeon_wdt_write_string(" ***\r\n");
  307. for (i = 0; i < 32; i++) {
  308. octeon_wdt_write_string("\t");
  309. octeon_wdt_write_string(reg_name[i]);
  310. octeon_wdt_write_string("\t0x");
  311. octeon_wdt_write_hex(reg[i], 16);
  312. if (i & 1)
  313. octeon_wdt_write_string("\r\n");
  314. }
  315. octeon_wdt_write_string("\terr_epc\t0x");
  316. octeon_wdt_write_hex(cp0_error_epc, 16);
  317. octeon_wdt_write_string("\tepc\t0x");
  318. octeon_wdt_write_hex(cp0_epc, 16);
  319. octeon_wdt_write_string("\r\n");
  320. octeon_wdt_write_string("\tstatus\t0x");
  321. octeon_wdt_write_hex(cp0_status, 16);
  322. octeon_wdt_write_string("\tcause\t0x");
  323. octeon_wdt_write_hex(cp0_cause, 16);
  324. octeon_wdt_write_string("\r\n");
  325. octeon_wdt_write_string("\tsum0\t0x");
  326. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_SUM0(coreid * 2)), 16);
  327. octeon_wdt_write_string("\ten0\t0x");
  328. octeon_wdt_write_hex(cvmx_read_csr(CVMX_CIU_INTX_EN0(coreid * 2)), 16);
  329. octeon_wdt_write_string("\r\n");
  330. octeon_wdt_write_string("*** Chip soft reset soon ***\r\n");
  331. }
  332. static void octeon_wdt_disable_interrupt(int cpu)
  333. {
  334. unsigned int core;
  335. unsigned int irq;
  336. union cvmx_ciu_wdogx ciu_wdog;
  337. core = cpu2core(cpu);
  338. irq = OCTEON_IRQ_WDOG0 + core;
  339. /* Poke the watchdog to clear out its state */
  340. cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
  341. /* Disable the hardware. */
  342. ciu_wdog.u64 = 0;
  343. cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  344. free_irq(irq, octeon_wdt_poke_irq);
  345. }
  346. static void octeon_wdt_setup_interrupt(int cpu)
  347. {
  348. unsigned int core;
  349. unsigned int irq;
  350. union cvmx_ciu_wdogx ciu_wdog;
  351. core = cpu2core(cpu);
  352. /* Disable it before doing anything with the interrupts. */
  353. ciu_wdog.u64 = 0;
  354. cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  355. per_cpu_countdown[cpu] = countdown_reset;
  356. irq = OCTEON_IRQ_WDOG0 + core;
  357. if (request_irq(irq, octeon_wdt_poke_irq,
  358. IRQF_NO_THREAD, "octeon_wdt", octeon_wdt_poke_irq))
  359. panic("octeon_wdt: Couldn't obtain irq %d", irq);
  360. cpumask_set_cpu(cpu, &irq_enabled_cpus);
  361. /* Poke the watchdog to clear out its state */
  362. cvmx_write_csr(CVMX_CIU_PP_POKEX(core), 1);
  363. /* Finally enable the watchdog now that all handlers are installed */
  364. ciu_wdog.u64 = 0;
  365. ciu_wdog.s.len = timeout_cnt;
  366. ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
  367. cvmx_write_csr(CVMX_CIU_WDOGX(core), ciu_wdog.u64);
  368. }
  369. static int octeon_wdt_cpu_callback(struct notifier_block *nfb,
  370. unsigned long action, void *hcpu)
  371. {
  372. unsigned int cpu = (unsigned long)hcpu;
  373. switch (action) {
  374. case CPU_DOWN_PREPARE:
  375. octeon_wdt_disable_interrupt(cpu);
  376. break;
  377. case CPU_ONLINE:
  378. case CPU_DOWN_FAILED:
  379. octeon_wdt_setup_interrupt(cpu);
  380. break;
  381. default:
  382. break;
  383. }
  384. return NOTIFY_OK;
  385. }
  386. static int octeon_wdt_ping(struct watchdog_device __always_unused *wdog)
  387. {
  388. int cpu;
  389. int coreid;
  390. for_each_online_cpu(cpu) {
  391. coreid = cpu2core(cpu);
  392. cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
  393. per_cpu_countdown[cpu] = countdown_reset;
  394. if ((countdown_reset || !do_coundown) &&
  395. !cpumask_test_cpu(cpu, &irq_enabled_cpus)) {
  396. /* We have to enable the irq */
  397. int irq = OCTEON_IRQ_WDOG0 + coreid;
  398. enable_irq(irq);
  399. cpumask_set_cpu(cpu, &irq_enabled_cpus);
  400. }
  401. }
  402. return 0;
  403. }
  404. static void octeon_wdt_calc_parameters(int t)
  405. {
  406. unsigned int periods;
  407. timeout_sec = max_timeout_sec;
  408. /*
  409. * Find the largest interrupt period, that can evenly divide
  410. * the requested heartbeat time.
  411. */
  412. while ((t % timeout_sec) != 0)
  413. timeout_sec--;
  414. periods = t / timeout_sec;
  415. /*
  416. * The last two periods are after the irq is disabled, and
  417. * then to the nmi, so we subtract them off.
  418. */
  419. countdown_reset = periods > 2 ? periods - 2 : 0;
  420. heartbeat = t;
  421. timeout_cnt = ((octeon_get_io_clock_rate() >> 8) * timeout_sec) >> 8;
  422. }
  423. static int octeon_wdt_set_timeout(struct watchdog_device *wdog,
  424. unsigned int t)
  425. {
  426. int cpu;
  427. int coreid;
  428. union cvmx_ciu_wdogx ciu_wdog;
  429. if (t <= 0)
  430. return -1;
  431. octeon_wdt_calc_parameters(t);
  432. for_each_online_cpu(cpu) {
  433. coreid = cpu2core(cpu);
  434. cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
  435. ciu_wdog.u64 = 0;
  436. ciu_wdog.s.len = timeout_cnt;
  437. ciu_wdog.s.mode = 3; /* 3 = Interrupt + NMI + Soft-Reset */
  438. cvmx_write_csr(CVMX_CIU_WDOGX(coreid), ciu_wdog.u64);
  439. cvmx_write_csr(CVMX_CIU_PP_POKEX(coreid), 1);
  440. }
  441. octeon_wdt_ping(wdog); /* Get the irqs back on. */
  442. return 0;
  443. }
  444. static int octeon_wdt_start(struct watchdog_device *wdog)
  445. {
  446. octeon_wdt_ping(wdog);
  447. do_coundown = 1;
  448. return 0;
  449. }
  450. static int octeon_wdt_stop(struct watchdog_device *wdog)
  451. {
  452. do_coundown = 0;
  453. octeon_wdt_ping(wdog);
  454. return 0;
  455. }
  456. static struct notifier_block octeon_wdt_cpu_notifier = {
  457. .notifier_call = octeon_wdt_cpu_callback,
  458. };
  459. static const struct watchdog_info octeon_wdt_info = {
  460. .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
  461. .identity = "OCTEON",
  462. };
  463. static const struct watchdog_ops octeon_wdt_ops = {
  464. .owner = THIS_MODULE,
  465. .start = octeon_wdt_start,
  466. .stop = octeon_wdt_stop,
  467. .ping = octeon_wdt_ping,
  468. .set_timeout = octeon_wdt_set_timeout,
  469. };
  470. static struct watchdog_device octeon_wdt = {
  471. .info = &octeon_wdt_info,
  472. .ops = &octeon_wdt_ops,
  473. };
  474. /**
  475. * Module/ driver initialization.
  476. *
  477. * Returns Zero on success
  478. */
  479. static int __init octeon_wdt_init(void)
  480. {
  481. int i;
  482. int ret;
  483. int cpu;
  484. u64 *ptr;
  485. /*
  486. * Watchdog time expiration length = The 16 bits of LEN
  487. * represent the most significant bits of a 24 bit decrementer
  488. * that decrements every 256 cycles.
  489. *
  490. * Try for a timeout of 5 sec, if that fails a smaller number
  491. * of even seconds,
  492. */
  493. max_timeout_sec = 6;
  494. do {
  495. max_timeout_sec--;
  496. timeout_cnt = ((octeon_get_io_clock_rate() >> 8) *
  497. max_timeout_sec) >> 8;
  498. } while (timeout_cnt > 65535);
  499. BUG_ON(timeout_cnt == 0);
  500. octeon_wdt_calc_parameters(heartbeat);
  501. pr_info("Initial granularity %d Sec\n", timeout_sec);
  502. octeon_wdt.timeout = timeout_sec;
  503. octeon_wdt.max_timeout = UINT_MAX;
  504. watchdog_set_nowayout(&octeon_wdt, nowayout);
  505. ret = watchdog_register_device(&octeon_wdt);
  506. if (ret) {
  507. pr_err("watchdog_register_device() failed: %d\n", ret);
  508. return ret;
  509. }
  510. /* Build the NMI handler ... */
  511. octeon_wdt_build_stage1();
  512. /* ... and install it. */
  513. ptr = (u64 *) nmi_stage1_insns;
  514. for (i = 0; i < 16; i++) {
  515. cvmx_write_csr(CVMX_MIO_BOOT_LOC_ADR, i * 8);
  516. cvmx_write_csr(CVMX_MIO_BOOT_LOC_DAT, ptr[i]);
  517. }
  518. cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0x81fc0000);
  519. cpumask_clear(&irq_enabled_cpus);
  520. cpu_notifier_register_begin();
  521. for_each_online_cpu(cpu)
  522. octeon_wdt_setup_interrupt(cpu);
  523. __register_hotcpu_notifier(&octeon_wdt_cpu_notifier);
  524. cpu_notifier_register_done();
  525. return 0;
  526. }
  527. /**
  528. * Module / driver shutdown
  529. */
  530. static void __exit octeon_wdt_cleanup(void)
  531. {
  532. int cpu;
  533. watchdog_unregister_device(&octeon_wdt);
  534. cpu_notifier_register_begin();
  535. __unregister_hotcpu_notifier(&octeon_wdt_cpu_notifier);
  536. for_each_online_cpu(cpu) {
  537. int core = cpu2core(cpu);
  538. /* Disable the watchdog */
  539. cvmx_write_csr(CVMX_CIU_WDOGX(core), 0);
  540. /* Free the interrupt handler */
  541. free_irq(OCTEON_IRQ_WDOG0 + core, octeon_wdt_poke_irq);
  542. }
  543. cpu_notifier_register_done();
  544. /*
  545. * Disable the boot-bus memory, the code it points to is soon
  546. * to go missing.
  547. */
  548. cvmx_write_csr(CVMX_MIO_BOOT_LOC_CFGX(0), 0);
  549. }
  550. MODULE_LICENSE("GPL");
  551. MODULE_AUTHOR("Cavium Networks <support@caviumnetworks.com>");
  552. MODULE_DESCRIPTION("Cavium Networks Octeon Watchdog driver.");
  553. module_init(octeon_wdt_init);
  554. module_exit(octeon_wdt_cleanup);