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(m5208_timer_state
*s
, int offset
,
50 /* The PIF bit is set-to-clear. */
51 if (value
& PCSR_PIF
) {
55 /* Avoid frobbing the timer if we're just twiddling IRQ bits. */
56 if (((s
->pcsr
^ value
) & ~PCSR_PIE
) == 0) {
58 m5208_timer_update(s
);
62 if (s
->pcsr
& PCSR_EN
)
63 ptimer_stop(s
->timer
);
67 prescale
= 1 << ((s
->pcsr
& PCSR_PRE_MASK
) >> PCSR_PRE_SHIFT
);
68 ptimer_set_freq(s
->timer
, (SYS_FREQ
/ 2) / prescale
);
69 if (s
->pcsr
& PCSR_RLD
)
73 ptimer_set_limit(s
->timer
, limit
, 0);
75 if (s
->pcsr
& PCSR_EN
)
76 ptimer_run(s
->timer
, 0);
81 if ((s
->pcsr
& PCSR_RLD
) == 0) {
82 if (s
->pcsr
& PCSR_OVW
)
83 ptimer_set_count(s
->timer
, value
);
85 ptimer_set_limit(s
->timer
, value
, s
->pcsr
& PCSR_OVW
);
91 /* Should never happen. */
94 m5208_timer_update(s
);
97 static void m5208_timer_trigger(void *opaque
)
99 m5208_timer_state
*s
= (m5208_timer_state
*)opaque
;
101 m5208_timer_update(s
);
105 m5208_timer_state timer
[2];
108 static uint32_t m5208_sys_read(void *opaque
, target_phys_addr_t addr
)
110 m5208_sys_state
*s
= (m5208_sys_state
*)opaque
;
114 return s
->timer
[0].pcsr
;
116 return s
->timer
[0].pmr
;
118 return ptimer_get_count(s
->timer
[0].timer
);
121 return s
->timer
[1].pcsr
;
123 return s
->timer
[1].pmr
;
125 return ptimer_get_count(s
->timer
[1].timer
);
127 /* SDRAM Controller. */
128 case 0xfc0a8110: /* SDCS0 */
131 for (n
= 0; n
< 32; n
++) {
132 if (ram_size
< (2u << n
))
135 return (n
- 1) | 0x40000000;
137 case 0xfc0a8114: /* SDCS1 */
141 cpu_abort(cpu_single_env
, "m5208_sys_read: Bad offset 0x%x\n",
147 static void m5208_sys_write(void *opaque
, target_phys_addr_t addr
,
150 m5208_sys_state
*s
= (m5208_sys_state
*)opaque
;
156 m5208_timer_write(&s
->timer
[0], addr
& 0xf, value
);
162 m5208_timer_write(&s
->timer
[1], addr
& 0xf, value
);
165 cpu_abort(cpu_single_env
, "m5208_sys_write: Bad offset 0x%x\n",
171 static CPUReadMemoryFunc
*m5208_sys_readfn
[] = {
177 static CPUWriteMemoryFunc
*m5208_sys_writefn
[] = {
183 static void mcf5208_sys_init(qemu_irq
*pic
)
190 s
= (m5208_sys_state
*)qemu_mallocz(sizeof(m5208_sys_state
));
191 iomemtype
= cpu_register_io_memory(0, m5208_sys_readfn
,
192 m5208_sys_writefn
, s
);
194 cpu_register_physical_memory(0xfc0a8000, 0x00004000, iomemtype
);
196 for (i
= 0; i
< 2; i
++) {
197 bh
= qemu_bh_new(m5208_timer_trigger
, &s
->timer
[i
]);
198 s
->timer
[i
].timer
= ptimer_init(bh
);
199 cpu_register_physical_memory(0xfc080000 + 0x4000 * i
, 0x00004000,
201 s
->timer
[i
].irq
= pic
[4 + i
];
205 static void mcf5208evb_init(int ram_size
, int vga_ram_size
,
206 const char *boot_device
, DisplayState
*ds
,
207 const char *kernel_filename
, const char *kernel_cmdline
,
208 const char *initrd_filename
, const char *cpu_model
)
218 env
= cpu_init(cpu_model
);
220 fprintf(stderr
, "Unable to find m68k CPU definition\n");
224 /* Initialize CPU registers. */
226 /* TODO: Configure BARs. */
228 /* DRAM at 0x20000000 */
229 cpu_register_physical_memory(0x40000000, ram_size
,
230 qemu_ram_alloc(ram_size
) | IO_MEM_RAM
);
233 cpu_register_physical_memory(0x80000000, 16384,
234 qemu_ram_alloc(16384) | IO_MEM_RAM
);
236 /* Internal peripherals. */
237 pic
= mcf_intc_init(0xfc048000, env
);
239 mcf_uart_mm_init(0xfc060000, pic
[26], serial_hds
[0]);
240 mcf_uart_mm_init(0xfc064000, pic
[27], serial_hds
[1]);
241 mcf_uart_mm_init(0xfc068000, pic
[28], serial_hds
[2]);
243 mcf5208_sys_init(pic
);
246 fprintf(stderr
, "Too many NICs\n");
249 if (nd_table
[0].vlan
) {
250 if (nd_table
[0].model
== NULL
251 || strcmp(nd_table
[0].model
, "mcf_fec") == 0) {
252 mcf_fec_init(&nd_table
[0], 0xfc030000, pic
+ 36);
253 } else if (strcmp(nd_table
[0].model
, "?") == 0) {
254 fprintf(stderr
, "qemu: Supported NICs: mcf_fec\n");
257 fprintf(stderr
, "qemu: Unsupported NIC: %s\n", nd_table
[0].model
);
262 /* 0xfc000000 SCM. */
263 /* 0xfc004000 XBS. */
264 /* 0xfc008000 FlexBus CS. */
265 /* 0xfc030000 FEC. */
266 /* 0xfc040000 SCM + Power management. */
267 /* 0xfc044000 eDMA. */
268 /* 0xfc048000 INTC. */
269 /* 0xfc058000 I2C. */
270 /* 0xfc05c000 QSPI. */
271 /* 0xfc060000 UART0. */
272 /* 0xfc064000 UART0. */
273 /* 0xfc068000 UART0. */
274 /* 0xfc070000 DMA timers. */
275 /* 0xfc080000 PIT0. */
276 /* 0xfc084000 PIT1. */
277 /* 0xfc088000 EPORT. */
278 /* 0xfc08c000 Watchdog. */
279 /* 0xfc090000 clock module. */
280 /* 0xfc0a0000 CCM + reset. */
281 /* 0xfc0a4000 GPIO. */
282 /* 0xfc0a8000 SDRAM controller. */
285 if (!kernel_filename
) {
286 fprintf(stderr
, "Kernel image must be specified\n");
290 kernel_size
= load_elf(kernel_filename
, 0, &elf_entry
, NULL
, NULL
);
292 if (kernel_size
< 0) {
293 kernel_size
= load_uboot(kernel_filename
, &entry
, NULL
);
295 if (kernel_size
< 0) {
296 kernel_size
= load_image(kernel_filename
, phys_ram_base
);
299 if (kernel_size
< 0) {
300 fprintf(stderr
, "qemu: could not load kernel '%s'\n", kernel_filename
);
307 QEMUMachine mcf5208evb_machine
= {