Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/*	$NetBSD: grf_nubus.c,v 1.78 2016/02/28 19:39:27 rjs Exp $	*/

/*
 * Copyright (c) 1995 Allen Briggs.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/*
 * Device-specific routines for handling Nubus-based video cards.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grf_nubus.c,v 1.78 2016/02/28 19:39:27 rjs Exp $");

#include <sys/param.h>

#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/systm.h>

#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/grfioctl.h>
#include <machine/viareg.h>

#include <mac68k/nubus/nubus.h>
#include <mac68k/dev/grfvar.h>

static void	load_image_data(void *, struct image_data *);

static void	grfmv_intr_generic_write1(void *);
static void	grfmv_intr_generic_write4(void *);
static void	grfmv_intr_generic_or4(void *);

static void	grfmv_intr_cb264(void *);
static void	grfmv_intr_cb364(void *);
static void	grfmv_intr_cmax(void *);
static void	grfmv_intr_cti(void *);
static void	grfmv_intr_radius(void *);
static void	grfmv_intr_radius24(void *);
static void	grfmv_intr_supermacgfx(void *);
static void	grfmv_intr_lapis(void *);
static void	grfmv_intr_formac(void *);
static void	grfmv_intr_vimage(void *);
static void	grfmv_intr_gvimage(void *);
static void	grfmv_intr_radius_gsc(void *);
static void	grfmv_intr_radius_gx(void *);
static void	grfmv_intr_relax_200(void *);
static void	grfmv_intr_mvc(void *);
static void	grfmv_intr_viltro_340(void *);

static int	grfmv_mode(struct grf_softc *, int, void *);
static int	grfmv_match(device_t, cfdata_t, void *);
static void	grfmv_attach(device_t, device_t, void *);

CFATTACH_DECL_NEW(macvid, sizeof(struct grfbus_softc),
    grfmv_match, grfmv_attach, NULL, NULL);

static void
load_image_data(void *	data, struct image_data *image)
{
	char *d = (char*)data;

	memcpy(&image->size,       d     , 4);
	memcpy(&image->offset,     d +  4, 4);
	memcpy(&image->rowbytes,   d +  8, 2);
	memcpy(&image->top,        d + 10, 2);
	memcpy(&image->left,       d + 12, 2);
	memcpy(&image->bottom,     d + 14, 2);
	memcpy(&image->right,      d + 16, 2);
	memcpy(&image->version,    d + 18, 2);
	memcpy(&image->packType,   d + 20, 2);
	memcpy(&image->packSize,   d + 22, 4);
	memcpy(&image->hRes,       d + 26, 4);
	memcpy(&image->vRes,       d + 30, 4);
	memcpy(&image->pixelType,  d + 34, 2);
	memcpy(&image->pixelSize,  d + 36, 2);
	memcpy(&image->cmpCount,   d + 38, 2);
	memcpy(&image->cmpSize,    d + 40, 2);
	memcpy(&image->planeBytes, d + 42, 4);
}


static int
grfmv_match(device_t parent, cfdata_t cf, void *aux)
{
	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;

	if (na->category != NUBUS_CATEGORY_DISPLAY)
		return 0;

	if (na->type != NUBUS_TYPE_VIDEO)
		return 0;

	if (na->drsw != NUBUS_DRSW_APPLE)
		return 0;

	/*
	 * If we've gotten this far, then we're dealing with a real-live
	 * Apple QuickDraw-compatible display card resource.  Now, how to
	 * determine that this is an active resource???  Dunno.  But we'll
	 * proceed like it is.
	 */

	return 1;
}

static void
grfmv_attach(device_t parent, device_t self, void *aux)
{
	struct grfbus_softc *sc = device_private(self);
	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
	struct image_data image_store, image;
	struct grfmode *gm;
	char cardname[CARD_NAME_LEN];
	nubus_dirent dirent;
	nubus_dir dir, mode_dir;
	int mode;

	memcpy(&sc->sc_slot, na->fmt, sizeof(nubus_slot));

	sc->sc_dev = self;
	sc->sc_tag = na->na_tag;
	sc->card_id = na->drhw;
	sc->sc_basepa = (bus_addr_t)NUBUS_SLOT2PA(na->slot);
	sc->sc_fbofs = 0;

	if (bus_space_map(sc->sc_tag, sc->sc_basepa, NBMEMSIZE,
	    0, &sc->sc_handle)) {
		printf(": grfmv_attach: failed to map slot %d\n", na->slot);
		return;
	}

	nubus_get_main_dir(&sc->sc_slot, &dir);

	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
	    &sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0) {
bad:
		bus_space_unmap(sc->sc_tag, sc->sc_handle, NBMEMSIZE);
		return;
	}

	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);

	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
	    &sc->sc_slot, &sc->board_dir, NUBUS_RSRC_TYPE, &dirent) <= 0)
		if ((na->rsrcid != 128) ||
		    (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
		    &sc->sc_slot, &dir, 129, &dirent) <= 0))
			goto bad;

	mode = NUBUS_RSRC_FIRSTMODE;
	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
	    &sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
		printf(": probe failed to get board rsrc.\n");
		goto bad;
	}

	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);

	if (nubus_find_rsrc(sc->sc_tag, sc->sc_handle,
	    &sc->sc_slot, &mode_dir, VID_PARAMS, &dirent) <= 0) {
		printf(": probe failed to get mode dir.\n");
		goto bad;
	}

	if (nubus_get_ind_data(sc->sc_tag, sc->sc_handle, &sc->sc_slot,
	    &dirent, (void *)&image_store, sizeof(struct image_data)) <= 0) {
		printf(": probe failed to get indirect mode data.\n");
		goto bad;
	}

	/* Need to load display info (and driver?), etc... (?) */

	load_image_data((void *)&image_store, &image);

	gm = &sc->curr_mode;
	gm->mode_id = mode;
	gm->ptype = image.pixelType;
	gm->psize = image.pixelSize;
	gm->width = image.right - image.left;
	gm->height = image.bottom - image.top;
	gm->rowbytes = image.rowbytes;
	gm->hres = image.hRes;
	gm->vres = image.vRes;
	gm->fbsize = gm->height * gm->rowbytes;
	gm->fbbase = (void *)(sc->sc_handle.base);	/* XXX evil hack */
	gm->fboff = image.offset;

	strncpy(cardname, nubus_get_card_name(sc->sc_tag, sc->sc_handle,
	    &sc->sc_slot), CARD_NAME_LEN);
	cardname[CARD_NAME_LEN-1] = '\0';
	printf(": %s\n", cardname);

	if (sc->card_id == NUBUS_DRHW_TFB) {
		/*
		 * This is the Toby card, but apparently some manufacturers
		 * (like Cornerstone) didn't bother to get/use their own
		 * value here, even though the cards are different, so we
		 * try to differentiate here.
		 */
		if (strncmp(cardname, "Samsung 768", 11) == 0)
			sc->card_id = NUBUS_DRHW_SAM768;
		else if (strncmp(cardname, "Toby frame", 10) != 0)
			printf("%s: This display card pretends to be a TFB!\n",
			    device_xname(self));
	}

	switch (sc->card_id) {
	case NUBUS_DRHW_TFB:
	case NUBUS_DRHW_M2HRVC:
	case NUBUS_DRHW_PVC:
		sc->cli_offset = 0xa0000;
		sc->cli_value = 0;
		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
		break;
	case NUBUS_DRHW_WVC:
		sc->cli_offset = 0xa00000;
		sc->cli_value = 0;
		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
		break;
	case NUBUS_DRHW_COLORMAX:
		add_nubus_intr(na->slot, grfmv_intr_cmax, sc);
		break;
	case NUBUS_DRHW_SE30:
		/* Do nothing--SE/30 interrupts are disabled */
		break;
	case NUBUS_DRHW_MDC:
		sc->cli_offset = 0x200148;
		sc->cli_value = 1;
		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);

		/* Enable interrupts; to disable, write 0x7 to this location */
		bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x20013C, 5);
		break;
	case NUBUS_DRHW_CB264:
		add_nubus_intr(na->slot, grfmv_intr_cb264, sc);
		break;
	case NUBUS_DRHW_CB364:
		add_nubus_intr(na->slot, grfmv_intr_cb364, sc);
		break;
	case NUBUS_DRHW_RPC8:
		sc->cli_offset = 0xfdff8f;
		sc->cli_value = 0xff;
		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
		break;
	case NUBUS_DRHW_RPC8XJ:
		sc->cli_value = 0x66;
		add_nubus_intr(na->slot, grfmv_intr_radius, sc);
		break;
	case NUBUS_DRHW_RPC24X:
	case NUBUS_DRHW_BOOGIE:
		sc->cli_value = 0x64;
		add_nubus_intr(na->slot, grfmv_intr_radius, sc);
		break;
	case NUBUS_DRHW_RPC24XP:
		add_nubus_intr(na->slot, grfmv_intr_radius24, sc);
		break;
	case NUBUS_DRHW_RADGSC:
		add_nubus_intr(na->slot, grfmv_intr_radius_gsc, sc);
		break;
	case NUBUS_DRHW_RDCGX:
		add_nubus_intr(na->slot, grfmv_intr_radius_gx, sc);
		break;
	case NUBUS_DRHW_FIILX:
	case NUBUS_DRHW_FIISXDSP:
	case NUBUS_DRHW_FUTURASX:
		sc->cli_offset = 0xf05000;
		sc->cli_value = 0x80;
		add_nubus_intr(na->slot, grfmv_intr_generic_write1, sc);
		break;
	case NUBUS_DRHW_SAM768:
		add_nubus_intr(na->slot, grfmv_intr_cti, sc);
		break;
	case NUBUS_DRHW_SUPRGFX:
		add_nubus_intr(na->slot, grfmv_intr_supermacgfx, sc);
		break;
	case NUBUS_DRHW_SPECTRM8:
		sc->cli_offset = 0x0de178;
		sc->cli_value = 0x80;
		add_nubus_intr(na->slot, grfmv_intr_generic_or4, sc);
		break;
	case NUBUS_DRHW_LAPIS:
		add_nubus_intr(na->slot, grfmv_intr_lapis, sc);
		break;
	case NUBUS_DRHW_RELAX200:
		add_nubus_intr(na->slot, grfmv_intr_relax_200, sc);
		break;
	case NUBUS_DRHW_BAER:
	case NUBUS_DRHW_FORMAC:
		add_nubus_intr(na->slot, grfmv_intr_formac, sc);
		break;
	case NUBUS_DRHW_ROPS24LXI:
	case NUBUS_DRHW_ROPS24XLTV:
	case NUBUS_DRHW_ROPS24MXTV:
		sc->cli_offset = 0xfb0010;
		sc->cli_value = 0x00;
		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
		break;
	case NUBUS_DRHW_ROPSPPGT:
		sc->cli_offset = 0xf50010;
		sc->cli_value = 0x02;
		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
		break;
	case NUBUS_DRHW_VIMAGE:
		add_nubus_intr(na->slot, grfmv_intr_vimage, sc);
		break;
	case NUBUS_DRHW_GVIMAGE:
		add_nubus_intr(na->slot, grfmv_intr_gvimage, sc);
		break;
	case NUBUS_DRHW_MC2124NB:
		sc->cli_offset = 0xfd1000;
		sc->cli_value = 0x00;
		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
		break;
	case NUBUS_DRHW_MICRON:
		sc->cli_offset = 0xa00014;
		sc->cli_value = 0;
		add_nubus_intr(na->slot, grfmv_intr_generic_write4, sc);
		break;
	case NUBUS_DRHW_MVC:
		add_nubus_intr(na->slot, grfmv_intr_mvc, sc);
		break;
	case NUBUS_DRHW_VILTRO340:
		add_nubus_intr(na->slot, grfmv_intr_viltro_340, sc);
		break;
	default:
		printf("%s: Unknown video card ID 0x%x --",
		    device_xname(self), sc->card_id);
		printf(" Not installing interrupt routine.\n");
		break;
	}

	/* Perform common video attachment. */
	grf_establish(sc, &sc->sc_slot, grfmv_mode);
}

static int
grfmv_mode(struct grf_softc *gp, int cmd, void *arg)
{
	switch (cmd) {
	case GM_GRFON:
	case GM_GRFOFF:
		return 0;
	case GM_CURRMODE:
		break;
	case GM_NEWMODE:
		break;
	case GM_LISTMODES:
		break;
	}
	return EINVAL;
}

/* Interrupt handlers... */
/*
 * Generic routine to clear interrupts for cards where it simply takes
 * a MOV.B to clear the interrupt.  The offset and value of this byte
 * varies between cards.
 */
/*ARGSUSED*/
static void
grfmv_intr_generic_write1(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_1(sc->sc_tag, sc->sc_handle,
	    sc->cli_offset, (u_int8_t)sc->cli_value);
}

/*
 * Generic routine to clear interrupts for cards where it simply takes
 * a MOV.L to clear the interrupt.  The offset and value of this byte
 * varies between cards.
 */
/*ARGSUSED*/
static void
grfmv_intr_generic_write4(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_4(sc->sc_tag, sc->sc_handle,
	    sc->cli_offset, sc->cli_value);
}

/*
 * Generic routine to clear interrupts for cards where it simply takes
 * an OR.L to clear the interrupt.  The offset and value of this byte
 * varies between cards.
 */
/*ARGSUSED*/
static void
grfmv_intr_generic_or4(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
	unsigned long	scratch;

	scratch = bus_space_read_4(sc->sc_tag, sc->sc_handle, sc->cli_offset);
	scratch |= 0x80;
	bus_space_write_4(sc->sc_tag, sc->sc_handle, sc->cli_offset, scratch);
}

/*
 * Routine to clear interrupts for the Radius PrecisionColor 8xj card.
 */
/*ARGSUSED*/
static void
grfmv_intr_radius(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
	u_int8_t c;

	c = sc->cli_value;

	c |= 0x80;
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
	c &= 0x7f;
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
}

/*
 * Routine to clear interrupts for the Radius PrecisionColor 24Xp card.
 * Is this what the 8xj routine is doing, too?
 */
/*ARGSUSED*/
static void
grfmv_intr_radius24(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
	u_int8_t c;

	c = 0x80 | bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xfffd8);
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
	c &= 0x7f;
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xd00403, c);
}

/*
 * Routine to clear interrupts on Samsung 768x1006 video controller.
 * This controller was manufactured by Cornerstone Technology, Inc.,
 * now known as Cornerstone Imaging.
 *
 * To clear this interrupt, we apparently have to set, then clear,
 * bit 2 at byte offset 0x80000 from the card's base.
 *	Information for this provided by Brad Salai <bsalai@servtech.com>
 */
/*ARGSUSED*/
static void
grfmv_intr_cti(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;
	u_int8_t c;

	c = bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x80000);
	c |= 0x02;
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80000, c);
	c &= 0xfd;
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80000, c);
}

/*ARGSUSED*/
static void
grfmv_intr_cb264(void *vsc)
{
	struct grfbus_softc *sc;
	volatile char *slotbase;

	sc = (struct grfbus_softc *)vsc;
	slotbase = (volatile char *)(sc->sc_handle.base); /* XXX evil hack */
	__asm volatile(
		"	movl	%0,%%a0				\n"
		"	movl	%%a0@(0xff6028),%%d0		\n"
		"	andl	#0x2,%%d0			\n"
		"	beq	_mv_intr0			\n"
		"	movql	#0x3,%%d0			\n"
		"_mv_intr0:					\n"
		"	movl	%%a0@(0xff600c),%%d1		\n"
		"	andl	#0x3,%%d1			\n"
		"	cmpl	%%d1,%%d0			\n"
		"	beq	_mv_intr_fin			\n"
		"	movl	%%d0,%%a0@(0xff600c)		\n"
		"	nop					\n"
		"	tstb	%%d0				\n"
		"	beq	_mv_intr1			\n"
		"	movl	#0x0002,%%a0@(0xff6040)		\n"
		"	movl	#0x0102,%%a0@(0xff6044)		\n"
		"	movl	#0x0105,%%a0@(0xff6048)		\n"
		"	movl	#0x000e,%%a0@(0xff604c)		\n"
		"	movl	#0x001c,%%a0@(0xff6050)		\n"
		"	movl	#0x00bc,%%a0@(0xff6054)		\n"
		"	movl	#0x00c3,%%a0@(0xff6058)		\n"
		"	movl	#0x0061,%%a0@(0xff605c)		\n"
		"	movl	#0x0012,%%a0@(0xff6060)		\n"
		"	bra	_mv_intr_fin			\n"
		"_mv_intr1:					\n"
		"	movl	#0x0002,%%a0@(0xff6040)		\n"
		"	movl	#0x0209,%%a0@(0xff6044)		\n"
		"	movl	#0x020c,%%a0@(0xff6048)		\n"
		"	movl	#0x000f,%%a0@(0xff604c)		\n"
		"	movl	#0x0027,%%a0@(0xff6050)		\n"
		"	movl	#0x00c7,%%a0@(0xff6054)		\n"
		"	movl	#0x00d7,%%a0@(0xff6058)		\n"
		"	movl	#0x006b,%%a0@(0xff605c)		\n"
		"	movl	#0x0029,%%a0@(0xff6060)		\n"
		"_mv_intr_fin:					\n"
		"	movl	#0x1,%%a0@(0xff6014)"
		: : "g" (slotbase) : "a0","d0","d1");
}

/*
 * Support for the Colorboard 364 might be more complex than it needs to
 * be.  If we can find more information about this card, this might be
 * significantly simplified.  Contributions welcome...  :-)
 */
/*ARGSUSED*/
static void
grfmv_intr_cb364(void *vsc)
{
	struct grfbus_softc *sc;
	volatile char *slotbase;

	sc = (struct grfbus_softc *)vsc;
	slotbase = (volatile char *)(sc->sc_handle.base); /* XXX evil hack */
	__asm volatile(
		"	movl	%0,%%a0				\n"
		"	movl	%%a0@(0xfe6028),%%d0		\n"
		"	andl	#0x2,%%d0			\n"
		"	beq	_cb364_intr4			\n"
		"	movql	#0x3,%%d0			\n"
		"	movl	%%a0@(0xfe6018),%%d1		\n"
		"	movl	#0x3,%%a0@(0xfe6018)		\n"
		"	movw	%%a0@(0xfe7010),%%d2		\n"
		"	movl	%%d1,%%a0@(0xfe6018)		\n"
		"	movl	%%a0@(0xfe6020),%%d1		\n"
		"	btst	#0x06,%%d2			\n"
		"	beq	_cb364_intr0			\n"
		"	btst	#0x00,%%d1			\n"
		"	beq	_cb364_intr5			\n"
		"	bsr	_cb364_intr1			\n"
		"	bra	_cb364_intr_out			\n"
		"_cb364_intr0:					\n"
		"	btst	#0x00,%%d1			\n"
		"	bne	_cb364_intr5			\n"
		"	bsr	_cb364_intr1			\n"
		"	bra	_cb364_intr_out			\n"
		"_cb364_intr1:					\n"
		"	movl	%%d0,%%a0@(0xfe600c)		\n"
		"	nop					\n"
		"	tstb	%%d0				\n"
		"	beq	_cb364_intr3			\n"
		"	movl	#0x0002,%%a0@(0xfe6040)		\n"
		"	movl	#0x0105,%%a0@(0xfe6048)		\n"
		"	movl	#0x000e,%%a0@(0xfe604c)		\n"
		"	movl	#0x00c3,%%a0@(0xfe6058)		\n"
		"	movl	#0x0061,%%a0@(0xfe605c)		\n"
		"	btst	#0x06,%%d2			\n"
		"	beq	_cb364_intr2			\n"
		"	movl	#0x001c,%%a0@(0xfe6050)		\n"
		"	movl	#0x00bc,%%a0@(0xfe6054)		\n"
		"	movl	#0x0012,%%a0@(0xfe6060)		\n"
		"	movl	#0x000e,%%a0@(0xfe6044)		\n"
		"	movl	#0x00c3,%%a0@(0xfe6064)		\n"
		"	movl	#0x0061,%%a0@(0xfe6020)		\n"
		"	rts					\n"
		"_cb364_intr2:					\n"
		"	movl	#0x0016,%%a0@(0xfe6050)		\n"
		"	movl	#0x00b6,%%a0@(0xfe6054)		\n"
		"	movl	#0x0011,%%a0@(0xfe6060)		\n"
		"	movl	#0x0101,%%a0@(0xfe6044)		\n"
		"	movl	#0x00bf,%%a0@(0xfe6064)		\n"
		"	movl	#0x0001,%%a0@(0xfe6020)		\n"
		"	rts					\n"
		"_cb364_intr3:					\n"
		"	movl	#0x0002,%%a0@(0xfe6040)		\n"
		"	movl	#0x0209,%%a0@(0xfe6044)		\n"
		"	movl	#0x020c,%%a0@(0xfe6048)		\n"
		"	movl	#0x000f,%%a0@(0xfe604c)		\n"
		"	movl	#0x0027,%%a0@(0xfe6050)		\n"
		"	movl	#0x00c7,%%a0@(0xfe6054)		\n"
		"	movl	#0x00d7,%%a0@(0xfe6058)		\n"
		"	movl	#0x006b,%%a0@(0xfe605c)		\n"
		"	movl	#0x0029,%%a0@(0xfe6060)		\n"
		"	oril	#0x0040,%%a0@(0xfe6064)		\n"
		"	movl	#0x0000,%%a0@(0xfe6020)		\n"
		"	rts					\n"
		"_cb364_intr4:					\n"
		"	movq	#0x00,%%d0			\n"
		"_cb364_intr5:					\n"
		"	movl	%%a0@(0xfe600c),%%d1		\n"
		"	andl	#0x3,%%d1			\n"
		"	cmpl	%%d1,%%d0			\n"
		"	beq	_cb364_intr_out			\n"
		"	bsr	_cb364_intr1			\n"
		"_cb364_intr_out:				\n"
		"	movl	#0x1,%%a0@(0xfe6014)		\n"
		"_cb364_intr_quit:"
		: : "g" (slotbase) : "a0","d0","d1","d2");
}

/*
 * Interrupt clearing routine for SuperMac GFX card.
 */
/*ARGSUSED*/
static void
grfmv_intr_supermacgfx(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xE70D3);
}

/*
 * Routine to clear interrupts for the Sigma Designs ColorMax card.
 */
/*ARGSUSED*/
static void
grfmv_intr_cmax(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0xf501c);
	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0xf5018);
}

/*
 * Routine to clear interrupts for the Lapis ProColorServer 8 PDS card
 * (for the SE/30).
 */
/*ARGSUSED*/
static void
grfmv_intr_lapis(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xff7000, 0x08);
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xff7000, 0x0C);
}

/*
 * Routine to clear interrupts for the Formac ProNitron 80.IVb
 * and Color Card II
 */
/*ARGSUSED*/
static void
grfmv_intr_formac(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xde80db);
	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xde80d3);
}

/*
 * Routine to clear interrupts for the Vimage by Interware Co., Ltd.
 */
/*ARGSUSED*/
static void
grfmv_intr_vimage(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x800000, 0x67);
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x800000, 0xE7);
}

/*
 * Routine to clear interrupts for the Grand Vimage by Interware Co., Ltd.
 */
/*ARGSUSED*/
static void
grfmv_intr_gvimage(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xf00000);
}

/*
 * Routine to clear interrupts for the Radius GS/C
 */
/*ARGSUSED*/
static void
grfmv_intr_radius_gsc(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0xfb802);
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0xfb802, 0xff);
}

/*
 * Routine to clear interrupts for the Radius GS/C
 */
/*ARGSUSED*/
static void
grfmv_intr_radius_gx(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x600000, 0x00);
	bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x600000, 0x20);
}

/*
 * Routine to clear interrupts for the Relax 19" model 200.
 */
/*ARGSUSED*/
static void
grfmv_intr_relax_200(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	/* The board ROM driver code has a tst.l here. */
	bus_space_read_4(sc->sc_tag, sc->sc_handle, 0x000D0040);
}

/*
 * Routine to clear interrupts for the Apple Mac II Monochrome Video Card.
 */
/*ARGSUSED*/
static void
grfmv_intr_mvc(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x00040000, 0);
	bus_space_write_4(sc->sc_tag, sc->sc_handle, 0x00020000, 0);	
}

/*
 * Routine to clear interrupts for the VillageTronic Mac Picasso 340.
 */
/*ARGSUSED*/
static void
grfmv_intr_viltro_340(void *vsc)
{
	struct grfbus_softc *sc = (struct grfbus_softc *)vsc;

	/* Yes, two read accesses to the same spot. */
	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x0500);
	bus_space_read_1(sc->sc_tag, sc->sc_handle, 0x0500);
}