2 * ARM Integrator CP System emulation.
4 * Copyright (c) 2005-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL
11 #include "primecell.h"
16 #include "exec-memory.h"
37 static uint8_t integrator_spd
[128] = {
38 128, 8, 4, 11, 9, 1, 64, 0, 2, 0xa0, 0xa0, 0, 0, 8, 0, 1,
39 0xe, 4, 0x1c, 1, 2, 0x20, 0xc0, 0, 0, 0, 0, 0x30, 0x28, 0x30, 0x28, 0x40
42 static uint32_t integratorcm_read(void *opaque
, target_phys_addr_t offset
)
44 integratorcm_state
*s
= (integratorcm_state
*)opaque
;
45 if (offset
>= 0x100 && offset
< 0x200) {
49 return integrator_spd
[offset
>> 2];
51 switch (offset
>> 2) {
63 if (s
->cm_lock
== 0xa05f) {
68 case 6: /* CM_LMBUSCNT */
69 /* ??? High frequency timer. */
70 hw_error("integratorcm_read: CM_LMBUSCNT");
71 case 7: /* CM_AUXOSC */
73 case 8: /* CM_SDRAM */
77 case 10: /* CM_REFCT */
78 /* ??? High frequency timer. */
79 hw_error("integratorcm_read: CM_REFCT");
80 case 12: /* CM_FLAGS */
82 case 14: /* CM_NVFLAGS */
84 case 16: /* CM_IRQ_STAT */
85 return s
->int_level
& s
->irq_enabled
;
86 case 17: /* CM_IRQ_RSTAT */
88 case 18: /* CM_IRQ_ENSET */
89 return s
->irq_enabled
;
90 case 20: /* CM_SOFT_INTSET */
91 return s
->int_level
& 1;
92 case 24: /* CM_FIQ_STAT */
93 return s
->int_level
& s
->fiq_enabled
;
94 case 25: /* CM_FIQ_RSTAT */
96 case 26: /* CM_FIQ_ENSET */
97 return s
->fiq_enabled
;
98 case 32: /* CM_VOLTAGE_CTL0 */
99 case 33: /* CM_VOLTAGE_CTL1 */
100 case 34: /* CM_VOLTAGE_CTL2 */
101 case 35: /* CM_VOLTAGE_CTL3 */
102 /* ??? Voltage control unimplemented. */
105 hw_error("integratorcm_read: Unimplemented offset 0x%x\n",
111 static void integratorcm_do_remap(integratorcm_state
*s
, int flash
)
114 if (s
->flash_mapped
) {
115 sysbus_del_memory(&s
->busdev
, &s
->flash
);
116 s
->flash_mapped
= false;
119 if (!s
->flash_mapped
) {
120 sysbus_add_memory_overlap(&s
->busdev
, 0, &s
->flash
, 1);
121 s
->flash_mapped
= true;
124 //??? tlb_flush (cpu_single_env, 1);
127 static void integratorcm_set_ctrl(integratorcm_state
*s
, uint32_t value
)
130 qemu_system_reset_request();
132 if ((s
->cm_ctrl
^ value
) & 4) {
133 integratorcm_do_remap(s
, (value
& 4) == 0);
135 if ((s
->cm_ctrl
^ value
) & 1) {
136 /* (value & 1) != 0 means the green "MISC LED" is lit.
137 * We don't have any nice place to display LEDs. printf is a bad
138 * idea because Linux uses the LED as a heartbeat and the output
139 * will swamp anything else on the terminal.
142 /* Note that the RESET bit [3] always reads as zero */
143 s
->cm_ctrl
= (s
->cm_ctrl
& ~5) | (value
& 5);
146 static void integratorcm_update(integratorcm_state
*s
)
148 /* ??? The CPU irq/fiq is raised when either the core module or base PIC
150 if (s
->int_level
& (s
->irq_enabled
| s
->fiq_enabled
))
151 hw_error("Core module interrupt\n");
154 static void integratorcm_write(void *opaque
, target_phys_addr_t offset
,
157 integratorcm_state
*s
= (integratorcm_state
*)opaque
;
158 switch (offset
>> 2) {
160 if (s
->cm_lock
== 0xa05f)
163 case 3: /* CM_CTRL */
164 integratorcm_set_ctrl(s
, value
);
166 case 5: /* CM_LOCK */
167 s
->cm_lock
= value
& 0xffff;
169 case 7: /* CM_AUXOSC */
170 if (s
->cm_lock
== 0xa05f)
171 s
->cm_auxosc
= value
;
173 case 8: /* CM_SDRAM */
176 case 9: /* CM_INIT */
177 /* ??? This can change the memory bus frequency. */
180 case 12: /* CM_FLAGSS */
181 s
->cm_flags
|= value
;
183 case 13: /* CM_FLAGSC */
184 s
->cm_flags
&= ~value
;
186 case 14: /* CM_NVFLAGSS */
187 s
->cm_nvflags
|= value
;
189 case 15: /* CM_NVFLAGSS */
190 s
->cm_nvflags
&= ~value
;
192 case 18: /* CM_IRQ_ENSET */
193 s
->irq_enabled
|= value
;
194 integratorcm_update(s
);
196 case 19: /* CM_IRQ_ENCLR */
197 s
->irq_enabled
&= ~value
;
198 integratorcm_update(s
);
200 case 20: /* CM_SOFT_INTSET */
201 s
->int_level
|= (value
& 1);
202 integratorcm_update(s
);
204 case 21: /* CM_SOFT_INTCLR */
205 s
->int_level
&= ~(value
& 1);
206 integratorcm_update(s
);
208 case 26: /* CM_FIQ_ENSET */
209 s
->fiq_enabled
|= value
;
210 integratorcm_update(s
);
212 case 27: /* CM_FIQ_ENCLR */
213 s
->fiq_enabled
&= ~value
;
214 integratorcm_update(s
);
216 case 32: /* CM_VOLTAGE_CTL0 */
217 case 33: /* CM_VOLTAGE_CTL1 */
218 case 34: /* CM_VOLTAGE_CTL2 */
219 case 35: /* CM_VOLTAGE_CTL3 */
220 /* ??? Voltage control unimplemented. */
223 hw_error("integratorcm_write: Unimplemented offset 0x%x\n",
229 /* Integrator/CM control registers. */
231 static CPUReadMemoryFunc
* const integratorcm_readfn
[] = {
237 static CPUWriteMemoryFunc
* const integratorcm_writefn
[] = {
243 static int integratorcm_init(SysBusDevice
*dev
)
246 integratorcm_state
*s
= FROM_SYSBUS(integratorcm_state
, dev
);
248 s
->cm_osc
= 0x01000048;
249 /* ??? What should the high bits of this value be? */
250 s
->cm_auxosc
= 0x0007feff;
251 s
->cm_sdram
= 0x00011122;
252 if (s
->memsz
>= 256) {
253 integrator_spd
[31] = 64;
255 } else if (s
->memsz
>= 128) {
256 integrator_spd
[31] = 32;
258 } else if (s
->memsz
>= 64) {
259 integrator_spd
[31] = 16;
261 } else if (s
->memsz
>= 32) {
262 integrator_spd
[31] = 4;
265 integrator_spd
[31] = 2;
267 memcpy(integrator_spd
+ 73, "QEMU-MEMORY", 11);
268 s
->cm_init
= 0x00000112;
269 memory_region_init_ram(&s
->flash
, NULL
, "integrator.flash", 0x100000);
270 s
->flash_mapped
= false;
272 iomemtype
= cpu_register_io_memory(integratorcm_readfn
,
273 integratorcm_writefn
, s
,
274 DEVICE_NATIVE_ENDIAN
);
275 sysbus_init_mmio(dev
, 0x00800000, iomemtype
);
276 integratorcm_do_remap(s
, 1);
277 /* ??? Save/restore. */
281 /* Integrator/CP hardware emulation. */
282 /* Primary interrupt controller. */
284 typedef struct icp_pic_state
288 uint32_t irq_enabled
;
289 uint32_t fiq_enabled
;
294 static void icp_pic_update(icp_pic_state
*s
)
298 flags
= (s
->level
& s
->irq_enabled
);
299 qemu_set_irq(s
->parent_irq
, flags
!= 0);
300 flags
= (s
->level
& s
->fiq_enabled
);
301 qemu_set_irq(s
->parent_fiq
, flags
!= 0);
304 static void icp_pic_set_irq(void *opaque
, int irq
, int level
)
306 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
308 s
->level
|= 1 << irq
;
310 s
->level
&= ~(1 << irq
);
314 static uint32_t icp_pic_read(void *opaque
, target_phys_addr_t offset
)
316 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
318 switch (offset
>> 2) {
319 case 0: /* IRQ_STATUS */
320 return s
->level
& s
->irq_enabled
;
321 case 1: /* IRQ_RAWSTAT */
323 case 2: /* IRQ_ENABLESET */
324 return s
->irq_enabled
;
325 case 4: /* INT_SOFTSET */
327 case 8: /* FRQ_STATUS */
328 return s
->level
& s
->fiq_enabled
;
329 case 9: /* FRQ_RAWSTAT */
331 case 10: /* FRQ_ENABLESET */
332 return s
->fiq_enabled
;
333 case 3: /* IRQ_ENABLECLR */
334 case 5: /* INT_SOFTCLR */
335 case 11: /* FRQ_ENABLECLR */
337 printf ("icp_pic_read: Bad register offset 0x%x\n", (int)offset
);
342 static void icp_pic_write(void *opaque
, target_phys_addr_t offset
,
345 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
347 switch (offset
>> 2) {
348 case 2: /* IRQ_ENABLESET */
349 s
->irq_enabled
|= value
;
351 case 3: /* IRQ_ENABLECLR */
352 s
->irq_enabled
&= ~value
;
354 case 4: /* INT_SOFTSET */
356 icp_pic_set_irq(s
, 0, 1);
358 case 5: /* INT_SOFTCLR */
360 icp_pic_set_irq(s
, 0, 0);
362 case 10: /* FRQ_ENABLESET */
363 s
->fiq_enabled
|= value
;
365 case 11: /* FRQ_ENABLECLR */
366 s
->fiq_enabled
&= ~value
;
368 case 0: /* IRQ_STATUS */
369 case 1: /* IRQ_RAWSTAT */
370 case 8: /* FRQ_STATUS */
371 case 9: /* FRQ_RAWSTAT */
373 printf ("icp_pic_write: Bad register offset 0x%x\n", (int)offset
);
379 static CPUReadMemoryFunc
* const icp_pic_readfn
[] = {
385 static CPUWriteMemoryFunc
* const icp_pic_writefn
[] = {
391 static int icp_pic_init(SysBusDevice
*dev
)
393 icp_pic_state
*s
= FROM_SYSBUS(icp_pic_state
, dev
);
396 qdev_init_gpio_in(&dev
->qdev
, icp_pic_set_irq
, 32);
397 sysbus_init_irq(dev
, &s
->parent_irq
);
398 sysbus_init_irq(dev
, &s
->parent_fiq
);
399 iomemtype
= cpu_register_io_memory(icp_pic_readfn
,
401 DEVICE_NATIVE_ENDIAN
);
402 sysbus_init_mmio(dev
, 0x00800000, iomemtype
);
406 /* CP control registers. */
407 static uint32_t icp_control_read(void *opaque
, target_phys_addr_t offset
)
409 switch (offset
>> 2) {
410 case 0: /* CP_IDFIELD */
412 case 1: /* CP_FLASHPROG */
414 case 2: /* CP_INTREG */
416 case 3: /* CP_DECODE */
419 hw_error("icp_control_read: Bad offset %x\n", (int)offset
);
424 static void icp_control_write(void *opaque
, target_phys_addr_t offset
,
427 switch (offset
>> 2) {
428 case 1: /* CP_FLASHPROG */
429 case 2: /* CP_INTREG */
430 case 3: /* CP_DECODE */
431 /* Nothing interesting implemented yet. */
434 hw_error("icp_control_write: Bad offset %x\n", (int)offset
);
437 static CPUReadMemoryFunc
* const icp_control_readfn
[] = {
443 static CPUWriteMemoryFunc
* const icp_control_writefn
[] = {
449 static void icp_control_init(uint32_t base
)
453 iomemtype
= cpu_register_io_memory(icp_control_readfn
,
454 icp_control_writefn
, NULL
,
455 DEVICE_NATIVE_ENDIAN
);
456 cpu_register_physical_memory(base
, 0x00800000, iomemtype
);
457 /* ??? Save/restore. */
463 static struct arm_boot_info integrator_binfo
= {
468 static void integratorcp_init(ram_addr_t ram_size
,
469 const char *boot_device
,
470 const char *kernel_filename
, const char *kernel_cmdline
,
471 const char *initrd_filename
, const char *cpu_model
)
474 MemoryRegion
*address_space_mem
= get_system_memory();
475 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
476 MemoryRegion
*ram_alias
= g_new(MemoryRegion
, 1);
483 cpu_model
= "arm926";
484 env
= cpu_init(cpu_model
);
486 fprintf(stderr
, "Unable to find CPU definition\n");
489 memory_region_init_ram(ram
, NULL
, "integrator.ram", ram_size
);
490 /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */
491 /* ??? RAM should repeat to fill physical memory space. */
492 /* SDRAM at address zero*/
493 memory_region_add_subregion(address_space_mem
, 0, ram
);
494 /* And again at address 0x80000000 */
495 memory_region_init_alias(ram_alias
, "ram.alias", ram
, 0, ram_size
);
496 memory_region_add_subregion(address_space_mem
, 0x80000000, ram_alias
);
498 dev
= qdev_create(NULL
, "integrator_core");
499 qdev_prop_set_uint32(dev
, "memsz", ram_size
>> 20);
500 qdev_init_nofail(dev
);
501 sysbus_mmio_map((SysBusDevice
*)dev
, 0, 0x10000000);
503 cpu_pic
= arm_pic_init_cpu(env
);
504 dev
= sysbus_create_varargs("integrator_pic", 0x14000000,
505 cpu_pic
[ARM_PIC_CPU_IRQ
],
506 cpu_pic
[ARM_PIC_CPU_FIQ
], NULL
);
507 for (i
= 0; i
< 32; i
++) {
508 pic
[i
] = qdev_get_gpio_in(dev
, i
);
510 sysbus_create_simple("integrator_pic", 0xca000000, pic
[26]);
511 sysbus_create_varargs("integrator_pit", 0x13000000,
512 pic
[5], pic
[6], pic
[7], NULL
);
513 sysbus_create_simple("pl031", 0x15000000, pic
[8]);
514 sysbus_create_simple("pl011", 0x16000000, pic
[1]);
515 sysbus_create_simple("pl011", 0x17000000, pic
[2]);
516 icp_control_init(0xcb000000);
517 sysbus_create_simple("pl050_keyboard", 0x18000000, pic
[3]);
518 sysbus_create_simple("pl050_mouse", 0x19000000, pic
[4]);
519 sysbus_create_varargs("pl181", 0x1c000000, pic
[23], pic
[24], NULL
);
520 if (nd_table
[0].vlan
)
521 smc91c111_init(&nd_table
[0], 0xc8000000, pic
[27]);
523 sysbus_create_simple("pl110", 0xc0000000, pic
[22]);
525 integrator_binfo
.ram_size
= ram_size
;
526 integrator_binfo
.kernel_filename
= kernel_filename
;
527 integrator_binfo
.kernel_cmdline
= kernel_cmdline
;
528 integrator_binfo
.initrd_filename
= initrd_filename
;
529 arm_load_kernel(env
, &integrator_binfo
);
532 static QEMUMachine integratorcp_machine
= {
533 .name
= "integratorcp",
534 .desc
= "ARM Integrator/CP (ARM926EJ-S)",
535 .init
= integratorcp_init
,
539 static void integratorcp_machine_init(void)
541 qemu_register_machine(&integratorcp_machine
);
544 machine_init(integratorcp_machine_init
);
546 static SysBusDeviceInfo core_info
= {
547 .init
= integratorcm_init
,
548 .qdev
.name
= "integrator_core",
549 .qdev
.size
= sizeof(integratorcm_state
),
550 .qdev
.props
= (Property
[]) {
551 DEFINE_PROP_UINT32("memsz", integratorcm_state
, memsz
, 0),
552 DEFINE_PROP_END_OF_LIST(),
556 static void integratorcp_register_devices(void)
558 sysbus_register_dev("integrator_pic", sizeof(icp_pic_state
), icp_pic_init
);
559 sysbus_register_withprop(&core_info
);
562 device_init(integratorcp_register_devices
)