2 * QEMU Sparc SLAVIO aux io port emulation
4 * Copyright (c) 2005 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 * This is the auxio port, chip control and system control part of
31 * chip STP2001 (Slave I/O), also produced as NCR89C105. See
32 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
34 * This also includes the PMC CPU idle controller.
37 typedef struct MiscState
{
49 typedef struct APCState
{
55 #define SYSCTRL_SIZE 4
59 #define AUX2_PWROFF 0x01
60 #define AUX2_PWRINTCLR 0x02
61 #define AUX2_PWRFAIL 0x20
63 #define CFG_PWRINTEN 0x08
65 #define SYS_RESET 0x01
66 #define SYS_RESETSTAT 0x02
68 static void slavio_misc_update_irq(void *opaque
)
70 MiscState
*s
= opaque
;
72 if ((s
->aux2
& AUX2_PWRFAIL
) && (s
->config
& CFG_PWRINTEN
)) {
73 trace_slavio_misc_update_irq_raise();
74 qemu_irq_raise(s
->irq
);
76 trace_slavio_misc_update_irq_lower();
77 qemu_irq_lower(s
->irq
);
81 static void slavio_misc_reset(DeviceState
*d
)
83 MiscState
*s
= container_of(d
, MiscState
, busdev
.qdev
);
85 // Diagnostic and system control registers not cleared in reset
86 s
->config
= s
->aux1
= s
->aux2
= s
->mctrl
= 0;
89 static void slavio_set_power_fail(void *opaque
, int irq
, int power_failing
)
91 MiscState
*s
= opaque
;
93 trace_slavio_set_power_fail(power_failing
, s
->config
);
94 if (power_failing
&& (s
->config
& CFG_PWRINTEN
)) {
95 s
->aux2
|= AUX2_PWRFAIL
;
97 s
->aux2
&= ~AUX2_PWRFAIL
;
99 slavio_misc_update_irq(s
);
102 static void slavio_cfg_mem_writeb(void *opaque
, target_phys_addr_t addr
,
105 MiscState
*s
= opaque
;
107 trace_slavio_cfg_mem_writeb(val
& 0xff);
108 s
->config
= val
& 0xff;
109 slavio_misc_update_irq(s
);
112 static uint32_t slavio_cfg_mem_readb(void *opaque
, target_phys_addr_t addr
)
114 MiscState
*s
= opaque
;
118 trace_slavio_cfg_mem_readb(ret
);
122 static CPUReadMemoryFunc
* const slavio_cfg_mem_read
[3] = {
123 slavio_cfg_mem_readb
,
128 static CPUWriteMemoryFunc
* const slavio_cfg_mem_write
[3] = {
129 slavio_cfg_mem_writeb
,
134 static void slavio_diag_mem_writeb(void *opaque
, target_phys_addr_t addr
,
137 MiscState
*s
= opaque
;
139 trace_slavio_diag_mem_writeb(val
& 0xff);
140 s
->diag
= val
& 0xff;
143 static uint32_t slavio_diag_mem_readb(void *opaque
, target_phys_addr_t addr
)
145 MiscState
*s
= opaque
;
149 trace_slavio_diag_mem_readb(ret
);
153 static CPUReadMemoryFunc
* const slavio_diag_mem_read
[3] = {
154 slavio_diag_mem_readb
,
159 static CPUWriteMemoryFunc
* const slavio_diag_mem_write
[3] = {
160 slavio_diag_mem_writeb
,
165 static void slavio_mdm_mem_writeb(void *opaque
, target_phys_addr_t addr
,
168 MiscState
*s
= opaque
;
170 trace_slavio_mdm_mem_writeb(val
& 0xff);
171 s
->mctrl
= val
& 0xff;
174 static uint32_t slavio_mdm_mem_readb(void *opaque
, target_phys_addr_t addr
)
176 MiscState
*s
= opaque
;
180 trace_slavio_mdm_mem_readb(ret
);
184 static CPUReadMemoryFunc
* const slavio_mdm_mem_read
[3] = {
185 slavio_mdm_mem_readb
,
190 static CPUWriteMemoryFunc
* const slavio_mdm_mem_write
[3] = {
191 slavio_mdm_mem_writeb
,
196 static void slavio_aux1_mem_writeb(void *opaque
, target_phys_addr_t addr
,
199 MiscState
*s
= opaque
;
201 trace_slavio_aux1_mem_writeb(val
& 0xff);
203 // Send a pulse to floppy terminal count line
205 qemu_irq_raise(s
->fdc_tc
);
206 qemu_irq_lower(s
->fdc_tc
);
210 s
->aux1
= val
& 0xff;
213 static uint32_t slavio_aux1_mem_readb(void *opaque
, target_phys_addr_t addr
)
215 MiscState
*s
= opaque
;
219 trace_slavio_aux1_mem_readb(ret
);
223 static CPUReadMemoryFunc
* const slavio_aux1_mem_read
[3] = {
224 slavio_aux1_mem_readb
,
229 static CPUWriteMemoryFunc
* const slavio_aux1_mem_write
[3] = {
230 slavio_aux1_mem_writeb
,
235 static void slavio_aux2_mem_writeb(void *opaque
, target_phys_addr_t addr
,
238 MiscState
*s
= opaque
;
240 val
&= AUX2_PWRINTCLR
| AUX2_PWROFF
;
241 trace_slavio_aux2_mem_writeb(val
& 0xff);
242 val
|= s
->aux2
& AUX2_PWRFAIL
;
243 if (val
& AUX2_PWRINTCLR
) // Clear Power Fail int
246 if (val
& AUX2_PWROFF
)
247 qemu_system_shutdown_request();
248 slavio_misc_update_irq(s
);
251 static uint32_t slavio_aux2_mem_readb(void *opaque
, target_phys_addr_t addr
)
253 MiscState
*s
= opaque
;
257 trace_slavio_aux2_mem_readb(ret
);
261 static CPUReadMemoryFunc
* const slavio_aux2_mem_read
[3] = {
262 slavio_aux2_mem_readb
,
267 static CPUWriteMemoryFunc
* const slavio_aux2_mem_write
[3] = {
268 slavio_aux2_mem_writeb
,
273 static void apc_mem_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
275 APCState
*s
= opaque
;
277 trace_apc_mem_writeb(val
& 0xff);
278 qemu_irq_raise(s
->cpu_halt
);
281 static uint32_t apc_mem_readb(void *opaque
, target_phys_addr_t addr
)
285 trace_apc_mem_readb(ret
);
289 static CPUReadMemoryFunc
* const apc_mem_read
[3] = {
295 static CPUWriteMemoryFunc
* const apc_mem_write
[3] = {
301 static uint32_t slavio_sysctrl_mem_readl(void *opaque
, target_phys_addr_t addr
)
303 MiscState
*s
= opaque
;
313 trace_slavio_sysctrl_mem_readl(ret
);
317 static void slavio_sysctrl_mem_writel(void *opaque
, target_phys_addr_t addr
,
320 MiscState
*s
= opaque
;
322 trace_slavio_sysctrl_mem_writel(val
);
325 if (val
& SYS_RESET
) {
326 s
->sysctrl
= SYS_RESETSTAT
;
327 qemu_system_reset_request();
335 static CPUReadMemoryFunc
* const slavio_sysctrl_mem_read
[3] = {
338 slavio_sysctrl_mem_readl
,
341 static CPUWriteMemoryFunc
* const slavio_sysctrl_mem_write
[3] = {
344 slavio_sysctrl_mem_writel
,
347 static uint32_t slavio_led_mem_readw(void *opaque
, target_phys_addr_t addr
)
349 MiscState
*s
= opaque
;
359 trace_slavio_led_mem_readw(ret
);
363 static void slavio_led_mem_writew(void *opaque
, target_phys_addr_t addr
,
366 MiscState
*s
= opaque
;
368 trace_slavio_led_mem_readw(val
& 0xffff);
378 static CPUReadMemoryFunc
* const slavio_led_mem_read
[3] = {
380 slavio_led_mem_readw
,
384 static CPUWriteMemoryFunc
* const slavio_led_mem_write
[3] = {
386 slavio_led_mem_writew
,
390 static const VMStateDescription vmstate_misc
= {
391 .name
="slavio_misc",
393 .minimum_version_id
= 1,
394 .minimum_version_id_old
= 1,
395 .fields
= (VMStateField
[]) {
396 VMSTATE_UINT32(dummy
, MiscState
),
397 VMSTATE_UINT8(config
, MiscState
),
398 VMSTATE_UINT8(aux1
, MiscState
),
399 VMSTATE_UINT8(aux2
, MiscState
),
400 VMSTATE_UINT8(diag
, MiscState
),
401 VMSTATE_UINT8(mctrl
, MiscState
),
402 VMSTATE_UINT8(sysctrl
, MiscState
),
403 VMSTATE_END_OF_LIST()
407 static int apc_init1(SysBusDevice
*dev
)
409 APCState
*s
= FROM_SYSBUS(APCState
, dev
);
412 sysbus_init_irq(dev
, &s
->cpu_halt
);
414 /* Power management (APC) XXX: not a Slavio device */
415 io
= cpu_register_io_memory(apc_mem_read
, apc_mem_write
, s
);
416 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
420 static int slavio_misc_init1(SysBusDevice
*dev
)
422 MiscState
*s
= FROM_SYSBUS(MiscState
, dev
);
425 sysbus_init_irq(dev
, &s
->irq
);
426 sysbus_init_irq(dev
, &s
->fdc_tc
);
428 /* 8 bit registers */
430 io
= cpu_register_io_memory(slavio_cfg_mem_read
,
431 slavio_cfg_mem_write
, s
);
432 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
435 io
= cpu_register_io_memory(slavio_diag_mem_read
,
436 slavio_diag_mem_write
, s
);
437 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
440 io
= cpu_register_io_memory(slavio_mdm_mem_read
,
441 slavio_mdm_mem_write
, s
);
442 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
444 /* 16 bit registers */
445 /* ss600mp diag LEDs */
446 io
= cpu_register_io_memory(slavio_led_mem_read
,
447 slavio_led_mem_write
, s
);
448 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
450 /* 32 bit registers */
452 io
= cpu_register_io_memory(slavio_sysctrl_mem_read
,
453 slavio_sysctrl_mem_write
, s
);
454 sysbus_init_mmio(dev
, SYSCTRL_SIZE
, io
);
456 /* AUX 1 (Misc System Functions) */
457 io
= cpu_register_io_memory(slavio_aux1_mem_read
,
458 slavio_aux1_mem_write
, s
);
459 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
461 /* AUX 2 (Software Powerdown Control) */
462 io
= cpu_register_io_memory(slavio_aux2_mem_read
,
463 slavio_aux2_mem_write
, s
);
464 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
466 qdev_init_gpio_in(&dev
->qdev
, slavio_set_power_fail
, 1);
471 static SysBusDeviceInfo slavio_misc_info
= {
472 .init
= slavio_misc_init1
,
473 .qdev
.name
= "slavio_misc",
474 .qdev
.size
= sizeof(MiscState
),
475 .qdev
.vmsd
= &vmstate_misc
,
476 .qdev
.reset
= slavio_misc_reset
,
479 static SysBusDeviceInfo apc_info
= {
482 .qdev
.size
= sizeof(MiscState
),
485 static void slavio_misc_register_devices(void)
487 sysbus_register_withprop(&slavio_misc_info
);
488 sysbus_register_withprop(&apc_info
);
491 device_init(slavio_misc_register_devices
)