2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2006-09-23 21:40:58 +04:00
|
|
|
* Status and system control registers for ARM RealView/Versatile boards.
|
|
|
|
*
|
2007-11-11 03:04:49 +03:00
|
|
|
* Copyright (c) 2006-2007 CodeSourcery.
|
2006-09-23 21:40:58 +04:00
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
|
|
|
* This code is licenced under the GPL.
|
|
|
|
*/
|
|
|
|
|
2009-09-13 17:54:41 +04:00
|
|
|
#include "hw.h"
|
|
|
|
#include "qemu-timer.h"
|
2009-05-15 01:35:07 +04:00
|
|
|
#include "sysbus.h"
|
2007-11-18 04:44:38 +03:00
|
|
|
#include "primecell.h"
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "sysemu.h"
|
2006-09-23 21:40:58 +04:00
|
|
|
|
|
|
|
#define LOCK_VALUE 0xa05f
|
|
|
|
|
|
|
|
typedef struct {
|
2009-05-15 01:35:07 +04:00
|
|
|
SysBusDevice busdev;
|
2006-09-23 21:40:58 +04:00
|
|
|
uint32_t sys_id;
|
|
|
|
uint32_t leds;
|
|
|
|
uint16_t lockval;
|
|
|
|
uint32_t cfgdata1;
|
|
|
|
uint32_t cfgdata2;
|
|
|
|
uint32_t flags;
|
|
|
|
uint32_t nvflags;
|
|
|
|
uint32_t resetlevel;
|
2009-11-13 06:30:33 +03:00
|
|
|
uint32_t proc_id;
|
2011-02-21 23:57:50 +03:00
|
|
|
uint32_t sys_mci;
|
2006-09-23 21:40:58 +04:00
|
|
|
} arm_sysctl_state;
|
|
|
|
|
2010-12-23 20:19:53 +03:00
|
|
|
static const VMStateDescription vmstate_arm_sysctl = {
|
|
|
|
.name = "realview_sysctl",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(leds, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT16(lockval, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT32(cfgdata1, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT32(cfgdata2, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT32(flags, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT32(nvflags, arm_sysctl_state),
|
|
|
|
VMSTATE_UINT32(resetlevel, arm_sysctl_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-02-21 23:57:50 +03:00
|
|
|
/* The PB926 actually uses a different format for
|
|
|
|
* its SYS_ID register. Fortunately the bits which are
|
|
|
|
* board type on later boards are distinct.
|
|
|
|
*/
|
|
|
|
#define BOARD_ID_PB926 0x100
|
|
|
|
#define BOARD_ID_EB 0x140
|
|
|
|
#define BOARD_ID_PBA8 0x178
|
|
|
|
#define BOARD_ID_PBX 0x182
|
|
|
|
|
|
|
|
static int board_id(arm_sysctl_state *s)
|
|
|
|
{
|
|
|
|
/* Extract the board ID field from the SYS_ID register value */
|
|
|
|
return (s->sys_id >> 16) & 0xfff;
|
|
|
|
}
|
|
|
|
|
2009-11-11 22:59:29 +03:00
|
|
|
static void arm_sysctl_reset(DeviceState *d)
|
|
|
|
{
|
|
|
|
arm_sysctl_state *s = FROM_SYSBUS(arm_sysctl_state, sysbus_from_qdev(d));
|
|
|
|
|
|
|
|
s->leds = 0;
|
|
|
|
s->lockval = 0;
|
|
|
|
s->cfgdata1 = 0;
|
|
|
|
s->cfgdata2 = 0;
|
|
|
|
s->flags = 0;
|
|
|
|
s->resetlevel = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static uint32_t arm_sysctl_read(void *opaque, target_phys_addr_t offset)
|
2006-09-23 21:40:58 +04:00
|
|
|
{
|
|
|
|
arm_sysctl_state *s = (arm_sysctl_state *)opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00: /* ID */
|
|
|
|
return s->sys_id;
|
|
|
|
case 0x04: /* SW */
|
|
|
|
/* General purpose hardware switches.
|
|
|
|
We don't have a useful way of exposing these to the user. */
|
|
|
|
return 0;
|
|
|
|
case 0x08: /* LED */
|
|
|
|
return s->leds;
|
|
|
|
case 0x20: /* LOCK */
|
|
|
|
return s->lockval;
|
|
|
|
case 0x0c: /* OSC0 */
|
|
|
|
case 0x10: /* OSC1 */
|
|
|
|
case 0x14: /* OSC2 */
|
|
|
|
case 0x18: /* OSC3 */
|
|
|
|
case 0x1c: /* OSC4 */
|
|
|
|
case 0x24: /* 100HZ */
|
|
|
|
/* ??? Implement these. */
|
|
|
|
return 0;
|
|
|
|
case 0x28: /* CFGDATA1 */
|
|
|
|
return s->cfgdata1;
|
|
|
|
case 0x2c: /* CFGDATA2 */
|
|
|
|
return s->cfgdata2;
|
|
|
|
case 0x30: /* FLAGS */
|
|
|
|
return s->flags;
|
|
|
|
case 0x38: /* NVFLAGS */
|
|
|
|
return s->nvflags;
|
|
|
|
case 0x40: /* RESETCTL */
|
|
|
|
return s->resetlevel;
|
|
|
|
case 0x44: /* PCICTL */
|
|
|
|
return 1;
|
|
|
|
case 0x48: /* MCI */
|
2011-02-21 23:57:50 +03:00
|
|
|
return s->sys_mci;
|
2006-09-23 21:40:58 +04:00
|
|
|
case 0x4c: /* FLASH */
|
|
|
|
return 0;
|
|
|
|
case 0x50: /* CLCD */
|
|
|
|
return 0x1000;
|
|
|
|
case 0x54: /* CLCDSER */
|
|
|
|
return 0;
|
|
|
|
case 0x58: /* BOOTCS */
|
|
|
|
return 0;
|
|
|
|
case 0x5c: /* 24MHz */
|
2009-09-13 17:54:41 +04:00
|
|
|
return muldiv64(qemu_get_clock(vm_clock), 24000000, get_ticks_per_sec());
|
2006-09-23 21:40:58 +04:00
|
|
|
case 0x60: /* MISC */
|
|
|
|
return 0;
|
|
|
|
case 0x84: /* PROCID0 */
|
2009-11-13 06:30:33 +03:00
|
|
|
return s->proc_id;
|
2006-09-23 21:40:58 +04:00
|
|
|
case 0x88: /* PROCID1 */
|
|
|
|
return 0xff000000;
|
|
|
|
case 0x64: /* DMAPSR0 */
|
|
|
|
case 0x68: /* DMAPSR1 */
|
|
|
|
case 0x6c: /* DMAPSR2 */
|
|
|
|
case 0x70: /* IOSEL */
|
|
|
|
case 0x74: /* PLDCTL */
|
|
|
|
case 0x80: /* BUSID */
|
|
|
|
case 0x8c: /* OSCRESET0 */
|
|
|
|
case 0x90: /* OSCRESET1 */
|
|
|
|
case 0x94: /* OSCRESET2 */
|
|
|
|
case 0x98: /* OSCRESET3 */
|
|
|
|
case 0x9c: /* OSCRESET4 */
|
|
|
|
case 0xc0: /* SYS_TEST_OSC0 */
|
|
|
|
case 0xc4: /* SYS_TEST_OSC1 */
|
|
|
|
case 0xc8: /* SYS_TEST_OSC2 */
|
|
|
|
case 0xcc: /* SYS_TEST_OSC3 */
|
|
|
|
case 0xd0: /* SYS_TEST_OSC4 */
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
printf ("arm_sysctl_read: Bad register offset 0x%x\n", (int)offset);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void arm_sysctl_write(void *opaque, target_phys_addr_t offset,
|
2006-09-23 21:40:58 +04:00
|
|
|
uint32_t val)
|
|
|
|
{
|
|
|
|
arm_sysctl_state *s = (arm_sysctl_state *)opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case 0x08: /* LED */
|
|
|
|
s->leds = val;
|
|
|
|
case 0x0c: /* OSC0 */
|
|
|
|
case 0x10: /* OSC1 */
|
|
|
|
case 0x14: /* OSC2 */
|
|
|
|
case 0x18: /* OSC3 */
|
|
|
|
case 0x1c: /* OSC4 */
|
|
|
|
/* ??? */
|
|
|
|
break;
|
|
|
|
case 0x20: /* LOCK */
|
|
|
|
if (val == LOCK_VALUE)
|
|
|
|
s->lockval = val;
|
|
|
|
else
|
|
|
|
s->lockval = val & 0x7fff;
|
|
|
|
break;
|
|
|
|
case 0x28: /* CFGDATA1 */
|
|
|
|
/* ??? Need to implement this. */
|
|
|
|
s->cfgdata1 = val;
|
|
|
|
break;
|
|
|
|
case 0x2c: /* CFGDATA2 */
|
|
|
|
/* ??? Need to implement this. */
|
|
|
|
s->cfgdata2 = val;
|
|
|
|
break;
|
|
|
|
case 0x30: /* FLAGSSET */
|
|
|
|
s->flags |= val;
|
|
|
|
break;
|
|
|
|
case 0x34: /* FLAGSCLR */
|
|
|
|
s->flags &= ~val;
|
|
|
|
break;
|
|
|
|
case 0x38: /* NVFLAGSSET */
|
|
|
|
s->nvflags |= val;
|
|
|
|
break;
|
|
|
|
case 0x3c: /* NVFLAGSCLR */
|
|
|
|
s->nvflags &= ~val;
|
|
|
|
break;
|
|
|
|
case 0x40: /* RESETCTL */
|
|
|
|
if (s->lockval == LOCK_VALUE) {
|
|
|
|
s->resetlevel = val;
|
|
|
|
if (val & 0x100)
|
2007-03-11 16:03:18 +03:00
|
|
|
qemu_system_reset_request ();
|
2006-09-23 21:40:58 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x44: /* PCICTL */
|
|
|
|
/* nothing to do. */
|
|
|
|
break;
|
|
|
|
case 0x4c: /* FLASH */
|
|
|
|
case 0x50: /* CLCD */
|
|
|
|
case 0x54: /* CLCDSER */
|
|
|
|
case 0x64: /* DMAPSR0 */
|
|
|
|
case 0x68: /* DMAPSR1 */
|
|
|
|
case 0x6c: /* DMAPSR2 */
|
|
|
|
case 0x70: /* IOSEL */
|
|
|
|
case 0x74: /* PLDCTL */
|
|
|
|
case 0x80: /* BUSID */
|
|
|
|
case 0x84: /* PROCID0 */
|
|
|
|
case 0x88: /* PROCID1 */
|
|
|
|
case 0x8c: /* OSCRESET0 */
|
|
|
|
case 0x90: /* OSCRESET1 */
|
|
|
|
case 0x94: /* OSCRESET2 */
|
|
|
|
case 0x98: /* OSCRESET3 */
|
|
|
|
case 0x9c: /* OSCRESET4 */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("arm_sysctl_write: Bad register offset 0x%x\n", (int)offset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUReadMemoryFunc * const arm_sysctl_readfn[] = {
|
2006-09-23 21:40:58 +04:00
|
|
|
arm_sysctl_read,
|
|
|
|
arm_sysctl_read,
|
|
|
|
arm_sysctl_read
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUWriteMemoryFunc * const arm_sysctl_writefn[] = {
|
2006-09-23 21:40:58 +04:00
|
|
|
arm_sysctl_write,
|
|
|
|
arm_sysctl_write,
|
|
|
|
arm_sysctl_write
|
|
|
|
};
|
|
|
|
|
2011-02-21 23:57:50 +03:00
|
|
|
static void arm_sysctl_gpio_set(void *opaque, int line, int level)
|
|
|
|
{
|
|
|
|
arm_sysctl_state *s = (arm_sysctl_state *)opaque;
|
|
|
|
switch (line) {
|
|
|
|
case ARM_SYSCTL_GPIO_MMC_WPROT:
|
|
|
|
{
|
|
|
|
/* For PB926 and EB write-protect is bit 2 of SYS_MCI;
|
|
|
|
* for all later boards it is bit 1.
|
|
|
|
*/
|
|
|
|
int bit = 2;
|
|
|
|
if ((board_id(s) == BOARD_ID_PB926) || (board_id(s) == BOARD_ID_EB)) {
|
|
|
|
bit = 4;
|
|
|
|
}
|
|
|
|
s->sys_mci &= ~bit;
|
|
|
|
if (level) {
|
|
|
|
s->sys_mci |= bit;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARM_SYSCTL_GPIO_MMC_CARDIN:
|
|
|
|
s->sys_mci &= ~1;
|
|
|
|
if (level) {
|
|
|
|
s->sys_mci |= 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-14 12:36:05 +04:00
|
|
|
static int arm_sysctl_init1(SysBusDevice *dev)
|
2006-09-23 21:40:58 +04:00
|
|
|
{
|
2009-05-15 01:35:07 +04:00
|
|
|
arm_sysctl_state *s = FROM_SYSBUS(arm_sysctl_state, dev);
|
2006-09-23 21:40:58 +04:00
|
|
|
int iomemtype;
|
|
|
|
|
2009-06-14 12:38:51 +04:00
|
|
|
iomemtype = cpu_register_io_memory(arm_sysctl_readfn,
|
2010-12-08 14:05:37 +03:00
|
|
|
arm_sysctl_writefn, s,
|
|
|
|
DEVICE_NATIVE_ENDIAN);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_init_mmio(dev, 0x1000, iomemtype);
|
2011-02-21 23:57:50 +03:00
|
|
|
qdev_init_gpio_in(&s->busdev.qdev, arm_sysctl_gpio_set, 2);
|
2006-09-23 21:40:58 +04:00
|
|
|
/* ??? Save/restore. */
|
2009-08-14 12:36:05 +04:00
|
|
|
return 0;
|
2006-09-23 21:40:58 +04:00
|
|
|
}
|
2009-05-15 01:35:07 +04:00
|
|
|
|
|
|
|
/* Legacy helper function. */
|
2009-11-13 06:30:33 +03:00
|
|
|
void arm_sysctl_init(uint32_t base, uint32_t sys_id, uint32_t proc_id)
|
2009-05-15 01:35:07 +04:00
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
|
|
|
|
dev = qdev_create(NULL, "realview_sysctl");
|
2009-07-15 15:43:31 +04:00
|
|
|
qdev_prop_set_uint32(dev, "sys_id", sys_id);
|
2009-10-07 03:15:58 +04:00
|
|
|
qdev_init_nofail(dev);
|
2009-11-13 06:30:33 +03:00
|
|
|
qdev_prop_set_uint32(dev, "proc_id", proc_id);
|
2009-05-15 01:35:07 +04:00
|
|
|
sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
|
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
static SysBusDeviceInfo arm_sysctl_info = {
|
|
|
|
.init = arm_sysctl_init1,
|
|
|
|
.qdev.name = "realview_sysctl",
|
|
|
|
.qdev.size = sizeof(arm_sysctl_state),
|
2010-12-23 20:19:53 +03:00
|
|
|
.qdev.vmsd = &vmstate_arm_sysctl,
|
2009-11-11 22:59:29 +03:00
|
|
|
.qdev.reset = arm_sysctl_reset,
|
2009-07-15 15:43:31 +04:00
|
|
|
.qdev.props = (Property[]) {
|
2009-08-03 19:35:20 +04:00
|
|
|
DEFINE_PROP_UINT32("sys_id", arm_sysctl_state, sys_id, 0),
|
2009-11-13 06:30:33 +03:00
|
|
|
DEFINE_PROP_UINT32("proc_id", arm_sysctl_state, proc_id, 0),
|
2009-08-03 19:35:20 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-15 01:35:07 +04:00
|
|
|
static void arm_sysctl_register_devices(void)
|
|
|
|
{
|
2009-07-15 15:43:31 +04:00
|
|
|
sysbus_register_withprop(&arm_sysctl_info);
|
2009-05-15 01:35:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
device_init(arm_sysctl_register_devices)
|