2 * QEMU Sparc SBI interrupt controller emulation
4 * Based on slavio_intctl, copyright (c) 2003-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 #define DPRINTF(fmt, ...) \
34 do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
36 #define DPRINTF(fmt, ...)
43 typedef struct SBIState
{
45 uint32_t regs
[SBI_NREGS
];
46 uint32_t intreg_pending
[MAX_CPUS
];
47 qemu_irq cpu_irqs
[MAX_CPUS
];
48 uint32_t pil_out
[MAX_CPUS
];
51 #define SBI_SIZE (SBI_NREGS * 4)
53 static void sbi_set_irq(void *opaque
, int irq
, int level
)
57 static uint32_t sbi_mem_readl(void *opaque
, target_phys_addr_t addr
)
68 DPRINTF("read system reg 0x" TARGET_FMT_plx
" = %x\n", addr
, ret
);
73 static void sbi_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
79 DPRINTF("write system reg 0x" TARGET_FMT_plx
" = %x\n", addr
, val
);
87 static CPUReadMemoryFunc
*sbi_mem_read
[3] = {
93 static CPUWriteMemoryFunc
*sbi_mem_write
[3] = {
99 static void sbi_save(QEMUFile
*f
, void *opaque
)
101 SBIState
*s
= opaque
;
104 for (i
= 0; i
< MAX_CPUS
; i
++) {
105 qemu_put_be32s(f
, &s
->intreg_pending
[i
]);
109 static int sbi_load(QEMUFile
*f
, void *opaque
, int version_id
)
111 SBIState
*s
= opaque
;
117 for (i
= 0; i
< MAX_CPUS
; i
++) {
118 qemu_get_be32s(f
, &s
->intreg_pending
[i
]);
124 static void sbi_reset(void *opaque
)
126 SBIState
*s
= opaque
;
129 for (i
= 0; i
< MAX_CPUS
; i
++) {
130 s
->intreg_pending
[i
] = 0;
134 DeviceState
*sbi_init(target_phys_addr_t addr
, qemu_irq
**parent_irq
)
140 dev
= qdev_create(NULL
, "sbi");
143 s
= sysbus_from_qdev(dev
);
145 for (i
= 0; i
< MAX_CPUS
; i
++) {
146 sysbus_connect_irq(s
, i
, *parent_irq
[i
]);
149 sysbus_mmio_map(s
, 0, addr
);
154 static void sbi_init1(SysBusDevice
*dev
)
156 SBIState
*s
= FROM_SYSBUS(SBIState
, dev
);
160 qdev_init_gpio_in(&dev
->qdev
, sbi_set_irq
, 32 + MAX_CPUS
);
161 for (i
= 0; i
< MAX_CPUS
; i
++) {
162 sysbus_init_irq(dev
, &s
->cpu_irqs
[i
]);
165 sbi_io_memory
= cpu_register_io_memory(sbi_mem_read
, sbi_mem_write
, s
);
166 sysbus_init_mmio(dev
, SBI_SIZE
, sbi_io_memory
);
168 register_savevm("sbi", -1, 1, sbi_save
, sbi_load
, s
);
169 qemu_register_reset(sbi_reset
, s
);
173 static SysBusDeviceInfo sbi_info
= {
176 .qdev
.size
= sizeof(SBIState
),
179 static void sbi_register_devices(void)
181 sysbus_register_withprop(&sbi_info
);
184 device_init(sbi_register_devices
)