grf_obio.c revision 1.38 1 1.38 scottr /* $NetBSD: grf_obio.c,v 1.38 1998/08/13 13:45:33 scottr 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.35 scottr
62 1.35 scottr #include "opt_grf.h"
63 1.1 briggs
64 1.1 briggs #include <sys/param.h>
65 1.1 briggs #include <sys/device.h>
66 1.1 briggs #include <sys/ioctl.h>
67 1.1 briggs #include <sys/file.h>
68 1.1 briggs #include <sys/malloc.h>
69 1.1 briggs #include <sys/mman.h>
70 1.1 briggs #include <sys/proc.h>
71 1.11 briggs #include <sys/systm.h>
72 1.1 briggs
73 1.18 briggs #include <machine/autoconf.h>
74 1.17 scottr #include <machine/bus.h>
75 1.17 scottr #include <machine/cpu.h>
76 1.1 briggs #include <machine/grfioctl.h>
77 1.18 briggs #include <machine/viareg.h>
78 1.1 briggs
79 1.32 scottr #include <mac68k/nubus/nubus.h>
80 1.32 scottr #include <mac68k/obio/obiovar.h>
81 1.22 scottr #include <mac68k/dev/grfvar.h>
82 1.1 briggs
83 1.5 briggs extern u_int32_t mac68k_vidphys;
84 1.36 scottr extern u_int32_t mac68k_vidlen;
85 1.36 scottr extern long videoaddr;
86 1.10 briggs extern long videorowbytes;
87 1.10 briggs extern long videobitdepth;
88 1.22 scottr extern u_long videosize;
89 1.5 briggs
90 1.11 briggs static int grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
91 1.16 scottr static int grfiv_match __P((struct device *, struct cfdata *, void *));
92 1.11 briggs static void grfiv_attach __P((struct device *, struct device *, void *));
93 1.12 scottr
94 1.12 scottr struct cfattach intvid_ca = {
95 1.12 scottr sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
96 1.11 briggs };
97 1.11 briggs
98 1.36 scottr #define DAFB_BASE 0xf9000000
99 1.36 scottr #define DAFB_CONTROL_BASE 0xf9800000
100 1.36 scottr #define CIVIC_BASE 0x50100000
101 1.25 briggs #define CIVIC_CONTROL_BASE 0x50036000
102 1.36 scottr #define VALKYRIE_BASE 0xf9000000
103 1.33 scottr #define VALKYRIE_CONTROL_BASE 0x50f2a000
104 1.18 briggs
105 1.11 briggs static int
106 1.16 scottr grfiv_match(parent, cf, aux)
107 1.16 scottr struct device *parent;
108 1.16 scottr struct cfdata *cf;
109 1.16 scottr void *aux;
110 1.1 briggs {
111 1.22 scottr struct obio_attach_args *oa = (struct obio_attach_args *)aux;
112 1.22 scottr bus_space_handle_t bsh;
113 1.34 scottr int found;
114 1.27 scottr u_int base;
115 1.18 briggs
116 1.18 briggs found = 1;
117 1.18 briggs
118 1.27 scottr switch (current_mac_model->class) {
119 1.36 scottr case MACH_CLASSQ2:
120 1.36 scottr if (current_mac_model->machineid != MACH_MACLC575) {
121 1.36 scottr base = VALKYRIE_CONTROL_BASE;
122 1.36 scottr
123 1.36 scottr if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh))
124 1.36 scottr return 0;
125 1.36 scottr
126 1.36 scottr /* Disable interrupts */
127 1.36 scottr bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
128 1.36 scottr }
129 1.36 scottr /*
130 1.36 scottr * Note: the only system in this class that does not have
131 1.36 scottr * the Valkyrie chip -- at least, that we know of -- is
132 1.36 scottr * the Performa/LC 57x series. This system has a version
133 1.36 scottr * of the DAFB controller, instead.
134 1.36 scottr *
135 1.36 scottr * If this assumption proves false, we'll have to be more
136 1.36 scottr * intelligent here.
137 1.36 scottr */
138 1.36 scottr /*FALLTHROUGH*/
139 1.20 briggs case MACH_CLASSQ:
140 1.20 briggs /*
141 1.20 briggs * Assume DAFB for all of these, unless we can't
142 1.20 briggs * access the memory.
143 1.20 briggs */
144 1.36 scottr base = DAFB_CONTROL_BASE;
145 1.18 briggs
146 1.36 scottr if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
147 1.36 scottr return 0;
148 1.18 briggs
149 1.36 scottr if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1c, 4) == 0) {
150 1.20 briggs bus_space_unmap(oa->oa_tag, bsh, 0x1000);
151 1.36 scottr return 0;
152 1.20 briggs }
153 1.20 briggs
154 1.18 briggs /* Set "Turbo SCSI" configuration to default */
155 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
156 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
157 1.1 briggs
158 1.18 briggs /* Disable interrupts */
159 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
160 1.18 briggs
161 1.18 briggs /* Clear any interrupts */
162 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
163 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
164 1.18 briggs bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
165 1.18 briggs
166 1.18 briggs bus_space_unmap(oa->oa_tag, bsh, 0x1000);
167 1.18 briggs break;
168 1.27 scottr case MACH_CLASSAV:
169 1.26 briggs base = CIVIC_CONTROL_BASE;
170 1.26 briggs
171 1.36 scottr if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
172 1.36 scottr return 0;
173 1.27 scottr
174 1.25 briggs /* Disable interrupts */
175 1.25 briggs bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
176 1.26 briggs
177 1.25 briggs bus_space_unmap(oa->oa_tag, bsh, 0x1000);
178 1.25 briggs break;
179 1.18 briggs default:
180 1.36 scottr if (mac68k_vidlen == 0)
181 1.18 briggs found = 0;
182 1.18 briggs break;
183 1.2 briggs }
184 1.7 briggs
185 1.18 briggs return found;
186 1.1 briggs }
187 1.1 briggs
188 1.11 briggs static void
189 1.11 briggs grfiv_attach(parent, self, aux)
190 1.11 briggs struct device *parent, *self;
191 1.11 briggs void *aux;
192 1.1 briggs {
193 1.22 scottr struct obio_attach_args *oa = (struct obio_attach_args *)aux;
194 1.22 scottr struct grfbus_softc *sc;
195 1.22 scottr struct grfmode *gm;
196 1.36 scottr u_long base, length;
197 1.36 scottr u_int32_t vbase1, vbase2;
198 1.11 briggs
199 1.22 scottr sc = (struct grfbus_softc *)self;
200 1.1 briggs
201 1.1 briggs sc->card_id = 0;
202 1.1 briggs
203 1.27 scottr switch (current_mac_model->class) {
204 1.36 scottr case MACH_CLASSQ2:
205 1.37 scottr if (current_mac_model->machineid == MACH_MACP580 ||
206 1.37 scottr current_mac_model->machineid == MACH_MACQ630) {
207 1.36 scottr printf(": Valkyrie video subsystem\n");
208 1.36 scottr sc->sc_basepa = VALKYRIE_BASE;
209 1.36 scottr length = 0x00100000; /* 1MB */
210 1.36 scottr
211 1.36 scottr if (sc->sc_basepa <= mac68k_vidphys &&
212 1.36 scottr mac68k_vidphys < (sc->sc_basepa + length))
213 1.36 scottr sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
214 1.36 scottr else
215 1.36 scottr sc->sc_fbofs = 0;
216 1.36 scottr
217 1.36 scottr printf(" @ %lx: Valkyrie video subsystem\n",
218 1.36 scottr sc->sc_basepa + sc->sc_fbofs);
219 1.36 scottr break;
220 1.36 scottr }
221 1.36 scottr /* See note in grfiv_match() */
222 1.36 scottr /*FALLTHROUGH*/
223 1.27 scottr case MACH_CLASSQ:
224 1.36 scottr base = DAFB_CONTROL_BASE;
225 1.18 briggs sc->sc_tag = oa->oa_tag;
226 1.26 briggs if (bus_space_map(sc->sc_tag, base, 0x1000, 0, &sc->sc_regh)) {
227 1.36 scottr printf(": failed to map DAFB register space\n");
228 1.36 scottr return;
229 1.18 briggs }
230 1.36 scottr
231 1.36 scottr sc->sc_basepa = DAFB_BASE;
232 1.36 scottr length = 0x00100000; /* 1MB */
233 1.36 scottr
234 1.36 scottr /* Compute the current frame buffer offset */
235 1.36 scottr vbase1 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x0) & 0xfff;
236 1.36 scottr vbase2 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x4) & 0xf;
237 1.36 scottr sc->sc_fbofs = (vbase1 << 9) | (vbase2 << 5);
238 1.38 scottr
239 1.38 scottr #if 1
240 1.38 scottr /*
241 1.38 scottr * XXX The following hack exists because the DAFB v7 in these
242 1.38 scottr * systems doesn't compute fbofs correctly. (sar 19980813)
243 1.38 scottr */
244 1.38 scottr switch (current_mac_model->machineid) {
245 1.38 scottr case MACH_MACLC475:
246 1.38 scottr case MACH_MACLC475_33:
247 1.38 scottr case MACH_MACLC575:
248 1.38 scottr sc->sc_fbofs = 0x1000;
249 1.38 scottr break;
250 1.38 scottr }
251 1.38 scottr #endif
252 1.36 scottr
253 1.36 scottr printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
254 1.36 scottr sc->sc_basepa + sc->sc_fbofs,
255 1.36 scottr (bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x1c) & 0x7));
256 1.36 scottr
257 1.25 briggs bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
258 1.18 briggs break;
259 1.27 scottr case MACH_CLASSAV:
260 1.36 scottr sc->sc_basepa = CIVIC_BASE;
261 1.36 scottr length = 0x00200000; /* 2MB */
262 1.36 scottr
263 1.36 scottr if (sc->sc_basepa <= mac68k_vidphys &&
264 1.36 scottr mac68k_vidphys < (sc->sc_basepa + length))
265 1.36 scottr sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
266 1.36 scottr else
267 1.36 scottr sc->sc_fbofs = 0;
268 1.36 scottr
269 1.36 scottr printf(" @ %lx: Civic video subsystem\n",
270 1.36 scottr sc->sc_basepa + sc->sc_fbofs);
271 1.36 scottr break;
272 1.18 briggs default:
273 1.36 scottr sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
274 1.36 scottr sc->sc_fbofs = mac68k_vidphys & PGOFSET;
275 1.36 scottr length = mac68k_vidlen + sc->sc_fbofs;
276 1.36 scottr
277 1.36 scottr printf(" @ %lx: On-board video\n",
278 1.36 scottr sc->sc_basepa + sc->sc_fbofs);
279 1.18 briggs break;
280 1.18 briggs }
281 1.1 briggs
282 1.36 scottr if (bus_space_map(sc->sc_tag, sc->sc_basepa, length, 0,
283 1.36 scottr &sc->sc_handle)) {
284 1.36 scottr printf("%s: failed to map video RAM\n", sc->sc_dev.dv_xname);
285 1.36 scottr return;
286 1.36 scottr }
287 1.36 scottr
288 1.36 scottr if (sc->sc_basepa <= mac68k_vidphys &&
289 1.36 scottr mac68k_vidphys < (sc->sc_basepa + length))
290 1.36 scottr videoaddr = sc->sc_handle + sc->sc_fbofs; /* XXX big ol' hack */
291 1.36 scottr
292 1.1 briggs gm = &(sc->curr_mode);
293 1.1 briggs gm->mode_id = 0;
294 1.10 briggs gm->psize = videobitdepth;
295 1.1 briggs gm->ptype = 0;
296 1.10 briggs gm->width = videosize & 0xffff;
297 1.10 briggs gm->height = (videosize >> 16) & 0xffff;
298 1.10 briggs gm->rowbytes = videorowbytes;
299 1.36 scottr gm->hres = 80; /* XXX hack */
300 1.36 scottr gm->vres = 80; /* XXX hack */
301 1.36 scottr gm->fbsize = gm->height * gm->rowbytes;
302 1.36 scottr gm->fbbase = (caddr_t)sc->sc_handle; /* XXX yet another hack */
303 1.36 scottr gm->fboff = sc->sc_fbofs;
304 1.1 briggs
305 1.12 scottr /* Perform common video attachment. */
306 1.33 scottr grf_establish(sc, NULL, grfiv_mode);
307 1.1 briggs }
308 1.1 briggs
309 1.11 briggs static int
310 1.1 briggs grfiv_mode(sc, cmd, arg)
311 1.1 briggs struct grf_softc *sc;
312 1.1 briggs int cmd;
313 1.1 briggs void *arg;
314 1.1 briggs {
315 1.4 briggs switch (cmd) {
316 1.4 briggs case GM_GRFON:
317 1.4 briggs case GM_GRFOFF:
318 1.4 briggs return 0;
319 1.4 briggs case GM_CURRMODE:
320 1.4 briggs break;
321 1.4 briggs case GM_NEWMODE:
322 1.4 briggs break;
323 1.4 briggs case GM_LISTMODES:
324 1.4 briggs break;
325 1.4 briggs }
326 1.4 briggs return EINVAL;
327 1.1 briggs }
328