grf_nubus.c revision 1.24 1 /* $NetBSD: grf_nubus.c,v 1.24 1997/05/03 02:29:54 briggs 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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Allen Briggs.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * Device-specific routines for handling Nubus-based video cards.
33 */
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 "nubus.h"
51 #include "grfvar.h"
52
53 static void load_image_data __P((caddr_t data, struct image_data *image));
54
55 static void grfmv_intr_generic __P((void *vsc, int slot));
56 static void grfmv_intr_radius __P((void *vsc, int slot));
57 static void grfmv_intr_cti __P((void *vsc, int slot));
58 static void grfmv_intr_cb264 __P((void *vsc, int slot));
59 static void grfmv_intr_cb364 __P((void *vsc, int slot));
60
61 static int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
62 static caddr_t grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
63 static int grfmv_match __P((struct device *, struct cfdata *, void *));
64 static void grfmv_attach __P((struct device *, struct device *, void *));
65
66 struct cfdriver macvid_cd = {
67 NULL, "macvid", DV_DULL
68 };
69
70 struct cfattach macvid_ca = {
71 sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
72 };
73
74 static void
75 load_image_data(data, image)
76 caddr_t data;
77 struct image_data *image;
78 {
79 bcopy(data , &image->size, 4);
80 bcopy(data + 4, &image->offset, 4);
81 bcopy(data + 8, &image->rowbytes, 2);
82 bcopy(data + 10, &image->top, 2);
83 bcopy(data + 12, &image->left, 2);
84 bcopy(data + 14, &image->bottom, 2);
85 bcopy(data + 16, &image->right, 2);
86 bcopy(data + 18, &image->version, 2);
87 bcopy(data + 20, &image->packType, 2);
88 bcopy(data + 22, &image->packSize, 4);
89 bcopy(data + 26, &image->hRes, 4);
90 bcopy(data + 30, &image->vRes, 4);
91 bcopy(data + 34, &image->pixelType, 2);
92 bcopy(data + 36, &image->pixelSize, 2);
93 bcopy(data + 38, &image->cmpCount, 2);
94 bcopy(data + 40, &image->cmpSize, 2);
95 bcopy(data + 42, &image->planeBytes, 4);
96 }
97
98
99 static int
100 grfmv_match(parent, cf, aux)
101 struct device *parent;
102 struct cfdata *cf;
103 void *aux;
104 {
105 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
106
107 if (na->category != NUBUS_CATEGORY_DISPLAY)
108 return 0;
109
110 if (na->type != NUBUS_TYPE_VIDEO)
111 return 0;
112
113 if (na->drsw != NUBUS_DRSW_APPLE)
114 return 0;
115
116 /*
117 * If we've gotten this far, then we're dealing with a real-live
118 * Apple QuickDraw-compatible display card resource. Now, how to
119 * determine that this is an active resource??? Dunno. But we'll
120 * proceed like it is.
121 */
122
123 return 1;
124 }
125
126 static void
127 grfmv_attach(parent, self, aux)
128 struct device *parent, *self;
129 void *aux;
130 {
131 struct grfbus_softc *sc = (struct grfbus_softc *)self;
132 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
133 struct image_data image_store, image;
134 struct grfmode *gm;
135 char cardname[CARD_NAME_LEN];
136 nubus_dirent dirent;
137 nubus_dir dir, mode_dir;
138 int mode;
139
140 sc->card_id = na->drhw;
141
142 bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
143
144 nubus_get_main_dir(&sc->sc_slot, &dir);
145
146 if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
147 return;
148
149 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
150
151 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
152 NUBUS_RSRC_TYPE, &dirent) <= 0)
153 if ((na->rsrcid != 128) ||
154 (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
155 return;
156
157 mode = NUBUS_RSRC_FIRSTMODE;
158 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
159 printf("\n%s: probe failed to get board rsrc.\n",
160 sc->sc_dev.dv_xname);
161 return;
162 }
163
164 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
165
166 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
167 <= 0) {
168 printf("\n%s: probe failed to get mode dir.\n",
169 sc->sc_dev.dv_xname);
170 return;
171 }
172
173 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t)&image_store,
174 sizeof(struct image_data)) <= 0) {
175 printf("\n%s: probe failed to get indirect mode data.\n",
176 sc->sc_dev.dv_xname);
177 return;
178 }
179
180 /* Need to load display info (and driver?), etc... (?) */
181
182 load_image_data((caddr_t)&image_store, &image);
183
184 gm = &sc->curr_mode;
185 gm->mode_id = mode;
186 gm->fbbase = (caddr_t)(sc->sc_slot.virtual_base + image.offset);
187 gm->fboff = image.offset;
188 gm->rowbytes = image.rowbytes;
189 gm->width = image.right - image.left;
190 gm->height = image.bottom - image.top;
191 gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
192 gm->hres = image.hRes;
193 gm->vres = image.vRes;
194 gm->ptype = image.pixelType;
195 gm->psize = image.pixelSize;
196
197 strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
198 CARD_NAME_LEN);
199 cardname[CARD_NAME_LEN-1] = '\0';
200 printf(": %s\n", cardname);
201
202 if (sc->card_id == NUBUS_DRHW_TFB) {
203 /*
204 * This is the Toby card, but apparently some manufacturers
205 * (like Cornerstone) didn't bother to get/use their own
206 * value here, even though the cards are different, so we
207 * so we try to differentiate here.
208 */
209 if (strncmp(cardname, "Samsung 768", 11) == 0)
210 sc->card_id = NUBUS_DRHW_SAM768;
211 else if (strncmp(cardname, "Toby frame", 10) != 0)
212 printf("%s: This display card pretends to be a TFB!",
213 sc->sc_dev.dv_xname);
214 }
215
216 switch (sc->card_id) {
217 case NUBUS_DRHW_M2HRVC:
218 case NUBUS_DRHW_TFB:
219 sc->cli_offset = 0xa0000;
220 sc->cli_value = 0;
221 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
222 break;
223 case NUBUS_DRHW_WVC:
224 sc->cli_offset = 0xa00000;
225 sc->cli_value = 0;
226 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
227 break;
228 case NUBUS_DRHW_RPC8XJ:
229 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_radius, sc);
230 break;
231 case NUBUS_DRHW_FIILX:
232 case NUBUS_DRHW_FIISXDSP:
233 sc->cli_offset = 0xF05000;
234 sc->cli_value = 0x80;
235 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
236 break;
237 case NUBUS_DRHW_SAM768:
238 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_cti, sc);
239 break;
240 case NUBUS_DRHW_CB264:
241 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_cb264, sc);
242 break;
243 case NUBUS_DRHW_CB364:
244 add_nubus_intr(sc->sc_slot.slot, grfmv_intr_cb364, sc);
245 break;
246 case NUBUS_DRHW_SE30:
247 /* Do nothing--SE/30 interrupts are disabled */
248 break;
249 case NUBUS_DRHW_MICRON:
250 /* What do we know about this one? */
251 default:
252 printf("%s: Unknown video card ID 0x%x --",
253 sc->sc_dev.dv_xname, sc->card_id);
254 printf(" Not installing interrupt routine.\n");
255 break;
256 }
257
258 /* Perform common video attachment. */
259 grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
260 }
261
262 static int
263 grfmv_mode(gp, cmd, arg)
264 struct grf_softc *gp;
265 int cmd;
266 void *arg;
267 {
268 switch (cmd) {
269 case GM_GRFON:
270 case GM_GRFOFF:
271 return 0;
272 case GM_CURRMODE:
273 break;
274 case GM_NEWMODE:
275 break;
276 case GM_LISTMODES:
277 break;
278 }
279 return EINVAL;
280 }
281
282 static caddr_t
283 grfmv_phys(gp, addr)
284 struct grf_softc *gp;
285 vm_offset_t addr;
286 {
287 return (caddr_t)(NUBUS_SLOT2PA(gp->sc_slot->slot) +
288 (addr - gp->sc_slot->virtual_base));
289 }
290
291 /* Interrupt handlers... */
292 /*
293 * Generic routine to clear interrupts for cards where it simply takes
294 * a CLR.B to clear the interrupt. The offset of this byte varies between
295 * cards.
296 */
297 /*ARGSUSED*/
298 static void
299 grfmv_intr_generic(vsc, slot)
300 void *vsc;
301 int slot;
302 {
303 static char zero = 0;
304 struct grfbus_softc *sc;
305 volatile char *slotbase;
306
307 sc = (struct grfbus_softc *)vsc;
308 slotbase = (volatile char *)sc->sc_slot.virtual_base;
309 slotbase[sc->cli_offset] = zero;
310 }
311
312 /*
313 * Generic routine to clear interrupts for cards where it simply takes
314 * a CLR.B to clear the interrupt. The offset of this byte varies between
315 * cards.
316 */
317 /*ARGSUSED*/
318 static void
319 grfmv_intr_radius(vsc, slot)
320 void *vsc;
321 int slot;
322 {
323 unsigned char c;
324 struct grfbus_softc *sc;
325 volatile char *slotbase;
326
327 sc = (struct grfbus_softc *)vsc;
328 slotbase = (volatile char *)sc->sc_slot.virtual_base;
329
330 /*
331 * The value 0x66 was the observed value on one card. It is read
332 * from the driver's information block, so this may not be sufficient.
333 * Then again, we're not setting up any other interrupts...
334 */
335 c = 0x66;
336
337 c |= 0x80;
338 slotbase[0xD00403] = c;
339 c &= 0x7F;
340 slotbase[0xD00403] = c;
341 }
342
343 /*
344 * Routine to clear interrupts on Samsung 768x1006 video controller.
345 * This controller was manufactured by Cornerstone Technology, Inc.,
346 * now known as Cornerstone Imaging.
347 *
348 * To clear this interrupt, we apparently have to set, then clear,
349 * bit 2 at byte offset 0x80000 from the card's base.
350 * Information for this provided by Brad Salai <bsalai (at) servtech.com>
351 */
352 /*ARGSUSED*/
353 static void
354 grfmv_intr_cti(vsc, slot)
355 void *vsc;
356 int slot;
357 {
358 struct grfbus_softc *sc;
359 volatile char *slotbase;
360
361 sc = (struct grfbus_softc *)vsc;
362 slotbase = ((volatile char *)sc->sc_slot.virtual_base) + 0x00080000;
363 *slotbase = (*slotbase | 0x02);
364 *slotbase = (*slotbase & 0xFD);
365 }
366
367 /*ARGSUSED*/
368 static void
369 grfmv_intr_cb264(vsc, slot)
370 void *vsc;
371 int slot;
372 {
373 struct grfbus_softc *sc;
374 volatile char *slotbase;
375
376 sc = (struct grfbus_softc *)vsc;
377 slotbase = (volatile char *)sc->sc_slot.virtual_base;
378 asm volatile(" movl %0,a0
379 movl a0@(0xff6028),d0
380 andl #0x2,d0
381 beq _mv_intr0
382 movql #0x3,d0
383 _mv_intr0:
384 movl a0@(0xff600c),d1
385 andl #0x3,d1
386 cmpl d1,d0
387 beq _mv_intr_fin
388 movl d0,a0@(0xff600c)
389 nop
390 tstb d0
391 beq _mv_intr1
392 movl #0x0002,a0@(0xff6040)
393 movl #0x0102,a0@(0xff6044)
394 movl #0x0105,a0@(0xff6048)
395 movl #0x000e,a0@(0xff604c)
396 movl #0x001c,a0@(0xff6050)
397 movl #0x00bc,a0@(0xff6054)
398 movl #0x00c3,a0@(0xff6058)
399 movl #0x0061,a0@(0xff605c)
400 movl #0x0012,a0@(0xff6060)
401 bra _mv_intr_fin
402 _mv_intr1:
403 movl #0x0002,a0@(0xff6040)
404 movl #0x0209,a0@(0xff6044)
405 movl #0x020c,a0@(0xff6048)
406 movl #0x000f,a0@(0xff604c)
407 movl #0x0027,a0@(0xff6050)
408 movl #0x00c7,a0@(0xff6054)
409 movl #0x00d7,a0@(0xff6058)
410 movl #0x006b,a0@(0xff605c)
411 movl #0x0029,a0@(0xff6060)
412 _mv_intr_fin:
413 movl #0x1,a0@(0xff6014)"
414 : : "g" (slotbase) : "a0","d0","d1");
415 }
416
417 /*
418 * Support for the Colorboard 364 might be more complex than it needs to
419 * be. If we can find more information about this card, this might be
420 * significantly simplified. Contributions welcome... :-)
421 */
422 /*ARGSUSED*/
423 static void
424 grfmv_intr_cb364(vsc, slot)
425 void *vsc;
426 int slot;
427 {
428 struct grfbus_softc *sc;
429 volatile char *slotbase;
430
431 sc = (struct grfbus_softc *)vsc;
432 slotbase = (volatile char *)sc->sc_slot.virtual_base;
433 asm volatile(" movl %0,a0
434 movl a0@(0xfe6028),d0
435 andl #0x2,d0
436 beq _cb364_intr4
437 movql #0x3,d0
438 movl a0@(0xfe6018),d1
439 movl #0x3,a0@(0xfe6018)
440 movw a0@(0xfe7010),d2
441 movl d1,a0@(0xfe6018)
442 movl a0@(0xfe6020),d1
443 btst #0x06,d2
444 beq _cb364_intr0
445 btst #0x00,d1
446 beq _cb364_intr5
447 bsr _cb364_intr1
448 bra _cb364_intr_out
449 _cb364_intr0:
450 btst #0x00,d1
451 bne _cb364_intr5
452 bsr _cb364_intr1
453 bra _cb364_intr_out
454 _cb364_intr1:
455 movl d0,a0@(0xfe600c)
456 nop
457 tstb d0
458 beq _cb364_intr3
459 movl #0x0002,a0@(0xfe6040)
460 movl #0x0105,a0@(0xfe6048)
461 movl #0x000e,a0@(0xfe604c)
462 movl #0x00c3,a0@(0xfe6058)
463 movl #0x0061,a0@(0xfe605c)
464 btst #0x06,d2
465 beq _cb364_intr2
466 movl #0x001c,a0@(0xfe6050)
467 movl #0x00bc,a0@(0xfe6054)
468 movl #0x0012,a0@(0xfe6060)
469 movl #0x000e,a0@(0xfe6044)
470 movl #0x00c3,a0@(0xfe6064)
471 movl #0x0061,a0@(0xfe6020)
472 rts
473 _cb364_intr2:
474 movl #0x0016,a0@(0xfe6050)
475 movl #0x00b6,a0@(0xfe6054)
476 movl #0x0011,a0@(0xfe6060)
477 movl #0x0101,a0@(0xfe6044)
478 movl #0x00bf,a0@(0xfe6064)
479 movl #0x0001,a0@(0xfe6020)
480 rts
481 _cb364_intr3:
482 movl #0x0002,a0@(0xfe6040)
483 movl #0x0209,a0@(0xfe6044)
484 movl #0x020c,a0@(0xfe6048)
485 movl #0x000f,a0@(0xfe604c)
486 movl #0x0027,a0@(0xfe6050)
487 movl #0x00c7,a0@(0xfe6054)
488 movl #0x00d7,a0@(0xfe6058)
489 movl #0x006b,a0@(0xfe605c)
490 movl #0x0029,a0@(0xfe6060)
491 oril #0x0040,a0@(0xfe6064)
492 movl #0x0000,a0@(0xfe6020)
493 rts
494 _cb364_intr4:
495 movq #0x00,d0
496 _cb364_intr5:
497 movl a0@(0xfe600c),d1
498 andl #0x3,d1
499 cmpl d1,d0
500 beq _cb364_intr_out
501 bsr _cb364_intr1
502 _cb364_intr_out:
503 movl #0x1,a0@(0xfe6014)
504 _cb364_intr_quit:
505 " : : "g" (slotbase) : "a0","d0","d1","d2");
506 }
507