2 * Status and system control registers for ARM RealView/Versatile boards.
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
11 #include "qemu-timer.h"
13 #include "primecell.h"
16 #define LOCK_VALUE 0xa05f
35 static const VMStateDescription vmstate_arm_sysctl
= {
36 .name
= "realview_sysctl",
38 .minimum_version_id
= 1,
39 .fields
= (VMStateField
[]) {
40 VMSTATE_UINT32(leds
, arm_sysctl_state
),
41 VMSTATE_UINT16(lockval
, arm_sysctl_state
),
42 VMSTATE_UINT32(cfgdata1
, arm_sysctl_state
),
43 VMSTATE_UINT32(cfgdata2
, arm_sysctl_state
),
44 VMSTATE_UINT32(flags
, arm_sysctl_state
),
45 VMSTATE_UINT32(nvflags
, arm_sysctl_state
),
46 VMSTATE_UINT32(resetlevel
, arm_sysctl_state
),
47 VMSTATE_UINT32_V(sys_mci
, arm_sysctl_state
, 2),
48 VMSTATE_UINT32_V(sys_cfgdata
, arm_sysctl_state
, 2),
49 VMSTATE_UINT32_V(sys_cfgctrl
, arm_sysctl_state
, 2),
50 VMSTATE_UINT32_V(sys_cfgstat
, arm_sysctl_state
, 2),
55 /* The PB926 actually uses a different format for
56 * its SYS_ID register. Fortunately the bits which are
57 * board type on later boards are distinct.
59 #define BOARD_ID_PB926 0x100
60 #define BOARD_ID_EB 0x140
61 #define BOARD_ID_PBA8 0x178
62 #define BOARD_ID_PBX 0x182
63 #define BOARD_ID_VEXPRESS 0x190
65 static int board_id(arm_sysctl_state
*s
)
67 /* Extract the board ID field from the SYS_ID register value */
68 return (s
->sys_id
>> 16) & 0xfff;
71 static void arm_sysctl_reset(DeviceState
*d
)
73 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, sysbus_from_qdev(d
));
83 static uint32_t arm_sysctl_read(void *opaque
, target_phys_addr_t offset
)
85 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
91 /* General purpose hardware switches.
92 We don't have a useful way of exposing these to the user. */
100 case 0x14: /* OSC2 */
101 case 0x18: /* OSC3 */
102 case 0x1c: /* OSC4 */
103 case 0x24: /* 100HZ */
104 /* ??? Implement these. */
106 case 0x28: /* CFGDATA1 */
108 case 0x2c: /* CFGDATA2 */
110 case 0x30: /* FLAGS */
112 case 0x38: /* NVFLAGS */
114 case 0x40: /* RESETCTL */
115 if (board_id(s
) == BOARD_ID_VEXPRESS
) {
116 /* reserved: RAZ/WI */
119 return s
->resetlevel
;
120 case 0x44: /* PCICTL */
124 case 0x4c: /* FLASH */
126 case 0x50: /* CLCD */
128 case 0x54: /* CLCDSER */
130 case 0x58: /* BOOTCS */
132 case 0x5c: /* 24MHz */
133 return muldiv64(qemu_get_clock_ns(vm_clock
), 24000000, get_ticks_per_sec());
134 case 0x60: /* MISC */
136 case 0x84: /* PROCID0 */
138 case 0x88: /* PROCID1 */
140 case 0x64: /* DMAPSR0 */
141 case 0x68: /* DMAPSR1 */
142 case 0x6c: /* DMAPSR2 */
143 case 0x70: /* IOSEL */
144 case 0x74: /* PLDCTL */
145 case 0x80: /* BUSID */
146 case 0x8c: /* OSCRESET0 */
147 case 0x90: /* OSCRESET1 */
148 case 0x94: /* OSCRESET2 */
149 case 0x98: /* OSCRESET3 */
150 case 0x9c: /* OSCRESET4 */
151 case 0xc0: /* SYS_TEST_OSC0 */
152 case 0xc4: /* SYS_TEST_OSC1 */
153 case 0xc8: /* SYS_TEST_OSC2 */
154 case 0xcc: /* SYS_TEST_OSC3 */
155 case 0xd0: /* SYS_TEST_OSC4 */
157 case 0xa0: /* SYS_CFGDATA */
158 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
161 return s
->sys_cfgdata
;
162 case 0xa4: /* SYS_CFGCTRL */
163 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
166 return s
->sys_cfgctrl
;
167 case 0xa8: /* SYS_CFGSTAT */
168 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
171 return s
->sys_cfgstat
;
174 printf ("arm_sysctl_read: Bad register offset 0x%x\n", (int)offset
);
179 static void arm_sysctl_write(void *opaque
, target_phys_addr_t offset
,
182 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
187 case 0x0c: /* OSC0 */
188 case 0x10: /* OSC1 */
189 case 0x14: /* OSC2 */
190 case 0x18: /* OSC3 */
191 case 0x1c: /* OSC4 */
194 case 0x20: /* LOCK */
195 if (val
== LOCK_VALUE
)
198 s
->lockval
= val
& 0x7fff;
200 case 0x28: /* CFGDATA1 */
201 /* ??? Need to implement this. */
204 case 0x2c: /* CFGDATA2 */
205 /* ??? Need to implement this. */
208 case 0x30: /* FLAGSSET */
211 case 0x34: /* FLAGSCLR */
214 case 0x38: /* NVFLAGSSET */
217 case 0x3c: /* NVFLAGSCLR */
220 case 0x40: /* RESETCTL */
221 if (board_id(s
) == BOARD_ID_VEXPRESS
) {
222 /* reserved: RAZ/WI */
225 if (s
->lockval
== LOCK_VALUE
) {
228 qemu_system_reset_request ();
231 case 0x44: /* PCICTL */
234 case 0x4c: /* FLASH */
235 case 0x50: /* CLCD */
236 case 0x54: /* CLCDSER */
237 case 0x64: /* DMAPSR0 */
238 case 0x68: /* DMAPSR1 */
239 case 0x6c: /* DMAPSR2 */
240 case 0x70: /* IOSEL */
241 case 0x74: /* PLDCTL */
242 case 0x80: /* BUSID */
243 case 0x84: /* PROCID0 */
244 case 0x88: /* PROCID1 */
245 case 0x8c: /* OSCRESET0 */
246 case 0x90: /* OSCRESET1 */
247 case 0x94: /* OSCRESET2 */
248 case 0x98: /* OSCRESET3 */
249 case 0x9c: /* OSCRESET4 */
251 case 0xa0: /* SYS_CFGDATA */
252 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
255 s
->sys_cfgdata
= val
;
257 case 0xa4: /* SYS_CFGCTRL */
258 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
261 s
->sys_cfgctrl
= val
& ~(3 << 18);
262 s
->sys_cfgstat
= 1; /* complete */
263 switch (s
->sys_cfgctrl
) {
264 case 0xc0800000: /* SYS_CFG_SHUTDOWN to motherboard */
265 qemu_system_shutdown_request();
267 case 0xc0900000: /* SYS_CFG_REBOOT to motherboard */
268 qemu_system_reset_request();
271 s
->sys_cfgstat
|= 2; /* error */
274 case 0xa8: /* SYS_CFGSTAT */
275 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
278 s
->sys_cfgstat
= val
& 3;
282 printf ("arm_sysctl_write: Bad register offset 0x%x\n", (int)offset
);
287 static CPUReadMemoryFunc
* const arm_sysctl_readfn
[] = {
293 static CPUWriteMemoryFunc
* const arm_sysctl_writefn
[] = {
299 static void arm_sysctl_gpio_set(void *opaque
, int line
, int level
)
301 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
303 case ARM_SYSCTL_GPIO_MMC_WPROT
:
305 /* For PB926 and EB write-protect is bit 2 of SYS_MCI;
306 * for all later boards it is bit 1.
309 if ((board_id(s
) == BOARD_ID_PB926
) || (board_id(s
) == BOARD_ID_EB
)) {
318 case ARM_SYSCTL_GPIO_MMC_CARDIN
:
327 static int arm_sysctl_init1(SysBusDevice
*dev
)
329 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, dev
);
332 iomemtype
= cpu_register_io_memory(arm_sysctl_readfn
,
333 arm_sysctl_writefn
, s
,
334 DEVICE_NATIVE_ENDIAN
);
335 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
336 qdev_init_gpio_in(&s
->busdev
.qdev
, arm_sysctl_gpio_set
, 2);
337 /* ??? Save/restore. */
341 /* Legacy helper function. */
342 void arm_sysctl_init(uint32_t base
, uint32_t sys_id
, uint32_t proc_id
)
346 dev
= qdev_create(NULL
, "realview_sysctl");
347 qdev_prop_set_uint32(dev
, "sys_id", sys_id
);
348 qdev_init_nofail(dev
);
349 qdev_prop_set_uint32(dev
, "proc_id", proc_id
);
350 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, base
);
353 static SysBusDeviceInfo arm_sysctl_info
= {
354 .init
= arm_sysctl_init1
,
355 .qdev
.name
= "realview_sysctl",
356 .qdev
.size
= sizeof(arm_sysctl_state
),
357 .qdev
.vmsd
= &vmstate_arm_sysctl
,
358 .qdev
.reset
= arm_sysctl_reset
,
359 .qdev
.props
= (Property
[]) {
360 DEFINE_PROP_UINT32("sys_id", arm_sysctl_state
, sys_id
, 0),
361 DEFINE_PROP_UINT32("proc_id", arm_sysctl_state
, proc_id
, 0),
362 DEFINE_PROP_END_OF_LIST(),
366 static void arm_sysctl_register_devices(void)
368 sysbus_register_withprop(&arm_sysctl_info
);
371 device_init(arm_sysctl_register_devices
)