grf_nubus.c revision 1.17 1 /* $NetBSD: grf_nubus.c,v 1.17 1997/02/24 06:20:06 scottr 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 static void grfmv_intr __P((void *vsc, int slot));
55
56 #ifndef MYSTERY
57 static char zero = 0;
58 #endif
59
60 static int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
61 static caddr_t grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
62 static int grfmv_match __P((struct device *, struct cfdata *, void *));
63 static void grfmv_attach __P((struct device *, struct device *, void *));
64
65 struct cfdriver macvid_cd = {
66 NULL, "macvid", DV_DULL
67 };
68
69 struct cfattach macvid_ca = {
70 sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
71 };
72
73 static void
74 load_image_data(data, image)
75 caddr_t data;
76 struct image_data *image;
77 {
78 bcopy(data , &image->size, 4);
79 bcopy(data + 4, &image->offset, 4);
80 bcopy(data + 8, &image->rowbytes, 2);
81 bcopy(data + 10, &image->top, 2);
82 bcopy(data + 12, &image->left, 2);
83 bcopy(data + 14, &image->bottom, 2);
84 bcopy(data + 16, &image->right, 2);
85 bcopy(data + 18, &image->version, 2);
86 bcopy(data + 20, &image->packType, 2);
87 bcopy(data + 22, &image->packSize, 4);
88 bcopy(data + 26, &image->hRes, 4);
89 bcopy(data + 30, &image->vRes, 4);
90 bcopy(data + 34, &image->pixelType, 2);
91 bcopy(data + 36, &image->pixelSize, 2);
92 bcopy(data + 38, &image->cmpCount, 2);
93 bcopy(data + 40, &image->cmpSize, 2);
94 bcopy(data + 42, &image->planeBytes, 4);
95 }
96
97 /*ARGSUSED*/
98 static void
99 grfmv_intr(vsc, slot)
100 void *vsc;
101 int slot;
102 {
103 #ifdef MYSTERY
104 struct grfbus_softc *sc;
105 caddr_t slotbase;
106
107 sc = (struct grfbus_softc *) vsc;
108 slotbase = (caddr_t) sc->sc_slot.virtual_base;
109 asm volatile(" movl %0,a0
110 movl a0@(0xff6028),d0
111 andl #0x2,d0
112 beq _mv_intr0
113 movql #0x3,d0
114 _mv_intr0:
115 movl a0@(0xff600c),d1
116 andl #0x3,d1
117 cmpl d1,d0
118 beq _mv_intr_fin
119 movl d0,a0@(0xff600c)
120 nop
121 tstb d0
122 beq _mv_intr1
123 movl #0x0002,a0@(0xff6040)
124 movl #0x0102,a0@(0xff6044)
125 movl #0x0105,a0@(0xff6048)
126 movl #0x000e,a0@(0xff604c)
127 movl #0x001c,a0@(0xff6050)
128 movl #0x00bc,a0@(0xff6054)
129 movl #0x00c3,a0@(0xff6058)
130 movl #0x0061,a0@(0xff605c)
131 movl #0x0012,a0@(0xff6060)
132 bra _mv_intr_fin
133 _mv_intr1:
134 movl #0x0002,a0@(0xff6040)
135 movl #0x0209,a0@(0xff6044)
136 movl #0x020c,a0@(0xff6048)
137 movl #0x000f,a0@(0xff604c)
138 movl #0x0027,a0@(0xff6050)
139 movl #0x00c7,a0@(0xff6054)
140 movl #0x00d7,a0@(0xff6058)
141 movl #0x006b,a0@(0xff605c)
142 movl #0x0029,a0@(0xff6060)
143 _mv_intr_fin:
144 movl #0x1,a0@(0xff6014)"
145 : : "g" (slotbase) : "a0","d0","d1");
146 #else
147 caddr_t slotbase;
148 struct grfbus_softc *sc;
149
150 sc = (struct grfbus_softc *) vsc;
151 slotbase = (caddr_t) sc->sc_slot.virtual_base;
152 slotbase[0xa0000] = zero;
153 #endif
154 }
155
156 static int
157 grfmv_match(parent, cf, aux)
158 struct device *parent;
159 struct cfdata *cf;
160 void *aux;
161 {
162 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
163
164 if (na->category != NUBUS_CATEGORY_DISPLAY)
165 return 0;
166
167 if (na->type != NUBUS_TYPE_VIDEO)
168 return 0;
169
170 if (na->drsw != NUBUS_DRSW_APPLE)
171 return 0;
172
173 /*
174 * If we've gotten this far, then we're dealing with a real-live
175 * Apple QuickDraw-compatible display card resource. Now, how to
176 * determine that this is an active resource??? Dunno. But we'll
177 * proceed like it is.
178 */
179
180 return 1;
181 }
182
183 static void
184 grfmv_attach(parent, self, aux)
185 struct device *parent, *self;
186 void *aux;
187 {
188 struct grfbus_softc *sc = (struct grfbus_softc *) self;
189 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
190 struct image_data image_store, image;
191 struct grfmode *gm;
192 char cardname[CARD_NAME_LEN];
193 nubus_dirent dirent;
194 nubus_dir dir, mode_dir;
195 int mode;
196
197 sc->card_id = na->drhw;
198
199 bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
200
201 nubus_get_main_dir(&sc->sc_slot, &dir);
202
203 if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
204 return;
205
206 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
207
208 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
209 NUBUS_RSRC_TYPE, &dirent) <= 0)
210 if ((na->rsrcid != 128) ||
211 (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
212 return;
213
214 mode = NUBUS_RSRC_FIRSTMODE;
215 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
216 printf("\n%s: probe failed to get board rsrc.\n",
217 sc->sc_dev.dv_xname);
218 return;
219 }
220
221 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
222
223 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
224 <= 0) {
225 printf("\n%s: probe failed to get mode dir.\n",
226 sc->sc_dev.dv_xname);
227 return;
228 }
229
230 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
231 sizeof(struct image_data)) <= 0) {
232 printf("\n%s: probe failed to get indirect mode data.\n",
233 sc->sc_dev.dv_xname);
234 return;
235 }
236
237 /* Need to load display info (and driver?), etc... (?) */
238
239 load_image_data((caddr_t) &image_store, &image);
240
241 gm = &sc->curr_mode;
242 gm->mode_id = mode;
243 gm->fbbase = (caddr_t) (sc->sc_slot.virtual_base + image.offset);
244 gm->fboff = image.offset;
245 gm->rowbytes = image.rowbytes;
246 gm->width = image.right - image.left;
247 gm->height = image.bottom - image.top;
248 gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
249 gm->hres = image.hRes;
250 gm->vres = image.vRes;
251 gm->ptype = image.pixelType;
252 gm->psize = image.pixelSize;
253
254 strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
255 CARD_NAME_LEN);
256 cardname[CARD_NAME_LEN-1] = '\0';
257
258 printf(": %s\n", cardname);
259
260 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
261
262 /* Perform common video attachment. */
263 grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
264 }
265
266 static int
267 grfmv_mode(gp, cmd, arg)
268 struct grf_softc *gp;
269 int cmd;
270 void *arg;
271 {
272 switch (cmd) {
273 case GM_GRFON:
274 case GM_GRFOFF:
275 return 0;
276 case GM_CURRMODE:
277 break;
278 case GM_NEWMODE:
279 break;
280 case GM_LISTMODES:
281 break;
282 }
283 return EINVAL;
284 }
285
286 static caddr_t
287 grfmv_phys(gp, addr)
288 struct grf_softc *gp;
289 vm_offset_t addr;
290 {
291 return (caddr_t) (NUBUS_SLOT2PA(gp->sc_slot->slot) +
292 (addr - gp->sc_slot->virtual_base));
293 }
294