2 * QEMU Sparc Sun4c 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
27 //#define DEBUG_IRQ_COUNT
31 #define DPRINTF(fmt, args...) \
32 do { printf("IRQ: " fmt , ##args); } while (0)
34 #define DPRINTF(fmt, args...)
38 * Registers of interrupt controller in sun4c.
44 typedef struct Sun4c_INTCTLState
{
45 #ifdef DEBUG_IRQ_COUNT
49 const uint32_t *intbit_to_level
;
57 static void sun4c_check_interrupts(void *opaque
);
59 static uint32_t sun4c_intctl_mem_readb(void *opaque
, target_phys_addr_t addr
)
61 Sun4c_INTCTLState
*s
= opaque
;
65 DPRINTF("read reg 0x" TARGET_FMT_plx
" = %x\n", addr
, ret
);
70 static void sun4c_intctl_mem_writeb(void *opaque
, target_phys_addr_t addr
,
73 Sun4c_INTCTLState
*s
= opaque
;
75 DPRINTF("write reg 0x" TARGET_FMT_plx
" = %x\n", addr
, val
);
78 sun4c_check_interrupts(s
);
81 static CPUReadMemoryFunc
*sun4c_intctl_mem_read
[3] = {
82 sun4c_intctl_mem_readb
,
87 static CPUWriteMemoryFunc
*sun4c_intctl_mem_write
[3] = {
88 sun4c_intctl_mem_writeb
,
93 void sun4c_pic_info(Monitor
*mon
, void *opaque
)
95 Sun4c_INTCTLState
*s
= opaque
;
97 monitor_printf(mon
, "master: pending 0x%2.2x, enabled 0x%2.2x\n",
101 void sun4c_irq_info(Monitor
*mon
, void *opaque
)
103 #ifndef DEBUG_IRQ_COUNT
104 monitor_printf(mon
, "irq statistic code not compiled.\n");
106 Sun4c_INTCTLState
*s
= opaque
;
109 monitor_printf(mon
, "IRQ statistics:\n");
110 count
= s
->irq_count
[i
];
112 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
, count
);
116 static const uint32_t intbit_to_level
[] = { 0, 1, 4, 6, 8, 10, 0, 14, };
118 static void sun4c_check_interrupts(void *opaque
)
120 Sun4c_INTCTLState
*s
= opaque
;
121 uint32_t pil_pending
;
124 DPRINTF("pending %x disabled %x\n", pending
, s
->intregm_disabled
);
126 if (s
->pending
&& !(s
->reg
& 0x80000000)) {
127 for (i
= 0; i
< 8; i
++) {
128 if (s
->pending
& (1 << i
))
129 pil_pending
|= 1 << intbit_to_level
[i
];
133 for (i
= 0; i
< MAX_PILS
; i
++) {
134 if (pil_pending
& (1 << i
)) {
135 if (!(s
->pil_out
& (1 << i
)))
136 qemu_irq_raise(s
->cpu_irqs
[i
]);
138 if (s
->pil_out
& (1 << i
))
139 qemu_irq_lower(s
->cpu_irqs
[i
]);
142 s
->pil_out
= pil_pending
;
146 * "irq" here is the bit number in the system interrupt register
148 static void sun4c_set_irq(void *opaque
, int irq
, int level
)
150 Sun4c_INTCTLState
*s
= opaque
;
151 uint32_t mask
= 1 << irq
;
152 uint32_t pil
= intbit_to_level
[irq
];
154 DPRINTF("Set irq %d -> pil %d level %d\n", irq
, pil
,
158 #ifdef DEBUG_IRQ_COUNT
165 sun4c_check_interrupts(s
);
169 static void sun4c_intctl_save(QEMUFile
*f
, void *opaque
)
171 Sun4c_INTCTLState
*s
= opaque
;
173 qemu_put_8s(f
, &s
->reg
);
174 qemu_put_8s(f
, &s
->pending
);
177 static int sun4c_intctl_load(QEMUFile
*f
, void *opaque
, int version_id
)
179 Sun4c_INTCTLState
*s
= opaque
;
184 qemu_get_8s(f
, &s
->reg
);
185 qemu_get_8s(f
, &s
->pending
);
186 sun4c_check_interrupts(s
);
191 static void sun4c_intctl_reset(void *opaque
)
193 Sun4c_INTCTLState
*s
= opaque
;
197 sun4c_check_interrupts(s
);
200 void *sun4c_intctl_init(target_phys_addr_t addr
, qemu_irq
**irq
,
201 qemu_irq
*parent_irq
)
203 int sun4c_intctl_io_memory
;
204 Sun4c_INTCTLState
*s
;
206 s
= qemu_mallocz(sizeof(Sun4c_INTCTLState
));
208 sun4c_intctl_io_memory
= cpu_register_io_memory(0, sun4c_intctl_mem_read
,
209 sun4c_intctl_mem_write
, s
);
210 cpu_register_physical_memory(addr
, INTCTL_SIZE
, sun4c_intctl_io_memory
);
211 s
->cpu_irqs
= parent_irq
;
213 register_savevm("sun4c_intctl", addr
, 1, sun4c_intctl_save
,
214 sun4c_intctl_load
, s
);
216 qemu_register_reset(sun4c_intctl_reset
, s
);
217 *irq
= qemu_allocate_irqs(sun4c_set_irq
, s
, 8);
219 sun4c_intctl_reset(s
);