root / hw / timer / etraxfs_timer.c @ 3bd88451
History | View | Annotate | Download (8.8 kB)
1 | 83fa1010 | ths | /*
|
---|---|---|---|
2 | e62b5b13 | edgar_igl | * QEMU ETRAX Timers
|
3 | 83fa1010 | ths | *
|
4 | 83fa1010 | ths | * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
|
5 | 83fa1010 | ths | *
|
6 | 83fa1010 | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 83fa1010 | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | 83fa1010 | ths | * in the Software without restriction, including without limitation the rights
|
9 | 83fa1010 | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 83fa1010 | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | 83fa1010 | ths | * furnished to do so, subject to the following conditions:
|
12 | 83fa1010 | ths | *
|
13 | 83fa1010 | ths | * The above copyright notice and this permission notice shall be included in
|
14 | 83fa1010 | ths | * all copies or substantial portions of the Software.
|
15 | 83fa1010 | ths | *
|
16 | 83fa1010 | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 83fa1010 | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 83fa1010 | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 83fa1010 | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 83fa1010 | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 83fa1010 | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 83fa1010 | ths | * THE SOFTWARE.
|
23 | 83fa1010 | ths | */
|
24 | 83c9f4ca | Paolo Bonzini | #include "hw/sysbus.h" |
25 | 9c17d615 | Paolo Bonzini | #include "sysemu/sysemu.h" |
26 | 1de7afc9 | Paolo Bonzini | #include "qemu/timer.h" |
27 | 83c9f4ca | Paolo Bonzini | #include "hw/ptimer.h" |
28 | 83fa1010 | ths | |
29 | bbaf29c7 | edgar_igl | #define D(x)
|
30 | bbaf29c7 | edgar_igl | |
31 | ca87d03b | edgar_igl | #define RW_TMR0_DIV 0x00 |
32 | ca87d03b | edgar_igl | #define R_TMR0_DATA 0x04 |
33 | ca87d03b | edgar_igl | #define RW_TMR0_CTRL 0x08 |
34 | ca87d03b | edgar_igl | #define RW_TMR1_DIV 0x10 |
35 | ca87d03b | edgar_igl | #define R_TMR1_DATA 0x14 |
36 | ca87d03b | edgar_igl | #define RW_TMR1_CTRL 0x18 |
37 | ca87d03b | edgar_igl | #define R_TIME 0x38 |
38 | ca87d03b | edgar_igl | #define RW_WD_CTRL 0x40 |
39 | 5439779e | edgar_igl | #define R_WD_STAT 0x44 |
40 | ca87d03b | edgar_igl | #define RW_INTR_MASK 0x48 |
41 | ca87d03b | edgar_igl | #define RW_ACK_INTR 0x4c |
42 | ca87d03b | edgar_igl | #define R_INTR 0x50 |
43 | ca87d03b | edgar_igl | #define R_MASKED_INTR 0x54 |
44 | 83fa1010 | ths | |
45 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer {
|
46 | 3b1fd90e | Edgar E. Iglesias | SysBusDevice busdev; |
47 | b8e5da2c | Edgar E. Iglesias | MemoryRegion mmio; |
48 | 3b1fd90e | Edgar E. Iglesias | qemu_irq irq; |
49 | 3b1fd90e | Edgar E. Iglesias | qemu_irq nmi; |
50 | 84ceea57 | Edgar E. Iglesias | |
51 | 84ceea57 | Edgar E. Iglesias | QEMUBH *bh_t0; |
52 | 84ceea57 | Edgar E. Iglesias | QEMUBH *bh_t1; |
53 | 84ceea57 | Edgar E. Iglesias | QEMUBH *bh_wd; |
54 | 84ceea57 | Edgar E. Iglesias | ptimer_state *ptimer_t0; |
55 | 84ceea57 | Edgar E. Iglesias | ptimer_state *ptimer_t1; |
56 | 84ceea57 | Edgar E. Iglesias | ptimer_state *ptimer_wd; |
57 | 84ceea57 | Edgar E. Iglesias | |
58 | 84ceea57 | Edgar E. Iglesias | int wd_hits;
|
59 | 84ceea57 | Edgar E. Iglesias | |
60 | 84ceea57 | Edgar E. Iglesias | /* Control registers. */
|
61 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_tmr0_div; |
62 | 84ceea57 | Edgar E. Iglesias | uint32_t r_tmr0_data; |
63 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_tmr0_ctrl; |
64 | 84ceea57 | Edgar E. Iglesias | |
65 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_tmr1_div; |
66 | 84ceea57 | Edgar E. Iglesias | uint32_t r_tmr1_data; |
67 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_tmr1_ctrl; |
68 | 84ceea57 | Edgar E. Iglesias | |
69 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_wd_ctrl; |
70 | 84ceea57 | Edgar E. Iglesias | |
71 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_intr_mask; |
72 | 84ceea57 | Edgar E. Iglesias | uint32_t rw_ack_intr; |
73 | 84ceea57 | Edgar E. Iglesias | uint32_t r_intr; |
74 | 84ceea57 | Edgar E. Iglesias | uint32_t r_masked_intr; |
75 | 83fa1010 | ths | }; |
76 | 83fa1010 | ths | |
77 | b8e5da2c | Edgar E. Iglesias | static uint64_t
|
78 | a8170e5e | Avi Kivity | timer_read(void *opaque, hwaddr addr, unsigned int size) |
79 | 83fa1010 | ths | { |
80 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
81 | 84ceea57 | Edgar E. Iglesias | uint32_t r = 0;
|
82 | 84ceea57 | Edgar E. Iglesias | |
83 | 84ceea57 | Edgar E. Iglesias | switch (addr) {
|
84 | 84ceea57 | Edgar E. Iglesias | case R_TMR0_DATA:
|
85 | 84ceea57 | Edgar E. Iglesias | r = ptimer_get_count(t->ptimer_t0); |
86 | 84ceea57 | Edgar E. Iglesias | break;
|
87 | 84ceea57 | Edgar E. Iglesias | case R_TMR1_DATA:
|
88 | 84ceea57 | Edgar E. Iglesias | r = ptimer_get_count(t->ptimer_t1); |
89 | 84ceea57 | Edgar E. Iglesias | break;
|
90 | 84ceea57 | Edgar E. Iglesias | case R_TIME:
|
91 | 74475455 | Paolo Bonzini | r = qemu_get_clock_ns(vm_clock) / 10;
|
92 | 84ceea57 | Edgar E. Iglesias | break;
|
93 | 84ceea57 | Edgar E. Iglesias | case RW_INTR_MASK:
|
94 | 84ceea57 | Edgar E. Iglesias | r = t->rw_intr_mask; |
95 | 84ceea57 | Edgar E. Iglesias | break;
|
96 | 84ceea57 | Edgar E. Iglesias | case R_MASKED_INTR:
|
97 | 84ceea57 | Edgar E. Iglesias | r = t->r_intr & t->rw_intr_mask; |
98 | 84ceea57 | Edgar E. Iglesias | break;
|
99 | 84ceea57 | Edgar E. Iglesias | default:
|
100 | 84ceea57 | Edgar E. Iglesias | D(printf ("%s %x\n", __func__, addr));
|
101 | 84ceea57 | Edgar E. Iglesias | break;
|
102 | 84ceea57 | Edgar E. Iglesias | } |
103 | 84ceea57 | Edgar E. Iglesias | return r;
|
104 | 83fa1010 | ths | } |
105 | 83fa1010 | ths | |
106 | 3b1fd90e | Edgar E. Iglesias | static void update_ctrl(struct etrax_timer *t, int tnum) |
107 | 83fa1010 | ths | { |
108 | 84ceea57 | Edgar E. Iglesias | unsigned int op; |
109 | 84ceea57 | Edgar E. Iglesias | unsigned int freq; |
110 | 84ceea57 | Edgar E. Iglesias | unsigned int freq_hz; |
111 | 84ceea57 | Edgar E. Iglesias | unsigned int div; |
112 | 84ceea57 | Edgar E. Iglesias | uint32_t ctrl; |
113 | 84ceea57 | Edgar E. Iglesias | |
114 | 84ceea57 | Edgar E. Iglesias | ptimer_state *timer; |
115 | 84ceea57 | Edgar E. Iglesias | |
116 | 84ceea57 | Edgar E. Iglesias | if (tnum == 0) { |
117 | 84ceea57 | Edgar E. Iglesias | ctrl = t->rw_tmr0_ctrl; |
118 | 84ceea57 | Edgar E. Iglesias | div = t->rw_tmr0_div; |
119 | 84ceea57 | Edgar E. Iglesias | timer = t->ptimer_t0; |
120 | 84ceea57 | Edgar E. Iglesias | } else {
|
121 | 84ceea57 | Edgar E. Iglesias | ctrl = t->rw_tmr1_ctrl; |
122 | 84ceea57 | Edgar E. Iglesias | div = t->rw_tmr1_div; |
123 | 84ceea57 | Edgar E. Iglesias | timer = t->ptimer_t1; |
124 | 84ceea57 | Edgar E. Iglesias | } |
125 | 84ceea57 | Edgar E. Iglesias | |
126 | 84ceea57 | Edgar E. Iglesias | |
127 | 84ceea57 | Edgar E. Iglesias | op = ctrl & 3;
|
128 | 84ceea57 | Edgar E. Iglesias | freq = ctrl >> 2;
|
129 | 84ceea57 | Edgar E. Iglesias | freq_hz = 32000000;
|
130 | 84ceea57 | Edgar E. Iglesias | |
131 | 84ceea57 | Edgar E. Iglesias | switch (freq)
|
132 | 84ceea57 | Edgar E. Iglesias | { |
133 | 84ceea57 | Edgar E. Iglesias | case 0: |
134 | 84ceea57 | Edgar E. Iglesias | case 1: |
135 | 84ceea57 | Edgar E. Iglesias | D(printf ("extern or disabled timer clock?\n"));
|
136 | 84ceea57 | Edgar E. Iglesias | break;
|
137 | 84ceea57 | Edgar E. Iglesias | case 4: freq_hz = 29493000; break; |
138 | 84ceea57 | Edgar E. Iglesias | case 5: freq_hz = 32000000; break; |
139 | 84ceea57 | Edgar E. Iglesias | case 6: freq_hz = 32768000; break; |
140 | 84ceea57 | Edgar E. Iglesias | case 7: freq_hz = 100000000; break; |
141 | 84ceea57 | Edgar E. Iglesias | default:
|
142 | 84ceea57 | Edgar E. Iglesias | abort(); |
143 | 84ceea57 | Edgar E. Iglesias | break;
|
144 | 84ceea57 | Edgar E. Iglesias | } |
145 | 84ceea57 | Edgar E. Iglesias | |
146 | 84ceea57 | Edgar E. Iglesias | D(printf ("freq_hz=%d div=%d\n", freq_hz, div));
|
147 | 84ceea57 | Edgar E. Iglesias | ptimer_set_freq(timer, freq_hz); |
148 | 84ceea57 | Edgar E. Iglesias | ptimer_set_limit(timer, div, 0);
|
149 | 84ceea57 | Edgar E. Iglesias | |
150 | 84ceea57 | Edgar E. Iglesias | switch (op)
|
151 | 84ceea57 | Edgar E. Iglesias | { |
152 | 84ceea57 | Edgar E. Iglesias | case 0: |
153 | 84ceea57 | Edgar E. Iglesias | /* Load. */
|
154 | 84ceea57 | Edgar E. Iglesias | ptimer_set_limit(timer, div, 1);
|
155 | 84ceea57 | Edgar E. Iglesias | break;
|
156 | 84ceea57 | Edgar E. Iglesias | case 1: |
157 | 84ceea57 | Edgar E. Iglesias | /* Hold. */
|
158 | 84ceea57 | Edgar E. Iglesias | ptimer_stop(timer); |
159 | 84ceea57 | Edgar E. Iglesias | break;
|
160 | 84ceea57 | Edgar E. Iglesias | case 2: |
161 | 84ceea57 | Edgar E. Iglesias | /* Run. */
|
162 | 84ceea57 | Edgar E. Iglesias | ptimer_run(timer, 0);
|
163 | 84ceea57 | Edgar E. Iglesias | break;
|
164 | 84ceea57 | Edgar E. Iglesias | default:
|
165 | 84ceea57 | Edgar E. Iglesias | abort(); |
166 | 84ceea57 | Edgar E. Iglesias | break;
|
167 | 84ceea57 | Edgar E. Iglesias | } |
168 | 83fa1010 | ths | } |
169 | 83fa1010 | ths | |
170 | 3b1fd90e | Edgar E. Iglesias | static void timer_update_irq(struct etrax_timer *t) |
171 | 83fa1010 | ths | { |
172 | 84ceea57 | Edgar E. Iglesias | t->r_intr &= ~(t->rw_ack_intr); |
173 | 84ceea57 | Edgar E. Iglesias | t->r_masked_intr = t->r_intr & t->rw_intr_mask; |
174 | 60237223 | edgar_igl | |
175 | 84ceea57 | Edgar E. Iglesias | D(printf("%s: masked_intr=%x\n", __func__, t->r_masked_intr));
|
176 | 3b1fd90e | Edgar E. Iglesias | qemu_set_irq(t->irq, !!t->r_masked_intr); |
177 | 83fa1010 | ths | } |
178 | 83fa1010 | ths | |
179 | 5439779e | edgar_igl | static void timer0_hit(void *opaque) |
180 | 60237223 | edgar_igl | { |
181 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
182 | 84ceea57 | Edgar E. Iglesias | t->r_intr |= 1;
|
183 | 84ceea57 | Edgar E. Iglesias | timer_update_irq(t); |
184 | 60237223 | edgar_igl | } |
185 | 60237223 | edgar_igl | |
186 | 5439779e | edgar_igl | static void timer1_hit(void *opaque) |
187 | 5439779e | edgar_igl | { |
188 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
189 | 84ceea57 | Edgar E. Iglesias | t->r_intr |= 2;
|
190 | 84ceea57 | Edgar E. Iglesias | timer_update_irq(t); |
191 | 5439779e | edgar_igl | } |
192 | 5439779e | edgar_igl | |
193 | 5439779e | edgar_igl | static void watchdog_hit(void *opaque) |
194 | 5439779e | edgar_igl | { |
195 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
196 | 84ceea57 | Edgar E. Iglesias | if (t->wd_hits == 0) { |
197 | 84ceea57 | Edgar E. Iglesias | /* real hw gives a single tick before reseting but we are
|
198 | 84ceea57 | Edgar E. Iglesias | a bit friendlier to compensate for our slower execution. */
|
199 | 84ceea57 | Edgar E. Iglesias | ptimer_set_count(t->ptimer_wd, 10);
|
200 | 84ceea57 | Edgar E. Iglesias | ptimer_run(t->ptimer_wd, 1);
|
201 | 3b1fd90e | Edgar E. Iglesias | qemu_irq_raise(t->nmi); |
202 | 84ceea57 | Edgar E. Iglesias | } |
203 | 84ceea57 | Edgar E. Iglesias | else
|
204 | 84ceea57 | Edgar E. Iglesias | qemu_system_reset_request(); |
205 | 84ceea57 | Edgar E. Iglesias | |
206 | 84ceea57 | Edgar E. Iglesias | t->wd_hits++; |
207 | 5439779e | edgar_igl | } |
208 | 5439779e | edgar_igl | |
209 | 3b1fd90e | Edgar E. Iglesias | static inline void timer_watchdog_update(struct etrax_timer *t, uint32_t value) |
210 | 5439779e | edgar_igl | { |
211 | 84ceea57 | Edgar E. Iglesias | unsigned int wd_en = t->rw_wd_ctrl & (1 << 8); |
212 | 84ceea57 | Edgar E. Iglesias | unsigned int wd_key = t->rw_wd_ctrl >> 9; |
213 | 84ceea57 | Edgar E. Iglesias | unsigned int wd_cnt = t->rw_wd_ctrl & 511; |
214 | 84ceea57 | Edgar E. Iglesias | unsigned int new_key = value >> 9 & ((1 << 7) - 1); |
215 | 84ceea57 | Edgar E. Iglesias | unsigned int new_cmd = (value >> 8) & 1; |
216 | 5439779e | edgar_igl | |
217 | 84ceea57 | Edgar E. Iglesias | /* If the watchdog is enabled, they written key must match the
|
218 | 84ceea57 | Edgar E. Iglesias | complement of the previous. */
|
219 | 84ceea57 | Edgar E. Iglesias | wd_key = ~wd_key & ((1 << 7) - 1); |
220 | 5439779e | edgar_igl | |
221 | 84ceea57 | Edgar E. Iglesias | if (wd_en && wd_key != new_key)
|
222 | 84ceea57 | Edgar E. Iglesias | return;
|
223 | 5439779e | edgar_igl | |
224 | 84ceea57 | Edgar E. Iglesias | D(printf("en=%d new_key=%x oldkey=%x cmd=%d cnt=%d\n",
|
225 | 84ceea57 | Edgar E. Iglesias | wd_en, new_key, wd_key, new_cmd, wd_cnt)); |
226 | 5439779e | edgar_igl | |
227 | 84ceea57 | Edgar E. Iglesias | if (t->wd_hits)
|
228 | 3b1fd90e | Edgar E. Iglesias | qemu_irq_lower(t->nmi); |
229 | 5ef98b47 | edgar_igl | |
230 | 84ceea57 | Edgar E. Iglesias | t->wd_hits = 0;
|
231 | 5ef98b47 | edgar_igl | |
232 | 84ceea57 | Edgar E. Iglesias | ptimer_set_freq(t->ptimer_wd, 760);
|
233 | 84ceea57 | Edgar E. Iglesias | if (wd_cnt == 0) |
234 | 84ceea57 | Edgar E. Iglesias | wd_cnt = 256;
|
235 | 84ceea57 | Edgar E. Iglesias | ptimer_set_count(t->ptimer_wd, wd_cnt); |
236 | 84ceea57 | Edgar E. Iglesias | if (new_cmd)
|
237 | 84ceea57 | Edgar E. Iglesias | ptimer_run(t->ptimer_wd, 1);
|
238 | 84ceea57 | Edgar E. Iglesias | else
|
239 | 84ceea57 | Edgar E. Iglesias | ptimer_stop(t->ptimer_wd); |
240 | 5439779e | edgar_igl | |
241 | 84ceea57 | Edgar E. Iglesias | t->rw_wd_ctrl = value; |
242 | 5439779e | edgar_igl | } |
243 | 5439779e | edgar_igl | |
244 | 83fa1010 | ths | static void |
245 | a8170e5e | Avi Kivity | timer_write(void *opaque, hwaddr addr,
|
246 | b8e5da2c | Edgar E. Iglesias | uint64_t val64, unsigned int size) |
247 | 83fa1010 | ths | { |
248 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
249 | b8e5da2c | Edgar E. Iglesias | uint32_t value = val64; |
250 | 84ceea57 | Edgar E. Iglesias | |
251 | 84ceea57 | Edgar E. Iglesias | switch (addr)
|
252 | 84ceea57 | Edgar E. Iglesias | { |
253 | 84ceea57 | Edgar E. Iglesias | case RW_TMR0_DIV:
|
254 | 84ceea57 | Edgar E. Iglesias | t->rw_tmr0_div = value; |
255 | 84ceea57 | Edgar E. Iglesias | break;
|
256 | 84ceea57 | Edgar E. Iglesias | case RW_TMR0_CTRL:
|
257 | 84ceea57 | Edgar E. Iglesias | D(printf ("RW_TMR0_CTRL=%x\n", value));
|
258 | 84ceea57 | Edgar E. Iglesias | t->rw_tmr0_ctrl = value; |
259 | 84ceea57 | Edgar E. Iglesias | update_ctrl(t, 0);
|
260 | 84ceea57 | Edgar E. Iglesias | break;
|
261 | 84ceea57 | Edgar E. Iglesias | case RW_TMR1_DIV:
|
262 | 84ceea57 | Edgar E. Iglesias | t->rw_tmr1_div = value; |
263 | 84ceea57 | Edgar E. Iglesias | break;
|
264 | 84ceea57 | Edgar E. Iglesias | case RW_TMR1_CTRL:
|
265 | 84ceea57 | Edgar E. Iglesias | D(printf ("RW_TMR1_CTRL=%x\n", value));
|
266 | 84ceea57 | Edgar E. Iglesias | t->rw_tmr1_ctrl = value; |
267 | 84ceea57 | Edgar E. Iglesias | update_ctrl(t, 1);
|
268 | 84ceea57 | Edgar E. Iglesias | break;
|
269 | 84ceea57 | Edgar E. Iglesias | case RW_INTR_MASK:
|
270 | 84ceea57 | Edgar E. Iglesias | D(printf ("RW_INTR_MASK=%x\n", value));
|
271 | 84ceea57 | Edgar E. Iglesias | t->rw_intr_mask = value; |
272 | 84ceea57 | Edgar E. Iglesias | timer_update_irq(t); |
273 | 84ceea57 | Edgar E. Iglesias | break;
|
274 | 84ceea57 | Edgar E. Iglesias | case RW_WD_CTRL:
|
275 | 84ceea57 | Edgar E. Iglesias | timer_watchdog_update(t, value); |
276 | 84ceea57 | Edgar E. Iglesias | break;
|
277 | 84ceea57 | Edgar E. Iglesias | case RW_ACK_INTR:
|
278 | 84ceea57 | Edgar E. Iglesias | t->rw_ack_intr = value; |
279 | 84ceea57 | Edgar E. Iglesias | timer_update_irq(t); |
280 | 84ceea57 | Edgar E. Iglesias | t->rw_ack_intr = 0;
|
281 | 84ceea57 | Edgar E. Iglesias | break;
|
282 | 84ceea57 | Edgar E. Iglesias | default:
|
283 | 84ceea57 | Edgar E. Iglesias | printf ("%s " TARGET_FMT_plx " %x\n", |
284 | 84ceea57 | Edgar E. Iglesias | __func__, addr, value); |
285 | 84ceea57 | Edgar E. Iglesias | break;
|
286 | 84ceea57 | Edgar E. Iglesias | } |
287 | 83fa1010 | ths | } |
288 | 83fa1010 | ths | |
289 | b8e5da2c | Edgar E. Iglesias | static const MemoryRegionOps timer_ops = { |
290 | b8e5da2c | Edgar E. Iglesias | .read = timer_read, |
291 | b8e5da2c | Edgar E. Iglesias | .write = timer_write, |
292 | b8e5da2c | Edgar E. Iglesias | .endianness = DEVICE_LITTLE_ENDIAN, |
293 | b8e5da2c | Edgar E. Iglesias | .valid = { |
294 | b8e5da2c | Edgar E. Iglesias | .min_access_size = 4,
|
295 | b8e5da2c | Edgar E. Iglesias | .max_access_size = 4
|
296 | b8e5da2c | Edgar E. Iglesias | } |
297 | 83fa1010 | ths | }; |
298 | 83fa1010 | ths | |
299 | 5439779e | edgar_igl | static void etraxfs_timer_reset(void *opaque) |
300 | 5439779e | edgar_igl | { |
301 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = opaque;
|
302 | 84ceea57 | Edgar E. Iglesias | |
303 | 84ceea57 | Edgar E. Iglesias | ptimer_stop(t->ptimer_t0); |
304 | 84ceea57 | Edgar E. Iglesias | ptimer_stop(t->ptimer_t1); |
305 | 84ceea57 | Edgar E. Iglesias | ptimer_stop(t->ptimer_wd); |
306 | 84ceea57 | Edgar E. Iglesias | t->rw_wd_ctrl = 0;
|
307 | 84ceea57 | Edgar E. Iglesias | t->r_intr = 0;
|
308 | 84ceea57 | Edgar E. Iglesias | t->rw_intr_mask = 0;
|
309 | 3b1fd90e | Edgar E. Iglesias | qemu_irq_lower(t->irq); |
310 | 5439779e | edgar_igl | } |
311 | 5439779e | edgar_igl | |
312 | 81a322d4 | Gerd Hoffmann | static int etraxfs_timer_init(SysBusDevice *dev) |
313 | 83fa1010 | ths | { |
314 | 3b1fd90e | Edgar E. Iglesias | struct etrax_timer *t = FROM_SYSBUS(typeof (*t), dev);
|
315 | 83fa1010 | ths | |
316 | 84ceea57 | Edgar E. Iglesias | t->bh_t0 = qemu_bh_new(timer0_hit, t); |
317 | 84ceea57 | Edgar E. Iglesias | t->bh_t1 = qemu_bh_new(timer1_hit, t); |
318 | 84ceea57 | Edgar E. Iglesias | t->bh_wd = qemu_bh_new(watchdog_hit, t); |
319 | 84ceea57 | Edgar E. Iglesias | t->ptimer_t0 = ptimer_init(t->bh_t0); |
320 | 84ceea57 | Edgar E. Iglesias | t->ptimer_t1 = ptimer_init(t->bh_t1); |
321 | 84ceea57 | Edgar E. Iglesias | t->ptimer_wd = ptimer_init(t->bh_wd); |
322 | 3b1fd90e | Edgar E. Iglesias | |
323 | 3b1fd90e | Edgar E. Iglesias | sysbus_init_irq(dev, &t->irq); |
324 | 3b1fd90e | Edgar E. Iglesias | sysbus_init_irq(dev, &t->nmi); |
325 | 83fa1010 | ths | |
326 | b8e5da2c | Edgar E. Iglesias | memory_region_init_io(&t->mmio, &timer_ops, t, "etraxfs-timer", 0x5c); |
327 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &t->mmio); |
328 | a08d4367 | Jan Kiszka | qemu_register_reset(etraxfs_timer_reset, t); |
329 | 81a322d4 | Gerd Hoffmann | return 0; |
330 | 83fa1010 | ths | } |
331 | 3b1fd90e | Edgar E. Iglesias | |
332 | 999e12bb | Anthony Liguori | static void etraxfs_timer_class_init(ObjectClass *klass, void *data) |
333 | 999e12bb | Anthony Liguori | { |
334 | 999e12bb | Anthony Liguori | SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); |
335 | 999e12bb | Anthony Liguori | |
336 | 999e12bb | Anthony Liguori | sdc->init = etraxfs_timer_init; |
337 | 999e12bb | Anthony Liguori | } |
338 | 999e12bb | Anthony Liguori | |
339 | 8c43a6f0 | Andreas Färber | static const TypeInfo etraxfs_timer_info = { |
340 | 39bffca2 | Anthony Liguori | .name = "etraxfs,timer",
|
341 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
342 | 39bffca2 | Anthony Liguori | .instance_size = sizeof (struct etrax_timer), |
343 | 39bffca2 | Anthony Liguori | .class_init = etraxfs_timer_class_init, |
344 | 999e12bb | Anthony Liguori | }; |
345 | 999e12bb | Anthony Liguori | |
346 | 83f7d43a | Andreas Färber | static void etraxfs_timer_register_types(void) |
347 | 3b1fd90e | Edgar E. Iglesias | { |
348 | 39bffca2 | Anthony Liguori | type_register_static(&etraxfs_timer_info); |
349 | 3b1fd90e | Edgar E. Iglesias | } |
350 | 3b1fd90e | Edgar E. Iglesias | |
351 | 83f7d43a | Andreas Färber | type_init(etraxfs_timer_register_types) |