grf_nubus.c revision 1.10 1 /* $NetBSD: grf_nubus.c,v 1.10 1996/05/06 03:27:20 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 sc->sc_slot = *slot;
173
174 /* Need to load display info (and driver?), etc... */
175
176 return 1;
177 }
178
179 static void
180 grfmv_attach(parent, self, aux)
181 struct device *parent, *self;
182 void *aux;
183 {
184 struct grf_softc *sc;
185 struct image_data image_store, image;
186 nubus_dirent dirent;
187 nubus_dir mode_dir;
188 int mode;
189 u_long base;
190
191 sc = (struct grf_softc *) self;
192
193 sc->g_mode = grfmv_mode;
194 sc->g_phys = grfmv_phys;
195
196 mode = NUBUS_RSRC_FIRSTMODE;
197 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
198 printf("grf probe failed to get board rsrc.\n");
199 return;
200 }
201
202 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
203
204 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
205 <= 0) {
206 printf("grf probe failed to get mode dir.\n");
207 return;
208 }
209
210 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
211 sizeof(struct image_data)) <= 0) {
212 printf("grf probe failed to get indirect mode data.\n");
213 return;
214 }
215
216 load_image_data((caddr_t) &image_store, &image);
217
218 base = sc->sc_slot.virtual_base;
219
220 sc->curr_mode.mode_id = mode;
221 sc->curr_mode.fbbase = (caddr_t) (base + image.offset);
222 sc->curr_mode.fboff = image.offset;
223 sc->curr_mode.rowbytes = image.rowbytes;
224 sc->curr_mode.width = image.right - image.left;
225 sc->curr_mode.height = image.bottom - image.top;
226 sc->curr_mode.fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
227 sc->curr_mode.hres = image.hRes;
228 sc->curr_mode.vres = image.vRes;
229 sc->curr_mode.ptype = image.pixelType;
230 sc->curr_mode.psize = image.pixelSize;
231
232 strncpy(sc->card_name, nubus_get_card_name(&sc->sc_slot),
233 CARD_NAME_LEN);
234
235 sc->card_name[CARD_NAME_LEN-1] = '\0';
236
237 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
238
239 sc->g_flags = GF_ALIVE;
240
241 printf(": %d x %d ", sc->curr_mode.width, sc->curr_mode.height);
242
243 if (sc->curr_mode.psize == 1)
244 printf("monochrome");
245 else
246 printf("%d color", 1 << sc->curr_mode.psize);
247
248 printf(" %s display\n", sc->card_name);
249 }
250
251 static int
252 grfmv_mode(gp, cmd, arg)
253 struct grf_softc *gp;
254 int cmd;
255 void *arg;
256 {
257 switch (cmd) {
258 case GM_GRFON:
259 case GM_GRFOFF:
260 return 0;
261 case GM_CURRMODE:
262 break;
263 case GM_NEWMODE:
264 break;
265 case GM_LISTMODES:
266 break;
267 }
268 return EINVAL;
269 }
270
271 static caddr_t
272 grfmv_phys(gp, addr)
273 struct grf_softc *gp;
274 vm_offset_t addr;
275 {
276 return (caddr_t) (NUBUS_SLOT_TO_PADDR(gp->sc_slot.slot) +
277 (addr - gp->sc_slot.virtual_base));
278 }
279