blob: c4adc09fa9fae26ccc4904b9b977e03d60d77de5 [file] [log] [blame]
blueswir17d858922007-12-28 20:57:43 +00001/*
2 * QEMU Sparc SBI interrupt controller emulation
3 *
4 * Based on slavio_intctl, copyright (c) 2003-2005 Fabrice Bellard
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
Blue Swirl7fc06732009-07-21 19:25:59 +000024
Blue Swirl7fc06732009-07-21 19:25:59 +000025#include "sysbus.h"
blueswir17d858922007-12-28 20:57:43 +000026
27//#define DEBUG_IRQ
28
29#ifdef DEBUG_IRQ
Blue Swirl001faf32009-05-13 17:53:17 +000030#define DPRINTF(fmt, ...) \
31 do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
blueswir17d858922007-12-28 20:57:43 +000032#else
Blue Swirl001faf32009-05-13 17:53:17 +000033#define DPRINTF(fmt, ...)
blueswir17d858922007-12-28 20:57:43 +000034#endif
35
36#define MAX_CPUS 16
37
38#define SBI_NREGS 16
39
40typedef struct SBIState {
Blue Swirl7fc06732009-07-21 19:25:59 +000041 SysBusDevice busdev;
blueswir17d858922007-12-28 20:57:43 +000042 uint32_t regs[SBI_NREGS];
43 uint32_t intreg_pending[MAX_CPUS];
Blue Swirl7fc06732009-07-21 19:25:59 +000044 qemu_irq cpu_irqs[MAX_CPUS];
blueswir17d858922007-12-28 20:57:43 +000045 uint32_t pil_out[MAX_CPUS];
46} SBIState;
47
48#define SBI_SIZE (SBI_NREGS * 4)
blueswir17d858922007-12-28 20:57:43 +000049
blueswir17d858922007-12-28 20:57:43 +000050static void sbi_set_irq(void *opaque, int irq, int level)
51{
52}
53
Anthony Liguoric227f092009-10-01 16:12:16 -050054static uint32_t sbi_mem_readl(void *opaque, target_phys_addr_t addr)
blueswir17d858922007-12-28 20:57:43 +000055{
56 SBIState *s = opaque;
57 uint32_t saddr, ret;
58
blueswir1e64d7d52008-12-02 17:47:02 +000059 saddr = addr >> 2;
blueswir17d858922007-12-28 20:57:43 +000060 switch (saddr) {
61 default:
62 ret = s->regs[saddr];
63 break;
64 }
65 DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
66
67 return ret;
68}
69
Anthony Liguoric227f092009-10-01 16:12:16 -050070static void sbi_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
blueswir17d858922007-12-28 20:57:43 +000071{
72 SBIState *s = opaque;
73 uint32_t saddr;
74
blueswir1e64d7d52008-12-02 17:47:02 +000075 saddr = addr >> 2;
blueswir17d858922007-12-28 20:57:43 +000076 DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
77 switch (saddr) {
78 default:
79 s->regs[saddr] = val;
80 break;
81 }
82}
83
Blue Swirld60efc62009-08-25 18:29:31 +000084static CPUReadMemoryFunc * const sbi_mem_read[3] = {
blueswir17c560452008-01-01 17:06:38 +000085 NULL,
86 NULL,
blueswir17d858922007-12-28 20:57:43 +000087 sbi_mem_readl,
88};
89
Blue Swirld60efc62009-08-25 18:29:31 +000090static CPUWriteMemoryFunc * const sbi_mem_write[3] = {
blueswir17c560452008-01-01 17:06:38 +000091 NULL,
92 NULL,
blueswir17d858922007-12-28 20:57:43 +000093 sbi_mem_writel,
94};
95
Blue Swirlb280fcd2009-10-24 20:08:43 +000096static const VMStateDescription vmstate_sbi = {
97 .name ="sbi",
98 .version_id = 1,
99 .minimum_version_id = 1,
100 .minimum_version_id_old = 1,
101 .fields = (VMStateField []) {
102 VMSTATE_UINT32_ARRAY(intreg_pending, SBIState, MAX_CPUS),
103 VMSTATE_END_OF_LIST()
blueswir17d858922007-12-28 20:57:43 +0000104 }
Blue Swirlb280fcd2009-10-24 20:08:43 +0000105};
blueswir17d858922007-12-28 20:57:43 +0000106
Blue Swirlb280fcd2009-10-24 20:08:43 +0000107static void sbi_reset(DeviceState *d)
blueswir17d858922007-12-28 20:57:43 +0000108{
Blue Swirlb280fcd2009-10-24 20:08:43 +0000109 SBIState *s = container_of(d, SBIState, busdev.qdev);
blueswir17d858922007-12-28 20:57:43 +0000110 unsigned int i;
111
112 for (i = 0; i < MAX_CPUS; i++) {
113 s->intreg_pending[i] = 0;
114 }
blueswir17d858922007-12-28 20:57:43 +0000115}
116
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200117static int sbi_init1(SysBusDevice *dev)
Blue Swirl7fc06732009-07-21 19:25:59 +0000118{
119 SBIState *s = FROM_SYSBUS(SBIState, dev);
120 int sbi_io_memory;
121 unsigned int i;
122
123 qdev_init_gpio_in(&dev->qdev, sbi_set_irq, 32 + MAX_CPUS);
124 for (i = 0; i < MAX_CPUS; i++) {
125 sysbus_init_irq(dev, &s->cpu_irqs[i]);
blueswir17d858922007-12-28 20:57:43 +0000126 }
127
Avi Kivity1eed09c2009-06-14 11:38:51 +0300128 sbi_io_memory = cpu_register_io_memory(sbi_mem_read, sbi_mem_write, s);
Blue Swirl7fc06732009-07-21 19:25:59 +0000129 sysbus_init_mmio(dev, SBI_SIZE, sbi_io_memory);
blueswir17d858922007-12-28 20:57:43 +0000130
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200131 return 0;
blueswir17d858922007-12-28 20:57:43 +0000132}
Blue Swirl7fc06732009-07-21 19:25:59 +0000133
134static SysBusDeviceInfo sbi_info = {
135 .init = sbi_init1,
136 .qdev.name = "sbi",
137 .qdev.size = sizeof(SBIState),
Blue Swirlb280fcd2009-10-24 20:08:43 +0000138 .qdev.vmsd = &vmstate_sbi,
139 .qdev.reset = sbi_reset,
Blue Swirl7fc06732009-07-21 19:25:59 +0000140};
141
142static void sbi_register_devices(void)
143{
144 sysbus_register_withprop(&sbi_info);
145}
146
147device_init(sbi_register_devices)