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