root / hw / wdt_ib700.c @ 07a1bea8
History | View | Annotate | Download (3.3 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 "qemu-timer.h" |
24 | 9dd986cc | Richard W.M. Jones | #include "watchdog.h" |
25 | 9dd986cc | Richard W.M. Jones | #include "hw.h" |
26 | 9dd986cc | Richard W.M. Jones | #include "isa.h" |
27 | 9dd986cc | Richard W.M. Jones | #include "pc.h" |
28 | 9dd986cc | Richard W.M. Jones | |
29 | 9dd986cc | Richard W.M. Jones | /*#define IB700_DEBUG 1*/
|
30 | 9dd986cc | Richard W.M. Jones | |
31 | 9dd986cc | Richard W.M. Jones | #ifdef IB700_DEBUG
|
32 | 9dd986cc | Richard W.M. Jones | #define ib700_debug(fs,...) \
|
33 | 9dd986cc | Richard W.M. Jones | fprintf(stderr,"ib700: %s: "fs,__func__,##__VA_ARGS__) |
34 | 9dd986cc | Richard W.M. Jones | #else
|
35 | 9dd986cc | Richard W.M. Jones | #define ib700_debug(fs,...)
|
36 | 9dd986cc | Richard W.M. Jones | #endif
|
37 | 9dd986cc | Richard W.M. Jones | |
38 | f309270b | Juan Quintela | typedef struct IB700state { |
39 | f309270b | Juan Quintela | ISADevice dev; |
40 | e8f27c72 | Juan Quintela | QEMUTimer *timer; |
41 | f309270b | Juan Quintela | } IB700State; |
42 | f309270b | Juan Quintela | |
43 | 9dd986cc | Richard W.M. Jones | /* This is the timer. We use a global here because the watchdog
|
44 | 9dd986cc | Richard W.M. Jones | * code ensures there is only one watchdog (it is located at a fixed,
|
45 | 9dd986cc | Richard W.M. Jones | * unchangable IO port, so there could only ever be one anyway).
|
46 | 9dd986cc | Richard W.M. Jones | */
|
47 | 9dd986cc | Richard W.M. Jones | |
48 | 9dd986cc | Richard W.M. Jones | /* A write to this register enables the timer. */
|
49 | 9dd986cc | Richard W.M. Jones | static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data) |
50 | 9dd986cc | Richard W.M. Jones | { |
51 | e8f27c72 | Juan Quintela | IB700State *s = vp; |
52 | 9dd986cc | Richard W.M. Jones | static int time_map[] = { |
53 | 9dd986cc | Richard W.M. Jones | 30, 28, 26, 24, 22, 20, 18, 16, |
54 | 9dd986cc | Richard W.M. Jones | 14, 12, 10, 8, 6, 4, 2, 0 |
55 | 9dd986cc | Richard W.M. Jones | }; |
56 | 9dd986cc | Richard W.M. Jones | int64 timeout; |
57 | 9dd986cc | Richard W.M. Jones | |
58 | 9dd986cc | Richard W.M. Jones | ib700_debug("addr = %x, data = %x\n", addr, data);
|
59 | 9dd986cc | Richard W.M. Jones | |
60 | 6ee093c9 | Juan Quintela | timeout = (int64_t) time_map[data & 0xF] * get_ticks_per_sec();
|
61 | e8f27c72 | Juan Quintela | qemu_mod_timer(s->timer, qemu_get_clock (vm_clock) + timeout); |
62 | 9dd986cc | Richard W.M. Jones | } |
63 | 9dd986cc | Richard W.M. Jones | |
64 | 9dd986cc | Richard W.M. Jones | /* A write (of any value) to this register disables the timer. */
|
65 | 9dd986cc | Richard W.M. Jones | static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data) |
66 | 9dd986cc | Richard W.M. Jones | { |
67 | e8f27c72 | Juan Quintela | IB700State *s = vp; |
68 | e8f27c72 | Juan Quintela | |
69 | 9dd986cc | Richard W.M. Jones | ib700_debug("addr = %x, data = %x\n", addr, data);
|
70 | 9dd986cc | Richard W.M. Jones | |
71 | e8f27c72 | Juan Quintela | qemu_del_timer(s->timer); |
72 | 9dd986cc | Richard W.M. Jones | } |
73 | 9dd986cc | Richard W.M. Jones | |
74 | 9dd986cc | Richard W.M. Jones | /* This is called when the watchdog expires. */
|
75 | 9dd986cc | Richard W.M. Jones | static void ib700_timer_expired(void *vp) |
76 | 9dd986cc | Richard W.M. Jones | { |
77 | e8f27c72 | Juan Quintela | IB700State *s = vp; |
78 | e8f27c72 | Juan Quintela | |
79 | 9dd986cc | Richard W.M. Jones | ib700_debug("watchdog expired\n");
|
80 | 9dd986cc | Richard W.M. Jones | |
81 | 9dd986cc | Richard W.M. Jones | watchdog_perform_action(); |
82 | e8f27c72 | Juan Quintela | qemu_del_timer(s->timer); |
83 | 9dd986cc | Richard W.M. Jones | } |
84 | 9dd986cc | Richard W.M. Jones | |
85 | 9958068d | Juan Quintela | static const VMStateDescription vmstate_ib700 = { |
86 | 9958068d | Juan Quintela | .name = "ib700_wdt",
|
87 | 9958068d | Juan Quintela | .version_id = 0,
|
88 | 9958068d | Juan Quintela | .minimum_version_id = 0,
|
89 | 9958068d | Juan Quintela | .minimum_version_id_old = 0,
|
90 | 9958068d | Juan Quintela | .fields = (VMStateField []) { |
91 | 9958068d | Juan Quintela | VMSTATE_TIMER(timer, IB700State), |
92 | 9958068d | Juan Quintela | VMSTATE_END_OF_LIST() |
93 | 9958068d | Juan Quintela | } |
94 | 9958068d | Juan Quintela | }; |
95 | 9dd986cc | Richard W.M. Jones | |
96 | 81a322d4 | Gerd Hoffmann | static int wdt_ib700_init(ISADevice *dev) |
97 | 9dd986cc | Richard W.M. Jones | { |
98 | f309270b | Juan Quintela | IB700State *s = DO_UPCAST(IB700State, dev, dev); |
99 | f309270b | Juan Quintela | |
100 | e8f27c72 | Juan Quintela | s->timer = qemu_new_timer(vm_clock, ib700_timer_expired, s); |
101 | 9958068d | Juan Quintela | vmstate_register(-1, &vmstate_ib700, s);
|
102 | f309270b | Juan Quintela | register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s); |
103 | f309270b | Juan Quintela | register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s); |
104 | 81a322d4 | Gerd Hoffmann | |
105 | 81a322d4 | Gerd Hoffmann | return 0; |
106 | 9dd986cc | Richard W.M. Jones | } |
107 | 9dd986cc | Richard W.M. Jones | |
108 | 9dd986cc | Richard W.M. Jones | static WatchdogTimerModel model = {
|
109 | 9dd986cc | Richard W.M. Jones | .wdt_name = "ib700",
|
110 | 9dd986cc | Richard W.M. Jones | .wdt_description = "iBASE 700",
|
111 | 9dd986cc | Richard W.M. Jones | }; |
112 | 9dd986cc | Richard W.M. Jones | |
113 | 09aaa160 | Markus Armbruster | static ISADeviceInfo wdt_ib700_info = {
|
114 | 09aaa160 | Markus Armbruster | .qdev.name = "ib700",
|
115 | f309270b | Juan Quintela | .qdev.size = sizeof(IB700State),
|
116 | 09aaa160 | Markus Armbruster | .init = wdt_ib700_init, |
117 | 09aaa160 | Markus Armbruster | }; |
118 | 09aaa160 | Markus Armbruster | |
119 | 09aaa160 | Markus Armbruster | static void wdt_ib700_register_devices(void) |
120 | 9dd986cc | Richard W.M. Jones | { |
121 | 9dd986cc | Richard W.M. Jones | watchdog_add_model(&model); |
122 | 09aaa160 | Markus Armbruster | isa_qdev_register(&wdt_ib700_info); |
123 | 9dd986cc | Richard W.M. Jones | } |
124 | 09aaa160 | Markus Armbruster | |
125 | 09aaa160 | Markus Armbruster | device_init(wdt_ib700_register_devices); |