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
32 * This is the auxio port, chip control and system control part of
33 * chip STP2001 (Slave I/O), also produced as NCR89C105. See
34 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
36 * This also includes the PMC CPU idle controller.
40 #define MISC_DPRINTF(fmt, ...) \
41 do { printf("MISC: " fmt , ## __VA_ARGS__); } while (0)
43 #define MISC_DPRINTF(fmt, ...)
46 typedef struct MiscState
{
58 typedef struct APCState
{
64 #define SYSCTRL_SIZE 4
68 #define AUX2_PWROFF 0x01
69 #define AUX2_PWRINTCLR 0x02
70 #define AUX2_PWRFAIL 0x20
72 #define CFG_PWRINTEN 0x08
74 #define SYS_RESET 0x01
75 #define SYS_RESETSTAT 0x02
77 static void slavio_misc_update_irq(void *opaque
)
79 MiscState
*s
= opaque
;
81 if ((s
->aux2
& AUX2_PWRFAIL
) && (s
->config
& CFG_PWRINTEN
)) {
82 MISC_DPRINTF("Raise IRQ\n");
83 qemu_irq_raise(s
->irq
);
85 MISC_DPRINTF("Lower IRQ\n");
86 qemu_irq_lower(s
->irq
);
90 static void slavio_misc_reset(DeviceState
*d
)
92 MiscState
*s
= container_of(d
, MiscState
, busdev
.qdev
);
94 // Diagnostic and system control registers not cleared in reset
95 s
->config
= s
->aux1
= s
->aux2
= s
->mctrl
= 0;
98 static void slavio_set_power_fail(void *opaque
, int irq
, int power_failing
)
100 MiscState
*s
= opaque
;
102 MISC_DPRINTF("Power fail: %d, config: %d\n", power_failing
, s
->config
);
103 if (power_failing
&& (s
->config
& CFG_PWRINTEN
)) {
104 s
->aux2
|= AUX2_PWRFAIL
;
106 s
->aux2
&= ~AUX2_PWRFAIL
;
108 slavio_misc_update_irq(s
);
111 static void slavio_cfg_mem_writeb(void *opaque
, target_phys_addr_t addr
,
114 MiscState
*s
= opaque
;
116 MISC_DPRINTF("Write config %2.2x\n", val
& 0xff);
117 s
->config
= val
& 0xff;
118 slavio_misc_update_irq(s
);
121 static uint32_t slavio_cfg_mem_readb(void *opaque
, target_phys_addr_t addr
)
123 MiscState
*s
= opaque
;
127 MISC_DPRINTF("Read config %2.2x\n", ret
);
131 static CPUReadMemoryFunc
* const slavio_cfg_mem_read
[3] = {
132 slavio_cfg_mem_readb
,
137 static CPUWriteMemoryFunc
* const slavio_cfg_mem_write
[3] = {
138 slavio_cfg_mem_writeb
,
143 static void slavio_diag_mem_writeb(void *opaque
, target_phys_addr_t addr
,
146 MiscState
*s
= opaque
;
148 MISC_DPRINTF("Write diag %2.2x\n", val
& 0xff);
149 s
->diag
= val
& 0xff;
152 static uint32_t slavio_diag_mem_readb(void *opaque
, target_phys_addr_t addr
)
154 MiscState
*s
= opaque
;
158 MISC_DPRINTF("Read diag %2.2x\n", ret
);
162 static CPUReadMemoryFunc
* const slavio_diag_mem_read
[3] = {
163 slavio_diag_mem_readb
,
168 static CPUWriteMemoryFunc
* const slavio_diag_mem_write
[3] = {
169 slavio_diag_mem_writeb
,
174 static void slavio_mdm_mem_writeb(void *opaque
, target_phys_addr_t addr
,
177 MiscState
*s
= opaque
;
179 MISC_DPRINTF("Write modem control %2.2x\n", val
& 0xff);
180 s
->mctrl
= val
& 0xff;
183 static uint32_t slavio_mdm_mem_readb(void *opaque
, target_phys_addr_t addr
)
185 MiscState
*s
= opaque
;
189 MISC_DPRINTF("Read modem control %2.2x\n", ret
);
193 static CPUReadMemoryFunc
* const slavio_mdm_mem_read
[3] = {
194 slavio_mdm_mem_readb
,
199 static CPUWriteMemoryFunc
* const slavio_mdm_mem_write
[3] = {
200 slavio_mdm_mem_writeb
,
205 static void slavio_aux1_mem_writeb(void *opaque
, target_phys_addr_t addr
,
208 MiscState
*s
= opaque
;
210 MISC_DPRINTF("Write aux1 %2.2x\n", val
& 0xff);
212 // Send a pulse to floppy terminal count line
214 qemu_irq_raise(s
->fdc_tc
);
215 qemu_irq_lower(s
->fdc_tc
);
219 s
->aux1
= val
& 0xff;
222 static uint32_t slavio_aux1_mem_readb(void *opaque
, target_phys_addr_t addr
)
224 MiscState
*s
= opaque
;
228 MISC_DPRINTF("Read aux1 %2.2x\n", ret
);
233 static CPUReadMemoryFunc
* const slavio_aux1_mem_read
[3] = {
234 slavio_aux1_mem_readb
,
239 static CPUWriteMemoryFunc
* const slavio_aux1_mem_write
[3] = {
240 slavio_aux1_mem_writeb
,
245 static void slavio_aux2_mem_writeb(void *opaque
, target_phys_addr_t addr
,
248 MiscState
*s
= opaque
;
250 val
&= AUX2_PWRINTCLR
| AUX2_PWROFF
;
251 MISC_DPRINTF("Write aux2 %2.2x\n", val
);
252 val
|= s
->aux2
& AUX2_PWRFAIL
;
253 if (val
& AUX2_PWRINTCLR
) // Clear Power Fail int
256 if (val
& AUX2_PWROFF
)
257 qemu_system_shutdown_request();
258 slavio_misc_update_irq(s
);
261 static uint32_t slavio_aux2_mem_readb(void *opaque
, target_phys_addr_t addr
)
263 MiscState
*s
= opaque
;
267 MISC_DPRINTF("Read aux2 %2.2x\n", ret
);
272 static CPUReadMemoryFunc
* const slavio_aux2_mem_read
[3] = {
273 slavio_aux2_mem_readb
,
278 static CPUWriteMemoryFunc
* const slavio_aux2_mem_write
[3] = {
279 slavio_aux2_mem_writeb
,
284 static void apc_mem_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
286 APCState
*s
= opaque
;
288 MISC_DPRINTF("Write power management %2.2x\n", val
& 0xff);
289 qemu_irq_raise(s
->cpu_halt
);
292 static uint32_t apc_mem_readb(void *opaque
, target_phys_addr_t addr
)
296 MISC_DPRINTF("Read power management %2.2x\n", ret
);
300 static CPUReadMemoryFunc
* const apc_mem_read
[3] = {
306 static CPUWriteMemoryFunc
* const apc_mem_write
[3] = {
312 static uint32_t slavio_sysctrl_mem_readl(void *opaque
, target_phys_addr_t addr
)
314 MiscState
*s
= opaque
;
324 MISC_DPRINTF("Read system control %08x\n", ret
);
328 static void slavio_sysctrl_mem_writel(void *opaque
, target_phys_addr_t addr
,
331 MiscState
*s
= opaque
;
333 MISC_DPRINTF("Write system control %08x\n", val
);
336 if (val
& SYS_RESET
) {
337 s
->sysctrl
= SYS_RESETSTAT
;
338 qemu_system_reset_request();
346 static CPUReadMemoryFunc
* const slavio_sysctrl_mem_read
[3] = {
349 slavio_sysctrl_mem_readl
,
352 static CPUWriteMemoryFunc
* const slavio_sysctrl_mem_write
[3] = {
355 slavio_sysctrl_mem_writel
,
358 static uint32_t slavio_led_mem_readw(void *opaque
, target_phys_addr_t addr
)
360 MiscState
*s
= opaque
;
370 MISC_DPRINTF("Read diagnostic LED %04x\n", ret
);
374 static void slavio_led_mem_writew(void *opaque
, target_phys_addr_t addr
,
377 MiscState
*s
= opaque
;
379 MISC_DPRINTF("Write diagnostic LED %04x\n", val
& 0xffff);
389 static CPUReadMemoryFunc
* const slavio_led_mem_read
[3] = {
391 slavio_led_mem_readw
,
395 static CPUWriteMemoryFunc
* const slavio_led_mem_write
[3] = {
397 slavio_led_mem_writew
,
401 static const VMStateDescription vmstate_misc
= {
402 .name
="slavio_misc",
404 .minimum_version_id
= 1,
405 .minimum_version_id_old
= 1,
406 .fields
= (VMStateField
[]) {
407 VMSTATE_UINT32(dummy
, MiscState
),
408 VMSTATE_UINT8(config
, MiscState
),
409 VMSTATE_UINT8(aux1
, MiscState
),
410 VMSTATE_UINT8(aux2
, MiscState
),
411 VMSTATE_UINT8(diag
, MiscState
),
412 VMSTATE_UINT8(mctrl
, MiscState
),
413 VMSTATE_UINT8(sysctrl
, MiscState
),
414 VMSTATE_END_OF_LIST()
418 static int apc_init1(SysBusDevice
*dev
)
420 APCState
*s
= FROM_SYSBUS(APCState
, dev
);
423 sysbus_init_irq(dev
, &s
->cpu_halt
);
425 /* Power management (APC) XXX: not a Slavio device */
426 io
= cpu_register_io_memory(apc_mem_read
, apc_mem_write
, s
);
427 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
431 static int slavio_misc_init1(SysBusDevice
*dev
)
433 MiscState
*s
= FROM_SYSBUS(MiscState
, dev
);
436 sysbus_init_irq(dev
, &s
->irq
);
437 sysbus_init_irq(dev
, &s
->fdc_tc
);
439 /* 8 bit registers */
441 io
= cpu_register_io_memory(slavio_cfg_mem_read
,
442 slavio_cfg_mem_write
, s
);
443 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
446 io
= cpu_register_io_memory(slavio_diag_mem_read
,
447 slavio_diag_mem_write
, s
);
448 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
451 io
= cpu_register_io_memory(slavio_mdm_mem_read
,
452 slavio_mdm_mem_write
, s
);
453 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
455 /* 16 bit registers */
456 /* ss600mp diag LEDs */
457 io
= cpu_register_io_memory(slavio_led_mem_read
,
458 slavio_led_mem_write
, s
);
459 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
461 /* 32 bit registers */
463 io
= cpu_register_io_memory(slavio_sysctrl_mem_read
,
464 slavio_sysctrl_mem_write
, s
);
465 sysbus_init_mmio(dev
, SYSCTRL_SIZE
, io
);
467 /* AUX 1 (Misc System Functions) */
468 io
= cpu_register_io_memory(slavio_aux1_mem_read
,
469 slavio_aux1_mem_write
, s
);
470 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
472 /* AUX 2 (Software Powerdown Control) */
473 io
= cpu_register_io_memory(slavio_aux2_mem_read
,
474 slavio_aux2_mem_write
, s
);
475 sysbus_init_mmio(dev
, MISC_SIZE
, io
);
477 qdev_init_gpio_in(&dev
->qdev
, slavio_set_power_fail
, 1);
482 static SysBusDeviceInfo slavio_misc_info
= {
483 .init
= slavio_misc_init1
,
484 .qdev
.name
= "slavio_misc",
485 .qdev
.size
= sizeof(MiscState
),
486 .qdev
.vmsd
= &vmstate_misc
,
487 .qdev
.reset
= slavio_misc_reset
,
490 static SysBusDeviceInfo apc_info
= {
493 .qdev
.size
= sizeof(MiscState
),
496 static void slavio_misc_register_devices(void)
498 sysbus_register_withprop(&slavio_misc_info
);
499 sysbus_register_withprop(&apc_info
);
502 device_init(slavio_misc_register_devices
)