root / hw / watchdog.c @ b31442c3
History | View | Annotate | Download (3.5 kB)
1 | 9dd986cc | Richard W.M. Jones | /*
|
---|---|---|---|
2 | 9dd986cc | Richard W.M. Jones | * Virtual hardware watchdog.
|
3 | 9dd986cc | Richard W.M. Jones | *
|
4 | 9dd986cc | Richard W.M. Jones | * Copyright (C) 2009 Red Hat Inc.
|
5 | 9dd986cc | Richard W.M. Jones | *
|
6 | 9dd986cc | Richard W.M. Jones | * This program is free software; you can redistribute it and/or
|
7 | 9dd986cc | Richard W.M. Jones | * modify it under the terms of the GNU General Public License
|
8 | 9dd986cc | Richard W.M. Jones | * as published by the Free Software Foundation; either version 2
|
9 | 9dd986cc | Richard W.M. Jones | * of the License, or (at your option) any later version.
|
10 | 9dd986cc | Richard W.M. Jones | *
|
11 | 9dd986cc | Richard W.M. Jones | * This program is distributed in the hope that it will be useful,
|
12 | 9dd986cc | Richard W.M. Jones | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 9dd986cc | Richard W.M. Jones | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 9dd986cc | Richard W.M. Jones | * GNU General Public License for more details.
|
15 | 9dd986cc | Richard W.M. Jones | *
|
16 | 9dd986cc | Richard W.M. Jones | * You should have received a copy of the GNU General Public License
|
17 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 9dd986cc | Richard W.M. Jones | *
|
19 | 9dd986cc | Richard W.M. Jones | * By Richard W.M. Jones (rjones@redhat.com).
|
20 | 9dd986cc | Richard W.M. Jones | */
|
21 | 9dd986cc | Richard W.M. Jones | |
22 | 9dd986cc | Richard W.M. Jones | #include "qemu-common.h" |
23 | 9dd986cc | Richard W.M. Jones | #include "sys-queue.h" |
24 | 9dd986cc | Richard W.M. Jones | #include "sysemu.h" |
25 | 9dd986cc | Richard W.M. Jones | #include "hw/watchdog.h" |
26 | 9dd986cc | Richard W.M. Jones | |
27 | 9dd986cc | Richard W.M. Jones | static LIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
|
28 | 9dd986cc | Richard W.M. Jones | |
29 | 9dd986cc | Richard W.M. Jones | void watchdog_add_model(WatchdogTimerModel *model)
|
30 | 9dd986cc | Richard W.M. Jones | { |
31 | 9dd986cc | Richard W.M. Jones | LIST_INSERT_HEAD(&watchdog_list, model, entry); |
32 | 9dd986cc | Richard W.M. Jones | } |
33 | 9dd986cc | Richard W.M. Jones | |
34 | 9dd986cc | Richard W.M. Jones | /* Returns:
|
35 | 9dd986cc | Richard W.M. Jones | * 0 = continue
|
36 | 9dd986cc | Richard W.M. Jones | * 1 = exit program with error
|
37 | 9dd986cc | Richard W.M. Jones | * 2 = exit program without error
|
38 | 9dd986cc | Richard W.M. Jones | */
|
39 | 9dd986cc | Richard W.M. Jones | int select_watchdog(const char *p) |
40 | 9dd986cc | Richard W.M. Jones | { |
41 | 9dd986cc | Richard W.M. Jones | WatchdogTimerModel *model; |
42 | 9dd986cc | Richard W.M. Jones | |
43 | 9dd986cc | Richard W.M. Jones | if (watchdog) {
|
44 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, |
45 | 9dd986cc | Richard W.M. Jones | "qemu: only one watchdog option may be given\n");
|
46 | 9dd986cc | Richard W.M. Jones | return 1; |
47 | 9dd986cc | Richard W.M. Jones | } |
48 | 9dd986cc | Richard W.M. Jones | |
49 | 9dd986cc | Richard W.M. Jones | /* -watchdog ? lists available devices and exits cleanly. */
|
50 | 9dd986cc | Richard W.M. Jones | if (strcmp(p, "?") == 0) { |
51 | 9dd986cc | Richard W.M. Jones | LIST_FOREACH(model, &watchdog_list, entry) { |
52 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "\t%s\t%s\n",
|
53 | 9dd986cc | Richard W.M. Jones | model->wdt_name, model->wdt_description); |
54 | 9dd986cc | Richard W.M. Jones | } |
55 | 9dd986cc | Richard W.M. Jones | return 2; |
56 | 9dd986cc | Richard W.M. Jones | } |
57 | 9dd986cc | Richard W.M. Jones | |
58 | 9dd986cc | Richard W.M. Jones | LIST_FOREACH(model, &watchdog_list, entry) { |
59 | 9dd986cc | Richard W.M. Jones | if (strcasecmp(model->wdt_name, p) == 0) { |
60 | 9dd986cc | Richard W.M. Jones | watchdog = model; |
61 | 9dd986cc | Richard W.M. Jones | return 0; |
62 | 9dd986cc | Richard W.M. Jones | } |
63 | 9dd986cc | Richard W.M. Jones | } |
64 | 9dd986cc | Richard W.M. Jones | |
65 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
|
66 | 9dd986cc | Richard W.M. Jones | LIST_FOREACH(model, &watchdog_list, entry) { |
67 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "\t%s\t%s\n",
|
68 | 9dd986cc | Richard W.M. Jones | model->wdt_name, model->wdt_description); |
69 | 9dd986cc | Richard W.M. Jones | } |
70 | 9dd986cc | Richard W.M. Jones | return 1; |
71 | 9dd986cc | Richard W.M. Jones | } |
72 | 9dd986cc | Richard W.M. Jones | |
73 | 9dd986cc | Richard W.M. Jones | int select_watchdog_action(const char *p) |
74 | 9dd986cc | Richard W.M. Jones | { |
75 | 9dd986cc | Richard W.M. Jones | if (strcasecmp(p, "reset") == 0) |
76 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_RESET; |
77 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "shutdown") == 0) |
78 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_SHUTDOWN; |
79 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "poweroff") == 0) |
80 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_POWEROFF; |
81 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "pause") == 0) |
82 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_PAUSE; |
83 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "debug") == 0) |
84 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_DEBUG; |
85 | 9dd986cc | Richard W.M. Jones | else if (strcasecmp(p, "none") == 0) |
86 | 9dd986cc | Richard W.M. Jones | watchdog_action = WDT_NONE; |
87 | 9dd986cc | Richard W.M. Jones | else
|
88 | 9dd986cc | Richard W.M. Jones | return -1; |
89 | 9dd986cc | Richard W.M. Jones | |
90 | 9dd986cc | Richard W.M. Jones | return 0; |
91 | 9dd986cc | Richard W.M. Jones | } |
92 | 9dd986cc | Richard W.M. Jones | |
93 | 9dd986cc | Richard W.M. Jones | /* This actually performs the "action" once a watchdog has expired,
|
94 | 9dd986cc | Richard W.M. Jones | * ie. reboot, shutdown, exit, etc.
|
95 | 9dd986cc | Richard W.M. Jones | */
|
96 | 9dd986cc | Richard W.M. Jones | void watchdog_perform_action(void) |
97 | 9dd986cc | Richard W.M. Jones | { |
98 | 9dd986cc | Richard W.M. Jones | switch(watchdog_action) {
|
99 | 9dd986cc | Richard W.M. Jones | case WDT_RESET: /* same as 'system_reset' in monitor */ |
100 | 9dd986cc | Richard W.M. Jones | qemu_system_reset_request(); |
101 | 9dd986cc | Richard W.M. Jones | break;
|
102 | 9dd986cc | Richard W.M. Jones | |
103 | 9dd986cc | Richard W.M. Jones | case WDT_SHUTDOWN: /* same as 'system_powerdown' in monitor */ |
104 | 9dd986cc | Richard W.M. Jones | qemu_system_powerdown_request(); |
105 | 9dd986cc | Richard W.M. Jones | break;
|
106 | 9dd986cc | Richard W.M. Jones | |
107 | 9dd986cc | Richard W.M. Jones | case WDT_POWEROFF: /* same as 'quit' command in monitor */ |
108 | 9dd986cc | Richard W.M. Jones | exit(0);
|
109 | 9dd986cc | Richard W.M. Jones | break;
|
110 | 9dd986cc | Richard W.M. Jones | |
111 | 9dd986cc | Richard W.M. Jones | case WDT_PAUSE: /* same as 'stop' command in monitor */ |
112 | 9dd986cc | Richard W.M. Jones | vm_stop(0);
|
113 | 9dd986cc | Richard W.M. Jones | break;
|
114 | 9dd986cc | Richard W.M. Jones | |
115 | 9dd986cc | Richard W.M. Jones | case WDT_DEBUG:
|
116 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "watchdog: timer fired\n");
|
117 | 9dd986cc | Richard W.M. Jones | break;
|
118 | 9dd986cc | Richard W.M. Jones | |
119 | 9dd986cc | Richard W.M. Jones | case WDT_NONE:
|
120 | 9dd986cc | Richard W.M. Jones | break;
|
121 | 9dd986cc | Richard W.M. Jones | } |
122 | 9dd986cc | Richard W.M. Jones | } |
123 | 9dd986cc | Richard W.M. Jones | |
124 | 9dd986cc | Richard W.M. Jones | void watchdog_pc_init(PCIBus *pci_bus)
|
125 | 9dd986cc | Richard W.M. Jones | { |
126 | 9dd986cc | Richard W.M. Jones | if (watchdog)
|
127 | 9dd986cc | Richard W.M. Jones | watchdog->wdt_pc_init(pci_bus); |
128 | 9dd986cc | Richard W.M. Jones | } |
129 | 9dd986cc | Richard W.M. Jones | |
130 | 9dd986cc | Richard W.M. Jones | void register_watchdogs(void) |
131 | 9dd986cc | Richard W.M. Jones | { |
132 | 9dd986cc | Richard W.M. Jones | wdt_ib700_init(); |
133 | 9dd986cc | Richard W.M. Jones | wdt_i6300esb_init(); |
134 | 9dd986cc | Richard W.M. Jones | } |