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
10 #include "hw/sysbus.h"
11 #include "hw/devices.h"
12 #include "hw/boards.h"
13 #include "hw/arm/arm.h"
15 #include "exec/address-spaces.h"
16 #include "sysemu/sysemu.h"
18 #define TYPE_INTEGRATOR_CM "integrator_core"
19 #define INTEGRATOR_CM(obj) \
20 OBJECT_CHECK(IntegratorCMState, (obj), TYPE_INTEGRATOR_CM)
22 typedef struct IntegratorCMState
{
24 SysBusDevice parent_obj
;
43 static uint8_t integrator_spd
[128] = {
44 128, 8, 4, 11, 9, 1, 64, 0, 2, 0xa0, 0xa0, 0, 0, 8, 0, 1,
45 0xe, 4, 0x1c, 1, 2, 0x20, 0xc0, 0, 0, 0, 0, 0x30, 0x28, 0x30, 0x28, 0x40
48 static uint64_t integratorcm_read(void *opaque
, hwaddr offset
,
51 IntegratorCMState
*s
= opaque
;
52 if (offset
>= 0x100 && offset
< 0x200) {
56 return integrator_spd
[offset
>> 2];
58 switch (offset
>> 2) {
70 if (s
->cm_lock
== 0xa05f) {
75 case 6: /* CM_LMBUSCNT */
76 /* ??? High frequency timer. */
77 hw_error("integratorcm_read: CM_LMBUSCNT");
78 case 7: /* CM_AUXOSC */
80 case 8: /* CM_SDRAM */
84 case 10: /* CM_REFCT */
85 /* ??? High frequency timer. */
86 hw_error("integratorcm_read: CM_REFCT");
87 case 12: /* CM_FLAGS */
89 case 14: /* CM_NVFLAGS */
91 case 16: /* CM_IRQ_STAT */
92 return s
->int_level
& s
->irq_enabled
;
93 case 17: /* CM_IRQ_RSTAT */
95 case 18: /* CM_IRQ_ENSET */
96 return s
->irq_enabled
;
97 case 20: /* CM_SOFT_INTSET */
98 return s
->int_level
& 1;
99 case 24: /* CM_FIQ_STAT */
100 return s
->int_level
& s
->fiq_enabled
;
101 case 25: /* CM_FIQ_RSTAT */
103 case 26: /* CM_FIQ_ENSET */
104 return s
->fiq_enabled
;
105 case 32: /* CM_VOLTAGE_CTL0 */
106 case 33: /* CM_VOLTAGE_CTL1 */
107 case 34: /* CM_VOLTAGE_CTL2 */
108 case 35: /* CM_VOLTAGE_CTL3 */
109 /* ??? Voltage control unimplemented. */
112 hw_error("integratorcm_read: Unimplemented offset 0x%x\n",
118 static void integratorcm_do_remap(IntegratorCMState
*s
)
120 /* Sync memory region state with CM_CTRL REMAP bit:
121 * bit 0 => flash at address 0; bit 1 => RAM
123 memory_region_set_enabled(&s
->flash
, !(s
->cm_ctrl
& 4));
126 static void integratorcm_set_ctrl(IntegratorCMState
*s
, uint32_t value
)
129 qemu_system_reset_request();
131 if ((s
->cm_ctrl
^ value
) & 1) {
132 /* (value & 1) != 0 means the green "MISC LED" is lit.
133 * We don't have any nice place to display LEDs. printf is a bad
134 * idea because Linux uses the LED as a heartbeat and the output
135 * will swamp anything else on the terminal.
138 /* Note that the RESET bit [3] always reads as zero */
139 s
->cm_ctrl
= (s
->cm_ctrl
& ~5) | (value
& 5);
140 integratorcm_do_remap(s
);
143 static void integratorcm_update(IntegratorCMState
*s
)
145 /* ??? The CPU irq/fiq is raised when either the core module or base PIC
147 if (s
->int_level
& (s
->irq_enabled
| s
->fiq_enabled
))
148 hw_error("Core module interrupt\n");
151 static void integratorcm_write(void *opaque
, hwaddr offset
,
152 uint64_t value
, unsigned size
)
154 IntegratorCMState
*s
= opaque
;
155 switch (offset
>> 2) {
157 if (s
->cm_lock
== 0xa05f)
160 case 3: /* CM_CTRL */
161 integratorcm_set_ctrl(s
, value
);
163 case 5: /* CM_LOCK */
164 s
->cm_lock
= value
& 0xffff;
166 case 7: /* CM_AUXOSC */
167 if (s
->cm_lock
== 0xa05f)
168 s
->cm_auxosc
= value
;
170 case 8: /* CM_SDRAM */
173 case 9: /* CM_INIT */
174 /* ??? This can change the memory bus frequency. */
177 case 12: /* CM_FLAGSS */
178 s
->cm_flags
|= value
;
180 case 13: /* CM_FLAGSC */
181 s
->cm_flags
&= ~value
;
183 case 14: /* CM_NVFLAGSS */
184 s
->cm_nvflags
|= value
;
186 case 15: /* CM_NVFLAGSS */
187 s
->cm_nvflags
&= ~value
;
189 case 18: /* CM_IRQ_ENSET */
190 s
->irq_enabled
|= value
;
191 integratorcm_update(s
);
193 case 19: /* CM_IRQ_ENCLR */
194 s
->irq_enabled
&= ~value
;
195 integratorcm_update(s
);
197 case 20: /* CM_SOFT_INTSET */
198 s
->int_level
|= (value
& 1);
199 integratorcm_update(s
);
201 case 21: /* CM_SOFT_INTCLR */
202 s
->int_level
&= ~(value
& 1);
203 integratorcm_update(s
);
205 case 26: /* CM_FIQ_ENSET */
206 s
->fiq_enabled
|= value
;
207 integratorcm_update(s
);
209 case 27: /* CM_FIQ_ENCLR */
210 s
->fiq_enabled
&= ~value
;
211 integratorcm_update(s
);
213 case 32: /* CM_VOLTAGE_CTL0 */
214 case 33: /* CM_VOLTAGE_CTL1 */
215 case 34: /* CM_VOLTAGE_CTL2 */
216 case 35: /* CM_VOLTAGE_CTL3 */
217 /* ??? Voltage control unimplemented. */
220 hw_error("integratorcm_write: Unimplemented offset 0x%x\n",
226 /* Integrator/CM control registers. */
228 static const MemoryRegionOps integratorcm_ops
= {
229 .read
= integratorcm_read
,
230 .write
= integratorcm_write
,
231 .endianness
= DEVICE_NATIVE_ENDIAN
,
234 static int integratorcm_init(SysBusDevice
*dev
)
236 IntegratorCMState
*s
= INTEGRATOR_CM(dev
);
238 s
->cm_osc
= 0x01000048;
239 /* ??? What should the high bits of this value be? */
240 s
->cm_auxosc
= 0x0007feff;
241 s
->cm_sdram
= 0x00011122;
242 if (s
->memsz
>= 256) {
243 integrator_spd
[31] = 64;
245 } else if (s
->memsz
>= 128) {
246 integrator_spd
[31] = 32;
248 } else if (s
->memsz
>= 64) {
249 integrator_spd
[31] = 16;
251 } else if (s
->memsz
>= 32) {
252 integrator_spd
[31] = 4;
255 integrator_spd
[31] = 2;
257 memcpy(integrator_spd
+ 73, "QEMU-MEMORY", 11);
258 s
->cm_init
= 0x00000112;
259 memory_region_init_ram(&s
->flash
, OBJECT(s
), "integrator.flash", 0x100000);
260 vmstate_register_ram_global(&s
->flash
);
262 memory_region_init_io(&s
->iomem
, OBJECT(s
), &integratorcm_ops
, s
,
263 "integratorcm", 0x00800000);
264 sysbus_init_mmio(dev
, &s
->iomem
);
266 integratorcm_do_remap(s
);
267 /* ??? Save/restore. */
271 /* Integrator/CP hardware emulation. */
272 /* Primary interrupt controller. */
274 #define TYPE_INTEGRATOR_PIC "integrator_pic"
275 #define INTEGRATOR_PIC(obj) \
276 OBJECT_CHECK(icp_pic_state, (obj), TYPE_INTEGRATOR_PIC)
278 typedef struct icp_pic_state
{
280 SysBusDevice parent_obj
;
285 uint32_t irq_enabled
;
286 uint32_t fiq_enabled
;
291 static void icp_pic_update(icp_pic_state
*s
)
295 flags
= (s
->level
& s
->irq_enabled
);
296 qemu_set_irq(s
->parent_irq
, flags
!= 0);
297 flags
= (s
->level
& s
->fiq_enabled
);
298 qemu_set_irq(s
->parent_fiq
, flags
!= 0);
301 static void icp_pic_set_irq(void *opaque
, int irq
, int level
)
303 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
305 s
->level
|= 1 << irq
;
307 s
->level
&= ~(1 << irq
);
311 static uint64_t icp_pic_read(void *opaque
, hwaddr offset
,
314 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
316 switch (offset
>> 2) {
317 case 0: /* IRQ_STATUS */
318 return s
->level
& s
->irq_enabled
;
319 case 1: /* IRQ_RAWSTAT */
321 case 2: /* IRQ_ENABLESET */
322 return s
->irq_enabled
;
323 case 4: /* INT_SOFTSET */
325 case 8: /* FRQ_STATUS */
326 return s
->level
& s
->fiq_enabled
;
327 case 9: /* FRQ_RAWSTAT */
329 case 10: /* FRQ_ENABLESET */
330 return s
->fiq_enabled
;
331 case 3: /* IRQ_ENABLECLR */
332 case 5: /* INT_SOFTCLR */
333 case 11: /* FRQ_ENABLECLR */
335 printf ("icp_pic_read: Bad register offset 0x%x\n", (int)offset
);
340 static void icp_pic_write(void *opaque
, hwaddr offset
,
341 uint64_t value
, unsigned size
)
343 icp_pic_state
*s
= (icp_pic_state
*)opaque
;
345 switch (offset
>> 2) {
346 case 2: /* IRQ_ENABLESET */
347 s
->irq_enabled
|= value
;
349 case 3: /* IRQ_ENABLECLR */
350 s
->irq_enabled
&= ~value
;
352 case 4: /* INT_SOFTSET */
354 icp_pic_set_irq(s
, 0, 1);
356 case 5: /* INT_SOFTCLR */
358 icp_pic_set_irq(s
, 0, 0);
360 case 10: /* FRQ_ENABLESET */
361 s
->fiq_enabled
|= value
;
363 case 11: /* FRQ_ENABLECLR */
364 s
->fiq_enabled
&= ~value
;
366 case 0: /* IRQ_STATUS */
367 case 1: /* IRQ_RAWSTAT */
368 case 8: /* FRQ_STATUS */
369 case 9: /* FRQ_RAWSTAT */
371 printf ("icp_pic_write: Bad register offset 0x%x\n", (int)offset
);
377 static const MemoryRegionOps icp_pic_ops
= {
378 .read
= icp_pic_read
,
379 .write
= icp_pic_write
,
380 .endianness
= DEVICE_NATIVE_ENDIAN
,
383 static int icp_pic_init(SysBusDevice
*sbd
)
385 DeviceState
*dev
= DEVICE(sbd
);
386 icp_pic_state
*s
= INTEGRATOR_PIC(dev
);
388 qdev_init_gpio_in(dev
, icp_pic_set_irq
, 32);
389 sysbus_init_irq(sbd
, &s
->parent_irq
);
390 sysbus_init_irq(sbd
, &s
->parent_fiq
);
391 memory_region_init_io(&s
->iomem
, OBJECT(s
), &icp_pic_ops
, s
,
392 "icp-pic", 0x00800000);
393 sysbus_init_mmio(sbd
, &s
->iomem
);
397 /* CP control registers. */
399 static uint64_t icp_control_read(void *opaque
, hwaddr offset
,
402 switch (offset
>> 2) {
403 case 0: /* CP_IDFIELD */
405 case 1: /* CP_FLASHPROG */
407 case 2: /* CP_INTREG */
409 case 3: /* CP_DECODE */
412 hw_error("icp_control_read: Bad offset %x\n", (int)offset
);
417 static void icp_control_write(void *opaque
, hwaddr offset
,
418 uint64_t value
, unsigned size
)
420 switch (offset
>> 2) {
421 case 1: /* CP_FLASHPROG */
422 case 2: /* CP_INTREG */
423 case 3: /* CP_DECODE */
424 /* Nothing interesting implemented yet. */
427 hw_error("icp_control_write: Bad offset %x\n", (int)offset
);
431 static const MemoryRegionOps icp_control_ops
= {
432 .read
= icp_control_read
,
433 .write
= icp_control_write
,
434 .endianness
= DEVICE_NATIVE_ENDIAN
,
437 static void icp_control_init(hwaddr base
)
441 io
= (MemoryRegion
*)g_malloc0(sizeof(MemoryRegion
));
442 memory_region_init_io(io
, NULL
, &icp_control_ops
, NULL
,
443 "control", 0x00800000);
444 memory_region_add_subregion(get_system_memory(), base
, io
);
445 /* ??? Save/restore. */
451 static struct arm_boot_info integrator_binfo
= {
456 static void integratorcp_init(QEMUMachineInitArgs
*args
)
458 ram_addr_t ram_size
= args
->ram_size
;
459 const char *cpu_model
= args
->cpu_model
;
460 const char *kernel_filename
= args
->kernel_filename
;
461 const char *kernel_cmdline
= args
->kernel_cmdline
;
462 const char *initrd_filename
= args
->initrd_filename
;
464 MemoryRegion
*address_space_mem
= get_system_memory();
465 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
466 MemoryRegion
*ram_alias
= g_new(MemoryRegion
, 1);
472 cpu_model
= "arm926";
474 cpu
= cpu_arm_init(cpu_model
);
476 fprintf(stderr
, "Unable to find CPU definition\n");
480 memory_region_init_ram(ram
, NULL
, "integrator.ram", ram_size
);
481 vmstate_register_ram_global(ram
);
482 /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */
483 /* ??? RAM should repeat to fill physical memory space. */
484 /* SDRAM at address zero*/
485 memory_region_add_subregion(address_space_mem
, 0, ram
);
486 /* And again at address 0x80000000 */
487 memory_region_init_alias(ram_alias
, NULL
, "ram.alias", ram
, 0, ram_size
);
488 memory_region_add_subregion(address_space_mem
, 0x80000000, ram_alias
);
490 dev
= qdev_create(NULL
, TYPE_INTEGRATOR_CM
);
491 qdev_prop_set_uint32(dev
, "memsz", ram_size
>> 20);
492 qdev_init_nofail(dev
);
493 sysbus_mmio_map((SysBusDevice
*)dev
, 0, 0x10000000);
495 dev
= sysbus_create_varargs(TYPE_INTEGRATOR_PIC
, 0x14000000,
496 qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_IRQ
),
497 qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_FIQ
),
499 for (i
= 0; i
< 32; i
++) {
500 pic
[i
] = qdev_get_gpio_in(dev
, i
);
502 sysbus_create_simple(TYPE_INTEGRATOR_PIC
, 0xca000000, pic
[26]);
503 sysbus_create_varargs("integrator_pit", 0x13000000,
504 pic
[5], pic
[6], pic
[7], NULL
);
505 sysbus_create_simple("pl031", 0x15000000, pic
[8]);
506 sysbus_create_simple("pl011", 0x16000000, pic
[1]);
507 sysbus_create_simple("pl011", 0x17000000, pic
[2]);
508 icp_control_init(0xcb000000);
509 sysbus_create_simple("pl050_keyboard", 0x18000000, pic
[3]);
510 sysbus_create_simple("pl050_mouse", 0x19000000, pic
[4]);
511 sysbus_create_varargs("pl181", 0x1c000000, pic
[23], pic
[24], NULL
);
512 if (nd_table
[0].used
)
513 smc91c111_init(&nd_table
[0], 0xc8000000, pic
[27]);
515 sysbus_create_simple("pl110", 0xc0000000, pic
[22]);
517 integrator_binfo
.ram_size
= ram_size
;
518 integrator_binfo
.kernel_filename
= kernel_filename
;
519 integrator_binfo
.kernel_cmdline
= kernel_cmdline
;
520 integrator_binfo
.initrd_filename
= initrd_filename
;
521 arm_load_kernel(cpu
, &integrator_binfo
);
524 static QEMUMachine integratorcp_machine
= {
525 .name
= "integratorcp",
526 .desc
= "ARM Integrator/CP (ARM926EJ-S)",
527 .init
= integratorcp_init
,
531 static void integratorcp_machine_init(void)
533 qemu_register_machine(&integratorcp_machine
);
536 machine_init(integratorcp_machine_init
);
538 static Property core_properties
[] = {
539 DEFINE_PROP_UINT32("memsz", IntegratorCMState
, memsz
, 0),
540 DEFINE_PROP_END_OF_LIST(),
543 static void core_class_init(ObjectClass
*klass
, void *data
)
545 DeviceClass
*dc
= DEVICE_CLASS(klass
);
546 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
548 k
->init
= integratorcm_init
;
549 dc
->props
= core_properties
;
552 static const TypeInfo core_info
= {
553 .name
= TYPE_INTEGRATOR_CM
,
554 .parent
= TYPE_SYS_BUS_DEVICE
,
555 .instance_size
= sizeof(IntegratorCMState
),
556 .class_init
= core_class_init
,
559 static void icp_pic_class_init(ObjectClass
*klass
, void *data
)
561 SysBusDeviceClass
*sdc
= SYS_BUS_DEVICE_CLASS(klass
);
563 sdc
->init
= icp_pic_init
;
566 static const TypeInfo icp_pic_info
= {
567 .name
= TYPE_INTEGRATOR_PIC
,
568 .parent
= TYPE_SYS_BUS_DEVICE
,
569 .instance_size
= sizeof(icp_pic_state
),
570 .class_init
= icp_pic_class_init
,
573 static void integratorcp_register_types(void)
575 type_register_static(&icp_pic_info
);
576 type_register_static(&core_info
);
579 type_init(integratorcp_register_types
)