grf_nubus.c revision 1.17 1 1.14 christos /* $NetBSD: grf_nubus.c,v 1.17 1997/02/24 06:20:06 scottr Exp $ */
2 1.1 briggs
3 1.1 briggs /*
4 1.1 briggs * Copyright (c) 1995 Allen Briggs. All rights reserved.
5 1.1 briggs *
6 1.1 briggs * Redistribution and use in source and binary forms, with or without
7 1.1 briggs * modification, are permitted provided that the following conditions
8 1.1 briggs * are met:
9 1.1 briggs * 1. Redistributions of source code must retain the above copyright
10 1.1 briggs * notice, this list of conditions and the following disclaimer.
11 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 briggs * notice, this list of conditions and the following disclaimer in the
13 1.1 briggs * documentation and/or other materials provided with the distribution.
14 1.1 briggs * 3. All advertising materials mentioning features or use of this software
15 1.1 briggs * must display the following acknowledgement:
16 1.1 briggs * This product includes software developed by Allen Briggs.
17 1.1 briggs * 4. The name of the author may not be used to endorse or promote products
18 1.1 briggs * derived from this software without specific prior written permission.
19 1.1 briggs *
20 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 briggs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 briggs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 briggs */
31 1.1 briggs /*
32 1.1 briggs * Device-specific routines for handling Nubus-based video cards.
33 1.1 briggs */
34 1.1 briggs
35 1.1 briggs #include <sys/param.h>
36 1.1 briggs
37 1.1 briggs #include <sys/device.h>
38 1.1 briggs #include <sys/ioctl.h>
39 1.1 briggs #include <sys/file.h>
40 1.1 briggs #include <sys/malloc.h>
41 1.1 briggs #include <sys/mman.h>
42 1.1 briggs #include <sys/proc.h>
43 1.8 briggs #include <sys/systm.h>
44 1.1 briggs
45 1.16 scottr #include <machine/bus.h>
46 1.8 briggs #include <machine/cpu.h>
47 1.1 briggs #include <machine/grfioctl.h>
48 1.8 briggs #include <machine/viareg.h>
49 1.1 briggs
50 1.1 briggs #include "nubus.h"
51 1.1 briggs #include "grfvar.h"
52 1.1 briggs
53 1.8 briggs static void load_image_data __P((caddr_t data, struct image_data *image));
54 1.8 briggs static void grfmv_intr __P((void *vsc, int slot));
55 1.1 briggs
56 1.17 scottr #ifndef MYSTERY
57 1.1 briggs static char zero = 0;
58 1.17 scottr #endif
59 1.1 briggs
60 1.8 briggs static int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
61 1.8 briggs static caddr_t grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
62 1.15 scottr static int grfmv_match __P((struct device *, struct cfdata *, void *));
63 1.8 briggs static void grfmv_attach __P((struct device *, struct device *, void *));
64 1.8 briggs
65 1.11 scottr struct cfdriver macvid_cd = {
66 1.11 scottr NULL, "macvid", DV_DULL
67 1.11 scottr };
68 1.11 scottr
69 1.11 scottr struct cfattach macvid_ca = {
70 1.11 scottr sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
71 1.8 briggs };
72 1.8 briggs
73 1.1 briggs static void
74 1.1 briggs load_image_data(data, image)
75 1.1 briggs caddr_t data;
76 1.1 briggs struct image_data *image;
77 1.1 briggs {
78 1.1 briggs bcopy(data , &image->size, 4);
79 1.1 briggs bcopy(data + 4, &image->offset, 4);
80 1.1 briggs bcopy(data + 8, &image->rowbytes, 2);
81 1.1 briggs bcopy(data + 10, &image->top, 2);
82 1.1 briggs bcopy(data + 12, &image->left, 2);
83 1.1 briggs bcopy(data + 14, &image->bottom, 2);
84 1.1 briggs bcopy(data + 16, &image->right, 2);
85 1.1 briggs bcopy(data + 18, &image->version, 2);
86 1.1 briggs bcopy(data + 20, &image->packType, 2);
87 1.1 briggs bcopy(data + 22, &image->packSize, 4);
88 1.1 briggs bcopy(data + 26, &image->hRes, 4);
89 1.1 briggs bcopy(data + 30, &image->vRes, 4);
90 1.1 briggs bcopy(data + 34, &image->pixelType, 2);
91 1.1 briggs bcopy(data + 36, &image->pixelSize, 2);
92 1.1 briggs bcopy(data + 38, &image->cmpCount, 2);
93 1.1 briggs bcopy(data + 40, &image->cmpSize, 2);
94 1.1 briggs bcopy(data + 42, &image->planeBytes, 4);
95 1.1 briggs }
96 1.1 briggs
97 1.8 briggs /*ARGSUSED*/
98 1.1 briggs static void
99 1.8 briggs grfmv_intr(vsc, slot)
100 1.8 briggs void *vsc;
101 1.1 briggs int slot;
102 1.1 briggs {
103 1.17 scottr #ifdef MYSTERY
104 1.17 scottr struct grfbus_softc *sc;
105 1.17 scottr caddr_t slotbase;
106 1.17 scottr
107 1.17 scottr sc = (struct grfbus_softc *) vsc;
108 1.17 scottr slotbase = (caddr_t) sc->sc_slot.virtual_base;
109 1.17 scottr asm volatile(" movl %0,a0
110 1.17 scottr movl a0@(0xff6028),d0
111 1.17 scottr andl #0x2,d0
112 1.17 scottr beq _mv_intr0
113 1.17 scottr movql #0x3,d0
114 1.17 scottr _mv_intr0:
115 1.17 scottr movl a0@(0xff600c),d1
116 1.17 scottr andl #0x3,d1
117 1.17 scottr cmpl d1,d0
118 1.17 scottr beq _mv_intr_fin
119 1.17 scottr movl d0,a0@(0xff600c)
120 1.17 scottr nop
121 1.17 scottr tstb d0
122 1.17 scottr beq _mv_intr1
123 1.17 scottr movl #0x0002,a0@(0xff6040)
124 1.17 scottr movl #0x0102,a0@(0xff6044)
125 1.17 scottr movl #0x0105,a0@(0xff6048)
126 1.17 scottr movl #0x000e,a0@(0xff604c)
127 1.17 scottr movl #0x001c,a0@(0xff6050)
128 1.17 scottr movl #0x00bc,a0@(0xff6054)
129 1.17 scottr movl #0x00c3,a0@(0xff6058)
130 1.17 scottr movl #0x0061,a0@(0xff605c)
131 1.17 scottr movl #0x0012,a0@(0xff6060)
132 1.17 scottr bra _mv_intr_fin
133 1.17 scottr _mv_intr1:
134 1.17 scottr movl #0x0002,a0@(0xff6040)
135 1.17 scottr movl #0x0209,a0@(0xff6044)
136 1.17 scottr movl #0x020c,a0@(0xff6048)
137 1.17 scottr movl #0x000f,a0@(0xff604c)
138 1.17 scottr movl #0x0027,a0@(0xff6050)
139 1.17 scottr movl #0x00c7,a0@(0xff6054)
140 1.17 scottr movl #0x00d7,a0@(0xff6058)
141 1.17 scottr movl #0x006b,a0@(0xff605c)
142 1.17 scottr movl #0x0029,a0@(0xff6060)
143 1.17 scottr _mv_intr_fin:
144 1.17 scottr movl #0x1,a0@(0xff6014)"
145 1.17 scottr : : "g" (slotbase) : "a0","d0","d1");
146 1.17 scottr #else
147 1.9 briggs caddr_t slotbase;
148 1.11 scottr struct grfbus_softc *sc;
149 1.1 briggs
150 1.11 scottr sc = (struct grfbus_softc *) vsc;
151 1.9 briggs slotbase = (caddr_t) sc->sc_slot.virtual_base;
152 1.3 briggs slotbase[0xa0000] = zero;
153 1.17 scottr #endif
154 1.1 briggs }
155 1.1 briggs
156 1.7 briggs static int
157 1.15 scottr grfmv_match(parent, cf, aux)
158 1.11 scottr struct device *parent;
159 1.15 scottr struct cfdata *cf;
160 1.15 scottr void *aux;
161 1.1 briggs {
162 1.15 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
163 1.1 briggs
164 1.15 scottr if (na->category != NUBUS_CATEGORY_DISPLAY)
165 1.1 briggs return 0;
166 1.1 briggs
167 1.15 scottr if (na->type != NUBUS_TYPE_VIDEO)
168 1.1 briggs return 0;
169 1.1 briggs
170 1.15 scottr if (na->drsw != NUBUS_DRSW_APPLE)
171 1.1 briggs return 0;
172 1.1 briggs
173 1.1 briggs /*
174 1.1 briggs * If we've gotten this far, then we're dealing with a real-live
175 1.1 briggs * Apple QuickDraw-compatible display card resource. Now, how to
176 1.1 briggs * determine that this is an active resource??? Dunno. But we'll
177 1.1 briggs * proceed like it is.
178 1.1 briggs */
179 1.1 briggs
180 1.1 briggs return 1;
181 1.1 briggs }
182 1.1 briggs
183 1.8 briggs static void
184 1.8 briggs grfmv_attach(parent, self, aux)
185 1.8 briggs struct device *parent, *self;
186 1.8 briggs void *aux;
187 1.1 briggs {
188 1.15 scottr struct grfbus_softc *sc = (struct grfbus_softc *) self;
189 1.15 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
190 1.1 briggs struct image_data image_store, image;
191 1.15 scottr struct grfmode *gm;
192 1.15 scottr char cardname[CARD_NAME_LEN];
193 1.15 scottr nubus_dirent dirent;
194 1.15 scottr nubus_dir dir, mode_dir;
195 1.15 scottr int mode;
196 1.15 scottr
197 1.15 scottr sc->card_id = na->drhw;
198 1.15 scottr
199 1.15 scottr bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
200 1.15 scottr
201 1.15 scottr nubus_get_main_dir(&sc->sc_slot, &dir);
202 1.1 briggs
203 1.15 scottr if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
204 1.15 scottr return;
205 1.15 scottr
206 1.15 scottr nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
207 1.15 scottr
208 1.15 scottr if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
209 1.15 scottr NUBUS_RSRC_TYPE, &dirent) <= 0)
210 1.15 scottr if ((na->rsrcid != 128) ||
211 1.15 scottr (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
212 1.15 scottr return;
213 1.8 briggs
214 1.1 briggs mode = NUBUS_RSRC_FIRSTMODE;
215 1.8 briggs if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
216 1.14 christos printf("\n%s: probe failed to get board rsrc.\n",
217 1.11 scottr sc->sc_dev.dv_xname);
218 1.8 briggs return;
219 1.8 briggs }
220 1.1 briggs
221 1.1 briggs nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
222 1.1 briggs
223 1.8 briggs if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
224 1.8 briggs <= 0) {
225 1.14 christos printf("\n%s: probe failed to get mode dir.\n",
226 1.11 scottr sc->sc_dev.dv_xname);
227 1.8 briggs return;
228 1.8 briggs }
229 1.1 briggs
230 1.1 briggs if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
231 1.8 briggs sizeof(struct image_data)) <= 0) {
232 1.14 christos printf("\n%s: probe failed to get indirect mode data.\n",
233 1.11 scottr sc->sc_dev.dv_xname);
234 1.8 briggs return;
235 1.8 briggs }
236 1.1 briggs
237 1.15 scottr /* Need to load display info (and driver?), etc... (?) */
238 1.15 scottr
239 1.1 briggs load_image_data((caddr_t) &image_store, &image);
240 1.1 briggs
241 1.15 scottr gm = &sc->curr_mode;
242 1.11 scottr gm->mode_id = mode;
243 1.11 scottr gm->fbbase = (caddr_t) (sc->sc_slot.virtual_base + image.offset);
244 1.11 scottr gm->fboff = image.offset;
245 1.11 scottr gm->rowbytes = image.rowbytes;
246 1.11 scottr gm->width = image.right - image.left;
247 1.11 scottr gm->height = image.bottom - image.top;
248 1.11 scottr gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
249 1.11 scottr gm->hres = image.hRes;
250 1.11 scottr gm->vres = image.vRes;
251 1.11 scottr gm->ptype = image.pixelType;
252 1.11 scottr gm->psize = image.pixelSize;
253 1.1 briggs
254 1.11 scottr strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
255 1.1 briggs CARD_NAME_LEN);
256 1.11 scottr cardname[CARD_NAME_LEN-1] = '\0';
257 1.1 briggs
258 1.14 christos printf(": %s\n", cardname);
259 1.1 briggs
260 1.1 briggs add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
261 1.1 briggs
262 1.11 scottr /* Perform common video attachment. */
263 1.12 scottr grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
264 1.1 briggs }
265 1.1 briggs
266 1.8 briggs static int
267 1.1 briggs grfmv_mode(gp, cmd, arg)
268 1.1 briggs struct grf_softc *gp;
269 1.1 briggs int cmd;
270 1.1 briggs void *arg;
271 1.1 briggs {
272 1.1 briggs switch (cmd) {
273 1.4 briggs case GM_GRFON:
274 1.4 briggs case GM_GRFOFF:
275 1.4 briggs return 0;
276 1.1 briggs case GM_CURRMODE:
277 1.1 briggs break;
278 1.1 briggs case GM_NEWMODE:
279 1.1 briggs break;
280 1.1 briggs case GM_LISTMODES:
281 1.1 briggs break;
282 1.1 briggs }
283 1.1 briggs return EINVAL;
284 1.6 briggs }
285 1.6 briggs
286 1.8 briggs static caddr_t
287 1.6 briggs grfmv_phys(gp, addr)
288 1.6 briggs struct grf_softc *gp;
289 1.6 briggs vm_offset_t addr;
290 1.6 briggs {
291 1.17 scottr return (caddr_t) (NUBUS_SLOT2PA(gp->sc_slot->slot) +
292 1.11 scottr (addr - gp->sc_slot->virtual_base));
293 1.1 briggs }
294