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