grf_nubus.c revision 1.15 1 1.14 christos /* $NetBSD: grf_nubus.c,v 1.15 1996/12/16 16:17: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.8 briggs #include <machine/cpu.h>
46 1.1 briggs #include <machine/grfioctl.h>
47 1.8 briggs #include <machine/viareg.h>
48 1.1 briggs
49 1.1 briggs #include "nubus.h"
50 1.1 briggs #include "grfvar.h"
51 1.1 briggs
52 1.8 briggs static void load_image_data __P((caddr_t data, struct image_data *image));
53 1.8 briggs static void grfmv_intr __P((void *vsc, int slot));
54 1.1 briggs
55 1.1 briggs static char zero = 0;
56 1.1 briggs
57 1.8 briggs static int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
58 1.8 briggs static caddr_t grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
59 1.15 scottr static int grfmv_match __P((struct device *, struct cfdata *, void *));
60 1.8 briggs static void grfmv_attach __P((struct device *, struct device *, void *));
61 1.8 briggs
62 1.11 scottr struct cfdriver macvid_cd = {
63 1.11 scottr NULL, "macvid", DV_DULL
64 1.11 scottr };
65 1.11 scottr
66 1.11 scottr struct cfattach macvid_ca = {
67 1.11 scottr sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
68 1.8 briggs };
69 1.8 briggs
70 1.1 briggs static void
71 1.1 briggs load_image_data(data, image)
72 1.1 briggs caddr_t data;
73 1.1 briggs struct image_data *image;
74 1.1 briggs {
75 1.1 briggs bcopy(data , &image->size, 4);
76 1.1 briggs bcopy(data + 4, &image->offset, 4);
77 1.1 briggs bcopy(data + 8, &image->rowbytes, 2);
78 1.1 briggs bcopy(data + 10, &image->top, 2);
79 1.1 briggs bcopy(data + 12, &image->left, 2);
80 1.1 briggs bcopy(data + 14, &image->bottom, 2);
81 1.1 briggs bcopy(data + 16, &image->right, 2);
82 1.1 briggs bcopy(data + 18, &image->version, 2);
83 1.1 briggs bcopy(data + 20, &image->packType, 2);
84 1.1 briggs bcopy(data + 22, &image->packSize, 4);
85 1.1 briggs bcopy(data + 26, &image->hRes, 4);
86 1.1 briggs bcopy(data + 30, &image->vRes, 4);
87 1.1 briggs bcopy(data + 34, &image->pixelType, 2);
88 1.1 briggs bcopy(data + 36, &image->pixelSize, 2);
89 1.1 briggs bcopy(data + 38, &image->cmpCount, 2);
90 1.1 briggs bcopy(data + 40, &image->cmpSize, 2);
91 1.1 briggs bcopy(data + 42, &image->planeBytes, 4);
92 1.1 briggs }
93 1.1 briggs
94 1.8 briggs /*ARGSUSED*/
95 1.1 briggs static void
96 1.8 briggs grfmv_intr(vsc, slot)
97 1.8 briggs void *vsc;
98 1.1 briggs int slot;
99 1.1 briggs {
100 1.9 briggs caddr_t slotbase;
101 1.11 scottr struct grfbus_softc *sc;
102 1.1 briggs
103 1.11 scottr sc = (struct grfbus_softc *) vsc;
104 1.9 briggs slotbase = (caddr_t) sc->sc_slot.virtual_base;
105 1.3 briggs slotbase[0xa0000] = zero;
106 1.1 briggs }
107 1.1 briggs
108 1.7 briggs static int
109 1.15 scottr grfmv_match(parent, cf, aux)
110 1.11 scottr struct device *parent;
111 1.15 scottr struct cfdata *cf;
112 1.15 scottr void *aux;
113 1.1 briggs {
114 1.15 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
115 1.1 briggs
116 1.15 scottr if (na->category != NUBUS_CATEGORY_DISPLAY)
117 1.1 briggs return 0;
118 1.1 briggs
119 1.15 scottr if (na->type != NUBUS_TYPE_VIDEO)
120 1.1 briggs return 0;
121 1.1 briggs
122 1.15 scottr if (na->drsw != NUBUS_DRSW_APPLE)
123 1.1 briggs return 0;
124 1.1 briggs
125 1.1 briggs /*
126 1.1 briggs * If we've gotten this far, then we're dealing with a real-live
127 1.1 briggs * Apple QuickDraw-compatible display card resource. Now, how to
128 1.1 briggs * determine that this is an active resource??? Dunno. But we'll
129 1.1 briggs * proceed like it is.
130 1.1 briggs */
131 1.1 briggs
132 1.1 briggs return 1;
133 1.1 briggs }
134 1.1 briggs
135 1.8 briggs static void
136 1.8 briggs grfmv_attach(parent, self, aux)
137 1.8 briggs struct device *parent, *self;
138 1.8 briggs void *aux;
139 1.1 briggs {
140 1.15 scottr struct grfbus_softc *sc = (struct grfbus_softc *) self;
141 1.15 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
142 1.1 briggs struct image_data image_store, image;
143 1.15 scottr struct grfmode *gm;
144 1.15 scottr char cardname[CARD_NAME_LEN];
145 1.15 scottr nubus_dirent dirent;
146 1.15 scottr nubus_dir dir, mode_dir;
147 1.15 scottr int mode;
148 1.15 scottr
149 1.15 scottr sc->card_id = na->drhw;
150 1.15 scottr
151 1.15 scottr bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
152 1.15 scottr
153 1.15 scottr nubus_get_main_dir(&sc->sc_slot, &dir);
154 1.1 briggs
155 1.15 scottr if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
156 1.15 scottr return;
157 1.15 scottr
158 1.15 scottr nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
159 1.15 scottr
160 1.15 scottr if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
161 1.15 scottr NUBUS_RSRC_TYPE, &dirent) <= 0)
162 1.15 scottr if ((na->rsrcid != 128) ||
163 1.15 scottr (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
164 1.15 scottr return;
165 1.8 briggs
166 1.1 briggs mode = NUBUS_RSRC_FIRSTMODE;
167 1.8 briggs if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
168 1.14 christos printf("\n%s: probe failed to get board rsrc.\n",
169 1.11 scottr sc->sc_dev.dv_xname);
170 1.8 briggs return;
171 1.8 briggs }
172 1.1 briggs
173 1.1 briggs nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
174 1.1 briggs
175 1.8 briggs if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
176 1.8 briggs <= 0) {
177 1.14 christos printf("\n%s: probe failed to get mode dir.\n",
178 1.11 scottr sc->sc_dev.dv_xname);
179 1.8 briggs return;
180 1.8 briggs }
181 1.1 briggs
182 1.1 briggs if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
183 1.8 briggs sizeof(struct image_data)) <= 0) {
184 1.14 christos printf("\n%s: probe failed to get indirect mode data.\n",
185 1.11 scottr sc->sc_dev.dv_xname);
186 1.8 briggs return;
187 1.8 briggs }
188 1.1 briggs
189 1.15 scottr /* Need to load display info (and driver?), etc... (?) */
190 1.15 scottr
191 1.1 briggs load_image_data((caddr_t) &image_store, &image);
192 1.1 briggs
193 1.15 scottr gm = &sc->curr_mode;
194 1.11 scottr gm->mode_id = mode;
195 1.11 scottr gm->fbbase = (caddr_t) (sc->sc_slot.virtual_base + image.offset);
196 1.11 scottr gm->fboff = image.offset;
197 1.11 scottr gm->rowbytes = image.rowbytes;
198 1.11 scottr gm->width = image.right - image.left;
199 1.11 scottr gm->height = image.bottom - image.top;
200 1.11 scottr gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
201 1.11 scottr gm->hres = image.hRes;
202 1.11 scottr gm->vres = image.vRes;
203 1.11 scottr gm->ptype = image.pixelType;
204 1.11 scottr gm->psize = image.pixelSize;
205 1.1 briggs
206 1.11 scottr strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
207 1.1 briggs CARD_NAME_LEN);
208 1.11 scottr cardname[CARD_NAME_LEN-1] = '\0';
209 1.1 briggs
210 1.14 christos printf(": %s\n", cardname);
211 1.1 briggs
212 1.1 briggs add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
213 1.1 briggs
214 1.11 scottr /* Perform common video attachment. */
215 1.12 scottr grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
216 1.1 briggs }
217 1.1 briggs
218 1.8 briggs static int
219 1.1 briggs grfmv_mode(gp, cmd, arg)
220 1.1 briggs struct grf_softc *gp;
221 1.1 briggs int cmd;
222 1.1 briggs void *arg;
223 1.1 briggs {
224 1.1 briggs switch (cmd) {
225 1.4 briggs case GM_GRFON:
226 1.4 briggs case GM_GRFOFF:
227 1.4 briggs return 0;
228 1.1 briggs case GM_CURRMODE:
229 1.1 briggs break;
230 1.1 briggs case GM_NEWMODE:
231 1.1 briggs break;
232 1.1 briggs case GM_LISTMODES:
233 1.1 briggs break;
234 1.1 briggs }
235 1.1 briggs return EINVAL;
236 1.6 briggs }
237 1.6 briggs
238 1.8 briggs static caddr_t
239 1.6 briggs grfmv_phys(gp, addr)
240 1.6 briggs struct grf_softc *gp;
241 1.6 briggs vm_offset_t addr;
242 1.6 briggs {
243 1.11 scottr return (caddr_t) (NUBUS_SLOT_TO_PADDR(gp->sc_slot->slot) +
244 1.11 scottr (addr - gp->sc_slot->virtual_base));
245 1.1 briggs }
246