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