grf_obio.c revision 1.41.2.1 1 /* $NetBSD: grf_obio.c,v 1.41.2.1 1999/03/11 19:27:46 scottr Exp $ */
2
3 /*
4 * Copyright (C) 1998 Scott Reynolds
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*
30 * Copyright (c) 1995 Allen Briggs. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by Allen Briggs.
43 * 4. The name of the author may not be used to endorse or promote products
44 * derived from this software without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57 /*
58 * Graphics display driver for the Macintosh internal video for machines
59 * that don't map it into a fake nubus card.
60 */
61
62 #include <sys/param.h>
63 #include <sys/device.h>
64 #include <sys/ioctl.h>
65 #include <sys/file.h>
66 #include <sys/malloc.h>
67 #include <sys/mman.h>
68 #include <sys/proc.h>
69 #include <sys/systm.h>
70
71 #include <machine/autoconf.h>
72 #include <machine/bus.h>
73 #include <machine/cpu.h>
74 #include <machine/grfioctl.h>
75 #include <machine/viareg.h>
76
77 #include <mac68k/nubus/nubus.h>
78 #include <mac68k/obio/obiovar.h>
79 #include <mac68k/dev/grfvar.h>
80
81 extern u_int32_t mac68k_vidphys;
82 extern u_int32_t mac68k_vidlen;
83 extern long videoaddr;
84 extern long videorowbytes;
85 extern long videobitdepth;
86 extern u_long videosize;
87
88 static int grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
89 static int grfiv_match __P((struct device *, struct cfdata *, void *));
90 static void grfiv_attach __P((struct device *, struct device *, void *));
91
92 struct cfattach intvid_ca = {
93 sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
94 };
95
96 #define DAFB_BASE 0xf9000000
97 #define DAFB_CONTROL_BASE 0xf9800000
98 #define CIVIC_BASE 0x50100000
99 #define CIVIC_CONTROL_BASE 0x50036000
100 #define VALKYRIE_BASE 0xf9000000
101 #define VALKYRIE_CONTROL_BASE 0x50f2a000
102
103 static int
104 grfiv_match(parent, cf, aux)
105 struct device *parent;
106 struct cfdata *cf;
107 void *aux;
108 {
109 struct obio_attach_args *oa = (struct obio_attach_args *)aux;
110 bus_space_handle_t bsh;
111 int found;
112 u_int base;
113
114 found = 1;
115
116 switch (current_mac_model->class) {
117 case MACH_CLASSQ2:
118 if (current_mac_model->machineid != MACH_MACLC575) {
119 base = VALKYRIE_CONTROL_BASE;
120
121 if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh))
122 return 0;
123
124 /* Disable interrupts */
125 bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
126 break;
127 }
128 /*
129 * Note: the only system in this class that does not have
130 * the Valkyrie chip -- at least, that we know of -- is
131 * the Performa/LC 57x series. This system has a version
132 * of the DAFB controller, instead.
133 *
134 * If this assumption proves false, we'll have to be more
135 * intelligent here.
136 */
137 /*FALLTHROUGH*/
138 case MACH_CLASSQ:
139 /*
140 * Assume DAFB for all of these, unless we can't
141 * access the memory.
142 */
143 base = DAFB_CONTROL_BASE;
144
145 if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
146 return 0;
147
148 if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1c, 4) == 0) {
149 bus_space_unmap(oa->oa_tag, bsh, 0x1000);
150 return 0;
151 }
152
153 /* Set "Turbo SCSI" configuration to default */
154 bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
155 bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
156
157 /* Disable interrupts */
158 bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
159
160 /* Clear any interrupts */
161 bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
162 bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
163 bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
164
165 bus_space_unmap(oa->oa_tag, bsh, 0x1000);
166 break;
167 case MACH_CLASSAV:
168 base = CIVIC_CONTROL_BASE;
169
170 if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
171 return 0;
172
173 /* Disable interrupts */
174 bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
175
176 bus_space_unmap(oa->oa_tag, bsh, 0x1000);
177 break;
178 case MACH_CLASSIIci:
179 case MACH_CLASSIIsi:
180 if (mac68k_vidlen == 0 ||
181 (via2_reg(rMonitor) & RBVMonitorMask) == RBVMonIDNone)
182 found = 0;
183 break;
184 default:
185 if (mac68k_vidlen == 0)
186 found = 0;
187 break;
188 }
189
190 return found;
191 }
192
193 static void
194 grfiv_attach(parent, self, aux)
195 struct device *parent, *self;
196 void *aux;
197 {
198 struct obio_attach_args *oa = (struct obio_attach_args *)aux;
199 struct grfbus_softc *sc;
200 struct grfmode *gm;
201 u_long base, length;
202 u_int32_t vbase1, vbase2;
203
204 sc = (struct grfbus_softc *)self;
205
206 sc->card_id = 0;
207
208 switch (current_mac_model->class) {
209 case MACH_CLASSQ2:
210 if (current_mac_model->machineid != MACH_MACLC575) {
211 sc->sc_basepa = VALKYRIE_BASE;
212 length = 0x00100000; /* 1MB */
213
214 if (sc->sc_basepa <= mac68k_vidphys &&
215 mac68k_vidphys < (sc->sc_basepa + length))
216 sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
217 else
218 sc->sc_fbofs = 0;
219
220 printf(" @ %lx: Valkyrie video subsystem\n",
221 sc->sc_basepa + sc->sc_fbofs);
222 break;
223 }
224 /* See note in grfiv_match() */
225 /*FALLTHROUGH*/
226 case MACH_CLASSQ:
227 base = DAFB_CONTROL_BASE;
228 sc->sc_tag = oa->oa_tag;
229 if (bus_space_map(sc->sc_tag, base, 0x1000, 0, &sc->sc_regh)) {
230 printf(": failed to map DAFB register space\n");
231 return;
232 }
233
234 sc->sc_basepa = DAFB_BASE;
235 length = 0x00100000; /* 1MB */
236
237 /* Compute the current frame buffer offset */
238 vbase1 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x0) & 0xfff;
239 vbase2 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x4) & 0xf;
240 sc->sc_fbofs = (vbase1 << 9) | (vbase2 << 5);
241
242 #if 1
243 /*
244 * XXX The following hack exists because the DAFB v7 in these
245 * systems doesn't compute fbofs correctly. (sar 19980813)
246 */
247 switch (current_mac_model->machineid) {
248 case MACH_MACLC475:
249 case MACH_MACLC475_33:
250 case MACH_MACLC575:
251 sc->sc_fbofs = 0x1000;
252 break;
253 }
254 #endif
255
256 printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
257 sc->sc_basepa + sc->sc_fbofs,
258 (bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x1c) & 0x7));
259
260 bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
261 break;
262 case MACH_CLASSAV:
263 sc->sc_basepa = CIVIC_BASE;
264 length = 0x00200000; /* 2MB */
265
266 if (sc->sc_basepa <= mac68k_vidphys &&
267 mac68k_vidphys < (sc->sc_basepa + length))
268 sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
269 else
270 sc->sc_fbofs = 0;
271
272 printf(" @ %lx: Civic video subsystem\n",
273 sc->sc_basepa + sc->sc_fbofs);
274 break;
275 case MACH_CLASSIIci:
276 case MACH_CLASSIIsi:
277 sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
278 sc->sc_fbofs = mac68k_vidphys & PGOFSET;
279 length = mac68k_vidlen + sc->sc_fbofs;
280
281 printf(" @ %lx: RBV video subsystem, ",
282 sc->sc_basepa + sc->sc_fbofs);
283 switch (via2_reg(rMonitor) & RBVMonitorMask) {
284 case RBVMonIDBWP:
285 printf("15\" monochrome portrait");
286 break;
287 case RBVMonIDRGB12:
288 printf("12\" color");
289 break;
290 case RBVMonIDRGB15:
291 printf("15\" color");
292 break;
293 case RBVMonIDStd:
294 printf("Macintosh II");
295 break;
296 default:
297 printf("unrecognized");
298 break;
299 }
300 printf(" display\n");
301
302 break;
303 default:
304 sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
305 sc->sc_fbofs = mac68k_vidphys & PGOFSET;
306 length = mac68k_vidlen + sc->sc_fbofs;
307
308 printf(" @ %lx: On-board video\n",
309 sc->sc_basepa + sc->sc_fbofs);
310 break;
311 }
312
313 if (bus_space_map(sc->sc_tag, sc->sc_basepa, length, 0,
314 &sc->sc_handle)) {
315 printf("%s: failed to map video RAM\n", sc->sc_dev.dv_xname);
316 return;
317 }
318
319 if (sc->sc_basepa <= mac68k_vidphys &&
320 mac68k_vidphys < (sc->sc_basepa + length))
321 videoaddr = sc->sc_handle + sc->sc_fbofs; /* XXX big ol' hack */
322
323 gm = &(sc->curr_mode);
324 gm->mode_id = 0;
325 gm->psize = videobitdepth;
326 gm->ptype = 0;
327 gm->width = videosize & 0xffff;
328 gm->height = (videosize >> 16) & 0xffff;
329 gm->rowbytes = videorowbytes;
330 gm->hres = 80; /* XXX hack */
331 gm->vres = 80; /* XXX hack */
332 gm->fbsize = gm->height * gm->rowbytes;
333 gm->fbbase = (caddr_t)sc->sc_handle; /* XXX yet another hack */
334 gm->fboff = sc->sc_fbofs;
335
336 /* Perform common video attachment. */
337 grf_establish(sc, NULL, grfiv_mode);
338 }
339
340 static int
341 grfiv_mode(sc, cmd, arg)
342 struct grf_softc *sc;
343 int cmd;
344 void *arg;
345 {
346 switch (cmd) {
347 case GM_GRFON:
348 case GM_GRFOFF:
349 return 0;
350 case GM_CURRMODE:
351 break;
352 case GM_NEWMODE:
353 break;
354 case GM_LISTMODES:
355 break;
356 }
357 return EINVAL;
358 }
359