2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2005-11-26 13:38:39 +03:00
|
|
|
* ARM Integrator CP System emulation.
|
|
|
|
*
|
2007-04-06 20:49:48 +04:00
|
|
|
* Copyright (c) 2005-2007 CodeSourcery.
|
2005-11-26 13:38:39 +03:00
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 06:21:35 +04:00
|
|
|
* This code is licensed under the GPL
|
2005-11-26 13:38:39 +03:00
|
|
|
*/
|
|
|
|
|
2009-05-15 01:35:07 +04:00
|
|
|
#include "sysbus.h"
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "devices.h"
|
|
|
|
#include "boards.h"
|
|
|
|
#include "arm-misc.h"
|
2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2005-11-26 13:38:39 +03:00
|
|
|
|
|
|
|
typedef struct {
|
2009-05-15 01:35:07 +04:00
|
|
|
SysBusDevice busdev;
|
2011-10-17 19:28:26 +04:00
|
|
|
MemoryRegion iomem;
|
2009-07-15 15:43:31 +04:00
|
|
|
uint32_t memsz;
|
2011-07-25 16:03:19 +04:00
|
|
|
MemoryRegion flash;
|
2005-11-26 13:38:39 +03:00
|
|
|
uint32_t cm_osc;
|
|
|
|
uint32_t cm_ctrl;
|
|
|
|
uint32_t cm_lock;
|
|
|
|
uint32_t cm_auxosc;
|
|
|
|
uint32_t cm_sdram;
|
|
|
|
uint32_t cm_init;
|
|
|
|
uint32_t cm_flags;
|
|
|
|
uint32_t cm_nvflags;
|
|
|
|
uint32_t int_level;
|
|
|
|
uint32_t irq_enabled;
|
|
|
|
uint32_t fiq_enabled;
|
|
|
|
} integratorcm_state;
|
|
|
|
|
|
|
|
static uint8_t integrator_spd[128] = {
|
|
|
|
128, 8, 4, 11, 9, 1, 64, 0, 2, 0xa0, 0xa0, 0, 0, 8, 0, 1,
|
|
|
|
0xe, 4, 0x1c, 1, 2, 0x20, 0xc0, 0, 0, 0, 0, 0x30, 0x28, 0x30, 0x28, 0x40
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t integratorcm_read(void *opaque, hwaddr offset,
|
2011-10-17 19:28:26 +04:00
|
|
|
unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
integratorcm_state *s = (integratorcm_state *)opaque;
|
|
|
|
if (offset >= 0x100 && offset < 0x200) {
|
|
|
|
/* CM_SPD */
|
|
|
|
if (offset >= 0x180)
|
|
|
|
return 0;
|
|
|
|
return integrator_spd[offset >> 2];
|
|
|
|
}
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* CM_ID */
|
|
|
|
return 0x411a3001;
|
|
|
|
case 1: /* CM_PROC */
|
|
|
|
return 0;
|
|
|
|
case 2: /* CM_OSC */
|
|
|
|
return s->cm_osc;
|
|
|
|
case 3: /* CM_CTRL */
|
|
|
|
return s->cm_ctrl;
|
|
|
|
case 4: /* CM_STAT */
|
|
|
|
return 0x00100000;
|
|
|
|
case 5: /* CM_LOCK */
|
|
|
|
if (s->cm_lock == 0xa05f) {
|
|
|
|
return 0x1a05f;
|
|
|
|
} else {
|
|
|
|
return s->cm_lock;
|
|
|
|
}
|
|
|
|
case 6: /* CM_LMBUSCNT */
|
|
|
|
/* ??? High frequency timer. */
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("integratorcm_read: CM_LMBUSCNT");
|
2005-11-26 13:38:39 +03:00
|
|
|
case 7: /* CM_AUXOSC */
|
|
|
|
return s->cm_auxosc;
|
|
|
|
case 8: /* CM_SDRAM */
|
|
|
|
return s->cm_sdram;
|
|
|
|
case 9: /* CM_INIT */
|
|
|
|
return s->cm_init;
|
|
|
|
case 10: /* CM_REFCT */
|
|
|
|
/* ??? High frequency timer. */
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("integratorcm_read: CM_REFCT");
|
2005-11-26 13:38:39 +03:00
|
|
|
case 12: /* CM_FLAGS */
|
|
|
|
return s->cm_flags;
|
|
|
|
case 14: /* CM_NVFLAGS */
|
|
|
|
return s->cm_nvflags;
|
|
|
|
case 16: /* CM_IRQ_STAT */
|
|
|
|
return s->int_level & s->irq_enabled;
|
|
|
|
case 17: /* CM_IRQ_RSTAT */
|
|
|
|
return s->int_level;
|
|
|
|
case 18: /* CM_IRQ_ENSET */
|
|
|
|
return s->irq_enabled;
|
|
|
|
case 20: /* CM_SOFT_INTSET */
|
|
|
|
return s->int_level & 1;
|
|
|
|
case 24: /* CM_FIQ_STAT */
|
|
|
|
return s->int_level & s->fiq_enabled;
|
|
|
|
case 25: /* CM_FIQ_RSTAT */
|
|
|
|
return s->int_level;
|
|
|
|
case 26: /* CM_FIQ_ENSET */
|
|
|
|
return s->fiq_enabled;
|
|
|
|
case 32: /* CM_VOLTAGE_CTL0 */
|
|
|
|
case 33: /* CM_VOLTAGE_CTL1 */
|
|
|
|
case 34: /* CM_VOLTAGE_CTL2 */
|
|
|
|
case 35: /* CM_VOLTAGE_CTL3 */
|
|
|
|
/* ??? Voltage control unimplemented. */
|
|
|
|
return 0;
|
|
|
|
default:
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("integratorcm_read: Unimplemented offset 0x%x\n",
|
|
|
|
(int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-06 22:58:28 +04:00
|
|
|
static void integratorcm_do_remap(integratorcm_state *s)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2012-01-06 22:58:28 +04:00
|
|
|
/* Sync memory region state with CM_CTRL REMAP bit:
|
|
|
|
* bit 0 => flash at address 0; bit 1 => RAM
|
|
|
|
*/
|
|
|
|
memory_region_set_enabled(&s->flash, !(s->cm_ctrl & 4));
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value)
|
|
|
|
{
|
|
|
|
if (value & 8) {
|
2011-09-12 18:43:31 +04:00
|
|
|
qemu_system_reset_request();
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
2011-09-12 18:43:31 +04:00
|
|
|
if ((s->cm_ctrl ^ value) & 1) {
|
|
|
|
/* (value & 1) != 0 means the green "MISC LED" is lit.
|
|
|
|
* We don't have any nice place to display LEDs. printf is a bad
|
|
|
|
* idea because Linux uses the LED as a heartbeat and the output
|
|
|
|
* will swamp anything else on the terminal.
|
|
|
|
*/
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
2011-09-12 18:43:31 +04:00
|
|
|
/* Note that the RESET bit [3] always reads as zero */
|
|
|
|
s->cm_ctrl = (s->cm_ctrl & ~5) | (value & 5);
|
2012-01-06 22:58:28 +04:00
|
|
|
integratorcm_do_remap(s);
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void integratorcm_update(integratorcm_state *s)
|
|
|
|
{
|
|
|
|
/* ??? The CPU irq/fiq is raised when either the core module or base PIC
|
|
|
|
are active. */
|
|
|
|
if (s->int_level & (s->irq_enabled | s->fiq_enabled))
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("Core module interrupt\n");
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void integratorcm_write(void *opaque, hwaddr offset,
|
2011-10-17 19:28:26 +04:00
|
|
|
uint64_t value, unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
integratorcm_state *s = (integratorcm_state *)opaque;
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 2: /* CM_OSC */
|
|
|
|
if (s->cm_lock == 0xa05f)
|
|
|
|
s->cm_osc = value;
|
|
|
|
break;
|
|
|
|
case 3: /* CM_CTRL */
|
|
|
|
integratorcm_set_ctrl(s, value);
|
|
|
|
break;
|
|
|
|
case 5: /* CM_LOCK */
|
|
|
|
s->cm_lock = value & 0xffff;
|
|
|
|
break;
|
|
|
|
case 7: /* CM_AUXOSC */
|
|
|
|
if (s->cm_lock == 0xa05f)
|
|
|
|
s->cm_auxosc = value;
|
|
|
|
break;
|
|
|
|
case 8: /* CM_SDRAM */
|
|
|
|
s->cm_sdram = value;
|
|
|
|
break;
|
|
|
|
case 9: /* CM_INIT */
|
|
|
|
/* ??? This can change the memory bus frequency. */
|
|
|
|
s->cm_init = value;
|
|
|
|
break;
|
|
|
|
case 12: /* CM_FLAGSS */
|
|
|
|
s->cm_flags |= value;
|
|
|
|
break;
|
|
|
|
case 13: /* CM_FLAGSC */
|
|
|
|
s->cm_flags &= ~value;
|
|
|
|
break;
|
|
|
|
case 14: /* CM_NVFLAGSS */
|
|
|
|
s->cm_nvflags |= value;
|
|
|
|
break;
|
|
|
|
case 15: /* CM_NVFLAGSS */
|
|
|
|
s->cm_nvflags &= ~value;
|
|
|
|
break;
|
|
|
|
case 18: /* CM_IRQ_ENSET */
|
|
|
|
s->irq_enabled |= value;
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 19: /* CM_IRQ_ENCLR */
|
|
|
|
s->irq_enabled &= ~value;
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 20: /* CM_SOFT_INTSET */
|
|
|
|
s->int_level |= (value & 1);
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 21: /* CM_SOFT_INTCLR */
|
|
|
|
s->int_level &= ~(value & 1);
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 26: /* CM_FIQ_ENSET */
|
|
|
|
s->fiq_enabled |= value;
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 27: /* CM_FIQ_ENCLR */
|
|
|
|
s->fiq_enabled &= ~value;
|
|
|
|
integratorcm_update(s);
|
|
|
|
break;
|
|
|
|
case 32: /* CM_VOLTAGE_CTL0 */
|
|
|
|
case 33: /* CM_VOLTAGE_CTL1 */
|
|
|
|
case 34: /* CM_VOLTAGE_CTL2 */
|
|
|
|
case 35: /* CM_VOLTAGE_CTL3 */
|
|
|
|
/* ??? Voltage control unimplemented. */
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("integratorcm_write: Unimplemented offset 0x%x\n",
|
|
|
|
(int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Integrator/CM control registers. */
|
|
|
|
|
2011-10-17 19:28:26 +04:00
|
|
|
static const MemoryRegionOps integratorcm_ops = {
|
|
|
|
.read = integratorcm_read,
|
|
|
|
.write = integratorcm_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2005-11-26 13:38:39 +03:00
|
|
|
};
|
|
|
|
|
2009-08-14 12:36:05 +04:00
|
|
|
static int integratorcm_init(SysBusDevice *dev)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2009-05-15 01:35:07 +04:00
|
|
|
integratorcm_state *s = FROM_SYSBUS(integratorcm_state, dev);
|
2005-11-26 13:38:39 +03:00
|
|
|
|
|
|
|
s->cm_osc = 0x01000048;
|
|
|
|
/* ??? What should the high bits of this value be? */
|
|
|
|
s->cm_auxosc = 0x0007feff;
|
|
|
|
s->cm_sdram = 0x00011122;
|
2009-07-15 15:43:31 +04:00
|
|
|
if (s->memsz >= 256) {
|
2005-11-26 13:38:39 +03:00
|
|
|
integrator_spd[31] = 64;
|
|
|
|
s->cm_sdram |= 0x10;
|
2009-07-15 15:43:31 +04:00
|
|
|
} else if (s->memsz >= 128) {
|
2005-11-26 13:38:39 +03:00
|
|
|
integrator_spd[31] = 32;
|
|
|
|
s->cm_sdram |= 0x0c;
|
2009-07-15 15:43:31 +04:00
|
|
|
} else if (s->memsz >= 64) {
|
2005-11-26 13:38:39 +03:00
|
|
|
integrator_spd[31] = 16;
|
|
|
|
s->cm_sdram |= 0x08;
|
2009-07-15 15:43:31 +04:00
|
|
|
} else if (s->memsz >= 32) {
|
2005-11-26 13:38:39 +03:00
|
|
|
integrator_spd[31] = 4;
|
|
|
|
s->cm_sdram |= 0x04;
|
|
|
|
} else {
|
|
|
|
integrator_spd[31] = 2;
|
|
|
|
}
|
|
|
|
memcpy(integrator_spd + 73, "QEMU-MEMORY", 11);
|
|
|
|
s->cm_init = 0x00000112;
|
2011-12-20 17:59:12 +04:00
|
|
|
memory_region_init_ram(&s->flash, "integrator.flash", 0x100000);
|
|
|
|
vmstate_register_ram_global(&s->flash);
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2011-10-17 19:28:26 +04:00
|
|
|
memory_region_init_io(&s->iomem, &integratorcm_ops, s,
|
|
|
|
"integratorcm", 0x00800000);
|
2011-11-27 13:38:10 +04:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2011-10-17 19:28:26 +04:00
|
|
|
|
2012-01-06 22:58:28 +04:00
|
|
|
integratorcm_do_remap(s);
|
2005-11-26 13:38:39 +03:00
|
|
|
/* ??? Save/restore. */
|
2009-08-14 12:36:05 +04:00
|
|
|
return 0;
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Integrator/CP hardware emulation. */
|
|
|
|
/* Primary interrupt controller. */
|
|
|
|
|
|
|
|
typedef struct icp_pic_state
|
|
|
|
{
|
2009-05-15 01:35:07 +04:00
|
|
|
SysBusDevice busdev;
|
2011-10-17 19:28:27 +04:00
|
|
|
MemoryRegion iomem;
|
2005-11-26 13:38:39 +03:00
|
|
|
uint32_t level;
|
|
|
|
uint32_t irq_enabled;
|
|
|
|
uint32_t fiq_enabled;
|
2007-04-07 22:14:41 +04:00
|
|
|
qemu_irq parent_irq;
|
|
|
|
qemu_irq parent_fiq;
|
2005-11-26 13:38:39 +03:00
|
|
|
} icp_pic_state;
|
|
|
|
|
|
|
|
static void icp_pic_update(icp_pic_state *s)
|
|
|
|
{
|
2006-04-09 05:32:52 +04:00
|
|
|
uint32_t flags;
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2007-04-07 22:14:41 +04:00
|
|
|
flags = (s->level & s->irq_enabled);
|
|
|
|
qemu_set_irq(s->parent_irq, flags != 0);
|
|
|
|
flags = (s->level & s->fiq_enabled);
|
|
|
|
qemu_set_irq(s->parent_fiq, flags != 0);
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
2006-04-09 05:32:52 +04:00
|
|
|
static void icp_pic_set_irq(void *opaque, int irq, int level)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2005-12-04 21:54:21 +03:00
|
|
|
icp_pic_state *s = (icp_pic_state *)opaque;
|
2005-11-26 13:38:39 +03:00
|
|
|
if (level)
|
2005-12-04 21:54:21 +03:00
|
|
|
s->level |= 1 << irq;
|
2005-11-26 13:38:39 +03:00
|
|
|
else
|
2005-12-04 21:54:21 +03:00
|
|
|
s->level &= ~(1 << irq);
|
2005-11-26 13:38:39 +03:00
|
|
|
icp_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t icp_pic_read(void *opaque, hwaddr offset,
|
2011-10-17 19:28:27 +04:00
|
|
|
unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
icp_pic_state *s = (icp_pic_state *)opaque;
|
|
|
|
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* IRQ_STATUS */
|
|
|
|
return s->level & s->irq_enabled;
|
|
|
|
case 1: /* IRQ_RAWSTAT */
|
|
|
|
return s->level;
|
|
|
|
case 2: /* IRQ_ENABLESET */
|
|
|
|
return s->irq_enabled;
|
|
|
|
case 4: /* INT_SOFTSET */
|
|
|
|
return s->level & 1;
|
|
|
|
case 8: /* FRQ_STATUS */
|
|
|
|
return s->level & s->fiq_enabled;
|
|
|
|
case 9: /* FRQ_RAWSTAT */
|
|
|
|
return s->level;
|
|
|
|
case 10: /* FRQ_ENABLESET */
|
|
|
|
return s->fiq_enabled;
|
|
|
|
case 3: /* IRQ_ENABLECLR */
|
|
|
|
case 5: /* INT_SOFTCLR */
|
|
|
|
case 11: /* FRQ_ENABLECLR */
|
|
|
|
default:
|
2006-11-20 02:07:17 +03:00
|
|
|
printf ("icp_pic_read: Bad register offset 0x%x\n", (int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void icp_pic_write(void *opaque, hwaddr offset,
|
2011-10-17 19:28:27 +04:00
|
|
|
uint64_t value, unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
icp_pic_state *s = (icp_pic_state *)opaque;
|
|
|
|
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 2: /* IRQ_ENABLESET */
|
|
|
|
s->irq_enabled |= value;
|
|
|
|
break;
|
|
|
|
case 3: /* IRQ_ENABLECLR */
|
|
|
|
s->irq_enabled &= ~value;
|
|
|
|
break;
|
|
|
|
case 4: /* INT_SOFTSET */
|
|
|
|
if (value & 1)
|
2007-04-07 22:14:41 +04:00
|
|
|
icp_pic_set_irq(s, 0, 1);
|
2005-11-26 13:38:39 +03:00
|
|
|
break;
|
|
|
|
case 5: /* INT_SOFTCLR */
|
|
|
|
if (value & 1)
|
2007-04-07 22:14:41 +04:00
|
|
|
icp_pic_set_irq(s, 0, 0);
|
2005-11-26 13:38:39 +03:00
|
|
|
break;
|
|
|
|
case 10: /* FRQ_ENABLESET */
|
|
|
|
s->fiq_enabled |= value;
|
|
|
|
break;
|
|
|
|
case 11: /* FRQ_ENABLECLR */
|
|
|
|
s->fiq_enabled &= ~value;
|
|
|
|
break;
|
|
|
|
case 0: /* IRQ_STATUS */
|
|
|
|
case 1: /* IRQ_RAWSTAT */
|
|
|
|
case 8: /* FRQ_STATUS */
|
|
|
|
case 9: /* FRQ_RAWSTAT */
|
|
|
|
default:
|
2006-11-20 02:07:17 +03:00
|
|
|
printf ("icp_pic_write: Bad register offset 0x%x\n", (int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
icp_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2011-10-17 19:28:27 +04:00
|
|
|
static const MemoryRegionOps icp_pic_ops = {
|
|
|
|
.read = icp_pic_read,
|
|
|
|
.write = icp_pic_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2005-11-26 13:38:39 +03:00
|
|
|
};
|
|
|
|
|
2009-08-14 12:36:05 +04:00
|
|
|
static int icp_pic_init(SysBusDevice *dev)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2009-05-15 01:35:07 +04:00
|
|
|
icp_pic_state *s = FROM_SYSBUS(icp_pic_state, dev);
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2009-05-26 17:56:11 +04:00
|
|
|
qdev_init_gpio_in(&dev->qdev, icp_pic_set_irq, 32);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_init_irq(dev, &s->parent_irq);
|
|
|
|
sysbus_init_irq(dev, &s->parent_fiq);
|
2011-10-17 19:28:27 +04:00
|
|
|
memory_region_init_io(&s->iomem, &icp_pic_ops, s, "icp-pic", 0x00800000);
|
2011-11-27 13:38:10 +04:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2009-08-14 12:36:05 +04:00
|
|
|
return 0;
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CP control registers. */
|
2011-10-17 19:28:28 +04:00
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t icp_control_read(void *opaque, hwaddr offset,
|
2011-10-17 19:28:28 +04:00
|
|
|
unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* CP_IDFIELD */
|
|
|
|
return 0x41034003;
|
|
|
|
case 1: /* CP_FLASHPROG */
|
|
|
|
return 0;
|
|
|
|
case 2: /* CP_INTREG */
|
|
|
|
return 0;
|
|
|
|
case 3: /* CP_DECODE */
|
|
|
|
return 0x11;
|
|
|
|
default:
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("icp_control_read: Bad offset %x\n", (int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void icp_control_write(void *opaque, hwaddr offset,
|
2011-10-17 19:28:28 +04:00
|
|
|
uint64_t value, unsigned size)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 1: /* CP_FLASHPROG */
|
|
|
|
case 2: /* CP_INTREG */
|
|
|
|
case 3: /* CP_DECODE */
|
|
|
|
/* Nothing interesting implemented yet. */
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-08 05:35:15 +04:00
|
|
|
hw_error("icp_control_write: Bad offset %x\n", (int)offset);
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 19:28:28 +04:00
|
|
|
static const MemoryRegionOps icp_control_ops = {
|
|
|
|
.read = icp_control_read,
|
|
|
|
.write = icp_control_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2005-11-26 13:38:39 +03:00
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void icp_control_init(hwaddr base)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2011-10-17 19:28:28 +04:00
|
|
|
MemoryRegion *io;
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2011-10-17 19:28:28 +04:00
|
|
|
io = (MemoryRegion *)g_malloc0(sizeof(MemoryRegion));
|
|
|
|
memory_region_init_io(io, &icp_control_ops, NULL,
|
|
|
|
"control", 0x00800000);
|
|
|
|
memory_region_add_subregion(get_system_memory(), base, io);
|
2005-11-26 13:38:39 +03:00
|
|
|
/* ??? Save/restore. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Board init. */
|
|
|
|
|
2008-04-15 00:27:51 +04:00
|
|
|
static struct arm_boot_info integrator_binfo = {
|
|
|
|
.loader_start = 0x0,
|
|
|
|
.board_id = 0x113,
|
|
|
|
};
|
|
|
|
|
2012-10-16 00:22:02 +04:00
|
|
|
static void integratorcp_init(QEMUMachineInitArgs *args)
|
2005-11-26 13:38:39 +03:00
|
|
|
{
|
2012-10-16 00:22:02 +04:00
|
|
|
ram_addr_t ram_size = args->ram_size;
|
|
|
|
const char *cpu_model = args->cpu_model;
|
|
|
|
const char *kernel_filename = args->kernel_filename;
|
|
|
|
const char *kernel_cmdline = args->kernel_cmdline;
|
|
|
|
const char *initrd_filename = args->initrd_filename;
|
2012-05-14 03:51:01 +04:00
|
|
|
ARMCPU *cpu;
|
2011-07-25 16:03:19 +04:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
MemoryRegion *ram = g_new(MemoryRegion, 1);
|
|
|
|
MemoryRegion *ram_alias = g_new(MemoryRegion, 1);
|
2009-05-15 01:35:07 +04:00
|
|
|
qemu_irq pic[32];
|
2007-04-07 22:14:41 +04:00
|
|
|
qemu_irq *cpu_pic;
|
2009-05-15 01:35:07 +04:00
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2012-05-14 03:51:01 +04:00
|
|
|
if (!cpu_model) {
|
2007-03-08 06:04:12 +03:00
|
|
|
cpu_model = "arm926";
|
2012-05-14 03:51:01 +04:00
|
|
|
}
|
|
|
|
cpu = cpu_arm_init(cpu_model);
|
|
|
|
if (!cpu) {
|
2007-11-10 18:15:54 +03:00
|
|
|
fprintf(stderr, "Unable to find CPU definition\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-05-14 03:51:01 +04:00
|
|
|
|
2011-12-20 17:59:12 +04:00
|
|
|
memory_region_init_ram(ram, "integrator.ram", ram_size);
|
|
|
|
vmstate_register_ram_global(ram);
|
2005-11-26 13:38:39 +03:00
|
|
|
/* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */
|
2008-06-03 23:51:57 +04:00
|
|
|
/* ??? RAM should repeat to fill physical memory space. */
|
2005-11-26 13:38:39 +03:00
|
|
|
/* SDRAM at address zero*/
|
2011-07-25 16:03:19 +04:00
|
|
|
memory_region_add_subregion(address_space_mem, 0, ram);
|
2005-11-26 13:38:39 +03:00
|
|
|
/* And again at address 0x80000000 */
|
2011-07-25 16:03:19 +04:00
|
|
|
memory_region_init_alias(ram_alias, "ram.alias", ram, 0, ram_size);
|
|
|
|
memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2009-05-15 01:35:07 +04:00
|
|
|
dev = qdev_create(NULL, "integrator_core");
|
2009-07-15 15:43:31 +04:00
|
|
|
qdev_prop_set_uint32(dev, "memsz", ram_size >> 20);
|
2009-10-07 03:15:58 +04:00
|
|
|
qdev_init_nofail(dev);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_mmio_map((SysBusDevice *)dev, 0, 0x10000000);
|
|
|
|
|
2012-05-14 06:21:52 +04:00
|
|
|
cpu_pic = arm_pic_init_cpu(cpu);
|
2009-05-15 01:35:07 +04:00
|
|
|
dev = sysbus_create_varargs("integrator_pic", 0x14000000,
|
|
|
|
cpu_pic[ARM_PIC_CPU_IRQ],
|
|
|
|
cpu_pic[ARM_PIC_CPU_FIQ], NULL);
|
|
|
|
for (i = 0; i < 32; i++) {
|
2009-05-26 17:56:11 +04:00
|
|
|
pic[i] = qdev_get_gpio_in(dev, i);
|
2009-05-15 01:35:07 +04:00
|
|
|
}
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_create_simple("integrator_pic", 0xca000000, pic[26]);
|
|
|
|
sysbus_create_varargs("integrator_pit", 0x13000000,
|
|
|
|
pic[5], pic[6], pic[7], NULL);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_create_simple("pl031", 0x15000000, pic[8]);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_create_simple("pl011", 0x16000000, pic[1]);
|
|
|
|
sysbus_create_simple("pl011", 0x17000000, pic[2]);
|
2005-11-26 13:38:39 +03:00
|
|
|
icp_control_init(0xcb000000);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
|
|
|
|
sysbus_create_simple("pl050_mouse", 0x19000000, pic[4]);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_create_varargs("pl181", 0x1c000000, pic[23], pic[24], NULL);
|
2012-07-24 19:35:11 +04:00
|
|
|
if (nd_table[0].used)
|
2009-01-13 22:39:36 +03:00
|
|
|
smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
|
2009-05-15 01:35:07 +04:00
|
|
|
|
|
|
|
sysbus_create_simple("pl110", 0xc0000000, pic[22]);
|
2005-11-26 13:38:39 +03:00
|
|
|
|
2008-04-15 00:27:51 +04:00
|
|
|
integrator_binfo.ram_size = ram_size;
|
|
|
|
integrator_binfo.kernel_filename = kernel_filename;
|
|
|
|
integrator_binfo.kernel_cmdline = kernel_cmdline;
|
|
|
|
integrator_binfo.initrd_filename = initrd_filename;
|
2012-05-14 04:39:57 +04:00
|
|
|
arm_load_kernel(cpu, &integrator_binfo);
|
2005-11-26 13:38:39 +03:00
|
|
|
}
|
|
|
|
|
2009-05-21 03:38:09 +04:00
|
|
|
static QEMUMachine integratorcp_machine = {
|
2008-10-08 00:34:35 +04:00
|
|
|
.name = "integratorcp",
|
|
|
|
.desc = "ARM Integrator/CP (ARM926EJ-S)",
|
|
|
|
.init = integratorcp_init,
|
2009-05-22 05:41:01 +04:00
|
|
|
.is_default = 1,
|
2005-11-26 13:38:39 +03:00
|
|
|
};
|
2009-05-15 01:35:07 +04:00
|
|
|
|
2009-05-21 03:38:09 +04:00
|
|
|
static void integratorcp_machine_init(void)
|
|
|
|
{
|
|
|
|
qemu_register_machine(&integratorcp_machine);
|
|
|
|
}
|
|
|
|
|
|
|
|
machine_init(integratorcp_machine_init);
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
static Property core_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("memsz", integratorcm_state, memsz, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void core_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 23:12:29 +04:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = integratorcm_init;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->props = core_properties;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static TypeInfo core_info = {
|
|
|
|
.name = "integrator_core",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(integratorcm_state),
|
|
|
|
.class_init = core_class_init,
|
2012-01-24 23:12:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void icp_pic_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
sdc->init = icp_pic_init;
|
|
|
|
}
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static TypeInfo icp_pic_info = {
|
|
|
|
.name = "integrator_pic",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(icp_pic_state),
|
|
|
|
.class_init = icp_pic_class_init,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void integratorcp_register_types(void)
|
2009-05-15 01:35:07 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&icp_pic_info);
|
|
|
|
type_register_static(&core_info);
|
2009-05-15 01:35:07 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(integratorcp_register_types)
|