grf_nubus.c revision 1.4 1 /* $NetBSD: grf_nubus.c,v 1.4 1995/06/30 05:21:33 briggs Exp $ */
2
3 /*
4 * Copyright (c) 1995 Allen Briggs. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Allen Briggs.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * Device-specific routines for handling Nubus-based video cards.
33 */
34
35 #include <sys/param.h>
36
37 #include <sys/device.h>
38 #include <sys/ioctl.h>
39 #include <sys/file.h>
40 #include <sys/malloc.h>
41 #include <sys/mman.h>
42 #include <sys/proc.h>
43
44 #include <machine/grfioctl.h>
45 #include <machine/cpu.h>
46
47 #include "nubus.h"
48 #include "grfvar.h"
49
50 extern int grfmv_probe __P((struct grf_softc *gp, nubus_slot *slot));
51 extern int grfmv_init __P((struct grf_softc *gp));
52 extern int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
53
54 static char zero = 0;
55
56 static void
57 load_image_data(data, image)
58 caddr_t data;
59 struct image_data *image;
60 {
61 bcopy(data , &image->size, 4);
62 bcopy(data + 4, &image->offset, 4);
63 bcopy(data + 8, &image->rowbytes, 2);
64 bcopy(data + 10, &image->top, 2);
65 bcopy(data + 12, &image->left, 2);
66 bcopy(data + 14, &image->bottom, 2);
67 bcopy(data + 16, &image->right, 2);
68 bcopy(data + 18, &image->version, 2);
69 bcopy(data + 20, &image->packType, 2);
70 bcopy(data + 22, &image->packSize, 4);
71 bcopy(data + 26, &image->hRes, 4);
72 bcopy(data + 30, &image->vRes, 4);
73 bcopy(data + 34, &image->pixelType, 2);
74 bcopy(data + 36, &image->pixelSize, 2);
75 bcopy(data + 38, &image->cmpCount, 2);
76 bcopy(data + 40, &image->cmpSize, 2);
77 bcopy(data + 42, &image->planeBytes, 4);
78 }
79
80 static void
81 grfmv_intr(sc, slot)
82 struct grf_softc *sc;
83 int slot;
84 {
85 struct grf_softc *gp;
86 caddr_t slotbase;
87
88 slotbase = (caddr_t) NUBUS_SLOT_TO_BASE(slot);
89 slotbase[0xa0000] = zero;
90 }
91
92 extern int
93 grfmv_probe(sc, slot)
94 struct grf_softc *sc;
95 nubus_slot *slot;
96 {
97 nubus_dir dir, *dirp, dir2, *dirp2;
98 nubus_dirent dirent, *direntp;
99 nubus_type slottype;
100
101 dirp = &dir;
102 direntp = &dirent;
103 nubus_get_main_dir(slot, dirp);
104
105 /*
106 * Unfortunately, I think we'll have to load this value from
107 * the macos. The alternative is putting in enough hooks to
108 * be able to call the card's PrimaryInit routine which could
109 * call just about any part of the ROM, I think.
110 */
111 if (nubus_find_rsrc(slot, dirp, 128, direntp) <= 0) {
112 if (nubus_find_rsrc(slot, dirp, 129, direntp) <= 0) {
113 return 0;
114 }
115 }
116
117 dirp2 = (nubus_dir *) &sc->board_dir;
118 nubus_get_dir_from_rsrc(slot, direntp, dirp2);
119
120 if (nubus_find_rsrc(slot, dirp2, NUBUS_RSRC_TYPE, direntp) <= 0)
121 /* Type is a required entry... This should never happen. */
122 return 0;
123
124 if (nubus_get_ind_data(slot, direntp,
125 (caddr_t) &slottype, sizeof(nubus_type)) <= 0)
126 return 0;
127
128 if (slottype.category != NUBUS_CATEGORY_DISPLAY)
129 return 0;
130
131 if (slottype.type != NUBUS_TYPE_VIDEO)
132 return 0;
133
134 if (slottype.drsw != NUBUS_DRSW_APPLE)
135 return 0;
136
137 /*
138 * If we've gotten this far, then we're dealing with a real-live
139 * Apple QuickDraw-compatible display card resource. Now, how to
140 * determine that this is an active resource??? Dunno. But we'll
141 * proceed like it is.
142 */
143
144 sc->card_id = slottype.drhw;
145
146 /* Need to load display info (and driver?), etc... */
147
148 return 1;
149 }
150
151 extern int
152 grfmv_init(sc)
153 struct grf_softc *sc;
154 {
155 struct image_data image_store, image;
156 nubus_dirent dirent;
157 nubus_dir mode_dir;
158 int mode;
159 u_long base;
160
161 mode = NUBUS_RSRC_FIRSTMODE;
162 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0)
163 return 0;
164
165 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
166
167 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent) <= 0)
168 return 0;
169
170 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
171 sizeof(struct image_data)) <= 0)
172 return 0;
173
174 load_image_data((caddr_t) &image_store, &image);
175
176 base = NUBUS_SLOT_TO_BASE(sc->sc_slot.slot);
177
178 sc->curr_mode.mode_id = mode;
179 sc->curr_mode.fbbase = (caddr_t) (base + image.offset);
180 sc->curr_mode.rowbytes = image.rowbytes;
181 sc->curr_mode.width = image.right - image.left;
182 sc->curr_mode.height = image.bottom - image.top;
183 sc->curr_mode.fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
184 sc->curr_mode.hres = image.hRes;
185 sc->curr_mode.vres = image.vRes;
186 sc->curr_mode.ptype = image.pixelType;
187 sc->curr_mode.psize = image.pixelSize;
188
189 strncpy(sc->card_name, nubus_get_card_name(&sc->sc_slot),
190 CARD_NAME_LEN);
191
192 sc->card_name[CARD_NAME_LEN-1] = '\0';
193
194 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
195
196 return 1;
197 }
198
199 extern int
200 grfmv_mode(gp, cmd, arg)
201 struct grf_softc *gp;
202 int cmd;
203 void *arg;
204 {
205 switch (cmd) {
206 case GM_GRFON:
207 case GM_GRFOFF:
208 return 0;
209 case GM_CURRMODE:
210 break;
211 case GM_NEWMODE:
212 break;
213 case GM_LISTMODES:
214 break;
215 }
216 return EINVAL;
217 }
218