grf_obio.c revision 1.18 1 /* $OpenBSD: grf_iv.c,v 1.13 1997/03/29 03:16:18 briggs Exp $ */
2 /* $NetBSD: grf_obio.c,v 1.18 1997/04/01 05:41:59 briggs Exp $ */
3
4 /*
5 * Copyright (c) 1995 Allen Briggs. 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Allen Briggs.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * Graphics display driver for the Macintosh internal video for machines
34 * that don't map it into a fake nubus card.
35 */
36
37 #include <sys/param.h>
38
39 #include <sys/device.h>
40 #include <sys/ioctl.h>
41 #include <sys/file.h>
42 #include <sys/malloc.h>
43 #include <sys/mman.h>
44 #include <sys/proc.h>
45 #include <sys/systm.h>
46
47 #include <machine/autoconf.h>
48 #include <machine/bus.h>
49 #include <machine/cpu.h>
50 #include <machine/grfioctl.h>
51 #include <machine/viareg.h>
52
53 #include "nubus.h"
54 #include "obiovar.h"
55 #include "grfvar.h"
56
57 extern u_int32_t mac68k_vidlog;
58 extern u_int32_t mac68k_vidphys;
59 extern long videorowbytes;
60 extern long videobitdepth;
61 extern unsigned long videosize;
62
63 static int grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
64 static caddr_t grfiv_phys __P((struct grf_softc *gp, vm_offset_t addr));
65 static int grfiv_match __P((struct device *, struct cfdata *, void *));
66 static void grfiv_attach __P((struct device *, struct device *, void *));
67
68 struct cfdriver intvid_cd = {
69 NULL, "intvid", DV_DULL
70 };
71
72 struct cfattach intvid_ca = {
73 sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
74 };
75
76 #define QUADRA_DAFB_BASE 0xF9800000
77
78 static int
79 grfiv_match(parent, cf, aux)
80 struct device *parent;
81 struct cfdata *cf;
82 void *aux;
83 {
84 struct obio_attach_args *oa = (struct obio_attach_args *) aux;
85 bus_space_handle_t bsh;
86 int found, sense;
87
88 found = 1;
89
90 switch (current_mac_model->class) {
91 case MACH_CLASSQ:
92 case MACH_CLASSQ2:
93
94 /* Assume DAFB for all of these */
95
96 if (bus_space_map(oa->oa_tag, QUADRA_DAFB_BASE, 0x1000,
97 0, &bsh)) {
98 panic("failed to map space for DAFB regs.\n");
99 }
100
101 sense = (bus_space_read_4(oa->oa_tag, bsh, 0x1C) & 7);
102
103 if (sense == 0)
104 found = 0;
105
106 /* Set "Turbo SCSI" configuration to default */
107 bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
108 bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
109
110 /* Disable interrupts */
111 bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
112
113 /* Clear any interrupts */
114 bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
115 bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
116 bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
117
118 bus_space_unmap(oa->oa_tag, bsh, 0x1000);
119
120 break;
121
122 default:
123 if (mac68k_vidlog == 0) {
124 found = 0;
125 }
126
127 break;
128 }
129
130 return found;
131 }
132
133 #define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)
134
135 static void
136 grfiv_attach(parent, self, aux)
137 struct device *parent, *self;
138 void *aux;
139 {
140 struct obio_attach_args *oa = (struct obio_attach_args *) aux;
141 struct grfbus_softc *sc;
142 struct grfmode *gm;
143
144 sc = (struct grfbus_softc *) self;
145
146 sc->card_id = 0;
147
148 switch (current_mac_model->class) {
149 case MACH_CLASSQ:
150 case MACH_CLASSQ2:
151 sc->sc_tag = oa->oa_tag;
152 if (bus_space_map(sc->sc_tag, QUADRA_DAFB_BASE, 0x1000,
153 0, &sc->sc_regh)) {
154 panic("failed to map space for DAFB regs.\n");
155 }
156 printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
157 break;
158 default:
159 printf(": Internal Video\n");
160 break;
161 }
162
163 gm = &(sc->curr_mode);
164 gm->mode_id = 0;
165 gm->psize = videobitdepth;
166 gm->ptype = 0;
167 gm->width = videosize & 0xffff;
168 gm->height = (videosize >> 16) & 0xffff;
169 gm->rowbytes = videorowbytes;
170 gm->hres = 80; /* XXX Hack */
171 gm->vres = 80; /* XXX Hack */
172 gm->fbsize = gm->rowbytes * gm->height;
173 gm->fbbase = (caddr_t) mac68k_trunc_page(mac68k_vidlog);
174 gm->fboff = mac68k_vidlog & PGOFSET;
175
176 /* Perform common video attachment. */
177 grf_establish(sc, NULL, grfiv_mode, grfiv_phys);
178 }
179
180 static int
181 grfiv_mode(sc, cmd, arg)
182 struct grf_softc *sc;
183 int cmd;
184 void *arg;
185 {
186 switch (cmd) {
187 case GM_GRFON:
188 case GM_GRFOFF:
189 return 0;
190 case GM_CURRMODE:
191 break;
192 case GM_NEWMODE:
193 break;
194 case GM_LISTMODES:
195 break;
196 }
197 return EINVAL;
198 }
199
200 static caddr_t
201 grfiv_phys(gp, addr)
202 struct grf_softc *gp;
203 vm_offset_t addr;
204 {
205 /*
206 * If we're using IIsi or similar, this will be 0.
207 * If we're using IIvx or similar, this will be correct.
208 */
209 return (caddr_t) mac68k_vidphys;
210 }
211