xref: /netbsd-src/sys/arch/mac68k/nubus/grf_nubus.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: grf_nubus.c,v 1.78 2016/02/28 19:39:27 rjs Exp $	*/
2 
3 /*
4  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * Device-specific routines for handling Nubus-based video cards.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: grf_nubus.c,v 1.78 2016/02/28 19:39:27 rjs Exp $");
34 
35 #include <sys/param.h>
36 
37 #include <sys/device.h>
38 #include <sys/ioctl.h>
39 #include <sys/file.h>
40 #include <sys/malloc.h>
41 #include <sys/mman.h>
42 #include <sys/proc.h>
43 #include <sys/systm.h>
44 
45 #include <machine/bus.h>
46 #include <machine/cpu.h>
47 #include <machine/grfioctl.h>
48 #include <machine/viareg.h>
49 
50 #include <mac68k/nubus/nubus.h>
51 #include <mac68k/dev/grfvar.h>
52 
53 static void	load_image_data(void *, struct image_data *);
54 
55 static void	grfmv_intr_generic_write1(void *);
56 static void	grfmv_intr_generic_write4(void *);
57 static void	grfmv_intr_generic_or4(void *);
58 
59 static void	grfmv_intr_cb264(void *);
60 static void	grfmv_intr_cb364(void *);
61 static void	grfmv_intr_cmax(void *);
62 static void	grfmv_intr_cti(void *);
63 static void	grfmv_intr_radius(void *);
64 static void	grfmv_intr_radius24(void *);
65 static void	grfmv_intr_supermacgfx(void *);
66 static void	grfmv_intr_lapis(void *);
67 static void	grfmv_intr_formac(void *);
68 static void	grfmv_intr_vimage(void *);
69 static void	grfmv_intr_gvimage(void *);
70 static void	grfmv_intr_radius_gsc(void *);
71 static void	grfmv_intr_radius_gx(void *);
72 static void	grfmv_intr_relax_200(void *);
73 static void	grfmv_intr_mvc(void *);
74 static void	grfmv_intr_viltro_340(void *);
75 
76 static int	grfmv_mode(struct grf_softc *, int, void *);
77 static int	grfmv_match(device_t, cfdata_t, void *);
78 static void	grfmv_attach(device_t, device_t, void *);
79 
80 CFATTACH_DECL_NEW(macvid, sizeof(struct grfbus_softc),
81     grfmv_match, grfmv_attach, NULL, NULL);
82 
83 static void
84 load_image_data(void *	data, struct image_data *image)
85 {
86 	char *d = (char*)data;
87 
88 	memcpy(&image->size,       d     , 4);
89 	memcpy(&image->offset,     d +  4, 4);
90 	memcpy(&image->rowbytes,   d +  8, 2);
91 	memcpy(&image->top,        d + 10, 2);
92 	memcpy(&image->left,       d + 12, 2);
93 	memcpy(&image->bottom,     d + 14, 2);
94 	memcpy(&image->right,      d + 16, 2);
95 	memcpy(&image->version,    d + 18, 2);
96 	memcpy(&image->packType,   d + 20, 2);
97 	memcpy(&image->packSize,   d + 22, 4);
98 	memcpy(&image->hRes,       d + 26, 4);
99 	memcpy(&image->vRes,       d + 30, 4);
100 	memcpy(&image->pixelType,  d + 34, 2);
101 	memcpy(&image->pixelSize,  d + 36, 2);
102 	memcpy(&image->cmpCount,   d + 38, 2);
103 	memcpy(&image->cmpSize,    d + 40, 2);
104 	memcpy(&image->planeBytes, d + 42, 4);
105 }
106 
107 
108 static int
109 grfmv_match(device_t parent, cfdata_t cf, void *aux)
110 {
111 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
112 
113 	if (na->category != NUBUS_CATEGORY_DISPLAY)
114 		return 0;
115 
116 	if (na->type != NUBUS_TYPE_VIDEO)
117 		return 0;
118 
119 	if (na->drsw != NUBUS_DRSW_APPLE)
120 		return 0;
121 
122 	/*
123 	 * If we've gotten this far, then we're dealing with a real-live
124 	 * Apple QuickDraw-compatible display card resource.  Now, how to
125 	 * determine that this is an active resource???  Dunno.  But we'll
126 	 * proceed like it is.
127 	 */
128 
129 	return 1;
130 }
131 
132 static void
133 grfmv_attach(device_t parent, device_t self, void *aux)
134 {
135 	struct grfbus_softc *sc = device_private(self);
136 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
137 	struct image_data image_store, image;
138 	struct grfmode *gm;
139 	char cardname[CARD_NAME_LEN];
140 	nubus_dirent dirent;
141 	nubus_dir dir, mode_dir;
142 	int mode;
143 
144 	memcpy(&sc->sc_slot, na->fmt, sizeof(nubus_slot));
145 
146 	sc->sc_dev = self;
147 	sc->sc_tag = na->na_tag;
148 	sc->card_id = na->drhw;
149 	sc->sc_basepa = (bus_addr_t)NUBUS_SLOT2PA(na->slot);
150 	sc->sc_fbofs = 0;
151 
152 	if (bus_space_map(sc->sc_tag, sc->sc_basepa, NBMEMSIZE,
153 	    0, &sc->sc_handle)) {
154 		printf(": grfmv_attach: failed to map slot %d\n", na->slot);
155 		return;
156 	}
157 
158 	nubus_get_main_dir(&sc->sc_slot, &dir);
159 
160 	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
161 	    &sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0) {
162 bad:
163 		bus_space_unmap(sc->sc_tag, sc->sc_handle, NBMEMSIZE);
164 		return;
165 	}
166 
167 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
168 
169 	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
170 	    &sc->sc_slot, &sc->board_dir, NUBUS_RSRC_TYPE, &dirent) <= 0)
171 		if ((na->rsrcid != 128) ||
172 		    (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
173 		    &sc->sc_slot, &dir, 129, &dirent) <= 0))
174 			goto bad;
175 
176 	mode = NUBUS_RSRC_FIRSTMODE;
177 	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
178 	    &sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
179 		printf(": probe failed to get board rsrc.\n");
180 		goto bad;
181 	}
182 
183 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
184 
185 	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
186 	    &sc->sc_slot, &mode_dir, VID_PARAMS, &dirent) <= 0) {
187 		printf(": probe failed to get mode dir.\n");
188 		goto bad;
189 	}
190 
191 	if (nubus_get_ind_data(sc->sc_tag, sc->sc_handle, &sc->sc_slot,
192 	    &dirent, (void *)&image_store, sizeof(struct image_data)) <= 0) {
193 		printf(": probe failed to get indirect mode data.\n");
194 		goto bad;
195 	}
196 
197 	/* Need to load display info (and driver?), etc... (?) */
198 
199 	load_image_data((void *)&image_store, &image);
200 
201 	gm = &sc->curr_mode;
202 	gm->mode_id = mode;
203 	gm->ptype = image.pixelType;
204 	gm->psize = image.pixelSize;
205 	gm->width = image.right - image.left;
206 	gm->height = image.bottom - image.top;
207 	gm->rowbytes = image.rowbytes;
208 	gm->hres = image.hRes;
209 	gm->vres = image.vRes;
210 	gm->fbsize = gm->height * gm->rowbytes;
211 	gm->fbbase = (void *)(sc->sc_handle.base);	/* XXX evil hack */
212 	gm->fboff = image.offset;
213 
214 	strncpy(cardname, nubus_get_card_name(sc->sc_tag, sc->sc_handle,
215 	    &sc->sc_slot), CARD_NAME_LEN);
216 	cardname[CARD_NAME_LEN-1] = '\0';
217 	printf(": %s\n", cardname);
218 
219 	if (sc->card_id == NUBUS_DRHW_TFB) {
220 		/*
221 		 * This is the Toby card, but apparently some manufacturers
222 		 * (like Cornerstone) didn't bother to get/use their own
223 		 * value here, even though the cards are different, so we
224 		 * try to differentiate here.
225 		 */
226 		if (strncmp(cardname, "Samsung 768", 11) == 0)
227 			sc->card_id = NUBUS_DRHW_SAM768;
228 		else if (strncmp(cardname, "Toby frame", 10) != 0)
229 			printf("%s: This display card pretends to be a TFB!\n",
230 			    device_xname(self));
231 	}
232 
233 	switch (sc->card_id) {
234 	case NUBUS_DRHW_TFB:
235 	case NUBUS_DRHW_M2HRVC:
236 	case NUBUS_DRHW_PVC:
237 		sc->cli_offset = 0xa0000;
238 		sc->cli_value = 0;
239 		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
240 		break;
241 	case NUBUS_DRHW_WVC:
242 		sc->cli_offset = 0xa00000;
243 		sc->cli_value = 0;
244 		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
245 		break;
246 	case NUBUS_DRHW_COLORMAX:
247 		add_nubus_intr(na->slot, grfmv_intr_cmax, sc);
248 		break;
249 	case NUBUS_DRHW_SE30:
250 		/* Do nothing--SE/30 interrupts are disabled */
251 		break;
252 	case NUBUS_DRHW_MDC:
253 		sc->cli_offset = 0x200148;
254 		sc->cli_value = 1;
255 		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
256 
257 		/* Enable interrupts; to disable, write 0x7 to this location */
258 		bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x20013C, 5);
259 		break;
260 	case NUBUS_DRHW_CB264:
261 		add_nubus_intr(na->slot, grfmv_intr_cb264, sc);
262 		break;
263 	case NUBUS_DRHW_CB364:
264 		add_nubus_intr(na->slot, grfmv_intr_cb364, sc);
265 		break;
266 	case NUBUS_DRHW_RPC8:
267 		sc->cli_offset = 0xfdff8f;
268 		sc->cli_value = 0xff;
269 		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
270 		break;
271 	case NUBUS_DRHW_RPC8XJ:
272 		sc->cli_value = 0x66;
273 		add_nubus_intr(na->slot, grfmv_intr_radius, sc);
274 		break;
275 	case NUBUS_DRHW_RPC24X:
276 	case NUBUS_DRHW_BOOGIE:
277 		sc->cli_value = 0x64;
278 		add_nubus_intr(na->slot, grfmv_intr_radius, sc);
279 		break;
280 	case NUBUS_DRHW_RPC24XP:
281 		add_nubus_intr(na->slot, grfmv_intr_radius24, sc);
282 		break;
283 	case NUBUS_DRHW_RADGSC:
284 		add_nubus_intr(na->slot, grfmv_intr_radius_gsc, sc);
285 		break;
286 	case NUBUS_DRHW_RDCGX:
287 		add_nubus_intr(na->slot, grfmv_intr_radius_gx, sc);
288 		break;
289 	case NUBUS_DRHW_FIILX:
290 	case NUBUS_DRHW_FIISXDSP:
291 	case NUBUS_DRHW_FUTURASX:
292 		sc->cli_offset = 0xf05000;
293 		sc->cli_value = 0x80;
294 		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
295 		break;
296 	case NUBUS_DRHW_SAM768:
297 		add_nubus_intr(na->slot, grfmv_intr_cti, sc);
298 		break;
299 	case NUBUS_DRHW_SUPRGFX:
300 		add_nubus_intr(na->slot, grfmv_intr_supermacgfx, sc);
301 		break;
302 	case NUBUS_DRHW_SPECTRM8:
303 		sc->cli_offset = 0x0de178;
304 		sc->cli_value = 0x80;
305 		add_nubus_intr(na->slot, grfmv_intr_generic_or4, sc);
306 		break;
307 	case NUBUS_DRHW_LAPIS:
308 		add_nubus_intr(na->slot, grfmv_intr_lapis, sc);
309 		break;
310 	case NUBUS_DRHW_RELAX200:
311 		add_nubus_intr(na->slot, grfmv_intr_relax_200, sc);
312 		break;
313 	case NUBUS_DRHW_BAER:
314 	case NUBUS_DRHW_FORMAC:
315 		add_nubus_intr(na->slot, grfmv_intr_formac, sc);
316 		break;
317 	case NUBUS_DRHW_ROPS24LXI:
318 	case NUBUS_DRHW_ROPS24XLTV:
319 	case NUBUS_DRHW_ROPS24MXTV:
320 		sc->cli_offset = 0xfb0010;
321 		sc->cli_value = 0x00;
322 		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
323 		break;
324 	case NUBUS_DRHW_ROPSPPGT:
325 		sc->cli_offset = 0xf50010;
326 		sc->cli_value = 0x02;
327 		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
328 		break;
329 	case NUBUS_DRHW_VIMAGE:
330 		add_nubus_intr(na->slot, grfmv_intr_vimage, sc);
331 		break;
332 	case NUBUS_DRHW_GVIMAGE:
333 		add_nubus_intr(na->slot, grfmv_intr_gvimage, sc);
334 		break;
335 	case NUBUS_DRHW_MC2124NB:
336 		sc->cli_offset = 0xfd1000;
337 		sc->cli_value = 0x00;
338 		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
339 		break;
340 	case NUBUS_DRHW_MICRON:
341 		sc->cli_offset = 0xa00014;
342 		sc->cli_value = 0;
343 		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
344 		break;
345 	case NUBUS_DRHW_MVC:
346 		add_nubus_intr(na->slot, grfmv_intr_mvc, sc);
347 		break;
348 	case NUBUS_DRHW_VILTRO340:
349 		add_nubus_intr(na->slot, grfmv_intr_viltro_340, sc);
350 		break;
351 	default:
352 		printf("%s: Unknown video card ID 0x%x --",
353 		    device_xname(self), sc->card_id);
354 		printf(" Not installing interrupt routine.\n");
355 		break;
356 	}
357 
358 	/* Perform common video attachment. */
359 	grf_establish(sc, &sc->sc_slot, grfmv_mode);
360 }
361 
362 static int
363 grfmv_mode(struct grf_softc *gp, int cmd, void *arg)
364 {
365 	switch (cmd) {
366 	case GM_GRFON:
367 	case GM_GRFOFF:
368 		return 0;
369 	case GM_CURRMODE:
370 		break;
371 	case GM_NEWMODE:
372 		break;
373 	case GM_LISTMODES:
374 		break;
375 	}
376 	return EINVAL;
377 }
378 
379 /* Interrupt handlers... */
380 /*
381  * Generic routine to clear interrupts for cards where it simply takes
382  * a MOV.B to clear the interrupt.  The offset and value of this byte
383  * varies between cards.
384  */
385 /*ARGSUSED*/
386 static void
387 grfmv_intr_generic_write1(void *vsc)
388 {
389 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
390 
391 	bus_space_write_1(sc->sc_tag, sc->sc_handle,
392 	    sc->cli_offset, (u_int8_t)sc->cli_value);
393 }
394 
395 /*
396  * Generic routine to clear interrupts for cards where it simply takes
397  * a MOV.L to clear the interrupt.  The offset and value of this byte
398  * varies between cards.
399  */
400 /*ARGSUSED*/
401 static void
402 grfmv_intr_generic_write4(void *vsc)
403 {
404 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
405 
406 	bus_space_write_4(sc->sc_tag, sc->sc_handle,
407 	    sc->cli_offset, sc->cli_value);
408 }
409 
410 /*
411  * Generic routine to clear interrupts for cards where it simply takes
412  * an OR.L to clear the interrupt.  The offset and value of this byte
413  * varies between cards.
414  */
415 /*ARGSUSED*/
416 static void
417 grfmv_intr_generic_or4(void *vsc)
418 {
419 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
420 	unsigned long	scratch;
421 
422 	scratch = bus_space_read_4(sc->sc_tag, sc->sc_handle, sc->cli_offset);
423 	scratch |= 0x80;
424 	bus_space_write_4(sc->sc_tag, sc->sc_handle, sc->cli_offset, scratch);
425 }
426 
427 /*
428  * Routine to clear interrupts for the Radius PrecisionColor 8xj card.
429  */
430 /*ARGSUSED*/
431 static void
432 grfmv_intr_radius(void *vsc)
433 {
434 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
435 	u_int8_t c;
436 
437 	c = sc->cli_value;
438 
439 	c |= 0x80;
440 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
441 	c &= 0x7f;
442 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
443 }
444 
445 /*
446  * Routine to clear interrupts for the Radius PrecisionColor 24Xp card.
447  * Is this what the 8xj routine is doing, too?
448  */
449 /*ARGSUSED*/
450 static void
451 grfmv_intr_radius24(void *vsc)
452 {
453 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
454 	u_int8_t c;
455 
456 	c = 0x80 | bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xfffd8);
457 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
458 	c &= 0x7f;
459 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
460 }
461 
462 /*
463  * Routine to clear interrupts on Samsung 768x1006 video controller.
464  * This controller was manufactured by Cornerstone Technology, Inc.,
465  * now known as Cornerstone Imaging.
466  *
467  * To clear this interrupt, we apparently have to set, then clear,
468  * bit 2 at byte offset 0x80000 from the card's base.
469  *	Information for this provided by Brad Salai <bsalai@servtech.com>
470  */
471 /*ARGSUSED*/
472 static void
473 grfmv_intr_cti(void *vsc)
474 {
475 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
476 	u_int8_t c;
477 
478 	c = bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x80000);
479 	c |= 0x02;
480 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80000, c);
481 	c &= 0xfd;
482 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80000, c);
483 }
484 
485 /*ARGSUSED*/
486 static void
487 grfmv_intr_cb264(void *vsc)
488 {
489 	struct grfbus_softc *sc;
490 	volatile char *slotbase;
491 
492 	sc = (struct grfbus_softc *)vsc;
493 	slotbase = (volatile char *)(sc->sc_handle.base); /* XXX evil hack */
494 	__asm volatile(
495 		"	movl	%0,%%a0				\n"
496 		"	movl	%%a0@(0xff6028),%%d0		\n"
497 		"	andl	#0x2,%%d0			\n"
498 		"	beq	_mv_intr0			\n"
499 		"	movql	#0x3,%%d0			\n"
500 		"_mv_intr0:					\n"
501 		"	movl	%%a0@(0xff600c),%%d1		\n"
502 		"	andl	#0x3,%%d1			\n"
503 		"	cmpl	%%d1,%%d0			\n"
504 		"	beq	_mv_intr_fin			\n"
505 		"	movl	%%d0,%%a0@(0xff600c)		\n"
506 		"	nop					\n"
507 		"	tstb	%%d0				\n"
508 		"	beq	_mv_intr1			\n"
509 		"	movl	#0x0002,%%a0@(0xff6040)		\n"
510 		"	movl	#0x0102,%%a0@(0xff6044)		\n"
511 		"	movl	#0x0105,%%a0@(0xff6048)		\n"
512 		"	movl	#0x000e,%%a0@(0xff604c)		\n"
513 		"	movl	#0x001c,%%a0@(0xff6050)		\n"
514 		"	movl	#0x00bc,%%a0@(0xff6054)		\n"
515 		"	movl	#0x00c3,%%a0@(0xff6058)		\n"
516 		"	movl	#0x0061,%%a0@(0xff605c)		\n"
517 		"	movl	#0x0012,%%a0@(0xff6060)		\n"
518 		"	bra	_mv_intr_fin			\n"
519 		"_mv_intr1:					\n"
520 		"	movl	#0x0002,%%a0@(0xff6040)		\n"
521 		"	movl	#0x0209,%%a0@(0xff6044)		\n"
522 		"	movl	#0x020c,%%a0@(0xff6048)		\n"
523 		"	movl	#0x000f,%%a0@(0xff604c)		\n"
524 		"	movl	#0x0027,%%a0@(0xff6050)		\n"
525 		"	movl	#0x00c7,%%a0@(0xff6054)		\n"
526 		"	movl	#0x00d7,%%a0@(0xff6058)		\n"
527 		"	movl	#0x006b,%%a0@(0xff605c)		\n"
528 		"	movl	#0x0029,%%a0@(0xff6060)		\n"
529 		"_mv_intr_fin:					\n"
530 		"	movl	#0x1,%%a0@(0xff6014)"
531 		: : "g" (slotbase) : "a0","d0","d1");
532 }
533 
534 /*
535  * Support for the Colorboard 364 might be more complex than it needs to
536  * be.  If we can find more information about this card, this might be
537  * significantly simplified.  Contributions welcome...  :-)
538  */
539 /*ARGSUSED*/
540 static void
541 grfmv_intr_cb364(void *vsc)
542 {
543 	struct grfbus_softc *sc;
544 	volatile char *slotbase;
545 
546 	sc = (struct grfbus_softc *)vsc;
547 	slotbase = (volatile char *)(sc->sc_handle.base); /* XXX evil hack */
548 	__asm volatile(
549 		"	movl	%0,%%a0				\n"
550 		"	movl	%%a0@(0xfe6028),%%d0		\n"
551 		"	andl	#0x2,%%d0			\n"
552 		"	beq	_cb364_intr4			\n"
553 		"	movql	#0x3,%%d0			\n"
554 		"	movl	%%a0@(0xfe6018),%%d1		\n"
555 		"	movl	#0x3,%%a0@(0xfe6018)		\n"
556 		"	movw	%%a0@(0xfe7010),%%d2		\n"
557 		"	movl	%%d1,%%a0@(0xfe6018)		\n"
558 		"	movl	%%a0@(0xfe6020),%%d1		\n"
559 		"	btst	#0x06,%%d2			\n"
560 		"	beq	_cb364_intr0			\n"
561 		"	btst	#0x00,%%d1			\n"
562 		"	beq	_cb364_intr5			\n"
563 		"	bsr	_cb364_intr1			\n"
564 		"	bra	_cb364_intr_out			\n"
565 		"_cb364_intr0:					\n"
566 		"	btst	#0x00,%%d1			\n"
567 		"	bne	_cb364_intr5			\n"
568 		"	bsr	_cb364_intr1			\n"
569 		"	bra	_cb364_intr_out			\n"
570 		"_cb364_intr1:					\n"
571 		"	movl	%%d0,%%a0@(0xfe600c)		\n"
572 		"	nop					\n"
573 		"	tstb	%%d0				\n"
574 		"	beq	_cb364_intr3			\n"
575 		"	movl	#0x0002,%%a0@(0xfe6040)		\n"
576 		"	movl	#0x0105,%%a0@(0xfe6048)		\n"
577 		"	movl	#0x000e,%%a0@(0xfe604c)		\n"
578 		"	movl	#0x00c3,%%a0@(0xfe6058)		\n"
579 		"	movl	#0x0061,%%a0@(0xfe605c)		\n"
580 		"	btst	#0x06,%%d2			\n"
581 		"	beq	_cb364_intr2			\n"
582 		"	movl	#0x001c,%%a0@(0xfe6050)		\n"
583 		"	movl	#0x00bc,%%a0@(0xfe6054)		\n"
584 		"	movl	#0x0012,%%a0@(0xfe6060)		\n"
585 		"	movl	#0x000e,%%a0@(0xfe6044)		\n"
586 		"	movl	#0x00c3,%%a0@(0xfe6064)		\n"
587 		"	movl	#0x0061,%%a0@(0xfe6020)		\n"
588 		"	rts					\n"
589 		"_cb364_intr2:					\n"
590 		"	movl	#0x0016,%%a0@(0xfe6050)		\n"
591 		"	movl	#0x00b6,%%a0@(0xfe6054)		\n"
592 		"	movl	#0x0011,%%a0@(0xfe6060)		\n"
593 		"	movl	#0x0101,%%a0@(0xfe6044)		\n"
594 		"	movl	#0x00bf,%%a0@(0xfe6064)		\n"
595 		"	movl	#0x0001,%%a0@(0xfe6020)		\n"
596 		"	rts					\n"
597 		"_cb364_intr3:					\n"
598 		"	movl	#0x0002,%%a0@(0xfe6040)		\n"
599 		"	movl	#0x0209,%%a0@(0xfe6044)		\n"
600 		"	movl	#0x020c,%%a0@(0xfe6048)		\n"
601 		"	movl	#0x000f,%%a0@(0xfe604c)		\n"
602 		"	movl	#0x0027,%%a0@(0xfe6050)		\n"
603 		"	movl	#0x00c7,%%a0@(0xfe6054)		\n"
604 		"	movl	#0x00d7,%%a0@(0xfe6058)		\n"
605 		"	movl	#0x006b,%%a0@(0xfe605c)		\n"
606 		"	movl	#0x0029,%%a0@(0xfe6060)		\n"
607 		"	oril	#0x0040,%%a0@(0xfe6064)		\n"
608 		"	movl	#0x0000,%%a0@(0xfe6020)		\n"
609 		"	rts					\n"
610 		"_cb364_intr4:					\n"
611 		"	movq	#0x00,%%d0			\n"
612 		"_cb364_intr5:					\n"
613 		"	movl	%%a0@(0xfe600c),%%d1		\n"
614 		"	andl	#0x3,%%d1			\n"
615 		"	cmpl	%%d1,%%d0			\n"
616 		"	beq	_cb364_intr_out			\n"
617 		"	bsr	_cb364_intr1			\n"
618 		"_cb364_intr_out:				\n"
619 		"	movl	#0x1,%%a0@(0xfe6014)		\n"
620 		"_cb364_intr_quit:"
621 		: : "g" (slotbase) : "a0","d0","d1","d2");
622 }
623 
624 /*
625  * Interrupt clearing routine for SuperMac GFX card.
626  */
627 /*ARGSUSED*/
628 static void
629 grfmv_intr_supermacgfx(void *vsc)
630 {
631 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
632 
633 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xE70D3);
634 }
635 
636 /*
637  * Routine to clear interrupts for the Sigma Designs ColorMax card.
638  */
639 /*ARGSUSED*/
640 static void
641 grfmv_intr_cmax(void *vsc)
642 {
643 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
644 
645 	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0xf501c);
646 	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0xf5018);
647 }
648 
649 /*
650  * Routine to clear interrupts for the Lapis ProColorServer 8 PDS card
651  * (for the SE/30).
652  */
653 /*ARGSUSED*/
654 static void
655 grfmv_intr_lapis(void *vsc)
656 {
657 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
658 
659 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xff7000, 0x08);
660 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xff7000, 0x0C);
661 }
662 
663 /*
664  * Routine to clear interrupts for the Formac ProNitron 80.IVb
665  * and Color Card II
666  */
667 /*ARGSUSED*/
668 static void
669 grfmv_intr_formac(void *vsc)
670 {
671 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
672 
673 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xde80db);
674 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xde80d3);
675 }
676 
677 /*
678  * Routine to clear interrupts for the Vimage by Interware Co., Ltd.
679  */
680 /*ARGSUSED*/
681 static void
682 grfmv_intr_vimage(void *vsc)
683 {
684 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
685 
686 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x800000, 0x67);
687 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x800000, 0xE7);
688 }
689 
690 /*
691  * Routine to clear interrupts for the Grand Vimage by Interware Co., Ltd.
692  */
693 /*ARGSUSED*/
694 static void
695 grfmv_intr_gvimage(void *vsc)
696 {
697 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
698 
699 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xf00000);
700 }
701 
702 /*
703  * Routine to clear interrupts for the Radius GS/C
704  */
705 /*ARGSUSED*/
706 static void
707 grfmv_intr_radius_gsc(void *vsc)
708 {
709 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
710 
711 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xfb802);
712 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xfb802, 0xff);
713 }
714 
715 /*
716  * Routine to clear interrupts for the Radius GS/C
717  */
718 /*ARGSUSED*/
719 static void
720 grfmv_intr_radius_gx(void *vsc)
721 {
722 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
723 
724 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x600000, 0x00);
725 	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x600000, 0x20);
726 }
727 
728 /*
729  * Routine to clear interrupts for the Relax 19" model 200.
730  */
731 /*ARGSUSED*/
732 static void
733 grfmv_intr_relax_200(void *vsc)
734 {
735 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
736 
737 	/* The board ROM driver code has a tst.l here. */
738 	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0x000D0040);
739 }
740 
741 /*
742  * Routine to clear interrupts for the Apple Mac II Monochrome Video Card.
743  */
744 /*ARGSUSED*/
745 static void
746 grfmv_intr_mvc(void *vsc)
747 {
748 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
749 
750 	bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x00040000, 0);
751 	bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x00020000, 0);
752 }
753 
754 /*
755  * Routine to clear interrupts for the VillageTronic Mac Picasso 340.
756  */
757 /*ARGSUSED*/
758 static void
759 grfmv_intr_viltro_340(void *vsc)
760 {
761 	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
762 
763 	/* Yes, two read accesses to the same spot. */
764 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x0500);
765 	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x0500);
766 }
767