MAINTAINERS: Add include/hw/xtensa/mx_pic.h to the XTFPGA machine section
[qemu/kevin.git] / hw / m68k / q800-glue.c
blobf413b1599a2c7494f22a21667be490fc9af21f3c
1 /*
2 * QEMU q800 logic GLUE (General Logic Unit)
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
23 #include "qemu/osdep.h"
24 #include "cpu.h"
25 #include "hw/m68k/q800-glue.h"
26 #include "hw/boards.h"
27 #include "hw/irq.h"
28 #include "hw/nmi.h"
29 #include "hw/qdev-properties.h"
30 #include "migration/vmstate.h"
33 * The GLUE (General Logic Unit) is an Apple custom integrated circuit chip
34 * that performs a variety of functions (RAM management, clock generation, ...).
35 * The GLUE chip receives interrupt requests from various devices,
36 * assign priority to each, and asserts one or more interrupt line to the
37 * CPU.
41 * The GLUE logic on the Quadra 800 supports 2 different IRQ routing modes
42 * controlled from the VIA1 auxmode GPIO (port B bit 6) which are documented
43 * in NetBSD as follows:
45 * A/UX mode (Linux, NetBSD, auxmode GPIO low)
47 * Level 0: Spurious: ignored
48 * Level 1: Software
49 * Level 2: VIA2 (except ethernet, sound)
50 * Level 3: Ethernet
51 * Level 4: Serial (SCC)
52 * Level 5: Sound
53 * Level 6: VIA1
54 * Level 7: NMIs: parity errors, RESET button, YANCC error
56 * Classic mode (default: used by MacOS, A/UX 3.0.1, auxmode GPIO high)
58 * Level 0: Spurious: ignored
59 * Level 1: VIA1 (clock, ADB)
60 * Level 2: VIA2 (NuBus, SCSI)
61 * Level 3:
62 * Level 4: Serial (SCC)
63 * Level 5:
64 * Level 6:
65 * Level 7: Non-maskable: parity errors, RESET button
67 * Note that despite references to A/UX mode in Linux and NetBSD, at least
68 * A/UX 3.0.1 still uses Classic mode.
71 static void GLUE_set_irq(void *opaque, int irq, int level)
73 GLUEState *s = opaque;
74 int i;
76 if (s->auxmode) {
77 /* Classic mode */
78 switch (irq) {
79 case GLUE_IRQ_IN_VIA1:
80 irq = 0;
81 break;
83 case GLUE_IRQ_IN_VIA2:
84 irq = 1;
85 break;
87 case GLUE_IRQ_IN_SONIC:
88 /* Route to VIA2 instead */
89 qemu_set_irq(s->irqs[GLUE_IRQ_NUBUS_9], level);
90 return;
92 case GLUE_IRQ_IN_ESCC:
93 irq = 3;
94 break;
96 case GLUE_IRQ_IN_NMI:
97 irq = 6;
98 break;
100 case GLUE_IRQ_IN_ASC:
101 /* Route to VIA2 instead, negative edge-triggered */
102 qemu_set_irq(s->irqs[GLUE_IRQ_ASC], !level);
103 return;
105 default:
106 g_assert_not_reached();
108 } else {
109 /* A/UX mode */
110 switch (irq) {
111 case GLUE_IRQ_IN_VIA1:
112 irq = 5;
113 break;
115 case GLUE_IRQ_IN_VIA2:
116 irq = 1;
117 break;
119 case GLUE_IRQ_IN_SONIC:
120 irq = 2;
121 break;
123 case GLUE_IRQ_IN_ESCC:
124 irq = 3;
125 break;
127 case GLUE_IRQ_IN_NMI:
128 irq = 6;
129 break;
131 case GLUE_IRQ_IN_ASC:
132 irq = 4;
133 break;
135 default:
136 g_assert_not_reached();
140 if (level) {
141 s->ipr |= 1 << irq;
142 } else {
143 s->ipr &= ~(1 << irq);
146 for (i = 7; i >= 0; i--) {
147 if ((s->ipr >> i) & 1) {
148 m68k_set_irq_level(s->cpu, i + 1, i + 25);
149 return;
152 m68k_set_irq_level(s->cpu, 0, 0);
155 static void glue_auxmode_set_irq(void *opaque, int irq, int level)
157 GLUEState *s = GLUE(opaque);
159 s->auxmode = level;
162 static void glue_nmi(NMIState *n, int cpu_index, Error **errp)
164 GLUEState *s = GLUE(n);
166 /* Hold NMI active for 100ms */
167 GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 1);
168 timer_mod(s->nmi_release, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 100);
171 static void glue_nmi_release(void *opaque)
173 GLUEState *s = GLUE(opaque);
175 GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 0);
178 static void glue_reset_hold(Object *obj)
180 GLUEState *s = GLUE(obj);
182 s->ipr = 0;
183 s->auxmode = 0;
185 timer_del(s->nmi_release);
188 static const VMStateDescription vmstate_glue = {
189 .name = "q800-glue",
190 .version_id = 0,
191 .minimum_version_id = 0,
192 .fields = (VMStateField[]) {
193 VMSTATE_UINT8(ipr, GLUEState),
194 VMSTATE_UINT8(auxmode, GLUEState),
195 VMSTATE_TIMER_PTR(nmi_release, GLUEState),
196 VMSTATE_END_OF_LIST(),
201 * If the m68k CPU implemented its inbound irq lines as GPIO lines
202 * rather than via the m68k_set_irq_level() function we would not need
203 * this cpu link property and could instead provide outbound IRQ lines
204 * that the board could wire up to the CPU.
206 static Property glue_properties[] = {
207 DEFINE_PROP_LINK("cpu", GLUEState, cpu, TYPE_M68K_CPU, M68kCPU *),
208 DEFINE_PROP_END_OF_LIST(),
211 static void glue_finalize(Object *obj)
213 GLUEState *s = GLUE(obj);
215 timer_free(s->nmi_release);
218 static void glue_init(Object *obj)
220 DeviceState *dev = DEVICE(obj);
221 GLUEState *s = GLUE(dev);
223 qdev_init_gpio_in(dev, GLUE_set_irq, 8);
224 qdev_init_gpio_in_named(dev, glue_auxmode_set_irq, "auxmode", 1);
226 qdev_init_gpio_out(dev, s->irqs, 2);
228 /* NMI release timer */
229 s->nmi_release = timer_new_ms(QEMU_CLOCK_VIRTUAL, glue_nmi_release, s);
232 static void glue_class_init(ObjectClass *klass, void *data)
234 DeviceClass *dc = DEVICE_CLASS(klass);
235 ResettableClass *rc = RESETTABLE_CLASS(klass);
236 NMIClass *nc = NMI_CLASS(klass);
238 dc->vmsd = &vmstate_glue;
239 device_class_set_props(dc, glue_properties);
240 rc->phases.hold = glue_reset_hold;
241 nc->nmi_monitor_handler = glue_nmi;
244 static const TypeInfo glue_info_types[] = {
246 .name = TYPE_GLUE,
247 .parent = TYPE_SYS_BUS_DEVICE,
248 .instance_size = sizeof(GLUEState),
249 .instance_init = glue_init,
250 .instance_finalize = glue_finalize,
251 .class_init = glue_class_init,
252 .interfaces = (InterfaceInfo[]) {
253 { TYPE_NMI },
259 DEFINE_TYPES(glue_info_types)