2 * Motorola ColdFire MCF5208 SoC emulation.
4 * Copyright (c) 2007 CodeSourcery.
6 * This code is licenced under the GPL
10 #include "qemu-timer.h"
15 #define SYS_FREQ 66000000
17 #define PCSR_EN 0x0001
18 #define PCSR_RLD 0x0002
19 #define PCSR_PIF 0x0004
20 #define PCSR_PIE 0x0008
21 #define PCSR_OVW 0x0010
22 #define PCSR_DBG 0x0020
23 #define PCSR_DOZE 0x0040
24 #define PCSR_PRE_SHIFT 8
25 #define PCSR_PRE_MASK 0x0f00
35 static void m5208_timer_update(m5208_timer_state
*s
)
37 if ((s
->pcsr
& (PCSR_PIE
| PCSR_PIF
)) == (PCSR_PIE
| PCSR_PIF
))
38 qemu_irq_raise(s
->irq
);
40 qemu_irq_lower(s
->irq
);
43 static void m5208_timer_write(void *opaque
, target_phys_addr_t offset
,
46 m5208_timer_state
*s
= (m5208_timer_state
*)opaque
;
51 /* The PIF bit is set-to-clear. */
52 if (value
& PCSR_PIF
) {
56 /* Avoid frobbing the timer if we're just twiddling IRQ bits. */
57 if (((s
->pcsr
^ value
) & ~PCSR_PIE
) == 0) {
59 m5208_timer_update(s
);
63 if (s
->pcsr
& PCSR_EN
)
64 ptimer_stop(s
->timer
);
68 prescale
= 1 << ((s
->pcsr
& PCSR_PRE_MASK
) >> PCSR_PRE_SHIFT
);
69 ptimer_set_freq(s
->timer
, (SYS_FREQ
/ 2) / prescale
);
70 if (s
->pcsr
& PCSR_RLD
)
74 ptimer_set_limit(s
->timer
, limit
, 0);
76 if (s
->pcsr
& PCSR_EN
)
77 ptimer_run(s
->timer
, 0);
82 if ((s
->pcsr
& PCSR_RLD
) == 0) {
83 if (s
->pcsr
& PCSR_OVW
)
84 ptimer_set_count(s
->timer
, value
);
86 ptimer_set_limit(s
->timer
, value
, s
->pcsr
& PCSR_OVW
);
92 cpu_abort(cpu_single_env
, "m5208_timer_write: Bad offset 0x%x\n",
96 m5208_timer_update(s
);
99 static void m5208_timer_trigger(void *opaque
)
101 m5208_timer_state
*s
= (m5208_timer_state
*)opaque
;
103 m5208_timer_update(s
);
106 static uint32_t m5208_timer_read(void *opaque
, target_phys_addr_t addr
)
108 m5208_timer_state
*s
= (m5208_timer_state
*)opaque
;
115 return ptimer_get_count(s
->timer
);
117 cpu_abort(cpu_single_env
, "m5208_timer_read: Bad offset 0x%x\n",
123 static CPUReadMemoryFunc
*m5208_timer_readfn
[] = {
129 static CPUWriteMemoryFunc
*m5208_timer_writefn
[] = {
135 static uint32_t m5208_sys_read(void *opaque
, target_phys_addr_t addr
)
138 case 0x110: /* SDCS0 */
141 for (n
= 0; n
< 32; n
++) {
142 if (ram_size
< (2u << n
))
145 return (n
- 1) | 0x40000000;
147 case 0x114: /* SDCS1 */
151 cpu_abort(cpu_single_env
, "m5208_sys_read: Bad offset 0x%x\n",
157 static void m5208_sys_write(void *opaque
, target_phys_addr_t addr
,
160 cpu_abort(cpu_single_env
, "m5208_sys_write: Bad offset 0x%x\n",
164 static CPUReadMemoryFunc
*m5208_sys_readfn
[] = {
170 static CPUWriteMemoryFunc
*m5208_sys_writefn
[] = {
176 static void mcf5208_sys_init(qemu_irq
*pic
)
179 m5208_timer_state
*s
;
183 iomemtype
= cpu_register_io_memory(0, m5208_sys_readfn
,
184 m5208_sys_writefn
, NULL
);
186 cpu_register_physical_memory(0xfc0a8000, 0x00004000, iomemtype
);
188 for (i
= 0; i
< 2; i
++) {
189 s
= (m5208_timer_state
*)qemu_mallocz(sizeof(m5208_timer_state
));
190 bh
= qemu_bh_new(m5208_timer_trigger
, s
);
191 s
->timer
= ptimer_init(bh
);
192 iomemtype
= cpu_register_io_memory(0, m5208_timer_readfn
,
193 m5208_timer_writefn
, s
);
194 cpu_register_physical_memory(0xfc080000 + 0x4000 * i
, 0x00004000,
200 static void mcf5208evb_init(ram_addr_t ram_size
, int vga_ram_size
,
201 const char *boot_device
, DisplayState
*ds
,
202 const char *kernel_filename
, const char *kernel_cmdline
,
203 const char *initrd_filename
, const char *cpu_model
)
213 env
= cpu_init(cpu_model
);
215 fprintf(stderr
, "Unable to find m68k CPU definition\n");
219 /* Initialize CPU registers. */
221 /* TODO: Configure BARs. */
223 /* DRAM at 0x20000000 */
224 cpu_register_physical_memory(0x40000000, ram_size
,
225 qemu_ram_alloc(ram_size
) | IO_MEM_RAM
);
228 cpu_register_physical_memory(0x80000000, 16384,
229 qemu_ram_alloc(16384) | IO_MEM_RAM
);
231 /* Internal peripherals. */
232 pic
= mcf_intc_init(0xfc048000, env
);
234 mcf_uart_mm_init(0xfc060000, pic
[26], serial_hds
[0]);
235 mcf_uart_mm_init(0xfc064000, pic
[27], serial_hds
[1]);
236 mcf_uart_mm_init(0xfc068000, pic
[28], serial_hds
[2]);
238 mcf5208_sys_init(pic
);
241 fprintf(stderr
, "Too many NICs\n");
244 if (nd_table
[0].vlan
) {
245 if (nd_table
[0].model
== NULL
246 || strcmp(nd_table
[0].model
, "mcf_fec") == 0) {
247 mcf_fec_init(&nd_table
[0], 0xfc030000, pic
+ 36);
248 } else if (strcmp(nd_table
[0].model
, "?") == 0) {
249 fprintf(stderr
, "qemu: Supported NICs: mcf_fec\n");
252 fprintf(stderr
, "qemu: Unsupported NIC: %s\n", nd_table
[0].model
);
257 /* 0xfc000000 SCM. */
258 /* 0xfc004000 XBS. */
259 /* 0xfc008000 FlexBus CS. */
260 /* 0xfc030000 FEC. */
261 /* 0xfc040000 SCM + Power management. */
262 /* 0xfc044000 eDMA. */
263 /* 0xfc048000 INTC. */
264 /* 0xfc058000 I2C. */
265 /* 0xfc05c000 QSPI. */
266 /* 0xfc060000 UART0. */
267 /* 0xfc064000 UART0. */
268 /* 0xfc068000 UART0. */
269 /* 0xfc070000 DMA timers. */
270 /* 0xfc080000 PIT0. */
271 /* 0xfc084000 PIT1. */
272 /* 0xfc088000 EPORT. */
273 /* 0xfc08c000 Watchdog. */
274 /* 0xfc090000 clock module. */
275 /* 0xfc0a0000 CCM + reset. */
276 /* 0xfc0a4000 GPIO. */
277 /* 0xfc0a8000 SDRAM controller. */
280 if (!kernel_filename
) {
281 fprintf(stderr
, "Kernel image must be specified\n");
285 kernel_size
= load_elf(kernel_filename
, 0, &elf_entry
, NULL
, NULL
);
287 if (kernel_size
< 0) {
288 kernel_size
= load_uimage(kernel_filename
, &entry
, NULL
, NULL
);
290 if (kernel_size
< 0) {
291 kernel_size
= load_image(kernel_filename
, phys_ram_base
);
294 if (kernel_size
< 0) {
295 fprintf(stderr
, "qemu: could not load kernel '%s'\n", kernel_filename
);
302 QEMUMachine mcf5208evb_machine
= {
303 .name
= "mcf5208evb",
304 .desc
= "MCF5206EVB",
305 .init
= mcf5208evb_init
,
306 .ram_require
= 16384,