1 /* $NetBSD: grf_obio.c,v 1.53.10.1 2007/10/03 19:24:10 garbled Exp $ */
4 * Copyright (C) 1998 Scott Reynolds
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
30 * Copyright (c) 1995 Allen Briggs. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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.
58 * Graphics display driver for the Macintosh internal video for machines
59 * that don't map it into a fake nubus card.
62 #include <sys/cdefs.h>
63 __KERNEL_RCSID(0, "$NetBSD: grf_obio.c,v 1.53.10.1 2007/10/03 19:24:10 garbled Exp $");
65 #include <sys/param.h>
66 #include <sys/device.h>
67 #include <sys/ioctl.h>
69 #include <sys/malloc.h>
72 #include <sys/systm.h>
74 #include <machine/autoconf.h>
75 #include <machine/bus.h>
76 #include <machine/cpu.h>
77 #include <machine/grfioctl.h>
78 #include <machine/viareg.h>
79 #include <machine/video.h>
81 #include <mac68k/nubus/nubus.h>
82 #include <mac68k/obio/obiovar.h>
83 #include <mac68k/dev/grfvar.h>
85 static int grfiv_mode(struct grf_softc
*, int, void *);
86 static int grfiv_match(struct device
*, struct cfdata
*, void *);
87 static void grfiv_attach(struct device
*, struct device
*, void *);
89 CFATTACH_DECL(intvid
, sizeof(struct grfbus_softc
),
90 grfiv_match
, grfiv_attach
, NULL
, NULL
);
92 #define DAFB_BASE 0xf9000000
93 #define DAFB_CONTROL_BASE 0xf9800000
94 #define CIVIC_BASE 0x50100000
95 #define CIVIC_CONTROL_BASE 0x50036000
96 #define VALKYRIE_BASE 0xf9000000
97 #define VALKYRIE_CONTROL_BASE 0x50f2a000
100 grfiv_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
102 struct obio_attach_args
*oa
= (struct obio_attach_args
*)aux
;
103 bus_space_handle_t bsh
;
109 switch (current_mac_model
->class) {
111 if (current_mac_model
->machineid
!= MACH_MACLC575
) {
112 base
= VALKYRIE_CONTROL_BASE
;
114 if (bus_space_map(oa
->oa_tag
, base
, 0x40, 0, &bsh
))
117 /* Disable interrupts */
118 bus_space_write_1(oa
->oa_tag
, bsh
, 0x18, 0x1);
120 bus_space_unmap(oa
->oa_tag
, bsh
, 0x40);
124 * Note: the only system in this class that does not have
125 * the Valkyrie chip -- at least, that we know of -- is
126 * the Performa/LC 57x series. This system has a version
127 * of the DAFB controller, instead.
129 * If this assumption proves false, we'll have to be more
135 * Assume DAFB for all of these, unless we can't
138 base
= DAFB_CONTROL_BASE
;
140 if (bus_space_map(oa
->oa_tag
, base
, 0x20, 0, &bsh
))
143 if (mac68k_bus_space_probe(oa
->oa_tag
, bsh
, 0x1c, 4) == 0) {
144 bus_space_unmap(oa
->oa_tag
, bsh
, 0x20);
148 bus_space_unmap(oa
->oa_tag
, bsh
, 0x20);
150 if (bus_space_map(oa
->oa_tag
, base
+ 0x100, 0x20, 0, &bsh
))
153 if (mac68k_bus_space_probe(oa
->oa_tag
, bsh
, 0x04, 4) == 0) {
154 bus_space_unmap(oa
->oa_tag
, bsh
, 0x20);
158 /* Disable interrupts */
159 bus_space_write_4(oa
->oa_tag
, bsh
, 0x04, 0);
161 /* Clear any interrupts */
162 bus_space_write_4(oa
->oa_tag
, bsh
, 0x0C, 0);
163 bus_space_write_4(oa
->oa_tag
, bsh
, 0x10, 0);
164 bus_space_write_4(oa
->oa_tag
, bsh
, 0x14, 0);
166 bus_space_unmap(oa
->oa_tag
, bsh
, 0x20);
169 base
= CIVIC_CONTROL_BASE
;
171 if (bus_space_map(oa
->oa_tag
, base
, 0x1000, 0, &bsh
))
174 /* Disable interrupts */
175 bus_space_write_1(oa
->oa_tag
, bsh
, 0x120, 0);
177 bus_space_unmap(oa
->oa_tag
, bsh
, 0x1000);
181 if (mac68k_video
.mv_len
== 0 ||
182 (via2_reg(rMonitor
) & RBVMonitorMask
) == RBVMonIDNone
)
186 if (mac68k_video
.mv_len
== 0)
195 grfiv_attach(struct device
*parent
, struct device
*self
, void *aux
)
197 struct obio_attach_args
*oa
= (struct obio_attach_args
*)aux
;
198 struct grfbus_softc
*sc
;
201 u_int32_t vbase1
, vbase2
;
203 sc
= (struct grfbus_softc
*)self
;
207 switch (current_mac_model
->class) {
209 if (current_mac_model
->machineid
!= MACH_MACLC575
) {
210 sc
->sc_basepa
= VALKYRIE_BASE
;
211 length
= 0x00100000; /* 1MB */
213 if (sc
->sc_basepa
<= mac68k_video
.mv_phys
&&
214 mac68k_video
.mv_phys
< (sc
->sc_basepa
+ length
)) {
216 mac68k_video
.mv_phys
- sc
->sc_basepa
;
219 m68k_trunc_page(mac68k_video
.mv_phys
);
221 m68k_page_offset(mac68k_video
.mv_phys
);
222 length
= mac68k_video
.mv_len
+ sc
->sc_fbofs
;
225 printf(" @ %lx: Valkyrie video subsystem\n",
226 sc
->sc_basepa
+ sc
->sc_fbofs
);
229 /* See note in grfiv_match() */
232 base
= DAFB_CONTROL_BASE
;
233 sc
->sc_tag
= oa
->oa_tag
;
234 if (bus_space_map(sc
->sc_tag
, base
, 0x20, 0, &sc
->sc_regh
)) {
235 printf(": failed to map DAFB register space\n");
239 sc
->sc_basepa
= DAFB_BASE
;
240 length
= 0x00100000; /* 1MB */
242 /* Compute the current frame buffer offset */
243 vbase1
= bus_space_read_4(sc
->sc_tag
, sc
->sc_regh
, 0x0) & 0xfff;
246 * XXX The following exists because the DAFB v7 in these
247 * systems doesn't return reasonable values to use for fbofs.
248 * Ken'ichi Ishizaka gets credit for this hack. (sar 19990426)
249 * (Does this get us the correct result for _all_ DAFB-
250 * equipped systems and monitor combinations? It seems
251 * possible, if not likely...)
253 switch (current_mac_model
->machineid
) {
255 case MACH_MACLC475_33
:
258 case MACH_MACQ605_33
:
263 vbase2
= bus_space_read_4(sc
->sc_tag
, sc
->sc_regh
, 0x4) & 0xf;
264 sc
->sc_fbofs
= (vbase1
<< 9) | (vbase2
<< 5);
266 printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
267 sc
->sc_basepa
+ sc
->sc_fbofs
,
268 (bus_space_read_4(sc
->sc_tag
, sc
->sc_regh
, 0x1c) & 0x7));
270 bus_space_unmap(sc
->sc_tag
, sc
->sc_regh
, 0x20);
273 sc
->sc_basepa
= CIVIC_BASE
;
274 length
= 0x00200000; /* 2MB */
275 if (mac68k_video
.mv_phys
>= sc
->sc_basepa
&&
276 mac68k_video
.mv_phys
< (sc
->sc_basepa
+ length
)) {
277 sc
->sc_fbofs
= mac68k_video
.mv_phys
- sc
->sc_basepa
;
279 sc
->sc_basepa
= m68k_trunc_page(mac68k_video
.mv_phys
);
280 sc
->sc_fbofs
= m68k_page_offset(mac68k_video
.mv_phys
);
281 length
= mac68k_video
.mv_len
+ sc
->sc_fbofs
;
284 printf(" @ %lx: CIVIC video subsystem\n",
285 sc
->sc_basepa
+ sc
->sc_fbofs
);
289 sc
->sc_basepa
= m68k_trunc_page(mac68k_video
.mv_phys
);
290 sc
->sc_fbofs
= m68k_page_offset(mac68k_video
.mv_phys
);
291 length
= mac68k_video
.mv_len
+ sc
->sc_fbofs
;
293 printf(" @ %lx: RBV video subsystem, ",
294 sc
->sc_basepa
+ sc
->sc_fbofs
);
295 switch (via2_reg(rMonitor
) & RBVMonitorMask
) {
297 printf("15\" monochrome portrait");
300 printf("12\" color");
303 printf("15\" color");
306 printf("Macintosh II");
309 printf("unrecognized");
312 printf(" display\n");
316 sc
->sc_basepa
= m68k_trunc_page(mac68k_video
.mv_phys
);
317 sc
->sc_fbofs
= m68k_page_offset(mac68k_video
.mv_phys
);
318 length
= mac68k_video
.mv_len
+ sc
->sc_fbofs
;
320 printf(" @ %lx: On-board video\n",
321 sc
->sc_basepa
+ sc
->sc_fbofs
);
325 if (bus_space_map(sc
->sc_tag
, sc
->sc_basepa
, length
, 0,
327 printf("%s: failed to map video RAM\n", sc
->sc_dev
.dv_xname
);
331 if (sc
->sc_basepa
<= mac68k_video
.mv_phys
&&
332 mac68k_video
.mv_phys
< (sc
->sc_basepa
+ length
)) {
334 mac68k_video
.mv_kvaddr
= sc
->sc_handle
.base
+ sc
->sc_fbofs
;
337 gm
= &(sc
->curr_mode
);
339 gm
->psize
= mac68k_video
.mv_depth
;
341 gm
->width
= mac68k_video
.mv_width
;
342 gm
->height
= mac68k_video
.mv_height
;
343 gm
->rowbytes
= mac68k_video
.mv_stride
;
344 gm
->hres
= 80; /* XXX hack */
345 gm
->vres
= 80; /* XXX hack */
346 gm
->fbsize
= gm
->height
* gm
->rowbytes
;
347 gm
->fbbase
= (void *)sc
->sc_handle
.base
; /* XXX yet another hack */
348 gm
->fboff
= sc
->sc_fbofs
;
350 /* Perform common video attachment. */
351 grf_establish(sc
, NULL
, grfiv_mode
);
355 grfiv_mode(struct grf_softc
*sc
, int cmd
, void *arg
)