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 licensed under the GPL.
11 #include "qemu/timer.h"
13 #include "primecell.h"
14 #include "sysemu/sysemu.h"
16 #define LOCK_VALUE 0xa05f
21 qemu_irq pl110_mux_ctrl
;
39 static const VMStateDescription vmstate_arm_sysctl
= {
40 .name
= "realview_sysctl",
42 .minimum_version_id
= 1,
43 .fields
= (VMStateField
[]) {
44 VMSTATE_UINT32(leds
, arm_sysctl_state
),
45 VMSTATE_UINT16(lockval
, arm_sysctl_state
),
46 VMSTATE_UINT32(cfgdata1
, arm_sysctl_state
),
47 VMSTATE_UINT32(cfgdata2
, arm_sysctl_state
),
48 VMSTATE_UINT32(flags
, arm_sysctl_state
),
49 VMSTATE_UINT32(nvflags
, arm_sysctl_state
),
50 VMSTATE_UINT32(resetlevel
, arm_sysctl_state
),
51 VMSTATE_UINT32_V(sys_mci
, arm_sysctl_state
, 2),
52 VMSTATE_UINT32_V(sys_cfgdata
, arm_sysctl_state
, 2),
53 VMSTATE_UINT32_V(sys_cfgctrl
, arm_sysctl_state
, 2),
54 VMSTATE_UINT32_V(sys_cfgstat
, arm_sysctl_state
, 2),
55 VMSTATE_UINT32_V(sys_clcd
, arm_sysctl_state
, 3),
60 /* The PB926 actually uses a different format for
61 * its SYS_ID register. Fortunately the bits which are
62 * board type on later boards are distinct.
64 #define BOARD_ID_PB926 0x100
65 #define BOARD_ID_EB 0x140
66 #define BOARD_ID_PBA8 0x178
67 #define BOARD_ID_PBX 0x182
68 #define BOARD_ID_VEXPRESS 0x190
70 static int board_id(arm_sysctl_state
*s
)
72 /* Extract the board ID field from the SYS_ID register value */
73 return (s
->sys_id
>> 16) & 0xfff;
76 static void arm_sysctl_reset(DeviceState
*d
)
78 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, SYS_BUS_DEVICE(d
));
86 if (board_id(s
) == BOARD_ID_VEXPRESS
) {
87 /* On VExpress this register will RAZ/WI */
90 /* All others: CLCDID 0x1f, indicating VGA */
95 static uint64_t arm_sysctl_read(void *opaque
, hwaddr offset
,
98 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
104 /* General purpose hardware switches.
105 We don't have a useful way of exposing these to the user. */
109 case 0x20: /* LOCK */
111 case 0x0c: /* OSC0 */
112 case 0x10: /* OSC1 */
113 case 0x14: /* OSC2 */
114 case 0x18: /* OSC3 */
115 case 0x1c: /* OSC4 */
116 case 0x24: /* 100HZ */
117 /* ??? Implement these. */
119 case 0x28: /* CFGDATA1 */
121 case 0x2c: /* CFGDATA2 */
123 case 0x30: /* FLAGS */
125 case 0x38: /* NVFLAGS */
127 case 0x40: /* RESETCTL */
128 if (board_id(s
) == BOARD_ID_VEXPRESS
) {
129 /* reserved: RAZ/WI */
132 return s
->resetlevel
;
133 case 0x44: /* PCICTL */
137 case 0x4c: /* FLASH */
139 case 0x50: /* CLCD */
141 case 0x54: /* CLCDSER */
143 case 0x58: /* BOOTCS */
145 case 0x5c: /* 24MHz */
146 return muldiv64(qemu_get_clock_ns(vm_clock
), 24000000, get_ticks_per_sec());
147 case 0x60: /* MISC */
149 case 0x84: /* PROCID0 */
151 case 0x88: /* PROCID1 */
153 case 0x64: /* DMAPSR0 */
154 case 0x68: /* DMAPSR1 */
155 case 0x6c: /* DMAPSR2 */
156 case 0x70: /* IOSEL */
157 case 0x74: /* PLDCTL */
158 case 0x80: /* BUSID */
159 case 0x8c: /* OSCRESET0 */
160 case 0x90: /* OSCRESET1 */
161 case 0x94: /* OSCRESET2 */
162 case 0x98: /* OSCRESET3 */
163 case 0x9c: /* OSCRESET4 */
164 case 0xc0: /* SYS_TEST_OSC0 */
165 case 0xc4: /* SYS_TEST_OSC1 */
166 case 0xc8: /* SYS_TEST_OSC2 */
167 case 0xcc: /* SYS_TEST_OSC3 */
168 case 0xd0: /* SYS_TEST_OSC4 */
170 case 0xa0: /* SYS_CFGDATA */
171 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
174 return s
->sys_cfgdata
;
175 case 0xa4: /* SYS_CFGCTRL */
176 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
179 return s
->sys_cfgctrl
;
180 case 0xa8: /* SYS_CFGSTAT */
181 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
184 return s
->sys_cfgstat
;
187 qemu_log_mask(LOG_GUEST_ERROR
,
188 "arm_sysctl_read: Bad register offset 0x%x\n",
194 static void arm_sysctl_write(void *opaque
, hwaddr offset
,
195 uint64_t val
, unsigned size
)
197 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
203 case 0x0c: /* OSC0 */
204 case 0x10: /* OSC1 */
205 case 0x14: /* OSC2 */
206 case 0x18: /* OSC3 */
207 case 0x1c: /* OSC4 */
210 case 0x20: /* LOCK */
211 if (val
== LOCK_VALUE
)
214 s
->lockval
= val
& 0x7fff;
216 case 0x28: /* CFGDATA1 */
217 /* ??? Need to implement this. */
220 case 0x2c: /* CFGDATA2 */
221 /* ??? Need to implement this. */
224 case 0x30: /* FLAGSSET */
227 case 0x34: /* FLAGSCLR */
230 case 0x38: /* NVFLAGSSET */
233 case 0x3c: /* NVFLAGSCLR */
236 case 0x40: /* RESETCTL */
237 switch (board_id(s
)) {
239 if (s
->lockval
== LOCK_VALUE
) {
242 qemu_system_reset_request();
248 if (s
->lockval
== LOCK_VALUE
) {
251 qemu_system_reset_request();
255 case BOARD_ID_VEXPRESS
:
258 /* reserved: RAZ/WI */
262 case 0x44: /* PCICTL */
265 case 0x4c: /* FLASH */
267 case 0x50: /* CLCD */
268 switch (board_id(s
)) {
270 /* On 926 bits 13:8 are R/O, bits 1:0 control
271 * the mux that defines how to interpret the PL110
272 * graphics format, and other bits are r/w but we
273 * don't implement them to do anything.
275 s
->sys_clcd
&= 0x3f00;
276 s
->sys_clcd
|= val
& ~0x3f00;
277 qemu_set_irq(s
->pl110_mux_ctrl
, val
& 3);
280 /* The EB is the same except that there is no mux since
281 * the EB has a PL111.
283 s
->sys_clcd
&= 0x3f00;
284 s
->sys_clcd
|= val
& ~0x3f00;
288 /* On PBA8 and PBX bit 7 is r/w and all other bits
289 * are either r/o or RAZ/WI.
291 s
->sys_clcd
&= (1 << 7);
292 s
->sys_clcd
|= val
& ~(1 << 7);
294 case BOARD_ID_VEXPRESS
:
296 /* On VExpress this register is unimplemented and will RAZ/WI */
300 case 0x54: /* CLCDSER */
301 case 0x64: /* DMAPSR0 */
302 case 0x68: /* DMAPSR1 */
303 case 0x6c: /* DMAPSR2 */
304 case 0x70: /* IOSEL */
305 case 0x74: /* PLDCTL */
306 case 0x80: /* BUSID */
307 case 0x84: /* PROCID0 */
308 case 0x88: /* PROCID1 */
309 case 0x8c: /* OSCRESET0 */
310 case 0x90: /* OSCRESET1 */
311 case 0x94: /* OSCRESET2 */
312 case 0x98: /* OSCRESET3 */
313 case 0x9c: /* OSCRESET4 */
315 case 0xa0: /* SYS_CFGDATA */
316 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
319 s
->sys_cfgdata
= val
;
321 case 0xa4: /* SYS_CFGCTRL */
322 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
325 s
->sys_cfgctrl
= val
& ~(3 << 18);
326 s
->sys_cfgstat
= 1; /* complete */
327 switch (s
->sys_cfgctrl
) {
328 case 0xc0800000: /* SYS_CFG_SHUTDOWN to motherboard */
329 qemu_system_shutdown_request();
331 case 0xc0900000: /* SYS_CFG_REBOOT to motherboard */
332 qemu_system_reset_request();
335 s
->sys_cfgstat
|= 2; /* error */
338 case 0xa8: /* SYS_CFGSTAT */
339 if (board_id(s
) != BOARD_ID_VEXPRESS
) {
342 s
->sys_cfgstat
= val
& 3;
346 qemu_log_mask(LOG_GUEST_ERROR
,
347 "arm_sysctl_write: Bad register offset 0x%x\n",
353 static const MemoryRegionOps arm_sysctl_ops
= {
354 .read
= arm_sysctl_read
,
355 .write
= arm_sysctl_write
,
356 .endianness
= DEVICE_NATIVE_ENDIAN
,
359 static void arm_sysctl_gpio_set(void *opaque
, int line
, int level
)
361 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
363 case ARM_SYSCTL_GPIO_MMC_WPROT
:
365 /* For PB926 and EB write-protect is bit 2 of SYS_MCI;
366 * for all later boards it is bit 1.
369 if ((board_id(s
) == BOARD_ID_PB926
) || (board_id(s
) == BOARD_ID_EB
)) {
378 case ARM_SYSCTL_GPIO_MMC_CARDIN
:
387 static int arm_sysctl_init(SysBusDevice
*dev
)
389 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, dev
);
391 memory_region_init_io(&s
->iomem
, &arm_sysctl_ops
, s
, "arm-sysctl", 0x1000);
392 sysbus_init_mmio(dev
, &s
->iomem
);
393 qdev_init_gpio_in(&s
->busdev
.qdev
, arm_sysctl_gpio_set
, 2);
394 qdev_init_gpio_out(&s
->busdev
.qdev
, &s
->pl110_mux_ctrl
, 1);
398 static Property arm_sysctl_properties
[] = {
399 DEFINE_PROP_UINT32("sys_id", arm_sysctl_state
, sys_id
, 0),
400 DEFINE_PROP_UINT32("proc_id", arm_sysctl_state
, proc_id
, 0),
401 DEFINE_PROP_END_OF_LIST(),
404 static void arm_sysctl_class_init(ObjectClass
*klass
, void *data
)
406 DeviceClass
*dc
= DEVICE_CLASS(klass
);
407 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
409 k
->init
= arm_sysctl_init
;
410 dc
->reset
= arm_sysctl_reset
;
411 dc
->vmsd
= &vmstate_arm_sysctl
;
412 dc
->props
= arm_sysctl_properties
;
415 static const TypeInfo arm_sysctl_info
= {
416 .name
= "realview_sysctl",
417 .parent
= TYPE_SYS_BUS_DEVICE
,
418 .instance_size
= sizeof(arm_sysctl_state
),
419 .class_init
= arm_sysctl_class_init
,
422 static void arm_sysctl_register_types(void)
424 type_register_static(&arm_sysctl_info
);
427 type_init(arm_sysctl_register_types
)