root / hw / mcf5206.c @ 0abaa7c1
History | View | Annotate | Download (13.8 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 0633879f | pbrook | * Motorola ColdFire MCF5206 SoC embedded peripheral emulation.
|
3 | 0633879f | pbrook | *
|
4 | 0633879f | pbrook | * Copyright (c) 2007 CodeSourcery.
|
5 | 0633879f | pbrook | *
|
6 | 0633879f | pbrook | * This code is licenced under the GPL
|
7 | 0633879f | pbrook | */
|
8 | 87ecb68b | pbrook | #include "hw.h" |
9 | 87ecb68b | pbrook | #include "mcf.h" |
10 | 87ecb68b | pbrook | #include "qemu-timer.h" |
11 | 87ecb68b | pbrook | #include "sysemu.h" |
12 | 0633879f | pbrook | |
13 | 0633879f | pbrook | /* General purpose timer module. */
|
14 | 0633879f | pbrook | typedef struct { |
15 | 0633879f | pbrook | uint16_t tmr; |
16 | 0633879f | pbrook | uint16_t trr; |
17 | 0633879f | pbrook | uint16_t tcr; |
18 | 0633879f | pbrook | uint16_t ter; |
19 | 0633879f | pbrook | ptimer_state *timer; |
20 | 0633879f | pbrook | qemu_irq irq; |
21 | 0633879f | pbrook | int irq_state;
|
22 | 0633879f | pbrook | } m5206_timer_state; |
23 | 0633879f | pbrook | |
24 | 0633879f | pbrook | #define TMR_RST 0x01 |
25 | 0633879f | pbrook | #define TMR_CLK 0x06 |
26 | 0633879f | pbrook | #define TMR_FRR 0x08 |
27 | 0633879f | pbrook | #define TMR_ORI 0x10 |
28 | 0633879f | pbrook | #define TMR_OM 0x20 |
29 | 0633879f | pbrook | #define TMR_CE 0xc0 |
30 | 0633879f | pbrook | |
31 | 0633879f | pbrook | #define TER_CAP 0x01 |
32 | 0633879f | pbrook | #define TER_REF 0x02 |
33 | 0633879f | pbrook | |
34 | 0633879f | pbrook | static void m5206_timer_update(m5206_timer_state *s) |
35 | 0633879f | pbrook | { |
36 | 0633879f | pbrook | if ((s->tmr & TMR_ORI) != 0 && (s->ter & TER_REF)) |
37 | 0633879f | pbrook | qemu_irq_raise(s->irq); |
38 | 0633879f | pbrook | else
|
39 | 0633879f | pbrook | qemu_irq_lower(s->irq); |
40 | 0633879f | pbrook | } |
41 | 0633879f | pbrook | |
42 | 0633879f | pbrook | static void m5206_timer_reset(m5206_timer_state *s) |
43 | 0633879f | pbrook | { |
44 | 0633879f | pbrook | s->tmr = 0;
|
45 | 0633879f | pbrook | s->trr = 0;
|
46 | 0633879f | pbrook | } |
47 | 0633879f | pbrook | |
48 | 0633879f | pbrook | static void m5206_timer_recalibrate(m5206_timer_state *s) |
49 | 0633879f | pbrook | { |
50 | 0633879f | pbrook | int prescale;
|
51 | 0633879f | pbrook | int mode;
|
52 | 0633879f | pbrook | |
53 | 0633879f | pbrook | ptimer_stop(s->timer); |
54 | 0633879f | pbrook | |
55 | 0633879f | pbrook | if ((s->tmr & TMR_RST) == 0) |
56 | 0633879f | pbrook | return;
|
57 | 0633879f | pbrook | |
58 | 0633879f | pbrook | prescale = (s->tmr >> 8) + 1; |
59 | 0633879f | pbrook | mode = (s->tmr >> 1) & 3; |
60 | 0633879f | pbrook | if (mode == 2) |
61 | 0633879f | pbrook | prescale *= 16;
|
62 | 0633879f | pbrook | |
63 | 0633879f | pbrook | if (mode == 3 || mode == 0) |
64 | 2ac71179 | Paul Brook | hw_error("m5206_timer: mode %d not implemented\n", mode);
|
65 | 0633879f | pbrook | if ((s->tmr & TMR_FRR) == 0) |
66 | 2ac71179 | Paul Brook | hw_error("m5206_timer: free running mode not implemented\n");
|
67 | 0633879f | pbrook | |
68 | 0633879f | pbrook | /* Assume 66MHz system clock. */
|
69 | 0633879f | pbrook | ptimer_set_freq(s->timer, 66000000 / prescale);
|
70 | 0633879f | pbrook | |
71 | 0633879f | pbrook | ptimer_set_limit(s->timer, s->trr, 0);
|
72 | 0633879f | pbrook | |
73 | 0633879f | pbrook | ptimer_run(s->timer, 0);
|
74 | 0633879f | pbrook | } |
75 | 0633879f | pbrook | |
76 | 0633879f | pbrook | static void m5206_timer_trigger(void *opaque) |
77 | 0633879f | pbrook | { |
78 | 0633879f | pbrook | m5206_timer_state *s = (m5206_timer_state *)opaque; |
79 | 0633879f | pbrook | s->ter |= TER_REF; |
80 | 0633879f | pbrook | m5206_timer_update(s); |
81 | 0633879f | pbrook | } |
82 | 0633879f | pbrook | |
83 | 0633879f | pbrook | static uint32_t m5206_timer_read(m5206_timer_state *s, uint32_t addr)
|
84 | 0633879f | pbrook | { |
85 | 0633879f | pbrook | switch (addr) {
|
86 | 0633879f | pbrook | case 0: |
87 | 0633879f | pbrook | return s->tmr;
|
88 | 0633879f | pbrook | case 4: |
89 | 0633879f | pbrook | return s->trr;
|
90 | 0633879f | pbrook | case 8: |
91 | 0633879f | pbrook | return s->tcr;
|
92 | 0633879f | pbrook | case 0xc: |
93 | 0633879f | pbrook | return s->trr - ptimer_get_count(s->timer);
|
94 | 0633879f | pbrook | case 0x11: |
95 | 0633879f | pbrook | return s->ter;
|
96 | 0633879f | pbrook | default:
|
97 | 0633879f | pbrook | return 0; |
98 | 0633879f | pbrook | } |
99 | 0633879f | pbrook | } |
100 | 0633879f | pbrook | |
101 | 0633879f | pbrook | static void m5206_timer_write(m5206_timer_state *s, uint32_t addr, uint32_t val) |
102 | 0633879f | pbrook | { |
103 | 0633879f | pbrook | switch (addr) {
|
104 | 0633879f | pbrook | case 0: |
105 | 0633879f | pbrook | if ((s->tmr & TMR_RST) != 0 && (val & TMR_RST) == 0) { |
106 | 0633879f | pbrook | m5206_timer_reset(s); |
107 | 0633879f | pbrook | } |
108 | 0633879f | pbrook | s->tmr = val; |
109 | 0633879f | pbrook | m5206_timer_recalibrate(s); |
110 | 0633879f | pbrook | break;
|
111 | 0633879f | pbrook | case 4: |
112 | 0633879f | pbrook | s->trr = val; |
113 | 0633879f | pbrook | m5206_timer_recalibrate(s); |
114 | 0633879f | pbrook | break;
|
115 | 0633879f | pbrook | case 8: |
116 | 0633879f | pbrook | s->tcr = val; |
117 | 0633879f | pbrook | break;
|
118 | 0633879f | pbrook | case 0xc: |
119 | 0633879f | pbrook | ptimer_set_count(s->timer, val); |
120 | 0633879f | pbrook | break;
|
121 | 0633879f | pbrook | case 0x11: |
122 | 0633879f | pbrook | s->ter &= ~val; |
123 | 0633879f | pbrook | break;
|
124 | 0633879f | pbrook | default:
|
125 | 0633879f | pbrook | break;
|
126 | 0633879f | pbrook | } |
127 | 0633879f | pbrook | m5206_timer_update(s); |
128 | 0633879f | pbrook | } |
129 | 0633879f | pbrook | |
130 | 0633879f | pbrook | static m5206_timer_state *m5206_timer_init(qemu_irq irq)
|
131 | 0633879f | pbrook | { |
132 | 0633879f | pbrook | m5206_timer_state *s; |
133 | 0633879f | pbrook | QEMUBH *bh; |
134 | 0633879f | pbrook | |
135 | 0633879f | pbrook | s = (m5206_timer_state *)qemu_mallocz(sizeof(m5206_timer_state));
|
136 | 0633879f | pbrook | bh = qemu_bh_new(m5206_timer_trigger, s); |
137 | 0633879f | pbrook | s->timer = ptimer_init(bh); |
138 | 0633879f | pbrook | s->irq = irq; |
139 | 0633879f | pbrook | m5206_timer_reset(s); |
140 | 0633879f | pbrook | return s;
|
141 | 0633879f | pbrook | } |
142 | 0633879f | pbrook | |
143 | 0633879f | pbrook | /* System Integration Module. */
|
144 | 0633879f | pbrook | |
145 | 0633879f | pbrook | typedef struct { |
146 | 0633879f | pbrook | CPUState *env; |
147 | 0633879f | pbrook | m5206_timer_state *timer[2];
|
148 | 20dcee94 | pbrook | void *uart[2]; |
149 | 0633879f | pbrook | uint8_t scr; |
150 | 0633879f | pbrook | uint8_t icr[14];
|
151 | 0633879f | pbrook | uint16_t imr; /* 1 == interrupt is masked. */
|
152 | 0633879f | pbrook | uint16_t ipr; |
153 | 0633879f | pbrook | uint8_t rsr; |
154 | 0633879f | pbrook | uint8_t swivr; |
155 | 0633879f | pbrook | uint8_t par; |
156 | 0633879f | pbrook | /* Include the UART vector registers here. */
|
157 | 0633879f | pbrook | uint8_t uivr[2];
|
158 | 0633879f | pbrook | } m5206_mbar_state; |
159 | 0633879f | pbrook | |
160 | 0633879f | pbrook | /* Interrupt controller. */
|
161 | 0633879f | pbrook | |
162 | 0633879f | pbrook | static int m5206_find_pending_irq(m5206_mbar_state *s) |
163 | 0633879f | pbrook | { |
164 | 0633879f | pbrook | int level;
|
165 | 0633879f | pbrook | int vector;
|
166 | 0633879f | pbrook | uint16_t active; |
167 | 0633879f | pbrook | int i;
|
168 | 0633879f | pbrook | |
169 | 0633879f | pbrook | level = 0;
|
170 | 0633879f | pbrook | vector = 0;
|
171 | 0633879f | pbrook | active = s->ipr & ~s->imr; |
172 | 0633879f | pbrook | if (!active)
|
173 | 0633879f | pbrook | return 0; |
174 | 0633879f | pbrook | |
175 | 0633879f | pbrook | for (i = 1; i < 14; i++) { |
176 | 0633879f | pbrook | if (active & (1 << i)) { |
177 | 0633879f | pbrook | if ((s->icr[i] & 0x1f) > level) { |
178 | 0633879f | pbrook | level = s->icr[i] & 0x1f;
|
179 | 0633879f | pbrook | vector = i; |
180 | 0633879f | pbrook | } |
181 | 0633879f | pbrook | } |
182 | 0633879f | pbrook | } |
183 | 0633879f | pbrook | |
184 | 0633879f | pbrook | if (level < 4) |
185 | 0633879f | pbrook | vector = 0;
|
186 | 0633879f | pbrook | |
187 | 0633879f | pbrook | return vector;
|
188 | 0633879f | pbrook | } |
189 | 0633879f | pbrook | |
190 | 0633879f | pbrook | static void m5206_mbar_update(m5206_mbar_state *s) |
191 | 0633879f | pbrook | { |
192 | 0633879f | pbrook | int irq;
|
193 | 0633879f | pbrook | int vector;
|
194 | 0633879f | pbrook | int level;
|
195 | 0633879f | pbrook | |
196 | 0633879f | pbrook | irq = m5206_find_pending_irq(s); |
197 | 0633879f | pbrook | if (irq) {
|
198 | 0633879f | pbrook | int tmp;
|
199 | 0633879f | pbrook | tmp = s->icr[irq]; |
200 | 0633879f | pbrook | level = (tmp >> 2) & 7; |
201 | 0633879f | pbrook | if (tmp & 0x80) { |
202 | 0633879f | pbrook | /* Autovector. */
|
203 | 0633879f | pbrook | vector = 24 + level;
|
204 | 0633879f | pbrook | } else {
|
205 | 0633879f | pbrook | switch (irq) {
|
206 | 0633879f | pbrook | case 8: /* SWT */ |
207 | 0633879f | pbrook | vector = s->swivr; |
208 | 0633879f | pbrook | break;
|
209 | 0633879f | pbrook | case 12: /* UART1 */ |
210 | 0633879f | pbrook | vector = s->uivr[0];
|
211 | 0633879f | pbrook | break;
|
212 | 0633879f | pbrook | case 13: /* UART2 */ |
213 | 0633879f | pbrook | vector = s->uivr[1];
|
214 | 0633879f | pbrook | break;
|
215 | 0633879f | pbrook | default:
|
216 | 0633879f | pbrook | /* Unknown vector. */
|
217 | 0633879f | pbrook | fprintf(stderr, "Unhandled vector for IRQ %d\n", irq);
|
218 | 0633879f | pbrook | vector = 0xf;
|
219 | 0633879f | pbrook | break;
|
220 | 0633879f | pbrook | } |
221 | 0633879f | pbrook | } |
222 | 0633879f | pbrook | } else {
|
223 | 0633879f | pbrook | level = 0;
|
224 | 0633879f | pbrook | vector = 0;
|
225 | 0633879f | pbrook | } |
226 | 0633879f | pbrook | m68k_set_irq_level(s->env, level, vector); |
227 | 0633879f | pbrook | } |
228 | 0633879f | pbrook | |
229 | 0633879f | pbrook | static void m5206_mbar_set_irq(void *opaque, int irq, int level) |
230 | 0633879f | pbrook | { |
231 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
232 | 0633879f | pbrook | if (level) {
|
233 | 0633879f | pbrook | s->ipr |= 1 << irq;
|
234 | 0633879f | pbrook | } else {
|
235 | 0633879f | pbrook | s->ipr &= ~(1 << irq);
|
236 | 0633879f | pbrook | } |
237 | 0633879f | pbrook | m5206_mbar_update(s); |
238 | 0633879f | pbrook | } |
239 | 0633879f | pbrook | |
240 | 0633879f | pbrook | /* System Integration Module. */
|
241 | 0633879f | pbrook | |
242 | 0633879f | pbrook | static void m5206_mbar_reset(m5206_mbar_state *s) |
243 | 0633879f | pbrook | { |
244 | 0633879f | pbrook | s->scr = 0xc0;
|
245 | 0633879f | pbrook | s->icr[1] = 0x04; |
246 | 0633879f | pbrook | s->icr[2] = 0x08; |
247 | 0633879f | pbrook | s->icr[3] = 0x0c; |
248 | 0633879f | pbrook | s->icr[4] = 0x10; |
249 | 0633879f | pbrook | s->icr[5] = 0x14; |
250 | 0633879f | pbrook | s->icr[6] = 0x18; |
251 | 0633879f | pbrook | s->icr[7] = 0x1c; |
252 | 0633879f | pbrook | s->icr[8] = 0x1c; |
253 | 0633879f | pbrook | s->icr[9] = 0x80; |
254 | 0633879f | pbrook | s->icr[10] = 0x80; |
255 | 0633879f | pbrook | s->icr[11] = 0x80; |
256 | 0633879f | pbrook | s->icr[12] = 0x00; |
257 | 0633879f | pbrook | s->icr[13] = 0x00; |
258 | 0633879f | pbrook | s->imr = 0x3ffe;
|
259 | 0633879f | pbrook | s->rsr = 0x80;
|
260 | 0633879f | pbrook | s->swivr = 0x0f;
|
261 | 0633879f | pbrook | s->par = 0;
|
262 | 0633879f | pbrook | } |
263 | 0633879f | pbrook | |
264 | 0633879f | pbrook | static uint32_t m5206_mbar_read(m5206_mbar_state *s, uint32_t offset)
|
265 | 0633879f | pbrook | { |
266 | 0633879f | pbrook | if (offset >= 0x100 && offset < 0x120) { |
267 | 0633879f | pbrook | return m5206_timer_read(s->timer[0], offset - 0x100); |
268 | 0633879f | pbrook | } else if (offset >= 0x120 && offset < 0x140) { |
269 | 0633879f | pbrook | return m5206_timer_read(s->timer[1], offset - 0x120); |
270 | 0633879f | pbrook | } else if (offset >= 0x140 && offset < 0x160) { |
271 | 20dcee94 | pbrook | return mcf_uart_read(s->uart[0], offset - 0x140); |
272 | 0633879f | pbrook | } else if (offset >= 0x180 && offset < 0x1a0) { |
273 | 20dcee94 | pbrook | return mcf_uart_read(s->uart[1], offset - 0x180); |
274 | 0633879f | pbrook | } |
275 | 0633879f | pbrook | switch (offset) {
|
276 | 0633879f | pbrook | case 0x03: return s->scr; |
277 | 0633879f | pbrook | case 0x14 ... 0x20: return s->icr[offset - 0x13]; |
278 | 0633879f | pbrook | case 0x36: return s->imr; |
279 | 0633879f | pbrook | case 0x3a: return s->ipr; |
280 | 0633879f | pbrook | case 0x40: return s->rsr; |
281 | 0633879f | pbrook | case 0x41: return 0; |
282 | 0633879f | pbrook | case 0x42: return s->swivr; |
283 | 0633879f | pbrook | case 0x50: |
284 | 0633879f | pbrook | /* DRAM mask register. */
|
285 | 0633879f | pbrook | /* FIXME: currently hardcoded to 128Mb. */
|
286 | 0633879f | pbrook | { |
287 | 0633879f | pbrook | uint32_t mask = ~0;
|
288 | 0633879f | pbrook | while (mask > ram_size)
|
289 | 0633879f | pbrook | mask >>= 1;
|
290 | 0633879f | pbrook | return mask & 0x0ffe0000; |
291 | 0633879f | pbrook | } |
292 | 0633879f | pbrook | case 0x5c: return 1; /* DRAM bank 1 empty. */ |
293 | 0633879f | pbrook | case 0xcb: return s->par; |
294 | 0633879f | pbrook | case 0x170: return s->uivr[0]; |
295 | 0633879f | pbrook | case 0x1b0: return s->uivr[1]; |
296 | 0633879f | pbrook | } |
297 | 2ac71179 | Paul Brook | hw_error("Bad MBAR read offset 0x%x", (int)offset); |
298 | 0633879f | pbrook | return 0; |
299 | 0633879f | pbrook | } |
300 | 0633879f | pbrook | |
301 | 0633879f | pbrook | static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset, |
302 | 0633879f | pbrook | uint32_t value) |
303 | 0633879f | pbrook | { |
304 | 0633879f | pbrook | if (offset >= 0x100 && offset < 0x120) { |
305 | 0633879f | pbrook | m5206_timer_write(s->timer[0], offset - 0x100, value); |
306 | 0633879f | pbrook | return;
|
307 | 0633879f | pbrook | } else if (offset >= 0x120 && offset < 0x140) { |
308 | 0633879f | pbrook | m5206_timer_write(s->timer[1], offset - 0x120, value); |
309 | 0633879f | pbrook | return;
|
310 | 0633879f | pbrook | } else if (offset >= 0x140 && offset < 0x160) { |
311 | 20dcee94 | pbrook | mcf_uart_write(s->uart[0], offset - 0x140, value); |
312 | 0633879f | pbrook | return;
|
313 | 0633879f | pbrook | } else if (offset >= 0x180 && offset < 0x1a0) { |
314 | 20dcee94 | pbrook | mcf_uart_write(s->uart[1], offset - 0x180, value); |
315 | 0633879f | pbrook | return;
|
316 | 0633879f | pbrook | } |
317 | 0633879f | pbrook | switch (offset) {
|
318 | 0633879f | pbrook | case 0x03: |
319 | 0633879f | pbrook | s->scr = value; |
320 | 0633879f | pbrook | break;
|
321 | 0633879f | pbrook | case 0x14 ... 0x20: |
322 | 0633879f | pbrook | s->icr[offset - 0x13] = value;
|
323 | 0633879f | pbrook | m5206_mbar_update(s); |
324 | 0633879f | pbrook | break;
|
325 | 0633879f | pbrook | case 0x36: |
326 | 0633879f | pbrook | s->imr = value; |
327 | 0633879f | pbrook | m5206_mbar_update(s); |
328 | 0633879f | pbrook | break;
|
329 | 0633879f | pbrook | case 0x40: |
330 | 0633879f | pbrook | s->rsr &= ~value; |
331 | 0633879f | pbrook | break;
|
332 | 0633879f | pbrook | case 0x41: |
333 | 0633879f | pbrook | /* TODO: implement watchdog. */
|
334 | 0633879f | pbrook | break;
|
335 | 0633879f | pbrook | case 0x42: |
336 | 0633879f | pbrook | s->swivr = value; |
337 | 0633879f | pbrook | break;
|
338 | 0633879f | pbrook | case 0xcb: |
339 | 0633879f | pbrook | s->par = value; |
340 | 0633879f | pbrook | break;
|
341 | 0633879f | pbrook | case 0x170: |
342 | 0633879f | pbrook | s->uivr[0] = value;
|
343 | 0633879f | pbrook | break;
|
344 | 0633879f | pbrook | case 0x178: case 0x17c: case 0x1c8: case 0x1bc: |
345 | 0633879f | pbrook | /* Not implemented: UART Output port bits. */
|
346 | 0633879f | pbrook | break;
|
347 | 0633879f | pbrook | case 0x1b0: |
348 | 0633879f | pbrook | s->uivr[1] = value;
|
349 | 0633879f | pbrook | break;
|
350 | 0633879f | pbrook | default:
|
351 | 2ac71179 | Paul Brook | hw_error("Bad MBAR write offset 0x%x", (int)offset); |
352 | 0633879f | pbrook | break;
|
353 | 0633879f | pbrook | } |
354 | 0633879f | pbrook | } |
355 | 0633879f | pbrook | |
356 | 0633879f | pbrook | /* Internal peripherals use a variety of register widths.
|
357 | 0633879f | pbrook | This lookup table allows a single routine to handle all of them. */
|
358 | 5fafdf24 | ths | static const int m5206_mbar_width[] = |
359 | 0633879f | pbrook | { |
360 | 0633879f | pbrook | /* 000-040 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, |
361 | 0633879f | pbrook | /* 040-080 */ 1, 2, 2, 2, 4, 1, 2, 4, 1, 2, 4, 2, 2, 4, 2, 2, |
362 | 0633879f | pbrook | /* 080-0c0 */ 4, 2, 2, 4, 2, 2, 4, 2, 2, 4, 2, 2, 4, 2, 2, 4, |
363 | 0633879f | pbrook | /* 0c0-100 */ 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
364 | 0633879f | pbrook | /* 100-140 */ 2, 2, 2, 2, 1, 0, 0, 0, 2, 2, 2, 2, 1, 0, 0, 0, |
365 | 0633879f | pbrook | /* 140-180 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
366 | 0633879f | pbrook | /* 180-1c0 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
367 | 0633879f | pbrook | /* 1c0-200 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
368 | 0633879f | pbrook | }; |
369 | 0633879f | pbrook | |
370 | 0633879f | pbrook | static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset); |
371 | 0633879f | pbrook | static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset); |
372 | 0633879f | pbrook | |
373 | 0633879f | pbrook | static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset) |
374 | 0633879f | pbrook | { |
375 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
376 | 0633879f | pbrook | offset &= 0x3ff;
|
377 | 0633879f | pbrook | if (offset > 0x200) { |
378 | 2ac71179 | Paul Brook | hw_error("Bad MBAR read offset 0x%x", (int)offset); |
379 | 0633879f | pbrook | } |
380 | 0633879f | pbrook | if (m5206_mbar_width[offset >> 2] > 1) { |
381 | 0633879f | pbrook | uint16_t val; |
382 | 0633879f | pbrook | val = m5206_mbar_readw(opaque, offset & ~1);
|
383 | 0633879f | pbrook | if ((offset & 1) == 0) { |
384 | 0633879f | pbrook | val >>= 8;
|
385 | 0633879f | pbrook | } |
386 | 0633879f | pbrook | return val & 0xff; |
387 | 0633879f | pbrook | } |
388 | 0633879f | pbrook | return m5206_mbar_read(s, offset);
|
389 | 0633879f | pbrook | } |
390 | 0633879f | pbrook | |
391 | 0633879f | pbrook | static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset) |
392 | 0633879f | pbrook | { |
393 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
394 | 0633879f | pbrook | int width;
|
395 | 0633879f | pbrook | offset &= 0x3ff;
|
396 | 0633879f | pbrook | if (offset > 0x200) { |
397 | 2ac71179 | Paul Brook | hw_error("Bad MBAR read offset 0x%x", (int)offset); |
398 | 0633879f | pbrook | } |
399 | 0633879f | pbrook | width = m5206_mbar_width[offset >> 2];
|
400 | 0633879f | pbrook | if (width > 2) { |
401 | 0633879f | pbrook | uint32_t val; |
402 | 0633879f | pbrook | val = m5206_mbar_readl(opaque, offset & ~3);
|
403 | 0633879f | pbrook | if ((offset & 3) == 0) |
404 | 0633879f | pbrook | val >>= 16;
|
405 | 0633879f | pbrook | return val & 0xffff; |
406 | 0633879f | pbrook | } else if (width < 2) { |
407 | 0633879f | pbrook | uint16_t val; |
408 | 0633879f | pbrook | val = m5206_mbar_readb(opaque, offset) << 8;
|
409 | 0633879f | pbrook | val |= m5206_mbar_readb(opaque, offset + 1);
|
410 | 0633879f | pbrook | return val;
|
411 | 0633879f | pbrook | } |
412 | 0633879f | pbrook | return m5206_mbar_read(s, offset);
|
413 | 0633879f | pbrook | } |
414 | 0633879f | pbrook | |
415 | 0633879f | pbrook | static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset) |
416 | 0633879f | pbrook | { |
417 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
418 | 0633879f | pbrook | int width;
|
419 | 0633879f | pbrook | offset &= 0x3ff;
|
420 | 0633879f | pbrook | if (offset > 0x200) { |
421 | 2ac71179 | Paul Brook | hw_error("Bad MBAR read offset 0x%x", (int)offset); |
422 | 0633879f | pbrook | } |
423 | 0633879f | pbrook | width = m5206_mbar_width[offset >> 2];
|
424 | 0633879f | pbrook | if (width < 4) { |
425 | 0633879f | pbrook | uint32_t val; |
426 | 0633879f | pbrook | val = m5206_mbar_readw(opaque, offset) << 16;
|
427 | 0633879f | pbrook | val |= m5206_mbar_readw(opaque, offset + 2);
|
428 | 0633879f | pbrook | return val;
|
429 | 0633879f | pbrook | } |
430 | 0633879f | pbrook | return m5206_mbar_read(s, offset);
|
431 | 0633879f | pbrook | } |
432 | 0633879f | pbrook | |
433 | 0633879f | pbrook | static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset, |
434 | 0633879f | pbrook | uint32_t value); |
435 | 0633879f | pbrook | static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset, |
436 | 0633879f | pbrook | uint32_t value); |
437 | 0633879f | pbrook | |
438 | 0633879f | pbrook | static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset, |
439 | 0633879f | pbrook | uint32_t value) |
440 | 0633879f | pbrook | { |
441 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
442 | 0633879f | pbrook | int width;
|
443 | 0633879f | pbrook | offset &= 0x3ff;
|
444 | 0633879f | pbrook | if (offset > 0x200) { |
445 | 2ac71179 | Paul Brook | hw_error("Bad MBAR write offset 0x%x", (int)offset); |
446 | 0633879f | pbrook | } |
447 | 0633879f | pbrook | width = m5206_mbar_width[offset >> 2];
|
448 | 0633879f | pbrook | if (width > 1) { |
449 | 0633879f | pbrook | uint32_t tmp; |
450 | 0633879f | pbrook | tmp = m5206_mbar_readw(opaque, offset & ~1);
|
451 | 0633879f | pbrook | if (offset & 1) { |
452 | 0633879f | pbrook | tmp = (tmp & 0xff00) | value;
|
453 | 0633879f | pbrook | } else {
|
454 | 0633879f | pbrook | tmp = (tmp & 0x00ff) | (value << 8); |
455 | 0633879f | pbrook | } |
456 | 0633879f | pbrook | m5206_mbar_writew(opaque, offset & ~1, tmp);
|
457 | 0633879f | pbrook | return;
|
458 | 0633879f | pbrook | } |
459 | 0633879f | pbrook | m5206_mbar_write(s, offset, value); |
460 | 0633879f | pbrook | } |
461 | 0633879f | pbrook | |
462 | 0633879f | pbrook | static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset, |
463 | 0633879f | pbrook | uint32_t value) |
464 | 0633879f | pbrook | { |
465 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
466 | 0633879f | pbrook | int width;
|
467 | 0633879f | pbrook | offset &= 0x3ff;
|
468 | 0633879f | pbrook | if (offset > 0x200) { |
469 | 2ac71179 | Paul Brook | hw_error("Bad MBAR write offset 0x%x", (int)offset); |
470 | 0633879f | pbrook | } |
471 | 0633879f | pbrook | width = m5206_mbar_width[offset >> 2];
|
472 | 0633879f | pbrook | if (width > 2) { |
473 | 0633879f | pbrook | uint32_t tmp; |
474 | 0633879f | pbrook | tmp = m5206_mbar_readl(opaque, offset & ~3);
|
475 | 0633879f | pbrook | if (offset & 3) { |
476 | 0633879f | pbrook | tmp = (tmp & 0xffff0000) | value;
|
477 | 0633879f | pbrook | } else {
|
478 | 0633879f | pbrook | tmp = (tmp & 0x0000ffff) | (value << 16); |
479 | 0633879f | pbrook | } |
480 | 0633879f | pbrook | m5206_mbar_writel(opaque, offset & ~3, tmp);
|
481 | 0633879f | pbrook | return;
|
482 | 0633879f | pbrook | } else if (width < 2) { |
483 | 0633879f | pbrook | m5206_mbar_writeb(opaque, offset, value >> 8);
|
484 | 0633879f | pbrook | m5206_mbar_writeb(opaque, offset + 1, value & 0xff); |
485 | 0633879f | pbrook | return;
|
486 | 0633879f | pbrook | } |
487 | 0633879f | pbrook | m5206_mbar_write(s, offset, value); |
488 | 0633879f | pbrook | } |
489 | 0633879f | pbrook | |
490 | 0633879f | pbrook | static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset, |
491 | 0633879f | pbrook | uint32_t value) |
492 | 0633879f | pbrook | { |
493 | 0633879f | pbrook | m5206_mbar_state *s = (m5206_mbar_state *)opaque; |
494 | 0633879f | pbrook | int width;
|
495 | 0633879f | pbrook | offset &= 0x3ff;
|
496 | 0633879f | pbrook | if (offset > 0x200) { |
497 | 2ac71179 | Paul Brook | hw_error("Bad MBAR write offset 0x%x", (int)offset); |
498 | 0633879f | pbrook | } |
499 | 0633879f | pbrook | width = m5206_mbar_width[offset >> 2];
|
500 | 0633879f | pbrook | if (width < 4) { |
501 | 0633879f | pbrook | m5206_mbar_writew(opaque, offset, value >> 16);
|
502 | 0633879f | pbrook | m5206_mbar_writew(opaque, offset + 2, value & 0xffff); |
503 | 0633879f | pbrook | return;
|
504 | 0633879f | pbrook | } |
505 | 0633879f | pbrook | m5206_mbar_write(s, offset, value); |
506 | 0633879f | pbrook | } |
507 | 0633879f | pbrook | |
508 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const m5206_mbar_readfn[] = { |
509 | 0633879f | pbrook | m5206_mbar_readb, |
510 | 0633879f | pbrook | m5206_mbar_readw, |
511 | 0633879f | pbrook | m5206_mbar_readl |
512 | 0633879f | pbrook | }; |
513 | 0633879f | pbrook | |
514 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const m5206_mbar_writefn[] = { |
515 | 0633879f | pbrook | m5206_mbar_writeb, |
516 | 0633879f | pbrook | m5206_mbar_writew, |
517 | 0633879f | pbrook | m5206_mbar_writel |
518 | 0633879f | pbrook | }; |
519 | 0633879f | pbrook | |
520 | 0633879f | pbrook | qemu_irq *mcf5206_init(uint32_t base, CPUState *env) |
521 | 0633879f | pbrook | { |
522 | 0633879f | pbrook | m5206_mbar_state *s; |
523 | 0633879f | pbrook | qemu_irq *pic; |
524 | 0633879f | pbrook | int iomemtype;
|
525 | 0633879f | pbrook | |
526 | 0633879f | pbrook | s = (m5206_mbar_state *)qemu_mallocz(sizeof(m5206_mbar_state));
|
527 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(m5206_mbar_readfn, |
528 | 0633879f | pbrook | m5206_mbar_writefn, s); |
529 | 20dcee94 | pbrook | cpu_register_physical_memory(base, 0x00001000, iomemtype);
|
530 | 0633879f | pbrook | |
531 | 0633879f | pbrook | pic = qemu_allocate_irqs(m5206_mbar_set_irq, s, 14);
|
532 | 0633879f | pbrook | s->timer[0] = m5206_timer_init(pic[9]); |
533 | 0633879f | pbrook | s->timer[1] = m5206_timer_init(pic[10]); |
534 | 20dcee94 | pbrook | s->uart[0] = mcf_uart_init(pic[12], serial_hds[0]); |
535 | 20dcee94 | pbrook | s->uart[1] = mcf_uart_init(pic[13], serial_hds[1]); |
536 | 0633879f | pbrook | s->env = env; |
537 | 0633879f | pbrook | |
538 | 0633879f | pbrook | m5206_mbar_reset(s); |
539 | 0633879f | pbrook | return pic;
|
540 | 0633879f | pbrook | } |