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
23 #include "qemu/osdep.h"
25 #include "hw/m68k/q800-glue.h"
26 #include "hw/boards.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
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
49 * Level 2: VIA2 (except ethernet, sound)
51 * Level 4: Serial (SCC)
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)
62 * Level 4: Serial (SCC)
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
;
79 case GLUE_IRQ_IN_VIA1
:
83 case GLUE_IRQ_IN_VIA2
:
87 case GLUE_IRQ_IN_SONIC
:
88 /* Route to VIA2 instead */
89 qemu_set_irq(s
->irqs
[GLUE_IRQ_NUBUS_9
], level
);
92 case GLUE_IRQ_IN_ESCC
:
100 case GLUE_IRQ_IN_ASC
:
101 /* Route to VIA2 instead, negative edge-triggered */
102 qemu_set_irq(s
->irqs
[GLUE_IRQ_ASC
], !level
);
106 g_assert_not_reached();
111 case GLUE_IRQ_IN_VIA1
:
115 case GLUE_IRQ_IN_VIA2
:
119 case GLUE_IRQ_IN_SONIC
:
123 case GLUE_IRQ_IN_ESCC
:
127 case GLUE_IRQ_IN_NMI
:
131 case GLUE_IRQ_IN_ASC
:
136 g_assert_not_reached();
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);
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
);
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
);
185 timer_del(s
->nmi_release
);
188 static const VMStateDescription vmstate_glue
= {
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
[] = {
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
[]) {
259 DEFINE_TYPES(glue_info_types
)