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
{
39 MemoryRegion cfg_iomem
;
40 MemoryRegion diag_iomem
;
41 MemoryRegion mdm_iomem
;
42 MemoryRegion led_iomem
;
43 MemoryRegion sysctrl_iomem
;
44 MemoryRegion aux1_iomem
;
45 MemoryRegion aux2_iomem
;
56 typedef struct APCState
{
63 #define SYSCTRL_SIZE 4
67 #define AUX2_PWROFF 0x01
68 #define AUX2_PWRINTCLR 0x02
69 #define AUX2_PWRFAIL 0x20
71 #define CFG_PWRINTEN 0x08
73 #define SYS_RESET 0x01
74 #define SYS_RESETSTAT 0x02
76 static void slavio_misc_update_irq(void *opaque
)
78 MiscState
*s
= opaque
;
80 if ((s
->aux2
& AUX2_PWRFAIL
) && (s
->config
& CFG_PWRINTEN
)) {
81 trace_slavio_misc_update_irq_raise();
82 qemu_irq_raise(s
->irq
);
84 trace_slavio_misc_update_irq_lower();
85 qemu_irq_lower(s
->irq
);
89 static void slavio_misc_reset(DeviceState
*d
)
91 MiscState
*s
= container_of(d
, MiscState
, busdev
.qdev
);
93 // Diagnostic and system control registers not cleared in reset
94 s
->config
= s
->aux1
= s
->aux2
= s
->mctrl
= 0;
97 static void slavio_set_power_fail(void *opaque
, int irq
, int power_failing
)
99 MiscState
*s
= opaque
;
101 trace_slavio_set_power_fail(power_failing
, s
->config
);
102 if (power_failing
&& (s
->config
& CFG_PWRINTEN
)) {
103 s
->aux2
|= AUX2_PWRFAIL
;
105 s
->aux2
&= ~AUX2_PWRFAIL
;
107 slavio_misc_update_irq(s
);
110 static void slavio_cfg_mem_writeb(void *opaque
, target_phys_addr_t addr
,
111 uint64_t val
, unsigned size
)
113 MiscState
*s
= opaque
;
115 trace_slavio_cfg_mem_writeb(val
& 0xff);
116 s
->config
= val
& 0xff;
117 slavio_misc_update_irq(s
);
120 static uint64_t slavio_cfg_mem_readb(void *opaque
, target_phys_addr_t addr
,
123 MiscState
*s
= opaque
;
127 trace_slavio_cfg_mem_readb(ret
);
131 static const MemoryRegionOps slavio_cfg_mem_ops
= {
132 .read
= slavio_cfg_mem_readb
,
133 .write
= slavio_cfg_mem_writeb
,
134 .endianness
= DEVICE_NATIVE_ENDIAN
,
136 .min_access_size
= 1,
137 .max_access_size
= 1,
141 static void slavio_diag_mem_writeb(void *opaque
, target_phys_addr_t addr
,
142 uint64_t val
, unsigned size
)
144 MiscState
*s
= opaque
;
146 trace_slavio_diag_mem_writeb(val
& 0xff);
147 s
->diag
= val
& 0xff;
150 static uint64_t slavio_diag_mem_readb(void *opaque
, target_phys_addr_t addr
,
153 MiscState
*s
= opaque
;
157 trace_slavio_diag_mem_readb(ret
);
161 static const MemoryRegionOps slavio_diag_mem_ops
= {
162 .read
= slavio_diag_mem_readb
,
163 .write
= slavio_diag_mem_writeb
,
164 .endianness
= DEVICE_NATIVE_ENDIAN
,
166 .min_access_size
= 1,
167 .max_access_size
= 1,
171 static void slavio_mdm_mem_writeb(void *opaque
, target_phys_addr_t addr
,
172 uint64_t val
, unsigned size
)
174 MiscState
*s
= opaque
;
176 trace_slavio_mdm_mem_writeb(val
& 0xff);
177 s
->mctrl
= val
& 0xff;
180 static uint64_t slavio_mdm_mem_readb(void *opaque
, target_phys_addr_t addr
,
183 MiscState
*s
= opaque
;
187 trace_slavio_mdm_mem_readb(ret
);
191 static const MemoryRegionOps slavio_mdm_mem_ops
= {
192 .read
= slavio_mdm_mem_readb
,
193 .write
= slavio_mdm_mem_writeb
,
194 .endianness
= DEVICE_NATIVE_ENDIAN
,
196 .min_access_size
= 1,
197 .max_access_size
= 1,
201 static void slavio_aux1_mem_writeb(void *opaque
, target_phys_addr_t addr
,
202 uint64_t val
, unsigned size
)
204 MiscState
*s
= opaque
;
206 trace_slavio_aux1_mem_writeb(val
& 0xff);
208 // Send a pulse to floppy terminal count line
210 qemu_irq_raise(s
->fdc_tc
);
211 qemu_irq_lower(s
->fdc_tc
);
215 s
->aux1
= val
& 0xff;
218 static uint64_t slavio_aux1_mem_readb(void *opaque
, target_phys_addr_t addr
,
221 MiscState
*s
= opaque
;
225 trace_slavio_aux1_mem_readb(ret
);
229 static const MemoryRegionOps slavio_aux1_mem_ops
= {
230 .read
= slavio_aux1_mem_readb
,
231 .write
= slavio_aux1_mem_writeb
,
232 .endianness
= DEVICE_NATIVE_ENDIAN
,
234 .min_access_size
= 1,
235 .max_access_size
= 1,
239 static void slavio_aux2_mem_writeb(void *opaque
, target_phys_addr_t addr
,
240 uint64_t val
, unsigned size
)
242 MiscState
*s
= opaque
;
244 val
&= AUX2_PWRINTCLR
| AUX2_PWROFF
;
245 trace_slavio_aux2_mem_writeb(val
& 0xff);
246 val
|= s
->aux2
& AUX2_PWRFAIL
;
247 if (val
& AUX2_PWRINTCLR
) // Clear Power Fail int
250 if (val
& AUX2_PWROFF
)
251 qemu_system_shutdown_request();
252 slavio_misc_update_irq(s
);
255 static uint64_t slavio_aux2_mem_readb(void *opaque
, target_phys_addr_t addr
,
258 MiscState
*s
= opaque
;
262 trace_slavio_aux2_mem_readb(ret
);
266 static const MemoryRegionOps slavio_aux2_mem_ops
= {
267 .read
= slavio_aux2_mem_readb
,
268 .write
= slavio_aux2_mem_writeb
,
269 .endianness
= DEVICE_NATIVE_ENDIAN
,
271 .min_access_size
= 1,
272 .max_access_size
= 1,
276 static void apc_mem_writeb(void *opaque
, target_phys_addr_t addr
,
277 uint64_t val
, unsigned size
)
279 APCState
*s
= opaque
;
281 trace_apc_mem_writeb(val
& 0xff);
282 qemu_irq_raise(s
->cpu_halt
);
285 static uint64_t apc_mem_readb(void *opaque
, target_phys_addr_t addr
,
290 trace_apc_mem_readb(ret
);
294 static const MemoryRegionOps apc_mem_ops
= {
295 .read
= apc_mem_readb
,
296 .write
= apc_mem_writeb
,
297 .endianness
= DEVICE_NATIVE_ENDIAN
,
299 .min_access_size
= 1,
300 .max_access_size
= 1,
304 static uint64_t slavio_sysctrl_mem_readl(void *opaque
, target_phys_addr_t addr
,
307 MiscState
*s
= opaque
;
317 trace_slavio_sysctrl_mem_readl(ret
);
321 static void slavio_sysctrl_mem_writel(void *opaque
, target_phys_addr_t addr
,
322 uint64_t val
, unsigned size
)
324 MiscState
*s
= opaque
;
326 trace_slavio_sysctrl_mem_writel(val
);
329 if (val
& SYS_RESET
) {
330 s
->sysctrl
= SYS_RESETSTAT
;
331 qemu_system_reset_request();
339 static const MemoryRegionOps slavio_sysctrl_mem_ops
= {
340 .read
= slavio_sysctrl_mem_readl
,
341 .write
= slavio_sysctrl_mem_writel
,
342 .endianness
= DEVICE_NATIVE_ENDIAN
,
344 .min_access_size
= 4,
345 .max_access_size
= 4,
349 static uint64_t slavio_led_mem_readw(void *opaque
, target_phys_addr_t addr
,
352 MiscState
*s
= opaque
;
362 trace_slavio_led_mem_readw(ret
);
366 static void slavio_led_mem_writew(void *opaque
, target_phys_addr_t addr
,
367 uint64_t val
, unsigned size
)
369 MiscState
*s
= opaque
;
371 trace_slavio_led_mem_readw(val
& 0xffff);
381 static const MemoryRegionOps slavio_led_mem_ops
= {
382 .read
= slavio_led_mem_readw
,
383 .write
= slavio_led_mem_writew
,
384 .endianness
= DEVICE_NATIVE_ENDIAN
,
386 .min_access_size
= 2,
387 .max_access_size
= 2,
391 static const VMStateDescription vmstate_misc
= {
392 .name
="slavio_misc",
394 .minimum_version_id
= 1,
395 .minimum_version_id_old
= 1,
396 .fields
= (VMStateField
[]) {
397 VMSTATE_UINT32(dummy
, MiscState
),
398 VMSTATE_UINT8(config
, MiscState
),
399 VMSTATE_UINT8(aux1
, MiscState
),
400 VMSTATE_UINT8(aux2
, MiscState
),
401 VMSTATE_UINT8(diag
, MiscState
),
402 VMSTATE_UINT8(mctrl
, MiscState
),
403 VMSTATE_UINT8(sysctrl
, MiscState
),
404 VMSTATE_END_OF_LIST()
408 static int apc_init1(SysBusDevice
*dev
)
410 APCState
*s
= FROM_SYSBUS(APCState
, dev
);
412 sysbus_init_irq(dev
, &s
->cpu_halt
);
414 /* Power management (APC) XXX: not a Slavio device */
415 memory_region_init_io(&s
->iomem
, &apc_mem_ops
, s
,
417 sysbus_init_mmio(dev
, &s
->iomem
);
421 static int slavio_misc_init1(SysBusDevice
*dev
)
423 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 memory_region_init_io(&s
->cfg_iomem
, &slavio_cfg_mem_ops
, s
,
431 "configuration", MISC_SIZE
);
432 sysbus_init_mmio(dev
, &s
->cfg_iomem
);
435 memory_region_init_io(&s
->diag_iomem
, &slavio_diag_mem_ops
, s
,
436 "diagnostic", MISC_SIZE
);
437 sysbus_init_mmio(dev
, &s
->diag_iomem
);
440 memory_region_init_io(&s
->mdm_iomem
, &slavio_mdm_mem_ops
, s
,
442 sysbus_init_mmio(dev
, &s
->mdm_iomem
);
444 /* 16 bit registers */
445 /* ss600mp diag LEDs */
446 memory_region_init_io(&s
->led_iomem
, &slavio_led_mem_ops
, s
,
448 sysbus_init_mmio(dev
, &s
->led_iomem
);
450 /* 32 bit registers */
452 memory_region_init_io(&s
->sysctrl_iomem
, &slavio_sysctrl_mem_ops
, s
,
453 "system-control", MISC_SIZE
);
454 sysbus_init_mmio(dev
, &s
->sysctrl_iomem
);
456 /* AUX 1 (Misc System Functions) */
457 memory_region_init_io(&s
->aux1_iomem
, &slavio_aux1_mem_ops
, s
,
458 "misc-system-functions", MISC_SIZE
);
459 sysbus_init_mmio(dev
, &s
->aux1_iomem
);
461 /* AUX 2 (Software Powerdown Control) */
462 memory_region_init_io(&s
->aux2_iomem
, &slavio_aux2_mem_ops
, s
,
463 "software-powerdown-control", MISC_SIZE
);
464 sysbus_init_mmio(dev
, &s
->aux2_iomem
);
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
)