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, args...) \
41 do { printf("MISC: " fmt , ##args); } while (0)
43 #define MISC_DPRINTF(fmt, args...)
46 typedef struct MiscState {
57 #define SYSCTRL_MAXADDR 3
58 #define SYSCTRL_SIZE (SYSCTRL_MAXADDR + 1)
60 #define LED_SIZE (LED_MAXADDR + 1)
62 #define MISC_MASK 0x0fff0000
63 #define MISC_LEDS 0x01600000
64 #define MISC_CFG 0x01800000
65 #define MISC_DIAG 0x01a00000
66 #define MISC_MDM 0x01b00000
67 #define MISC_SYS 0x01f00000
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 void slavio_set_power_fail(void *opaque, 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_misc_mem_writeb(void *opaque, target_phys_addr_t addr,
115 MiscState *s = opaque;
117 switch (addr & MISC_MASK) {
119 MISC_DPRINTF("Write config %2.2x\n", val & 0xff);
120 s->config = val & 0xff;
121 slavio_misc_update_irq(s);
124 MISC_DPRINTF("Write diag %2.2x\n", val & 0xff);
125 s->diag = val & 0xff;
128 MISC_DPRINTF("Write modem control %2.2x\n", val & 0xff);
129 s->mctrl = val & 0xff;
136 static uint32_t slavio_misc_mem_readb(void *opaque, target_phys_addr_t addr)
138 MiscState *s = opaque;
141 switch (addr & MISC_MASK) {
144 MISC_DPRINTF("Read config %2.2x\n", ret);
148 MISC_DPRINTF("Read diag %2.2x\n", ret);
152 MISC_DPRINTF("Read modem control %2.2x\n", ret);
160 static CPUReadMemoryFunc *slavio_misc_mem_read[3] = {
161 slavio_misc_mem_readb,
166 static CPUWriteMemoryFunc *slavio_misc_mem_write[3] = {
167 slavio_misc_mem_writeb,
172 static void slavio_aux1_mem_writeb(void *opaque, target_phys_addr_t addr,
175 MiscState *s = opaque;
177 MISC_DPRINTF("Write aux1 %2.2x\n", val & 0xff);
178 s->aux1 = val & 0xff;
181 static uint32_t slavio_aux1_mem_readb(void *opaque, target_phys_addr_t addr)
183 MiscState *s = opaque;
187 MISC_DPRINTF("Read aux1 %2.2x\n", ret);
192 static CPUReadMemoryFunc *slavio_aux1_mem_read[3] = {
193 slavio_aux1_mem_readb,
198 static CPUWriteMemoryFunc *slavio_aux1_mem_write[3] = {
199 slavio_aux1_mem_writeb,
204 static void slavio_aux2_mem_writeb(void *opaque, target_phys_addr_t addr,
207 MiscState *s = opaque;
209 val &= AUX2_PWRINTCLR | AUX2_PWROFF;
210 MISC_DPRINTF("Write aux2 %2.2x\n", val);
211 val |= s->aux2 & AUX2_PWRFAIL;
212 if (val & AUX2_PWRINTCLR) // Clear Power Fail int
215 if (val & AUX2_PWROFF)
216 qemu_system_shutdown_request();
217 slavio_misc_update_irq(s);
220 static uint32_t slavio_aux2_mem_readb(void *opaque, target_phys_addr_t addr)
222 MiscState *s = opaque;
226 MISC_DPRINTF("Read aux2 %2.2x\n", ret);
231 static CPUReadMemoryFunc *slavio_aux2_mem_read[3] = {
232 slavio_aux2_mem_readb,
237 static CPUWriteMemoryFunc *slavio_aux2_mem_write[3] = {
238 slavio_aux2_mem_writeb,
243 static void apc_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
245 MiscState *s = opaque;
247 MISC_DPRINTF("Write power management %2.2x\n", val & 0xff);
248 cpu_interrupt(s->env, CPU_INTERRUPT_HALT);
251 static uint32_t apc_mem_readb(void *opaque, target_phys_addr_t addr)
255 MISC_DPRINTF("Read power management %2.2x\n", ret);
259 static CPUReadMemoryFunc *apc_mem_read[3] = {
265 static CPUWriteMemoryFunc *apc_mem_write[3] = {
271 static uint32_t slavio_sysctrl_mem_readl(void *opaque, target_phys_addr_t addr)
273 MiscState *s = opaque;
274 uint32_t ret = 0, saddr;
276 saddr = addr & SYSCTRL_MAXADDR;
284 MISC_DPRINTF("Read system control reg 0x" TARGET_FMT_plx " = %x\n", addr,
289 static void slavio_sysctrl_mem_writel(void *opaque, target_phys_addr_t addr,
292 MiscState *s = opaque;
295 saddr = addr & SYSCTRL_MAXADDR;
296 MISC_DPRINTF("Write system control reg 0x" TARGET_FMT_plx " = %x\n", addr,
300 if (val & SYS_RESET) {
301 s->sysctrl = SYS_RESETSTAT;
302 qemu_system_reset_request();
310 static CPUReadMemoryFunc *slavio_sysctrl_mem_read[3] = {
313 slavio_sysctrl_mem_readl,
316 static CPUWriteMemoryFunc *slavio_sysctrl_mem_write[3] = {
319 slavio_sysctrl_mem_writel,
322 static uint32_t slavio_led_mem_readw(void *opaque, target_phys_addr_t addr)
324 MiscState *s = opaque;
325 uint32_t ret = 0, saddr;
327 saddr = addr & LED_MAXADDR;
335 MISC_DPRINTF("Read diagnostic LED reg 0x" TARGET_FMT_plx " = %x\n", addr,
340 static void slavio_led_mem_writew(void *opaque, target_phys_addr_t addr,
343 MiscState *s = opaque;
346 saddr = addr & LED_MAXADDR;
347 MISC_DPRINTF("Write diagnostic LED reg 0x" TARGET_FMT_plx " = %x\n", addr,
358 static CPUReadMemoryFunc *slavio_led_mem_read[3] = {
360 slavio_led_mem_readw,
364 static CPUWriteMemoryFunc *slavio_led_mem_write[3] = {
366 slavio_led_mem_writew,
370 static void slavio_misc_save(QEMUFile *f, void *opaque)
372 MiscState *s = opaque;
377 qemu_put_be32s(f, &tmp); /* ignored, was IRQ. */
378 qemu_put_8s(f, &s->config);
379 qemu_put_8s(f, &s->aux1);
380 qemu_put_8s(f, &s->aux2);
381 qemu_put_8s(f, &s->diag);
382 qemu_put_8s(f, &s->mctrl);
383 tmp8 = s->sysctrl & 0xff;
384 qemu_put_8s(f, &tmp8);
387 static int slavio_misc_load(QEMUFile *f, void *opaque, int version_id)
389 MiscState *s = opaque;
396 qemu_get_be32s(f, &tmp);
397 qemu_get_8s(f, &s->config);
398 qemu_get_8s(f, &s->aux1);
399 qemu_get_8s(f, &s->aux2);
400 qemu_get_8s(f, &s->diag);
401 qemu_get_8s(f, &s->mctrl);
402 qemu_get_8s(f, &tmp8);
403 s->sysctrl = (uint32_t)tmp8;
407 void *slavio_misc_init(target_phys_addr_t base, target_phys_addr_t power_base,
408 target_phys_addr_t aux1_base,
409 target_phys_addr_t aux2_base, qemu_irq irq,
415 s = qemu_mallocz(sizeof(MiscState));
420 /* 8 bit registers */
421 io = cpu_register_io_memory(0, slavio_misc_mem_read,
422 slavio_misc_mem_write, s);
424 cpu_register_physical_memory(base + MISC_CFG, MISC_SIZE, io);
426 cpu_register_physical_memory(base + MISC_DIAG, MISC_SIZE, io);
428 cpu_register_physical_memory(base + MISC_MDM, MISC_SIZE, io);
430 /* 16 bit registers */
431 io = cpu_register_io_memory(0, slavio_led_mem_read,
432 slavio_led_mem_write, s);
433 /* ss600mp diag LEDs */
434 cpu_register_physical_memory(base + MISC_LEDS, MISC_SIZE, io);
436 /* 32 bit registers */
437 io = cpu_register_io_memory(0, slavio_sysctrl_mem_read,
438 slavio_sysctrl_mem_write, s);
440 cpu_register_physical_memory(base + MISC_SYS, SYSCTRL_SIZE, io);
443 // AUX 1 (Misc System Functions)
445 io = cpu_register_io_memory(0, slavio_aux1_mem_read,
446 slavio_aux1_mem_write, s);
447 cpu_register_physical_memory(aux1_base, MISC_SIZE, io);
450 // AUX 2 (Software Powerdown Control)
452 io = cpu_register_io_memory(0, slavio_aux2_mem_read,
453 slavio_aux2_mem_write, s);
454 cpu_register_physical_memory(aux2_base, MISC_SIZE, io);
457 // Power management (APC) XXX: not a Slavio device
459 io = cpu_register_io_memory(0, apc_mem_read, apc_mem_write, s);
460 cpu_register_physical_memory(power_base, MISC_SIZE, io);
466 register_savevm("slavio_misc", base, 1, slavio_misc_save, slavio_misc_load,
468 qemu_register_reset(slavio_misc_reset, s);
469 slavio_misc_reset(s);