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
33 * This is the auxio port, chip control and system control part of
34 * chip STP2001 (Slave I/O), also produced as NCR89C105. See
35 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
37 * This also includes the PMC CPU idle controller.
41 #define MISC_DPRINTF(fmt, ...) \
42 do { printf("MISC: " fmt , ## __VA_ARGS__); } while (0)
44 #define MISC_DPRINTF(fmt, ...)
47 typedef struct MiscState
{
59 typedef struct APCState
{
65 #define SYSCTRL_SIZE 4
69 #define AUX2_PWROFF 0x01
70 #define AUX2_PWRINTCLR 0x02
71 #define AUX2_PWRFAIL 0x20
73 #define CFG_PWRINTEN 0x08
75 #define SYS_RESET 0x01
76 #define SYS_RESETSTAT 0x02
78 static void slavio_misc_update_irq(void *opaque
)
80 MiscState
*s
= opaque
;
82 if ((s
->aux2
& AUX2_PWRFAIL
) && (s
->config
& CFG_PWRINTEN
)) {
83 MISC_DPRINTF("Raise IRQ\n");
84 qemu_irq_raise(s
->irq
);
86 MISC_DPRINTF("Lower IRQ\n");
87 qemu_irq_lower(s
->irq
);
91 static void slavio_misc_reset(void *opaque
)
93 MiscState
*s
= opaque
;
95 // Diagnostic and system control registers not cleared in reset
96 s
->config
= s
->aux1
= s
->aux2
= s
->mctrl
= 0;
99 static void slavio_set_power_fail(void *opaque
, int irq
, int power_failing
)
101 MiscState
*s
= opaque
;
103 MISC_DPRINTF("Power fail: %d, config: %d\n", power_failing
, s
->config
);
104 if (power_failing
&& (s
->config
& CFG_PWRINTEN
)) {
105 s
->aux2
|= AUX2_PWRFAIL
;
107 s
->aux2
&= ~AUX2_PWRFAIL
;
109 slavio_misc_update_irq(s
);
112 static void slavio_cfg_mem_writeb(void *opaque
, target_phys_addr_t addr
,
115 MiscState
*s
= opaque
;
117 MISC_DPRINTF("Write config %2.2x\n", val
& 0xff);
118 s
->config
= val
& 0xff;
119 slavio_misc_update_irq(s
);
122 static uint32_t slavio_cfg_mem_readb(void *opaque
, target_phys_addr_t addr
)
124 MiscState
*s
= opaque
;
128 MISC_DPRINTF("Read config %2.2x\n", ret
);
132 static CPUReadMemoryFunc
* const slavio_cfg_mem_read
[3] = {
133 slavio_cfg_mem_readb
,
138 static CPUWriteMemoryFunc
* const slavio_cfg_mem_write
[3] = {
139 slavio_cfg_mem_writeb
,
144 static void slavio_diag_mem_writeb(void *opaque
, target_phys_addr_t addr
,
147 MiscState
*s
= opaque
;
149 MISC_DPRINTF("Write diag %2.2x\n", val
& 0xff);
150 s
->diag
= val
& 0xff;
153 static uint32_t slavio_diag_mem_readb(void *opaque
, target_phys_addr_t addr
)
155 MiscState
*s
= opaque
;
159 MISC_DPRINTF("Read diag %2.2x\n", ret
);
163 static CPUReadMemoryFunc
* const slavio_diag_mem_read
[3] = {
164 slavio_diag_mem_readb
,
169 static CPUWriteMemoryFunc
* const slavio_diag_mem_write
[3] = {
170 slavio_diag_mem_writeb
,
175 static void slavio_mdm_mem_writeb(void *opaque
, target_phys_addr_t addr
,
178 MiscState
*s
= opaque
;
180 MISC_DPRINTF("Write modem control %2.2x\n", val
& 0xff);
181 s
->mctrl
= val
& 0xff;
184 static uint32_t slavio_mdm_mem_readb(void *opaque
, target_phys_addr_t addr
)
186 MiscState
*s
= opaque
;
190 MISC_DPRINTF("Read modem control %2.2x\n", ret
);
194 static CPUReadMemoryFunc
* const slavio_mdm_mem_read
[3] = {
195 slavio_mdm_mem_readb
,
200 static CPUWriteMemoryFunc
* const slavio_mdm_mem_write
[3] = {
201 slavio_mdm_mem_writeb
,
206 static void slavio_aux1_mem_writeb(void *opaque
, target_phys_addr_t addr
,
209 MiscState
*s
= opaque
;
211 MISC_DPRINTF("Write aux1 %2.2x\n", val
& 0xff);
213 // Send a pulse to floppy terminal count line
215 qemu_irq_raise(s
->fdc_tc
);
216 qemu_irq_lower(s
->fdc_tc
);
220 s
->aux1
= val
& 0xff;
223 static uint32_t slavio_aux1_mem_readb(void *opaque
, target_phys_addr_t addr
)
225 MiscState
*s
= opaque
;
229 MISC_DPRINTF("Read aux1 %2.2x\n", ret
);
234 static CPUReadMemoryFunc
* const slavio_aux1_mem_read
[3] = {
235 slavio_aux1_mem_readb
,
240 static CPUWriteMemoryFunc
* const slavio_aux1_mem_write
[3] = {
241 slavio_aux1_mem_writeb
,
246 static void slavio_aux2_mem_writeb(void *opaque
, target_phys_addr_t addr
,
249 MiscState
*s
= opaque
;
251 val
&= AUX2_PWRINTCLR
| AUX2_PWROFF
;
252 MISC_DPRINTF("Write aux2 %2.2x\n", val
);
253 val
|= s
->aux2
& AUX2_PWRFAIL
;
254 if (val
& AUX2_PWRINTCLR
) // Clear Power Fail int
257 if (val
& AUX2_PWROFF
)
258 qemu_system_shutdown_request();
259 slavio_misc_update_irq(s
);
262 static uint32_t slavio_aux2_mem_readb(void *opaque
, target_phys_addr_t addr
)
264 MiscState
*s
= opaque
;
268 MISC_DPRINTF("Read aux2 %2.2x\n", ret
);
273 static CPUReadMemoryFunc
* const slavio_aux2_mem_read
[3] = {
274 slavio_aux2_mem_readb
,
279 static CPUWriteMemoryFunc
* const slavio_aux2_mem_write
[3] = {
280 slavio_aux2_mem_writeb
,
285 static void apc_mem_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
287 APCState
*s
= opaque
;
289 MISC_DPRINTF("Write power management %2.2x\n", val
& 0xff);
290 qemu_irq_raise(s
->cpu_halt
);
293 static uint32_t apc_mem_readb(void *opaque
, target_phys_addr_t addr
)
297 MISC_DPRINTF("Read power management %2.2x\n", ret
);
301 static CPUReadMemoryFunc
* const apc_mem_read
[3] = {
307 static CPUWriteMemoryFunc
* const apc_mem_write
[3] = {
313 static uint32_t slavio_sysctrl_mem_readl(void *opaque
, target_phys_addr_t addr
)
315 MiscState
*s
= opaque
;
325 MISC_DPRINTF("Read system control %08x\n", ret
);
329 static void slavio_sysctrl_mem_writel(void *opaque
, target_phys_addr_t addr
,
332 MiscState
*s
= opaque
;
334 MISC_DPRINTF("Write system control %08x\n", val
);
337 if (val
& SYS_RESET
) {
338 s
->sysctrl
= SYS_RESETSTAT
;
339 qemu_system_reset_request();
347 static CPUReadMemoryFunc
* const slavio_sysctrl_mem_read
[3] = {
350 slavio_sysctrl_mem_readl
,
353 static CPUWriteMemoryFunc
* const slavio_sysctrl_mem_write
[3] = {
356 slavio_sysctrl_mem_writel
,
359 static uint32_t slavio_led_mem_readw(void *opaque
, target_phys_addr_t addr
)
361 MiscState
*s
= opaque
;
371 MISC_DPRINTF("Read diagnostic LED %04x\n", ret
);
375 static void slavio_led_mem_writew(void *opaque
, target_phys_addr_t addr
,
378 MiscState
*s
= opaque
;
380 MISC_DPRINTF("Write diagnostic LED %04x\n", val
& 0xffff);
390 static CPUReadMemoryFunc
* const slavio_led_mem_read
[3] = {
392 slavio_led_mem_readw
,
396 static CPUWriteMemoryFunc
* const slavio_led_mem_write
[3] = {
398 slavio_led_mem_writew
,
402 static const VMStateDescription vmstate_misc
= {
403 .name
="slavio_misc",
405 .minimum_version_id
= 1,
406 .minimum_version_id_old
= 1,
407 .fields
= (VMStateField
[]) {
408 VMSTATE_UINT32(dummy
, MiscState
),
409 VMSTATE_UINT8(config
, MiscState
),
410 VMSTATE_UINT8(aux1
, MiscState
),
411 VMSTATE_UINT8(aux2
, MiscState
),
412 VMSTATE_UINT8(diag
, MiscState
),
413 VMSTATE_UINT8(mctrl
, MiscState
),
414 VMSTATE_UINT8(sysctrl
, MiscState
),
415 VMSTATE_END_OF_LIST()
419 static int apc_init1(SysBusDevice
*dev
)
421 APCState
*s
= FROM_SYSBUS(APCState
, dev
);
424 sysbus_init_irq(dev
, &s
->cpu_halt
);
426 /* Power management (APC) XXX: not a Slavio device */
427 io
= cpu_register_io_memory(apc_mem_read
, apc_mem_write
, s
);
428 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
432 static int slavio_misc_init1(SysBusDevice
*dev
)
434 MiscState
*s
= FROM_SYSBUS(MiscState
, dev
);
437 sysbus_init_irq(dev
, &s
->irq
);
438 sysbus_init_irq(dev
, &s
->fdc_tc
);
440 /* 8 bit registers */
442 io
= cpu_register_io_memory(slavio_cfg_mem_read
,
443 slavio_cfg_mem_write
, s
);
444 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
447 io
= cpu_register_io_memory(slavio_diag_mem_read
,
448 slavio_diag_mem_write
, s
);
449 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
452 io
= cpu_register_io_memory(slavio_mdm_mem_read
,
453 slavio_mdm_mem_write
, s
);
454 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
456 /* 16 bit registers */
457 /* ss600mp diag LEDs */
458 io
= cpu_register_io_memory(slavio_led_mem_read
,
459 slavio_led_mem_write
, s
);
460 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
462 /* 32 bit registers */
464 io
= cpu_register_io_memory(slavio_sysctrl_mem_read
,
465 slavio_sysctrl_mem_write
, s
);
466 sysbus_init_mmio(dev
, SYSCTRL_SIZE
, io
);
468 /* AUX 1 (Misc System Functions) */
469 io
= cpu_register_io_memory(slavio_aux1_mem_read
,
470 slavio_aux1_mem_write
, s
);
471 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
473 /* AUX 2 (Software Powerdown Control) */
474 io
= cpu_register_io_memory(slavio_aux2_mem_read
,
475 slavio_aux2_mem_write
, s
);
476 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
478 qdev_init_gpio_in(&dev
->qdev
, slavio_set_power_fail
, 1);
480 vmstate_register(-1, &vmstate_misc
, s
);
481 qemu_register_reset(slavio_misc_reset
, s
);
482 slavio_misc_reset(s
);
486 static SysBusDeviceInfo slavio_misc_info
= {
487 .init
= slavio_misc_init1
,
488 .qdev
.name
= "slavio_misc",
489 .qdev
.size
= sizeof(MiscState
),
492 static SysBusDeviceInfo apc_info
= {
495 .qdev
.size
= sizeof(MiscState
),
498 static void slavio_misc_register_devices(void)
500 sysbus_register_withprop(&slavio_misc_info
);
501 sysbus_register_withprop(&apc_info
);
504 device_init(slavio_misc_register_devices
)