root / hw / mcf5208.c @ 5041fccd
History | View | Annotate | Download (7.8 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 20dcee94 | pbrook | * Motorola ColdFire MCF5208 SoC emulation.
|
3 | 20dcee94 | pbrook | *
|
4 | 20dcee94 | pbrook | * Copyright (c) 2007 CodeSourcery.
|
5 | 20dcee94 | pbrook | *
|
6 | 20dcee94 | pbrook | * This code is licenced under the GPL
|
7 | 20dcee94 | 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 | 87ecb68b | pbrook | #include "net.h" |
13 | 87ecb68b | pbrook | #include "boards.h" |
14 | ca20cf32 | Blue Swirl | #include "loader.h" |
15 | ca20cf32 | Blue Swirl | #include "elf.h" |
16 | 20dcee94 | pbrook | |
17 | 20dcee94 | pbrook | #define SYS_FREQ 66000000 |
18 | 20dcee94 | pbrook | |
19 | 20dcee94 | pbrook | #define PCSR_EN 0x0001 |
20 | 20dcee94 | pbrook | #define PCSR_RLD 0x0002 |
21 | 20dcee94 | pbrook | #define PCSR_PIF 0x0004 |
22 | 20dcee94 | pbrook | #define PCSR_PIE 0x0008 |
23 | 20dcee94 | pbrook | #define PCSR_OVW 0x0010 |
24 | 20dcee94 | pbrook | #define PCSR_DBG 0x0020 |
25 | 20dcee94 | pbrook | #define PCSR_DOZE 0x0040 |
26 | 20dcee94 | pbrook | #define PCSR_PRE_SHIFT 8 |
27 | 20dcee94 | pbrook | #define PCSR_PRE_MASK 0x0f00 |
28 | 20dcee94 | pbrook | |
29 | 20dcee94 | pbrook | typedef struct { |
30 | 20dcee94 | pbrook | qemu_irq irq; |
31 | 20dcee94 | pbrook | ptimer_state *timer; |
32 | 20dcee94 | pbrook | uint16_t pcsr; |
33 | 20dcee94 | pbrook | uint16_t pmr; |
34 | 20dcee94 | pbrook | uint16_t pcntr; |
35 | 20dcee94 | pbrook | } m5208_timer_state; |
36 | 20dcee94 | pbrook | |
37 | 20dcee94 | pbrook | static void m5208_timer_update(m5208_timer_state *s) |
38 | 20dcee94 | pbrook | { |
39 | 20dcee94 | pbrook | if ((s->pcsr & (PCSR_PIE | PCSR_PIF)) == (PCSR_PIE | PCSR_PIF))
|
40 | 20dcee94 | pbrook | qemu_irq_raise(s->irq); |
41 | 20dcee94 | pbrook | else
|
42 | 20dcee94 | pbrook | qemu_irq_lower(s->irq); |
43 | 20dcee94 | pbrook | } |
44 | 20dcee94 | pbrook | |
45 | c227f099 | Anthony Liguori | static void m5208_timer_write(void *opaque, target_phys_addr_t offset, |
46 | 20dcee94 | pbrook | uint32_t value) |
47 | 20dcee94 | pbrook | { |
48 | 8da3ff18 | pbrook | m5208_timer_state *s = (m5208_timer_state *)opaque; |
49 | 20dcee94 | pbrook | int prescale;
|
50 | 20dcee94 | pbrook | int limit;
|
51 | 20dcee94 | pbrook | switch (offset) {
|
52 | 20dcee94 | pbrook | case 0: |
53 | 20dcee94 | pbrook | /* The PIF bit is set-to-clear. */
|
54 | 20dcee94 | pbrook | if (value & PCSR_PIF) {
|
55 | 20dcee94 | pbrook | s->pcsr &= ~PCSR_PIF; |
56 | 20dcee94 | pbrook | value &= ~PCSR_PIF; |
57 | 20dcee94 | pbrook | } |
58 | 20dcee94 | pbrook | /* Avoid frobbing the timer if we're just twiddling IRQ bits. */
|
59 | 20dcee94 | pbrook | if (((s->pcsr ^ value) & ~PCSR_PIE) == 0) { |
60 | 20dcee94 | pbrook | s->pcsr = value; |
61 | 20dcee94 | pbrook | m5208_timer_update(s); |
62 | 20dcee94 | pbrook | return;
|
63 | 20dcee94 | pbrook | } |
64 | 20dcee94 | pbrook | |
65 | 20dcee94 | pbrook | if (s->pcsr & PCSR_EN)
|
66 | 20dcee94 | pbrook | ptimer_stop(s->timer); |
67 | 20dcee94 | pbrook | |
68 | 20dcee94 | pbrook | s->pcsr = value; |
69 | 20dcee94 | pbrook | |
70 | 20dcee94 | pbrook | prescale = 1 << ((s->pcsr & PCSR_PRE_MASK) >> PCSR_PRE_SHIFT);
|
71 | 20dcee94 | pbrook | ptimer_set_freq(s->timer, (SYS_FREQ / 2) / prescale);
|
72 | 20dcee94 | pbrook | if (s->pcsr & PCSR_RLD)
|
73 | 20dcee94 | pbrook | limit = s->pmr; |
74 | 6d9db39c | pbrook | else
|
75 | 6d9db39c | pbrook | limit = 0xffff;
|
76 | 20dcee94 | pbrook | ptimer_set_limit(s->timer, limit, 0);
|
77 | 20dcee94 | pbrook | |
78 | 20dcee94 | pbrook | if (s->pcsr & PCSR_EN)
|
79 | 20dcee94 | pbrook | ptimer_run(s->timer, 0);
|
80 | 20dcee94 | pbrook | break;
|
81 | 20dcee94 | pbrook | case 2: |
82 | 20dcee94 | pbrook | s->pmr = value; |
83 | 20dcee94 | pbrook | s->pcsr &= ~PCSR_PIF; |
84 | 6d9db39c | pbrook | if ((s->pcsr & PCSR_RLD) == 0) { |
85 | 6d9db39c | pbrook | if (s->pcsr & PCSR_OVW)
|
86 | 6d9db39c | pbrook | ptimer_set_count(s->timer, value); |
87 | 6d9db39c | pbrook | } else {
|
88 | 6d9db39c | pbrook | ptimer_set_limit(s->timer, value, s->pcsr & PCSR_OVW); |
89 | 6d9db39c | pbrook | } |
90 | 20dcee94 | pbrook | break;
|
91 | 20dcee94 | pbrook | case 4: |
92 | 20dcee94 | pbrook | break;
|
93 | 20dcee94 | pbrook | default:
|
94 | 2ac71179 | Paul Brook | hw_error("m5208_timer_write: Bad offset 0x%x\n", (int)offset); |
95 | 8da3ff18 | pbrook | break;
|
96 | 20dcee94 | pbrook | } |
97 | 20dcee94 | pbrook | m5208_timer_update(s); |
98 | 20dcee94 | pbrook | } |
99 | 20dcee94 | pbrook | |
100 | 20dcee94 | pbrook | static void m5208_timer_trigger(void *opaque) |
101 | 20dcee94 | pbrook | { |
102 | 20dcee94 | pbrook | m5208_timer_state *s = (m5208_timer_state *)opaque; |
103 | 20dcee94 | pbrook | s->pcsr |= PCSR_PIF; |
104 | 20dcee94 | pbrook | m5208_timer_update(s); |
105 | 20dcee94 | pbrook | } |
106 | 20dcee94 | pbrook | |
107 | c227f099 | Anthony Liguori | static uint32_t m5208_timer_read(void *opaque, target_phys_addr_t addr) |
108 | 8da3ff18 | pbrook | { |
109 | 8da3ff18 | pbrook | m5208_timer_state *s = (m5208_timer_state *)opaque; |
110 | 8da3ff18 | pbrook | switch (addr) {
|
111 | 8da3ff18 | pbrook | case 0: |
112 | 8da3ff18 | pbrook | return s->pcsr;
|
113 | 8da3ff18 | pbrook | case 2: |
114 | 8da3ff18 | pbrook | return s->pmr;
|
115 | 8da3ff18 | pbrook | case 4: |
116 | 8da3ff18 | pbrook | return ptimer_get_count(s->timer);
|
117 | 8da3ff18 | pbrook | default:
|
118 | 2ac71179 | Paul Brook | hw_error("m5208_timer_read: Bad offset 0x%x\n", (int)addr); |
119 | 8da3ff18 | pbrook | return 0; |
120 | 8da3ff18 | pbrook | } |
121 | 8da3ff18 | pbrook | } |
122 | 8da3ff18 | pbrook | |
123 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const m5208_timer_readfn[] = { |
124 | 8da3ff18 | pbrook | m5208_timer_read, |
125 | 8da3ff18 | pbrook | m5208_timer_read, |
126 | 8da3ff18 | pbrook | m5208_timer_read |
127 | 8da3ff18 | pbrook | }; |
128 | 8da3ff18 | pbrook | |
129 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const m5208_timer_writefn[] = { |
130 | 8da3ff18 | pbrook | m5208_timer_write, |
131 | 8da3ff18 | pbrook | m5208_timer_write, |
132 | 8da3ff18 | pbrook | m5208_timer_write |
133 | 8da3ff18 | pbrook | }; |
134 | 20dcee94 | pbrook | |
135 | c227f099 | Anthony Liguori | static uint32_t m5208_sys_read(void *opaque, target_phys_addr_t addr) |
136 | 20dcee94 | pbrook | { |
137 | 20dcee94 | pbrook | switch (addr) {
|
138 | 8da3ff18 | pbrook | case 0x110: /* SDCS0 */ |
139 | 20dcee94 | pbrook | { |
140 | 20dcee94 | pbrook | int n;
|
141 | 20dcee94 | pbrook | for (n = 0; n < 32; n++) { |
142 | 20dcee94 | pbrook | if (ram_size < (2u << n)) |
143 | 20dcee94 | pbrook | break;
|
144 | 20dcee94 | pbrook | } |
145 | 20dcee94 | pbrook | return (n - 1) | 0x40000000; |
146 | 20dcee94 | pbrook | } |
147 | 8da3ff18 | pbrook | case 0x114: /* SDCS1 */ |
148 | 20dcee94 | pbrook | return 0; |
149 | 20dcee94 | pbrook | |
150 | 20dcee94 | pbrook | default:
|
151 | 2ac71179 | Paul Brook | hw_error("m5208_sys_read: Bad offset 0x%x\n", (int)addr); |
152 | 20dcee94 | pbrook | return 0; |
153 | 20dcee94 | pbrook | } |
154 | 20dcee94 | pbrook | } |
155 | 20dcee94 | pbrook | |
156 | c227f099 | Anthony Liguori | static void m5208_sys_write(void *opaque, target_phys_addr_t addr, |
157 | 20dcee94 | pbrook | uint32_t value) |
158 | 20dcee94 | pbrook | { |
159 | 2ac71179 | Paul Brook | hw_error("m5208_sys_write: Bad offset 0x%x\n", (int)addr); |
160 | 20dcee94 | pbrook | } |
161 | 20dcee94 | pbrook | |
162 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const m5208_sys_readfn[] = { |
163 | 20dcee94 | pbrook | m5208_sys_read, |
164 | 20dcee94 | pbrook | m5208_sys_read, |
165 | 20dcee94 | pbrook | m5208_sys_read |
166 | 20dcee94 | pbrook | }; |
167 | 20dcee94 | pbrook | |
168 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const m5208_sys_writefn[] = { |
169 | 20dcee94 | pbrook | m5208_sys_write, |
170 | 20dcee94 | pbrook | m5208_sys_write, |
171 | 20dcee94 | pbrook | m5208_sys_write |
172 | 20dcee94 | pbrook | }; |
173 | 20dcee94 | pbrook | |
174 | 20dcee94 | pbrook | static void mcf5208_sys_init(qemu_irq *pic) |
175 | 20dcee94 | pbrook | { |
176 | 20dcee94 | pbrook | int iomemtype;
|
177 | 8da3ff18 | pbrook | m5208_timer_state *s; |
178 | 20dcee94 | pbrook | QEMUBH *bh; |
179 | 20dcee94 | pbrook | int i;
|
180 | 20dcee94 | pbrook | |
181 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(m5208_sys_readfn, |
182 | 8da3ff18 | pbrook | m5208_sys_writefn, NULL);
|
183 | 20dcee94 | pbrook | /* SDRAMC. */
|
184 | 20dcee94 | pbrook | cpu_register_physical_memory(0xfc0a8000, 0x00004000, iomemtype); |
185 | 20dcee94 | pbrook | /* Timers. */
|
186 | 20dcee94 | pbrook | for (i = 0; i < 2; i++) { |
187 | 8da3ff18 | pbrook | s = (m5208_timer_state *)qemu_mallocz(sizeof(m5208_timer_state));
|
188 | 8da3ff18 | pbrook | bh = qemu_bh_new(m5208_timer_trigger, s); |
189 | 8da3ff18 | pbrook | s->timer = ptimer_init(bh); |
190 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(m5208_timer_readfn, |
191 | 8da3ff18 | pbrook | m5208_timer_writefn, s); |
192 | 20dcee94 | pbrook | cpu_register_physical_memory(0xfc080000 + 0x4000 * i, 0x00004000, |
193 | 20dcee94 | pbrook | iomemtype); |
194 | 8da3ff18 | pbrook | s->irq = pic[4 + i];
|
195 | 20dcee94 | pbrook | } |
196 | 20dcee94 | pbrook | } |
197 | 20dcee94 | pbrook | |
198 | c227f099 | Anthony Liguori | static void mcf5208evb_init(ram_addr_t ram_size, |
199 | 3023f332 | aliguori | const char *boot_device, |
200 | 20dcee94 | pbrook | const char *kernel_filename, const char *kernel_cmdline, |
201 | 20dcee94 | pbrook | const char *initrd_filename, const char *cpu_model) |
202 | 20dcee94 | pbrook | { |
203 | 20dcee94 | pbrook | CPUState *env; |
204 | 20dcee94 | pbrook | int kernel_size;
|
205 | 20dcee94 | pbrook | uint64_t elf_entry; |
206 | c227f099 | Anthony Liguori | target_phys_addr_t entry; |
207 | 20dcee94 | pbrook | qemu_irq *pic; |
208 | 20dcee94 | pbrook | |
209 | 20dcee94 | pbrook | if (!cpu_model)
|
210 | 20dcee94 | pbrook | cpu_model = "m5208";
|
211 | aaed909a | bellard | env = cpu_init(cpu_model); |
212 | aaed909a | bellard | if (!env) {
|
213 | aaed909a | bellard | fprintf(stderr, "Unable to find m68k CPU definition\n");
|
214 | aaed909a | bellard | exit(1);
|
215 | 20dcee94 | pbrook | } |
216 | 20dcee94 | pbrook | |
217 | 20dcee94 | pbrook | /* Initialize CPU registers. */
|
218 | 20dcee94 | pbrook | env->vbr = 0;
|
219 | 20dcee94 | pbrook | /* TODO: Configure BARs. */
|
220 | 20dcee94 | pbrook | |
221 | dcac9679 | pbrook | /* DRAM at 0x40000000 */
|
222 | 20dcee94 | pbrook | cpu_register_physical_memory(0x40000000, ram_size,
|
223 | 20dcee94 | pbrook | qemu_ram_alloc(ram_size) | IO_MEM_RAM); |
224 | 20dcee94 | pbrook | |
225 | 20dcee94 | pbrook | /* Internal SRAM. */
|
226 | 20dcee94 | pbrook | cpu_register_physical_memory(0x80000000, 16384, |
227 | 20dcee94 | pbrook | qemu_ram_alloc(16384) | IO_MEM_RAM);
|
228 | 20dcee94 | pbrook | |
229 | 20dcee94 | pbrook | /* Internal peripherals. */
|
230 | 20dcee94 | pbrook | pic = mcf_intc_init(0xfc048000, env);
|
231 | 20dcee94 | pbrook | |
232 | 20dcee94 | pbrook | mcf_uart_mm_init(0xfc060000, pic[26], serial_hds[0]); |
233 | 20dcee94 | pbrook | mcf_uart_mm_init(0xfc064000, pic[27], serial_hds[1]); |
234 | 20dcee94 | pbrook | mcf_uart_mm_init(0xfc068000, pic[28], serial_hds[2]); |
235 | 20dcee94 | pbrook | |
236 | 20dcee94 | pbrook | mcf5208_sys_init(pic); |
237 | 20dcee94 | pbrook | |
238 | 7e049b8a | pbrook | if (nb_nics > 1) { |
239 | 7e049b8a | pbrook | fprintf(stderr, "Too many NICs\n");
|
240 | 7e049b8a | pbrook | exit(1);
|
241 | 7e049b8a | pbrook | } |
242 | 0ae18cee | aliguori | if (nd_table[0].vlan) |
243 | 0ae18cee | aliguori | mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36); |
244 | 7e049b8a | pbrook | |
245 | 20dcee94 | pbrook | /* 0xfc000000 SCM. */
|
246 | 20dcee94 | pbrook | /* 0xfc004000 XBS. */
|
247 | 20dcee94 | pbrook | /* 0xfc008000 FlexBus CS. */
|
248 | 7e049b8a | pbrook | /* 0xfc030000 FEC. */
|
249 | 20dcee94 | pbrook | /* 0xfc040000 SCM + Power management. */
|
250 | 20dcee94 | pbrook | /* 0xfc044000 eDMA. */
|
251 | 20dcee94 | pbrook | /* 0xfc048000 INTC. */
|
252 | 20dcee94 | pbrook | /* 0xfc058000 I2C. */
|
253 | 20dcee94 | pbrook | /* 0xfc05c000 QSPI. */
|
254 | 20dcee94 | pbrook | /* 0xfc060000 UART0. */
|
255 | 20dcee94 | pbrook | /* 0xfc064000 UART0. */
|
256 | 20dcee94 | pbrook | /* 0xfc068000 UART0. */
|
257 | 20dcee94 | pbrook | /* 0xfc070000 DMA timers. */
|
258 | 20dcee94 | pbrook | /* 0xfc080000 PIT0. */
|
259 | 20dcee94 | pbrook | /* 0xfc084000 PIT1. */
|
260 | 20dcee94 | pbrook | /* 0xfc088000 EPORT. */
|
261 | 20dcee94 | pbrook | /* 0xfc08c000 Watchdog. */
|
262 | 20dcee94 | pbrook | /* 0xfc090000 clock module. */
|
263 | 20dcee94 | pbrook | /* 0xfc0a0000 CCM + reset. */
|
264 | 20dcee94 | pbrook | /* 0xfc0a4000 GPIO. */
|
265 | 20dcee94 | pbrook | /* 0xfc0a8000 SDRAM controller. */
|
266 | 20dcee94 | pbrook | |
267 | 20dcee94 | pbrook | /* Load kernel. */
|
268 | 20dcee94 | pbrook | if (!kernel_filename) {
|
269 | 20dcee94 | pbrook | fprintf(stderr, "Kernel image must be specified\n");
|
270 | 20dcee94 | pbrook | exit(1);
|
271 | 20dcee94 | pbrook | } |
272 | 20dcee94 | pbrook | |
273 | ca20cf32 | Blue Swirl | kernel_size = load_elf(kernel_filename, 0, &elf_entry, NULL, NULL, |
274 | ca20cf32 | Blue Swirl | 1, ELF_MACHINE, 0); |
275 | 20dcee94 | pbrook | entry = elf_entry; |
276 | 20dcee94 | pbrook | if (kernel_size < 0) { |
277 | 5a9154e0 | aliguori | kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL); |
278 | 20dcee94 | pbrook | } |
279 | 20dcee94 | pbrook | if (kernel_size < 0) { |
280 | dcac9679 | pbrook | kernel_size = load_image_targphys(kernel_filename, 0x40000000,
|
281 | dcac9679 | pbrook | ram_size); |
282 | dcac9679 | pbrook | entry = 0x40000000;
|
283 | 20dcee94 | pbrook | } |
284 | 20dcee94 | pbrook | if (kernel_size < 0) { |
285 | 20dcee94 | pbrook | fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
|
286 | 20dcee94 | pbrook | exit(1);
|
287 | 20dcee94 | pbrook | } |
288 | 20dcee94 | pbrook | |
289 | 20dcee94 | pbrook | env->pc = entry; |
290 | 20dcee94 | pbrook | } |
291 | 20dcee94 | pbrook | |
292 | f80f9ec9 | Anthony Liguori | static QEMUMachine mcf5208evb_machine = {
|
293 | 4b32e168 | aliguori | .name = "mcf5208evb",
|
294 | 4b32e168 | aliguori | .desc = "MCF5206EVB",
|
295 | 4b32e168 | aliguori | .init = mcf5208evb_init, |
296 | 0c257437 | Anthony Liguori | .is_default = 1,
|
297 | 20dcee94 | pbrook | }; |
298 | f80f9ec9 | Anthony Liguori | |
299 | f80f9ec9 | Anthony Liguori | static void mcf5208evb_machine_init(void) |
300 | f80f9ec9 | Anthony Liguori | { |
301 | f80f9ec9 | Anthony Liguori | qemu_register_machine(&mcf5208evb_machine); |
302 | f80f9ec9 | Anthony Liguori | } |
303 | f80f9ec9 | Anthony Liguori | |
304 | f80f9ec9 | Anthony Liguori | machine_init(mcf5208evb_machine_init); |