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
:
101 g_assert_not_reached();
106 case GLUE_IRQ_IN_VIA1
:
110 case GLUE_IRQ_IN_VIA2
:
114 case GLUE_IRQ_IN_SONIC
:
118 case GLUE_IRQ_IN_ESCC
:
122 case GLUE_IRQ_IN_NMI
:
127 g_assert_not_reached();
134 s
->ipr
&= ~(1 << irq
);
137 for (i
= 7; i
>= 0; i
--) {
138 if ((s
->ipr
>> i
) & 1) {
139 m68k_set_irq_level(s
->cpu
, i
+ 1, i
+ 25);
143 m68k_set_irq_level(s
->cpu
, 0, 0);
146 static void glue_auxmode_set_irq(void *opaque
, int irq
, int level
)
148 GLUEState
*s
= GLUE(opaque
);
153 static void glue_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
155 GLUEState
*s
= GLUE(n
);
157 /* Hold NMI active for 100ms */
158 GLUE_set_irq(s
, GLUE_IRQ_IN_NMI
, 1);
159 timer_mod(s
->nmi_release
, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + 100);
162 static void glue_nmi_release(void *opaque
)
164 GLUEState
*s
= GLUE(opaque
);
166 GLUE_set_irq(s
, GLUE_IRQ_IN_NMI
, 0);
169 static void glue_reset(DeviceState
*dev
)
171 GLUEState
*s
= GLUE(dev
);
176 timer_del(s
->nmi_release
);
179 static const VMStateDescription vmstate_glue
= {
182 .minimum_version_id
= 0,
183 .fields
= (VMStateField
[]) {
184 VMSTATE_UINT8(ipr
, GLUEState
),
185 VMSTATE_UINT8(auxmode
, GLUEState
),
186 VMSTATE_TIMER_PTR(nmi_release
, GLUEState
),
187 VMSTATE_END_OF_LIST(),
192 * If the m68k CPU implemented its inbound irq lines as GPIO lines
193 * rather than via the m68k_set_irq_level() function we would not need
194 * this cpu link property and could instead provide outbound IRQ lines
195 * that the board could wire up to the CPU.
197 static Property glue_properties
[] = {
198 DEFINE_PROP_LINK("cpu", GLUEState
, cpu
, TYPE_M68K_CPU
, M68kCPU
*),
199 DEFINE_PROP_END_OF_LIST(),
202 static void glue_finalize(Object
*obj
)
204 GLUEState
*s
= GLUE(obj
);
206 timer_free(s
->nmi_release
);
209 static void glue_init(Object
*obj
)
211 DeviceState
*dev
= DEVICE(obj
);
212 GLUEState
*s
= GLUE(dev
);
214 qdev_init_gpio_in(dev
, GLUE_set_irq
, 8);
215 qdev_init_gpio_in_named(dev
, glue_auxmode_set_irq
, "auxmode", 1);
217 qdev_init_gpio_out(dev
, s
->irqs
, 1);
219 /* NMI release timer */
220 s
->nmi_release
= timer_new_ms(QEMU_CLOCK_VIRTUAL
, glue_nmi_release
, s
);
223 static void glue_class_init(ObjectClass
*klass
, void *data
)
225 DeviceClass
*dc
= DEVICE_CLASS(klass
);
226 NMIClass
*nc
= NMI_CLASS(klass
);
228 dc
->vmsd
= &vmstate_glue
;
229 dc
->reset
= glue_reset
;
230 device_class_set_props(dc
, glue_properties
);
231 nc
->nmi_monitor_handler
= glue_nmi
;
234 static const TypeInfo glue_info_types
[] = {
237 .parent
= TYPE_SYS_BUS_DEVICE
,
238 .instance_size
= sizeof(GLUEState
),
239 .instance_init
= glue_init
,
240 .instance_finalize
= glue_finalize
,
241 .class_init
= glue_class_init
,
242 .interfaces
= (InterfaceInfo
[]) {
249 DEFINE_TYPES(glue_info_types
)