root / hw / slavio_timer.c @ 53ea95de
History | View | Annotate | Download (13.9 kB)
1 | e80cfcfc | bellard | /*
|
---|---|---|---|
2 | e80cfcfc | bellard | * QEMU Sparc SLAVIO timer controller emulation
|
3 | e80cfcfc | bellard | *
|
4 | 66321a11 | bellard | * Copyright (c) 2003-2005 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | e80cfcfc | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | e80cfcfc | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | e80cfcfc | bellard | * in the Software without restriction, including without limitation the rights
|
9 | e80cfcfc | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | e80cfcfc | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | e80cfcfc | bellard | * furnished to do so, subject to the following conditions:
|
12 | e80cfcfc | bellard | *
|
13 | e80cfcfc | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | e80cfcfc | bellard | * all copies or substantial portions of the Software.
|
15 | e80cfcfc | bellard | *
|
16 | e80cfcfc | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | e80cfcfc | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | e80cfcfc | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | e80cfcfc | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | e80cfcfc | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | e80cfcfc | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | e80cfcfc | bellard | * THE SOFTWARE.
|
23 | e80cfcfc | bellard | */
|
24 | c70c59ee | Blue Swirl | |
25 | 87ecb68b | pbrook | #include "sun4m.h" |
26 | 87ecb68b | pbrook | #include "qemu-timer.h" |
27 | c70c59ee | Blue Swirl | #include "sysbus.h" |
28 | e80cfcfc | bellard | |
29 | e80cfcfc | bellard | //#define DEBUG_TIMER
|
30 | e80cfcfc | bellard | |
31 | 66321a11 | bellard | #ifdef DEBUG_TIMER
|
32 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
33 | 001faf32 | Blue Swirl | do { printf("TIMER: " fmt , ## __VA_ARGS__); } while (0) |
34 | 66321a11 | bellard | #else
|
35 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do {} while (0) |
36 | 66321a11 | bellard | #endif
|
37 | 66321a11 | bellard | |
38 | e80cfcfc | bellard | /*
|
39 | e80cfcfc | bellard | * Registers of hardware timer in sun4m.
|
40 | e80cfcfc | bellard | *
|
41 | e80cfcfc | bellard | * This is the timer/counter part of chip STP2001 (Slave I/O), also
|
42 | e80cfcfc | bellard | * produced as NCR89C105. See
|
43 | e80cfcfc | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
|
44 | 5fafdf24 | ths | *
|
45 | e80cfcfc | bellard | * The 31-bit counter is incremented every 500ns by bit 9. Bits 8..0
|
46 | e80cfcfc | bellard | * are zero. Bit 31 is 1 when count has been reached.
|
47 | e80cfcfc | bellard | *
|
48 | ba3c64fb | bellard | * Per-CPU timers interrupt local CPU, system timer uses normal
|
49 | ba3c64fb | bellard | * interrupt routing.
|
50 | ba3c64fb | bellard | *
|
51 | e80cfcfc | bellard | */
|
52 | e80cfcfc | bellard | |
53 | 81732d19 | blueswir1 | #define MAX_CPUS 16 |
54 | 81732d19 | blueswir1 | |
55 | 7204ff9c | Blue Swirl | typedef struct CPUTimerState { |
56 | d7edfd27 | blueswir1 | qemu_irq irq; |
57 | 8d05ea8a | blueswir1 | ptimer_state *timer; |
58 | 8d05ea8a | blueswir1 | uint32_t count, counthigh, reached; |
59 | 8d05ea8a | blueswir1 | uint64_t limit; |
60 | 115646b6 | blueswir1 | // processor only
|
61 | 22548760 | blueswir1 | uint32_t running; |
62 | 7204ff9c | Blue Swirl | } CPUTimerState; |
63 | 7204ff9c | Blue Swirl | |
64 | 7204ff9c | Blue Swirl | typedef struct SLAVIO_TIMERState { |
65 | 7204ff9c | Blue Swirl | SysBusDevice busdev; |
66 | 7204ff9c | Blue Swirl | uint32_t num_cpus; |
67 | 7204ff9c | Blue Swirl | CPUTimerState cputimer[MAX_CPUS + 1];
|
68 | 7204ff9c | Blue Swirl | uint32_t cputimer_mode; |
69 | e80cfcfc | bellard | } SLAVIO_TIMERState; |
70 | e80cfcfc | bellard | |
71 | 7204ff9c | Blue Swirl | typedef struct TimerContext { |
72 | 7204ff9c | Blue Swirl | SLAVIO_TIMERState *s; |
73 | 7204ff9c | Blue Swirl | unsigned int timer_index; /* 0 for system, 1 ... MAX_CPUS for CPU timers */ |
74 | 7204ff9c | Blue Swirl | } TimerContext; |
75 | 7204ff9c | Blue Swirl | |
76 | 115646b6 | blueswir1 | #define SYS_TIMER_SIZE 0x14 |
77 | 81732d19 | blueswir1 | #define CPU_TIMER_SIZE 0x10 |
78 | e80cfcfc | bellard | |
79 | d2c38b24 | blueswir1 | #define TIMER_LIMIT 0 |
80 | d2c38b24 | blueswir1 | #define TIMER_COUNTER 1 |
81 | d2c38b24 | blueswir1 | #define TIMER_COUNTER_NORST 2 |
82 | d2c38b24 | blueswir1 | #define TIMER_STATUS 3 |
83 | d2c38b24 | blueswir1 | #define TIMER_MODE 4 |
84 | d2c38b24 | blueswir1 | |
85 | d2c38b24 | blueswir1 | #define TIMER_COUNT_MASK32 0xfffffe00 |
86 | d2c38b24 | blueswir1 | #define TIMER_LIMIT_MASK32 0x7fffffff |
87 | d2c38b24 | blueswir1 | #define TIMER_MAX_COUNT64 0x7ffffffffffffe00ULL |
88 | d2c38b24 | blueswir1 | #define TIMER_MAX_COUNT32 0x7ffffe00ULL |
89 | d2c38b24 | blueswir1 | #define TIMER_REACHED 0x80000000 |
90 | d2c38b24 | blueswir1 | #define TIMER_PERIOD 500ULL // 500ns |
91 | d2c38b24 | blueswir1 | #define LIMIT_TO_PERIODS(l) ((l) >> 9) |
92 | d2c38b24 | blueswir1 | #define PERIODS_TO_LIMIT(l) ((l) << 9) |
93 | d2c38b24 | blueswir1 | |
94 | 7204ff9c | Blue Swirl | static int slavio_timer_is_user(TimerContext *tc) |
95 | 115646b6 | blueswir1 | { |
96 | 7204ff9c | Blue Swirl | SLAVIO_TIMERState *s = tc->s; |
97 | 7204ff9c | Blue Swirl | unsigned int timer_index = tc->timer_index; |
98 | 7204ff9c | Blue Swirl | |
99 | 7204ff9c | Blue Swirl | return timer_index != 0 && (s->cputimer_mode & (1 << (timer_index - 1))); |
100 | 115646b6 | blueswir1 | } |
101 | 115646b6 | blueswir1 | |
102 | e80cfcfc | bellard | // Update count, set irq, update expire_time
|
103 | 8d05ea8a | blueswir1 | // Convert from ptimer countdown units
|
104 | 7204ff9c | Blue Swirl | static void slavio_timer_get_out(CPUTimerState *t) |
105 | e80cfcfc | bellard | { |
106 | bd7e2875 | blueswir1 | uint64_t count, limit; |
107 | e80cfcfc | bellard | |
108 | 7204ff9c | Blue Swirl | if (t->limit == 0) { /* free-run system or processor counter */ |
109 | bd7e2875 | blueswir1 | limit = TIMER_MAX_COUNT32; |
110 | 7204ff9c | Blue Swirl | } else {
|
111 | 7204ff9c | Blue Swirl | limit = t->limit; |
112 | 7204ff9c | Blue Swirl | } |
113 | 9ebec28b | Blue Swirl | count = limit - PERIODS_TO_LIMIT(ptimer_get_count(t->timer)); |
114 | 9ebec28b | Blue Swirl | |
115 | 7204ff9c | Blue Swirl | DPRINTF("get_out: limit %" PRIx64 " count %x%08x\n", t->limit, t->counthigh, |
116 | 7204ff9c | Blue Swirl | t->count); |
117 | 7204ff9c | Blue Swirl | t->count = count & TIMER_COUNT_MASK32; |
118 | 7204ff9c | Blue Swirl | t->counthigh = count >> 32;
|
119 | e80cfcfc | bellard | } |
120 | e80cfcfc | bellard | |
121 | e80cfcfc | bellard | // timer callback
|
122 | e80cfcfc | bellard | static void slavio_timer_irq(void *opaque) |
123 | e80cfcfc | bellard | { |
124 | 7204ff9c | Blue Swirl | TimerContext *tc = opaque; |
125 | 7204ff9c | Blue Swirl | SLAVIO_TIMERState *s = tc->s; |
126 | 7204ff9c | Blue Swirl | CPUTimerState *t = &s->cputimer[tc->timer_index]; |
127 | 7204ff9c | Blue Swirl | |
128 | 7204ff9c | Blue Swirl | slavio_timer_get_out(t); |
129 | 7204ff9c | Blue Swirl | DPRINTF("callback: count %x%08x\n", t->counthigh, t->count);
|
130 | 7204ff9c | Blue Swirl | t->reached = TIMER_REACHED; |
131 | 7204ff9c | Blue Swirl | if (!slavio_timer_is_user(tc)) {
|
132 | 7204ff9c | Blue Swirl | qemu_irq_raise(t->irq); |
133 | 7204ff9c | Blue Swirl | } |
134 | e80cfcfc | bellard | } |
135 | e80cfcfc | bellard | |
136 | c227f099 | Anthony Liguori | static uint32_t slavio_timer_mem_readl(void *opaque, target_phys_addr_t addr) |
137 | e80cfcfc | bellard | { |
138 | 7204ff9c | Blue Swirl | TimerContext *tc = opaque; |
139 | 7204ff9c | Blue Swirl | SLAVIO_TIMERState *s = tc->s; |
140 | 8d05ea8a | blueswir1 | uint32_t saddr, ret; |
141 | 7204ff9c | Blue Swirl | unsigned int timer_index = tc->timer_index; |
142 | 7204ff9c | Blue Swirl | CPUTimerState *t = &s->cputimer[timer_index]; |
143 | e80cfcfc | bellard | |
144 | e64d7d59 | blueswir1 | saddr = addr >> 2;
|
145 | e80cfcfc | bellard | switch (saddr) {
|
146 | d2c38b24 | blueswir1 | case TIMER_LIMIT:
|
147 | f930d07e | blueswir1 | // read limit (system counter mode) or read most signifying
|
148 | f930d07e | blueswir1 | // part of counter (user mode)
|
149 | 7204ff9c | Blue Swirl | if (slavio_timer_is_user(tc)) {
|
150 | 115646b6 | blueswir1 | // read user timer MSW
|
151 | 7204ff9c | Blue Swirl | slavio_timer_get_out(t); |
152 | 7204ff9c | Blue Swirl | ret = t->counthigh | t->reached; |
153 | 115646b6 | blueswir1 | } else {
|
154 | 115646b6 | blueswir1 | // read limit
|
155 | f930d07e | blueswir1 | // clear irq
|
156 | 7204ff9c | Blue Swirl | qemu_irq_lower(t->irq); |
157 | 7204ff9c | Blue Swirl | t->reached = 0;
|
158 | 7204ff9c | Blue Swirl | ret = t->limit & TIMER_LIMIT_MASK32; |
159 | f930d07e | blueswir1 | } |
160 | 8d05ea8a | blueswir1 | break;
|
161 | d2c38b24 | blueswir1 | case TIMER_COUNTER:
|
162 | f930d07e | blueswir1 | // read counter and reached bit (system mode) or read lsbits
|
163 | f930d07e | blueswir1 | // of counter (user mode)
|
164 | 7204ff9c | Blue Swirl | slavio_timer_get_out(t); |
165 | 7204ff9c | Blue Swirl | if (slavio_timer_is_user(tc)) { // read user timer LSW |
166 | 7204ff9c | Blue Swirl | ret = t->count & TIMER_MAX_COUNT64; |
167 | 7204ff9c | Blue Swirl | } else { // read limit |
168 | 7204ff9c | Blue Swirl | ret = (t->count & TIMER_MAX_COUNT32) | |
169 | 7204ff9c | Blue Swirl | t->reached; |
170 | 7204ff9c | Blue Swirl | } |
171 | 8d05ea8a | blueswir1 | break;
|
172 | d2c38b24 | blueswir1 | case TIMER_STATUS:
|
173 | 115646b6 | blueswir1 | // only available in processor counter/timer
|
174 | f930d07e | blueswir1 | // read start/stop status
|
175 | 7204ff9c | Blue Swirl | if (timer_index > 0) { |
176 | 7204ff9c | Blue Swirl | ret = t->running; |
177 | 7204ff9c | Blue Swirl | } else {
|
178 | 7204ff9c | Blue Swirl | ret = 0;
|
179 | 7204ff9c | Blue Swirl | } |
180 | 8d05ea8a | blueswir1 | break;
|
181 | d2c38b24 | blueswir1 | case TIMER_MODE:
|
182 | 115646b6 | blueswir1 | // only available in system counter
|
183 | f930d07e | blueswir1 | // read user/system mode
|
184 | 7204ff9c | Blue Swirl | ret = s->cputimer_mode; |
185 | 8d05ea8a | blueswir1 | break;
|
186 | e80cfcfc | bellard | default:
|
187 | 115646b6 | blueswir1 | DPRINTF("invalid read address " TARGET_FMT_plx "\n", addr); |
188 | 8d05ea8a | blueswir1 | ret = 0;
|
189 | 8d05ea8a | blueswir1 | break;
|
190 | e80cfcfc | bellard | } |
191 | 8d05ea8a | blueswir1 | DPRINTF("read " TARGET_FMT_plx " = %08x\n", addr, ret); |
192 | 8d05ea8a | blueswir1 | |
193 | 8d05ea8a | blueswir1 | return ret;
|
194 | e80cfcfc | bellard | } |
195 | e80cfcfc | bellard | |
196 | c227f099 | Anthony Liguori | static void slavio_timer_mem_writel(void *opaque, target_phys_addr_t addr, |
197 | d2c38b24 | blueswir1 | uint32_t val) |
198 | e80cfcfc | bellard | { |
199 | 7204ff9c | Blue Swirl | TimerContext *tc = opaque; |
200 | 7204ff9c | Blue Swirl | SLAVIO_TIMERState *s = tc->s; |
201 | e80cfcfc | bellard | uint32_t saddr; |
202 | 7204ff9c | Blue Swirl | unsigned int timer_index = tc->timer_index; |
203 | 7204ff9c | Blue Swirl | CPUTimerState *t = &s->cputimer[timer_index]; |
204 | e80cfcfc | bellard | |
205 | 8d05ea8a | blueswir1 | DPRINTF("write " TARGET_FMT_plx " %08x\n", addr, val); |
206 | e64d7d59 | blueswir1 | saddr = addr >> 2;
|
207 | e80cfcfc | bellard | switch (saddr) {
|
208 | d2c38b24 | blueswir1 | case TIMER_LIMIT:
|
209 | 7204ff9c | Blue Swirl | if (slavio_timer_is_user(tc)) {
|
210 | e1cb9502 | blueswir1 | uint64_t count; |
211 | e1cb9502 | blueswir1 | |
212 | 115646b6 | blueswir1 | // set user counter MSW, reset counter
|
213 | 7204ff9c | Blue Swirl | t->limit = TIMER_MAX_COUNT64; |
214 | 7204ff9c | Blue Swirl | t->counthigh = val & (TIMER_MAX_COUNT64 >> 32);
|
215 | 7204ff9c | Blue Swirl | t->reached = 0;
|
216 | 7204ff9c | Blue Swirl | count = ((uint64_t)t->counthigh << 32) | t->count;
|
217 | 0bf9e31a | Blue Swirl | DPRINTF("processor %d user timer set to %016" PRIx64 "\n", |
218 | 7204ff9c | Blue Swirl | timer_index, count); |
219 | 9ebec28b | Blue Swirl | ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count)); |
220 | 115646b6 | blueswir1 | } else {
|
221 | 115646b6 | blueswir1 | // set limit, reset counter
|
222 | 7204ff9c | Blue Swirl | qemu_irq_lower(t->irq); |
223 | 7204ff9c | Blue Swirl | t->limit = val & TIMER_MAX_COUNT32; |
224 | 7204ff9c | Blue Swirl | if (t->timer) {
|
225 | 7204ff9c | Blue Swirl | if (t->limit == 0) { /* free-run */ |
226 | 7204ff9c | Blue Swirl | ptimer_set_limit(t->timer, |
227 | 77f193da | blueswir1 | LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1);
|
228 | 7204ff9c | Blue Swirl | } else {
|
229 | 7204ff9c | Blue Swirl | ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 1);
|
230 | 7204ff9c | Blue Swirl | } |
231 | 85e3023e | blueswir1 | } |
232 | 81732d19 | blueswir1 | } |
233 | 115646b6 | blueswir1 | break;
|
234 | d2c38b24 | blueswir1 | case TIMER_COUNTER:
|
235 | 7204ff9c | Blue Swirl | if (slavio_timer_is_user(tc)) {
|
236 | e1cb9502 | blueswir1 | uint64_t count; |
237 | e1cb9502 | blueswir1 | |
238 | 115646b6 | blueswir1 | // set user counter LSW, reset counter
|
239 | 7204ff9c | Blue Swirl | t->limit = TIMER_MAX_COUNT64; |
240 | 7204ff9c | Blue Swirl | t->count = val & TIMER_MAX_COUNT64; |
241 | 7204ff9c | Blue Swirl | t->reached = 0;
|
242 | 7204ff9c | Blue Swirl | count = ((uint64_t)t->counthigh) << 32 | t->count;
|
243 | 0bf9e31a | Blue Swirl | DPRINTF("processor %d user timer set to %016" PRIx64 "\n", |
244 | 7204ff9c | Blue Swirl | timer_index, count); |
245 | 9ebec28b | Blue Swirl | ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count)); |
246 | 115646b6 | blueswir1 | } else
|
247 | 115646b6 | blueswir1 | DPRINTF("not user timer\n");
|
248 | 115646b6 | blueswir1 | break;
|
249 | d2c38b24 | blueswir1 | case TIMER_COUNTER_NORST:
|
250 | f930d07e | blueswir1 | // set limit without resetting counter
|
251 | 7204ff9c | Blue Swirl | t->limit = val & TIMER_MAX_COUNT32; |
252 | 9ebec28b | Blue Swirl | if (t->limit == 0) { /* free-run */ |
253 | 9ebec28b | Blue Swirl | ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 0);
|
254 | 9ebec28b | Blue Swirl | } else {
|
255 | 9ebec28b | Blue Swirl | ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 0);
|
256 | 85e3023e | blueswir1 | } |
257 | f930d07e | blueswir1 | break;
|
258 | d2c38b24 | blueswir1 | case TIMER_STATUS:
|
259 | 7204ff9c | Blue Swirl | if (slavio_timer_is_user(tc)) {
|
260 | 115646b6 | blueswir1 | // start/stop user counter
|
261 | 7204ff9c | Blue Swirl | if ((val & 1) && !t->running) { |
262 | 7204ff9c | Blue Swirl | DPRINTF("processor %d user timer started\n",
|
263 | 7204ff9c | Blue Swirl | timer_index); |
264 | 9ebec28b | Blue Swirl | ptimer_run(t->timer, 0);
|
265 | 7204ff9c | Blue Swirl | t->running = 1;
|
266 | 7204ff9c | Blue Swirl | } else if (!(val & 1) && t->running) { |
267 | 7204ff9c | Blue Swirl | DPRINTF("processor %d user timer stopped\n",
|
268 | 7204ff9c | Blue Swirl | timer_index); |
269 | 9ebec28b | Blue Swirl | ptimer_stop(t->timer); |
270 | 7204ff9c | Blue Swirl | t->running = 0;
|
271 | f930d07e | blueswir1 | } |
272 | f930d07e | blueswir1 | } |
273 | f930d07e | blueswir1 | break;
|
274 | d2c38b24 | blueswir1 | case TIMER_MODE:
|
275 | 7204ff9c | Blue Swirl | if (timer_index == 0) { |
276 | 81732d19 | blueswir1 | unsigned int i; |
277 | 81732d19 | blueswir1 | |
278 | 7204ff9c | Blue Swirl | for (i = 0; i < s->num_cpus; i++) { |
279 | 67e42751 | blueswir1 | unsigned int processor = 1 << i; |
280 | 7204ff9c | Blue Swirl | CPUTimerState *curr_timer = &s->cputimer[i + 1];
|
281 | 67e42751 | blueswir1 | |
282 | 67e42751 | blueswir1 | // check for a change in timer mode for this processor
|
283 | 7204ff9c | Blue Swirl | if ((val & processor) != (s->cputimer_mode & processor)) {
|
284 | 67e42751 | blueswir1 | if (val & processor) { // counter -> user timer |
285 | 7204ff9c | Blue Swirl | qemu_irq_lower(curr_timer->irq); |
286 | 67e42751 | blueswir1 | // counters are always running
|
287 | 7204ff9c | Blue Swirl | ptimer_stop(curr_timer->timer); |
288 | 7204ff9c | Blue Swirl | curr_timer->running = 0;
|
289 | 67e42751 | blueswir1 | // user timer limit is always the same
|
290 | 7204ff9c | Blue Swirl | curr_timer->limit = TIMER_MAX_COUNT64; |
291 | 7204ff9c | Blue Swirl | ptimer_set_limit(curr_timer->timer, |
292 | 7204ff9c | Blue Swirl | LIMIT_TO_PERIODS(curr_timer->limit), |
293 | 77f193da | blueswir1 | 1);
|
294 | 67e42751 | blueswir1 | // set this processors user timer bit in config
|
295 | 67e42751 | blueswir1 | // register
|
296 | 7204ff9c | Blue Swirl | s->cputimer_mode |= processor; |
297 | 67e42751 | blueswir1 | DPRINTF("processor %d changed from counter to user "
|
298 | 7204ff9c | Blue Swirl | "timer\n", timer_index);
|
299 | 67e42751 | blueswir1 | } else { // user timer -> counter |
300 | 67e42751 | blueswir1 | // stop the user timer if it is running
|
301 | 7204ff9c | Blue Swirl | if (curr_timer->running) {
|
302 | 7204ff9c | Blue Swirl | ptimer_stop(curr_timer->timer); |
303 | 7204ff9c | Blue Swirl | } |
304 | 67e42751 | blueswir1 | // start the counter
|
305 | 7204ff9c | Blue Swirl | ptimer_run(curr_timer->timer, 0);
|
306 | 7204ff9c | Blue Swirl | curr_timer->running = 1;
|
307 | 67e42751 | blueswir1 | // clear this processors user timer bit in config
|
308 | 67e42751 | blueswir1 | // register
|
309 | 7204ff9c | Blue Swirl | s->cputimer_mode &= ~processor; |
310 | 67e42751 | blueswir1 | DPRINTF("processor %d changed from user timer to "
|
311 | 7204ff9c | Blue Swirl | "counter\n", timer_index);
|
312 | 67e42751 | blueswir1 | } |
313 | 115646b6 | blueswir1 | } |
314 | 81732d19 | blueswir1 | } |
315 | 7204ff9c | Blue Swirl | } else {
|
316 | 115646b6 | blueswir1 | DPRINTF("not system timer\n");
|
317 | 7204ff9c | Blue Swirl | } |
318 | f930d07e | blueswir1 | break;
|
319 | e80cfcfc | bellard | default:
|
320 | 115646b6 | blueswir1 | DPRINTF("invalid write address " TARGET_FMT_plx "\n", addr); |
321 | f930d07e | blueswir1 | break;
|
322 | e80cfcfc | bellard | } |
323 | e80cfcfc | bellard | } |
324 | e80cfcfc | bellard | |
325 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const slavio_timer_mem_read[3] = { |
326 | 7c560456 | blueswir1 | NULL,
|
327 | 7c560456 | blueswir1 | NULL,
|
328 | e80cfcfc | bellard | slavio_timer_mem_readl, |
329 | e80cfcfc | bellard | }; |
330 | e80cfcfc | bellard | |
331 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const slavio_timer_mem_write[3] = { |
332 | 7c560456 | blueswir1 | NULL,
|
333 | 7c560456 | blueswir1 | NULL,
|
334 | e80cfcfc | bellard | slavio_timer_mem_writel, |
335 | e80cfcfc | bellard | }; |
336 | e80cfcfc | bellard | |
337 | f4b19cd0 | Blue Swirl | static const VMStateDescription vmstate_timer = { |
338 | f4b19cd0 | Blue Swirl | .name ="timer",
|
339 | f4b19cd0 | Blue Swirl | .version_id = 3,
|
340 | f4b19cd0 | Blue Swirl | .minimum_version_id = 3,
|
341 | f4b19cd0 | Blue Swirl | .minimum_version_id_old = 3,
|
342 | f4b19cd0 | Blue Swirl | .fields = (VMStateField []) { |
343 | f4b19cd0 | Blue Swirl | VMSTATE_UINT64(limit, CPUTimerState), |
344 | f4b19cd0 | Blue Swirl | VMSTATE_UINT32(count, CPUTimerState), |
345 | f4b19cd0 | Blue Swirl | VMSTATE_UINT32(counthigh, CPUTimerState), |
346 | f4b19cd0 | Blue Swirl | VMSTATE_UINT32(reached, CPUTimerState), |
347 | f4b19cd0 | Blue Swirl | VMSTATE_UINT32(running, CPUTimerState), |
348 | f4b19cd0 | Blue Swirl | VMSTATE_PTIMER(timer, CPUTimerState), |
349 | f4b19cd0 | Blue Swirl | VMSTATE_END_OF_LIST() |
350 | 7204ff9c | Blue Swirl | } |
351 | f4b19cd0 | Blue Swirl | }; |
352 | e80cfcfc | bellard | |
353 | f4b19cd0 | Blue Swirl | static const VMStateDescription vmstate_slavio_timer = { |
354 | f4b19cd0 | Blue Swirl | .name ="slavio_timer",
|
355 | f4b19cd0 | Blue Swirl | .version_id = 3,
|
356 | f4b19cd0 | Blue Swirl | .minimum_version_id = 3,
|
357 | f4b19cd0 | Blue Swirl | .minimum_version_id_old = 3,
|
358 | f4b19cd0 | Blue Swirl | .fields = (VMStateField []) { |
359 | f4b19cd0 | Blue Swirl | VMSTATE_STRUCT_ARRAY(cputimer, SLAVIO_TIMERState, MAX_CPUS + 1, 3, |
360 | f4b19cd0 | Blue Swirl | vmstate_timer, CPUTimerState), |
361 | f4b19cd0 | Blue Swirl | VMSTATE_END_OF_LIST() |
362 | 7204ff9c | Blue Swirl | } |
363 | f4b19cd0 | Blue Swirl | }; |
364 | e80cfcfc | bellard | |
365 | 0e0bfeea | Blue Swirl | static void slavio_timer_reset(DeviceState *d) |
366 | e80cfcfc | bellard | { |
367 | 0e0bfeea | Blue Swirl | SLAVIO_TIMERState *s = container_of(d, SLAVIO_TIMERState, busdev.qdev); |
368 | 7204ff9c | Blue Swirl | unsigned int i; |
369 | 7204ff9c | Blue Swirl | CPUTimerState *curr_timer; |
370 | 7204ff9c | Blue Swirl | |
371 | 7204ff9c | Blue Swirl | for (i = 0; i <= MAX_CPUS; i++) { |
372 | 7204ff9c | Blue Swirl | curr_timer = &s->cputimer[i]; |
373 | 7204ff9c | Blue Swirl | curr_timer->limit = 0;
|
374 | 7204ff9c | Blue Swirl | curr_timer->count = 0;
|
375 | 7204ff9c | Blue Swirl | curr_timer->reached = 0;
|
376 | 7204ff9c | Blue Swirl | if (i < s->num_cpus) {
|
377 | 7204ff9c | Blue Swirl | ptimer_set_limit(curr_timer->timer, |
378 | 7204ff9c | Blue Swirl | LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1);
|
379 | 7204ff9c | Blue Swirl | ptimer_run(curr_timer->timer, 0);
|
380 | 7204ff9c | Blue Swirl | } |
381 | 7204ff9c | Blue Swirl | curr_timer->running = 1;
|
382 | 85e3023e | blueswir1 | } |
383 | 7204ff9c | Blue Swirl | s->cputimer_mode = 0;
|
384 | e80cfcfc | bellard | } |
385 | e80cfcfc | bellard | |
386 | 81a322d4 | Gerd Hoffmann | static int slavio_timer_init1(SysBusDevice *dev) |
387 | c70c59ee | Blue Swirl | { |
388 | c70c59ee | Blue Swirl | int io;
|
389 | c70c59ee | Blue Swirl | SLAVIO_TIMERState *s = FROM_SYSBUS(SLAVIO_TIMERState, dev); |
390 | 8d05ea8a | blueswir1 | QEMUBH *bh; |
391 | 7204ff9c | Blue Swirl | unsigned int i; |
392 | 7204ff9c | Blue Swirl | TimerContext *tc; |
393 | e80cfcfc | bellard | |
394 | 7204ff9c | Blue Swirl | for (i = 0; i <= MAX_CPUS; i++) { |
395 | 7204ff9c | Blue Swirl | tc = qemu_mallocz(sizeof(TimerContext));
|
396 | 7204ff9c | Blue Swirl | tc->s = s; |
397 | 7204ff9c | Blue Swirl | tc->timer_index = i; |
398 | c70c59ee | Blue Swirl | |
399 | 7204ff9c | Blue Swirl | bh = qemu_bh_new(slavio_timer_irq, tc); |
400 | 7204ff9c | Blue Swirl | s->cputimer[i].timer = ptimer_init(bh); |
401 | 7204ff9c | Blue Swirl | ptimer_set_period(s->cputimer[i].timer, TIMER_PERIOD); |
402 | e80cfcfc | bellard | |
403 | 7204ff9c | Blue Swirl | io = cpu_register_io_memory(slavio_timer_mem_read, |
404 | 7204ff9c | Blue Swirl | slavio_timer_mem_write, tc); |
405 | 7204ff9c | Blue Swirl | if (i == 0) { |
406 | 7204ff9c | Blue Swirl | sysbus_init_mmio(dev, SYS_TIMER_SIZE, io); |
407 | 7204ff9c | Blue Swirl | } else {
|
408 | 7204ff9c | Blue Swirl | sysbus_init_mmio(dev, CPU_TIMER_SIZE, io); |
409 | 7204ff9c | Blue Swirl | } |
410 | 7204ff9c | Blue Swirl | |
411 | 7204ff9c | Blue Swirl | sysbus_init_irq(dev, &s->cputimer[i].irq); |
412 | c70c59ee | Blue Swirl | } |
413 | c70c59ee | Blue Swirl | |
414 | 81a322d4 | Gerd Hoffmann | return 0; |
415 | 81732d19 | blueswir1 | } |
416 | 81732d19 | blueswir1 | |
417 | c70c59ee | Blue Swirl | static SysBusDeviceInfo slavio_timer_info = {
|
418 | c70c59ee | Blue Swirl | .init = slavio_timer_init1, |
419 | c70c59ee | Blue Swirl | .qdev.name = "slavio_timer",
|
420 | c70c59ee | Blue Swirl | .qdev.size = sizeof(SLAVIO_TIMERState),
|
421 | 0e0bfeea | Blue Swirl | .qdev.vmsd = &vmstate_slavio_timer, |
422 | 0e0bfeea | Blue Swirl | .qdev.reset = slavio_timer_reset, |
423 | ee6847d1 | Gerd Hoffmann | .qdev.props = (Property[]) { |
424 | 18c637dc | Gerd Hoffmann | DEFINE_PROP_UINT32("num_cpus", SLAVIO_TIMERState, num_cpus, 0), |
425 | 18c637dc | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
426 | c70c59ee | Blue Swirl | } |
427 | c70c59ee | Blue Swirl | }; |
428 | c70c59ee | Blue Swirl | |
429 | c70c59ee | Blue Swirl | static void slavio_timer_register_devices(void) |
430 | c70c59ee | Blue Swirl | { |
431 | c70c59ee | Blue Swirl | sysbus_register_withprop(&slavio_timer_info); |
432 | c70c59ee | Blue Swirl | } |
433 | c70c59ee | Blue Swirl | |
434 | c70c59ee | Blue Swirl | device_init(slavio_timer_register_devices) |