grf_nubus.c revision 1.9 1 /* $NetBSD: grf_nubus.c,v 1.9 1996/05/06 01:08:30 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/cpu.h>
46 #include <machine/grfioctl.h>
47 #include <machine/viareg.h>
48
49 #include "nubus.h"
50 #include "grfvar.h"
51
52 static void load_image_data __P((caddr_t data, struct image_data *image));
53 static void grfmv_intr __P((void *vsc, int slot));
54 static int get_vrsrcid __P((nubus_slot *slot));
55
56 static char zero = 0;
57
58 static int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
59 static caddr_t grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
60 static int grfmv_match __P((struct device *, void *, void *));
61 static void grfmv_attach __P((struct device *, struct device *, void *));
62
63 struct cfattach grf_mv_ca = {
64 sizeof(struct grf_softc), grfmv_match, grfmv_attach
65 };
66
67 static void
68 load_image_data(data, image)
69 caddr_t data;
70 struct image_data *image;
71 {
72 bcopy(data , &image->size, 4);
73 bcopy(data + 4, &image->offset, 4);
74 bcopy(data + 8, &image->rowbytes, 2);
75 bcopy(data + 10, &image->top, 2);
76 bcopy(data + 12, &image->left, 2);
77 bcopy(data + 14, &image->bottom, 2);
78 bcopy(data + 16, &image->right, 2);
79 bcopy(data + 18, &image->version, 2);
80 bcopy(data + 20, &image->packType, 2);
81 bcopy(data + 22, &image->packSize, 4);
82 bcopy(data + 26, &image->hRes, 4);
83 bcopy(data + 30, &image->vRes, 4);
84 bcopy(data + 34, &image->pixelType, 2);
85 bcopy(data + 36, &image->pixelSize, 2);
86 bcopy(data + 38, &image->cmpCount, 2);
87 bcopy(data + 40, &image->cmpSize, 2);
88 bcopy(data + 42, &image->planeBytes, 4);
89 }
90
91 /*ARGSUSED*/
92 static void
93 grfmv_intr(vsc, slot)
94 void *vsc;
95 int slot;
96 {
97 caddr_t slotbase;
98 struct grf_softc *sc;
99
100 sc = (struct grf_softc *) vsc;
101 slotbase = (caddr_t) sc->sc_slot.virtual_base;
102 slotbase[0xa0000] = zero;
103 }
104
105 static int
106 get_vrsrcid(slot)
107 nubus_slot *slot;
108 {
109 extern u_short mac68k_vrsrc_vec[];
110 int i;
111
112 for (i = 0 ; i < 6 ; i++)
113 if ((mac68k_vrsrc_vec[i] & 0xff) == slot->slot)
114 return ((mac68k_vrsrc_vec[i] >> 8) & 0xff);
115 return 0x80;
116 }
117
118 static int
119 grfmv_match(pdp, match, aux)
120 struct device *pdp;
121 void *match, *aux;
122 {
123 struct grf_softc *sc;
124 nubus_slot *slot = (nubus_slot *) aux;
125 nubus_dir dir, *dirp, *dirp2;
126 nubus_dirent dirent, *direntp;
127 nubus_type slottype;
128 int vrsrc;
129
130 sc = (struct grf_softc *) match;
131 dirp = &dir;
132 direntp = &dirent;
133 nubus_get_main_dir(slot, dirp);
134
135 vrsrc = get_vrsrcid(slot);
136 if (nubus_find_rsrc(slot, dirp, vrsrc, direntp) <= 0) {
137 if ( (vrsrc != 128)
138 || (nubus_find_rsrc(slot, dirp, 129, direntp) <= 0)) {
139 return 0;
140 }
141 }
142
143 dirp2 = (nubus_dir *) &sc->board_dir;
144 nubus_get_dir_from_rsrc(slot, direntp, dirp2);
145
146 if (nubus_find_rsrc(slot, dirp2, NUBUS_RSRC_TYPE, direntp) <= 0)
147 /* Type is a required entry... This should never happen. */
148 return 0;
149
150 if (nubus_get_ind_data(slot, direntp,
151 (caddr_t) &slottype, sizeof(nubus_type)) <= 0)
152 return 0;
153
154 if (slottype.category != NUBUS_CATEGORY_DISPLAY)
155 return 0;
156
157 if (slottype.type != NUBUS_TYPE_VIDEO)
158 return 0;
159
160 if (slottype.drsw != NUBUS_DRSW_APPLE)
161 return 0;
162
163 /*
164 * If we've gotten this far, then we're dealing with a real-live
165 * Apple QuickDraw-compatible display card resource. Now, how to
166 * determine that this is an active resource??? Dunno. But we'll
167 * proceed like it is.
168 */
169
170 sc->card_id = slottype.drhw;
171
172 /* Need to load display info (and driver?), etc... */
173
174 return 1;
175 }
176
177 static void
178 grfmv_attach(parent, self, aux)
179 struct device *parent, *self;
180 void *aux;
181 {
182 struct grf_softc *sc;
183 struct image_data image_store, image;
184 nubus_dirent dirent;
185 nubus_dir mode_dir;
186 int mode;
187 u_long base;
188
189 sc = (struct grf_softc *) self;
190
191 sc->g_mode = grfmv_mode;
192 sc->g_phys = grfmv_phys;
193
194 mode = NUBUS_RSRC_FIRSTMODE;
195 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
196 printf("grf probe failed to get board rsrc.\n");
197 return;
198 }
199
200 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
201
202 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
203 <= 0) {
204 printf("grf probe failed to get mode dir.\n");
205 return;
206 }
207
208 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
209 sizeof(struct image_data)) <= 0) {
210 printf("grf probe failed to get indirect mode data.\n");
211 return;
212 }
213
214 load_image_data((caddr_t) &image_store, &image);
215
216 base = sc->sc_slot.virtual_base;
217
218 sc->curr_mode.mode_id = mode;
219 sc->curr_mode.fbbase = (caddr_t) (base + image.offset);
220 sc->curr_mode.fboff = image.offset;
221 sc->curr_mode.rowbytes = image.rowbytes;
222 sc->curr_mode.width = image.right - image.left;
223 sc->curr_mode.height = image.bottom - image.top;
224 sc->curr_mode.fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
225 sc->curr_mode.hres = image.hRes;
226 sc->curr_mode.vres = image.vRes;
227 sc->curr_mode.ptype = image.pixelType;
228 sc->curr_mode.psize = image.pixelSize;
229
230 strncpy(sc->card_name, nubus_get_card_name(&sc->sc_slot),
231 CARD_NAME_LEN);
232
233 sc->card_name[CARD_NAME_LEN-1] = '\0';
234
235 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
236
237 sc->g_flags = GF_ALIVE;
238
239 printf(": %d x %d ", sc->curr_mode.width, sc->curr_mode.height);
240
241 if (sc->curr_mode.psize == 1)
242 printf("monochrome");
243 else
244 printf("%d color", 1 << sc->curr_mode.psize);
245
246 printf(" %s display\n", sc->card_name);
247 }
248
249 static int
250 grfmv_mode(gp, cmd, arg)
251 struct grf_softc *gp;
252 int cmd;
253 void *arg;
254 {
255 switch (cmd) {
256 case GM_GRFON:
257 case GM_GRFOFF:
258 return 0;
259 case GM_CURRMODE:
260 break;
261 case GM_NEWMODE:
262 break;
263 case GM_LISTMODES:
264 break;
265 }
266 return EINVAL;
267 }
268
269 static caddr_t
270 grfmv_phys(gp, addr)
271 struct grf_softc *gp;
272 vm_offset_t addr;
273 {
274 return (caddr_t) (NUBUS_SLOT_TO_PADDR(gp->sc_slot.slot) +
275 (addr - gp->sc_slot.virtual_base));
276 }
277